Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1580788rwb; Wed, 14 Dec 2022 12:03:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf7U+998vDVglvG2FfDspsHwUUkemEMMppDhV1GclrRc1FgzwBirKtSBQHMXt/ZkPBi2loHA X-Received: by 2002:a17:907:c08d:b0:7c1:7c38:f079 with SMTP id st13-20020a170907c08d00b007c17c38f079mr12608717ejc.71.1671048200999; Wed, 14 Dec 2022 12:03:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1671048200; cv=pass; d=google.com; s=arc-20160816; b=voHHP0Ec7YsrBUk2abPJ0DbZztJtwjtrHAp4rAftZKJNnL8PvRhoSGOQLYXIkkWM1Q AWP6/3PF88gbA//C1O0yE/8xXrmjKU1sgSOeeX2XXEat4sdq0GV7MdUQThm8kyXnzMWF olAX1kNYop/5HlVW/Rn77DRIYbtGBP2yaIrAqipE3YKB9wA5udr41LDt2xpeiZjSGVQ4 WBWwMcN/Bwpn8iS+QOpnUnnDHgcWy7zvSBUp93kmjvp6vsC+G/KZQkpodGLiVMsW66RV 6//R2mHMBHzuLcsl8Z/GydF+ITGGxIHaIROeyFxf42h4okF2tB4qZG7UTYdNh1g/rBW0 fpvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=88WHvW9ADwXvsGBtRWmkyKTWFmgVWRi3HBKItCn1SNw=; b=zWiJpQ8xx8l6/6RrxAnFRdRAgAKR+rjR0VGn95sVnH1TBcYwGuWePBKHhzjFbYSFih 6mpi53eNEqIOysqfuIxtYGai+ui9L3JTlD5LOVxWkmMeK6y7kfXAiHFNQ/tp1hXTAuJH DP017nmhEX7hQ3FiDJlGyJUKj8hYNGXumOK4UuRsHDKt/TDHC+GzeLJ1Wh8fHfMKVOB9 45qfjnbOY7tUoNqy1Od8/FVt8HBkJDKNpFDWYDlCzcXvX/cgFEX1I09bFpgAyPxizlvt SWSQg4fdU7dP5gtLSUwCrqCf6DKcXLKfMq0QrQ9GeFsCIieErhuB0dxBRykxEdAchkEu MpQw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=GiyBOtfp; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k11-20020a1709062a4b00b007ba16fcfefdsi5412285eje.936.2022.12.14.12.02.57; Wed, 14 Dec 2022 12:03:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=GiyBOtfp; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229469AbiLNUAN (ORCPT + 99 others); Wed, 14 Dec 2022 15:00:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbiLNT7F (ORCPT ); Wed, 14 Dec 2022 14:59:05 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2056.outbound.protection.outlook.com [40.107.220.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EDF9FF2; Wed, 14 Dec 2022 11:56:15 -0800 (PST) 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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; -- 2.25.1