From patchwork Mon Jun 20 23:06:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12888454 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A41EC43334 for ; Mon, 20 Jun 2022 23:06:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D75296B007B; Mon, 20 Jun 2022 19:06:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D24536B007D; Mon, 20 Jun 2022 19:06:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B768F8E0001; Mon, 20 Jun 2022 19:06:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AA0416B007B for ; Mon, 20 Jun 2022 19:06:37 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7A451205D9 for ; Mon, 20 Jun 2022 23:06:37 +0000 (UTC) X-FDA: 79600150434.09.A5340C7 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2071.outbound.protection.outlook.com [40.107.220.71]) by imf30.hostedemail.com (Postfix) with ESMTP id 03FB680016 for ; Mon, 20 Jun 2022 23:06:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K4ZH3rcUc1cGp0a/kleGE8EA4NL/a8vCUSzFM0n9Tnx7q2joOUG5zueN9Te82EA8C3JvR40ldWSo21/IKNYm2Oh1YW7PXMlJ0WA3o1eo8Fv+NPwUp+/d7DjHMkLINsfemRhABOUGBkp3ohkPw7bgDZQDvCUgKvLiz8Vn8gYLMid8Y5xWVDof6OlYV6uvhfnn/JZYuvSv6M59LoWtfnoLDIVHqacIXJH5Hj7UsMHTd3G7Hd/o4ZD8HZkQJC7xMzT1VIE5/9aim/iuouG2DO76F9Y81ctAa9PI7DsSPa6lBhukYo32PbQVDbHFfHdfQB9HCPDs2U0nGJQ7F3IEbiDIlw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3tZOxG7AgzCZe0+1CVlFh8fB6J+bbifNVbINdstdbH4=; b=X3BKPE/YsWIu+9V7KTXu3jW7xvJ+ZdTlRYAgK0L8/ZgNnI3gvcA1lqbDvFdxfDZiiptYbBIUkUaHdbW9lhkQSILdQsACr8m75MpeVBooz7mP0nxirYMF76t2gQqWmi/294n0qn4JCZ6ip/q4Ika8KufyRFYBctMkuc34s/WA8dueKOyKk2k0rQ6BBXScqdCzUgIg7yByuFzAMe+tPxgqnzluHSvH2ZduJdg+2SwVWbrVkv4iyP958ZsLNglnT9JOae77HMoVrtwG0HZ66C07K1FKisDSMCNQncYBM9pc1QcOUSJ88S9nnZMTc4EXK1q8C7cfIgthLCP4J0EcRwEKcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=3tZOxG7AgzCZe0+1CVlFh8fB6J+bbifNVbINdstdbH4=; b=OYTWbivhCvGGQX+dD/Iy7xgPY73aICG4Z69UTDIynptMO1KxD/wiVbYaTjbFh7dL+GMwxDIG8VYmQTnUHPnDOn0eTy0QCAStwhJEDPUtkBU/IXYTWRlgyARkVFaMo+9xDZu5awHKj3gGCiS1fVjbbJzzvNAmFoRFMf32DGQFzU8= Received: from DS7PR06CA0004.namprd06.prod.outlook.com (2603:10b6:8:2a::19) by DM5PR1201MB0010.namprd12.prod.outlook.com (2603:10b6:3:e3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Mon, 20 Jun 2022 23:06:33 +0000 Received: from DM6NAM11FT025.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2a:cafe::f0) by DS7PR06CA0004.outlook.office365.com (2603:10b6:8:2a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.14 via Frontend Transport; Mon, 20 Jun 2022 23:06:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT025.mail.protection.outlook.com (10.13.172.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5353.14 via Frontend Transport; Mon, 20 Jun 2022 23:06:33 +0000 Received: from ashkalraubuntuserver.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Mon, 20 Jun 2022 18:06:30 -0500 From: Ashish Kalra To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH Part2 v6 19/49] KVM: SVM: Add support to handle AP reset MSR protocol Date: Mon, 20 Jun 2022 23:06:21 +0000 Message-ID: <98644cfc4cdb6be5a0d51776d422b00662121282.1655761627.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e9fde532-2d22-4130-15b6-08da531184cb X-MS-TrafficTypeDiagnostic: DM5PR1201MB0010:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yRpyPMW6JJLX++46sBvIrwlEm34wg72ZnWTR1iMuJ3GgS88358FkMc4NV8bC+FmpepnuuPhhKpcZuC3PM/DP/pHsZg/n4Xr+mhOc6Cv9X0zRk76qALTlyJBdqO0/mS3LtE7tcAXKLaQvW9PoT12oGvJl4SWfXPgh16a9Uo6zj4SFTDy+L4qH9inpl+dtbhWHe4Dwnl/wkDujkIHJGItzxMMnftk+k5zWKFJ6K9Qj349CL3lQF061zm6RE2sOAeXLf3GeLpfbqJQ0hfQryFOcYdvaUV1QN9120UfVdomARdG6WYiBhUzjQC3aOIJX3GVmg7Atl22vxx/bLgq2WqrVaXlI6+mbkWxFi40+yl7px+lJpOJUQJJYN0BGkq2JuC/LmpchK0zfVI3rAR7LwjHkTAsbKLtJTwfn+Wbibnhz5l2rN/DZZv0HejlmZbwlFtsfCr72QrpvT0taa2Gezm2r8W08mOB2/ZT/EJFlMRobzw7Z7bSKcqrf26v5a37DUWhI2v22R6105Ky3/u0Fq9++IQH1GWt6znBkicWl9rWFxZ9NNTSXhE/DfZ3nDMPh7Z6pzniBCnYhHoodYlJpuBpSBJfoVJwshE7xRyt/qgM4uTqSiYh+ucZxK2WsN2QAigIkdkNme48y4mfe684uqZV3rvJgItntOPiomQkZVXoT5VHVYmYavzkogcV0aKy9pEz8x/huNV7jl1IoIY6UalzNqgA3ffKvdwADDPR1NXGQWvx2HiBjeWf8H964auGjbKGlcdBWsve5ifuAYvmjZc7dew== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(346002)(376002)(39860400002)(396003)(136003)(46966006)(36840700001)(40470700004)(336012)(82740400003)(81166007)(16526019)(426003)(47076005)(7696005)(2616005)(41300700001)(26005)(186003)(6666004)(356005)(83380400001)(8936002)(70586007)(36860700001)(40480700001)(70206006)(7416002)(5660300002)(7406005)(82310400005)(4326008)(36756003)(2906002)(86362001)(40460700003)(316002)(8676002)(54906003)(110136005)(478600001)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2022 23:06:33.2704 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e9fde532-2d22-4130-15b6-08da531184cb X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT025.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0010 ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=OYTWbivh; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf30.hostedemail.com: domain of Ashish.Kalra@amd.com designates 40.107.220.71 as permitted sender) smtp.mailfrom=Ashish.Kalra@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655766397; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3tZOxG7AgzCZe0+1CVlFh8fB6J+bbifNVbINdstdbH4=; b=JzjkkCd4ZK6fYPJW5nD+aa3YpYnh6/fo4XLFy55h/UrBLnh6D640A3KBw9e5y6gAAGvIxj hna9UWpDxwcn5N5Uu2gynmJ7DvwpfR5Rfx1k8KQcRJ/XVAeQ2aZHHeqI6iU9rfJhWkvail FY1ULYRgZxyVqtKgPyB9W81OGQfTiAU= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1655766397; a=rsa-sha256; cv=pass; b=ku3+aNsiwLaEz0c+a8Ugq5Ily7ZJHzIvnSbsl7v5TL9YL8G4Iju3LQPFgyRPL4ZlMSCaT9 +HgkRLSvkNKmb1kVkyZHP3PAbkwmBxdqvwVGs8HKWnfD1KRGRP22y1HUJtJEBb7AramZ/O wSksC4N0t0m79vbzGI8+ydDybhoCd/s= X-Rspamd-Queue-Id: 03FB680016 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=OYTWbivh; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf30.hostedemail.com: domain of Ashish.Kalra@amd.com designates 40.107.220.71 as permitted sender) smtp.mailfrom=Ashish.Kalra@amd.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: tjjtcpr3bcd4yuusjyk1aym1jrkgay6i X-HE-Tag: 1655766396-149086 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Tom Lendacky Add support for AP Reset Hold being invoked using the GHCB MSR protocol, available in version 2 of the GHCB specification. Signed-off-by: Tom Lendacky Signed-off-by: Brijesh Singh --- arch/x86/include/asm/sev-common.h | 2 ++ arch/x86/kvm/svm/sev.c | 56 ++++++++++++++++++++++++++----- arch/x86/kvm/svm/svm.h | 1 + 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h index b8357d6ecd47..e15548d88f2a 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -56,6 +56,8 @@ /* AP Reset Hold */ #define GHCB_MSR_AP_RESET_HOLD_REQ 0x006 #define GHCB_MSR_AP_RESET_HOLD_RESP 0x007 +#define GHCB_MSR_AP_RESET_HOLD_RESULT_POS 12 +#define GHCB_MSR_AP_RESET_HOLD_RESULT_MASK GENMASK_ULL(51, 0) /* GHCB GPA Register */ #define GHCB_MSR_REG_GPA_REQ 0x012 diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 609471204c6e..a1318236acd2 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -56,6 +56,10 @@ module_param_named(sev_es, sev_es_enabled, bool, 0444); #define sev_es_enabled false #endif /* CONFIG_KVM_AMD_SEV */ +#define AP_RESET_HOLD_NONE 0 +#define AP_RESET_HOLD_NAE_EVENT 1 +#define AP_RESET_HOLD_MSR_PROTO 2 + static u8 sev_enc_bit; static DECLARE_RWSEM(sev_deactivate_lock); static DEFINE_MUTEX(sev_bitmap_lock); @@ -2511,6 +2515,9 @@ static int sev_es_validate_vmgexit(struct vcpu_svm *svm) void sev_es_unmap_ghcb(struct vcpu_svm *svm) { + /* Clear any indication that the vCPU is in a type of AP Reset Hold */ + svm->sev_es.ap_reset_hold_type = AP_RESET_HOLD_NONE; + if (!svm->sev_es.ghcb) return; @@ -2723,6 +2730,22 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) GHCB_MSR_INFO_POS); break; } + case GHCB_MSR_AP_RESET_HOLD_REQ: + svm->sev_es.ap_reset_hold_type = AP_RESET_HOLD_MSR_PROTO; + ret = kvm_emulate_ap_reset_hold(&svm->vcpu); + + /* + * Preset the result to a non-SIPI return and then only set + * the result to non-zero when delivering a SIPI. + */ + set_ghcb_msr_bits(svm, 0, + GHCB_MSR_AP_RESET_HOLD_RESULT_MASK, + GHCB_MSR_AP_RESET_HOLD_RESULT_POS); + + set_ghcb_msr_bits(svm, GHCB_MSR_AP_RESET_HOLD_RESP, + GHCB_MSR_INFO_MASK, + GHCB_MSR_INFO_POS); + break; case GHCB_MSR_TERM_REQ: { u64 reason_set, reason_code; @@ -2823,6 +2846,7 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu) ret = svm_invoke_exit_handler(vcpu, SVM_EXIT_IRET); break; case SVM_VMGEXIT_AP_HLT_LOOP: + svm->sev_es.ap_reset_hold_type = AP_RESET_HOLD_NAE_EVENT; ret = kvm_emulate_ap_reset_hold(vcpu); break; case SVM_VMGEXIT_AP_JUMP_TABLE: { @@ -2966,13 +2990,29 @@ void sev_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector) return; } - /* - * Subsequent SIPI: Return from an AP Reset Hold VMGEXIT, where - * the guest will set the CS and RIP. Set SW_EXIT_INFO_2 to a - * non-zero value. - */ - if (!svm->sev_es.ghcb) - return; + /* Subsequent SIPI */ + switch (svm->sev_es.ap_reset_hold_type) { + case AP_RESET_HOLD_NAE_EVENT: + /* + * Return from an AP Reset Hold VMGEXIT, where the guest will + * set the CS and RIP. Set SW_EXIT_INFO_2 to a non-zero value. + */ + ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, 1); + break; + case AP_RESET_HOLD_MSR_PROTO: + /* + * Return from an AP Reset Hold VMGEXIT, where the guest will + * set the CS and RIP. Set GHCB data field to a non-zero value. + */ + set_ghcb_msr_bits(svm, 1, + GHCB_MSR_AP_RESET_HOLD_RESULT_MASK, + GHCB_MSR_AP_RESET_HOLD_RESULT_POS); - ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, 1); + set_ghcb_msr_bits(svm, GHCB_MSR_AP_RESET_HOLD_RESP, + GHCB_MSR_INFO_MASK, + GHCB_MSR_INFO_POS); + break; + default: + break; + } } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index bb9ec9139af3..9f7eb1f18893 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -186,6 +186,7 @@ struct vcpu_sev_es_state { struct ghcb *ghcb; struct kvm_host_map ghcb_map; bool received_first_sipi; + unsigned int ap_reset_hold_type; /* SEV-ES scratch area support */ void *ghcb_sa;