From patchwork Thu Apr 30 08:40:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A28313B2 for ; Thu, 30 Apr 2020 08:40:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 481152173E for ; Thu, 30 Apr 2020 08:40:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="uyO8BceX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbgD3Ikt (ORCPT ); Thu, 30 Apr 2020 04:40:49 -0400 Received: from mail-dm6nam12on2076.outbound.protection.outlook.com ([40.107.243.76]:14610 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726754AbgD3Ikt (ORCPT ); Thu, 30 Apr 2020 04:40:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LOdjiy7b794A6y+z8gEsAI61X6skaOPZMD53BgfCC1zziI5yE9tmNhFlnBQkWrDZIh7Q47G41bnpyMHE4KRnX/X50hOEocIRqGdRsjxMOvdYozrPeaSvh6D0/Q65WSLB5Ps6itCSHu3/VoHnKoHkS4KqjyCRh6ZHkxX3aZJesWtC5he+IUOa5cypjx6HJLRxSi2NXJfsqCKLPiuUkw/bupMQFgH4MHvl5ROVNYI0le0jFwu80RhQ81GvLGbyAUYvr9g+puMLF61/5nlKzbSRabqutBNZBSpzdCZhTgbBRT5EHEsjm+raHUdJLJxQ+XxlpFxP1JalprAzo8G7gUkLNA== 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=6RN28DlwIc8RRI8Uq6lrkfx+zWgbR9fO57VBxpIVyYE=; b=ZSNMWARCMNb7bfMqpMpuWkiDD1Ec0bx7vx1fozAm7xKNRTGs0yPdFUafDRzpGKreBA16tFXnqbGEqIb2MV70fYczXz7V116ntUiKPk7jDhm1ULMwMn0A8+yWEOGTREMeX7wIWYeDCa4uydDHlcZsm72DI+LXgVBksK37ad53EjEGclzy9iCewW1wFXa/KWDQQLU61RiRP8Y2TuTNp78V2nQIoqr1OI+vFDU1Q/NNPQ4D1+nwwFjHeJXLtAeh0zuxlMmgjnpVEtWiVh0mr8dkh28XGXjReHu8F5B9RZDwg42Q1yve36IZJVb4SZ1IPnzSUOwJYR9n229EUVv/zMYaEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6RN28DlwIc8RRI8Uq6lrkfx+zWgbR9fO57VBxpIVyYE=; b=uyO8BceXHViSbKMRqqUFyrOUl96VzqLtJn2ebHtVBrcueRDT4ZqCoc9It48xJKE6kcUmv2carrtB+z4S+rN+B/9tWc0BgapWZcvoQYunqzxdBxBfP6at5UH2sZSbmRwYd3E7/bFT3sheuDetEfYjNlV8WHX9PRusgb0k4mJT2oQ= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1194.namprd12.prod.outlook.com (2603:10b6:3:6e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:40:45 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:40:45 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 01/18] KVM: SVM: Add KVM_SEV SEND_START command Date: Thu, 30 Apr 2020 08:40:34 +0000 Message-Id: <6473e5803d8c47d9b207810e8015c3066c39f17d.1588234824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN4PR0801CA0012.namprd08.prod.outlook.com (2603:10b6:803:29::22) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN4PR0801CA0012.namprd08.prod.outlook.com (2603:10b6:803:29::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:40:43 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e1042b79-54a1-4432-5929-08d7ece22c43 X-MS-TrafficTypeDiagnostic: DM5PR12MB1194:|DM5PR12MB1194: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(136003)(396003)(366004)(376002)(39860400002)(4326008)(6486002)(6916009)(66574012)(66476007)(66946007)(52116002)(186003)(36756003)(7696005)(6666004)(316002)(5660300002)(26005)(86362001)(2906002)(8676002)(478600001)(66556008)(8936002)(956004)(2616005)(7416002)(16526019)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KintJ+iMvXU4o8iu2vQ/fgcGA19w0Ufkg90/gUL4Nu8ypfpu43+XrYvuUgdhBGXH+qzoXo3CMBZDgGvWcCX15HBvy4840UKnCnmGduaOrf2G7CFii5SAAhFVF8GAQ9IKv0QlDtsh3siyrWp6pyKepImWdl8qgABf682qSqnFXzLf3wc6IEtEa+RPupq29m8P8aJg+L0Pu4xVaY9wfRQoWN9PNfkyxzwRn/V8uebKJbiBxLF/wtbQbtc4o8UaFZ+t+ISOjQOkoCYIFsWwKiPx6O0bpR0mTe4tlyouDrd7LdTmAMeSQcOF2TwyJxtldYa4idrD5iWTjfQhzP5AlhqXAakJRgeBDHoeSDyCHb97r9A7dW2oRoHpSBNwqTQZ11ppIteThtR12ukNsZYvylY5c3U+mwhA1yyEcFu777gejOU3BovTag+kXHIi891FsljcGDbMiWKt4m8obPpsiII41dskl/z4glwBkC4EAJiGz4MtwF8P1jvqLw2cepkAIwsh X-MS-Exchange-AntiSpam-MessageData: 1KO4DvalnBEgzG2luYDHNEVm81x+1v7KcshDqUznuJocVinprSg2mlyelpEPJT1mOzCQXPPNkNouMmvPoa0YUqTrAYHJPGuSgEL0ksIVsFOOWPrBamr8/oqpYTmVj1/bJp27c5AVumNniXY/IcYUDJnsLEuowGUldIwLyrdumW8Db/I1s/JCVeuSZcIR/X8wtChVm67osSsLG+k4faw21HuiR8ImyiPVYnm4pqY0Sc5l6HB1e17VrrnvjkP/lTupXqALemjpPFsuqAKPm3+rfiyZSTt+nf5Mq+ofSTV94igpBXuk9za0zq/kPaUS9TeM/IFokd9KRs15Yb40e/V8gRxHtVSeid7EiYyMNRV2F6DWVVldD+bT660WMBLrhEDz4iQBUVy7cwLaXPKLQ3pw0s1K2LpXmjrfylJ25rKtOvkLQVTuVFARNXLG/qXw5fBBGnzFWiOEGaVProRxWlwqX18qOJXWAQP81jh+vr8SZh+l+fekgrwvFqvudp9AZG71GQWV5iSFKcRzAsBIackjdm/Mu6wt53Oeb1oUHSB/+nTmxEJhrnd4ORy4/LPmvaJaBiVBVNL2sOKgLpoZIutlMSzQQQv6envWcIprAwdWrlYowzFciSogl0DKPgsusHK9FbapDyQRu+XxarAjlClXC7c3YoeH2wDrF3yQIBTNrvd1gOCacoxF7wzQXdB0dMXxVAAyGLyg74aINH/ucbpfTAUxUx2WYnThVg6MAVorY86MZy+BasOGXKSfRWnQq4xzS97TW7RrcpslniyawX9i49sWwwTMpI6odkMX3l+dG14= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1042b79-54a1-4432-5929-08d7ece22c43 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:40:44.8838 (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: SQJl8X2SPL1qVRQ7wCDwtTm2O4vuHhpe21JzGk2AWWhmAKeST/SEFxBcNTOeTvLRoWY+JbkBJN1bDwFVUv+tkA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1194 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used to create an outgoing SEV guest encryption context. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 27 ++++ arch/x86/kvm/svm/sev.c | 125 ++++++++++++++++++ include/linux/psp-sev.h | 8 +- include/uapi/linux/kvm.h | 12 ++ 4 files changed, 168 insertions(+), 4 deletions(-) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index c3129b9ba5cb..4fd34fc5c7a7 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -263,6 +263,33 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +10. KVM_SEV_SEND_START +---------------------- + +The KVM_SEV_SEND_START command can be used by the hypervisor to create an +outgoing guest encryption context. + +Parameters (in): struct kvm_sev_send_start + +Returns: 0 on success, -negative on error + +:: + struct kvm_sev_send_start { + __u32 policy; /* guest policy */ + + __u64 pdh_cert_uaddr; /* platform Diffie-Hellman certificate */ + __u32 pdh_cert_len; + + __u64 plat_certs_uadr; /* platform certificate chain */ + __u32 plat_certs_len; + + __u64 amd_certs_uaddr; /* AMD certificate */ + __u32 amd_cert_len; + + __u64 session_uaddr; /* Guest session information */ + __u32 session_len; + }; + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index cf912b4aaba8..5a15b43b4349 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -913,6 +913,128 @@ static int sev_launch_secret(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +/* Userspace wants to query session length. */ +static int +__sev_send_start_query_session_length(struct kvm *kvm, struct kvm_sev_cmd *argp, + struct kvm_sev_send_start *params) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_start *data; + int ret; + + data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT); + if (data == NULL) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_START, data, &argp->error); + + params->session_len = data->session_len; + if (copy_to_user((void __user *)(uintptr_t)argp->data, params, + sizeof(struct kvm_sev_send_start))) + ret = -EFAULT; + + kfree(data); + return ret; +} + +static int sev_send_start(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_start *data; + struct kvm_sev_send_start params; + void *amd_certs, *session_data; + void *pdh_cert, *plat_certs; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_send_start))) + return -EFAULT; + + /* if session_len is zero, userspace wants to query the session length */ + if (!params.session_len) + return __sev_send_start_query_session_length(kvm, argp, + ¶ms); + + /* some sanity checks */ + if (!params.pdh_cert_uaddr || !params.pdh_cert_len || + !params.session_uaddr || params.session_len > SEV_FW_BLOB_MAX_SIZE) + return -EINVAL; + + /* allocate the memory to hold the session data blob */ + session_data = kmalloc(params.session_len, GFP_KERNEL_ACCOUNT); + if (!session_data) + return -ENOMEM; + + /* copy the certificate blobs from userspace */ + pdh_cert = psp_copy_user_blob(params.pdh_cert_uaddr, + params.pdh_cert_len); + if (IS_ERR(pdh_cert)) { + ret = PTR_ERR(pdh_cert); + goto e_free_session; + } + + plat_certs = psp_copy_user_blob(params.plat_certs_uaddr, + params.plat_certs_len); + if (IS_ERR(plat_certs)) { + ret = PTR_ERR(plat_certs); + goto e_free_pdh; + } + + amd_certs = psp_copy_user_blob(params.amd_certs_uaddr, + params.amd_certs_len); + if (IS_ERR(amd_certs)) { + ret = PTR_ERR(amd_certs); + goto e_free_plat_cert; + } + + data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT); + if (data == NULL) { + ret = -ENOMEM; + goto e_free_amd_cert; + } + + /* populate the FW SEND_START field with system physical address */ + data->pdh_cert_address = __psp_pa(pdh_cert); + data->pdh_cert_len = params.pdh_cert_len; + data->plat_certs_address = __psp_pa(plat_certs); + data->plat_certs_len = params.plat_certs_len; + data->amd_certs_address = __psp_pa(amd_certs); + data->amd_certs_len = params.amd_certs_len; + data->session_address = __psp_pa(session_data); + data->session_len = params.session_len; + data->handle = sev->handle; + + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_START, data, &argp->error); + + if (!ret && copy_to_user((void __user *)(uintptr_t)params.session_uaddr, + session_data, params.session_len)) { + ret = -EFAULT; + goto e_free; + } + + params.policy = data->policy; + params.session_len = data->session_len; + if (copy_to_user((void __user *)(uintptr_t)argp->data, ¶ms, + sizeof(struct kvm_sev_send_start))) + ret = -EFAULT; + +e_free: + kfree(data); +e_free_amd_cert: + kfree(amd_certs); +e_free_plat_cert: + kfree(plat_certs); +e_free_pdh: + kfree(pdh_cert); +e_free_session: + kfree(session_data); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -957,6 +1079,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_LAUNCH_SECRET: r = sev_launch_secret(kvm, &sev_cmd); break; + case KVM_SEV_SEND_START: + r = sev_send_start(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 5167bf2bfc75..9f63b9d48b63 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -323,11 +323,11 @@ struct sev_data_send_start { u64 pdh_cert_address; /* In */ u32 pdh_cert_len; /* In */ u32 reserved1; - u64 plat_cert_address; /* In */ - u32 plat_cert_len; /* In */ + u64 plat_certs_address; /* In */ + u32 plat_certs_len; /* In */ u32 reserved2; - u64 amd_cert_address; /* In */ - u32 amd_cert_len; /* In */ + u64 amd_certs_address; /* In */ + u32 amd_certs_len; /* In */ u32 reserved3; u64 session_address; /* In */ u32 session_len; /* In/Out */ diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 428c7dde6b4b..8827d43e2684 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1598,6 +1598,18 @@ struct kvm_sev_dbg { __u32 len; }; +struct kvm_sev_send_start { + __u32 policy; + __u64 pdh_cert_uaddr; + __u32 pdh_cert_len; + __u64 plat_certs_uaddr; + __u32 plat_certs_len; + __u64 amd_certs_uaddr; + __u32 amd_certs_len; + __u64 session_uaddr; + __u32 session_len; +}; + #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2) From patchwork Thu Apr 30 08:40:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBF6A14B4 for ; Thu, 30 Apr 2020 08:41:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB9F321973 for ; Thu, 30 Apr 2020 08:41:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="lf2feP0R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726793AbgD3IlF (ORCPT ); Thu, 30 Apr 2020 04:41:05 -0400 Received: from mail-mw2nam10on2058.outbound.protection.outlook.com ([40.107.94.58]:6149 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726745AbgD3IlE (ORCPT ); Thu, 30 Apr 2020 04:41:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C/l1+CWmwFPYjf3z5M8hyxyEbTaQ55gjSIwFdq7+Fhx4eAK1y9wAtsDYA4hjN56MXr6zdUeacKERATj1F+WqZljIa72JvpgqXoTVAuNul3gVnRqCTS5gsTw3BoouH8AGi1sT82kz4QffsCbZUFiNdxCq33OWqNy1ppbEI3VYu4apX5pP9bwRX+WSR5G/AssFoPAY3poW1An5wkvYSkD3HZkHBnR3+pYXUKQHwPDy1M0piitqrNSpEPMLO5F/uRUHLI2yEEQkw2wsFy2jLTFNLn7MUcTe5ksx3wVvwRIAG3Jm8V87Ke8AhWwCj7+ktZw19mioQ4znwZxlsCnEoEvtHQ== 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=44QDKHsa4qasKw8Lcijcs9cSFGs51YW3G2Xs1RZrv5g=; b=g4zHn2PHvK7/qdN7oc6Sjc4awcfWnj7WhxgAtLqo9+7ab2y38qUEzBNfl0CVyOiso2+HMlAIUInlPYN08ZScF62KgQO0x1pEEGfNp+Ir2ZzfFT8X8FIsxkGAgCchx75gnhOhnxqB+G8tIjxkHOF4rPcDjEnB2NstftLkdfdHJ1ITkjbkCic10jGMRWQJOSbrM8D6kBGA1O2BxZZyZw7rUq088GNryss95FvotIRSWpFmn6011UeV2IVpoUs3cl3n9Gzj6kAbmayNhLa3z6c0zyklHmCwv6r8TTqhMd2bdXwYgjYcL8dRziM8bwZxXq7md9pATXQNwVwgqSjKy11qvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=44QDKHsa4qasKw8Lcijcs9cSFGs51YW3G2Xs1RZrv5g=; b=lf2feP0R0AcCEHVdtKObN8UmIcrcvd5vmqBMyispVEhZRskCSznTh7cy1gJGgncP+dYLZc7wvtQIyVGoCllV95WCsPtn+TloCzA1tB2Wy+QUCRsooNqpkS//pjtBMlVEqkc7W78ggncGaQEn1uucg1WEn7izANt5rQxKta9+tkk= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1194.namprd12.prod.outlook.com (2603:10b6:3:6e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:40:59 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:40:59 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 02/18] KVM: SVM: Add KVM_SEND_UPDATE_DATA command Date: Thu, 30 Apr 2020 08:40:50 +0000 Message-Id: <8d336fdd83e9b698354b5572d5f2bd1660879fc4.1588234824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0015.namprd20.prod.outlook.com (2603:10b6:3:93::25) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by DM5PR20CA0015.namprd20.prod.outlook.com (2603:10b6:3:93::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:40:58 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a6b82b8b-c1d7-4436-21de-08d7ece23533 X-MS-TrafficTypeDiagnostic: DM5PR12MB1194:|DM5PR12MB1194: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(136003)(396003)(366004)(376002)(39860400002)(4326008)(6486002)(6916009)(66574012)(66476007)(66946007)(52116002)(186003)(36756003)(7696005)(6666004)(316002)(5660300002)(26005)(86362001)(2906002)(8676002)(478600001)(66556008)(8936002)(956004)(2616005)(7416002)(16526019)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GAsbBh0kA9WPiUy1+Srsgc2EDqs0oTMqYUmII9J0H0R8NvzCLBzyESj8ZnIqHvZva1TiVaBNvAybURtLaUbJ2AGSe8kbLIws1LGygUyVwlibITntzsSyu0/Yrlo9VZF7eszAPlWrh93Q36CAaUoqK+tyCSsQwtpZS0Aj7TRxXTQiZ3eKbLM9ipEHxvherhQNFoaFXKpAghhfjLvDV9j7et3OEyppogKLlaepd10SxkQrc58RdKtBemHNroeqj3qe+jM0rDlkl7pothh4tYkxFkBhaX8CUW5ayTNsfevk8OR3ge6vgMFFYL3n/Cxp6DfBReotH4OPgHxr/ejLhzl7VtJURmxDYuMh9HiKT1nZZkjm1RJrYlNvWPf94quG9DalMab7QJXkSoLAWMYOgwUYBOy8N3JPhgitCNd/f8Rs/oI96ir6qVUaze9EDRVSYZA0Hc4M9FAxMOM3IJiKt0TmKpCM+y0pJCobtBwe4gxkcTrl+P2SayhFntNyM0mBv19w X-MS-Exchange-AntiSpam-MessageData: TSvucj60dSn/samwtUeJ/cd2pGjWVSezNLs3ksvvDkK33OwMg/x/1QjHKV4kjmrKKAZrnnSd2R+YxLrLqY9V6s4rCVxOEOYDHEWujSX+1rA7x9uZom6MLzAwBkoUEE8zrvFbdKGXtE/q+flA5UPO4pjy/WyDD27QuNw+XGFogDYvLaybRdGH/a+7z6aFlMes5KualVf7MoylpJnWE974e7zyr0txWbO0LYSYVQVT8hXTE3mh8c/uIrGfJu+FvgG8JHgsmqoPmZ4E931myqWLp4KCHNSOOffUqr4L3hH0euX34I+01LYNDbHrGoCg1o/OkPqWYl5SXOGh0P9NCR5wzJM8tBJ4YpKvkm31wlfxY5nN2gjprLb8uyaNOtOHWQ7JQJDpNs+q40xYOY2O3z/L0gbZ1FGK5mHARS+tfx8dg/rkGntP9eLDz13Gz6jim9TyfohXDYQlEOU7AhDO9KlNs8WeBVKzgiXz4j0L+N7ni8owtO1ev6gP7JF74sFF9VXFPX6JU5pzaRMxmPI20ID8vQ23Nep5n0vz1ZmrRajwx9xS+tEfon0FUMwX73MWH0pifWOXOYIDLH2RIpcVNH4WpUGbkTG6KaaLR1oscwqcSu57aRmdE3j6ga6PQVMFT5mQpRoUh90u3GEXINPCeR77x7f/vAvabDzmh1xUx6ZIV2zaMk+0dCTKEHn9de2KmxediHeTJrVM3w9Ds99V0FIuZEOE4gMc1X2PetYj1X5WM0ezhBMpo6kTGaWD1vlU20CIduhQwxQ3cTqsdYfhQKJsYgtDm0AugdQqjHVMySemUsE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6b82b8b-c1d7-4436-21de-08d7ece23533 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:40:59.7721 (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: naVY8FbRz9vPmRUuXl1i8mgGdBbHaUm3AP8AvLp0fZzDg+d7quCdaKGjAcwva3XcTPImwv3TKFkwMyb36Ge3oA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1194 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used for encrypting the guest memory region using the encryption context created with KVM_SEV_SEND_START. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by : Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 24 ++++ arch/x86/kvm/svm/sev.c | 135 +++++++++++++++++- include/uapi/linux/kvm.h | 9 ++ 3 files changed, 164 insertions(+), 4 deletions(-) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index 4fd34fc5c7a7..f46817ef7019 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -290,6 +290,30 @@ Returns: 0 on success, -negative on error __u32 session_len; }; +11. KVM_SEV_SEND_UPDATE_DATA +---------------------------- + +The KVM_SEV_SEND_UPDATE_DATA command can be used by the hypervisor to encrypt the +outgoing guest memory region with the encryption context creating using +KVM_SEV_SEND_START. + +Parameters (in): struct kvm_sev_send_update_data + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_launch_send_update_data { + __u64 hdr_uaddr; /* userspace address containing the packet header */ + __u32 hdr_len; + + __u64 guest_uaddr; /* the source memory region to be encrypted */ + __u32 guest_len; + + __u64 trans_uaddr; /* the destition memory region */ + __u32 trans_len; + }; + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 5a15b43b4349..0c92c16505ab 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -23,6 +23,7 @@ static DECLARE_RWSEM(sev_deactivate_lock); static DEFINE_MUTEX(sev_bitmap_lock); unsigned int max_sev_asid; static unsigned int min_sev_asid; +static unsigned long sev_me_mask; static unsigned long *sev_asid_bitmap; static unsigned long *sev_reclaim_asid_bitmap; #define __sme_page_pa(x) __sme_set(page_to_pfn(x) << PAGE_SHIFT) @@ -1035,6 +1036,123 @@ static int sev_send_start(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +/* Userspace wants to query either header or trans length. */ +static int +__sev_send_update_data_query_lengths(struct kvm *kvm, struct kvm_sev_cmd *argp, + struct kvm_sev_send_update_data *params) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_update_data *data; + int ret; + + data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT); + if (!data) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_UPDATE_DATA, data, &argp->error); + + params->hdr_len = data->hdr_len; + params->trans_len = data->trans_len; + + if (copy_to_user((void __user *)(uintptr_t)argp->data, params, + sizeof(struct kvm_sev_send_update_data))) + ret = -EFAULT; + + kfree(data); + return ret; +} + +static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_update_data *data; + struct kvm_sev_send_update_data params; + void *hdr, *trans_data; + struct page **guest_page; + unsigned long n; + int ret, offset; + + if (!sev_guest(kvm)) + return -ENOTTY; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_send_update_data))) + return -EFAULT; + + /* userspace wants to query either header or trans length */ + if (!params.trans_len || !params.hdr_len) + return __sev_send_update_data_query_lengths(kvm, argp, ¶ms); + + if (!params.trans_uaddr || !params.guest_uaddr || + !params.guest_len || !params.hdr_uaddr) + return -EINVAL; + + /* Check if we are crossing the page boundary */ + offset = params.guest_uaddr & (PAGE_SIZE - 1); + if ((params.guest_len + offset > PAGE_SIZE)) + return -EINVAL; + + /* Pin guest memory */ + guest_page = sev_pin_memory(kvm, params.guest_uaddr & PAGE_MASK, + PAGE_SIZE, &n, 0); + if (!guest_page) + return -EFAULT; + + /* allocate memory for header and transport buffer */ + ret = -ENOMEM; + hdr = kmalloc(params.hdr_len, GFP_KERNEL_ACCOUNT); + if (!hdr) + goto e_unpin; + + trans_data = kmalloc(params.trans_len, GFP_KERNEL_ACCOUNT); + if (!trans_data) + goto e_free_hdr; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + goto e_free_trans_data; + + data->hdr_address = __psp_pa(hdr); + data->hdr_len = params.hdr_len; + data->trans_address = __psp_pa(trans_data); + data->trans_len = params.trans_len; + + /* The SEND_UPDATE_DATA command requires C-bit to be always set. */ + data->guest_address = (page_to_pfn(guest_page[0]) << PAGE_SHIFT) + + offset; + data->guest_address |= sev_me_mask; + data->guest_len = params.guest_len; + data->handle = sev->handle; + + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_UPDATE_DATA, data, &argp->error); + + if (ret) + goto e_free; + + /* copy transport buffer to user space */ + if (copy_to_user((void __user *)(uintptr_t)params.trans_uaddr, + trans_data, params.trans_len)) { + ret = -EFAULT; + goto e_unpin; + } + + /* Copy packet header to userspace. */ + ret = copy_to_user((void __user *)(uintptr_t)params.hdr_uaddr, hdr, + params.hdr_len); + +e_free: + kfree(data); +e_free_trans_data: + kfree(trans_data); +e_free_hdr: + kfree(hdr); +e_unpin: + sev_unpin_memory(kvm, guest_page, n); + + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1082,6 +1200,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_SEND_START: r = sev_send_start(kvm, &sev_cmd); break; + case KVM_SEV_SEND_UPDATE_DATA: + r = sev_send_update_data(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; @@ -1238,16 +1359,22 @@ void sev_vm_destroy(struct kvm *kvm) int __init sev_hardware_setup(void) { struct sev_user_data_status *status; + u32 eax, ebx; int rc; - /* Maximum number of encrypted guests supported simultaneously */ - max_sev_asid = cpuid_ecx(0x8000001F); + /* + * Query the memory encryption information. + * EBX: Bit 0:5 Pagetable bit position used to indicate encryption + * (aka Cbit). + * ECX: Maximum number of encrypted guests supported simultaneously. + * EDX: Minimum ASID value that should be used for SEV guest. + */ + cpuid(0x8000001f, &eax, &ebx, &max_sev_asid, &min_sev_asid); if (!svm_sev_enabled()) return 1; - /* Minimum ASID value that should be used for SEV guest */ - min_sev_asid = cpuid_edx(0x8000001F); + sev_me_mask = 1UL << (ebx & 0x3f); /* Initialize SEV ASID bitmaps */ sev_asid_bitmap = bitmap_zalloc(max_sev_asid, GFP_KERNEL); diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 8827d43e2684..7aaed8ee33cf 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1610,6 +1610,15 @@ struct kvm_sev_send_start { __u32 session_len; }; +struct kvm_sev_send_update_data { + __u64 hdr_uaddr; + __u32 hdr_len; + __u64 guest_uaddr; + __u32 guest_len; + __u64 trans_uaddr; + __u32 trans_len; +}; + #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2) From patchwork Thu Apr 30 08:41:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519487 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 897C814B4 for ; Thu, 30 Apr 2020 08:41:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CB652173E for ; Thu, 30 Apr 2020 08:41:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="yLk39r6x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726877AbgD3IlZ (ORCPT ); Thu, 30 Apr 2020 04:41:25 -0400 Received: from mail-dm6nam12on2047.outbound.protection.outlook.com ([40.107.243.47]:52736 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726842AbgD3IlU (ORCPT ); Thu, 30 Apr 2020 04:41:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZdtL6/Z3+z8SLhgE3x/zNfXnpvUjpovup4mdy2KyIzra85xUTw/ix7OX9hYxxfthbioUfrEx7sKQSEJBesx2VhP5AI/2AeWt9m0gJkyEAZC0TDMdpL2pdQ0oBiQMhia06FMiKofTyrWjIJ4dm+KQqJXeySs5KdfbqcJTMjeg3+lgFvcnrHoqXNFgwaOhsoFhplyLlfFAbbhRjvAdNhXwPnL28TiqghE4oh6Q3nHftCRwJoj6iZUR61ILOSbiJRYtT3ydNai3wqiMnamQ+zOsdXTd6c9yLLWjYnOVKLpmWHmj9vFQQ4+HPr8048st6O+szsF4g2ohnISVnx9ImSLvFw== 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=7t1u0Odkf4Ry/swhE1/sGgWCpzmGYMaFxWHHKqwhBe8=; b=bpiRD7WK7CLLkEmferddpOxj8z+YnpJ4azVPf8Qr1mJwS/zNMEuaV/vGpUhQ+mo8A1LY8BZDy2KowoIFXPzF0rS7P6pvzWxlLECzaeJSDD0Gp7itGy8fIqm6eUrSzxtW7uVcz3FQhqzTvBcMFSS5m+ApQXYPWWfSaOKoyMPGWDkURiHhONmuaMjdgzXsDPeqxgr+EAME/FpjRgrB4QEIgr/1bnZspfNxZ2nY3DrXWHHO0TXGIC3Otdly0MU+YYmWVFxuL2dqDz0b0I50TpBhMGjbe6YfdxtDqjCqalNS2aQ5NWoSxEUlWQpjfSDg7J0Q5/0lT6AYyyYSgKcW5f1uTg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7t1u0Odkf4Ry/swhE1/sGgWCpzmGYMaFxWHHKqwhBe8=; b=yLk39r6xoCNCwGB96QgtZM4gDiGkFNRWjCYMh/yYW/hCZEzjlEbno3Vg2SYq+17fd9NplErf+Icjg5C+YwWjZjyG44L3Y4e6mq9BuJo8AYjMJARbPgfsn4Kf03oJSqsaxRgZNx1PMLLopW2IA5GxO/NCLqJexcPXS4J+t5u+UN8= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1194.namprd12.prod.outlook.com (2603:10b6:3:6e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:41:17 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:41:17 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 03/18] KVM: SVM: Add KVM_SEV_SEND_FINISH command Date: Thu, 30 Apr 2020 08:41:08 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR19CA0034.namprd19.prod.outlook.com (2603:10b6:3:9a::20) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by DM5PR19CA0034.namprd19.prod.outlook.com (2603:10b6:3:9a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:41:17 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ed154eca-ac80-4ba2-67bf-08d7ece23ff4 X-MS-TrafficTypeDiagnostic: DM5PR12MB1194:|DM5PR12MB1194: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(136003)(396003)(366004)(376002)(39860400002)(4326008)(6486002)(6916009)(66574012)(66476007)(66946007)(52116002)(186003)(36756003)(7696005)(6666004)(316002)(5660300002)(26005)(86362001)(2906002)(8676002)(478600001)(66556008)(8936002)(956004)(2616005)(7416002)(16526019)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qb8o12gaF4sLWBNilRvD/4t0H6ZCEQg9rXZL/C6mfp0PuNMbJforTcPsiuWpnqoUSGkEbjxQrLtSOia9etD9jGkjql9UbRPVEFjaGe7S7l9k5Qm48U2zk0XbemXLODViwpKIsX/0js0VkyZH3GFsYxAeyjBM6v0KvFB0GrEgoL8JrCFxZNoSAx3etO3wU5FJZEys0YQTTMjz2utuxf8ddySaJFhojH9xiISQOaQKp4D8WpxtdzHMPnnMEo3hTXj+wNmTKClGDcEzcu2Yvd5rjedjsvt64s+SHyktbICD6gTe2xKZr0AK4SGmChlXI5jXYx2oaWhlIovWwjdVzU9IPidvBgThS0Cq4jC9rEgLVM0yR4mvp+7BOvJl7IOm0lMS9t436JROu3gH6TV4HATvZhAtEKKl4uBRSy7Ty9P51vsL1To45oFMwJo+hIbV9yzb6tGA/U77tYJplPUSCEfpSiPHaHQrUmK8K9HFWFtSs6favOXnQILAUCJOIpln63lk X-MS-Exchange-AntiSpam-MessageData: 0ejhoAqzrONz+O7HRbNBgFCPhbX35cSpnVPZeVYaFMmezdzqb2IOEHaCkPZXTK1aA3OjdVJv2GA3cK1s8eCuZYeZejnn4FXrcppiblb1Psswep2ljMJk2winNF2gntJT4927ekCtb7VinnNx+aLoyhLo837OnttmM+3wmwHPoRaC9sZSVcYjvQmheZcl8OY8kJBLMxh6eGfkIa2yOn24SuEs34AyJQcT88w/+P0vbrk1I6zngYoThijSSH04Jg4C8JYq18WnyVEFGX8rw4rLJs7ztUHBCIMMr0vgzbl3jCk1e5koGea6V5rTxBI4+pUTmTDzp5oCMIM8If/oMXNZ2DoCkmCB4houht8/v9wRdUSKjgjHf9bZ3I/iptucKn6gjYlmQVeDoufWE5D3z9tSUtpvDkymJRnfU0PsQAZgbwaxU8IPqh8e7EbGPj6RSblFfHpi2aRG0TY+RM0F61cAg9Es1sYhRAK0gZYuM2qpEC7vR93COSXdenEFOVDSLHoo81ZWlv3gKKurx+TmtrnWuTBy6vkTzK3IBAA6O++YyK09SKmf6lC2r31OTfRAbVw7mXnR6WXd+oFNTC45pUgd58p+aSxz4q8aURPuYnNFL7/sZ8GXHnnb4w4Mx2Z/9HhQbIpKRAMMytwCor7h7v8wELNQYIZodzVnkXsB61sAWzMnvRzsxF2p9R9ZMIEjfICgQNWvFXI6ZAP0uk2LaXpWWU2BGHY43RoubueMUI0Tk9g6zOpaI8wrrCvv81oED6CHd2+Mg56zb3CwCPluH5WrAyMg1CTUufTwYPsSESOc0/4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed154eca-ac80-4ba2-67bf-08d7ece23ff4 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:41:17.8229 (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: wFRWFQNujn2TIA+OK45hEjNMrS2v6iz+PsrFSD4e6XKOIrzz4ZFNGv3rNKBXVCMXfauXQe58dZ/zHtaw76qXHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1194 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used to finailize the encryption context created with KVM_SEV_SEND_START command. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../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 f46817ef7019..a45dcb5f8687 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -314,6 +314,14 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +12. KVM_SEV_SEND_FINISH +------------------------ + +After completion of the migration flow, the KVM_SEV_SEND_FINISH command can be +issued by the hypervisor to delete the encryption context. + +Returns: 0 on success, -negative on error + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 0c92c16505ab..81d661706d31 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1153,6 +1153,26 @@ static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_send_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_finish *data; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_FINISH, data, &argp->error); + + kfree(data); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1203,6 +1223,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_SEND_UPDATE_DATA: r = sev_send_update_data(kvm, &sev_cmd); break; + case KVM_SEV_SEND_FINISH: + r = sev_send_finish(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; From patchwork Thu Apr 30 08:42:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519489 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5AB013B2 for ; Thu, 30 Apr 2020 08:42:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 841C82186A for ; Thu, 30 Apr 2020 08:42:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="T+wvdE98" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726757AbgD3ImT (ORCPT ); Thu, 30 Apr 2020 04:42:19 -0400 Received: from mail-mw2nam10on2080.outbound.protection.outlook.com ([40.107.94.80]:25472 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726412AbgD3ImS (ORCPT ); Thu, 30 Apr 2020 04:42:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aPz+E/DZMwKeMn6p8/u1SsMjJAfxGZ0Ed2Ey0U9a1vriMbfb9Eq8OZh5FVFhb+8o9f7uTTshumXIvDzyDqGQLy944fB0TISRdtxLoKt8JABFYDdW0wgIzxC0Engazm8M/gu8k2NB5pwDrCMagynabF6mG98xx5zc0ayMv9XgTuV9+YP+r8Ql+nRIz+lRe3XK+186wDOHTRyO9dIDjsST1dW8QxSXRMSiKk2ERzXz+MuBsSMy6ZUfatx04u294+tqnpFgQpuA4PCax4InAqMv0OiiMf6XijSf0o1BY4jMh1E5ka6yFWt+T/LZGHpCzXvnsVssp/mGoHqZ2MTsR0mmWQ== 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=/H/Y28SnmelHNh6Ay33aqWw4exMfXpw0rMmSi3rnEOc=; b=CyrhtQNdEqid4zHVlUnoDkrbOnYvrJdEhaWqeHHD9tVozAsTyPeF485xUjDvy9G5a3Y3ii1gWRayKVzEvYflt7uv03Eso3RokKn/a0bgq8LdqJ8DtTXER7EiOmxe7SaaIf2drTSCkou7mnj2zEk/57akW8kflGy0Ry2av3I2REgfkie5GDBAHU/cvTJDNyg83/wLKj7Gi4shLiCe6zasLiXDYrHEY1/o0dwloHl6Pd/Gxh7n/d5ibuGqoYT++f49Hobz61Y1R8k/f4Ig9LWA4m84dD9GzZNp55KSLRUPkWrtKWqI6rlh6K0A/4d5WPT8ptRrx6gG3YC8dWeDEV1Teg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/H/Y28SnmelHNh6Ay33aqWw4exMfXpw0rMmSi3rnEOc=; b=T+wvdE98l4ttcJt6fK+6qpvNzPdfdyuwRPbpVFjHFYvK/w7BX/tOjHQrwrW6ncGpCfh2v7/EuzmclNSMWJ4ItP05C7PzZUNFGzf2AMKTx5dUsPFp5w3qYXgOXS5HgXmUFjj5uWYAUi455JbSVece6T3+xITgHwK/QR1H795zFek= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1194.namprd12.prod.outlook.com (2603:10b6:3:6e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:42:14 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:42:14 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 04/18] KVM: SVM: Add support for KVM_SEV_RECEIVE_START command Date: Thu, 30 Apr 2020 08:42:02 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR16CA0054.namprd16.prod.outlook.com (2603:10b6:805:ca::31) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN6PR16CA0054.namprd16.prod.outlook.com (2603:10b6:805:ca::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:42:13 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d0ed2ab8-05bc-4ac3-85ef-08d7ece261e2 X-MS-TrafficTypeDiagnostic: DM5PR12MB1194:|DM5PR12MB1194: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2331; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(136003)(396003)(366004)(376002)(39860400002)(4326008)(6486002)(6916009)(66574012)(66476007)(66946007)(52116002)(186003)(36756003)(7696005)(6666004)(316002)(5660300002)(26005)(86362001)(2906002)(8676002)(478600001)(66556008)(8936002)(956004)(2616005)(7416002)(16526019)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +q91FRugWzuM6vCoyWCaAdW63uGEbXRoxoKMQjeMJAXUq1rZi5w/GmMJIwxNAYntCl7hMK1OR5f3APiufFaKQB49kcjFyKRLzKp1HTLVnFykMtpgKB9rKukkD1O5d+930UzC41J0G50v9j8ABn90M/Q4lcE9lpqwB9qCp5BboA4yDpwbkisizgubHt8HJRCkzh+QaYRuddgvPDelWJs3ZkT7DoeoHjFEmwwyGtIyrOIvlplGUQ8REqvITW18Fh3w97UgBRbQzZ7zZUP8cWwhS7/9m3lG9Ow2P7uyWKgerDAIp8+PhZAqPBjedQ5WGy94BT97Qs0wSRq8FqTIZdAHwdpEfT0cDOn+8tQTLqMibH1QquPn87lwwA7ONFaE260nRr9ZHp0g1yz6Bd5le+6oV5oVJ3KNWvuLMsg7GAPhCjcwFQESEBmA3Qd7N2ZfTW02FhLy6JxLpYYD6vbPOibRqCvob5lVPtVX2eTmwkCV/2fUApxgZ/rtd2gr/OwvxHl4 X-MS-Exchange-AntiSpam-MessageData: UQR6TNj5bF3Ikxon+Pz7P70cQPuDOZQ3ay5bh0UmbeZWZ89vX0ZoVslkGoZOml5jD5al1pYPzzB32OqGNZb3Fo9qnBloF0JbSShLGX7zv9Zt5cqgXhlf869KjO/c2HTQbs9qOTRDDEod1zS3SQ9XWzdCni67fvlg/QQPrZDy1gcjepSEhtwyH8xt1zklLVI3EbJqtd6fH1Rhkyzy/i1rYgYiO5d4YphRcSx6Yctrmn3cw0ufZp8rinqSvdOFzSJ9dfbFoyDKnsgr3IQUkI1640fcjwRNBEuVH2dLT05WRxphKLoUgyGG3Q2qPsyiOrCVcEf3wK5XoPUlFhNQKnKy0zOPdyJNG5OPxvOmxCm+MkmNK3bPvDTGhi4lYJTfg6VXeDBy7Avl9UzzlkAJjhC7A+zEaVjf3m1OOtyYjcyZymRRx08bN8v20YFI0jySV5kD/KZxW9S6aSsl6zj7SDxRCy4PIkT7jGVHA/CGVB9nhK8E6oz4in/fs6Yjci3e8UDoCVQGyrfvNNZY39B1J6aZASbfOi78H25z1spZP2qg4+A5BKpib92QB3ASgBnh9+pnxYUrVtxxqJNVq0YXkU06BrhNtsFUI7vwZRIg2MvH0HzkUtSVrq5S54Q6IuzVqMQvtdwTcvtLIAUPzreBAQPqfrfDzoeMIWRWyRNOARBtw4I2XSFMRMrHvVsMGuDvTefIf8zGb6gbb6ULSho6JWP+cQmmnies6zlphNs3awLXV553I+36BYr9hmzEJYW8pcb48Y/TikVh47BBfeA5fWdGTGZJCqhpD5g6CwnlUfKsi5A= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d0ed2ab8-05bc-4ac3-85ef-08d7ece261e2 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:42:14.7412 (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: QDb/xVdmu5Z4ZLFFSR92iMvPeFfloizZ6W7cZlWgDwn2f8JO5s+BFwL0Gc52y6OyquD49q1bhElieEPpqnJRjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1194 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used to create the encryption context for an incoming SEV guest. The encryption context can be later used by the hypervisor to import the incoming data into the SEV guest memory space. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../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 a45dcb5f8687..ef1f1f3a5b40 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -322,6 +322,35 @@ issued by the hypervisor to delete the encryption context. Returns: 0 on success, -negative on error +13. KVM_SEV_RECEIVE_START +------------------------ + +The KVM_SEV_RECEIVE_START command is used for creating the memory encryption +context for an incoming SEV guest. To create the encryption context, the user must +provide a guest policy, the platform public Diffie-Hellman (PDH) key and session +information. + +Parameters: struct kvm_sev_receive_start (in/out) + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_receive_start { + __u32 handle; /* if zero then firmware creates a new handle */ + __u32 policy; /* guest's policy */ + + __u64 pdh_uaddr; /* userspace address pointing to the PDH key */ + __u32 dh_len; + + __u64 session_addr; /* 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 81d661706d31..74a847c9106d 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1173,6 +1173,84 @@ static int sev_send_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_receive_start(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_receive_start *start; + struct kvm_sev_receive_start params; + int *error = &argp->error; + void *session_data; + void *pdh_data; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + /* Get parameter from the userspace */ + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_receive_start))) + return -EFAULT; + + /* some sanity checks */ + if (!params.pdh_uaddr || !params.pdh_len || + !params.session_uaddr || !params.session_len) + return -EINVAL; + + pdh_data = psp_copy_user_blob(params.pdh_uaddr, params.pdh_len); + if (IS_ERR(pdh_data)) + return PTR_ERR(pdh_data); + + session_data = psp_copy_user_blob(params.session_uaddr, + params.session_len); + if (IS_ERR(session_data)) { + ret = PTR_ERR(session_data); + goto e_free_pdh; + } + + ret = -ENOMEM; + start = kzalloc(sizeof(*start), GFP_KERNEL); + if (!start) + goto e_free_session; + + start->handle = params.handle; + start->policy = params.policy; + start->pdh_cert_address = __psp_pa(pdh_data); + start->pdh_cert_len = params.pdh_len; + start->session_address = __psp_pa(session_data); + start->session_len = params.session_len; + + /* create memory encryption context */ + ret = __sev_issue_cmd(argp->sev_fd, SEV_CMD_RECEIVE_START, start, + error); + if (ret) + goto e_free; + + /* Bind ASID to this guest */ + ret = sev_bind_asid(kvm, start->handle, error); + if (ret) + goto e_free; + + params.handle = start->handle; + if (copy_to_user((void __user *)(uintptr_t)argp->data, + ¶ms, sizeof(struct kvm_sev_receive_start))) { + ret = -EFAULT; + sev_unbind_asid(kvm, start->handle); + goto e_free; + } + + sev->handle = start->handle; + sev->fd = argp->sev_fd; + +e_free: + kfree(start); +e_free_session: + kfree(session_data); +e_free_pdh: + kfree(pdh_data); + + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1226,6 +1304,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_SEND_FINISH: r = sev_send_finish(kvm, &sev_cmd); break; + case KVM_SEV_RECEIVE_START: + r = sev_receive_start(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 7aaed8ee33cf..24ac57151d53 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1619,6 +1619,15 @@ struct kvm_sev_send_update_data { __u32 trans_len; }; +struct kvm_sev_receive_start { + __u32 handle; + __u32 policy; + __u64 pdh_uaddr; + __u32 pdh_len; + __u64 session_uaddr; + __u32 session_len; +}; + #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2) From patchwork Thu Apr 30 08:42:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519491 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD69314B4 for ; Thu, 30 Apr 2020 08:42:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B1D021974 for ; Thu, 30 Apr 2020 08:42:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="WkdANb1J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726571AbgD3Imf (ORCPT ); Thu, 30 Apr 2020 04:42:35 -0400 Received: from mail-dm6nam12on2042.outbound.protection.outlook.com ([40.107.243.42]:27355 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726412AbgD3Imf (ORCPT ); Thu, 30 Apr 2020 04:42:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uv3DDH5ju/czUiKPJvInqECBFenvUcyd4J4cgAetfrUL21r3fp0aAQtYJcH3kXsCMbVz1QuYRvFxBwze8aEmXRvyRzzpegbg9nlr+EbEYbcBoICks6PdiMBvfYy2ZT9XEEKMWfPu4aW1OwWRtHws/RH5dtiTRMxRtrRVcA37mGtXgNCx4ERHtTh5dp7uymo/X2+c98qyvZlQzpf4VPxQhiK5JHDE8s1lSEJp/UlB7CTo0eDxe8EtcKrBikztzXlR7fcQO/0KJ0AeHdI3J0TdBkfog2KxpgiXrtX9wvDDQEW6Cg9N6L3YR7isavseSQNRO/pHCZCNlUJLE1WcfxvkUw== 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=6b3VjYnBbMaZnBOtWYZedbsnefh0du4wQJSw6x1hNlI=; b=U/tmm6xjvmVIfrebzzpz+fj5AgMU5CPyYhS9sjSDmeQy9X1IjQJccr70xLY4SX2UtvfVvqEBUcbEkAINTcDQyJsimYoFQfy304swzh9NCaYFFgSpdRwvZLDnYGEbMD4cTSv2obY1tiPLGJpsGKIi6K8sC5CL1Fj8fMQvlAOGwZuAMqoFaulVGjenSDSZ4TGeKZFD5o6/pn3ChlFnTqTOwqBfTNHDZ/BtnNN2nInUKf3BWckcVJPHozLCdIKey5jFlxk1fbeXTa9A0VkSt7kryiH72RTktZx2LTYYDKL79uqOzQKT7zXhkJLUaR2bHV+90EK/R6woAhSG6W8RlVeL6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6b3VjYnBbMaZnBOtWYZedbsnefh0du4wQJSw6x1hNlI=; b=WkdANb1JJ2F161GPVhyEYZpylI3FMbzVFMLbkeq489axQfPGtakICdUwQkvBG7thDVZD/NMv1PQykYfyoSj5+i76adQiIeqv58Owo2ebydhrw764v82OdXUaocDFI1ahdsuNC7zaj9xlEZm8fY59LdfPjWr3sSioaLbOSfn9R1Y= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1194.namprd12.prod.outlook.com (2603:10b6:3:6e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:42:31 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:42:31 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 05/18] KVM: SVM: Add KVM_SEV_RECEIVE_UPDATE_DATA command Date: Thu, 30 Apr 2020 08:42:21 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0021.namprd10.prod.outlook.com (2603:10b6:806:a7::26) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA9PR10CA0021.namprd10.prod.outlook.com (2603:10b6:806:a7::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:42:30 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4665b064-c5d8-40cb-f970-08d7ece26ba9 X-MS-TrafficTypeDiagnostic: DM5PR12MB1194:|DM5PR12MB1194: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(136003)(396003)(366004)(376002)(39860400002)(4326008)(6486002)(6916009)(66574012)(66476007)(66946007)(52116002)(186003)(36756003)(7696005)(6666004)(316002)(5660300002)(26005)(86362001)(2906002)(8676002)(478600001)(66556008)(8936002)(956004)(2616005)(7416002)(16526019)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GGWgFkpDCuvIhFx0mQl5aVzRjtmSeWepm14xqJWV13xzxHZDFBGcERt/IsXe/Q/mTZgpukky8Fm35plrB85IV+uY4xVxgNlmT94waj80TXkVQlhTFBknvyOMuCbYN2ADmrsa50N12GL30fz4cypb709YsmE7rfNz8MwCyCBbOJQg0BIa8Ibttowun+2D2kMFgQEmPzX7/XRnZKofTr9NMkA5zyfKr/X+VyOA6bA6E04Hk/XiX6eMGf8WFkaSe4nq+Bu3Uzhn2LAKI91YB84Yx6khun+BmmEO56gg0kCQMtCh8dAbPssyjd8SkhtdbldtXe229HaTJCHQpZcmqwRkHNs//yOd+IEm1Z91rt/scatnkO0gsd7L/iTpuktGpbgOIV55ox+E5chXshoxX+CgIBbWYJMuldf3AwekhDPW30ClnXzlQug5nekqakRprGz7Ko19e2i3XYOFvkHQL/G0e+X3Nbb7PgCvHUM5KUU6rqAo3mg2rDPVXn8tYm1ZuDLy X-MS-Exchange-AntiSpam-MessageData: 7XYcMl9k6G4GgBTAunkirpKVc5ESzm7PJ/hbjuuMTdPBngmpYQ4iwrVjhL3jerDpaiUJJdYhFOA/VO5cHWGYBmO0TMpzPjr6JeXsfJr8l8y+wK/zOvozjJoXyOi8knPUR1wLmZTgwmJ/AlQZM5iz67qXrGT4L5zcodxQj1HE3inKzFxAfaPjvq/0oHtMxKNjEQq+3ViBvnL6HfNzWVPRfF0sCLZjjErd1QfEgcnM8U/aPDBCWjLZzlUdTG8RbWNyMJhOUfHP36d7QifcwQslOfkUHYB52mzZheWyCFGVUcnJWNN8VB5jSBQzkoIdkLNiDDpz5V4sWxuucmprQ9RDsOhBEaBXfuPV2e/dLePkt0QsEQM+vXYQGZNGzltq8A7WETKVdsng0DDhbixiO99VKcwEFSldUjo2u+CvoW7eEg8VSImbj763kTcm+sFktm5Ja8HiBiebYW8Lw3k1SWW8zsXSbUBVCki9l67FOJBIkWmboEnpjrFb0qlfPP44bZLdWEE9gP+dXdPbRZ5PvjYvnUXpzonOGL+9fXpHJg3iFpxVtkblDm8Z0T/RrkoULTolTN2mt/VnL4/pAvFQNvTQsPdLg4ZydJ7jTJgJG9yWtWcTn2J6UzdQPKzsUANsLGGcDE3T2bzJK7FJBsFkW2JePxff+gGJnpoSkp8apaWry3Lm5w1nbuXbyQQir0SJFLhVAXeVH8UHaIb9FkvMI2IXxhu05E4m+zaolzwxIe4RhscubsA9zpR1E+NXIjK/5egJG+eNSblkSH+946pWOHiin79g7AMaLz3SmXG1AI5G38Q= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4665b064-c5d8-40cb-f970-08d7ece26ba9 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:42:31.1469 (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: eX8Tyx4CUH3rX4fc3WY/ct3F2TVfk5/1vYuIkbBwBb7Fkxy85NLF3XaaRFvzv3VdxXoxLhwnANM+EsY6Wyi+tg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1194 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used for copying the incoming buffer into the SEV guest memory space. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Venu Busireddy Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 24 ++++++ arch/x86/kvm/svm/sev.c | 79 +++++++++++++++++++ include/uapi/linux/kvm.h | 9 +++ 3 files changed, 112 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index ef1f1f3a5b40..554aa33a99cc 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -351,6 +351,30 @@ On success, the 'handle' field contains a new handle and on error, a negative va For more details, see SEV spec Section 6.12. +14. KVM_SEV_RECEIVE_UPDATE_DATA +---------------------------- + +The KVM_SEV_RECEIVE_UPDATE_DATA command can be used by the hypervisor to copy +the incoming buffers into the guest memory region with encryption context +created during the KVM_SEV_RECEIVE_START. + +Parameters (in): struct kvm_sev_receive_update_data + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_launch_receive_update_data { + __u64 hdr_uaddr; /* userspace address containing the packet header */ + __u32 hdr_len; + + __u64 guest_uaddr; /* the destination guest memory region */ + __u32 guest_len; + + __u64 trans_uaddr; /* the incoming buffer memory region */ + __u32 trans_len; + }; + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 74a847c9106d..d5dfd0da53b9 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1251,6 +1251,82 @@ static int sev_receive_start(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_receive_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct kvm_sev_receive_update_data params; + struct sev_data_receive_update_data *data; + void *hdr = NULL, *trans = NULL; + struct page **guest_page; + unsigned long n; + int ret, offset; + + if (!sev_guest(kvm)) + return -EINVAL; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_receive_update_data))) + return -EFAULT; + + if (!params.hdr_uaddr || !params.hdr_len || + !params.guest_uaddr || !params.guest_len || + !params.trans_uaddr || !params.trans_len) + return -EINVAL; + + /* Check if we are crossing the page boundary */ + offset = params.guest_uaddr & (PAGE_SIZE - 1); + if ((params.guest_len + offset > PAGE_SIZE)) + return -EINVAL; + + hdr = psp_copy_user_blob(params.hdr_uaddr, params.hdr_len); + if (IS_ERR(hdr)) + return PTR_ERR(hdr); + + trans = psp_copy_user_blob(params.trans_uaddr, params.trans_len); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + goto e_free_hdr; + } + + ret = -ENOMEM; + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + goto e_free_trans; + + data->hdr_address = __psp_pa(hdr); + data->hdr_len = params.hdr_len; + data->trans_address = __psp_pa(trans); + data->trans_len = params.trans_len; + + /* Pin guest memory */ + ret = -EFAULT; + guest_page = sev_pin_memory(kvm, params.guest_uaddr & PAGE_MASK, + PAGE_SIZE, &n, 0); + if (!guest_page) + goto e_free; + + /* The RECEIVE_UPDATE_DATA command requires C-bit to be always set. */ + data->guest_address = (page_to_pfn(guest_page[0]) << PAGE_SHIFT) + + offset; + data->guest_address |= sev_me_mask; + data->guest_len = params.guest_len; + data->handle = sev->handle; + + ret = sev_issue_cmd(kvm, SEV_CMD_RECEIVE_UPDATE_DATA, data, + &argp->error); + + sev_unpin_memory(kvm, guest_page, n); + +e_free: + kfree(data); +e_free_trans: + kfree(trans); +e_free_hdr: + kfree(hdr); + + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1307,6 +1383,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_RECEIVE_START: r = sev_receive_start(kvm, &sev_cmd); break; + case KVM_SEV_RECEIVE_UPDATE_DATA: + r = sev_receive_update_data(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 24ac57151d53..0fe1d206d750 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1628,6 +1628,15 @@ struct kvm_sev_receive_start { __u32 session_len; }; +struct kvm_sev_receive_update_data { + __u64 hdr_uaddr; + __u32 hdr_len; + __u64 guest_uaddr; + __u32 guest_len; + __u64 trans_uaddr; + __u32 trans_len; +}; + #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2) From patchwork Thu Apr 30 08:42:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519493 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77FA213B2 for ; Thu, 30 Apr 2020 08:42:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59CF4214D8 for ; Thu, 30 Apr 2020 08:42:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="bzXcHiDq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727042AbgD3Imw (ORCPT ); Thu, 30 Apr 2020 04:42:52 -0400 Received: from mail-dm6nam12on2088.outbound.protection.outlook.com ([40.107.243.88]:1515 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726127AbgD3Imv (ORCPT ); Thu, 30 Apr 2020 04:42:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GBr5YAaD7g1RjajA9lqjCd1tNQPGfD9uyXE9ah//mPNt2bAHyQvp5ZV1//oO7bLqyYLrGMzI6Cxz5ZnHFwadwh8rFGN+vuiMoiFJaFlUZMXvLVz7uMly/+Zi/SD6cgK2fdC+2lV+8E9opa/u/OjIAxCImkCF9hTWS7HQuFCO26ymUH5O6c6mbW48cb8XSiRmR5KQVlt0bsK6HjQc7bE3LA91/hpLEVwEKjcckTjIZlnQauptVdhvZReH3D5VegedhdQ6H1CT28IK9g9rsfXRtwd5e6uUSzXrbFsDSJQEG7f6JTBKivLaUnu1YL1ogY+Sde3LtOW9u0mLCVHVyocqJw== 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=N433244vsAX8No2Y65AniCLT2vuoX/pv1hHiEXKxOaE=; b=MUharnlm/2lQ0wRK32gQHLyOaBNuiQ2NAR9nCyfianHdpcwQb7K0TvpdJA3t7Mm8g4lUxv05Ii0SyYsSWFUGrO1+Iv1w3ZxWTa/vyLLMQPLD0GTN6CQa9EGvKuWoEaElWKYIPLGAtPFGh32IUW5t1aqn5LKsgSvcJK+9dqIkTlmCYD7PDwdxUCoYY2piCG9S2QX4U1uQJ86AjWv+3dhKN2FVcNxwrrsmpeRZl35eVSm5+mc+QWCaKYi/NClCVGxU00VtIc1hP8Z8382i/KSI5vbsgXdvuw5rhsRiDLrhk5gHfnXbEDfcUjldgI6bnQEuBNixmRwHu88n3VzSKus0zg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N433244vsAX8No2Y65AniCLT2vuoX/pv1hHiEXKxOaE=; b=bzXcHiDqio1/GwykzrqReDWfLfISEdKUSXocqBbYlp1IpIXJQYbdRR6nQ07V9ZOuut8fGZ5wfoqdQ7lqi+7WuQjo+WfirBdS8K2af05xzi99fWSU2687ugJ8cEIvaJcXpoWfIYLd2LOwRYqWLnufTkxRhrLUHFArNwQ0KYYqLAw= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1194.namprd12.prod.outlook.com (2603:10b6:3:6e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:42:47 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:42:47 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 06/18] KVM: SVM: Add KVM_SEV_RECEIVE_FINISH command Date: Thu, 30 Apr 2020 08:42:37 +0000 Message-Id: <01ba3a317e54756593e54b7029e7df846c33d3e4.1588234824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR07CA0070.namprd07.prod.outlook.com (2603:10b6:5:74::47) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by DM6PR07CA0070.namprd07.prod.outlook.com (2603:10b6:5:74::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:42:46 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6d12fdb8-b1d6-43e0-26f7-08d7ece27515 X-MS-TrafficTypeDiagnostic: DM5PR12MB1194:|DM5PR12MB1194: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(136003)(396003)(366004)(376002)(39860400002)(4326008)(6486002)(6916009)(66574012)(66476007)(66946007)(52116002)(186003)(36756003)(7696005)(6666004)(316002)(5660300002)(26005)(86362001)(2906002)(8676002)(478600001)(66556008)(8936002)(956004)(2616005)(7416002)(16526019)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tA3kvit04lZAHCS1NTFTjMFDP0D9iqJ3OFcR6Tq1CuNwGIAMxVwAmF86Bdn50RtAgbWil0O+G6aKh3DYZWBAF55wWBNPrR/NNIdfabuBsJT5b1xaT/umCdPMRL1cP5dWmIzPi5WwNfKNokivQEphLgD1kAbzPoXCfno4t3ogEPka2pFUphRFtRyH/2KPwP1/N/4+GCn6eid3lFLAQJZdHXX+/JiZJEU/VWuchTev4RMhxMRipySvRvhorxpIP5OEksa5F6koFGPCr1WXBVo4YofqVmre/1RNui+hnDKfUN9n7ghgp6TC2mmCAUXxs7ptCe4V/z8ZHwZ4iCqK+R2j4OFYctPxmLcZlyIx0lDN/x23yooKI5cJoxWZP/nz8sHQr0p6734dew3WLnpztSgSNZBCMe+2UY3b7NKW04qM5FAio0FUAqcQe+yGhTp1FmZFHntTs35gVsodw+ED8HkVeq3TsOJU/3+w6olRoEyd97TiNuMoQtc2sRnLSV6kU3/f X-MS-Exchange-AntiSpam-MessageData: OHAUYs7EsmCHGXUDOs97qMVIpdF0hxutYAnHG9hnwbbxMd2tMMhUJxaSE69CLpfIHJ+OV98rzwH9th4uQx1hjQeLUCO+swW5vMxHzuLa7XqNQegj02N4nx3vv02dGPC6kriZnMP/7f9AnrWh+P0jgbyYGROhHFwDo3MfXtxLWMsGSghMQpKDnDdpVPD7h8bOZZxKDut9Yvsxx20bVc5PIx/f09XGM/cqLv9dmlcuCG+Ow7qZuTTDngoYyA1r2Sw691HKSOi3aaowyCM90Praces6ddICdtb9Br0hG7WLu/ZfrxnkKsUhe2ozaGypZWdmAp+y8tN1kRjZQse3i/fv7HuvbK2bcr7y1Ykw0q+u8wIoeK0mpIHiY2zgpwgsb+JvqA88lO77tskLi/usGNtXnp/kq2DlpPMlBAiSRTps5yEdz3TFfYSlpfOONSIe4d3rL8LLqwhPn0u7ds7Y7f1cg8CnAn3r312do9okrMvmiFooVD0OEQ4lFw7sWnH5N2XkVA464fTHs/OQIkaGkN9d2NM7Yf9qwmrnTaqqWu41zsx2YQpUXvfsRIHAE6ksuDQ2GJEEu7L6wDlyPp/DzXI0Ap3lZo6r38jk3zDcTeNvW0iXTZcxXporxJDDWxpfHRsabUl/X04F2ueHEB4HJDJ5qYw119AhsgWoZe1D4nz0KxxY5qRrsXFD+FFboBE/zobhcxBnfl5rB9lBHuEua6ZDBJw4TDKZ8lQ4Y0xIVd3ue6CxQMgvZYDfL4hdSi9exNABXCB/XzpFm5W9rIA9FhpYIzYWnid7p908/vOstgOQEaw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d12fdb8-b1d6-43e0-26f7-08d7ece27515 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:42:46.9468 (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: zwZkRvtYf7txNTRxcoRpH3KU2ps1TVlU+ckxe3Aam2907SrjPT992BGwlSzAoHG689iNAG5SBmCXNR4Rp5EA7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1194 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command finalize the guest receiving process and make the SEV guest ready for the execution. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 8 +++++++ arch/x86/kvm/svm/sev.c | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index 554aa33a99cc..93cd95d9a6c0 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -375,6 +375,14 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +15. KVM_SEV_RECEIVE_FINISH +------------------------ + +After completion of the migration flow, the KVM_SEV_RECEIVE_FINISH command can be +issued by the hypervisor to make the guest ready for execution. + +Returns: 0 on success, -negative on error + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index d5dfd0da53b9..1f9181e37ef0 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1327,6 +1327,26 @@ static int sev_receive_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_receive_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_receive_finish *data; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_RECEIVE_FINISH, data, &argp->error); + + kfree(data); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1386,6 +1406,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_RECEIVE_UPDATE_DATA: r = sev_receive_update_data(kvm, &sev_cmd); break; + case KVM_SEV_RECEIVE_FINISH: + r = sev_receive_finish(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; From patchwork Thu Apr 30 08:42:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519495 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03EE713B2 for ; Thu, 30 Apr 2020 08:43:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBD642192A for ; Thu, 30 Apr 2020 08:43:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="HUi1gnjv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727065AbgD3InG (ORCPT ); Thu, 30 Apr 2020 04:43:06 -0400 Received: from mail-mw2nam10on2065.outbound.protection.outlook.com ([40.107.94.65]:30768 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726661AbgD3InG (ORCPT ); Thu, 30 Apr 2020 04:43:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O/zDqBU8A3kGYxaw0UcUFifkrPA2+m0SO85agWkED4o26C9PXpKVRyKPX3DnijZkTybnBvtn78nCNXCiynidORc44wnuAg4GT0VcZg7xptM5Jsg2Y/GeQ/g8gwTVV0KIxM+uBHGmVUQ95DoJywKgCuo53cXTe3Nh3X4VexsPmsQNTybU/ME60QTIBIDtqDCEamqiHzXwsjRKjuS9YITxoOJwDitgZFHI1PONl1/g5RVMxFlgbEaCI+1kyFavPS45PsisLYKVdlvFCVvBMxGHqxklprC1P9iQ2DcbH4HdFWx+z1AMQp3di4DGeJGJv/NIcNCHpt4Ta5/5SqHEb8kNFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kg80pzkz3epoBCgvmHD4sEajd/FQGSuBjGWFCCBN+lM=; b=ksMJB1jtlnNEy40yPTImUaBP33kQqO6CFc7RHnE0iTjYAt6VOKm2nMDJO8PFC4URLbxrNpV62q/kYnVxCPB93sS5kJ9F4Aippeia8yjBEN7Uvuma01myWahN4znSEda7hxOvYkwgZT0CFPupSgB921f6+3+Ox9zdV3+PkAADcJO5kyCk704+vs0RQUwpqSOKX5FEiXcUV9hNlIKWyeYy1UtWBYnKL3l+toggjSblDbJzlop2HV+SxCHDCEXdjJqCglwpdNqAZQjqSXxgSCUub0sBnv7EsqXAQUjH+6PBsaWaxiVLCIU6VJyPn0L4+qD5jCzsOgE2+6PGHP0axMJ7tA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kg80pzkz3epoBCgvmHD4sEajd/FQGSuBjGWFCCBN+lM=; b=HUi1gnjvCHRZN5Ru4r/uKdfYUhLfqsjNA13GSjN2xIj58qKaSPvza+Zb0mO0P16qofkAF3Dxrl3Txl5Zt7Wo98gZHjtvdmYnzaj+jLtkncO757sJuCholdZM3fan5U4FI6kQ3Aucbm4wyjJb1Wby0jSKG+oK8BlPAsDtM4WMxug= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1883.namprd12.prod.outlook.com (2603:10b6:3:113::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13; Thu, 30 Apr 2020 08:43:03 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:43:03 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 07/18] KVM: x86: Add AMD SEV specific Hypercall3 Date: Thu, 30 Apr 2020 08:42:53 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0116.namprd12.prod.outlook.com (2603:10b6:0:51::12) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by DM3PR12CA0116.namprd12.prod.outlook.com (2603:10b6:0:51::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:43:02 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c82908ea-3c68-4e77-1ea6-08d7ece27eb3 X-MS-TrafficTypeDiagnostic: DM5PR12MB1883:|DM5PR12MB1883: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(396003)(366004)(136003)(376002)(39860400002)(478600001)(86362001)(956004)(8936002)(26005)(2906002)(2616005)(6916009)(8676002)(36756003)(6486002)(7416002)(4326008)(16526019)(186003)(7696005)(66476007)(5660300002)(66946007)(6666004)(52116002)(66556008)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RwC0IcVQsAhLhb6DgkRVZXIvbv9J8AZ4qOfyLaMf5zHspS4HH/eld5leALr0JehMmDeRq9GvlAd+OiNlOFmEt3G8ywwzodQ1HXGHm6ksX8j3Ygy3UBO+RJWW1yeZE42RAfjSf6GkNN/0jV/Miac8WiHL1B1W2v+IjWd7Hp+/CdWLCi3dF6FU5jRpXJ9v7Q4a7oOzS0iy/hDvSEK9Z3YC6zA2y6v0Alf5FQY0930OAgkrZtkzzdJx29+qgLuM5F2rpTvp25grneBkAH6CaycjQy13ik26PtrzujWOSiPlb6Cf/no1oGl1Y50L2Y26ydncKUorkAppBSGRGaPxfTWAUUTWNQxUrjCn76rnnLPWhmX2uHrzoY9oRhla91ObaN5r0iYnrJPk0jxqO/Jvf7eLymTohuos20ui0vl64TjNmilnmLtYN/W2ygPBeGqoE8gci8zdcZctx300/D56RSjdDpaUNQ6xuF8KWwskxa1Y4Ls2QuDI+/5Jp0uep/evaRAJ X-MS-Exchange-AntiSpam-MessageData: c/maZRnvK8uT3A1CWcwKtdFAbl5UJ19O4H4DVbu89jUlwhk0DnclbMwvfWolNKf70nfUgE93f70dnULcwM4ysheIwzfgZCqRblI1/OWzw6DGKlGbMO1pTxy0m4Q+DMOIyaKXfy+D/I8Ntrf4CLroxQdG0GKOIQuAmtgpdKKzEuNCNYiIGw1Ma3b7YhSEV2hKbyNMJSfgtpq+f8d7Ebw1xyq5/PSvYWiQ74xfuvtI96AonnEW3TCoQ/A3Ymojly4jNioa3BJ3u5em6jEKY8qSiWuAg7H4OB4AYSTkliYPSxkXXMg56JLjk8LuY8NNxWIUBXgljXGwAIl08t5u77pXpkLeDyi3001pGecPxypS0I+jQyUX2z3Tfc9PoeYbrlFc7z+hHxkuxb+YdgCjGMkV/IGQn+VYyIyQ/VZ5jcKhnwZ+d2IlfmzGp5Ff+TdwKWh350acNY7HuhpVL4xGK/mhq/OkTDDHfTafo5zK7O6sHR4mKluvdPtTAdO29AX4r5fNFq/EyhiIDilU8lbZ+L52hNDvqCzmGL7j0/J1o3jKunXBTocM/gzWyWLnPylvKxBFrmpJTBy+lrsQZAGSsZQh55UCYuI7/PWtV7XA4k+aIWPoGWdCua7DeCVDbNbaEKlgnFBPI9H0iv2kRnqPLlFwGAmhOhV7qiGLCLGzPT9kznE4rHsctA81WAe5sOjaHR+RCVuFNJLoNDSK9PhA0R7xtnh3odfY6Wik+b048DZeXRWfFlbOegq6QfuiIBIbrrbuyukLDdUkMVaXBZCzUwtfMQEm6y7bSW2X7L7P80C9tb4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c82908ea-3c68-4e77-1ea6-08d7ece27eb3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:43:03.0935 (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: 7b9qMoAbKnd+MogI7J/rCW4RH7rLF6rMl9Wh/+t4CiUppX3ptHFkZcgan9kR9xF3wGoZtFf4dJY2Zvhv+PkyIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1883 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh KVM hypercall framework relies on alternative framework to patch the VMCALL -> VMMCALL on AMD platform. If a hypercall is made before apply_alternative() is called then it defaults to VMCALL. The approach works fine on non SEV guest. A VMCALL would causes #UD, and hypervisor will be able to decode the instruction and do the right things. But when SEV is active, guest memory is encrypted with guest key and hypervisor will not be able to decode the instruction bytes. Add SEV specific hypercall3, it unconditionally uses VMMCALL. The hypercall will be used by the SEV guest to notify encrypted pages to the hypervisor. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- arch/x86/include/asm/kvm_para.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h index 9b4df6eaa11a..6c09255633a4 100644 --- a/arch/x86/include/asm/kvm_para.h +++ b/arch/x86/include/asm/kvm_para.h @@ -84,6 +84,18 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, return ret; } +static inline long kvm_sev_hypercall3(unsigned int nr, unsigned long p1, + unsigned long p2, unsigned long p3) +{ + long ret; + + asm volatile("vmmcall" + : "=a"(ret) + : "a"(nr), "b"(p1), "c"(p2), "d"(p3) + : "memory"); + return ret; +} + #ifdef CONFIG_KVM_GUEST bool kvm_para_available(void); unsigned int kvm_arch_para_features(void); From patchwork Thu Apr 30 08:43:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519497 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C414B14B4 for ; Thu, 30 Apr 2020 08:43:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3B9F214D8 for ; Thu, 30 Apr 2020 08:43:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="JHRLDGPx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbgD3InV (ORCPT ); Thu, 30 Apr 2020 04:43:21 -0400 Received: from mail-eopbgr700045.outbound.protection.outlook.com ([40.107.70.45]:54881 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726765AbgD3InV (ORCPT ); Thu, 30 Apr 2020 04:43:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cVb6zaTegTw4CAdYUSs9zd6u3Qhcbt5yLDsKWJsQIJpCK3QbpPPwSLSmgziGvTLs9igm467/5PKgzbGduQ/tSIYDZszkotdE1pzcGO0x8gEm7L0Wb9iJXiJZZ/1FfJ16G8KODkC5FxTwcqzQGZB0qtOcaHQGkAhlgdxJVw0N3EkgiQ42tIfgsf+oJgBalpqYwgtpZZp2IW88+Yw296sVuZ/YIg0XecByS8BuQU9bxUEJGtu3PU8HgzncOMWyLQJZusDTK+jlN36RLE8J584tgcnT2dCuSPNVpsynMVAJ42blP7oZi35Po1mychgDQTyKlX/JcV0aQVwucKPe0ONVVg== 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=th9gCGQ91L9XX4ZbdL4mIFdQGKabGX+H5YWFfqm6wpI=; b=J6oIRYSSyZsgox2GuCK3UHRUPqhULQmwfFIy300zO9TKR6SSHOtI7BWCHI516e4I26lhVFlJGc1S2UyFthWSvTpNgkLh8wvW8TI2QVazea5hq17a5Wuojk/mIolnvmFinDhdeAkm7hJo6NhnnE4S32kVlEN/4cC5+7axtYafvbhn8GEYRBNUWfOO5WtHLGeU6DQpUuxniqQ2Tc4bVx5F8xDP0DKlBIFLEL+RD2zVnlvHa22hEQLX5brogSwXE9dMzRP6uvIvRt9dy0WPnj8ygFWjpmNfrxTE/ULwmAC8OGpXCYLmnuu5ejggB4m9gLE+4XOhxarjLB3q515Ka0eDfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=th9gCGQ91L9XX4ZbdL4mIFdQGKabGX+H5YWFfqm6wpI=; b=JHRLDGPxJ05LI1dE1EX7yNDdtxO/W4NVL2HU/+HJQo4YrX3NCKQ2fr73OEgzzqTr8RzH3UtrAIe7AcV75XjHfTpYNB0VZT9WUSvIOuiIR4d01qC03IHKpRsk25ACTwLGkBKyrU0iR2fFnd54huAMqozIsny2ukIRpW0fYuyQzzM= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1883.namprd12.prod.outlook.com (2603:10b6:3:113::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13; Thu, 30 Apr 2020 08:43:18 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:43:17 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 08/18] KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall Date: Thu, 30 Apr 2020 08:43:08 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR02CA0133.namprd02.prod.outlook.com (2603:10b6:5:1b4::35) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by DM6PR02CA0133.namprd02.prod.outlook.com (2603:10b6:5:1b4::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:43:16 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a4fa82e9-b60b-43e8-e20e-08d7ece28779 X-MS-TrafficTypeDiagnostic: DM5PR12MB1883:|DM5PR12MB1883: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:323; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(396003)(366004)(136003)(376002)(39860400002)(478600001)(86362001)(956004)(8936002)(26005)(2906002)(2616005)(6916009)(8676002)(36756003)(6486002)(7416002)(4326008)(16526019)(186003)(66574012)(7696005)(66476007)(5660300002)(66946007)(6666004)(52116002)(66556008)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k2RxeY3oMUm87IUTy/1S2GTb7Xii4u7JwgcaIcz5Yzb83ASa4SNZin/AS1wTwIXNtF/sSEk41INoZhdICimKq/I2V6DjPxEPoiCUza/uowZnkoDfsjoB7XM9hp4pyq7fh5KQUGtkzdzByI1QvelbaFmyTOsCjN/aodzYwl6tvpPg7TtJs5K6Jv5UmVrp6K+Zdlz1MQhgbWcJIkWk2CUjb3X5mYbzfFyClFe2oXqcwaoqUScFGk2lhrd5ZOytXnDO9+45XCY7lAyW/6lkUVmrAeLmbi7QzxaZIgbMCb89du5WOJ//yM8cElk9bY7Qbc7TJ5FyucgHnGv6U5T/T3kZjsOtKD3axbHfbTfEtgxEPQU9K8cAV+mD1KGvpj8jHyftvQFORy3dqNPBKHd2ad/TKn8KbBEwEjyx/X1Lr4txaYCOCZ5QKRQeJGM+8Y9LicptiZfovxJBuTBZPzbRNpe77bebSiEhLy2kgeYVdaaYixHLM+Hf55LbFCaLXulrFd52 X-MS-Exchange-AntiSpam-MessageData: STgdo3WnvWXp8dSfsaOztMje/cTfZhGV7GDGhZZayc6+GMMWSEF0woU0qPDQkzSb4tlNTlDMl+RiewFZ8M1We2qoxehCZ7dx6mYCrwTAPXh+I9I/nnISV/DTJP2Eh/A6MJWFfvkM4Kt4AIBUQZh5FQPVMzDtyy32oxajoWQLuv+ASOkYq8UeFBz4hA5y+YASVB1iC0mZJmdvUxJ1xzNL6zfnu8QGGWWhAr9i8PTank5LEpL0J0/YkDgjWm4tVvEGC5xIf+ndFiB6qFrqAixTpc5wI5BTnnGJl1zEDIYiaYQwram9pwcGPG3mg7e4TSUx869wR3QKEXkM2+YCwDQYv/DwgUP9s9hggzxsSlmWpATfSk7TZPkmBUYcUtxhuGCYzsycIzppYmHtEGPI+wDArh398UNWv6BfcMg+Eb46OqEnEpmxbL+VbKNsGwuVSwGbUfQkowbj7k+F2ho4BF8XivEgGlceKHVbzgNW2Gbd9HLkudurvwPEiYqKqrIKvyR8C6rcSbmK8qICkiB/HshzzSz/ZjG3a0Zt5obcSItlzyAfXzzYdt5CF7c14L5rgx3zJxhvtx/3MKE23M7R78S+VHhNg/JHZ+Kn5TK809qjOL1PdLxelLYwip6SMwvAZbF+5pTgIb4k9fI7ZZMP+sTuzTh4Aa/BtLYqGF31WmfsU0UKfrqQQpjdB/mqAnnHI/fLpUALMy270BZZewi/d7sP6RUo0ZsFehYGrjTVng4+kkJsY/umotjzh6utjDennOCGiC0mxFMTQ747Wc+WQabcOk/4bjvb/Me7Qm79aTh41Zs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4fa82e9-b60b-43e8-e20e-08d7ece28779 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:43:17.8069 (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: OxAeo4kfcYoKlSi4y+3hPT5CNqNi9tJph0dNcnS5m1sFkBccIbs+SwNKkVq4rQ3WANogbBKeDVELKlGVNITrNg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1883 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh This hypercall is used by the SEV guest to notify a change in the page encryption status to the hypervisor. The hypercall should be invoked only when the encryption attribute is changed from encrypted -> decrypted and vice versa. By default all guest pages are considered encrypted. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- Documentation/virt/kvm/hypercalls.rst | 15 +++++ arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/svm/sev.c | 90 +++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 2 + arch/x86/kvm/svm/svm.h | 4 ++ arch/x86/kvm/vmx/vmx.c | 1 + arch/x86/kvm/x86.c | 6 ++ include/uapi/linux/kvm_para.h | 1 + 8 files changed, 121 insertions(+) diff --git a/Documentation/virt/kvm/hypercalls.rst b/Documentation/virt/kvm/hypercalls.rst index dbaf207e560d..ff5287e68e81 100644 --- a/Documentation/virt/kvm/hypercalls.rst +++ b/Documentation/virt/kvm/hypercalls.rst @@ -169,3 +169,18 @@ a0: destination APIC ID :Usage example: When sending a call-function IPI-many to vCPUs, yield if any of the IPI target vCPUs was preempted. + + +8. KVM_HC_PAGE_ENC_STATUS +------------------------- +:Architecture: x86 +:Status: active +:Purpose: Notify the encryption status changes in guest page table (SEV guest) + +a0: the guest physical address of the start page +a1: the number of pages +a2: encryption attribute + + Where: + * 1: Encryption attribute is set + * 0: Encryption attribute is cleared diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 42a2d0d3984a..4a8ee22f4f5b 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1254,6 +1254,8 @@ struct kvm_x86_ops { bool (*apic_init_signal_blocked)(struct kvm_vcpu *vcpu); int (*enable_direct_tlbflush)(struct kvm_vcpu *vcpu); + int (*page_enc_status_hc)(struct kvm *kvm, unsigned long gpa, + unsigned long sz, unsigned long mode); }; struct kvm_x86_init_ops { diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 1f9181e37ef0..7dc68db70405 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1347,6 +1347,93 @@ static int sev_receive_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_resize_page_enc_bitmap(struct kvm *kvm, unsigned long new_size) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + unsigned long *map; + unsigned long sz; + + if (sev->page_enc_bmap_size >= new_size) + return 0; + + sz = ALIGN(new_size, BITS_PER_LONG) / 8; + + map = vmalloc(sz); + if (!map) { + pr_err_once("Failed to allocate encrypted bitmap size %lx\n", + sz); + return -ENOMEM; + } + + /* mark the page encrypted (by default) */ + memset(map, 0xff, sz); + + bitmap_copy(map, sev->page_enc_bmap, sev->page_enc_bmap_size); + kvfree(sev->page_enc_bmap); + + sev->page_enc_bmap = map; + sev->page_enc_bmap_size = new_size; + + return 0; +} + +int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, + unsigned long npages, unsigned long enc) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + kvm_pfn_t pfn_start, pfn_end; + gfn_t gfn_start, gfn_end; + + if (!sev_guest(kvm)) + return -EINVAL; + + if (!npages) + return 0; + + gfn_start = gpa_to_gfn(gpa); + gfn_end = gfn_start + npages; + + /* out of bound access error check */ + if (gfn_end <= gfn_start) + return -EINVAL; + + /* lets make sure that gpa exist in our memslot */ + pfn_start = gfn_to_pfn(kvm, gfn_start); + pfn_end = gfn_to_pfn(kvm, gfn_end); + + if (is_error_noslot_pfn(pfn_start) && !is_noslot_pfn(pfn_start)) { + /* + * Allow guest MMIO range(s) to be added + * to the page encryption bitmap. + */ + return -EINVAL; + } + + if (is_error_noslot_pfn(pfn_end) && !is_noslot_pfn(pfn_end)) { + /* + * Allow guest MMIO range(s) to be added + * to the page encryption bitmap. + */ + return -EINVAL; + } + + mutex_lock(&kvm->lock); + + if (sev->page_enc_bmap_size < gfn_end) + goto unlock; + + if (enc) + __bitmap_set(sev->page_enc_bmap, gfn_start, + gfn_end - gfn_start); + else + __bitmap_clear(sev->page_enc_bmap, gfn_start, + gfn_end - gfn_start); + +unlock: + mutex_unlock(&kvm->lock); + return 0; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1560,6 +1647,9 @@ void sev_vm_destroy(struct kvm *kvm) sev_unbind_asid(kvm, sev->handle); sev_asid_free(sev->asid); + + kvfree(sev->page_enc_bmap); + sev->page_enc_bmap = NULL; } int __init sev_hardware_setup(void) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 2f379bacbb26..1013ef0f4ce2 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4014,6 +4014,8 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .apic_init_signal_blocked = svm_apic_init_signal_blocked, .check_nested_events = svm_check_nested_events, + + .page_enc_status_hc = svm_page_enc_status_hc, }; static struct kvm_x86_init_ops svm_init_ops __initdata = { diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index df3474f4fb02..6a562f5928a2 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -65,6 +65,8 @@ struct kvm_sev_info { int fd; /* SEV device fd */ unsigned long pages_locked; /* Number of pages locked */ struct list_head regions_list; /* List of registered regions */ + unsigned long *page_enc_bmap; + unsigned long page_enc_bmap_size; }; struct kvm_svm { @@ -400,6 +402,8 @@ int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr, bool has_error_code, u32 error_code); int svm_check_nested_events(struct kvm_vcpu *vcpu); int nested_svm_exit_special(struct vcpu_svm *svm); +int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, + unsigned long npages, unsigned long enc); /* avic.c */ diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index c2c6335a998c..7d01d3aa6461 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7838,6 +7838,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .nested_get_evmcs_version = NULL, .need_emulation_on_page_fault = vmx_need_emulation_on_page_fault, .apic_init_signal_blocked = vmx_apic_init_signal_blocked, + .page_enc_status_hc = NULL, }; static __init int hardware_setup(void) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c5835f9cb9ad..5f5ddb5765e2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7605,6 +7605,12 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) kvm_sched_yield(vcpu->kvm, a0); ret = 0; break; + case KVM_HC_PAGE_ENC_STATUS: + ret = -KVM_ENOSYS; + if (kvm_x86_ops.page_enc_status_hc) + ret = kvm_x86_ops.page_enc_status_hc(vcpu->kvm, + a0, a1, a2); + break; default: ret = -KVM_ENOSYS; break; diff --git a/include/uapi/linux/kvm_para.h b/include/uapi/linux/kvm_para.h index 8b86609849b9..847b83b75dc8 100644 --- a/include/uapi/linux/kvm_para.h +++ b/include/uapi/linux/kvm_para.h @@ -29,6 +29,7 @@ #define KVM_HC_CLOCK_PAIRING 9 #define KVM_HC_SEND_IPI 10 #define KVM_HC_SCHED_YIELD 11 +#define KVM_HC_PAGE_ENC_STATUS 12 /* * hypercalls use architecture specific From patchwork Thu Apr 30 08:43:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519499 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3C8313B2 for ; Thu, 30 Apr 2020 08:43:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D203920757 for ; Thu, 30 Apr 2020 08:43:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="oCcIzpj+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727103AbgD3Iny (ORCPT ); Thu, 30 Apr 2020 04:43:54 -0400 Received: from mail-mw2nam10on2088.outbound.protection.outlook.com ([40.107.94.88]:6064 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726420AbgD3Inx (ORCPT ); Thu, 30 Apr 2020 04:43:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bVqjhxVLtiiBbnfQg29LliWknvSO4J+YiIhSQS56UbQefzZ2DzLZyQqh5+UNwOGVRHPmussgVpKdVVkks8sOYjeiSGTm5RgtrkPPrHjfAX1RRjvkDJhuJaYvDg7KRlidFXPrqoJI1eL9BqWvNoLAqHwgsaJPsiVnzuh6SxAu13+3B2CtqS23qEAMULYs2GiisKfx5KIgKGX7jal7oLtwDNpxxi5hgmbqvzxk4dRqmjl6Eq34lnpynzj+lZIvRWa5Cgeaz0bTxS+jx1VyoCuryYNDtS+vA0GEMJIxsTYXQl6/IFXSz1wI3jJB1nK3JsFH7Vvm8VhPAu3KqF2wEoBTQQ== 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=2jLb5iLrusH1EUXdHjpvbBVaxCR+QjOausPk4SriTzc=; b=BVy/ksvXUBscBO4wJfgW0Ib8M4jE+ZvUh9X5sJCDvrJisclI4kw4n3h4Gib3FnYYw9i6Yy05b+JHWFTQ/AXeDCrls5anGktEW5MeKIL5KmkB18fkkZM0vcZfjDcWt/K9STdo2k8h1G/7VFhwy2KCj2rTt+aMB6iAM5kEVKRL/9IrwUi7hwrCEHsFYcMvLUeHTyySwuY75xQgeLhUJWj0oe4u/76kka3ngFDFg0v8r5qMU2B32UUyHRMzpkh2PMQYT6m5HW9UeGQh1bk0XO0/NBne1tdSkZ9zZhRRne+pdfABTqWNSIt4WF8GFsJqF/bw52ttoDl+pEcr19iC8oFVQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2jLb5iLrusH1EUXdHjpvbBVaxCR+QjOausPk4SriTzc=; b=oCcIzpj+mJt7+BCj54b44gZqFRcT3wrWu50UxEptSJ1MTpX1G9AS/VmoaxhJ4Z6BAc9c6KAqNTJ0OWc3h9ffL+MlUayS9kO05eBRhk0meb2Bk6nqLHYJkhykelB4tkpmKbVm2P51v+MfB+Q84qy62Unl5SNx/PiS0/gwX4Pfi0Q= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1883.namprd12.prod.outlook.com (2603:10b6:3:113::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13; Thu, 30 Apr 2020 08:43:50 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:43:50 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 09/18] KVM: x86: Introduce KVM_GET_PAGE_ENC_BITMAP ioctl Date: Thu, 30 Apr 2020 08:43:40 +0000 Message-Id: <4f4246c58ab1ee7e61b72b0ef0a3b023d7976803.1588234824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR08CA0032.namprd08.prod.outlook.com (2603:10b6:805:66::45) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN6PR08CA0032.namprd08.prod.outlook.com (2603:10b6:805:66::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:43:49 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 23cb389d-ad7f-4aa5-5b67-08d7ece29ae2 X-MS-TrafficTypeDiagnostic: DM5PR12MB1883:|DM5PR12MB1883: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3173; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(396003)(366004)(136003)(376002)(39860400002)(478600001)(86362001)(956004)(8936002)(26005)(2906002)(2616005)(6916009)(8676002)(36756003)(6486002)(7416002)(4326008)(16526019)(186003)(66574012)(7696005)(66476007)(5660300002)(66946007)(6666004)(52116002)(66556008)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cs4ONKTSZatzbWxtrFY3cOu1H2Tloa4Be1MFBHxVGvaLK36aprlcqemPb/5r5AEQk0aHFNUtfB3jvlcvBrJ/HGvJFWXW8bP11qz4yQVkTa2rV7iXIQoXpug6fczX7R+dcuHE5hgvnxZAG7x8CiaOMkUNM3Np/rYXE1BSuA42jga/5XYzZPEdP6R7yW8+9cvAtoaxAwqgNfLOyqFQwU3VpX5OzQBxmGg4ZmkOK6xBOjhu+KAMLoXtverJ61bDO//fRKT7oiTffwKubLTqTmE6haNCo3GN5YfdkIoEKHl03HEporgqErzNaYnz+YdIfCiK7/45cyeY8F7R4yCyCNgDdxWNof5yLy7+VRqhsdpuoTNJ2Ecb7VYrYmo1Y1apDvEhr3gdVTTHAPFHN6w4ThnwIhUrSydj7jrZQExoVrTGN7UXxL6rH/F5MlUtA7sVQudPkTifkBFz/1FrOHNVbzHWTo6LB15djqE/cwwUrUbITrON3S71A38qeYRxzhCcV739 X-MS-Exchange-AntiSpam-MessageData: C8fcHq5PcQQiLAuzeFVfKgVhArk/79Rkj8gzx7Oxh/exkIDFkjXe0hIVdVDrE87bvUbCExym7FZtaAvEPtnr7iG2Ye7x7cxecDfpztV5DFNeXU7TTNPYaonjtQLS8MI6yC1BfUIN2I/3nu+ToN7y06WY2tDytOXmmuqvoay+n4gpiGwiDL6mlPe+hH2cX923UeY4360Qcz58QPMYAcozZ2881GtOKFvs2o/v4YB0roETD5E0okPgKd9KYRLkjHzCkP1N788i8OAAA2ZTgMLaqcPiDgz45PYnTqSvDoxv/GCGXs4Po79NbZyEfRRHCgZvaWGjAbfY8EgsKXKmxxzA6l8QyMqDeOiSVTwE0sThGXb+Q85xyVN4PLvemQPNOgMr+rGaTklmvOUXHM0Sx1BjhUX9gfsYmYxoQ96e5L33zymWJ6Itf2YgTQuacTBkyH5UfuYf856ER9X9Bj4f4We8zDOtuXwYZK6cS1+vWoFdAt5TLbi45Ekm7j+J3a+4bvDJPKKTEbLLdXp7P4rDmaOh9bkGn85zqBsYBJ0wNcd6ghIZ2zcDaaQbOhf3M5T5Wzy7cZQrWiGe430WEk/faNrIzLkkIxjKhfWCHjfv06+dYGGDYuK+kg/JJNBv+wOu5niB9UtJQG13ulFyc0RDDV0KkfzXEiNZ4OtNOIMBWAf8+FCu6Qnsl6x00OwsShitcvJH0XjWxcAoKxcYK+7g+Q6OxuIlCioiUhqCpQkKynL/7CdqM9TErOBIrYIWY3N/LJDpfu1L7hfYh1yW6rGYeVGoBpFeTTRFkYwEO4nXprunOao= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23cb389d-ad7f-4aa5-5b67-08d7ece29ae2 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:43:50.3253 (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: dtqzgzLad4FRzy77yoFc0xqbLU/tStLcdFFP5mIwnX4m2YL3Sm5EaHpOg78EbCOGH0248SzDT1urArZO+9NWnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1883 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The ioctl can be used to retrieve page encryption bitmap for a given gfn range. Return the correct bitmap as per the number of pages being requested by the user. Ensure that we only copy bmap->num_pages bytes in the userspace buffer, if bmap->num_pages is not byte aligned we read the trailing bits from the userspace and copy those bits as is. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- Documentation/virt/kvm/api.rst | 27 +++++++++++++ arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/svm/sev.c | 70 +++++++++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 1 + arch/x86/kvm/x86.c | 12 ++++++ include/uapi/linux/kvm.h | 12 ++++++ 7 files changed, 125 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index efbbe570aa9b..e2f0dd105b5c 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -4636,6 +4636,33 @@ This ioctl resets VCPU registers and control structures according to the clear cpu reset definition in the POP. However, the cpu is not put into ESA mode. This reset is a superset of the initial reset. +4.125 KVM_GET_PAGE_ENC_BITMAP (vm ioctl) +--------------------------------------- + +:Capability: basic +:Architectures: x86 +:Type: vm ioctl +:Parameters: struct kvm_page_enc_bitmap (in/out) +:Returns: 0 on success, -1 on error + +/* for KVM_GET_PAGE_ENC_BITMAP */ +struct kvm_page_enc_bitmap { + __u64 start_gfn; + __u64 num_pages; + union { + void __user *enc_bitmap; /* one bit per page */ + __u64 padding2; + }; +}; + +The encrypted VMs have concept of private and shared pages. The private +page is encrypted with the guest-specific key, while shared page may +be encrypted with the hypervisor key. The KVM_GET_PAGE_ENC_BITMAP can +be used to get the bitmap indicating whether the guest page is private +or shared. The bitmap can be used during the guest migration, if the page +is private then userspace need to use SEV migration commands to transmit +the page. + 4.125 KVM_S390_PV_COMMAND ------------------------- diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 4a8ee22f4f5b..9e428befb6a4 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1256,6 +1256,8 @@ struct kvm_x86_ops { int (*enable_direct_tlbflush)(struct kvm_vcpu *vcpu); int (*page_enc_status_hc)(struct kvm *kvm, unsigned long gpa, unsigned long sz, unsigned long mode); + int (*get_page_enc_bitmap)(struct kvm *kvm, + struct kvm_page_enc_bitmap *bmap); }; struct kvm_x86_init_ops { diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 7dc68db70405..73bbbffb3487 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1434,6 +1434,76 @@ int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, return 0; } +int svm_get_page_enc_bitmap(struct kvm *kvm, + struct kvm_page_enc_bitmap *bmap) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + unsigned long gfn_start, gfn_end; + unsigned long sz, i, sz_bytes; + unsigned long *bitmap; + int ret, n; + + if (!sev_guest(kvm)) + return -ENOTTY; + + gfn_start = bmap->start_gfn; + gfn_end = gfn_start + bmap->num_pages; + + sz = ALIGN(bmap->num_pages, BITS_PER_LONG) / BITS_PER_BYTE; + bitmap = kmalloc(sz, GFP_KERNEL); + if (!bitmap) + return -ENOMEM; + + /* by default all pages are marked encrypted */ + memset(bitmap, 0xff, sz); + + mutex_lock(&kvm->lock); + if (sev->page_enc_bmap) { + i = gfn_start; + for_each_clear_bit_from(i, sev->page_enc_bmap, + min(sev->page_enc_bmap_size, gfn_end)) + clear_bit(i - gfn_start, bitmap); + } + mutex_unlock(&kvm->lock); + + ret = -EFAULT; + + n = bmap->num_pages % BITS_PER_BYTE; + sz_bytes = ALIGN(bmap->num_pages, BITS_PER_BYTE) / BITS_PER_BYTE; + + /* + * Return the correct bitmap as per the number of pages being + * requested by the user. Ensure that we only copy bmap->num_pages + * bytes in the userspace buffer, if bmap->num_pages is not byte + * aligned we read the trailing bits from the userspace and copy + * those bits as is. + */ + + if (n) { + unsigned char *bitmap_kernel = (unsigned char *)bitmap; + unsigned char bitmap_user; + unsigned long offset, mask; + + offset = bmap->num_pages / BITS_PER_BYTE; + if (copy_from_user(&bitmap_user, bmap->enc_bitmap + offset, + sizeof(unsigned char))) + goto out; + + mask = GENMASK(n - 1, 0); + bitmap_user &= ~mask; + bitmap_kernel[offset] &= mask; + bitmap_kernel[offset] |= bitmap_user; + } + + if (copy_to_user(bmap->enc_bitmap, bitmap, sz_bytes)) + goto out; + + ret = 0; +out: + kfree(bitmap); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 1013ef0f4ce2..588709a9f68e 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4016,6 +4016,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .check_nested_events = svm_check_nested_events, .page_enc_status_hc = svm_page_enc_status_hc, + .get_page_enc_bitmap = svm_get_page_enc_bitmap, }; static struct kvm_x86_init_ops svm_init_ops __initdata = { diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 6a562f5928a2..f087fa7b380c 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -404,6 +404,7 @@ int svm_check_nested_events(struct kvm_vcpu *vcpu); int nested_svm_exit_special(struct vcpu_svm *svm); int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, unsigned long npages, unsigned long enc); +int svm_get_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); /* avic.c */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5f5ddb5765e2..937797cfaf9a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5208,6 +5208,18 @@ long kvm_arch_vm_ioctl(struct file *filp, case KVM_SET_PMU_EVENT_FILTER: r = kvm_vm_ioctl_set_pmu_event_filter(kvm, argp); break; + case KVM_GET_PAGE_ENC_BITMAP: { + struct kvm_page_enc_bitmap bitmap; + + r = -EFAULT; + if (copy_from_user(&bitmap, argp, sizeof(bitmap))) + goto out; + + r = -ENOTTY; + if (kvm_x86_ops.get_page_enc_bitmap) + r = kvm_x86_ops.get_page_enc_bitmap(kvm, &bitmap); + break; + } default: r = -ENOTTY; } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 0fe1d206d750..af62f2afaa5d 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -505,6 +505,16 @@ struct kvm_dirty_log { }; }; +/* for KVM_GET_PAGE_ENC_BITMAP */ +struct kvm_page_enc_bitmap { + __u64 start_gfn; + __u64 num_pages; + union { + void __user *enc_bitmap; /* one bit per page */ + __u64 padding2; + }; +}; + /* for KVM_CLEAR_DIRTY_LOG */ struct kvm_clear_dirty_log { __u32 slot; @@ -1518,6 +1528,8 @@ struct kvm_pv_cmd { /* Available with KVM_CAP_S390_PROTECTED */ #define KVM_S390_PV_COMMAND _IOWR(KVMIO, 0xc5, struct kvm_pv_cmd) +#define KVM_GET_PAGE_ENC_BITMAP _IOW(KVMIO, 0xc6, struct kvm_page_enc_bitmap) + /* Secure Encrypted Virtualization command */ enum sev_cmd_id { /* Guest initialization commands */ From patchwork Thu Apr 30 08:43:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519501 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B352113B2 for ; Thu, 30 Apr 2020 08:44:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92C6E20838 for ; Thu, 30 Apr 2020 08:44:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="FabLR7Hs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727116AbgD3IoJ (ORCPT ); Thu, 30 Apr 2020 04:44:09 -0400 Received: from mail-mw2nam10on2051.outbound.protection.outlook.com ([40.107.94.51]:65505 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726847AbgD3IoI (ORCPT ); Thu, 30 Apr 2020 04:44:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ILfY/s63BMnViIhRyEJbcxEXdoHU9gd6W/MTZgOAfkN4jEpJYvLXRv2c0mGudRd8UIGR/MT06oIp6Qkb+GnvZcwqaLoP+NkPiOQyN9xiwzdA1KR1M2MZpBDtnfKqAkavwf2vKDRLzTSgx0a+liG1vQrNjjqRB8yxxs7Bqcu+qGQiSCeZIrR9Gcr6+6B+vWp1+poaKzaxvONBwiTTUoTdVCbHx3xk38TlHHTJtUNiwQAVJmnqYdH9/ZUVHVoHsDrOrOawFTPKNVMKoc9kmrdBhZvfyKIqfNqGt/O171Akv1YVfUCJD0ADvOVHZO8XCkVqDWZwoNsFf1/hFSItqK3D0Q== 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=vQDCVeMKIfaGig1049n1T2F6f1dFD41S9/diaiTH3r8=; b=boCWpeT39Napz9CNJBSrEKtZiZE2+wHv3pEHMZjgR19ntQE5UJLKrLaBJMeQPSYHIK7PP8xaZeutjvyV1bO7/TkVa8op+IzoYaq50RBlGp8mRiyXcCOwKh5eYTvnm/MB1rTVeltnwRxYC9di44t/PYdOwBtpNWBpc3D4NrKYiyustMxuBAzdnZUMSVnkTBMzRbhle5+3yfI3s52mlf6cVo7FyKcROH51g0M4/I4hrpMj/MnWr2mXMUVDM9vjv4sL1M/PB3GuV0opGRwZhyXElMZ3I6N+Du/HCZ4uI0eFPCSWmnjHXaXPMWtU9GhFN9yEPb3l2BGFlfRpvQQNDNhkcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vQDCVeMKIfaGig1049n1T2F6f1dFD41S9/diaiTH3r8=; b=FabLR7HsvVfh693rFRe7fWC6Ok9z+cUAPUq0ZFr/NsieijOcfwCPfStIQvOyvYLzQZ7Z8pBo01AfOqg4/nonwtb9CaOzMpCe7F9cNzPsWtHhN03IZxz0onphW2F8A2OLQ3yBN38uEZclKtEIxZCoptl0r1HveBFj7xFycfIYiLI= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1883.namprd12.prod.outlook.com (2603:10b6:3:113::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13; Thu, 30 Apr 2020 08:44:05 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:44:05 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 10/18] x86/paravirt: Add hypervisor specific hypercall for SEV live migration. Date: Thu, 30 Apr 2020 08:43:56 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0004.namprd10.prod.outlook.com (2603:10b6:806:a7::9) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA9PR10CA0004.namprd10.prod.outlook.com (2603:10b6:806:a7::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:44:04 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4dcf4919-9c68-4254-f468-08d7ece2a40b X-MS-TrafficTypeDiagnostic: DM5PR12MB1883:|DM5PR12MB1883: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(396003)(366004)(136003)(376002)(39860400002)(478600001)(86362001)(956004)(8936002)(26005)(2906002)(2616005)(6916009)(8676002)(36756003)(6486002)(7416002)(4326008)(16526019)(186003)(7696005)(66476007)(5660300002)(66946007)(6666004)(52116002)(66556008)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NDuMQol5YnWFabbXPn/Ze6x3mbGBowDR2dr45qNx9tq7cC0T/BrJzPXMCbrs42oagUSO7LZm1pLzZjyZSeNe+4f5ECnPEvlYt+LSX0pk2lTO3RFHI+jnzeGuDSu22dt6DYbNUlNOHZ5ireZjkZXqc+WidcLkoZdjBKm+I9HVO3L9X04CWTWlk7ibH9TBUBUQ+KWP5vcqkiGobnva2WkHtVMXTIEgzc+J8K2WFKiV6jayJFLQ+OZdMhe83ONPSTRJGxaTbOvq54z4YdXAeCZn4737EwXRsVXeK6V323ZnHD3pzHrziWYVz/yT+xV9kx9/w5HCDVQEiaQ9uzoskbaNXCUUZDYFCaXOBj2EmilrgWZs6Ql1+W9tCB0Uxq8eeroJ1RSwGjRaAoUKrZA/+FLiOog17LFjrqPydtLlIa0MQH37I4YxDhGFTdbrPLzg1mC/CEu0We8PcvRNI+0g75UKPLRcL2Aou73TW3krJintHR0++/rcFPYYYm2EfaTMFiJI X-MS-Exchange-AntiSpam-MessageData: /sJSpTx8cMslcrefE3SePTJRPW1nA0TkL2vEQ0lmFaYXmL85YRZkOB1OnFLPBfUVabo6Bbs3i+E+nhQFAuHC/G/PeqGZjuJCietNGFHUVGzmJ1/hTWLDZMFao8adtnUp95lMzcD9VpdP75bnMSIxmg1ZijejUE+wGldF7wOFQd7xo76aQsTgvrbyqvYy2p3f0sHPiCFZG/heW9ct4P2XZUcYpc8WkYtqoW4XEDcQPXa22khSqNEJzTSoQirQqepX8WdmFwtQXWo+bzsyaouq963oLOTdzlXV0qka1IZIVpEyVLuANsexrzPpY7d0em8R3B3DrId5Tmuo3RxJHUeLMAIZ5qsDRnnk23/YVH+CiyVpiBzHFZYsUwu+4S+uOr6pYZQ2044I8y3+wysQtbF1tYL06sBi74mH3uu2Foh8WydgZCLRFLiRfLBVgKUdqS3nEgsLlUsAmcL/2wR6X9j+M6xjhWlS/ckkhSzO1ioCxIk22ICBtl+t1VjxmrFIwr7rQUuXuIEVvMKXh+QOHQ/VIirRnadxzs3vbnLZujx575Ub7RIIKlxht9bSVjA8khMnpvBpk9iJyBDIOty8sav3u8V/aqB6XoOi3OC1Fssdsp0MydkVAuCSr5PhZ7Fp1u87Mz/ORFINhXcKl0w4wbUeshAm6cUr2WjMd7jrKASBp2tGp+PbIkkdJxNwNLPdZFFJ/7d8iLupg5mKrXuB1FB+WBCd0NG2+nNMQqwDskPzqoqbtdMt5HMoWE+xJ4Rg2HiaFjrxB+IWB9EaYnO85BA63hUC1aENYf9FGaCQIdL+YiI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4dcf4919-9c68-4254-f468-08d7ece2a40b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:44:05.7264 (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: GwnVni2KMgZ259hZjUZk+roj4iKLJPxLxJD6XGzYPIAgsG66iJa1/1A4DshrAcjyXj4nMeXF1Sql20xrkIeZ0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1883 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Add a new paravirt callback as part of x86_hyper_runtime (x86 hypervisor specific runtime callbacks) to do hypervisor specific page encryption status notifications from the SEV guest. Signed-off-by: Ashish Kalra Reported-by: kbuild test robot --- arch/x86/include/asm/x86_init.h | 10 +++++++++- arch/x86/kernel/kvm.c | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h index 96d9cd208610..888dca30a17a 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -238,10 +238,18 @@ struct x86_legacy_features { /** * struct x86_hyper_runtime - x86 hypervisor specific runtime callbacks * - * @pin_vcpu: pin current vcpu to specified physical cpu (run rarely) + * @pin_vcpu: pin current vcpu to specified physical + * cpu (run rarely) + * @sev_migration_hcall: this hypercall is used by the SEV guest + * to notify a change in the page encryption + * status to the hypervisor. */ struct x86_hyper_runtime { void (*pin_vcpu)(int cpu); +#if defined(CONFIG_AMD_MEM_ENCRYPT) + long (*sev_migration_hcall)(unsigned long physaddr, + unsigned long npages, bool enc); +#endif }; /** diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 6efe0410fb72..928ddb8a8cfc 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -729,6 +729,15 @@ static void __init kvm_init_platform(void) x86_platform.apic_post_init = kvm_apic_init; } +#if defined(CONFIG_AMD_MEM_ENCRYPT) +long kvm_sev_migration_hcall(unsigned long physaddr, unsigned long npages, + bool enc) +{ + return kvm_sev_hypercall3(KVM_HC_PAGE_ENC_STATUS, physaddr, npages, + enc); +} +#endif + const __initconst struct hypervisor_x86 x86_hyper_kvm = { .name = "KVM", .detect = kvm_detect, @@ -736,6 +745,9 @@ const __initconst struct hypervisor_x86 x86_hyper_kvm = { .init.guest_late_init = kvm_guest_init, .init.x2apic_available = kvm_para_available, .init.init_platform = kvm_init_platform, +#if defined(CONFIG_AMD_MEM_ENCRYPT) + .runtime.sev_migration_hcall = kvm_sev_migration_hcall, +#endif }; static __init int activate_jump_labels(void) From patchwork Thu Apr 30 08:45:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519503 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 91A4613B2 for ; Thu, 30 Apr 2020 08:45:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F59F2186A for ; Thu, 30 Apr 2020 08:45:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="jS5U1SmA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726692AbgD3Ipg (ORCPT ); Thu, 30 Apr 2020 04:45:36 -0400 Received: from mail-mw2nam10on2062.outbound.protection.outlook.com ([40.107.94.62]:52607 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726420AbgD3Ipf (ORCPT ); Thu, 30 Apr 2020 04:45:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ajeyfw9D+ZxfFiNLToKFzGpMQTJCfHTklh9RqJ3XLPDvN320m9h9SafRxYUsdkvmWc3FUdU2I/iuJjg2R6VO8tKDtnSBxEo29usn/9xnnN8WVLx6zXGfyQGB8KJoGUCrnauUOAyBDstDPymIoJvLgI/4iVbGzyKfe3SH6oqVCkPw0u3GyjiswMQR9nOAAR0NdOr0dmBmbIIrCHiE13wJZLRuD0GHYNfRSVwk+uJLxkFTCtQ52Z1mpCcjhtDTOe8YYj+Co5ho8Zpy32D8HKrsjJacaBfSrOGhI5mfKUYvchQ4AtVnAOFCjUAWzo5HbfSeDJVXKGRuj6iP0RZRko+j9w== 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=dGc+4NNuqOeQw8l5bUjqXtWiVGPKR4A0/3wOmAcBaGY=; b=dk9vhJTidepIzu6yeSrpiwtAKCWuRby9Bnwf87hjPKqL992gTeCntpS/B7/SRibyOKktafRgZBxElJpkJ3tGrwFrMgIUwwFOPyhQYpV1iewcu1ypVlKmTicGm9bHiSHxMYIzvKPqbZgQisrLZi/hKR7VLf8Q5Za+yqTVyfCw5HTB9Z3OjwQdlrhV6dMWDG1IUsjTG/ePJD8JDtUgh2r+FswLWSMFGc6pTQKYlLo0Kv2SofGLKVOjTE5IqI3jDvZMjL9TPeqgFFHHlTE28HTkEW0TEKzXmKEjQRqI82S7/4xwzfluJ4/sfqD8wI0cOx2zrNKuKQHhzJkPACyW7OSuhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dGc+4NNuqOeQw8l5bUjqXtWiVGPKR4A0/3wOmAcBaGY=; b=jS5U1SmAkpCMY8VcsyrGh50J/9kqDSGiL9z5LrydBx77sB3iOvXoFzZgGM7mZM1x56pNYhC9T16ChUWXTB9LrqPDiyEnz+N68iO9ahsxRl56zXIvJE0PtC/7f9AnfPGcpiJxKvei2K0F0TakyeeknhFTPFP1GqmNCp3XL4Lq1oc= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1883.namprd12.prod.outlook.com (2603:10b6:3:113::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13; Thu, 30 Apr 2020 08:45:31 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:45:31 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 11/18] mm: x86: Invoke hypercall when page encryption status is changed Date: Thu, 30 Apr 2020 08:45:22 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:45:30 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 67b929f0-3678-4ca5-e54d-08d7ece2d745 X-MS-TrafficTypeDiagnostic: DM5PR12MB1883:|DM5PR12MB1883: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(396003)(366004)(136003)(376002)(39860400002)(478600001)(86362001)(956004)(8936002)(26005)(2906002)(2616005)(6916009)(8676002)(36756003)(6486002)(7416002)(4326008)(16526019)(186003)(66574012)(7696005)(66476007)(5660300002)(66946007)(6666004)(52116002)(66556008)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3Vg8mt3VIP5rW2C3gRPQSzzARK1hMBZNHjdNcKshgTK3fQlT8DukaYCjHSp8y4oTkGxpsxkI8gmQCyK+EDgsMEdBrwRZ/KNDikGVeXAMfyzoIBRPGmQ/akdoa7M3/ZD03eb5ChcVkAveb/FHUFE6QOBA6iVIAst4QPbV7Ocs1x2oAy1usLjGN3KHPoILNoTC8Kj8rdfnW3gbtGpql8YAG/S9+HrsujnEyz92JKYAi5jJ+B4GCWqpPLvuWlSB7aKTaYRxWZd9BYj/NZYdvG2EkkRdZUpvTnSPm1I83D15taEsyzs7vHgwqGZnjNWoGe5Nu1BJjjJfNSsKN7n7g+jL7sRnCCk1p+Y+9Jp3LpQaYBIvPSKKeFlfhHdJAa5Z42pUso36B+zrJULi/ZxGGJcaAGaMa4bpzKwvvqCs5HxbDA2afx3e+sPOw8f452sv/h1Beacphsc4n5ufAGVRIJJpZsc6ZM5s5zRlmpmFH0uPT0zzeSo+dPJ1ZbnTGxNPQfPB X-MS-Exchange-AntiSpam-MessageData: QfKTJjf4o9A9IAyYjEKdaDiSgCX8QknrfM3ZdjFDAkxBCEW01NTUYf2/vIXsxBeb7ZC+qK3iDME2ZTl0LOrA7OGjwKqqNG38uqat+iD1SiJXxr6f8A4qMRG+VnIa5xD6aFMG2tPTH6NnFk9t8qWnypFvA1vlrkse8X1FKH3TVERArZn0Kn+USmCdHgAp/ZYNSl5gVdDEPKc3i6ak1cBaaeO46IKU4/a/uCg5uoTGxAhmFpZLbDiRHjIrLn2I0x/Fjpz8vVfs3Vumj+WGzDDhaBOufVF6Nm3488RzT3wYvGlS3aqz4E5OIIpYxQNTYbXTLDjvywk6KDuWygHuSznAoLPBG54WKWLolwAgNcErUGH3KCBm88Uwn3/g9APtrtuY+D817NKFDLhwSW+wUGJqvMSjUkZbtnLJTE1FH//OrtApvzS0BLLX5OcV8Lmk7MpWbtLSUD8dkI3/ouc//yccgUC0ApXNfvEjd3T1maRX5V/CndDRJ4dlb8fGvE69fQFyo6Edr/mzvvDi/Vlr9xG20en+/zKr3W7RWQzio0wErCmJMKrQgob4p6eKSJhB9bd+3LPRrAnzVDoOBFwlGYjxHCh+6C6DqymMwO63hewqYKWhppXkvLp0OxTQZhPcoJe/wiX5bcFezLHBHC+QAnzq0vig341aG94Ywr1FTOyRxcrnv+1KzbmMo0h4OVjZFuaV6xxkdstES3p0XLdV3iYNcjcAYKXQORc0OKshIFfg1YrSava0rtwgVZoYONhDXhr6tub84PF3Ds/K4yKVeWEiBE18lFPPADtZiACwKQjKT18= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 67b929f0-3678-4ca5-e54d-08d7ece2d745 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:45:31.6559 (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: DNuT1N/MrHIWhOWAP+M7PQXF4veW83s1dOKqpmeKlzmb3ety0Hx3uAmzVN8J90C5FES0JhOT5cCRnFpe/wK8DQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1883 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh Invoke a hypercall when a memory region is changed from encrypted -> decrypted and vice versa. Hypervisor needs to know the page encryption status during the guest migration. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- 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 | 58 ++++++++++++++++++++++++++- arch/x86/mm/pat/set_memory.c | 7 ++++ 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h index 694d8daf4983..8127b9c141bf 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -78,6 +78,12 @@ static inline void paravirt_arch_exit_mmap(struct mm_struct *mm) PVOP_VCALL1(mmu.exit_mmap, mm); } +static inline void page_encryption_changed(unsigned long vaddr, int npages, + bool enc) +{ + PVOP_VCALL3(mmu.page_encryption_changed, vaddr, npages, enc); +} + #ifdef CONFIG_PARAVIRT_XXL static inline void load_sp0(unsigned long sp0) { @@ -946,6 +952,10 @@ static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm, static inline void paravirt_arch_exit_mmap(struct mm_struct *mm) { } + +static inline void page_encryption_changed(unsigned long vaddr, int npages, bool enc) +{ +} #endif #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_PARAVIRT_H */ diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h index 732f62e04ddb..03bfd515c59c 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -215,6 +215,8 @@ struct pv_mmu_ops { /* Hook for intercepting the destruction of an mm_struct. */ void (*exit_mmap)(struct mm_struct *mm); + void (*page_encryption_changed)(unsigned long vaddr, int npages, + bool enc); #ifdef CONFIG_PARAVIRT_XXL struct paravirt_callee_save read_cr2; diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index c131ba4e70ef..840c02b23aeb 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -367,6 +367,7 @@ struct paravirt_patch_template pv_ops = { (void (*)(struct mmu_gather *, void *))tlb_remove_page, .mmu.exit_mmap = paravirt_nop, + .mmu.page_encryption_changed = paravirt_nop, #ifdef CONFIG_PARAVIRT_XXL .mmu.read_cr2 = __PV_IS_CALLEE_SAVE(native_read_cr2), diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index f4bd4b431ba1..603f5abf8a78 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,7 @@ #include #include #include +#include #include "mm_internal.h" @@ -196,6 +198,48 @@ void __init sme_early_init(void) swiotlb_force = SWIOTLB_FORCE; } +static void set_memory_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc) +{ + unsigned long sz = npages << PAGE_SHIFT; + unsigned long vaddr_end, vaddr_next; + + vaddr_end = vaddr + sz; + + for (; vaddr < vaddr_end; vaddr = vaddr_next) { + int psize, pmask, level; + unsigned long pfn; + pte_t *kpte; + + kpte = lookup_address(vaddr, &level); + if (!kpte || pte_none(*kpte)) + return; + + switch (level) { + case PG_LEVEL_4K: + pfn = pte_pfn(*kpte); + break; + case PG_LEVEL_2M: + pfn = pmd_pfn(*(pmd_t *)kpte); + break; + case PG_LEVEL_1G: + pfn = pud_pfn(*(pud_t *)kpte); + break; + default: + return; + } + + psize = page_level_size(level); + pmask = page_level_mask(level); + + if (x86_platform.hyper.sev_migration_hcall) + x86_platform.hyper.sev_migration_hcall(pfn << PAGE_SHIFT, + psize >> PAGE_SHIFT, + enc); + vaddr_next = (vaddr & pmask) + psize; + } +} + static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) { pgprot_t old_prot, new_prot; @@ -253,12 +297,13 @@ static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) static int __init early_set_memory_enc_dec(unsigned long vaddr, unsigned long size, bool enc) { - unsigned long vaddr_end, vaddr_next; + unsigned long vaddr_end, vaddr_next, start; unsigned long psize, pmask; int split_page_size_mask; int level, ret; pte_t *kpte; + start = vaddr; vaddr_next = vaddr; vaddr_end = vaddr + size; @@ -313,6 +358,8 @@ static int __init early_set_memory_enc_dec(unsigned long vaddr, ret = 0; + set_memory_enc_dec_hypercall(start, PAGE_ALIGN(size) >> PAGE_SHIFT, + enc); out: __flush_tlb_all(); return ret; @@ -451,6 +498,15 @@ void __init mem_encrypt_init(void) if (sev_active()) static_branch_enable(&sev_enable_key); +#ifdef CONFIG_PARAVIRT + /* + * With SEV, we need to make a hypercall when page encryption state is + * changed. + */ + if (sev_active()) + pv_ops.mmu.page_encryption_changed = set_memory_enc_dec_hypercall; +#endif + pr_info("AMD %s active\n", sev_active() ? "Secure Encrypted Virtualization (SEV)" : "Secure Memory Encryption (SME)"); diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 59eca6a94ce7..9aaf1b6f5a1b 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "../mm_internal.h" @@ -2003,6 +2004,12 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) */ cpa_flush(&cpa, 0); + /* Notify hypervisor that a given memory range is mapped encrypted + * or decrypted. The hypervisor will use this information during the + * VM migration. + */ + page_encryption_changed(addr, numpages, enc); + return ret; } From patchwork Thu Apr 30 08:45:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519505 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5773113B2 for ; Thu, 30 Apr 2020 08:45:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33E8F214D8 for ; Thu, 30 Apr 2020 08:45:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="3RddnF9d" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726886AbgD3Ipw (ORCPT ); Thu, 30 Apr 2020 04:45:52 -0400 Received: from mail-co1nam11on2085.outbound.protection.outlook.com ([40.107.220.85]:6130 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726420AbgD3Ipw (ORCPT ); Thu, 30 Apr 2020 04:45:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZsL9ECMLuPbJ1fhUrc2/p5ZKZAKy3QLkz5UWZoHu7rN+lqSXGGodQWsKAjdLix7UsGSnP9CXcW20uz2fcmHpYaXK1pG6BxmIlADHFhQCTv7AiV07j+YLix/vqo6mR0E13kxwniB24sa22MFATk6u74FDITXzBJTNZfdqS0aMVqWKHVdKGny6G0GgTYma47FAMVGXkglG1irGo4G1JQNXSTJXv9UEMMuwiTQUU9Emda4g18oPcWQQz8PnsPyJu2nMjcqBNjB/MH/qwfwSj1E5u2YBupOM9DppXtT+pF0pNtbNP96z8P6TZURy04aj1/b29t2d9DaX/xSgMkQ+a4If6A== 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=zG1GNnsFAMpxrgSuUje/Rq2PgwImXbX2EmeBSMrLeCA=; b=n+tZBBctMtihzVlKh/ocuKyNU2eHoymXIE5t0H2vcImT96Cj2hn6WCJsSEsakABDl5/KelKhNtFmWuRKbW42zBlZKuWO9OXp/bAP7YV0DirIAFMwxWloP9y3o8e3hUB+mH61nAykL11NcaWq+AKHT0tqIHB3nYZygqlAAd7IMdSHoUIwVxXHAcEGF/cywDyufyxixABbYAfzP3dAXBndQu2rl5l0+EJAjWW1Egwy66y5/nn5O9QcNbxy3XKAhrN3Rvy+LJwnC9F/XHj9YNXQ4RMMP5iqIYf1PWg4Z8lHEqznYRfrf+wnd0/PwRKgct732dTj4uwYfxNvfhsxeVIiZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zG1GNnsFAMpxrgSuUje/Rq2PgwImXbX2EmeBSMrLeCA=; b=3RddnF9dHKpfsLSTELX4XM3kGgG3y2BCl6Qxd4HG8RQZBNw51yES3JjoKbIENMWT2bsBOmTt2JTzRXlP4ROKSNozifeUAxbBo90DrgJB4fzIFFsWWRAi+j82U7gr/Plgssx/o6Sowcm6GNqdNOgVkMdg3XivG2Xupo4AmS5vPwY= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1465.namprd12.prod.outlook.com (2603:10b6:4:7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:45:47 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:45:47 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 12/18] KVM: x86: Introduce KVM_SET_PAGE_ENC_BITMAP ioctl Date: Thu, 30 Apr 2020 08:45:37 +0000 Message-Id: <6366a6d1ae1bdca23435949a8ce7d8bf62098f4f.1588234824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN4PR0701CA0045.namprd07.prod.outlook.com (2603:10b6:803:2d::21) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN4PR0701CA0045.namprd07.prod.outlook.com (2603:10b6:803:2d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.19 via Frontend Transport; Thu, 30 Apr 2020 08:45:46 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5168120f-2d67-432c-c1db-08d7ece2e0b2 X-MS-TrafficTypeDiagnostic: DM5PR12MB1465:|DM5PR12MB1465: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(396003)(366004)(376002)(136003)(346002)(7416002)(66946007)(26005)(36756003)(86362001)(66556008)(66476007)(5660300002)(478600001)(186003)(8936002)(2906002)(66574012)(8676002)(16526019)(6916009)(7696005)(956004)(2616005)(52116002)(316002)(4326008)(6666004)(6486002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tvNgtsAKMTUZLhh4EY5Lk7f7zKzyNUAhTDX6EpBiEp9fco/p2tCM9VEdWMh4JkHA1q1fJ1MRglDOvZ2V5y/t/0Ri9DvrKRl0DRQW+dvGZla1A9mABl1eR7F8GXO4hk4GTwNca25cn0GDokTiUrsz61KNlLI9v8kw+f7fEbJxC/eECkzr7CDboDPx4TYAwUl6czsYnaaTWlmot++vipCI/AHvHlwYriScNcfxmqfgBTJL6OaY93ZoXBZje9fEynL7Wl38V6gW1gRjJIEE+U2xc5yatbQ4nJbrdy8byGy/71/vEiTA27e1vjJ3ZM9LuDMmDIur1h2XNEs7oyBCGBVp4xeTR0Dr3AgejYt2gg5wNTtfCBAOgOW3QLBdC9EDiqP3SOF+acgMbGHzP3nh5Wnv/UOgLqQ8y9rCilkAjIW7XNmLBHALzwFbJpAWhTqEYe/MV2Xf/ZUuzAWe6LUHDLMB4suD1MiwVe23nCpniQhTLhMfAyvtfeH6lOGPGZyZxZdY X-MS-Exchange-AntiSpam-MessageData: yQX30PhtgOvZ5fFBwRS/+uMWZ+XoxvwDa8Tb1n5fndEmNfOeAn8mGS+10KSbe1DtAMNdmkQ3A2bNXwdGXU/zEzvB6i8vS+Ywh1UQzADIl8gvNWB7UigKbL62giVZtEcoQlPKokY4vHSFC3SPmo4lTH1meccxLJ2txyT0giDwCehMfmPPzN+o4KE1omoG96nS63BXtS2+nvHBMAkNXLqFZPQjtDml/V1UFiweYMX5/OBEI62qXu0CfJ9jBGLRC3LWt9LRByKDnA7xPP0bpsOvU6toKE86khY0IhIFHz0fiuAHlAZYkloITlVxLV7pC515Yp1PV6gs8YCeh41LWu4cZL+8CSpHJfJYMSwxiwZjcIqbA8YZBzS7edk7wWJ1loC5dEQxpXdJ3ftsBE6/fDWF2e0FCgaIcTWwCR6M8d4QzGkW/pGxM4GALS4rlYNXfrsBzAFg5jlvQ6ziZ2V57UsI4Y19surRBvbQ3g1C0QCp2wbXfzrhTaJ8BImG5nlWr6qrsaye0JERW+I2AyB1A5ZX2U8w+9aSuiDRqrkcDWiLCGYGP3YtDyBFyE5yeXJXn6e3G5h1dlXEvReT1C+kywfpj9ajns2Y6dJCfmlTebMNOxY9/yL6SBfBdnPtKHYBr39ExLaZskIVC6E3fBPiWdongcrfsEVnzjLgwkkz/aYWW4z0FAuWuskgijkFfSon8u9WrC/M2Xas+WbNXXiMRPuI/a0ia9m3RHa6+JKBcmnnI0sxIBmzwDBAmtEbWj8VaaejDMLQvI039cdc4LJ9G+qiVFzYrz+pt87cXUAP3vQtBMc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5168120f-2d67-432c-c1db-08d7ece2e0b2 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:45:47.4869 (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: MEbyn913aEEOid6K7tffiqnifrzeORhXC4JOldZI8A87rCQ1YRVIxJ62TSSSoUxtElsHKTuTdsUB3CoIedmgxw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1465 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The ioctl can be used to set page encryption bitmap for an incoming guest. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- Documentation/virt/kvm/api.rst | 44 ++++++++++++++++++++++++++++++ arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/svm/sev.c | 48 +++++++++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 1 + arch/x86/kvm/x86.c | 12 +++++++++ include/uapi/linux/kvm.h | 1 + 7 files changed, 109 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index e2f0dd105b5c..56c934db2a96 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -4663,6 +4663,28 @@ or shared. The bitmap can be used during the guest migration, if the page is private then userspace need to use SEV migration commands to transmit the page. +4.126 KVM_SET_PAGE_ENC_BITMAP (vm ioctl) +--------------------------------------- + +:Capability: basic +:Architectures: x86 +:Type: vm ioctl +:Parameters: struct kvm_page_enc_bitmap (in/out) +:Returns: 0 on success, -1 on error + +/* for KVM_SET_PAGE_ENC_BITMAP */ +struct kvm_page_enc_bitmap { + __u64 start_gfn; + __u64 num_pages; + union { + void __user *enc_bitmap; /* one bit per page */ + __u64 padding2; + }; +}; + +During the guest live migration the outgoing guest exports its page encryption +bitmap, the KVM_SET_PAGE_ENC_BITMAP can be used to build the page encryption +bitmap for an incoming guest. 4.125 KVM_S390_PV_COMMAND ------------------------- @@ -4717,6 +4739,28 @@ KVM_PV_VM_VERIFY Verify the integrity of the unpacked image. Only if this succeeds, KVM is allowed to start protected VCPUs. +4.126 KVM_SET_PAGE_ENC_BITMAP (vm ioctl) +--------------------------------------- + +:Capability: basic +:Architectures: x86 +:Type: vm ioctl +:Parameters: struct kvm_page_enc_bitmap (in/out) +:Returns: 0 on success, -1 on error + +/* for KVM_SET_PAGE_ENC_BITMAP */ +struct kvm_page_enc_bitmap { + __u64 start_gfn; + __u64 num_pages; + union { + void __user *enc_bitmap; /* one bit per page */ + __u64 padding2; + }; +}; + +During the guest live migration the outgoing guest exports its page encryption +bitmap, the KVM_SET_PAGE_ENC_BITMAP can be used to build the page encryption +bitmap for an incoming guest. 5. The kvm_run structure ======================== diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 9e428befb6a4..fc74144d5ab0 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1258,6 +1258,8 @@ struct kvm_x86_ops { unsigned long sz, unsigned long mode); int (*get_page_enc_bitmap)(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); + int (*set_page_enc_bitmap)(struct kvm *kvm, + struct kvm_page_enc_bitmap *bmap); }; struct kvm_x86_init_ops { diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 73bbbffb3487..64ff51ec4933 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1504,6 +1504,54 @@ int svm_get_page_enc_bitmap(struct kvm *kvm, return ret; } +int svm_set_page_enc_bitmap(struct kvm *kvm, + struct kvm_page_enc_bitmap *bmap) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + unsigned long gfn_start, gfn_end; + unsigned long *bitmap; + unsigned long sz; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + /* special case of resetting the complete bitmap */ + if (!bmap->enc_bitmap) { + mutex_lock(&kvm->lock); + /* by default all pages are marked encrypted */ + if (sev->page_enc_bmap_size) + bitmap_fill(sev->page_enc_bmap, sev->page_enc_bmap_size); + mutex_unlock(&kvm->lock); + return 0; + } + + gfn_start = bmap->start_gfn; + gfn_end = gfn_start + bmap->num_pages; + + sz = ALIGN(bmap->num_pages, BITS_PER_LONG) / 8; + bitmap = kmalloc(sz, GFP_KERNEL); + if (!bitmap) + return -ENOMEM; + + ret = -EFAULT; + if (copy_from_user(bitmap, bmap->enc_bitmap, sz)) + goto out; + + mutex_lock(&kvm->lock); + ret = sev_resize_page_enc_bitmap(kvm, gfn_end); + if (ret) + goto unlock; + + bitmap_copy(sev->page_enc_bmap + BIT_WORD(gfn_start), bitmap, (gfn_end - gfn_start)); + + ret = 0; +unlock: + mutex_unlock(&kvm->lock); +out: + kfree(bitmap); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 588709a9f68e..501e82f5593c 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4017,6 +4017,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .page_enc_status_hc = svm_page_enc_status_hc, .get_page_enc_bitmap = svm_get_page_enc_bitmap, + .set_page_enc_bitmap = svm_set_page_enc_bitmap, }; static struct kvm_x86_init_ops svm_init_ops __initdata = { diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index f087fa7b380c..2ebdcce50312 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -405,6 +405,7 @@ int nested_svm_exit_special(struct vcpu_svm *svm); int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, unsigned long npages, unsigned long enc); int svm_get_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); +int svm_set_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); /* avic.c */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 937797cfaf9a..c4166d7a0493 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5220,6 +5220,18 @@ long kvm_arch_vm_ioctl(struct file *filp, r = kvm_x86_ops.get_page_enc_bitmap(kvm, &bitmap); break; } + case KVM_SET_PAGE_ENC_BITMAP: { + struct kvm_page_enc_bitmap bitmap; + + r = -EFAULT; + if (copy_from_user(&bitmap, argp, sizeof(bitmap))) + goto out; + + r = -ENOTTY; + if (kvm_x86_ops.set_page_enc_bitmap) + r = kvm_x86_ops.set_page_enc_bitmap(kvm, &bitmap); + break; + } default: r = -ENOTTY; } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index af62f2afaa5d..2798b17484d0 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1529,6 +1529,7 @@ struct kvm_pv_cmd { #define KVM_S390_PV_COMMAND _IOWR(KVMIO, 0xc5, struct kvm_pv_cmd) #define KVM_GET_PAGE_ENC_BITMAP _IOW(KVMIO, 0xc6, struct kvm_page_enc_bitmap) +#define KVM_SET_PAGE_ENC_BITMAP _IOW(KVMIO, 0xc7, struct kvm_page_enc_bitmap) /* Secure Encrypted Virtualization command */ enum sev_cmd_id { From patchwork Thu Apr 30 08:45:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519507 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4655C92C for ; Thu, 30 Apr 2020 08:46:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BA3C2192A for ; Thu, 30 Apr 2020 08:46:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="weuv39b2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726950AbgD3IqH (ORCPT ); Thu, 30 Apr 2020 04:46:07 -0400 Received: from mail-co1nam11on2078.outbound.protection.outlook.com ([40.107.220.78]:6046 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726757AbgD3IqG (ORCPT ); Thu, 30 Apr 2020 04:46:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FgCfRQcCZyC62B1ZDUjGouFlOSjQMG4ibMjfe5M0OylWJOmapxELgHsekZvZMGOICi2Cs7gL6MuzarApmJmmdrSbO4dNwlh6fjrQoUSPOCYZtD5Z7Ll9hdhqN3E9qtyt0Q5UZy4KsxapdDXs9V5KtH2Zy2vu0pdn7Z1SyFPJ2mTyGBxVaI++u9UbBIOy+tHxUrnLyeWjb9ter48G17CPf27MgcFYql6cLJUDC81TIT6ueK7Fg7m16UWOekRSAwSSOGUCSZq9JVba01bb0ZsP99Ic2w5NG+vZwqJamX/p39JfCE9TR7D38fFHHpA7rm9ZdddLSDqntQQWuK8euakAYg== 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=EzwMzHX60rxpYIUI4KqsiBfs2p/n4Z3+Gd9M0tG7y7s=; b=icOErLzvhupaPmhCh/DwjqxbXmB2IFMuKpoGo0zAkC2cbFnzcc1VikzTWSwYpV9mgeso0oiypjx0JkE/ll6rR+3X8pLoeRL529X99u5XxUsstn5Q3GWGs3cEOBL8V/zC6g0O2UZUvS3kdf28wQkpNutQvzhdjRa0Ip+uj+W+HBZQ7xVNrVDMUKTeiWLCytHEGtU5Rr7rcxnR+ATEiIg0++iD393Ct3SeCaWHLSbu6e68pnAIa4TN3xTPWkTUqGAMA9rEvAq3Ms9Lhrkbd+2Sqj9XBNpi8FyB6rVm7M1QO8wLPWxcPpy/bTXnRCPVJRmOqu5O4T/0L9aumMYO5KfCqQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EzwMzHX60rxpYIUI4KqsiBfs2p/n4Z3+Gd9M0tG7y7s=; b=weuv39b2H2BaD4D/q1Pcn+Z5pA4v134+rN7dhJpc7EfQUkL8LWvUNbMzdmkrf/ZgTvEuw+hwt5lowHstE3AFNT5IIginr9CiP59e9VckZwj1Xc94WaVBEIn39M92A43UKjfo/aLQ069umJ53hm1CiQJuqI8Q6vsVLlRnfg2qYsg= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1465.namprd12.prod.outlook.com (2603:10b6:4:7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:46:04 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:46:04 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 13/18] KVM: SVM: Add support for static allocation of unified Page Encryption Bitmap. Date: Thu, 30 Apr 2020 08:45:54 +0000 Message-Id: <47996d4b5feb7ee8572120dc19bbc5bb9962a979.1588234824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN4PR0701CA0043.namprd07.prod.outlook.com (2603:10b6:803:2d::11) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN4PR0701CA0043.namprd07.prod.outlook.com (2603:10b6:803:2d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.19 via Frontend Transport; Thu, 30 Apr 2020 08:46:03 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 99eddf84-8793-4fc9-5df5-08d7ece2ea83 X-MS-TrafficTypeDiagnostic: DM5PR12MB1465:|DM5PR12MB1465: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:416; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(396003)(366004)(376002)(136003)(346002)(7416002)(66946007)(26005)(36756003)(86362001)(66556008)(66476007)(5660300002)(478600001)(186003)(8936002)(2906002)(8676002)(16526019)(6916009)(7696005)(956004)(2616005)(52116002)(316002)(4326008)(6666004)(6486002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t8N29pZhULQHi8Us8v0k8sA4Ob7vmhOxAmsAADVHyJyb4TsipJL73LOuJCJeVSJINAmwBKLvc11mwBrmIZOBBUWA4b0KWdKJV5VKIwnydd6ZxXVuiHHh3Ljs1cf5wRSG9ZEPRo3dTsQ3lFqvFrFc/5IEb9rhQC5kJ+blOWmJN0WNwjiEvFhgzlJqWpzVtEkFMC3ALhA/qYpXLvm/SsiW5+KirjMWAA5RRQ52lXwC/rR5hRtBNHYFWVPT02Zzkg/B91fYp0PzXb4Rlxg/71/UvEHaRwjSFjC2haAqSGwR8E9rrQIsWE77iVPIuHlfwTlsgYY7ZKoQlNbExGETevF0oofjUHs+E5sV8nwr55ffeN1a4KOzTqdlAKrlIrSZCbt2gSBxH5Z3tG/lf6t8xBBzPzht4qytG00gEJ7YPCsnislU13xfabHKpT9zV5VZQS+pj3bpvJB7UoGHptlpwxREKLqfbfO9oiiAyKlgE8hKYdlF2ryge10FlTWUq+YPl0J+ X-MS-Exchange-AntiSpam-MessageData: Fbl7PNFu6nvfph7e2P6YGsPsM24TCS7YS6bpGxi2yxpbrNIdHUH26Fnrr3p9zNKGvi4g23WC5EqcOkpjfEREQTDbHr3meCmF2E+xjoxqyuLQZwb8btqTAkVxSHbsmRRXy0yv4KQnuuL12QoGwjyQ178CEeJ5xhwYtbz73LBaol2XUW/1vn3G+5QrTtUwQI3XJZCZ6zLVlH4lDP4HfLqpIeXBLyHrv4GXzFbI2mHN4NAkMOOOKAV7jbffb7REqWs2J1Vd30bvF3zkjbVSyq5mVfTvNtLlA+uaSTcwDAEEL48aXL09xuASXlwYBtl6BbVnHA45v18ydTCermqU4uYNR40gPwX6zBxlSewR7eaPC030Gw6l9fTzVKGZjZtAlZap73aNsHlDd7ROIhVub1Fcqw4VER1vlsAShN2Ka8ZSxFIn6WFzkAlJ95vGAXQhZJKIl7eJp5WmqK0OVPWvx6ba1W/OWF5dOE0hRdO0nD+PH8FJTYuutJzVbhvmkKMjMkQMlTaRwVGNr50Pizfs6msc3BJvPIKW4Rk2O4yOXBuT3G74hlXTIo5x6tp2l+2zhpqNzw8Agp+6M3H6lthcfl7lSdy9qQc+6IqOEDIGIurz5D8pwTtvGZfDwujZDf6v7fP2AZKGvAmLLrgJ06SSIYXv69H+dlHuAOU0Xzi5xMVP02aoK5QiEFKcDz5BomvK+Q2iSstfThHkFwA2uzvxLwrtg1mcR4FExavTfYk+cq74bWOvKaNy+jqe0JgYXTzGYPBt+hPQsRdCIz9r5hOu6iKTESafigbXjDUn5q8Pp/jlbxU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 99eddf84-8793-4fc9-5df5-08d7ece2ea83 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:46:03.9345 (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: 0GK0ElkGLXg5Oier4gz+1ToA550csMnKzTL2ByPzZRYwCEHkXY1RjVr9/C9qJM90ve0mRzCm8vpLaluFc0kuVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1465 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Add support for static allocation of the unified Page encryption bitmap by extending kvm_arch_commit_memory_region() callack to add svm specific x86_ops which can read the userspace provided memory region/memslots and calculate the amount of guest RAM managed by the KVM and grow the bitmap based on that information, i.e. the highest guest PA that is mapped by a memslot. Signed-off-by: Ashish Kalra --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm/sev.c | 35 +++++++++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 1 + arch/x86/kvm/x86.c | 5 +++++ 5 files changed, 43 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index fc74144d5ab0..b573ea85b57e 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1254,6 +1254,7 @@ struct kvm_x86_ops { bool (*apic_init_signal_blocked)(struct kvm_vcpu *vcpu); int (*enable_direct_tlbflush)(struct kvm_vcpu *vcpu); + void (*commit_memory_region)(struct kvm *kvm, enum kvm_mr_change change); int (*page_enc_status_hc)(struct kvm *kvm, unsigned long gpa, unsigned long sz, unsigned long mode); int (*get_page_enc_bitmap)(struct kvm *kvm, diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 64ff51ec4933..ba5ecd1de644 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1377,6 +1377,41 @@ static int sev_resize_page_enc_bitmap(struct kvm *kvm, unsigned long new_size) return 0; } +void svm_commit_memory_region(struct kvm *kvm, enum kvm_mr_change change) +{ + struct kvm_memslots *slots; + struct kvm_memory_slot *memslot; + gfn_t start, end = 0; + + spin_lock(&kvm->mmu_lock); + if (change == KVM_MR_CREATE) { + slots = kvm_memslots(kvm); + kvm_for_each_memslot(memslot, slots) { + start = memslot->base_gfn; + end = memslot->base_gfn + memslot->npages; + /* + * KVM memslots is a sorted list, starting with + * the highest mapped guest PA, so pick the topmost + * valid guest PA. + */ + if (memslot->npages) + break; + } + } + spin_unlock(&kvm->mmu_lock); + + if (end) { + /* + * NORE: This callback is invoked in vm ioctl + * set_user_memory_region, hence we can use a + * mutex here. + */ + mutex_lock(&kvm->lock); + sev_resize_page_enc_bitmap(kvm, end); + mutex_unlock(&kvm->lock); + } +} + int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, unsigned long npages, unsigned long enc) { diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 501e82f5593c..442adbbb0641 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4015,6 +4015,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .check_nested_events = svm_check_nested_events, + .commit_memory_region = svm_commit_memory_region, .page_enc_status_hc = svm_page_enc_status_hc, .get_page_enc_bitmap = svm_get_page_enc_bitmap, .set_page_enc_bitmap = svm_set_page_enc_bitmap, diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 2ebdcce50312..fd99e0a5417a 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -406,6 +406,7 @@ int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, unsigned long npages, unsigned long enc); int svm_get_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); int svm_set_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap); +void svm_commit_memory_region(struct kvm *kvm, enum kvm_mr_change change); /* avic.c */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c4166d7a0493..8938de868d42 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10133,6 +10133,11 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, kvm_mmu_change_mmu_pages(kvm, kvm_mmu_calculate_default_mmu_pages(kvm)); + if (change == KVM_MR_CREATE || change == KVM_MR_DELETE) { + if (kvm_x86_ops.commit_memory_region) + kvm_x86_ops.commit_memory_region(kvm, change); + } + /* * Dirty logging tracks sptes in 4k granularity, meaning that large * sptes have to be split. If live migration is successful, the guest From patchwork Thu Apr 30 08:46:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519517 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B84E1805 for ; Thu, 30 Apr 2020 08:46:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE11120787 for ; Thu, 30 Apr 2020 08:46:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="17AmAffW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727769AbgD3IqZ (ORCPT ); Thu, 30 Apr 2020 04:46:25 -0400 Received: from mail-co1nam11on2061.outbound.protection.outlook.com ([40.107.220.61]:14689 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726817AbgD3IqX (ORCPT ); Thu, 30 Apr 2020 04:46:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GjBPo2nfDDYGceeUL4cVe7A8yWoBNPBiDXrdfacJlv8lQ1Gz3uM2kw6TX63IO17pF/CUGzR0jzXAS4zjdJYuitQtTenCtDqdwDFTUnSYx9lxDXmSDd/yp8ypZdtJgDiwXtGr6MOj68+KtgoFC5f4cjrZA4Shn8bIzgyYQvrNI9TaqeiH5CTAn1muIXMNZi4AjPD10SAWlVZeF4WgIklmQpXU46o/R+4eVDk/wJva9ZiG5NuOFfMrBJ8Ly/MGNgyZKy50UBMRaUO4FGc1zacNTEQn/UxlvUDB8oifxkCHOh4I7GCsBmb8QqgJDgS5/9ME9Xyj+llnwKHEndiP/26WrQ== 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=hT8CBOMYv6cdJeX95Ltogepk0p3OUE0tkeZ7OuWxJ4w=; b=oWzuyV5A3t9ba+S7GNt248wUquB565pipvj2Ttep8Ivs9vtDY6NaZ+ccbM2IFfW3nuGw15d9chgpxMdXFzZ9JbgWotZkTcTtAOvWfo97kWqLKMdALtYWLhdJqI+dIAEa1tkY1RtqCwyii8vQYyZBDX0SzG5CaODZ3BbJ6+otcn58kzDcXaX7F1dAI49thYzxr8qTudWsahJJF/d4RyK4Heo/koXKa7LSmFmYIBN/bdT5iMq6j1Vo8LitiATF1lvE517eLNdZ+MqCh09NMA3hAgThfWSFhkj/u0m3vvtXBTZkcqm4WIftyv7rUCmFM/avRhyjiTvUfGe295EPnN33OA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hT8CBOMYv6cdJeX95Ltogepk0p3OUE0tkeZ7OuWxJ4w=; b=17AmAffWuqX8+0CmKdKbKeHBh1LCaD4qVsYI+UUOJvSZDyAB4k4hVPSK2CMTRLoT8G5xhrNtMHZGfAn2OBW87dAXjoIxRB+abv/WLpsO3A6d4qQYOM8bul+SPtzS/314ARsNhlXFif2HFv7U1T1aVwx32DmiYKB0NVw19O0Cfd8= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1465.namprd12.prod.outlook.com (2603:10b6:4:7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:46:20 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:46:20 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 14/18] KVM: x86: Introduce new KVM_FEATURE_SEV_LIVE_MIGRATION feature & Custom MSR. Date: Thu, 30 Apr 2020 08:46:10 +0000 Message-Id: <17482f099a66e4eb3533f79eac138725c3945ace.1588234824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN4PR0601CA0004.namprd06.prod.outlook.com (2603:10b6:803:2f::14) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN4PR0601CA0004.namprd06.prod.outlook.com (2603:10b6:803:2f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.19 via Frontend Transport; Thu, 30 Apr 2020 08:46:19 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cf05f6b7-1f89-49bf-3026-08d7ece2f421 X-MS-TrafficTypeDiagnostic: DM5PR12MB1465:|DM5PR12MB1465: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(396003)(366004)(376002)(136003)(346002)(7416002)(66946007)(26005)(36756003)(86362001)(66556008)(66476007)(5660300002)(478600001)(186003)(8936002)(2906002)(8676002)(16526019)(6916009)(7696005)(956004)(2616005)(52116002)(316002)(4326008)(6666004)(6486002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oTLT9G6Zkr3sYOKuN1u5Pb4qT9owZPDLT0ySAzsuYz4Zgl2JiGMDY6CWNDPyoagHuyE8dYLtm0vbu7c9HdX9VQWnYbJP5d3shvfNKJGzkvGjiAehjvBMxdUqQYnA/aj/7nex5M3zrtmnfMCAAojlMA3nWGKma3cPseFA8isNj2doisuPGQyfZ8VZ6WyzgLKoeCx7eUEb1tmE+IUTJOu1XcpkSzUiE2Fu7+VBVIiO4IaXiBoGAX42WlUGMn5sHf5kJ9dmPgN2uIOB+Z0CJqVQbxg+9mPuzzLjutE0wKHwLBcxWeaAm6qZ0CN6DaN9OwVe/j7QvzgvOdANS1Gh7E4OB6ReddcdiYOL0HVnTIiPCXJNBE0vyht1J9qfifoenjFfCOyT4YgD9CFpGdzZPQ83ZCqf1z3SwICFCnYProvgLVP5BHTuXT6K+zsulh3IN60pQGI4DFVkRkW4KBmjbrCvyIKxeLDlY67Zgvwzavwjjs56DSIJH/6jq92d1imgpOnB X-MS-Exchange-AntiSpam-MessageData: sbrMfv8gzViQoRlQ+UkuRwHzURW0SiCCEmt54HShL0PUaRUtFRQypSUYCgWgnt7OVVSbTcfEiBEgGvbxgXQZ5Mdo2TCCCh1BT6+ZJfSPseiv42yGKV19AFTqSkhB0cHL0CyUOTRFdbh+w0D2L/1m90NwHf+GZVP1hT645b8HGXBiEy0wm3d5xLkGDCMeeLJC/3u5HZWEcf4ZuLL5MlOyCSBTrdL+rau0OJeJspTejGmj7uClHQ6Y4/JKADww1K4Y0OuZMgCJpb8EoyqHrXn+SlIcp6YNxX8xMyj5hP56WjB7WHvfq7ijVZvKvT6QyQa96GYiSfVx1VAFvuNk3XYy7W61AG9vR5JrJYhlWbzI3EJKLZEm/7wv6SNEfpIGxET+lfZazOMfrHU4IYOc7EptzpNu4o6bBxyZ+9e5YhIHqAYaZqqkXTg+k4dEp7zvmuPI7hjZ1b155s8ALrW6SMtykcEHMuewB1AmZUDJjnlsd1PxzbOteWPgjyudIQ/Wz7uisEmxB6P/oQJUnK0CE4BjnPQ7cjSMWBoFIzs6cNCdhCT61FgUypSsileRmcLiBgiRHgNhCx+0gGtEzva51YKMxPHOuJaxqqJq2QkrhwGUbuhlap7VpzyjCYtSW4MmV8d2Rfpe+PwZ+yMsm6dQ/XlprjhV8/vwBqW0mQWyZaaeS+GdALzKmNP6Y9SoChBXtoRK0OTLVIje+PWN6r9MimqTjEczB9pzpCdz/bGGzEWWEXmkpqvn8N5BTbwQuZfgNSCB7QjWlkBYvv0kRrw5uFVhSMCY/vhz+5p3CmPYa7sEKOY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cf05f6b7-1f89-49bf-3026-08d7ece2f421 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:46:20.0623 (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: +z7t5btL06j6Ssm7gbMGY41+497yKfz3pU/L/JCTHlXWmxJPc2jqmvM63yPfQ5dTrlKFNNeF8x0/FJgUFlGQNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1465 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Add new KVM_FEATURE_SEV_LIVE_MIGRATION feature for guest to check for host-side support for SEV live migration. Also add a new custom MSR_KVM_SEV_LIVE_MIG_EN for guest to enable the SEV live migration feature. Signed-off-by: Ashish Kalra --- Documentation/virt/kvm/cpuid.rst | 5 +++++ Documentation/virt/kvm/msr.rst | 10 ++++++++++ arch/x86/include/uapi/asm/kvm_para.h | 5 +++++ arch/x86/kvm/svm/sev.c | 14 ++++++++++++++ arch/x86/kvm/svm/svm.c | 16 ++++++++++++++++ arch/x86/kvm/svm/svm.h | 2 ++ 6 files changed, 52 insertions(+) diff --git a/Documentation/virt/kvm/cpuid.rst b/Documentation/virt/kvm/cpuid.rst index 01b081f6e7ea..0514523e00cd 100644 --- a/Documentation/virt/kvm/cpuid.rst +++ b/Documentation/virt/kvm/cpuid.rst @@ -86,6 +86,11 @@ KVM_FEATURE_PV_SCHED_YIELD 13 guest checks this feature bit before using paravirtualized sched yield. +KVM_FEATURE_SEV_LIVE_MIGRATION 14 guest checks this feature bit before + using the page encryption state + hypercall to notify the page state + change + KVM_FEATURE_CLOCSOURCE_STABLE_BIT 24 host will warn if no guest-side per-cpu warps are expeced in kvmclock diff --git a/Documentation/virt/kvm/msr.rst b/Documentation/virt/kvm/msr.rst index 33892036672d..7cd7786bbb03 100644 --- a/Documentation/virt/kvm/msr.rst +++ b/Documentation/virt/kvm/msr.rst @@ -319,3 +319,13 @@ data: KVM guests can request the host not to poll on HLT, for example if they are performing polling themselves. + +MSR_KVM_SEV_LIVE_MIG_EN: + 0x4b564d06 + + Control SEV Live Migration features. + +data: + Bit 0 enables (1) or disables (0) host-side SEV Live Migration feature. + Bit 1 enables (1) or disables (0) support for SEV Live Migration extensions. + All other bits are reserved. diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h index 2a8e0b6b9805..d9d4953b42ad 100644 --- a/arch/x86/include/uapi/asm/kvm_para.h +++ b/arch/x86/include/uapi/asm/kvm_para.h @@ -31,6 +31,7 @@ #define KVM_FEATURE_PV_SEND_IPI 11 #define KVM_FEATURE_POLL_CONTROL 12 #define KVM_FEATURE_PV_SCHED_YIELD 13 +#define KVM_FEATURE_SEV_LIVE_MIGRATION 14 #define KVM_HINTS_REALTIME 0 @@ -50,6 +51,7 @@ #define MSR_KVM_STEAL_TIME 0x4b564d03 #define MSR_KVM_PV_EOI_EN 0x4b564d04 #define MSR_KVM_POLL_CONTROL 0x4b564d05 +#define MSR_KVM_SEV_LIVE_MIG_EN 0x4b564d06 struct kvm_steal_time { __u64 steal; @@ -122,4 +124,7 @@ struct kvm_vcpu_pv_apf_data { #define KVM_PV_EOI_ENABLED KVM_PV_EOI_MASK #define KVM_PV_EOI_DISABLED 0x0 +#define KVM_SEV_LIVE_MIGRATION_ENABLED (1 << 0) +#define KVM_SEV_LIVE_MIGRATION_EXTENSIONS_SUPPORTED (1 << 1) + #endif /* _UAPI_ASM_X86_KVM_PARA_H */ diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index ba5ecd1de644..0ac82e4aac33 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1469,6 +1469,17 @@ int svm_page_enc_status_hc(struct kvm *kvm, unsigned long gpa, return 0; } +void sev_update_migration_flags(struct kvm *kvm, u64 data) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + + if (!sev_guest(kvm)) + return; + + if (data & KVM_SEV_LIVE_MIGRATION_ENABLED) + sev->live_migration_enabled = true; +} + int svm_get_page_enc_bitmap(struct kvm *kvm, struct kvm_page_enc_bitmap *bmap) { @@ -1481,6 +1492,9 @@ int svm_get_page_enc_bitmap(struct kvm *kvm, if (!sev_guest(kvm)) return -ENOTTY; + if (!sev->live_migration_enabled) + return -EINVAL; + gfn_start = bmap->start_gfn; gfn_end = gfn_start + bmap->num_pages; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 442adbbb0641..a99f5457f244 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2633,6 +2633,9 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) svm->msr_decfg = data; break; } + case MSR_KVM_SEV_LIVE_MIG_EN: + sev_update_migration_flags(vcpu->kvm, data); + break; case MSR_IA32_APICBASE: if (kvm_vcpu_apicv_active(vcpu)) avic_update_vapic_bar(to_svm(vcpu), data); @@ -3493,6 +3496,19 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu) svm->nrips_enabled = kvm_cpu_cap_has(X86_FEATURE_NRIPS) && guest_cpuid_has(&svm->vcpu, X86_FEATURE_NRIPS); + /* + * If SEV guest then enable the Live migration feature. + */ + if (sev_guest(vcpu->kvm)) { + struct kvm_cpuid_entry2 *best; + + best = kvm_find_cpuid_entry(vcpu, KVM_CPUID_FEATURES, 0); + if (!best) + return; + + best->eax |= (1 << KVM_FEATURE_SEV_LIVE_MIGRATION); + } + if (!kvm_vcpu_apicv_active(vcpu)) return; diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index fd99e0a5417a..77f132a6fead 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -65,6 +65,7 @@ struct kvm_sev_info { int fd; /* SEV device fd */ unsigned long pages_locked; /* Number of pages locked */ struct list_head regions_list; /* List of registered regions */ + bool live_migration_enabled; unsigned long *page_enc_bmap; unsigned long page_enc_bmap_size; }; @@ -494,5 +495,6 @@ int svm_unregister_enc_region(struct kvm *kvm, void pre_sev_run(struct vcpu_svm *svm, int cpu); int __init sev_hardware_setup(void); void sev_hardware_teardown(void); +void sev_update_migration_flags(struct kvm *kvm, u64 data); #endif From patchwork Thu Apr 30 08:46:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519523 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 839AF13B2 for ; Thu, 30 Apr 2020 08:46:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65E322192A for ; Thu, 30 Apr 2020 08:46:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="StkOBco2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727785AbgD3Iqj (ORCPT ); Thu, 30 Apr 2020 04:46:39 -0400 Received: from mail-co1nam11on2054.outbound.protection.outlook.com ([40.107.220.54]:38369 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726871AbgD3Iqi (ORCPT ); Thu, 30 Apr 2020 04:46:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UFh/rjaUknIpy4DSETGUzzBylo0Ong9jf5eRnuv9ogF844Okfs13X4APPo4Pl9trMurhbFY6Fx4MJw739p+E/dtOcgoYB6L1fjMoAog2oqmmPwzwJd3T4rJ+U+pLXriVECZzpZ5iRxuzzSP/BBs+o0JOWOLwHgIYJTMnBEQh0xMN2H186+HjAG6grmHX7PfM84KoibaS2zO2PDs8u1m6NSR7Z5cr4AMX/siyqfT/pxX23uIJUY7IItf63IC8f34fRwaCVFQCA7fzlBBnresmP5Ri5v4s7BG6/mXCLA67kBJ1DSq4iZThleGIFjYgJOHD/Sy4VQbuFi4vpd7lk6WLvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3D/kK5cQCLuGeO7hC945SONJQJPxE71P6AsK3LWgYTk=; b=oWNu+5zIIG1ofDbEyAsopPnx9h5ubCLMZRRKuO6AMTKH3e3OElFlnoID2CFJVj0RmpDrDNFCf++0qBIcEcCWkYj32qlA5GXpSoG3LoawX55RvGk+iZqB0bczNsDlwHe7sjP3C6JM6ttFdX0Jq/v72eWYXDRIv8xd9j72apEZ/iTN8kF8KWj/PGqQz0WMopJFj7pPxycXVmJn35PFiy1KsVvriQMaVUGyPr2kKxHI/gKLty6B6bUPLuCurZRDNkKNacTcXzqF1POn5bWlq1BwjBBPfiGby7CRr8VI/3AYtsHlI4SBtvjsGBsBFVPppQn2US8DLep94AzdvAegQIMyAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3D/kK5cQCLuGeO7hC945SONJQJPxE71P6AsK3LWgYTk=; b=StkOBco2JpN1RvR50gilkdXwwiN+jLyQJmCRLtTFka97Ir2ZuCxjg3i3MajBzRi5nELdwPo+itChvNvAccalH07LxJe05fX+KF5w16Kon30ITKjzE9CDF5kK3umP9Oc5I0KRQRnfNC9Emj5NFicFITIW8g8I+BiDl+hnOH6xLBM= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1465.namprd12.prod.outlook.com (2603:10b6:4:7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:46:36 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:46:36 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 15/18] EFI: Introduce the new AMD Memory Encryption GUID. Date: Thu, 30 Apr 2020 08:46:26 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR16CA0065.namprd16.prod.outlook.com (2603:10b6:805:ca::42) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN6PR16CA0065.namprd16.prod.outlook.com (2603:10b6:805:ca::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:46:35 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b2aa1ecf-633c-4fab-6589-08d7ece2fdd0 X-MS-TrafficTypeDiagnostic: DM5PR12MB1465:|DM5PR12MB1465: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(396003)(366004)(376002)(136003)(346002)(7416002)(66946007)(26005)(36756003)(86362001)(66556008)(66476007)(5660300002)(478600001)(186003)(8936002)(2906002)(8676002)(16526019)(6916009)(7696005)(956004)(2616005)(52116002)(316002)(4326008)(6666004)(6486002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0UQM1RbbLv3IQ+ShWeoVLWWvuw7E5OS1iF2Ic8EJe2f4G+Tf5g01nzsVgRRUy2TOLkQ2gvC4dLS5v3ePLIQkfmgiaL4dvPz1iFIoeVrMGTeAk3xvF9y8MzVc7vfaKv8b1VAYeOuSk7KJdgvWjcjcEUTUFzZB4nLFTxEaE/sq6hscDTVSmd1ykYx6rS26VChnWzjv5hjNJLwY8oXGnvo0odr0r5uC2iNxabXgbE0u4gwedvhZ+yxCg4O3t6U5niBX633U7AxODBYL6CFHHcybH/c1bd90Dt4RCweNabqo69/CSmjdA21r4TvdGJGvThe/6fSyamOBZSE1SspEm8bhb9q1zkvOdbeDORNxvtOurynFR2ytI5wDJvIR4VFvRe8Q0YPrB2JTr8WeithFt58Tjlekb95qC0wtHn28HFQ79mLaobmZ91OY9PDKylGvdiwtqE5yTDnIOqJQwkqPX4gFuEDCX2b6J8wKfzXgFKBAShP2irY3gRAn3xIpuTtXKU5X X-MS-Exchange-AntiSpam-MessageData: yHJw1RXYMpTvqC1OtEaDSwbKxLp7RJLLN2CiMAmO7IA5mDOT6O94er7mFu/HPAm0FYsBiXBTSswPjfQYaNhdhAM/S+j/IazLUWfSYneMBW/cQzMgSE3gGyI9VN/YsIQROqE1kJzux/yDb79+pBl8PJ+RDqVB2ZXVMfl1jDceCbw+PJR0AS52PtNYBLYXnUSULqAAL4MstZtEIz5Xhl41BRmepYJBKySQGXs6mgLbB7FPIxtIreMRmwsKbooM9Fu84hILAo05Pznul2WlQbbxyvgoqmNcrDB9mC9PcSFJguWeTy1ixAsMVIXIZFnAx9qJTnP5jbv+5EfU1kwtqZl1K/l9Od1DLShTj0x0hyNZq6hjGDQe4xCC2v6b+9oxSHWJVQITsAI4WUfw60sukzxSiuKKqdZ00KhrXNvPx1i7JYcYi58bvPkf4EvJegcg7YeTWUrNlfXV6Rh2uUMLV+ThF+wqOWDMNRsKFrRWKCvxNaHEhKHmWf7Z8YCm9nxTpokNN8+5BNeSWLw6HHXcFY3QK+DF/jTs9h3wGZOVGMKta3UBnirVObCgUFgRiGSSSXAg4PurE75ZkB9k2KWnzYH0UJ8P8NIKEkgUry/JvqLpeJo52bF5Ar9hJI4HhmUc6Oy7gVD7M3/dJEz7Uu5YA3JA4gje2lQX4YXbY357OorWNGPtO/+/wEgwuZ+coMw9u+HVnRKe4fYbL1eaMsGRE9oAiIydGSlCWBEk9oqN6inUj1SsFmuALXrtiXLVemlHs3/zjROSmqjktffcJsTGIR62qWuiNMxPs5HeRAZbPz6FlJk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b2aa1ecf-633c-4fab-6589-08d7ece2fdd0 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:46:36.3440 (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: bjLlf8O41nco/qRdO7emg9xu5a7uxAvhf62FqktfiQlxYXWkExlV2KOTAsJL6F00fuQx8sjR44iuvxet5v1W6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1465 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Introduce a new AMD Memory Encryption GUID which is currently used for defining a new UEFI enviroment variable which indicates UEFI/OVMF support for the SEV live migration feature. This variable is setup when UEFI/OVMF detects host/hypervisor support for SEV live migration and later this variable is read by the kernel using EFI runtime services to verify if OVMF supports the live migration feature. Signed-off-by: Ashish Kalra --- include/linux/efi.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/efi.h b/include/linux/efi.h index 251f1f783cdf..2efb42ccf3a8 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -358,6 +358,7 @@ void efi_native_runtime_setup(void); /* OEM GUIDs */ #define DELLEMC_EFI_RCI2_TABLE_GUID EFI_GUID(0x2d9f28a2, 0xa886, 0x456a, 0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55) +#define MEM_ENCRYPT_GUID EFI_GUID(0x0cf29b71, 0x9e51, 0x433a, 0xa3, 0xb7, 0x81, 0xf3, 0xab, 0x16, 0xb8, 0x75) typedef struct { efi_guid_t guid; From patchwork Thu Apr 30 08:46:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519527 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5208113B2 for ; Thu, 30 Apr 2020 08:47:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DE7721974 for ; Thu, 30 Apr 2020 08:47:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="4HLEpFJ+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727813AbgD3Iq6 (ORCPT ); Thu, 30 Apr 2020 04:46:58 -0400 Received: from mail-co1nam11on2068.outbound.protection.outlook.com ([40.107.220.68]:20319 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726531AbgD3Iq6 (ORCPT ); Thu, 30 Apr 2020 04:46:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DpyhZhbN/sReW7APNfNMNgHCfShIXZR31r/3nVKCsJ4qXNaAMbfnE5UiU+ZU317jfnnx4xX/r5biN4C8BJaDysqzmDtiudQGRcZV5e4HJOIP6pHlnx+w332lfgPDbueP1c7GZVGTfQTCJenJMf8ZY97Hukq3LkHyDfFUkHf/ANJx6+2bvGGryoOR8w1ikuCfm4beJSSMlLH+xBYZ6W3Lk7re33LYO73EvEWE7bhtt0tzijzKF6BOVm9SVbMZrPPawUGFVt8OIzFRBp66GJtaRRDQYDD4PBCbghq6niKDYDGHOrKyRScSmTERDBBAo2rWCGq84xXhR7LjV8+Vm1uBTg== 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=u1aLjTSYiHLZkDpAoiK+ds5AKq9cbyq79KY5RaSvjxQ=; b=cx0nBXfTVU2Ll9uBWZxZ5pkxsV1T1oKwoTWXoTdTHCrtxj2nNjCP786g/Cl/PPaIeQ7uDj+LGNuue+n6n/TnsOO/cJkk8aNrcl6CuqITVJCMyK2OW/ysrvvJ6PzgpfcIw9wruSaBdDV35nVSC8RXwRWyXi7EliDXSd1rLS+lgD9LN0i0LQqFDS6OIOb+B9EZOmyxN+e5mW3xpyWERq7ibzyajeAg5MY6zSD7CxkIBLffJG5waIhAJHtEoe5obBZMWdFcQ3qgQqKFxdhceEq/I8ze98tm+kDndAXEnEGN/IhiCnpE0A8VuosiRZzKWcYpngkEGAbfh3Hq601sY8IuDg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=u1aLjTSYiHLZkDpAoiK+ds5AKq9cbyq79KY5RaSvjxQ=; b=4HLEpFJ++KPTtLRH/dNfEKU/nq/Jhxnls4XDdE+yMPHhv94UqVIBzJz2FEMUvHfaBV28sjl5SyyTLiTP+w9Y4s+yt/CLGd5rci4vO3uR7ZfgpQzBQ+Y60Eeq2CYR2ogCzWdL3X3HPTRU3c1SyOzTaZxHNz96JhWreqUl+HfB9y8= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1465.namprd12.prod.outlook.com (2603:10b6:4:7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:46:54 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:46:54 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 16/18] KVM: x86: Add guest support for detecting and enabling SEV Live Migration feature. Date: Thu, 30 Apr 2020 08:46:45 +0000 Message-Id: <42947fc3dc7a01c73677560c84dfd87498d381e0.1588234824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0025.namprd21.prod.outlook.com (2603:10b6:805:106::35) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN6PR2101CA0025.namprd21.prod.outlook.com (2603:10b6:805:106::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.2 via Frontend Transport; Thu, 30 Apr 2020 08:46:53 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2d13ee51-2c35-4333-9caa-08d7ece308ab X-MS-TrafficTypeDiagnostic: DM5PR12MB1465:|DM5PR12MB1465: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(396003)(366004)(376002)(136003)(346002)(7416002)(66946007)(26005)(36756003)(86362001)(66556008)(66476007)(5660300002)(478600001)(186003)(8936002)(2906002)(8676002)(16526019)(6916009)(7696005)(956004)(2616005)(52116002)(316002)(4326008)(6666004)(6486002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tIqkBRGUEJLOQuN0b8OJPgnk3NcgXxNZ9e59ZTXKeOSQ14Sb8wN0hFvj8MByoXlChW+QSRF0jhpggTDLbyREP7hvFHj18xEhLDIrG2sdWUe9q4A8t7gJ+pGeCtMKwvDdcq/U5gRYhgBSewBlFJp8Tb5OXzoPP/eyTacRC1snEJmmHhUzj8aVPwgjR+ol0HPJCJ1AdWDQAgn8MV8NgbzuFsbha3eJzNI8ZXERJbf/LvAys4JLhDQKlQ3vElR+1+0D2E9yeIoUkoiawbdM3BEn1Ce3Ch+tHwnyY75GTXUU4OjqBzOn44oH/sc6qhoZ+ZHS+kL7XYl4R2+DGzhGdgT2/pvWhoXyavl/ewppAkLCLSryNBdiL4AEE9RJxTtBdGJOlaToLXm3gQvVJZtw3szjjpsl9dQVD1KlyW43wA/UVg7tXX4kPV3vYku3w+fKCNapC4RLyQMZBmnQODCppuldY2M+bVkGFA0M0sRpYYDQWxbFyP2jfHftp6n5sGPOyrI/ X-MS-Exchange-AntiSpam-MessageData: xKvklJk5e56s97igKE50DP0w3+2IzLYrFMz6uRhtaU2eLjYPHyTaZvgW5TTYVRkDZ4n/stQHIe7rOV2ZTk49Jc25N9dy87Ig55JII7I3nOKAmSqCDlz4darSdSrI3wdFTKyYMT0wFNa2vh/IuG8uHXzsZhisLjP2kAp6qzJQB3L4FlkCo5Fmm7YAea32HNEBOg2qwnjXAM2X7dtG2bplFMgRwYCfDdBOoGlcKRroDGj+2O3IOoTgH4a3Mv6Ju99qW2+jzkqQuL4LUbzh1z5WpYhwQMVbPi3nYooz5q+5JpWSSYGEEfGO3DLb+wDa/GJDS5qVpdiHwGQVfFTsRUG6M7M/QCjkDDe0hJrN/pEfclJ6xDH/ZRRyXMRYTwIIO7N9dWgJKzo4qm7Z7HpqUfuqJIU9x28Gr3YvKulLmCms0cEeWQ6X2Vzku+G8lCOx09V40PkAG/kFv1ku2TTJv0IR7ClaoRB46rYa2qz8pWG1Xrm2YJZvRE8ApAbUSGCaKssx8egufICCJoS8zobW8CTDcgxDfQ8T5nTLkdqKU6mYBKBahYSvD8wYDlLDUFXNTKlEgc766CwTuQbnI8cMni69BEyksMcBKFMw7dtrZ490dxgyucrUhocxVYV6dExmZkQl+B47yaWqCK6SPZDjI8Ghf1dzssuMiw3ai0pGuHqF4LcQ5wRZUZmGhX+cxoLpSORvMnI6CF2O4dLjbSnNxbNYESQT7rrgtQ95TJl9H4wgxyc7YRqY9Xb/eqknIEvfRZZkRjXxYQWOIcMarY2HlHWfSokzFeTTFApMvHYQFWqYTE0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d13ee51-2c35-4333-9caa-08d7ece308ab X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:46:54.5309 (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: I5YcWq0OTTropECMlhr3/JT81jVcFtVU7p11wb9ORlmmMY8Eqx9BZWIAMicwQV/aEMK6XLbF4/h9hK2txVg2gg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1465 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra The guest support for detecting and enabling SEV Live migration feature uses the following logic : - kvm_init_plaform() checks if its booted under the EFI - If not EFI, i) check for the KVM_FEATURE_CPUID ii) if CPUID reports that migration is support then issue wrmsrl to enable the SEV migration support - If EFI, i) Check the KVM_FEATURE_CPUID. ii) If CPUID reports that migration is supported, then reads the UEFI enviroment variable which indicates OVMF support for live migration. iii) If variable is set then wrmsr to enable the SEV migration support. The EFI live migration check is done using a late_initcall() callback. Signed-off-by: Ashish Kalra Reported-by: kbuild test robot --- arch/x86/include/asm/mem_encrypt.h | 11 ++++++ arch/x86/kernel/kvm.c | 62 ++++++++++++++++++++++++++++++ arch/x86/mm/mem_encrypt.c | 11 ++++++ 3 files changed, 84 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 848ce43b9040..d10e92ae5ca1 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -20,6 +20,7 @@ extern u64 sme_me_mask; extern bool sev_enabled; +extern bool sev_live_mig_enabled; void sme_encrypt_execute(unsigned long encrypted_kernel_vaddr, unsigned long decrypted_kernel_vaddr, @@ -42,6 +43,8 @@ void __init sme_enable(struct boot_params *bp); int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size); int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size); +void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc); /* Architecture __weak replacement functions */ void __init mem_encrypt_init(void); @@ -55,6 +58,7 @@ bool sev_active(void); #else /* !CONFIG_AMD_MEM_ENCRYPT */ #define sme_me_mask 0ULL +#define sev_live_mig_enabled false static inline void __init sme_early_encrypt(resource_size_t paddr, unsigned long size) { } @@ -76,6 +80,8 @@ static inline int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0; } static inline int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; } +static inline void __init +early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, bool enc) {} #define __bss_decrypted @@ -102,6 +108,11 @@ static inline u64 sme_get_me_mask(void) return sme_me_mask; } +static inline bool sev_live_migration_enabled(void) +{ + return sev_live_mig_enabled; +} + #endif /* __ASSEMBLY__ */ #endif /* __X86_MEM_ENCRYPT_H__ */ diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 928ddb8a8cfc..8b8cc87a3461 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -403,6 +404,53 @@ static inline void __set_percpu_decrypted(void *ptr, unsigned long size) early_set_memory_decrypted((unsigned long) ptr, size); } +#ifdef CONFIG_EFI +static bool setup_kvm_sev_migration(void) +{ + efi_char16_t efi_Sev_Live_Mig_support_name[] = L"SevLiveMigrationEnabled"; + efi_guid_t efi_variable_guid = MEM_ENCRYPT_GUID; + efi_status_t status; + unsigned long size; + bool enabled; + + if (!sev_live_migration_enabled()) + return false; + + size = sizeof(enabled); + + if (!efi_enabled(EFI_RUNTIME_SERVICES)) { + pr_info("setup_kvm_sev_migration: no efi\n"); + return false; + } + + /* Get variable contents into buffer */ + status = efi.get_variable(efi_Sev_Live_Mig_support_name, + &efi_variable_guid, NULL, &size, &enabled); + + if (status == EFI_NOT_FOUND) { + pr_info("setup_kvm_sev_migration: variable not found\n"); + return false; + } + + if (status != EFI_SUCCESS) { + pr_info("setup_kvm_sev_migration: get_variable fail\n"); + return false; + } + + if (enabled == 0) { + pr_info("setup_kvm_sev_migration: live migration disabled in OVMF\n"); + return false; + } + + pr_info("setup_kvm_sev_migration: live migration enabled in OVMF\n"); + wrmsrl(MSR_KVM_SEV_LIVE_MIG_EN, KVM_SEV_LIVE_MIGRATION_ENABLED); + + return true; +} + +late_initcall(setup_kvm_sev_migration); +#endif + /* * Iterate through all possible CPUs and map the memory region pointed * by apf_reason, steal_time and kvm_apic_eoi as decrypted at once. @@ -725,6 +773,20 @@ static void __init kvm_apic_init(void) static void __init kvm_init_platform(void) { + if (sev_active() && + kvm_para_has_feature(KVM_FEATURE_SEV_LIVE_MIGRATION)) { + + printk(KERN_INFO "KVM enable live migration\n"); + sev_live_mig_enabled = true; + /* + * If not booted using EFI, enable Live migration support. + */ + if (!efi_enabled(EFI_BOOT)) + wrmsrl(MSR_KVM_SEV_LIVE_MIG_EN, + KVM_SEV_LIVE_MIGRATION_ENABLED); + } else + printk(KERN_INFO "KVM enable live migration feature unsupported\n"); + 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 603f5abf8a78..3964f5de058c 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -46,6 +46,8 @@ EXPORT_SYMBOL_GPL(sev_enable_key); bool sev_enabled __section(.data); +bool sev_live_mig_enabled __section(.data); + /* Buffer used for early in-place encryption by BSP, no locking needed */ static char sme_early_buffer[PAGE_SIZE] __initdata __aligned(PAGE_SIZE); @@ -204,6 +206,9 @@ static void set_memory_enc_dec_hypercall(unsigned long vaddr, int npages, unsigned long sz = npages << PAGE_SHIFT; unsigned long vaddr_end, vaddr_next; + if (!sev_live_migration_enabled()) + return; + vaddr_end = vaddr + sz; for (; vaddr < vaddr_end; vaddr = vaddr_next) { @@ -375,6 +380,12 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size) return early_set_memory_enc_dec(vaddr, size, true); } +void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc) +{ + set_memory_enc_dec_hypercall(vaddr, npages, enc); +} + /* * SME and SEV are very similar but they are not the same, so there are * times that the kernel will need to distinguish between SME and SEV. The From patchwork Thu Apr 30 08:47:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519529 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F0FE92C for ; Thu, 30 Apr 2020 08:47:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4314021973 for ; Thu, 30 Apr 2020 08:47:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="T5CqBX/6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726937AbgD3IrO (ORCPT ); Thu, 30 Apr 2020 04:47:14 -0400 Received: from mail-co1nam11on2062.outbound.protection.outlook.com ([40.107.220.62]:6047 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726531AbgD3IrN (ORCPT ); Thu, 30 Apr 2020 04:47:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dOJdi+v/Tw775zRDrttkCZZUK+9pC6hk9KnvYCCjDSHdshLTrF1NkzutiWqFRDZy3r0z0M3Z2dTfXsloMi7Jpj84jgl3/S06LcExSymEctHzmnSrFk3RY16alxpEom1/9l0B3yamntlNbxuA76iJWswJ0TDt5ENYVEpxgIZoubzlUWgwJj5fRS7AsbLCcfIkJeOzamqABBZXAyIJDKT0KVl4jXq7fFi3faojLkEx48R8hmjN6p1ZTiJK49Jz3c9KG4cbOdaTwaVlkCql0rLC8GlIpFKj7WvBpQnf6ScOu7ZNNGzYkYiPWnN/rXN0M3Squ2FCXad/lJCpvHMewXeTIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ms5T1TbPWzXX58Hb+fiuk/V0KrkIf2MtQZxaywTUg50=; b=Ge43m7NLhkBS6UGze2XCARDMY5E+IOkMWj/uOjEwRol0uOOr+6GO9J3V7BuG7hf+zKueY6wQIFfuz3eXzHjADin4E4DABfV0krl9EAYTetfY4KTrVKmV2x1QOeSO4sppk+lRzH1890+n5D7lj0YoP6JCzcLwc16ytnMFazIQU7dv4a+8KjOg/NHKTE3axkUdMDZN4Eq/2iMinlUuctTDrkLuNGLVb3vLeiiygpCrx2Ln17Wr+B2ulWpUoj3OyU3zvt2XDwGhowjjfwuNQh00KMpJLsxHO/3xfp6JsneW3bI/rbXyADDM2YILmLgIeQ0WwvHDr04cZsKe0CuV+sha2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ms5T1TbPWzXX58Hb+fiuk/V0KrkIf2MtQZxaywTUg50=; b=T5CqBX/6zrpu2TReQ0Lw5VvJMXregFuYEbw6qcH1L07IK5tR/Mfwa6W5zMgHNllH2Qt/66H/EEPb4SdXTqyCLwJHZn0U+UKYzjcSIzpOTvrpp/Zku0oeA5HAd03dn7P9DR44vx4Rh/3ns4Qm83deF/vvkkhWpBTr60FZfk2lwd0= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1465.namprd12.prod.outlook.com (2603:10b6:4:7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Thu, 30 Apr 2020 08:47:10 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:47:10 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v7 17/18] KVM: x86: Mark _bss_decrypted section variables as decrypted in page encryption bitmap. Date: Thu, 30 Apr 2020 08:47:01 +0000 Message-Id: <864a701c953f01ff12f97f4215512901b4d933ea.1588234824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR16CA0062.namprd16.prod.outlook.com (2603:10b6:805:ca::39) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN6PR16CA0062.namprd16.prod.outlook.com (2603:10b6:805:ca::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 08:47:09 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 318b1ebb-28fa-469a-fb04-08d7ece3122d X-MS-TrafficTypeDiagnostic: DM5PR12MB1465:|DM5PR12MB1465: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1186; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(396003)(366004)(376002)(136003)(346002)(7416002)(66946007)(26005)(36756003)(86362001)(66556008)(66476007)(5660300002)(478600001)(186003)(8936002)(2906002)(8676002)(16526019)(6916009)(7696005)(956004)(2616005)(52116002)(316002)(4326008)(6666004)(6486002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X6YwnWhMUIXu2IGbyq9XQsyF7BQBw7psrgyXcrbGNkG4TLdwXoCdZEcupJcIQQjfYIW1x4QmJMAyffHXqJwnkjy3dGY7hM5LPAdmR0XyzP896xKELBDx0wQUmd7gdHSoJVznqJqyHqAZtTvABTajr3AQb65umZUkUCv4oHCUDMkEF1TL7q1KlqjPFIH84PzJM+uXrbsLGaZ4xqEEVAhBURRV2mAunoWbxwLp20+9BX9yyuNIeGOhwLQlD+I+WgX8UXvKGW27Exg8QmS1llXPk5WZtJQi3Par/wW0KDC4n3kRYYk+/kAGDr2VlQU0Neh8zNkERJRuBEUot5zsBx1bu6jDrB8ADJ23bpk9uQZu8+M6/6451AvtaBGt0TnDi91R3/VSnJB0zarh2B6EBz8OnbGPdW7ZIbc/MbBC3uy1Wk6R2GLWP0u3CrASbRzU78fNHZup/9QYta1QCylQJBucRb7kK8z6uUktIsGouRFTa1GBZjxTqbRfAiTkzXQvFAqf X-MS-Exchange-AntiSpam-MessageData: paiWBeaXBRnVtRxoeHDlwQmbdn5lUCln0RuE/ug3yp4ZOQrtbdoJWjVJSQjcL+FGvintd+FhlYFWRKMHsY5wVNpNKo4DDLZJImmKPe2niyGncDDg1JY+K0grsPgRDRmHe+wPlyG2eI2v8RoKIypqzXrXj/G/ApMKq4l5CV7auDubeyexQwa186MHZksMTMzjWX31FqVGtYxy21P/5Fn/qplmaU81irkUMEf82vs04hrSItf+OyRW41MXHsEoht5OlwHYBBX+CXzmW87ahcH66EcSWD2L7mRR/t8wR3gR2ZB2erJmeBuynQ1R1dNUL7/hwS0jm11fIPy6eAdvGq6fR+c2DxoqojCG595Vynr9ANUJ/g+DWRc5D/RDhJku56YP91XTY6hDUBV75Ce4Nl0l4Gzr9J1Z7Uea7XCPew4olu7q95Y+OgoIg1QTGZVYCPns70fYMm1xXUeSBx5kwWX8ARiW1TJg0EHKmYvPYlYTgTpO1t8lP9xfknshUE9SbWngI/S8C5qe/NW27DJNEnx52RElqZGDTe/Wn9p0m/PZ2m3LkJCJVEWnta+rZBYblL7OmwYI0VGmSRaIY+AbuKBf13cTd4cjKA4M2mCVFli6ns8rxAWn5jGzS0ZwEWSYZDK80IJZ3/Zma0JAKhwirdYK/gCSNfYlXHYVFEN/WPl3rcncbs7qenehkVkdlEdMlkrvwmTOY4+TLNqE2VbPDPLZ6MgzCne9Oxg8BlvAlWlW3T0qLPrfDayBJ0gJdrX//2kgF2MMEtMTkKV+CzQQWN9ZSE2KAJvLIcbYtlwGNcovEZs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 318b1ebb-28fa-469a-fb04-08d7ece3122d X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:47:10.5248 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: J/3+xDFD+XvPZ/vbrTC46Yg6PWDy/PrENNcAFya210H6xJsL73evllnNMI9ho4KR+v+OxLRt0vLT47ZfD4e51A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1465 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Ensure that _bss_decrypted section variables such as hv_clock_boot and wall_clock are marked as decrypted in the page encryption bitmap if sev liv migration is supported. Signed-off-by: Ashish Kalra --- arch/x86/kernel/kvmclock.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 34b18f6eeb2c..65777bf1218d 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -334,6 +334,18 @@ void __init kvmclock_init(void) pr_info("kvm-clock: Using msrs %x and %x", msr_kvm_system_time, msr_kvm_wall_clock); + if (sev_live_migration_enabled()) { + unsigned long nr_pages; + /* + * sizeof(hv_clock_boot) is already PAGE_SIZE aligned + */ + early_set_mem_enc_dec_hypercall((unsigned long)hv_clock_boot, + 1, 0); + nr_pages = DIV_ROUND_UP(sizeof(wall_clock), PAGE_SIZE); + early_set_mem_enc_dec_hypercall((unsigned long)&wall_clock, + nr_pages, 0); + } + this_cpu_write(hv_clock_per_cpu, &hv_clock_boot[0]); kvm_register_clock("primary cpu clock"); pvclock_set_pvti_cpu0_va(hv_clock_boot); From patchwork Thu Apr 30 08:48:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11519535 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D152692C for ; Thu, 30 Apr 2020 08:48:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B478521D79 for ; Thu, 30 Apr 2020 08:48:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="UoP5cDTk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbgD3Isl (ORCPT ); Thu, 30 Apr 2020 04:48:41 -0400 Received: from mail-mw2nam10on2078.outbound.protection.outlook.com ([40.107.94.78]:22881 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726611AbgD3Isl (ORCPT ); Thu, 30 Apr 2020 04:48:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lqz8ct5ikjwWKAYzQ1Gi6ukBN2WpuugrQ1gL8sP+hXhKJ5enSELQVoVVgnUXnqG8ikUR509HWM7B1mdTDiOCpGoWH2itUjTjRkoD54YEEEs6PJti9FeNNmikUJCYDkcaj1Thw4q+xQNsWIrU4YEPaxaaLOSBbZn4cstZA3PIwB2VyomfNfg77YvBHOKK14BUunXVgcKvRs+ZMLrBT/9m9u1HHqmhu1urpilxFJ4rQf5fqutm8GXPpqajw92Vp22MGjZ8BZlUUQ9RyzVvz90adE/SGbOyTjJKsKCHlk18m2rw7jSak2e1vo+QG6BkUPPs+5+y1XJayP89Ss/uwn4RXw== 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=KMnmWSXOVuAuctdePqPIk4ECMJVF0D55bCj+XKGA+uU=; b=EwbxZEqUXHV3Lr5czEyWvDtebDwyplWnWTSp1JqrSu7m57eH+qF+NFhym4tHsYT5ziM1E+F06Lk7oJN0yAyWVtZRZYZ55B4VaG+eootnbFsavHgd9vU3Ls5s8lyrfR5qv82owUHoQMysCm2hAdO42jZXRLT/9/TsxIHMwfSGJUIrxjM4YGYVEpRn7qFHBrAB9IzWb3ifuxFj4i99l8o59hpMzHmQUpfuFxnNrZyUyJGodwFYHeeuepEWCUswdf7j6HzVqIYGO2Qv9POuwfmB+gPzbdaeyTWRBx3HMoF/XPSpZviB8vYS9WCXiOYgrreyvYPxx0uT5BJQwYwgRV+/wA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KMnmWSXOVuAuctdePqPIk4ECMJVF0D55bCj+XKGA+uU=; b=UoP5cDTk9XQMdnsbWT1sP9ZJZKAz6SJ+9WTKbLWzM4gAYDCeH14WHkymIGfPONH07u5/Z6eDZKZVQcHx/BStB46lZFZ3eck+ugcuvwSRcln2YMaBd2Bwbo8FbgGUt858/fxV7rOPmMyyxLUFc7u6y4/gnhAqXCBr6Rp+TwUYYGA= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) by DM5PR12MB1883.namprd12.prod.outlook.com (2603:10b6:3:113::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13; Thu, 30 Apr 2020 08:48:39 +0000 Received: from DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c]) by DM5PR12MB1386.namprd12.prod.outlook.com ([fe80::969:3d4e:6f37:c33c%12]) with mapi id 15.20.2937.028; Thu, 30 Apr 2020 08:48:39 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, rientjes@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com, kexec@lists.infradead.org Subject: [PATCH v7 18/18] KVM: x86: Add kexec support for SEV Live Migration. Date: Thu, 30 Apr 2020 08:48:29 +0000 Message-Id: <0adf76ea0f88e137bef5e045ebf96ebb004ee8df.1588234824.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR05CA0016.namprd05.prod.outlook.com (2603:10b6:805:de::29) To DM5PR12MB1386.namprd12.prod.outlook.com (2603:10b6:3:77::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN6PR05CA0016.namprd05.prod.outlook.com (2603:10b6:805:de::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.12 via Frontend Transport; Thu, 30 Apr 2020 08:48:37 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4ed7b96d-b898-453e-235f-08d7ece346e8 X-MS-TrafficTypeDiagnostic: DM5PR12MB1883:|DM5PR12MB1883: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2512; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1386.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(396003)(366004)(136003)(376002)(39860400002)(478600001)(86362001)(956004)(8936002)(26005)(2906002)(2616005)(6916009)(8676002)(36756003)(6486002)(7416002)(4326008)(16526019)(186003)(7696005)(66476007)(5660300002)(66946007)(6666004)(52116002)(66556008)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C+HsTCYEW6FdZIthQxJbm6pL1Nl+FxJQVp09/rh0kiem0AxDlZyCxAE/9dPTmdModyfIoYgzshaPnjTVurKsCs6pjTCVwhp1fnSAaqimJMkPyne5Or5cxkWQarJWVlM4Ae+bHt+1Ez79zXDRNIPdXSIljLGKFCcoabk0KHaa3OcycxT0TKCdrmBmnHLc2bagphc9cvWvQ6FgfsQi5HI5Vq1Rf0Ix0oPmE4fjHRPSB0ADMeXWbHPJGd7j3yd7c7GRwUYxXU9/Y9/wSfYHSWGE1gNDohpcZn9+HCd0szuhF6qtpyIBPIcFa6HS93k9KXIJCgxUXCjiAgNVxhrbjdSnvaUw5xVzvQm1JTh4d36avowcHrZOYxbPqfBcJMiAbzFBFeFHnxy+ekaVpO1G+iRXSXpGvtelWyHV9IrbT/GvLELv1SRAz7Fwa6Ui83fEqt1GWVp6+WNWQo7TQQKI4rtYBvDRQbwapKKDLLf9LH6PSBUSRhN9c8ggzWdRiXE5buB8 X-MS-Exchange-AntiSpam-MessageData: hklji63G1mQx/Km/dj7Y0UVbSP4x4/xnziRt4TLpNiAAY4ffPSPly5bAmN8bGg2//bTT6TjKTsw46YC49yeagMarSLN1WWKEjY3moYE8PqyOhnDRLt8uyOKrFh5trNfPpcvDZ9C/ROFUA8ZFM5WW4F/Uc0vn9Px4AgYjsGxSVl/FDsiZlZmbwcQKMB1co+pvS0EiLc0yurGhjdBy2fOVE3+V+Bki62GJx0oRRdVeP+Bs0knXeh/kf/348zCZYleZSmTHrhzvyVZIxbRjKldmJ7hiIGlG2E12Vl5oeidNNJRxIZiCO8TJ4e9MJYZ0rI0PBCqr4tiPEfuW1YgwTzq3eBDGkPkoPMtshwPAAwBIlTUxf+5Qs9YBkudOZyo7nEt3xYtY7BdXO7xd0MrE48bWmL3U5OncG7MwXztpJF+shu/rwPUeLhI4jGeVkGNqYI2geNs1NAe+U1nysVYythTpHyFLXwpX5ddV8p9SxQtpcR3hCnZJ4yhpq0/CmBn2/f2XUhB2w+VtCo1l0NzMzhHKs6ML0ESEH3ZPpNX6pXJ/ES5aMnBxogmIrY8/iXCz2xcP4mlCaeeChccA1tXCkqpzzS2Zboa7r4e8+b+Ws3YyUGluGxz/GxRfT8DxbWgliTXmwu72K3KgO4MCSN3iBtfWHj0g3ugl1O/61b39uANQlv2x9Ns/DszjJMGyQa+2lJXWJhwCzaAr2e4tlLAHrur4HpHML6fJx3C06DKC/KIdooTistD8uEDOQsKNny1Ld4XnNsYeejJn/iJybOF7piyYOlyjglG5MPZ5GHoNgxSe854= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ed7b96d-b898-453e-235f-08d7ece346e8 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 08:48:38.9523 (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: hYA9XJorzJVZIF1Q+62mPXLTQSFaAYzgTFj9zroL1yg4CWBzUZmanD51TqFSi10gCv9c/Y/FOzMU2lS7DMxfDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1883 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Reset the host's page encryption bitmap related to kernel specific page encryption status settings before we load a new kernel by kexec. We cannot reset the complete page encryption bitmap here as we need to retain the UEFI/OVMF firmware specific settings. Signed-off-by: Ashish Kalra --- arch/x86/kernel/kvm.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 8b8cc87a3461..68f2de4c1e74 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -35,6 +35,7 @@ #include #include #include +#include static int kvmapf = 1; @@ -358,6 +359,33 @@ static void kvm_pv_guest_cpu_reboot(void *unused) */ if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) wrmsrl(MSR_KVM_PV_EOI_EN, 0); + /* + * Reset the host's page encryption bitmap related to kernel + * specific page encryption status settings before we load a + * new kernel by kexec. NOTE: We cannot reset the complete + * page encryption bitmap here as we need to retain the + * UEFI/OVMF firmware specific settings. + */ + if (sev_live_migration_enabled() & (smp_processor_id() == 0)) { + int i; + unsigned long nr_pages; + + for (i = 0; i < e820_table->nr_entries; i++) { + struct e820_entry *entry = &e820_table->entries[i]; + unsigned long start_pfn; + unsigned long end_pfn; + + if (entry->type != E820_TYPE_RAM) + continue; + + start_pfn = entry->addr >> PAGE_SHIFT; + end_pfn = (entry->addr + entry->size) >> PAGE_SHIFT; + nr_pages = DIV_ROUND_UP(entry->size, PAGE_SIZE); + + kvm_sev_hypercall3(KVM_HC_PAGE_ENC_STATUS, + entry->addr, nr_pages, 1); + } + } kvm_pv_disable_apf(); kvm_disable_steal_time(); }