[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH for-4.17] x86/efi: don't translate EFI memory map MMIO regions to e820 RESERVED


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Fri, 30 Sep 2022 16:17:37 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • 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=j4P5LOK2FjEE0nC05OzIne4cDkC1S7mT9I06GQuHXkk=; b=HKCW9PdC2i40ul2g/XM9sNKGl+O/hWgGG0oE3JFL1DMk/7eHrlGmokX/hkqtuKCEvjjj0+ydujWjHiuCykbpEzROrWiPZ217yGZIDxNondSu4qH6g4QyTAuInEHmTQ7Orxiayq/05ELeQKp1BZNizPEWzZzNsWhclg3qHyikg++BdWGkLbhd4RKsEYlwSyYDRJnOy0LATkZWYpj/XOjVY4+GGMIzjq8GPzSatORM/xnH55c2dWNskRHyAOGtCya+HAOh6JuhAqG2Rsqlr93F6A9bToarC47UEr0DXlvsS45F0Qjm4MjOZwxDmaTY8sJMyjEdQrtMDbilW8hYddEv/A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FMYiRb0O5Zn71KJz/eIohqSr0RY+a+NJkIeU8kgLK2gbpWx4wEYuga140uLED4BbhJPI5Z+4NigNWwOQc429G4d2iMuSytRUChkK904ShKvwK2nWsPy+62Q810nRIpY7sMhh12g/TFkeA+azfZJyxao8bkYo4fULyKishDgfgvCfJLJMKJK56pAT4VEzueT/1Zf7wH+71b0f8r+0LeUiN4k8NpOz/LhZausIK1R2PODMjKRSAMklrxYmmTcA7dKfW1X+AaVrBtpQZKNJOX+7ykIqJxBxgLSqBXONXYt1/HrkdozZxFC3JG7bUxH615N9i4A6aE9jBq0WnxE6MW5uPw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 30 Sep 2022 14:18:46 +0000
  • Ironport-data: A9a23:hWokVK14EVjRqnVx9PbD5chwkn2cJEfYwER7XKvMYLTBsI5bp2dVn 2VMXWzSbqyDNzH2fY92Oou18R9QusTRx4VnSAJtpC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliefSAOKU5NfsYkhZXRVjRDoqlSVtkus4hp8AqdWiCkaGt MiaT/f3YTdJ4BYpdDNPg06/gEk35q6q6WhA5gZWic1j5zcyqVFEVPrzGonpR5fIatE8NvK3Q e/F0Ia48gvxl/v6Ior4+lpTWhRiro/6ZWBiuFIPM0SRqkEqShgJ+rQ6LJIhhXJ/0F1lqTzTJ OJl7vRcQS9xVkHFdX90vxNwS0mSNoUekFPLzOTWXWV+ACQqflO1q8iCAn3aMqVB3vtMGmIN2 8UbDzsJKRWnq7Kk64u0H7wEasQLdKEHPas5k1Q4l3TiK69jRprOBaLX+dVfwTE8wNhUGurTb NYYbjwpawncZxpIOREcD5dWcOWA3yGjNWEH7g/K4/Zui4TQ5FUZPLzFKt3ad8bMXcxItk2Zu njH7yLyBRRy2Nm3mWbfqSv21rWncSXTYpI8OYei3eRW3geBwExCEhQbTX2Hvqzs4qK5c5cFQ 6AOwQI+oK53+EG1Q93VWxyjvGXCrhMaQ8BXEeAx9EeK0KW8ywSTC3UATzVBQMc7r8JwTjsvv neWm/v5CDopt6eaIU9x7Z+RpDK2fDMTdGYEbCpcFw8duYG/+cc0kw7FSctlHOitlNrpFDrsw jeM6i8jm7EUis1N3KK+lbzavw+RSlHyZlZdzm3qsqiNs2uVuKbNi1SU1GXm
  • Ironport-hdrordr: A9a23:tN/7MKnf60JbDsVOtGH7ZWbOxezpDfPDimdD5ihNYBxZY6Wkfp +V8cjzhCWftN9OYhodcLC7V5Voj0msl6KdhrNhRYtKPTOWwVdASbsP0WKM+UyFJ8STzI5gPM RbAtVD4aPLfD9HZK/BiWHXcurIqOP3ipxA7t2uqkuFIzsaCJ2JuGxCe32m+wBNNX17LKt8MK DZyttMpjKmd3hSRsOnBkMdV+yGg9HQjprpbTMPGhZisWC1/EWVwY+/NyLd8gYVUjtJz7tn2W /Zkzbh7qHml/2g0BfT20La8pwTstr8zdloAtCKl6EuW0LRozftQL4kd6yJvTgzru3qwFE2kO PUqxNlBMh342O5RBDHnTLdny3blBo+4X7rzlGVxVH5p9bieT48A81dwapEbxrw8SMbzZtB+Z MO+1jcm4tcDBvGkii4zcPPTQtWmk29pmdnufIPjkZYTZAVZNZq3MciFXtuYds99R/Bmc8a+L EENrCT2B8WSyLTU5nhhBgj/DT2NU5DXytvQSA5y7yoOnZt7TBEJnAjtbIid0c7he4AoqZ/lp v529xT5ddzp+8tHNBA7bQ6ML6KI12IZy7wG0SvBnmiPJ07Ghv22u/KCfMOlaiXRKA=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The EFI memory map contains two memory types (EfiMemoryMappedIO and
EfiMemoryMappedIOPortSpace) used to describe IO memory areas of
devices used by EFI.

