Received: by 10.192.165.156 with SMTP id m28csp2993786imm; Sun, 15 Apr 2018 14:27:15 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+IDwV/WDPiYSjW1PZkE0QMpIoXziQO8twoU0giIp+xci4/Z+tTJ8wtDtmfyi5BJd8dwvQc X-Received: by 10.101.76.77 with SMTP id l13mr10747459pgr.192.1523827635760; Sun, 15 Apr 2018 14:27:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523827635; cv=none; d=google.com; s=arc-20160816; b=u6w440RfaYTwg+ZooiUxH5kTMZclswMELWxAlnlnlm/nvhePUR3dd29a8sZsBtqyG7 V+nFUSJS/817EcQkd4J+/serNFhuy6nvd71rxEEzex2q76XL/F+KEs7+gdTWHhDJn9OZ wkz0/MrZEN5eyuX5IgYb3Y3gfTKTax2RB7cGY8jr3jmhcIhWlqrFQc2eVufYxVzUj0+K MOLu0IqzJ1jnluhv3hIMJVGdCmqMn+5EAguRrXNw70rc7Ei++NDq2Xg/ZLgFnbiA21Tl 5UNY1Q7NzpPdyuCNvWDzecP+iG9xjBwof4TzNz9J3h6BoYXHHxLBmssRuNMwXPYll5xY xvVg== 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=7eFA0BV2eHSQTyeYODrBr+1LVdqFfQFVTcFfwoIUjQ8=; b=YpAm/Sx1j4auExVZb55vGI1r7uQ1jEyUo/QBxJ9vQTnEXKJXMYGX83Ow260tvz3HLa JcKn4QerCksMghrvZetjWuQqTXUpe/0d7/YnpZKP+K+hEDfKqXp7GHdOd8tqGCIL7nvo ZeRiVxDH5Lnmsfp591FE9zZ4FeKZ1fipE7HIooSuQUAn/C5eGrwKlkBotn1EEpsWsbYl CT4ePU87zcy6toDtIMXWA4E3JQhPNNv8qAZ9ib/HvvCelTnA2JoWJai9g8CdwS3yXiYm fqfD0C4QFR6UCF/lRkCR7tXLNaUwBSqVYopnzsrsrmpP0gnQBtn1JjBzM61jCKoFb37y jmog== 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 a21si8985132pfi.349.2018.04.15.14.26.28; Sun, 15 Apr 2018 14:27:15 -0700 (PDT) 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 S1753178AbeDOVWz (ORCPT + 99 others); Sun, 15 Apr 2018 17:22:55 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40316 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753133AbeDOVWu (ORCPT ); Sun, 15 Apr 2018 17:22:50 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3FLJP7Z094461 for ; Sun, 15 Apr 2018 17:22:50 -0400 Received: from e14.ny.us.ibm.com (e14.ny.us.ibm.com [129.33.205.204]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hc379a6m7-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Sun, 15 Apr 2018 17:22:49 -0400 Received: from localhost by e14.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 15 Apr 2018 17:22:49 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e14.ny.us.ibm.com (146.89.104.201) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 15 Apr 2018 17:22:45 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3FLMh6B56164438; Sun, 15 Apr 2018 21:22:43 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E799AAE03B; Sun, 15 Apr 2018 17:24:29 -0400 (EDT) Received: from localhost.localdomain (unknown [9.85.139.141]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTPS id DA527AE034; Sun, 15 Apr 2018 17:24:28 -0400 (EDT) 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, berrange@redhat.com, fiuczy@linux.vnet.ibm.com, buendgen@de.ibm.com, akrowiak@linux.vnet.ibm.com Subject: [PATCH v4 07/15] s390: vfio-ap: register matrix device with VFIO mdev framework Date: Sun, 15 Apr 2018 17:22:17 -0400 X-Mailer: git-send-email 1.7.1 In-Reply-To: <1523827345-11600-1-git-send-email-akrowiak@linux.vnet.ibm.com> References: <1523827345-11600-1-git-send-email-akrowiak@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041521-0052-0000-0000-000002DB5A1E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008862; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000257; SDB=6.01018429; UDB=6.00519481; IPR=6.00797666; MB=3.00020592; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-15 21:22:47 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041521-0053-0000-0000-00005C578068 Message-Id: <1523827345-11600-8-git-send-email-akrowiak@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-15_10:,, 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-1804150214 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 | 17 +++++ 5 files changed, 133 insertions(+), 1 deletions(-) create mode 100644 drivers/s390/crypto/vfio_ap_ops.c diff --git a/MAINTAINERS b/MAINTAINERS index 1124c4c..6eb8d8a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12226,6 +12226,7 @@ W: http://www.ibm.com/developerworks/linux/linux390/ S: Supported 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 014d70f..cc7fbd7 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..d41b0b8 --- /dev/null +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Adjunct processor matrix VFIO device driver callbacks. + * + * Copyright IBM Corp. 2018 + * 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 15ed458..c47aeec 100644 --- a/drivers/s390/crypto/vfio_ap_private.h +++ b/drivers/s390/crypto/vfio_ap_private.h @@ -10,14 +10,31 @@ #define _VFIO_AP_PRIVATE_H_ #include +#include +#include #include "ap_bus.h" #define VFIO_AP_MODULE_NAME "vfio_ap" #define VFIO_AP_DRV_NAME "vfio_ap" +/** + * 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