From patchwork Tue May 5 21:14:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529917 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D2CB1392 for ; Tue, 5 May 2020 21:14:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29791206B8 for ; Tue, 5 May 2020 21:14:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="rjp5I1Tz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729312AbgEEVO4 (ORCPT ); Tue, 5 May 2020 17:14:56 -0400 Received: from mail-bn7nam10on2087.outbound.protection.outlook.com ([40.107.92.87]:6075 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728569AbgEEVOz (ORCPT ); Tue, 5 May 2020 17:14:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B9FpM6g/rRwk3sVqXhwRn7zdSMoumI1GWw2A/n6/O6ifSkbI+nmZxBNOaxt6aYXuhpcUVGWSK4EGw7OmGcKGOLmN2bCLTpwaSGEmDYEUfQKlfniwJ6WKYwBUFrgOzHMhvwrb7lnDiW+Vvvnvi/y9F8IyeAdscv5qxB7ziY9a4op/U6TpRzE77qBMbGsYOIbqnuYsI5yrOS4VtR2EE9aT6Kayw1+14kaxFYgd1uZP7ZiibbagYrEqJ6N+Ip4oQsbjGF7b7w7VCgepNwdEbMFB4DxCp32NRpSIZaUWibmJmx8PvOrwuqCtjFytKUEkhaIbf1PcC/ywd0ba7v3ieocpJA== 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=PDgfuQklGju4Gg05clXYxpilK8eFCAieFKUU9qqubCY=; b=gjRFnCR3xqVdg47wg9E4cvxZyDcL9asVJ1ATI077ivNdBtJLHkAahfVxoPa3BgAbTvSFVPFHvQgklCVoKaafLIf6SdfIarjOO9h7wAGimVGQEicMiHDgctDtx6+C8Qih2Et/9jFirCAwITTm+4Dd2rV9vbq38Q8OEhXAbn1gXsd5vUuT4f3KzKUlj8tt4EaTL81GkXMPZD6o69dksJGo1ZdN9211NJB7UItxoC7XOmx0yituEDIOTecPrxJ9qkVoaKdw3CYXtV8x5RO+3osK5zAXeASTfJwcKbubiUx0nKFZtrBUUxadrdYC1JYy7qqcFZsYftajD+IAO/4j/8hGaA== 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=PDgfuQklGju4Gg05clXYxpilK8eFCAieFKUU9qqubCY=; b=rjp5I1TzxdWXXhWmDlLDeJwVv+fxZYX+xaNrsn9/NV1pPHZkt3ybzcNznvHgA0QbjEwAYgij/sGpafjTin/3YOCBIGqJLiQM3CN25ZpYLwRnJa5yP8a/sW9v2oQW51DsYy7tQywsYmTt6Q3bAGTAVnRPV7qDzCfzIPldJhe9fvA= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:14:49 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:14:49 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 01/18] KVM: SVM: Add KVM_SEV SEND_START command Date: Tue, 5 May 2020 21:14:39 +0000 Message-Id: <58e0fb4c4d207028ec3b13cc3c20503224c95b86.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR16CA0024.namprd16.prod.outlook.com (2603:10b6:3:c0::34) 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 DM5PR16CA0024.namprd16.prod.outlook.com (2603:10b6:3:c0::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27 via Frontend Transport; Tue, 5 May 2020 21:14:48 +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: 01520af0-e10f-4e37-65c2-08d7f1395827 X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a5qzEWZXhMAHEa7UdKaM5lL/1aCLrVc8ntehAqrYWMX6jwzOShsO2+wTb+P/+df4ZpGApCdIwB0m/MN1wWvBC+LCRiEc6S6Zpvdbdj8q6CUHbc1ShgqTy3CrDle6xsjRPq14GgKK1XOwXZA9LayyrMInqtbHkE/y9C2N09hXQOGxZ/bwwxZ0KzBeAYcX0I8rv39CbcKd8S2p48LzrQs8YYOD/k8iPo3fM7p3FJmfIQUT0MogGfDd1vy7dkj9aMrpbXcXupAvmZfNyaADFaUnmmykg+46cAVO0mX/EnrQ9ndsSgSBRGezBHiFfKb0QxTGbXOD8OYtl0nPDSHrmqC7Kdr98B7M5nMB27evgsZmowzbQoLVuY5M2Ec89kncjUZ8NnmBYP8f0GJveyzWB7AehHhgsfS2TIzcifUp4QwicWHrgSNtQS0qNAcm3SsycfBP5IdiJoShaCbOVc+hL8zJxwwVwwEeJaHGfqhHpkqDu1RxtCv8hrYbKjwIC6tjiVyc1+TP+FPBov9yqHdBZ47rqZR4E5se3aGReNZafzs+KwpFKonP5s37ARr68ajGeKxi 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(66574013)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: uKY+IUi2QMDMTfdLkZAabxByr9M0k0AJpSScir1ZA82S7FwLYRsQd4gt2fHiFIIhiHuwZ2QvUVsqV9n8Y020PFXwotNUxrrowAAjjlLXtYX/bWG1Utpa2P6m7sj0ClhcJqaDXHN+kZkloxgQhkpf9D1Cz/NSeu+SZ9izx82uWHKYKyB5U8p7HTAXGfOFh1hS5jTjTN6ZWLQXLEUnETZhi/iWcWbyAGv+JoKYDIif8z9yS5HN4laSzYIYrL45omROHAR//J5wNc+iyMX0lPJabuumBuRtiep96McnjKQPU0zyqx4ZVSoYwXH9SnOWAUHflT5qa5YecBIGBDEhg210s9pUz2PFy1gGeuhih876cmfG4nFkhUWTi94Cog3M4ZSaGMrgjYV8oG2ijugLlP1JUTLNO1zjt0qBNqBKLpeIZnQeeltbkp1pfMqqY+SB4lahXHiewJD67WXXgKxMr93pBG6urZCxywYOz24hay6qb/7FTkhdWMFxpbQamoYkudY83GxZFkMhbfvEdVGpxp4o2UUzDnNyoUVVtjsk5KGwDNne4vF28RQ/pHrj99I4IjGCO4vN/5wBosmZHHlz2QWeTannuALz0xiUmf6FVMa82BzGJ4wmR7ST1EcdHF+6Vl87eGqly7hvaLK0yhRgHQUPUMm547YdNl/No1blPmP813+2VcqAwhql1p886MW83MtLriKdgdAlkXoTu+KdghzcegSKbpd6bdZ+gredLm1B9pVIZmjTejwYXaRzQemQsLONJsnczS29S8L3XJDixy038gCymFcc2m+bjJtSMaBZTT0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 01520af0-e10f-4e37-65c2-08d7f1395827 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:14:49.5169 (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: 2P10ktXDd9SRJANM5lX6ZVaDu0PsPjHHKpvmhCmdl58jk3nBx4ljkrRH1RlCgzPcwp5NY1UVx+WzWjg9e2aDnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used to create an outgoing SEV guest encryption context. 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 Reviewed-by: Steve Rutherford Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 27 ++++ arch/x86/kvm/svm/sev.c | 125 ++++++++++++++++++ include/linux/psp-sev.h | 8 +- include/uapi/linux/kvm.h | 12 ++ 4 files changed, 168 insertions(+), 4 deletions(-) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index c3129b9ba5cb..59cb59bd4675 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -263,6 +263,33 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +10. KVM_SEV_SEND_START +---------------------- + +The KVM_SEV_SEND_START command can be used by the hypervisor to create an +outgoing guest encryption context. + +Parameters (in): struct kvm_sev_send_start + +Returns: 0 on success, -negative on error + +:: + struct kvm_sev_send_start { + __u32 policy; /* guest policy */ + + __u64 pdh_cert_uaddr; /* platform Diffie-Hellman certificate */ + __u32 pdh_cert_len; + + __u64 plat_certs_uaddr; /* platform certificate chain */ + __u32 plat_certs_len; + + __u64 amd_certs_uaddr; /* AMD certificate */ + __u32 amd_certs_len; + + __u64 session_uaddr; /* Guest session information */ + __u32 session_len; + }; + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index cf912b4aaba8..5a15b43b4349 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -913,6 +913,128 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +/* Userspace wants to query session length. */ +static int +__sev_send_start_query_session_length(struct kvm *kvm, struct kvm_sev_cmd *argp, + struct kvm_sev_send_start *params) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_start *data; + int ret; + + data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT); + if (data == NULL) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_START, data, &argp->error); + + params->session_len = data->session_len; + if (copy_to_user((void __user *)(uintptr_t)argp->data, params, + sizeof(struct kvm_sev_send_start))) + ret = -EFAULT; + + kfree(data); + return ret; +} + +static int sev_send_start(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_start *data; + struct kvm_sev_send_start params; + void *amd_certs, *session_data; + void *pdh_cert, *plat_certs; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_send_start))) + return -EFAULT; + + /* if session_len is zero, userspace wants to query the session length */ + if (!params.session_len) + return __sev_send_start_query_session_length(kvm, argp, + ¶ms); + + /* some sanity checks */ + if (!params.pdh_cert_uaddr || !params.pdh_cert_len || + !params.session_uaddr || params.session_len > SEV_FW_BLOB_MAX_SIZE) + return -EINVAL; + + /* allocate the memory to hold the session data blob */ + session_data = kmalloc(params.session_len, GFP_KERNEL_ACCOUNT); + if (!session_data) + return -ENOMEM; + + /* copy the certificate blobs from userspace */ + pdh_cert = psp_copy_user_blob(params.pdh_cert_uaddr, + params.pdh_cert_len); + if (IS_ERR(pdh_cert)) { + ret = PTR_ERR(pdh_cert); + goto e_free_session; + } + + plat_certs = psp_copy_user_blob(params.plat_certs_uaddr, + params.plat_certs_len); + if (IS_ERR(plat_certs)) { + ret = PTR_ERR(plat_certs); + goto e_free_pdh; + } + + amd_certs = psp_copy_user_blob(params.amd_certs_uaddr, + params.amd_certs_len); + if (IS_ERR(amd_certs)) { + ret = PTR_ERR(amd_certs); + goto e_free_plat_cert; + } + + data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT); + if (data == NULL) { + ret = -ENOMEM; + goto e_free_amd_cert; + } + + /* populate the FW SEND_START field with system physical address */ + data->pdh_cert_address = __psp_pa(pdh_cert); + data->pdh_cert_len = params.pdh_cert_len; + data->plat_certs_address = __psp_pa(plat_certs); + data->plat_certs_len = params.plat_certs_len; + data->amd_certs_address = __psp_pa(amd_certs); + data->amd_certs_len = params.amd_certs_len; + data->session_address = __psp_pa(session_data); + data->session_len = params.session_len; + data->handle = sev->handle; + + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_START, data, &argp->error); + + if (!ret && copy_to_user((void __user *)(uintptr_t)params.session_uaddr, + session_data, params.session_len)) { + ret = -EFAULT; + goto e_free; + } + + params.policy = data->policy; + params.session_len = data->session_len; + if (copy_to_user((void __user *)(uintptr_t)argp->data, ¶ms, + sizeof(struct kvm_sev_send_start))) + ret = -EFAULT; + +e_free: + kfree(data); +e_free_amd_cert: + kfree(amd_certs); +e_free_plat_cert: + kfree(plat_certs); +e_free_pdh: + kfree(pdh_cert); +e_free_session: + kfree(session_data); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -957,6 +1079,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_LAUNCH_SECRET: r = sev_launch_secret(kvm, &sev_cmd); break; + case KVM_SEV_SEND_START: + r = sev_send_start(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 5167bf2bfc75..9f63b9d48b63 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -323,11 +323,11 @@ struct sev_data_send_start { u64 pdh_cert_address; /* In */ u32 pdh_cert_len; /* In */ u32 reserved1; - u64 plat_cert_address; /* In */ - u32 plat_cert_len; /* In */ + u64 plat_certs_address; /* In */ + u32 plat_certs_len; /* In */ u32 reserved2; - u64 amd_cert_address; /* In */ - u32 amd_cert_len; /* In */ + u64 amd_certs_address; /* In */ + u32 amd_certs_len; /* In */ u32 reserved3; u64 session_address; /* In */ u32 session_len; /* In/Out */ diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 428c7dde6b4b..8827d43e2684 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1598,6 +1598,18 @@ struct kvm_sev_dbg { __u32 len; }; +struct kvm_sev_send_start { + __u32 policy; + __u64 pdh_cert_uaddr; + __u32 pdh_cert_len; + __u64 plat_certs_uaddr; + __u32 plat_certs_len; + __u64 amd_certs_uaddr; + __u32 amd_certs_len; + __u64 session_uaddr; + __u32 session_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) From patchwork Tue May 5 21:14:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529919 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C6D6E1668 for ; Tue, 5 May 2020 21:15:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4DE620721 for ; Tue, 5 May 2020 21:15:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="GUX70gMr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729320AbgEEVPK (ORCPT ); Tue, 5 May 2020 17:15:10 -0400 Received: from mail-bn7nam10on2082.outbound.protection.outlook.com ([40.107.92.82]:60735 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728853AbgEEVPJ (ORCPT ); Tue, 5 May 2020 17:15:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EkfgcTxLVBkgdAakAJGKBkYDc2rg0oLZTsCRRttTaXe+p0nTZ8gE8HBfYoHktFu42aQLakIXhikZCdEeMPa8Ezrhy7Qn4yIdaH1tVQmusNEyy7cD6po8ZAadCCxqwtKDokORMyGI+2sQvjWqE/tg+GpoHb3eQ0bRsw+yAB9lJ1+Nztzz+pBnyQ1JqIarWumX/mpFZQ/FXxx28mG5rjzcZ0uGTLyyB4kkQHGwrrNbeKxXWmmAILxzHJ1dUIu9PIwMVF/+CSc/uOywlf/sRLRrRERA6BjAbPshlu1Q3d7/3z1mlI+hMimiaUR4zw7McBDMgZ7cpCTVp/UHegfgXP4Ovg== 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=n0Lwc78YKNJodnIhCkdHYVmKyqIWhzRZLe8A4sNSd7M=; b=khnbvxOqzYCmbkN8D5f8JMSORWC6XNx0HFlRsAjYv6lAhbAox0MWtpIOrabSM6emqcYngveax3k3e4r+BjPto7VfJjQp6LdkPfxQZNHxDd3CNHXFJ0qtvqlWMPL1STEVhVzwqbIL8Sbkynaetuz2l02xKJfwTt26aF9IM8og+UUF9/s6gldudkeqT37k9Nzs9ocl9uBCatc2RE2EBTV0gaYz1UHp1MUWglLrA0ZcXC+tu7is2nF0TeVdBejMTssexpzPtj+JGkYu7tskVTW6fQ7Bw5ZOXMyFryC5E4EG3cvek9lO9v9OPkC60mQLAUvBSpeHxEfM2btUq6Y7uihN5w== 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=n0Lwc78YKNJodnIhCkdHYVmKyqIWhzRZLe8A4sNSd7M=; b=GUX70gMrdTqI5d1H08MgBzgxNZCAAR28uuCCMePznRxK07ITYFoluCtGUYB3bW2rM9pCVE9mcO/wCVHyxuoMq5RIsA5gwzavbgwGj26suC5N1hFBBqseZtqNwErCDfOyhb7yR2K5ck+4GZcXGWsfUHWaGr9CvCOUkLaPpiXSKLQ= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:15:05 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:15:05 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 02/18] KVM: SVM: Add KVM_SEND_UPDATE_DATA command Date: Tue, 5 May 2020 21:14:54 +0000 Message-Id: <1f43054f423c956e5fdf9c0fbad0c18be4ea3935.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0063.namprd05.prod.outlook.com (2603:10b6:803:41::40) 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 SN4PR0501CA0063.namprd05.prod.outlook.com (2603:10b6:803:41::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.14 via Frontend Transport; Tue, 5 May 2020 21:15:03 +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: cd5207fa-e991-433e-9a1b-08d7f13961bd X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yroXkSH2opnEriw8Dur4MA/eD2HTV645IAEXzkrw+yu+e8ixbYzIi6l5x9OS0QMpl7ClpGgdGfOgXObIoD/0O1S80RddowYTPG+rvHU6e1gpI4WLSaOZ2IQjAHGRgJDcBq/mjbIVa3ixWNuzF3xI+7AgtoF6tBbIC6mkPlYQv3y45QS6x9FJtrdX6Pqa0Kuu2rN/uhfZvoCxoavDS36EZDv9R2xvVWLTLN3lhKsMldSCQauNFLMk7hghJXuxCPg6qiMCkGGyFs9xQq2QWmmBsDBPJCns7zhooaBqzZQZB29R9x9qbJ6OqsblQjrEjTJM4kRfgqbDASXEjOxU69OOurzgLTwdrQmeVW6+gaEBSmb19S+vUPo0TrTOuMwJ39HR66Pniax/4oFnvMwo+JsYLDFKzweDTq7H9JTjWhAhiBaYPS1k1s6fl4kFJun9QV3tGWb+XRlF9t6oECAIS5Yk/482G5pAKd+DtjbeI7pT1Dq4hXDOgReiadQFA8o0RfSrpLCsXpnZB6E9VEKWUpVM5s/raT7qRwe9a3fqfLV8wm3GCGOE/6zje8xLxKXNoRQ7 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(66574013)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: GIzo2DK4h3BTJ1+NDHb1fVKnl81DziBPDWkX42T/WN7wEFvTdYwWxXKwl1E+wTwkBChUwKhBYgcQBmB0CR85/yGa5p2c3X5k0Tv6EvHLxzlYQ6cR6p5yGWEnkItCuTFp5b22uNkj3CDqZ1uPGtjULar9V4SW+FzGLjtMNtbxJTTPmq3g2e+3nRg8rN8uKywedblAiMzghmhDP3tSIJVZo8AawjJ1rMPg7m4lbRj8ItY72Xiz7iLOf1IxzXvpxbXY8jlTe2nTK8cThRdYEGxZP44Fqw59OQ1s1osMtoFjOJbYQy21wt4LsJ2jlbDs4qnQhA+fyuzW+Row4iM56WWkK+/OpgyBNbqxYVL4R5K7tN/mZDcNgWWmC24+Csq3ZneUj29rmLmm8+O4SzuMEqFVSw7DX4ZgCSM97zbrU3fSyk2WrFePLM3Q+93wsZ+JiBcQyr3y0xYYA3IrvUbg6CDZ0g76B2ijN3AWgBOD5sclEEe0PHhchmEcVc4QSJoiJpRBrG3yiB/RAof4Ay3lcuFOu9yID+ixNpsMClWUXk0FXKKbiJL+tTpHgYyqOfRIhPWBUnUFLSOb+ruy3rjlNwY1T8APf62WuBg7fJV9kZHXZ3R14CjJt58iKqWRKPGOwT8OOAUfQa2A+9mSQsMG25ngV9cRZ5YeUDBBYP8x1SeUEPj2mZJ2GJAvjbf2eZ1FHw2JcVkB9Sc59IbjtnO4E+13r0JcKbbQy+cnUWiugfoccDfs2Nlqgw5Qm19u91HE0WXenjKQJ8gi0zwrdjzPWbmdkwvRCexwJbz9cwhvVN8dARY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd5207fa-e991-433e-9a1b-08d7f13961bd X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:15:05.4048 (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: LS6AV3+W/vBtlmZDCm9gLKvwQNEBn+0rbsyq92unyHgvSEgsKmdIgAFv0rLhZzUxnnJ0Ruk+EKROz3iCUvFYtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used for encrypting the guest memory region using the encryption context created with KVM_SEV_SEND_START. 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 Reviewed-by : Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Reviewed-by: Venu Busireddy --- .../virt/kvm/amd-memory-encryption.rst | 24 ++++ arch/x86/kvm/svm/sev.c | 135 +++++++++++++++++- include/uapi/linux/kvm.h | 9 ++ 3 files changed, 164 insertions(+), 4 deletions(-) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index 59cb59bd4675..d0dfa5b54e4f 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -290,6 +290,30 @@ Returns: 0 on success, -negative on error __u32 session_len; }; +11. KVM_SEV_SEND_UPDATE_DATA +---------------------------- + +The KVM_SEV_SEND_UPDATE_DATA command can be used by the hypervisor to encrypt the +outgoing guest memory region with the encryption context creating using +KVM_SEV_SEND_START. + +Parameters (in): struct kvm_sev_send_update_data + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_launch_send_update_data { + __u64 hdr_uaddr; /* userspace address containing the packet header */ + __u32 hdr_len; + + __u64 guest_uaddr; /* the source memory region to be encrypted */ + __u32 guest_len; + + __u64 trans_uaddr; /* the destition memory region */ + __u32 trans_len; + }; + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 5a15b43b4349..7031b660f64d 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -23,6 +23,7 @@ static DECLARE_RWSEM(sev_deactivate_lock); static DEFINE_MUTEX(sev_bitmap_lock); unsigned int max_sev_asid; static unsigned int min_sev_asid; +static unsigned long sev_me_mask; static unsigned long *sev_asid_bitmap; static unsigned long *sev_reclaim_asid_bitmap; #define __sme_page_pa(x) __sme_set(page_to_pfn(x) << PAGE_SHIFT) @@ -1035,6 +1036,123 @@ static int sev_send_start(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +/* Userspace wants to query either header or trans length. */ +static int +__sev_send_update_data_query_lengths(struct kvm *kvm, struct kvm_sev_cmd *argp, + struct kvm_sev_send_update_data *params) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_update_data *data; + int ret; + + data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT); + if (!data) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_UPDATE_DATA, data, &argp->error); + + params->hdr_len = data->hdr_len; + params->trans_len = data->trans_len; + + if (copy_to_user((void __user *)(uintptr_t)argp->data, params, + sizeof(struct kvm_sev_send_update_data))) + ret = -EFAULT; + + kfree(data); + return ret; +} + +static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_update_data *data; + struct kvm_sev_send_update_data params; + void *hdr, *trans_data; + struct page **guest_page; + unsigned long n; + int ret, offset; + + if (!sev_guest(kvm)) + return -ENOTTY; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_send_update_data))) + return -EFAULT; + + /* userspace wants to query either header or trans length */ + if (!params.trans_len || !params.hdr_len) + return __sev_send_update_data_query_lengths(kvm, argp, ¶ms); + + if (!params.trans_uaddr || !params.guest_uaddr || + !params.guest_len || !params.hdr_uaddr) + 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; + + /* Pin guest memory */ + guest_page = sev_pin_memory(kvm, params.guest_uaddr & PAGE_MASK, + PAGE_SIZE, &n, 0); + if (!guest_page) + return -EFAULT; + + /* allocate memory for header and transport buffer */ + ret = -ENOMEM; + hdr = kmalloc(params.hdr_len, GFP_KERNEL_ACCOUNT); + if (!hdr) + goto e_unpin; + + trans_data = kmalloc(params.trans_len, GFP_KERNEL_ACCOUNT); + if (!trans_data) + goto e_free_hdr; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + goto e_free_trans_data; + + data->hdr_address = __psp_pa(hdr); + data->hdr_len = params.hdr_len; + data->trans_address = __psp_pa(trans_data); + data->trans_len = params.trans_len; + + /* The SEND_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_SEND_UPDATE_DATA, data, &argp->error); + + if (ret) + goto e_free; + + /* copy transport buffer to user space */ + if (copy_to_user((void __user *)(uintptr_t)params.trans_uaddr, + trans_data, params.trans_len)) { + ret = -EFAULT; + goto e_free; + } + + /* Copy packet header to userspace. */ + ret = copy_to_user((void __user *)(uintptr_t)params.hdr_uaddr, hdr, + params.hdr_len); + +e_free: + kfree(data); +e_free_trans_data: + kfree(trans_data); +e_free_hdr: + kfree(hdr); +e_unpin: + sev_unpin_memory(kvm, guest_page, n); + + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1082,6 +1200,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_SEND_START: r = sev_send_start(kvm, &sev_cmd); break; + case KVM_SEV_SEND_UPDATE_DATA: + r = sev_send_update_data(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; @@ -1238,16 +1359,22 @@ void sev_vm_destroy(struct kvm *kvm) int __init sev_hardware_setup(void) { struct sev_user_data_status *status; + u32 eax, ebx; int rc; - /* Maximum number of encrypted guests supported simultaneously */ - max_sev_asid = cpuid_ecx(0x8000001F); + /* + * Query the memory encryption information. + * EBX: Bit 0:5 Pagetable bit position used to indicate encryption + * (aka Cbit). + * ECX: Maximum number of encrypted guests supported simultaneously. + * EDX: Minimum ASID value that should be used for SEV guest. + */ + cpuid(0x8000001f, &eax, &ebx, &max_sev_asid, &min_sev_asid); if (!svm_sev_enabled()) return 1; - /* Minimum ASID value that should be used for SEV guest */ - min_sev_asid = cpuid_edx(0x8000001F); + sev_me_mask = 1UL << (ebx & 0x3f); /* Initialize SEV ASID bitmaps */ sev_asid_bitmap = bitmap_zalloc(max_sev_asid, GFP_KERNEL); diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 8827d43e2684..7aaed8ee33cf 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1610,6 +1610,15 @@ struct kvm_sev_send_start { __u32 session_len; }; +struct kvm_sev_send_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) From patchwork Tue May 5 21:15:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529923 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1765F1668 for ; Tue, 5 May 2020 21:15:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDCA720752 for ; Tue, 5 May 2020 21:15:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="FieeBJVi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729342AbgEEVP0 (ORCPT ); Tue, 5 May 2020 17:15:26 -0400 Received: from mail-bn8nam12on2050.outbound.protection.outlook.com ([40.107.237.50]:25025 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728076AbgEEVPZ (ORCPT ); Tue, 5 May 2020 17:15:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AGPoFympT+uksyyj2qGAgPMLtXInZiWUjd3kfINyUxQYULkzlqasel9wf4IAWwhoyEHcvcSyQJyGEIlR3akJOY03y7XJ4/2S4M3w2he8BeODLU74W31ev3ItdtQuLK4Cz0lVEGgs0ajKvVtFhow17167HTmnvzdkr2WrrkFz7BDh28dIAhNMqBuDCr/xbBNxmdadNEi+ks55cSCberio0nSNXVmmw4cYrtrQ4kxH4+01uNVVEyQIQkJ+iRjvSp7/s4mpc5HQYAqaCCydv5XaKNDjK4sESfvgj1GmVGSglLsfEzDTMs30fLClrtOh0NzT6Y+L3wZgxpcfwXXLPGjHcA== 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=7lBY6/QnX5N877zCGUMQUdYeLw0dYdUpoeLZC46wsdU=; b=noVKW7W7aFGYT/EK2FxwYVgOiKF9k2LM193fGhg6U6+6vB1VgqkhsIui3RcB9ZLiEkWpK4KVj/y1fS0Pss/liNAqLQI19cwFirvXwl8wrTaXWtfmyFvdItQLKajisdC85+N0AfT9HOpMZa9bgnKgZn4gGqUwLHjO2w/jwvlkpWprxPboWM567v0mAf4CbeeSo4XQFV32CPj8Hi0kUB0mvbqtRZJkc6g2AYgm6Njf52fUjVt/2XbaXscl/lJgqMFAgXAkWjkYjzL88EWfBOXhNp7GmVoN6suNhl3nF2TBizFVzZ4vzxRWECWA8o/ChVF9nV1vkbh1TwYvg3ugp5lUuQ== 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=7lBY6/QnX5N877zCGUMQUdYeLw0dYdUpoeLZC46wsdU=; b=FieeBJViOPn8NNELmoE8Z7WqP0fsF9c77wksmzAZKOheY1+iX8JUIGcb0OmVIop/VyP04tmCg8EGGq+qtwMwFt9tMF69+tDsY6GL3kTGbsU2Y0jkvwUEflWNZLyrqxdUPpZhr2ic9zlr78eeTqy2AsEc31N+78il1f3SaqtkpMU= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:15:22 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:15:21 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 03/18] KVM: SVM: Add KVM_SEV_SEND_FINISH command Date: Tue, 5 May 2020 21:15:11 +0000 Message-Id: <3ad971e9977700140d9092259d5326caab986f1f.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0055.namprd02.prod.outlook.com (2603:10b6:803:20::17) 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 SN4PR0201CA0055.namprd02.prod.outlook.com (2603:10b6:803:20::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26 via Frontend Transport; Tue, 5 May 2020 21:15:20 +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: fa68eb36-42bd-4972-d958-08d7f1396b8c X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KRwjTPJi3DdB2p60wmXcYQMmVUbVgzWw4w/Pdxe25zLBXH8sievXAL+x/jAEDM5CFdPxaQcdTDHMb6JnFiWEhSoJD7Gmyq5pDp6FU0mfv0lixF/Apnv54aw7+pbVDxAJErKkZyxYj/06LtbtxBDdDP5w8lG/h2cgDz7mbJTB3bsr8neMZ6xriUIUTtYe+do0KYhiXCFYNFWN7dtVBIOSf6Jg60YQN98aSy9yDtmzYamQJfqHnOfU5BXIzCANhGRhozN9xy6WpX72B4yjLrFswH5vC7XHwqqMnf+To7O2mKz1ZFsCGY6LScDluHKqz47+KGqEJUChoFjGKT/sLhFMw/L+DwLHOZSjDl9X5XhSzEd/v6MILTEL0hvw05aPqUF/nRwRguj3+vmMdfEGLESJxURe401AHZJ0psicWz4ym2rnL60KhqiStA0nVxjDREDOsx3aPmN8c2xdvfXDg86a2dt3XMMDs02dgtalXYwlOqRxvpNBpyPSdjHZinN75SWu/q7mr/uBEuMvMwKUiEOW+Kq4ArMsFH8IgNHGOy4MLfwTzPn2uRLTJDB8EnGkZM75 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(66574013)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 4M0e0IcDAbHu7OLgI5IZLBaSE4SNEFwAeOFWobFw2vPdaOh490Fm6jXQfTOjn+uPTlJzkmoSAaPvt+VCEbGc/b1hmUPtyUAgYr9n7FqcZT8eRsc0moGzExl1MD28GT7ysvh4Ur4pCOJVuJP8HASdn4bnx4KC84S5PdyosvFGxKkFIW8qebZYqnQNLLpnzfANLguurfJLey//XYQMXS9klXhkvrNCX2wENVaUiK4Y4AV6X6VVDVqsXE9EZHB1bNN0jUiTACpFvH7MBg1++3Zd0EAnxjs7RMTxeFIpmpWdMP5xouxtzfIjBc6Ppjac8sDnbQsOAnZcDANGXfdfhj2JcuoPoJBmdVCWYh3VTbhKr7O7Q/RB1tjb81ZQsC3HVsBkmfzJDj0pHaz/t6z/ok0Yy+sGaq/BzeDq47046kWVl1oeNOM8Q1H9GG9YdATCRNYlfjXtqXqDvJJ+rgkdY9exD3Y/c1Z+T4iK2LjkOW4hoZEgT56hNl6Sorbl/fHBFJ9yH4XGSgc97Yc7BErwR6ddb6YTiAyBMxPCqcYd30Yv7zEq5BM3IWp98gYGsypaEAKFMMO0A5kHHPtBnB9nKWwNFPDbLpqavUMS8H6Uq+TzMVj4Q02gywL9uBwpaAjdA6Hu+OcPjdPBlGuEC6kJh9S2UkhXROQrK/3SbGf/uQPzS3cBHOlmS2iEAXFOJQ9jBbcgrnfuyrx5j9QvDRJtQ8qpTC/WCpf2Vyr2TdYX6/Ke8DL9OdAIskQ13N+YtBxSQXtFljgafbervKoJCp9VOgPKkr3q3yv7mz/1YzOcuNhtqCs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa68eb36-42bd-4972-d958-08d7f1396b8c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:15:21.8256 (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: 6kpiwRjgQumL0cFrworTVeUYa8Z1JmxDXmKYUhGqP93myx23JrlU8TSZ/eQPQl+RfTu2hs6S0wPGemqJ8idEzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used to finailize the encryption context created with KVM_SEV_SEND_START command. 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 Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Reviewed-by: Venu Busireddy --- .../virt/kvm/amd-memory-encryption.rst | 8 +++++++ arch/x86/kvm/svm/sev.c | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index d0dfa5b54e4f..93884ec8918e 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -314,6 +314,14 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +12. KVM_SEV_SEND_FINISH +------------------------ + +After completion of the migration flow, the KVM_SEV_SEND_FINISH command can be +issued by the hypervisor to delete the encryption context. + +Returns: 0 on success, -negative on error + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 7031b660f64d..4d3031c9fdcf 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1153,6 +1153,26 @@ static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_send_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_finish *data; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_FINISH, data, &argp->error); + + kfree(data); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1203,6 +1223,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_SEND_UPDATE_DATA: r = sev_send_update_data(kvm, &sev_cmd); break; + case KVM_SEV_SEND_FINISH: + r = sev_send_finish(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; From patchwork Tue May 5 21:15:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529925 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B43D31668 for ; Tue, 5 May 2020 21:15:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9061B206B8 for ; Tue, 5 May 2020 21:15:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="QKJVb7a7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729372AbgEEVP4 (ORCPT ); Tue, 5 May 2020 17:15:56 -0400 Received: from mail-bn7nam10on2049.outbound.protection.outlook.com ([40.107.92.49]:23149 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726593AbgEEVP4 (ORCPT ); Tue, 5 May 2020 17:15:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Do42VTnO6SJT+hb11q+b5Z9SKI1vh4BCXzmpkc5YexqF1TX/fCI5UB+/DF9+3cJ3CTkRVEyBsWHyZS5g0hxgTJV1QZFJcZUgSqoVBMkKC6c7iRLBhoGO8MjjqYmx7fJQH6qxSWZpF8Exy5tVlJWmVzy1d/bJQSx6R5aXhqqeOtrBOjtimXso0dZFWmY9vzHwc8aLEePnkflO3i27KK4JY+7THYtL/b2JC0kxtxJWpGguzS4f6WRUmMHUFFwp5/nXowWmKPeBJGvn+NOO2lyrw4MeiFeXaWLR5YXxGakGjN404mJYx8lnjt7WYlaTyfi0i+onhxFS72XcM30Ux/GebA== 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=vjJZixnJDfkhDsqg7fjk4XzPCgKAeabThStuu2/u8TQ=; b=mrA+zIceXlLhfzLYsTemkIebvEvcUEjnEjoiAFZMhAGbyfL/K4Y/Egpw1ZSpA2NgujqiNSnVe6P68DhGjm4O3gN9UbjGYmKWwWIUhzorDtbBYkqwGaGDAs/2grgLzejFJnONmNw3ANRe4A/g27UZB7X9TXlwVmQDBS9i/3dB1KxoGylPoQphPWKRHBJdmdU+clgX9v1fvsHTrnwEOMAfXIdrbBJC0tf6Ujivl/LWjmCJmsL12l+0V9jg1bo2RyyvdTO6DAaK50tLmX3P7IDt7gK1DGsU1X/TNoccOQNLaYHpphi1k0GeekZxx9GlQNWwnN1VyyrYjAZbLFYMXL5cXQ== 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=vjJZixnJDfkhDsqg7fjk4XzPCgKAeabThStuu2/u8TQ=; b=QKJVb7a7WBuht9pA35Dw0N6qHK6RO3mv3OEeMh5UkcJqaC5c0jk+DxzBWoX5AwFo+St7ugHjyc5cHJSIr/rKZHUPf5XSR/Mfcj+N+1pNc4NlJDBEkhaj4+mff1sPS95gdUdXa2FLh9+5b6oFexGL8Tso5Gnf18HGw2zt2o9sw/o= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:15:50 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:15:50 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 04/18] KVM: SVM: Add support for KVM_SEV_RECEIVE_START command Date: Tue, 5 May 2020 21:15:40 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0018.namprd11.prod.outlook.com (2603:10b6:806:6e::23) 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 SA9PR11CA0018.namprd11.prod.outlook.com (2603:10b6:806:6e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.27 via Frontend Transport; Tue, 5 May 2020 21:15:49 +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: a45d0979-fac7-49c4-fe0a-08d7f1397cbb X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2331; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ifnHq/jNjuPxG1XcFxsft7Ms9BDuiJeLcHWL1mU2EMroRwk0ExzgEXugFtKe92DrmQdgPmNRQvo90YYAF+j9knkFqZljtiGcQ4LZeGUHQjFMfFFNEPdx6JK9SWHNUjhhqntpBE2n9GjwBUqwhusm7D5IMloqtrIz8DW81u3m8I7Kybx4dHDBN00kThmVxmfU+OKDzuex+MGoz1Xn0MUbZjv+RyIGejiBD4JsKCmGj3atAB5PwcPLRDLISS5LdZ2k41+vn3DrKQoW18SCnAxVcPK0s0scvtEUzdCklyf/YZUIEEfUB6fWzQEWdOqGX9gtUuyxn+b4LBspH0ze3a4QhhbIzHhRnsqlMVoyWJ9o5p4ibPqMTxOR7soeMejhojeYqM6RWEj5e0WWtaPTkx3wiiXx6EW56OozMWieoOgG48eRCAOJG2mxtGnVVOtLpOf6X8Ulgfi0hK2SLvispFvAyAQxYQK+752QX0APXArQAmXXLuy2e+udwpwuLXtzvqhNtaZTT3DkaBFguoTWhBfjSnvo1wJ83n2q1h49uCqYswK1EagPaEXHCOSRLUbu6FTn 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(66574013)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: T4Ys+jKukfSH4ibltrFy2ejGOpCr0qP39co/YhPYJv/arue1wBIDNe5+GcsGvqSc1dY7dRPnLeUEhIpOdTqHnzeOnEknuUwdHB3oWIWgndqwcSVHgLrQow/7yqYqikObYUTxBHpkLQa/dojyiCB4/BdocqqWq4Mw7yfkJgva7bZI2d8c2rDckNqW42ygMLRj2EF8Qww33D3wt1/4ATkmcJSBUxQrh6xHpOI9dIYRFIXNAuyv8hgAZmG8RmN3uThlWVx7y6ua7PWaaMZCz0l18NDvnOnomQECSdJ1A7vW+kgtOtxRSNa1b02SJhFpTJcOPi5f+gSYhV5cLKrUMwpeS5hdKH3ymhwJH/XIsk8XFK//9zLuDEqN43X2Igssc6L28pGO6iTTC8seA6DBHnZyWcpyVYzg7uSUFydMXlPcS4mvbN6WbziyV97H9O+LADL54ZUdjEEPXARPkrHBJB9n2OzYlWBJFKGDepDMAzfj9tLeAMQGoBhdPU7VMuktZfKN9WOlDd8ed3SL/wEcdDZ+tZjPF/uBDRvW8CFaUjCwsDlJoBSCrvUPRUhfwjxh4DJMxL2m35k5pGpIdJbUzqIYf0hTvheoTtN/4fSx2vy0NzBd5enpLXdpeYnotaunTLEe3uEYEEGeSjQEs+WE1qFWA5LPgOoLjPYpKQb7TizoHypNon0JmEVwQg+u8TMqv/kNaSGcJ/2Z8hYrogNpQ+Q/OlrWofj1+LVOju29LlvasPM4Ls+hpQ2FA5J/BtAZLx977LUEHT9IK8yRNqFiI6KOz+Tm/Lfp5YXdhgQqVq5Qa+c= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a45d0979-fac7-49c4-fe0a-08d7f1397cbb X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:15:50.6608 (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: 4L6fpWPLc0fqhLWwh4JGLphlDw1P57wfZN8RbxC/k5eJDcbJG6V7plFAOWDE9Aq7bceoqCWrAIZIz3Oeo6bmtw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used to create the encryption context for an incoming SEV guest. The encryption context can be later used by the hypervisor to import the incoming data 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 Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Reviewed-by: Venu Busireddy --- .../virt/kvm/amd-memory-encryption.rst | 29 +++++++ arch/x86/kvm/svm/sev.c | 81 +++++++++++++++++++ include/uapi/linux/kvm.h | 9 +++ 3 files changed, 119 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index 93884ec8918e..337bf6a8a3ee 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -322,6 +322,35 @@ issued by the hypervisor to delete the encryption context. Returns: 0 on success, -negative on error +13. KVM_SEV_RECEIVE_START +------------------------ + +The KVM_SEV_RECEIVE_START command is used for creating the memory encryption +context for an incoming SEV guest. To create the encryption context, the user must +provide a guest policy, the platform public Diffie-Hellman (PDH) key and session +information. + +Parameters: struct kvm_sev_receive_start (in/out) + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_receive_start { + __u32 handle; /* if zero then firmware creates a new handle */ + __u32 policy; /* guest's policy */ + + __u64 pdh_uaddr; /* userspace address pointing to the PDH key */ + __u32 pdh_len; + + __u64 session_uaddr; /* userspace address which points to the guest session information */ + __u32 session_len; + }; + +On success, the 'handle' field contains a new handle and on error, a negative value. + +For more details, see SEV spec Section 6.12. + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 4d3031c9fdcf..b575aa8e27af 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1173,6 +1173,84 @@ static int sev_send_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_receive_start(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_receive_start *start; + struct kvm_sev_receive_start params; + int *error = &argp->error; + void *session_data; + void *pdh_data; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + /* Get parameter from the userspace */ + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_receive_start))) + return -EFAULT; + + /* some sanity checks */ + if (!params.pdh_uaddr || !params.pdh_len || + !params.session_uaddr || !params.session_len) + return -EINVAL; + + pdh_data = psp_copy_user_blob(params.pdh_uaddr, params.pdh_len); + if (IS_ERR(pdh_data)) + return PTR_ERR(pdh_data); + + session_data = psp_copy_user_blob(params.session_uaddr, + params.session_len); + if (IS_ERR(session_data)) { + ret = PTR_ERR(session_data); + goto e_free_pdh; + } + + ret = -ENOMEM; + start = kzalloc(sizeof(*start), GFP_KERNEL); + if (!start) + goto e_free_session; + + start->handle = params.handle; + start->policy = params.policy; + start->pdh_cert_address = __psp_pa(pdh_data); + start->pdh_cert_len = params.pdh_len; + start->session_address = __psp_pa(session_data); + start->session_len = params.session_len; + + /* create memory encryption context */ + ret = __sev_issue_cmd(argp->sev_fd, SEV_CMD_RECEIVE_START, start, + error); + if (ret) + goto e_free; + + /* Bind ASID to this guest */ + ret = sev_bind_asid(kvm, start->handle, error); + if (ret) + goto e_free; + + params.handle = start->handle; + if (copy_to_user((void __user *)(uintptr_t)argp->data, + ¶ms, sizeof(struct kvm_sev_receive_start))) { + ret = -EFAULT; + sev_unbind_asid(kvm, start->handle); + goto e_free; + } + + sev->handle = start->handle; + sev->fd = argp->sev_fd; + +e_free: + kfree(start); +e_free_session: + kfree(session_data); +e_free_pdh: + kfree(pdh_data); + + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1226,6 +1304,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_SEND_FINISH: r = sev_send_finish(kvm, &sev_cmd); break; + case KVM_SEV_RECEIVE_START: + r = sev_receive_start(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 7aaed8ee33cf..24ac57151d53 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1619,6 +1619,15 @@ struct kvm_sev_send_update_data { __u32 trans_len; }; +struct kvm_sev_receive_start { + __u32 handle; + __u32 policy; + __u64 pdh_uaddr; + __u32 pdh_len; + __u64 session_uaddr; + __u32 session_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) From patchwork Tue May 5 21:15:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529927 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AFC901392 for ; Tue, 5 May 2020 21:16:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DF6620661 for ; Tue, 5 May 2020 21:16:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="d/6a7tSt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729210AbgEEVQL (ORCPT ); Tue, 5 May 2020 17:16:11 -0400 Received: from mail-bn8nam12on2043.outbound.protection.outlook.com ([40.107.237.43]:18785 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728135AbgEEVQL (ORCPT ); Tue, 5 May 2020 17:16:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JHFAIa9US3xdkZu6Y02c4jfO0LXjlSx1f19EyGTQKhYbJknHdOR6yiwY73e8wWE724tsrkOYGJtSw98YqKN7cFcO8909meC2tjqn5fiNsisO43EVkhmq4Lf14muzB0dOdJ0sJMMBQjLSioHyfWASAKmCHpvGD2Ae1BAsuKavDP9jaJhn6wNJq8Cazg6DwBF6JYoSL7P0XfVfnO+GBahMQaGnhQ7sa3JALyeHQEmebMVA7dHjNCuwUsVllju2heFt1q2pDKe/8f7hL+y0CSOlfVEuP3pEt3P8bhU6sHtKPAWRf/56uMGJUOTgWrHqrXjzM0PLTbTboTDgBRWlvAN3+Q== 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=V/EKHUhHpQNT0DbA78p7H6D6PQBYjPxCDqiXy0V866g=; b=SLmFG6wa2LHLG+DH9kr7ip2goKjz944PIvgW4B0Xk9p6xzNi8KcYJCN/8WBSu0X47J9dVUwOZv9VBhmt+bMfE+CLsxaiVni+qK1oRosjWDVis0j0rCimvRKvatLG/IcwsPbhVVhhwd7hTCKdjW8FzvIBOz7QRuoDGBUE1899msSM28paIzVhIrSl7o+lnVeOms10Wlw3kgr80grRrnEsVaqUo6X+K37D1yc2epnUfIxDjxReijYfEWfrPvCld/dMuKk+ZwbauFMwMKJjmMO3HNu/GkkisDAkHX5YuyKx/8R78ed0wkbZDGx/z/t3UVSf9VFSBetQHlfdZFgl8G8CFw== 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=V/EKHUhHpQNT0DbA78p7H6D6PQBYjPxCDqiXy0V866g=; b=d/6a7tStcj/W2p3P6rDst2zvry/gexTp+VFyeAyg7/r7MLxbtkVu3j18AxZQaXuArXpu6tzHG/FMxcVC4qsEpGu0wsRj+phv3X6rNAqmWK+v1x9GLjNmtHT/vR8K7uzRDuBD1HhQnY57T7VTZJD+Wcud8GIt+MJLgUFQ3EUmrzs= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:16:08 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:16:08 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 05/18] KVM: SVM: Add KVM_SEV_RECEIVE_UPDATE_DATA command Date: Tue, 5 May 2020 21:15:59 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0012.namprd20.prod.outlook.com (2603:10b6:4:16::22) 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 DM5PR2001CA0012.namprd20.prod.outlook.com (2603:10b6:4:16::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26 via Frontend Transport; Tue, 5 May 2020 21:16:07 +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: 72774dc4-3a00-4d49-89bc-08d7f139872b X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kL/AVCtNoxdxkAXlZEkVD6uByIPFgnsjXbXQqh6fJN+h5kmoynQY0pfT4Ge6WCeVUXLnUyZJq1k3KndPb+E4vWoPNqBcyaSNCb2MWyyuFLRf1C+L/PoJZND96WLED+FLh7qsKoBMeXWDi5RqQ10YJZuSjF8H20sbeAMyKHitHepvqauzwwsxTLErmFAI5yUiwgfZY0REXH1kn1Kphz6BX+Vf+2jdlqhS3h98KnSMEAFcwE+IAThnr984VQzx9LfFrhAH/Lgyj8m3PmUz9Y6hf1fp0wHFAgqFjhyVIOCxnGejGH2ecBwJgHXWg6GU5AwZi1gVzKApaz1Wg4KLKdCh9yB7zOmg44vQzcFReNvjltLeb+gVd1FZhjkea3BPoAIxgGvTTmWu3hDHsFzovp3E9hjaYe5+o+klhPkfOgjrAxP5ocI07jq1ZvpFVUg7yFQ7OGDxYU3PZ1FwTFFrO0yxoO+MaBTNOM/0uhlW58f4cvaOKrALUJ0ENy9Xr8pamSNI/4LZLZl9xAyS28Ov9OJqjHwMM4ootm8XyKEePFPHGoJ9K61Ntv7HnvxHkTtStcQh 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(66574013)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: rDcNK8BB0PvoJCY68iZQQMNu1Gq+dyn/W0tVpXqc9kBp7qglFr4G/82iCkw95iLS5fm4BbVHdCYoldHPttNNM6MK/NqVCenEu1DRGXdWVasGBCIQtiaCRBGBDf5hNrDSb5R4OLDppc1pmW+cCmXck3FVlxg0UL6C+4WJblIcBC5emHDeXeMNWrJlzo35fi3B1pJxuhIsHjTOfnR2zwBmNWg9iO7kAJjoFztSk3WxAO2dBKsYTtW7K741afb91RosWtJhvTiysA0BAN0lGAl/TWoYC2CQpI84gV3E18cmWuUO+i10Kibi8xbCMhkA7hyBq+BcE06xmtE7MqrJE1/I3dcCiGOuLmDWt5zNlOZf6mR4eEGy7kYxeScfifZ6Du9zKFNE9nZ6B8+Dhf4PPFyZJLHlrd0YpUwrne3FZ0eHOR1hsxqYY8K2tp47TiWqDnjB2DX/YAntutBL+R9EtH0YtFDws9t5o3qkI2GeIHQt4potPQrSRSPUl0wRbAGr8tEjgbrAOVigt5WsI4hRGB1PHFBDuI7sniZxF5Qm9G9yyDkmlJBkmbRdIi2ZJNO9/hNIwPk4rxE5eyh008QlqaXB/2VXGYH3a05vUyjDUeJMrnDe9HM6bqMeZM8XjjiwXJPBJ9lGV7mtHcbL1SE7EBIk8qHR51kTVExJ404WL7OUqg3XEHykvano4vz4fXlo7DWOCaYHCfz8qWQL45G3ODtOKFAQf6nDjf0fkJvVFtsvY0Ynf1BDeNwYLsfFcKs7lBswLnXrEMAwqf50ilYDiEh5rB3qig7YZSPPQ5WYdrDDong= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72774dc4-3a00-4d49-89bc-08d7f139872b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:16:08.1630 (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: j/nAyh3Zd2ibsT+F8Dyaux8t4A0bwY3Xt07rB8JZ640etdnru5lgq4awjbxx5kWra4ElB/vFxcMPC85xNMCpbw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@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 Reviewed-by: Venu Busireddy Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 24 ++++++ arch/x86/kvm/svm/sev.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 337bf6a8a3ee..04333ec1b001 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/sev.c b/arch/x86/kvm/svm/sev.c index b575aa8e27af..165a612f317a 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1251,6 +1251,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; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1307,6 +1383,9 @@ 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 24ac57151d53..0fe1d206d750 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1628,6 +1628,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) From patchwork Tue May 5 21:16:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529929 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51BAF1668 for ; Tue, 5 May 2020 21:16:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34DEB20757 for ; Tue, 5 May 2020 21:16:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="BLcSK0hg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729406AbgEEVQn (ORCPT ); Tue, 5 May 2020 17:16:43 -0400 Received: from mail-bn8nam12on2048.outbound.protection.outlook.com ([40.107.237.48]:6110 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728642AbgEEVQn (ORCPT ); Tue, 5 May 2020 17:16:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gscxq+tK8PSPykGMVY9fIU1JSFb2HGIZ1MEexLUwMMks1hfXYtH/tWjw14hWLyB4gagVU7rOCupk+9dXZfvDxXIKkAOf0bS1wjWplD3xSyxCkhMmGmbDJhbqj8ZIqutNxu3aAHmL7vleohECBRqtZZBAarwpG8MVqSXs2PpqQQkWmS+5bEpMRuGAS+3AoDjY2PaV5rnOm4GlesLy+ahRZK4sJ8IygdnjX/u0EnrS+EqHjxg0W3Cy+WxQxJ+EzD2UZgLBCjTCp0tQszzJHouPoitbSMtYMtH5WdjWeT/XHEHRci7KlF2X8F6pCNpLnfrNFRYlbEUhRbUbgFW/s9rIlg== 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=shPMzEfRG/xoJ/stMxk05l3wKT5pzEhKGN8GTUgE4P0=; b=gPXJdHm+8OYcEWuvj6eMKjlBX99uv4AQsOr2djUn2ud6PLjiCyFtfQfJjAUITlQ9bsQp5t6E1F2K4MFyBikUpXM5sip5pZyY1vyuVMwvoEY82Ed7hrHnn2bfRQTUnVAGcSOYNJCrgJ0usESRYDTnlrSmp0TzjB4NWdYwroVpeeNjG6ULh0pfW44McaOE/M30nWG+pAwtVo8+8mj3kyJkMVvYgmRGn+sx68sDgXUy+/PDFc9iEAr8Y9rN8XWNL5mRvm2MTTZwYm+/e/2pqikKmH6Dwrp3HdV3dbMkqC9dr1K6Q19GM+frcw/grO561LWyWrlisWjkZ0vQRMQXO9dYcQ== 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=shPMzEfRG/xoJ/stMxk05l3wKT5pzEhKGN8GTUgE4P0=; b=BLcSK0hg1FxwtlHf2tD9zUjUrRUOwQ52/ts/DgRcmebJu72goxRkYMTyEqQRYiC9zzQjucSb55BQ430y6xjIAsDZQZLE+WVKI/gli8zMdi9Q9AMM62ns4HB01v07HHqlCwZXsBCh6mk4JCxQ4x6x7lS7aCqETWn1YBS9K6uvK1w= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:16:39 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:16:39 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 06/18] KVM: SVM: Add KVM_SEV_RECEIVE_FINISH command Date: Tue, 5 May 2020 21:16:29 +0000 Message-Id: <9df744ad5d7f8056362b04f34198d7fdaeb8db72.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR1401CA0006.namprd14.prod.outlook.com (2603:10b6:4:4a::16) 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 DM5PR1401CA0006.namprd14.prod.outlook.com (2603:10b6:4:4a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27 via Frontend Transport; Tue, 5 May 2020 21:16:38 +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: 5b249a6e-558c-4148-904a-08d7f13999af X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: udDPhcebMabbmAILKfH5wLtWuXaTymZU0tWRJXDnOBSnVFstrhmTB8pJxkeLiFfZ1Ne1o9HAwKiOhALn3kyHFAhqnPH5HEG2YMClpVQQqZSSvbrxajVlzo76CYjtE3UiRKlm0d6IZYng/DGp9eGuvcZiLDAAI0rwgfmuodiwO60+sUDZkR+0Ra7CIPba20t5S6S+f62cXWaZ+EmmIb8lN/i5HV17iYwchOssBFipLUvWHsACj88hJE3GYPBd/v1bgZu2Oj1EYA5hgdZq5fr26NK5R2+IHv+0M38sRTsOA6X+Y4+BulIoPKTCYMadTZcBQb/+9aUCx8GK9gkWr4CrEk0sgCEAjbYjP8xdIcc+cdH9A4pJkmA4FE/YqK4s4n1tHxU2UdQtjauU7o89UOs9P0pHHsADdMAufqkQymtuk/hqPQXHCL/6AIsrwPv5UdVC8CdWOeaTaVBDCt8NWil5XCIZfYG0O0v6y+2PwuxzSatAqcaQvwfJBcBHJBgwaYLzYcgti+F92QVHztu8FLdpBY6XA1xYCCJR6qA7+AOwExp2hkq763bF8jEm5QCv9CAz 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:(4636009)(366004)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(6486002)(498600001)(2906002)(5660300002)(6666004)(2616005)(66574013)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8TVtXgV0r5crcKzUlhvEBOE9c1YGfwT2EkApZEcT4pMaZqSQY+IchAIFQcbGLyy21rlHXQLwgUrYbXK6Yv4pzs/gneLt1POeet8gohh4YyFVKrvHVkctLMTHW231XO5zRcCEWsCHoIXSGxXISWmTXU/hHD9G6Wnz0fsM5slBnSvpPeFBtGPOncaWT+ikcDnn0Ras55Ic3VW6viUBc52PqpFB/aRnoJccsdC4W2HIxvDXfyhFrXEBRbikwAzuG7zgLumI6lZXM1hC2EII+xXyOtfxdBanvyuK4pxO4OkLmFsGPsnidnu2pVH0EQMxm4a03nHYWa9xifEtBPMws4Lsu5doD6nn7RpXFuNxcorUvvUe9LDQYVOPmp3fiQ+YGFxLhUrXuOPgVqoHSltAl5xfahrV7yjHf+q8w40lvFkfVWv26pNdDjnzVAo0/u/f9qH2Cb/NZ+kYarRD6wfPdW47Ax3gmJMRa7GTkQ9O2Huu5r2iJTjOfy+oELJngPqOvitA5XYwnHaYz3FRxEPc/ZxhmQ/AQRABByKjA9xDFHkpM/iq7QKL4+8XpggFRaAEGzpc4kZ6D6s4LLwfaXBOySlvuVwHm7pLMOvH1hI6X5shB0E0CfHJiSw1QrL3UrW8NxfJzBT5YLU8Z3+RqkXICLLmfgge0NZhNPLLZNqHFhsW3lMeu9/t+axJ7TqauMKe4iLVx8oETllZgI25d1SDKpf1IQIhx7IgO5ameUP37drsp8TiWnQaYBh46OYX+HvM4UZPgDyy5YB2Wcl8as8uwiZ+J36bbNOhcGSZc1jtlL0iGgs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b249a6e-558c-4148-904a-08d7f13999af X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:16:39.2533 (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: 5REqI6Q528azz3tqBUEgURmvPEG/946pFuxVDQc7khJtgC61ucLknojg9tsGKKDNB8tWmebSh4up4R8Zpnzeww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command finalize the guest receiving process and make the SEV guest ready for the execution. 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 Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 8 +++++++ arch/x86/kvm/svm/sev.c | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index 04333ec1b001..de5a00d86506 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -375,6 +375,14 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +15. KVM_SEV_RECEIVE_FINISH +------------------------ + +After completion of the migration flow, the KVM_SEV_RECEIVE_FINISH command can be +issued by the hypervisor to make the guest ready for execution. + +Returns: 0 on success, -negative on error + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 165a612f317a..698704defbcd 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1327,6 +1327,26 @@ static int sev_receive_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_receive_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_receive_finish *data; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_RECEIVE_FINISH, data, &argp->error); + + kfree(data); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1386,6 +1406,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_RECEIVE_UPDATE_DATA: r = sev_receive_update_data(kvm, &sev_cmd); break; + case KVM_SEV_RECEIVE_FINISH: + r = sev_receive_finish(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; From patchwork Tue May 5 21:16:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529931 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECFBC1668 for ; Tue, 5 May 2020 21:17:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFFA320721 for ; Tue, 5 May 2020 21:17:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="KIIbsHZF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729274AbgEEVQ6 (ORCPT ); Tue, 5 May 2020 17:16:58 -0400 Received: from mail-dm6nam12on2065.outbound.protection.outlook.com ([40.107.243.65]:43774 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728569AbgEEVQ6 (ORCPT ); Tue, 5 May 2020 17:16:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CR0liGIWRCSPN5+q0OZSR6lau9JCxcSEWGLU8DPzPf5HW9Je99HsGTmKt1JWoPnUgVYu0eMHuAa1X2yFR5S/hONyA6gSmgiR2AI1joHHl5oryC6tC1KmWzmdN/pOCZFmsz8okcnjU0zslWwC5gl9rhKaoxyf9w48ne634Saaze5S/a/8GeMZk12X6rVCRktnx+drk2f+phbvCwzztzlDfIrpgzGD+EnxnAK92wKjc1OZjQevj8r0/CqY6SttUHVGiA4qfk5xx8zQizfKN7wfWoo/K9cFgHGhxSqUXUUrao+ax6ZKUtd7WaftolKez0W7ifQ6ywhe8i85nIatpYUT5g== 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=kg80pzkz3epoBCgvmHD4sEajd/FQGSuBjGWFCCBN+lM=; b=NPJPbWuTlcngTvQXTSvXPWg2gCyvXyOnfyFe7Ck23jne6A5Kh0BAe+n1wxRVgQH9R9o+I5DVIScrpBdLDYBJCngrmc2xFr+WYxWsVlrn9eMVK6f38y9Xe+wUanoAYGwZH9ue7TPhwbf2mH7VZ+oSYj3ukJBP4mILuB+cGrv47a5IaeH8cLsK9yE3D7+KZ+drODZXnIyFJ//ITDXp0q0bRiRtcBcaHhZjJOfQIljfJPh/e7mnCQKAKFRKUG1M1TixQ4BAkiNSx1bTPne3hm36r0vg21XKK1sDscZJ/y9St331zTFlkKkj5E/z5JYYnY0A/9JC8bTg9zEe+Y5Yu0DbLA== 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=kg80pzkz3epoBCgvmHD4sEajd/FQGSuBjGWFCCBN+lM=; b=KIIbsHZFbEPEOfK/kDTkKF3qW/U6yj5MwaOAC+rkDNCLxZkbTwjyU7R+X3gMYBjIVQoevvClD2NEYDGagvw7HEeaV1XWr3HdoYS8E0ugaYWKRroy4DV1f0NZCIE531HUBiWoASBomxsYy6NPlG7JYWT7WHW3UgwJaiw8Lj41N1E= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:16:55 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:16:55 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 07/18] KVM: x86: Add AMD SEV specific Hypercall3 Date: Tue, 5 May 2020 21:16:45 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR22CA0008.namprd22.prod.outlook.com (2603:10b6:3:101::18) 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 DM5PR22CA0008.namprd22.prod.outlook.com (2603:10b6:3:101::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27 via Frontend Transport; Tue, 5 May 2020 21:16:54 +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: 4f43e34f-4027-4235-ed46-08d7f139a318 X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BgnMc5k5A/hGat7oq3Mj1xmCtGFjJeqcKJCq41u0fNT5CTaud/A38kPBiCISqnBt96QvjMH0qlUs1P6R4AeaBKFN0ZkgqQSpTcBbjLDn58ooL+22+slVAa08um+Hs+lHw0qZHTqk9nggb91Dn1BicPPg7lfpl0AJJFQf34/KC3Dcoj+fjQuByJEDtrIIeKoByP1znJrZ9aguAUneaezJYMODPmnr8FbXvxT8t6T52ltaC5l25IUZcdaFQBdeQrFM4iOMIa8NYGETPmljpA/1N7crccpN+HQHfPsOqzEj5bjpEeDrlJdQnrWNfSsk2dDPedM6fcwLEk36AD9Gij23jw6GiabS0sjKWPAolZSKIPS9rZnaxeuvoNIB9j2bSpEAbg/32lOjfR8N1hjDjmXCdwAqJiZcDFCl4O+DDLI0pJcunYi/1Jd1jE/qDuu3YZqt5pzEPzt7cY2zsdWHYuspzAJuXXGBW2wavFmSRN1+akws4GHqT5XMPZiwO/iZKDVsyrvxS53RVsUUUQp2wSGsWIZVIVK8lqEKK0jE7uSsV/v+YvIrpdlqjuu/z8Wj5gKe 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: xgN2zlBJCDAvUg5C9vo4wD4QFH6rkqOoIMbS2k+lww5/mDfXTXF7m/6Uz3Kxw2kEMKNVq+njotNDxDb5gEXWG2bZcREisv3msRVmoK7lbm3FnuDkBG9j+reTC6oAY7pcywfi6sgdtyHv6ajLxAM6loIBCGZWOvNYcQ2xXXnu3Jzj87E61tExm+KcGLo3vsiQ76gQ5HJ2LzzFiizDLtHWnCEk+wwH02pM4U9+VGVDBlORilLA6Ws7tvTn8uH6tJYOVgAmIcuLhh/ER+D4UQPvIylcHrVGKpOn7NnQCRRhaM8yKIA9n3bOsA1YDoYceTa2QGrLV38Qhp6gdTk50J8tPtpy+pg5GbWeT5qpF3FkfA7kGFIfAgkA1/qc9JB0RELAKXid6OVeYrBUddqrcE89CZs/dFkZQ0dO9ZklVDHJ4gdVmRgaHSm5URY2BQ1GD6C/A371hut/L6iy/E4EprLCZcOdm99Hx9jNMbgqGFcOPx9woRmbItumW6K7AphmCkrp1BJzSzIhs6TxP95JUE1syWV5hXIpKdNTcXMNrF5l5O8W3um1M/kCBzEsvVJHrWLbT788AJwTmtxt6qY1KaGqaA/FPVtBU8cqTcBND0ysEzB6LNYEhedHc+/zzkXA9G3vpDWBDXX1XOvcXqS9n0oaTtQS9F3Up7GNMR0jbPLv36MqKGPL9xsWipXhxzrSR34CCmMM9Hj4hNauGZke9IkQ7fTO+ETYb8IZl50HPfqRtpbr0/bYaEKnPddRvYokH+PEd0Q0W0xa0dRG9N6NpM96/zaO4JfBO2Thqsa4m3bh/ZU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f43e34f-4027-4235-ed46-08d7f139a318 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:16:55.0493 (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: tw6h/dm3CvHUXgHpnp8WINeZEuSslUku3JgOIFOBoqvQ3eqJoJYaKCSsu6usoaHHkwbGM+tKFnoI2Hy/7dJA2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh KVM hypercall framework relies on alternative framework to patch the VMCALL -> VMMCALL on AMD platform. If a hypercall is made before apply_alternative() is called then it defaults to VMCALL. The approach works fine on non SEV guest. A VMCALL would causes #UD, and hypervisor will be able to decode the instruction and do the right things. But when SEV is active, guest memory is encrypted with guest key and hypervisor will not be able to decode the instruction bytes. Add SEV specific hypercall3, it unconditionally uses VMMCALL. The hypercall will be used by the SEV guest to notify encrypted pages to the hypervisor. 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 Reviewed-by: Steve Rutherford Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- arch/x86/include/asm/kvm_para.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h index 9b4df6eaa11a..6c09255633a4 100644 --- a/arch/x86/include/asm/kvm_para.h +++ b/arch/x86/include/asm/kvm_para.h @@ -84,6 +84,18 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, return ret; } +static inline long kvm_sev_hypercall3(unsigned int nr, unsigned long p1, + unsigned long p2, unsigned long p3) +{ + long ret; + + asm volatile("vmmcall" + : "=a"(ret) + : "a"(nr), "b"(p1), "c"(p2), "d"(p3) + : "memory"); + return ret; +} + #ifdef CONFIG_KVM_GUEST bool kvm_para_available(void); unsigned int kvm_arch_para_features(void); From patchwork Tue May 5 21:17:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529935 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9B4A1392 for ; Tue, 5 May 2020 21:17:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A43892075E for ; Tue, 5 May 2020 21:17:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="Kd1QauSb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729443AbgEEVRg (ORCPT ); Tue, 5 May 2020 17:17:36 -0400 Received: from mail-dm6nam12on2069.outbound.protection.outlook.com ([40.107.243.69]:22337 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729265AbgEEVRf (ORCPT ); Tue, 5 May 2020 17:17:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VVjSIfnipxmUNOqm+WTkByWGOvunEG4mSKB8vg50ccR7gvvEK5WXr2l+oPJdZos8f9Co23RBMHAWohM2xmX7iiy3aA9NOs58fNzCu3XTvhGHQovhkgtEBgx1IvYu3uGmzJbGEyMvGpW3uT1he0YDmmIRTMdPiO2geKo6GVuzO4XMNbZFutaDw+2ts1COwhd1BuF9LpbnZ1XXvPllAjhbuooagjKHdCGO/cd+7QV3fBxGHSiuKgI7kTRzzmeYH08YYvUtjX48IHjyp1w76Mstp4iPG/moxDgEsNkdNRyzZi08r55I3M7GOCEIfV5KqVdGn37xn2VnCnCoXlI80sFcLw== 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=MbqCDveUBPc1zlWDRF+76ey8lhRbWeu3iyq7/E93A8s=; b=XKegZ7Ia1iYOGQXqi6eRYQnOIC7QYPonuyArjQQY/93ZRvRFWC4jrU30q02LNIwmg5yQRR1+J+e35++Trm6NeTvKwrrRzugOihke2fYIgOa+WbrhOWXWkqY6TDkdKen1LLU3va0446r/P8i+fDYSfZuO34kmUghAIBibDwBds4kncbfMxeFYNlpd+NyjlOjfXZT8CxSb3r8EICoD2lr7fvLGZ/24Ymw1ndtwwMxZlLYl3JGhXH1daOVUDq+a35c02J9B+QwezD+19suHla9F4F42AQmqvut9FchrberNXalmr6vSFZUyFm6vrH2obin8kUapDj3zCTwEwAhMidfJIg== 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=MbqCDveUBPc1zlWDRF+76ey8lhRbWeu3iyq7/E93A8s=; b=Kd1QauSb0I+6w2uO0td7H9Zd5YXCA76XHHCwfMahuuI/C8RjO3Ytfk/enRYmczSYx5UikRpTlxB2slU1oukdEEsydii1NEYCme7h9mxDf3BR3UFmZeTHvAKUVR0UI//Mzok24YmsoJSAOAkSEwU0sX6qdTbh357VVZPSDsYgWXM= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:17:28 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:17:28 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 08/18] KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall Date: Tue, 5 May 2020 21:17:19 +0000 Message-Id: <12a50d857773f74f25555e0985480fb565ec8438.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR18CA0052.namprd18.prod.outlook.com (2603:10b6:3:22::14) 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 DM5PR18CA0052.namprd18.prod.outlook.com (2603:10b6:3:22::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26 via Frontend Transport; Tue, 5 May 2020 21:17:27 +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: 95b10c00-2e29-4035-49de-08d7f139b70d X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:323; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lWYODXPbThbfeBGxj0DyEb8bu6tGv9zgSdj/A3gguOLvFfK/M6dTTyi+PzOW8Sh32/6SFFQojXXuywG5GIuTSmwwK0lazOpZVV3h9yzeaQ8+YDl944Ge4lslfgeUaGaOIFMOrYngHa0cPgwUZDEU5dWia0jO3Jc9gyuCQHA3y8lkdJ63XRrfKov0SfbZnpRo1OwMgO2o92f1jThZ4rGgbqZPT2TOADbNJGZiz4mGZ7Zzrp2qBGI6yyKzvKpfG4WbdxwEoE4egpTs9nVcehByxfXkknmbVkASqi9k8iVrz1OwbizsZez5Xa79fIG9KCL/z94tl+NzsHPW/r/x3VVcAsiRYhfNEz3rLWuOfL6zduIokvImbjbbOIS+l6h3EgsEXC9DaexE1jCdIYxCdjmCvw4KdEXY6IVTHHPLA5DI2KePeZx9YFcfRCpdJODR6kEdUP0qjz0C7F4k5LbErYZAe5h0yK77gPQOK4w51xLb/0A4LCbibP8rndKtA9LMPhj852PT2is/L3arg/5fUfUs1TYlGIX8OXs9Iv/0uXNwDmINkg+eAYCnI02rrWWJi0xd 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(66574013)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: W0JGkS/wT/97e/wABpdq/1tfpYYkEmzXDKe3mVsVo7glv8uxHQ5dH7wH5+UPThgvAwlAX94jhvWO8oFR2L+NERPZllZtVxQGHCeFlB7/5e7MiBLeZE4R3HLrght51csm8MDVsyASlMQt6TdhfvtBVov+RTzOaHfD56lQ6nreX5vDblmHGjoKF27eug+n6x/lJr54mduaboMlteqZhikmADRji9lnrCAaIpV15zYrrI/HHpoJ+IDjAUzVo0bb4cc8XCT9/705OQSdHaA7FVAZEvK9PgD2mnDWR3xQdC2SVxLypk4XM84NxcDDLplwr/Bke80ds04db6xn9KtlI8KU8f5CaIzTesqLFJAkiJSJwHB+VQOlF9OG8omZhK5gRlkq9x77XAub6uuKR+zFTmKhi0Kyq4mU7Hci8A1ytpBbzEvFLDgH33KKuv3PnB1r9gq7VnAtgA/00NdSTt7UcZvvTXw9hWYyzI1rqFraxsrp2gSulSmsk+elqRo8N3m7An/sujocneaCduMjsj4k82zQ+2Kl6IMsxHiB/PWS+FYNXkUfNvvkcIYT0Rw+RV2gZsorzoes8VK8dwEySEKiFOUqD9rYTkV874Q+TUOsHRlvZcEs7BNXXGW4Ub581qLMEwb1W+h0jopLXcW7LDFBW4wNaWQp2bkKXAHMJrrtN2aCGxtpYjBE6436Zul2oEuuINH2s/IrFPds4gSCzNrUugD8VIlxTUih6KE/mfDLVsURLXEcjYKxD50QswMJsnAO09vqXnzxVeQq41+3C3QX7ipZdKrPh6R1jXRchFUAqGG6QnI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95b10c00-2e29-4035-49de-08d7f139b70d X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:17:28.5054 (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: l0YOyp6HqEQWkrfxNeR62HM/V9VoUrct8cQecyBiNwL+8IsKHnz1OxPc05POxNE6HSWM/v0DG6b0PbcW0udxYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh This hypercall is used by the SEV guest to notify a change in the page encryption status to the hypervisor. The hypercall should be invoked only when the encryption attribute is changed from encrypted -> decrypted and vice versa. By default all guest pages are considered encrypted. 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 Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- Documentation/virt/kvm/hypercalls.rst | 15 +++++ arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/svm/sev.c | 90 +++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 2 + arch/x86/kvm/svm/svm.h | 4 ++ arch/x86/kvm/vmx/vmx.c | 1 + arch/x86/kvm/x86.c | 6 ++ include/uapi/linux/kvm_para.h | 1 + 8 files changed, 121 insertions(+) diff --git a/Documentation/virt/kvm/hypercalls.rst b/Documentation/virt/kvm/hypercalls.rst index dbaf207e560d..ff5287e68e81 100644 --- a/Documentation/virt/kvm/hypercalls.rst +++ b/Documentation/virt/kvm/hypercalls.rst @@ -169,3 +169,18 @@ a0: destination APIC ID :Usage example: When sending a call-function IPI-many to vCPUs, yield if any of the IPI target vCPUs was preempted. + + +8. KVM_HC_PAGE_ENC_STATUS +------------------------- +:Architecture: x86 +:Status: active +:Purpose: Notify the encryption status changes in guest page table (SEV guest) + +a0: the guest physical address of the start page +a1: the number of pages +a2: encryption attribute + + Where: + * 1: Encryption attribute is set + * 0: Encryption attribute is cleared diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 42a2d0d3984a..4a8ee22f4f5b 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1254,6 +1254,8 @@ struct kvm_x86_ops { bool (*apic_init_signal_blocked)(struct kvm_vcpu *vcpu); int (*enable_direct_tlbflush)(struct kvm_vcpu *vcpu); + int (*page_enc_status_hc)(struct kvm *kvm, unsigned long gpa, + unsigned long sz, unsigned long mode); }; struct kvm_x86_init_ops { diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 698704defbcd..f088467708f0 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1347,6 +1347,93 @@ static int sev_receive_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_resize_page_enc_bitmap(struct kvm *kvm, unsigned long new_size) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + unsigned long *map; + unsigned long sz; + + if (sev->page_enc_bmap_size >= new_size) + return 0; + + sz = ALIGN(new_size, BITS_PER_LONG) / 8; + + map = vmalloc(sz); + if (!map) { + pr_err_once("Failed to allocate encrypted bitmap size %lx\n", + sz); + return -ENOMEM; + } + + /* mark the page encrypted (by default) */ + memset(map, 0xff, sz); + + bitmap_copy(map, sev->page_enc_bmap, sev->page_enc_bmap_size); + kvfree(sev->page_enc_bmap); + + sev->page_enc_bmap = map; + sev->page_enc_bmap_size = new_size; + + return 0; +} + +int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, + unsigned long npages, unsigned long enc) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + kvm_pfn_t pfn_start, pfn_end; + gfn_t gfn_start, gfn_end; + + if (!sev_guest(kvm)) + return -EINVAL; + + if (!npages) + return 0; + + gfn_start = gpa_to_gfn(gpa); + gfn_end = gfn_start + npages; + + /* out of bound access error check */ + if (gfn_end <= gfn_start) + return -EINVAL; + + /* lets make sure that gpa exist in our memslot */ + pfn_start = gfn_to_pfn(kvm, gfn_start); + pfn_end = gfn_to_pfn(kvm, gfn_end); + + if (is_error_noslot_pfn(pfn_start) && !is_noslot_pfn(pfn_start)) { + /* + * Allow guest MMIO range(s) to be added + * to the page encryption bitmap. + */ + return -EINVAL; + } + + if (is_error_noslot_pfn(pfn_end) && !is_noslot_pfn(pfn_end)) { + /* + * Allow guest MMIO range(s) to be added + * to the page encryption bitmap. + */ + return -EINVAL; + } + + mutex_lock(&kvm->lock); + + if (sev->page_enc_bmap_size < gfn_end) + goto unlock; + + if (enc) + __bitmap_set(sev->page_enc_bmap, gfn_start, + gfn_end - gfn_start); + else + __bitmap_clear(sev->page_enc_bmap, gfn_start, + gfn_end - gfn_start); + +unlock: + mutex_unlock(&kvm->lock); + return 0; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1560,6 +1647,9 @@ void sev_vm_destroy(struct kvm *kvm) sev_unbind_asid(kvm, sev->handle); sev_asid_free(sev->asid); + + kvfree(sev->page_enc_bmap); + sev->page_enc_bmap = NULL; } int __init sev_hardware_setup(void) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 2f379bacbb26..1013ef0f4ce2 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4014,6 +4014,8 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .apic_init_signal_blocked = svm_apic_init_signal_blocked, .check_nested_events = svm_check_nested_events, + + .page_enc_status_hc = svm_page_enc_status_hc, }; static struct kvm_x86_init_ops svm_init_ops __initdata = { diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index df3474f4fb02..6a562f5928a2 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -65,6 +65,8 @@ struct kvm_sev_info { int fd; /* SEV device fd */ unsigned long pages_locked; /* Number of pages locked */ struct list_head regions_list; /* List of registered regions */ + unsigned long *page_enc_bmap; + unsigned long page_enc_bmap_size; }; struct kvm_svm { @@ -400,6 +402,8 @@ int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr, bool has_error_code, u32 error_code); int svm_check_nested_events(struct kvm_vcpu *vcpu); int nested_svm_exit_special(struct vcpu_svm *svm); +int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, + unsigned long npages, unsigned long enc); /* avic.c */ diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index c2c6335a998c..7d01d3aa6461 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7838,6 +7838,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .nested_get_evmcs_version = NULL, .need_emulation_on_page_fault = vmx_need_emulation_on_page_fault, .apic_init_signal_blocked = vmx_apic_init_signal_blocked, + .page_enc_status_hc = NULL, }; static __init int hardware_setup(void) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c5835f9cb9ad..5f5ddb5765e2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7605,6 +7605,12 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) kvm_sched_yield(vcpu->kvm, a0); ret = 0; break; + case KVM_HC_PAGE_ENC_STATUS: + ret = -KVM_ENOSYS; + if (kvm_x86_ops.page_enc_status_hc) + ret = kvm_x86_ops.page_enc_status_hc(vcpu->kvm, + a0, a1, a2); + break; default: ret = -KVM_ENOSYS; break; diff --git a/include/uapi/linux/kvm_para.h b/include/uapi/linux/kvm_para.h index 8b86609849b9..847b83b75dc8 100644 --- a/include/uapi/linux/kvm_para.h +++ b/include/uapi/linux/kvm_para.h @@ -29,6 +29,7 @@ #define KVM_HC_CLOCK_PAIRING 9 #define KVM_HC_SEND_IPI 10 #define KVM_HC_SCHED_YIELD 11 +#define KVM_HC_PAGE_ENC_STATUS 12 /* * hypercalls use architecture specific From patchwork Tue May 5 21:17:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529937 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7EAC61392 for ; Tue, 5 May 2020 21:17:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CDF020721 for ; Tue, 5 May 2020 21:17:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="H5xL3on7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729465AbgEEVRt (ORCPT ); Tue, 5 May 2020 17:17:49 -0400 Received: from mail-dm6nam12on2042.outbound.protection.outlook.com ([40.107.243.42]:11328 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729265AbgEEVRs (ORCPT ); Tue, 5 May 2020 17:17:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M+wkRg4P9n6H9eWtHk5d8t+Wc4xkHm2heHJGac+2G/Dw94CnmHTUoq2sfi8gkKvnfofDdPig86Vxvs7wfZaqh3o5Xg+jEnz9OgfZVQXuEFwXHqCdFtfL00vL5o9teqm6yBNSVkbb0Cta60zRkaCRJxpYMQm2aJB3fv0bjWrVRCXwlkKiij1GXCWfI1uEZ7dCbJrCls7PJS076p2/9JQ2TAnSDvgkxwVYKuHUFJYJy8w5jAr40VAEB5amMibHpqoJHZc2tEnqC6+DbeM3pzUv1pMkKkJhWEodD0m6uD6RyaVhCoRTn+cBMv1SK/DwiZuUfiR3aLvLfMyc/5Q2qoLiWQ== 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=VJkoKmVjJqkltyErVApWJjKqvxonYUARPOrvexVML0k=; b=YDfRRyeHS2XF/BQboigFgCxNY2NjdY7J2kwgCVfWyqA8gnh+boo474si1NYDpN1Cp7F9UA8odJQ57CLOOnhhT7MVxutw8GZzgIoojEfgU6fFC6ZfhnJrBIiKcH4a+crMTIH71SHhBMUfdXLI7Y2hqTXQeA+GMHLDBWf0VnVM9JX0cBFcRyLoCuh7Z+BtAtNVBqFdPV854ZfWocO5RNE1i7az44HCcpfi7WjxYSOxQ6xhjNGHH3Qa4HRfdv8VW7N5OFTgdvmqLA0a2bmKo3jd8Krd9DrNvBwgF+pr/LnMvpoj+4iLGXTNeBprauoxTzPxYLXxgk+4Cj1Ed2qZsEIEQQ== 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=VJkoKmVjJqkltyErVApWJjKqvxonYUARPOrvexVML0k=; b=H5xL3on712HTDl57jB6oF5c7teeH5PUBjTfVcrM0UQIOMEGJgyQP7Ka1P5WafplLUqrInZgnBmRPpl5+b+Fnrhgiz1L/4+tHRHiXkKyDb4SrLiY7qh4gHzUHC4mJ4kQmL8ojzVTM4zwj6FxcfZvohA/9IOxHpta5wQGcUW2Oi5E= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:17:45 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:17:45 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 09/18] KVM: x86: Introduce KVM_GET_PAGE_ENC_BITMAP ioctl Date: Tue, 5 May 2020 21:17:35 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR14CA0038.namprd14.prod.outlook.com (2603:10b6:5:18f::15) 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 DM6PR14CA0038.namprd14.prod.outlook.com (2603:10b6:5:18f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26 via Frontend Transport; Tue, 5 May 2020 21:17:44 +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: e673d749-ca8b-45b3-2109-08d7f139c0d6 X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3173; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /qYqKWpnxwzVcKG5eLdPYLD5xiPGMb7UL6ZcEOSl3zeSoKMyrln8Yko98YycoyAp/xo2ULo/f2fCxLHD3FmD1Liju7jaJ+zY6HI7iVus3T/guNLmBJAvTsG+no6K9S+OCoVOTT5Eg9wqqKWRUxA3QSZu67upf2+jD3i+TRKWKv1NzcPoKhh+YJqZiI8JzEY6V/YDoq30WiK1MLeGnYyW5nSJOi3c6bjnBpofcGyVj3gpKugWrMvryi/wKYY6yIVzFu/pxT811Mr1jguxRV3l7j3Lt6dibybhopgYwzHwC24lpUw1r/mRMi+hzo7YnY8BLxy3h25GQAIxozTRGJBIVQm+5l2d63cVv6hbu5QZn66aTbP0WlU5+BjdBboZxL3btAXNgwQ6alZPmQ9sMLnDF3y1HSz3Um7EIHcdm0SvoYOOK9H5c6p2ffnvFpvBzczJBIuAvDfUXoliyLGtoFibwcdAw8SIxyiZUv+DBhsHWF4ocJt2QB8LnDowwbEWoEcezEHKUgwTHH/KfYji8VMpRvGOex4GcdyJlEZwUmHUiScNs5Wr/ZZTtRsNnKyzoFxT 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(66574013)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: VQMmZeBVffnR0BYDA22nXJjEzMfhBlruEVTo86GM8eyY6HowQOJrCa5ewXyO+PmvRJFzOfE18liqgzs2yrfOGaxwHtK89GcVh5qm9embDdmxZOB/05+BttGlH/KvOyXmDqpdOM9sfn+HbO/r2M0qeNFTozyFXdTedIq3Vav0LYf0ZRuIWWeP6Y6lrenXRun7BUtwa0FSGahd2STOTmIb7NdtRjQ6TJfp6AI6Sf9z+Zgb8r/ctEOWDA7h+MGHyuh5eKFjmhoQCiJAwOBI/qtj8put6vi3nKDyWTm1ypJR6v5/Bopo8ljflFXDgnyKZrEEbeqQ6M/LFqjXBUPLKdpAm1/eJhmfaeiVoQcW6qt+7BGj99SDmmnlaAGCt6X+S6Rx9qaMGFbDLHEbWZXpPleNY4N3OBLV39qc1Khhr9mzjazE3qaj+LKkU6sTVeVrUlTIQ5xheirEVaEckhkQDZIeDemrV8kKn308hnzJ6lKP/R0X6yy0nULrb/rNXx29GvpVQOhb8+pW/HukREA0Xp88pgADPfhO8G/U4E5I+zdOePLG9Y7M8p9BO325Sl/+HZdTInCGC3DYNowwn3eO6jhZrNtKVv/lqxKHeCSmf718yiV14NHua2KCywNyJir+WnVUchq0FKb7o7VNC1guN/tHRsBzBqHeQat+54J1cvVUAP3alSV6crf/ltXXSylGNOPqmDIpKIDUd9TtFQBruKZDprMzxGcY6/1Haoa9bFbH3ZF49JB1HgI3RzcBpiPSnSJOuBUudiPnxv4oC3l+KCVVgf7Wqweh61HcKSMKFMPFdhg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e673d749-ca8b-45b3-2109-08d7f139c0d6 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:17:44.9281 (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: vQhQDja0NlqonwwDUb/qYFQSZJ9jzhdkHXFBtJUxpoD2zqmKKrIUgmpQvWBVPhC1z6qkcDPSS9u3aJuEZbhQDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The ioctl can be used to retrieve page encryption bitmap for a given gfn range. Return the correct bitmap as per the number of pages being requested by the user. Ensure that we only copy bmap->num_pages bytes in the userspace buffer, if bmap->num_pages is not byte aligned we read the trailing bits from the userspace and copy those bits as is. 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 Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- Documentation/virt/kvm/api.rst | 27 +++++++++++++ arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/svm/sev.c | 70 +++++++++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 1 + arch/x86/kvm/x86.c | 12 ++++++ include/uapi/linux/kvm.h | 12 ++++++ 7 files changed, 125 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index efbbe570aa9b..ecad84086892 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -4636,6 +4636,33 @@ This ioctl resets VCPU registers and control structures according to the clear cpu reset definition in the POP. However, the cpu is not put into ESA mode. This reset is a superset of the initial reset. +4.125 KVM_GET_PAGE_ENC_BITMAP (vm ioctl) +--------------------------------------- + +:Capability: basic +:Architectures: x86 +:Type: vm ioctl +:Parameters: struct kvm_page_enc_bitmap (in/out) +:Returns: 0 on success, -1 on error + +/* for KVM_GET_PAGE_ENC_BITMAP */ +struct kvm_page_enc_bitmap { + __u64 start_gfn; + __u64 num_pages; + union { + void __user *enc_bitmap; /* one bit per page */ + __u64 padding2; + }; +}; + +The encrypted VMs have the concept of private and shared pages. The private +pages are encrypted with the guest-specific key, while the shared pages may +be encrypted with the hypervisor key. The KVM_GET_PAGE_ENC_BITMAP can +be used to get the bitmap indicating whether the guest page is private +or shared. The bitmap can be used during the guest migration. If the page +is private then the userspace need to use SEV migration commands to transmit +the page. + 4.125 KVM_S390_PV_COMMAND ------------------------- diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 4a8ee22f4f5b..9e428befb6a4 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1256,6 +1256,8 @@ struct kvm_x86_ops { int (*enable_direct_tlbflush)(struct kvm_vcpu *vcpu); int (*page_enc_status_hc)(struct kvm *kvm, unsigned long gpa, unsigned long sz, unsigned long mode); + int (*get_page_enc_bitmap)(struct kvm *kvm, + struct kvm_page_enc_bitmap *bmap); }; struct kvm_x86_init_ops { diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index f088467708f0..387045902470 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1434,6 +1434,76 @@ int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, return 0; } +int svm_get_page_enc_bitmap(struct kvm *kvm, + struct kvm_page_enc_bitmap *bmap) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + unsigned long gfn_start, gfn_end; + unsigned long sz, i, sz_bytes; + unsigned long *bitmap; + int ret, n; + + if (!sev_guest(kvm)) + return -ENOTTY; + + gfn_start = bmap->start_gfn; + gfn_end = gfn_start + bmap->num_pages; + + sz = ALIGN(bmap->num_pages, BITS_PER_LONG) / BITS_PER_BYTE; + bitmap = kmalloc(sz, GFP_KERNEL); + if (!bitmap) + return -ENOMEM; + + /* by default all pages are marked encrypted */ + memset(bitmap, 0xff, sz); + + mutex_lock(&kvm->lock); + if (sev->page_enc_bmap) { + i = gfn_start; + for_each_clear_bit_from(i, sev->page_enc_bmap, + min(sev->page_enc_bmap_size, gfn_end)) + clear_bit(i - gfn_start, bitmap); + } + mutex_unlock(&kvm->lock); + + ret = -EFAULT; + + n = bmap->num_pages % BITS_PER_BYTE; + sz_bytes = ALIGN(bmap->num_pages, BITS_PER_BYTE) / BITS_PER_BYTE; + + /* + * Return the correct bitmap as per the number of pages being + * requested by the user. Ensure that we only copy bmap->num_pages + * bytes in the userspace buffer, if bmap->num_pages is not byte + * aligned we read the trailing bits from the userspace and copy + * those bits as is. + */ + + if (n) { + unsigned char *bitmap_kernel = (unsigned char *)bitmap; + unsigned char bitmap_user; + unsigned long offset, mask; + + offset = bmap->num_pages / BITS_PER_BYTE; + if (copy_from_user(&bitmap_user, bmap->enc_bitmap + offset, + sizeof(unsigned char))) + goto out; + + mask = GENMASK(n - 1, 0); + bitmap_user &= ~mask; + bitmap_kernel[offset] &= mask; + bitmap_kernel[offset] |= bitmap_user; + } + + if (copy_to_user(bmap->enc_bitmap, bitmap, sz_bytes)) + goto out; + + ret = 0; +out: + kfree(bitmap); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 1013ef0f4ce2..588709a9f68e 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4016,6 +4016,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .check_nested_events = svm_check_nested_events, .page_enc_status_hc = svm_page_enc_status_hc, + .get_page_enc_bitmap = svm_get_page_enc_bitmap, }; static struct kvm_x86_init_ops svm_init_ops __initdata = { diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 6a562f5928a2..f087fa7b380c 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -404,6 +404,7 @@ int svm_check_nested_events(struct kvm_vcpu *vcpu); int nested_svm_exit_special(struct vcpu_svm *svm); int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, unsigned long npages, unsigned long enc); +int svm_get_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); /* avic.c */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5f5ddb5765e2..937797cfaf9a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5208,6 +5208,18 @@ long kvm_arch_vm_ioctl(struct file *filp, case KVM_SET_PMU_EVENT_FILTER: r = kvm_vm_ioctl_set_pmu_event_filter(kvm, argp); break; + case KVM_GET_PAGE_ENC_BITMAP: { + struct kvm_page_enc_bitmap bitmap; + + r = -EFAULT; + if (copy_from_user(&bitmap, argp, sizeof(bitmap))) + goto out; + + r = -ENOTTY; + if (kvm_x86_ops.get_page_enc_bitmap) + r = kvm_x86_ops.get_page_enc_bitmap(kvm, &bitmap); + break; + } default: r = -ENOTTY; } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 0fe1d206d750..af62f2afaa5d 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -505,6 +505,16 @@ struct kvm_dirty_log { }; }; +/* for KVM_GET_PAGE_ENC_BITMAP */ +struct kvm_page_enc_bitmap { + __u64 start_gfn; + __u64 num_pages; + union { + void __user *enc_bitmap; /* one bit per page */ + __u64 padding2; + }; +}; + /* for KVM_CLEAR_DIRTY_LOG */ struct kvm_clear_dirty_log { __u32 slot; @@ -1518,6 +1528,8 @@ struct kvm_pv_cmd { /* Available with KVM_CAP_S390_PROTECTED */ #define KVM_S390_PV_COMMAND _IOWR(KVMIO, 0xc5, struct kvm_pv_cmd) +#define KVM_GET_PAGE_ENC_BITMAP _IOW(KVMIO, 0xc6, struct kvm_page_enc_bitmap) + /* Secure Encrypted Virtualization command */ enum sev_cmd_id { /* Guest initialization commands */ From patchwork Tue May 5 21:17:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529939 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32FC11392 for ; Tue, 5 May 2020 21:18:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 105B320752 for ; Tue, 5 May 2020 21:18:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="dxKS2EBc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729335AbgEEVSF (ORCPT ); Tue, 5 May 2020 17:18:05 -0400 Received: from mail-dm6nam12on2080.outbound.protection.outlook.com ([40.107.243.80]:38440 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729031AbgEEVSE (ORCPT ); Tue, 5 May 2020 17:18:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OkJ8uu4o0WocCzYsdZ9r09OCD0L0k3WK6a+UqQprvoS3kQOUmh3gfGRwTC2JvzTHaRLFtOz6qPBY/9qTxlTYG6Pl+9lap9oq6gh7UxHtbndOT7xTURQhXs5oo84yhoI7dMobdX3qPr7uFMhYYR+k5StSEqccWyBZsw5da9j5ieV/l0rZcuEVrl6GPHKYExybMfaIS2JfGR26QJyjGJ8OcaBu6bgIvu+cyJCijgwa7ihVCp5aGXmfUFiedGjHmXgV1T56invPALQFAb777wESCs4/og+zNv/xARz5eYwwmBdLyBQNJzjr7qBODZsY33m35zsmeh8Upze/6xtizGkiNg== 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=5bhVHeAVhZrK5JtuHfzsSsof/IlRxtS6Tsp+BauBXfQ=; b=MBZlKDUP9Iu1tc08/jBQxUwhEq2sArgbsr9dXa9GWPjFn/x1zR/ue+2va34VY0axjvBauu0UMC5h57RAnARTCiTJtG4Q56+wF2WxzfThXh6Xa0yxKMSz5X8YlNjLpdvtnFGFfXHG93qdagObNVkijWTZ7muydD2g8fZolvui+DhzNBdgRx5JcgM3xD7q4hCsZAv7TqOLlyr6VosxEa/4DKh58rh30JmIUpD2rRD2HtxALxIDX6HxtqWFBoQmwXMDCSeZpp+hAg/sZq/wL2qguEU7WXgr6cMLQC7THgzIviVWtnOykDZIZrmANCzlBgJ1OpeJPLK61mGpapPBBtZ2YQ== 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=5bhVHeAVhZrK5JtuHfzsSsof/IlRxtS6Tsp+BauBXfQ=; b=dxKS2EBchlG9ZZsUv2HcksYjoeYH5BlBtTBKH42Ixp7+1VZozIue4HiYTvaWccBE48aTgHM7Z58B3n3Xtq5T1NfhsjEbdHpNfvTcQQ6kyfhV54+XWDW2i3ZzpOEOb89sGBcC0ALOzpSnI/VmeW2MIm8IBMVsNcwsx3QQRqVRykM= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:18:01 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:18:01 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 10/18] mm: x86: Invoke hypercall when page encryption status is changed Date: Tue, 5 May 2020 21:17:51 +0000 Message-Id: <40272f7b19bd179b094ac1305c787f7e5002c068.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR08CA0008.namprd08.prod.outlook.com (2603:10b6:5:80::21) 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 DM6PR08CA0008.namprd08.prod.outlook.com (2603:10b6:5:80::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26 via Frontend Transport; Tue, 5 May 2020 21:17:59 +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: 883b01b1-bbd5-46d9-2342-08d7f139ca33 X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D7Fl9sqOZjNES3ajKs08vKFUhfh925jqui9FNn4F6PHWna8fqEhwbsrXePJJCCJMZQqk0F5Q5rdKjvPew5X9/uKaLIZDXAVif5PT9UGAk9LsJ9c/g409qEMIBUOvCXvgsnRMaBpOg+CEw0ivm8IO/zhufNmHsCgYndExaq1lywUK5cE/FwMrYfY7TyR5PTjJysubwg1S7bt3tdZCidr5Q4s8CWQHBAFmrRuPkVa4o9HTNPcQvLnh9Cp808hlCTbrFXNtPtHMeI53WGQ5nM1zW09PU+lNxMuj+icZ9ERR4BGjDdaCjdXK5WzZVI7LDwW6e7uVr58u7V8m1/WvX8YNPlisud8mdNUs+ppndTysiQYuNBtM/VCwGTM2xl6pQ2SrRWHkW95eq4SE0DflsGWI6o2jNhvUQp4M/aU9egcY7B868uuVknCdfZd45uxLfwV9Gdb3Pjqg6dXcT+H56hKVQSz0DQyOhrgwfO8wL+t/GZ8vcipgDg+4ItyNTr5ZQX1YW2TTA5KmaR1dRluHvfbMvC69dyeg02Jh2y5A6qygtzqM6u9M3zmKTW1JjNNelsaz 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(66574013)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 4X52NAGENLL9PcGtV6myV6TVS/gb9rAfW6sSJgF5+EXywnxYs4hke/7qksfDSHE6eLYREo7VwWgzEfB771MVSLPkdx0dcBdBmce50tsQqv4Q4mdskj0gwJb7yYPLiAjoU73qaywcrBHZTdK5hTroKNhkyLgmVk0w9I6uJfKk7ElQSfp+oD6Thp66EmViuIZhzd0W2Q3ztvVk7HcEsuVYCJR8SToHyIBc2iPgm3tUtOXt2z/bZJKFr5idF60HQTMgx59N6iaumH10KFmvQodzIBO3iqhFnM1WC0TtZxVUS7FvkJx2WgrNem5pOWRITIrhv1maNQoV5uk+gFb77DnwrZxTcRO3gmtIQ/6rP3kmA0YkOmWTJGlWdr0Hxz1pmHMo6kM0v+SBKG4/dQwVQOMuktgp8GOC79orejsiMa+ZawD2xJLA1qT3UMEznHv+FGdCjqYZv1AvFCo1JkHYCEtEqOd2yP4JJzr+YjibDBLT+OzBtJzQVnBUfiISGFESw2DqG4ofMK6/SQ96nLUfRQyX4Q2V3PdbsLkn5bvSq5wVXsBcDhj8dqlnWuS3w81ZVfufuXomL1dAaGI237Ai18wTuYp7Oxc5Fo9b8p05h8Pdxl0NnB6kjJpCJcQBMJ4i6dl+UF4SKoKVXEZhZmj1aDQpuMIXRVh9PxyXxunUdaqyYhUm7MwljL14ctCP3FUAaXoz4vVD6a4A+309ZnZlSkLRPNEyGZ2gCed3w4tiuCm75b8oylvEu4lWXs5cqLo6/cFv0Q9i49Ay9qIKoWGtuwktdwameNRry8shAaSf38+lY2I= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 883b01b1-bbd5-46d9-2342-08d7f139ca33 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:18:00.6282 (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: i5KJX7vg6VBCi/YsSwB4FbxAYq7c0k9ejwJQKfNBVW5zVvUaU6K31zyY6Nh3nOtvn8+k+9KQgDBSy4rhi+IsKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh Invoke a hypercall when a memory region is changed from encrypted -> decrypted and vice versa. Hypervisor needs to know the page encryption status during the guest migration. 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 Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- arch/x86/include/asm/paravirt.h | 10 +++++ arch/x86/include/asm/paravirt_types.h | 2 + arch/x86/kernel/paravirt.c | 1 + arch/x86/mm/mem_encrypt.c | 57 ++++++++++++++++++++++++++- arch/x86/mm/pat/set_memory.c | 7 ++++ 5 files changed, 76 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h index 694d8daf4983..8127b9c141bf 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -78,6 +78,12 @@ static inline void paravirt_arch_exit_mmap(struct mm_struct *mm) PVOP_VCALL1(mmu.exit_mmap, mm); } +static inline void page_encryption_changed(unsigned long vaddr, int npages, + bool enc) +{ + PVOP_VCALL3(mmu.page_encryption_changed, vaddr, npages, enc); +} + #ifdef CONFIG_PARAVIRT_XXL static inline void load_sp0(unsigned long sp0) { @@ -946,6 +952,10 @@ static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm, static inline void paravirt_arch_exit_mmap(struct mm_struct *mm) { } + +static inline void page_encryption_changed(unsigned long vaddr, int npages, bool enc) +{ +} #endif #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_PARAVIRT_H */ diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h index 732f62e04ddb..03bfd515c59c 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -215,6 +215,8 @@ struct pv_mmu_ops { /* Hook for intercepting the destruction of an mm_struct. */ void (*exit_mmap)(struct mm_struct *mm); + void (*page_encryption_changed)(unsigned long vaddr, int npages, + bool enc); #ifdef CONFIG_PARAVIRT_XXL struct paravirt_callee_save read_cr2; diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index c131ba4e70ef..840c02b23aeb 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -367,6 +367,7 @@ struct paravirt_patch_template pv_ops = { (void (*)(struct mmu_gather *, void *))tlb_remove_page, .mmu.exit_mmap = paravirt_nop, + .mmu.page_encryption_changed = paravirt_nop, #ifdef CONFIG_PARAVIRT_XXL .mmu.read_cr2 = __PV_IS_CALLEE_SAVE(native_read_cr2), diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index f4bd4b431ba1..c9800fa811f6 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,7 @@ #include #include #include +#include #include "mm_internal.h" @@ -196,6 +198,47 @@ void __init sme_early_init(void) swiotlb_force = SWIOTLB_FORCE; } +static void set_memory_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc) +{ + unsigned long sz = npages << PAGE_SHIFT; + unsigned long vaddr_end, vaddr_next; + + vaddr_end = vaddr + sz; + + for (; vaddr < vaddr_end; vaddr = vaddr_next) { + int psize, pmask, level; + unsigned long pfn; + pte_t *kpte; + + kpte = lookup_address(vaddr, &level); + if (!kpte || pte_none(*kpte)) + return; + + switch (level) { + case PG_LEVEL_4K: + pfn = pte_pfn(*kpte); + break; + case PG_LEVEL_2M: + pfn = pmd_pfn(*(pmd_t *)kpte); + break; + case PG_LEVEL_1G: + pfn = pud_pfn(*(pud_t *)kpte); + break; + default: + return; + } + + psize = page_level_size(level); + pmask = page_level_mask(level); + + kvm_sev_hypercall3(KVM_HC_PAGE_ENC_STATUS, + pfn << PAGE_SHIFT, psize >> PAGE_SHIFT, enc); + + vaddr_next = (vaddr & pmask) + psize; + } +} + static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) { pgprot_t old_prot, new_prot; @@ -253,12 +296,13 @@ static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) static int __init early_set_memory_enc_dec(unsigned long vaddr, unsigned long size, bool enc) { - unsigned long vaddr_end, vaddr_next; + unsigned long vaddr_end, vaddr_next, start; unsigned long psize, pmask; int split_page_size_mask; int level, ret; pte_t *kpte; + start = vaddr; vaddr_next = vaddr; vaddr_end = vaddr + size; @@ -313,6 +357,8 @@ static int __init early_set_memory_enc_dec(unsigned long vaddr, ret = 0; + set_memory_enc_dec_hypercall(start, PAGE_ALIGN(size) >> PAGE_SHIFT, + enc); out: __flush_tlb_all(); return ret; @@ -451,6 +497,15 @@ void __init mem_encrypt_init(void) if (sev_active()) static_branch_enable(&sev_enable_key); +#ifdef CONFIG_PARAVIRT + /* + * With SEV, we need to make a hypercall when page encryption state is + * changed. + */ + if (sev_active()) + pv_ops.mmu.page_encryption_changed = set_memory_enc_dec_hypercall; +#endif + pr_info("AMD %s active\n", sev_active() ? "Secure Encrypted Virtualization (SEV)" : "Secure Memory Encryption (SME)"); diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 59eca6a94ce7..9aaf1b6f5a1b 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "../mm_internal.h" @@ -2003,6 +2004,12 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) */ cpa_flush(&cpa, 0); + /* Notify hypervisor that a given memory range is mapped encrypted + * or decrypted. The hypervisor will use this information during the + * VM migration. + */ + page_encryption_changed(addr, numpages, enc); + return ret; } From patchwork Tue May 5 21:18:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529941 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E0B11668 for ; Tue, 5 May 2020 21:18:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE69920721 for ; Tue, 5 May 2020 21:18:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="LjuOYJvc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729498AbgEEVSV (ORCPT ); Tue, 5 May 2020 17:18:21 -0400 Received: from mail-bn7nam10on2041.outbound.protection.outlook.com ([40.107.92.41]:6189 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729031AbgEEVSU (ORCPT ); Tue, 5 May 2020 17:18:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hF7eVkx7IQLKj69PWKAvybHL2Qa68Rx7gmbJ4nKX0PHA8vAK/V5TfVQEMUpJ7Z+PTc6HDy/AnHoEl3lHzYeoA3wWVgSS4VfCYNKRtKlycC+gG9i6J8FRT34cPs1hPoi93V8qmnvPmfcym80ZdjY8IfrVxqE5CvdiZ8F2kdtCGIQNUFHw1TmvlS+Y17R8KNZ2GxsxzTG1iNvU8Lfq8KcqxZkP/StyfKi5YxbdeIdVigt0F4eQXTAFiOz9OM0pFNLhYPPksSB3pQ2lom1cyjb1UfomLHH55LA6cuTaNWShsjk2jYMSAGmi62+txXJhJ0MmAdQKqmEHwjaq6XG927wW9A== 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=4d9nd2guchaUPlm62R2CFdQ0ghiakGkEXEeHVbGcpME=; b=oSXEkhsrMQ9bc5/ezyBkKfw/M+zaxvpJtFHpWhKmi8S/nH14DRjkG1ZCmt5jFgWyXJyuug03s8kX/IKo5DWNPipreUMQK9iZM0HnsyeD0E+29IuJKtAOXGKOfAgg32wmBccH1vDzlrr3/2tON/1Jig/Gw0ttVxWDZrmJMlTYCrXhASXIcLFvzpjNDBLDQ6ksDLB0kQnFKLJ3+UxL//crWEKIhwyVy2NI00HNEDk0i+pVv4ogoayrSeVoN8aUuxiM0d/V1BdW/Cv6KZ9DPTpM8WlcjscsSEHTSCLfDvJXQJUPR9KLBh+l97mEVGg8sdbEGm5bcwT7fIXKD9R+GZ1ebA== 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=4d9nd2guchaUPlm62R2CFdQ0ghiakGkEXEeHVbGcpME=; b=LjuOYJvcdoGqXO21kOTPJ6vB1doc+u0qaNjld8tzCzV9CzJz2bVORvI2vdXCdj8Na3Xc4hFSF1D4/y8IAm3cPt6TFnsvs4IOf7nXdPzSXaHHWglAYiYfwUNJ3/yvFxosHtVdRjUesgAuJ7ET1izkBu0reqPOt5/gH/CN0xdaTIo= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:18:16 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:18:16 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 11/18] KVM: x86: Introduce KVM_SET_PAGE_ENC_BITMAP ioctl Date: Tue, 5 May 2020 21:18:07 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR15CA0053.namprd15.prod.outlook.com (2603:10b6:3:ae::15) 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 DM5PR15CA0053.namprd15.prod.outlook.com (2603:10b6:3:ae::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Tue, 5 May 2020 21:18:15 +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: 1fbc5c5d-bbae-41b3-1798-08d7f139d3a8 X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q0h8LGw8DSUPJT7l6eV4RNlp/H6ah0qVlG+hL8eR55efn39yuGwtblVGwCpeW9YXXa5oFRJoqNmxehYnOrTPSfIuxkFPL7cu/r0QWbU2AM53hWDbAq0RQm7CvUSL9pyGlHWYwIX18l0XfJPICWfAnwaOLe5eaFR9jW2hsPdFXQQOOiQ1OrCwR0EZV2TxekvoiTw9NSy8wN8+Ns3tHSQyuKsn4r4B0jCZ2Ox6wMaWHMzHMvnLa4jNMkfAx80Q3ilHDjl0BRwTs20/v0d6ZtME20EDDLrl2ROY4VHdshnCnm439KqET+T2UMueDdZvWnkt7UKTexadAmT+MR0rgDOKmdYCTPnrZEALfH+9afSuKdYoWdNFPIgmAmztKwjfs3WMQauY8e+JuTWvVllflDVB57pQeV2KHmk5UEGLsvamp9Mx5Uqm33X9mtT9/5U7TgCRah2AowHChQufjo2DwWm+NjSUeTYYa0LUhJ+YkiQHFZ97IhK3iBpTeB+GGFv1P0Vu8dEX+3hSC/zutudEfw9get6wqOgYOT30p/oJ149oeejZ36sJ0DRU2iUM+TAKcCOA 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(66574013)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: BHLbGlGa8tdZCjPAe21C6qiBOLDWr2+fqfHfW0BAx9GUX/FH4aLdHdAsi+PEDrebDKZDbml/pQplEAETXKQGpLz7lvh8U7HdrY4TsJeKSG5ujzy3C+s92tzndgYS+XOXGWJq2M71F4BQsI+0TgpezXzPtJpfhi0Ihjwm9EKAHe52UlpuMSSmAboC1rEgg5KyP4/Zmtf4+dM89bGBOKPHGcskC3JykBaB9Ex4BHfygniIYHfbpFp1ggjCbNDQ/ag10b/ZpDs04jlVCQL+ozYicYNbW5SlYQLHznsUj3MWfikeMTpCvsDtV/EZTNWMXuk05Jqn8iutH01aKCPpay6UCPTN4QeuRFPkbuq7n6kKiKkvok+dmQwO8xbG2UtvHqxZAaDxTV6OFw37TGwtfqYHntfI3XtFV7PvVBipULzZxKzwIwAi6+TdZFAK5JpwW2bNEKApJcnL8O0wA3hKQvroktZkhIcSzCs2fsuHJim/+Eik2fuh4SpEUwEMttKYic7DLYn2Wihu5HNDcTV32i4AY6y0zcYBax9JxXKd5qTkQ3Yqcq0fiQB3DfA+vk2dLB/vComBRO9fIQ5SqHY8KRoHrNkK6cWLaS/Cb6f2GtzBQrTLcCP51jfbJpu72Q+dloU3vc5pY9uRvx3d2LFh1T/QG/1+A9tmO+DIYxfga8rE1jzAntkBuV3OuJNk4WrYOXrzSt4HLdR/k0t8NnHD588C3IO2dKXoWEPlRhrfgg2bnugBX6jkvFBntnK4NGfmKGGLH0ELR5MVoc3gHMdvYt8T5UyMgUKublaOoIBantvX2Mc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1fbc5c5d-bbae-41b3-1798-08d7f139d3a8 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:18:16.4802 (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: RnBq9FBT/nbGK9wqWc8xaDMIth/Xd0GGpcFolzaJCD/Um26SS4PtAcWIxPqQlQJhuJV9oVnJFVRlSrwKo7x/3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The ioctl can be used to set page encryption bitmap for an incoming guest. 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 Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- Documentation/virt/kvm/api.rst | 44 +++++++++++++++++++++++++++++ arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/svm/sev.c | 50 +++++++++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 1 + arch/x86/kvm/x86.c | 12 ++++++++ include/uapi/linux/kvm.h | 1 + 7 files changed, 111 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index ecad84086892..fa70017ee693 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -4663,6 +4663,28 @@ or shared. The bitmap can be used during the guest migration. If the page is private then the userspace need to use SEV migration commands to transmit the page. +4.126 KVM_SET_PAGE_ENC_BITMAP (vm ioctl) +--------------------------------------- + +:Capability: basic +:Architectures: x86 +:Type: vm ioctl +:Parameters: struct kvm_page_enc_bitmap (in/out) +:Returns: 0 on success, -1 on error + +/* for KVM_SET_PAGE_ENC_BITMAP */ +struct kvm_page_enc_bitmap { + __u64 start_gfn; + __u64 num_pages; + union { + void __user *enc_bitmap; /* one bit per page */ + __u64 padding2; + }; +}; + +During the guest live migration the outgoing guest exports its page encryption +bitmap, the KVM_SET_PAGE_ENC_BITMAP can be used to build the page encryption +bitmap for an incoming guest. 4.125 KVM_S390_PV_COMMAND ------------------------- @@ -4717,6 +4739,28 @@ KVM_PV_VM_VERIFY Verify the integrity of the unpacked image. Only if this succeeds, KVM is allowed to start protected VCPUs. +4.126 KVM_SET_PAGE_ENC_BITMAP (vm ioctl) +--------------------------------------- + +:Capability: basic +:Architectures: x86 +:Type: vm ioctl +:Parameters: struct kvm_page_enc_bitmap (in/out) +:Returns: 0 on success, -1 on error + +/* for KVM_SET_PAGE_ENC_BITMAP */ +struct kvm_page_enc_bitmap { + __u64 start_gfn; + __u64 num_pages; + union { + void __user *enc_bitmap; /* one bit per page */ + __u64 padding2; + }; +}; + +During the guest live migration the outgoing guest exports its page encryption +bitmap, the KVM_SET_PAGE_ENC_BITMAP can be used to build the page encryption +bitmap for an incoming guest. 5. The kvm_run structure ======================== diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 9e428befb6a4..fc74144d5ab0 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1258,6 +1258,8 @@ struct kvm_x86_ops { unsigned long sz, unsigned long mode); int (*get_page_enc_bitmap)(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); + int (*set_page_enc_bitmap)(struct kvm *kvm, + struct kvm_page_enc_bitmap *bmap); }; struct kvm_x86_init_ops { diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 387045902470..30efc1068707 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1504,6 +1504,56 @@ int svm_get_page_enc_bitmap(struct kvm *kvm, return ret; } +int svm_set_page_enc_bitmap(struct kvm *kvm, + struct kvm_page_enc_bitmap *bmap) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + unsigned long gfn_start, gfn_end; + unsigned long *bitmap; + unsigned long sz; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + /* special case of resetting the complete bitmap */ + if (!bmap->enc_bitmap) { + mutex_lock(&kvm->lock); + /* by default all pages are marked encrypted */ + if (sev->page_enc_bmap_size) + bitmap_fill(sev->page_enc_bmap, + sev->page_enc_bmap_size); + mutex_unlock(&kvm->lock); + return 0; + } + + gfn_start = bmap->start_gfn; + gfn_end = gfn_start + bmap->num_pages; + + sz = ALIGN(bmap->num_pages, BITS_PER_LONG) / 8; + bitmap = kmalloc(sz, GFP_KERNEL); + if (!bitmap) + return -ENOMEM; + + ret = -EFAULT; + if (copy_from_user(bitmap, bmap->enc_bitmap, sz)) + goto out; + + mutex_lock(&kvm->lock); + ret = sev_resize_page_enc_bitmap(kvm, gfn_end); + if (ret) + goto unlock; + + bitmap_copy(sev->page_enc_bmap + BIT_WORD(gfn_start), bitmap, + (gfn_end - gfn_start)); + + ret = 0; +unlock: + mutex_unlock(&kvm->lock); +out: + kfree(bitmap); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 588709a9f68e..501e82f5593c 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4017,6 +4017,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .page_enc_status_hc = svm_page_enc_status_hc, .get_page_enc_bitmap = svm_get_page_enc_bitmap, + .set_page_enc_bitmap = svm_set_page_enc_bitmap, }; static struct kvm_x86_init_ops svm_init_ops __initdata = { diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index f087fa7b380c..2ebdcce50312 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -405,6 +405,7 @@ int nested_svm_exit_special(struct vcpu_svm *svm); int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, unsigned long npages, unsigned long enc); int svm_get_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); +int svm_set_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); /* avic.c */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 937797cfaf9a..c4166d7a0493 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5220,6 +5220,18 @@ long kvm_arch_vm_ioctl(struct file *filp, r = kvm_x86_ops.get_page_enc_bitmap(kvm, &bitmap); break; } + case KVM_SET_PAGE_ENC_BITMAP: { + struct kvm_page_enc_bitmap bitmap; + + r = -EFAULT; + if (copy_from_user(&bitmap, argp, sizeof(bitmap))) + goto out; + + r = -ENOTTY; + if (kvm_x86_ops.set_page_enc_bitmap) + r = kvm_x86_ops.set_page_enc_bitmap(kvm, &bitmap); + break; + } default: r = -ENOTTY; } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index af62f2afaa5d..2798b17484d0 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1529,6 +1529,7 @@ struct kvm_pv_cmd { #define KVM_S390_PV_COMMAND _IOWR(KVMIO, 0xc5, struct kvm_pv_cmd) #define KVM_GET_PAGE_ENC_BITMAP _IOW(KVMIO, 0xc6, struct kvm_page_enc_bitmap) +#define KVM_SET_PAGE_ENC_BITMAP _IOW(KVMIO, 0xc7, struct kvm_page_enc_bitmap) /* Secure Encrypted Virtualization command */ enum sev_cmd_id { From patchwork Tue May 5 21:18:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529943 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A9F51392 for ; Tue, 5 May 2020 21:18:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2274320721 for ; Tue, 5 May 2020 21:18:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="aCi0V9hV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729031AbgEEVSv (ORCPT ); Tue, 5 May 2020 17:18:51 -0400 Received: from mail-bn8nam12on2050.outbound.protection.outlook.com ([40.107.237.50]:6270 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728076AbgEEVSv (ORCPT ); Tue, 5 May 2020 17:18:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WFKQhwLGo6JL2tQXAXucmHsYdBUNDlN8QQKcwh06KDlAR2Mol5pcda2niBJghkOA1yOBy0Iax0hZI3PTqtNWnwsfFH3flFhcxxgk/ZWO4DsmiRusPVNzzwPptx9Y+WPm95Wxx0x/geNokpCAC+NnXHF0+DbZO2Cqao3nD/RVN5gUiydQQDlGST3InACD6kPjMMaN+5MRrZsNeeZQTmj6CGUSOv1c9SNAyop8P4rmIbHuPQbn6TyuBDjaRZ11/+RPDp1fe3st3hMQb3crJ5FPabeQsx9XPUwgJbN9lM9wM1Mmtgit++fQ9AC3CKdIPkVdHPM+b6306BcQQGwMKbyLkA== 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=EjHp0+pzexUmP/9EFqhPehoytBsTiu+D1qHk0K2efAQ=; b=k2cEvWv5E03nugT+w8XcDsfuBe7q5PJml0ZS/2T8gEXREt7pmKNmHRtpdvkRYAgCBigYdeVLsZlPiSLp9rocHqS8TMSOVT7Fz+nC/4WVvHBtV9LUR0fUwKo3vEP+06tiQGIIjFKmndxD4b6xgJ3XBpUAkp+bbjnF6tEINWFTg6ONJkBFMiw7bj0GkIbIRjYQXZ675k955sdIi2L0D9AZW/jIkPAe8jQFAvkcHok3tvxNlNJ98JxRoq1GhTwvO1tWFN2MSz8ieL7FASFdBmrn6QQmIZwgYp6mc0NlgoBINAvn/yt4it4nz+6aqf7BDncR/tdOVrUqeDNA/qIldExJZw== 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=EjHp0+pzexUmP/9EFqhPehoytBsTiu+D1qHk0K2efAQ=; b=aCi0V9hVsJ92LHcyPEs/UJru6YpAKNbZYSReomTupsOiHq+ukOP5SOEypZaKHVbml2SYxYOqUWh/nF6Kjey0SJkkkAPVrSSfHxSOrz6n8cASe/I9JoKt6gKuQJufQQcDYZ4cSQVa8nhaSbPvMQl372G3jrq9/Dkp9cPkTPN0skE= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:18:47 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:18:47 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 12/18] KVM: SVM: Add support for static allocation of unified Page Encryption Bitmap. Date: Tue, 5 May 2020 21:18:38 +0000 Message-Id: <17c14245a404ff679253313ffe899c5f4e966717.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0089.namprd07.prod.outlook.com (2603:10b6:4:ae::18) 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 DM5PR07CA0089.namprd07.prod.outlook.com (2603:10b6:4:ae::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26 via Frontend Transport; Tue, 5 May 2020 21:18:46 +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: f798c1ec-d64a-4ca7-cf84-08d7f139e634 X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:416; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: REVf5hw2Vukos678fcJtiHXrFAAz6eFpXeE2oFK+UoKyNvNrQTiYOEyVwgnxFkoonxhMP/6S76AfsYu4WzIuEAmUwuaX4bxtjxA6Yeu5N9VS+AzF5IRKhmnXlhqIaST0UsSnup8qz/5/VLTiyBWBiMkZxzKvv4kdc2mEeCFsEl4ntm17sVVsHxq1Gqi5Tn1eWNEei7u9SVVkF1miL8/7iBf4fHCAGRa9wxfNt0swo2WzcBI2Makvv4HsBJ9hSO6meiZIeTj0JJLsvHgnkcgcI/lgboFbh/xIxp9qEAM2gjESty6qljZrifvgQQ3FchDxcyoJkmxU8chUc+ZrBLGULbeg4p2gY91TjUwTOErLCsyQ55wno+TQW2a6RTlMZ4JlbbMtcYWp5aC1rDG8QClhmQgnjIx8Pei0fp7h7V7ZtSIsSQSr7zkeH4CKp3WA/yWUAnwlC53RM5lBZBB0EAqZxnEpZgvRLPVzblF3+3LZB5RtD7bw0255OTkaNFXk1ruQY9Ul1WGGtYZQj5x0dkojQnnbE0qU68OngI0Gve8Qn5GMT7rAgLrlJ6SjsDJd8K3Y 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: beUI8aZ6Jqa4Z2bVYfI4RgjdQfmSapUimtX+b5OP/Xu7+GRAcDns4h3rCs3we3wwCLph2H+PsPLIxtdqJ4Jk/nqpmIWHIMM42/TJu/J+NgvL0GLa01IlnqiBVai3a79fUV4EHGvOEYlA8cohKqcSYNmEG991T6/mbCfoW7/WIPg1FpgeA6bYKdyD5zX8OEy902gkl77nrMMeTsC7VLPSUOhaP9i71bqZUgZWn5m5J+U9jCZEWq0nTrY+uxM1CdyEaCsv0z/lHw2jSDkzUcJDj27BfkMTUuQ12Rx2YZHZCrSzyWDQ4GgkXmosZqaCcEt2dKsxFu6R2zhRxYGGIQJbKuvKmZJeQtC1LM+amKw5wJuzonUgLhCYQ8jdQBTv3OoSwaXtZN5oIQW+bOYwhM54eGPD+iKSgosLHH/txui0hngSzs/1fr6Ax9t93nmshrRVolaf/Zf0DMJALiHFTEP/xrKEO3QQgZSmqAfrEPJQIkIRfHdAdcSPt6C0GdeAC92r5VD5qszDWfaAaaJ99QQ/VIkY0J/opOESeA7ZxP/bGCjRrGkO5FbI1Cp2NWgeXtgvP8wX/21ehKJlqq7G+rh+5nR1CfyUbxo+gH8EQnMe9tbgNXQYk7nivlPeu/D/35JYmAX39fWQblo4JODH96DeNIISVwMaaCwR/sU9QE/fQnHER9+3cHrjH30wZ4V5VkSQFgSmu5YWG7O3PoEXqUGTX60m1MU4pBGYTD6we0JbkV7wMI9mbOPzSh0Dz7JAb2wNeTg5eqkVst55cJfPWjWWbK6KGpJUTDjdpvf158Wa8R4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f798c1ec-d64a-4ca7-cf84-08d7f139e634 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:18:47.5864 (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: y48TVJIDnm5JwTNePmnk0DVe+fGkQrSrD8GOPP74qHEfXGrMx7vL5apTtkuUg8Pfw6E7B0jzdX1lqOdNyE8FnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Add support for static allocation of the unified Page encryption bitmap by extending kvm_arch_commit_memory_region() callack to add svm specific x86_ops which can read the userspace provided memory region/memslots and calculate the amount of guest RAM managed by the KVM and grow the bitmap based on that information, i.e. the highest guest PA that is mapped by a memslot. Signed-off-by: Ashish Kalra --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm/sev.c | 35 +++++++++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 1 + arch/x86/kvm/x86.c | 5 +++++ 5 files changed, 43 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index fc74144d5ab0..b573ea85b57e 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1254,6 +1254,7 @@ struct kvm_x86_ops { bool (*apic_init_signal_blocked)(struct kvm_vcpu *vcpu); int (*enable_direct_tlbflush)(struct kvm_vcpu *vcpu); + void (*commit_memory_region)(struct kvm *kvm, enum kvm_mr_change change); int (*page_enc_status_hc)(struct kvm *kvm, unsigned long gpa, unsigned long sz, unsigned long mode); int (*get_page_enc_bitmap)(struct kvm *kvm, diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 30efc1068707..c0d7043a0627 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1377,6 +1377,41 @@ static int sev_resize_page_enc_bitmap(struct kvm *kvm, unsigned long new_size) return 0; } +void svm_commit_memory_region(struct kvm *kvm, enum kvm_mr_change change) +{ + struct kvm_memslots *slots; + struct kvm_memory_slot *memslot; + gfn_t start, end = 0; + + spin_lock(&kvm->mmu_lock); + if (change == KVM_MR_CREATE) { + slots = kvm_memslots(kvm); + kvm_for_each_memslot(memslot, slots) { + start = memslot->base_gfn; + end = memslot->base_gfn + memslot->npages; + /* + * KVM memslots is a sorted list, starting with + * the highest mapped guest PA, so pick the topmost + * valid guest PA. + */ + if (memslot->npages) + break; + } + } + spin_unlock(&kvm->mmu_lock); + + if (end) { + /* + * NORE: This callback is invoked in vm ioctl + * set_user_memory_region, hence we can use a + * mutex here. + */ + mutex_lock(&kvm->lock); + sev_resize_page_enc_bitmap(kvm, end); + mutex_unlock(&kvm->lock); + } +} + int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, unsigned long npages, unsigned long enc) { diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 501e82f5593c..442adbbb0641 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4015,6 +4015,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .check_nested_events = svm_check_nested_events, + .commit_memory_region = svm_commit_memory_region, .page_enc_status_hc = svm_page_enc_status_hc, .get_page_enc_bitmap = svm_get_page_enc_bitmap, .set_page_enc_bitmap = svm_set_page_enc_bitmap, diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 2ebdcce50312..fd99e0a5417a 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -406,6 +406,7 @@ int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, unsigned long npages, unsigned long enc); int svm_get_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); int svm_set_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); +void svm_commit_memory_region(struct kvm *kvm, enum kvm_mr_change change); /* avic.c */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c4166d7a0493..8938de868d42 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10133,6 +10133,11 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, kvm_mmu_change_mmu_pages(kvm, kvm_mmu_calculate_default_mmu_pages(kvm)); + if (change == KVM_MR_CREATE || change == KVM_MR_DELETE) { + if (kvm_x86_ops.commit_memory_region) + kvm_x86_ops.commit_memory_region(kvm, change); + } + /* * Dirty logging tracks sptes in 4k granularity, meaning that large * sptes have to be split. If live migration is successful, the guest From patchwork Tue May 5 21:19:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529945 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4949B1392 for ; Tue, 5 May 2020 21:19:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2548B20721 for ; Tue, 5 May 2020 21:19:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="jGKPB6Hh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729322AbgEEVTe (ORCPT ); Tue, 5 May 2020 17:19:34 -0400 Received: from mail-dm6nam12on2084.outbound.protection.outlook.com ([40.107.243.84]:34596 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728737AbgEEVTd (ORCPT ); Tue, 5 May 2020 17:19:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dduXz3mTTOUsZ051mMnwfo4Vc5hDdxzlmR63ouRZtdflx/ZhdxpyypNxNkffMCYJkao9mkWXU4GAwSVPW6ErVCTZRxHcoYVAuECIR+3QXb2QPYfzEltjvHB68p5jlHSYTUm2B+TT09wJ1KmSp/HFSphHtUcnKX8qdIeb0YkRvth4rxBjYmQeGrFgojPG6qguqLcxWTaNp9RYallUny1Z5FltusnmTn6lfwnfgvLwszMpZchPItc5zKMJ1fOoexLU1GWLHgFt4rQ/2vbBFJe/XpRaMhccvLhJsYPeFRhNh771xMxsWJ9o1EaCtsTgTXo2mtTb6PCZk8RuKDDwuv9Bng== 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=cuXaRdjmmHCPd9wR81thyrxqDncCwgKk5BxExn3Vw/M=; b=bXv3ceeHLAQ9i/Dv8fVvD2ooCcsW4cQFVyjxZKudrDmUQF0DgsBViLsLio+CghXlVk6Tw6XMy7lyekBgw8gmAcTcb7QWGupaJFxC/gkiNv0WsiUVyIHAy5pJhxLMyiTo+IAHkfMWiaCCj8vKyZ8R2ZKE4PwH3UH/u6sF5EdzZeIlKjHYTtBW8pfe0xQtcy4wXrjFewrawDJwKjeN0frTq2lcYGZRtoY8oxj/7DlCifgEeafE2wJKC7VOQcwOmX1XT+CR6nAUtKcZiORcd8/znGMQlwwBnZIS3s4zou1VdzU8yqaUnFHZyhRLZ7QJFvFxdIG5xeVLB9ZUVbiujf55qQ== 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=cuXaRdjmmHCPd9wR81thyrxqDncCwgKk5BxExn3Vw/M=; b=jGKPB6Hh9a+ZIfs98ZuMO183CPcZKcHBvJukkMeXs9tziugkYFfLQN21YjqdTqMUylF/UI3G5kzSrgMJAxy9WYeBZtqPhwABcVIDi19n76fc/toI1sY3M3OsPgipzaZ+uaDnCWVBBXMZf32e+4dYsBuOzqere/coj3Ix3T8RvsU= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:19:30 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:19: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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 13/18] KVM: x86: Introduce new KVM_FEATURE_SEV_LIVE_MIGRATION feature & Custom MSR. Date: Tue, 5 May 2020 21:19:17 +0000 Message-Id: <4ff020b446baa06037136ceeb1e66d4eba8ad492.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0002.namprd02.prod.outlook.com (2603:10b6:803:2b::12) 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 SN4PR0201CA0002.namprd02.prod.outlook.com (2603:10b6:803:2b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27 via Frontend Transport; Tue, 5 May 2020 21:19: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: 30c44a4e-17a9-4692-c133-08d7f139ff76 X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M4Aoe7YrfbzYPdFhQPBjHB8JQRME1Pc6EQe0d4w7OP3YHkPrEucw3k79qMuTyAIQMP0xpZXe9ohD1Y48yAIX/VcroCjOfbACatqOWroE7gyLsVlvJr/4Vni4afk7CtB4oVOGaF8ZAUUIybtOwQTAtNzVwrU66Cp2ZdW4NHP3laOyTdF30Hi+lyqZfB+g0d+WOm02rlzRElbvSOBNtMhNyJTmoTeJ7oY7AzoHe8ZpXw+2CWnznV0OQdf9fMwTBpSdj7JEmsN31Nh9ZInxQtt8MZHwQZUADCuziWEdq0RPnjJwFrq9jh6KubfqvXlC4ySYLurp7yqrINdf+hxE2cbJxnUqivPNZsMjw/xNX/T9KPAPA5VVy2jGWnbwUlBADoVQvONk7ZG0LqZ4oakyW1bKHPjlTMpM7DFyksa3uNjsoXdmlfhBEbOdkhr4ImlXZ83BQbhRwCCvNELqu4iuCXt72VaSu1uXS2paEavbzATF6E/CjiBQ24qAH/ZMTlaJRdOZnIt5ouamiFi5Sjmusu8HIAr3peedyh/kSjvhlPiJPWSxvV6acCIspHZ0rtSVeKGw 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ghI6GI7EUZgzu5afUfm8T9tdQ124xf6yIar+p2mJabI5bR+ON5APNc0nW2NsggiSMQQHwO85HIgDoA6qe4i2AJcGVYi/LNCazp29OQbOYiS2K8udpGNUNC0pPc+YzAKQu+loT6M6PorL0v2na2XmlwiZNJXw928sIx1NSVsdjMEIpgm7Xrz+IL7CbryfqAaTUKRvxGAhuITvOD28eS5rP/qJuxHQPRzvbjGnxXDDmK1WI6JB9mNA/a9ki/L/jM8942d9HmphNUhl/MoPsyN69uBco4qPkcKSS1NoSQCmfqN//PKeWzzKPI7D5B3858TRMb4iZTB4Gq9fbbdb+n1rpvrImw9Q9YV2j8VmwWPpjXJfa4dtpN0ytnb7q5EtAn0u88LWRMFltz2SAo8fFnYC7nSavBORwB23ksGdd6BpjKB0zYFy9ZuoJmu9FSQb0X3TzJWihXYHz0B81IhtGrg1D9r+5pq5mePuroMFSHNxKjIJljO/q9r9dNk3g458yYsw0dcQJjwB7ww1Y/StVYnaSZh1VLVsxvpP1HDJL8P04NTzRKQQUi0K3zMWoebNGCaEt6Pj6rKGoPAVjYIm1ldMvFvVDP/TxuGFd94qlGuZ3B+pB/AoHOFXMFPJWFqIZAPDpPn67IlF89w4bdEUtwk4mFT43liLZiDJx3mvhwOOkqzVHMjhz9Wjk+44//rRaXk87jowU1aFzHrvuDS0zqFacNNSMVc5OelvaAG3iiYLU6DbriiR+BUeUW7qgW8+6XcKDWKNJEsdRNjiyb0lpEkvFiijZJfe3b8tyiTqEuxBeIA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30c44a4e-17a9-4692-c133-08d7f139ff76 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:19:29.9606 (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: xyj5F8nnXqm3xHhpy5FCePPgRJGwoLZG3r/Mx+THD7rZ6vt8Ulm6KZzUA8zKpL1xZQvffS+vYecE88/8RHZmxw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Add new KVM_FEATURE_SEV_LIVE_MIGRATION feature for guest to check for host-side support for SEV live migration. Also add a new custom MSR_KVM_SEV_LIVE_MIG_EN for guest to enable the SEV live migration feature. Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- Documentation/virt/kvm/cpuid.rst | 5 +++++ Documentation/virt/kvm/msr.rst | 10 ++++++++++ arch/x86/include/uapi/asm/kvm_para.h | 5 +++++ arch/x86/kvm/svm/sev.c | 14 ++++++++++++++ arch/x86/kvm/svm/svm.c | 16 ++++++++++++++++ arch/x86/kvm/svm/svm.h | 2 ++ 6 files changed, 52 insertions(+) diff --git a/Documentation/virt/kvm/cpuid.rst b/Documentation/virt/kvm/cpuid.rst index 01b081f6e7ea..0514523e00cd 100644 --- a/Documentation/virt/kvm/cpuid.rst +++ b/Documentation/virt/kvm/cpuid.rst @@ -86,6 +86,11 @@ KVM_FEATURE_PV_SCHED_YIELD 13 guest checks this feature bit before using paravirtualized sched yield. +KVM_FEATURE_SEV_LIVE_MIGRATION 14 guest checks this feature bit before + using the page encryption state + hypercall to notify the page state + change + KVM_FEATURE_CLOCSOURCE_STABLE_BIT 24 host will warn if no guest-side per-cpu warps are expeced in kvmclock diff --git a/Documentation/virt/kvm/msr.rst b/Documentation/virt/kvm/msr.rst index 33892036672d..7cd7786bbb03 100644 --- a/Documentation/virt/kvm/msr.rst +++ b/Documentation/virt/kvm/msr.rst @@ -319,3 +319,13 @@ data: KVM guests can request the host not to poll on HLT, for example if they are performing polling themselves. + +MSR_KVM_SEV_LIVE_MIG_EN: + 0x4b564d06 + + Control SEV Live Migration features. + +data: + Bit 0 enables (1) or disables (0) host-side SEV Live Migration feature. + Bit 1 enables (1) or disables (0) support for SEV Live Migration extensions. + All other bits are reserved. diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h index 2a8e0b6b9805..d9d4953b42ad 100644 --- a/arch/x86/include/uapi/asm/kvm_para.h +++ b/arch/x86/include/uapi/asm/kvm_para.h @@ -31,6 +31,7 @@ #define KVM_FEATURE_PV_SEND_IPI 11 #define KVM_FEATURE_POLL_CONTROL 12 #define KVM_FEATURE_PV_SCHED_YIELD 13 +#define KVM_FEATURE_SEV_LIVE_MIGRATION 14 #define KVM_HINTS_REALTIME 0 @@ -50,6 +51,7 @@ #define MSR_KVM_STEAL_TIME 0x4b564d03 #define MSR_KVM_PV_EOI_EN 0x4b564d04 #define MSR_KVM_POLL_CONTROL 0x4b564d05 +#define MSR_KVM_SEV_LIVE_MIG_EN 0x4b564d06 struct kvm_steal_time { __u64 steal; @@ -122,4 +124,7 @@ struct kvm_vcpu_pv_apf_data { #define KVM_PV_EOI_ENABLED KVM_PV_EOI_MASK #define KVM_PV_EOI_DISABLED 0x0 +#define KVM_SEV_LIVE_MIGRATION_ENABLED (1 << 0) +#define KVM_SEV_LIVE_MIGRATION_EXTENSIONS_SUPPORTED (1 << 1) + #endif /* _UAPI_ASM_X86_KVM_PARA_H */ diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index c0d7043a0627..6f69c3a47583 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1469,6 +1469,17 @@ int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, return 0; } +void sev_update_migration_flags(struct kvm *kvm, u64 data) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + + if (!sev_guest(kvm)) + return; + + if (data & KVM_SEV_LIVE_MIGRATION_ENABLED) + sev->live_migration_enabled = true; +} + int svm_get_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap) { @@ -1481,6 +1492,9 @@ int svm_get_page_enc_bitmap(struct kvm *kvm, if (!sev_guest(kvm)) return -ENOTTY; + if (!sev->live_migration_enabled) + return -EINVAL; + gfn_start = bmap->start_gfn; gfn_end = gfn_start + bmap->num_pages; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 442adbbb0641..a99f5457f244 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2633,6 +2633,9 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) svm->msr_decfg = data; break; } + case MSR_KVM_SEV_LIVE_MIG_EN: + sev_update_migration_flags(vcpu->kvm, data); + break; case MSR_IA32_APICBASE: if (kvm_vcpu_apicv_active(vcpu)) avic_update_vapic_bar(to_svm(vcpu), data); @@ -3493,6 +3496,19 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu) svm->nrips_enabled = kvm_cpu_cap_has(X86_FEATURE_NRIPS) && guest_cpuid_has(&svm->vcpu, X86_FEATURE_NRIPS); + /* + * If SEV guest then enable the Live migration feature. + */ + if (sev_guest(vcpu->kvm)) { + struct kvm_cpuid_entry2 *best; + + best = kvm_find_cpuid_entry(vcpu, KVM_CPUID_FEATURES, 0); + if (!best) + return; + + best->eax |= (1 << KVM_FEATURE_SEV_LIVE_MIGRATION); + } + if (!kvm_vcpu_apicv_active(vcpu)) return; diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index fd99e0a5417a..77f132a6fead 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -65,6 +65,7 @@ struct kvm_sev_info { int fd; /* SEV device fd */ unsigned long pages_locked; /* Number of pages locked */ struct list_head regions_list; /* List of registered regions */ + bool live_migration_enabled; unsigned long *page_enc_bmap; unsigned long page_enc_bmap_size; }; @@ -494,5 +495,6 @@ int svm_unregister_enc_region(struct kvm *kvm, void pre_sev_run(struct vcpu_svm *svm, int cpu); int __init sev_hardware_setup(void); void sev_hardware_teardown(void); +void sev_update_migration_flags(struct kvm *kvm, u64 data); #endif From patchwork Tue May 5 21:20:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529949 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CE191392 for ; Tue, 5 May 2020 21:20:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F5F720752 for ; Tue, 5 May 2020 21:20:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="3XCt+yAN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729132AbgEEVUY (ORCPT ); Tue, 5 May 2020 17:20:24 -0400 Received: from mail-bn8nam12on2077.outbound.protection.outlook.com ([40.107.237.77]:35425 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726350AbgEEVUX (ORCPT ); Tue, 5 May 2020 17:20:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kvCP0kDVzczrNyRDI8sbYXSbaifXh+0sxSwwI6/0WUhTDvkIXioGoXKOmNkgZqiWVA/IEIhXHGP4e9r3MfrPhRdRoL7utbpf0ViZrxf8JQAmBNxcn9UjNipjLQEsxmYk/Xx+ShfKuByBCxMPYQdvYap0Nhsy4GBEVxGVIslsRiRxxSpHipgmQrkr+A8S0Y/7wGFLGpqkVxuIxWbK3k2VvYRMhPf9eXuZHPR3xlEmfOy/TN9TvxBzyoP2Vu7oRN6Ay6r0LDHLtA5tAMLLlS49zFoft3zzOBNKKWwrv/fItoYuMWdSNYabG5eqOxo1uytJQqAV/aLGPzxGLFhMBRSSqA== 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=3D/kK5cQCLuGeO7hC945SONJQJPxE71P6AsK3LWgYTk=; b=bgGAbdPKjUjku970jGicXOfvsgKI+ppnKjHX/SWnYXQ/T3+KtJnKYIBblMaO2XaChitlJLHJCH1ee0pZVUQFGfqG09iZ75jvnSLhvR0WrBy8JFSOWExlCTrO8MgmUY4pLZfdPc7u6Hk9nRuQKqPI68mf8pPUmVOnLq4jpi6b5KD3lVXjqfIoVoscsqEsErqXdhb+/yJfK5fY2fcsGitgSZPwH7N9T3WCAhgYWsX0Qv4NvOxDTypDlIXRDyjMkGktS/8TAkGIy5ctbej6qR691NdcSsJWyar2wHOdHEEweCcVJH/oajQbzRU5yvlYwJouIv0/J6T5/tH1wOBWuCsb2Q== 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=3D/kK5cQCLuGeO7hC945SONJQJPxE71P6AsK3LWgYTk=; b=3XCt+yAN1oMCEz4hZxw/PHO7XmNQ7ZWitWCUSUMhV9EnlhcF6p1pb6GXxcfBkKKQs2y9SPXWZB9OOIlOeYJfSOwM/ZlmCrGOq+xDSDb3sdHZhl/VZqKhepv2RqyX1Jf49pGyZLN6drmnqZzHT116Xu6Qodl7cBK1YWZrQ3Z18IU= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:20:20 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:20:20 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 14/18] EFI: Introduce the new AMD Memory Encryption GUID. Date: Tue, 5 May 2020 21:20:10 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0144.namprd05.prod.outlook.com (2603:10b6:803:2c::22) 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 SN4PR0501CA0144.namprd05.prod.outlook.com (2603:10b6:803:2c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.16 via Frontend Transport; Tue, 5 May 2020 21:20:19 +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: c66a1315-9d42-4c51-7cf4-08d7f13a1d7b X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cCMYPo30k/cHdH4LE8RLu1MGBdDHXs/EgEqnhg8sQg2uPHRdDrN8e33OdnHL96N0vY0HwzgYTtwvZsvMCA4Esmmw5N1Tczt14JdOoyOaOp1b/FNqEs6tUgFtdLUkVfCuvUMFPadyJ0g4ElMLuRFeA5Fe9L5llDYwQh+iH10GEQcEjtMN+qBM64auiRM6yIKv++V5afNMMfBU/0sBp+jWXL6xY3wUoyGcdVANKeLtfPUTFUVea62ypxfXaGh72KLohIJB378Q5Y0uXWp/jRiVnUAIXgN/Vlyn1NrwA6qd85X0QOpMgsd0jZwB3cpgdDP8GvdC2kfOa94YlSjUM2HbuQ1jJIHWz5KynxulcDpYUGTvSIJro14s4u6UnNzTgEfoFlgEehti0AJQM6ezs8l0ytntYwPFzUGjmCqcA7XRCAeDJ6SuHIzlTHJ04Sob6Ql6M+cKkUDZLpu2y6WGZU+bY0dk/BWudQ7PqRyJD6gg0rQ9iXQVqiOKsdrEWy3NRM+hlHIDmcAw5mpS7irJXopeefYeQhVQoZVhUG1GbnGtfu8LImh/B6IntWibw4qnD2ra 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:(4636009)(396003)(366004)(136003)(39860400002)(346002)(376002)(33430700001)(6916009)(26005)(36756003)(956004)(16526019)(478600001)(6486002)(2906002)(5660300002)(6666004)(2616005)(186003)(66476007)(7416002)(52116002)(8936002)(86362001)(7696005)(8676002)(66556008)(66946007)(4326008)(33440700001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: EaSLzdjKbVWIg348tdZflwQT/6VpczASOGYB9VCdw6dwnqwsYKIGxhKW0jRKf/5DEi9w513Jam+LkUi+xvqHVXujYQYbPMeB2JXHHupPUwxaYDed3vcNNegZo9eM4FMFX99EMYaVpai4v6N65v1+qozUmOierrbTNsnszVsg0dhOD/PSHotn/9S+5gbB8RcQH2eDlQbGhapYONLroI/MoneBg0NM48NvMpFJOEL52s76K/6ctPq7mJ7LOLKIxVOTkzXLrD28tb6APDar6F8DAdyusWQofuJ9Ij8rf1MhSGwXu+1QsIVXFUpZD/ynQuBFm8/piTFEwbn1BZyxsSded9vetTwMiLMTv111bXcfCqx0+lh2RpfzNyvs3UlJ66K5RQkHkQbPWRO3Nfuc1mIfix43gnHKciSU1k8P80xRGxC/eaChGUmCooQeXszKjx8STezh5l8XX7/1FqeSgaA8PnUurai4o32PO9t/oMcb7BLObvTAvr5TwULHgJc2bqmQu6Xo5gCGsNN9lG82ZI+r/r5DklW575aUlx9u9iX3Zc6PMdBXqvcBjX9bjmF5uTbsuTGtDEm9Qmcvy3+0Pqx4YllkIzeHns5LFQlVt8DdFDAVRzaA5vndLpL9pjqn3yKC+/zBXzKsWdBxmrcqo1AD8eRjlicme6bg4KgdVwnu8sEKP5qXNGp65+Bv/BA3Ewme0kHZ6jawXjbnTp5AYs+R6lLv+unFrUeDJtuS/fZ1WqV5dqPNWS7uLLy5vUXgsM+lSCmpF5yh16XT4QL9byGjt/oYnntO0GTRGZTZZZiAkQY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c66a1315-9d42-4c51-7cf4-08d7f13a1d7b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:20:20.4002 (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: ieIM9XTNMcOdsBqwJhZwE6AzER83wCe6wXU8K1qAts/9iY6O4FsHzG995RsorxTwyhy2GWBee76q2Xj5SuhAbQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Introduce a new AMD Memory Encryption GUID which is currently used for defining a new UEFI enviroment variable which indicates UEFI/OVMF support for the SEV live migration feature. This variable is setup when UEFI/OVMF detects host/hypervisor support for SEV live migration and later this variable is read by the kernel using EFI runtime services to verify if OVMF supports the live migration feature. Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- include/linux/efi.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/efi.h b/include/linux/efi.h index 251f1f783cdf..2efb42ccf3a8 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -358,6 +358,7 @@ void efi_native_runtime_setup(void); /* OEM GUIDs */ #define DELLEMC_EFI_RCI2_TABLE_GUID EFI_GUID(0x2d9f28a2, 0xa886, 0x456a, 0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55) +#define MEM_ENCRYPT_GUID EFI_GUID(0x0cf29b71, 0x9e51, 0x433a, 0xa3, 0xb7, 0x81, 0xf3, 0xab, 0x16, 0xb8, 0x75) typedef struct { efi_guid_t guid; From patchwork Tue May 5 21:20:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529951 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B19901392 for ; Tue, 5 May 2020 21:20:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DFDE20752 for ; Tue, 5 May 2020 21:20:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="MMjWJGPa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729356AbgEEVUp (ORCPT ); Tue, 5 May 2020 17:20:45 -0400 Received: from mail-bn8nam12on2084.outbound.protection.outlook.com ([40.107.237.84]:6247 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728135AbgEEVUo (ORCPT ); Tue, 5 May 2020 17:20:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cdS3cMRwWFeoFT9fp1MjtBdtg1JHb/MTTS3A/q4MSEeRh2buHTpvCHniwIpXgFUIRIicq4EwUsKoawaTXZxe3aVrDKfNcgo2GXXvcjqU2/H/6gYogfbK3noUCoiecOlrbF5cks1Is9c4tXP76BDB15F0yd8dwnvAY0DOkcYAIfcC3ukPUCALhuMK+uvY9yG6D/d2dBxTifZ5u5cqJCSVD81fwh7mq117ddYq8HfxKyoDBLjI3SghPTJvo2MIPd190mTABFHTw7svyhc3i5QMRZYYpjipshUNjISBNCUjgNMtWwDJ82t4pJTF/d4XcHc8bxtkqgxVtDf+AEr4flWmMg== 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=i6M75aJ86EErmULkq3AISRtesIH5UXicdvxN1tkBGDs=; b=Z9bb3546wBUnqSJv57RSzifbzUm72GaFQFS05h77oEDS2ct23hFxIywKIZHQyQL9u3YLXo3do+3FO0A2ycM4V3oyW6Omfhd6dwdc/YeU4DRxnYTDzMBhFwXfEisrwsTNTce1obb2nzhoDvt56X5/bpJb7OuKTer62GbozIESYHDSvgeAz2u9sHIIKcDDGtN8JORhxaayWP4M4bFj2MyAwn7hR6B7nsJkKPjQJXgIJ++vq+oJNFi3AB+8QOWfe8iAg+GmBFHW1jR774ggs/eAPPcKQqRYJgxHWkih1Q0tqgZaO0acKl+plL2NYlCD66z54waZEiZK3GqXJNP7qkXVWA== 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=i6M75aJ86EErmULkq3AISRtesIH5UXicdvxN1tkBGDs=; b=MMjWJGPa/RYV+vNzkuZhLofd+qWflUu8KtWHsS58+Xx++BA77O79flxbhMhcj9mAdNXxmr2viaMAaZI2wC0hrX2Gz233WzSDzMGgeSphmpH1gFIrSgxa8iydw9wSGSWy7pYBEVdWQkesu99zmXYGkBZdOpos/1OQleME03dm1V8= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:20:39 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:20:39 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 15/18] KVM: x86: Add guest support for detecting and enabling SEV Live Migration feature. Date: Tue, 5 May 2020 21:20:30 +0000 Message-Id: <939af9274e47bb106f49b0154fd4222dd23e7f6d.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR08CA0023.namprd08.prod.outlook.com (2603:10b6:805:66::36) 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 SN6PR08CA0023.namprd08.prod.outlook.com (2603:10b6:805:66::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27 via Frontend Transport; Tue, 5 May 2020 21:20:38 +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: b82027a6-4795-4a34-29cb-08d7f13a28f7 X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GwfynD9ZxxFFsPZNaQIttXFc2CXsBtAqlHIr0H4+wXOLyyR3gbbaN8taJ4DmBxCCdnff2xzvNvzVV2K3ndpx3E6fROdI3qmAmLyT1MAfP0BZtGwaCxNwF7UvvA9QB9+zUaV0VUcVDvRhwwGWJUucj/XRwXtfCmxUR5RT922OizKlHoQGXWaZIVxlkBy26MXDOz6n95VRFeI2QrrFn+c/kqk4Vmtcg7zjFV49lcT4LrcyAfcsUDHjklc2tNPTwAe4wfaAw3KNrW6NOM33oEPsCo8kgnRtP7D7ruKrslo1GOoEUXMxvtooFSHxA9R6LGkLJTlTUtnGo+D2oUZbS2N1rZygMEUH4eLVWqaGr/5/owF5RwfsoF9+WHlwNkRiPzaiPwtsulTDsrtFwYNR3oZYvdamaMwITDiJCD8SNJg1ljwcvKIjqmcv5Zlf5ljU0DQ2F6ySkoYEnyjbAeumS/x6Nr4bxKYgfr6wiMKqil7oKMePwajfV75i/no1KOiUoTUgkvEnOMQtSlN7VoinGGti/eQ+3JofiBFEnaL2YUoVc4YO81w1Ocf1ioMXzaOpPLvy 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:(4636009)(346002)(376002)(39860400002)(136003)(366004)(396003)(33430700001)(86362001)(8676002)(66556008)(7696005)(66476007)(52116002)(8936002)(7416002)(4326008)(33440700001)(316002)(66946007)(16526019)(478600001)(6486002)(6916009)(26005)(36756003)(956004)(5660300002)(2906002)(6666004)(186003)(2616005)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: uECiuVQgKZaTuDoSnZwyxp1ldpTShRBnnaS1QUIUAYnUYZ1x0rOWQVOTeFyfTotxh+pH0lFc1T+NDLKqfVSTKl2fP1klzP0PBsAmX0Ngd6SpD+BXhxDqKFkRNRuqoZRB/Ia1nGitAbMdIErc0HmY/Zk0kKDYOP+HotYUrwotC5Rt0PzZl8J2B2mL7sWz6FpTKlCt0myL/11XWu+YvxMeY95yymblgvKIBHaCykrX+43ODhrVoWws0JRbaRO5TDep6l+G6xoueLtWpsT+lwWHR+JNUg9ChSasU9s1uh2OjxcGECziYj7NYmwyCNkm82qaDBGXPS6jb8wll8qKWwZvUjiYEb5Br9VMV1KDhkwPxaF8qpMA6nHoqSok6TOpkPkD3vCcqTkB1udhiyrh/JgQkngDiXfzXhYFToygYejX4i/pNe1u8ZGuKZK/FXpHakin++JNgWl7YXvruZDOEXS0WfSS0Lw9ZgLr1C9I8a7KWX7+DvjMa6Yjh0F98pTCr7iTUdjTt5PvJy18f9vEbhyZ5CpXaJdCVjbxMNpfwm/znoboshAF8pFJn5kzGmTFgu8vq9R2ZKkMFQcMGoq3FSCiu3Tv6ZTZe3ISxJ/Qk1/HwCTMEhUL6CE/pjPhqGFkVFDhLQb0T7DcI8HERN1oHOda8bN1Q56yC1AWje5ajzlwgwONsU0lC9kDhMsEV147abVaHnLb00ZdLwYGYEU0DdAbCWq8L9dn5qoitsbLSXfcPF/vivZclYcVL9+MI7QfzY1/CnwupYjxsCNqr7FSRf9wnBEFHS0wN5Q3Gztup3mVuxA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b82027a6-4795-4a34-29cb-08d7f13a28f7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:20:39.6017 (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: HS5uepFN0whSzchPKLYB1r+tsQ9OvzjvBhu6jBF+QBkxdRldETiQYW2mlX/v2RRoi6nua2GNOHWSeyo5kdbBBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra The guest support for detecting and enabling SEV Live migration feature uses the following logic : - kvm_init_plaform() checks if its booted under the EFI - If not EFI, i) check for the KVM_FEATURE_CPUID ii) if CPUID reports that migration is support then issue wrmsrl to enable the SEV migration support - If EFI, i) Check the KVM_FEATURE_CPUID. ii) If CPUID reports that migration is supported, then reads the UEFI enviroment variable which indicates OVMF support for live migration. iii) If variable is set then wrmsr to enable the SEV migration support. The EFI live migration check is done using a late_initcall() callback. Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- arch/x86/include/asm/mem_encrypt.h | 11 ++++++ arch/x86/kernel/kvm.c | 62 ++++++++++++++++++++++++++++++ arch/x86/mm/mem_encrypt.c | 11 ++++++ 3 files changed, 84 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 848ce43b9040..d10e92ae5ca1 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -20,6 +20,7 @@ extern u64 sme_me_mask; extern bool sev_enabled; +extern bool sev_live_mig_enabled; void sme_encrypt_execute(unsigned long encrypted_kernel_vaddr, unsigned long decrypted_kernel_vaddr, @@ -42,6 +43,8 @@ void __init sme_enable(struct boot_params *bp); int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size); int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size); +void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc); /* Architecture __weak replacement functions */ void __init mem_encrypt_init(void); @@ -55,6 +58,7 @@ bool sev_active(void); #else /* !CONFIG_AMD_MEM_ENCRYPT */ #define sme_me_mask 0ULL +#define sev_live_mig_enabled false static inline void __init sme_early_encrypt(resource_size_t paddr, unsigned long size) { } @@ -76,6 +80,8 @@ static inline int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0; } static inline int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; } +static inline void __init +early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, bool enc) {} #define __bss_decrypted @@ -102,6 +108,11 @@ static inline u64 sme_get_me_mask(void) return sme_me_mask; } +static inline bool sev_live_migration_enabled(void) +{ + return sev_live_mig_enabled; +} + #endif /* __ASSEMBLY__ */ #endif /* __X86_MEM_ENCRYPT_H__ */ diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 6efe0410fb72..4b29815de873 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -403,6 +404,53 @@ static inline void __set_percpu_decrypted(void *ptr, unsigned long size) early_set_memory_decrypted((unsigned long) ptr, size); } +#ifdef CONFIG_EFI +static bool setup_kvm_sev_migration(void) +{ + efi_char16_t efi_Sev_Live_Mig_support_name[] = L"SevLiveMigrationEnabled"; + efi_guid_t efi_variable_guid = MEM_ENCRYPT_GUID; + efi_status_t status; + unsigned long size; + bool enabled; + + if (!sev_live_migration_enabled()) + return false; + + size = sizeof(enabled); + + if (!efi_enabled(EFI_RUNTIME_SERVICES)) { + pr_info("setup_kvm_sev_migration: no efi\n"); + return false; + } + + /* Get variable contents into buffer */ + status = efi.get_variable(efi_Sev_Live_Mig_support_name, + &efi_variable_guid, NULL, &size, &enabled); + + if (status == EFI_NOT_FOUND) { + pr_info("setup_kvm_sev_migration: variable not found\n"); + return false; + } + + if (status != EFI_SUCCESS) { + pr_info("setup_kvm_sev_migration: get_variable fail\n"); + return false; + } + + if (enabled == 0) { + pr_info("setup_kvm_sev_migration: live migration disabled in OVMF\n"); + return false; + } + + pr_info("setup_kvm_sev_migration: live migration enabled in OVMF\n"); + wrmsrl(MSR_KVM_SEV_LIVE_MIG_EN, KVM_SEV_LIVE_MIGRATION_ENABLED); + + return true; +} + +late_initcall(setup_kvm_sev_migration); +#endif + /* * Iterate through all possible CPUs and map the memory region pointed * by apf_reason, steal_time and kvm_apic_eoi as decrypted at once. @@ -725,6 +773,20 @@ static void __init kvm_apic_init(void) static void __init kvm_init_platform(void) { +#ifdef CONFIG_AMD_MEM_ENCRYPT + if (sev_active() && + kvm_para_has_feature(KVM_FEATURE_SEV_LIVE_MIGRATION)) { + printk(KERN_INFO "KVM enable live migration\n"); + sev_live_mig_enabled = true; + /* + * If not booted using EFI, enable Live migration support. + */ + if (!efi_enabled(EFI_BOOT)) + wrmsrl(MSR_KVM_SEV_LIVE_MIG_EN, + KVM_SEV_LIVE_MIGRATION_ENABLED); + } else + printk(KERN_INFO "KVM enable live migration feature unsupported\n"); +#endif kvmclock_init(); x86_platform.apic_post_init = kvm_apic_init; } diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index c9800fa811f6..f54be71bc75f 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -46,6 +46,8 @@ EXPORT_SYMBOL_GPL(sev_enable_key); bool sev_enabled __section(.data); +bool sev_live_mig_enabled __section(.data); + /* Buffer used for early in-place encryption by BSP, no locking needed */ static char sme_early_buffer[PAGE_SIZE] __initdata __aligned(PAGE_SIZE); @@ -204,6 +206,9 @@ static void set_memory_enc_dec_hypercall(unsigned long vaddr, int npages, unsigned long sz = npages << PAGE_SHIFT; unsigned long vaddr_end, vaddr_next; + if (!sev_live_migration_enabled()) + return; + vaddr_end = vaddr + sz; for (; vaddr < vaddr_end; vaddr = vaddr_next) { @@ -374,6 +379,12 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size) return early_set_memory_enc_dec(vaddr, size, true); } +void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc) +{ + set_memory_enc_dec_hypercall(vaddr, npages, enc); +} + /* * SME and SEV are very similar but they are not the same, so there are * times that the kernel will need to distinguish between SME and SEV. The From patchwork Tue May 5 21:20:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529953 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B9411392 for ; Tue, 5 May 2020 21:21:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F37B820752 for ; Tue, 5 May 2020 21:21:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="vIfssTlG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729416AbgEEVVA (ORCPT ); Tue, 5 May 2020 17:21:00 -0400 Received: from mail-dm6nam12on2061.outbound.protection.outlook.com ([40.107.243.61]:6207 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726593AbgEEVU7 (ORCPT ); Tue, 5 May 2020 17:20:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RSbvotpTuVNkTv+dhk9NJpmoWteDR7K0GQpbDCXsX8jfLM9Q5KSPjt220wBRJrZ6kU8MwxgH85GrDPcVrcx6bAdsaPkCQ9nouwBh7SW8cv0h1Cm783oL7cw+VU0MizMg/kIUttFGPQvY1MflDVreuSKn+1MC4ONgvrAMhvZA7wTX3jbIwHK2pVu3h5IRleuuRft3da2qTqEkL/aSvSQfpjw8794jnpW9h52XMtuj/7G9kw6f+0U9qpYkSY24Uler9uN7t9M3rKyLYcUBZ9CM7sM+KeO5/PkeNfoQDLLOmcmlTlqDImNIVLbIvgy47EzuvKCRDqyHaJO6hoa4LcK+mg== 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=Ms5T1TbPWzXX58Hb+fiuk/V0KrkIf2MtQZxaywTUg50=; b=lhpA+mGJM1heRCcioo1EYYJGdctdkreQlSpivuL/FnGmYU7sjn+RRbZeaiVujZTEL30l1mmGtZSy2pTYmNJABGRYEQ4gfDPdv2u8fjn+qgTaXXmmVNiUTeEFu/jCGqvluaSvwxplfqxZ9PiBeyQuuLHM+jckojVswHdmLS2khlIXpAnYljhjwhYvzjk7zbgiNsjNGhld6z8OQrZqfZPRU99fiUJQ1p9413vAl67oSLpTd6fMzd/mbogdGn489YmHQvRSyPOytOKyJLhOgu6nSgoDGLAVu3/JkPk1o5CwF049+qJ429OFUo8QdXSauJcPnOeanW+Bq5jLQEtPVsSFYw== 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=Ms5T1TbPWzXX58Hb+fiuk/V0KrkIf2MtQZxaywTUg50=; b=vIfssTlGpJWyqawm+0azAZ5FU9ir0kxBHfzwGx2BEX/NQ/k7rTLtJW/X0OuNO+Ejq62T/XTzYA+0+paKuxjnVCzKUfD20qOtp/4t4F4VIc2cMvTL3vuMzI/LgYCS1ipyFUQc7nqFY8pc38zQdAQiwGB+FUOg+ZRryOv26DqLDNs= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:20:56 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:20:56 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 16/18] KVM: x86: Mark _bss_decrypted section variables as decrypted in page encryption bitmap. Date: Tue, 5 May 2020 21:20:47 +0000 Message-Id: <02cde03d5754c84cfa0dc485f62d85507a2a9dd5.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR02CA0051.namprd02.prod.outlook.com (2603:10b6:5:177::28) 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 DM6PR02CA0051.namprd02.prod.outlook.com (2603:10b6:5:177::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27 via Frontend Transport; Tue, 5 May 2020 21:20:55 +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: f85d8190-8302-4953-c3d1-08d7f13a333c X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1186; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9yVt5MHIdBqPfsYM4vBI3Vd2bV5RclYWWxX8JZG3I6aM+F0CmYZreruLfAOVbzr0UHfx3wAFlImfRxp+tVAyyPk4vU2b6W11/nbmgPs33eAXEyQpOISVwpB+wsrgbCIyahnLPK3fysgxm1JkepWM46ViZs6tkMnBqGtIJvXIknQ8aoxJRoLPqOV1PbEu6bR7wAo7eBNFrL+gje2dAfxlcA5C80TVNgRfwVlcEM2Dcc8QUWz9joeALurLLlf/s0YmzyzWo4UK7/AKT/EAoMoQticVmqmhjBIUDJiTTgMHQMycOz3qIpXShM2ctmDIfhCB3Xl73852AAMv3+f7naeYV1I3XkU+0WGwPFpXEUNDqDxfCn7E+n7/UZ/3YckZ/u2bzXMb+7OPzNBY8jH9PrNOrrJy5N6bVQbgB8HiL/aB0jAqCTlP2nSbINexJ2i3GG+ttukh9A+Q0sSjWTFKamCIRdC867A5dL3hHZtZBOim1S39ui8W+JLDchI0PEsZnJw+qhNJbAQodmESagGEhS4ayL3e/WFv0MvIUVbkMnTxV5c30+onDl2AWpsggZgm75HW 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:(4636009)(346002)(376002)(39860400002)(136003)(366004)(396003)(33430700001)(86362001)(8676002)(66556008)(7696005)(66476007)(52116002)(8936002)(7416002)(4326008)(33440700001)(316002)(66946007)(16526019)(478600001)(6486002)(6916009)(26005)(36756003)(956004)(5660300002)(2906002)(6666004)(186003)(2616005)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: iEk/Jq3RFY3W/pk3IC+QiOWRv+kmPciLZ+MLgesG3w0I05+BPn29N/GyNOFQcS2QT1uRNzr1RoGaaM4BQJaO156J2kxZCeTHSO7A7316lvz2nU69X0BE//bGKufChL1y6/FajCdKznf4gPoF+IbdsM5laTYxDVmJ2aJeAR6B5qZ1AUpVq7Ha/sv4q25VUaaxVrF2oRCsPt0UvAnofk8yDRHUnAZ+XLGzAQRsykp09X5kTHxp7ZsMBHSBiG05jiQq/Zx+m3wg47moOCWZCNuf6KWmnK97KKQl2W++vXwkUatAurLk1sqjkeWx7K1sZs9xUkb7tu/Y2Anrv5S2/Ulxv0g3P72SvBrDWtAk/4vQj6VEKlkZgLbBLEmCEr50xUmu3gi5pSX4BaD3jPQOY/z81xCJEa7egHG3ezJTd2GRkt3bbfmLCCPe5huwbxA9tNH8VF/WY2WvKOWC4Qd7FQCiUuYnNSDgqa2pvw9xosJ808V/apMnKmlsnH6tVi1adFm0uuPa1nM+jjdzo6o26XgtXo0duloOGmU2Z0GFffbrzNOMTwI0z3naUQSf4pT76gaAXjfxqKMU5D4wZi0XMlL0sBpry7U0Bmg0zpe5wq1X623U+MOgK/0xWyeKN6Ew9I5s0FKqQWifEIVUyS6QVHgdnFcDz3h7tppTUpfnBsLyn8Cm9VfRZ/1SYi+vaEmjYCrkt6lqRx12wSQX3Xu0ItIKx7e9ncjskBiqGJlCQec1k5InEUKOClTz2xrk1P54ZHxTf6txyqnYLy0LiZyRqcWGBSZZO9Mu4V9vRJMQxRlgKNg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f85d8190-8302-4953-c3d1-08d7f13a333c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:20:56.8351 (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: 4Vsj6iDNQHVI1EdEmumq0aL6h63xP7wmFWPtk3Bn031uT7h3tD+LKfPNg6Qxy0rz1DO2YKye4HHxP1YDxw9QHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Ensure that _bss_decrypted section variables such as hv_clock_boot and wall_clock are marked as decrypted in the page encryption bitmap if sev liv migration is supported. Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- arch/x86/kernel/kvmclock.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 34b18f6eeb2c..65777bf1218d 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -334,6 +334,18 @@ void __init kvmclock_init(void) pr_info("kvm-clock: Using msrs %x and %x", msr_kvm_system_time, msr_kvm_wall_clock); + if (sev_live_migration_enabled()) { + unsigned long nr_pages; + /* + * sizeof(hv_clock_boot) is already PAGE_SIZE aligned + */ + early_set_mem_enc_dec_hypercall((unsigned long)hv_clock_boot, + 1, 0); + nr_pages = DIV_ROUND_UP(sizeof(wall_clock), PAGE_SIZE); + early_set_mem_enc_dec_hypercall((unsigned long)&wall_clock, + nr_pages, 0); + } + this_cpu_write(hv_clock_per_cpu, &hv_clock_boot[0]); kvm_register_clock("primary cpu clock"); pvclock_set_pvti_cpu0_va(hv_clock_boot); From patchwork Tue May 5 21:21:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529955 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 309ED1392 for ; Tue, 5 May 2020 21:22:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1306720752 for ; Tue, 5 May 2020 21:22:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="vedzh/8c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729195AbgEEVV6 (ORCPT ); Tue, 5 May 2020 17:21:58 -0400 Received: from mail-eopbgr680053.outbound.protection.outlook.com ([40.107.68.53]:50171 "EHLO NAM04-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728584AbgEEVV5 (ORCPT ); Tue, 5 May 2020 17:21:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JkoBs0EpDKrn/TsTkZbUoB5S8d7q6WvMtKzqOXAKAD9xPESkAIf3dypV9xO8epHUzWtxxoyhCRirpES3v7375nvIO5DM5wTvWHw2Ii4rgdsmh8pPnQrwvWp2cW74hzHIUalAY6cSmRwyUxVVPWRoWaJDzY+fPaAYKCGoxNCGzgzx9ysIY5+SUl3QM18PkGZlt8BSRIAhiByo6cr3k82qWRxMay04GFpJKYbagZoocfy6mhzd/9DDwT//2vOXcH04OBh95igMJ1oo+djxHOi95zlD0ITy496WjzUeyCQq1JJxY1Z1Z0X+kb7wt6rAm035F2sw+k4lOwR00DnpZS7w8Q== 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=LRen4pFPZF/iqIIqXMSRdOmlGqIWpQk3u36Pdq3rBKU=; b=n500X0B+SsTZ02X5bygbbx0ouqdxWVp8Y8Q85u3j+9e9soQbYPxcLZO7OSSSOV7qauunksnZUMg0CZon5/HMbMyogGxN57XL2j3QqalDdCNqugzSqjCJelaay55HXMPqKcjcp7qPRIF230Oac8tmYHYQJHwxZmLGgPsOof0bpcuosqSDyEy+26eQXdrbs2Sb7xk73ALn7pDvJ0XY35X2n/s1ZLG43HVgGdPIf2npoZN5Cl86yCHgN89ZF59l+ZQYbk4CIysI9GTMP1jrJLLMOsGHFfuNxuvjuasF8sWTq4wtVl1xOTQfLy8Z3YyxJWoc7irqphWym6TI+djF3zgpqQ== 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=LRen4pFPZF/iqIIqXMSRdOmlGqIWpQk3u36Pdq3rBKU=; b=vedzh/8cwel7B5k3sHqssn79OJI4IpZgn01JNKR5AINrbcKCMMzPgs617vsCi+XG90nJsUt6rStl+smjv1Mq24YcMm4foFd+ZCo9fUt9jyYBtCxYgqmYQgo5iGZClAgDJrf4aZhIgWRwgVcoSYvuyzTDvWp41fPqUFX7ilxMGWs= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:21:54 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:21:54 +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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com, kexec@lists.infradead.org Subject: [PATCH v8 17/18] KVM: x86: Add kexec support for SEV Live Migration. Date: Tue, 5 May 2020 21:21:44 +0000 Message-Id: <697cbb9301acf18296b65bb63686b6c0d422e382.1588711355.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR22CA0019.namprd22.prod.outlook.com (2603:10b6:3:101::29) 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 DM5PR22CA0019.namprd22.prod.outlook.com (2603:10b6:3:101::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Tue, 5 May 2020 21:21:53 +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: 17b7dd6f-675e-43a1-a819-08d7f13a55a4 X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9SQKmArPcpvLceDNjqj2kamGeL0F9TTIZuqO/pI6HsU2kB/zC3tRh9Lp2U8VSt6NaEDpwfXpaal9tTb/Q21EVzaTOxf8KUJglqQrOMjVyqvFrD4PaQYKE+6HYnSR0IPt5qpgyjiBAQSiqealfSxMQJrFfrjvLTdLLY21rShNCfAPHo48vF5ntY9W1jhJ+8sJ7jhwFAwZl4+O2Opq/D05HjIFHVtR+ohzLKKvaz+2Zp7xz0Va6q6U6iYQapbxQeWF1f5RY5xVQJRLEI8J4uyGvQPXyJKPzq3FwIkihkBnRX4cGyAe09dD8lGd5aIxah1oyosbgfyJ/kDJZXAG8P6545QoFAuGq2EJPfh84ItRCzgo0ws1WUmfSYU1Z3To5LhkdWnGetx3BAaVfOGpBhbOtqkunJeGUpZwei6KLqk7jVdINLE/SFjPpESal6YjRtSpmoX6XvqcwJ1R2vpAjg6ib+5/ZjL8bC/9P1rYdjaNGlDC9RBC/ksWlQQshwj8afk5t+WgZSbe5w9dSPvtDjOpLl+YTG3UnvFjWvbT8icIhP+30khNr2owuMgBbVtJFYzM 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:(4636009)(346002)(376002)(39860400002)(136003)(366004)(396003)(33430700001)(86362001)(8676002)(66556008)(7696005)(66476007)(52116002)(8936002)(7416002)(4326008)(33440700001)(316002)(66946007)(16526019)(478600001)(6486002)(6916009)(26005)(36756003)(956004)(5660300002)(2906002)(6666004)(186003)(2616005)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: luXNGpqSXp3iI+YgYq05al6MSZC85f4OrEvGEpLyUCTHUIdJORgXjZetT0kEZ3DZv49jC9+msbRlB86Efe+jWKtMo/44GZtocITAx/4C/eNJgmooWxKTO1gvEwYGs0ac1F60jqdFcq6E3okzd5Hfp1tey1jDaSHQgI+D92X0aR8GLaTnW0gTXOiTj3IUws5euSJX4UbcMj81CUok5S7LQNFWqDwIcFGNBahWCDIgJQqlXDFvfLe/DJ6oEQYhNjQmj1/sAFGj3pHP/vCbWle4E+1i4I9I/Ldsg9Xqt12esMisctbDCYEDq+lhitX6zrZNAUnwiHBTqmEboS5OQ5fLq5do8geDfhg0AaKNpMdj8YuCabJAi+vkQv3VnqWAwdG29MtVO3aWGtZPdZWzrEOSUj8cv4L2l3mG7X8poUW9JqFb9pGQ7f5naHpHJGINbeon5+Fh9me0FN+O0KDPMcrq13Pqb/RHFih/dovY0yAT5g5aNHdQ8Gxgdakxg099P499nZmWdg3q8LvfJSiOBCqwVgucluR+Z1LqJGTxeuRYhD5TnQrYsBFehMd3lcgkc6R2Z8yXLWy8AYxneisZUtmVX9uNYG6Vu70rh5IkqWB9lzK/Li1lk1+NlLNp1ZgF+HLJEWZL3lg19IdHnHK4V0sCZ53R/vxmzpS6m1MgTgAGtgFe886YXhlT9WD7ZmbfnOm40nlovFRakwTL5YEP+XfM73x94Sy7l/VJD9pgZ7/YU2CWRAViftaP5Rvaa85YNdfTQbEAV5DJRmgyin3jvin7i53ek2p4JfPbqaQvztgk+IM= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17b7dd6f-675e-43a1-a819-08d7f13a55a4 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:21:54.5605 (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: u0Xj+Tg2M+yb/dLIO99F/dGxozVbBBMJnBOs8weCISMOH67FnyKDOXGDq6Zahr4lElHlEmEX3HoXGi1gG2V7gA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Reset the host's page encryption bitmap related to kernel specific page encryption status settings before we load a new kernel by kexec. We cannot reset the complete page encryption bitmap here as we need to retain the UEFI/OVMF firmware specific settings. The host's page encryption bitmap is maintained for the guest to keep the encrypted/decrypted state of the guest pages, therefore we need to explicitly mark all shared pages as encrypted again before rebooting into the new guest kernel. Signed-off-by: Ashish Kalra --- arch/x86/kernel/kvm.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 4b29815de873..a8bc30d5b15b 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -35,6 +35,7 @@ #include #include #include +#include static int kvmapf = 1; @@ -358,6 +359,33 @@ static void kvm_pv_guest_cpu_reboot(void *unused) */ if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) wrmsrl(MSR_KVM_PV_EOI_EN, 0); + /* + * Reset the host's page encryption bitmap related to kernel + * specific page encryption status settings before we load a + * new kernel by kexec. NOTE: We cannot reset the complete + * page encryption bitmap here as we need to retain the + * UEFI/OVMF firmware specific settings. + */ + if (sev_live_migration_enabled() & (smp_processor_id() == 0)) { + int i; + unsigned long nr_pages; + + for (i = 0; i < e820_table->nr_entries; i++) { + struct e820_entry *entry = &e820_table->entries[i]; + unsigned long start_pfn; + unsigned long end_pfn; + + if (entry->type != E820_TYPE_RAM) + continue; + + start_pfn = entry->addr >> PAGE_SHIFT; + end_pfn = (entry->addr + entry->size) >> PAGE_SHIFT; + nr_pages = DIV_ROUND_UP(entry->size, PAGE_SIZE); + + kvm_sev_hypercall3(KVM_HC_PAGE_ENC_STATUS, + entry->addr, nr_pages, 1); + } + } kvm_pv_disable_apf(); kvm_disable_steal_time(); } From patchwork Tue May 5 21:22:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11529957 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 941311392 for ; Tue, 5 May 2020 21:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 745EA20757 for ; Tue, 5 May 2020 21:22:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="BF7l7040" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729323AbgEEVWd (ORCPT ); Tue, 5 May 2020 17:22:33 -0400 Received: from mail-eopbgr680083.outbound.protection.outlook.com ([40.107.68.83]:13287 "EHLO NAM04-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729012AbgEEVWd (ORCPT ); Tue, 5 May 2020 17:22:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hVJjNCRCRdWZZYpJ1nhQ2HEwyEtvfNu5KUHjcIH9K1RiC2GuZwoq0EHrG+da3EkBNnsKi73SRoy9lB/cNxnSTEFTGyEGB6AKaA8mYrywGeaamgB79FlEgQsW0/fmJINUH8QOOkYHHuFfV1BCB0LMqdnPZBiZGkfFUfZKAF+h6AUYJgcKElG/t/4FZ7EHXAVC0kcGZTUkwtitM9tslo2sOTDIDGV20uRVbHriVyGr7sVqfmOzrQX6HrZ8lVFTLty80xEFcpN+8mWmWsjw40uQaTlX09CEDTxtKHLvE2V4aaZvHFJC6swoHip4jCxbc6QOkqajNzvaWfp307sjUBnt2g== 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=L9098FbS/ih6PujoFe74gEOURfZhPMlbdmUwU1cvULw=; b=D0+HeN0qwr6mtOerRcVYONay3p4yjXmbnYfiyi05YZsE2GVuYt6VCLQVhKE4uq6BL3EFcies+vUmUfCNFQQMT9vlf7FT79ZyNaiL/fzqf8QBC5uW6bN3PgeLeOdsH3PUX8hFZIS7NkxBWV2dPSAovWvfdQatKkEYJOY2bvUTLaROL1FJSIUuurD0cjfXfj4sSXs6202qjclO/XpPfGprk4WkD7vmUUXr4qaoT2d4Q4SQnUZuKuxM77QFeCCVjAlw4wTJXh0C6prFj0kB4xGmMlSjddEIUKl0vRAMamgDqcLEuZERr0ffUyKc5bde/cPzWDtLK492l++AsJDPCrzUrA== 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=L9098FbS/ih6PujoFe74gEOURfZhPMlbdmUwU1cvULw=; b=BF7l7040aFllP0Zoj759Rvr4oTg+HQzdBTYfKiW1jUWl0Zuv3qzOEzPaByLSXg5zNt36BGSh/JerzSGkbxYvQnNa7+Wap72Q5zE98k1g4GGq5gKazypO4wFA5mltSvL+yIqanxdrqt8vyIRXbGjTptm3R6HSJJUhyFKop3Rg+QM= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB2518.namprd12.prod.outlook.com (2603:10b6:4:b0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Tue, 5 May 2020 21:22:30 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::6962:a808:3fd5:7adb%3]) with mapi id 15.20.2958.030; Tue, 5 May 2020 21:22: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, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v8 18/18] KVM: SVM: Enable SEV live migration feature implicitly on Incoming VM(s). Date: Tue, 5 May 2020 21:22:21 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR16CA0025.namprd16.prod.outlook.com (2603:10b6:4:15::11) 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 DM5PR16CA0025.namprd16.prod.outlook.com (2603:10b6:4:15::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27 via Frontend Transport; Tue, 5 May 2020 21:22: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: 84ccae53-9f40-4866-8709-08d7f13a6aec X-MS-TrafficTypeDiagnostic: DM5PR12MB2518:|DM5PR12MB2518: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:372; X-Forefront-PRVS: 0394259C80 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MlmxByyXe++BTu6JcdeTXf7/yF8V4aioABz8YqmuEDDew2x30RtX5nPcTXudbo/VFP6ZhnKR+afGdezE2lCcbWa+OsFy6NuP3UGKxyhxyqDqzQa8inTRAz7Ghgm282UvqHkwKsW0anO6fuMSl/HK/q6rXi2JknZ+JzszERiMVU8qauVGg7YBaAkYQug/86WKosuxUohTYy11vk0UYtOEQ5+5THMVKsSrEI547p+2mh0PLP+NbNbigzWRbVcqBHN3e9NRql/MFykVQcAP/+XuBPgc9NTm0Ic5WCEJMxOqVwfKfvrSQ5o2bCXMwapwLDt8TMoekDYrDpXGIXIxYZIYlsIBqOIXeZsu5b2x7WVYtxHRrkK+q0XX05Eqqocrzf18Q4rW5FK9qvzDg9j9dhz/kqotcNfzAb84GQLcb3ct/zxpsaTJxJofdunMnax1y1ZZzyj37wv2cbHCSP0adiAZJ1aQrD+FoZCN2wFTKHdnjlnu5rq1WJT80+1zydy+xlSxBByBLVZp+83nyHSdrGSMUZI8LiHOyFwB1WLhCGT9V6PKy/10t0HGn7b2KjpKJJsj 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:(4636009)(346002)(376002)(39860400002)(136003)(366004)(396003)(33430700001)(86362001)(8676002)(66556008)(7696005)(66476007)(52116002)(8936002)(7416002)(4326008)(33440700001)(316002)(66946007)(16526019)(478600001)(6486002)(6916009)(26005)(36756003)(956004)(4744005)(5660300002)(2906002)(6666004)(186003)(2616005)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: coU6DRLgi07RTD0efX+TmUokISpYK6dXVvSI24mnlDlztiEdjpIOzk4C1+rN6s5/0ZXp3bDJYMHkAkQ32PvGkqUp/ONDy+kLwN+Eg2gYXuRoc9WNpuvaDcM4mQaED6wDumH6H0T+EOW0U1ufTunuALPVrMyEvE5ZPSYig4symnOyDrRRbh4fsUJ4WurNbZX1vG4GxV8uAY1j7m223DaVkKD0YP1Wxkd2mZbYCE+n4l1nNbtWxQKMlTEws1m5hMTAhykYjuV+7K5qxoBOtaLjOer39DmDfoVaisLcnN1PCCNJAIaQVnohBOKWEgS1Xo+K3wZSpFc69pJPgpQyyNRSXv1jojl5NoRMjkps4NoFTI+MPe+Entrb65PkVZ59xCzriC5WGVgD48Bgw6grf4KRMeFWFziMmrX86ythQ3PYxuj2BjGW20C+SY+l8Wa/0//HkaxMDlp65IhNkblhXUmXe1PaaACPCvqJwe7cXRIeimpIUe88J18IJ6Q/MRUwhcQ5DFXTNNFvHsGbP17OfsdszjmDVoM3VApXwgCjHWlysOQVqT8GxHqsFrFzArNLEQZTBXoMVFqlk6/PjTYYScfVSNgKkeusmu/YnZRv/VfwpdvyiNDEePS85dC8vuRVQ0CD1ra04o0IsBweZJ9aqaRRBloBfKtueKc1IRyQLtTBoOo+Lxkw+DypqaOFCOj+WgOJyZim0auF+YmEZ+KdB5Iu8qbup6IUSbbHxekpNw4CMj0JKLsbcnPO7ric2w1GOEX0Yyo5au2nMwwwJvFI3VwoFQZN1yykbCiTrto+su0py1c= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84ccae53-9f40-4866-8709-08d7f13a6aec X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2020 21:22:30.2716 (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: l62jqcMv1DGJEmF36LtbVBv02nkvRcqICJhYZY+ZEYFgTMgUI9Q+VtVL3MV249aGFT24Xck1VOJyOoe9ElCptg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2518 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra For source VM, live migration feature is enabled explicitly when the guest is booting, for the incoming VM(s) it is implied. This is required for handling A->B->C->... VM migrations case. Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- arch/x86/kvm/svm/sev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 6f69c3a47583..ba7c0ebfa1f3 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1592,6 +1592,13 @@ int svm_set_page_enc_bitmap(struct kvm *kvm, if (ret) goto unlock; + /* + * For source VM, live migration feature is enabled + * explicitly when the guest is booting, for the + * incoming VM(s) it is implied. + */ + sev_update_migration_flags(kvm, KVM_SEV_LIVE_MIGRATION_ENABLED); + bitmap_copy(sev->page_enc_bmap + BIT_WORD(gfn_start), bitmap, (gfn_end - gfn_start));