Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3941349pxj; Mon, 21 Jun 2021 09:50:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4rWPMgUpbrUTava3dv79EeTgfF/1DjIjJqFN5u/iwk8jvFytRZpR1vfqKBJaMr9UOem4A X-Received: by 2002:a92:d906:: with SMTP id s6mr9440079iln.12.1624294252688; Mon, 21 Jun 2021 09:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624294252; cv=none; d=google.com; s=arc-20160816; b=eHxsoeswob8ybEFpZfh58R0IAFe/TKQ473L7mKMT4t5KPSwrDE6mr6huu0akuWhpJZ kZdyeNqcpdVyf8zqRCt8IgWrGo7/Rp0SI7Bbvyl9QQ5y83pvHODRV2CO2YHnUX6hbRFs J2c+GQeKJnpeUOPxmJxLXZCXBeEgRPYRPKmtPrP5lKAYzQ5TolBGgouo/5O+sTJvcQN4 5X4zf4vEBbUf8zyIIa/E2Tb0+SCRyZViRYhEy+ec9IAH1XrqYlIYs3kMR5qO5GhT7KFx zMAZCFGFd0WHjb6IwI5l+PxVg1KayIIkF1saWEyiBJjDe06M1cXEFWJCsU65s28cvYrI 1Uvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=J4+DGq/mbs/cd8owe8kVhxWcwBU8R09PKtQ9hu/9F8I=; b=g6kRl3gDoZAggM8N2q/j7TnyPENNpwh9pkRva8K4AxGAwYrlsDOoE6/iYqPd9zhSO1 4pEzNKAfsf38YL42izY3ZlPTUKPiAhhVMpUJwsuL/YjB5YSvKNiG8DrBoxWQwC8Yzuo9 xYonscggW0kE+nAvoo5wT6ojPtnBkUWSgPtI6Zx0IxZV5Xuj5+TfPnQYg8nkmyk3+6GS FjrSaD/+PSa08U3Qbs9FNmEZ43sqIXTLplggH0zS75ImoAXn7lMLVAkPHkRo7nATbNFt kcA/LAvS2qRF4NtkbnDPyWkI6PANWevLUEg5ilpIPr9guRM3hI8xwq6OiqtIN+eT07k9 5cpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WmdFjhXz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c4si1539925ilm.10.2021.06.21.09.50.41; Mon, 21 Jun 2021 09:50:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WmdFjhXz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231144AbhFUQvD (ORCPT + 99 others); Mon, 21 Jun 2021 12:51:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:38068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232537AbhFUQrq (ORCPT ); Mon, 21 Jun 2021 12:47:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B66AC61418; Mon, 21 Jun 2021 16:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624293217; bh=Kx5gsh0tLRYTOoK4Dnww7+GDnHFfBKKOzu5ZzMlGyaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WmdFjhXzo4gm3PEtW6kek8xuZyIxImHSzaitcg06Ki3M/+vqFm+zj5dEqOCEZTxF6 4xEwM0Yj01tTgyr8r2JDScMViydhGvqt5kFGXwAjAVzRA7xyE0Z1xz8YoZfgbY396d 59rGx3GAh1RcFqQ0EBLsNm83RuU4ukDCl90IHHAE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joerg Roedel , Tom Lendacky , Borislav Petkov Subject: [PATCH 5.12 142/178] x86/ioremap: Map EFI-reserved memory as encrypted for SEV Date: Mon, 21 Jun 2021 18:15:56 +0200 Message-Id: <20210621154927.604089185@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Lendacky commit 8d651ee9c71bb12fc0c8eb2786b66cbe5aa3e43b upstream. Some drivers require memory that is marked as EFI boot services data. In order for this memory to not be re-used by the kernel after ExitBootServices(), efi_mem_reserve() is used to preserve it by inserting a new EFI memory descriptor and marking it with the EFI_MEMORY_RUNTIME attribute. Under SEV, memory marked with the EFI_MEMORY_RUNTIME attribute needs to be mapped encrypted by Linux, otherwise the kernel might crash at boot like below: EFI Variables Facility v0.08 2004-May-17 general protection fault, probably for non-canonical address 0x3597688770a868b2: 0000 [#1] SMP NOPTI CPU: 13 PID: 1 Comm: swapper/0 Not tainted 5.12.4-2-default #1 openSUSE Tumbleweed Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 RIP: 0010:efi_mokvar_entry_next [...] Call Trace: efi_mokvar_sysfs_init ? efi_mokvar_table_init do_one_initcall ? __kmalloc kernel_init_freeable ? rest_init kernel_init ret_from_fork Expand the __ioremap_check_other() function to additionally check for this other type of boot data reserved at runtime and indicate that it should be mapped encrypted for an SEV guest. [ bp: Massage commit message. ] Fixes: 58c909022a5a ("efi: Support for MOK variable config table") Reported-by: Joerg Roedel Signed-off-by: Tom Lendacky Signed-off-by: Joerg Roedel Signed-off-by: Borislav Petkov Tested-by: Joerg Roedel Cc: # 5.10+ Link: https://lkml.kernel.org/r/20210608095439.12668-2-joro@8bytes.org Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/ioremap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -118,7 +118,9 @@ static void __ioremap_check_other(resour if (!IS_ENABLED(CONFIG_EFI)) return; - if (efi_mem_type(addr) == EFI_RUNTIME_SERVICES_DATA) + if (efi_mem_type(addr) == EFI_RUNTIME_SERVICES_DATA || + (efi_mem_type(addr) == EFI_BOOT_SERVICES_DATA && + efi_mem_attributes(addr) & EFI_MEMORY_RUNTIME)) desc->flags |= IORES_MAP_ENCRYPTED; }