From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:16690 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229646AbhA1Vad (ORCPT ); Thu, 28 Jan 2021 16:30:33 -0500 Subject: Re: [PATCH v13 08/15] s390/vfio-ap: sysfs attribute to display the guest's matrix References: <20201223011606.5265-1-akrowiak@linux.ibm.com> <20201223011606.5265-9-akrowiak@linux.ibm.com> <20210111235806.5df42658.pasic@linux.ibm.com> From: Tony Krowiak Message-ID: <6b526a2c-138c-55ad-d3f0-9c96558b255b@linux.ibm.com> Date: Thu, 28 Jan 2021 16:29:44 -0500 MIME-Version: 1.0 In-Reply-To: <20210111235806.5df42658.pasic@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-ID: To: Halil Pasic Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, freude@linux.ibm.com, borntraeger@de.ibm.com, cohuck@redhat.com, mjrosato@linux.ibm.com, alex.williamson@redhat.com, kwankhede@nvidia.com, fiuczy@linux.ibm.com, frankja@linux.ibm.com, david@redhat.com, hca@linux.ibm.com, gor@linux.ibm.com On 1/11/21 5:58 PM, Halil Pasic wrote: > On Tue, 22 Dec 2020 20:15:59 -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 > Reviewed-by: Halil Pasic > > But because vfio_ap_mdev_commit_shadow_apcb() is not used (see prev > patch) the attribute won't show the guest matrix at this point. :( I'll move this patch following all of the filtering and hot plug patches. > >> --- >> 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 44b3a81cadfb..1b1d5975ee0e 100644 >> --- a/drivers/s390/crypto/vfio_ap_ops.c >> +++ b/drivers/s390/crypto/vfio_ap_ops.c >> @@ -894,29 +894,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(&matrix_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); >> @@ -925,25 +920,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(&matrix_dev->lock); >> + nchars = vfio_ap_mdev_matrix_show(&matrix_mdev->matrix, buf); >> mutex_unlock(&matrix_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(&matrix_dev->lock); >> + nchars = vfio_ap_mdev_matrix_show(&matrix_mdev->shadow_apcb, buf); >> + 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, >> @@ -953,6 +975,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, >> }; >>