From patchwork Thu Apr 15 15:53:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D59DC433B4 for ; Thu, 15 Apr 2021 15:53:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31B0A610EA for ; Thu, 15 Apr 2021 15:53:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233939AbhDOPyJ (ORCPT ); Thu, 15 Apr 2021 11:54:09 -0400 Received: from mail-bn7nam10on2056.outbound.protection.outlook.com ([40.107.92.56]:15745 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231726AbhDOPyI (ORCPT ); Thu, 15 Apr 2021 11:54:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bDgXXkpGdpduBZ/B0cbxxiaQ6XMsfROOoDuZCKu6QS1fiLLKxUjR9j0OsH9lgC1hCwgdo4Tk1NQ9U6gE9rX97HFIPitUwg82+dg17A3ONM1FUl4FJbiMkpph9S5a0Aq4/Ohj5u3WJWaRc8/6yKHGuJM3Jk82t5loA+6JDxp/fBKaSOx6PDJ1j03umJJqDHuYUFR4o2iRs8H12mCGpzegSX8n8nYL8+FnmjtKfq8rKgiUXjIn7C7+I+0yyNLeQtF383COaSb5UDlKrqv63VtVJWz4u0o1cE7PuPCBje7tiC4gbRkNo0Pj0AdpCd9cHAaapKCdniQ8g8HQDWHNIQT+pA== 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=p9+vMxeGG/Np/pHxZBLItVNVJH2aLDUxgz42hCBtD2c=; b=oMSdzV4gDKpRhfmL9eXmwWWXAENhokaaDP5pZ/7coCq70MQYoDCWHAoexlZxDseHSLO5IFvUxtUPj1ebrNnr1U9XIwlVzE8T3MimUH0uwnZBNo0F8RS4S3MqxI4eHKIX0THuziW5qxxJX8FpMkd/R/QHD0W1FeU/n2XAZMuhHLMIo5Q8GVzhoJg5V6Ny3MiRq9phzg7dIclkbTMn1GhpHrjSHEVHmQvu6b03zRBZus4+ZuKn36MFB2ms0B5UTNtOVQpLKkNTKSwCTdzTQ/ppiLNVkIGG4ZBXFVOBI+2C5jI0D1uAx+KTooFdm9UqDhiYdOq3bqlXAsI6e44uXny+TA== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p9+vMxeGG/Np/pHxZBLItVNVJH2aLDUxgz42hCBtD2c=; b=wLJv50LUh4B4c8/U5pHHudjCzGZ8tITqZFxf4alLIA4w4e47lLsIV35qOy9/J+4Efna3ukGZZ/yitRm/ps3Qkv/l1E5AydFp7KuXOricwD82/cGiPXYDmpCbQd2jPNSakHYetcAzHFu221/Zoi+oxQgFlmkex+p+9Sjxj9X/ZdI= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4384.namprd12.prod.outlook.com (2603:10b6:806:9f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Thu, 15 Apr 2021 15:53:43 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:53:43 +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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 01/12] KVM: SVM: Add KVM_SEV SEND_START command Date: Thu, 15 Apr 2021 15:53:14 +0000 Message-Id: <2f1686d0164e0f1b3d6a41d620408393e0a48376.1618498113.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0161.namprd04.prod.outlook.com (2603:10b6:806:125::16) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN7PR04CA0161.namprd04.prod.outlook.com (2603:10b6:806:125::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18 via Frontend Transport; Thu, 15 Apr 2021 15:53:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6c671cd1-4deb-4c5b-20f7-08d90026a541 X-MS-TrafficTypeDiagnostic: SA0PR12MB4384: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wSTTGRjOmF9r4zGJj7IjvfNi0uhN/dBdA80EO3+UNxTtDCf7NbfhajhGogbYlrlnrgfjndrdsuucCI/menihmID9u3xULIcpHQdDZwunnL8KFc+rlMsRQVedT9LXzbpWasRomP4Ac2of7PtxklvpSeDXjRfzUuALzwIrb9ISFs4QK7xusmL545Dq4kP2hojG5sTo4uyRRtc260i3Fz43WJNkbrFwKzcC/cI5KGCTIE6nxyuxr08cwOv7+g267z4PfmiUiaMM2JNB5tvvFvkxneyc9FoYUq0Saautd0ceMewQ3dCJgLb4tJCwFE0NfneAUrEKPBLQMAhAIftXWujxrqL5gzf/I1Z3PdGmt5J2QbxuMxnya3GOQhfrKZoMsYTI0cWSOrs0wSeNs2LhdWHOqAkRBKCnKtMk/0Eta0lwqY8LZnKNDr3FQsvNYGEqIFgVWHHiJoaP3cb9KT8UTAdLNKzOIlHKISd6YUGOS8fLEPysvHQfo1ouK6XRQGs7zRnYC/dS09V40xfyuifn2lIFynGEyuKIKHxPn5QDZdW1/KwCjLZzSsWQaRqtxEWjs/hJorR7H103YwCI3ySJLOZEAp2XIU1QNxFTm9qQgREIe+W/s7g1l0ED85c6EJb3vgxgGUMFQqDdN8T+JUmkgmBXMg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(346002)(136003)(376002)(39860400002)(366004)(2906002)(4326008)(83380400001)(6666004)(316002)(38350700002)(2616005)(38100700002)(36756003)(8676002)(956004)(8936002)(26005)(16526019)(7696005)(66946007)(186003)(66476007)(66556008)(478600001)(5660300002)(7416002)(52116002)(6486002)(86362001)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?/+NMsKWNr6e0ghwuMoX2R3eY8w5Q+p?= =?utf-8?q?HPVbptvQkTpOrTb8GM/5ESCHNfQuWn4eONJ07OCYsK96sxzGEGd8zyjaYKM+zjlA0?= =?utf-8?q?KMyXt6zK6DlzRnQrXWJfMEb7So+W8eD70N2WV6odWAMpARqEYqIqwCsuOmG23nP4U?= =?utf-8?q?gBrRJ6DfAvGeBfpin3E+zvRlsmqdBt2ghX3YZ8EvZrl51lqa5q9iqbCnmfOLo0C+E?= =?utf-8?q?hc2zuuwmISKNGs+ATVFFIzWy2h3hsCtwR4ME7DDqCM+2fDHhGxu9uWCB/fPh10P4Q?= =?utf-8?q?8sllMgq3nDDuk4PNEnWeTFGiBf0nolkYb1zL84dslf1/0F0UD96pD5mcKGag3+AsN?= =?utf-8?q?mjqyY8Z75RZK3PH9/y2egrcQVhk7itfat1A7+AiS5hQY9xhowPSbKi4Uk2MICUXn/?= =?utf-8?q?eZ4lnu5PZVrHidPFXCbYh2+KqKEl3STd2utuDKPQuyG1v7cXroap3g/z2QOlbSp7l?= =?utf-8?q?/Y6YOldKdyiQn4zK2hGkXSphR6rymna3lqCMKZl/L8/w51Se20/PRNBDX9zFfhlnI?= =?utf-8?q?1pS2xmQMWH86ZKSnI+WsJ2Jo91ZJBBCEUHzu7uBNGkH+aeRI9y+AM6tFgR6eleyjD?= =?utf-8?q?Ksgae7St4i27gYcOIDN+pKrVrnbMGmID26v6mk6gkZ4Qh4k3cBPgOIJ+x1j45tqEk?= =?utf-8?q?UeBsx5v0rGwejQMaLGQIq+knHQi9or8PrJ9QvLgLb7uXypct0B6P9kCge6vPR025Y?= =?utf-8?q?PnvYSwSRdwdt1wvd7nsHms4Xs5MGuImsrLrhi2V5nL34pCZUYhjRWxpriYQNltxbD?= =?utf-8?q?mtlqcZhNWg2i/oluInyaSl+AbfiHG/DKr2+X+FyNmX/LnBzgiUAOZo8O+F6rJKWFi?= =?utf-8?q?2QtoezIs+pyEjg0lqoIdFK/MCUSHr2O87zlK91eBtof9HE4a3FV8714f7SfsqSoxY?= =?utf-8?q?Qq7tGMTAYo3TyQQjGuWZl1Dm/qsPFS8QIpfK8CyvDZ+gJrUXzik6H4Xov3uyZ9LXf?= =?utf-8?q?If13lgFLjC8oCyQYiqoxxRkzjSKvrauqDo0HEB9TFt7AlR21ROeRo8+RaPMxS5Obp?= =?utf-8?q?dNyelbu8BL4Y+zzog4Qk46ysswWSzq9tov8U3BVkPSfnT/gtNOsLjYms5CEPOMBoE?= =?utf-8?q?WYoJEq3bpbkVuq2HJI71tPQzR/xyyEX/o0k9PvRpFqfe80khQp/bt9lIjeO+SHxUf?= =?utf-8?q?zdEQpT2D+rlI521842hh3khgheQbtEHtnkVHL3l2kSPVC7wZYQzCSdri8QrszAko4?= =?utf-8?q?MvolN2L206h7q1iGkDc0F4WVmTC10G56lwxY22/0PI0hxNKDDz/G3maT7f0iWHwLJ?= =?utf-8?q?5qR/++Nn5kQ2aP?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c671cd1-4deb-4c5b-20f7-08d90026a541 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:53:43.3230 (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: 7XTjZAocLQtlGcEehXJXIM+mbV9YsBwQjCYo7NAiUeJVTPpMcdpivXvYVHOeqMJA9WiVR0KhwfS5hAB/RyLdLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4384 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: 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 469a6308765b..ac799dd7a618 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -284,6 +284,33 @@ Returns: 0 on success, -negative on error __u32 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 874ea309279f..2b65900c05d6 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1110,6 +1110,128 @@ static int sev_get_attestation_report(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; @@ -1163,6 +1285,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_GET_ATTESTATION_REPORT: r = sev_get_attestation_report(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 b801ead1e2bb..73da511b9423 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -326,11 +326,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 f6afee209620..ac53ad2e7271 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1729,6 +1729,18 @@ struct kvm_sev_attestation_report { __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 Thu Apr 15 15:53:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B895EC433B4 for ; Thu, 15 Apr 2021 15:54:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9798661152 for ; Thu, 15 Apr 2021 15:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233914AbhDOPyc (ORCPT ); Thu, 15 Apr 2021 11:54:32 -0400 Received: from mail-bn7nam10on2073.outbound.protection.outlook.com ([40.107.92.73]:60993 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231726AbhDOPyb (ORCPT ); Thu, 15 Apr 2021 11:54:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A74J/l9TJJBHU9/zIoBWUu5HI3GTHQrLRioLlO6aEzx7aDdfLkjMmE+9yz0t5qNG3CSYslFdfxVrcAWENhHR7omJ3wtFgtNaAECsIE1cy1eNU/gqlako8/U5gMcvbCls+vjyEGlH472IARdQRjpJtiWZTI4UbUFacvLfbRT5zwf+2MRN7joxmMkW2Ji53CVMxTndVH/kleXCn9w/42nc5P7zf/pXxxG6DW38rWKfVwhuT7enGIzJ0ry4p8/usuNW+9J765XyyiFbBSdJDMSGF0O/tZAvyclT1VK9PgMxw+Vdxd+ME2YYGm01Oj7HjJOYQRVFv4+E2MeQmAVNVbkkwA== 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=TmptNcWrK0Wse7VDXUmUvzb21xGh5dE1N4aXqer08gc=; b=iXyVBzhOkAcoP5LNGlzQXy4XlcGK6wU2AFt5Ukv6rUdJEt1Ufcp0cvYvGx4JoWOfvDLRQtvltoYdHWUxCxb6fSeRmQqcrbbWhtIJlkrvmmCDI2THM2q7WWjdxbksYKXm6wKoDYM6czzPimlg3GRn2ozXgQCeTsLeuTrnvcAT47OX5JUsjDqGbu7mOWYFmvdf3M2iOh3q523F+H0uscwBX99gWlg+6prTd7F98ba5l2k5C22+j3pYCKq0bruc3njUNrm66F1GDXCGu1RM+X+UtwaUfX9Gp7/Go3w4nTCLVohvOD2Pyb9SHJyf7cibVL1toNcuRfmqP/r4ui3w8lYkMg== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TmptNcWrK0Wse7VDXUmUvzb21xGh5dE1N4aXqer08gc=; b=hkI1q+I6w4mQ77SEdAT9ZgY3UWRnDbgiF6vJK+Ne9K85MVWMT4yAs9Uk3ujC7Xwa3VTgZ3rPNire3gSHpN1TER8XJnOToyPUe4+ofqnI5LyQlXBMq9+gAYyQMNQxMXYZTTylgih+37B6Oy2PXK1+j04GlrzAz/5QPj1WCfNNKDE= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4384.namprd12.prod.outlook.com (2603:10b6:806:9f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Thu, 15 Apr 2021 15:54:06 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:54:06 +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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 02/12] KVM: SVM: Add KVM_SEND_UPDATE_DATA command Date: Thu, 15 Apr 2021 15:53:55 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0066.namprd11.prod.outlook.com (2603:10b6:806:d2::11) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR11CA0066.namprd11.prod.outlook.com (2603:10b6:806:d2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 15:54:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ee5759df-fa0f-452c-95f0-08d90026b32b X-MS-TrafficTypeDiagnostic: SA0PR12MB4384: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uIeyPmAxjzCHW6Z61RNCCiP6cEVrzTPDWNLCWwaymb1I1LXdZMMusx4Y0Gf8pMoQp39+wKLNJlBqjbQ5dDGc8y8PDeHbPqqYqA4XCmh9VqlR99zKsbKdtfEk1RMRVg9zUy1XKITUWsRqje3IjX3rmVCfVNlCnQs+nIboRUC3JijjTXc8jrBl8FHVXY/fZLd+Hxw4fiuSG6WoNz8MTE2oCy7Wjbmx4CMu5tKKuZacVzPn7SYFXJw6BrUCUJQ03dzFoiujg8JticixkyPAaI9/NkGti8SijpgMsOpvMGwtfktdSM9ie6lhX+VY/uUkMSbRxUwS61wUFXHldRb9T6Womh13kFVTkU2Hq9xzeqiX4YNcnbduRi0qWVyFG4V+eQYMdEZeWuHksuvb6kta/aFa3dmmfHHyXgFFmFPajpjqnZOXUgUVaKupAnJkdXkwbFOxQg304bKN6uWtpnE1Zjby0J4pbfNi8vITjuVMcK5a8x2RtRW0J/HTZkxdtLwwhKLEta9f4bkCk1jyRW1OB6bHxfsS61Kknqg/NvqBmzBrifc02hDZd2SFsJGSzby+eC2rPzul+kwSW4/plPsubaACle5Qsb7VkrKBdz28Hh0Yzwl8w2tZJIP4D7emAEho9o2oBluAVuftmshoPB40nu65Uw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(346002)(136003)(376002)(39860400002)(366004)(2906002)(4326008)(83380400001)(6666004)(316002)(38350700002)(2616005)(38100700002)(36756003)(8676002)(956004)(8936002)(26005)(16526019)(7696005)(66946007)(186003)(66476007)(66556008)(478600001)(5660300002)(7416002)(52116002)(6486002)(86362001)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?He7s817nqUA9Br8nK3QCxDR0WOQzwm?= =?utf-8?q?izK/5vmxkBBEHiLFNqXOk5vto8YHwPrPTGrXKKO3w13hoSqjdWAl9RyARgkjh+bCe?= =?utf-8?q?bAjqYYULCoUlSfHOPu1vWXR18g7U6SnxTymie/CCNbc+SHlbDc92xiOdUd7fAgGOm?= =?utf-8?q?kTp+QAPaz2iNBpdqnWr1c7jwmiCkLpjt5nE2Nl6Jb/5Q+Uh8YQeiChKb+uVesE1O+?= =?utf-8?q?CS6xywPtfg3QABAT+Zm5iTkVe6gkB1Cy2gMHH8SvjtP36jSfMTeyR0JowP64nf2I0?= =?utf-8?q?Vr9+Kgw5wUduv8x2V+MVIyrJL80OpW7AhXtoOjnFXq7uHGrW8sNKuHVr+eHEj2jtC?= =?utf-8?q?q38Oh925sxWMM5MnHht0F85z6faaJUZFMlZfpi4vk+upVgePYd3OTuiqG6/4hthbH?= =?utf-8?q?spwUfygpljTgpSavV2Iqa/rA2mV0vcyRXuzozI22xkjxr5Lf/jEbQsipNFQfsTO+H?= =?utf-8?q?797PDGVgTvyzC+vY6A3XzR1TdfwXDbNg8KJOMY4FtQ5/c1JNNwFtAd0oWDxrgmltS?= =?utf-8?q?k+f9cKmMTfY61hRNMzzk0GoNsoOQhym6foQA6Rw0M3fxWwSQ19fZjlmqyvbIHh3IE?= =?utf-8?q?QRZKpCdR543hOwPoVXU21r7k9scfPjcrEGL1CWkPilJw7yjTj48NLNkSZ0ef0qjdt?= =?utf-8?q?wfkkmpzlHMUSWLGGvL/wwXLCFDjMJtKAD/QOwYpDxvc5LkO9OH4JrvsTHn3bgxSa8?= =?utf-8?q?pwLd79QxO3SbNhKstuBf4QerJ1OLjoxQ7p9ej0zB8pKm++pSbR2B619s1cFaWeYgc?= =?utf-8?q?NiaKbUR4U6sC3Pjx2KEruBc3PJhYuLYy+mJ1YLAebrE45RLdOUfePXmLYJYgyXAGX?= =?utf-8?q?AH4K/cXh1YKxWmoEVaLpqbvE4Y9AIzC3FgenNTi3XNijXtnHcq5hwF+mUFrpm/eCs?= =?utf-8?q?ueVXdy2PS7RoShtmIEFusePe6TJ2/EogBAQZA8c9PTci/TCnjFktFcyJAy7JEP6T9?= =?utf-8?q?Rz9RlbQtbEyH5g7qKng968IJhvzZTNGGhbEs5E+eDaw5Dh1X1Tbm0IPrrBdhIZeFQ?= =?utf-8?q?Zv6S0S6B3gh5BXOVJ5lJDUCF6vnCVv7/EhH53CtEwfbbp9dse73+cpQTKJPo4coT/?= =?utf-8?q?pYXgQhx8eH8KdmGvWmsAiDMsQeiqfgXjOTpVAV/Jt9P1sXRRCtNbkbAnxoS6+/i9G?= =?utf-8?q?rS0drDETuKeMGlCSdJpM7kJCS/5Y7w/pBuAi9dog/JsJUBkUZYkDQtPNU50Kq7tOP?= =?utf-8?q?1Yk8VfpZGBYt27XmwUNqgatkJk+yN6b6UTQTtxpAuR71DF5/BNA6GDLcth+nBpnof?= =?utf-8?q?Qz1rvAFVGAEFMp?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee5759df-fa0f-452c-95f0-08d90026b32b X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:54:06.6479 (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: k8BQlZl7CCBEpny5O/a+A99SReWE4O9S/tisSR25txggIlqlaLrFVZTvpZEprTPkIDHgVTdUHEMLWYoSpAG79w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4384 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: 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 | 24 ++++ arch/x86/kvm/svm/sev.c | 122 ++++++++++++++++++ include/uapi/linux/kvm.h | 9 ++ 3 files changed, 155 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index ac799dd7a618..3c5456e0268a 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -311,6 +311,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 2b65900c05d6..30527285a39a 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -34,6 +34,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; @@ -1232,6 +1233,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; @@ -1288,6 +1406,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; @@ -1467,6 +1588,7 @@ void __init sev_hardware_setup(void) /* Minimum ASID value that should be used for SEV guest */ min_sev_asid = edx; + 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 ac53ad2e7271..d45af34c31be 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1741,6 +1741,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 Thu Apr 15 15:54:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D99DCC433ED for ; Thu, 15 Apr 2021 15:54:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFD0B611CD for ; Thu, 15 Apr 2021 15:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233987AbhDOPy6 (ORCPT ); Thu, 15 Apr 2021 11:54:58 -0400 Received: from mail-bn7nam10on2080.outbound.protection.outlook.com ([40.107.92.80]:58256 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233369AbhDOPy5 (ORCPT ); Thu, 15 Apr 2021 11:54:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X3dtEnpxtFDyR8H65pFSH6g+3faofYuljlOT/VREeKuTZHy0kPM+H2KvuiUvp/QXVNnIIVQY4hh+RSGU8k2yUMMTvLtmrrSJV5mw7s5GKyRNMAnSDi4F6mQFCIwBmdBV8hvpixvsKQvF1wunhXIYUa2mLgsL8RIm2ecxOpZGyMj1XpZ/wh/k+lFbeUlv6Lbv9zweSfUgG2h92JM2oWN3lKFot7BHtfO1lKIj5wOVV429ItV2KKUni63N2r2VJSI4hKhWcMik3qDeo/LHektTMN7EVA/K2Ks0ekDD3iJhDiWGHZK7WyypLm6hJIMwt3iLhjFLiHaH8kgurf75RO+9mQ== 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=OoXsYPtt9BXmkmjz+xmowRRzJrV5xMeUKi1J8IY9VRA=; b=dgWbClRt0z8MVQuzLDc5ROb3KxRz43ukVqbG+GoMmTMXM+pJbNuaCft/FrIR0NqULaCf2JLQD0J3Ho2NpATg+98yYeibvX67FwVdfWDsMg9wgFfAplENoRwmT/sNoD3ycW9f9lwJWKJ6g6lqv10/y2wTBbXS7LVcK/9eEH5+9h/r0ZFNaoI1asRvJE1Gcaz01SP/eLwIEEjyJO/e8RbdDX5FrmNne/hVDeLwGTF14gulUeH7TzMXlqbiH0Swkdqky33RBX/Au/rXrfLXd61qNm68sCSKltZD1RqxRUC63jcfSkEuYAMgmCFkjHiSF2bpmZHly5A/42r1reiNO0EslA== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OoXsYPtt9BXmkmjz+xmowRRzJrV5xMeUKi1J8IY9VRA=; b=Z9f/fSIu0iSFB+tR52r1p0hHZNvIOHKNfdSqe8wYTyKXln8Y/vjqT5DYcmyhofQKafKy/uX6MYxcuPbJ3OGdvoEBKPTYj5MZFAJciPKuI7OItRGGtRbe4QuosWNZf+BjT8avTqaBn3iQQPwhAw4U1gaKyFwhH/1/hhND/294EXM= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4384.namprd12.prod.outlook.com (2603:10b6:806:9f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Thu, 15 Apr 2021 15:54:32 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:54:32 +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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 03/12] KVM: SVM: Add KVM_SEV_SEND_FINISH command Date: Thu, 15 Apr 2021 15:54:15 +0000 Message-Id: <5082bd6a8539d24bc55a1dd63a1b341245bb168f.1618498113.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0223.namprd04.prod.outlook.com (2603:10b6:806:127::18) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN7PR04CA0223.namprd04.prod.outlook.com (2603:10b6:806:127::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 15:54:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b0448f58-7341-4970-a3af-08d90026c2cc X-MS-TrafficTypeDiagnostic: SA0PR12MB4384: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E/oTqNgi3h5Xbomc4m90faWkBPrvyHM8zATlvHMT5rQDf9W30v5qSW8zcBn62Ns3KLA8yLaELW5uHqT0WWV9vFId9ZPcJOKrluEAy6DiTH7GXfp5ebz7s/ZcRP3GaNhx3kfuCqZWQnT8DLbdvm7SSGDY3uqSNK7h1IADfSN9a+R7SJKhGxj8eCHk9+l5PXZYgL/OpesSkkHYz/f1PsmaGiM2t1+pTTfiOX7sFPoB+XghMepayWBTaOeB63xuTDYn/eRqEOtHhq7OxRJELSg1sZxpVgVjPc5UZ9toum7LMDMMJJG00h5r7j8hR1zrpZgzxxyMMgZStcUoHFQK2zsnkIShkzk4OqRmJTFGV/Z7oKqJLWVQqbkAYNYcCUuSn00rsPp/6ApTbmZkEA32VL48/cmMD8EQdBc9Vjdi817RJPL/pg74dRkXhoaQqlnuaRgIx4dOGKjfgvvVk5Z662hMAcLHVvCyVFKBREW8qnNGbmfhzwxhfZvzP7jLXVRhH566+F1LhNXoy7bwfsvEyoClofiejMicJVXxPjt1IBMN8KXtEUwwI3B2wZEN2wCedc+ShWeUbSNVzEa3iCM/vvTf0eZttWqGTbggJpvc1mERcTD+s/4TmBr6g9xACEs26u/lZIbPPlyjzTe0Xg/ZDk9AUw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(346002)(136003)(376002)(39860400002)(366004)(2906002)(4326008)(83380400001)(6666004)(316002)(38350700002)(2616005)(38100700002)(36756003)(8676002)(956004)(8936002)(26005)(16526019)(7696005)(66946007)(186003)(66476007)(66556008)(478600001)(5660300002)(7416002)(52116002)(6486002)(86362001)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?ijmlbXB3IDw/i+V9PHUdy+Of7dTAQK?= =?utf-8?q?ItYBpJI0vZ//wK5V1NgUl3KuHzqSv2x/p3TuWJxuOE+t9anOrKF4Jc62jv5e3Nr/x?= =?utf-8?q?URgqGNfu3KATauWICA1NmpT3rIMVcNWUi2gNOk9idP7PCLUamVIgcRu0NlvA660Zb?= =?utf-8?q?4Iw15isOqihB7Md2wtroqGWn9G78Li+sbbpVe05THCyXdSjdfXhJ0yBAul2yFV58F?= =?utf-8?q?/lFbzvKYaCMoqzsyXkvn/FZ11Bfgq/O35uT6rbhIOuT9pI86epSwX9ytacXc6H6Nu?= =?utf-8?q?mR/oUZoVss3YfP4f8JIlyeQQt6l6JgKhfqKizmfMJhEJgc33rPYEczU77TmbsWu4c?= =?utf-8?q?AXYiDojg7K5qP2oYKO+QK55gV5yLTuKlMZeZdM2SCBHVEaEz45zyaG/CsduF7sjiJ?= =?utf-8?q?alXAEDbSm6AnqQMTySP0S1RdsmAyc4DcCEwaBUQPGew8efzEZG7XkB+IvEt9PyNB4?= =?utf-8?q?YoGAI2zvHqZPW6VN+oGuNGqsCqGjJSdnd3wDnyDLy6Yq2ei48ZmROPXDfnkMwDi+z?= =?utf-8?q?rJnATltc9KujX6p9ofpLFJzR2tTV3z1iWQtlVv9XTzQUJlVgyBNW26wMSZzzKwCLo?= =?utf-8?q?xSQ5AytmhTfvQqOUwsSkd/SwFQRaZIWDNs31BeVIY06CO9vQjmONm+F3tHuZPaELX?= =?utf-8?q?1Z1iRVh8sH2mcxN1PPv1rstplue4OlFo+VhHT8rt4UsP8rglvNgkaztLtSOICWjZa?= =?utf-8?q?pxX8AQJUz4t5X4cmVKuM7i8NIc3ycmt7Xn3QfhbQC7DmSQKBMnpopKrl/2OUFV92M?= =?utf-8?q?FvmcLGQPuBFtE6hb6diTce8RWlWAkhLfXLCQzw4jUPAIU8cFZlrSxhBsJ3iPju6CH?= =?utf-8?q?2gqV5LSkoKZFOt/GLbR7GpUJHrnG0Z1Q82yAIwRSPHX+qlJ8WOnrLY9JzX6JjDoD5?= =?utf-8?q?Spc6JZStPflgK425duJljqdaRKtKSDcL6ZBRDoiia72vW74P2F0UKQC9QC/xyOCFw?= =?utf-8?q?mPsiekBkl19t98hhIX2YkUoOUOI89l2VsAPregDw9V8luM98gWWYqk/4fJemdpEXW?= =?utf-8?q?Ybp04sowSg5HzkwOtd+sYP7lctF7Ep4hnjcZlspxhPxi1fnGR6qepOQBlpLKE/O1d?= =?utf-8?q?wmajiEcKbKn70YLFuuc0YO8+lwsShiP/nyF4dEuieFnsJ1VZD5DG84SvXcJvfr02z?= =?utf-8?q?1gLiGznL9b5KCQYal6TKEV1Yomqg+U1ZLh0K17dRRAwnkNB4M09BmFOYA5lpf5nn3?= =?utf-8?q?KheKlm0cFcfX/msOl2K8XyF+xPZXIMfTTlp2nJbNdj6n7DABN93KZD7Mx85uf8oFd?= =?utf-8?q?DkosVMHFkuDwMH?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0448f58-7341-4970-a3af-08d90026c2cc X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:54:32.8213 (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: fN5VjtUkQyeVrOy57GfleTWx1G4mtiqmA5/l/lFY+/I8MscXz7UEsJIiG7ZuhoW9XbMqecGMK0aARHhsfpRv4w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4384 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: 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 3c5456e0268a..26c4e6c83f62 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -335,6 +335,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 30527285a39a..92325d9527ce 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1350,6 +1350,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; @@ -1409,6 +1429,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 Thu Apr 15 15:54:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96CB0C433B4 for ; Thu, 15 Apr 2021 15:55:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C9FF610EA for ; Thu, 15 Apr 2021 15:55:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234037AbhDOPz1 (ORCPT ); Thu, 15 Apr 2021 11:55:27 -0400 Received: from mail-dm6nam10on2075.outbound.protection.outlook.com ([40.107.93.75]:28384 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232913AbhDOPz0 (ORCPT ); Thu, 15 Apr 2021 11:55:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GnLdlQOKjFTGxVhIZfoU2A5jTaD4FFwQRGACnJCQyWUcFCGiWruvp3WHBhgo5HWKHRhtZZrK6PmdfJ/GhYTB/pD6u4yXAaCliFJa4Fnmp6v8V3V8cHUy9Cc3EojlAHYgSajHX8KJgxaKmO+7hhuZUIJBw1PIMlWkOQgJKs4Fd4b/L30652R6lJitYk91T7RxR3Z7NhZpHvF6CKdibdhORCzibzqe3gBL7tDoxHRrDBIo7C7tIwG1HB5Hixk7rXdjC016R5ByAmpymzWxbBYTZq+8/qHO5EWkQM6z5VOFOjsqG6/xFzAWKplaRPpgSOOgjEHyJG0eoBeWS+qxiQBksA== 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=UL+lHwQVytiB/W+Txx8qhIcS4kg9BpXMgb/clYt+Co4=; b=KvUJ0FLejOqP31PaPWvktplZRf30sdy52OQHfnkjsJKj2bjz2nF95uDbbmKAerj3zV93Tf16M4y0+jmh1CusnXGz1EsG+yAiXARtn3iRflRWJUbejNLBXmF0ioHhzxgOk84wuLGq3bvtAwHJdVRh3oeJxdmQ6CftBIhdoS5EQusIkEvWUQCsoF8A3ry43MWkxk8MfNcDHtLkucpXwzFLtoNfHwqd3aIIw1YgPDTmm9IjPUVBViPB8nN41LWKqGvZwgYtMRmWv/DTPFCkB0j4AKyyJnX/mWytmfcCnN3ungwISj1Uw8tNKA3dQ+hRgVVVj3ClKysUpH4OrOzc4W+NIA== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UL+lHwQVytiB/W+Txx8qhIcS4kg9BpXMgb/clYt+Co4=; b=KlRW151RXOER1v6Tw/JDrs+1MEcSNJemYzLTfFF4Wh8/hRsktQU5ZGCDOQcaVK/frUhuvthQDBPvECePz/tjRh3y10J8Drzg/R4ny5rP1LrkTFHZ3gRWAvzLtS3FxzursEX2l7bFna6cOy9iRlkfPTkZNkHnikaTmI6t5gXd5R8= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4592.namprd12.prod.outlook.com (2603:10b6:806:9b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Thu, 15 Apr 2021 15:55:01 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:55: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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 04/12] KVM: SVM: Add support for KVM_SEV_RECEIVE_START command Date: Thu, 15 Apr 2021 15:54:50 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR13CA0008.namprd13.prod.outlook.com (2603:10b6:806:21::13) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA9PR13CA0008.namprd13.prod.outlook.com (2603:10b6:806:21::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.6 via Frontend Transport; Thu, 15 Apr 2021 15:55:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7c499711-96cc-4b3a-80a9-08d90026d3c6 X-MS-TrafficTypeDiagnostic: SA0PR12MB4592: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2331; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yeBGT9I+dG6v6CwetAVF8URw2ionJyHbHwvaql/7mEkh/vnlFgkhEmi5IyoxjwhfxgWXmww1LfjA+HHvyHyVHt0elOyOMr2d2ok9uly0zbRUSCWHhF0cMxBxyZ1y5EoCVf+pATtpTr2CTkPy7rAk4gjfw6U4kPflwpVRLKtu/T2GBDdam86IOqfsCv/mdoJbInRqCL3A1fij/mS+od/hSVwvjlzhB8/4AM/j5avg9vtTGHfZe5FDhda+RohJ0Hus/+j9M/2FXdJR/uedkICbM2XUcnZ+iU4T47ogVsncxlLxT2W48FBddT1Ouhok9ostH4qcMi7e46GU0LQcK9uxFXcJ52mIHkE2jB87+xh22fzHa7TYEr1VLU83bZnULzVlA65toX2ggpxsoKCLqlmWlkrYkswZDP1wDwSbwDKQ9XnPQHc008BHjBnst3h7E4zuNXG4wirNS5upX+z8iw3PPvIAP008q5txs5Hr2EZH79+5Si8yX8nC6+DbZbs9LcR5r8IttgtvlBgSzVoxA+CE8q16BCyKO8E5g7nfFCsdNBwF7VbwDpmCJhKKXbLleIQbn5lNx3x2nhV9tbhQ3D5w6y1PaQcW6H5JHX0Hf9crhpBlfw6paKotDUtu4NHLBh9KC0qsw+nalRi5+hB/546cYg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(396003)(366004)(136003)(346002)(39860400002)(5660300002)(186003)(26005)(956004)(66556008)(16526019)(4326008)(83380400001)(478600001)(6666004)(2616005)(6916009)(38350700002)(52116002)(86362001)(36756003)(7416002)(7696005)(8936002)(66476007)(8676002)(2906002)(66946007)(316002)(6486002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?uFNt2O/NeF2qvRs+bl+m0fmlyJkped?= =?utf-8?q?iYUDojRjiZift4drRNiShfr2dJwVYaoE0kZjjAbUUnRpDdg8Tx8DbPshWNO9/Rt9s?= =?utf-8?q?gmR9OPFymN054SO+p98Zb0MkgSXDacLKibjM1MAhgib3vOqUAvBNsIWuasbY6Ppsk?= =?utf-8?q?RAQ9fC/S+qf8ARXPS4ktzT0OOvHAzA+slqH5rOvsc+eIXcencfHITqHEgEuGectcI?= =?utf-8?q?rJA26o0t/1UAwcAqDoX403UbCxKQcv7eO7PMsDRn+NCbsgCqd8j+7higWGr/OVtiQ?= =?utf-8?q?e8NKMXgYXoLcjj3nihtG/lDTxOHmT/PQHq3lT8hlb7bJxLvF3KlMbpofgdJDZ7F8K?= =?utf-8?q?yuaDdklkAfQsv/x5zmmCDKQybuPqNBFZI6gHYHSVxjw5QoueEiVUQp3NBRWfHA6Nd?= =?utf-8?q?o4N/3Qsm6KaquugxKyR5n6TJT7iJmuKkkloIkjeuvDad9xPWADp/FjGQ7j/sEz74f?= =?utf-8?q?VYhvsPsPTzwmz9RGClIY8KcAG+uuOegvlFj9kRckLQcunXoYFyqVs/UILk9QlLoxT?= =?utf-8?q?elQsQPx71wBgXBIefTbdMJ607XdSl0Uenz/Y34I04kJ5o8i8lS+4RbQCO1XYWqOxF?= =?utf-8?q?o6faSJHa/lW6x8kQvyBcfYGDtjNoPelA70IC42/UyRtn71CzSarw2Xcbdu97zbk4F?= =?utf-8?q?7LzWJulVhlhBJrnylExi1cDIHE2451MIplPFaBFc27R0aevUGevPzUjpjmRgI9uyV?= =?utf-8?q?9R+86Xb35r4l0rrFUO8wtWUp6Nq1iyQ/f0idGD+WZlIVd8F9VcNi5+VwkOuC74ccv?= =?utf-8?q?SrCsrKS8WRO0SYvORgzGWvGivxvn5lmS1C8A+JaEtkDIyZEpjW1ViRTUOiujleZiY?= =?utf-8?q?nlwZKedYDi8lv9zcHcS2z99BXrWx0GwEo/VqdtQGBtVHbkx3QdfAvfIzFynEJUE39?= =?utf-8?q?Vkd1tIkJYVdQVc4Gh/U+owVNlVG+fsbIwvERiBFzh7MMgtkCB5XnDbWhfqm6f9dyn?= =?utf-8?q?5UINxzJ+ytVaW/tqQbZ1XvewOMgxJbZGaPbzoplFFeYoNkVB7AUdU+R8cXHIG0Yi3?= =?utf-8?q?tiXzwwLqeuq1rUaLPdjg4i4L4LwO7W7TyDS3DF4Pc/WZ44KtfOVHejmcEar997uTW?= =?utf-8?q?AclT7sOeU/uWzPR4fILjvUOi3evUfVWfmR/fw9DmQCj29nzmggiRJEmedXknUwc5I?= =?utf-8?q?mf7IB+7clpLRl7+gxCVfhoSj2EGbGTqgpKj4StHYRvg8rcmAf1aD/s9m5hsmRokLK?= =?utf-8?q?7lL7AtMjEmbGIDF8RYRTKAblUjFu5eKykOm2dB42CMstTCd6dgKw5aL+wVJZGfSKw?= =?utf-8?q?AmIlRT/97W5sFv?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c499711-96cc-4b3a-80a9-08d90026d3c6 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:55:01.2564 (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: z2pY1Yfn9csqslUIAxvZE2PRIx7UOCpNdsxpTps8Nw2Irl7VrqYO7gCzPkH63Fm82rdpcoko0voUTY4mM1hy4w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4592 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: 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 | 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 26c4e6c83f62..c86c1ded8dd8 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -343,6 +343,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 92325d9527ce..e530c2b34b5e 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1370,6 +1370,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; @@ -1432,6 +1510,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 d45af34c31be..29c25e641a0c 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1750,6 +1750,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 Thu Apr 15 15:55:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93E8DC433ED for ; Thu, 15 Apr 2021 15:55:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 794846117A for ; Thu, 15 Apr 2021 15:55:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234150AbhDOPzx (ORCPT ); Thu, 15 Apr 2021 11:55:53 -0400 Received: from mail-mw2nam12on2076.outbound.protection.outlook.com ([40.107.244.76]:35297 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232913AbhDOPzw (ORCPT ); Thu, 15 Apr 2021 11:55:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KJ5hUrANdMzAngqMGctkBJ6BvUjltc+9Kj+oSDyAeDTbEhRTWxU7XO8jUR1b0VR6G5/K41FIyynEULwsSUztPY177KSLltavteACeChIMXK5Mp9El6hlf5/aPrBRuK0MYf4qKV4Xa6YgkV5B4q9cI8CUp1WzOOs4UoxUzCBo/jL9VG+OAue9En4b3ZlsUgUYUP9J9f6r92pCDAWWNfOZiVvWprOIERq6eVQ0Vv76mBwDR6PMWPhgNtOPDaftl94RsC3eB67JdSGpTqeq+WJaZVWJXhD2dhdSJ96eih5LfEZywAsZ/Xw2Lg2RTR4/I5q/YdJcpptRRywWAbjhavuFFw== 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=wW+QIzgm47mqkBj6KHO+72rt7qHzdoxmlba2LXIzqI4=; b=VFQIjZv8stMf+uFgBFx1EAf9WJ9QYP+vibKT2nRVMj313acoKzTo/yrOjf5eGbcfu7+P+k3Hzqv2qT02hbcmXt37YIgVMOYr/gUJkxCoP5H9FxXt1shf31+NIkzKRS23vWKRbvkFhQzC+V5adJuK249jaX1/EcRQNiyoqmqNR+dE95pzU0ttnPYtaLrkWEzfjC3Xf0bF6RHpLEgtTaN7PhIdmKVUxapqvkL5gaIuIbNl7Kvfrvt8pak/6mYcw0pE0sIuqYOZehrcOZLrhrhfYG0iMwUSIjAoASs6AOd00ZHNaBJV/gn7FfwPsTCvPWLKFyhlPJCxwr9XAjRump/EqA== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wW+QIzgm47mqkBj6KHO+72rt7qHzdoxmlba2LXIzqI4=; b=h9JqXxr8LAxgTZE8GWP1ixgHxbi70gTDsdVSU5oyDvwzXBQAWVycT3LVQwhIXNOd/9U3Xg5lE4wruqTUdNOBmxzGf67w+bAcWu5MssFLQSjpMa+wkwmJJ2RlfvogA4rf5oTTz6ksWV9iPgeWMngQ1XMROF6mhbOWz8bsIABPAfU= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4592.namprd12.prod.outlook.com (2603:10b6:806:9b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Thu, 15 Apr 2021 15:55:28 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:55: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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 05/12] KVM: SVM: Add KVM_SEV_RECEIVE_UPDATE_DATA command Date: Thu, 15 Apr 2021 15:55:17 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR12CA0015.namprd12.prod.outlook.com (2603:10b6:806:6f::20) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR12CA0015.namprd12.prod.outlook.com (2603:10b6:806:6f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 15:55:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eb54e82b-548f-41bc-2f03-08d90026e3ac X-MS-TrafficTypeDiagnostic: SA0PR12MB4592: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e5n0diah7fxcsljFicy0GrvQIoENZrmenfI/QM6cUYOyHujGPyg9pwrppo8kgTo8rzkUfKTRfElUuAoxfrqYB2zLlBLz5vlmH0HV3pm/IBcORBTWwOzlOty/N8yU4WU8aOsH4T9gSYLO/syTysnaQHdMT1pyOkAjIbjYMtIaFlDTOkFBKXwjPZa4ftopvdQdiGVS3wiFHqzxcNVUSVAe9gw8Y0Z4wMHb9eOfCgOE14jj7jNAXGS5u9LlTTicTZr4K7c/MNApXVFR5moz5I3++AMTYYDIGBl//SIaJbrg9DRE6Qf0OcqQIEMlvxjZpWF9uugqreVwXMAyrCIkYYhRrgDsh5vhhpkrrp5rQ0AyWalaw8JvGEBK+m4kFdpZKm82j9aOGt6X738AydFt8HyogGOigqNnhsBgRyRDW3Kl1UZCpj+v/IttRsDWt5Lcb93OGHEbgD8yY3k6l8xuchl45mfIDiMmlodKAbr61vQYgLwYOqTWBMBfFa7ZoBuXHro18OL2+Gfgy9EhCwS/SLmdXjAGxCDb28UAfvf/GhpQfCQQJWwCg2lwhPbLEiv4nPkKQbMuPPU/fpBP2ACAiVEcNl/wnPtoI/PwLg5YSXczIuE2XXjBC05+50wHxV6F8BGLMzK+0X1T/Zov8vHnCEACOA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(396003)(366004)(136003)(346002)(39860400002)(5660300002)(186003)(26005)(956004)(66556008)(16526019)(4326008)(83380400001)(478600001)(6666004)(2616005)(6916009)(38350700002)(52116002)(86362001)(36756003)(7416002)(7696005)(8936002)(66476007)(8676002)(2906002)(66946007)(316002)(6486002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?C4NdRGSHmSXe0WaHWL0tZdziveqwOf?= =?utf-8?q?oUbqN4s9qYTdnE0/GYa3JuNp5a6ytAEsvjSk9o/UOs4RF2nj5GM+Mcm3i9LvYtHmw?= =?utf-8?q?PW0JfDkfNcMBh/DaUWCUrP+cDTF7Km27vwqdalPdydZ1bf/EELXRO0MF+JCM8OBV6?= =?utf-8?q?SwadWiHUBOexTXO95OQ6pbqGSYcwDogmVSEvyZfX+GhIX7saNsfXr3qaWTMxDXnb6?= =?utf-8?q?6lJMuHlV++ewCt0COorwEJJ6KC0RD1T6JNrCYYSoeWJ49DkdlVSQ/TVSb1GxzYlYy?= =?utf-8?q?kNhTw+CEE1TOP5buqsM1MRyXVcmIq2Dyxrp9Ljss/PMsOJFEg+S7qB0P3nWxdaVul?= =?utf-8?q?AkzZySFvN6BSgilfuRcUu9r/MKBKoWscJAK78ymw1cOWUmIWKalYQCSjqtsljbz7C?= =?utf-8?q?fIOtcy/F9efMiR1ckt58aKvecxZFjxLjRoACptTmcwfcgqK8BcfJyrRs1qumH/Poq?= =?utf-8?q?2RV/6JipzC6sYRnQosCOEkYYK3nLU5MDhFylxnbDCC56UZuA5fewOADkVo3cSPahy?= =?utf-8?q?FcrXyklBmWEJFwMucrljkVDN/NrmCVjJkWDg3iU3cG76ifreELLREQexj5iMRRr1B?= =?utf-8?q?r1llt1Cnsjc0hCRnFUpOOAcZNZAkKW0+GuYHdpy/y4t8c7aqOLok45KpHhBquNMNE?= =?utf-8?q?WqNfLyTyOItgfoqNYqVm6nQ7REsujNN/eilS/IeGD4sQjRS6NgG5tO2Ij6/P2fvCE?= =?utf-8?q?yPEp9ayvGsGfS60sP9/aWDY0yZC4r87eyXX3fjIjj3zx8fdYIGNTJDQ8LqobeITXM?= =?utf-8?q?NbwyhZkPUh2hUZTZ6FbNsFNdpOkvY2Gf9JDpLYhJ1n/wgZ8ns9AcPC6Pzrw9S9xHM?= =?utf-8?q?MgE3kaGzALgdwLAqdqLAZE3YnjbzMYbFpRAVIsI2ebCKNVblcg546vTj1JUGBkz6K?= =?utf-8?q?fiFciegNQ1DKJ1yC83MqqY9SK9GvCSQvLKDRJgDgjJn3Ph2l2foNscpMXRu/E6e7N?= =?utf-8?q?U4thqWqAb9lPy8fMukLh8WGhGnuxVVtPJOFWLAuSnFbXzlFOfkBnfqBPjOoUzigpI?= =?utf-8?q?Q7xrfeca2ELDG4/R+ulZI5gwu06ccyvB7kuDacX3R+zbnHrIK4DYKoBrMx6DFA3C+?= =?utf-8?q?19McvhfNDmCOgl3Si4h8qgPWX0cx/j+X0l1I4Knf1qG82cji3cjqoszXyIStE5ezg?= =?utf-8?q?t6dxAJvwokSU9rVLoRROkMMOwOsn91Io0g4V87SMjSI9Qk/VJICSbRkirLbD3Gjhj?= =?utf-8?q?RZOMXJmS55xB3UHepgm9PvgbKAVjBVCM9VoA0tYiiWDt7ym+34bAPTOHyYCzQjEwd?= =?utf-8?q?fHk83Bo2IYT+7S?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb54e82b-548f-41bc-2f03-08d90026e3ac X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:55:27.9474 (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: 9Rgnxx/KYQGCxUudYk0okNIWaYMAVlSjR4L7/yKtTA/NdImmLVCuVvPvrJcQOHEqiOkVEzZie3bJY5sXoLqJhw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4592 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: 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 | 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 c86c1ded8dd8..c6ed5b26d841 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -372,6 +372,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 e530c2b34b5e..2c95657cc9bf 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1448,6 +1448,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; @@ -1513,6 +1589,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 29c25e641a0c..3a656d43fc6c 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1759,6 +1759,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 Thu Apr 15 15:55:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A21FDC433B4 for ; Thu, 15 Apr 2021 15:56:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EEED611AD for ; Thu, 15 Apr 2021 15:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234184AbhDOP4W (ORCPT ); Thu, 15 Apr 2021 11:56:22 -0400 Received: from mail-dm6nam10on2055.outbound.protection.outlook.com ([40.107.93.55]:43488 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233682AbhDOP4U (ORCPT ); Thu, 15 Apr 2021 11:56:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cqbg+AQUv2gxFtXoGr6mUHetlpKipqBOeppq4l5aD0Gl9xSft7ffarx8wzyNE/vdAAiE5ue7ECetccFlt0t0+FE7J/gELtycwYHLPD4OsxopJPhJeHu/MGT1u/kIYTb9NRUzCkd6OpMyAExcl71JhLc/uT4oOXHhX1R0uCqu0FmH+ib2TYUHcr5GBcL1k/tWyyxNFS5M3gPR8Til/3TKKZ03bzvIZS0lMk4gbYyqsr0hfL/xCR9qXAKB++NEwkkumDSKG8EAZNgAJiGPOiIPQMfTCCS/6saRiqS/JhB6JyvLuvWTDg3qiv/Zp5zzR+1HeWxEq5IsXQAPnFJ9awKZdQ== 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=ecWJetWk79BG8nSoPDpZq7XRRwLaEAjNQ7SI2nOsNIA=; b=HcKpjcORKmP6PZ83FLEoIOEId7xUpdpDwkR22YyO4SLqCObhlwKMpc36CZ9ePcWZJP8ndGeCnbcB2S0WcObde1Gvfg5dK3fQho7Usxf56pe9VqIuoDRGzIqOALZl1Eu017LjugqfpWQ1tBX8E8SA0V2xN5cerEcrAiBJrIdJe1NwzBUJsTA+FnWRrU/RWzD1rEW9jdlUtuWwpU54GBx6NCC22JWWbvQXZ3L6pkNxqhvNbrQWcaD5rxXb9qAyDMyUexJ2FF8E/h2ODUrPisjO39PhMDR2RKqtV22DG7IgIrN03dnsKiWyHg9XMudOPzqJaEmwI4Ft8YNTYX87+XTOIA== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ecWJetWk79BG8nSoPDpZq7XRRwLaEAjNQ7SI2nOsNIA=; b=M+PaGQG1dDVxPXCzCjPtWhamWXPvogHZTOhQ4D1bnsrRCN5x4wkCt65phWEul6O/1FpdRYo4ECIo+ChK6N3V+gPMlM2ElA5yWOpPp1HGbYjlBpqe7jhhdG/rcrO2B1iMIIK/jw1owwqjow+d1u0u/4IjiTHozVmKKtqtFZ/lEt8= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN1PR12MB2510.namprd12.prod.outlook.com (2603:10b6:802:28::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.19; Thu, 15 Apr 2021 15:55:54 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:55:53 +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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 06/12] KVM: SVM: Add KVM_SEV_RECEIVE_FINISH command Date: Thu, 15 Apr 2021 15:55:40 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR13CA0051.namprd13.prod.outlook.com (2603:10b6:806:22::26) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA9PR13CA0051.namprd13.prod.outlook.com (2603:10b6:806:22::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.8 via Frontend Transport; Thu, 15 Apr 2021 15:55:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 17b18f70-3826-4222-e926-08d90026f2a0 X-MS-TrafficTypeDiagnostic: SN1PR12MB2510: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KKGtURmgn6Z0j/WfgtwFW8rNaytzDVZdVEcRnj+c0Erg2LPM4mNY1d3QufdAp89fM1rofFuEjm051FfUATdzVfL5X9RnFOuWSneaqCJLh6QGawzIgKUzaZ0TLns/E2lvSjDn5RIASV/g7numen0kufqYmJafl7/xdlRuff1Fo2B/qf8MEGqQVGP8zgXOZ4hv2KHeduIhbkp/o8oi+t2ETPbkvVN3IaLLcFNa1oiDHD1OC9zmbY6XiTAowgzzNgSoCYr4Vm7Md/HyHQFC4GUJvQMJaEQaL9TCVrI30t31PXiPpM4ResjVVNrIGmK9kRV0Z0wPfHd3QPfcxBRi1Xuyfc3TABnqKlj2f7Qt6Ze/Y8wRAGVgs2lCp4QMYzbUFlJUSlxmVxMvORdtE3M88ReMDU/IRZ7zOFoTn4Yhi6EoLjGbyLNLfsFoT4K8CWBVgw03F4PDFzNjK1tZxXoGFsKftTAbafxUcmPJIjfeNwj+o9FKB2rCWXTOXqEgsfi0NczfOU2jjKmUv8kXkaZIWljiugb2ht04N8+wmvSjkhrFRqQpApKEZQVQuWifyJqaVtzzaa3lxB+Z0C3/KOGfUI0W5fzeYtTgkLip+r3P7q2DGMEy2V5LHP8iqgbumno0IIg2u6UiDxeZrKXh11G8z8q+Ig== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(346002)(366004)(39860400002)(376002)(396003)(5660300002)(956004)(2906002)(4326008)(6486002)(2616005)(36756003)(16526019)(26005)(86362001)(83380400001)(186003)(8676002)(52116002)(7696005)(7416002)(66556008)(316002)(66946007)(66476007)(478600001)(38100700002)(38350700002)(6916009)(8936002)(6666004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?Y7OOAEnVZoTfgylXP97Wqg3B7WDBVu?= =?utf-8?q?q30CvUookLUOcaCdO9R0IVxFJQ5wTPCCsS0ff41DJYFV+VgpXxeJl1w/JY9Djk+Wy?= =?utf-8?q?BIzbkd/16SNeiyJHj39xtR0GwBlp1raRzXfvHa0mjHmAsAbxTc6MEnD5ZQgUiGujl?= =?utf-8?q?cEqc6AkR3UcdERqtmanVReibnUBROTIukrP95r2Sa2hInUtet/Ax5dLySMuwVclKA?= =?utf-8?q?KGBs7XZcP00CV4O84X1tRoZLi86O7bq/fmuKDUjeHb1qtGS/mgbAXbgewuka0cqFm?= =?utf-8?q?dD9Nz4CxUOxsSm5vC1SGOIxaS7MvPCTUEiOYeFPw2oYUrkJy+2Xxz9cf6GDwW3eSC?= =?utf-8?q?7rFUQNMUT+qhQ2yxYwbLU2xMkF2H102doMnJC71lUsmE724lznSHszwHDxRT2RnwU?= =?utf-8?q?89mrJu1IHoqqzXzFdJLCc3i5qYsmnKC5G+YbSUvxXDFR35pOtOpFgMMX+3OLGP9qF?= =?utf-8?q?pqYWc/FwY78Yj+n7L3zkkN2qyld7LW3lyarsLbdRVh2UAVCmaZ92ewIs5xzyGm+Dz?= =?utf-8?q?TYRSPaqu08WqU/d8NMWbAXDB46oA+8S1SEwBhzYdhEJw/aU6Jhu+S8471F7JehK+f?= =?utf-8?q?Aam1WqDNYzEF/1gSVdDP2lOjqtAFM0CUeK9kctvGo6qYmjrinj0zKRjpLMHiePhRz?= =?utf-8?q?vLO0cXCw62RBktD3E3U3gLy61VqT1qHhe5AAAQvmlvLU1Hix67arznQUH5q5z6fei?= =?utf-8?q?DNleqE7DEDCTkmvWd5bv0W0Hi+yqpDZxFPUUyxL/02F0Y9WeOXQ7lGejIdwcgpn/2?= =?utf-8?q?66kbihkAKY3fnXDDKDseyMUdlDdgVHete5SL+Tk5kcbGHv5KbZHKheudGBC31KdkB?= =?utf-8?q?6ubPP8fTAbWzRolA6UQKM+8R/f9QFSq8hVgk4P4fTBuDofC0e9YQWk8mYrjESFKcG?= =?utf-8?q?u4AeZMbe6eO8Q3P9sjZEobMIX/Uc43g1PDQGCmLi6Anoh6SrElumJz5h8qjuFznD4?= =?utf-8?q?9CcgCPrvB99OupWghQR6RsqcqacAlJtRbQmDs2GyX+P3cqXHWXpfHQcO04NaPk2w7?= =?utf-8?q?RRh6qfZXfJOE5akF9r4rqoJicngafxEyJfW86FiLf0yyUtMTY3wLR0BTRj8JwOLGA?= =?utf-8?q?QP8mnHP3KVKbNri15vl+4+DmPPYQfh6XnR5LrVaS0rjy8d7aGYA+FABB7LvShQP1N?= =?utf-8?q?MCj4bsEZfu3Aux6Y2qU8dnb7+UjZteroetZBA9J7uTiWAC43JkUUw+f9FAe1TEupb?= =?utf-8?q?fhSlth5ZnyM/BGeDULVHRuGeUcDoURXKDx+Ap1CwMZDJwRg6qkM3FomIvlSc5mexM?= =?utf-8?q?9FcAIW++ri009/?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17b18f70-3826-4222-e926-08d90026f2a0 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:55:53.0743 (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: iC6r7rq7rj7tgSD5nYQONMK30fBMP43BZYAjblo9b+cpAnjdd7BfnWQ5RSfraEjzbO1Zh5A8s5M/qlj4qoRVhg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2510 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: 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 c6ed5b26d841..0466c0febff9 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -396,6 +396,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 2c95657cc9bf..c9795a22e502 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1524,6 +1524,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; @@ -1592,6 +1612,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 Thu Apr 15 15:56:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19083C433ED for ; Thu, 15 Apr 2021 15:56:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB9A4611AD for ; Thu, 15 Apr 2021 15:56:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234192AbhDOP4m (ORCPT ); Thu, 15 Apr 2021 11:56:42 -0400 Received: from mail-co1nam11on2062.outbound.protection.outlook.com ([40.107.220.62]:50656 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233939AbhDOP4l (ORCPT ); Thu, 15 Apr 2021 11:56:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fL/fEUEVOBjcIwaNsKNR2c4cPzD3yHsJwHRfAfSzHsaAD7cMiIj60YE8jF8XOXBgJSs6UGMewQ0HIeul+RYaVpoVbrltyeMn1dP+hKm8Be7E8aVPhu2Qu+aQ4PO23bcE/ywFan3XTMuJx2HuNUhkPdmSsrA1QOXV1vgkVHPcVAtMHFO+9dR/iA87yLvgEdfYecv8doOZ5jjO7hezyQ12HV/O64CGBvkOCYPiQZECl0I2TwURGciTpfp4ozQ/CZjWwIdDxhNwHnu/9BwbJ+ja8DAcuRNge3tQDoAuOtz6yyub8MN1LBQna4doftU15nNsAk3dUcuqlR/J6vZZzC5P4w== 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=CLNAo19buTg3Yb1D6/ZVJBYv5MP2n7HijI3gYDV3fvM=; b=llVe5D7hyGFYB/YuXzMlI0NnAsPU5U33JtafB16KX2mq/SvqaDbELOTiXMbC2BDA2pfiNhSHw+FaN3s0qKhuU0uyI5pcPqPHFM6BqCRVj/B1qZr+Z1rxStWaf0EOqJ7e5qgJrnUywG+RLti5UM1Xe6FiA91pJjB/cWhyJqoabbzlXEEH3Obe9ysFwllG5j3C78CgU6XMZ4AuHWd7J7HC8tizTnvfFB0zDoshTtGaieKPlm1nVRUzWjl5TJ9LDMsv2ZJbmgmi4TQJqB2/ATFnKYg6nWEq7RRJlhPkXx8ulqfnCZmqQxG4uOq7B1KcOZV+TAa0t/Z6bOeSi3z8iTF+GA== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CLNAo19buTg3Yb1D6/ZVJBYv5MP2n7HijI3gYDV3fvM=; b=EgGTsAAE/P+r81KC7TuYwZtPefk9D6K9Hz/FfkXlw96DmUf7OnIQ0jQj5euxXzEOQZ2EoT7sYiqOzZvln9Zg96AUSKMEOTV6dcs65bA5RGbpicbYvGA8/wGVAQyE+aUfAEy/ehOMkLDuwxCgeMLY1xIXQYIP6urWLW3fpabMdwc= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB2766.namprd12.prod.outlook.com (2603:10b6:805:78::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Thu, 15 Apr 2021 15:56:16 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:56: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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 07/12] KVM: x86: Add AMD SEV specific Hypercall3 Date: Thu, 15 Apr 2021 15:56:05 +0000 Message-Id: <999bdd6f4e9e2d7f4bdc20cea9459182327f505b.1618498113.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0197.namprd11.prod.outlook.com (2603:10b6:806:1bc::22) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR11CA0197.namprd11.prod.outlook.com (2603:10b6:806:1bc::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 15:56:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ea5ff5c7-5006-4b4b-627c-08d90027004c X-MS-TrafficTypeDiagnostic: SN6PR12MB2766: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AYgdXjuBhPJ88yjqf2kbusCtx48uHiybODb4oef3KnmqgLSd4PZaDIRE9D8tU21Pxo9XT96OGFfMyX9DuD/XZdYkYTD8P1TrutGs+ftUu02yfPVg7cYQw0wugpnXPmS/EJonAfHdyHmm2/OHRHbwAccJvuv/Nse7JSpunnE89Lh92G/J+h2Pcw0JKEPkikQ+yDArvGi8oOgXQXGpcM2fdWs0JZ7M0E0Sa0ONLa4P5FHZX9yNg3OGKhBHhRmcedp7Pnnyr7fco8ccoeNA21ibuXYcAA3rhYvacN7hEsG2M/D8Pi5nIZ/h6JRj1JqaxgX+XcDov3rBK9+nLmudWfhdhwOkN0VmgCrDNByoVUxNdiQITIHUmD5RZc1OdNpry8pnR4l8igQpmIUF/YhNoub+SRdnDqrtM3jYidrIbTKiFeeGBYv08SAM2ap4RJZWkkFHUtCdgCUeIauk5mXYiKiTbO1XndeweSI76Y2WoLhrBTu8ymQ3nBqLgah5tllVUpYbUi8K+DtfkLHxR3eyZIcuDs626HQyZ54webLcVeQS9shXOE/fznrTJ2LxPqiDoI9IVex0AoRmW8iCqvxoahzNUHCteE+UoK6fdn9uMecEhb8rPDhL6uVvWhaoVY25N/nR1H2AmTBdmNhraNy0mGQaQA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(136003)(346002)(366004)(396003)(2616005)(6666004)(8676002)(36756003)(4326008)(316002)(52116002)(8936002)(478600001)(956004)(6916009)(6486002)(38350700002)(26005)(5660300002)(2906002)(86362001)(16526019)(7416002)(38100700002)(66946007)(7696005)(66556008)(66476007)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?ITZNETrCvWxuy4gC462p/tdrLt5oNV?= =?utf-8?q?z67r1J+LsrIaOJzs9LsbZwABM+IK1BGKfj0AVchMyyiO+/l0yeiZQBSi5whFYuzb8?= =?utf-8?q?uBw/LMylTfhBt7s6E0n2ZnwICYFeZ8n2N0FfP5CWPPcHRnAroXfR+tC3eUQlLg/eC?= =?utf-8?q?4sU00DyFcJTvjFIFJVVlgx3h8EbVRKPXEs98Y45BWFST1UI1+EfxqrHge8bwhOspr?= =?utf-8?q?CImkqDhOY+ESu2bv/5PJb7/xFWqXWnnK3PfPoF4RpbHq9dPEtwD+xfTNLiZwOwtpq?= =?utf-8?q?q61klKavhTf7/v7oOA3DWeJji+pOE/7ujzunjzM/7s2U0N2CWexLrwE+4TNRuwB0b?= =?utf-8?q?WoXsNMPWGmSN9AwBVZcy27XZCVVsJIKUPHlsMLFm7aCELX/dpCN5n3K2OBSAB6QHb?= =?utf-8?q?BLuchs5eVB+gvu00I8NcdfiAB2SeoJnytIw25vwvxO9UcPWKMn6T980BduisNGe9t?= =?utf-8?q?MdthLv4b3fW9/BExK3kcDeo60LgXaiQRJ9Prm6j4dL26oa0DEwxHcPVcFjj/kj6Ev?= =?utf-8?q?h68hau3C5V+bJLW6cvR4pUWWIR9Nqtv6XGGHJpI/qpygW68qjNHy71hroXI+4DN3q?= =?utf-8?q?1GTAIlUyVQkBsrDSSJawCWBBITPkK5LDsavEwFNG2kw6dvTr2AYxedVd8G1FCynhA?= =?utf-8?q?PXOokQJ7t1hQrWUqI7UQMQ4JD/4/qRgKNwLfA4hwhg1wtISzFr7s/GVQK0TDPjwRy?= =?utf-8?q?69/nFn/wF9NBNmxqBCArDK4JgwmHvZHabfeEbf5uSg1aPibC6HMy0z4au7TG9KQ1L?= =?utf-8?q?eNc9A51qd9iMpdQEm56sxndZo3rFcQrkiU8aIs77WVNzHhE64seycpVy5dIhJSm7B?= =?utf-8?q?vI4ukE9zI4iUAkBpl6WyRh9thK0rVrp62Js+JfPqNqxvQjJ4l/RU+ITSnLE/iEylS?= =?utf-8?q?wKw05iIaFFszsYhtOi0VFXaia5P5VqZDJY/3lXMPbRQbrHtvwp7IXBupeA3db6IPw?= =?utf-8?q?5UnrM1yNXZtwQBO3KAt2C7bH/bGFWnfaVkvsa+j6E8gNVgXeaR9Yv9MIFQUz+Rb0N?= =?utf-8?q?TsiB85AZwiQJ+nZ5cyOq5OCf5LvGWPXu0IG2+9fC50AIFAvavGs2S6H/FpedHYpMT?= =?utf-8?q?xERpyFNgXneT1pI2oRxcpsOh4k6r9kBXucWDZKK5hyBs6sHMY2wqIYj+kdwIaRVWi?= =?utf-8?q?qK7E9OrY6m/7jdXLBKkAXYYNR3/NNYhWD01svMVCrEFxwW3OBKOTo7GBN3g60ttqf?= =?utf-8?q?XrupYXfYmT6frH1P7zMbouwcq2kCM9OHjTRd7KRKcaVXEwiM3VxGZ5uyW7jZ/oBbM?= =?utf-8?q?eI3y0D2mThxuMp?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea5ff5c7-5006-4b4b-627c-08d90027004c X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:56:15.9685 (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: t2jRmwR48ASAwTQjEYAdYhTf7Ot6ObSJO2Q1hXxnxZqLyaGsL7M0IVFJIzGzMiwET/iEJLpr46i+wBgRfHkuBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2766 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: 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 338119852512..bc1b11d057fc 100644 --- a/arch/x86/include/asm/kvm_para.h +++ b/arch/x86/include/asm/kvm_para.h @@ -85,6 +85,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 Thu Apr 15 15:57:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B766DC433ED for ; Thu, 15 Apr 2021 15:57:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 910FD6023F for ; Thu, 15 Apr 2021 15:57:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233914AbhDOP5l (ORCPT ); Thu, 15 Apr 2021 11:57:41 -0400 Received: from mail-dm6nam10on2052.outbound.protection.outlook.com ([40.107.93.52]:56416 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232769AbhDOP5h (ORCPT ); Thu, 15 Apr 2021 11:57:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RmrDpTtt2eG6AS3f7a5BLZWJ10dv7XZTHne7QaOXxpgfkRLJ2PIDB0D7Q0bO+yOtabzJbZonsXNd1Jw+g/EEkr1ZT2H+lkXhNC67w5Qzuk7+RR6luMRHfSygSSW/niIGuHMTmsyop7XGDAezRLEZhoZ9P0W9kJG/AZj2ztckcJG7sH5tXeG2KEgoK/AocfLuwvDLttSkm4/L4z8IcepjTjfPPWtiA7QTuzcowxmUy7iMQgSh+8GF+BLc4l20SERSzkD1CPfcN6h13c3vKSLJaz6AqiP7jSkJF6zt+JZh2gEqKrLwoiTK/MG/1/8jNkYe005GOLuw6kKAkdj9F2mnfw== 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=Du+thO9ohpgzgOkPsRWmn6Ieq9jDz6CtEVwC7pMeS40=; b=d0/xlIAZO1/oTOg5w+/QeTYRXLJpz4rP5qS0rxE9Nzw/dtnSNw5kNd1yctEh0P/XEIXUuRBefK8BnPnWkhFf+i/uYbvu3MnuAk9urj0UwnPwPu/kBTAWZPsGGGEjvnfoNvpmmXyxfYa1gd5AengS/bQgROslFLtVxWudBFInPg6ZDaN9visUsmgRVklZlSl1uF9pC4JQwyAN73LlIHKAiJ0/Bs7pjAn8Yf1B5F025BjytN396f/sOhLplo/ciGfgzIIk7/iiq0Z9qbOYW29tcFZzn2ii2bEsdEKLvRMsu0o1y1KsXYWFnmT4L2AZmLyFCegw9IwHav81AU3jE3pXZQ== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Du+thO9ohpgzgOkPsRWmn6Ieq9jDz6CtEVwC7pMeS40=; b=fzlABt8rp93t6AUs1OqrlZ5TStAuPYYTKTTmqF5P7kt7sKfHkpttAD+K+fjo6Y8S93ksKKXWi/wPraF7hRBuiHKFGeNtTdyKUJsR3E7L6D6XJ7PncEZvMz9l9WYN7l1O1XJm7B1dDEOnNPBHvcGIQul/23a5wY2GgabFHO1w0hI= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4592.namprd12.prod.outlook.com (2603:10b6:806:9b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Thu, 15 Apr 2021 15:57:13 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:57:13 +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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 08/12] KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall Date: Thu, 15 Apr 2021 15:57:02 +0000 Message-Id: <93d7f2c2888315adc48905722574d89699edde33.1618498113.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR13CA0021.namprd13.prod.outlook.com (2603:10b6:806:130::26) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR13CA0021.namprd13.prod.outlook.com (2603:10b6:806:130::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.6 via Frontend Transport; Thu, 15 Apr 2021 15:57:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 603a7daa-a8a2-46e5-8502-08d900272234 X-MS-TrafficTypeDiagnostic: SA0PR12MB4592: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ol8JMrsSX6aUpGK4Q0+UPmU3K/ZQBl1Hnt0TZO2kjh5nKDephYyLCvwjvQSzBVKJlfMhsfdFqKsDum9e2ba0AoyyOL75I4/x+yKBZj2kmSOOutMsUsfdl2g2aKwRA6djqwKAonniPDAgOp4K3Hh2oqYGRDR/ussaAQMHOewByE0d/QCEF2HXMRl56SuAybcF7SzWKcNxXzQ6wxvAWH/VipH+U40pgwJ0zM7oqjTAKGQJZHwWOonYUW867spsidTI5Diqfbnetlmi80nCKbDBrP3/I+klUWQZAtWeykjIpbx6qYcwS8coxy9BqXBmEDulTKgfxARTrqh+OzLXI3QQBtZioVvWjAwHDPXRgxLbEvVkHKOe1XgZ24Y23oVS6fTkTQA6bexj/sYnKFfbSRTYMweIKwsljrPzGHKTe7xQvG0YRtsy+84xsYiLywKc2OBHOtNa1JXL4p11nOVzxTGrQI7S1UfRb9TIRbMtq7fHSVBmuDcjAMDYuoTl9or883JYPthF/CQKEvw8DAgdXpMqx3fi4fdNsQAu3J5ixzgKjQIeh7Cb6i1ZTZzH5Jl/QbPlzelLuqVt1pn6Ju27ZCJqmfRL6tprt4LiHUEUE+DdT30kXu2fsPG75ZukYPBay+arBu8WitK/30AN1x5NyAlTAA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(396003)(366004)(136003)(346002)(39860400002)(5660300002)(186003)(26005)(956004)(66556008)(16526019)(4326008)(83380400001)(478600001)(6666004)(2616005)(6916009)(38350700002)(52116002)(86362001)(36756003)(7416002)(7696005)(8936002)(66476007)(8676002)(2906002)(66946007)(316002)(6486002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8FW9IsnbpVzwhLkhBnJbNo7fTG0Pr1wPCIgin2btFAIz3qvBM+mWtFcJ/oxOyHuOzHTvBYxez2ponFLa4Zx7WrUG15G6DayyztDibr932Fo+hAQhsWpP1KuPPqCl+0L184RjCUQOtaHXZM+pdno8g5OhqFguvKjWegQhnFtEgxCUw4Tv1E0gco1dWaABm8vCWKpc53C4eWH2Yf86pgwHrYYtbprey8ZEWXWT+yTikYFyEQt7MN1bZBqXOGdix2/lSB0GtWgD1cdLTBcNUpG9YcsPHVJgbRyUobuCw3EcxTG/ibYBzQLGgo6Isf9pK1cv3eYUwc8hFnM8VeNWGuwew/ruQXaIbSIHhWXFjG0B1U93g6RebG8ED5XR83fdaFwqRH5yp+VPr0GxriYEUDGGZ112eCsKrSziXPyDDV6k2a1PORcGPRWd7AnlQ2zEw4nYPkbT68+/j9AViiaqZyOQ5lu90d7k7zk9QT6QOYvAv5KYSa0Ewonj4+BlLzCZ6C72ArFmF8XDvft4SXn+on19oJVsAI4irO8c9ExBKsfeih07bzowAiCfwVHrPX0tZCt46HMCTDFm7gpQuXgD9jhgcfm6DylL1djMe+M6zi5WBlGhjKjaOVLC1FTlzkXHRftmf1qa8r84PSa6J+XS2gRebdtzwQpShIxPYiSZbxbI0/FF382m+uAWaExwcbjM1pY/RXooQ3F+4fDS5FFnKeu0T4RfBNAHd14/eoTBrjaQpXk6aYxsXh8HZyCWj/R0h/YkYANnS1vT3J0Xy6Q/rnBi225D9ehzG4vKN+V78aENiTtRz++MxN4ULdqV9HcttFb5/47t3ymrAm89vd6KNnco5oswszewaXYIL/zc5Nl4RFsZcXtRt/tPR0fWikfKRE6DxCJIGr6DoJBi4GiqC4AVEuklN1ubZxtzh8mSQvAEy/hI4aVDmLjYfae5gFCVhYWbN22B7XJ6B3W5HP/L99nnb0zNYA9cXFIoHZt63tUV1QSLoX0CumIJtD7rTePL7t5xWrDq1RM1+znwTzGAllPNDHP6a/3ZeBnVmfeTjNSt6QSnjoNiAkwsX5GvszekZluaiq/zv3gWPaFf9TX/fE4ZHGoX9kasbLwxwxc65vXNmBgjNySijMw1vPd6wVHuRes7MJrKZYHdarkX9vessXMURZAj7biIxBZ4jVCNOLcHMUR+9wek5cs2RInNvxRmWfqOUHzROIAk4EqONsfL4ppPs41V0tqEDHvI1cJ9i7pQyyprPDUlWr0Tw43fdM3xN3Th6uzUb9yRbyhnUOcAwBb5UFXSzTf0HuFg1TmrfGhg8WEQKpKlrEVGfgfN7V6NK+4Y X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 603a7daa-a8a2-46e5-8502-08d900272234 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:57:12.8606 (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: xkpg1QiAhrCL+96wI9xhU8Sfy7sIww6CzRaUCX/xWxPlkh23lsXPo7MMc/6M3n+XhhYQdhz9yaXukyE3UZ55UA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4592 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra 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. The hypercall exits to userspace to manage the guest shared regions and integrate with the userspace VMM's migration code. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini 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 Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- Documentation/virt/kvm/hypercalls.rst | 15 ++++++++++++++ arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/svm/sev.c | 1 + arch/x86/kvm/x86.c | 29 +++++++++++++++++++++++++++ include/uapi/linux/kvm_para.h | 1 + 5 files changed, 48 insertions(+) diff --git a/Documentation/virt/kvm/hypercalls.rst b/Documentation/virt/kvm/hypercalls.rst index ed4fddd364ea..7aff0cebab7c 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 3768819693e5..42eb0fe3df5d 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1050,6 +1050,8 @@ struct kvm_arch { bool bus_lock_detection_enabled; + bool page_enc_hc_enable; + /* Deflect RDMSR and WRMSR to user space when they trigger a #GP */ u32 user_space_msr_mask; struct kvm_x86_msr_filter __rcu *msr_filter; diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index c9795a22e502..5184a0c0131a 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -197,6 +197,7 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) sev->active = true; sev->asid = asid; INIT_LIST_HEAD(&sev->regions_list); + kvm->arch.page_enc_hc_enable = true; return 0; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f7d12fca397b..e8986478b653 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8208,6 +8208,13 @@ static void kvm_sched_yield(struct kvm *kvm, unsigned long dest_id) kvm_vcpu_yield_to(target); } +static int complete_hypercall_exit(struct kvm_vcpu *vcpu) +{ + kvm_rax_write(vcpu, vcpu->run->hypercall.ret); + ++vcpu->stat.hypercalls; + return kvm_skip_emulated_instruction(vcpu); +} + int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) { unsigned long nr, a0, a1, a2, a3, ret; @@ -8273,6 +8280,28 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) kvm_sched_yield(vcpu->kvm, a0); ret = 0; break; + case KVM_HC_PAGE_ENC_STATUS: { + u64 gpa = a0, npages = a1, enc = a2; + + ret = -KVM_ENOSYS; + if (!vcpu->kvm->arch.page_enc_hc_enable) + break; + + if (!PAGE_ALIGNED(gpa) || !npages || + gpa_to_gfn(gpa) + npages <= gpa_to_gfn(gpa)) { + ret = -EINVAL; + break; + } + + vcpu->run->exit_reason = KVM_EXIT_HYPERCALL; + vcpu->run->hypercall.nr = KVM_HC_PAGE_ENC_STATUS; + vcpu->run->hypercall.args[0] = gpa; + vcpu->run->hypercall.args[1] = npages; + vcpu->run->hypercall.args[2] = enc; + vcpu->run->hypercall.longmode = op_64_bit; + vcpu->arch.complete_userspace_io = complete_hypercall_exit; + return 0; + } 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 Thu Apr 15 15:57:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CC1DC433B4 for ; Thu, 15 Apr 2021 15:58:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28A94611AC for ; Thu, 15 Apr 2021 15:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234052AbhDOP6f (ORCPT ); Thu, 15 Apr 2021 11:58:35 -0400 Received: from mail-mw2nam12on2043.outbound.protection.outlook.com ([40.107.244.43]:22998 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233835AbhDOP6e (ORCPT ); Thu, 15 Apr 2021 11:58:34 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LUuezIMoiP4TuxRfOXRZZYMTRAjFflevohZ6e6UJzUrzYx5lzgUW0N6/zXGVYpNkwNor24Oj3pOHbr6yHM/ii1wEtFVn7+tj8Vz9VM36Axb3gIHSJS/PoYUWi95RvGzcKt8hdnk4WJqs5DctAKUY9y3v23Kgnhd6zSn2jOtnICCE5NbMwjGUo7ZumFM2OmF0czyro8WEYEI73RPGM76mmYxtVyOqqBiima3O7sWQ5NVVx0EhhDMTii24UfxJqVmVYlK4YH2JmcgNtNjgpRnOqZoHaksLacfPrDtQaLczmRYBReqzx8QPAn1mvLSHKTHGbkqnwIvWneUz029epjnUew== 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=aeeqct5+sugnu9WBplpXTxst9mSGFBE80DKsxBaznhQ=; b=khJ/flng2RvR8TEjL2S82/UDQzxJYnCBp6liXRT33itBWVxSk5EM5CEREejpJI4PRFHFYTQo9VGBI6dfsHQXcIeGGm9BMlD+lwA9rsV+kx+2KJ58WcEIjT0lUjrYzUqIc+Uq6ZdZIKuGVKXKZlxaZ+DlzuX3pZZRBNUz8GaC4vtgiMJ3Fg4p5Sg7Hn9/Pt8ibDdKV8Z99mNsVFNGDnAyhlpeBf24brBroJeIa2FulfrApDgfO7rXackl2zwaGavjgV6U6grxw/5Erj+guEDjiOf1XimuENidKa9ibzzZkfMv92c52LD4PxeFkdTYrccHfGU+j59qDG9jM+9c9P/X7Q== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aeeqct5+sugnu9WBplpXTxst9mSGFBE80DKsxBaznhQ=; b=wt7spPrUKwdG35q9Bb5y8PjDw5rXnXiRvdRmy+7yKBfKsU/Hm9dzNeRXY/EA6TZ4PQldVWC7Yg6A7YxrSyoZ5J5c3YHcjzJDDJJXvcU0+bv9JeQ8mYa4YWC+T8cTNvedfKK9+ZktEtMmhv//yKaNUZPqW2e1PafVzEVF/pW4Raw= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB2720.namprd12.prod.outlook.com (2603:10b6:805:70::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Thu, 15 Apr 2021 15:58:09 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:58:09 +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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 09/12] mm: x86: Invoke hypercall when page encryption status is changed Date: Thu, 15 Apr 2021 15:57:26 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR13CA0008.namprd13.prod.outlook.com (2603:10b6:806:130::13) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR13CA0008.namprd13.prod.outlook.com (2603:10b6:806:130::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.6 via Frontend Transport; Thu, 15 Apr 2021 15:58:08 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd91f4b0-329e-4cfe-b442-08d90027439c X-MS-TrafficTypeDiagnostic: SN6PR12MB2720: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qvv/VkVrWPj3pnYbTGzTcYWYzbjn9cYJbh670G4TeTTtRoX46QJFG1TAdQsve+73wLaeayBFa0ULYsyEtuVTgcf32lcYJzrFJ9k+QLNbl4mY3efAySdQniSB/KJlFvXQm0P8J9XrxOr4V+RfMJd99F+mtZxn2tE6Q5gXGu3TVr4+JE/7hK8p1u85vJyIxMoQ2QodpxE4OcJCIUMVoCyuRUsAbVFnmuTGHVWdeMtsOVGnvD74sfMEL/AmeKRsMa+SaC0/USFZFGflEQY97l719nDIsEpcvvQuOf79zT9yyjITPFDai9XUHDSQFBtDEbkXYWABCNmOFnpD5ZolVBikGj+RVZdUsTZ+w9mbmMInTQcKM2ctUs8M8HezEX6SStHL+lrLO3ZgEVREG/AQYpJB5Z79m2XjkI6B4sh7/TjhINlnuqPSFsLjmBRrVR7R2eRt/XU9E3jc0nQGKAQely1374lqLNzLY+L8lJMSR4KAqBExDX7vpOSdxPckEJAf8JKMjLxvNEncCEIQvfxrnl8z2T+Af4Q8et7r9Qsr5m71Wf88HimiP6cUPhJmK8dev2VuY3FIfigmejjZGGG65irrthYr9CBkz40oBZtcvwBzWia3uYlNue/oJm+dD6w2xreN/BefoddFzCVf9vxwEsCnzA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(136003)(346002)(376002)(396003)(16526019)(186003)(6666004)(26005)(2906002)(956004)(2616005)(8936002)(316002)(83380400001)(66556008)(66946007)(5660300002)(66476007)(86362001)(478600001)(38350700002)(4326008)(38100700002)(8676002)(7416002)(52116002)(7696005)(36756003)(6486002)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: khCPJPozJFeaa7sqUYwsuPtH5e3oLxfN5GXQAjH4xicOR9R1yb/FncRpvIp6fxDzQcYv8i4oCqi4g3krKjC2RBciF8quY31uprNurvpwSTJuZZ4zJ1eRWt7d5Fj46Qp3/jmR6OfkMT+sIj4tRTFKRlJ9zZpsXxbNEP76pEzxw9I5UQ1pvUEFlpDEtvZTzfuvAtHwSfCKKApTXkkBwqngfq8hzU/s1IJLGM/Uy0wM7UBPO2lRvm096AIlwcJF1ahIpFWctQRFGO/Y1SMGojM/CgJcwuhXzKODYkxcJ9tTn/oVQ/lmTdndZOPZAeKnnLFECSwC2J7ElbstO3uEqZtcuf/YkslStiOYROa610DA5qMTbAezEQE2583TaP2qmWoscQ4FlzQV5T/ckN4iBgpqjM93mDs0ZWwzMqqC5YFaPHTnRVoy5KwW0t+RyF1r4HkyJ+Acz94CrDh6s/DMYvHT4MaKSsXh7XF/rTHlWFdh4ZaRyP4WqboQbMFQIVz3ib1h3G+mf2omDX35exZY81lkWKxBpJrYhe78e2gakmjS4GxAVVWFO0u5NJGgNA1uL62uSJH4Lf/nSeX9dJA3DBcDbYQYW2p5m4pJ7JbkBRIkZjAsd8tH132LMaMh0ISFZLn8YqB4qLuCUGERTsl9Br6ZECsRW9hE4G0iY3VAvocz6mB52lKt8Jn8QhmV7hmsAzO+ymptF7v3jKGOjQd0aZlpwW+33zLfqZiTTyzYMSOdQLdCWNTvNTqcvXfBM5jWBWz8CyXmyv+8tuB4KBO1+4kyaCiD2h4w+S/1MS1z7W0TqPbZTfHOmuuAjwlQb2kSPMzjbZo3kkrYzvf8D9k8mHPxvcTOR1Ea6E13U6O6mXR99YtkhYQtAyUGz2x5WFblwcMLpY7BhOKifGgCQCv1kxU33tBcG1rQY+GxjLHmMfrMnx52f9kl9MDwq8qtBzFywEDA9fQrEzBDqg34Bj0MCiyng9K0Cj+4YKAYelaZGHyeMQOTTgaN9xBO3inLaIlVSkldsLjlRBoOXwGjjAVxn2howp2Q7f4CGKHgTE6Bs3SXc/+mGk0DjMM2J51cK5kDgEI+8uYQdPdBMrPEVwIk9cS1ispkLdx9Jtkjec9WPrV15EWLy5rsmrXg5v0308QI5+Q7LcDpqbFDxLqEjhwfkw8HQB3kGSCfH7Z3V7pesOTwRQkdvcoLm/c1x1BwfyjmYXzYKSBkDRrvL2mEgWWyTbrkkVQCzDFMbuLmTvtrDObLqoCMHeWLRQJBIban7DhnHDXJdOux1ZbTo9rYq0GzwYX5xY5FWkNX64/7f3s6Yy76Faez2JRH0um8fUNoNLOBFl5s X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd91f4b0-329e-4cfe-b442-08d90027439c X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:58:08.9042 (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: RAhNjALUP6Tp+LjEgKnMzsxPBsHbXbPesH2xl+GN3diy40io67PbuwpCbGdv6b57OwqIxd52KWs4nsStS4gqsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2720 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: 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/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 4abf110e2243..efaa3e628967 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -84,6 +84,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) { @@ -799,6 +805,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 de87087d3bde..69ef9c207b38 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -195,6 +195,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 c60222ab8ab9..9f206e192f6b 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -335,6 +335,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 ae78cef79980..fae9ccbd0da7 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" @@ -229,6 +231,47 @@ void __init sev_setup_arch(void) swiotlb_adjust_size(size); } +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; @@ -286,12 +329,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; @@ -346,6 +390,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; @@ -481,6 +527,15 @@ void __init mem_encrypt_init(void) if (sev_active() && !sev_es_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 + print_mem_encrypt_feature_info(); } diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 16f878c26667..3576b583ac65 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" @@ -2012,6 +2013,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 Thu Apr 15 15:58:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3830DC43461 for ; Thu, 15 Apr 2021 15:58:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1906A611AB for ; Thu, 15 Apr 2021 15:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234216AbhDOP6z (ORCPT ); Thu, 15 Apr 2021 11:58:55 -0400 Received: from mail-mw2nam08on2085.outbound.protection.outlook.com ([40.107.101.85]:35008 "EHLO NAM04-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233520AbhDOP6x (ORCPT ); Thu, 15 Apr 2021 11:58:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n/gTSiIVWe9BLTvCXegLdmP0BZC8JNEKYqx921MsxHGq8FLT+BrRM3PAl1dpIoTotcLU57J28H/MK9lPQyJvBGaYIGYQlzmef3Y42ZH05/p/O/HvNGB/kd8imbE/8lmA8HijhLvxZV4nzuN4UdepTwMPoMNP2elGbCt7mkpQD29L6LApF5E44UIthCHK29GB6mwhRSkhV+FNnI5Gd7TIXsFDTnefi3u0qNIQiRs2AXR4gFm/xVh1z4w7DMCxnB5Ajfeo9LrKvVMRxx3bRR/T1qA/z6eScu1mwz8x3hGFu9QehTSp8rjMmwkQhGFYXC2IDVdGIdiaFEVAcIbjPDDX0w== 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=fxaCy/NKB3rxM9gYsE1EVvmOL2tgzwh48NPLoJzhB8A=; b=eJco73kUxqdyG4lTPT+3XQg3ak6DvjpQs7iQlIq2Mjv9qJgOOY5E1vFosX2hyV83aotPv+6ecmMqX9du7BS/QsI4CTF859uRveX3SDXgJ87rwyJIjW6mH9UFp+B9ZotMaloVGcZ7VFNdxdxrgYCjv1sOnc5Sg01/FMWwRq+02tvdxPqlBjwnGp2kdh7m0NX1NyCnY8B0g4zq5fJgw+6miYsx1qt9xm1j3i3/2bH963xPnlDtSDwGEET46ma+0gGWr5qFGa/C9//WDxHpiDzYk6SRk8CK38ng28tpNz43IltQd/KtFcMrniK1uQp8lE2xgTxepkCaO8OOyatprXuFlg== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fxaCy/NKB3rxM9gYsE1EVvmOL2tgzwh48NPLoJzhB8A=; b=TXo+UuSoB5GCnNtuH3n3LwFidSohmsLw/HQuaBsc7SjpyI8I7Ue5kTwp6itrh7n+CG9lhUJjeQmzlTirivX5TEgRVUX3IHWAc2+BSzZngQRlpbmmFqvMhIJ9Y7w6t8Pz7UohQXRtAYJgFk8xrMgeDkTu5BHiqiqbOLvv2fdJ4D0= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4415.namprd12.prod.outlook.com (2603:10b6:806:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Thu, 15 Apr 2021 15:58:28 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:58: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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 10/12] KVM: x86: Introduce new KVM_FEATURE_SEV_LIVE_MIGRATION feature & Custom MSR. Date: Thu, 15 Apr 2021 15:58:17 +0000 Message-Id: <3232806199b2f4b307d28f6fd4f756d487b4e482.1618498113.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0065.namprd04.prod.outlook.com (2603:10b6:806:121::10) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN7PR04CA0065.namprd04.prod.outlook.com (2603:10b6:806:121::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 15:58:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 479e2c2a-3983-4789-e99f-08d900274f6b X-MS-TrafficTypeDiagnostic: SA0PR12MB4415: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7OUJEyKAmYmImQrg5dnZJpVjD9/dC5C2YYr/dZIaC+lFWExSoCqj+3AXUoExb1aJMxfbcC2BG+15A55a/Z3AGRwWod/gAP6RRUNx9CFOI+FiV3iiJ+B4mxMKOhw4h1ljO5l4ZLV80auB420msw6Zmf6GVgmGFYIwX7gb+SKFSaGQq/uOW3vPCrt8yVPaDYLRageZpkFQwFaykDPsNC8I2yWL2xdPv9L8R1uDgwe9WBPSMVx/KTDAOE5LJYEgwAcqti0/Y62LmRpkjHp6RQZ/pPDmM/X+L3M9N/ilaW2+a0/siL7H364VIL1I64IUmYZL995vL6qtLKLGDW/LTQRa8tF2Pjjs32Q8WSXJ+wi/c72vKQhBIiZcwdXpYr2V7NeWA3dluILyEhUKDce2iQzAOy9VQQC/onJ5Xddf9btr1XUkSYMP+3Mt/iNzBwQJNU2TZg+vq4A0jhZQ8w/GcAvwH9eci9WAHGFkDJ9xCoARr12rOYaMJVKORRmi2jG2y25XzzMwIFfQa7XKTB0RQLPOQi+x14JaVznq/EZu565gA7+qzjqXXNeh1N+EEPebWVTXiuDaKw+K5EpnNBiNL+tr1JX5xbkyouaoqFEN+Rv1C+olh2uWbvvcG91Q6ImMHCRY724jz5c5SL05kqrkqg10+g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(366004)(346002)(376002)(396003)(39860400002)(2616005)(6666004)(38100700002)(316002)(956004)(66476007)(36756003)(38350700002)(66946007)(4326008)(66556008)(26005)(86362001)(478600001)(7696005)(52116002)(6916009)(6486002)(2906002)(8676002)(16526019)(8936002)(186003)(7416002)(83380400001)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: cJbTKq7cycThfu6QmcyGTuk33W+ok5LeonDd2CnAkQs1bvpSHHY79WUD1P4DFeP9TR3q4AOF4cMvZlkkmqvwUuRhwvUNbM8MB1zcbcbawPrfXnwMxa0UaPtRoCI/Ng40NPUIxAvhbk0OC02PMowNzlxZOjPNEGZ0Z4PeSHT/XXQUvrrJTXS9r/kaX56pYVbsbB3Q/UAKhGFM7jHuQZi5mOOgMv8FE2733+oR4my8wOXcCwyyioaKyUJTx093xwpHJVppzb92BvWOh3jMNqVVT8Sc5qmqQOCblcR9/5kWpLXuF8/zKo2SNt7t9OunAb6LXxHA/RNBufbLoSEZ/SQQ7Xcp6FI/pNZV5KuB8X2dTIXWd2oi1/8r7x5zD1zdLJmiPjrCxUPyoeRnw4iDbkqzrtvG5PdD86GtIHoyuJ20ySn/YxTMZdk/mtDfV1+Kqpa1xC2e8u1jUzN0OdHqfSYmHAdbYNehLbmw3cBEesJABSV55TVMufhVO3MHam646LrJ3H1h3DVa8V/Cigxq0Nffl++PsMXpjjjOpx6g98DAQoCuyfjEvh6sz54L3z/zsqFTdmCENGFChrr99+Tmf1j3yUtG/ok3y28lSuW1zOtz7+80klew95c8k95yyvEtBwAUOh0LVm1v7DFeafz2LOMJRL2P+pCyPNbkcZERllnx5qwWE1iddbhCqVkBnumpWlHXzsTKpwfvh/Zr/MEvlhMBatwAKAqOZOXTcYBMlaUv3XCUdQJ0o8d7PBGYyAJFQg/Hox88sXa5XH4EHh4C+T3/dofZs24DJjzA++Ay60XyazCgdVbn8OaUMGMnaDZxtdatRx/jl4ON+nwx0hw4Q0xlmmJIBDP1eE2hnue5d5qlNRxausMAmQqkoc9dhA6p3+slPHL/l7KLbKgD3w/DR45a9X8xe2x+3uV45ldh0p81KYP0swoDxKubrqqjkDMV2Vhz4kwm82Emtlu9KzCmZMOO3FUtPzJ7mtJxOFfC6rgklI0qdVBfNXa1qIpvbY6sM6rBhRTUKJCCQqpD+Z1BOY/ZShBpvqE5Icaj7AWACcJ24DnXwwcx8YTvtDxOvwfMyXDbep9rQ3FD6DY4le8K3K7cK3gfDm9jxoAbuNqiwohepkxAITnwtzxxqWqZaodESK/aDrXFTHJQzIg9I8q0BQbrhGUs416NCsaunklANUDEIClhfzKjoTaZQjaAFZ9jMIECyaXyFucobTX7p0tYsrle/WVQFmdjkhoByhGtFBvKtlXO5T2bKe5eb5k4CflGHtBs3kiQP3Ohk/c0DSnz2RP9qEMMKulCE7Jn1MNqTsrsVEBx8dJaN0d09gpVj/C3bn2i X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 479e2c2a-3983-4789-e99f-08d900274f6b X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:58:28.7531 (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: 74/Ac9nbnAY3MZJP1N+UPr+D0CxGwkUpFMGS48roFVKZHBRAoDb+J4slb2gk8vEKgOYnzY1mNy4YiiPyeYTAsw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4415 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_MIGRATION for guest to enable the SEV live migration feature. MSR is handled by userspace using MSR filters. Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- Documentation/virt/kvm/cpuid.rst | 5 +++++ Documentation/virt/kvm/msr.rst | 12 ++++++++++++ arch/x86/include/uapi/asm/kvm_para.h | 4 ++++ arch/x86/kvm/cpuid.c | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Documentation/virt/kvm/cpuid.rst b/Documentation/virt/kvm/cpuid.rst index cf62162d4be2..0bdb6cdb12d3 100644 --- a/Documentation/virt/kvm/cpuid.rst +++ b/Documentation/virt/kvm/cpuid.rst @@ -96,6 +96,11 @@ KVM_FEATURE_MSI_EXT_DEST_ID 15 guest checks this feature bit before using extended destination ID bits in MSI address bits 11-5. +KVM_FEATURE_SEV_LIVE_MIGRATION 16 guest checks this feature bit before + using the page encryption state + hypercall to notify the page state + change + KVM_FEATURE_CLOCKSOURCE_STABLE_BIT 24 host will warn if no guest-side per-cpu warps are expected in kvmclock diff --git a/Documentation/virt/kvm/msr.rst b/Documentation/virt/kvm/msr.rst index e37a14c323d2..020245d16087 100644 --- a/Documentation/virt/kvm/msr.rst +++ b/Documentation/virt/kvm/msr.rst @@ -376,3 +376,15 @@ data: write '1' to bit 0 of the MSR, this causes the host to re-scan its queue and check if there are more notifications pending. The MSR is available if KVM_FEATURE_ASYNC_PF_INT is present in CPUID. + +MSR_KVM_SEV_LIVE_MIGRATION: + 0x4b564d08 + + Control SEV Live Migration features. + +data: + Bit 0 enables (1) or disables (0) host-side SEV Live Migration feature, + in other words, this is guest->host communication that it's properly + handling the shared pages list. + + 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 950afebfba88..f6bfa138874f 100644 --- a/arch/x86/include/uapi/asm/kvm_para.h +++ b/arch/x86/include/uapi/asm/kvm_para.h @@ -33,6 +33,7 @@ #define KVM_FEATURE_PV_SCHED_YIELD 13 #define KVM_FEATURE_ASYNC_PF_INT 14 #define KVM_FEATURE_MSI_EXT_DEST_ID 15 +#define KVM_FEATURE_SEV_LIVE_MIGRATION 16 #define KVM_HINTS_REALTIME 0 @@ -54,6 +55,7 @@ #define MSR_KVM_POLL_CONTROL 0x4b564d05 #define MSR_KVM_ASYNC_PF_INT 0x4b564d06 #define MSR_KVM_ASYNC_PF_ACK 0x4b564d07 +#define MSR_KVM_SEV_LIVE_MIGRATION 0x4b564d08 struct kvm_steal_time { __u64 steal; @@ -136,4 +138,6 @@ 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 BIT_ULL(0) + #endif /* _UAPI_ASM_X86_KVM_PARA_H */ diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 6bd2f8b830e4..4e2e69a692aa 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -812,7 +812,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) (1 << KVM_FEATURE_PV_SEND_IPI) | (1 << KVM_FEATURE_POLL_CONTROL) | (1 << KVM_FEATURE_PV_SCHED_YIELD) | - (1 << KVM_FEATURE_ASYNC_PF_INT); + (1 << KVM_FEATURE_ASYNC_PF_INT) | + (1 << KVM_FEATURE_SEV_LIVE_MIGRATION); if (sched_info_on()) entry->eax |= (1 << KVM_FEATURE_STEAL_TIME); From patchwork Thu Apr 15 15:58:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16A42C433B4 for ; Thu, 15 Apr 2021 15:59:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E763F611AD for ; Thu, 15 Apr 2021 15:59:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234018AbhDOP7l (ORCPT ); Thu, 15 Apr 2021 11:59:41 -0400 Received: from mail-bn7nam10on2085.outbound.protection.outlook.com ([40.107.92.85]:8161 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232769AbhDOP7l (ORCPT ); Thu, 15 Apr 2021 11:59:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lSMhqhb+nw2tk7EyAm68yFMOgxq3WvwKvd9QKoFQyv6AsK6QOk9YT5+K6h9ZD0GAbXjg5vbR4yu3xUMOoTVClr9Snx8MH1Phk240YcgXamnjG9jiCW1LieZ5v0D1/+lkTgWtuEaLQKzMmMZ67P88dCE/lggrrIuqw937ng57XtE9H3iNlynXF6CNlZbTKx46NlSbQ6vmmXrHX7QroQQ62Rvly5kok+BFXzRLUExrRA5Ij7FWzjFdYKY54tGEiZqDzhWyngFJ+6C3CNME5kZ3oxREXY3+ic4QhU13ek3H9+jNvywQyXk8CLV2oh2G0EGlAS66xobLeL6I2YZfYv+MvA== 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=fzHgR4/srdRrnpCFf//he/wMHnI5/X07xubuaqy1vPo=; b=NfgLHJ2T6MuMbSe23bwfXaZ/LdwuaC8RuUxzq6IkpQcZ7XjfEGct3C8VsTS0hqD6rEr1GUbQRP1KgM6NAZc89ERh1d+GBmynwK+qXvIbVdEXT6w/JDyE8/H2QiF84wsMJDAFGiksnHg79xSYE3WAtLOt/+xG4VpgsDB2ia/5n+1+YDZe4sGpXTkUIP2ZJ39vmw5t6N7aoH4wEzMsh9snxMHkGFmTbMsjErw9QT3jxl/INw8pXZLa+zAE+Voj8ebc6+jJrHNTaPVmjFQSi0KFKu1k8GX7YJsg9R3WJVrvSr/idHUU4TI8u7AXrST4rlixHhxQUNdJ2BdRWH/EbGBXHA== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fzHgR4/srdRrnpCFf//he/wMHnI5/X07xubuaqy1vPo=; b=C27UeugGWc8rOIbZnDg0GHGNf+Z83G0Lg892ZKRNHEtK1F7QYzaY34r3jPhPXwVB0vgKi9Zda2uvjuyrkcGw263QOR/SOKvbeaXfSr4bMVZO6776cTV3Wz+xzb5lQmkIHLELn5hucQC15sSxwVFnfUocLuBXd91wZfBQryNn984= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB2719.namprd12.prod.outlook.com (2603:10b6:805:6c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Thu, 15 Apr 2021 15:59:15 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:59:15 +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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 11/12] EFI: Introduce the new AMD Memory Encryption GUID. Date: Thu, 15 Apr 2021 15:58:42 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0148.namprd11.prod.outlook.com (2603:10b6:806:131::33) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR11CA0148.namprd11.prod.outlook.com (2603:10b6:806:131::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.17 via Frontend Transport; Thu, 15 Apr 2021 15:59:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f50d6138-f304-4e83-f381-08d900276b29 X-MS-TrafficTypeDiagnostic: SN6PR12MB2719: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kHkVVc+1LjHrlX9jRhSixpjha9JCtOPV+RpylX5ZduaLLKwpZ69veDWGNReaXXqBx5X+ZM1OoxiQOhpBRKujjMMtvHVkRlhfULIRkvlRhQ6g2DncB2tsLOQ9v/2SZZmfmSv0raMeCtAt/wPDRdWNLhvg4n4KHBWsQMMDoXpFkEL4Gyp72XlzadrgQS0mRI87V4Ln5XY85SibOse/sjx+4ET6nbBy7S8x8EzkW7PxRC7B1Evp4qW/9wsnAGnav8ffm7UB1Arc/3eOH+JIaE4YQ76h5hhr81Tic1QSsXxMlecTwoABez193uAhjCTaZR5k/iy62f+ejc2znQrXiV0xi/oc0uFacC8Uo8U4s6wG+Pef4y6713KgM9anHbfxlAdG/GbekEu5snprFQzKjZd8mscJPpcYwC8byhkHzfS6vTSpZ4u6U4xSdG8aFd5i8RZamkvnPpyqYZ5E5v9mXxXsYNBIKsO6zM+t2qJ/hUf48/ByiA9Zr1H4hun9OTFbk0uZlvoA/vIlAdmpPb8dsVUYk66LZ1bUMXRWSoxpYHP7yvB6PTLGz7TWPAqLSJvCcF6voBEmaxy0r3ryWNtpPLcaBv+/V0GwKSK0uS3TNWQnyP/DWclkIZWE6oL1p1nLMhU8lFLDJRUmcWrEOzxNGbiw2g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(396003)(376002)(346002)(136003)(39860400002)(2616005)(6486002)(956004)(6916009)(16526019)(66476007)(66556008)(8676002)(2906002)(66946007)(83380400001)(478600001)(6666004)(316002)(36756003)(8936002)(5660300002)(52116002)(7416002)(86362001)(26005)(38350700002)(38100700002)(7696005)(4326008)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: OQPJgTgpGqwJpB8vUzAn9G6UMz0CT7iiPzsQhUfumu1r8oXmidxLmHTnLLisqRM4uU2STbr/vR806Mepin+raJqhD+KYGMKWlI3tv6zYBkOBf00PWsl4T1WrWBmO3+fMM1hFk1Ammm+w6FJLrW+VtLCwgzym0r0yPg/IaAJ5ghEiCMmpVFrSfi0Ce9uLs1nCPhRkH8qgYu6MTaKR13R81PnKkzx/ma4zgHM840dWFcZhBKOscOS9sMxHxID86mT16pBkEUXqlqqOT+M2YVZKM8SwYidpGPPuY85CtPyliMGDQ/q9dx3VsLgyl1ax8T1ptD/j+wYvSKVNQ3v3sfUtkbi/2X9dnESIHCetqSfLXtqjWSVMhqktHZp06KC8aXn5aqWkQjhX+frJA8fUOI/8zEVPRhYEKOF5lEWfVKOi/PiJKdI8vIW6XGAvZHhwW5E4ElLkuj1NQ45RMfFx/Yv5vpXPj2f+/y6o6eVfVFD1i1v+Yw4d1hfPXhvy1Xk8VvaqAh8Z8s478HmcbCi0475DAU1eyLxouwfg39SifTX7Bp32VhTbK+GnxCcmnPkldWFLQFOBz8WFmZiqRAn2dGPjEq4C+YDNME23rOeq/T8ahbOT9sqs573eL8yjhGbM7Z9qwJYdoiLBJdq5CCKPI6v9e7YuxVGy5qqRSbXPyGMZ3LbOHBIcMQR1trMeistHBTRI+XRtd33t5ML3Pm1B180V1hJgzw/oWyF484bzs+BMLyDZBpCukkKIqvIEkDOMKc6/xKhF7Xfxl7CK94oFtQEH4fxa8hwYtQzEcV3RxEId5Khzy9Ch199zy2RXP+tw1nbBTlBcvouWbmQjYjR2cwtE3zLFsjy4Y3B48nE9gh31jolw+L+4tz4PEDpAQWIaPDrGL6aPNQFovO+gD0lbDn2yYUUdYqefVQlJ/8EL1JD+TFlnCITHXrXSCcT752I6SoahvXrqmflWacj/+kgODAVRl/wS/2TXYSKA49sJMm+WugoxBBRV+GbnUQhlO+a4b8YuERzApuhGkO0pvpkfcHz/DF/ebcOjCUhjBkb1V6t21+2gLe0TmDsKX7xDA5rqPsZjRhkeNCJ9shTCUCGKQDV7sQeherAu95hcZsYpi12pgYdhyF2zo9YTXg+9WdDX69GGibdfcXgf8PHMrlxxme7cB5un93/LJ5hjn6ZIzLmYvfkrwL4DtApXJOyShMsNwtwOGzyz5PsGTX1dn03zGdTdHIqVhCK4Suv2O3WJ9TzZa2IDOfwjWwCJqP2tnb7pRpsKR8qJgvLRGNeY4SaP5hqGoLPjUuc677EgRls7EV/rP3wC1bMEumNYiFE/sWd1V5f6 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f50d6138-f304-4e83-f381-08d900276b29 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:59:15.2581 (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: AoSVWllmSoP5kMHmrnw8Lv/sTbH85KOoPc1wNzhcyDOhtslr+H3n1oUJ3FN5qkASrFZ0y2W56GcfnAWvsFPrHg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2719 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 environment 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 6b5d36babfcc..6f364ace82cb 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -362,6 +362,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 Thu Apr 15 16:01:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69441C433B4 for ; Thu, 15 Apr 2021 16:01:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3847A611AD for ; Thu, 15 Apr 2021 16:01:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234086AbhDOQBw (ORCPT ); Thu, 15 Apr 2021 12:01:52 -0400 Received: from mail-co1nam11on2062.outbound.protection.outlook.com ([40.107.220.62]:11987 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231726AbhDOQBv (ORCPT ); Thu, 15 Apr 2021 12:01:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VZiXjUQSgXvuq2sq6olpi25CigZ0Lr8pLkynpVdD91lmBwIshfktncgu8FR42KMl6RHE3W2c5hT37gQahY8DpSPtESNbqFBx4ukA/z6lAg/SxZQlIiBJELtRwXtok0YACVewhpkxNbENh+eHDmPOTGRR/f2OPnv5JCRnQij42l+u81dFdBQsczZW4+1ygsMdmRO0uDHVAQ9EDdpcMbs6YblbhctxmjelFxpAdTEbFsU5YzRgMNnR49MOnhpyiM0dU0RyLfg1fEHGg1ogOgWLGooS+uyhLdwjzFQarhpFC5hWFZjaQCKAqEOslpXGDN6jak54P198zPdohJfkKHFn9g== 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=uLF70FUMovikKo8IBygF7beVKFc18vJMfTzLHEG+vVc=; b=GPHfMgao9axBGUf0KJ+nVs6kFTdb4P42Ay4/f06zMvc9hGtUiUtSQ4ojC0mWo3wqcNpd7t0XQbPRyS4vHz6HzrMXAA/ne3wlNfFeDcgM2M8pQ6ueJTTcS3BtzNjfninRBGiKv8TK82AP+u/RdjK53ClE0dmESU8KqGjCF/vraZ5oabF+3vP8S+V/KRPsSEfxpDCGCqR/yurC5LXamEHpmgnYvy7zb/RuSdQlyHxN4GctYJJSV1zZvXOR3PGBYFTWldHUbpXUvWxbFGkc1DkeGk09SdQ6Nr+DGi2qxN6uJQzyTvkh8PrtuoCDbkwjvqAw+78gnHqnTAMdG5HYJ50Dvw== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uLF70FUMovikKo8IBygF7beVKFc18vJMfTzLHEG+vVc=; b=1hphpmb0uBZVYPYYOMfnmFX2o/mwU82tbAcI3rrwu6ihP6OV3LH+LRQylxX57U3QRvGeYETfNkRHPp18YhyxAXgY1tjbUS4qbPq5/F98oue8Kq5sTpSNvm2YEtpH4yYGymkM43Y5JvuTriBF9/c5zNzNldV2SU0edN25/gK71K8= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4415.namprd12.prod.outlook.com (2603:10b6:806:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Thu, 15 Apr 2021 16:01:26 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 16:01:26 +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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com, kexec@lists.infradead.org Subject: [PATCH v13 12/12] x86/kvm: Add guest support for detecting and enabling SEV Live Migration feature. Date: Thu, 15 Apr 2021 16:01:16 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0187.namprd11.prod.outlook.com (2603:10b6:806:1bc::12) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR11CA0187.namprd11.prod.outlook.com (2603:10b6:806:1bc::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 16:01:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 90f20e35-6b85-4e9a-b1e3-08d90027b94d X-MS-TrafficTypeDiagnostic: SA0PR12MB4415: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:331; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c7OaLCqVQzfQJ8Yj/wuS7iimES+6mbFznkg9yDSR4Utip8Y5ULHORaFYAUXVqldDJuLs7bY6rYeHyQW15E1bR2z2cZwv5Tc8mTJj3juOTnZ8hvbYMtluXoiB+LTymRnpCRpS38KAmWwjwBh69bflpsWeD2+HFpcuGkf1YWASmeVc606q1sWtzikl99HxmFxIQN0T4ZgFvyrS/R8BGu41ARl0WCYC/eD9Ld3MeJfjxr8LvN1dXrGGkrcSosqjgnXpjkfaC22kgVUlom/UU13JA8P1WZSpIEOeBv70PZ7v8HJia5mHRykb9lC6L3JZkXfhFGdCKXYMrxCW97Q83r8GIaiWKzVvqcThTGKf4+j/YfQKE2sLslFCOSf73Y4PZjhqKGvNwRHsZFVx/5BJLSCtjcE/sk9gNKV5F8hUP/Ucsjj6W5j9X4MRz7+bpY12YwYIvT1L2wKMnQoIOhNQFTcFfnYk0Pss5vOuG7CFMwK/IVwVuIPOvXJkD+1qVa9b2D9LZ71se/M6xfnTz8VXRgg+6GJg6EV12czGTEM/TGLpPpE4LqBL0b90pJtZV5m4uAc230EE1KkWaEal8o7R1/1EnAywW1aKqyTF8JxZiKCiN/vQ7G9h2eYeykClhkP4Vciw62CARPFGfD6sCY86QrcZMg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(39860400002)(396003)(376002)(366004)(136003)(7416002)(16526019)(8676002)(186003)(8936002)(5660300002)(83380400001)(66476007)(36756003)(38350700002)(66946007)(956004)(66556008)(4326008)(6666004)(2616005)(316002)(38100700002)(7696005)(6916009)(52116002)(2906002)(6486002)(26005)(86362001)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: qvxKANlCqAx/1M8UFJMUJZIAKTginIJfwPcVFav+j/q6Fk0/uCW8TgMxSciIN+Jv/xypb66NqQl5hqTQFqFGzs3fYRYhMa93KUjm6RSAeuQ1RWiav/woKiEYZeKOc2U0GOFW+XtxQmR8ecDZX7PrlWcC6CvYM5zwCMJCU1ZbI1fG9UcJPHTDJlL0/7E4i5TcgEA+tAOIN+/oyMNdAZUrHlUy7IzGD2eDYH4gNnxwpNNNLCVfMA1Qjoz3LF0J4+SQTD08Z4I7bbAfZwNt6E+oPJ5d5BL5SQEERbolAWv6QvP+atVXFbMdWPbh1huMHBeaySO76kh/sJwDTL6p3cbPrKnmyykse3ewK3adGpiUu4/IWO/MJSz0eQRInHVJ1VhjwJNsC2Oawpj5y/j4cnEoRIGhknfyiN8kJhClxGbBxQ0KD/bwI9lJ4wH6zWk0VijT7wHiGZBm4lqxFSJvNXgPt9J/GU7mFF1/kN0VS03OIlGnt1KyvMV1PZ+8O1Dbmi5eVDm52baRvj86U14EX9Fn0x1jXGbf2sgt4ahORhE/FsXt731nVpYEzTMW9JJxhspQrmq0Nb7uRtX4wPpwVaBHIQTvjV+28CwH4WFmfcBfrmj2JtZmCgqg9Lwq2OtLKvI7P2iuZiq/oWiBcwTfz8nrnOOPXHFG4bqNxBmbT6bpk/B5KAvugtGneR1E4wA6Rz1AEW5wU2QX5CLAC+0tNkGkrt5KONG8LJfBHYWaHQVYirpw73D+FmakHMWgUBiM42kyYW72kmbIJv3wF6sCXgFPfPWn0J+x9Ec6guIqh4FirnPxMTk6kigM2FWvBdMUc33BVUAWieAOoBpAxZG0ClL6BEJtOfNbew97FVoRCRp7+U1njiFn9N58mLMjFFywuNI6lVF9+j4AKElrBg1ZHcK5Us0iQbkp3RIW45WTq0wSqoGhl8q4mmFt5cWJRGtUMYkjqTkSIPE8ak5tiKfhrCODwYvJkra3yYPz/ve6c+Bey10CB/NE2jqVNz8tDv3xrI/miG2bjQuD6L53ri2NHqicIq576vpLvbhYWfa2msDmXwZ+L0CVZZafVNYcIbiIhjFilyV5cuA73q2NgQyG0GfKMB5PAiL/SrM54+M3JfXRsfYlq2j0EbGQQ0O+Xn9LJ5/zWwIkYmcAMqSlXUEe0uBzPbD9blaEVWUPVnwM8qJz3Yb4+bqTFumVATU0ETm+vYKnrdAeKMaMxNWaYD8e/0U79DaM9KKNWu3EKUIiPhtFsolRyYmXi3q4EvG0wBBF7dqc5z19armCT+N8q2d1jzh2XySbqQZdpJIVvgDnz7ZMstp7j0jhIA29dWtCK7yufP8+ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 90f20e35-6b85-4e9a-b1e3-08d90027b94d X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 16:01:26.3816 (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: mgQDBZtxm3h8gvxES9AJs4SFLHUgdYTSdCEzhakAwEhf7yplFWebNEkkUAMMBTN4AM+kNxyBCLzOGQaBllFCgw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4415 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() invokes check_kvm_sev_migration() which checks if its booted under the EFI - If not EFI, i) check for the KVM_FEATURE_CPUID ii) if CPUID reports that migration is supported, issue a wrmsrl() to enable the SEV live migration support - If EFI, i) check for the KVM_FEATURE_CPUID ii) If CPUID reports that migration is supported, read the UEFI variable which indicates OVMF support for live migration iii) the variable indicates live migration is supported, issue a wrmsrl() to enable the SEV live migration support The EFI live migration check is done using a late_initcall() callback. Also, ensure that _bss_decrypted section is marked as decrypted in the shared pages list. Also adds kexec support for SEV Live Migration. Reset the host's shared pages list related to kernel specific page encryption status settings before we load a new kernel by kexec. We cannot reset the complete shared pages list here as we need to retain the UEFI/OVMF firmware specific settings. The host's shared pages list is maintained for the guest to keep track of all unencrypted guest memory regions, 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/include/asm/mem_encrypt.h | 8 ++++ arch/x86/kernel/kvm.c | 55 +++++++++++++++++++++++++ arch/x86/mm/mem_encrypt.c | 64 ++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 31c4df123aa0..19b77f3a62dc 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -21,6 +21,7 @@ extern u64 sme_me_mask; extern u64 sev_status; extern bool sev_enabled; +extern bool sev_live_migration_enabled; void sme_encrypt_execute(unsigned long encrypted_kernel_vaddr, unsigned long decrypted_kernel_vaddr, @@ -44,8 +45,11 @@ 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); void __init mem_encrypt_free_decrypted_mem(void); +void __init check_kvm_sev_migration(void); /* Architecture __weak replacement functions */ void __init mem_encrypt_init(void); @@ -60,6 +64,7 @@ bool sev_es_active(void); #else /* !CONFIG_AMD_MEM_ENCRYPT */ #define sme_me_mask 0ULL +#define sev_live_migration_enabled false static inline void __init sme_early_encrypt(resource_size_t paddr, unsigned long size) { } @@ -84,8 +89,11 @@ 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) {} static inline void mem_encrypt_free_decrypted_mem(void) { } +static inline void check_kvm_sev_migration(void) { } #define __bss_decrypted diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 78bb0fae3982..94ef16d263a7 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -429,6 +430,59 @@ static inline void __set_percpu_decrypted(void *ptr, unsigned long size) early_set_memory_decrypted((unsigned long) ptr, size); } +static int __init setup_kvm_sev_migration(void) +{ + efi_char16_t efi_sev_live_migration_enabled[] = L"SevLiveMigrationEnabled"; + efi_guid_t efi_variable_guid = MEM_ENCRYPT_GUID; + efi_status_t status; + unsigned long size; + bool enabled; + + /* + * check_kvm_sev_migration() invoked via kvm_init_platform() before + * this callback would have setup the indicator that live migration + * feature is supported/enabled. + */ + if (!sev_live_migration_enabled) + return 0; + + if (!efi_enabled(EFI_BOOT)) + return 0; + + if (!efi_enabled(EFI_RUNTIME_SERVICES)) { + pr_info("%s : EFI runtime services are not enabled\n", __func__); + return 0; + } + + size = sizeof(enabled); + + /* Get variable contents into buffer */ + status = efi.get_variable(efi_sev_live_migration_enabled, + &efi_variable_guid, NULL, &size, &enabled); + + if (status == EFI_NOT_FOUND) { + pr_info("%s : EFI live migration variable not found\n", __func__); + return 0; + } + + if (status != EFI_SUCCESS) { + pr_info("%s : EFI variable retrieval failed\n", __func__); + return 0; + } + + if (enabled == 0) { + pr_info("%s: live migration disabled in EFI\n", __func__); + return 0; + } + + pr_info("%s : live migration enabled in EFI\n", __func__); + wrmsrl(MSR_KVM_SEV_LIVE_MIGRATION, KVM_SEV_LIVE_MIGRATION_ENABLED); + + return true; +} + +late_initcall(setup_kvm_sev_migration); + /* * Iterate through all possible CPUs and map the memory region pointed * by apf_reason, steal_time and kvm_apic_eoi as decrypted at once. @@ -747,6 +801,7 @@ static bool __init kvm_msi_ext_dest_id(void) static void __init kvm_init_platform(void) { + check_kvm_sev_migration(); 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 fae9ccbd0da7..382d1d4f00f5 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include "mm_internal.h" @@ -48,6 +50,8 @@ EXPORT_SYMBOL_GPL(sev_enable_key); bool sev_enabled __section(".data"); +bool sev_live_migration_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); @@ -237,6 +241,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) { @@ -407,6 +414,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 @@ -462,6 +475,57 @@ bool force_dma_unencrypted(struct device *dev) return false; } +void __init check_kvm_sev_migration(void) +{ + if (sev_active() && + kvm_para_has_feature(KVM_FEATURE_SEV_LIVE_MIGRATION)) { + unsigned long nr_pages; + int i; + + pr_info("KVM enable live migration\n"); + WRITE_ONCE(sev_live_migration_enabled, true); + + /* + * Reset the host's shared pages list related to kernel + * specific page encryption status settings before we load a + * new kernel by kexec. Reset the page encryption status + * during early boot intead of just before kexec to avoid SMP + * races during kvm_pv_guest_cpu_reboot(). + * NOTE: We cannot reset the complete shared pages list + * here as we need to retain the UEFI/OVMF firmware + * specific settings. + */ + + for (i = 0; i < e820_table->nr_entries; i++) { + struct e820_entry *entry = &e820_table->entries[i]; + + if (entry->type != E820_TYPE_RAM) + continue; + + nr_pages = DIV_ROUND_UP(entry->size, PAGE_SIZE); + + kvm_sev_hypercall3(KVM_HC_PAGE_ENC_STATUS, entry->addr, + nr_pages, 1); + } + + /* + * Ensure that _bss_decrypted section is marked as decrypted in the + * shared pages list. + */ + nr_pages = DIV_ROUND_UP(__end_bss_decrypted - __start_bss_decrypted, + PAGE_SIZE); + early_set_mem_enc_dec_hypercall((unsigned long)__start_bss_decrypted, + nr_pages, 0); + + /* + * If not booted using EFI, enable Live migration support. + */ + if (!efi_enabled(EFI_BOOT)) + wrmsrl(MSR_KVM_SEV_LIVE_MIGRATION, + KVM_SEV_LIVE_MIGRATION_ENABLED); + } +} + void __init mem_encrypt_free_decrypted_mem(void) { unsigned long vaddr, vaddr_end, npages;