]> git.baikalelectronics.ru Git - kernel.git/commitdiff
s390/vfio-ap: sysfs attribute to display the guest's matrix
authorTony Krowiak <akrowiak@linux.ibm.com>
Tue, 10 Sep 2019 15:17:45 +0000 (11:17 -0400)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Tue, 19 Jul 2022 14:18:11 +0000 (16:18 +0200)
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 <akrowiak@linux.ibm.com>
Reviewed-by: Jason J. Herne <jjherne@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
drivers/s390/crypto/vfio_ap_ops.c

index 4a864fc5b78822b0e9ca9df4a7b01f71c527ae1f..6d722de44e8dce02f500ed1d338f691b601f68fa 100644 (file)
@@ -1427,28 +1427,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 ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
        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(&matrix_dev->mdevs_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);
@@ -1457,25 +1453,50 @@ 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 ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
+
+       mutex_lock(&matrix_dev->mdevs_lock);
+       nchars = vfio_ap_mdev_matrix_show(&matrix_mdev->matrix, buf);
        mutex_unlock(&matrix_dev->mdevs_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 ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
+
+       mutex_lock(&matrix_dev->mdevs_lock);
+       nchars = vfio_ap_mdev_matrix_show(&matrix_mdev->shadow_apcb, buf);
+       mutex_unlock(&matrix_dev->mdevs_lock);
+
+       return nchars;
+}
+static DEVICE_ATTR_RO(guest_matrix);
+
 static struct attribute *vfio_ap_mdev_attrs[] = {
        &dev_attr_assign_adapter.attr,
        &dev_attr_unassign_adapter.attr,
@@ -1485,6 +1506,7 @@ static struct attribute *vfio_ap_mdev_attrs[] = {
        &dev_attr_unassign_control_domain.attr,
        &dev_attr_control_domains.attr,
        &dev_attr_matrix.attr,
+       &dev_attr_guest_matrix.attr,
        NULL,
 };