From patchwork Wed Feb 9 18:09:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 12740671 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A725BC43217 for ; Wed, 9 Feb 2022 18:11:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238664AbiBISLf (ORCPT ); Wed, 9 Feb 2022 13:11:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238677AbiBISLd (ORCPT ); Wed, 9 Feb 2022 13:11:33 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2063.outbound.protection.outlook.com [40.107.101.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8671C05CB8A; Wed, 9 Feb 2022 10:11:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oYqf0Z9uzXg+wDG/fZzYYVZkodNu1jLPqDV/XTeQ5qE28jcP2W11lx+l0YoO6pjX0dDLH6unEt2FEzh2Y7+YLkuvQR/yOzRM6Sh1G1IyRME0jriNTXEPR2PSfhHmewl5h8iWRhjb5aMh4Ovu+nkOI4HlxmwhlCuZVuDAFWcYzMEEZToyzYlWjji1FD3T+Y4fMJBvncUBVYWIky7JKUa5PJi0BijlC2+fRKmA9A5IYJjV7kdMskVx2RerF5jgQnbfSqPBtkLUcAwoKECBWgWkbSeJ07EN7ed2ax7gIj3sCVrx8OqBf4BXufTMv1p6j070vUHuC26VEWUKmzBlnaJwIA== 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=bmXVTRy6UQm1WoPAcgkt9HTG92DGrjYJGd7ZkLbvCRA=; b=KaS7hrGPEJ6KW51q8XLA3RpOHY2HD4vPqdprs+/yhn9Z6zX4pngHo9tJWN9nIcnKY/BI/AqVqKMg/yTanYYesb8JTpfHtaBVwyodn+8z1xHQVJ5uJAK5rHGEvLOG3HHAt/pNMYrV9edMy8WqSPhp4DaZXyE36k50WR/lKpRVvUJraGTTKlb3mRlo+QWB+q+URtKs3CFkCohKxQ35HpErBsEySqcymkL7tRTsu+ZAcw0rbqWkEaY7rKxRNJ6P8NNPbjp/GvR7w/P5xqPszHy0929gXN+OxAgkyQtFzRb+E13NmuU7WfSsars/uIbu8rtan7G+AVRF8QAUf2RNFCi+oA== 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=bmXVTRy6UQm1WoPAcgkt9HTG92DGrjYJGd7ZkLbvCRA=; b=pFBnnOIE/H3C+Jf7a/+mq6I5lVp6wQGRekQjNp7ZJmPxsguysg/32DX8Ngf9ppChILBzSZwrWc46kDCg7O97xdxkdH1MDFeNMcq5OcwtWE/HVnz2pWtOPTVc6sDmlLBjx0ESf0bOOm29dQ1fj19Kd8rS8i4w0YKu4WSma2Futxk= Received: from BN9PR03CA0582.namprd03.prod.outlook.com (2603:10b6:408:10d::17) by MW3PR12MB4492.namprd12.prod.outlook.com (2603:10b6:303:57::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 9 Feb 2022 18:11:32 +0000 Received: from BN8NAM11FT044.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10d:cafe::17) by BN9PR03CA0582.outlook.office365.com (2603:10b6:408:10d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 9 Feb 2022 18:11:31 +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 BN8NAM11FT044.mail.protection.outlook.com (10.13.177.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4975.11 via Frontend Transport; Wed, 9 Feb 2022 18:11:31 +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; Wed, 9 Feb 2022 12:11:29 -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 v10 03/45] KVM: SVM: Create a separate mapping for the GHCB save area Date: Wed, 9 Feb 2022 12:09:57 -0600 Message-ID: <20220209181039.1262882-4-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209181039.1262882-1-brijesh.singh@amd.com> References: <20220209181039.1262882-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: 656fbc10-7449-41f2-c332-08d9ebf799b4 X-MS-TrafficTypeDiagnostic: MW3PR12MB4492:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xPKsIOYrf6mIyOqD8bnK6yxInH/Y651STwZ9ShahRlEQWD3Tg0yU2IT4eX4iPAaUVGc+5Bz6phP0ItLloWhCrr2wNzFN3EYQ1By1nihc2OivJWz/5P/3v8XFkgdIlQ2wJ2vbxB4cJXGM2vcpANukigx9lBEk1v0Co72UQCAGjku4iGBcvnAgSlk5u30rtPmezdshGkyg2YiYMirdDpEAPIXrejnhrblCOvUUvSIMyxAT1sAhyrbAY3+Poi7zLPUudBBvShXp91l1atFDUX5rzVm0dcRrrFvOYKx1HCskOrqibyKcHJHL1BiYrY4pnqrAiE45jvVeVW040U6PftaR4Y7UIsfmq4iBu/f5TxmROoEUvuuJXGTTrohqZ4IU/QhoJODFjCJpDKGO0GzLnDRMS5qqEol/cPUd5Orrk4ixLP8XNtySklpPaY4jc0a5pNo22y0w9mpdZ1QRpNWGBfK9oB4Mv7EX7H37gKy1GHVT5OCBCTE3J0M6Tn6T2n8/K7lFhTMcDCKAgVvaaksaATF2wyTxxumgP4zIWBWFCV+AnCOW7np5Y0NYwwbxgiAzp1H1jK/cXCqCHadS29CehBB5yYr5lcx7Je3jYl33xHnJ9hWnPlSQs1KZZbtsIdf8nWE+l7FXyL3j+Z2lAEeMyMmbmd73w3FAOUZHSqo2KFI8afFfGCu4IB1kmo0BlMowpnF67Ge9bkThzwv9pt+iQCsgz4P5oidDl6U6IDUjW/DKnkU= 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)(8676002)(7416002)(8936002)(7406005)(4326008)(86362001)(70206006)(70586007)(47076005)(82310400004)(40460700003)(5660300002)(83380400001)(356005)(81166007)(54906003)(110136005)(6666004)(36756003)(7696005)(316002)(508600001)(2616005)(26005)(1076003)(2906002)(186003)(426003)(336012)(44832011)(16526019)(36860700001)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 18:11:31.7064 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 656fbc10-7449-41f2-c332-08d9ebf799b4 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: BN8NAM11FT044.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4492 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org 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 3ce2e575a2de..5ff1fa364a31 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -354,11 +354,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]; @@ -369,6 +409,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 @@ -376,6 +417,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); @@ -446,7 +488,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) \