Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3286246iog; Mon, 20 Jun 2022 16:11:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tsei2gFhzObqB2roRtsXqOfEaxiNVqFCLWn2WfoSX3TR89xaA/YovGT6B3jhymknW0Sr0X X-Received: by 2002:a17:90b:4d88:b0:1ec:aa96:ac92 with SMTP id oj8-20020a17090b4d8800b001ecaa96ac92mr7730406pjb.196.1655766683204; Mon, 20 Jun 2022 16:11:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655766683; cv=pass; d=google.com; s=arc-20160816; b=P7/FoMBJBYy9n7fXPGEf4CUNGbj6X0XPZr/WY0FDhU3Smknv9qsH4sTbxR6THRjLYX iZ9pTi7Gd04NTKr6RH5EDy4jv0r+4Hgm5Y7BkqubjrYdp7JD49r+xHzkUw9jMlHlI6B1 6v7jpENisZItti1wT2J6tcCVtpaKxjupR/oil08t6vCrBaYahoqzSuLzjaK12b0xQESs dSKzmZB9qXDSClNTP+ETPmlAGvMeIlsj6dSm49oAL6FZRu+jTr3OdR36U3nz7s9Xv0Xq AtpaPTJg1YtL2s/iBeqNIaARa89Nm2RSfyy8hwYD9SgRTfSVCpukabZK/8+spIumJZ82 OZew== 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=3tZOxG7AgzCZe0+1CVlFh8fB6J+bbifNVbINdstdbH4=; b=Lna0YW09gDKhhsa0+rS+nyqdKXwQc7GmlcQU2xtxxdUpoEPIqKXAveMBgvVXDEhjfU AzUeIF7frLwEI/aG/0hfgWhK4y7Ia2pvGF9S+z7RWWVcqyVdgU7n4o4cLQzSYNnYBJNX 3CO7oeCTPj/Btm/3YrelgyVxhj91h7RtfJn+wwXMX4MHh3Mfow3Shrj7MBIKUsq39tpu 2EOMjk9yJArAqRXvbb6LzSEXuJeZC0uWpnlzVs3ohgnfB2TP9Fgut0bng7tzxqSzg8ig et6gFNlwoMrq/qKOmZ1sy4Vf38r6NHVc9+c7FPReYtTqe35Miy2CL5g4K5TJ5gJePm2N SXqg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=OYTWbivh; 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 a64-20020a639043000000b0040cf2e6edeasi939180pge.307.2022.06.20.16.11.11; Mon, 20 Jun 2022 16:11:23 -0700 (PDT) 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=OYTWbivh; 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 S1346464AbiFTXH5 (ORCPT + 99 others); Mon, 20 Jun 2022 19:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346466AbiFTXHj (ORCPT ); Mon, 20 Jun 2022 19:07:39 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2086.outbound.protection.outlook.com [40.107.220.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 361E923BE9; Mon, 20 Jun 2022 16:06:36 -0700 (PDT) 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 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-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 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,T_SCC_BODY_TEXT_LINE 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 --- 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; -- 2.25.1