From patchwork Tue Dec 8 22:05:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11959923 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 561A0C2BBD4 for ; Tue, 8 Dec 2020 22:06:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0FF36222B3 for ; Tue, 8 Dec 2020 22:06:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730920AbgLHWGp (ORCPT ); Tue, 8 Dec 2020 17:06:45 -0500 Received: from mail-mw2nam12on2074.outbound.protection.outlook.com ([40.107.244.74]:34912 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730486AbgLHWGm (ORCPT ); Tue, 8 Dec 2020 17:06:42 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KvmzFZp2vVvO7DTSbWAgMde4DOy5jSACGsXF9ZQDgGvAfdjkQ+eJUln4OQxZmYFsBzt5siWKJ3doAzxWQkAeQhwMtbftn31UEsVqzPfOLqMjAF07dTcIzqOUfG/P82MRubd0L++OM3eCgbyzLQEtlkoIxQyk2AMfHCBiP/Ufwe6cYytbgh6lUU5yq/xEWONr8U80qbFnvn9V6cVxxh3l5nDrq2yhTQtnFXE/pDDd/8TvKJI94fW3Pr4asZ3U4etYkw+wMcxz6wDDckEAUzzFHfHtqTAufWtfV/0limQr/kigqeW5qKU/32u2ACHwl9IJtUvW7NV9ZVQcFaCDwsMfzQ== 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=M75rSIoIjHyp8gjWTs/3Jm6+mwNRo44GL4tGH8ct4lA=; b=DEQpy4LrRZIEJyYwLCPkUBz4iwoHNp4jzcuuDq+4CL4DxNInveRmfPbH9WbyzO2JdDXjDpdchV4+1p76AmGx6ugd0smGR67QkG6mIbWsfLdBYqRsHXnt1VmkbuwHxhbsU3EYQoHvAeFQHlz7RRoyDjm+awG36CUVWUN4B19OKOoePSmQNDLiqnOrUkoOCXbanYUcktVojnEoT610vUJKPpcwYZv7Pb0YgO6RXPw4cHE+OMzbCkzCw4F7EuyRGk2t9LVfA5Faa+UZHaC83A0DsMZfr4NV3yLBJs5M4Dzf8lG6USatSzKh2HP9ymRZg+xElLGh1Lv3Yb6YMlQACZyWig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M75rSIoIjHyp8gjWTs/3Jm6+mwNRo44GL4tGH8ct4lA=; b=gdfR6GmfRd6U5VJq7ciyQhjGZXm0p6Z9BP2hgOw8lkA9hu9UlksMIKDo+MLHZksJQr/4WqcHhuONpEXuoE8gTqfUfLoa+486lL/pJL4aOMVbVH0Upxp2KsKcHUF2wBIq3Q1wmZ5BgT+utBzs/nbnpCTNhyMfK+o9DtNd4UezhE8= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SA0PR12MB4415.namprd12.prod.outlook.com (2603:10b6:806:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.23; Tue, 8 Dec 2020 22:05:50 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::d8f2:fde4:5e1d:afec]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::d8f2:fde4:5e1d:afec%3]) with mapi id 15.20.3632.021; Tue, 8 Dec 2020 22:05:50 +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, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v9 06/18] KVM: SVM: Add KVM_SEV_RECEIVE_FINISH command Date: Tue, 8 Dec 2020 22:05:38 +0000 Message-Id: <97f0da36644b54701cb8a85b5d9394585da3a66f.1607460588.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: CH2PR05CA0007.namprd05.prod.outlook.com (2603:10b6:610::20) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by CH2PR05CA0007.namprd05.prod.outlook.com (2603:10b6:610::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.5 via Frontend Transport; Tue, 8 Dec 2020 22:05:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f273f058-e10c-4e9f-c216-08d89bc56c64 X-MS-TrafficTypeDiagnostic: SA0PR12MB4415: 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: xvfvOQXNvfEoQrW+tK7kW+NQy0mPgZEks7Z8YZmf+lnIBbjSZS+IAFc44whdb1q1MolZzyz6ZZcnJ5efrLGN0Z3rrL/rlp/o2FcM2nqkWtwUhXm6JSa/W4EpTyhnI5p67W+YPb9ojt9LGdmv6yYwQKoefjEp8hIGNdQP6QwbrY1LwEQnVuHOq8ICizzw5byX7cjPaFtiLZ4s5zErkrS+uNjNqilUT/dke73+A1dO634gN0CqCiUsV7oHANu8ioy60dfi54iqwVsVZRHIbxg17KRsBJDsCw1UFtGeIq+FYju1pP63xRrv95e1CZBE7N0oCY29/dGkylaZK4dEB2ZAJz4q0P3L8jSgVDQX1D3butkNR8jSirZ4sX8hyeVT0pds 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)(346002)(136003)(366004)(34490700003)(83380400001)(186003)(4326008)(86362001)(6916009)(7416002)(16526019)(6486002)(5660300002)(66556008)(8676002)(8936002)(508600001)(7696005)(52116002)(66574015)(66946007)(956004)(36756003)(2906002)(6666004)(26005)(66476007)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?+ei7nvjVkmEPjApZTBaw3pAtBJUN4C?= =?utf-8?q?V1lmMV3JXUH627DEETyh3eAPV9xET9c7C2Z0CnhU9O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4SjvD8Igb0jy48EHb0hrYXm/QFvZ?= =?utf-8?q?bClBfUyfv0MsgKO2iVk?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2020 22:05:50.1560 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: f273f058-e10c-4e9f-c216-08d89bc56c64 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kKjgp2+6LTMGroCIAZ1hLx3JMCEIU97RlbH6c7mW4V/QM4gq1Kx0W5vPiUVwxfAJBylYl7neQuFTzg71RRfBpw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4415 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh The command finalize the guest receiving process and make the SEV guest ready for the execution. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- .../virt/kvm/amd-memory-encryption.rst | 8 +++++++ arch/x86/kvm/svm/sev.c | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index da40be3d8bc2..1f7bbda1f971 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -375,6 +375,14 @@ Returns: 0 on success, -negative on error __u32 trans_len; }; +15. KVM_SEV_RECEIVE_FINISH +------------------------ + +After completion of the migration flow, the KVM_SEV_RECEIVE_FINISH command can be +issued by the hypervisor to make the guest ready for execution. + +Returns: 0 on success, -negative on error + References ========== diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 34240c022042..edd98a8de2f8 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1341,6 +1341,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; @@ -1400,6 +1420,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;