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

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


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 4 Oct 2022 14:59:17 +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=waDwAaiXiRRXDcBI8kJO/v0XUalPOoo5kuxE445hk1M=; b=b6zPHxJMYA3JYhh4F1VYNnjHXM2fQd8r4jkYt6jA42+p3ghF14P2qrUOKVWss/QLAT/yUZ6R3ZK6s6peXlwAVtTXbBGYr4rbw7dLThF/bZEdYfRSWx+v2KawRBsPnW9ZPtTFXDGYCnwdjEnP6HQVF09Ifz9b/7voZyurtz9Xz2PB0j3krmh+feQlFrPT5eP/9g6PhSwuY+ORz6OUvUvWqOYI9ZkCiwkdUP7kT00VQvUvMW4tCO3p86SAxNCKfSAF6xC7/73q2edfK4GZyJsoLEZ/q77SkDFWTkg6ipGrzaySH70dNf3IhPwRR+xbsKFvXlUokdeJAYm8xwpvsKaqPQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QS7AEi54ObmODJ7ufodLA7Rx2V80tejm3ERSoaa+bI/exywH6hTvqkGonMeMn0zgDYHLzVyVopUG0zZtKw7hUCAAIQOA+cuE4jbWn4kqYa1PiCIFvrmc67aFtG11uvfS+NFRH/4p7Lla9vS/k/ZjbfaFpw5EyR1b8FVFQUQZk5HiwuxVSxCbmQEeLKwX/2b4/OYMa3RMpGIDrqbuqEoG1G6SO4/dBE4dp0nrJ0AAYxj4ufwvCDQ7ZZqI2AV0s/cIHbJehrnDW+jYbFwnWOfFRLC5eGOrB5Ye0VoXUUh4wEzobeGtYCOIdpAMxoVe/QzsnHL2CR9X+Rlxqpi9AhUHgQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 04 Oct 2022 12:59:34 +0000
  • Ironport-data: A9a23:iEwpSay5HNTVRIp0/2t6t+ctxyrEfRIJ4+MujC+fZmUNrF6WrkVVz zMXWz+Aa/uLYjekLo8kb4q180oF6pfTy9JmGQRs/yAxQypGp/SeCIXCJC8cHc8wwu7rFxs7s ppEOrEsCOhuExcwcz/0auCJQUFUjP3OHPykYAL9EngZbRd+Tys8gg5Ulec8g4p56fC0GArIs t7pyyHlEAbNNwVcbyRFtspvlDs15K6o4WtA4gRkDRx2lAS2e0c9Xcp3yZ6ZdxMUcqEMdsamS uDKyq2O/2+x13/B3fv8z94X2mVTKlLjFVDmZkh+AsBOsTAbzsAG6Y4pNeJ0VKtio27hc+ada jl6ncfYpQ8BZsUgkQmGOvVSO3kW0aZuoNcrLZUj2CA6IoKvn3bEmp1T4E8K0YIwyON3L2J+s uwjdRMxTQiKhe+U+66cY7w57igjBJGD0II3nFhFlGicJ9B2BJfJTuPN+MNS2yo2ioZWB/HCa sEFaD1pKhPdfxlIPVRRA5U79AuqriCnL3sE9xTI9exuvTi7IA9ZidABNPLPfdOHX4NNl1uwr WPa5WXpRBodMbRzzBLVqyry3rOVzEsXXqoCJb/o/aJg3GbM/UgDTy07Flu7ruCm3xvWt9V3b hZ8FjAVhao4+VGvT9L9dwalu3PCtRkZM/JPF8Uq5QfLzbDbiy6JC25BQjNfZdgOsM4tWSdsx lKPh8nuBzFkrPuSU331y1uPhTa7OCxQJ2lSYyYBFFIB+4O6/tF1iQ/TRNF+FqLzlsfyBTz73 zGNqm45mqkXiskIka68+Dgrng6Rm3QAdSZtji2/Y45vxlohDGJ5T+REMWTm0Ms=
  • Ironport-hdrordr: A9a23:htUIJKxOn3btlmwmIkr/KrPxt+skLtp133Aq2lEZdPULSKGlfp GV9sjziyWetN9wYh4dcB67Scy9qFfnhOZICO4qTMyftWjdyRKVxeRZgbcKrAeBJ8STzJ8/6U 4kSdkFNDSSNykEsS+Z2njeLz9I+rDunsGVbKXlvhFQpGlRGt1dBmxCe2Km+yNNNWt77c1TLu vg2iMLnUvXRV0nKuCAQlUVVenKoNPG0LrgfB49HhYirC2Dlymh5rLWGwWRmk52aUIG/Z4StU z+1yDp7KSqtP+2jjfaym/o9pxT3P/s0MFKCsCggtUcbh/slgGrToJ8XKDqhkF9nMifrHIR1P XcqRYpOMp+r1vXY2GOuBPonzLt1T4/gkWSvGOwsD/Gm4jUVTg6A81OicZyaR3C8Xctu9l6ze Ziw3+Zn4A/N2KNoA3No/zzEz16nEu9pnQv1cQJiWZEbIcYYLhN6aQC4UJuFosaFi6S0vFrLA BXNrCT2B9qSyLaU5iA1VMfgOBEH05DVCtue3Jy9fB8iFNt7TNEJ0hx/r1sop5PzuN+d3B+3Z W1Dk1ZrsAxciYoV9MNOA4ge7rCNoWfe2O6DEuiZXLaKYogB1Xh77bK3ZRd3pDYRHVP9up4pK j8
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Oct 04, 2022 at 02:21:20PM +0200, Jan Beulich wrote:
> On 04.10.2022 14:17, Roger Pau Monné wrote:
> > On Tue, Oct 04, 2022 at 12:40:10PM +0200, Jan Beulich wrote:
> >> On 04.10.2022 11:27, Roger Pau Monné wrote:
> >>> On Tue, Oct 04, 2022 at 11:01:18AM +0200, Jan Beulich wrote:
> >>>> On 30.09.2022 16:17, Roger Pau Monne wrote:
> >>>>> 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>
> >>>>
> >>>> In the best case this is moving us from one way of being wrong to 
> >>>> another:
> >>>> So far we wrongly include BARs in E820_RESERVED (_if_ they can be
> >>>> legitimately covered by a EfiMemoryMappedIO region in the first place,
> >>>> which I'm not sure is actually permitted - iirc just like E820_RESERVED
> >>>> may not be used for BARs, this memory type also may not be), whereas with
> >>>> your change we would no longer report non-BAR MMIO space (chipset 
> >>>> specific
> >>>> ranges for example) as reserved. In fact I think the example you provide
> >>>> is at least partly due to bogus firmware behavior: The BAR is put in 
> >>>> space
> >>>> normally used for firmware specific memory (MMIO) ranges. I think 
> >>>> firmware
> >>>> should either assign the BAR differently or exclude the range from the
> >>>> memory map.
> >>>
> >>> Hm, I'm not sure the example is bogus, how would firmware request a BAR
> >>> to be mapped for run time services to access it otherwise if it's not
> >>> using EfiMemoryMappedIO?
> >>>
> >>> Not adding the BAR to the memory map in any way would mean the OS is
> >>> free to not map it for runtime services to access.
> >>
> >> My view is that BARs should not be marked for runtime services use. Doing
> >> so requires awareness of the driver inside the OS, which I don't think
> >> one can expect. If firmware needs to make use of a device in a system, it
> >> ought to properly hide it from the OS. Note how the potential sharing of
> >> an RTC requires special provisions in the spec, mandating driver awareness.
> >>
> >> Having a BAR expressed in the memory map also contradicts the ability of
> >> an OS to relocate all BARs of all devices, if necessary.
> > 
> > I've failed to figure out if there's a way in UEFI to report a device
> > is in use by the firmware.  I've already looked before sending the
> > patch (see also the post commit notes about for example not passing
> > through the device to any guest for obvious reason).
> > 
> > I've got no idea if Linux has any checks to avoid trying to move BARs
> > residing in EfiMemoryMappedIO ranges, we have now observed this
> > behavior in two systems already.
> > 
> > Maybe we could do a special check for PCI devices and allow them
> > having BARs in EfiMemoryMappedIO, together with printing a warning
> > message.
> 
> Right, that's one of the possible quirk workarounds I was thinking of.
> At the risk of stating the obvious - the same would presumably apply to
> E820_RESERVED on non-EFI systems then.

One option would be to strictly limit to EfiMemoryMappedIO, by taking
the EFI memory map into account also if present.

Another maybe simpler option is to allow BARs to be placed in
E820_RESERVED regions, and translate EfiMemoryMappedIO into
E820_RESERVED like we have been doing.

I will attempt the later if you are OK with the approach.

Thanks, Roger.



 


Rackspace

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