Re: [PATCH v12 09/17] s390/vfio-ap: sysfs attribute to display the guest's matrix

2020-12-16 Thread Tony Krowiak

Thanks for the review.

On 11/28/20 7:49 PM, Halil Pasic wrote:

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


The matrix of adapters and domains configured in a guest's APCB may
differ from the matrix of adapters and domains assigned to the matrix mdev,
so this patch introduces a sysfs attribute to display the matrix of
adapters and domains that are or will be assigned to the APCB of a guest
that is or will be using the matrix mdev. For a matrix mdev denoted by
$uuid, the guest matrix can be displayed as follows:

cat /sys/devices/vfio_ap/matrix/$uuid/guest_matrix

Signed-off-by: Tony Krowiak 

Code looks good, but it may be a little early, since the treatment of
guset_matrix is changed by the following patches.




Re: [PATCH v12 09/17] s390/vfio-ap: sysfs attribute to display the guest's matrix

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

> The matrix of adapters and domains configured in a guest's APCB may
> differ from the matrix of adapters and domains assigned to the matrix mdev,
> so this patch introduces a sysfs attribute to display the matrix of
> adapters and domains that are or will be assigned to the APCB of a guest
> that is or will be using the matrix mdev. For a matrix mdev denoted by
> $uuid, the guest matrix can be displayed as follows:
> 
>cat /sys/devices/vfio_ap/matrix/$uuid/guest_matrix
> 
> Signed-off-by: Tony Krowiak 

Code looks good, but it may be a little early, since the treatment of
guset_matrix is changed by the following patches.


[PATCH v12 09/17] s390/vfio-ap: sysfs attribute to display the guest's matrix

2020-11-24 Thread Tony Krowiak
The matrix of adapters and domains configured in a guest's APCB may
differ from the matrix of adapters and domains assigned to the matrix mdev,
so this patch introduces a sysfs attribute to display the matrix of
adapters and domains that are or will be assigned to the APCB of a guest
that is or will be using the matrix mdev. For a matrix mdev denoted by
$uuid, the guest matrix can be displayed as follows:

   cat /sys/devices/vfio_ap/matrix/$uuid/guest_matrix

Signed-off-by: Tony Krowiak 
---
 drivers/s390/crypto/vfio_ap_ops.c | 51 ++-
 1 file changed, 37 insertions(+), 14 deletions(-)

diff --git a/drivers/s390/crypto/vfio_ap_ops.c 
b/drivers/s390/crypto/vfio_ap_ops.c
index 89b0e81657ca..a69422d76e7f 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -1075,29 +1075,24 @@ static ssize_t control_domains_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(control_domains);
 
-static ssize_t matrix_show(struct device *dev, struct device_attribute *attr,
-  char *buf)
+static ssize_t vfio_ap_mdev_matrix_show(struct ap_matrix *matrix, char *buf)
 {
-   struct mdev_device *mdev = mdev_from_dev(dev);
-   struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
char *bufpos = buf;
unsigned long apid;
unsigned long apqi;
unsigned long apid1;
unsigned long apqi1;
-   unsigned long napm_bits = matrix_mdev->matrix.apm_max + 1;
-   unsigned long naqm_bits = matrix_mdev->matrix.aqm_max + 1;
+   unsigned long napm_bits = matrix->apm_max + 1;
+   unsigned long naqm_bits = matrix->aqm_max + 1;
int nchars = 0;
int n;
 
-   apid1 = find_first_bit_inv(matrix_mdev->matrix.apm, napm_bits);
-   apqi1 = find_first_bit_inv(matrix_mdev->matrix.aqm, naqm_bits);
-
-   mutex_lock(_dev->lock);
+   apid1 = find_first_bit_inv(matrix->apm, napm_bits);
+   apqi1 = find_first_bit_inv(matrix->aqm, naqm_bits);
 
if ((apid1 < napm_bits) && (apqi1 < naqm_bits)) {
-   for_each_set_bit_inv(apid, matrix_mdev->matrix.apm, napm_bits) {
-   for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm,
+   for_each_set_bit_inv(apid, matrix->apm, napm_bits) {
+   for_each_set_bit_inv(apqi, matrix->aqm,
 naqm_bits) {
n = sprintf(bufpos, "%02lx.%04lx\n", apid,
apqi);
@@ -1106,25 +1101,52 @@ static ssize_t matrix_show(struct device *dev, struct 
device_attribute *attr,
}
}
} else if (apid1 < napm_bits) {
-   for_each_set_bit_inv(apid, matrix_mdev->matrix.apm, napm_bits) {
+   for_each_set_bit_inv(apid, matrix->apm, napm_bits) {
n = sprintf(bufpos, "%02lx.\n", apid);
bufpos += n;
nchars += n;
}
} else if (apqi1 < naqm_bits) {
-   for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm, naqm_bits) {
+   for_each_set_bit_inv(apqi, matrix->aqm, naqm_bits) {
n = sprintf(bufpos, ".%04lx\n", apqi);
bufpos += n;
nchars += n;
}
}
 
+   return nchars;
+}
+
+static ssize_t matrix_show(struct device *dev, struct device_attribute *attr,
+  char *buf)
+{
+   ssize_t nchars;
+   struct mdev_device *mdev = mdev_from_dev(dev);
+   struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+   mutex_lock(_dev->lock);
+   nchars = vfio_ap_mdev_matrix_show(_mdev->matrix, buf);
mutex_unlock(_dev->lock);
 
return nchars;
 }
 static DEVICE_ATTR_RO(matrix);
 
+static ssize_t guest_matrix_show(struct device *dev,
+struct device_attribute *attr, char *buf)
+{
+   ssize_t nchars;
+   struct mdev_device *mdev = mdev_from_dev(dev);
+   struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+
+   mutex_lock(_dev->lock);
+   nchars = vfio_ap_mdev_matrix_show(_mdev->shadow_apcb, buf);
+   mutex_unlock(_dev->lock);
+
+   return nchars;
+}
+static DEVICE_ATTR_RO(guest_matrix);
+
 static struct attribute *vfio_ap_mdev_attrs[] = {
_attr_assign_adapter.attr,
_attr_unassign_adapter.attr,
@@ -1134,6 +1156,7 @@ static struct attribute *vfio_ap_mdev_attrs[] = {
_attr_unassign_control_domain.attr,
_attr_control_domains.attr,
_attr_matrix.attr,
+   _attr_guest_matrix.attr,
NULL,
 };
 
-- 
2.21.1