Merge tag 'vfio-v6.1-rc1' of https://github.com/awilliam/linux-vfio
[platform/kernel/linux-rpi.git] / drivers / s390 / crypto / vfio_ap_ops.c
index 2884189..0b4cc8c 100644 (file)
@@ -943,6 +943,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);
@@ -1068,6 +1073,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;
@@ -1142,6 +1152,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);
@@ -1245,6 +1260,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;
@@ -1288,6 +1308,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
@@ -1337,6 +1362,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)) {