Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5040275rwd; Sun, 11 Jun 2023 21:47:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lxNrOLvzhosESgaSavnb/UecH3pPkluqYduLKbrNuJ2xgbpAEF0ptYBG1Q2EPP6LkI4CX X-Received: by 2002:a05:6a20:3d28:b0:117:2125:559d with SMTP id y40-20020a056a203d2800b001172125559dmr9997749pzi.4.1686545223870; Sun, 11 Jun 2023 21:47:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686545223; cv=pass; d=google.com; s=arc-20160816; b=bgJCAreQfrTft80OVc4tViral5ByeWSRPfMCit7qyRWXbZzv3lKgTgrgT9psGBjAlu bXvGK6WGYymMuABAOAoi9Um68yjvuoEQKSsKHEtQ8P7271wrDTo9e+Ueo4jh3qgSujIL wE+2eYAag6dbT6ORrmUchq/VMuHWQfsfJ6Zzozc4srS6dfHfzuqS/dvaxDXtKgaMOH/6 duEk/AMkafrNFIpawjIyR4aRnz13tqxyGYOtNsyjmJwL0IThHNA3pOaz/LJkCRIEukHc nZam7I4tUGYK4hDvUvEcQ6g19SEg9beVSJnAYLH64HC3zxNDB2f3VYabS49GlZxRs5sp AZuw== 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=8o93p9mYoqybhgkAygPC0Obm+t8oGE9xTvNcEMl5QmM=; b=tE5WiIphGSIZhtKHmLFF1g0YeXSKdQggElvG9PT2uvnocI97VUmUrOeFqBCJgKRoVn zihx/zc9lqU0xMEc9Ed3dlRQBK6r6Lx7zeyajQ0vyL8zV3Eoe3LMCSh212qXPVkFX3Xz QBbonas7n2qIxgXrr0hFZexD7UVwRtGu3CReTPaUOv+VJi56Zs3hui54Ipw8BDzTJL15 yXAm8zESnZCbsWpBrSJYeB8VVuPv8kpnAtZz65orWFWC5LPiJqaQ/nB69IZylu0tgs2y SbKGpBlBJR1dlV3OIpwcwNgoC8Sv144zt+CnZjc4CfBTOj+TcGjDMmMLqlPV4n9mfqGa 9auQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=sJeOJvOV; 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 l197-20020a633ece000000b0052c419dc8d1si6524353pga.274.2023.06.11.21.46.51; Sun, 11 Jun 2023 21:47:03 -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=sJeOJvOV; 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 S234991AbjFLEoL (ORCPT + 99 others); Mon, 12 Jun 2023 00:44:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234419AbjFLEni (ORCPT ); Mon, 12 Jun 2023 00:43:38 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2082.outbound.protection.outlook.com [40.107.243.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61DD210DC; Sun, 11 Jun 2023 21:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O12/pME0uzjckk/ABw6QRC4tnn3lbuYvnXvz9qqT69vKlBPvuW6B2oDifguCp5TKopURcv+wdNufKXytJQUEWENeyohdiWeDSD3XwTQ0X2Twh56saQON8k8tn3NPgsUoB9+Nyf9KY8h5gjT4qu/QoDgpvDZaHshQPJPoj0+aJhbE2jTTXHlNT+Ngup04a9IK4gSZYf8DENeBaJZJePRlypn7ix7dYhDTcBcnbDciP0rrBPRjfG8gfKR96ZNJB4rtgNjgrcQGdiedTTqGP/YweBonTP/k2oiVtgktydCNXy6o4vg3jfEWkIic1UJW0wynXFAdmAzoUFZy4dJ6/5PGEw== 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=8o93p9mYoqybhgkAygPC0Obm+t8oGE9xTvNcEMl5QmM=; b=APqRrqIBYBUQcXOMV4k/cxzuQ4hSe7cJSBvLqLZEJhjVgp+8T7GdRRRBuB2J66SG78XIvNG38q67t+0TSecOdfnlbbgQ8XGEkoMe0hKW3C7gnafCl+8J+vrZHrxg4jb740KTrFCNLV9DVgzNZXt0EAncem99WHwRFXKzrzJx8iLLeeDyAP8TbViiruWoTAYrLYm4yQL2eLKkqV4H5Nyngutap99tkEbFuKhhJghXwaviHzaywqw16gfeZUESxur8tfjL1TOCp9LueHR2+3UBEJXhCoF8x/iEfyTeDiBKSKz3esPp/gqw6ToHr8bz1TFggYK6ApuwyblWE1mOHEr6BQ== 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=8o93p9mYoqybhgkAygPC0Obm+t8oGE9xTvNcEMl5QmM=; b=sJeOJvOVTtkjsMBo/7ie9TkKrFWihO4tOBUERnY7dAm//EW2LCRV16bQ1/Vuwej4icA2lO2FT7jO/Uw4r53MgKxMPJaXfenB4T9JcxHg7UVMmty4y/tPhZytVaJ8YLC3+h1z6dhYDsSYQUMw5ZmFzlD8xws3WsnyfQaPezoMAn8= Received: from DS7PR05CA0056.namprd05.prod.outlook.com (2603:10b6:8:2f::17) by DM4PR12MB6591.namprd12.prod.outlook.com (2603:10b6:8:8e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.42; Mon, 12 Jun 2023 04:43:06 +0000 Received: from DM6NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2f:cafe::2e) by DS7PR05CA0056.outlook.office365.com (2603:10b6:8:2f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.21 via Frontend Transport; Mon, 12 Jun 2023 04:43:06 +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 DM6NAM11FT024.mail.protection.outlook.com (10.13.172.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.21 via Frontend Transport; Mon, 12 Jun 2023 04:43:05 +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.23; Sun, 11 Jun 2023 23:43:03 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH RFC v9 34/51] KVM: SVM: Add support to handle GHCB GPA register VMGEXIT Date: Sun, 11 Jun 2023 23:25:42 -0500 Message-ID: <20230612042559.375660-35-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230612042559.375660-1-michael.roth@amd.com> References: <20230612042559.375660-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT024:EE_|DM4PR12MB6591:EE_ X-MS-Office365-Filtering-Correlation-Id: 46dfd1bf-083e-4c81-62bc-08db6aff838a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xbR7swrgqngFy9fYN9jwKBTPShikayOIVylnXb1sUAyy/9mAA60vMeabHj2cu2WcJPmA70IJn/llAtuqXZi/0LgVJ/UeY8rT/aCf5hP0O9WXmCA4PUvEPKXyvK6LilGDQ6S6tzsus6EJig0Ei2Z9KxJRSoS3ysPlzBDx5Tv9j6VVBU2aInYA6zHR7tsOc0E5AbpM+u5G86pCxCzSjF1ChQgydywnVDuxhi5JRZt+nsuWzW8IU95+Ow0zn6tjkHV02YGOlnV4bzbMY+aUtZ4hytjC4V2O89zEP+Nx6FNcW3Nfwh71EMeuUiXGA/5Q0IBbRYPaklbYy+rfSdLT0o+Em0Q0t2dT3pjLNj3e94cJaaMGMz3RQC+qPe0oteTjDq1PI30n3B/89SDe8tu0FJogbTMmtJEjhoUZBPby2VVL6hh47yM4vdLKjVWQsmM3gtGAO7QHdTceznZfV4/A6Y8/mfEklKHthXWXfIRin/Z4jt/vQL/MnCdr3wrbO7d32iVV1PClT4G8P8Hh5p+Jw1aPpx06RyJy4shN2maASRpGFljZMykbw79EyyzK/QfIPbTCXC3kJ7lHGzCI8uOgiWxaEQOOoOnVhFlYlTb2Y1J5uRqTLbLsITJBegPuTqc0zUhh9/L/L5ZXQzBNSfM0yU6kLERCB7VaGakT8XH1dYkUA8TST4ReWEl6RFGd/m3PmCChUAd/mQBWBE/CV50NuWQQ7p6danGEF/9RECdKSCPBfQEIS5+B4j9Jpg5Ws/JjCWV+m4eIXGOdTI7wDoTYTEGhHA== 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:(13230028)(4636009)(136003)(39860400002)(396003)(346002)(376002)(451199021)(46966006)(36840700001)(40470700004)(36756003)(47076005)(478600001)(54906003)(6916009)(4326008)(70586007)(6666004)(316002)(70206006)(86362001)(40480700001)(8676002)(8936002)(5660300002)(41300700001)(2906002)(44832011)(82310400005)(7416002)(356005)(7406005)(81166007)(82740400003)(2616005)(426003)(1076003)(26005)(16526019)(186003)(83380400001)(36860700001)(336012)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2023 04:43:05.8365 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 46dfd1bf-083e-4c81-62bc-08db6aff838a 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: DM6NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6591 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no 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: Brijesh Singh SEV-SNP guests are required to perform a GHCB GPA registration. Before using a GHCB GPA for a vCPU the first time, a guest must register the vCPU GHCB GPA. If hypervisor can work with the guest requested GPA then it must respond back with the same GPA otherwise return -1. On VMEXIT, Verify that GHCB GPA matches with the registered value. If a mismatch is detected then abort the guest. Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra Signed-off-by: Michael Roth --- arch/x86/include/asm/sev-common.h | 8 ++++++++ arch/x86/kvm/svm/sev.c | 27 +++++++++++++++++++++++++++ arch/x86/kvm/svm/svm.h | 7 +++++++ 3 files changed, 42 insertions(+) diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h index aaea4afcda98..d499730e1f15 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -59,6 +59,14 @@ #define GHCB_MSR_AP_RESET_HOLD_RESULT_POS 12 #define GHCB_MSR_AP_RESET_HOLD_RESULT_MASK GENMASK_ULL(51, 0) +/* Preferred GHCB GPA Request */ +#define GHCB_MSR_PREF_GPA_REQ 0x010 +#define GHCB_MSR_GPA_VALUE_POS 12 +#define GHCB_MSR_GPA_VALUE_MASK GENMASK_ULL(51, 0) + +#define GHCB_MSR_PREF_GPA_RESP 0x011 +#define GHCB_MSR_PREF_GPA_NONE 0xfffffffffffff + /* GHCB GPA Register */ #define GHCB_MSR_REG_GPA_REQ 0x012 #define GHCB_MSR_REG_GPA_REQ_VAL(v) \ diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index a7cbdc24ccdb..44fdcf407759 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3312,6 +3312,27 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) GHCB_MSR_INFO_MASK, GHCB_MSR_INFO_POS); break; } + case GHCB_MSR_PREF_GPA_REQ: { + set_ghcb_msr_bits(svm, GHCB_MSR_PREF_GPA_NONE, GHCB_MSR_GPA_VALUE_MASK, + GHCB_MSR_GPA_VALUE_POS); + set_ghcb_msr_bits(svm, GHCB_MSR_PREF_GPA_RESP, GHCB_MSR_INFO_MASK, + GHCB_MSR_INFO_POS); + break; + } + case GHCB_MSR_REG_GPA_REQ: { + u64 gfn; + + gfn = get_ghcb_msr_bits(svm, GHCB_MSR_GPA_VALUE_MASK, + GHCB_MSR_GPA_VALUE_POS); + + svm->sev_es.ghcb_registered_gpa = gfn_to_gpa(gfn); + + set_ghcb_msr_bits(svm, gfn, GHCB_MSR_GPA_VALUE_MASK, + GHCB_MSR_GPA_VALUE_POS); + set_ghcb_msr_bits(svm, GHCB_MSR_REG_GPA_RESP, GHCB_MSR_INFO_MASK, + GHCB_MSR_INFO_POS); + break; + } case GHCB_MSR_TERM_REQ: { u64 reason_set, reason_code; @@ -3378,6 +3399,12 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu) exit_code = ghcb_get_sw_exit_code(ghcb); + /* SEV-SNP guest requires that the GHCB GPA must be registered */ + if (sev_snp_guest(svm->vcpu.kvm) && !ghcb_gpa_is_registered(svm, ghcb_gpa)) { + vcpu_unimpl(&svm->vcpu, "vmgexit: GHCB GPA [%#llx] is not registered.\n", ghcb_gpa); + return -EINVAL; + } + ret = sev_es_validate_vmgexit(svm); if (ret) return ret; diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 9a7cafb018fe..02edbdd443e4 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -205,6 +205,8 @@ struct vcpu_sev_es_state { u32 ghcb_sa_len; bool ghcb_sa_sync; bool ghcb_sa_free; + + u64 ghcb_registered_gpa; }; struct vcpu_svm { @@ -359,6 +361,11 @@ static __always_inline bool sev_snp_guest(struct kvm *kvm) return sev_es_guest(kvm) && sev->snp_active; } +static inline bool ghcb_gpa_is_registered(struct vcpu_svm *svm, u64 val) +{ + return svm->sev_es.ghcb_registered_gpa == val; +} + static inline void vmcb_mark_all_dirty(struct vmcb *vmcb) { vmcb->control.clean = 0; -- 2.25.1