Lines Matching refs:matrix_mdev

35 static int vfio_ap_mdev_reset_queues(struct ap_matrix_mdev *matrix_mdev);
51 * 3. matrix_dev->mdevs_lock: required to access data stored in a matrix_mdev
88 * @matrix_mdev: a pointer to a struct ap_matrix_mdev object containing the AP
94 * 2. matrix_mdev->kvm->lock: required to update a guest's APCB
95 * 3. matrix_dev->mdevs_lock: required to access data stored in a matrix_mdev
97 * Note: If @matrix_mdev is NULL or is not attached to a KVM guest, the KVM
100 static inline void get_update_locks_for_mdev(struct ap_matrix_mdev *matrix_mdev)
103 if (matrix_mdev && matrix_mdev->kvm)
104 mutex_lock(&matrix_mdev->kvm->lock);
112 * @matrix_mdev: a pointer to a struct ap_matrix_mdev object containing the AP
117 * 2. matrix_mdev->kvm->lock
120 * Note: If @matrix_mdev is NULL or is not attached to a KVM guest, the KVM
123 static inline void release_update_locks_for_mdev(struct ap_matrix_mdev *matrix_mdev)
126 if (matrix_mdev && matrix_mdev->kvm)
127 mutex_unlock(&matrix_mdev->kvm->lock);
141 * 2. matrix_mdev->kvm->lock: required to update a guest's APCB
142 * 3. matrix_dev->mdevs_lock: required to access data stored in a matrix_mdev
144 * Note: If @apqn is not assigned to a matrix_mdev, the matrix_mdev->kvm->lock
152 struct ap_matrix_mdev *matrix_mdev;
156 list_for_each_entry(matrix_mdev, &matrix_dev->mdev_list, node) {
157 if (test_bit_inv(AP_QID_CARD(apqn), matrix_mdev->matrix.apm) &&
158 test_bit_inv(AP_QID_QUEUE(apqn), matrix_mdev->matrix.aqm)) {
159 if (matrix_mdev->kvm)
160 mutex_lock(&matrix_mdev->kvm->lock);
164 return matrix_mdev;
183 * 2. q->matrix_mdev->kvm->lock: required to update a guest's APCB
184 * 3. matrix_dev->mdevs_lock: required to access data stored in matrix_mdev
192 if (q->matrix_mdev && q->matrix_mdev->kvm)
193 mutex_lock(&q->matrix_mdev->kvm->lock);
200 * @matrix_mdev: the matrix mdev
204 * NULL if the queue is not assigned to @matrix_mdev
207 struct ap_matrix_mdev *matrix_mdev,
212 hash_for_each_possible(matrix_mdev->qtable.queues, q, mdev_qnode,
274 !WARN_ON(!(q->matrix_mdev && q->matrix_mdev->kvm))) {
275 kvm_s390_gisc_unregister(q->matrix_mdev->kvm, q->saved_isc);
278 if (q->saved_iova && !WARN_ON(!q->matrix_mdev)) {
279 vfio_unpin_pages(&q->matrix_mdev->vdev, q->saved_iova, 1);
440 ret = vfio_pin_pages(&q->matrix_mdev->vdev, nib, 1,
454 kvm = q->matrix_mdev->kvm;
463 vfio_unpin_pages(&q->matrix_mdev->vdev, nib, 1);
473 vfio_unpin_pages(&q->matrix_mdev->vdev, nib, 1);
496 vfio_unpin_pages(&q->matrix_mdev->vdev, nib, 1);
589 struct ap_matrix_mdev *matrix_mdev;
610 matrix_mdev = container_of(vcpu->kvm->arch.crypto.pqap_hook,
614 if (!matrix_mdev->kvm) {
615 vfio_ap_le_guid_to_be_uuid(&matrix_mdev->mdev->uuid, uuid);
622 q = vfio_ap_mdev_get_queue(matrix_mdev, apqn);
653 static void signal_guest_ap_cfg_changed(struct ap_matrix_mdev *matrix_mdev)
655 if (matrix_mdev->cfg_chg_trigger)
656 eventfd_signal(matrix_mdev->cfg_chg_trigger);
659 static void vfio_ap_mdev_update_guest_apcb(struct ap_matrix_mdev *matrix_mdev)
661 if (matrix_mdev->kvm) {
662 kvm_arch_crypto_set_masks(matrix_mdev->kvm,
663 matrix_mdev->shadow_apcb.apm,
664 matrix_mdev->shadow_apcb.aqm,
665 matrix_mdev->shadow_apcb.adm);
667 signal_guest_ap_cfg_changed(matrix_mdev);
671 static bool vfio_ap_mdev_filter_cdoms(struct ap_matrix_mdev *matrix_mdev)
675 bitmap_copy(prev_shadow_adm, matrix_mdev->shadow_apcb.adm, AP_DOMAINS);
676 bitmap_and(matrix_mdev->shadow_apcb.adm, matrix_mdev->matrix.adm,
679 return !bitmap_equal(prev_shadow_adm, matrix_mdev->shadow_apcb.adm,
704 * @matrix_mdev: the matrix mdev whose matrix is to be filtered.
720 static bool vfio_ap_mdev_filter_matrix(struct ap_matrix_mdev *matrix_mdev,
727 bitmap_copy(prev_shadow_apm, matrix_mdev->shadow_apcb.apm, AP_DEVICES);
728 bitmap_copy(prev_shadow_aqm, matrix_mdev->shadow_apcb.aqm, AP_DOMAINS);
729 vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->shadow_apcb);
737 bitmap_and(matrix_mdev->shadow_apcb.apm, matrix_mdev->matrix.apm,
739 bitmap_and(matrix_mdev->shadow_apcb.aqm, matrix_mdev->matrix.aqm,
742 for_each_set_bit_inv(apid, matrix_mdev->shadow_apcb.apm, AP_DEVICES) {
743 for_each_set_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm,
754 if (!_queue_passable(vfio_ap_mdev_get_queue(matrix_mdev, apqn))) {
755 clear_bit_inv(apid, matrix_mdev->shadow_apcb.apm);
770 return !bitmap_equal(prev_shadow_apm, matrix_mdev->shadow_apcb.apm,
772 !bitmap_equal(prev_shadow_aqm, matrix_mdev->shadow_apcb.aqm,
778 struct ap_matrix_mdev *matrix_mdev =
781 matrix_mdev->mdev = to_mdev_device(vdev->dev);
782 vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->matrix);
783 matrix_mdev->pqap_hook = handle_pqap;
784 vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->shadow_apcb);
785 hash_init(matrix_mdev->qtable.queues);
792 struct ap_matrix_mdev *matrix_mdev;
795 matrix_mdev = vfio_alloc_device(ap_matrix_mdev, vdev, &mdev->dev,
797 if (IS_ERR(matrix_mdev))
798 return PTR_ERR(matrix_mdev);
800 ret = vfio_register_emulated_iommu_dev(&matrix_mdev->vdev);
803 matrix_mdev->req_trigger = NULL;
804 matrix_mdev->cfg_chg_trigger = NULL;
805 dev_set_drvdata(&mdev->dev, matrix_mdev);
807 list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
812 vfio_put_device(&matrix_mdev->vdev);
816 static void vfio_ap_mdev_link_queue(struct ap_matrix_mdev *matrix_mdev,
819 if (!q || vfio_ap_mdev_get_queue(matrix_mdev, q->apqn))
822 q->matrix_mdev = matrix_mdev;
823 hash_add(matrix_mdev->qtable.queues, &q->mdev_qnode, q->apqn);
826 static void vfio_ap_mdev_link_apqn(struct ap_matrix_mdev *matrix_mdev, int apqn)
831 vfio_ap_mdev_link_queue(matrix_mdev, q);
841 q->matrix_mdev = NULL;
844 static void vfio_ap_mdev_unlink_fr_queues(struct ap_matrix_mdev *matrix_mdev)
849 for_each_set_bit_inv(apid, matrix_mdev->matrix.apm, AP_DEVICES) {
850 for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm,
852 q = vfio_ap_mdev_get_queue(matrix_mdev,
855 q->matrix_mdev = NULL;
862 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(&mdev->dev);
864 vfio_unregister_group_dev(&matrix_mdev->vdev);
868 vfio_ap_mdev_reset_queues(matrix_mdev);
869 vfio_ap_mdev_unlink_fr_queues(matrix_mdev);
870 list_del(&matrix_mdev->node);
873 vfio_put_device(&matrix_mdev->vdev);
967 * @matrix_mdev: the mdev to which the APQNs being validated are assigned.
972 * o EADDRNOTAVAIL if an APQN assigned to @matrix_mdev is reserved for the
974 * o EADDRINUSE if an APQN assigned to @matrix_mdev is assigned to another mdev
977 static int vfio_ap_mdev_validate_masks(struct ap_matrix_mdev *matrix_mdev)
979 if (ap_apqn_in_matrix_owned_by_def_drv(matrix_mdev->matrix.apm,
980 matrix_mdev->matrix.aqm))
983 return vfio_ap_mdev_verify_no_sharing(matrix_mdev,
984 matrix_mdev->matrix.apm,
985 matrix_mdev->matrix.aqm);
988 static void vfio_ap_mdev_link_adapter(struct ap_matrix_mdev *matrix_mdev,
993 for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm, AP_DOMAINS)
994 vfio_ap_mdev_link_apqn(matrix_mdev,
998 static void collect_queues_to_reset(struct ap_matrix_mdev *matrix_mdev,
1005 for_each_set_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm, AP_DOMAINS) {
1006 q = vfio_ap_mdev_get_queue(matrix_mdev, AP_MKQID(apid, apqi));
1012 static void reset_queues_for_apid(struct ap_matrix_mdev *matrix_mdev,
1018 collect_queues_to_reset(matrix_mdev, apid, &qlist);
1022 static int reset_queues_for_apids(struct ap_matrix_mdev *matrix_mdev,
1034 collect_queues_to_reset(matrix_mdev, apid, &qlist);
1080 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1083 get_update_locks_for_mdev(matrix_mdev);
1089 if (apid > matrix_mdev->matrix.apm_max) {
1094 if (test_bit_inv(apid, matrix_mdev->matrix.apm)) {
1099 set_bit_inv(apid, matrix_mdev->matrix.apm);
1101 ret = vfio_ap_mdev_validate_masks(matrix_mdev);
1103 clear_bit_inv(apid, matrix_mdev->matrix.apm);
1107 vfio_ap_mdev_link_adapter(matrix_mdev, apid);
1109 if (vfio_ap_mdev_filter_matrix(matrix_mdev, apm_filtered)) {
1110 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
1111 reset_queues_for_apids(matrix_mdev, apm_filtered);
1116 release_update_locks_for_mdev(matrix_mdev);
1124 *vfio_ap_unlink_apqn_fr_mdev(struct ap_matrix_mdev *matrix_mdev,
1129 q = vfio_ap_mdev_get_queue(matrix_mdev, AP_MKQID(apid, apqi));
1141 * @matrix_mdev: the matrix mediated device to which the adapter was assigned.
1146 static void vfio_ap_mdev_unlink_adapter(struct ap_matrix_mdev *matrix_mdev,
1153 for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm, AP_DOMAINS) {
1154 q = vfio_ap_unlink_apqn_fr_mdev(matrix_mdev, apid, apqi);
1157 if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) &&
1158 test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm))
1164 static void vfio_ap_mdev_hot_unplug_adapters(struct ap_matrix_mdev *matrix_mdev,
1175 vfio_ap_mdev_unlink_adapter(matrix_mdev, apid, &qlist);
1177 if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm)) {
1178 clear_bit_inv(apid, matrix_mdev->shadow_apcb.apm);
1185 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
1195 static void vfio_ap_mdev_hot_unplug_adapter(struct ap_matrix_mdev *matrix_mdev,
1202 vfio_ap_mdev_hot_unplug_adapters(matrix_mdev, apids);
1226 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1228 get_update_locks_for_mdev(matrix_mdev);
1234 if (apid > matrix_mdev->matrix.apm_max) {
1239 if (!test_bit_inv(apid, matrix_mdev->matrix.apm)) {
1244 clear_bit_inv((unsigned long)apid, matrix_mdev->matrix.apm);
1245 vfio_ap_mdev_hot_unplug_adapter(matrix_mdev, apid);
1248 release_update_locks_for_mdev(matrix_mdev);
1253 static void vfio_ap_mdev_link_domain(struct ap_matrix_mdev *matrix_mdev,
1258 for_each_set_bit_inv(apid, matrix_mdev->matrix.apm, AP_DEVICES)
1259 vfio_ap_mdev_link_apqn(matrix_mdev,
1304 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1307 get_update_locks_for_mdev(matrix_mdev);
1313 if (apqi > matrix_mdev->matrix.aqm_max) {
1318 if (test_bit_inv(apqi, matrix_mdev->matrix.aqm)) {
1323 set_bit_inv(apqi, matrix_mdev->matrix.aqm);
1325 ret = vfio_ap_mdev_validate_masks(matrix_mdev);
1327 clear_bit_inv(apqi, matrix_mdev->matrix.aqm);
1331 vfio_ap_mdev_link_domain(matrix_mdev, apqi);
1333 if (vfio_ap_mdev_filter_matrix(matrix_mdev, apm_filtered)) {
1334 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
1335 reset_queues_for_apids(matrix_mdev, apm_filtered);
1340 release_update_locks_for_mdev(matrix_mdev);
1347 static void vfio_ap_mdev_unlink_domain(struct ap_matrix_mdev *matrix_mdev,
1354 for_each_set_bit_inv(apid, matrix_mdev->matrix.apm, AP_DEVICES) {
1355 q = vfio_ap_unlink_apqn_fr_mdev(matrix_mdev, apid, apqi);
1358 if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) &&
1359 test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm))
1365 static void vfio_ap_mdev_hot_unplug_domains(struct ap_matrix_mdev *matrix_mdev,
1376 vfio_ap_mdev_unlink_domain(matrix_mdev, apqi, &qlist);
1378 if (test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm)) {
1379 clear_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm);
1386 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
1396 static void vfio_ap_mdev_hot_unplug_domain(struct ap_matrix_mdev *matrix_mdev,
1403 vfio_ap_mdev_hot_unplug_domains(matrix_mdev, apqis);
1427 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1429 get_update_locks_for_mdev(matrix_mdev);
1435 if (apqi > matrix_mdev->matrix.aqm_max) {
1440 if (!test_bit_inv(apqi, matrix_mdev->matrix.aqm)) {
1445 clear_bit_inv((unsigned long)apqi, matrix_mdev->matrix.aqm);
1446 vfio_ap_mdev_hot_unplug_domain(matrix_mdev, apqi);
1450 release_update_locks_for_mdev(matrix_mdev);
1475 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1477 get_update_locks_for_mdev(matrix_mdev);
1483 if (id > matrix_mdev->matrix.adm_max) {
1488 if (test_bit_inv(id, matrix_mdev->matrix.adm)) {
1498 set_bit_inv(id, matrix_mdev->matrix.adm);
1499 if (vfio_ap_mdev_filter_cdoms(matrix_mdev))
1500 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
1504 release_update_locks_for_mdev(matrix_mdev);
1529 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1531 get_update_locks_for_mdev(matrix_mdev);
1537 if (domid > matrix_mdev->matrix.adm_max) {
1542 if (!test_bit_inv(domid, matrix_mdev->matrix.adm)) {
1547 clear_bit_inv(domid, matrix_mdev->matrix.adm);
1549 if (test_bit_inv(domid, matrix_mdev->shadow_apcb.adm)) {
1550 clear_bit_inv(domid, matrix_mdev->shadow_apcb.adm);
1551 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
1556 release_update_locks_for_mdev(matrix_mdev);
1566 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1567 unsigned long max_domid = matrix_mdev->matrix.adm_max;
1571 for_each_set_bit_inv(id, matrix_mdev->matrix.adm, max_domid + 1)
1612 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1615 nchars = vfio_ap_mdev_matrix_show(&matrix_mdev->matrix, buf);
1626 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1629 nchars = vfio_ap_mdev_matrix_show(&matrix_mdev->shadow_apcb, buf);
1645 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1648 idx += write_ap_bitmap(matrix_mdev->matrix.apm, buf, idx, ',');
1649 idx += write_ap_bitmap(matrix_mdev->matrix.aqm, buf, idx, ',');
1650 idx += write_ap_bitmap(matrix_mdev->matrix.adm, buf, idx, '\n');
1672 static int ap_matrix_overflow_check(struct ap_matrix_mdev *matrix_mdev)
1676 for_each_set_bit_inv(bit, matrix_mdev->matrix.apm, AP_DEVICES) {
1677 if (bit > matrix_mdev->matrix.apm_max)
1681 for_each_set_bit_inv(bit, matrix_mdev->matrix.aqm, AP_DOMAINS) {
1682 if (bit > matrix_mdev->matrix.aqm_max)
1686 for_each_set_bit_inv(bit, matrix_mdev->matrix.adm, AP_DOMAINS) {
1687 if (bit > matrix_mdev->matrix.adm_max)
1708 struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
1722 get_update_locks_for_mdev(matrix_mdev);
1725 ap_matrix_copy(&m_old, &matrix_mdev->matrix);
1738 /* Need new bitmaps in matrix_mdev for validation */
1739 ap_matrix_copy(&matrix_mdev->matrix, &m_new);
1742 rc = vfio_ap_mdev_validate_masks(matrix_mdev);
1744 ap_matrix_copy(&matrix_mdev->matrix, &m_old);
1747 rc = ap_matrix_overflow_check(matrix_mdev);
1749 ap_matrix_copy(&matrix_mdev->matrix, &m_old);
1754 /* Need old bitmaps in matrix_mdev for unplug/unlink */
1755 ap_matrix_copy(&matrix_mdev->matrix, &m_old);
1758 vfio_ap_mdev_hot_unplug_adapters(matrix_mdev, m_removed.apm);
1759 vfio_ap_mdev_hot_unplug_domains(matrix_mdev, m_removed.aqm);
1761 /* Need new bitmaps in matrix_mdev for linking new adapters/domains */
1762 ap_matrix_copy(&matrix_mdev->matrix, &m_new);
1766 vfio_ap_mdev_link_adapter(matrix_mdev, newbit);
1769 vfio_ap_mdev_link_domain(matrix_mdev, newbit);
1772 do_update = vfio_ap_mdev_filter_matrix(matrix_mdev, apm_filtered);
1773 do_update |= vfio_ap_mdev_filter_cdoms(matrix_mdev);
1777 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
1778 reset_queues_for_apids(matrix_mdev, apm_filtered);
1781 release_update_locks_for_mdev(matrix_mdev);
1812 * vfio_ap_mdev_set_kvm - sets all data for @matrix_mdev that are needed
1815 * @matrix_mdev: a mediated matrix device
1821 static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev,
1828 kvm->arch.crypto.pqap_hook = &matrix_mdev->pqap_hook;
1834 if (m != matrix_mdev && m->kvm == kvm) {
1841 matrix_mdev->kvm = kvm;
1842 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
1850 static void unmap_iova(struct ap_matrix_mdev *matrix_mdev, u64 iova, u64 length)
1852 struct ap_queue_table *qtable = &matrix_mdev->qtable;
1865 struct ap_matrix_mdev *matrix_mdev =
1870 unmap_iova(matrix_mdev, iova, length);
1877 * by @matrix_mdev.
1879 * @matrix_mdev: a matrix mediated device
1881 static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev)
1883 struct kvm *kvm = matrix_mdev->kvm;
1893 vfio_ap_mdev_reset_queues(matrix_mdev);
1895 matrix_mdev->kvm = NULL;
2017 static int vfio_ap_mdev_reset_queues(struct ap_matrix_mdev *matrix_mdev)
2022 hash_for_each(matrix_mdev->qtable.queues, loop_cursor, q, mdev_qnode)
2025 hash_for_each(matrix_mdev->qtable.queues, loop_cursor, q, mdev_qnode) {
2055 struct ap_matrix_mdev *matrix_mdev =
2061 return vfio_ap_mdev_set_kvm(matrix_mdev, vdev->kvm);
2066 struct ap_matrix_mdev *matrix_mdev =
2069 vfio_ap_mdev_unset_kvm(matrix_mdev);
2075 struct ap_matrix_mdev *matrix_mdev;
2077 matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev);
2079 get_update_locks_for_mdev(matrix_mdev);
2081 if (matrix_mdev->kvm) {
2082 kvm_arch_crypto_clear_masks(matrix_mdev->kvm);
2083 signal_guest_ap_cfg_changed(matrix_mdev);
2086 if (matrix_mdev->req_trigger) {
2092 eventfd_signal(matrix_mdev->req_trigger);
2098 release_update_locks_for_mdev(matrix_mdev);
2172 static int vfio_ap_set_request_irq(struct ap_matrix_mdev *matrix_mdev,
2187 if (matrix_mdev->req_trigger)
2188 eventfd_ctx_put(matrix_mdev->req_trigger);
2189 matrix_mdev->req_trigger = NULL;
2195 if (matrix_mdev->req_trigger)
2196 eventfd_ctx_put(matrix_mdev->req_trigger);
2198 matrix_mdev->req_trigger = req_trigger;
2206 static int vfio_ap_set_cfg_change_irq(struct ap_matrix_mdev *matrix_mdev, unsigned long arg)
2220 if (matrix_mdev->cfg_chg_trigger)
2221 eventfd_ctx_put(matrix_mdev->cfg_chg_trigger);
2222 matrix_mdev->cfg_chg_trigger = NULL;
2228 if (matrix_mdev->cfg_chg_trigger)
2229 eventfd_ctx_put(matrix_mdev->cfg_chg_trigger);
2231 matrix_mdev->cfg_chg_trigger = cfg_chg_trigger;
2239 static int vfio_ap_set_irqs(struct ap_matrix_mdev *matrix_mdev,
2253 return vfio_ap_set_request_irq(matrix_mdev, arg);
2255 return vfio_ap_set_cfg_change_irq(matrix_mdev, arg);
2267 struct ap_matrix_mdev *matrix_mdev =
2277 ret = vfio_ap_mdev_reset_queues(matrix_mdev);
2283 ret = vfio_ap_set_irqs(matrix_mdev, arg);
2296 struct ap_matrix_mdev *matrix_mdev;
2300 list_for_each_entry(matrix_mdev, &matrix_dev->mdev_list, node) {
2301 if (test_bit_inv(apid, matrix_mdev->matrix.apm) &&
2302 test_bit_inv(apqi, matrix_mdev->matrix.aqm))
2303 return matrix_mdev;
2316 struct ap_matrix_mdev *matrix_mdev;
2321 matrix_mdev = vfio_ap_mdev_for_queue(q);
2327 if (matrix_mdev) {
2335 if (matrix_mdev->kvm &&
2336 test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) &&
2337 test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm))
2421 struct ap_matrix_mdev *matrix_mdev;
2437 matrix_mdev = get_update_locks_by_apqn(q->apqn);
2439 if (matrix_mdev) {
2440 vfio_ap_mdev_link_queue(matrix_mdev, q);
2449 if (!bitmap_empty(matrix_mdev->apm_add, AP_DEVICES) ||
2450 !bitmap_empty(matrix_mdev->aqm_add, AP_DOMAINS))
2453 if (vfio_ap_mdev_filter_matrix(matrix_mdev, apm_filtered)) {
2454 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
2455 reset_queues_for_apids(matrix_mdev, apm_filtered);
2461 release_update_locks_for_mdev(matrix_mdev);
2474 struct ap_matrix_mdev *matrix_mdev;
2479 matrix_mdev = q->matrix_mdev;
2483 if (matrix_mdev) {
2485 if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) &&
2486 test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm)) {
2492 clear_bit_inv(apid, matrix_mdev->shadow_apcb.apm);
2493 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
2494 reset_queues_for_apid(matrix_mdev, apid);
2511 if (matrix_mdev)
2516 release_update_locks_for_mdev(matrix_mdev);
2551 * @matrix_mdev: an ap_matrix_mdev object attached to a KVM guest.
2557 static void vfio_ap_mdev_hot_unplug_cfg(struct ap_matrix_mdev *matrix_mdev,
2565 do_hotplug |= bitmap_andnot(matrix_mdev->shadow_apcb.apm,
2566 matrix_mdev->shadow_apcb.apm,
2571 do_hotplug |= bitmap_andnot(matrix_mdev->shadow_apcb.aqm,
2572 matrix_mdev->shadow_apcb.aqm,
2577 do_hotplug |= bitmap_andnot(matrix_mdev->shadow_apcb.adm,
2578 matrix_mdev->shadow_apcb.adm,
2582 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
2602 struct ap_matrix_mdev *matrix_mdev;
2608 list_for_each_entry(matrix_mdev, &matrix_dev->mdev_list, node) {
2609 mutex_lock(&matrix_mdev->kvm->lock);
2613 matrix_mdev->matrix.apm,
2616 matrix_mdev->matrix.aqm,
2619 matrix_mdev->matrix.adm,
2623 vfio_ap_mdev_hot_unplug_cfg(matrix_mdev, aprem, aqrem,
2627 mutex_unlock(&matrix_mdev->kvm->lock);
2744 struct ap_matrix_mdev *matrix_mdev;
2751 list_for_each_entry(matrix_mdev, &matrix_dev->mdev_list, node) {
2752 bitmap_and(matrix_mdev->apm_add,
2753 matrix_mdev->matrix.apm, apm_add, AP_DEVICES);
2754 bitmap_and(matrix_mdev->aqm_add,
2755 matrix_mdev->matrix.aqm, aqm_add, AP_DOMAINS);
2756 bitmap_and(matrix_mdev->adm_add,
2757 matrix_mdev->matrix.adm, adm_add, AP_DEVICES);
2819 static void vfio_ap_mdev_hot_plug_cfg(struct ap_matrix_mdev *matrix_mdev)
2824 mutex_lock(&matrix_mdev->kvm->lock);
2827 filter_adapters = bitmap_intersects(matrix_mdev->matrix.apm,
2828 matrix_mdev->apm_add, AP_DEVICES);
2829 filter_domains = bitmap_intersects(matrix_mdev->matrix.aqm,
2830 matrix_mdev->aqm_add, AP_DOMAINS);
2831 filter_cdoms = bitmap_intersects(matrix_mdev->matrix.adm,
2832 matrix_mdev->adm_add, AP_DOMAINS);
2835 do_hotplug = vfio_ap_mdev_filter_matrix(matrix_mdev, apm_filtered);
2838 do_hotplug |= vfio_ap_mdev_filter_cdoms(matrix_mdev);
2841 vfio_ap_mdev_update_guest_apcb(matrix_mdev);
2843 reset_queues_for_apids(matrix_mdev, apm_filtered);
2846 mutex_unlock(&matrix_mdev->kvm->lock);
2852 struct ap_matrix_mdev *matrix_mdev;
2856 list_for_each_entry(matrix_mdev, &matrix_dev->mdev_list, node) {
2857 if (bitmap_empty(matrix_mdev->apm_add, AP_DEVICES) &&
2858 bitmap_empty(matrix_mdev->aqm_add, AP_DOMAINS) &&
2859 bitmap_empty(matrix_mdev->adm_add, AP_DOMAINS))
2862 vfio_ap_mdev_hot_plug_cfg(matrix_mdev);
2863 bitmap_clear(matrix_mdev->apm_add, 0, AP_DEVICES);
2864 bitmap_clear(matrix_mdev->aqm_add, 0, AP_DOMAINS);
2865 bitmap_clear(matrix_mdev->adm_add, 0, AP_DOMAINS);