From patchwork Mon Feb 20 18:38:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13146941 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 3F4EFC636D6 for ; Mon, 20 Feb 2023 18:54:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1DCD6B0078; Mon, 20 Feb 2023 13:54:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCDC36B007B; Mon, 20 Feb 2023 13:54:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6EED6B007D; Mon, 20 Feb 2023 13:54:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A75466B0078 for ; Mon, 20 Feb 2023 13:54:50 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 702871A01F7 for ; Mon, 20 Feb 2023 18:54:50 +0000 (UTC) X-FDA: 80488571940.23.7BE2B51 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2089.outbound.protection.outlook.com [40.107.102.89]) by imf06.hostedemail.com (Postfix) with ESMTP id 8F266180010 for ; Mon, 20 Feb 2023 18:54:47 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Qy73IVK5; spf=pass (imf06.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.102.89 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=1676919287; a=rsa-sha256; cv=pass; b=glhvXmUPpxBTzeNrFdnYX+DX/O5WBsdwXjvGgYZZAqyNemGvTut1D8vPbBU9zLmkVbaXOR 61Mz1Cipf3E9LRDG7x2aOC/RTDo7mwahql+ehiDAq2mZdkOQetSj9mIb2MNDjjcpws1o1G uJm9JmLJBo6MxpPGpAMHo73s63/e7a8= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Qy73IVK5; spf=pass (imf06.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.102.89 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=1676919287; 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=bfbbeYCbDjRFikAqVByP3v8vGvoyVHSwAy9gWugZHqw=; b=lHuOoPcbVQQUiczIimFPq3Sk05MwaV+YSnZHfyE+4kQlRHZO45EncdCb+E6KSPICyX6eck 8rQywkkJbujTKGSsKdgW0LwelzH1g1/GJOSP7gs3Sg2J9Dsqlttm5Q4irQmCLnnxamDPWQ /RTThmNz5+mhJK5NXKqvhMR0D5hwNV0= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BMjdDOy7d+TGYiSCPoRPo35y/JJ2qyZxQe0obeJnNphm+bHKC+9noC1dy+TNw/u7ZNPLMcrTrcqPvgnR7wJztZwkTOcYuqtuZYYvh9KuIHLEhITFHFwjORWc+8ZTto1vuxphZfDgsJwq/rB7m5EDy3uf4oVvlAfTRk10DZAuXSszI9O13r3BnZNNXC8lynH4DYCAHFooUOERu9KQa3VFE3sML9b+KRyJirjU+23ZBQBGRdHDlpzNsRRpW3lrgn+bAbWG8bIgUZRdqgxq/7If84WawhE2Sut4ukbeCVqakpTJs5dv0ZDy1U/0/6IjI16dp5Nai6cqCVtzQXjyhLJU/w== 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=bfbbeYCbDjRFikAqVByP3v8vGvoyVHSwAy9gWugZHqw=; b=mmYnq/OVDJkalwxZeYfAN3IjTsVqEHDhs5T9DD010YZMVelQ2WXK18Z57gJJESHAHcn7cuwEvpGBAgDGWq4H3UI4mMuBH+ZgVdsc0tLfpjLuuyjOvNXuogS2V1u1vdMA9EB8On1I/Rkfl/BO13ijigVWs+wJV+aTzvMBE4EUBY4ILfqiNkx+K3q6/aP/YzU0IjSmAmvos410dcBcjnqQSkjskywtc/J/eqawqKoQHmpyjfliI0qnnqbsqV7cByjgKIGh1IT6K2tXvHZ2b7Fm0RUUVtPpQNuH9MViwQq980GyT2cApoeim31FFbEgtQfTed+trZ3cpL3hRT8n4C4Gqw== 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=bfbbeYCbDjRFikAqVByP3v8vGvoyVHSwAy9gWugZHqw=; b=Qy73IVK5J+rW4qYNtPBVxqNDSFQxh6fHM/zyJYzPElvAMJhM63QkTCYQijBSY36UQZgVUdf75cRnQKrwQL275VSEY4U1VF1yBAdIwst+ttU/mh4zwh2CzuYh5+TZ6vkd7rRC890S1Epn0a7GFEhpnOGk4S6rwWhHs4JeBPiSoiY= Received: from DM6PR07CA0041.namprd07.prod.outlook.com (2603:10b6:5:74::18) by DS7PR12MB8252.namprd12.prod.outlook.com (2603:10b6:8:ee::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.19; Mon, 20 Feb 2023 18:54:44 +0000 Received: from DM6NAM11FT072.eop-nam11.prod.protection.outlook.com (2603:10b6:5:74:cafe::84) by DM6PR07CA0041.outlook.office365.com (2603:10b6:5:74::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.20 via Frontend Transport; Mon, 20 Feb 2023 18:54:44 +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 DM6NAM11FT072.mail.protection.outlook.com (10.13.173.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6111.19 via Frontend Transport; Mon, 20 Feb 2023 18:54:43 +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; Mon, 20 Feb 2023 12:54:43 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH RFC v8 39/56] KVM: SVM: Add support to handle GHCB GPA register VMGEXIT Date: Mon, 20 Feb 2023 12:38:30 -0600 Message-ID: <20230220183847.59159-40-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230220183847.59159-1-michael.roth@amd.com> References: <20230220183847.59159-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: DM6NAM11FT072:EE_|DS7PR12MB8252:EE_ X-MS-Office365-Filtering-Correlation-Id: 7221e5be-bcf1-4593-4950-08db1373ee1c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xpE3iW1to2rfFR02Hs7J3oU3JFQMw/vvjU8mpcQIwsY2g2HIU+zZrpJvzR9uLiqsQW/oIQkaosDhtXurnhZ4hYNnTW3ytPeQ1OdQFhjUzuO02X5vPp9sjITZKYe541rwy73t7vUX/PTeuAccj5UZVZy2DMCcj2CMdVBqbaZa/OMFoJvc5MkUE1kQ4DuanP06t2DRQyUSgQeNYWrRRddgGITg55zTmIcS3MFNGbwUiTHwItYmtQZP3GXSGkuerp6b6x9lSVbzBPgiG4iAxZrfSz1p4rnzketUmHp19ft/teFVs5VpyDo7/wzelCtkltwjbco1HsW0wTZrBbMI6Pwd/qq0Z3eUQdhzc2uSmBlhFVrfv6yvu8i1IWtL7xL70M0IcbhfKGYArYObpVtOv5pNwDLpXeRqhOkBCQBm244YS7WGlemSEeSKmsDzBRvPEx7WZBFQZck3623OwYTobVf2X17cZaO5wnE8VXIz+Cd6saVNiOd+t+ea/u/wSJ1FNswHOTHL7EXVCVUK+f6J/qHv8CDeFDuILgR0vUJrG88JcdPhc46MjYqgqZ3no0gFe+2d6R4faZxEwnb4MFVauAImZfrt2t4bbsD9ytwlrGUt7Fg3rvKdokCmq+E10ZQoe2yKXIXi7/8YDm/iN3T4BZE9hPYCqDMxUOubVa7MJfUPW4giKkzRGC5sqL1EYzSQeh3QVIS4yzbnGrUHlVmx3Yo0Ov9dOUyHPQurnponB5D6xdg= 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:(13230025)(4636009)(136003)(396003)(376002)(346002)(39860400002)(451199018)(40470700004)(46966006)(36840700001)(40460700003)(41300700001)(70586007)(70206006)(83380400001)(7406005)(5660300002)(7416002)(8676002)(54906003)(1076003)(2616005)(6916009)(6666004)(8936002)(316002)(4326008)(186003)(478600001)(426003)(26005)(47076005)(16526019)(356005)(82310400005)(36756003)(40480700001)(336012)(2906002)(82740400003)(86362001)(36860700001)(44832011)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2023 18:54:43.9273 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7221e5be-bcf1-4593-4950-08db1373ee1c 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: DM6NAM11FT072.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8252 X-Rspam-User: X-Rspamd-Queue-Id: 8F266180010 X-Rspamd-Server: rspam01 X-Stat-Signature: 6wsrxcqrh6cj71btki1zxt4ahkf53odd X-HE-Tag: 1676919287-510464 X-HE-Meta: U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sxM/a2RULyeoDvdCVrlcTENVP6I2TmXLCHZgviKEWFmKhhot0LCZhHSnjpcyE6LdKJc/XJFwygZQTSbpphWlfFXlBl8/gK8SWUvTQa9eGnQlNbfr4kr5QFQkbEAIMCwBndVbF6mRJpyJxDjQHAethDZLPgPDDXSgRbigE7EJYArzyPDjIcbWmiZ6P0Pw7Qv/Gyl48iA2xs3cIQtavK1aUIo5HaaMz1ux3n9GTfLFhM+5FYRdDEc63Z8Z3yrxEnww1ZbUU/qlI= 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: 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 539de6b93420..0a9055cdfae2 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 e8740c35be39..2613311f4fcc 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3424,6 +3424,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; @@ -3490,6 +3511,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 cbd4594f1cca..0c655a4d32d5 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -204,6 +204,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 { @@ -336,6 +338,11 @@ static 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;