@@ -984,6 +984,11 @@ static ssize_t assign_adapter_store(struct device *dev,
984984 goto done ;
985985 }
986986
987+ if (test_bit_inv (apid , matrix_mdev -> matrix .apm )) {
988+ ret = count ;
989+ goto done ;
990+ }
991+
987992 set_bit_inv (apid , matrix_mdev -> matrix .apm );
988993
989994 ret = vfio_ap_mdev_validate_masks (matrix_mdev );
@@ -1109,6 +1114,11 @@ static ssize_t unassign_adapter_store(struct device *dev,
11091114 goto done ;
11101115 }
11111116
1117+ if (!test_bit_inv (apid , matrix_mdev -> matrix .apm )) {
1118+ ret = count ;
1119+ goto done ;
1120+ }
1121+
11121122 clear_bit_inv ((unsigned long )apid , matrix_mdev -> matrix .apm );
11131123 vfio_ap_mdev_hot_unplug_adapter (matrix_mdev , apid );
11141124 ret = count ;
@@ -1183,6 +1193,11 @@ static ssize_t assign_domain_store(struct device *dev,
11831193 goto done ;
11841194 }
11851195
1196+ if (test_bit_inv (apqi , matrix_mdev -> matrix .aqm )) {
1197+ ret = count ;
1198+ goto done ;
1199+ }
1200+
11861201 set_bit_inv (apqi , matrix_mdev -> matrix .aqm );
11871202
11881203 ret = vfio_ap_mdev_validate_masks (matrix_mdev );
@@ -1286,6 +1301,11 @@ static ssize_t unassign_domain_store(struct device *dev,
12861301 goto done ;
12871302 }
12881303
1304+ if (!test_bit_inv (apqi , matrix_mdev -> matrix .aqm )) {
1305+ ret = count ;
1306+ goto done ;
1307+ }
1308+
12891309 clear_bit_inv ((unsigned long )apqi , matrix_mdev -> matrix .aqm );
12901310 vfio_ap_mdev_hot_unplug_domain (matrix_mdev , apqi );
12911311 ret = count ;
@@ -1329,6 +1349,11 @@ static ssize_t assign_control_domain_store(struct device *dev,
13291349 goto done ;
13301350 }
13311351
1352+ if (test_bit_inv (id , matrix_mdev -> matrix .adm )) {
1353+ ret = count ;
1354+ goto done ;
1355+ }
1356+
13321357 /* Set the bit in the ADM (bitmask) corresponding to the AP control
13331358 * domain number (id). The bits in the mask, from most significant to
13341359 * 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,
13781403 goto done ;
13791404 }
13801405
1406+ if (!test_bit_inv (domid , matrix_mdev -> matrix .adm )) {
1407+ ret = count ;
1408+ goto done ;
1409+ }
1410+
13811411 clear_bit_inv (domid , matrix_mdev -> matrix .adm );
13821412
13831413 if (test_bit_inv (domid , matrix_mdev -> shadow_apcb .adm )) {
0 commit comments