Re: [PATCH v12 05/17] s390/vfio-ap: manage link between queue struct and matrix mdev

2020-12-14 Thread Tony Krowiak




On 11/26/20 9:08 AM, Halil Pasic wrote:

On Tue, 24 Nov 2020 16:40:04 -0500
Tony Krowiak  wrote:


@@ -1155,6 +1243,11 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device 
*mdev)
 matrix_mdev->matrix.apm_max + 1) {
for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm,
 matrix_mdev->matrix.aqm_max + 1) {
+   q = vfio_ap_mdev_get_queue(matrix_mdev,
+  AP_MKQID(apid, apqi));
+   if (!q)
+   continue;
+
ret = vfio_ap_mdev_reset_queue(apid, apqi, 1);
/*
 * Regardless whether a queue turns out to be busy, or
@@ -1164,9 +1257,7 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device 
*mdev)
if (ret)
rc = ret;
  
-			q = vfio_ap_get_queue(matrix_mdev, AP_MKQID(apid, apqi);

-   if (q)
-   vfio_ap_free_aqic_resources(q);
+   vfio_ap_free_aqic_resources(q);
}
}

During the review of v11 we discussed this. Introducing this the one
way around, just to change it in the next patch, which should deal
with something different makes no sense to me.


This is handled by the vfio_ap_mdev_reset_queue() function in the
next version.



BTW I've provided a ton of feedback for '[PATCH v11 03/14]
s390/vfio-ap: manage link between queue struct and matrix mdev', but I
can't find your response to that. Some of the things resurface here, and
I don't feel like repeating myself. Can you provide me an answer to
the v11 version?


I can.




Re: [PATCH v12 05/17] s390/vfio-ap: manage link between queue struct and matrix mdev

2020-12-14 Thread Tony Krowiak




On 11/26/20 9:45 AM, Halil Pasic wrote:

On Tue, 24 Nov 2020 16:40:04 -0500
Tony Krowiak  wrote:


Let's create links between each queue device bound to the vfio_ap device
driver and the matrix mdev to which the queue is assigned. The idea is to
facilitate efficient retrieval of the objects representing the queue
devices and matrix mdevs as well as to verify that a queue assigned to
a matrix mdev is bound to the driver.

The links will be created as follows:

* When the queue device is probed, if its APQN is assigned to a matrix
  mdev, the structures representing the queue device and the matrix mdev
  will be linked.

* When an adapter or domain is assigned to a matrix mdev, for each new
  APQN assigned that references a queue device bound to the vfio_ap
  device driver, the structures representing the queue device and the
  matrix mdev will be linked.

The links will be removed as follows:

* When the queue device is removed, if its APQN is assigned to a matrix
  mdev, the structures representing the queue device and the matrix mdev
  will be unlinked.

* When an adapter or domain is unassigned from a matrix mdev, for each
  APQN unassigned that references a queue device bound to the vfio_ap
  device driver, the structures representing the queue device and the
  matrix mdev will be unlinked.

Signed-off-by: Tony Krowiak 

Actually some aspects of this look much better than last time,
but I'm afraid there one new issue that must be corrected -- see below.


---
  drivers/s390/crypto/vfio_ap_ops.c | 161 +++---
  drivers/s390/crypto/vfio_ap_private.h |   3 +
  2 files changed, 146 insertions(+), 18 deletions(-)

diff --git a/drivers/s390/crypto/vfio_ap_ops.c 
b/drivers/s390/crypto/vfio_ap_ops.c
index dc699fd54505..07caf871943c 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -28,7 +28,6 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device 
*mdev);
  
  /**

   * vfio_ap_get_queue: Retrieve a queue with a specific APQN.
- * @matrix_mdev: the associated mediated matrix
   * @apqn: The queue APQN
   *
   * Retrieve a queue with a specific APQN from the AP queue devices attached to
@@ -36,32 +35,36 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device 
*mdev);
   *
   * Returns the pointer to the vfio_ap_queue with the specified APQN, or NULL.
   */
-static struct vfio_ap_queue *vfio_ap_get_queue(
-   struct ap_matrix_mdev *matrix_mdev,
-   int apqn)
+static struct vfio_ap_queue *vfio_ap_get_queue(int apqn)
  {
struct ap_queue *queue;
struct vfio_ap_queue *q = NULL;
  
-	if (!test_bit_inv(AP_QID_CARD(apqn), matrix_mdev->matrix.apm))

-   return NULL;
-   if (!test_bit_inv(AP_QID_QUEUE(apqn), matrix_mdev->matrix.aqm))
-   return NULL;
-
queue = ap_get_qdev(apqn);
if (!queue)
return NULL;
  
  	put_device(>ap_dev.device);
  
-	if (queue->ap_dev.device.driver == _dev->vfio_ap_drv->driver) {

+   if (queue->ap_dev.device.driver == _dev->vfio_ap_drv->driver)
q = dev_get_drvdata(>ap_dev.device);
-   q->matrix_mdev = matrix_mdev;
-   }
  
  	return q;

  }
  
+static struct vfio_ap_queue *

+vfio_ap_mdev_get_queue(struct ap_matrix_mdev *matrix_mdev, unsigned long apqn)
+{
+   struct vfio_ap_queue *q;
+
+   hash_for_each_possible(matrix_mdev->qtable, q, mdev_qnode, apqn) {
+   if (q && (q->apqn == apqn))
+   return q;
+   }
+
+   return NULL;
+}
+
  /**
   * vfio_ap_wait_for_irqclear
   * @apqn: The AP Queue number
@@ -172,7 +175,6 @@ static struct ap_queue_status vfio_ap_irq_disable(struct 
vfio_ap_queue *q)
  status.response_code);
  end_free:
vfio_ap_free_aqic_resources(q);
-   q->matrix_mdev = NULL;
return status;
  }
  
@@ -288,7 +290,7 @@ static int handle_pqap(struct kvm_vcpu *vcpu)

matrix_mdev = container_of(vcpu->kvm->arch.crypto.pqap_hook,
   struct ap_matrix_mdev, pqap_hook);
  
-	q = vfio_ap_get_queue(matrix_mdev, apqn);

+   q = vfio_ap_mdev_get_queue(matrix_mdev, apqn);
if (!q)
goto out_unlock;
  
@@ -331,6 +333,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
  
  	matrix_mdev->mdev = mdev;

vfio_ap_matrix_init(_dev->info, _mdev->matrix);
+   hash_init(matrix_mdev->qtable);
mdev_set_drvdata(mdev, matrix_mdev);
matrix_mdev->pqap_hook.hook = handle_pqap;
matrix_mdev->pqap_hook.owner = THIS_MODULE;
@@ -559,6 +562,87 @@ static int vfio_ap_mdev_verify_no_sharing(struct 
ap_matrix_mdev *matrix_mdev)
return 0;
  }
  
+enum qlink_action {

+   LINK_APID,
+   LINK_APQI,
+   UNLINK_APID,
+   UNLINK_APQI,
+};
+
+static void vfio_ap_mdev_link_queue(struct 

Re: [PATCH v12 05/17] s390/vfio-ap: manage link between queue struct and matrix mdev

2020-11-26 Thread Halil Pasic
On Tue, 24 Nov 2020 16:40:04 -0500
Tony Krowiak  wrote:

> Let's create links between each queue device bound to the vfio_ap device
> driver and the matrix mdev to which the queue is assigned. The idea is to
> facilitate efficient retrieval of the objects representing the queue
> devices and matrix mdevs as well as to verify that a queue assigned to
> a matrix mdev is bound to the driver.
> 
> The links will be created as follows:
> 
>* When the queue device is probed, if its APQN is assigned to a matrix
>  mdev, the structures representing the queue device and the matrix mdev
>  will be linked.
> 
>* When an adapter or domain is assigned to a matrix mdev, for each new
>  APQN assigned that references a queue device bound to the vfio_ap
>  device driver, the structures representing the queue device and the
>  matrix mdev will be linked.
> 
> The links will be removed as follows:
> 
>* When the queue device is removed, if its APQN is assigned to a matrix
>  mdev, the structures representing the queue device and the matrix mdev
>  will be unlinked.
> 
>* When an adapter or domain is unassigned from a matrix mdev, for each
>  APQN unassigned that references a queue device bound to the vfio_ap
>  device driver, the structures representing the queue device and the
>  matrix mdev will be unlinked.
> 
> Signed-off-by: Tony Krowiak 

Actually some aspects of this look much better than last time,
but I'm afraid there one new issue that must be corrected -- see below.

> ---
>  drivers/s390/crypto/vfio_ap_ops.c | 161 +++---
>  drivers/s390/crypto/vfio_ap_private.h |   3 +
>  2 files changed, 146 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/s390/crypto/vfio_ap_ops.c 
> b/drivers/s390/crypto/vfio_ap_ops.c
> index dc699fd54505..07caf871943c 100644
> --- a/drivers/s390/crypto/vfio_ap_ops.c
> +++ b/drivers/s390/crypto/vfio_ap_ops.c
> @@ -28,7 +28,6 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device 
> *mdev);
>  
>  /**
>   * vfio_ap_get_queue: Retrieve a queue with a specific APQN.
> - * @matrix_mdev: the associated mediated matrix
>   * @apqn: The queue APQN
>   *
>   * Retrieve a queue with a specific APQN from the AP queue devices attached 
> to
> @@ -36,32 +35,36 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device 
> *mdev);
>   *
>   * Returns the pointer to the vfio_ap_queue with the specified APQN, or NULL.
>   */
> -static struct vfio_ap_queue *vfio_ap_get_queue(
> - struct ap_matrix_mdev *matrix_mdev,
> - int apqn)
> +static struct vfio_ap_queue *vfio_ap_get_queue(int apqn)
>  {
>   struct ap_queue *queue;
>   struct vfio_ap_queue *q = NULL;
>  
> - if (!test_bit_inv(AP_QID_CARD(apqn), matrix_mdev->matrix.apm))
> - return NULL;
> - if (!test_bit_inv(AP_QID_QUEUE(apqn), matrix_mdev->matrix.aqm))
> - return NULL;
> -
>   queue = ap_get_qdev(apqn);
>   if (!queue)
>   return NULL;
>  
>   put_device(>ap_dev.device);
>  
> - if (queue->ap_dev.device.driver == _dev->vfio_ap_drv->driver) {
> + if (queue->ap_dev.device.driver == _dev->vfio_ap_drv->driver)
>   q = dev_get_drvdata(>ap_dev.device);
> - q->matrix_mdev = matrix_mdev;
> - }
>  
>   return q;
>  }
>  
> +static struct vfio_ap_queue *
> +vfio_ap_mdev_get_queue(struct ap_matrix_mdev *matrix_mdev, unsigned long 
> apqn)
> +{
> + struct vfio_ap_queue *q;
> +
> + hash_for_each_possible(matrix_mdev->qtable, q, mdev_qnode, apqn) {
> + if (q && (q->apqn == apqn))
> + return q;
> + }
> +
> + return NULL;
> +}
> +
>  /**
>   * vfio_ap_wait_for_irqclear
>   * @apqn: The AP Queue number
> @@ -172,7 +175,6 @@ static struct ap_queue_status vfio_ap_irq_disable(struct 
> vfio_ap_queue *q)
> status.response_code);
>  end_free:
>   vfio_ap_free_aqic_resources(q);
> - q->matrix_mdev = NULL;
>   return status;
>  }
>  
> @@ -288,7 +290,7 @@ static int handle_pqap(struct kvm_vcpu *vcpu)
>   matrix_mdev = container_of(vcpu->kvm->arch.crypto.pqap_hook,
>  struct ap_matrix_mdev, pqap_hook);
>  
> - q = vfio_ap_get_queue(matrix_mdev, apqn);
> + q = vfio_ap_mdev_get_queue(matrix_mdev, apqn);
>   if (!q)
>   goto out_unlock;
>  
> @@ -331,6 +333,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, 
> struct mdev_device *mdev)
>  
>   matrix_mdev->mdev = mdev;
>   vfio_ap_matrix_init(_dev->info, _mdev->matrix);
> + hash_init(matrix_mdev->qtable);
>   mdev_set_drvdata(mdev, matrix_mdev);
>   matrix_mdev->pqap_hook.hook = handle_pqap;
>   matrix_mdev->pqap_hook.owner = THIS_MODULE;
> @@ -559,6 +562,87 @@ static int vfio_ap_mdev_verify_no_sharing(struct 
> ap_matrix_mdev *matrix_mdev)
>   return 0;
>  }
>  
> +enum qlink_action {
> + 

Re: [PATCH v12 05/17] s390/vfio-ap: manage link between queue struct and matrix mdev

2020-11-26 Thread Halil Pasic
On Tue, 24 Nov 2020 16:40:04 -0500
Tony Krowiak  wrote:

> @@ -1155,6 +1243,11 @@ static int vfio_ap_mdev_reset_queues(struct 
> mdev_device *mdev)
>matrix_mdev->matrix.apm_max + 1) {
>   for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm,
>matrix_mdev->matrix.aqm_max + 1) {
> + q = vfio_ap_mdev_get_queue(matrix_mdev,
> +AP_MKQID(apid, apqi));
> + if (!q)
> + continue;
> +
>   ret = vfio_ap_mdev_reset_queue(apid, apqi, 1);
>   /*
>* Regardless whether a queue turns out to be busy, or
> @@ -1164,9 +1257,7 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device 
> *mdev)
>   if (ret)
>   rc = ret;
>  
> - q = vfio_ap_get_queue(matrix_mdev, AP_MKQID(apid, apqi);
> - if (q)
> - vfio_ap_free_aqic_resources(q);
> + vfio_ap_free_aqic_resources(q);
>   }
>   }

During the review of v11 we discussed this. Introducing this the one
way around, just to change it in the next patch, which should deal
with something different makes no sense to me.

BTW I've provided a ton of feedback for '[PATCH v11 03/14]
s390/vfio-ap: manage link between queue struct and matrix mdev', but I
can't find your response to that. Some of the things resurface here, and
I don't feel like repeating myself. Can you provide me an answer to
the v11 version?