Skip to content

Commit 98a03cb

Browse files
committed
s390/pci: Serialize device addition and removal
jira LE-4018 Rebuild_History Non-Buildable kernel-5.14.0-570.39.1.el9_6 commit-author Niklas Schnelle <[email protected]> commit 774a1fa Prior changes ensured that when zpci_release_device() is called and it removed the zdev from the zpci_list this instance can not be found via the zpci_list anymore even while allowing re-add of reserved devices. This only accounts for the overall lifetime and zpci_list addition and removal, it does not yet prevent concurrent add of a new instance for the same underlying device. Such concurrent add would subsequently cause issues such as attempted re-use of the same IOMMU sysfs directory and is generally undesired. Introduce a new zpci_add_remove_lock mutex to serialize adding a new device with removal. Together this ensures that if a struct zpci_dev is not found in the zpci_list it was either already removed and torn down, or its removal and tear down is in progress with the zpci_add_remove_lock held. Cc: [email protected] Fixes: a46044a ("s390/pci: fix zpci_zdev_put() on reserve") Reviewed-by: Gerd Bayer <[email protected]> Tested-by: Gerd Bayer <[email protected]> Signed-off-by: Niklas Schnelle <[email protected]> Signed-off-by: Heiko Carstens <[email protected]> (cherry picked from commit 774a1fa) Signed-off-by: Jonathan Maple <[email protected]>
1 parent bcf5608 commit 98a03cb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/s390/pci/pci.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
/* list of all detected zpci devices */
4444
static LIST_HEAD(zpci_list);
4545
static DEFINE_SPINLOCK(zpci_list_lock);
46+
static DEFINE_MUTEX(zpci_add_remove_lock);
4647

4748
static DECLARE_BITMAP(zpci_domain, ZPCI_DOMAIN_BITMAP_SIZE);
4849
static DEFINE_SPINLOCK(zpci_domain_lock);
@@ -72,7 +73,9 @@ void zpci_zdev_put(struct zpci_dev *zdev)
7273
{
7374
if (!zdev)
7475
return;
76+
mutex_lock(&zpci_add_remove_lock);
7577
kref_put_lock(&zdev->kref, zpci_release_device, &zpci_list_lock);
78+
mutex_unlock(&zpci_add_remove_lock);
7679
}
7780

7881
struct zpci_dev *get_zdev_by_fid(u32 fid)
@@ -836,6 +839,7 @@ int zpci_add_device(struct zpci_dev *zdev)
836839
{
837840
int rc;
838841

842+
mutex_lock(&zpci_add_remove_lock);
839843
zpci_dbg(1, "add fid:%x, fh:%x, c:%d\n", zdev->fid, zdev->fh, zdev->state);
840844
rc = zpci_init_iommu(zdev);
841845
if (rc)
@@ -849,12 +853,14 @@ int zpci_add_device(struct zpci_dev *zdev)
849853
spin_lock(&zpci_list_lock);
850854
list_add_tail(&zdev->entry, &zpci_list);
851855
spin_unlock(&zpci_list_lock);
856+
mutex_unlock(&zpci_add_remove_lock);
852857
return 0;
853858

854859
error_destroy_iommu:
855860
zpci_destroy_iommu(zdev);
856861
error:
857862
zpci_dbg(0, "add fid:%x, rc:%d\n", zdev->fid, rc);
863+
mutex_unlock(&zpci_add_remove_lock);
858864
return rc;
859865
}
860866

@@ -941,6 +947,7 @@ void zpci_release_device(struct kref *kref)
941947
{
942948
struct zpci_dev *zdev = container_of(kref, struct zpci_dev, kref);
943949

950+
lockdep_assert_held(&zpci_add_remove_lock);
944951
WARN_ON(zdev->state != ZPCI_FN_STATE_RESERVED);
945952
/*
946953
* We already hold zpci_list_lock thanks to kref_put_lock().

0 commit comments

Comments
 (0)