From patchwork Wed Jun 2 14:04:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 12294581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51F72C47092 for ; Wed, 2 Jun 2021 14:05:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E6FF76140D for ; Wed, 2 Jun 2021 14:05:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6FF76140D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 382078E000A; Wed, 2 Jun 2021 10:05:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 331CB8E0001; Wed, 2 Jun 2021 10:05:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 136788E000A; Wed, 2 Jun 2021 10:05:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0029.hostedemail.com [216.40.44.29]) by kanga.kvack.org (Postfix) with ESMTP id D5B988E0001 for ; Wed, 2 Jun 2021 10:05:12 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 78115DDFE for ; Wed, 2 Jun 2021 14:05:12 +0000 (UTC) X-FDA: 78208955664.37.6FDF89D Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2072.outbound.protection.outlook.com [40.107.101.72]) by imf28.hostedemail.com (Postfix) with ESMTP id EF0E220010AB for ; Wed, 2 Jun 2021 14:04:58 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dUMMebSC3B5N41Un1rN3/G7lAF+e2xEwpaIGqQ10ZguOh4UO7advMUfRhJd63m1e4IQOfRUJyHLU31nb1rk+A2QHOOCi3yElP6SyKVjD6XcJ1um7c2g5K9zt/sATLgmGSD+dwIq+sTlmz5TZ+jLt58Lz7nVy26Xw5zdw1oMko7GJGr1CRD6tL7WDSdT77rX0omppvi97S6Depi2HzAIjdq3iza4UNEHTRLA1EUOrxQfLrem6MPQmUNKqwI80BhUeqak9YC9ezKUoJAD+6TyrtPAPmk9STZ+PA6wRWAULf7uztoVG2tHW+u8klg6UUeOtIg+MqrmNLBOqIGryn39lTQ== 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-SenderADCheck; bh=awnMpOPG0eeizOJVeGcQAnq9ILBGxpAUriKoAFC3lWQ=; b=khm+84Y8lNl7RXV1XAjyy5QRsFd0XgmAhvmeuhiQYkRZxZuG4aUT6OZN8BLgadyGZQvyz3TgTpRQVIuWTPyA9O9e8STAx9GI1VjPglsFOuOj2qfTNJiVnnR1M5DkJrIYjO90oTTPVGBGnIrOLFKo8jOQunsq2zci14Lvh+uui1VbYqL4hbZX7KqJ4dQoOzmZVHUre1hOjPd4lldqzs9aiQCQdCWDpmbAoxxOkfyyonaOXvyuIf4ffdAV386KFdQd3QY5Gi//avDr5k5UDJKSEEuxzKBS/1+ZIbnAO4X2IqQFal2r65v6WaLAZuXtyp/xb/2b4b+TjwDQ+Owi1xCuoA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=awnMpOPG0eeizOJVeGcQAnq9ILBGxpAUriKoAFC3lWQ=; b=hLT7p4n2ekIYfY6H9VepEOUq+AK5vi1AHoOdzhZElZ4IuPEuyQU7wIWT21e45rwcrP532qTR7K5/OfId34H688eCA9KSQGO4yGjtQH/XxOB9DTGVw9UngAHk0m83mLEiM9Z3toxs/Rl5WczP9mYvXVjLXpHlkkC2z55cQABNqo0= Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4446.namprd12.prod.outlook.com (2603:10b6:806:71::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22; Wed, 2 Jun 2021 14:05:08 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94%6]) with mapi id 15.20.4173.030; Wed, 2 Jun 2021 14:05:08 +0000 From: Brijesh Singh To: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , tony.luck@intel.com, npmccallum@redhat.com, Brijesh Singh Subject: [PATCH Part1 RFC v3 17/22] KVM: SVM: Create a separate mapping for the GHCB save area Date: Wed, 2 Jun 2021 09:04:11 -0500 Message-Id: <20210602140416.23573-18-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210602140416.23573-1-brijesh.singh@amd.com> References: <20210602140416.23573-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR05CA0010.namprd05.prod.outlook.com (2603:10b6:805:de::23) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN6PR05CA0010.namprd05.prod.outlook.com (2603:10b6:805:de::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.9 via Frontend Transport; Wed, 2 Jun 2021 14:05:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1b517165-5d82-4e49-7c46-08d925cf6ddf X-MS-TrafficTypeDiagnostic: SA0PR12MB4446: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t8aqpmOh1Y1s+WFbmvd/VCe19Wlcyrf+wdck0c/PqZfVXlJzKyAJ4wQrC8r+acusxgW3JW0M0Rok9DE91jUjb3PD4h6HEYw4TJKLaP/rrKzzVGlYRW6weSLHE7jtqttQKAWePg54rDxC3+YHZmmUnOCDV9vUT7Lg45E1/YWXy0WgvKqK3VPkDerl/EnmTZw79WkCjojd1w6h1klkCKE6C20ws4YE4Jy+5lf4T2y8uKoAvU4SEhnTIZFQrFbotxm+X/Y3c6MvG5B5ghCZGL09SCt1OFdwG/ll5zabKw3vyhP9Wqx/qcocVoS/vDRqbA8/Qj0bTE11zBBcUlhuwiA24t2AZ3v9gqNSqb+604wjH/dFVJtrCVBNohkotI081O5TO75A3K7XbKqgTvR5itnW3iYjrRBTqIVkRjCUNvVMkeUHW5JxpY4d1TWL7YPnE40LFdtNONvw87K6GehDkXk0V+kTgl9uftjRrvgc0IbfAqOjUTxKCVcsHxkahajA8JzYpx7bU5pC+khaFt6qSfUEJSdPCtxwcW1L4h6KXEbULJyUZQX+0Ginjvk3Xg/5rq2VWofTzwcPr4sYCCvPBq381e27N7j4kUegQPw3xespUuAeoo8a9m7LNuD8t9omAZqD+UAcrErrHChdzuF3z5V1/Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(396003)(346002)(136003)(39860400002)(478600001)(8936002)(7416002)(16526019)(44832011)(66476007)(186003)(66946007)(4326008)(8676002)(7696005)(52116002)(1076003)(86362001)(83380400001)(38350700002)(6486002)(316002)(6666004)(5660300002)(54906003)(38100700002)(26005)(66556008)(36756003)(2616005)(956004)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: VZvm2oS1zVwcvRPgpHZ0XwkDyUYzejJa2uiJ/YhRKKVTSiEre/tSYuUkS3d+baiVuOS+YJNzwL0pALBn/El++z0IQDkm+5f1pE22g0tdLlyfpJGbhkitfxhEpBN571u1pUbRVx/7HtauMBhd/coP1jd2S7fEQdTuA6r0cLqtcW1x+xJnzD8S4VDivh7uAv0DrxuTNXPw32m+Wn+JqgccQb5rbkjz2VLAoO9i1iNMpwqUr2UAfFiQ9mWLcXrIcD7KD+3QktqRx9Z10uF0K6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com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b517165-5d82-4e49-7c46-08d925cf6ddf X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 14:05:08.3445 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3NnJhp2TN06lMN0xBvP/MwjyFVX85u5vTieZSP8ndXHxwCGWQ4+W2nYCcZHsLyaYzvgbDiPY64kqz38Zf7puHg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4446 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=hLT7p4n2; spf=pass (imf28.hostedemail.com: domain of brijesh.singh@amd.com designates 40.107.101.72 as permitted sender) smtp.mailfrom=brijesh.singh@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: EF0E220010AB X-Stat-Signature: 934uww1iwypaa6gghm51n499pk3zetfb X-HE-Tag: 1622642698-764277 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. 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 482fb20104da..f5edfc552240 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -346,9 +346,49 @@ 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; + 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[2032]; @@ -359,6 +399,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 272 #define EXPECTED_GHCB_SIZE PAGE_SIZE @@ -366,6 +407,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); @@ -437,7 +479,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) \