From patchwork Wed Dec 14 19:40:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13073426 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 8BE60C4332F for ; Wed, 14 Dec 2022 19:56:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32F848E0005; Wed, 14 Dec 2022 14:56:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B8B88E0002; Wed, 14 Dec 2022 14:56:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10B6C8E0005; Wed, 14 Dec 2022 14:56:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F33B78E0002 for ; Wed, 14 Dec 2022 14:56:18 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ABD48140274 for ; Wed, 14 Dec 2022 19:56:18 +0000 (UTC) X-FDA: 80241968436.10.A1452F8 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by imf09.hostedemail.com (Postfix) with ESMTP id EA27D140007 for ; Wed, 14 Dec 2022 19:56:15 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=GiyBOtfp; spf=pass (imf09.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.236.40 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1671047776; a=rsa-sha256; cv=pass; b=VBqEzeRHaoYiV9Uz0Fj1MeQNTWZS4S8ieuZizEN9wK7/SErkAt8dIRRdKBz3AbGB+ol8Iq SDMwFM7aP+NCk2GfnsS5AWDhuqUu8AqVIJAvhlXguHQPH/XRNI408xaSFW1s+N28rL6wjr Tk4K56fvRlAwhwH7Az/P+AjC7ThbwwY= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=GiyBOtfp; spf=pass (imf09.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.236.40 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671047776; 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=88WHvW9ADwXvsGBtRWmkyKTWFmgVWRi3HBKItCn1SNw=; b=4i0dGqF8hzv5D8adT0AZY3f7x0qdHfBgUoCEshJrbfhxkHpD2vscPbSElW0OvTvmOkA304 TumuOmPAMRGee6ciDLDq2Mj2ElfJSez5m+2Ea126dgv5xqT2ffCGMQ0BdkGrMyTspnsYTX awpcIKwODpF621oCbeMFzIC+smHxFlM= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dAr3vpwryknawdfv26MjyM1IFvVy8CD9jUuss1PqPZUwLPdbcHmWj+3afBrVEY2KXjzf6tZPscH7PGoA2QFPrnV4ntGlMY3k1KpXY8oPdzPJr3JmrNE7IHdWWmyRwvDvznDkA9MDKekotdUiV5Y7Jltkc+i6S+QuUjn54QA/fB1in7lrxrpR1YzNkZuk2lhU65ZBtLI8ShFli3ocvw+K4ensbI3VW/+EWCxraxDLut7uNhHB+eFHjmzan39oBmsWIRim2vxdj6SCURipjlVJ+uH1Tu8gbBgLC8IN8P1D+wV1QmRC426uv9ZUk0aV4QWFES6V1Ewxr4qUp9acMzpDaA== 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=88WHvW9ADwXvsGBtRWmkyKTWFmgVWRi3HBKItCn1SNw=; b=AQ6lmeXcpWw5XLxk1B7oKUmzXUSt4eYt1OZaXL3fBkK/Y0LZjgggUthe2G8BD9DGEYJtiVJPBgnQHG7DqL54f3O2Oics5t6nFm5tpaaBQ2uFBiwxHxFhO65vtUk7N6J2qxjQS2GorHCb4kFK5NJVDCZ2LDXacqN/rvnw+prXI6AO7H6tkbv3wdsmzNDjWDh+enXIB650i1O8l3xoSmbl4qb/9hgZWgP3biIUFcN2xg/Ra5BzlsWeV9pX5/nUrTgE8Ip7yowQ1o4YGpm5xMvtk/X81fQ2rKytyzGzXTxKRy54syZ0AQj4tcEmp9ueLIm18XdyVkiDDapQwzepvxp4yw== 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=88WHvW9ADwXvsGBtRWmkyKTWFmgVWRi3HBKItCn1SNw=; b=GiyBOtfphDNB+Ap5T1ka6WhgU7A6mIPhycEseBQqEGBKQi1joRzcQNmB8PvxKK/X0gabGaNqAQeHv9UOX0VIkxbUYBR8ZWNg1ZqWI0p1OvHz9jLs4MiizGikv0SHC5p26i13zNr/6H5NuPHdKveBEm/o0Jrt5jGFfWN9MW8TyxA= Received: from MW4PR04CA0295.namprd04.prod.outlook.com (2603:10b6:303:89::30) by DM6PR12MB4545.namprd12.prod.outlook.com (2603:10b6:5:2a3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Wed, 14 Dec 2022 19:56:12 +0000 Received: from CO1NAM11FT098.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::bb) by MW4PR04CA0295.outlook.office365.com (2603:10b6:303:89::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19 via Frontend Transport; Wed, 14 Dec 2022 19:56:12 +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 CO1NAM11FT098.mail.protection.outlook.com (10.13.174.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 19:56:11 +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.2375.34; Wed, 14 Dec 2022 13:56:10 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH RFC v7 33/64] KVM: SVM: Add support to handle AP reset MSR protocol Date: Wed, 14 Dec 2022 13:40:25 -0600 Message-ID: <20221214194056.161492-34-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221214194056.161492-1-michael.roth@amd.com> References: <20221214194056.161492-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: CO1NAM11FT098:EE_|DM6PR12MB4545:EE_ X-MS-Office365-Filtering-Correlation-Id: 4faf35c1-dc41-47cd-e9c7-08dade0d403c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K+eekyF1/M9vXMssGj0Os608tV/uINsw71NB5lmNxYziPQMo7Kkl2jxT0mBCQ9BwXc751QGb3KveOln4Ab9ppZAEQjS0yoMpyg9mVJpA17eSFtmMEzrTfx3TfxN13a22CmyIm7uwJ9p8AZy8QHpC4Dd+qPrIohd6a00Y5BvnQvrgAEyD5GG2pFlXL35pXYCJCNoDjl0tHhxx09f6h2BlMfVmNDBITz9Hn+LJnRIq3C0xgGtHRyH4so6bAAGBOPKTn14JpKvS6aymmbo0ucqkolsfgAFgUf7sK7P/XLL73i56tIAOe6ENUh0GMODAJk6EVtKxhbbduiTcIv3/LTWLjM0Au8lKh+YES/TjOvc1w3Egvg1F9qOu1KSPrVCVslldLQn8GhMOiD4Q0kJFCd58y6436DF0kD3p2TiAxj1weU3/o++3185AtpZeryy28/KZwgbayQaK+/hru3hj3bNxLg81Gupgw7iA8kC9hslAO5Jkyno1OpJguRDp/WTv+mNd5viPdCyaUgM6R1GguQ4btGsMLfXP8QaX9An71Jdt8HRs1GC/vu3F3u6At6t8/hUmUHi8XoUxNOBtOt7mikRaAbkGsJ0BIwX8ACbkk8o10zOf170PoRZEooq2uYL+E3xmGV3jOBrYrzmxKcE+MPi+ZGZiZoXO3mb0rkiX+7KgW4Ahk9a2MVMLqvK/M+MnSKC5VIgUp1HVSIHzCM6qB0iWyOTsIDCjThsxuxLSbv/mI8A= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:CA;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(39860400002)(396003)(346002)(451199015)(40470700004)(46966006)(36840700001)(47076005)(336012)(81166007)(26005)(1076003)(2616005)(83380400001)(16526019)(6666004)(82740400003)(478600001)(356005)(36756003)(86362001)(186003)(426003)(82310400005)(8676002)(41300700001)(4326008)(8936002)(70206006)(70586007)(40460700003)(54906003)(2906002)(40480700001)(7416002)(44832011)(5660300002)(36860700001)(7406005)(316002)(6916009)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2022 19:56:11.8615 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4faf35c1-dc41-47cd-e9c7-08dade0d403c 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: CO1NAM11FT098.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4545 X-Rspam-User: X-Rspamd-Queue-Id: EA27D140007 X-Rspamd-Server: rspam01 X-Stat-Signature: 3oce6om9imb1cf4jyg8bjyukquu7ufoj X-HE-Tag: 1671047775-23223 X-HE-Meta: U2FsdGVkX1/3hsasesJAeay2u13m5RnOTFJVCUf0sCb4rKTpJmAlNKVEDh2+tcBXR3EU4/Vg/sG/rypBvlqXiBeo/WZRqBcBN8kdJQIcGtDIu4E0ilGsjc+8Fnj2gIESvj0d4ThTYP+7TDrhAJF6Kb1iox9sROEL3wWSSq+ds7O6TmICc8K6SztVXp3gHKGXnEW5vBHN+eMYqYg03uriZk86SOsmUw/fFohU9nnPio5J/vbd7TBNnI35Zen+42HwdlIAIkJSH1HcihKQkuMiAXbR3FDJlLDxoSa6ap+/ZZs/nUCnJN1kcPlesM2KMMcebqsZuaZFB5unGCyk7mGy61FIHpV5RUYzEq/OhJnjQ40o4svOgho5rIaE4dh+Bo6I1cKRD3y2aQvoGC+BfjRwH+7RmSwswwiS+PMdhX3QYYyBQy1WWRsfGj+DhyC3ZccMhScMqRvb0UPcNjhm9Raijku0AodUyxlwb3AsZSsS6PEbWDYWA+lobHU8EY+OdAS59fY7IX/A3N29mq/rmquG+K5F0A7sXRGLC43pUxKd0m2RWb3NEp5XhidZQPINnN7h40tF/1zKmkY6VeyKpgEq1WJT9bt7eEFCg0IexXj/QqmSkpbIwBQEg0zTRDCdljPNgd8zKE3DrZwfrJeKYF3g8LVtiOBSYvDhrVdu26WOUSBXQYnjSbylpGIvEkzDOs2UeUv2QOrme8hHJEqH7dJAgiC0/wVOwHVeORt8hajteB8BrMax+42fc5Gzt67UcLMP1VpJJZt1du9h0ofGb2kIl55b7MKl5ey1Uj6HJSYZMKqg3s+2CwQiNOZyyMmw0ltl5u//H42BNSvZs0E2vkVP8X+jvTdgCZkLVBQiKjXl7YHgRHpG2PAq+FyXzglUPOu0KHfdS/7kBy2F4BgblUCJqxskMJDo+119bMS8FHzQbAoHKa98dO1JwMkPXG6RqmIO8RKqouQBEMAvGh9Njas Dafm1UQz MjlEW 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 Signed-off-by: Michael Roth --- 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 6579ed218f6a..244c58bd3de7 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -57,6 +57,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); @@ -2698,6 +2702,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; @@ -2910,6 +2917,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; @@ -3009,6 +3032,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: { @@ -3169,15 +3193,31 @@ 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; + } } int sev_fault_is_private(struct kvm *kvm, gpa_t gpa, u64 error_code, bool *private_fault) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index c760ec51a910..cb9da04e745a 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -198,6 +198,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;