All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Krowiak <akrowiak@linux.ibm.com>
To: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org
Cc: freude@linux.ibm.com, borntraeger@de.ibm.com, cohuck@redhat.com,
	mjrosato@linux.ibm.com, pasic@linux.ibm.com,
	alex.williamson@redhat.com, kwankhede@nvidia.com,
	fiuczy@linux.ibm.com, Tony Krowiak <akrowiak@linux.ibm.com>
Subject: [PATCH v9 07/15] s390/vfio-ap: sysfs attribute to display the guest's matrix
Date: Mon, 20 Jul 2020 11:03:36 -0400	[thread overview]
Message-ID: <20200720150344.24488-8-akrowiak@linux.ibm.com> (raw)
In-Reply-To: <20200720150344.24488-1-akrowiak@linux.ibm.com>

The matrix of adapters and domains configured in a guest's CRYCB 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 a guest
using the matrix mdev. For a matrix mdev denoted by $uuid, the crycb for a
guest using the matrix mdev can be displayed as follows:

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

If a guest is not using the matrix mdev at the time the crycb is displayed,
an error (ENODEV) will be returned.

Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
---
 drivers/s390/crypto/vfio_ap_ops.c | 58 +++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index efb229033f9e..30bf23734af6 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -1119,6 +1119,63 @@ static ssize_t matrix_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(matrix);
 
+static ssize_t guest_matrix_show(struct device *dev,
+				 struct device_attribute *attr, 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->shadow_apcb.apm_max + 1;
+	unsigned long naqm_bits = matrix_mdev->shadow_apcb.aqm_max + 1;
+	int nchars = 0;
+	int n;
+
+	if (!vfio_ap_mdev_has_crycb(matrix_mdev))
+		return -ENODEV;
+
+	apid1 = find_first_bit_inv(matrix_mdev->shadow_apcb.apm, napm_bits);
+	apqi1 = find_first_bit_inv(matrix_mdev->shadow_apcb.aqm, naqm_bits);
+
+	mutex_lock(&matrix_dev->lock);
+
+	if ((apid1 < napm_bits) && (apqi1 < naqm_bits)) {
+		for_each_set_bit_inv(apid, matrix_mdev->shadow_apcb.apm,
+				     napm_bits) {
+			for_each_set_bit_inv(apqi,
+					     matrix_mdev->shadow_apcb.aqm,
+					     naqm_bits) {
+				n = sprintf(bufpos, "%02lx.%04lx\n", apid,
+					    apqi);
+				bufpos += n;
+				nchars += n;
+			}
+		}
+	} else if (apid1 < napm_bits) {
+		for_each_set_bit_inv(apid, matrix_mdev->shadow_apcb.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->shadow_apcb.aqm,
+				     naqm_bits) {
+			n = sprintf(bufpos, ".%04lx\n", apqi);
+			bufpos += n;
+			nchars += n;
+		}
+	}
+
+	mutex_unlock(&matrix_dev->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,
@@ -1128,6 +1185,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,
 };
 
-- 
2.21.1

  parent reply	other threads:[~2020-07-20 15:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-20 15:03 [PATCH v9 00/15] s390/vfio-ap: dynamic configuration support Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 01/15] s390/vfio-ap: add version vfio_ap module Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 02/15] s390/vfio-ap: use new AP bus interface to search for queue devices Tony Krowiak
2020-07-24  8:38   ` Pierre Morel
2020-07-27 13:42     ` Tony Krowiak
2020-07-27 14:09     ` Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 03/15] s390/vfio-ap: manage link between queue struct and matrix mdev Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 04/15] s390/zcrypt: driver callback to indicate resource in use Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 05/15] s390/vfio-ap: implement in-use callback for vfio_ap driver Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 06/15] s390/vfio-ap: introduce shadow APCB Tony Krowiak
2020-07-20 15:03 ` Tony Krowiak [this message]
2020-07-20 15:03 ` [PATCH v9 08/15] s390/vfio-ap: filter matrix for unavailable queue devices Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 09/15] s390/vfio-ap: allow assignment of unavailable AP queues to mdev device Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 10/15] s390/vfio-ap: allow configuration of matrix mdev in use by a KVM guest Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 11/15] s390/vfio-ap: allow hot plug/unplug of AP resources using mdev device Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 12/15] s390/zcrypt: Notify driver on config changed and scan complete callbacks Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 13/15] s390/vfio-ap: handle host AP config change notification Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 14/15] s390/vfio-ap: handle AP bus scan completed notification Tony Krowiak
2020-07-20 15:03 ` [PATCH v9 15/15] s390/vfio-ap: handle probe/remove not due to host AP config changes Tony Krowiak
2020-08-04 14:28 ` [PATCH v9 00/15] s390/vfio-ap: dynamic configuration support Tony Krowiak
2020-08-10 15:39 ` Tony Krowiak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200720150344.24488-8-akrowiak@linux.ibm.com \
    --to=akrowiak@linux.ibm.com \
    --cc=alex.williamson@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=fiuczy@linux.ibm.com \
    --cc=freude@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.