The current parsing of the EFI memory map was translating
EfiMemoryMappedIO and EfiMemoryMappedIOPortSpace to E820_RESERVED on
x86.  This is an issue because device MMIO regions (BARs) should not
be positioned on reserved regions.  Any BARs positioned on non-hole
areas of the memory map will cause is_memory_hole() to return false,
which would then cause memory decoding to be disabled for such device.
This leads to EFI firmware malfunctions when using runtime services.

The system under which this was observed has:

EFI memory map:
[...]
 00000fd000000-00000fe7fffff type=11 attr=800000000000100d
[...]
0000:00:1f.5 disabled: BAR [0xfe010, 0xfe010] overlaps with memory map

The device behind this BAR is:

00:1f.5 Serial bus controller [0c80]: Intel Corporation Lewisburg SPI 
Controller (rev 09)
        Subsystem: Super Micro Computer Inc Device 091c
        Flags: fast devsel
        Memory at fe010000 (32-bit, non-prefetchable) [size=4K]well

For the record, the symptom observed in that machine was a hard freeze
when attempting to set an EFI variable (XEN_EFI_set_variable).

Fix by not adding regions with type EfiMemoryMappedIO or
EfiMemoryMappedIOPortSpace to the e820 memory map, that allows BARs to
be positioned there.

Fixes: 75cc460a1b ('xen/pci: detect when BARs are not suitably positioned')
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
I don't understand the definition of EfiMemoryMappedIOPortSpace:

"System memory-mapped IO region that is used to translate memory
cycles to IO cycles by the processor."

But given its name I would assume it's also likely used to mark ranges
in use by PCI device BARs.

It would also be interesting to forward this information to dom0, so
it doesn't attempt to move the BARs of this device(s) around, or else
issues will arise.

And of course the device must not be passed through to domUs, as
disabling memory decoding on it can lead to a host DoS.  Not that it
makes much sense to pass devices like the one above to guests.

It also makes me wonder whether this playing with the decoding bit
that we do in Xen is safe.  It might be more resilient to only disable
memory decoding when the BARs overlap a RAM region, as that would
indeed cause issues.

We should also consider moving away from the e820 and instead using
the EFI memory map for things like is_memory_hole(), but that would
involve translating e820 memory maps into EFI format, which might be
easier and more reliable than the other way around which we currently
do.
---
 xen/arch/x86/efi/efi-boot.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index 836e8c2ba1..12ad94cd71 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -169,6 +169,14 @@ static void __init 
efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,
 
         switch ( desc->Type )
         {
+        case EfiMemoryMappedIO:
+        case EfiMemoryMappedIOPortSpace:
+            /*
+             * There no suitable e820 memory type to represent a MMIO area
+             * except a hole.
+             */
+            continue;
+
         case EfiBootServicesCode:
         case EfiBootServicesData:
             if ( map_bs )
-- 
2.37.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.