fixup! s390/vfio-ap: Notify userspace that guest's AP config changed when mdev removed
Subsystems (4)
RFC PATCH 1/1 fixup! s390/vfio-ap: Notify userspace that guest's AP config changed when mdev removed
This patch is based on the s390/features branch
The guest's AP configuration is cleared when the mdev is removed, so userspace must be notified that the AP configuration has changed. To this end, this patch:
* Removes call to 'signal_guest_ap_cfg_changed()' function from the 'vfio_ap_mdev_unset_kvm()' function because it has no affect given it is called after the mdev fd is closed.
* Adds call to 'signal_guest_ap_cfg_changed()' function to the 'vfio_ap_mdev_request()' function to notify userspace that the guest's AP configuration has changed before signaling the request to remove the mdev.
Minor change - Fixed an indentation issue in function 'signal_guest_ap_cfg_changed()'
--- drivers/s390/crypto/vfio_ap_ops.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +16 -3
@@ -652,8 +652,8 @@ static void vfio_ap_matrix_init(struct ap_config_info *info,static void signal_guest_ap_cfg_changed (struct ap_matrix_mdev *matrix_mdev) { -if (matrix_mdev->cfg_chg_trigger) -eventfd_signal (matrix_mdev->cfg_chg_trigger); +if (matrix_mdev->cfg_chg_trigger) +eventfd_signal (matrix_mdev->cfg_chg_trigger); }static void vfio_ap_mdev_update_guest_apcb (struct ap_matrix_mdev *matrix_mdev)
@@ -1870,7 +1870,6 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev)get_update_locks_for_kvm (kvm);kvm_arch_crypto_clear_masks (kvm); -signal_guest_ap_cfg_changed (matrix_mdev);vfio_ap_mdev_reset_queues (matrix_mdev);kvm_put_kvm (kvm); matrix_mdev->kvm =NULL ;
@@ -2057,6 +2056,14 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count) matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev); +if (matrix_mdev->kvm) { +get_update_locks_for_kvm (matrix_mdev->kvm); +kvm_arch_crypto_clear_masks (matrix_mdev->kvm); +signal_guest_ap_cfg_changed (matrix_mdev); + }else { +mutex_lock (&matrix_dev->mdevs_lock); + } +if (matrix_mdev->req_trigger) {if (!(count %10 )) dev_notice_ratelimited(dev,
@@ -2068,6 +2075,12 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count)dev_notice (dev,"No device request registered, blocked until released by user\n" ); } + +if (matrix_mdev->kvm) +release_update_locks_for_kvm (matrix_mdev->kvm); +else +mutex_unlock (&matrix_dev->mdevs_lock); + }static int vfio_ap_mdev_get_device_info (unsigned long arg)
Signature · 1 line
2.48.1
Anthony Krowiak
maintainerQuoted 48 lines · Rorie Reyes
This patch is based on the s390/features branch
The guest's AP configuration is cleared when the mdev is removed, so userspace must be notified that the AP configuration has changed. To this end, this patch:
* Removes call to '
signal_guest_ap_cfg_changed()' function from the 'vfio_ap_mdev_unset_kvm()' function because it has no affect given it is called after the mdev fd is closed.* Adds call to '
signal_guest_ap_cfg_changed()' function to the 'vfio_ap_mdev_request()' function to notify userspace that the guest's AP configuration has changed before signaling the request to remove the mdev.Minor change - Fixed an indentation issue in function '
signal_guest_ap_cfg_changed()'Fixes 2ba4410dd477 ("s390/vfio-ap: Signal eventfd when guest AP configuration is changed")Signed-off-by Rorie Reyes <[email protected]>--- drivers/s390/crypto/vfio_ap_ops.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)drivers/s390/crypto/vfio_ap_ops.c +2
-3@@ -652,8 +652,8 @@ static void vfio_ap_matrix_init(struct ap_config_info *info,static void signal_guest_ap_cfg_changed (struct ap_matrix_mdev *matrix_mdev) { -if (matrix_mdev->cfg_chg_trigger) -eventfd_signal (matrix_mdev->cfg_chg_trigger); +if (matrix_mdev->cfg_chg_trigger) +eventfd_signal (matrix_mdev->cfg_chg_trigger); }static void vfio_ap_mdev_update_guest_apcb (struct ap_matrix_mdev *matrix_mdev)@@ -1870,7 +1870,6 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev)get_update_locks_for_kvm (kvm);kvm_arch_crypto_clear_masks (kvm); -signal_guest_ap_cfg_changed (matrix_mdev);vfio_ap_mdev_reset_queues (matrix_mdev);kvm_put_kvm (kvm); matrix_mdev->kvm =NULL ;
drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count) · line 2060
Quoted 5 lines
drivers/s390/crypto/vfio_ap_ops.c +2
-0@@ -2057,6 +2056,14 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count) matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev); +if (matrix_mdev->kvm) { +get_update_locks_for_kvm (matrix_mdev->kvm);
I know we talked about this prior to submission of this patch, but looking at this again I think you should use the get_update_locks_for_mdev() function for two reasons:
1. It is safer because it will take the matrix_dev->guests_lock which will prevent the matrix_mdev->kvm field from changing before you check it
2. I will eliminate the need for the else
get_update_locks_for_mdev(matrix_mdev)
if (matrix_mdev->kvm) {
clear the masks
signal guest config changed
}
...release_update_locks_for_mdev(matrix_mdev); Sorry about not seeing this before you posted this patch.
Quoted 22 lines
drivers/s390/crypto/vfio_ap_ops.c +12
-0+kvm_arch_crypto_clear_masks (matrix_mdev->kvm); +signal_guest_ap_cfg_changed (matrix_mdev); + }else { +mutex_lock (&matrix_dev->mdevs_lock); + } +if (matrix_mdev->req_trigger) {if (!(count %10 )) dev_notice_ratelimited(dev,@@ -2068,6 +2075,12 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count)dev_notice (dev,"No device request registered, blocked until released by user\n" ); } + +if (matrix_mdev->kvm) +release_update_locks_for_kvm (matrix_mdev->kvm); +else +mutex_unlock (&matrix_dev->mdevs_lock); + }static int vfio_ap_mdev_get_device_info (unsigned long arg)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Anthony Krowiak
maintainerQuoted 21 lines · Rorie Reyes
Quoted 18 lines · Anthony Krowiak
Quoted 10 lines
static void
vfio_ap_mdev_update_guest_apcb(struct ap_matrix_mdev *matrix_mdev)drivers/s390/crypto/vfio_ap_ops.c +0
-1@@ -1870,7 +1870,6 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev) get_update_locks_for_kvm(kvm); kvm_arch_crypto_clear_masks(kvm); - signal_guest_ap_cfg_changed(matrix_mdev); vfio_ap_mdev_reset_queues(matrix_mdev); kvm_put_kvm(kvm); matrix_mdev->kvm = NULL;drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_mdev_request(struct · line 2059
Quoted 4 lines
drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -2057,6 +2056,14 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count) matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev); + if (matrix_mdev->kvm) { + get_update_locks_for_kvm(matrix_mdev->kvm);I know we talked about this prior to submission of this patch, but looking at this again I think you should use the
get_update_locks_for_mdev()function for two reasons:
Quoted 4 lines
Quoted 3 lines
1. It is safer because it will take the
matrix_dev->guests_lockwhich will prevent thematrix_mdev->kvmfield from changing before you check itSo I'll replace *get_update_locks_for_kvm(matrix_mdev->kvm)* with *get_update_locks_for_mdev(&matrix_dev->guests_lock)*
See code below:get_update_locks_for_mdev(matrix_mdev) That function will take the guests_lock
Quoted 15 lines
Quoted 14 lines
2. I will eliminate the need for the else
get_update_locks_for_mdev(matrix_mdev)
if (matrix_mdev->kvm) {
clear the masks
signal guest config changed
}
...release_update_locks_for_mdev(matrix_mdev); Sorry about not seeing this before you posted this patch.Quoted 5 lines
drivers/s390/crypto/vfio_ap_ops.c +5
-0+kvm_arch_crypto_clear_masks (matrix_mdev->kvm); + signal_guest_ap_cfg_changed(matrix_mdev); + } else { + mutex_lock(&matrix_dev->mdevs_lock); + }So remove the else statement that contains the mutex function
Quoted 25 lines · Anthony Krowiak
Quoted 21 lines · Rorie Reyes
Quoted 18 lines · Anthony Krowiak
Quoted 10 lines
static void
vfio_ap_mdev_update_guest_apcb(struct ap_matrix_mdev *matrix_mdev)drivers/s390/crypto/vfio_ap_ops.c +0
-1@@ -1870,7 +1870,6 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev) get_update_locks_for_kvm(kvm); kvm_arch_crypto_clear_masks(kvm); - signal_guest_ap_cfg_changed(matrix_mdev); vfio_ap_mdev_reset_queues(matrix_mdev); kvm_put_kvm(kvm); matrix_mdev->kvm = NULL;drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_mdev_request(struct · line 2059
Quoted 4 lines
drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -2057,6 +2056,14 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count) matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev); + if (matrix_mdev->kvm) { + get_update_locks_for_kvm(matrix_mdev->kvm);I know we talked about this prior to submission of this patch, but looking at this again I think you should use the
get_update_locks_for_mdev()function for two reasons:
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
1. It is safer because it will take the
matrix_dev->guests_lockwhich will prevent thematrix_mdev->kvmfield from changing before you check itSo I'll replace *get_update_locks_for_kvm(matrix_mdev->kvm)* with *get_update_locks_for_mdev(&matrix_dev->guests_lock)*
See code below:get_update_locks_for_mdev(matrix_mdev) That function will take the
guests_lock
Ah ok, I see now. I'll make those changes. Thank you!
Quoted 16 lines
Quoted 15 lines
Quoted 14 lines
2. I will eliminate the need for the else
get_update_locks_for_mdev(matrix_mdev)
if (matrix_mdev->kvm) {
clear the masks
signal guest config changed
}
...release_update_locks_for_mdev(matrix_mdev); Sorry about not seeing this before you posted this patch.Quoted 5 lines
drivers/s390/crypto/vfio_ap_ops.c +5
-0+kvm_arch_crypto_clear_masks (matrix_mdev->kvm); + signal_guest_ap_cfg_changed(matrix_mdev); + } else { + mutex_lock(&matrix_dev->mdevs_lock); + }So remove the else statement that contains the mutex function