All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: linux-pci@vger.kernel.org, "Bjorn Helgaas" <helgaas@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Lukas Wunner" <lukas@wunner.de>
Cc: linux-kernel@vger.kernel.org,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH 00/17] PCI: Improve LNKCTL & LNKCTL2 concurrency control
Date: Thu, 11 May 2023 16:14:24 +0300	[thread overview]
Message-ID: <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com> (raw)

LNKCTL register is written by a number of things in the kernel as RMW
operations without any concurrency control. This could in the unlucky
case lead to losing one of the updates. One of the most obvious path
which can race with most of the other LNKCTL RMW operations seems to be
ASPM policy sysfs write which triggers LNKCTL update.

Add pcie_capability_clear_and_set_word_locked() that uses a per device
spinlock to protect the RMW operations. Introduce helpers for updating
LNKCTL and LNKCTL2 that internally do
pcie_capability_clear_and_set_word_locked(). Convert RMW to use the new
helpers.

These could be mostly marked with Fixes tags but I've not spent the
effort to find those out for each and every patch until this series has
seen some discussion. I certainly will try to find the Fixes tags if
asked to.

There could be a few LNKCTL RMW that are so early into the init that
they would be safe but I was not able to convince myself so I've
included them (namely, some ASPM init paths and hp link enable). Even
if that is the case, it seems safer to use an access pattern with these
registers that is safe even if there would be a few cases where locking
would not be stricly necessary.

As for LNKCTL2, I think all current users are safe but these came up as
a part of PCIe bandwidth control work (for thermal reasons) that will
be adding a writer for LNKCTL2. I'll send PCI BW ctrl patches
separately later as there's plenty of patches in this series already.
If most of this series is deemed worthy of Fixes tags, I could separate
those few LNKCTL2 changes into own patches.

The series is based on top of the "PCI/ASPM: Handle link retraining
race" patch I sent earlier but is not yet applied.

Ilpo Järvinen (17):
  PCI: Add concurrency safe clear_and_set variants for LNKCTL{,2}
  PCI: pciehp: Protect LNKCTL changes
  PCI/ASPM: Use pcie_lnkctl_clear_and_set()
  drm/amdgpu: Use pcie_lnkctl{,2}_clear_and_set() for changing
    LNKCTL{,2}
  drm/radeon: Use pcie_lnkctl{,2}_clear_and_set() for changing
    LNKCTL{,2}
  IB/hfi1: Use pcie_lnkctl{,2}_clear_and_set() for changing LNKCTL{,2}
  e1000e: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
  net/mlx5: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
  wifi: ath9k: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
  mt76: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
  Bluetooth: hci_bcm4377: Use pcie_lnkctl_clear_and_set() for changing
    LNKCTL
  misc: rtsx: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
  net/tg3: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
  r8169: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
  wifi: ath11k: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
  wifi: ath12k: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
  wifi: ath10k: Use pcie_lnkctl_clear_and_set() for changing LNKCTL

 drivers/bluetooth/hci_bcm4377.c               |  3 +-
 drivers/gpu/drm/amd/amdgpu/cik.c              | 72 +++++-------------
 drivers/gpu/drm/amd/amdgpu/si.c               | 74 ++++++-------------
 drivers/gpu/drm/radeon/cik.c                  | 71 +++++-------------
 drivers/gpu/drm/radeon/si.c                   | 72 +++++-------------
 drivers/infiniband/hw/hfi1/aspm.c             | 16 ++--
 drivers/infiniband/hw/hfi1/pcie.c             | 28 ++-----
 drivers/misc/cardreader/rts5228.c             |  6 +-
 drivers/misc/cardreader/rts5261.c             |  6 +-
 drivers/misc/cardreader/rtsx_pcr.c            |  8 +-
 drivers/net/ethernet/broadcom/tg3.c           | 14 ++--
 drivers/net/ethernet/intel/e1000e/netdev.c    |  6 +-
 .../ethernet/mellanox/mlx5/core/fw_reset.c    |  9 +--
 drivers/net/ethernet/realtek/r8169_main.c     |  6 +-
 drivers/net/wireless/ath/ath10k/pci.c         |  8 +-
 drivers/net/wireless/ath/ath11k/pci.c         |  8 +-
 drivers/net/wireless/ath/ath12k/pci.c         |  8 +-
 drivers/net/wireless/ath/ath9k/pci.c          |  9 ++-
 drivers/net/wireless/mediatek/mt76/pci.c      |  5 +-
 drivers/pci/access.c                          | 14 ++++
 drivers/pci/hotplug/pciehp_hpc.c              | 11 +--
 drivers/pci/pcie/aspm.c                       | 48 ++++--------
 drivers/pci/probe.c                           |  1 +
 include/linux/pci.h                           | 17 +++++
 24 files changed, 183 insertions(+), 337 deletions(-)

-- 
2.30.2


             reply	other threads:[~2023-05-11 13:15 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-11 13:14 Ilpo Järvinen [this message]
2023-05-11 13:14 ` [PATCH 01/17] PCI: Add concurrency safe clear_and_set variants for LNKCTL{,2} Ilpo Järvinen
2023-05-11 15:55   ` Bjorn Helgaas
2023-05-11 17:35     ` Ilpo Järvinen
2023-05-11 19:22       ` Bjorn Helgaas
2023-05-11 19:58         ` Ilpo Järvinen
2023-05-11 20:07           ` Lukas Wunner
2023-05-11 20:28             ` Ilpo Järvinen
2023-05-11 22:21               ` Bjorn Helgaas
2023-05-11 21:27           ` Bjorn Helgaas
2023-05-11 20:23     ` Lukas Wunner
2023-05-12  8:25       ` Ilpo Järvinen
2023-05-14 10:10         ` Lukas Wunner
2023-05-15 11:59           ` Ilpo Järvinen
2023-05-15 18:28             ` Bjorn Helgaas
2023-05-15 22:12             ` Lukas Wunner
2023-05-11 13:14 ` [PATCH 02/17] PCI: pciehp: Protect LNKCTL changes Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 03/17] PCI/ASPM: Use pcie_lnkctl_clear_and_set() Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 04/17] drm/amdgpu: Use pcie_lnkctl{,2}_clear_and_set() for changing LNKCTL{,2} Ilpo Järvinen
2023-05-11 13:14   ` [PATCH 04/17] drm/amdgpu: Use pcie_lnkctl{, 2}_clear_and_set() for changing LNKCTL{, 2} Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 05/17] drm/radeon: Use pcie_lnkctl{,2}_clear_and_set() for changing LNKCTL{,2} Ilpo Järvinen
2023-05-11 13:14   ` [PATCH 05/17] drm/radeon: Use pcie_lnkctl{, 2}_clear_and_set() for changing LNKCTL{, 2} Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 06/17] IB/hfi1: Use pcie_lnkctl{,2}_clear_and_set() for changing LNKCTL{,2} Ilpo Järvinen
2023-05-11 15:19   ` Dean Luick
2023-05-11 20:02     ` Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 07/17] e1000e: Use pcie_lnkctl_clear_and_set() for changing LNKCTL Ilpo Järvinen
2023-05-11 13:14   ` [Intel-wired-lan] " Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 08/17] net/mlx5: " Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 09/17] wifi: ath9k: " Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 10/17] mt76: " Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 11/17] Bluetooth: hci_bcm4377: " Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 12/17] misc: rtsx: " Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 13/17] net/tg3: " Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 14/17] r8169: " Ilpo Järvinen
2023-05-11 19:49   ` Heiner Kallweit
2023-05-11 20:00     ` Ilpo Järvinen
2023-05-11 20:10       ` Lukas Wunner
2023-05-11 20:11         ` Heiner Kallweit
2023-05-11 20:02     ` Lukas Wunner
2023-05-11 20:17       ` Heiner Kallweit
2023-05-11 13:14 ` [PATCH 15/17] wifi: ath11k: " Ilpo Järvinen
2023-05-11 13:14   ` Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 16/17] wifi: ath12k: " Ilpo Järvinen
2023-05-11 13:14   ` Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 17/17] wifi: ath10k: " Ilpo Järvinen
2023-05-11 13:14   ` Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230511131441.45704-1-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=helgaas@kernel.org \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=lukas@wunner.de \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.