Skip to content

Commit 774a1fa

Browse files
niklas88hcahca
authored andcommitted
s390/pci: Serialize device addition and removal
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]>
1 parent 4b1815a commit 774a1fa

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
@@ -45,6 +45,7 @@
4545
/* list of all detected zpci devices */
4646
static LIST_HEAD(zpci_list);
4747
static DEFINE_SPINLOCK(zpci_list_lock);
48+
static DEFINE_MUTEX(zpci_add_remove_lock);
4849

4950
static DECLARE_BITMAP(zpci_domain, ZPCI_DOMAIN_BITMAP_SIZE);
5051
static DEFINE_SPINLOCK(zpci_domain_lock);
@@ -74,7 +75,9 @@ void zpci_zdev_put(struct zpci_dev *zdev)
7475
{
7576
if (!zdev)
7677
return;
78+
mutex_lock(&zpci_add_remove_lock);
7779
kref_put_lock(&zdev->kref, zpci_release_device, &zpci_list_lock);
80+
mutex_unlock(&zpci_add_remove_lock);
7881
}
7982

8083
struct zpci_dev *get_zdev_by_fid(u32 fid)
@@ -844,6 +847,7 @@ int zpci_add_device(struct zpci_dev *zdev)
844847
{
845848
int rc;
846849

850+
mutex_lock(&zpci_add_remove_lock);
847851
zpci_dbg(1, "add fid:%x, fh:%x, c:%d\n", zdev->fid, zdev->fh, zdev->state);
848852
rc = zpci_init_iommu(zdev);
849853
if (rc)
@@ -857,12 +861,14 @@ int zpci_add_device(struct zpci_dev *zdev)
857861
spin_lock(&zpci_list_lock);
858862
list_add_tail(&zdev->entry, &zpci_list);
859863
spin_unlock(&zpci_list_lock);
864+
mutex_unlock(&zpci_add_remove_lock);
860865
return 0;
861866

862867
error_destroy_iommu:
863868
zpci_destroy_iommu(zdev);
864869
error:
865870
zpci_dbg(0, "add fid:%x, rc:%d\n", zdev->fid, rc);
871+
mutex_unlock(&zpci_add_remove_lock);
866872
return rc;
867873
}
868874

@@ -953,6 +959,7 @@ void zpci_release_device(struct kref *kref)
953959
{
954960
struct zpci_dev *zdev = container_of(kref, struct zpci_dev, kref);
955961

962+
lockdep_assert_held(&zpci_add_remove_lock);
956963
WARN_ON(zdev->state != ZPCI_FN_STATE_RESERVED);
957964
/*
958965
* We already hold zpci_list_lock thanks to kref_put_lock().

0 commit comments

Comments
 (0)