From patchwork Thu Feb 24 16:55:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 12758911 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 529F4C433F5 for ; Thu, 24 Feb 2022 16:58:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A3F18D0005; Thu, 24 Feb 2022 11:58:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 02CB08D0001; Thu, 24 Feb 2022 11:58:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBF528D0005; Thu, 24 Feb 2022 11:58:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id CF6328D0001 for ; Thu, 24 Feb 2022 11:58:02 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BA989617D1 for ; Thu, 24 Feb 2022 16:58:02 +0000 (UTC) X-FDA: 79178280804.04.607A643 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2084.outbound.protection.outlook.com [40.107.223.84]) by imf16.hostedemail.com (Postfix) with ESMTP id A510C18000D for ; Thu, 24 Feb 2022 16:58:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=coDDjmD3d/fW90MfmQYlW0VPpMN4TbSgVNYlEX4LuK3p3pBSy8TUT4gogijtDVrDWJt0W8qOxRmA47YsgJ0h6bhfX69yuZdY5reOUqHhoJnE+1FRh0RdcdOwnxcKaGC47Z/NJ+Ic4dRoGrb/b7zVLoAn6v04O59JMIxRxoOTcZklhyw7KWZAuXiQ5nTovdsbu9NJ95rGTpkGtQaiSXZFVey+wHW4Pofo4p00SZ6rEmHZ2w6Vv3H9gnPWe1Ik5xvGlF17wEhnc9sIrYA2SmAGQPjfVgwZ8ppHH+N5241x8OHGeVdvfJt/ur3Zk2tPgiuyLujE2l6hmnerkU7KRD5KUg== 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=Xpty5kmwM2i/MklGipgcFQvhXKgpuuRpXZ2Y2DaVX5w=; b=fPWzaiMh86sc14sV7kAsbKwb9V0fDnM64yrAYdhUAW+GLXULbQOvQX09DDW5b0UxQlUgpZjvWIRQCnHPqk6NRO48i5v8iVKIfno1jr9B1BSAhQ67eXAcRbcp0FTPyntZoORtId8moJAaaD7pozGub06L/BJ6JzxKY1AEYikQBnLZiYWC0ZroGOkbtX+GF7LCdsWMc4lerpEK/9hjNGyckOMydVlmpx5ohBDdvwuray22Uykpp38afuCcv5f+Hm4bLadh7zf0ISIlsbEACj6b0lJXmcMd61C1YLZvwAsO/dKAens3tOJ06R9iBbwCqhvWYLpsRCUKfIVQ1tYqjfgspg== 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=Xpty5kmwM2i/MklGipgcFQvhXKgpuuRpXZ2Y2DaVX5w=; b=Eqq9J6kVKndakL1+DjGi4wZaWjXOz8VCwQNyuZGHoErJIGgkwR8kKKELcs3OrbCSuqq6FUQPmuUjxOwBK21N9VE0ULhIJWjnwokrVydarCHnYIZhG8PS62fQoVj1k7bBsyorS0uqC9wbi9xzA1ZXIWAH0h5ahQF7KM325WaXH2Y= Received: from DM5PR22CA0015.namprd22.prod.outlook.com (2603:10b6:3:101::25) by DM6PR12MB4880.namprd12.prod.outlook.com (2603:10b6:5:1bc::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23; Thu, 24 Feb 2022 16:57:59 +0000 Received: from DM6NAM11FT030.eop-nam11.prod.protection.outlook.com (2603:10b6:3:101:cafe::d0) by DM5PR22CA0015.outlook.office365.com (2603:10b6:3:101::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24 via Frontend Transport; Thu, 24 Feb 2022 16:57:59 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT030.mail.protection.outlook.com (10.13.172.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 16:57:59 +0000 Received: from sbrijesh-desktop.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.18; Thu, 24 Feb 2022 10:57:56 -0600 From: Brijesh Singh To: , , , , , , CC: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , "Vitaly Kuznetsov" , Jim Mattson , "Andy Lutomirski" , Dave Hansen , Sergio Lopez , Peter Gonda , "Peter Zijlstra" , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , "Dr . David Alan Gilbert" , , , , , Venu Busireddy , Brijesh Singh Subject: [PATCH v11 03/45] KVM: SVM: Create a separate mapping for the GHCB save area Date: Thu, 24 Feb 2022 10:55:43 -0600 Message-ID: <20220224165625.2175020-4-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224165625.2175020-1-brijesh.singh@amd.com> References: <20220224165625.2175020-1-brijesh.singh@amd.com> MIME-Version: 1.0 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-Office365-Filtering-Correlation-Id: 424ed86a-5570-4496-e4a7-08d9f7b6cff3 X-MS-TrafficTypeDiagnostic: DM6PR12MB4880: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: +MgQeim6mu3xOwYa4f5u0I8ZcOXcL/vE1gdrrlcey4qb9O+22ji4RviUkdYKHSP7gh94m/xIbQZQNQgWmJ/watIi0CV7AhaopOtxsvKJD6LX4QbPQrB9C5xfeXTQX0mrMEjjCzYAgNlRJ+b46RRMLHBmQE37hPXlm2xCSB3ErgDNx4OPN5s+cPeOiLj8YF09+nJvg2ZjVGpE697TBtlKScgO3M+EP6P0fBIBDbESMOf+2S1XvTimqSHWWUfTlrVMOU2cIW4UWr0GYaQcdk+8GmxKyeitReSsOas2ABNpTthPzQiBMYFlVcbljiJjRD45by57Frg6xUb+VP+ZolQsatW5ckAJG1PudFTxGDuRVM8T3y5C+CdQ+B45fYYfd1bOCJdc56ETPIpO8Uep2nChpPQXIXI8r4Z+EdKNVqYFtVt8rDC2NSmERD6lA5b3KXD1OUmbuc6pt1SPnbiOhefA/2Sk6BkM0wtaMQ5v0/957hQAJhKmEF0jX1itFh+iyPoVGIjS+mn9I/chES/kkZP2OT1r3TIvr9DB5cLBuKVq6f36Z/A6JB9yiAs1yp1aLW/sGW4iYB/8vhahuh/KEvgRsYmbyMj2p0LgAWKFU/QiFwuPGHXAOSgXlX40RYR1p2M43c0trkdvkjx1pTaR+zmXSdaYJ0S6SbIVZLnBNIdgPJiTwOXMLUvW21CjzK0YkXwk+d3HIyKJ65Hxb9WMwoNnl+KvY0kfgh0VQ/FOAFAaztQ= 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:(13230001)(4636009)(40470700004)(46966006)(36840700001)(47076005)(336012)(426003)(36860700001)(82310400004)(83380400001)(44832011)(8936002)(110136005)(86362001)(54906003)(7406005)(316002)(5660300002)(1076003)(6666004)(7416002)(508600001)(7696005)(36756003)(4326008)(356005)(16526019)(2616005)(81166007)(186003)(26005)(70586007)(70206006)(2906002)(8676002)(40460700003)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 16:57:59.3518 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 424ed86a-5570-4496-e4a7-08d9f7b6cff3 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: DM6NAM11FT030.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4880 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A510C18000D X-Stat-Signature: btgrzj45zrqn363dsuq393gcukrrkny1 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Eqq9J6kV; spf=pass (imf16.hostedemail.com: domain of brijesh.singh@amd.com designates 40.107.223.84 as permitted sender) smtp.mailfrom=brijesh.singh@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-HE-Tag: 1645721881-990508 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 The initial implementation of the GHCB spec was based on trying to keep the register state offsets the same relative to the VM save area. However, the save area for SEV-ES has changed within the hardware causing the relation between the SEV-ES save area to change relative to the GHCB save area. This is the second step in defining the multiple save areas to keep them separate and ensuring proper operation amongst the different types of guests. Create a GHCB save area that matches the GHCB specification. Reviewed-by: Venu Busireddy Signed-off-by: Tom Lendacky Signed-off-by: Brijesh Singh --- arch/x86/include/asm/svm.h | 48 +++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index e748aa33c355..eae5c7ab9c6c 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -390,11 +390,51 @@ struct sev_es_save_area { u64 x87_state_gpa; } __packed; +struct ghcb_save_area { + u8 reserved_1[203]; + u8 cpl; + u8 reserved_2[116]; + u64 xss; + u8 reserved_3[24]; + u64 dr7; + u8 reserved_4[16]; + u64 rip; + u8 reserved_5[88]; + u64 rsp; + u8 reserved_6[24]; + u64 rax; + u8 reserved_7[264]; + u64 rcx; + u64 rdx; + u64 rbx; + u8 reserved_8[8]; + u64 rbp; + u64 rsi; + u64 rdi; + u64 r8; + u64 r9; + u64 r10; + u64 r11; + u64 r12; + u64 r13; + u64 r14; + u64 r15; + u8 reserved_9[16]; + u64 sw_exit_code; + u64 sw_exit_info_1; + u64 sw_exit_info_2; + u64 sw_scratch; + u8 reserved_10[56]; + u64 xcr0; + u8 valid_bitmap[16]; + u64 x87_state_gpa; +} __packed; + #define GHCB_SHARED_BUF_SIZE 2032 struct ghcb { - struct sev_es_save_area save; - u8 reserved_save[2048 - sizeof(struct sev_es_save_area)]; + struct ghcb_save_area save; + u8 reserved_save[2048 - sizeof(struct ghcb_save_area)]; u8 shared_buffer[GHCB_SHARED_BUF_SIZE]; @@ -405,6 +445,7 @@ struct ghcb { #define EXPECTED_VMCB_SAVE_AREA_SIZE 740 +#define EXPECTED_GHCB_SAVE_AREA_SIZE 1032 #define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1032 #define EXPECTED_VMCB_CONTROL_AREA_SIZE 1024 #define EXPECTED_GHCB_SIZE PAGE_SIZE @@ -412,6 +453,7 @@ struct ghcb { static inline void __unused_size_checks(void) { BUILD_BUG_ON(sizeof(struct vmcb_save_area) != EXPECTED_VMCB_SAVE_AREA_SIZE); + BUILD_BUG_ON(sizeof(struct ghcb_save_area) != EXPECTED_GHCB_SAVE_AREA_SIZE); BUILD_BUG_ON(sizeof(struct sev_es_save_area) != EXPECTED_SEV_ES_SAVE_AREA_SIZE); BUILD_BUG_ON(sizeof(struct vmcb_control_area) != EXPECTED_VMCB_CONTROL_AREA_SIZE); BUILD_BUG_ON(sizeof(struct ghcb) != EXPECTED_GHCB_SIZE); @@ -482,7 +524,7 @@ struct vmcb { /* GHCB Accessor functions */ #define GHCB_BITMAP_IDX(field) \ - (offsetof(struct sev_es_save_area, field) / sizeof(u64)) + (offsetof(struct ghcb_save_area, field) / sizeof(u64)) #define DEFINE_GHCB_ACCESSORS(field) \ static inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \