From patchwork Mon Apr 5 14:21:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0E62C433B4 for ; Mon, 5 Apr 2021 14:21:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7288E613B5 for ; Mon, 5 Apr 2021 14:21:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241306AbhDEOVn (ORCPT ); Mon, 5 Apr 2021 10:21:43 -0400 Received: from mail-bn8nam12on2078.outbound.protection.outlook.com ([40.107.237.78]:15969 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237153AbhDEOVm (ORCPT ); Mon, 5 Apr 2021 10:21:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jUyr67wqGRCMr+gRODwwKsUNtbx7BzDSelI+Z9VMoKRRFAzRLfEEwU45XDKkOGuyw9LJWoDvV/iI0DSyFnqCgo4h2M88dng2e1+8BgijzudhXTqS3NYr1O33sM4PuLNnUYtynoCVV4isNhOK4YToRVG9F2oY2FhwVDctkTqSup1Cw/f6BGVw1eRLuTZY/yuj9lo9OcTcw0yPBLY0wlmRcdA9g+/izBU26Vp6lCHLTuKjtp1o5MELoIj+fiNHhQCiQpnb4SDteYlm/vZiwWu8RohsqcrR4xgxAiphQZ+N0IQA1qYgjPr4HLfQkNaKCflFy2fyI1PWU5j+KW19966NCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p9+vMxeGG/Np/pHxZBLItVNVJH2aLDUxgz42hCBtD2c=; b=dwNnLNRUv5mOEGzwRlzT9gDjN/z4C9yWBsrrvrrgHoZa7J+BbpGr+DGX6ObWx7IJmmobz0kjfuQrd/yTcuJDcFDKJ1RduBVeaHV6rVIAqqjcr3+oeZ5sKWiv5+Ej+w70SFyjXurC9WwJ0GQWqfLe9L7qlTB/oAbkDQvE/la3KlW0S3lrF5hLyWGocSHMoloBdSg0bA+lFG0MX7y3BqnsqtkPxULSa9kUlX3Whmx/ywhuYchcd+nTvLK+c8viMvA1Nzp4YJPYc6VoqNu2s5lSwO5pCLBNEFIpiVFCc+nX+rgdRw6fzQGKZV0ESWR9UFkbNNa95pH3dWxdfJaFeXamqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p9+vMxeGG/Np/pHxZBLItVNVJH2aLDUxgz42hCBtD2c=; b=25FevdG+zUOahB3nPyieqa0f0Wh7/6/jO4F3jGuRdiz1mpBXtp/46AsB7gSqyVP9AVfVQqGL9rtXPtpchP0lyxbml7u0RUFHoFufR7kFpnZ7Jo1JhdafixHU4/1mUEB3wtsySjodNUlMZIpmeDWv/kk7LHvLode07Y2ImceicKo= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4557.namprd12.prod.outlook.com (2603:10b6:806:9d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Mon, 5 Apr 2021 14:21:34 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:21:34 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, rkrcmar@redhat.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 01/13] KVM: SVM: Add KVM_SEV SEND_START command Date: Mon, 5 Apr 2021 14:21:24 +0000 Message-Id: <2f1686d0164e0f1b3d6a41d620408393e0a48376.1617302792.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR03CA0001.namprd03.prod.outlook.com (2603:10b6:806:20::6) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA9PR03CA0001.namprd03.prod.outlook.com (2603:10b6:806:20::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27 via Frontend Transport; Mon, 5 Apr 2021 14:21:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7f6f66aa-b896-4e6b-17bb-08d8f83e1db4 X-MS-TrafficTypeDiagnostic: SA0PR12MB4557: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p+Z6VjhV00tRpj4tD4KxMFBFu3zAZkXZ6VFL8pb+UbQX0NHFVn/BIkCkyZJ82XjFAZtDazjh5qLy6PrkvrEtPx+2n7DTf56VP+9bVTS58g4HCugkvslL6k9vahFca2QCxwaBdLzdrIONjYHmZxQU0XZvmy/DWWOiorTeL9iAWXnl1A2uk71TIZYstwQWJ5X5VutsHD3wNAQEg6IZvcBZbs48JrgHg+NJ99dF3OxwuRqmJ/ytV/B7O6LNyoEPeuNuQkNdK1H4NFINfKFHjUA6EIyAmGvv9RK33Q0ApGFhuU9XQmVTF/oij9IBlfvHqVmelIdwz2jHWwatgjEJwdush16R3U2yv84WU+UOHwXPjXrizZ3JjRypv0hfmcZTZVxmjuj5/O00TSx+4pyIHBlJi/YPeilDE90/FF8H7USk4Jk4slcedY1Xh8ERik/38qylFS8/o716fOIHG80uwj1f3k8XMlaJw42c6BeHw6nwSwrk9+jOqbPIz1PweWTyGxi0GXk7eBwpwYCz+n+F4X8dwR8PaPhlwFC0FdWT9ARI/583Bxgkoen2SRfYtKyey1dDd/okt8SQZMaZR5mWnV9qsfKeniRFb5ofXbrOkeo+q5a6gQimPjIvV6B6aRxvLgIghdxEk05NDU94dU0Yu6RQWbxRG+goBqmKZglI7+jbkQA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(136003)(366004)(376002)(956004)(6916009)(4326008)(52116002)(7696005)(8676002)(316002)(8936002)(36756003)(66556008)(26005)(5660300002)(66946007)(38100700001)(6666004)(83380400001)(2616005)(66476007)(478600001)(2906002)(16526019)(86362001)(186003)(6486002)(7416002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?73otMRskXsD17PG3jo0FYSYB4laI2P?= =?utf-8?q?4Cp5HLqtOP6GPp/FwMzvmYZChyOzY4//w7evWt18MLILxBqowY1Q4qgtLT43zlr96?= =?utf-8?q?tAM7Iz9KQ6lt8mX1BLb71hpkSCtgtgNvPRlGrl6VSEOBUZZXDB+6QcLdiHYybfD3O?= =?utf-8?q?yPaOHRZvgR5kqhFoN55S2SeUZJg13HOL+EZjUpBOXV9t/sG15vOkGmkDwWzEmbca0?= =?utf-8?q?mzv5kARAroioKwaCW349WAys7JLq9XEYXTl2a/DYnXt+qkfSiIJlXPFYXJrHv4ehw?= =?utf-8?q?DpKsFnppbXb99mwJqwdHcUd6jGNYFE0nSzdycuC8Ncm4MwjWPs+WUkvQIrXN3CJIE?= =?utf-8?q?n70gfpAxV6UJ/S1lr5fgPhfi+lV0ckJaB06ZIzF74sXuoZ783Fl3zP0PRinVxHM0y?= =?utf-8?q?y5IjFFS0qY9KIHkKjKqtdKNB7S2lGgoyMC+2Z2ecbb1RKgXCNm8ES2N/l2cwtLNrY?= =?utf-8?q?7cXKJSZreoahMLckwC76UyWYYMeKNv6gW1Z0aav882bNeryO0z//QSKrM1YnprXCx?= =?utf-8?q?8GuCWEox1jYRKsYURsVk8olUxk/xQ0d3oCHyPSzyRiXKuMeoA1kcKMrLO+rDMQ/ds?= =?utf-8?q?7nCUTigeuNSgILPJUa53vlOnvg7ATu3huCgL4/3GbREDpOwm3mf39gPUu90hCq4lZ?= =?utf-8?q?3kuWzlpe0kMaUcb9KRzxWsL1k3AxD0NhoPGrzGgIbweg/L0kROMw8U2yyRpZ+EGgj?= =?utf-8?q?b4tKxXBAuu2z1rKsjkhZauE16c59xUXKnhNMZqwveyVEBbNSo/9Jma/C8xvLCIb12?= =?utf-8?q?ScWTAzinHTgNDpsc7AKZEJzcnMFqc1gSWz3c8p3ZDFW0JwEJSji9h3v/ipMCV6rQX?= =?utf-8?q?gKcO7G2Md9QizvWM6Thr3NQ1Rbdcoke8nHvw0CoVsXH8/9u17rokrr7UqXvlWm//U?= =?utf-8?q?vi23BrXc+Hpvi58vOTsGRCEuh9Hyd+WOgad5xQkTCIAH4Jas8JJ4nnAbu4HWbC2qm?= =?utf-8?q?MdOaBVS+3lkRIXHkCXYavN5OdsjbEKbkaWzRJB0rlPsY7ffsZSKj9ykWcHv8KL1lJ?= =?utf-8?q?Y6rKHssWhrGru/XVbZ64zAtfs3XomXvHbcb0fx6OBcDDlWnP2JYaaicJtqxBmLn23?= =?utf-8?q?yejwyasuml8Jq5yTqT14TBzd67Q0BZ5nu552PJfB+EeWAgnzoqgJ23+nFGb/OSNWe?= =?utf-8?q?OEQz6ICxzj65e2xbFC5J0aDXaaFJM9GiZ1tvfdbblJiN+WFWq4ZqxS7G+SFjkl/+U?= =?utf-8?q?D6LaWOSXvtobVDT2jf9Oxgztvy6PA7QpCC1Fw6DFtvc2ChTEzcCzGGnJT+O+eKALU?= =?utf-8?q?XQmJWxr/6VY32K?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f6f66aa-b896-4e6b-17bb-08d8f83e1db4 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:21:34.5306 (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: 5/wNpaYDaTfii61WSH7CUhKSLea4HAWNquaMuxetL6RcVLf843SIXn4V26JMW3alE6utrEeTGbnNIRboQwx0Cg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4557 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used to create an outgoing SEV guest encryption context. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 27 ++++ arch/x86/kvm/svm/sev.c | 125 ++++++++++++++++++ include/linux/psp-sev.h | 8 +- include/uapi/linux/kvm.h | 12 ++ 4 files changed, 168 insertions(+), 4 deletions(-) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index 469a6308765b..ac799dd7a618 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -284,6 +284,33 @@ Returns: 0 on success, -negative on error __u32 len; }; +10. KVM_SEV_SEND_START +---------------------- + +The KVM_SEV_SEND_START command can be used by the hypervisor to create an +outgoing guest encryption context. + +Parameters (in): struct kvm_sev_send_start + +Returns: 0 on success, -negative on error + +:: + struct kvm_sev_send_start { + __u32 policy; /* guest policy */ + + __u64 pdh_cert_uaddr; /* platform Diffie-Hellman certificate */ + __u32 pdh_cert_len; + + __u64 plat_certs_uaddr; /* platform certificate chain */ + __u32 plat_certs_len; + + __u64 amd_certs_uaddr; /* AMD certificate */ + __u32 amd_certs_len; + + __u64 session_uaddr; /* Guest session information */ + __u32 session_len; + }; + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 874ea309279f..2b65900c05d6 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1110,6 +1110,128 @@ static int sev_get_attestation_report(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +/* Userspace wants to query session length. */ +static int +__sev_send_start_query_session_length(struct kvm *kvm, struct kvm_sev_cmd *argp, + struct kvm_sev_send_start *params) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_start *data; + int ret; + + data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT); + if (data == NULL) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_START, data, &argp->error); + + params->session_len = data->session_len; + if (copy_to_user((void __user *)(uintptr_t)argp->data, params, + sizeof(struct kvm_sev_send_start))) + ret = -EFAULT; + + kfree(data); + return ret; +} + +static int sev_send_start(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_start *data; + struct kvm_sev_send_start params; + void *amd_certs, *session_data; + void *pdh_cert, *plat_certs; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_send_start))) + return -EFAULT; + + /* if session_len is zero, userspace wants to query the session length */ + if (!params.session_len) + return __sev_send_start_query_session_length(kvm, argp, + ¶ms); + + /* some sanity checks */ + if (!params.pdh_cert_uaddr || !params.pdh_cert_len || + !params.session_uaddr || params.session_len > SEV_FW_BLOB_MAX_SIZE) + return -EINVAL; + + /* allocate the memory to hold the session data blob */ + session_data = kmalloc(params.session_len, GFP_KERNEL_ACCOUNT); + if (!session_data) + return -ENOMEM; + + /* copy the certificate blobs from userspace */ + pdh_cert = psp_copy_user_blob(params.pdh_cert_uaddr, + params.pdh_cert_len); + if (IS_ERR(pdh_cert)) { + ret = PTR_ERR(pdh_cert); + goto e_free_session; + } + + plat_certs = psp_copy_user_blob(params.plat_certs_uaddr, + params.plat_certs_len); + if (IS_ERR(plat_certs)) { + ret = PTR_ERR(plat_certs); + goto e_free_pdh; + } + + amd_certs = psp_copy_user_blob(params.amd_certs_uaddr, + params.amd_certs_len); + if (IS_ERR(amd_certs)) { + ret = PTR_ERR(amd_certs); + goto e_free_plat_cert; + } + + data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT); + if (data == NULL) { + ret = -ENOMEM; + goto e_free_amd_cert; + } + + /* populate the FW SEND_START field with system physical address */ + data->pdh_cert_address = __psp_pa(pdh_cert); + data->pdh_cert_len = params.pdh_cert_len; + data->plat_certs_address = __psp_pa(plat_certs); + data->plat_certs_len = params.plat_certs_len; + data->amd_certs_address = __psp_pa(amd_certs); + data->amd_certs_len = params.amd_certs_len; + data->session_address = __psp_pa(session_data); + data->session_len = params.session_len; + data->handle = sev->handle; + + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_START, data, &argp->error); + + if (!ret && copy_to_user((void __user *)(uintptr_t)params.session_uaddr, + session_data, params.session_len)) { + ret = -EFAULT; + goto e_free; + } + + params.policy = data->policy; + params.session_len = data->session_len; + if (copy_to_user((void __user *)(uintptr_t)argp->data, ¶ms, + sizeof(struct kvm_sev_send_start))) + ret = -EFAULT; + +e_free: + kfree(data); +e_free_amd_cert: + kfree(amd_certs); +e_free_plat_cert: + kfree(plat_certs); +e_free_pdh: + kfree(pdh_cert); +e_free_session: + kfree(session_data); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1163,6 +1285,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_GET_ATTESTATION_REPORT: r = sev_get_attestation_report(kvm, &sev_cmd); break; + case KVM_SEV_SEND_START: + r = sev_send_start(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index b801ead1e2bb..73da511b9423 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -326,11 +326,11 @@ struct sev_data_send_start { u64 pdh_cert_address; /* In */ u32 pdh_cert_len; /* In */ u32 reserved1; - u64 plat_cert_address; /* In */ - u32 plat_cert_len; /* In */ + u64 plat_certs_address; /* In */ + u32 plat_certs_len; /* In */ u32 reserved2; - u64 amd_cert_address; /* In */ - u32 amd_cert_len; /* In */ + u64 amd_certs_address; /* In */ + u32 amd_certs_len; /* In */ u32 reserved3; u64 session_address; /* In */ u32 session_len; /* In/Out */ diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index f6afee209620..ac53ad2e7271 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1729,6 +1729,18 @@ struct kvm_sev_attestation_report { __u32 len; }; +struct kvm_sev_send_start { + __u32 policy; + __u64 pdh_cert_uaddr; + __u32 pdh_cert_len; + __u64 plat_certs_uaddr; + __u32 plat_certs_len; + __u64 amd_certs_uaddr; + __u32 amd_certs_len; + __u64 session_uaddr; + __u32 session_len; +}; + #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2) From patchwork Mon Apr 5 14:23:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABDADC433B4 for ; Mon, 5 Apr 2021 14:23:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D9626139E for ; Mon, 5 Apr 2021 14:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241324AbhDEOXq (ORCPT ); Mon, 5 Apr 2021 10:23:46 -0400 Received: from mail-co1nam11on2083.outbound.protection.outlook.com ([40.107.220.83]:47073 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237153AbhDEOXp (ORCPT ); Mon, 5 Apr 2021 10:23:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b9+93Nup24VIPaJzESMre/36Xt4iDw9MniC3qoqomBGNaaWVOtW0TBaM63W3AIDa2iqnYwiHhRikHijBfRwwZtw+QXdyLaLvNjpPtbC1x+DcdkQ2vKvLdZiRBk8EXjG6K7dR8AHh8u9SMYpbIeCNBjQq6B/LkgvAf9GrGq1oPjpuUjx1SYhsQmTrbiv2IDjOfwGHmnBFXS8PvJ9352mA+HbGlrVNMiZR0RNqzQbZh8Mjke8xxDvgsg6giyxH/SKxxIvU/LFEvULdQ36tCMG5ltUAfkV18zmKkIjwoUFCmnhppjANQ9SB3q+rbIEF5nh93K7ndkVwXHTymyVZ8hAXcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TmptNcWrK0Wse7VDXUmUvzb21xGh5dE1N4aXqer08gc=; b=EZtqL+fMuW+yWr49xkeSC2GtHzboQ5P3DcsgQKydpphCZgadlItwv/0g5BOquS1YG5f0LceJXeJVqaOR9ex3ih48Elt5jecaTNi/YS2zBlzzs8M2skvF82ZQ5fY0cIFAnFwI4tffM7af7KqlwuN6SvwduZFnP5SiM3Eepu78LJfkaytb7u8bggytuOQH+TYpeUW18oYyWHcJkNB28VGaDATZD5CBVvlc/7WJl1cF/IjVYj6qkfriu3qAgUCGI62xK5JBRbbOt5y7z6ztB9C5rHU8d3+5OK0zA7lhXXX4EnCKpDMSOB9J2FE0ja7dtrCNHOw9ISinriY1CBgN37YNqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TmptNcWrK0Wse7VDXUmUvzb21xGh5dE1N4aXqer08gc=; b=0uTnF3dLspluMcbIpBbcyPTUH2DDDfAOWyX+sd8H8RoNRBxxwRKLdm9guTiOhNcSG9kROh0RtxKhteUrVowhu1of2oGk4Y0OmmZ0+QdyNfS3bgc60AeZca0KeZ/UIRVRCweNKpvkTgk5EogC6/JKorfgHX/PIcAzgyzd9DmnM9s= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Mon, 5 Apr 2021 14:23:36 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:23: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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 02/13] KVM: SVM: Add KVM_SEND_UPDATE_DATA command Date: Mon, 5 Apr 2021 14:23:26 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0003.namprd05.prod.outlook.com (2603:10b6:803:40::16) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN4PR0501CA0003.namprd05.prod.outlook.com (2603:10b6:803:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.8 via Frontend Transport; Mon, 5 Apr 2021 14:23:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e63b4af0-bc8e-4755-87e3-08d8f83e663f X-MS-TrafficTypeDiagnostic: SN6PR12MB2767: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P11NxgzdRtGI5edZ6QOaiiJwh2OqXh6M+MNrn6bHczGOpNGwl9dxssIGKZyAX/3PL/nPHDutlmyEaA4qwzW0Q/8SZEqIWF7FX4U4ouxvNFJJVb5WkIXR9AOd0jH/4Kd0vq/SW286Z16UItwEeWkSzDM/bavTJQC5ViryK3qgcD0MUnnreEGcG6REuUgOQh6zZuH9lot2HlEUqtsJZYZ6YEJFKxe587BCREoq44NbqXO9mF9aaGjijTU6+GhgdmuwibhnCUF23PjoJ2El5P6bg+Q2uEST9UR80etZQlloaXgzzpKXecEY7W/Wi4KWW2vomkza+8kHLEIImM3E/dRZUOFJ3bJLoaPW8SrvNNtVMcYZj/twTWQZLaADbpcv5AnKnPK2zevibioZCfvWz9/UGfKnTXpKasQ6LjowiwBSAGWUUE97QQBaYkIPQIqkTgY+9NUNTyODWvKFxePOLvq2GXosr7r+/8YX+5WQVVWZI+hdFXz5e4iU+mBPXDGA1ayt5eoxYRZ+v7sGdIn+r/zyAOsRkljbp4xrXOy++PY6NVQOflISEgFU9oDN8cMxkcEgDgSd2rm+Q0JVHo8v8+K+qynYQWsM9OYcrmHcK7JHMBhVYjY05r6TS5x/kXHJYrL4H3H3dTv4jTGF3McHA+Q7qytGFlUahBy5Qs8ABxmZgeg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(366004)(39860400002)(376002)(396003)(136003)(66556008)(8936002)(66476007)(478600001)(36756003)(83380400001)(7696005)(66946007)(52116002)(5660300002)(186003)(2616005)(16526019)(26005)(86362001)(2906002)(38100700001)(6666004)(6916009)(7416002)(316002)(4326008)(956004)(8676002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?6o6x1mJnJBn4c3/aZd2qBI+fG2/J6m?= =?utf-8?q?C1O2vELwwxOwVsz9xH41HQt8VsFzbqlaHPpnuGLbkr9lrFD53+FdpX/Kbd+fQpP/p?= =?utf-8?q?Jar0NXfs19tg1AH5u9dIZQfLQ3/2F60spfPoh9QIEz8xIOA97OrSuN8WH5F5ihvUN?= =?utf-8?q?nTQfODYl74wCHwI8+L6bm6nJwoG9UH1ZkjGL1MFksNLbgi0bMce0OwIMmCOX4BHLo?= =?utf-8?q?OQutE+cwnlJ2ACcTeOeqX9CNJieyDLvPUqju8zhFJPBCsVdG82eaMqNFIOtwIP6PY?= =?utf-8?q?l54IQ0GmcFjxOmU8J4k7wrvRv14HpmncdHP9GBduAH+d/DTYvVAibYSV2pJImAcfN?= =?utf-8?q?oy7lITymwXOj+WPGvuM/L0DRO981gMy/1OcieCzB7Sy3Wm4dvM79loBtH5vmI9Uk3?= =?utf-8?q?gUhifoVdRHhZD8lDkwKvoZU5236GoUGdk+LjV32Th3C0DxVgm+zT1+qhSR+8496di?= =?utf-8?q?UBWw7H47ty7i+Cs0nWWNGKT9gBoj0cB2c+KwPMU036sOydEQENeFYMevwm9og6Fuh?= =?utf-8?q?SpHEg0ldzozdejfOnCHOEGbPI66oJtzG4Nrqq8vVIVH6p4YQm+HowfUeMeLSVGzeb?= =?utf-8?q?2xNUBNyR4h+MJ1D+U05ALsTtWMRqvFnqCG1KkVlIOmD6DX6fSyC5idzD0IylwMJpM?= =?utf-8?q?fAhgRzlnFW8G+t6KkTLNEAv87xvU7auSe9Z5Qylra4uDxzukFJox8XDyRdFdyDmtf?= =?utf-8?q?mG9jxz7cPnED/pk8g5fby7+xTB04AnBqzvOi6GQQYKIBXGuzrkjXMKq66g74lmMOb?= =?utf-8?q?B5vBli+LT7i/6PPU86yHIlyPo+KFbp0tQM+AmLOKHzAirKufKvheScuDHOWVQEsVx?= =?utf-8?q?fSSEu/Llr2mvYzT7+y3sJxJ11xM3y+qZ3KuN/E/MqDqZp6wFXDDatCE0yO0z+XVre?= =?utf-8?q?eD4JsSMhWKkoSogVtw4ineihjz2+6LrITxmuGkiHfE/0+mJoq2KLNFNM65nWjEsBd?= =?utf-8?q?OEIPbd62fEgvHKWHXeRGYiKQL3dQ6ybvIbMsoMZsWYcpGUGkwtWpaSPP8JlJVcVF1?= =?utf-8?q?iSzkuOaTjIXG4lHoxmCr5nZQ0cI8asJnqWAu5dv32m7RQNBtsFQlgv5KE0mAAIp/b?= =?utf-8?q?nult4goLsfmziuLiIcDOgkXJrK77LzKCpAIPrYzJ97VC9FKH62RSZtiPQzDJiCJ5C?= =?utf-8?q?XiDJ0sN5Znn3cZt8rGbCi6k9GhnPy7zPrZbYdHoIRtI3RCIfnUnBalZYzWcLIv0n/?= =?utf-8?q?LKhNGSm0dpXapR1LLNiYkmdSXcNdM5+f/ZfkWsoDp2nAl1M24nz1aYzoRTRVTcuhZ?= =?utf-8?q?83w9pAZBvbGodW?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e63b4af0-bc8e-4755-87e3-08d8f83e663f X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:23:36.1334 (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: Mm8KST750zFF5twWI9SfcLrGw0zcPhbzypj5swPuwY4AjV4/HEJ082iuDASd/RaiQx3ow0VXK5lDDLUGn8R4Yw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2767 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used for encrypting the guest memory region using the encryption context created with KVM_SEV_SEND_START. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by : Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 24 ++++ arch/x86/kvm/svm/sev.c | 122 ++++++++++++++++++ include/uapi/linux/kvm.h | 9 ++ 3 files changed, 155 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index ac799dd7a618..3c5456e0268a 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -311,6 +311,30 @@ Returns: 0 on success, -negative on error __u32 session_len; }; +11. KVM_SEV_SEND_UPDATE_DATA +---------------------------- + +The KVM_SEV_SEND_UPDATE_DATA command can be used by the hypervisor to encrypt the +outgoing guest memory region with the encryption context creating using +KVM_SEV_SEND_START. + +Parameters (in): struct kvm_sev_send_update_data + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_launch_send_update_data { + __u64 hdr_uaddr; /* userspace address containing the packet header */ + __u32 hdr_len; + + __u64 guest_uaddr; /* the source memory region to be encrypted */ + __u32 guest_len; + + __u64 trans_uaddr; /* the destition memory region */ + __u32 trans_len; + }; + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 2b65900c05d6..30527285a39a 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -34,6 +34,7 @@ static DECLARE_RWSEM(sev_deactivate_lock); static DEFINE_MUTEX(sev_bitmap_lock); unsigned int max_sev_asid; static unsigned int min_sev_asid; +static unsigned long sev_me_mask; static unsigned long *sev_asid_bitmap; static unsigned long *sev_reclaim_asid_bitmap; @@ -1232,6 +1233,123 @@ static int sev_send_start(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +/* Userspace wants to query either header or trans length. */ +static int +__sev_send_update_data_query_lengths(struct kvm *kvm, struct kvm_sev_cmd *argp, + struct kvm_sev_send_update_data *params) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_update_data *data; + int ret; + + data = kzalloc(sizeof(*data), GFP_KERNEL_ACCOUNT); + if (!data) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_UPDATE_DATA, data, &argp->error); + + params->hdr_len = data->hdr_len; + params->trans_len = data->trans_len; + + if (copy_to_user((void __user *)(uintptr_t)argp->data, params, + sizeof(struct kvm_sev_send_update_data))) + ret = -EFAULT; + + kfree(data); + return ret; +} + +static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_update_data *data; + struct kvm_sev_send_update_data params; + void *hdr, *trans_data; + struct page **guest_page; + unsigned long n; + int ret, offset; + + if (!sev_guest(kvm)) + return -ENOTTY; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_send_update_data))) + return -EFAULT; + + /* userspace wants to query either header or trans length */ + if (!params.trans_len || !params.hdr_len) + return __sev_send_update_data_query_lengths(kvm, argp, ¶ms); + + if (!params.trans_uaddr || !params.guest_uaddr || + !params.guest_len || !params.hdr_uaddr) + return -EINVAL; + + /* Check if we are crossing the page boundary */ + offset = params.guest_uaddr & (PAGE_SIZE - 1); + if ((params.guest_len + offset > PAGE_SIZE)) + return -EINVAL; + + /* Pin guest memory */ + guest_page = sev_pin_memory(kvm, params.guest_uaddr & PAGE_MASK, + PAGE_SIZE, &n, 0); + if (!guest_page) + return -EFAULT; + + /* allocate memory for header and transport buffer */ + ret = -ENOMEM; + hdr = kmalloc(params.hdr_len, GFP_KERNEL_ACCOUNT); + if (!hdr) + goto e_unpin; + + trans_data = kmalloc(params.trans_len, GFP_KERNEL_ACCOUNT); + if (!trans_data) + goto e_free_hdr; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + goto e_free_trans_data; + + data->hdr_address = __psp_pa(hdr); + data->hdr_len = params.hdr_len; + data->trans_address = __psp_pa(trans_data); + data->trans_len = params.trans_len; + + /* The SEND_UPDATE_DATA command requires C-bit to be always set. */ + data->guest_address = (page_to_pfn(guest_page[0]) << PAGE_SHIFT) + + offset; + data->guest_address |= sev_me_mask; + data->guest_len = params.guest_len; + data->handle = sev->handle; + + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_UPDATE_DATA, data, &argp->error); + + if (ret) + goto e_free; + + /* copy transport buffer to user space */ + if (copy_to_user((void __user *)(uintptr_t)params.trans_uaddr, + trans_data, params.trans_len)) { + ret = -EFAULT; + goto e_free; + } + + /* Copy packet header to userspace. */ + ret = copy_to_user((void __user *)(uintptr_t)params.hdr_uaddr, hdr, + params.hdr_len); + +e_free: + kfree(data); +e_free_trans_data: + kfree(trans_data); +e_free_hdr: + kfree(hdr); +e_unpin: + sev_unpin_memory(kvm, guest_page, n); + + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1288,6 +1406,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_SEND_START: r = sev_send_start(kvm, &sev_cmd); break; + case KVM_SEV_SEND_UPDATE_DATA: + r = sev_send_update_data(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; @@ -1467,6 +1588,7 @@ void __init sev_hardware_setup(void) /* Minimum ASID value that should be used for SEV guest */ min_sev_asid = edx; + sev_me_mask = 1UL << (ebx & 0x3f); /* Initialize SEV ASID bitmaps */ sev_asid_bitmap = bitmap_zalloc(max_sev_asid, GFP_KERNEL); diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index ac53ad2e7271..d45af34c31be 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1741,6 +1741,15 @@ struct kvm_sev_send_start { __u32 session_len; }; +struct kvm_sev_send_update_data { + __u64 hdr_uaddr; + __u32 hdr_len; + __u64 guest_uaddr; + __u32 guest_len; + __u64 trans_uaddr; + __u32 trans_len; +}; + #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2) From patchwork Mon Apr 5 14:23:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182971 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE060C433B4 for ; Mon, 5 Apr 2021 14:24:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA110613B2 for ; Mon, 5 Apr 2021 14:24:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237696AbhDEOYF (ORCPT ); Mon, 5 Apr 2021 10:24:05 -0400 Received: from mail-co1nam11on2051.outbound.protection.outlook.com ([40.107.220.51]:39265 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235959AbhDEOYE (ORCPT ); Mon, 5 Apr 2021 10:24:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WKc4Kyh6y0s060WROLw0tMJ5p1HpoRg0I0BRpUH2U0uh3esh9JvzdGKoTkcfgC2krrgK5lA/CU0do6/LEWJDK+0C+xZoR8cUaut5znsggel1bDrmN6FmHyFqLYcs94YFQN35UEMsYET0Rdwy1yTw/K8QaiYz2RG/jO0NXB9pp76XPzNrY5cX1HlG10Do0yWjD8Lwqs3Js/8U0M9xicfLScAOE0MIsea2abwXd/A43etR+rX2S7MR/65H6Y9ATDMbdYiT1yGWGvx0wIiFCZcJH7j+Z+hzj2YW5LpIYObROZRNP1AWKC+ql4dN/7gLv1Hp4ySqHDn3qk5GVAmIp3oVcQ== 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=MYVNY8BsTybE58fvtY+jcGFOHWn1tynkMK/KKN9NcjU=; b=h3ePSEUJ/eSgS4/lF+eon4d7iFNinZB3jPyMpnSm/hz/hAuZcUpiTplQ0JddJNeJtVdmFzYtx7Qs+8FfOoJ6N5k2ZdszFkYnS0y/GeTk48yKiEdqGCjNlOU8OZVrr9A3bCoet7li+zMknSaNvF1/TflLW5C0i3f3RmLCvDGTaeodD0FI89xkwTKUimT8GokqZ80FO1gGmbOLRFFdmRsLsIiFm+p3pewH3LoX4ub9AK+j7SRiTUl6BSZvkKWsplqh1GfpEIvIGeHFbcCARlOXg8DGL0t7F69+rdENyN6B+CqbvWcVRo6+xMBgTfL0ePurhQT0R9sKB4sVWQcJ/jCd8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MYVNY8BsTybE58fvtY+jcGFOHWn1tynkMK/KKN9NcjU=; b=211wAsb3mKGUBl9eeGLfPNvFEGDZiWJtO7XvRdtL5c8zNYyQjCk7sOHO2/ajwUpAUXLTLC95G3Ip8MCZBfTc1OyfFeffLCnHkRmfHnwHS+Uc5AYDZlpMdJpWPMQ1iEafIvzfi1RqXbz3v+0y8rpE3ahpCn1m2JuH4tuOpkFk+JI= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Mon, 5 Apr 2021 14:23:55 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:23:55 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 03/13] KVM: SVM: Add KVM_SEV_SEND_FINISH command Date: Mon, 5 Apr 2021 14:23:46 +0000 Message-Id: <5082bd6a8539d24bc55a1dd63a1b341245bb168f.1617302792.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0059.namprd11.prod.outlook.com (2603:10b6:806:d0::34) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR11CA0059.namprd11.prod.outlook.com (2603:10b6:806:d0::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 14:23:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 550547da-4c50-487b-9fef-08d8f83e71bb X-MS-TrafficTypeDiagnostic: SN6PR12MB2767: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EetquNzebLFx5+WWh4lV8fvoBzd0cLsG3srX9inzhWx3tPiSdUbH1+6Yrxf/IsdOAKXeTD5pJL5IrnkEeH37N/Npz84+NP/vJxe2Z7D04rroLDUOVOKZiCsdaKKd9l0XZcX74E2SaPF3Vdn/4yvthaltioanZZBiV+CmZC7cxL1cwaSZ6sUJnpoe8aC3YErYCJzYEUPdOU4lS0jBfrbZf3CjtYLfiu/v4/EBew8Kh0rRe68nZ6ciHUn9v8y5uvnUKCJrW9PP0R6CW8kpV4Z+Od71LxarHRJKYUR1kuUGGx+NxRmRf3Am6fzx/EJfFEOlulLB9ViqdlYgfyhLiVBivQ/h4/f5hKGqdRX+PjZLMKSQz4DOfBRQnhFpBxDymVd3UBzbpo2kzrb/lLmry571l2SDGjLjjevuzz5sRwLCQG6J8avxWu8vhL4CsDzZu1GRLzA5J05CEUKOieb+0qWf2wUqIPs4rl1UCSytaJ7yx4xelY92qMxH66M5sdIjMhRhvZjzjeYtwcUGl9G5IIsb3fshMUgTBk7r5UQhQoWKzUzImCswPynqfJR8t/r4372Z77sSm+DhNMbFhNc3C9/7el+82HvzkjLp1BwUy1TsFGfgePqyus4rlEbXAhX8q1VvFhgSW9veq8xsDJ4ATIWlug== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(366004)(39860400002)(376002)(396003)(136003)(66556008)(8936002)(66476007)(478600001)(36756003)(83380400001)(7696005)(66946007)(52116002)(5660300002)(186003)(2616005)(16526019)(26005)(86362001)(2906002)(38100700001)(6666004)(6916009)(7416002)(316002)(4326008)(956004)(8676002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?O27z7PwnLGShQUPj5fFh6qwhQydhfU?= =?utf-8?q?UhWxqRxwJNWWxXH++6AXmDievDKF5w52SMlqaXNRzeBpojhfnhJ6z6BN9dfxQVE6W?= =?utf-8?q?aZEOkcfEE2kOK2yp9Bw31lthYHbJRZRsSpomLLa5xEoK7PZ8WC4RFY7Kk7WNME1en?= =?utf-8?q?VFcOmeYHEXZiw0jEJq28n1iifgos25ngpuRkrRQxAZ/y45g3G3zllK/8x34KcuUKb?= =?utf-8?q?jh246FmZsbcf/9usuM2fUgaWE4y9YuSl9Uol7SismIuHUD0dSUdc9bA6QTt6Cakn2?= =?utf-8?q?Nk/g/kBQOfSkNyM7fP8hwojgQFYK7N8yOsaov0vS1bUAlj/wAK59Bi+QfXD58KGJ0?= =?utf-8?q?K2v7hfjYmdizWDiGqde8f3bm4W3BE8qCN8LGDJh/G5fbsXOaP3lkxp2fhfd4Px3ZJ?= =?utf-8?q?OIL2jRzwjEKHXJd+s7XnAoRrQIrIC+SHnJu2UQKrv4bsJ3oho5Z70mkQOqqJ8WH+m?= =?utf-8?q?sn/Q+KYw0MyRhHKzuX0vNHQwi7yhK1Z/AJt4TEJzjc8rCqV9hvNya3Nyxm7YUlrKV?= =?utf-8?q?mzSnV65/poJYhk/kSeFHsk5FeanBIj4PG5DvvJ33vLo18rNpwKW7doeEDedhkVWGw?= =?utf-8?q?1wh2qB6UwgrIELdvRewaSmmHpaAmtTLkr15HAuJXIK5P+9ga/bNiETks/Pm3nTc5K?= =?utf-8?q?glLm3vqUtVC4wzjQAYVXaw8WZdtRWyCG5gPjhM/jnkEBzAxn8bKGhb6KAgb2HActw?= =?utf-8?q?d1VIRXNw9UaS0MIWbV35fhzL4u7fQOAP03LcPbSHug/2AUr4rrKFHbz5C6RuoIEUZ?= =?utf-8?q?fN6g4vdU2oD0rwF8hXeNtyB5mOU+IPuKxSGDd7ZyRLovi3fPQiCvXkSURHKrdcVvM?= =?utf-8?q?cZ4FHTeDGPopKp2zGxSbHU7ijy8V5/HY9tCgB4FZ0DsNBCrwLtjQ1gCgjVavIIIj6?= =?utf-8?q?tegtez0j2tkz8Tf12ATku1he/8Q30AEvX3QpEqttoO5Bd4x8lOAmeGHQGMQEG1oQE?= =?utf-8?q?YAiGOlyKLpSeyT5War6vCjLomQSEGeJIDMciBqJbzKdvZhMubn95mDc8VUQGt0QQK?= =?utf-8?q?WS4Jq481fUgZZPVq2Gi4Aq9nsbTm4YIZQK4xFgLpFxqqj57cN/enyKi5+hRAXnvKh?= =?utf-8?q?uecT3g/6LdfMz56PgWV3tdnwTND+qCFfaNxgnmlCBu4OuBBV+D2vp9ETy07hzzrTf?= =?utf-8?q?tzpI9kvFwRzJ0tpwQC+rUp6H/F8ZeYLI26xWlZo2WYmkkd2nNgZEsULEaC4cKvmL6?= =?utf-8?q?y32zqRzHdWb/FfXW/U0Ype1oqNHVTqatqFYDTciGCNG3pF0OTEIMfh9DUomRoURFB?= =?utf-8?q?JywsoGbeId6CZR?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 550547da-4c50-487b-9fef-08d8f83e71bb X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:23:55.3916 (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: 1ifooUy1JouaSZ3LvtRR+9G7xzIIZW/bk3a+ql2AFM5v67WFM0D30DBBpA/RXfY520F7Cm8Kggg2PM+TKl2o9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2767 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used to finailize the encryption context created with KVM_SEV_SEND_START command. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 8 +++++++ arch/x86/kvm/svm/sev.c | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index 3c5456e0268a..26c4e6c83f62 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -335,6 +335,14 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +12. KVM_SEV_SEND_FINISH +------------------------ + +After completion of the migration flow, the KVM_SEV_SEND_FINISH command can be +issued by the hypervisor to delete the encryption context. + +Returns: 0 on success, -negative on error + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 30527285a39a..92325d9527ce 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1350,6 +1350,26 @@ static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_send_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_finish *data; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_FINISH, data, &argp->error); + + kfree(data); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1409,6 +1429,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_SEND_UPDATE_DATA: r = sev_send_update_data(kvm, &sev_cmd); break; + case KVM_SEV_SEND_FINISH: + r = sev_send_finish(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; From patchwork Mon Apr 5 14:24:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CDDDC433ED for ; Mon, 5 Apr 2021 14:24:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41087613B4 for ; Mon, 5 Apr 2021 14:24:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241337AbhDEOYo (ORCPT ); Mon, 5 Apr 2021 10:24:44 -0400 Received: from mail-dm6nam12on2052.outbound.protection.outlook.com ([40.107.243.52]:48993 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235959AbhDEOYn (ORCPT ); Mon, 5 Apr 2021 10:24:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XmCitbkNAGKsuYD21LbBUmBCaXLoA5DUjFE2Yz5p00eia9j9KQeInz9q3VvU89eE4E8j0srcVCu2sU3QGfCL8juRI5lMNGtXVZpiDxdas6cAypVIr5R4Fhzeu/O8OAHB9jXjZX3g3eyfkSamv66Gg8DISKNu2GyeKDDgEIxh7TGX+KME8of55ZnOulyqilH7KPT9PoOQGmKYyFFDWd5zS97Bnyv42CMbH0zmJASPke6Dj/qQZsOUTD+0yQv5jriVuAf/Qz2DDEC9HX1uODP3y7LmXbXUi1HXH0q/pf1EiqaFkYCUnNFAy+0/O6DxW+8ZK/f92JKEsNAaK/kxaR4Y5w== 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=Hoe8sGamNdrTHVOTWOtnEUu268YbmQzoeLNrHgJhv9Q=; b=L62Mob4Q45SKqaU6Ixm7iSagKcPrTOPEJPCBxjL2KYM8jY9UCxlvILn+GY4Nqu3EZx9H/7CA1u4malW4TRIrle30P3Kg6OcpU8+yDS72xrCXwao4yoiLyhMb5TY0DsVVVTfUlEnW28PVcF2459OiU7NdYMGJHjhp6rF9rP0ngGDYhiMPIhHS0LVu88pVI6XQt5BVoufphpWXi7b/sa8I7BxmeQXcEDUno9i6eS+SvhhztkFpZu7tSnxNuuTo15U0NC4nNIO9hMg/uKqxBzz99lF9ABwzy1O7xEzv8ptXTd5uCLg+A4eWQ7nBQ7wJulyxaCpqvofXa/X7mCQXgpTaJQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Hoe8sGamNdrTHVOTWOtnEUu268YbmQzoeLNrHgJhv9Q=; b=ZIkQ9/BTXrysUbAbShZZ4rZBuG7z0DEK/7lbmSnh6aZHEwyXzQMqCNIfe7DDla479YWCe/ISHIXfhv7gVO/VQ8XB3CBNY6lS5B/HCFlm1YobBpJqZi6+Bdea0UozOfOD//jKBACN31B5XS9ZrHdIeZspgdzz+4taFb8NlhV5wtw= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Mon, 5 Apr 2021 14:24:33 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:24:33 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 04/13] KVM: SVM: Add support for KVM_SEV_RECEIVE_START command Date: Mon, 5 Apr 2021 14:24:23 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0031.namprd05.prod.outlook.com (2603:10b6:803:40::44) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN4PR0501CA0031.namprd05.prod.outlook.com (2603:10b6:803:40::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.9 via Frontend Transport; Mon, 5 Apr 2021 14:24:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f58ff675-4bda-4623-3c4d-08d8f83e8835 X-MS-TrafficTypeDiagnostic: SN6PR12MB2767: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2331; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VHZ3n+M2rXLiya++hAZrh1p5Dxb/h2SVbu1HFESX90fzg+5qAlc7usPL+cZlClodiAauo7j3kwcQyIiszWzEW93Xc2Us0AYAwZTYr7+N5Fq7OhSUlLfuy12dLLm1n2EVZpDkRoEBA7WIfA2o8CAP9RlgXfjTbMStG1aRUsgx0UWhWa1TG55SluEvYIOrlbxecV2BAARCuvRlJ3YFoH3U7XV8/hpISJB2qpiG3gXkunIDhxVSmnJFiXUt2l4UMRIkAMZEsLPwEc2vW4iILLmTtrtRqMasTg68kpnIIkJUPWT6FKnOoLmSt/+uY4r40PekgCa6WMMkeJD4Gw6BfthNomkJDc5p9vTQEzHyHmGoG5xSpJXtj2vX0DpeysW41VZcOlSu1XsgEG+fY7v+11yMjdm+I3BipaN6Zhe4iE8K8S47QbCgSAP28zfh4JHM4V9Y0r+MQHgDyWOzZcfYTvvv0sU6SuIhVCxRCzy6YR/CtnAVz5zDcjDZrFLEoFYvdDNJLBL4fVVFQjmHdIGZQT4aocNJMtg4LP4DBgJv+cInXd+hk5vBfNNDMm6TIQnr5IrUOEAuYEX03wWZbrfNcA138kpxmOViP4Sxc/1qp3wQqAD2hND21BTQFItaGvxUdlmdX93vTdcDz61lZFKt3cOLOEW4BczV7B19XjkhOOmEwvg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(366004)(39860400002)(376002)(396003)(136003)(66556008)(8936002)(66476007)(478600001)(36756003)(83380400001)(7696005)(66946007)(52116002)(5660300002)(186003)(2616005)(16526019)(26005)(86362001)(2906002)(38100700001)(6666004)(6916009)(7416002)(316002)(4326008)(956004)(8676002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?j5TYTDiXWOOJmrb7gLMfh0w68jLsgP?= =?utf-8?q?uX033f79EwlgX7x/fq7tuMCvRG4PKN+M4W9qMM8e5DUY/QHAIrHlLptXH8SV1CCBw?= =?utf-8?q?1FPtCc/LL5FmPi7//nC1l1Z0Y9ly74I0W4BvWUUsjJcF+REsdtAgMQzkOpekHsjnc?= =?utf-8?q?sOX2W7taaOVoFSUj5+4++dHoS1gw8tYz/1s2GNhDECfNet8GEJNr9REQcjKRr+XBj?= =?utf-8?q?UWogJQdBb4WkIy8UNLUi+Jmu/2FnD52t60eYWS2d2FMfACk4xCjfvxEtA67zMeNrW?= =?utf-8?q?qt7/G7e2HS7Sed0y1+CESGdk5B0mdDAuFInsMqHwFHeRc6NsHjnhDT49EzM1d38Lc?= =?utf-8?q?ORvGPBlE2927ecNs3FLg4r7HJxCZg4655rf55On0Ux4IcHuaXxXkk7ITwbbjQbU9j?= =?utf-8?q?eIF+BW+Nzck8g5egZK6UsArh/dpnV/RSCKgaWc6hK1kAxE1pah0w7Gk0aK7jkyuFQ?= =?utf-8?q?Vn2cb4ZCj0u88e0292rxvkVsIIH53a0S/3nVtgMTXeHXpryP3gAbVA8YJ7nRfBsGU?= =?utf-8?q?6nYVGxJPuVeD35av7zqTQ7vj/0gGMbvPifHHLi4z12rOxM3FTYZ+9JXxncdOOdUpj?= =?utf-8?q?kj2/DfLk5HZoONj+K/56uZp3LwnlMgl3OOmjxg6BHZMSUIDv3Z+i3pnCAcu3U9Keo?= =?utf-8?q?qd+p600npQzNMqzCdOFZtIRD+w0YkMJEuJ74JiDbi7AIV7WkPBl26agEZ7vhPERm1?= =?utf-8?q?wUtBbOrrd0Y2grw0muPLTZAZ7MVty1wB7PmvQkaXq5coG9WUdI8StNmOvViNluVaf?= =?utf-8?q?u3NGfpIj8gDUjBauEevYDqACuOjSAzUEcZ2vV5XRKSGqeYU0msodhzLunbURe8QBT?= =?utf-8?q?pGuzQi5YJ+ZgJ2dVh3MicF/WTfO8atBsKix4C0hERJm5dgNdsLDN0TVrIHTxX22iR?= =?utf-8?q?V5IZp7/G7awT7Oz03pmO8DwJEfYo3/X5ZdJTEEBjfMbNYZAzz8IfFQ+yPxSCA6AfH?= =?utf-8?q?aGc+K//sq8XnZVw4QIy+5txm8HPObyCJtz1wFpliti2eX1dldteAyJ/7NVovdmo24?= =?utf-8?q?NXO+nGS+statbBgKR+M1MA5jAD5MVbGvBfIXMvpiOjpzb6l3JlWeHAP/VO74Kh9H/?= =?utf-8?q?N5Xuc4CsMsYcknDxSM41/dIK90y/SPK9fhNYzdZ0mezhn5teanD4RnhJhkc7QBY8D?= =?utf-8?q?oQ/uywC9CGC3ME3VnuMGsSE+tjaciJw310Ixq4+/zNyU3QnTDTQDJEdG6mWHj9Jc/?= =?utf-8?q?NDFL166SixtkbJ0rpTWtLmZzelmJzAHIQtYSby6wP7detMA9FGt9jPPApADhd3ADV?= =?utf-8?q?W9zpNmk9NZv93i?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f58ff675-4bda-4623-3c4d-08d8f83e8835 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:24:33.1595 (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: KRJsEb4W+qaI9wy41f/yONJaFhDw71/pKUcLieY8lZ14t0x/zEy/26msU0w/M4u9pUXjKSA2zEd6vfX5Ln9Lvg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2767 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used to create the encryption context for an incoming SEV guest. The encryption context can be later used by the hypervisor to import the incoming data into the SEV guest memory space. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 29 +++++++ arch/x86/kvm/svm/sev.c | 81 +++++++++++++++++++ include/uapi/linux/kvm.h | 9 +++ 3 files changed, 119 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index 26c4e6c83f62..c86c1ded8dd8 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -343,6 +343,35 @@ issued by the hypervisor to delete the encryption context. Returns: 0 on success, -negative on error +13. KVM_SEV_RECEIVE_START +------------------------ + +The KVM_SEV_RECEIVE_START command is used for creating the memory encryption +context for an incoming SEV guest. To create the encryption context, the user must +provide a guest policy, the platform public Diffie-Hellman (PDH) key and session +information. + +Parameters: struct kvm_sev_receive_start (in/out) + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_receive_start { + __u32 handle; /* if zero then firmware creates a new handle */ + __u32 policy; /* guest's policy */ + + __u64 pdh_uaddr; /* userspace address pointing to the PDH key */ + __u32 pdh_len; + + __u64 session_uaddr; /* userspace address which points to the guest session information */ + __u32 session_len; + }; + +On success, the 'handle' field contains a new handle and on error, a negative value. + +For more details, see SEV spec Section 6.12. + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 92325d9527ce..e530c2b34b5e 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1370,6 +1370,84 @@ static int sev_send_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_receive_start(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_receive_start *start; + struct kvm_sev_receive_start params; + int *error = &argp->error; + void *session_data; + void *pdh_data; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + /* Get parameter from the userspace */ + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_receive_start))) + return -EFAULT; + + /* some sanity checks */ + if (!params.pdh_uaddr || !params.pdh_len || + !params.session_uaddr || !params.session_len) + return -EINVAL; + + pdh_data = psp_copy_user_blob(params.pdh_uaddr, params.pdh_len); + if (IS_ERR(pdh_data)) + return PTR_ERR(pdh_data); + + session_data = psp_copy_user_blob(params.session_uaddr, + params.session_len); + if (IS_ERR(session_data)) { + ret = PTR_ERR(session_data); + goto e_free_pdh; + } + + ret = -ENOMEM; + start = kzalloc(sizeof(*start), GFP_KERNEL); + if (!start) + goto e_free_session; + + start->handle = params.handle; + start->policy = params.policy; + start->pdh_cert_address = __psp_pa(pdh_data); + start->pdh_cert_len = params.pdh_len; + start->session_address = __psp_pa(session_data); + start->session_len = params.session_len; + + /* create memory encryption context */ + ret = __sev_issue_cmd(argp->sev_fd, SEV_CMD_RECEIVE_START, start, + error); + if (ret) + goto e_free; + + /* Bind ASID to this guest */ + ret = sev_bind_asid(kvm, start->handle, error); + if (ret) + goto e_free; + + params.handle = start->handle; + if (copy_to_user((void __user *)(uintptr_t)argp->data, + ¶ms, sizeof(struct kvm_sev_receive_start))) { + ret = -EFAULT; + sev_unbind_asid(kvm, start->handle); + goto e_free; + } + + sev->handle = start->handle; + sev->fd = argp->sev_fd; + +e_free: + kfree(start); +e_free_session: + kfree(session_data); +e_free_pdh: + kfree(pdh_data); + + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1432,6 +1510,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_SEND_FINISH: r = sev_send_finish(kvm, &sev_cmd); break; + case KVM_SEV_RECEIVE_START: + r = sev_receive_start(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index d45af34c31be..29c25e641a0c 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1750,6 +1750,15 @@ struct kvm_sev_send_update_data { __u32 trans_len; }; +struct kvm_sev_receive_start { + __u32 handle; + __u32 policy; + __u64 pdh_uaddr; + __u32 pdh_len; + __u64 session_uaddr; + __u32 session_len; +}; + #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2) From patchwork Mon Apr 5 14:24:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6B7DC433B4 for ; Mon, 5 Apr 2021 14:25:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6876613B4 for ; Mon, 5 Apr 2021 14:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235994AbhDEOZP (ORCPT ); Mon, 5 Apr 2021 10:25:15 -0400 Received: from mail-dm6nam12on2057.outbound.protection.outlook.com ([40.107.243.57]:61793 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235915AbhDEOZP (ORCPT ); Mon, 5 Apr 2021 10:25:15 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UPilkxhFbaHYZTXuBBslVVYeDZRwgAYvhu7U73Q15y/iDhjhb55wOG4ZF0TGjb0dLcH0YdsljV8QF1Zu7RhwGbggR31X/nwJMVK+/dbcBQe3K3uzTXZF0pNLEG0SDVKYntbiMkwSPxdxVsERuKs1EyLKUhiBP3iBipr6eqTNOyZt6RhWIAVwJvKcBUvgeMJfyW+2SZAUdl4/FYPYF3Qvas6ZxNlqDnzLi228oUK0gRQCzdG7pCvplSgPi7Mbycun8slpo9JSfv4LUAA/KioucO6WcdZP8hjLJrSai5bwtu/GlWTuZZy8IIoOs9G/Kjc+B0hiEPECaicQ3ZR4j+WVcg== 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=OAR4TeFg0Nlu/8iO2BhJJHdmuEIITuF8bwy+t8L0m98=; b=O1AhOJNVH0tU9IJ7wJkU4xt93qmvPG2MY2EJLpU6Gt1ZlAI8qFOMUemuIfRbnUpmC2tWRvYexva72N6NtPJzcg9wNabUAyEEG4u7PcBXqeUiGJEYhb82u53XOmCZUHZz9mWX3dHCY5r6bpZuZJONYjkvENWXT5QEHmfKRZK62HRkKAAIFGCnOGmTx/Lj0SYxx35TaMGpJ93/ATWcQEet4+e2tfhe0pERbMt42BFPr2PVIsrwzqIdfDQOdRP6RmYUKKIdLkI/jPklsypwGGlW1U4XsIrcYBnsgzPCxpKAJfBLW0pCASUulekSLu+zl2ckaxwbU55iFopOHHclQ/FR7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OAR4TeFg0Nlu/8iO2BhJJHdmuEIITuF8bwy+t8L0m98=; b=L7h190nL0r9GLfe64WZ7Z/vKeju8cWpByXcJX7glHdM2I3euu/yknuvNAKj2TLXt75wVxujCUFtjfFNexw34WgEB+x5sy9Xa5TZm0ag7Bit7j1azB1Uz3zYH49wluuRVG6aIokegF3nWsmmSmUdZ05eCm/A16cT/M2HAmTx5PjQ= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Mon, 5 Apr 2021 14:25:05 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:25: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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 05/13] KVM: SVM: Add KVM_SEV_RECEIVE_UPDATE_DATA command Date: Mon, 5 Apr 2021 14:24:41 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0201CA0035.namprd02.prod.outlook.com (2603:10b6:803:2e::21) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN4PR0201CA0035.namprd02.prod.outlook.com (2603:10b6:803:2e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26 via Frontend Transport; Mon, 5 Apr 2021 14:25:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 149d5d3e-5733-44e2-5fc2-08d8f83e9b9e X-MS-TrafficTypeDiagnostic: SN6PR12MB2767: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YnSQZ337hI5r5Sx3s1OF9RURMiJjTks+mwL5JyE9a/htp2T4ikoxBKorrN5CdngWam1AHnp6vK9RLs7s1RbLHnmapDAoW1ncpaklYQlEUgabUjpCT+Lnjfm9wx7dfZBRvi70m+40OMg3ZDW3d0Xx1QHl1dYPG1IOweB69/gg5ONhd4ffPnpAgR+S3sGKF+UmZyWMIBTnpggO+2OZj6HS0KCnF1rvceKV0iT/Shh+fTjxRdJexRRw8t8MQ/z3jNywlycHgTAASxN0rZDwB2Qx9e9KcrSYsVU2036K0SnumzUcKJxqV6dnna44OCHSqrHN6s+XrKPS8ilSUjnaCfvbSylVVTP39lbWw227iknhKvZH9OWlbVh0uUXqc5FIl4IRMyzHG09/5WMEjKHRQvDNe5zbLgdQHqK9U1lkKL35a8UE9vcFH6JI7kBPdLQjeI1BRx7ZxUmJmxe55hDEXZ/HPWceFnZ0mu2DTqXWyxedknqw8A9GmDC+X6Q9xbXnEpsQkzqoVd91t1j1P5gG3dGaUV4wM0Z//Ab5S0ZpgLXS7DnKiD0gX1zTsBovN3TLb4rcGJ6MOm5sDGOQ6cE4IQr33m5NS5Gf2GnJrjTGtzxhcabKHe3X4R9pkgNlAkPxl2p7m055cKeKsXKwiX5kx36xoqODQQdvi0IKNz226KHoh8U= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(366004)(39860400002)(376002)(396003)(136003)(66556008)(8936002)(66476007)(478600001)(36756003)(83380400001)(7696005)(66946007)(52116002)(5660300002)(186003)(2616005)(16526019)(26005)(86362001)(2906002)(38100700001)(6666004)(6916009)(7416002)(316002)(4326008)(956004)(8676002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?U3sHDo7kOH6mvUuj4VBqlPxr0C+b3a?= =?utf-8?q?UeQzw5KRkt9K/tezZ7prXYQ51Fuslt+joDVwuCIIpsJgCIQrgk/se0l6aZmi3vwuG?= =?utf-8?q?A0Nwu9V/AScDqnv3kyci596YJxeM6KWUMcmlKj917RKojYF7ofN69Fcrv/YtwzHlY?= =?utf-8?q?Bwjswmz/3KkKA6ht/3wJaH9pKP1IiouLvRbOD5KY+C7Sy31Tr3e+aaEueoSh8oV/G?= =?utf-8?q?D3ybK4x1p/vmYUZabrMso9Qq6vcMKsTeV4crlD8GHuidyUM1omRb8eTLBSWTNTTli?= =?utf-8?q?d+8xWypHhEsMJJOyoFFLUbozwIJm6BKRruLrtEpwX7z1davnGtvOhgfQFQ+peKyjK?= =?utf-8?q?9dhbqqkV1JH6U98usypePkGoAh+wqt6JIUZVkkK1yKx+Jqjzr8rx9eCRsTNgErmHN?= =?utf-8?q?4SVhIxa29p6Qxt5cp4sz0ubEt9mwwpRJ0OTFVxWiE+Lu7qF/0JBGM70VUQvink3ef?= =?utf-8?q?Rug6uFRHLximvATss49nqlMZz1AbUqTsVzcoGIYfXvxc8kKj/r8xKRNyNXqg3ZRjW?= =?utf-8?q?S+3p8T7SF7sAnkwk1YRMDbh+hGF2/SygcrveiR8sPZ5T4i5SlXQjsu58PUQ/8Y2qe?= =?utf-8?q?EeXQA3XAlQA0AsLJ8fbKNDOSnPZE70D3mni31COCCeVE1hoyg4zwEtmov+V7fpDl4?= =?utf-8?q?YJlusVd2AhdplF1n03z9xESfTKCWUDJK/ZrpS6Gq71+xOKsuM+o6m9OPxFhMpO4nH?= =?utf-8?q?Uyrx3nT+o2uU8/8tgOQkLO78xqGRs9GpM4D1xtuXfCW5UGpSjTWsSbXnmRjQf8Nbz?= =?utf-8?q?PZm6NSxw+GrqlnUOC1uwh46vYkBvDZ4lSJPVpRdbr5JjT4eDJjCBAcIFr4UBuCORX?= =?utf-8?q?Ouq6YOJQHmp3YjqXCuJukZ6LmBkE3xuYkRepSn+jZ9dKewc0//em4TguRaKhCEkKg?= =?utf-8?q?CzI2N8U2zl268FWZP9apRRKxOafMsIWbQ2iekW0q2HBXyxAaipHmIh7OB+uBg4pSw?= =?utf-8?q?9tHchFClSjSAUDH1mPwCR3owv0zhNmu3XiBG7WWrUl7XLrnlLo/3TlVJfaveqtk9T?= =?utf-8?q?HuiaNUJVBo8pot6rk1eYj5EZbTvtVnheKA+pHrndBXztTcA6gks4cWlRX1tTxzojp?= =?utf-8?q?xaT2fOuRJQoUb2ckM+ZPOG9vW0zOOQ8nn8qIAS3HVbY2M9MR8HRzy66AqiwF1+07I?= =?utf-8?q?nbQ6/725K7yfFgR4/uU3xJr8M/GZ9T2T/VHvhnTbHLPCyZrTw1HnPf/zp0fPJZuns?= =?utf-8?q?X3lu2oFLF7rs8CL+fLxbuqP1n3YUv+DCd23xYwwo5XTzKGSaPxmhJejK5QNE8B18c?= =?utf-8?q?lAFVrWfFnzp41s?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 149d5d3e-5733-44e2-5fc2-08d8f83e9b9e X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:25:05.7342 (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: LYy1339lIa3tvK3z8g0hwIgeB7Ti5NMKapQEB+MVD0eAwDpmg8zX+Q4uWHD/mDcwjYeYLDrtH3DqSZoQS5e4ng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2767 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used for copying the incoming buffer into the SEV guest memory space. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 24 ++++++ arch/x86/kvm/svm/sev.c | 79 +++++++++++++++++++ include/uapi/linux/kvm.h | 9 +++ 3 files changed, 112 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index c86c1ded8dd8..c6ed5b26d841 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -372,6 +372,30 @@ On success, the 'handle' field contains a new handle and on error, a negative va For more details, see SEV spec Section 6.12. +14. KVM_SEV_RECEIVE_UPDATE_DATA +---------------------------- + +The KVM_SEV_RECEIVE_UPDATE_DATA command can be used by the hypervisor to copy +the incoming buffers into the guest memory region with encryption context +created during the KVM_SEV_RECEIVE_START. + +Parameters (in): struct kvm_sev_receive_update_data + +Returns: 0 on success, -negative on error + +:: + + struct kvm_sev_launch_receive_update_data { + __u64 hdr_uaddr; /* userspace address containing the packet header */ + __u32 hdr_len; + + __u64 guest_uaddr; /* the destination guest memory region */ + __u32 guest_len; + + __u64 trans_uaddr; /* the incoming buffer memory region */ + __u32 trans_len; + }; + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index e530c2b34b5e..2c95657cc9bf 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1448,6 +1448,82 @@ static int sev_receive_start(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_receive_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct kvm_sev_receive_update_data params; + struct sev_data_receive_update_data *data; + void *hdr = NULL, *trans = NULL; + struct page **guest_page; + unsigned long n; + int ret, offset; + + if (!sev_guest(kvm)) + return -EINVAL; + + if (copy_from_user(¶ms, (void __user *)(uintptr_t)argp->data, + sizeof(struct kvm_sev_receive_update_data))) + return -EFAULT; + + if (!params.hdr_uaddr || !params.hdr_len || + !params.guest_uaddr || !params.guest_len || + !params.trans_uaddr || !params.trans_len) + return -EINVAL; + + /* Check if we are crossing the page boundary */ + offset = params.guest_uaddr & (PAGE_SIZE - 1); + if ((params.guest_len + offset > PAGE_SIZE)) + return -EINVAL; + + hdr = psp_copy_user_blob(params.hdr_uaddr, params.hdr_len); + if (IS_ERR(hdr)) + return PTR_ERR(hdr); + + trans = psp_copy_user_blob(params.trans_uaddr, params.trans_len); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + goto e_free_hdr; + } + + ret = -ENOMEM; + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + goto e_free_trans; + + data->hdr_address = __psp_pa(hdr); + data->hdr_len = params.hdr_len; + data->trans_address = __psp_pa(trans); + data->trans_len = params.trans_len; + + /* Pin guest memory */ + ret = -EFAULT; + guest_page = sev_pin_memory(kvm, params.guest_uaddr & PAGE_MASK, + PAGE_SIZE, &n, 0); + if (!guest_page) + goto e_free; + + /* The RECEIVE_UPDATE_DATA command requires C-bit to be always set. */ + data->guest_address = (page_to_pfn(guest_page[0]) << PAGE_SHIFT) + + offset; + data->guest_address |= sev_me_mask; + data->guest_len = params.guest_len; + data->handle = sev->handle; + + ret = sev_issue_cmd(kvm, SEV_CMD_RECEIVE_UPDATE_DATA, data, + &argp->error); + + sev_unpin_memory(kvm, guest_page, n); + +e_free: + kfree(data); +e_free_trans: + kfree(trans); +e_free_hdr: + kfree(hdr); + + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1513,6 +1589,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_RECEIVE_START: r = sev_receive_start(kvm, &sev_cmd); break; + case KVM_SEV_RECEIVE_UPDATE_DATA: + r = sev_receive_update_data(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 29c25e641a0c..3a656d43fc6c 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1759,6 +1759,15 @@ struct kvm_sev_receive_start { __u32 session_len; }; +struct kvm_sev_receive_update_data { + __u64 hdr_uaddr; + __u32 hdr_len; + __u64 guest_uaddr; + __u32 guest_len; + __u64 trans_uaddr; + __u32 trans_len; +}; + #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2) From patchwork Mon Apr 5 14:25:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F71EC433B4 for ; Mon, 5 Apr 2021 14:25:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3E93613B2 for ; Mon, 5 Apr 2021 14:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241332AbhDEOZo (ORCPT ); Mon, 5 Apr 2021 10:25:44 -0400 Received: from mail-co1nam11on2064.outbound.protection.outlook.com ([40.107.220.64]:22862 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235915AbhDEOZo (ORCPT ); Mon, 5 Apr 2021 10:25:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UExTH/3s/niz6XMjSjTMX4DryhPynwNnHFBFhEoHYBg6C1ekfwg6o8KH0EUDOSX+gVDaUDtJtSKOeoHIxRi06astl3GRyppKj1Zx++L4f2z84BOId7+ls4Z+VpXA2nyvFPGN79tzsuSs1FBqKgC5lrtVwyYUZNPCGrTd8w2QN/2pAI6nQoTwGmVSgsi8L0Vq9+1vbX78fyMYsQB4ncnWfEt1cdbqGhxNcvHQxcZRpbNDtSrKsEElLOCmSiVzKkPovq9Ol5m5euzIAejEWfnHaMj1CKpv/hDk2FaaptvGNTqHdkDKq5ZNX2kjTftU7Vq7xmnuvAn++GmQDbAumU0oZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ecWJetWk79BG8nSoPDpZq7XRRwLaEAjNQ7SI2nOsNIA=; b=bhEecpHXtyKeRxPY5Mh4zNfywFKMFDwrn+er2OaDHlZGbjDWH+D8UcYNRyW7GUB80x/ajp2m9PeyIAFv3SCiAU6EVqZQDx3jmmUHZb700tJEmY4fb08EwCsklc379b1X5dss3/UV2O3NvUjz3TwcTNt0TqbJTOwPhJH2tXAFovSguLxi1h3H0xpEYmHuTuhwfICIR68Q9F2yeDFFzsw5P7txfc3I5Z8mmvI1J8/956bSD8tprHUFQyiwEM3QM6Fn40tZlmnddCt3VUObhFLsdii9fTxJifMUzodCBduup69jCvSRrKX1Q4oCobIKJxRcFzDwvln8oM9hafduvrLsjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ecWJetWk79BG8nSoPDpZq7XRRwLaEAjNQ7SI2nOsNIA=; b=vNL3nhk4ZWsedP2xAQYUwV3BC8CT3QQg+xjrNl/iloqqsPhvX/LpUR+qzmNeVv2uL4ZjNlF34p6dbj54EG1IVsMmDLA/ed6j5bjzWzqY4CZFoIGxJUaFytdc/+aIe+ySOCTShWXximbBJGFlI93vXQTo0cbZ2CCir7K2Q5Ub+38= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Mon, 5 Apr 2021 14:25:35 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:25:35 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 06/13] KVM: SVM: Add KVM_SEV_RECEIVE_FINISH command Date: Mon, 5 Apr 2021 14:25:24 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0102.namprd04.prod.outlook.com (2603:10b6:806:122::17) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN7PR04CA0102.namprd04.prod.outlook.com (2603:10b6:806:122::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27 via Frontend Transport; Mon, 5 Apr 2021 14:25:34 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 42f4af13-7ad8-4951-3667-08d8f83ead2f X-MS-TrafficTypeDiagnostic: SN6PR12MB2767: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PoBpvwgLo7zrEE3onrDzfEH5lgjdq9vu1yyp1PHqahatwYcHJHGlP+ET+eSeiRDdq5v1nQyXVult22QghzBeiH+Rlk+iYLCQBR4oHbgdiBk/fOI8hOeVD+2a2JtvRF2xoqPq3et0f65ujz4gKKo89BcPaVEWKlYkcf+8k+tFPGBZVHjpf815NWYxORSzraCk5UdOeYZ+nH7jrta/eNo6VPwR+WlVwwaN2pIAQAMG6U/j3f6BqiHeeURAE0x92JwbLHq/osEfJ3lG1MeDrVIK3kIy+mww1f/tvfcWeV+xN/u7AkatMZmF9wCINaAQKN4UIZnAQvOgHJv/H1yqEXZyKy7CHOyGbD14qCowtAHsL9BaIEyXA2OO+X5PmDi0kevoG7ZMcKVaqrcNijNi7kYP6EFIigxP7+yykIajXokcguGqchUD8SygkjD506SvtJWsiIk5BYlwkAPVYIC/Q5L/fB/7XZWxYULpGdK2gD0NXon7Cb/vvCSIml61QP60+n7SLpOFYjKMhtNp+5ynJRe72youfwwXpnhuwTD1Z36GuAk1XyEGuBRUcoXO1cpnfLjG4tneUptkwfwghG9PyARxu3W0meTUOk3UCycq1Op8G76wfuOB0F+t2cN6kckDKn5vaWcb6WercVfIHPeDX6x+PA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(366004)(39860400002)(376002)(396003)(136003)(66556008)(8936002)(66476007)(478600001)(36756003)(83380400001)(7696005)(66946007)(52116002)(5660300002)(186003)(2616005)(16526019)(26005)(86362001)(2906002)(38100700001)(6666004)(6916009)(7416002)(316002)(4326008)(956004)(8676002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?rAGBC28a2rfT4XmeDnkHHENttVwA5F?= =?utf-8?q?W+pNpVcNP8dkhUjqR33hsrThVCF0bq80TF3U+10OTpgu3TI3ndLWX8q7qIsgLQhe5?= =?utf-8?q?ZEB6hunwwQ9+RbUCwTk4BranUE0BQRPSt6WS+8oi+X0GCBl/mVQMYEDg5jr7DlnzC?= =?utf-8?q?0iX3uCqlN/RCiBkNQWIlUv2REn8VM5dGdWY16MICx5ViFvFSF2h7rX+/Bfco9p0Yy?= =?utf-8?q?/WQRcCJwWqpBJwsAa5ZakwmkmQA5oetyqqwhFekW3WQJDVCory8y/OdFl7r75GRSL?= =?utf-8?q?RIVKm88G/g2wq84aaDcSTUltcsjapj8GSsDXC7MXAfUn7DWajpy3Q7Me1z+4k1NU3?= =?utf-8?q?k1KaM6XIPYkd86IcKFzmVQcjgp59BLhuq/qWMbB8T/EPkJ8w7Hz7XS0qBh/PNd3ch?= =?utf-8?q?J1TBCKJMZPOUzwejDATLKwXNJIf4mHLuVRl7Ujj+ULekiZqYtwPcLdx8LFhuh5VVM?= =?utf-8?q?GiB61/9vkvYcHbfvmdwoEFoIzQCUUB6oDFrdFcmZx1fNVLqu56LeazYBLa/v2/IB7?= =?utf-8?q?FHsujCUPK1p97JnhCoyuTz5kdQWbawTE/wp1JSP8hIIK6F5qlQZlaEjhPNrJX6QG4?= =?utf-8?q?yLKikOLFYWzLoIQQl3iJMxWfZjsmdaXyJOlOJ+55OGzJJv1mGGQDAe8ClLJT3UR6s?= =?utf-8?q?rZ5JHe/WIq9U7KeAxp+iPw5Tp3QSpDcaObVMD4jsimksSGqEG8+Il2KsIjUNH/X6V?= =?utf-8?q?99+EWfZYAaMjjR3t647r2byoGhUtXqW7xtO+HM0YG0YDTwlMjZNDDCvuhNpZp9zFs?= =?utf-8?q?eRTvADQwSCn107Bga5/BC4aqYJDMd9NvHBPGDmtb2iwdZ81UlI7am6EkLc10MkFab?= =?utf-8?q?iX3PHDAMQvzVmj2zvmcyWuWGmlrPy8ESloeAEiPVtS3EDmaf9irb2pW8iGRBY89sc?= =?utf-8?q?CJA4d1gr6iv0QAvSpmzuOORmY+Qj3XJkRwUdxDxIpxP4+69UThAdXNkeW0naM/6qM?= =?utf-8?q?+4KqbZIxTNqzUN8lvsPJRNmgjGVRJyC3Wmf8kAfkSEcHo3aZ6e6GbMHX0tynOB+eC?= =?utf-8?q?PuaZixYCZNLciENNWV/kY6xuuAbktkdXive1tAxfvzfngkf83Fl0YWafRnV1jCamd?= =?utf-8?q?O0motSO6eIYWY13dHAHOjpcGjDDsgxR83C6vCAToFzq9fKRCo8JpldM2Mp3tiFIHI?= =?utf-8?q?HRPduBrJUDMPftfEE1zUqcluIpFXcGU/ktpecIsOsWgalZmDgVmHPUFg0pqiVgbFi?= =?utf-8?q?5SGOwNwE0WtFlZqyZynDOIRL/+m2Y3utBC9K0U7U7ak35x8baNfrJKOeNTyUcaPW3?= =?utf-8?q?inZ77Ruqikchgp?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42f4af13-7ad8-4951-3667-08d8f83ead2f X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:25:35.1557 (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: ohkNyEFDpa2cb9TukEnUKGAD/9N2311YO3htH8d9lnJlx/IqCybK/d9x1khXPwldmG/mMePN5R2VoNzETm6Zzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2767 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command finalize the guest receiving process and make the SEV guest ready for the execution. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 8 +++++++ arch/x86/kvm/svm/sev.c | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index c6ed5b26d841..0466c0febff9 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -396,6 +396,14 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +15. KVM_SEV_RECEIVE_FINISH +------------------------ + +After completion of the migration flow, the KVM_SEV_RECEIVE_FINISH command can be +issued by the hypervisor to make the guest ready for execution. + +Returns: 0 on success, -negative on error + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 2c95657cc9bf..c9795a22e502 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1524,6 +1524,26 @@ static int sev_receive_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_receive_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_receive_finish *data; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_RECEIVE_FINISH, data, &argp->error); + + kfree(data); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1592,6 +1612,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_RECEIVE_UPDATE_DATA: r = sev_receive_update_data(kvm, &sev_cmd); break; + case KVM_SEV_RECEIVE_FINISH: + r = sev_receive_finish(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out; From patchwork Mon Apr 5 14:26:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A504BC433B4 for ; Mon, 5 Apr 2021 14:26:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77D04613B4 for ; Mon, 5 Apr 2021 14:26:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241351AbhDEO0Z (ORCPT ); Mon, 5 Apr 2021 10:26:25 -0400 Received: from mail-dm6nam11on2058.outbound.protection.outlook.com ([40.107.223.58]:19712 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235915AbhDEO0X (ORCPT ); Mon, 5 Apr 2021 10:26:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HWDA/4MXP9a68MmTdcqqYfBYvunPRaNOYEOelY7vqXtvrrxWyCqK549JepO5NhkSoNGcxw2kpr7Gbzx/mvJg0bMa+5tDCchusRy1anVo8j04fmgzBt3S8UkA0qZ8fV+SS7szf5Gsh1NcYsWqfQhMFe3yJsu7pE+5rXNBFCfmGYaKa3C3WYnyx6vYxwTknbYBdk6HjJ4xvNra85QUALJ091YW/E+H/iNELrvkGOaG21mpW1tNlj9N5In0Fvq+OS0JhKReCFDVNgPKytkTDcwVV0DTBYP5NFxvkq9LHkdlCjBBkg7TUIZP4EQv1dteJQG1sF0vdpZlayp+Cd5c2F/XYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CLNAo19buTg3Yb1D6/ZVJBYv5MP2n7HijI3gYDV3fvM=; b=Ae6H7X5zpvsR96eDg77YPQ9iIJMyVPpUH7XsUUzl+vBPsugMG1jn1hbhUAhBr83a/a7gQyn4YZ0Si8bodLeMvDTCqURk+GRHNm65k4ntVqnfZVaVhwg2BZfD54XYSAL+is1qT+pHM55eJNE46zwRSiY1RRbAS/8HKcKIb386k1npgzJrKAE52lsy0gmimjMcNZaBIxlCWhW2EWxibkK7DcUG15YoS6t5D5ulxImzrIUbubGRVHkEtxhJKdZ2oa5M1yvgYvjWyeENkUZTOzvmy6U4FM+qP2rWKTHn/lFczpnHMBUs0R4vP9Tg56dSQyhnVicnGVHcsP2OPdGqRIYgJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CLNAo19buTg3Yb1D6/ZVJBYv5MP2n7HijI3gYDV3fvM=; b=2sZwhCEN+7ukIDbpEb/+rokq+R/QUHXDcK/ovRoAIyTAvLF8t7tnDRhwEW0lCbbgpwZ17kDU6z1Ylo+LWa3jSk4dt10TwYZpDyIsoOe+iJCdGqxffzgbF+EX0IUQgp2JuOOpJhDdkdN4Gr7CrY10EGUs9vW/hQ0dNyoAFRkJyhY= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN1PR12MB2416.namprd12.prod.outlook.com (2603:10b6:802:2f::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26; Mon, 5 Apr 2021 14:26:14 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:26: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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 07/13] KVM: x86: Add AMD SEV specific Hypercall3 Date: Mon, 5 Apr 2021 14:26:04 +0000 Message-Id: <999bdd6f4e9e2d7f4bdc20cea9459182327f505b.1617302792.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR12CA0061.namprd12.prod.outlook.com (2603:10b6:802:20::32) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN1PR12CA0061.namprd12.prod.outlook.com (2603:10b6:802:20::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26 via Frontend Transport; Mon, 5 Apr 2021 14:26:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cddd17eb-b637-4bca-1501-08d8f83ec49a X-MS-TrafficTypeDiagnostic: SN1PR12MB2416: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZQz6VECSIl5HrWr4N3afKbQQ8nI7qaPmiJpMPcRgkyqThABdr5PXgikAafNQMc/mIxKz78wwZwbvcBdsfQlfMcmJBAzOpPZpf0skapCy3wvum4UXtLajxa5w58XQvRTN9QBCHE1krC4/VsGJWcET+5EbtoUaoRfuKRZxn1dShpvS54eEyY7CednUGY7l3jn+PhjEv2CtOCtZMuAuVuUksSOqh1b2yIBJrGaP7G3+5pL2uVDFFZ6Os55ODezmW0XrxfZ3aVmuZ7JKouC0VxGvUhrV85Xfmwp3lP8Yg08Awo8nblvQy0Qy5QRyuXHf5Kyi27Fum4x345Q/DRiiQbCn6E4JGf7SFVUBbppH7EHFbB/M9MHsGTTpdifBqRmFFB0liokgVDVz+Plemij3VSZbMyFDcyJso+H8HxHEXfF4Qb+S6i4sbtf5nf49mY5Mfg/oe05BMn4yV/+cwxFFgysLmGKvk0ytUIrLlgHukDJwOa1KarJ5QPeygT6N+lUgJbzG8FPUebK0OavW3zvU3xCXZoAmSFZ5QV/ojoaeGXkqYX2NwAwR26TL86ZVFG8HMgV5qRd6tBSNYzaSs8mTWNQ/mdHAh/9vWLkEUOLhf8J+Lb3Zn2rHGsELCFzU2WV0beITO6zhyydMJTWw2Zy5GM2QoDtHdmfS34uDBNKFv60BUt0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(376002)(346002)(366004)(136003)(7416002)(16526019)(186003)(52116002)(36756003)(26005)(6916009)(7696005)(316002)(5660300002)(2906002)(66946007)(38100700001)(86362001)(478600001)(8676002)(8936002)(4326008)(6666004)(2616005)(956004)(66476007)(66556008)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?VCNvmU7wvgZ5Kfgx1GOrxgElxGU+xK?= =?utf-8?q?uOL4fP3Q/0yxTmwcUavBKL6XBk54p5a6BnaEs74/Jdg29UXbX13wZ6B1SQyDE2zOC?= =?utf-8?q?7wI9raZ7pMBPsXyi+v6dj0VHmfHnQmquNKH/sLp8nbLD346rPkMkHBmDUuK2iEHI8?= =?utf-8?q?Y3vwiWzm7RreZvBk/SsbKCZ+IKkmdy6ksAfsJVZCXh/a0qRvAcex7GB6wR0f4cQOJ?= =?utf-8?q?nbmDUpjjpnrRB/0BI/iUjKxQ3EOh7ux99qF9I23XjdQaAA2hx2UHaXIr4h/PUw3QM?= =?utf-8?q?OJY6YYeUhhwcEJ5s+YLnxztJ+hvcsfs6HWTIE6m8CLR448y3DAtfDcPR03gwyp/5A?= =?utf-8?q?lf6rwdgHXB5GjDg/ZqrCozpjCaMAYEp7sTrbQ2Wx1whnFEv9P9qJbYVvgzVajvett?= =?utf-8?q?jlzjCQgAuxfuaRrYPp9toK5UMRKBLl3oBWnP96xQ5YnsUYVSZ16Zj63X8lzi4oDns?= =?utf-8?q?2QF0iifxsnwAdX+93XRXBkPyL3MPwS2+E8gUlug6VkG/nWArjL67Rbp6rrWYw/vqb?= =?utf-8?q?EaTkB3+BCIwJae5LjHM3Xn5TXxupZzNabKeKlYpQmMBYkaDZnrWjYhr1FAl3GQcpQ?= =?utf-8?q?WNFZzOT629p61ZA+Rl1MBNJfN0QNptF64kCH91PjbBLyYZ2XDXgBWwE7AJHB0ZWdz?= =?utf-8?q?vRtvX4NjXiGoF+w0bjtk8D1yuzphn+6oy5cX4wY6Cc7d3xgqA59MxOHq0co1Oi6w3?= =?utf-8?q?raLicI51eju5U2C40nlVihsR3YMSX1tv9iMSwylE40j2GOtZMRqTxCZww/c51mIzf?= =?utf-8?q?TM4uygP3+Ptv2rHuQFT5fsw4MDdkiwNslxhvuZ9rFzzr8yJSRn7j5keYx0kEClqkU?= =?utf-8?q?Sr9/n/R7FBZigo+BmA05SRRQh/izYMbqKrxYowqW8eSvcuMf5/rx2o4yL7CKfTf+n?= =?utf-8?q?9VN/0r4QN1Hf9iPBaDVkX4YuGml65LaOtf3xa6nJ/GrhEWCFYLsubye7m7zHXr7IO?= =?utf-8?q?1TwbvgeyiGmBROM55IP0ndvCek4EXeAM44XPQYrwOLhJPlnvSsWCqbOVV1kFJCFsg?= =?utf-8?q?njrtGPrh2khv2AwwWfj2qWG1WrcaPfsyJl937qB3AK7I5F1pDUghLxxDnnA5++ne0?= =?utf-8?q?JkEDlVkY2rTrCMmGbDxllige+0P5YxxKHuEQaZILADVlNNRm3F2Q8lnbmagQh3LJI?= =?utf-8?q?WYgGIs6UGt3HPEoGza3Ed7HLzhh3ag92ZMmbeK3XADNtkle3KpIFqS0ie1H5Cf+wI?= =?utf-8?q?WmftdsWGx9iIBf6JSgMhaA8qLyeA23dhUFsjYN16dBeRymO8biltFTrAD2vUeRgCN?= =?utf-8?q?YtODleXHFcKNfS?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cddd17eb-b637-4bca-1501-08d8f83ec49a X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:26:14.4677 (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: 4fEdUADdQbOQUm/io9MUgtqbXnoUjL4MpEC6BFoOURSgu1B7Nr3KIHXRMq1ZMEmC6s0429Wr3dWiljWI5LC0Dg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2416 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh KVM hypercall framework relies on alternative framework to patch the VMCALL -> VMMCALL on AMD platform. If a hypercall is made before apply_alternative() is called then it defaults to VMCALL. The approach works fine on non SEV guest. A VMCALL would causes #UD, and hypervisor will be able to decode the instruction and do the right things. But when SEV is active, guest memory is encrypted with guest key and hypervisor will not be able to decode the instruction bytes. Add SEV specific hypercall3, it unconditionally uses VMMCALL. The hypercall will be used by the SEV guest to notify encrypted pages to the hypervisor. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- arch/x86/include/asm/kvm_para.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h index 338119852512..bc1b11d057fc 100644 --- a/arch/x86/include/asm/kvm_para.h +++ b/arch/x86/include/asm/kvm_para.h @@ -85,6 +85,18 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, return ret; } +static inline long kvm_sev_hypercall3(unsigned int nr, unsigned long p1, + unsigned long p2, unsigned long p3) +{ + long ret; + + asm volatile("vmmcall" + : "=a"(ret) + : "a"(nr), "b"(p1), "c"(p2), "d"(p3) + : "memory"); + return ret; +} + #ifdef CONFIG_KVM_GUEST bool kvm_para_available(void); unsigned int kvm_arch_para_features(void); From patchwork Mon Apr 5 14:28:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 214CCC433B4 for ; Mon, 5 Apr 2021 14:28:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF2576128D for ; Mon, 5 Apr 2021 14:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241337AbhDEO2x (ORCPT ); Mon, 5 Apr 2021 10:28:53 -0400 Received: from mail-mw2nam08on2086.outbound.protection.outlook.com ([40.107.101.86]:12288 "EHLO NAM04-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235915AbhDEO2v (ORCPT ); Mon, 5 Apr 2021 10:28:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Se7f0NRbgrxG4kYIUxyiryKgf+6mFV4YuOREuG/GFDD0/KHPJecehIT1lGQOn0bjWBp455eID7oFe4D41Cdgs74ZTWAwmRdmC1NQNmSVqv83KSsKy5QooTVN6e980ey5Mmn/cbICnpadG8pfy/Ln34ycYGe+7yRU+uIRmIowAYATttbuGlIPFSLk9gyiwZ/xADEpXNoeXd6y0GpxqssWRHTNkjq80fsBaFK6M/LMAuMctU+Xz4nLgEJCXmAW5gjDE+mrBbnWM6/MEXxQeVyu9AZ9IJa52enRBIUeQt8m42K12lIVq8/2mSYspbAfkT88+YC1p0xN3GiJam+AkccHOA== 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=U3QtukQKZIJ+olgbztN942htCrg0VvOeCKPt9wchrDY=; b=APiNF2TQ8HwcfGjvjQQO5M4Rj4lNqLcJIqpqY0xD8POEZMu98FCQXdabebiEu3Fm7gWQ+llczQtHgAIyOCtAmiPb2UxMT4yR73qDzM4B8+qqFrlwcyZEZ8fl+Nt4hSJn0aVHthraTOrC/No+EaTL2YxkYMI+zhi/v4sviUNbGcNVLdcsY5vRcSpu9p8joL3kvrDhIuTl11X1GZxDgkAkK+FVGre5rDVf4I3B9dXLajnronjyb6opyVCXdcRw0aEtDgYRtJ4RdeYdkNQ7ysUWi0SbdVZZKArKQhGxmdf4Bi45027fX+69/jL1BMYzgCJrxD2W45L9IzuA8/9XZ6wx3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U3QtukQKZIJ+olgbztN942htCrg0VvOeCKPt9wchrDY=; b=WUf2J7khi8PTjgKj+GrluEEBtEOojTTakRmJBkDEiTeuqb+X+74XpKPPCjqA63RetlmBf26L8d+OlVwftABKnWX+e4rsshWwV1srSOIAuAPOdYqNr1TiudUpfvFSA3THVYNCpVJnoOUbobXPkS8jj3rAhElsSK8TLEDJ3UKlzUc= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4413.namprd12.prod.outlook.com (2603:10b6:806:9e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Mon, 5 Apr 2021 14:28:42 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:28:42 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com, will@kernel.org, maz@kernel.org, qperret@google.com Subject: [PATCH v11 08/13] KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall Date: Mon, 5 Apr 2021 14:28:32 +0000 Message-Id: <4da0d40c309a21ba3952d06f346b6411930729c9.1617302792.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0201CA0072.namprd02.prod.outlook.com (2603:10b6:803:20::34) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN4PR0201CA0072.namprd02.prod.outlook.com (2603:10b6:803:20::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 14:28:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d08e309b-5e11-4424-7dc4-08d8f83f1ce9 X-MS-TrafficTypeDiagnostic: SA0PR12MB4413: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2201; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QzqUIw4QWYumX+dsMCF75E49ceXAHUnQVCtEjEquL+ZDgxnQsARKy/kyW1aIO2bOfxTXuoABz+ZMr6lbcc3DvBpwjqVcjmTkIS8ncSRYMLGNuzyuvWc+f1p/48lJXzX4WACYK5WeIOvMldOlVOSC1oIH7msicnyMc7ibmB5MLWTFblHlHt+qpcMpqfKY85v+pLNq5a9xQnWzqDaOUZQOwmbrF45kjY/KuAgM+kwYMUL7w00oZURZ9ds2zEj/by9mjikwC1aHkOQ7HtgHDJooKbHji+qR/lvrxCBSIVuDz/qpG+z/q6IXq0FW+VZys0bnjDeYzGZZ4Vuv4S007HTmy6gsXND1hd31KWMhemvwb5jBH+rYK1PikjbSCOz7594kT9bWyiZkt/t3xSj8uOiQ5OzCA/Mn1jvNrcucpGaBqL7LoSJerNJc+6ppaaoa//4rX3r1V944EVMl1p4UW9jR+en/YJHneD+Kw93NQSEYf6Zqy3JFAzd62/J7HFbvcrhqS4sqTUGdsFCuHXlJos+oj6/l3o4c/Y5cZjXZhHJzSdbHeuHijNMl+qU7p+RcHo3NVbw5IbWKicbz8nH+9MGVQ4cnxh5gMtLrtKGIdo/WlrAo0NqbpkzJ8UAcjijtj2/dTfLVuPqgvSDGwTEKAVj5ZHNfaenwhiMYDqkA/T6R0AA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(39860400002)(366004)(346002)(396003)(38100700001)(7416002)(26005)(316002)(8936002)(83380400001)(16526019)(956004)(52116002)(7696005)(66946007)(6666004)(6486002)(36756003)(478600001)(8676002)(86362001)(66476007)(2616005)(2906002)(4326008)(6916009)(186003)(66556008)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?JZp5VDS3buPrkbHZ8AkJXM9iNTGG8/?= =?utf-8?q?ilofTH51bIriWwKiXshBCXYrhfZkKbMoywAWHuwHnOgrp78dbySUT3ZlCPrlzniiC?= =?utf-8?q?MgWWpYq6uPrC99Gl9dGWpcrvP6rvv5YMKR/yVvaWbskCwpVjyyo1SOrrUzVo3txR5?= =?utf-8?q?McymNdu9osIP6hlSWk5pVjgeW24T2GWxlcVK3EIHzAZzhKnMkUADwwrnpRVw4JRor?= =?utf-8?q?WhUY4q+Mkd5vpAqvCH+xdw7Ro7Dw3itSrZ8Ro70Olb5ctM4VdIlhXo2SEK4FpY6UH?= =?utf-8?q?tPJGVXYTdnv2zhmNZXF2tVrATQL7iGkWmQJTxt+bj7+81U23wrLnneB56x+5qjEtt?= =?utf-8?q?TKoiOGOjF0gdy+lif5PxzVf3EN9AHptUsLR8fkA4a6dLcVYgRPGJyL2rvSb6BdSm0?= =?utf-8?q?B9jpFRJEruX+zzriqTc3a01pwr90aO4M0rjoKYvFpsfLGS6AkDJPlZfaG44zb7F8J?= =?utf-8?q?4cok+ZKJnBcGofcruma+JHkRjIRYBPyUy5r6zeKf4uodEKxetqdx/vmH4VjnxEDAu?= =?utf-8?q?SoLANtKowexEfjYwD54l6hiQWLXCMRA8s3rdnzyji4bN6d1rklp/62J4TBEKh1B0E?= =?utf-8?q?MfkeMvXUfbiTP2CMZtOgh2leNxwiMa4WuVLiZcnjn2gxeX5syjWogvjlA/cRhHM/A?= =?utf-8?q?MHCeS5BBr7/cHwgm0Wpy/8liOHDBwdPk3XzWTo3ajAUrT3qph6DWMWvFsOpMVMVSe?= =?utf-8?q?ifjvA765+zcXu+voIvG1vWXGYuxS+1HfU4DvfQ9OtMGFDFyvGZv/ZseHG2WBNZZYm?= =?utf-8?q?0iz8JtE42Eo4JihIynNvpJu6bXYBjoi/FUCHNcFgfgWVEYiMEMwcYcIVhfGdQLbag?= =?utf-8?q?aM4P9zOVjxaU8vZsweofhj3K3jgI0kjrobsSWfdlbX9PNQ56zh6MpScZbn9wszvQb?= =?utf-8?q?GtvLc5BBf+YLR7em+nJiVWijUfLybddlYE9+7aaeVTU9xZF2o0VGYmHD6SyBwcg0K?= =?utf-8?q?xo4pffMK3dK1Hd1SJUY+G4EhiNxmqf1QXeHq591PYiKDlz/nuS9gNU7nPraG1aETb?= =?utf-8?q?aVQ7Z+HOXReFZC+ReR7+0MMA+N+IVMj1jgYWN2+RJ4YmV06vonDaQB2wOzeD6OXfy?= =?utf-8?q?GCZhhSXHT3Ku6u90yXQjafEBxk9gxWzw7y4QI1pQMFLkcLE1lJ5xe33hdjw0eUcU+?= =?utf-8?q?u6yGUiTb1oshImIcYVdb8qGpG+WkRmlRXR54i3NJjCHxSPDAIHUHHlzpveMiP+ozR?= =?utf-8?q?TzeniiTiQw3JGr9FcD8q4QsUJU7oPzUGgk9I6Ui1DkejsP4UcZh0Byctw9Fcvi4GR?= =?utf-8?q?aYiGroKJlCM8wq?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d08e309b-5e11-4424-7dc4-08d8f83f1ce9 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:28:42.6186 (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: p7fXAVPkJWAvt8gICbuh2l5n0DWFH7od+3qEmJIBkdBuNBwaj3uZ27aE8VsUTQ/U7wzc4/vTxGOIqzdEW1nngw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4413 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra This hypercall is used by the SEV guest to notify a change in the page encryption status to the hypervisor. The hypercall should be invoked only when the encryption attribute is changed from encrypted -> decrypted and vice versa. By default all guest pages are considered encrypted. The hypercall exits to userspace to manage the guest shared regions and integrate with the userspace VMM's migration code. The patch integrates and extends DMA_SHARE/UNSHARE hypercall to userspace exit functionality (arm64-specific) patch from Marc Zyngier, to avoid arch-specific stuff and have a common interface from the guest back to the VMM and sharing of the host handling of the hypercall to support use case for a guest to share memory with a host. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Reviewed-by: Steve Rutherford --- Documentation/virt/kvm/api.rst | 18 ++++++++ Documentation/virt/kvm/hypercalls.rst | 15 +++++++ arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/svm/sev.c | 61 +++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 2 + arch/x86/kvm/svm/svm.h | 2 + arch/x86/kvm/vmx/vmx.c | 1 + arch/x86/kvm/x86.c | 12 ++++++ include/uapi/linux/kvm.h | 8 ++++ include/uapi/linux/kvm_para.h | 1 + 10 files changed, 122 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 307f2fcf1b02..52bd7e475fd6 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -5475,6 +5475,24 @@ Valid values for 'type' are: Userspace is expected to place the hypercall result into the appropriate field before invoking KVM_RUN again. +:: + + /* KVM_EXIT_DMA_SHARE / KVM_EXIT_DMA_UNSHARE */ + struct { + __u64 addr; + __u64 len; + __u64 ret; + } dma_sharing; + +This defines a common interface from the guest back to the KVM to support +use case for a guest to share memory with a host. + +The addr and len fields define the starting address and length of the +shared memory region. + +Userspace is expected to place the hypercall result into the "ret" field +before invoking KVM_RUN again. + :: /* Fix the size of the union. */ diff --git a/Documentation/virt/kvm/hypercalls.rst b/Documentation/virt/kvm/hypercalls.rst index ed4fddd364ea..7aff0cebab7c 100644 --- a/Documentation/virt/kvm/hypercalls.rst +++ b/Documentation/virt/kvm/hypercalls.rst @@ -169,3 +169,18 @@ a0: destination APIC ID :Usage example: When sending a call-function IPI-many to vCPUs, yield if any of the IPI target vCPUs was preempted. + + +8. KVM_HC_PAGE_ENC_STATUS +------------------------- +:Architecture: x86 +:Status: active +:Purpose: Notify the encryption status changes in guest page table (SEV guest) + +a0: the guest physical address of the start page +a1: the number of pages +a2: encryption attribute + + Where: + * 1: Encryption attribute is set + * 0: Encryption attribute is cleared diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 3768819693e5..78284ebbbee7 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1352,6 +1352,8 @@ struct kvm_x86_ops { int (*complete_emulated_msr)(struct kvm_vcpu *vcpu, int err); void (*vcpu_deliver_sipi_vector)(struct kvm_vcpu *vcpu, u8 vector); + int (*page_enc_status_hc)(struct kvm_vcpu *vcpu, unsigned long gpa, + unsigned long sz, unsigned long mode); }; struct kvm_x86_nested_ops { diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index c9795a22e502..fb3a315e5827 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1544,6 +1544,67 @@ static int sev_receive_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_complete_userspace_page_enc_status_hc(struct kvm_vcpu *vcpu) +{ + vcpu->run->exit_reason = 0; + kvm_rax_write(vcpu, vcpu->run->dma_sharing.ret); + ++vcpu->stat.hypercalls; + return kvm_skip_emulated_instruction(vcpu); +} + +int svm_page_enc_status_hc(struct kvm_vcpu *vcpu, unsigned long gpa, + unsigned long npages, unsigned long enc) +{ + kvm_pfn_t pfn_start, pfn_end; + struct kvm *kvm = vcpu->kvm; + 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 shared pages list. + */ + return -EINVAL; + } + + if (is_error_noslot_pfn(pfn_end) && !is_noslot_pfn(pfn_end)) { + /* + * Allow guest MMIO range(s) to be added + * to the shared pages list. + */ + return -EINVAL; + } + + if (enc) + vcpu->run->exit_reason = KVM_EXIT_DMA_UNSHARE; + else + vcpu->run->exit_reason = KVM_EXIT_DMA_SHARE; + + vcpu->run->dma_sharing.addr = gfn_start; + vcpu->run->dma_sharing.len = npages * PAGE_SIZE; + vcpu->arch.complete_userspace_io = + sev_complete_userspace_page_enc_status_hc; + + return 0; +} + 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 58a45bb139f8..3cbf000beff1 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4620,6 +4620,8 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .complete_emulated_msr = svm_complete_emulated_msr, .vcpu_deliver_sipi_vector = svm_vcpu_deliver_sipi_vector, + + .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 39e071fdab0c..9cc16d2c0b8f 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -451,6 +451,8 @@ int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr, bool has_error_code, u32 error_code); int nested_svm_exit_special(struct vcpu_svm *svm); void sync_nested_vmcb_control(struct vcpu_svm *svm); +int svm_page_enc_status_hc(struct kvm_vcpu *vcpu, unsigned long gpa, + unsigned long npages, unsigned long enc); extern struct kvm_x86_nested_ops svm_nested_ops; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 32cf8287d4a7..2c98a5ed554b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7748,6 +7748,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .can_emulate_instruction = vmx_can_emulate_instruction, .apic_init_signal_blocked = vmx_apic_init_signal_blocked, .migrate_timers = vmx_migrate_timers, + .page_enc_status_hc = NULL, .msr_filter_changed = vmx_msr_filter_changed, .complete_emulated_msr = kvm_complete_insn_gp, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f7d12fca397b..ef5c77d59651 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8273,6 +8273,18 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) kvm_sched_yield(vcpu->kvm, a0); ret = 0; break; + case KVM_HC_PAGE_ENC_STATUS: { + int r; + + ret = -KVM_ENOSYS; + if (kvm_x86_ops.page_enc_status_hc) { + r = kvm_x86_ops.page_enc_status_hc(vcpu, a0, a1, a2); + if (r >= 0) + return r; + ret = r; + } + break; + } default: ret = -KVM_ENOSYS; break; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 3a656d43fc6c..4174925aa5fc 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -268,6 +268,8 @@ struct kvm_xen_exit { #define KVM_EXIT_AP_RESET_HOLD 32 #define KVM_EXIT_X86_BUS_LOCK 33 #define KVM_EXIT_XEN 34 +#define KVM_EXIT_DMA_SHARE 35 +#define KVM_EXIT_DMA_UNSHARE 36 /* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */ @@ -446,6 +448,12 @@ struct kvm_run { } msr; /* KVM_EXIT_XEN */ struct kvm_xen_exit xen; + /* KVM_EXIT_DMA_SHARE / KVM_EXIT_DMA_UNSHARE */ + struct { + __u64 addr; + __u64 len; + __u64 ret; + } dma_sharing; /* Fix the size of the union. */ char padding[256]; }; 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 Mon Apr 5 14:29:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50EBAC433ED for ; Mon, 5 Apr 2021 14:30:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14ED46139E for ; Mon, 5 Apr 2021 14:30:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241368AbhDEOaF (ORCPT ); Mon, 5 Apr 2021 10:30:05 -0400 Received: from mail-dm6nam12on2073.outbound.protection.outlook.com ([40.107.243.73]:16353 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235915AbhDEOaD (ORCPT ); Mon, 5 Apr 2021 10:30:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MYGXd7HE9j+Y2KvUwzY1/TNIgP8o6EVhvXrDcyhuAbOW2drp2t5Q+PPzMJ1isOI0D5GMPAqAvtFINr9DOilC8gsEUjYKQl48zrmjWnFz4UEVgIJd5lPxSM+wQTEITxhXAWJIxegLaOXQWsShrNrX99c6lBpCZ2t4m4WJe1qjgY6n3SrXqy0z0AMrZBCJ7sZmteRh0bcIO6UFH3Tj6wxBqnD7X/ff/r9OvMJps2W2CyndmSSCO8I7AwxgbkJf12OvFNgESYSTStLpfC0PEMvfglfPnvIewxokZsMe5arAo1C30CLPEbTf7LPS/C+29VVpCuRHP9LTB6rSvnrHfXp2Lg== 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=ptwi1W+4zT0Cz1ubGqqSi1V3I2VOGialOuW68ChkUDM=; b=YokomW78j8QgLrChXuHtr4efEP81USoEiSGxejK5X3r+/OhNYSphBsaS7jc88pzihAhl4IFVZipEG22p3utpZl4KtWGgNhUM7s1modobzOYYX/l5PMYRfdldmm9ma2yZYDfxN3ocbAj9/0a3shf1t311IIyBoknAnPMsxmmOSzvp5ZWNf/YHLE5xsj6ZLXc55n8JJ/z0XMS41d7RA/y3PN3moUfaO8M1EUvrEI8MpxohXg2VdJ5R82ksOIXP/DBcDEiylDU0aIsVsFUHI8dZ1UNRy7eMtNPAwrnlRjJw9lH80kWXeoPqIngmXTU4fWp5fmIVXBoE6hg4KPrIHOpcoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ptwi1W+4zT0Cz1ubGqqSi1V3I2VOGialOuW68ChkUDM=; b=shB5bzYI3B7OIUOYvaUgaNV1DH4tA7BtX5ucL93HB1omLTvIW5PdOJz/+XrcQw/YbaXhg795Eb7FS92beEfCUdJTnHgynwiUHdpQKL/jvyOBDsjXRiMmvr3mloQnISDon6BRPHFJFfHsS37HsTYJZbsc2jpn4o/uX40/87kOh/s= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4413.namprd12.prod.outlook.com (2603:10b6:806:9e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Mon, 5 Apr 2021 14:29:55 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:29:55 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 09/13] mm: x86: Invoke hypercall when page encryption status is changed Date: Mon, 5 Apr 2021 14:29:46 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR04CA0108.namprd04.prod.outlook.com (2603:10b6:805:f2::49) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN6PR04CA0108.namprd04.prod.outlook.com (2603:10b6:805:f2::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27 via Frontend Transport; Mon, 5 Apr 2021 14:29:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e15bc9e2-ef77-4775-8330-08d8f83f4884 X-MS-TrafficTypeDiagnostic: SA0PR12MB4413: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c612td/fEkLbpdN1+W4oDYTpd7tCS0KmK5b78sg9VWfi7ilEuRHN69Jmg16N3BFdHCAIzH4MTe2W8Mmnyecpoo2nemxxK3AOdUOk+Trs7z1dnmsOatchqD5iG5NPjZ4Hoxpgq+WRxrOjktezNvNnvs1MvGPCrSpgRaCxE8pZl8IxNvJNIRox5TNO1ekV5iRQ4p4gKOhugjfYcB0lYthfxNEmyDyh36gya6vH4KlGdYi4pAeiRmJ0eDtAcVozlqCQzpPETl+qqiIUwtVZGe8m8tyYf+AsAO3MI9G4rfoQsyNvlygRmprBoVJhCIO072K8BXfCq9hiv/OWGHNLiIEw7lsWfTQeEhuiIqrUPjrdtRJ4efhzGKdanXYXWSowQx8W1//GPZk0zr56L3EBM6A67fmm6MfsDPi8GiUl+VPErt8Hu4WzrA0jdroDhbSsLQOvBPr+g+jj4myJw1BpBTmtDWFFu6eYl7fAh47JWNhnFN+Rzr9vvcnVLaOiCMkJq9O65/m42zsA0ybRLxznuKs7Gnnj78RhHwy3MlRapiDWQimSQemgQhS01FxjgrosKpWIKOF0APKa2AuBgFOyXyPz4p0bF7tHB6OxCsxdW+GZapn1KF5VZ/qJnSdAnVGi8pHdZjDQ7BrNXiKCb4g/yHq1YBmfe4LiUO61ws+cqoVWfRE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(39860400002)(366004)(346002)(396003)(38100700001)(7416002)(26005)(316002)(8936002)(83380400001)(16526019)(956004)(52116002)(7696005)(66946007)(6666004)(6486002)(36756003)(478600001)(8676002)(86362001)(66476007)(2616005)(2906002)(4326008)(6916009)(186003)(66556008)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?EiVlPApL1XclI2uZoPYgob1ZMjf7AC?= =?utf-8?q?Bk7mEiwqBEuXMf09Y28GnkG9oMI/Fc7Jy/368KDWyFcSCi+jwsNBRrSGHj8pRustW?= =?utf-8?q?qHIw0SLb9rz1USocKb15Yj7zLGRZ6oA4ZJysjDotwDxyd30+RZBC0iJGdjKtLuwNf?= =?utf-8?q?vqKpPfkeeuzHIE09hAJ1RF20MiIUaJNuSf/VWYi6tv4gSZ7xWIcEVE26rtzKXNeNI?= =?utf-8?q?aVCrAhPO+VmLX+uVY1lLpIcknCqxpcm21Yw/5cjWiO+h9bhQcXzBs+AIFlF5THGJN?= =?utf-8?q?YbA0ZQRUs5G1MdY2RiM47SYjwjJ++HnC/zy9kQANd8+WiHETXQDgLu1moO3TgxQoC?= =?utf-8?q?3N2X68B9cWyDaQmCTKuHrZkIQll99fHJpQV2GSKg6/ECYiK9q5zK0U76eJN5U+AN7?= =?utf-8?q?27YMn014DteXt2olDuE0fk4XlZ/1IW9ju5haJA/apevzlRYd9Tm5mEScNvgR3yjCF?= =?utf-8?q?Y2USLoSMzXHW1/XlGnA5NVPGEgh1kXfItftQf4+PYpdnyvZQDFjMismmQagGFKgep?= =?utf-8?q?leygjxtm1G0qAO+1xJXqIFmZEC2M7ih+6pg+Ht0KtQlC41KaJloJ0SKKKI2nNIbm1?= =?utf-8?q?+go2j1xNla0ULLfxilUSl3g2vvZjmgMB3Z/KCvDooFhG6LP+c8zgpnlMEy8/VAT7V?= =?utf-8?q?BehhudHWnxeHzUhlbcY5tnxezESywgVkH4XKvoEr6ZSGFNX559kviPC91NgzCQBSq?= =?utf-8?q?Gly8kbBrpPDKH9lDPubEAF0u4ybQNMnm7WEYX3VqZM3DT0WXXDtrVPh/7ANlwCHZJ?= =?utf-8?q?FCDiP0rCmCa3nxaFRGfnt9ZlvLotGxnXkLNmxtl0ASpai9A807+1I1Z9jQx9mBzWI?= =?utf-8?q?42CZ2mfpYOxandf8AhkrM3wOlMl1s8If3hO+6BDWGPgyRlMVKj4a9BT7WrBOl/rtK?= =?utf-8?q?kEZ58FK4E+wMY38WS2qWTpY809G76P+/8OYjn+Kh2nuV1MD7oKTFHV51hq/gnXTps?= =?utf-8?q?EaKJ2bUdKHhpVxVhWE592D2igAVJUot0Y2wZBCYW2nhFLxh8hROj3GOQJYNe4vJHT?= =?utf-8?q?LOEiGae9osdBnMedsYD+bhQftxRHBOw+JVz/2BtB40xI/v79es78UmQQx/ANlEuCE?= =?utf-8?q?D4sHr87owFAitvaphkp3RTRJEeqXyuctjjJq3qXYdFQFzX4fsPQFrD0F6+tyD0rzv?= =?utf-8?q?SvLlFMHgWuQhDT2hJv/glqw5fHgF7fYzPo0+EQg5VldF9Q1/TTWVRgR7GBVR8y3+J?= =?utf-8?q?j+8EqMUejuCVDtR8lxIQJEkLNEcIqMT5XTBIKKGd8c3Z++0q/9WImcBeMyrzMS5In?= =?utf-8?q?SC0Ow72JHR7LtR?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e15bc9e2-ef77-4775-8330-08d8f83f4884 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:29:55.7446 (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: ql0WxH1XD7k3kEztQ9jJvT/7PqjL+BB34efSuh04EbxfxZbpRRmHQTfYBlnFu5aR36I2aesmqVFt/JRrvsjIoQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4413 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh Invoke a hypercall when a memory region is changed from encrypted -> decrypted and vice versa. Hypervisor needs to know the page encryption status during the guest migration. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- arch/x86/include/asm/paravirt.h | 10 +++++ arch/x86/include/asm/paravirt_types.h | 2 + arch/x86/kernel/paravirt.c | 1 + arch/x86/mm/mem_encrypt.c | 57 ++++++++++++++++++++++++++- arch/x86/mm/pat/set_memory.c | 7 ++++ 5 files changed, 76 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h index 4abf110e2243..efaa3e628967 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -84,6 +84,12 @@ static inline void paravirt_arch_exit_mmap(struct mm_struct *mm) PVOP_VCALL1(mmu.exit_mmap, mm); } +static inline void page_encryption_changed(unsigned long vaddr, int npages, + bool enc) +{ + PVOP_VCALL3(mmu.page_encryption_changed, vaddr, npages, enc); +} + #ifdef CONFIG_PARAVIRT_XXL static inline void load_sp0(unsigned long sp0) { @@ -799,6 +805,10 @@ static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm, static inline void paravirt_arch_exit_mmap(struct mm_struct *mm) { } + +static inline void page_encryption_changed(unsigned long vaddr, int npages, bool enc) +{ +} #endif #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_PARAVIRT_H */ diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h index de87087d3bde..69ef9c207b38 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -195,6 +195,8 @@ struct pv_mmu_ops { /* Hook for intercepting the destruction of an mm_struct. */ void (*exit_mmap)(struct mm_struct *mm); + void (*page_encryption_changed)(unsigned long vaddr, int npages, + bool enc); #ifdef CONFIG_PARAVIRT_XXL struct paravirt_callee_save read_cr2; diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index c60222ab8ab9..9f206e192f6b 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -335,6 +335,7 @@ struct paravirt_patch_template pv_ops = { (void (*)(struct mmu_gather *, void *))tlb_remove_page, .mmu.exit_mmap = paravirt_nop, + .mmu.page_encryption_changed = paravirt_nop, #ifdef CONFIG_PARAVIRT_XXL .mmu.read_cr2 = __PV_IS_CALLEE_SAVE(native_read_cr2), diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index ae78cef79980..fae9ccbd0da7 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,7 @@ #include #include #include +#include #include "mm_internal.h" @@ -229,6 +231,47 @@ void __init sev_setup_arch(void) swiotlb_adjust_size(size); } +static void set_memory_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc) +{ + unsigned long sz = npages << PAGE_SHIFT; + unsigned long vaddr_end, vaddr_next; + + vaddr_end = vaddr + sz; + + for (; vaddr < vaddr_end; vaddr = vaddr_next) { + int psize, pmask, level; + unsigned long pfn; + pte_t *kpte; + + kpte = lookup_address(vaddr, &level); + if (!kpte || pte_none(*kpte)) + return; + + switch (level) { + case PG_LEVEL_4K: + pfn = pte_pfn(*kpte); + break; + case PG_LEVEL_2M: + pfn = pmd_pfn(*(pmd_t *)kpte); + break; + case PG_LEVEL_1G: + pfn = pud_pfn(*(pud_t *)kpte); + break; + default: + return; + } + + psize = page_level_size(level); + pmask = page_level_mask(level); + + kvm_sev_hypercall3(KVM_HC_PAGE_ENC_STATUS, + pfn << PAGE_SHIFT, psize >> PAGE_SHIFT, enc); + + vaddr_next = (vaddr & pmask) + psize; + } +} + static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) { pgprot_t old_prot, new_prot; @@ -286,12 +329,13 @@ static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc) static int __init early_set_memory_enc_dec(unsigned long vaddr, unsigned long size, bool enc) { - unsigned long vaddr_end, vaddr_next; + unsigned long vaddr_end, vaddr_next, start; unsigned long psize, pmask; int split_page_size_mask; int level, ret; pte_t *kpte; + start = vaddr; vaddr_next = vaddr; vaddr_end = vaddr + size; @@ -346,6 +390,8 @@ static int __init early_set_memory_enc_dec(unsigned long vaddr, ret = 0; + set_memory_enc_dec_hypercall(start, PAGE_ALIGN(size) >> PAGE_SHIFT, + enc); out: __flush_tlb_all(); return ret; @@ -481,6 +527,15 @@ void __init mem_encrypt_init(void) if (sev_active() && !sev_es_active()) static_branch_enable(&sev_enable_key); +#ifdef CONFIG_PARAVIRT + /* + * With SEV, we need to make a hypercall when page encryption state is + * changed. + */ + if (sev_active()) + pv_ops.mmu.page_encryption_changed = set_memory_enc_dec_hypercall; +#endif + print_mem_encrypt_feature_info(); } diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 16f878c26667..3576b583ac65 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "../mm_internal.h" @@ -2012,6 +2013,12 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) */ cpa_flush(&cpa, 0); + /* Notify hypervisor that a given memory range is mapped encrypted + * or decrypted. The hypervisor will use this information during the + * VM migration. + */ + page_encryption_changed(addr, numpages, enc); + return ret; } From patchwork Mon Apr 5 14:30:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7382CC433B4 for ; Mon, 5 Apr 2021 14:30:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A056613B4 for ; Mon, 5 Apr 2021 14:30:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241384AbhDEOa0 (ORCPT ); Mon, 5 Apr 2021 10:30:26 -0400 Received: from mail-mw2nam10on2053.outbound.protection.outlook.com ([40.107.94.53]:18177 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235915AbhDEOa0 (ORCPT ); Mon, 5 Apr 2021 10:30:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BNQOtkm1cyMiUK+tTQjI1dUj0Zpkwba8zicAKIFh47yFPSU0bQJSsiRnaA5Jv9o5xIgC97i1PNjXxrXHdynssmQkH2WVqB4x0IuYrqBAJDgiJvSizIGM3mrYQWmfl2VqA0IpbKsxiJ3CwcTWvL+2QgpKnYQXhb/OfrEpz+4joL4PHmNYFXyBzTk3ofBzGei2AYRXM4absvE1zyGxtsSlrj7HXM+EjM5bjQC1EJe+KQzp3xkASmiTREFUWCGoZB9NFi0naf9igu1+bWNAicrGwqKi6sR5eQCtYyK9ez9ERR2P7ajLYGp7xxK3OyN0rB1se/o1If+RSpVvbxu+WkH5rg== 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=srKv4wJn6605FhurZXMhV1Mx3xPzBtYCQYZ8fqgXoMs=; b=I8tWoNE2Rz/CA/PPhT+90rJ26JrMqrQgEvPXbBDt8XQf1RJeCKqyjA1k7D3N5QDd6TR4L34Iir9/JBjiRNlhnLdoB/kYKnNu9C6OVykqhELGkqaMGeSEWjpPNpWo+GRWF9Z2C5lC9lQ5YKZC3l4i2d1SUkEM+sbAPlOJxAz5LYOu+Tp+itWct0Z23RHeME7FoE/ljbr+xsaEUg5NGvSErdlfycVmUMCg9t35ht6ScK6x1mP9KVjthtzBhMAYf1hV1oMj0lgBc6RBRWFwDbAFuxxXMdxxO7HihdIV9HgPX+46uu7xRW7gEJPJ0YHgm6dKsfRBtNHLsON2wOM6uvAVDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=srKv4wJn6605FhurZXMhV1Mx3xPzBtYCQYZ8fqgXoMs=; b=DXlQAv8AkBayNZ9Q7onHFZLjf2jjvEYoKy7+3zqxquAiKzpGirn9Wb+NDdecyLg9mH4KfGvLN/8tD9nkdwR1qQUhhZm9J4aKqyJPdtuBC6hzQTswPU13azsSg47bIb+NqI4mwlVdbxt5X8Vkt+c5mTRv3EXdeX0Kd9Q+co9UH7E= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4509.namprd12.prod.outlook.com (2603:10b6:806:9e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Mon, 5 Apr 2021 14:30:19 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:30:19 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 10/13] KVM: x86: Introduce new KVM_FEATURE_SEV_LIVE_MIGRATION feature & Custom MSR. Date: Mon, 5 Apr 2021 14:30:09 +0000 Message-Id: <69dd6d5c4f467e6c8a0f4f1065f7f2a3d25f37f8.1617302792.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0232.namprd04.prod.outlook.com (2603:10b6:806:127::27) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN7PR04CA0232.namprd04.prod.outlook.com (2603:10b6:806:127::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26 via Frontend Transport; Mon, 5 Apr 2021 14:30:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c3789e13-5de4-42df-d671-08d8f83f565a X-MS-TrafficTypeDiagnostic: SA0PR12MB4509: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eWyjm5DDLmptM6fkLBJlzYwOdlzGAHvcuobym3lwmg/zc58y3Mnv4BOyJiIWQB9KGtN5ouZ85Fs/g35771ysfXaGSIyP8+fwJ3hNpVPRuRF5c823LJXThLrzFaNzsD26jq5C8q/a8KNMuk0xshKSwBSXVmH+a2/EfyaLhkLxbcZEsRnDs7R5oPohpufhStBG3IvfTBFq6D71ukGEALoMUMD1xmh5H/d8nQrhR8x0Y4pBnSFPrIT8lwOF5AUcHUva+2VDvNncwoQmGE1iixo+C7EWsKAwrLY8CZFLX429M6+WW8gaAFrf5L4XpF3pYg0vi4lDDbYVAq9+krlkKPqdpVL5w3BiLI7NeyxUukKhZymOZFJOOnXcvlmdLtI79C/0WAgvDvMEOklvDQ5HGXJqHfMLZYEFrPxkYceNv+qnJssADPkxuiAnGIy5HiKlCs7N1kbv5bnbnOw8IpyFbKvHDbyRUzTHOXbRJVzhf7L/zwIsy9knRJb4uNJlt7XLSQq2g1sRCW1MYS7B6xlWVqdP9+iKs/jYK1HNaeyQfs0BfpB+ST4ojcDPJorGOxqthn0FJMZurOvP5dbZxNCCUs09boPciQn9r/Fiax71KTFpdPPfANMYZz4R0OhnL/GkzAWIft9i+BlB99sHTmqteBCqdw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(346002)(376002)(396003)(39860400002)(366004)(7416002)(2906002)(6916009)(8936002)(83380400001)(8676002)(186003)(26005)(38100700001)(16526019)(36756003)(4326008)(2616005)(6486002)(956004)(7696005)(66476007)(52116002)(316002)(6666004)(478600001)(66946007)(66556008)(5660300002)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UqsvhxaldCc3qWqN0qjQW2qGFXYZ/yDaxUgAiQoaKbT5EcPX1SgbSjJyK4k2Awx9jR6zHjXwHL3938NuEvKSKMkP2is/3UDL8hRHyR2vmd2xf4YOVxojQTU4iuwljD5N1RvRCsRoyQeX+OrrllA71muLwl9xkWRone64/yY9AABQ5VhPSnhmAU3wn8LBPQTMZ9BUOKNN9SqNwLWSCLyLd9I73ElS06nZkiG2402D3TuYlt4yxgMJhfNDCPzO05+PJCqAhNTjhpSxJvH2VzXhyNcMLF6x9jd0Y5eEDI4U3K2ZC47ftsO1TNvGJwZvgLPBRDEjsAE144uToUukxnCluWgJlDWzsS6nA7+yBoWF5FNpW/YS6fRQ6ZmjFadoE0gJxVW1+r4dL7RBorPCCpaPzaCMccxGd6PT5J3txaqaULo2/vB95pgzPv9yWvfpp9bzORz016BYVDqd7KURZI/mPHVmz+Eyc00rMas5+8fO7AgeelQgJqYOm2n3u4Srx+30YaALpELZJ5CWr3XutyIzuZ2oOcxbudTTY/pUm70Y1ti9caOSxPkQV0We1aGE9tH9zj17sQofQb5Z+Yrnx2BfhRnHeFE8KH5YukL7sB8++LdWjUMeKPgRbGSpxG7ZU3B5aB9O8fmM6ziwQgm2+PPqUOas8EhL88Rzyh1igjoE9Rg7U88eKThLqsndj7WtaRc7GHffO6zQ4xUdD4ybPrLGtA3bTO8gTWyyPRxMTkq1/wj+cTdUhKgGwBN3VJ31uSBP3SBRcA7VeTLPm2aRr/HINbIrOis/7zYB0qPUs1u8baNXaGEAacT6rR62zZ34t1um37f24F60UDqfQohC897ZJoqHaGMIefif2xIdOkz19cCogQYS4l94vrybY43D/0yZslBWfBszzyCjNnpe+r3ztZrXIEUoaG2jk2/M/R5GqihJqbEXTNvyAh+mAbut1pFSNFN83DH04mhrvzqoYY5EskVRNqDTQu/phMo7xEx8pfCRksyCipgysBtDNTicOp95gx6ZnuyhPtTEqgfq7G9hjNQRXjemwtRlzNw0kQC3NqIcwYDZehQvisS7Ue0A50AGJxLrbaPaEYPp594v70aUIudqqfXXERsPp5WawJVGhzPUPOxW4PpauqyafzOKAtXuBU6d/spt0rKGz+S1ayINSDVFe+646oz3aZP275hI6p1ZSflBZYSDz/kkt6aeCtor6O0Ikjht9xmLsaAsfa6rH7daDBYZvKrxHdmCQrysIy2wbjaEM4zkHeIyUAEnq5IocrIcTj7iTbgEwYJaFmW1dRptDP+GhsDm8FMT6FzBfDLw9EHkDTPQYGPGj/OH48YS X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3789e13-5de4-42df-d671-08d8f83f565a X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:30:18.9716 (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: IJ67ouWGT6MC37KtiyZgEprbMWzBsV14pRw6X9gxbSha53gF4VMEy5eU8cVCuyh2wMbkJ6nc7GxeW43wvvdSNw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4509 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Add new KVM_FEATURE_SEV_LIVE_MIGRATION feature for guest to check for host-side support for SEV live migration. Also add a new custom MSR_KVM_SEV_LIVE_MIGRATION for guest to enable the SEV live migration feature. MSR is handled by userspace using MSR filters. Signed-off-by: Ashish Kalra --- Documentation/virt/kvm/cpuid.rst | 5 +++++ Documentation/virt/kvm/msr.rst | 12 ++++++++++++ arch/x86/include/uapi/asm/kvm_para.h | 4 ++++ arch/x86/kvm/cpuid.c | 3 ++- arch/x86/kvm/svm/svm.c | 22 ++++++++++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Documentation/virt/kvm/cpuid.rst b/Documentation/virt/kvm/cpuid.rst index cf62162d4be2..0bdb6cdb12d3 100644 --- a/Documentation/virt/kvm/cpuid.rst +++ b/Documentation/virt/kvm/cpuid.rst @@ -96,6 +96,11 @@ KVM_FEATURE_MSI_EXT_DEST_ID 15 guest checks this feature bit before using extended destination ID bits in MSI address bits 11-5. +KVM_FEATURE_SEV_LIVE_MIGRATION 16 guest checks this feature bit before + using the page encryption state + hypercall to notify the page state + change + KVM_FEATURE_CLOCKSOURCE_STABLE_BIT 24 host will warn if no guest-side per-cpu warps are expected in kvmclock diff --git a/Documentation/virt/kvm/msr.rst b/Documentation/virt/kvm/msr.rst index e37a14c323d2..020245d16087 100644 --- a/Documentation/virt/kvm/msr.rst +++ b/Documentation/virt/kvm/msr.rst @@ -376,3 +376,15 @@ data: write '1' to bit 0 of the MSR, this causes the host to re-scan its queue and check if there are more notifications pending. The MSR is available if KVM_FEATURE_ASYNC_PF_INT is present in CPUID. + +MSR_KVM_SEV_LIVE_MIGRATION: + 0x4b564d08 + + Control SEV Live Migration features. + +data: + Bit 0 enables (1) or disables (0) host-side SEV Live Migration feature, + in other words, this is guest->host communication that it's properly + handling the shared pages list. + + All other bits are reserved. diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h index 950afebfba88..f6bfa138874f 100644 --- a/arch/x86/include/uapi/asm/kvm_para.h +++ b/arch/x86/include/uapi/asm/kvm_para.h @@ -33,6 +33,7 @@ #define KVM_FEATURE_PV_SCHED_YIELD 13 #define KVM_FEATURE_ASYNC_PF_INT 14 #define KVM_FEATURE_MSI_EXT_DEST_ID 15 +#define KVM_FEATURE_SEV_LIVE_MIGRATION 16 #define KVM_HINTS_REALTIME 0 @@ -54,6 +55,7 @@ #define MSR_KVM_POLL_CONTROL 0x4b564d05 #define MSR_KVM_ASYNC_PF_INT 0x4b564d06 #define MSR_KVM_ASYNC_PF_ACK 0x4b564d07 +#define MSR_KVM_SEV_LIVE_MIGRATION 0x4b564d08 struct kvm_steal_time { __u64 steal; @@ -136,4 +138,6 @@ struct kvm_vcpu_pv_apf_data { #define KVM_PV_EOI_ENABLED KVM_PV_EOI_MASK #define KVM_PV_EOI_DISABLED 0x0 +#define KVM_SEV_LIVE_MIGRATION_ENABLED BIT_ULL(0) + #endif /* _UAPI_ASM_X86_KVM_PARA_H */ diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 6bd2f8b830e4..4e2e69a692aa 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -812,7 +812,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) (1 << KVM_FEATURE_PV_SEND_IPI) | (1 << KVM_FEATURE_POLL_CONTROL) | (1 << KVM_FEATURE_PV_SCHED_YIELD) | - (1 << KVM_FEATURE_ASYNC_PF_INT); + (1 << KVM_FEATURE_ASYNC_PF_INT) | + (1 << KVM_FEATURE_SEV_LIVE_MIGRATION); if (sched_info_on()) entry->eax |= (1 << KVM_FEATURE_STEAL_TIME); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 3cbf000beff1..1ac79e2f2a6c 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2800,6 +2800,17 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) case MSR_F10H_DECFG: msr_info->data = svm->msr_decfg; break; + case MSR_KVM_SEV_LIVE_MIGRATION: + if (!sev_guest(vcpu->kvm)) + return 1; + + if (!guest_cpuid_has(vcpu, KVM_FEATURE_SEV_LIVE_MIGRATION)) + return 1; + + /* + * Let userspace handle the MSR using MSR filters. + */ + return KVM_MSR_RET_FILTERED; default: return kvm_get_msr_common(vcpu, msr_info); } @@ -2996,6 +3007,17 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) svm->msr_decfg = data; break; } + case MSR_KVM_SEV_LIVE_MIGRATION: + if (!sev_guest(vcpu->kvm)) + return 1; + + if (!guest_cpuid_has(vcpu, KVM_FEATURE_SEV_LIVE_MIGRATION)) + return 1; + + /* + * Let userspace handle the MSR using MSR filters. + */ + return KVM_MSR_RET_FILTERED; case MSR_IA32_APICBASE: if (kvm_vcpu_apicv_active(vcpu)) avic_update_vapic_bar(to_svm(vcpu), data); From patchwork Mon Apr 5 14:30:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CD95C433ED for ; Mon, 5 Apr 2021 14:30:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 082556128D for ; Mon, 5 Apr 2021 14:30:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241391AbhDEObD (ORCPT ); Mon, 5 Apr 2021 10:31:03 -0400 Received: from mail-bn8nam11on2067.outbound.protection.outlook.com ([40.107.236.67]:14458 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237352AbhDEObC (ORCPT ); Mon, 5 Apr 2021 10:31:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R/3rqWiPLkIkHHidVwVp7devP2I7Z+abv9kkjbdpX4kbpFBl1vrZL9WksZTYvHveYXLHlHrAYD2YhHcRP3oDAMfTjROOBsQBgxUbLFrmwU9Bb4VemITNFbWJKL5dss7D8h+5gUdL22EOgbBFL/UDaVSqhjoa6tapF1JWvQUrsZRAGNk9PjKWTJ041QK8nOy7h3G28fHEf9TNAzqrTqoPrmxum1xkgvzSehet33hQbfFNtWlWpgm3JHzT5KZoQ/6nVvOf6V4A2LgbX5uAIFUvPyKTf+8WHfOQHwCxi7DVEm+hgCqivXA5z2jXY9d6sQafPq6X3Y14Mo+dv5KbWhMZCg== 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=YQJQQaTWARObKBfzmviOopLOxzSz7S7p/w3nsNWbJwQ=; b=gB5K1ELRkN1Zb26J3KcHB3ojUHMBQxD0tm1A5xZ3n6TVEDzFcgaV8P07CWNDTz68oDiD8GTg5bolbDLLHY28H5xd0IqLpVMvM9K1nXK421DglzeU6tCaGY1BTo3JXHJhsMhFOHRdy6SXUZ3ED0w8kSZjwejGi6otMN9vG6siXi0o1+BziRQ5Nrn4MbQDJfm+S/0wWV6vS3Jr7xsvxWTUGV9HKYH7/T0b2iAhMftxF88Drahly7CpQQzxAyqE0TR/YkjuIUrxeUP6Gb+1GHxcNEzogXUyyRWX86wiF78vR/7ZYgi4detLEv8JHgnyeolBe6A9e5sWvpf8dLTWgu463Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YQJQQaTWARObKBfzmviOopLOxzSz7S7p/w3nsNWbJwQ=; b=Os2YykXeA0otdwRZRPff6L+g+aat8S+omEeXn8zh6OMqjYPCO/oRJP2Cd0Fi7xTuONZqfWtK5CVh8mhCb7HhyL5PlNm2TQzr/NliLKijsEiTNmfkPbrT6UjE8m/PQcxuVns9NdMei1uPHZYkIWIcOzNqpdoqgO+Qi8RTsRP/zO0= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4509.namprd12.prod.outlook.com (2603:10b6:806:9e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Mon, 5 Apr 2021 14:30:54 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:30: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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 11/13] EFI: Introduce the new AMD Memory Encryption GUID. Date: Mon, 5 Apr 2021 14:30:45 +0000 Message-Id: <4b36af89adb2f8009e07f371548e632e85350dde.1617302792.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR13CA0030.namprd13.prod.outlook.com (2603:10b6:806:130::35) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR13CA0030.namprd13.prod.outlook.com (2603:10b6:806:130::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.9 via Frontend Transport; Mon, 5 Apr 2021 14:30:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 528c78f5-35f3-4c9b-3bc2-08d8f83f6bbb X-MS-TrafficTypeDiagnostic: SA0PR12MB4509: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q8GA0ogaBW7tWoFN3O/XYGO8Mees6O5RZIy8P/9TWOngUpRC3DZ7J6xdUABF8w2sIDC2kBgKafx5UN8Uk7nM5DeEGCw8wuhNAL6Yjk4UPyd69d8KsUR+AXJdGBDr02xtVBlmmmmgKyhRPbhMhsFD07gdiFFoQjmzmYroOIV2+ksvsSeKKyHrIeLcIfpw0cJbRvDIXpWTSqtPvMHBN72QqBsd00NEx00zKlbdCn3EiW80a9gUZPlXrA5s1SqW9kjRqFLkk/KYLU+ObbEAWSIVQfXhkIupQEq0WT1iZ2yPHyowLwCu47WzfaMTAkMhzKxweZFzC7lwLeHqhMpeQILyoWAJJ8tA5t2uv+qqfqKcis61eoZcC0IL4BVBKGCPdY7ft1y4Q2LcNQpYXwcx9nnoy4DXHk28cLUCHsyTvLvdQShhn+/+Rhq2rwQQidjDfS2rZaNPEnkU65Mrg98r9yLs2hplSivEF2mwXkMelUazF7KuThqyTahTQmFNigpaRp7TuL789xAlB2Rbg1atQ8LMQpwhI3gj0EF02fZiXJcWy0KaEUql5yUzgXzlELwpyfjAvUOFNi35d+NEoby6WhJMgcqDlLACT/UtEH/d0RUYMOHElHvKpOSj2yNpnE/n6ME6LglMFq5vyV2vJX6t4cgkIA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(346002)(376002)(396003)(39860400002)(366004)(7416002)(2906002)(6916009)(8936002)(83380400001)(8676002)(186003)(26005)(38100700001)(16526019)(36756003)(4326008)(2616005)(6486002)(956004)(7696005)(66476007)(52116002)(316002)(6666004)(478600001)(66946007)(66556008)(5660300002)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: o8q8UGQmrmZnQZv2DdR/RQ9+mYGzj0QOmCyEKIYNIb6NuXmbp0wcxo+a9nKn3MsetL6v4zXr0qvovxNTeU4RbTdx/wWSHuQ0boaw4vi8iO+L30M+r6mT2KRVfJYHn6jw7XRkM51AzXiaXo9IpdNpwmvyfJV0DZReZ+Zkg3O3R/9zeGl+ZKGOgqiP+2WFDDJ0bGCA92kpudTBQ+lJDQ32Spjc6hEQizckae141OQOWchksuuYEuqcYNW5Onv6WwM/8/TS2ljtUD12W/MTGsYUYv0I8dJQvnrzrxRMpKCDrIfengvfhzWpoSWap5wVlljjPn54ca6bJOE024tlYzBR7YixLCo1Sg8vVZrG5YRdILZuilzrI+tz0rLe1zJ3KXpVNC6t8gefMGIsZU0/j6r7S/fYbalnFyRQun+NvmCKlB1bBmtMIxId/cBen+BZoSG+rx90IfLFpZStCKDXtkt+Mc0p86t+My8OjP5PK43b+Prm16aaFnOigJtqaKnv/P93ZQJLWImhlKqJ/Hcgm1nFSMM89IZSWsJLbEK2sQXLdFuaazI+XYdxcmHd8JolV02jI4HSbYFX14AuNZv1wT/M4ruS6e0OvRMNe7MF7Pq0hRCVPQdXEa4h/nn/c3oH0xNzVaH+rmD/6GldjRX5t9dplbdfiDv2Hq1pyQQvDIdJwWEgCWYYbyrmpXg3eIpwL4HbpRHz8NplgqyNDoL6EOYbiMT/locdjIXF5cqSLIqnD2vAieBdUBFT7txVDg5UDeFoYeSyFFFcdVRHvo3FXl78tIJHvYyd78lzlXf0Rf+mh0cmkmmlwvNNLH6d/6rmkoYQxan21nY2UpiYpgI1ejgTjy7GkkChYRiatR3ynobAXuMrNV/3cJCzDsB1DxQzHZaRoBErtcWh5QeEVdoz9MWDLH1mSFCBphR+hOyi8sAMfnmWp8c0lEC+V+axsBN+/auc2bzxON41uhyND00tEW6Ji5I8gaXl0uH3+3y0YNPS++T9ruJ8OvN09YpBnopg/x2fDFjPTGuxiDIT4YJXKenRmmaEs/sprePSltb56rb6YN2RoV2orvyF4mia15XbRPxpr+AK+D1ZnLCHQfRV+Gjiw9Ds12IqBOzqJgCCncb1tkNvXEhiSz5kB109GJNLlMn/JaTXBJiajQVBLPYNUIjiW2l3oTp4Z+IZ3zfitjfh4EENzBquZDT94vqEZytb8yu/oGIRmyhQHT/3J+ZCPHt6WCYhHyXqGdzlKosikj4eSCNCVi5ry4RlPVCPbpa9xErVhG3Mk2LRR53WZMiu6N36o8bOUvqLKdyZfsW00mft1vb7WlL9q8Aqz/rz74ecVNE5 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 528c78f5-35f3-4c9b-3bc2-08d8f83f6bbb X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:30:54.8155 (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: 42VlBgarantXXC9d6xHI6vEtkdlvYcPtg+nx/lNjFFO2lhtPz/mkgkBtHAhK1HwSDjrbQ9vTHBKQlaqK4In39A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4509 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Introduce a new AMD Memory Encryption GUID which is currently used for defining a new UEFI environment variable which indicates UEFI/OVMF support for the SEV live migration feature. This variable is setup when UEFI/OVMF detects host/hypervisor support for SEV live migration and later this variable is read by the kernel using EFI runtime services to verify if OVMF supports the live migration feature. Signed-off-by: Ashish Kalra --- include/linux/efi.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/efi.h b/include/linux/efi.h index 6b5d36babfcc..6f364ace82cb 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -362,6 +362,7 @@ void efi_native_runtime_setup(void); /* OEM GUIDs */ #define DELLEMC_EFI_RCI2_TABLE_GUID EFI_GUID(0x2d9f28a2, 0xa886, 0x456a, 0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55) +#define MEM_ENCRYPT_GUID EFI_GUID(0x0cf29b71, 0x9e51, 0x433a, 0xa3, 0xb7, 0x81, 0xf3, 0xab, 0x16, 0xb8, 0x75) typedef struct { efi_guid_t guid; From patchwork Mon Apr 5 14:31:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3166C433B4 for ; Mon, 5 Apr 2021 14:31:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70BC56139E for ; Mon, 5 Apr 2021 14:31:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241409AbhDEObZ (ORCPT ); Mon, 5 Apr 2021 10:31:25 -0400 Received: from mail-eopbgr750054.outbound.protection.outlook.com ([40.107.75.54]:54087 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235915AbhDEObY (ORCPT ); Mon, 5 Apr 2021 10:31:24 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jEN2jKQgRgIckWKq6/ZMFKLJV386QF/QyRRkabo/qP+Zgc/A7WbYw1OGPoGZSxV2PlduIMlX4uAAbI9HFHHNptwxxZdzcpyEjycwLvAvxGCzZEX0tjQSCDoAgtY8/+uRjYYPQKk/pK33GJLtR9yzHHRx+cwaiopp2/191Fh8/Ir+Z4zG2d5QEptUSitxY4CA8kbLw08HKEd6EkmMzJa7g0/GgHATJoX+4EcQ4E+k8gWbW7oVVAeg2MEvThS0RRnUZQEiI5yt33S2n+/uQRzD0VMUF+lJsvtYyTMaiOyZ55vXqflJlcFbE3yoqIjzJf6K1BsauL4EZS3kfTKaLfwLxA== 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=JvcQs5qLrU5in+oRyqaqqedPuuiSJAyZl7IgwhgRMKA=; b=RGLvRdFhKHbMQsKHoZHIP1X7Xyct/y6DXK2IwC35euh75dRB4oXva1+Q8ASfKOr+FauDQDAFuu8jFM3n1zwuyYVxBP/tmU0lncg6vQ3HkJct/Mq2MLf+mCr2WOereRhJa5/f/nZwh8mXG1H6H9sHQuaEyDA+wOyIY6tE80GU2tPN3nONHp8GISK3/Ie0peVVIDnxD3fpLivxTGsUG/pYUuXsD3wyx+7m0/mj8o9J46tGRV/BeIyEssIT4OvCPrK4EJHP2qv+vw3JDyM5/OOapU1cJcN+xtTNL6prMYUnOu2fpV9b0WVZ47mHwDlK/aatjO8Gki9vOZ2LB5P9ROhctA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JvcQs5qLrU5in+oRyqaqqedPuuiSJAyZl7IgwhgRMKA=; b=4VigqtqrOqWfN1I/nh84kIibbvWBTYanNYO/snCMHwnUfkejZ+/FL/U78cbxCHR3YY5zChyVH6E5CpQ/GUP+n7H4RAZvZ/EyDZTFZShzozrt+9s1BtMk6FWPVT7kAMkWMKKXW8c5pQgc3B0WnH9LcgU891HZtAPTfzERmbRtifM= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN1PR12MB2512.namprd12.prod.outlook.com (2603:10b6:802:31::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Mon, 5 Apr 2021 14:31:14 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:31: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, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v11 12/13] x86/kvm: Add guest support for detecting and enabling SEV Live Migration feature. Date: Mon, 5 Apr 2021 14:31:04 +0000 Message-Id: <1acd3e6796b0ffcda880e92baccae4f148d38ce6.1617302792.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR03CA0005.namprd03.prod.outlook.com (2603:10b6:806:20::10) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA9PR03CA0005.namprd03.prod.outlook.com (2603:10b6:806:20::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26 via Frontend Transport; Mon, 5 Apr 2021 14:31:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6df493da-7bb1-43f4-eeae-08d8f83f7749 X-MS-TrafficTypeDiagnostic: SN1PR12MB2512: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:257; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NJ8P02F2KQaXkCyN3XaWG3ArDkPUndTdZjX//NaVqJ7z9aHU7XTwumLLGt6NgEMo43K8xTi0vwb5TVqZkCMrGOsY4vI94vTTRB0XgmmHXy2JfYQdzGJz575jBhQu0hJaE2tzl5Aamxw7T5KXD/eTykuk6yPvtAlAKq7UXGiKCgI2tsXx5j/OYpuDQwxM+My8MHHvt5Bib5e95bxaa6q3spNXY2Ty2UBN45am05lffivCppGE5kLUZs0gqCQ7cXqUfxYrgI50n1Aa62ZNALb/yIDrayiTKWQ9cnwBPZH8Hp7SZ9hfeLt0Y7NAIsK3R1Xnx1aeeitOYdIWOc7zbO11QqsiqhvI847EyggFpQ7LNGtZknbwSmUZkgAe+Emfa/pCLw4oKQgHjhNdPWBlB/Awf+N9sW8m4d9WzeEBjitQHBIrvITsm+YjwTB+WSd/0KA/C1pisIXANVG+D9ds2Cc46+XvOIku8QVLv4Z5exzhtl3BbcRQwusceb8G8A9MYR9esT0R1m2ajYB/XGevSTZz4SrWrrNDMC+TT61wdXoKXbayALBcGZ8Py69vQx2p/Fdkmw8hm3gmZbYFCahporT1diFWp6dQCD3cgtPTDPtz1d53bP15HJAPvIs6x/nT6iXx9mhyODcJ3iJ57WE2Yq39RA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(346002)(39860400002)(396003)(136003)(376002)(38100700001)(8936002)(2616005)(36756003)(7696005)(52116002)(66476007)(66556008)(6486002)(7416002)(86362001)(6916009)(66946007)(6666004)(16526019)(186003)(5660300002)(83380400001)(2906002)(316002)(4326008)(8676002)(26005)(956004)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: P2fH2FS9IzwoQe0zTu6PZUZQIVt1+txG50odZGVhyw9bnyVz7MJGOb8vJdWvVwySaSQGPp2V+pBmYrdUi8itg0zAg2HYplJuhSfPNqtLnj5ylDBP0+M7g2HTHYBekkUUAbfhwMYX9ldf+lndMV0LgI6xjWhDsHfHFihlN8QYSjuaKHGnV41BxbOPlljFTEC1J2bBYe+jJqWz7AtgAiLCuIrmdLS/jL1DMnuZNPeYgH/faTT4Spk7pLcGn+kuY/1DltGwjvBKdyqfFKbgK+M55YnD0M+0XI5vkY7BlQ/8RvfbdwhsNKXhjeMshNcEjFeZbEcz+kMJF85wnpAuKIk9E1rXWVKBchZLD+Qyu6AK4CEnoit0pVorHm31IZz1IgnD7mKxkgRrW4oDjbtrA7TQuD2zcRS2/hpxjNFcgn93SkwZE+yy/VR12LAyl1Uz7W7aQQhivtPIx7CR5jXH5b7RwWwuNCLvYw1J8egSffceUfbjsKHBaMRjjoNbq6uIIn8+P/YdV3Ek4vUx8zIhNU/JRbYuOcZxM78Zs+2uGZWWKLzTHB5xPkURnmUlDQxJgGCrHcoc4/liOjVjiVxhsRBPdZ7fr/UvfRN9AVwU1UBEHJv9UZq/a3YwGKMJ5Pq6QZcNML36GIVLkTqwwSdxSCPlpMOBO3xQLvUdEJkxENlghdfrxyW3TqYzjeDridfMzRchzxFbajtmOijjFezinPA11peFJk5bWjsHy7eGAjCYKTtbmml4HtXqDxM2EXIRq+Prf2N2Tb7DVQexIgzVl5d6luF+pYM0OXh96UrOXT3p+NX4hVgx/vcviPuB29YNkW3OCzAY7DiwASnRPMrZifzi9zaJwHHPFxGK0jf1xZ8QjswZNhQRupuwXBPlpj8OzR35wwrNwdV/X1MwRiGAfc/59Z5+hXM57lAdgtdPXaSfvMS0R2NMHPzkwfnN0ukH5qmNsokg4RKilabj+eQ/2l8xow3KUWZQdbboepN4seWWhO1KOpaWDLacY6NVJ/O+4jo3kff5A5XlszA/g42i9MqCGDoVeK/LNdCHJC5GX4wp3q2Dutju9LBcyoMNQAtWtBRTGe8ccP36gRd61lpZdDUxUN5QJRpTYroNxI0Ky3is6tKldWrIpHefkXlXxgsSHMSvwfZrcOFE70ZYb2woZGIIY0J0mVGNKGAZ7XbJs+0TKWsCThRnqjgFSl6AoSkuXBx50PbAN2HsKn90uifcrcdpMoXYZdSWD0f3UeUB8KtnYTX9j74C1T3FoCAzlx01Rz6jLOuiEK97RjyfrYe8jEGF4sCrbp/eaXSQ5zpLileiTvSEE7Ht1BQ0SP2xAZZRk8Sp X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6df493da-7bb1-43f4-eeae-08d8f83f7749 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:31:14.2396 (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: yx8B/kpAyRjE0qlZTp4OuJqQ8zfpXepIJVE6sqnAoAYJv+vUomhARqWWGJm/Bg5xtm7yaiTsfegUoMT8gDgmMQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2512 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra The guest support for detecting and enabling SEV Live migration feature uses the following logic : - kvm_init_plaform() invokes check_kvm_sev_migration() which checks if its booted under the EFI - If not EFI, i) check for the KVM_FEATURE_CPUID ii) if CPUID reports that migration is supported, issue a wrmsrl() to enable the SEV live migration support - If EFI, i) check for the KVM_FEATURE_CPUID ii) If CPUID reports that migration is supported, read the UEFI variable which indicates OVMF support for live migration iii) the variable indicates live migration is supported, issue a wrmsrl() to enable the SEV live migration support The EFI live migration check is done using a late_initcall() callback. Also, ensure that _bss_decrypted section is marked as decrypted in the shared pages list. Signed-off-by: Ashish Kalra --- arch/x86/include/asm/mem_encrypt.h | 8 +++++ arch/x86/kernel/kvm.c | 52 ++++++++++++++++++++++++++++++ arch/x86/mm/mem_encrypt.c | 41 +++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 31c4df123aa0..19b77f3a62dc 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -21,6 +21,7 @@ extern u64 sme_me_mask; extern u64 sev_status; extern bool sev_enabled; +extern bool sev_live_migration_enabled; void sme_encrypt_execute(unsigned long encrypted_kernel_vaddr, unsigned long decrypted_kernel_vaddr, @@ -44,8 +45,11 @@ void __init sme_enable(struct boot_params *bp); int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size); int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size); +void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc); void __init mem_encrypt_free_decrypted_mem(void); +void __init check_kvm_sev_migration(void); /* Architecture __weak replacement functions */ void __init mem_encrypt_init(void); @@ -60,6 +64,7 @@ bool sev_es_active(void); #else /* !CONFIG_AMD_MEM_ENCRYPT */ #define sme_me_mask 0ULL +#define sev_live_migration_enabled false static inline void __init sme_early_encrypt(resource_size_t paddr, unsigned long size) { } @@ -84,8 +89,11 @@ static inline int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0; } static inline int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; } +static inline void __init +early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, bool enc) {} static inline void mem_encrypt_free_decrypted_mem(void) { } +static inline void check_kvm_sev_migration(void) { } #define __bss_decrypted diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 78bb0fae3982..bcc82e0c9779 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -429,6 +430,56 @@ static inline void __set_percpu_decrypted(void *ptr, unsigned long size) early_set_memory_decrypted((unsigned long) ptr, size); } +static int __init setup_kvm_sev_migration(void) +{ + efi_char16_t efi_sev_live_migration_enabled[] = L"SevLiveMigrationEnabled"; + efi_guid_t efi_variable_guid = MEM_ENCRYPT_GUID; + efi_status_t status; + unsigned long size; + bool enabled; + + /* + * check_kvm_sev_migration() invoked via kvm_init_platform() before + * this callback would have setup the indicator that live migration + * feature is supported/enabled. + */ + if (!sev_live_migration_enabled) + return 0; + + if (!efi_enabled(EFI_RUNTIME_SERVICES)) { + pr_info("%s : EFI runtime services are not enabled\n", __func__); + return 0; + } + + size = sizeof(enabled); + + /* Get variable contents into buffer */ + status = efi.get_variable(efi_sev_live_migration_enabled, + &efi_variable_guid, NULL, &size, &enabled); + + if (status == EFI_NOT_FOUND) { + pr_info("%s : EFI live migration variable not found\n", __func__); + return 0; + } + + if (status != EFI_SUCCESS) { + pr_info("%s : EFI variable retrieval failed\n", __func__); + return 0; + } + + if (enabled == 0) { + pr_info("%s: live migration disabled in EFI\n", __func__); + return 0; + } + + pr_info("%s : live migration enabled in EFI\n", __func__); + wrmsrl(MSR_KVM_SEV_LIVE_MIGRATION, KVM_SEV_LIVE_MIGRATION_ENABLED); + + return true; +} + +late_initcall(setup_kvm_sev_migration); + /* * Iterate through all possible CPUs and map the memory region pointed * by apf_reason, steal_time and kvm_apic_eoi as decrypted at once. @@ -747,6 +798,7 @@ static bool __init kvm_msi_ext_dest_id(void) static void __init kvm_init_platform(void) { + check_kvm_sev_migration(); kvmclock_init(); x86_platform.apic_post_init = kvm_apic_init; } diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index fae9ccbd0da7..4de417333c09 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,8 @@ EXPORT_SYMBOL_GPL(sev_enable_key); bool sev_enabled __section(".data"); +bool sev_live_migration_enabled __section(".data"); + /* Buffer used for early in-place encryption by BSP, no locking needed */ static char sme_early_buffer[PAGE_SIZE] __initdata __aligned(PAGE_SIZE); @@ -237,6 +240,9 @@ static void set_memory_enc_dec_hypercall(unsigned long vaddr, int npages, unsigned long sz = npages << PAGE_SHIFT; unsigned long vaddr_end, vaddr_next; + if (!sev_live_migration_enabled) + return; + vaddr_end = vaddr + sz; for (; vaddr < vaddr_end; vaddr = vaddr_next) { @@ -407,6 +413,12 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size) return early_set_memory_enc_dec(vaddr, size, true); } +void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, + bool enc) +{ + set_memory_enc_dec_hypercall(vaddr, npages, enc); +} + /* * SME and SEV are very similar but they are not the same, so there are * times that the kernel will need to distinguish between SME and SEV. The @@ -462,6 +474,35 @@ bool force_dma_unencrypted(struct device *dev) return false; } +void __init check_kvm_sev_migration(void) +{ + if (sev_active() && + kvm_para_has_feature(KVM_FEATURE_SEV_LIVE_MIGRATION)) { + unsigned long nr_pages; + + pr_info("KVM enable live migration\n"); + sev_live_migration_enabled = true; + + /* + * Ensure that _bss_decrypted section is marked as decrypted in the + * shared pages list. + */ + nr_pages = DIV_ROUND_UP(__end_bss_decrypted - __start_bss_decrypted, + PAGE_SIZE); + early_set_mem_enc_dec_hypercall((unsigned long)__start_bss_decrypted, + nr_pages, 0); + + /* + * If not booted using EFI, enable Live migration support. + */ + if (!efi_enabled(EFI_BOOT)) + wrmsrl(MSR_KVM_SEV_LIVE_MIGRATION, + KVM_SEV_LIVE_MIGRATION_ENABLED); + } else { + pr_info("KVM enable live migration feature unsupported\n"); + } +} + void __init mem_encrypt_free_decrypted_mem(void) { unsigned long vaddr, vaddr_end, npages; From patchwork Mon Apr 5 14:35:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12182999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30BBCC433ED for ; Mon, 5 Apr 2021 14:36:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07D4D6128D for ; Mon, 5 Apr 2021 14:36:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241417AbhDEOgI (ORCPT ); Mon, 5 Apr 2021 10:36:08 -0400 Received: from mail-bn7nam10on2053.outbound.protection.outlook.com ([40.107.92.53]:56769 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235915AbhDEOgH (ORCPT ); Mon, 5 Apr 2021 10:36:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=coGYKRnhXmhdf2i9e632oexkHYJkKYkF5r5JO1iLqseSlz9w0iPjURB/FjV2BdRFDcDlou5K5cYlnpXLEzEkb18Ro8nsgFs6K8kHnuwkKDX7m4cTAnq8ABBl7TDh4Qf7J4J8AJCzzMLX8hMxj+gUIFxSHvWOuS31xF9Rc0lBmAzclB4a6nR0fOV0yTr/7txYj492293SvFE+aerB9VJ5cVwdPgfWWedQ9ENy1fwRXDJqqQTtMuD19JdcrtdoBkQ2aLRGE2dhqS/GcbV4OoeC/mQuA/tVYKNwAmY7eK/7I98+rGK4CSlHQ0/M2Saw0VlnkdlyM/e5P6MyxFjcypZB/w== 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=vMFsE5kyHk8b/BTrnc+Jh1LeIka8vWE7qzvszbJdnIY=; b=cg1NdDdsSv0KU+LGL+PPsugviOTRQvejRKbRmLWGwvBN82YAQZopuql1Ymn2qSyKK8oU0WOjNxQY3rOL/PWGy3iqV4LVcVIrk/ITWfCJOSCJWE+HFPSB0ksb45pvtyq6aeoNxEiaKf1JTaXAmFSSTqGmY2OL9HaBfK+FEP6pg7q20bD03TeQNDW66zrD8vLPFmArqnTyhXGTHfDXVLORbXTxR07vNkwIBThtfOCTAoYSyQdrPAkn/dX3xyynhO394oGFfBs2Ja6Uf9tFmuVVZK+sX28xNejov5Egwapd4Jwhraw71Om3mKVPD+VyExJkyEdGQh21KqlO/J5cbnnUOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vMFsE5kyHk8b/BTrnc+Jh1LeIka8vWE7qzvszbJdnIY=; b=MawoovEZGc82CTvoDR6ecL+2ENSgqgb+BJFZXtyxdk1r5fGCxEKx3hZlOhiWou8CNrpBi5O5YIcZe2qJRfmN3jsVMGMBFWjoyfHVGc15RHdr4NCezZLkjmM/7337TCGvUNGbgeaG/vlkCbJC9w+77aj0h+4p/dpBO47WMHjOz0o= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN1PR12MB2543.namprd12.prod.outlook.com (2603:10b6:802:2a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Mon, 5 Apr 2021 14:35:57 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::24bb:3e53:c95e:cb8e%7]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 14:35:57 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com, kexec@lists.infradead.org Subject: [PATCH v11 13/13] x86/kvm: Add kexec support for SEV Live Migration. Date: Mon, 5 Apr 2021 14:35:46 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0074.namprd05.prod.outlook.com (2603:10b6:803:22::12) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN4PR0501CA0074.namprd05.prod.outlook.com (2603:10b6:803:22::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.9 via Frontend Transport; Mon, 5 Apr 2021 14:35:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6b96be1d-68ab-49a8-e8ab-08d8f8402022 X-MS-TrafficTypeDiagnostic: SN1PR12MB2543: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8sGJAHtrO3nHFjbmStGyIuoKwx62113iKM+TyvxqtX7T2yGxr/LfDd33IIEr1NWqi5LHbIxW/HMH5f0A/iP5lv6QLfFVGER8i7pnW0aXy8SytPsNsbpbkbET0xXfWO0WRDGd/SnkQvpxCris5mf8N+ah7Dm1PNfUSY2I9WZEFRnfdPtu/7HohbjCBKFT/1cw2TEO0yzmdND+vh3f1yxVebT+RB8wUtW+c65VLXmrz3PzGpyvqb+kOm4PvKFn9s8pSJr5jv7mOzhRVJLVy8UXe/lZ8ClBhp9+vF7lhEZ/y4/ru9zX0z/+lxIjylIbHN2ydzk1O94VVcpoZdKNJJo7BX1yO37Mqa56SqCqGy/4NXK10iAWQg9GRj2mHCstCBbePCjtvUhV96KQ9mPivnGGgXxunD+bGkVvHc/C+ngzr3kERT5mkhXjlMmBHDdVZy+EcSoFLJQIKCmsAiORziMc8Il9Rt3z4XmTpcMTwFZjUuwmrSuDKksUeqRWTN613JLOKyW0VrA8V3k62UnOWZCZDI7qGE60FiduVIUss5XRf7LIYZGe0MtFAjLWrOlpDxUaIKCuRf3RBYHfrZ9Y0SPg/VCDvfm1DRq8jh1KAtvhIvOI/sYbHd/zcFHkQTrDjSHdjhd+VaZ6fP9frQ5cGRTYIDrHX/jkl+gwQ2IoRgOW6wo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(136003)(39860400002)(396003)(376002)(346002)(7416002)(52116002)(7696005)(26005)(2906002)(186003)(4326008)(8676002)(66556008)(8936002)(66946007)(478600001)(36756003)(6666004)(86362001)(38100700001)(956004)(66476007)(6916009)(5660300002)(2616005)(6486002)(316002)(16526019);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: tTvrt9gA6tM01bHUq0yoVixCjbDeDBuvP67/4BLAm4ScI/zMyBIUK46jsmrRHWmDeXRJl/17YLx/td34Ea8AHykdKmHaZlZDHpilIMOXTxQIb03s+C30snJe92QYSWJlFXNM0wYJGgdWP63wSoMYGbCs0xOQ9vimglH4SW4qv5LnscxiglxEgzXi4//3wy/VIxlfFBDc4jQTyfHjExPdixT/Jp3Qr12ZpMqcRK24EUr+E+kNoSo36EkY/C6yAT/DsbgEeNLZ8eZEQyinNokgvhEcZ8Dh2Vpd1HJYNMbhLfUxz3PNPnKWvJ3Av36HJ4GDqJLlbxyeoa9Q3bafxjcZVEzvTxcPsIFk3VfMgHsNAzkJrb9pKs//W55wb9PA2mv3vpzzmmsvsXostbcvkHFZCYTLaJjyKZfiqAAo68FtC7ZfaIXszg6Hf1rirBbZm5nJBzuY+mRE+msQ3UlbBxsMozrI/RMILkleO3GD2tUL49HeYqxgnJQ4n5JR7ZSS7rzkr4EzRPG3jALI0X0TkAeZdmTi+3uOrrgDMbnl33GPsg46dqBlxVRgepfBbSLFsv2kqWKjuKZTOXm672etG1/oVYbexEBXplhA+5VwlCTa5PI5uHoyM9ftQv4TnQj2/g7oKKf284+dkqirTvLTDR7owTnnE3NbSYgV0hO3E8cEs8/6GNd0YcSxfto9hsuA2pJrrms8/rRn2Axcfo8aI5xy6hXswvy6/J6CtLWniag4/qV3W5sy6WwX6ZJvQaHWWQyA/9gYqaD9TcdLTrhDjjHNmRcL+HaJDK1hOMswf0uPABYE5pBesR2Rt9hm835hOB312R14zhOpuoJInXIzOwsq9/JRKCdPWQYjGOxjpZZtT/iooDwTmGuJsTW+Ii0SZkVJATjLV3kEfLtVNctY6HPRMcsqpfnLa0a9kbL+AlpU4EbJI+bhbM3blHEIJtf5v+47FATkwjqE7vUtFGiEK6EFlf8qlzNcZXrL3A1+vZo8F93Lm1gSDSuPt32dutLR0iet83AzLxvatB77pSjo7HkdRZLWA7+6AoA68KHVN8AKCBHsJbpQnq35zcrUbtRCl0Ghc3UnqbUkYquMvXgZ2pxLuDEjty2MrCPzUNRrwHxJm5CrjqCmPlT7xykl7IVUH2x5em435KkRP9E0PNzoaB8TO8mor0yH/a+IIotKyfG1S7XrHtA8Q1oLl7ngPDmmQySSXTBpJCOsJjVh81RyYyOdcyQxgMnAHW7G7pMGtDXeUtr30vITkrBDHX2koKCcuj7siOoM8MwZASGHwi4L+SaO6ExAtleZhMPshuo12lpB14R9xGu/oxOtypvpMgXbI4hE X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b96be1d-68ab-49a8-e8ab-08d8f8402022 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 14:35:57.5118 (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: MWtD5LurCfSzITVFqKd2tyI2K94soHjqeFWTvwnmsEoLtKiOo08pkzhggVtbg2VmCrhvKegPxBaEjXSHhsnapw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2543 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Ashish Kalra Reset the host's shared pages list related to kernel specific page encryption status settings before we load a new kernel by kexec. We cannot reset the complete shared pages list here as we need to retain the UEFI/OVMF firmware specific settings. The host's shared pages list is maintained for the guest to keep track of all unencrypted guest memory regions, therefore we need to explicitly mark all shared pages as encrypted again before rebooting into the new guest kernel. Signed-off-by: Ashish Kalra --- arch/x86/kernel/kvm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index bcc82e0c9779..4ad3ed547ff1 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -39,6 +39,7 @@ #include #include #include +#include DEFINE_STATIC_KEY_FALSE(kvm_async_pf_enabled); @@ -384,6 +385,29 @@ 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 shared pages list related to kernel + * specific page encryption status settings before we load a + * new kernel by kexec. NOTE: We cannot reset the complete + * shared pages list 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]; + + if (entry->type != E820_TYPE_RAM) + continue; + + nr_pages = DIV_ROUND_UP(entry->size, PAGE_SIZE); + + kvm_sev_hypercall3(KVM_HC_PAGE_ENC_STATUS, + entry->addr, nr_pages, 1); + } + } kvm_pv_disable_apf(); kvm_disable_steal_time(); }