Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2127730ybb; Sun, 29 Mar 2020 23:23:17 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuDcbJwvUcjlnRo+pdnT/yNu9FGBTtkm5NPSjxelhkc93satLD5HKbXHTn18qAZHOCcNdpg X-Received: by 2002:aca:c608:: with SMTP id w8mr6831055oif.163.1585549397441; Sun, 29 Mar 2020 23:23:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1585549397; cv=pass; d=google.com; s=arc-20160816; b=H4YAOLbWcNZ8hdHpB6yDbqtdnXq3oW0gWrRycQB5qoDWhI5u/jfqBrhl7vC+tncWA9 nOkI6czX3O8tEROv6qi3clZQYSOrCOVQV+Ogvpedu8H8bVEWaKYjY7jATr2B8f/zkz6y BEs4IPCJTjTU53VvIv9xZ8lWa7WQJs9H0YZ9Xwvujo1Y7QxrHxJwCO95PHPBpyIzVw6b zDt3L5DotVXD9SIlv8HpHZLU+9um98R3R6oCmrs40fGnng+SNPwA5NZ8IAoeEn4rJ3dO 98HNbOXeKcJCZxoO0YAVTRlYRb8ghB7S0DGe/D3PZdpHARF4UCOcoCtGecvpgMxdlaM3 0Ykg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rjNjizM2G0T7+C7VEkNBPnrtlTTrAO5qxWvmKQ4fvJQ=; b=xRD3xM787WGWC9NOTtmrKBnPBJwZKN6Y55kaln4NhBHbuimUZ2NJ3qvtwJMBEluebC 8q6wT1RA0DynZxoo3N5ZaRKkZMJeUIWHZkr7ZfdvMEiOY1wQJHnRkr6Td2yIyFnONqBd ERXN/iYHtMPGPwAqH21/Sqy+tJrc2wg2U1tCE1b+wFULJkJO/mLl1YCvwCE1fgMZ0T0s ZMTnaZVNFqdE9SRqkLHrVDrYqphAM9NkDGnAgUgRUZF2HLZ/F2LPKU0zdKKEZe5ZukPX RMZUIHTmK9L4HeIvRU5Id6bWxz01+0lZk9dn9HFMY+PhP+HkHjaD+vJxpY66Zkmuuahy cWsA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=1gMwS6kx; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o20si5774279ota.17.2020.03.29.23.23.05; Sun, 29 Mar 2020 23:23:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=1gMwS6kx; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729035AbgC3GWF (ORCPT + 99 others); Mon, 30 Mar 2020 02:22:05 -0400 Received: from mail-dm6nam12on2077.outbound.protection.outlook.com ([40.107.243.77]:20854 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728732AbgC3GWF (ORCPT ); Mon, 30 Mar 2020 02:22:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ntw4bn1vrLr23jYwIu+dhzBMvARX6WB2s3p/tXrAg1OoU3TFZLU1+KufOJ0HA/4cH6/zGQ6BFCN7LN6T3fKl+WHKY56D1WYtDc53LBxJm0xu55mpFnup6j6FFyV9ivHUmKlzSmbj0qf35EsN1d5ua8Nafm6lZnNBz5ds3Hh/FFrFzCw74TxH7o5hpNHXEsxRh4EmemfNn7uCV9mMqr3wRfBPhjh1ivkf2Lm6WAAQt3/wW4Dlkpge56pRS47/ATUUTUuvAp208rfZ0l71G9U4tF4upbrH1j4KwIvULxpy/VJpbDWWWwC1gn4XHKcG1fpx8mZ66/K+raskG61MLy3EUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rjNjizM2G0T7+C7VEkNBPnrtlTTrAO5qxWvmKQ4fvJQ=; b=SEEiUbRrKnIAsTSAHdySvu4iyV1Zo9toaSYMs7OhmQgjtYQxQue0sWeUvfxg8HtRnfZ1pNjmetL4F7TNhsIUfCfv9st4fs1A5lFasH8/i9427Kzi+u7sh4CxbcLjeXwe8OfK4W1F9wg4Qy4o/cS71BpA2bvKI+KvEzVzeKl4r8MGHXI+bao8/pYlhiPJr/jnhfwrVWoHIpfohyPyelhC2ohKajpQBOUsmzMzjUR2K+ezf+WuiQLPB43u+0YbKsqriqiCGiCy8wEnaEbHRArEz0WYX/501K896bjUzf/fNcJKcF9eK/so6wAbJoMotvAy8LTFIjJ8XOfCIz0nVta/SQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rjNjizM2G0T7+C7VEkNBPnrtlTTrAO5qxWvmKQ4fvJQ=; b=1gMwS6kx+hejI6oEq0s0DYEOcGM0jqKC2m7VzftptVVLLq5136+ImXlKQaAQxcUf1y04FFlIyVlHvq8eflCBh44qDbQc7eBAw+2gUm6PZhwVl5iu+OW2Sb7Kw321OQA/Y04HoLODuSEPlLFWmEuglcg+eKjAjBQXREeOD7jLRnM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Ashish.Kalra@amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1692.namprd12.prod.outlook.com (2603:10b6:4:5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.18; Mon, 30 Mar 2020 06:21:30 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2856.019; Mon, 30 Mar 2020 06:21:30 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, rientjes@google.com, srutherford@google.com, luto@kernel.org, brijesh.singh@amd.com Subject: [PATCH v6 05/14] KVM: SVM: Add KVM_SEV_RECEIVE_UPDATE_DATA command Date: Mon, 30 Mar 2020 06:21:20 +0000 Message-Id: <871a1e89a4dff59f50d9c264c6d9a4cfd0eab50f.1585548051.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: DM5PR19CA0041.namprd19.prod.outlook.com (2603:10b6:3:9a::27) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by DM5PR19CA0041.namprd19.prod.outlook.com (2603:10b6:3:9a::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.19 via Frontend Transport; Mon, 30 Mar 2020 06:21:29 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ada39456-9f53-4927-e990-08d7d47295aa X-MS-TrafficTypeDiagnostic: DM5PR12MB1692:|DM5PR12MB1692: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-Forefront-PRVS: 0358535363 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(396003)(376002)(39860400002)(366004)(136003)(346002)(16526019)(186003)(26005)(5660300002)(6666004)(8936002)(6486002)(4326008)(2906002)(36756003)(7416002)(316002)(66946007)(66476007)(86362001)(66556008)(66574012)(8676002)(7696005)(81156014)(6916009)(2616005)(956004)(81166006)(52116002)(478600001)(136400200001);DIR:OUT;SFP:1101; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0Ytf1AN4EVFWGoQL1KMXF/41oQP7sdXk7PYPELcpXB3MCFlX1RWIt3NCO7Oo9yuxy2s7ThzD4y/cNHJob9qaHHMYp36uEoNK09Fz67Rqjt/4gkMe3O9gt3zIBof6XAXZbwdw04njv7FAY8sUIjd2FJ5wpv1fdp5EEVW1k7pgitxsjKFj2jbheZ+uC/bLjlRwui02M7RnUW1PlvlSO71dAfu5PXpU3lFx2fXQIsniJBapCw/unbcLu7opEA3vX1Pj1szwY4VDfaMK80NoUd+sYgEt/dTnGVfBIO3IKADG4yi/K1tWEofgFvq1MS+xrKwMUybXOEBZtc3kBd5qMBSGNnGM9pR1oKaW8TM8OiKJPjyH7c4JzBzxP4+FP6ajvu5cHohrQ5+3ZVTpIcOQj1L7sHu5vHRBmjBQabxEUvBRXnvVAxbZ3tOgMMbzEnFjqy6bT06HPKumhc7rvjDO6S8FOPJYqXO0X2OK5JWicqPRvzRIWKnYbDUtUEPeBUe1uFOv X-MS-Exchange-AntiSpam-MessageData: pK54jsF/Wx2mxk0CexoGwTONAi8Gs38eXSw1+JWYpSKE3gZMGAG27d3dBEDUftV9iY6YdNGpuHmGyl2uB2NB4zoNTChvxrG0IaCESVzuaaMrRsdWKPmU7dC41s8lm9DtcPpy+JchKm3qzTVuSqo1yg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ada39456-9f53-4927-e990-08d7d47295aa X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2020 06:21:30.0010 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UohcYNDw60ONTkQ1AI7S0ardICDvxagvIYFQihKJDGhGy4n/8hhQ4PhGvUCkizpENtxrrm5PBrWSUh+v5+IGxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1692 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Brijesh Singh The command is used for copying the incoming buffer into the SEV guest memory space. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 24 ++++++ arch/x86/kvm/svm.c | 79 +++++++++++++++++++ include/uapi/linux/kvm.h | 9 +++ 3 files changed, 112 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index ef1f1f3a5b40..554aa33a99cc 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -351,6 +351,30 @@ On success, the 'handle' field contains a new handle and on error, a negative va For more details, see SEV spec Section 6.12. +14. KVM_SEV_RECEIVE_UPDATE_DATA +---------------------------- + +The KVM_SEV_RECEIVE_UPDATE_DATA command can be used by the hypervisor to copy +the incoming buffers into the guest memory region with encryption context +created during the KVM_SEV_RECEIVE_START. + +Parameters (in): struct kvm_sev_receive_update_data + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_launch_receive_update_data { + __u64 hdr_uaddr; /* userspace address containing the packet header */ + __u32 hdr_len; + + __u64 guest_uaddr; /* the destination guest memory region */ + __u32 guest_len; + + __u64 trans_uaddr; /* the incoming buffer memory region */ + __u32 trans_len; + }; + References ========== diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 038b47685733..5fc5355536d7 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -7497,6 +7497,82 @@ static int sev_receive_start(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_receive_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct kvm_sev_receive_update_data params; + struct sev_data_receive_update_data *data; + void *hdr = NULL, *trans = NULL; + struct page **guest_page; + unsigned long n; + int ret, offset; + + if (!sev_guest(kvm)) + return -EINVAL; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_receive_update_data))) + return -EFAULT; + + if (!params.hdr_uaddr || !params.hdr_len || + !params.guest_uaddr || !params.guest_len || + !params.trans_uaddr || !params.trans_len) + return -EINVAL; + + /* Check if we are crossing the page boundary */ + offset = params.guest_uaddr & (PAGE_SIZE - 1); + if ((params.guest_len + offset > PAGE_SIZE)) + return -EINVAL; + + hdr = psp_copy_user_blob(params.hdr_uaddr, params.hdr_len); + if (IS_ERR(hdr)) + return PTR_ERR(hdr); + + trans = psp_copy_user_blob(params.trans_uaddr, params.trans_len); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + goto e_free_hdr; + } + + ret = -ENOMEM; + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + goto e_free_trans; + + data->hdr_address = __psp_pa(hdr); + data->hdr_len = params.hdr_len; + data->trans_address = __psp_pa(trans); + data->trans_len = params.trans_len; + + /* Pin guest memory */ + ret = -EFAULT; + guest_page = sev_pin_memory(kvm, params.guest_uaddr & PAGE_MASK, + PAGE_SIZE, &n, 0); + if (!guest_page) + goto e_free; + + /* The RECEIVE_UPDATE_DATA command requires C-bit to be always set. */ + data->guest_address = (page_to_pfn(guest_page[0]) << PAGE_SHIFT) + + offset; + data->guest_address |= sev_me_mask; + data->guest_len = params.guest_len; + data->handle = sev->handle; + + ret = sev_issue_cmd(kvm, SEV_CMD_RECEIVE_UPDATE_DATA, data, + &argp->error); + + sev_unpin_memory(kvm, guest_page, n); + +e_free: + kfree(data); +e_free_trans: + kfree(trans); +e_free_hdr: + kfree(hdr); + + return ret; +} + static int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -7553,6 +7629,9 @@ static int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_RECEIVE_START: r = sev_receive_start(kvm, &sev_cmd); break; + case KVM_SEV_RECEIVE_UPDATE_DATA: + r = sev_receive_update_data(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 74764b9db5fa..4e80c57a3182 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1588,6 +1588,15 @@ struct kvm_sev_receive_start { __u32 session_len; }; +struct kvm_sev_receive_update_data { + __u64 hdr_uaddr; + __u32 hdr_len; + __u64 guest_uaddr; + __u32 guest_len; + __u64 trans_uaddr; + __u32 trans_len; +}; + #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2) -- 2.17.1