diff mbox series

[RFC,v2] s390/vfio-ap: Notify userspace that guest's AP config changed when mdev removed

Message ID 20250304200812.54556-1-rreyes@linux.ibm.com (mailing list archive)
State New
Headers show
Series [RFC,v2] s390/vfio-ap: Notify userspace that guest's AP config changed when mdev removed | expand

Commit Message

Rorie Reyes March 4, 2025, 8:08 p.m. UTC
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: 07d89045bffe ("s390/vfio-ap: Signal eventfd when guest AP configuration is changed")
Signed-off-by: Rorie Reyes <rreyes@linux.ibm.com>
---
This patch is based on the s390/features branch

V1 -> V2:
- replaced get_update_locks_for_kvm() with get_update_locks_for_mdev
- removed else statements that were unnecessary
- Addressed review comments for commit messages/details
---
 drivers/s390/crypto/vfio_ap_ops.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Anthony Krowiak March 4, 2025, 8:11 p.m. UTC | #1
On 3/4/25 3:08 PM, Rorie Reyes wrote:
> 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: 07d89045bffe ("s390/vfio-ap: Signal eventfd when guest AP configuration is changed")
> Signed-off-by: Rorie Reyes <rreyes@linux.ibm.com>
> ---
> This patch is based on the s390/features branch
>
> V1 -> V2:
> - replaced get_update_locks_for_kvm() with get_update_locks_for_mdev
> - removed else statements that were unnecessary
> - Addressed review comments for commit messages/details
> ---
>   drivers/s390/crypto/vfio_ap_ops.c | 15 ++++++++++++---
>   1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
> index 571f5dcb49c5..ae2bc5c1d445 100644
> --- a/drivers/s390/crypto/vfio_ap_ops.c
> +++ b/drivers/s390/crypto/vfio_ap_ops.c
> @@ -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,13 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count)
>   
>   	matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev);
>   
> +	get_update_locks_for_mdev(matrix_mdev);
> +
> +	if (matrix_mdev->kvm) {
> +		kvm_arch_crypto_clear_masks(matrix_mdev->kvm);
> +		signal_guest_ap_cfg_changed(matrix_mdev);
> +	}
> +
>   	if (matrix_mdev->req_trigger) {
>   		if (!(count % 10))
>   			dev_notice_ratelimited(dev,
> @@ -2068,6 +2074,9 @@ 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");
>   	}
> +
> +	release_update_locks_for_mdev(matrix_mdev);
> +

Get rid of empty line; other than that, LGTM
Reviewed-by: Anthony Krowiak <akrowiak@linux.ibm.com>

>   }
>   
>   static int vfio_ap_mdev_get_device_info(unsigned long arg)
Vasily Gorbik March 4, 2025, 9 p.m. UTC | #2
On Tue, Mar 04, 2025 at 03:11:12PM -0500, Anthony Krowiak wrote:
> On 3/4/25 3:08 PM, Rorie Reyes wrote:
> > 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: 07d89045bffe ("s390/vfio-ap: Signal eventfd when guest AP configuration is changed")
> > Signed-off-by: Rorie Reyes <rreyes@linux.ibm.com>
> > ---
> > This patch is based on the s390/features branch
> > 
> > V1 -> V2:
> > - replaced get_update_locks_for_kvm() with get_update_locks_for_mdev
> > - removed else statements that were unnecessary
> > - Addressed review comments for commit messages/details
> > ---
> >   drivers/s390/crypto/vfio_ap_ops.c | 15 ++++++++++++---
> >   1 file changed, 12 insertions(+), 3 deletions(-)

> > @@ -2068,6 +2074,9 @@ 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");
> >   	}
> > +
> > +	release_update_locks_for_mdev(matrix_mdev);
> > +
> 
> Get rid of empty line; other than that, LGTM
> Reviewed-by: Anthony Krowiak <akrowiak@linux.ibm.com>

Removed the empty line and applied, thank you!
diff mbox series

Patch

diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index 571f5dcb49c5..ae2bc5c1d445 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -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,13 @@  static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count)
 
 	matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev);
 
+	get_update_locks_for_mdev(matrix_mdev);
+
+	if (matrix_mdev->kvm) {
+		kvm_arch_crypto_clear_masks(matrix_mdev->kvm);
+		signal_guest_ap_cfg_changed(matrix_mdev);
+	}
+
 	if (matrix_mdev->req_trigger) {
 		if (!(count % 10))
 			dev_notice_ratelimited(dev,
@@ -2068,6 +2074,9 @@  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");
 	}
+
+	release_update_locks_for_mdev(matrix_mdev);
+
 }
 
 static int vfio_ap_mdev_get_device_info(unsigned long arg)