From patchwork Mon Oct 16 13:27:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423297 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 2836FCDB474 for ; Mon, 16 Oct 2023 13:34:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C41548D007B; Mon, 16 Oct 2023 09:34:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCA238D0001; Mon, 16 Oct 2023 09:34:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6B1B8D007B; Mon, 16 Oct 2023 09:34:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 97E668D0001 for ; Mon, 16 Oct 2023 09:34:57 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 65594A0916 for ; Mon, 16 Oct 2023 13:34:57 +0000 (UTC) X-FDA: 81351420234.30.6FCEE72 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2067.outbound.protection.outlook.com [40.107.101.67]) by imf17.hostedemail.com (Postfix) with ESMTP id 4682740016 for ; Mon, 16 Oct 2023 13:34:53 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=SV0mMhEd; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf17.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.101.67 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697463294; 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=AE4GksiataJH38qe5d8aubQhmfPm1P38EUM2AdHOb10=; b=qFip2AqlAm+LHYINV7NfUCWXBDU3QYN9ddQvMdGav6qprBUkk+G+djm9MzOxOUzAYjN4/A W18GCd2fQA2phJBofGw816IXqSs41J/41JAs0X20NrRvrjF1hcuFw+XMDpeJ/sjY4eYggl j42sWslKhlJF2whBwJk+fJMsC+b8XwM= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697463294; a=rsa-sha256; cv=pass; b=pQzoPE22YfDA2blV7VGDk4QUjp2OhahjtlMUKwol21S/opV7VaKReaatcrOMsL9zPMt6U0 kVLKb6ldhCnxoHRWnKvv0xDqfmYCC/xKBAeGA5zRzyB+/dC/0UICQb/nnwPkc784VRZ5Fa W8/paImBrv7/G7Hy8H9M5C9cWm8DOJY= ARC-Authentication-Results: i=2; imf17.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=SV0mMhEd; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf17.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.101.67 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZPyDDeXog7cARI6NkEIBt3/xqvPPbGG588ySXcVgDK88cwheTqVYEqWSvxb/nrYbFjsEszujcyI0DT5K7UFBPGteKEmzHzClqbs0AZ7hFWeRNFjI2WBMHH4gA0Z1yk2Pp7WL/PdiAwEspKCFaOJw09cPw+qFxfcHOPp7ctdhHd5/CxbFOlmx2JCHfXfaWtTUZptACQCpZ63kzdgG/jttGDUEkJXOrwDqy+NuBzI4CNtYjOWHR0DbScVgTz/gVd38JxDVdundsDjZqcdTcY4HwclU5lCAatHkGCatN9hQynuSL1lBP4EAobVVsHxpjY9RUHpo56+QykmBCQxSDfADug== 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=AE4GksiataJH38qe5d8aubQhmfPm1P38EUM2AdHOb10=; b=bsm5pBEJdQK+cm69S/MbCHQh3MDuSK6KWa2WqRNKyl9DTyHQ1JAlicQLIU9q3NalCDFDzszNZrcQzVflLRycytj4J0775Cj1feS40+dSsmMcxaviF+l/TbMSONdD7P+WsI6GppMhj0f7Z9dp0CnGpiL5J5YhmpoJRuvLbAchQ2DWG95zN//Cweaa+wtnRaDOMNCfg9bXINWkBi/xg2OFl6AxvYt8dgajgpcbib57241uPHaJeVR+11jDxY8zhotnA3+U63i6ixU7F8FLg8R3Juzbj662AfbxKOCk68olRYNTw3g93R702lGHJl+qM44Q6z3kBtS+IqfMVzlmAqYrNg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.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=AE4GksiataJH38qe5d8aubQhmfPm1P38EUM2AdHOb10=; b=SV0mMhEda7j4gpGqqwEk8VaNrVADgt16gpOjgDtUwjIiE9igk+2Tg+Fzq3rJ9O88OeFnQ9qPy+bFNiFE1PSstDQOfO7Viz2nfjNl8R87HTIVV46ciEKD75qaOEclHlGViyPEVQkoW1UQY1WbbcdTu00sbSMjxg9viGH7bFNX+7Y= Received: from SJ0PR03CA0003.namprd03.prod.outlook.com (2603:10b6:a03:33a::8) by CH2PR12MB4087.namprd12.prod.outlook.com (2603:10b6:610:7f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.37; Mon, 16 Oct 2023 13:34:48 +0000 Received: from MWH0EPF000989EA.namprd02.prod.outlook.com (2603:10b6:a03:33a:cafe::de) by SJ0PR03CA0003.outlook.office365.com (2603:10b6:a03:33a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 13:34:47 +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 MWH0EPF000989EA.mail.protection.outlook.com (10.167.241.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 13:34:47 +0000 Received: from localhost (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.2507.27; Mon, 16 Oct 2023 08:34:42 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH v10 21/50] KVM: SEV: Add support to handle AP reset MSR protocol Date: Mon, 16 Oct 2023 08:27:50 -0500 Message-ID: <20231016132819.1002933-22-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016132819.1002933-1-michael.roth@amd.com> References: <20231016132819.1002933-1-michael.roth@amd.com> 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-TrafficTypeDiagnostic: MWH0EPF000989EA:EE_|CH2PR12MB4087:EE_ X-MS-Office365-Filtering-Correlation-Id: 7af4c1ff-5b88-45e6-9ba7-08dbce4caa76 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CN2Dvujy9XcXqhc6fvW9EZRgl7qxIdsZcHvQu5956o5OtpLd7oFCCaF6fvoivV3a0FktGoTpYNbq95kE/MWwy0hx7jeBJVtDiTc9mDwcQormLQdvuEgYF4XNEFT6fDsxbn6d7aNJ2/KiirGMwcNimE9honQMjrVoIb+5W1QTUkg3M1I+6Pvp3RpTSoKqongaHypQAoU/F2J+FCUkrdZfNMJKwK50LmPuCTNtyqpKMtUbs1OUwzkBZZYpVERQ/D/Ok/WaMYZkCjGqWsC3MllUlKc5HP8wCbBKGmAI3brdSzLgSaFItXUrdHewunm1CJVpME5acJntlG9OYNODIn95/gmA44zGHnf5bXnaeU6kdyvoVYA36XM69zF3SSk/QKPyEXEHSXLnLaMN1Y9MnlLyoAHwkT0JwL6d04fbb/O6vIqnlimszyfOoWKg2taRPN5rtA8wvy7FKooaeR8iPERJMf/wHQBCTfA5NMb9ueiCE3giwZDL1+PMHN2D18elYKyeyMyzP3yVpclb3vv+gARQ+c++O0vLaq64llJ2EtmLFUN+B42XGlhPt6Ga4bpEFPs5fvoID8H5rbm5SOs2amktRE+h7U8uCSe2JsDoBCw1jV1ROnuTrIEG+NBoMnybY0tKlGl1k6DniPWGc7CdIUefDpS5YBsz2dQVRv8X7trieGrVDdSVV6j6yhcjGLDmEqJFxle3CI+iTKbc2DkkrLj+83zWcK+GW1E4nHQQ+ABneobTa+9rMqU7FHLLpcrAX7hglsW08wsJ4Td5piVXovYNtg== 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:(13230031)(4636009)(136003)(376002)(346002)(396003)(39860400002)(230922051799003)(1800799009)(186009)(82310400011)(64100799003)(451199024)(46966006)(40470700004)(36840700001)(40480700001)(6666004)(47076005)(26005)(5660300002)(40460700003)(426003)(1076003)(316002)(2616005)(54906003)(336012)(6916009)(16526019)(7416002)(70206006)(83380400001)(70586007)(36860700001)(7406005)(82740400003)(4326008)(44832011)(478600001)(8936002)(8676002)(41300700001)(2906002)(36756003)(81166007)(356005)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 13:34:47.4230 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7af4c1ff-5b88-45e6-9ba7-08dbce4caa76 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: MWH0EPF000989EA.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4087 X-Stat-Signature: u3gz4nmx58aqiio6mcm1yzn5f8n1ahzg X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4682740016 X-Rspam-User: X-HE-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2Xx+mZvGY5Y1qLnFnU5IOQkfpckAG6syJvEwbn06FYhlpX23j2zNO6ZX8P072tqRHgI7IwhD2D9mKkaZroUysT1TU9ANtssLH3X2V1FcLor33ydjA57NsgRkNoQUaoPTu3/EBhYGqHBgQP3L49sCzwJ9b7nolwf5YZn1pcBxvpxlreBEnh6Y/TBUvtvXXFAE4tB85BFPNRPmsDYfL5bLyYxC6x+RR230cm6mC0xKYbZ2LGMWY2Cn5zaiCl32DnGLAQrCjvV+oOax6pNbgXX+5M= 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 Signed-off-by: Ashish Kalra --- 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 93ec8c12c91d..57ced29264ce 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 6ee925d66648..4f895a7201ed 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -65,6 +65,10 @@ module_param_named(debug_swap, sev_es_debug_swap_enabled, bool, 0444); #define sev_es_debug_swap_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); @@ -2594,6 +2598,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; @@ -2805,6 +2812,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; @@ -2904,6 +2927,7 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu) ret = 1; 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: { @@ -3147,13 +3171,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 c409f934c377..b74231511493 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -195,6 +195,7 @@ struct vcpu_sev_es_state { u8 valid_bitmap[16]; struct kvm_host_map ghcb_map; bool received_first_sipi; + unsigned int ap_reset_hold_type; /* SEV-ES scratch area support */ u64 sw_scratch;