From patchwork Thu Apr 15 15:54:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D99DCC433ED for ; Thu, 15 Apr 2021 15:54:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFD0B611CD for ; Thu, 15 Apr 2021 15:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233987AbhDOPy6 (ORCPT ); Thu, 15 Apr 2021 11:54:58 -0400 Received: from mail-bn7nam10on2080.outbound.protection.outlook.com ([40.107.92.80]:58256 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233369AbhDOPy5 (ORCPT ); Thu, 15 Apr 2021 11:54:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X3dtEnpxtFDyR8H65pFSH6g+3faofYuljlOT/VREeKuTZHy0kPM+H2KvuiUvp/QXVNnIIVQY4hh+RSGU8k2yUMMTvLtmrrSJV5mw7s5GKyRNMAnSDi4F6mQFCIwBmdBV8hvpixvsKQvF1wunhXIYUa2mLgsL8RIm2ecxOpZGyMj1XpZ/wh/k+lFbeUlv6Lbv9zweSfUgG2h92JM2oWN3lKFot7BHtfO1lKIj5wOVV429ItV2KKUni63N2r2VJSI4hKhWcMik3qDeo/LHektTMN7EVA/K2Ks0ekDD3iJhDiWGHZK7WyypLm6hJIMwt3iLhjFLiHaH8kgurf75RO+9mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OoXsYPtt9BXmkmjz+xmowRRzJrV5xMeUKi1J8IY9VRA=; b=dgWbClRt0z8MVQuzLDc5ROb3KxRz43ukVqbG+GoMmTMXM+pJbNuaCft/FrIR0NqULaCf2JLQD0J3Ho2NpATg+98yYeibvX67FwVdfWDsMg9wgFfAplENoRwmT/sNoD3ycW9f9lwJWKJ6g6lqv10/y2wTBbXS7LVcK/9eEH5+9h/r0ZFNaoI1asRvJE1Gcaz01SP/eLwIEEjyJO/e8RbdDX5FrmNne/hVDeLwGTF14gulUeH7TzMXlqbiH0Swkdqky33RBX/Au/rXrfLXd61qNm68sCSKltZD1RqxRUC63jcfSkEuYAMgmCFkjHiSF2bpmZHly5A/42r1reiNO0EslA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OoXsYPtt9BXmkmjz+xmowRRzJrV5xMeUKi1J8IY9VRA=; b=Z9f/fSIu0iSFB+tR52r1p0hHZNvIOHKNfdSqe8wYTyKXln8Y/vjqT5DYcmyhofQKafKy/uX6MYxcuPbJ3OGdvoEBKPTYj5MZFAJciPKuI7OItRGGtRbe4QuosWNZf+BjT8avTqaBn3iQQPwhAw4U1gaKyFwhH/1/hhND/294EXM= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4384.namprd12.prod.outlook.com (2603:10b6:806:9f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Thu, 15 Apr 2021 15:54:32 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:54:32 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 03/12] KVM: SVM: Add KVM_SEV_SEND_FINISH command Date: Thu, 15 Apr 2021 15:54:15 +0000 Message-Id: <5082bd6a8539d24bc55a1dd63a1b341245bb168f.1618498113.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0223.namprd04.prod.outlook.com (2603:10b6:806:127::18) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SN7PR04CA0223.namprd04.prod.outlook.com (2603:10b6:806:127::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 15:54:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b0448f58-7341-4970-a3af-08d90026c2cc X-MS-TrafficTypeDiagnostic: SA0PR12MB4384: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E/oTqNgi3h5Xbomc4m90faWkBPrvyHM8zATlvHMT5rQDf9W30v5qSW8zcBn62Ns3KLA8yLaELW5uHqT0WWV9vFId9ZPcJOKrluEAy6DiTH7GXfp5ebz7s/ZcRP3GaNhx3kfuCqZWQnT8DLbdvm7SSGDY3uqSNK7h1IADfSN9a+R7SJKhGxj8eCHk9+l5PXZYgL/OpesSkkHYz/f1PsmaGiM2t1+pTTfiOX7sFPoB+XghMepayWBTaOeB63xuTDYn/eRqEOtHhq7OxRJELSg1sZxpVgVjPc5UZ9toum7LMDMMJJG00h5r7j8hR1zrpZgzxxyMMgZStcUoHFQK2zsnkIShkzk4OqRmJTFGV/Z7oKqJLWVQqbkAYNYcCUuSn00rsPp/6ApTbmZkEA32VL48/cmMD8EQdBc9Vjdi817RJPL/pg74dRkXhoaQqlnuaRgIx4dOGKjfgvvVk5Z662hMAcLHVvCyVFKBREW8qnNGbmfhzwxhfZvzP7jLXVRhH566+F1LhNXoy7bwfsvEyoClofiejMicJVXxPjt1IBMN8KXtEUwwI3B2wZEN2wCedc+ShWeUbSNVzEa3iCM/vvTf0eZttWqGTbggJpvc1mERcTD+s/4TmBr6g9xACEs26u/lZIbPPlyjzTe0Xg/ZDk9AUw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(346002)(136003)(376002)(39860400002)(366004)(2906002)(4326008)(83380400001)(6666004)(316002)(38350700002)(2616005)(38100700002)(36756003)(8676002)(956004)(8936002)(26005)(16526019)(7696005)(66946007)(186003)(66476007)(66556008)(478600001)(5660300002)(7416002)(52116002)(6486002)(86362001)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?ijmlbXB3IDw/i+V9PHUdy+Of7dTAQK?= =?utf-8?q?ItYBpJI0vZ//wK5V1NgUl3KuHzqSv2x/p3TuWJxuOE+t9anOrKF4Jc62jv5e3Nr/x?= =?utf-8?q?URgqGNfu3KATauWICA1NmpT3rIMVcNWUi2gNOk9idP7PCLUamVIgcRu0NlvA660Zb?= =?utf-8?q?4Iw15isOqihB7Md2wtroqGWn9G78Li+sbbpVe05THCyXdSjdfXhJ0yBAul2yFV58F?= =?utf-8?q?/lFbzvKYaCMoqzsyXkvn/FZ11Bfgq/O35uT6rbhIOuT9pI86epSwX9ytacXc6H6Nu?= =?utf-8?q?mR/oUZoVss3YfP4f8JIlyeQQt6l6JgKhfqKizmfMJhEJgc33rPYEczU77TmbsWu4c?= =?utf-8?q?AXYiDojg7K5qP2oYKO+QK55gV5yLTuKlMZeZdM2SCBHVEaEz45zyaG/CsduF7sjiJ?= =?utf-8?q?alXAEDbSm6AnqQMTySP0S1RdsmAyc4DcCEwaBUQPGew8efzEZG7XkB+IvEt9PyNB4?= =?utf-8?q?YoGAI2zvHqZPW6VN+oGuNGqsCqGjJSdnd3wDnyDLy6Yq2ei48ZmROPXDfnkMwDi+z?= =?utf-8?q?rJnATltc9KujX6p9ofpLFJzR2tTV3z1iWQtlVv9XTzQUJlVgyBNW26wMSZzzKwCLo?= =?utf-8?q?xSQ5AytmhTfvQqOUwsSkd/SwFQRaZIWDNs31BeVIY06CO9vQjmONm+F3tHuZPaELX?= =?utf-8?q?1Z1iRVh8sH2mcxN1PPv1rstplue4OlFo+VhHT8rt4UsP8rglvNgkaztLtSOICWjZa?= =?utf-8?q?pxX8AQJUz4t5X4cmVKuM7i8NIc3ycmt7Xn3QfhbQC7DmSQKBMnpopKrl/2OUFV92M?= =?utf-8?q?FvmcLGQPuBFtE6hb6diTce8RWlWAkhLfXLCQzw4jUPAIU8cFZlrSxhBsJ3iPju6CH?= =?utf-8?q?2gqV5LSkoKZFOt/GLbR7GpUJHrnG0Z1Q82yAIwRSPHX+qlJ8WOnrLY9JzX6JjDoD5?= =?utf-8?q?Spc6JZStPflgK425duJljqdaRKtKSDcL6ZBRDoiia72vW74P2F0UKQC9QC/xyOCFw?= =?utf-8?q?mPsiekBkl19t98hhIX2YkUoOUOI89l2VsAPregDw9V8luM98gWWYqk/4fJemdpEXW?= =?utf-8?q?Ybp04sowSg5HzkwOtd+sYP7lctF7Ep4hnjcZlspxhPxi1fnGR6qepOQBlpLKE/O1d?= =?utf-8?q?wmajiEcKbKn70YLFuuc0YO8+lwsShiP/nyF4dEuieFnsJ1VZD5DG84SvXcJvfr02z?= =?utf-8?q?1gLiGznL9b5KCQYal6TKEV1Yomqg+U1ZLh0K17dRRAwnkNB4M09BmFOYA5lpf5nn3?= =?utf-8?q?KheKlm0cFcfX/msOl2K8XyF+xPZXIMfTTlp2nJbNdj6n7DABN93KZD7Mx85uf8oFd?= =?utf-8?q?DkosVMHFkuDwMH?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0448f58-7341-4970-a3af-08d90026c2cc X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:54:32.8213 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fN5VjtUkQyeVrOy57GfleTWx1G4mtiqmA5/l/lFY+/I8MscXz7UEsJIiG7ZuhoW9XbMqecGMK0aARHhsfpRv4w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4384 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command is used to finailize the encryption context created with KVM_SEV_SEND_START command. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 8 +++++++ arch/x86/kvm/svm/sev.c | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index 3c5456e0268a..26c4e6c83f62 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -335,6 +335,14 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +12. KVM_SEV_SEND_FINISH +------------------------ + +After completion of the migration flow, the KVM_SEV_SEND_FINISH command can be +issued by the hypervisor to delete the encryption context. + +Returns: 0 on success, -negative on error + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 30527285a39a..92325d9527ce 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1350,6 +1350,26 @@ static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) return ret; } +static int sev_send_finish(struct kvm *kvm, struct kvm_sev_cmd *argp) +{ + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + struct sev_data_send_finish *data; + int ret; + + if (!sev_guest(kvm)) + return -ENOTTY; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->handle = sev->handle; + ret = sev_issue_cmd(kvm, SEV_CMD_SEND_FINISH, data, &argp->error); + + kfree(data); + return ret; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1409,6 +1429,9 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp) case KVM_SEV_SEND_UPDATE_DATA: r = sev_send_update_data(kvm, &sev_cmd); break; + case KVM_SEV_SEND_FINISH: + r = sev_send_finish(kvm, &sev_cmd); + break; default: r = -EINVAL; goto out;