Received: by 10.223.185.116 with SMTP id b49csp5078898wrg; Tue, 27 Feb 2018 07:28:45 -0800 (PST) X-Google-Smtp-Source: AH8x2254Rip245jwH9HHNq+tHNkfublgQtypNm99nqo8vnE+xa5gZG8AVb/Akx35LGxNncXPDULA X-Received: by 10.99.9.195 with SMTP id 186mr11490048pgj.152.1519745325239; Tue, 27 Feb 2018 07:28:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519745325; cv=none; d=google.com; s=arc-20160816; b=02KdXXOOOL/48CqrEa9pCYVRDYrluSSerAKT0k1ByMSzYhfJZfKhXxU/rpGrcWkhUs p46jBP6uptXpB0tDi3mOXOQol2tvKgj0tVfAbT134YXiHAGwDZmv6WqEcLc1Ob3uofVj UPuomAT28O5xx8Te3Rw9rS6NSH5uzNbYZbqn6CzdOlJ5rycr7QEFMSZpIJzwfqUgSaVc DjKfpqlJgvVxsOyKrJHSLovpJh1OIES7SW1ueVCsSOFSP2u3+46EqxUy29z4I0YBDdnL hbVMhhW9I/XAXdZeQzKQcTawKsJdK67+ikCJA4BOIlaEsNSz3S9GOKM9eURKDXP1/LDa swJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=DjY0tg8uB1Milez2hE4fdwGUjk5v6SeIhaO7MkAoPLw=; b=gF+9B6fo9/sbX3PddPgfirpL3tK7uhkhdlP31SiUQGPzxowDdIfJH8NU7NHPwg18Kl MFTAhK8xZ+x32IgHpsxqSBbsU7EYrjJO2W+ZdojkOBNazCffjIoAtF8Xe43rU5w0elM7 39QvLrhnSQHgAl342ouBytuPH+X2gx6Hnhl8WlFJoB9RsIloZhk+AFNK4YOM2Oh0tv/R 9+HZUoxtyBZHki4yOurKFkqvuMVFTrhzKV+5Da/6jBLTKONz5fb7E6Q6U+kWhns2W2Ui Pj01k2RnrNYB3Ldf+jpJpPnqcZ3ByG8ZTUZGHz8rhbldesq4gL82O5B9Iqy+xMpxFbcE nyGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e90-v6si1766551plb.265.2018.02.27.07.28.31; Tue, 27 Feb 2018 07:28:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753923AbeB0Obv (ORCPT + 99 others); Tue, 27 Feb 2018 09:31:51 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48196 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753901AbeB0Obt (ORCPT ); Tue, 27 Feb 2018 09:31:49 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1REVmIi141029 for ; Tue, 27 Feb 2018 09:31:48 -0500 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gd5wxsd8r-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 27 Feb 2018 09:31:41 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 27 Feb 2018 07:28:46 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 27 Feb 2018 07:28:42 -0700 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w1RESeDG4391212; Tue, 27 Feb 2018 07:28:40 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A2EE77803F; Tue, 27 Feb 2018 07:28:40 -0700 (MST) Received: from localhost.localdomain (unknown [9.60.75.238]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTPS id D7C8D78037; Tue, 27 Feb 2018 07:28:38 -0700 (MST) From: Tony Krowiak To: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: freude@de.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, borntraeger@de.ibm.com, cohuck@redhat.com, kwankhede@nvidia.com, bjsdjshi@linux.vnet.ibm.com, pbonzini@redhat.com, alex.williamson@redhat.com, pmorel@linux.vnet.ibm.com, alifm@linux.vnet.ibm.com, mjrosato@linux.vnet.ibm.com, jjherne@linux.vnet.ibm.com, thuth@redhat.com, pasic@linux.vnet.ibm.com, fiuczy@linux.vnet.ibm.com, buendgen@de.ibm.com, Tony Krowiak Subject: [PATCH v2 06/15] s390: vfio-ap: register matrix device with VFIO mdev framework Date: Tue, 27 Feb 2018 09:28:04 -0500 X-Mailer: git-send-email 1.7.1 In-Reply-To: <1519741693-17440-1-git-send-email-akrowiak@linux.vnet.ibm.com> References: <1519741693-17440-1-git-send-email-akrowiak@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18022714-0020-0000-0000-00000D840AD4 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008601; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000254; SDB=6.00995862; UDB=6.00506230; IPR=6.00775186; MB=3.00019761; MTD=3.00000008; XFM=3.00000015; UTC=2018-02-27 14:28:44 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18022714-0021-0000-0000-0000604AA621 Message-Id: <1519741693-17440-7-git-send-email-akrowiak@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-27_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1802270183 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Registers the matrix device created by the VFIO AP device driver with the VFIO mediated device framework. Registering the matrix device will create the sysfs structures needed to create mediated matrix devices each of which will be used to configure the AP matrix for a guest and connect it to the VFIO AP device driver. Registering the matrix device with the VFIO mediated device framework will create the following sysfs structures: /sys/devices/vfio_ap ... [matrix] ...... [mdev_supported_types] ......... [vfio_ap-passthrough] ............ create To create a mediated device for the AP matrix device, write a UUID to the create file: uuidgen > create A symbolic link to the mediated device's directory will be created in the devices subdirectory named after the generated $uuid: /sys/devices/vfio_ap ... [matrix] ...... [mdev_supported_types] ......... [vfio_ap-passthrough] ............ [devices] ............... [$uuid] Signed-off-by: Tony Krowiak --- MAINTAINERS | 1 + drivers/s390/crypto/Makefile | 2 +- drivers/s390/crypto/vfio_ap_drv.c | 9 +++ drivers/s390/crypto/vfio_ap_ops.c | 105 +++++++++++++++++++++++++++++++++ drivers/s390/crypto/vfio_ap_private.h | 18 ++++++ 5 files changed, 134 insertions(+), 1 deletions(-) create mode 100644 drivers/s390/crypto/vfio_ap_ops.c diff --git a/MAINTAINERS b/MAINTAINERS index a2f232d..fb9e0d4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11886,6 +11886,7 @@ F: arch/s390/include/asm/kvm/kvm-ap.h F: arch/s390/kvm/kvm-ap.c F: drivers/s390/crypto/vfio_ap_drv.c F: drivers/s390/crypto/vfio_ap_private.h +F: drivers/s390/crypto/vfio_ap_ops.c S390 ZFCP DRIVER M: Steffen Maier diff --git a/drivers/s390/crypto/Makefile b/drivers/s390/crypto/Makefile index 48e466e..8d36b05 100644 --- a/drivers/s390/crypto/Makefile +++ b/drivers/s390/crypto/Makefile @@ -17,5 +17,5 @@ pkey-objs := pkey_api.o obj-$(CONFIG_PKEY) += pkey.o # adjunct processor matrix -vfio_ap-objs := vfio_ap_drv.o +vfio_ap-objs := vfio_ap_drv.o vfio_ap_ops.o obj-$(CONFIG_VFIO_AP) += vfio_ap.o diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c index 8bb72af..f45f83b 100644 --- a/drivers/s390/crypto/vfio_ap_drv.c +++ b/drivers/s390/crypto/vfio_ap_drv.c @@ -121,11 +121,20 @@ int __init vfio_ap_init(void) return ret; } + ret = vfio_ap_mdev_register(ap_matrix); + if (ret) { + ap_driver_unregister(&vfio_ap_drv); + vfio_ap_matrix_dev_destroy(ap_matrix); + + return ret; + } + return 0; } void __exit vfio_ap_exit(void) { + vfio_ap_mdev_unregister(ap_matrix); ap_driver_unregister(&vfio_ap_drv); vfio_ap_matrix_dev_destroy(ap_matrix); } diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c new file mode 100644 index 0000000..4292a5e --- /dev/null +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -0,0 +1,105 @@ +/* + * Adjunct processor matrix VFIO device driver callbacks. + * + * Copyright IBM Corp. 2017 + * Author(s): Tony Krowiak + * + */ +#include +#include +#include +#include +#include + +#include "vfio_ap_private.h" + +#define VFOP_AP_MDEV_TYPE_HWVIRT "passthrough" +#define VFIO_AP_MDEV_NAME_HWVIRT "VFIO AP Passthrough Device" + +static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev) +{ + struct ap_matrix *ap_matrix = to_ap_matrix(mdev_parent_dev(mdev)); + + ap_matrix->available_instances--; + + return 0; +} + +static int vfio_ap_mdev_remove(struct mdev_device *mdev) +{ + struct ap_matrix *ap_matrix = to_ap_matrix(mdev_parent_dev(mdev)); + + ap_matrix->available_instances++; + + return 0; +} + +static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf) +{ + return sprintf(buf, "%s\n", VFIO_AP_MDEV_NAME_HWVIRT); +} + +MDEV_TYPE_ATTR_RO(name); + +static ssize_t available_instances_show(struct kobject *kobj, + struct device *dev, char *buf) +{ + struct ap_matrix *ap_matrix; + + ap_matrix = to_ap_matrix(dev); + + return sprintf(buf, "%d\n", ap_matrix->available_instances); +} + +MDEV_TYPE_ATTR_RO(available_instances); + +static ssize_t device_api_show(struct kobject *kobj, struct device *dev, + char *buf) +{ + return sprintf(buf, "%s\n", VFIO_DEVICE_API_AP_STRING); +} + +MDEV_TYPE_ATTR_RO(device_api); + +static struct attribute *vfio_ap_mdev_type_attrs[] = { + &mdev_type_attr_name.attr, + &mdev_type_attr_device_api.attr, + &mdev_type_attr_available_instances.attr, + NULL, +}; + +static struct attribute_group vfio_ap_mdev_hwvirt_type_group = { + .name = VFOP_AP_MDEV_TYPE_HWVIRT, + .attrs = vfio_ap_mdev_type_attrs, +}; + +static struct attribute_group *vfio_ap_mdev_type_groups[] = { + &vfio_ap_mdev_hwvirt_type_group, + NULL, +}; + +static const struct mdev_parent_ops vfio_ap_matrix_ops = { + .owner = THIS_MODULE, + .supported_type_groups = vfio_ap_mdev_type_groups, + .create = vfio_ap_mdev_create, + .remove = vfio_ap_mdev_remove, +}; + +int vfio_ap_mdev_register(struct ap_matrix *ap_matrix) +{ + int ret; + + ret = mdev_register_device(&ap_matrix->device, &vfio_ap_matrix_ops); + if (ret) + return ret; + + ap_matrix->available_instances = AP_MATRIX_MAX_AVAILABLE_INSTANCES; + + return 0; +} + +void vfio_ap_mdev_unregister(struct ap_matrix *ap_matrix) +{ + ap_matrix->available_instances--; + mdev_unregister_device(&ap_matrix->device); +} diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h index 3505947..c264415 100644 --- a/drivers/s390/crypto/vfio_ap_private.h +++ b/drivers/s390/crypto/vfio_ap_private.h @@ -9,12 +9,30 @@ #define _VFIO_AP_PRIVATE_H_ #include +#include +#include "ap_bus.h" #define VFIO_AP_MODULE_NAME "vfio_ap" #define VFIO_AP_DRV_NAME "vfio_ap" +#define VFIO_AP_MATRIX_MODULE_NAME "vfio_ap_matrix" +/** + * There must be one mediated matrix device per guest. If every APQN is assigned + * to a guest, then the maximum number of guests with a unique APQN assigned + * would be 255 adapters x 255 domains = 72351 guests. + */ +#define AP_MATRIX_MAX_AVAILABLE_INSTANCES 72351 struct ap_matrix { struct device device; + int available_instances; }; +static inline struct ap_matrix *to_ap_matrix(struct device *dev) +{ + return container_of(dev, struct ap_matrix, device); +} + +extern int vfio_ap_mdev_register(struct ap_matrix *ap_matrix); +extern void vfio_ap_mdev_unregister(struct ap_matrix *ap_matrix); + #endif /* _VFIO_AP_PRIVATE_H_ */ -- 1.7.1