Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2750132rwd; Fri, 19 May 2023 09:40:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ442BCC23cEN3Y6el62uGtkehON6eJ3NzAM19edj40MfYxHJGIQBajcItg94ujcjkFLkjmx X-Received: by 2002:a17:902:b401:b0:1ae:6947:e63b with SMTP id x1-20020a170902b40100b001ae6947e63bmr2836774plr.16.1684514402519; Fri, 19 May 2023 09:40:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1684514402; cv=pass; d=google.com; s=arc-20160816; b=eTSVwRk2QFuYKhL6QUdN5lU+fJLgABEJhbQCVJIUFNMAADIYLwmSAyHp3g3V1ZMlCm 1ujlneLL8iPw9s4uK727gu4+Tp3XM2WVVJVo/blRt1aMLpfFl1Bk/wbYdwL0nvVq0OGo o4E1LX3miEDWXC3nJz1qvYjTQMeUrPh2OJKcAMwvJj52cjPTbWDL0H7rmINd1CEM276k lx/rVrKPamrxPUNebV5PwSROUGOTtdJDjokzF5MtBSun01/z5ffUzOubxN1aJtH/WudR EFe2kUly8cao3091ud9e5JpH35ISyO5kvmvStF/VUr7ugkqgw8BfI2EyYSigBC9lhwpU 1sLg== 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=MH9GCEWsgAt9YKaKenSWcFZ6c7NWvrzv26GHiVvz04o=; b=AzlFDteD4Zqo+upHSPrOYqsruFdZVkeH24sclljKh4frKdqIX5B8zRma3vzKXY1/et he3NMLZ1DGH/Q5HZ6Up1RdojMFN79ICfR7Sbryzl5BeqkwciPNlQ3SuLAIq2Qu/9AMRc XI38EG3ROOw0UDACgA2xtu6rvalY0q2k/t8dcZGjFxIVSI/j9CodcyEzpWSYWErMnVWc iw/k1ML+kBdZQxlGaxdWL2X5+/zZ5fhlDrs0SNxXxHPRFkx154hBMrVgbq1HfaIb0xll z4VnlYSQyWkkn5iLURdmvrzsIGDyGBWfDYB0zR98AoRCBoxiobpOkzBz67Df5TQsFdym 2CsQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Bz3uTo7L; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 jc13-20020a17090325cd00b001a1d76e7214si3764529plb.111.2023.05.19.09.39.41; Fri, 19 May 2023 09:40:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=Bz3uTo7L; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S230445AbjESQZt (ORCPT + 99 others); Fri, 19 May 2023 12:25:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbjESQZr (ORCPT ); Fri, 19 May 2023 12:25:47 -0400 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2066.outbound.protection.outlook.com [40.107.102.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66B08173C for ; Fri, 19 May 2023 09:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PxKL7yJ+25GB7ofqOF1Oy5QVd6DOu+gTBz+zctG36L41QS7mwCzhgo94UKB2S6Hi0vhWspH1nD+Bc8A8MyhIZEKH6/9bLukexQWGPdKJv0NF1nLNGa+PMEyIrUVKcqCshmU93i/GUcm7tACYV2dWhkryUGPQ2yWscQEqqFNV8DKFd3iPJdaDnO1pZ8/uG8q94HtpP7qAqJz4OF3ajtJHBlOORAYqTuJifqaFBebJfogWGXjtocvuhHuQ3ECsmYRD9/Mg8zQnkvRr3lC2qAwUrtWA7MNQWyTVZ3EWo8cw3bInF+J/ViWvxKNnUY/3u95hcoHxuT7D0t7T8iRVV6WiXA== 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=MH9GCEWsgAt9YKaKenSWcFZ6c7NWvrzv26GHiVvz04o=; b=I1jADgBA3efdLAMGwbKbUKv3vizQTTR5oMQGhQmUpbYx059mbJ00FnVwPbPequJXu1mQi8qbxbte1/ixA9Miyb8+w2Zrb0dAeAgd9pPDJEJZz0fmV8EKZsdRDWqkZjZUyBEll5i4aTK1KAoQ5YIFMAhReNu/y7g4n7EqQOVulO0P8Wl/kSc1/vtvupUZJDrfxKhL2Sws8bAoziefXVmKz5GAur1/szfE2f5MHif6+zmo3nn9IAOBZNZfctZbPzNf6pyVY8u6P4o7p5DvUuSoFQSywiC2v4mXNl2wfuot5AWesD48Eh8WLWMa4tE0iKuFDxAzyPItJzj1vLr3J7/lDg== 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=MH9GCEWsgAt9YKaKenSWcFZ6c7NWvrzv26GHiVvz04o=; b=Bz3uTo7Lp8Pyi/yOvvGwfvHq/o5Hr/N6Z1LDYCNwORx5cPUmP4RVUu0rvHmo+EiFLoEAtkc4adfnjIbjXkw60NedaRO4dxDpZkHQl4LE55QqJ9G2nyc+KZXbD0OEYlYUQp0b8bCNJVjeXIaj7EaGC37giK/jB6M7IC+j4XxVwDk= Received: from MW4PR03CA0327.namprd03.prod.outlook.com (2603:10b6:303:dd::32) by DM4PR12MB8572.namprd12.prod.outlook.com (2603:10b6:8:17d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.21; Fri, 19 May 2023 16:25:20 +0000 Received: from CO1NAM11FT080.eop-nam11.prod.protection.outlook.com (2603:10b6:303:dd:cafe::ad) by MW4PR03CA0327.outlook.office365.com (2603:10b6:303:dd::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.21 via Frontend Transport; Fri, 19 May 2023 16:25:20 +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 CO1NAM11FT080.mail.protection.outlook.com (10.13.174.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.21 via Frontend Transport; Fri, 19 May 2023 16:25:20 +0000 Received: from tlendack-t1.amdoffice.net (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; Fri, 19 May 2023 11:25:17 -0500 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "Kirill A. Shutemov" , "H. Peter Anvin" , Michael Roth , Joerg Roedel , Dionna Glaze , Andy Lutomirski , Peter Zijlstra , Ard Biescheuvel , "Min M. Xu" , Gerd Hoffmann , James Bottomley , Tom Lendacky , Jiewen Yao , Erdem Aktas , "Kirill A. Shutemov" Subject: [PATCH 6/6] x86/efi: Safely enable unaccepted memory in UEFI Date: Fri, 19 May 2023 11:24:17 -0500 Message-ID: <430269747cb961c7e70288b5808925f4fa4c544d.1684513457.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230518231434.26080-1-kirill.shutemov@linux.intel.com> References: <20230518231434.26080-1-kirill.shutemov@linux.intel.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: CO1NAM11FT080:EE_|DM4PR12MB8572:EE_ X-MS-Office365-Filtering-Correlation-Id: 04c1b3d1-eeb3-43a3-621a-08db5885a3aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kuDlCP9iubqIn85+NAyFj5Fw92YaMKoJ/bkRP2ev0YII2EeG5yYUkfIee8S5BtpRcn9M7vqoUmySUvX6Shyxedqclo+NwjL+DpGU5hxebB2howkPR0Wcwrx8iOH0QTocO1FCelkIRqJAv0he0T22E9mvPL7KXKlRWiA1zIHSmbRynYNWg4+EscMyEjkcDpEPy3c0ALOPAbAJQ+w1e8UKebZ097A81gam5/jUcbDKIILHk+ldmYmLsZ6hifDN0BzSuL+uzu8puGPkweRaLtFXNbpqUI3aIs68CwdAx6hhxElXGETSnFWrOnK8Axu52aTIunMrwW+yjKVxWLo5//uJ0WeoWGFloF86LtENeGf5ecgv7fGkJf8zwe7tChFmCXtgSzhHcLJxNof2PbEhIPj/mhJsXpmJopdU7CxNWmfKmuxk23BHJOkzdgSoyPH9PwwkqaoKy5h6sazUjn8ovia+Q+Q5f/LQUSpBPLvsxc9lo1pJBoVt4Bz5a/Q6y0lPKvpnbnHBtbwg9CQfrw89VXchBYy8PJwY/Z/aS7lYsvNwzMlEydcDRLeq2q4hLX0goZwxa7tq3ggT4U6VMRnBYzosX7mlzYZ4RbCE8bTGWDmhZEnukLzq7ht9EridjD3T6J6K09OB+IHHm4l/DpNFBIp7qPOCJ4QCgHVgrvHUA5ci0La5BgxW1Phz48fsBadRncjloxiFpOCyqmuOtJr5/sa94jHuZ3ITts59za/db8SGQSX8jtooCDVcJhYhQjTt5gpiJGkRXCz/QRC48ixrLt/K0Q== 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)(396003)(346002)(136003)(39860400002)(376002)(451199021)(40470700004)(36840700001)(46966006)(36860700001)(83380400001)(81166007)(82740400003)(356005)(40460700003)(36756003)(8936002)(5660300002)(8676002)(7416002)(41300700001)(82310400005)(40480700001)(86362001)(4326008)(316002)(70206006)(70586007)(426003)(47076005)(16526019)(110136005)(26005)(186003)(336012)(2906002)(478600001)(2616005)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2023 16:25:20.1398 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04c1b3d1-eeb3-43a3-621a-08db5885a3aa 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: CO1NAM11FT080.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB8572 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,URIBL_BLOCKED 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-kernel@vger.kernel.org From: Dionna Glaze The UEFI v2.9 specification includes a new memory type to be used in environments where the OS must accept memory that is provided from its host. Before the introduction of this memory type, all memory was accepted eagerly in the firmware. In order for the firmware to safely stop accepting memory on the OS's behalf, the OS must affirmatively indicate support to the firmware. This is only a problem for AMD SEV-SNP, since Linux has had support for it since 5.19. The other technology that can make use of unaccepted memory, Intel TDX, does not yet have Linux support, so it can strictly require unaccepted memory support as a dependency of CONFIG_TDX and not require communication with the firmware. Enabling unaccepted memory requires calling a 0-argument enablement protocol before ExitBootServices. This call is only made if the kernel is compiled with UNACCEPTED_MEMORY=y This protocol will be removed after the end of life of the first LTS that includes it, in order to give firmware implementations an expiration date for it. When the protocol is removed, firmware will strictly infer that a SEV-SNP VM is running an OS that supports the unaccepted memory type. At the earliest convenience, when unaccepted memory support is added to Linux, SEV-SNP may take strict dependence in it. After the firmware removes support for the protocol, this patch should be reverted. [tl: address some checkscript warnings] Cc: Ard Biescheuvel Cc: "Min M. Xu" Cc: Gerd Hoffmann Cc: James Bottomley Cc: Tom Lendacky Cc: Jiewen Yao Cc: Erdem Aktas Cc: "Kirill A. Shutemov" Cc: Dave Hansen Cc: Borislav Petkov Signed-off-by: Dionna Glaze Signed-off-by: Tom Lendacky --- drivers/firmware/efi/libstub/x86-stub.c | 36 +++++++++++++++++++++++++ include/linux/efi.h | 3 +++ 2 files changed, 39 insertions(+) diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 8d17cee8b98e..e2193dbe1f66 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -26,6 +26,17 @@ const efi_dxe_services_table_t *efi_dxe_table; u32 image_offset __section(".data"); static efi_loaded_image_t *image = NULL; +typedef union sev_memory_acceptance_protocol sev_memory_acceptance_protocol_t; +union sev_memory_acceptance_protocol { + struct { + efi_status_t (__efiapi * allow_unaccepted_memory)( + sev_memory_acceptance_protocol_t *); + }; + struct { + u32 allow_unaccepted_memory; + } mixed_mode; +}; + static efi_status_t preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) { @@ -310,6 +321,29 @@ setup_memory_protection(unsigned long image_base, unsigned long image_size) #endif } +static void setup_unaccepted_memory(void) +{ + efi_guid_t mem_acceptance_proto = OVMF_SEV_MEMORY_ACCEPTANCE_PROTOCOL_GUID; + sev_memory_acceptance_protocol_t *proto; + efi_status_t status; + + if (!IS_ENABLED(CONFIG_UNACCEPTED_MEMORY)) + return; + + /* + * Enable unaccepted memory before calling exit boot services in order + * for the UEFI to not accept all memory on EBS. + */ + status = efi_bs_call(locate_protocol, &mem_acceptance_proto, NULL, + (void **)&proto); + if (status != EFI_SUCCESS) + return; + + status = efi_call_proto(proto, allow_unaccepted_memory); + if (status != EFI_SUCCESS) + efi_err("Memory acceptance protocol failed\n"); +} + static const efi_char16_t apple[] = L"Apple"; static void setup_quirks(struct boot_params *boot_params, @@ -908,6 +942,8 @@ asmlinkage unsigned long efi_main(efi_handle_t handle, setup_quirks(boot_params, bzimage_addr, buffer_end - buffer_start); + setup_unaccepted_memory(); + status = exit_boot(boot_params, handle); if (status != EFI_SUCCESS) { efi_err("exit_boot() failed!\n"); diff --git a/include/linux/efi.h b/include/linux/efi.h index 9864f9c00da2..8c5abcf70a05 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -437,6 +437,9 @@ void efi_native_runtime_setup(void); #define DELLEMC_EFI_RCI2_TABLE_GUID EFI_GUID(0x2d9f28a2, 0xa886, 0x456a, 0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55) #define AMD_SEV_MEM_ENCRYPT_GUID EFI_GUID(0x0cf29b71, 0x9e51, 0x433a, 0xa3, 0xb7, 0x81, 0xf3, 0xab, 0x16, 0xb8, 0x75) +/* OVMF protocol GUIDs */ +#define OVMF_SEV_MEMORY_ACCEPTANCE_PROTOCOL_GUID EFI_GUID(0xc5a010fe, 0x38a7, 0x4531, 0x8a, 0x4a, 0x05, 0x00, 0xd2, 0xfd, 0x16, 0x49) + typedef struct { efi_guid_t guid; u64 table; -- 2.40.0