Re: [PATCH] x86/PCI: Conditionally add a non-e820 mapped window to root bridge

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

 




On 10/7/21 4:58 AM, Bjorn Helgaas wrote:
[+cc Myron, just FYI]

On Thu, Jun 24, 2021 at 05:53:24PM +0800, Hui Wang wrote:
The touchpad can't work on many Lenovo Ideapad S145/BS145 laptops.
But it works well under Windows.

On those machines, the touchpad is an I2C device, while the I2C host
controllers fail to initialize as below shown:
  pci 0000:00:15.0: BAR 0: no space for [mem size 0x00001000 64bit]
  pci 0000:00:15.0: BAR 0: failed to assign [mem size 0x00001000 64bit]
  pci 0000:00:15.1: BAR 0: no space for [mem size 0x00001000 64bit]
  pci 0000:00:15.1: BAR 0: failed to assign [mem size 0x00001000 64bit]

The BIOS assigns iomem space to host bridge and I2C host controller
like this:
  pci_bus 0000:00: root bus resource [mem 0x000a0000-0x000bffff window]
  pci_bus 0000:00: root bus resource [mem 0x65400000-0xbfffffff window]

  pci 0000:00:15.0: [8086:34e8] type 00 class 0x0c8000
  pci 0000:00:15.0: reg 0x10: [mem 0x00000000-0x00000fff 64bit]
  pci 0000:00:15.1: [8086:34e9] type 00 class 0x0c8000
  pci 0000:00:15.1: reg 0x10: [mem 0x00000000-0x00000fff 64bit]

The I2C host controllers need to allocate iomem space from root
bridge, but all iomem window of the root bridge are overlapped with
BIOS-e820 mapped region, that makes the allocate_resource() fail:
  BIOS-e820: [mem 0x0000000000000000-0x000000000009efff] usable
  BIOS-e820: [mem 0x000000000009f000-0x00000000000fffff] reserved
  ...
  BIOS-e820: [mem 0x000000004bc50000-0x00000000cfffffff] reserved

We could add "pci=nocrs" to make the touchpad work, but users expect
the touchpad to work out-of-box under Linux distro as under Windows.

Here design a generic solution for x86 machines, if host bridge uses
crs, we will check if all root bridge iomem windows are overlapped
with BIOS-e820 mapped region, if yes, we try to build a non-e820
mapped window according to the biggest gap in the e820 mapped region,
and we need to clip this window with MMCONFIG region if this region
is not mapped by BIOS-e820, then insert this window to the tail of
the root bridge.

After this change, the I2C host controller could allocate the iomem
region from host bridge successfully and the touchpad could work
out-of-box.
I see from
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1931715 that a
fix has been committed, I assume to the Ubuntu kernel, but I assume
this is still a problem for upstream and probably other distro
kernels.
No, the patch is not applied to Ubuntu kernels, Someone set it to committed by a mistake, and the bug status was changed back to confirmed already.
The 0-day bot found some issue, which I haven't looked at:
https://lore.kernel.org/r/20210627143859.GD17986@xsang-OptiPlex-9020
I reread the dmesg today, found all pci root bridges have at least one iomem window which is not overlapped with e820 reserved region, that is to say, in theory my patch will not assign new iomem window for any pci root bridges. So I don't know how my patch introduces the crashing on that machine.
I think this patch might be the wrong approach.  We learned from _CRS
that [mem 0x65400000-0xbfffffff window] is assigned to the PNP0A08:00
host bridge.

The e820 "[mem 0x000000004bc50000-0x00000000cfffffff] reserved" region
certainly includes all of that PCI aperture, and this entry should
prevent that space from being allocated to devices that haven't
already been assigned space.

But I don't think that e820 entry should prevent the PCI core from
managing that PCI aperture.  The platform told us that PNP0A08:00 owns
the [mem 0x65400000-0xbfffffff window], and the PNP0A08:00 driver
(pci_root.c) should be able to manage it as needed.

The e820 entry prevent the pci devices from getting the overlapped region by the path below:

kernel/resource.c:__find_resource()--->arch/x86/kernel/resource.c:arch_remove_reservations()--->remove_e820_regions()

Maybe we could remove arch_remove_reservations() as other architectures?


Regards,

Hui.


BugLink: http://bugs.launchpad.net/bugs/1931715
BugLink: http://bugs.launchpad.net/bugs/1932069
BugLink: http://bugs.launchpad.net/bugs/1921649
Cc: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
Cc: Yinghai Lu <yinghai@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
Cc: linux-acpi@xxxxxxxxxxxxxxx
Cc: linux-pci@xxxxxxxxxxxxxxx
Signed-off-by: Hui Wang <hui.wang@xxxxxxxxxxxxx>
---
  arch/x86/include/asm/e820/api.h |  1 +
  arch/x86/include/asm/pci.h      |  2 ++
  arch/x86/include/asm/pci_x86.h  |  1 +
  arch/x86/kernel/e820.c          |  2 ++
  arch/x86/pci/acpi.c             | 46 ++++++++++++++++++++++++++++++++-
  arch/x86/pci/mmconfig-shared.c  | 28 ++++++++++++++++++++
  6 files changed, 79 insertions(+), 1 deletion(-)




[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux