Skip to content
Permalink
Artem-Lapkin/P…
Switch branches/tags

Commits on Jun 18, 2021

  1. PCI: dwc: meson add quirk

    Device set same 256 bytes maximum read request size equal MAX_READ_REQ_SIZE
    was find some issue with HDMI scrambled picture and nvme devices
    at intensive writing...
    
    [    4.798971] nvme 0000:01:00.0: fix MRRS from 512 to 256
    
    This quirk setup same MRRS if we try solve this problem with
    pci=pcie_bus_perf kernel command line param
    
    Signed-off-by: Artem Lapkin <art@khadas.com>
    Artem Lapkin authored and intel-lab-lkp committed Jun 18, 2021

Commits on Jun 17, 2021

  1. Merge branch 'remotes/lorenzo/pci/xgene'

    - Annotate __iomem pointer (Bjorn Helgaas)
    
    - Fix kernel-doc comment (Krzysztof Wilczyński)
    
    * remotes/lorenzo/pci/xgene:
      PCI: xgene: Fix a non-compliant kernel-doc
      PCI: xgene: Annotate __iomem pointer
    bjorn-helgaas committed Jun 17, 2021
  2. Merge branch 'remotes/lorenzo/pci/tegra'

    - Fix host init during resume (Vidya Sagar)
    
    - Add missing MODULE_DEVICE_TABLE for driver loading (Zou Wei)
    
    * remotes/lorenzo/pci/tegra:
      PCI: tegra: Add missing MODULE_DEVICE_TABLE
      PCI: tegra: Fix host initialization during resume
    bjorn-helgaas committed Jun 17, 2021
  3. Merge branch 'remotes/lorenzo/pci/mobiveil'

    - Removed unused readl and writel functions (Krzysztof Wilczyński)
    
    * remotes/lorenzo/pci/mobiveil:
      PCI: mobiveil: Remove unused readl and writel functions
    bjorn-helgaas committed Jun 17, 2021
  4. Merge branch 'remotes/lorenzo/pci/microchip'

    - Make struct event_descs static (Krzysztof Wilczyński)
    
    * remotes/lorenzo/pci/microchip:
      PCI: microchip: Make the struct event_descs static
    bjorn-helgaas committed Jun 17, 2021
  5. Merge branch 'remotes/lorenzo/pci/mediatek'

    - Drop redundant error message from mtk_pcie_subsys_powerup() (Zhen Lei)
    
    * remotes/lorenzo/pci/mediatek:
      PCI: mediatek: Remove redundant error printing in mtk_pcie_subsys_powerup()
    bjorn-helgaas committed Jun 17, 2021
  6. Merge branch 'remotes/lorenzo/pci/hv'

    - Fix race when removing device (Long Li)
    
    - Remove unused bus device removal refcount/functions (Long Li)
    
    * remotes/lorenzo/pci/hv:
      PCI: hv: Remove bus device removal unused refcount/functions
      PCI: hv: Fix a race condition when removing the device
    bjorn-helgaas committed Jun 17, 2021
  7. Merge branch 'remotes/lorenzo/pci/ftpci100'

    - Rename PCI_IOSIZE, etc in ftpci100 to avoid macro name collisions (Randy
      Dunlap)
    
    * remotes/lorenzo/pci/ftpci100:
      PCI: ftpci100: Rename macro name collision
    bjorn-helgaas committed Jun 17, 2021
  8. Merge branch 'remotes/lorenzo/pci/dwc'

    - Drop redundant error message from imx6_pcie_probe() (Zhen Lei)
    
    * remotes/lorenzo/pci/dwc:
      PCI: dwc/imx6: Remove redundant error printing in imx6_pcie_probe()
    bjorn-helgaas committed Jun 17, 2021
  9. Merge branch 'pci/virtualization'

    - Clarify error message for unbound devices (Moritz Fischer)
    
    * pci/virtualization:
      PCI/IOV: Clarify error message for unbound devices
    bjorn-helgaas committed Jun 17, 2021
  10. Merge branch 'pci/sysfs'

    - Fix dsm_label_utf16s_to_utf8s() buffer overrun (Krzysztof Wilczyński)
    
    - Use sysfs_emit() and sysfs_emit_at() in "show" functions (Krzysztof
      Wilczyński)
    
    - Fix 'resource_alignment' newline issues (Krzysztof Wilczyński)
    
    - Add newline to 'devspec' sysfs file (Krzysztof Wilczyński)
    
    * pci/sysfs:
      PCI/sysfs: Add 'devspec' newline
      PCI/sysfs: Fix 'resource_alignment' newline issues
      PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions
      PCI/sysfs: Rely on lengths from scnprintf(), dsm_label_utf16s_to_utf8s()
      PCI/sysfs: Fix dsm_label_utf16s_to_utf8s() buffer overrun
    bjorn-helgaas committed Jun 17, 2021
  11. Merge branch 'pci/resource'

    - Coalesce host bridge apertures so we can allocate large BARs that cross
      contiguous apertures (Kai-Heng Feng)
    
    * pci/resource:
      PCI: Coalesce host bridge contiguous apertures
    bjorn-helgaas committed Jun 17, 2021
  12. Merge branch 'pci/pm'

    - Leave Apple Thunderbolt controllers on for s2idle or standby so they work
      after resume (Konstantin Kharlamov)
    
    * pci/pm:
      PCI: Leave Apple Thunderbolt controllers on for s2idle or standby
    bjorn-helgaas committed Jun 17, 2021
  13. Merge branch 'pci/p2pdma'

    - Rename Rename upstream_bridge_distance() to calc_map_type_and_dist()
      (Logan Gunthorpe)
    
    - Collect ACS list message in stack buffer to avoid sleeping (Logan
      Gunthorpe)
    
    - Use correct calc_map_type_and_dist() return type (Logan Gunthorpe)
    
    - Warn if host bridge not in whitelist (Logan Gunthorpe)
    
    - Refactor pci_p2pdma_map_type() (Logan Gunthorpe)
    
    - Avoid pci_get_slot(), which may sleep (Logan Gunthorpe)
    
    - Simplify distance calculation in __calc_map_type_and_dist() and
      calc_map_type_and_dist_warn() (Christoph Hellwig)
    
    * pci/p2pdma:
      PCI/P2PDMA: Simplify distance calculation
      PCI/P2PDMA: Avoid pci_get_slot(), which may sleep
      PCI/P2PDMA: Refactor pci_p2pdma_map_type()
      PCI/P2PDMA: Warn if host bridge not in whitelist
      PCI/P2PDMA: Use correct calc_map_type_and_dist() return type
      PCI/P2PDMA: Collect acs list in stack buffer to avoid sleeping
      PCI/P2PDMA: Rename upstream_bridge_distance() and rework doc
    bjorn-helgaas committed Jun 17, 2021
  14. Merge branch 'pci/misc'

    - Return true/false (not 1/0) from bool functions (Yang Li)
    
    * pci/misc:
      x86/pci: Return true/false (not 1/0) from bool functions
    bjorn-helgaas committed Jun 17, 2021
  15. Merge branch 'pci/hotplug'

    - Ignore pciehp Link Down/Up caused by DPC so device remains bound to
      driver (Lukas Wunner)
    
    * pci/hotplug:
      PCI: pciehp: Ignore Link Down/Up caused by DPC
    bjorn-helgaas committed Jun 17, 2021
  16. Merge branch 'pci/error'

    - Make domain/bus/dev/fn format in AER messages match pci_name() format
      (Yicong Yang)
    
    * pci/error:
      Documentation: PCI: Fix typo in pci-error-recovery.rst
      PCI/AER: Use consistent format when printing PCI device
    bjorn-helgaas committed Jun 17, 2021
  17. Merge branch 'pci/enumeration'

    - Add a debug message on PCI device release (Niklas Schnelle)
    
    - Dynamically map ECAM regions to reduce vmalloc usage (Russell King)
    
    * pci/enumeration:
      PCI: Dynamically map ECAM regions
      PCI: Print a debug message on PCI device release
    bjorn-helgaas committed Jun 17, 2021

Commits on Jun 16, 2021

  1. PCI: Dynamically map ECAM regions

    Attempting to boot 32-bit ARM kernels under QEMU's 3.x virt models fails
    when we have more than 512M of RAM in the model as we run out of vmalloc
    space for the PCI ECAM regions. This failure will be silent when running
    libvirt, as the console in that situation is a PCI device.
    
    In this configuration, the kernel maps the whole ECAM, which QEMU sets up
    for 256 buses, even when maybe only seven buses are in use.  Each bus uses
    1M of ECAM space, and ioremap() adds an additional guard page between
    allocations. The kernel vmap allocator will align these regions to 512K,
    resulting in each mapping eating 1.5M of vmalloc space. This means we need
    384M of vmalloc space just to map all of these, which is very wasteful of
    resources.
    
    Fix this by only mapping the ECAM for buses we are going to be using.  In
    my setups, this is around seven buses in most guests, which is 10.5M of
    vmalloc space - way smaller than the 384M that would otherwise be required.
    This also means that the kernel can boot without forcing extra RAM into
    highmem with the vmalloc= argument, or decreasing the virtual RAM available
    to the guest.
    
    Suggested-by: Arnd Bergmann <arnd@arndb.de>
    Link: https://lore.kernel.org/r/E1lhCAV-0002yb-50@rmk-PC.armlinux.org.uk
    Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Arnd Bergmann <arnd@arndb.de>
    Russell King authored and bjorn-helgaas committed Jun 16, 2021
  2. PCI: pciehp: Ignore Link Down/Up caused by DPC

    Downstream Port Containment (PCIe r5.0, sec. 6.2.10) disables the link upon
    an error and attempts to re-enable it when instructed by the DPC driver.
    
    A slot which is both DPC- and hotplug-capable is currently powered off by
    pciehp once DPC is triggered (due to the link change) and powered back up
    on successful recovery.  That's undesirable, the slot should remain powered
    so the hotplugged device remains bound to its driver.  DPC notifies the
    driver of the error and of successful recovery in pcie_do_recovery() and
    the driver may then restore the device to working state.
    
    Moreover, Sinan points out that turning off slot power by pciehp may foil
    recovery by DPC:  Power off/on is a cold reset concurrently to DPC's warm
    reset.  Sathyanarayanan reports extended delays or failure in link
    retraining by DPC if pciehp brings down the slot.
    
    Fix by detecting whether a Link Down event is caused by DPC and awaiting
    recovery if so.  On successful recovery, ignore both the Link Down and the
    subsequent Link Up event.
    
    Afterwards, check whether the link is down to detect surprise-removal or
    another DPC event immediately after DPC recovery.  Ensure that the
    corresponding DLLSC event is not ignored by synthesizing it and invoking
    irq_wake_thread() to trigger a re-run of pciehp_ist().
    
    The IRQ threads of the hotplug and DPC drivers, pciehp_ist() and
    dpc_handler(), race against each other.  If pciehp is faster than DPC, it
    will wait until DPC recovery completes.
    
    Recovery consists of two steps:  The first step (waiting for link
    disablement) is recognizable by pciehp through a set DPC Trigger Status
    bit.  The second step (waiting for link retraining) is recognizable through
    a newly introduced PCI_DPC_RECOVERING flag.
    
    If DPC is faster than pciehp, neither of the two flags will be set and
    pciehp may glean the recovery status from the new PCI_DPC_RECOVERED flag.
    The flag is zero if DPC didn't occur at all, hence DLLSC events are not
    ignored by default.
    
    pciehp waits up to 4 seconds before assuming that DPC recovery failed and
    bringing down the slot.  This timeout is not taken from the spec (it
    doesn't mandate one) but based on a report from Yicong Yang that DPC may
    take a bit more than 3 seconds on HiSilicon's Kunpeng platform.
    
    The timeout is necessary because the DPC Trigger Status bit may never
    clear:  On Root Ports which support RP Extensions for DPC, the DPC driver
    polls the DPC RP Busy bit for up to 1 second before giving up on DPC
    recovery.  Without the timeout, pciehp would then wait indefinitely for DPC
    to complete.
    
    This commit draws inspiration from previous attempts to synchronize DPC
    with pciehp:
    
    By Sinan Kaya, August 2018:
    https://lore.kernel.org/linux-pci/20180818065126.77912-1-okaya@kernel.org/
    
    By Ethan Zhao, October 2020:
    https://lore.kernel.org/linux-pci/20201007113158.48933-1-haifeng.zhao@intel.com/
    
    By Kuppuswamy Sathyanarayanan, March 2021:
    https://lore.kernel.org/linux-pci/59cb30f5e5ac6d65427ceaadf1012b2ba8dbf66c.1615606143.git.sathyanarayanan.kuppuswamy@linux.intel.com/
    
    Link: https://lore.kernel.org/r/0be565d97438fe2a6d57354b3aa4e8626952a00b.1619857124.git.lukas@wunner.de
    Reported-by: Sinan Kaya <okaya@kernel.org>
    Reported-by: Ethan Zhao <haifeng.zhao@intel.com>
    Reported-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
    Tested-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
    Tested-by: Yicong Yang <yangyicong@hisilicon.com>
    Signed-off-by: Lukas Wunner <lukas@wunner.de>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
    Cc: Dan Williams <dan.j.williams@intel.com>
    Cc: Ashok Raj <ashok.raj@intel.com>
    Cc: Keith Busch <kbusch@kernel.org>
    l1k authored and bjorn-helgaas committed Jun 16, 2021
  3. PCI/P2PDMA: Simplify distance calculation

    Merge __calc_map_type_and_dist() and calc_map_type_and_dist_warn() into
    calc_map_type_and_dist() to simplify the code a bit.  This now means we add
    the devfn strings to the acs_buf unconditionally even if the buffer is not
    printed, but that is not a lot of overhead and keeps the code much simpler.
    
    Link: https://lore.kernel.org/r/20210614055310.3960791-1-hch@lst.de
    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
    Christoph Hellwig authored and bjorn-helgaas committed Jun 16, 2021

Commits on Jun 10, 2021

  1. PCI/P2PDMA: Avoid pci_get_slot(), which may sleep

    In order to use upstream_bridge_distance_warn() from a dma_map function, it
    must not sleep. However, pci_get_slot() takes the pci_bus_sem so it might
    sleep.
    
    In order to avoid this, try to get the host bridge's device from the first
    element in the device list. It should be impossible for the host bridge's
    device to go away while references are held on child devices, so the first
    element should not be able to change and, thus, this should be safe.
    
    Introduce a static function called pci_host_bridge_dev() to obtain the host
    bridge's root device.
    
    Link: https://lore.kernel.org/r/20210610160609.28447-7-logang@deltatee.com
    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    lsgunth authored and bjorn-helgaas committed Jun 10, 2021
  2. PCI/P2PDMA: Refactor pci_p2pdma_map_type()

    All callers of pci_p2pdma_map_type() have a struct dev_pgmap and a struct
    device (of the client doing the DMA transfer). Thus move the conversion to
    struct pci_devs for the provider and client into this function.
    
    Link: https://lore.kernel.org/r/20210610160609.28447-6-logang@deltatee.com
    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    lsgunth authored and bjorn-helgaas committed Jun 10, 2021
  3. PCI/P2PDMA: Warn if host bridge not in whitelist

    If the host bridge is not in the whitelist print a warning in the
    calc_map_type_and_dist_warn() path detailing the vendor and device IDs that
    would need to be added to the whitelist.
    
    Suggested-by: Don Dutile <ddutile@redhat.com>
    Link: https://lore.kernel.org/r/20210610160609.28447-5-logang@deltatee.com
    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    lsgunth authored and bjorn-helgaas committed Jun 10, 2021
  4. PCI/P2PDMA: Use correct calc_map_type_and_dist() return type

    Instead of using an int for the return value of this function, use the
    correct enum pci_p2pdma_map_type.
    
    Link: https://lore.kernel.org/r/20210610160609.28447-4-logang@deltatee.com
    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    lsgunth authored and bjorn-helgaas committed Jun 10, 2021
  5. PCI/P2PDMA: Collect acs list in stack buffer to avoid sleeping

    In order to call the calc_map_type_and_dist_warn() function from a dma_map
    operation, the function must not sleep. The only reason it sleeps is to
    allocate memory for the seq_buf to print a verbose warning telling the user
    how to disable ACS for that path.
    
    Instead of allocating the memory with kmalloc(), allocate a smaller buffer
    on the stack. A 128 byte buffer is enough to print 10 PCI device names. A
    system with 10 bridge ports between two devices that have ACS enabled would
    be unusually large, so this should still be a reasonable limit.
    
    This also cleans up the awkward (and broken) return with -ENOMEM which
    contradicts the return type and the caller was not prepared for.
    
    Link: https://lore.kernel.org/r/20210610160609.28447-3-logang@deltatee.com
    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    lsgunth authored and bjorn-helgaas committed Jun 10, 2021
  6. PCI/P2PDMA: Rename upstream_bridge_distance() and rework doc

    The function upstream_bridge_distance() has evolved such that its name is
    no longer entirely reflective of what the function does.  It not only
    calculates the distance between two peers but also calculates how the DMA
    addresses for those two peers should be mapped.
    
    Rename it to calc_map_type_and_dist() and rework the documentation to
    better describe the two pieces of information the function returns.
    
    [bhelgaas: tweak comment wording]
    Link: https://lore.kernel.org/r/20210610160609.28447-2-logang@deltatee.com
    Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    lsgunth authored and bjorn-helgaas committed Jun 10, 2021
  7. PCI/IOV: Clarify error message for unbound devices

    Be more verbose to disambiguate the error case when trying to configure
    SR-IOV with no driver bound vs. a driver that does not implement the
    .sriov_configure() callback.
    
    Link: https://lore.kernel.org/r/20210327175140.682708-1-mdf@kernel.org
    Reported-by: Brian Foley <bpfoley@google.com>
    Signed-off-by: Moritz Fischer <mdf@kernel.org>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Krzysztof Wilczyński <kw@linux.com>
    mfischer authored and bjorn-helgaas committed Jun 10, 2021

Commits on Jun 7, 2021

  1. PCI: Leave Apple Thunderbolt controllers on for s2idle or standby

    On Macbook 2013, resuming from suspend-to-idle or standby resulted in the
    external monitor no longer being detected, a stacktrace, and errors like
    this in dmesg:
    
      pcieport 0000:06:00.0: can't change power state from D3hot to D0 (config space inaccessible)
    
    The reason is that we know how to turn power to the Thunderbolt controller
    *off* via the SXIO/SXFP/SXLF methods, but we don't know how to turn power
    back on.  We have to rely on firmware to turn the power back on.
    
    When going to the "suspend-to-idle" or "standby" system sleep states,
    firmware is not involved either on the suspend side or the resume side, so
    we can't use SXIO/SXFP/SXLF to turn the power off.
    
    Skip SXIO/SXFP/SXLF when firmware isn't involved in suspend, e.g., when
    we're going to the "suspend-to-idle" or "standby" system sleep states.
    
    Fixes: 1df5172 ("PCI: Suspend/resume quirks for Apple thunderbolt")
    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=212767
    Link: https://lore.kernel.org/r/20210520235501.917397-1-Hi-Angel@yandex.ru
    Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Lukas Wunner <lukas@wunner.de>
    Cc: stable@vger.kernel.org
    Hi-Angel authored and bjorn-helgaas committed Jun 7, 2021

Commits on Jun 4, 2021

  1. PCI: Coalesce host bridge contiguous apertures

    Built-in graphics on HP EliteDesk 805 G6 doesn't work because graphics
    can't get the BAR it needs:
    
      pci_bus 0000:00: root bus resource [mem 0x10020200000-0x100303fffff window]
      pci_bus 0000:00: root bus resource [mem 0x10030400000-0x100401fffff window]
    
      pci 0000:00:08.1:   bridge window [mem 0xd2000000-0xd23fffff]
      pci 0000:00:08.1:   bridge window [mem 0x10030000000-0x100401fffff 64bit pref]
      pci 0000:00:08.1: can't claim BAR 15 [mem 0x10030000000-0x100401fffff 64bit pref]: no compatible bridge window
      pci 0000:00:08.1: [mem 0x10030000000-0x100401fffff 64bit pref] clipped to [mem 0x10030000000-0x100303fffff 64bit pref]
      pci 0000:00:08.1:   bridge window [mem 0x10030000000-0x100303fffff 64bit pref]
      pci 0000:07:00.0: can't claim BAR 0 [mem 0x10030000000-0x1003fffffff 64bit pref]: no compatible bridge window
      pci 0000:07:00.0: can't claim BAR 2 [mem 0x10040000000-0x100401fffff 64bit pref]: no compatible bridge window
    
    However, the root bus has two contiguous apertures that can contain the
    child resource requested.
    
    Coalesce contiguous apertures so we can allocate from the entire contiguous
    region.
    
    [bhelgaas: fold in https://lore.kernel.org/r/20210528170242.1564038-1-kai.heng.feng@canonical.com]
    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=212013
    Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
    Link: https://lore.kernel.org/r/20210401131252.531935-1-kai.heng.feng@canonical.com
    Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    khfeng authored and bjorn-helgaas committed Jun 4, 2021
  2. PCI/sysfs: Add 'devspec' newline

    Previously, when the value of the "devspec" sysfs attribute was read from
    the user space there was no newline present, and utilities such as "cat"
    wouldn't display the result of the read correctly.
    
    Append a newline character in the show() function to match other "devspec"
    attributes.
    
    Link: https://lore.kernel.org/r/20210603000112.703037-5-kw@linux.com
    Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
    kwilczynski authored and bjorn-helgaas committed Jun 4, 2021
  3. PCI/sysfs: Fix 'resource_alignment' newline issues

    The value of the "resource_alignment" can be specified using a kernel
    command-line argument ("pci=resource_alignment=") or through the
    corresponding sysfs attribute under the /sys/bus/pci path.
    
    Previously, when the value was set via the kernel command-line argument,
    and then subsequently accessed through sysfs attribute, the value read back
    was not correct:
    
      # grep -oE 'pci=resource_alignment.+' /proc/cmdline
      pci=resource_alignment=20@00:1f.2
      # cat /sys/bus/pci/resource_alignment
      20@00:1f.
    
    This was also true when the value was set through the sysfs attribute
    without including a trailing newline:
    
      # echo -n 20@00:1f.2 > /sys/bus/pci/resource_alignment
      # cat /sys/bus/pci/resource_alignment
      20@00:1f.
    
    When it was set through the sysfs attribute *including* a newline,
    reading it back worked as intended:
    
      # echo 20@00:1f.2 > /sys/bus/pci/resource_alignment
      # cat /sys/bus/pci/resource_alignment
      20@00:1f.2
    
    To fix this inconsistency, append a trailing newline in the show() function
    and strip the trailing line in the store() function if one is present.
    
    Also, allow for the value previously set using either a command-line
    argument or through the sysfs object to be cleared at run-time.
    
    [bhelgaas: fold in kfree fix from
    https://lore.kernel.org/linux-pci/20210604133230.983956-4-kw@linux.com]
    Fixes: e499081 ("PCI: Force trailing new line to resource_alignment_param in sysfs")
    Link: https://lore.kernel.org/r/20210603000112.703037-4-kw@linux.com
    Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
    kwilczynski authored and bjorn-helgaas committed Jun 4, 2021
  4. PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions

    The sysfs_emit() and sysfs_emit_at() functions were introduced to make
    it less ambiguous which function is preferred when writing to the output
    buffer in a device attribute's "show" callback [1].
    
    Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
    and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
    latter is aware of the PAGE_SIZE buffer and correctly returns the number
    of bytes written into the buffer.
    
    No functional change intended.
    
    [1] Documentation/filesystems/sysfs.rst
    
    Related commit: ad025f8 ("PCI/sysfs: Use sysfs_emit() and
    sysfs_emit_at() in "show" functions").
    
    Link: https://lore.kernel.org/r/20210603000112.703037-2-kw@linux.com
    Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
    kwilczynski authored and bjorn-helgaas committed Jun 4, 2021

Commits on Jun 3, 2021

  1. PCI/sysfs: Rely on lengths from scnprintf(), dsm_label_utf16s_to_utf8s()

    scnprintf() returns the number of bytes written into the buffer.  Change
    dsm_label_utf16s_to_utf8s() to do the same.  Rely on those values instead
    of using strlen() to compute the buffer length.
    
    No functional change intended.
    
    [bhelgaas: reorder patch in series, len++ to include newline added by
    dsm_label_utf16s_to_utf8s(), commit log]
    Link: https://lore.kernel.org/r/20210603000112.703037-3-kw@linux.com
    Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
    kwilczynski authored and bjorn-helgaas committed Jun 3, 2021
  2. PCI/sysfs: Fix dsm_label_utf16s_to_utf8s() buffer overrun

    "utf16s_to_utf8s(..., buf, PAGE_SIZE)" puts up to PAGE_SIZE bytes into
    "buf" and returns the number of bytes it actually put there.  If it wrote
    PAGE_SIZE bytes, the newline added by dsm_label_utf16s_to_utf8s() would
    overrun "buf".
    
    Reduce the size available for utf16s_to_utf8s() to use so there is always
    space for the newline.
    
    [bhelgaas: reorder patch in series, commit log]
    Fixes: 6058989 ("PCI: Export ACPI _DSM provided firmware instance number and string name to sysfs")
    Link: https://lore.kernel.org/r/20210603000112.703037-7-kw@linux.com
    Reported-by: Joe Perches <joe@perches.com>
    Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    kwilczynski authored and bjorn-helgaas committed Jun 3, 2021
Older