From nobody Thu Mar 28 17:24:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599253932; cv=none; d=zohomail.com; s=zohoarc; b=drde/rY850LcAtr9P3l4HOrvFEhAUVhAoFSQSV/6SmwakwuYAjy1DC97RdRn9fqKsNMtAlyu2SWTkhQWxlY1NlYpRnhk4GD7nIjtrxPwGXYemm5LW9AOY1WxTWxc3GB/7njKhUCdVLAOGu6mIeQ4n6GNS0tLDLgRLyBXu0lYk0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599253932; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=//KXuylVvthkDJr5aVQkUH3yamZO89ultIey67juH/k=; b=Uhn3xfRWmhHa9E/Zv/X7jotuy+R9ftcgw4KVQFAWax25mQkBao7o2HwssnTQZRZTBvZ7BXITEk2dde/XvfmJgsATkY+qx5o/iT6Zmcn1++2N3ChUcIPemgRcEUptE2NT+ioqJoYa8xlYkZN//nDjvyL8JfAdxRalGYBGv7dRhaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1599253932858403.2436681187311; Fri, 4 Sep 2020 14:12:12 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kEIzw-00044h-Qm; Fri, 04 Sep 2020 21:11:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kEIzw-00044c-5G for xen-devel@lists.xenproject.org; Fri, 04 Sep 2020 21:11:52 +0000 Received: from mail-lf1-x143.google.com (unknown [2a00:1450:4864:20::143]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id bf6c73fe-3394-4bd5-a4e7-9a533994c092; Fri, 04 Sep 2020 21:11:51 +0000 (UTC) Received: by mail-lf1-x143.google.com with SMTP id y2so4529539lfy.10 for ; Fri, 04 Sep 2020 14:11:51 -0700 (PDT) Received: from PRECISION-M4800.localdomain (109-252-108-19.nat.spd-mgts.ru. [109.252.108.19]) by smtp.googlemail.com with ESMTPSA id n8sm721542lji.1.2020.09.04.14.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 14:11:48 -0700 (PDT) X-Inumbo-ID: bf6c73fe-3394-4bd5-a4e7-9a533994c092 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=//KXuylVvthkDJr5aVQkUH3yamZO89ultIey67juH/k=; b=kh2E3pFRqSejH/ZqsyUyLkjTHTADLExdRzlhCqHGP01HatEp9cQsJv7y7cBFHwUcgC 14ynFwVxuastsGnWYMwHcGJEgaG25NKGS1hC8K9nRwDyfqZCiovpr4zr+cA4kotjWmAS 1UFhlnRaFWqFHeonaeIB61T9mQNwYdq7SGxJnt8gqxCVkUI8I9cAOeSv7D2R6qmgPgeT bmsMvf4wGSqD0u1rIWGEaxDVvvxKMc9HcS5Aiu1l8w/fvjziZk56FNQGq2ege+KRkkG6 F6ippZXwLVejGo9uLjyr3mNbQoQzts0+uQe9pEJsNv89F5EoylyCjxyjf9gU1QTpffUq 8BXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=//KXuylVvthkDJr5aVQkUH3yamZO89ultIey67juH/k=; b=Pzryi5ilWk8B4DOCIsSKSE5EOdZr8oxOHM68vgX9BnKfEQ7r8isdqC/QXVitcpu2Wn PQ2XfyzRzOTilNNw2W/13y4SltsZ/QdYzwjGS2QHDqFQ8WfA8G4OfvQT2knCMc0Qm07p 3ghuRPr9wH4xSvezmm7L45lg+mDDu8/ZDsB9vEE6e28bXrCDRmjQaD8kszh0A36S1dgn njIfnRYJbjciVE6YD4IdZTw84hShkm1LXSuwLbPGG4b/JncwQNHIJuZl/k6XmOKOk8dY hp4A2yB8zkHo3gLg5MTK6bF36n346BkbghBVxYBmnDO/mf99LNHibFrCc2BBDQ9836Es f22w== X-Gm-Message-State: AOAM531MuLBAFFh+ndeEYgsce32NRFPjGgCYFO9ANPKIUcZ8W5ysB06X eNzQn6PNemz9VeVTSUbusrdUuPv+dKGE6g== X-Google-Smtp-Source: ABdhPJytt+h7hUnNAlIjXGn1gnOAiIeAJVkciJ+Tfud5YBvXrahetapMuG51DPHMdd4fXhOjHcFtUA== X-Received: by 2002:a19:42c4:: with SMTP id p187mr4703915lfa.149.1599253909658; Fri, 04 Sep 2020 14:11:49 -0700 (PDT) From: Sergey Temerkhanov To: xen-devel@lists.xenproject.org Cc: Sergey Temerkhanov , Jan Beulich Subject: [PATCH v2] efi: Always map EfiRuntimeServicesCode and EfiRuntimeServicesData Date: Sat, 5 Sep 2020 00:11:40 +0300 Message-Id: <20200904211140.9875-1-s.temerkhanov@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" This helps overcome problems observed with some UEFI implementations which don't set the Attributes field in memery descriptors properly Signed-off-by: Sergey Temerkhanov --- xen/common/efi/boot.c | 19 ++++++++++++++++++- xen/include/efi/efidef.h | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 5a520bf21d..05cfbf4de0 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1100,7 +1100,9 @@ static void __init efi_exit_boot(EFI_HANDLE ImageHand= le, EFI_SYSTEM_TABLE *Syste { EFI_MEMORY_DESCRIPTOR *desc =3D efi_memmap + i; =20 - if ( desc->Attribute & EFI_MEMORY_RUNTIME ) + if ( (desc->Attribute & EFI_MEMORY_RUNTIME) || + desc->Type =3D=3D EfiRuntimeServicesCode || + desc->Type =3D=3D EfiRuntimeServicesData ) desc->VirtualStart =3D desc->PhysicalStart; else desc->VirtualStart =3D INVALID_VIRTUAL_ADDRESS; @@ -1510,6 +1512,21 @@ void __init efi_init_memory(void) desc->PhysicalStart, desc->PhysicalStart + len - 1, desc->Type, desc->Attribute); =20 + if (efi_enabled(EFI_RS) && + (!(desc->Attribute & EFI_MEMORY_RUNTIME) && + (desc->Type =3D=3D EfiRuntimeServicesCode || + desc->Type =3D=3D EfiRuntimeServicesData))) { + printk(XENLOG_WARNING "Fixing memory attributes for area %013" + PRIx64 "-%013" PRIx64 "\n", + desc->PhysicalStart, desc->PhysicalStart + len - 1); + desc->Attribute |=3D EFI_MEMORY_RUNTIME; + if ( !(desc->Attribute & EFI_MEMORY_CACHEABILITY_MASK) ) { + desc->Attribute |=3D (desc->Type =3D=3D EfiRuntimeServices= Code) && + (efi_bs_revision >=3D EFI_REVISION(2, 5= )) ? + EFI_MEMORY_WP : EFI_MEMORY_UC; + } + } + if ( (desc->Attribute & (EFI_MEMORY_WB | EFI_MEMORY_WT)) || (efi_bs_revision >=3D EFI_REVISION(2, 5) && (desc->Attribute & EFI_MEMORY_WP)) ) diff --git a/xen/include/efi/efidef.h b/xen/include/efi/efidef.h index 86a7e111bf..05170da2db 100644 --- a/xen/include/efi/efidef.h +++ b/xen/include/efi/efidef.h @@ -158,6 +158,9 @@ typedef enum { #define EFI_MEMORY_UCE 0x0000000000000010 =20 #define EFI_MEMORY_WP 0x0000000000001000 =20 +#define EFI_MEMORY_CACHEABILITY_MASK \ + 0x000000000000101F + // physical memory protection on range=20 #define EFI_MEMORY_RP 0x0000000000002000 #define EFI_MEMORY_XP 0x0000000000004000 --=20 2.26.2