From patchwork Fri Sep 11 14:43:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Temerkhanov X-Patchwork-Id: 11770773 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0072B92C for ; Fri, 11 Sep 2020 14:43:52 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C2E65222D5 for ; Fri, 11 Sep 2020 14:43:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IbNWkAjU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C2E65222D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kGkGn-0002hi-LF; Fri, 11 Sep 2020 14:43:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kGkGm-0002hV-M6 for xen-devel@lists.xenproject.org; Fri, 11 Sep 2020 14:43:20 +0000 X-Inumbo-ID: 471c8463-3cd1-4c16-b695-ac17ad5da6d6 Received: from mail-lf1-x143.google.com (unknown [2a00:1450:4864:20::143]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 471c8463-3cd1-4c16-b695-ac17ad5da6d6; Fri, 11 Sep 2020 14:43:19 +0000 (UTC) Received: by mail-lf1-x143.google.com with SMTP id y17so6101221lfa.8 for ; Fri, 11 Sep 2020 07:43:19 -0700 (PDT) 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=BvedKb7Sr/CE7Ttt3dYfKDZQEiZgHq5KXUSwKLJ8TUw=; b=IbNWkAjUo8+dg9GgHHyX111rI8DTV5Yflz0u/9zlMSHjxFn2eveetaNRoUV3vJUW8L is9P18GtxqaSfU34d8891p92Fd+pfvc34DyEWP64U6Q9h2LaqFgU4Qb7tR4TOMzK2Tc+ EEyRQWygKj8uTsvJvmG8+IVR9bwgLJNnXzeq4b8XfaTAEpBBtdlsSCMkJB82+RVXPPzV VXzf6n5zcGf1YC0rJMukxq4E7VLhFhKbZ70qxvfcKusqWh8/vd8SpL9lNXOsFa7gmnpP B9cvLdn0vA0CM0J3il/fT0/GgUGX3rxr28LtY1bL5A/nbmyW0azKURGzbf7tr9rPflwk SPWQ== 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=BvedKb7Sr/CE7Ttt3dYfKDZQEiZgHq5KXUSwKLJ8TUw=; b=BQK15sUzRdirYdrgp5z1T1/G5bvEEMFQfmOQYy94BbkvdDxwun9ZMgyf55fslwYbfp TDE/PDKshefSKWTPMVB9myPmM7reZVFz5mhez1n4rrH58i3SzVc1jvhitFD++EJ6wLNk xI5es9DIbLG+r1htjCr4t7A4155qYVoIdONjlNIBCR8bCbmg0Nr0Qba+ab+5VKW8XQtl /RI8mAo3YIzNYH1jzKpUv8ugZGRNgdlSr0iNJehhhrayY1xmG9ye9/7z6LNdT8cxpaWV LxZL3dWmPWcSdCfRiebKEN1gm43BK9LJYWLfbWApMkP5KwF58gw/Sm7pArk4HbrIWVcm x8Vg== X-Gm-Message-State: AOAM531BZ5HzBoines22M0moPQ+hYF01rVPBv/Q8bH35M1iodi+o0cjp qtkRkKEnZAfvVvjZaOdtYDJlrb6STFO2xg== X-Google-Smtp-Source: ABdhPJzq4usMM46y/jRSMDiUmTNxSfrCGy74bejcm9RGjpuRNuz8vWj2UxaoxRX8BD5+jo7kL3pKSQ== X-Received: by 2002:a05:6512:370e:: with SMTP id z14mr909773lfr.80.1599835398357; Fri, 11 Sep 2020 07:43:18 -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 z22sm459268lfd.23.2020.09.11.07.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 07:43:17 -0700 (PDT) From: Sergey Temerkhanov To: xen-devel@lists.xenproject.org Cc: Sergey Temerkhanov , Jan Beulich Subject: [PATCH v3] efi: Always map EfiRuntimeServicesCode and EfiRuntimeServicesData Date: Fri, 11 Sep 2020 17:43:09 +0300 Message-Id: <20200911144309.4559-1-s.temerkhanov@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 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" 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 | 27 ++++++++++++++++++++++++++- xen/include/efi/efidef.h | 6 ++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 5a520bf21d..811d8a0923 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1100,7 +1100,14 @@ static void __init efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *Syste { EFI_MEMORY_DESCRIPTOR *desc = efi_memmap + i; - if ( desc->Attribute & EFI_MEMORY_RUNTIME ) + /* + * EfiRuntimeServicesCode and EfiRuntimeServicesData + * memory ranges are always mapped here. + * Attributes may be adjusted in efi_init_memory() + */ + if ( (desc->Attribute & EFI_MEMORY_RUNTIME) || + desc->Type == EfiRuntimeServicesCode || + desc->Type == EfiRuntimeServicesData ) desc->VirtualStart = desc->PhysicalStart; else desc->VirtualStart = INVALID_VIRTUAL_ADDRESS; @@ -1510,6 +1517,24 @@ void __init efi_init_memory(void) desc->PhysicalStart, desc->PhysicalStart + len - 1, desc->Type, desc->Attribute); + /* + * EfiRuntimeServicesCode and EfiRuntimeServicesData + * memory ranges are adjusted here. Any changes + * or adjustments must be kept in sync with efi_exit_boot() + */ + if ( efi_enabled(EFI_RS) && + (!(desc->Attribute & EFI_MEMORY_RUNTIME) && + (desc->Attribute & EFI_MEMORY_CACHEABILITY_MASK) && + (desc->Type == EfiRuntimeServicesCode || + desc->Type == EfiRuntimeServicesData)) ) + { + printk(XENLOG_WARNING + "Setting EFI_RUNTIME memory attribute for area %013" + PRIx64 "-%013" PRIx64 "\n", + desc->PhysicalStart, desc->PhysicalStart + len - 1); + desc->Attribute |= EFI_MEMORY_RUNTIME; + } + if ( (desc->Attribute & (EFI_MEMORY_WB | EFI_MEMORY_WT)) || (efi_bs_revision >= 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..3a35bfc8be 100644 --- a/xen/include/efi/efidef.h +++ b/xen/include/efi/efidef.h @@ -158,6 +158,12 @@ typedef enum { #define EFI_MEMORY_UCE 0x0000000000000010 #define EFI_MEMORY_WP 0x0000000000001000 +#define EFI_MEMORY_CACHEABILITY_MASK ( EFI_MEMORY_UC | \ + EFI_MEMORY_WC | \ + EFI_MEMORY_WT | \ + EFI_MEMORY_WB | \ + EFI_MEMORY_UCE ) + // physical memory protection on range #define EFI_MEMORY_RP 0x0000000000002000 #define EFI_MEMORY_XP 0x0000000000004000