* [PATCH 1/2] s390/vfio-ap: fix hang during removal of mdev after duplicate assignment
2022-08-17 22:52 [PATCH 0/2] s390/vfio-ap: fix two problems discovered in the vfio_ap driver Tony Krowiak
@ 2022-08-17 22:52 ` Tony Krowiak
2022-08-17 22:52 ` [PATCH 2/2] s390/vfio-ap: fix unlinking of queues from the mdev Tony Krowiak
2022-08-18 8:04 ` [PATCH 0/2] s390/vfio-ap: fix two problems discovered in the vfio_ap driver Alexander Gordeev
2 siblings, 0 replies; 5+ messages in thread
From: Tony Krowiak @ 2022-08-17 22:52 UTC (permalink / raw)
To: linux-s390, linux-kernel, kvm
Cc: jjherne, borntraeger, cohuck, mjrosato, pasic, alex.williamson,
kwankhede, fiuczy
When the same adapter or domain is assigned more than one time prior to
removing the matrix mdev to which it is assigned, the remove operation
will hang. The reason is because the same vfio_ap_queue objects with an
APQN containing the APID of the adapter or APQI of the domain being
assigned will get added to the hashtable that holds them multiple times.
This results in the pprev and next pointers of the hlist_node (mdev_qnode
field in the vfio_ap_queue object) pointing to the queue object itself.
This causes an interminable loop when the mdev is removed and the queue
table is iterated to reset the queues.
To fix this problem, the assignment operation is bypassed when assigning
an adapter or domain if it is already assigned to the matrix mdev.
Since it is not necessary to assign a resource already assigned or to
unassign a resource that has not been assigned, this patch will bypass
all assignment/unassignment operations for an adapter, domain or
control domain under these circumstances.
Reported-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
---
drivers/s390/crypto/vfio_ap_ops.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index 6c8c41fac4e1..ee82207b4e60 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -984,6 +984,11 @@ static ssize_t assign_adapter_store(struct device *dev,
goto done;
}
+ if (test_bit_inv(apid, matrix_mdev->matrix.apm)) {
+ ret = count;
+ goto done;
+ }
+
set_bit_inv(apid, matrix_mdev->matrix.apm);
ret = vfio_ap_mdev_validate_masks(matrix_mdev);
@@ -1109,6 +1114,11 @@ static ssize_t unassign_adapter_store(struct device *dev,
goto done;
}
+ if (!test_bit_inv(apid, matrix_mdev->matrix.apm)) {
+ ret = count;
+ goto done;
+ }
+
clear_bit_inv((unsigned long)apid, matrix_mdev->matrix.apm);
vfio_ap_mdev_hot_unplug_adapter(matrix_mdev, apid);
ret = count;
@@ -1183,6 +1193,11 @@ static ssize_t assign_domain_store(struct device *dev,
goto done;
}
+ if (test_bit_inv(apqi, matrix_mdev->matrix.aqm)) {
+ ret = count;
+ goto done;
+ }
+
set_bit_inv(apqi, matrix_mdev->matrix.aqm);
ret = vfio_ap_mdev_validate_masks(matrix_mdev);
@@ -1286,6 +1301,11 @@ static ssize_t unassign_domain_store(struct device *dev,
goto done;
}
+ if (!test_bit_inv(apqi, matrix_mdev->matrix.aqm)) {
+ ret = count;
+ goto done;
+ }
+
clear_bit_inv((unsigned long)apqi, matrix_mdev->matrix.aqm);
vfio_ap_mdev_hot_unplug_domain(matrix_mdev, apqi);
ret = count;
@@ -1329,6 +1349,11 @@ static ssize_t assign_control_domain_store(struct device *dev,
goto done;
}
+ if (test_bit_inv(id, matrix_mdev->matrix.adm)) {
+ ret = count;
+ goto done;
+ }
+
/* Set the bit in the ADM (bitmask) corresponding to the AP control
* domain number (id). The bits in the mask, from most significant to
* least significant, correspond to IDs 0 up to the one less than the
@@ -1378,6 +1403,11 @@ static ssize_t unassign_control_domain_store(struct device *dev,
goto done;
}
+ if (!test_bit_inv(domid, matrix_mdev->matrix.adm)) {
+ ret = count;
+ goto done;
+ }
+
clear_bit_inv(domid, matrix_mdev->matrix.adm);
if (test_bit_inv(domid, matrix_mdev->shadow_apcb.adm)) {
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/2] s390/vfio-ap: fix unlinking of queues from the mdev
2022-08-17 22:52 [PATCH 0/2] s390/vfio-ap: fix two problems discovered in the vfio_ap driver Tony Krowiak
2022-08-17 22:52 ` [PATCH 1/2] s390/vfio-ap: fix hang during removal of mdev after duplicate assignment Tony Krowiak
@ 2022-08-17 22:52 ` Tony Krowiak
2022-08-18 8:04 ` [PATCH 0/2] s390/vfio-ap: fix two problems discovered in the vfio_ap driver Alexander Gordeev
2 siblings, 0 replies; 5+ messages in thread
From: Tony Krowiak @ 2022-08-17 22:52 UTC (permalink / raw)
To: linux-s390, linux-kernel, kvm
Cc: jjherne, borntraeger, cohuck, mjrosato, pasic, alex.williamson,
kwankhede, fiuczy
The vfio_ap_mdev_unlink_adapter and vfio_ap_mdev_unlink_domain functions
add the associated vfio_ap_queue objects to the hashtable that links them
to the matrix mdev to which their APQN is assigned. In order to unlink
them, they must be deleted from the hashtable. This patch fixes that
issue.
Reported-by: Tony Krowiak <akrowiak@linux.ibm.com>
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
---
drivers/s390/crypto/vfio_ap_ops.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index ee82207b4e60..2493926b5dfb 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -1049,8 +1049,7 @@ static void vfio_ap_mdev_unlink_adapter(struct ap_matrix_mdev *matrix_mdev,
if (q && qtable) {
if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) &&
test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm))
- hash_add(qtable->queues, &q->mdev_qnode,
- q->apqn);
+ vfio_ap_unlink_queue_fr_mdev(q);
}
}
}
@@ -1236,8 +1235,7 @@ static void vfio_ap_mdev_unlink_domain(struct ap_matrix_mdev *matrix_mdev,
if (q && qtable) {
if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) &&
test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm))
- hash_add(qtable->queues, &q->mdev_qnode,
- q->apqn);
+ vfio_ap_unlink_queue_fr_mdev(q);
}
}
}
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 0/2] s390/vfio-ap: fix two problems discovered in the vfio_ap driver
2022-08-17 22:52 [PATCH 0/2] s390/vfio-ap: fix two problems discovered in the vfio_ap driver Tony Krowiak
2022-08-17 22:52 ` [PATCH 1/2] s390/vfio-ap: fix hang during removal of mdev after duplicate assignment Tony Krowiak
2022-08-17 22:52 ` [PATCH 2/2] s390/vfio-ap: fix unlinking of queues from the mdev Tony Krowiak
@ 2022-08-18 8:04 ` Alexander Gordeev
2022-08-18 13:18 ` Anthony Krowiak
2 siblings, 1 reply; 5+ messages in thread
From: Alexander Gordeev @ 2022-08-18 8:04 UTC (permalink / raw)
To: Tony Krowiak
Cc: linux-s390, linux-kernel, kvm, jjherne, borntraeger, cohuck,
mjrosato, pasic, alex.williamson, kwankhede, fiuczy
On Wed, Aug 17, 2022 at 06:52:40PM -0400, Tony Krowiak wrote:
> Two problems have been discovered with the vfio_ap device driver since the
> hot plug support was recently introduced:
Hi Tony,
Could you please add Fixes tags to the patches?
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread