Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1824753imm; Wed, 16 May 2018 03:44:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo8X8n6MAkz//Vr6LRkFHdrTc+GYL5C7g/8baTzFlgWR8QFjh7XLkEra2TQfud2hKY+1f+p X-Received: by 2002:a17:902:2805:: with SMTP id e5-v6mr383760plb.55.1526467464649; Wed, 16 May 2018 03:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526467464; cv=none; d=google.com; s=arc-20160816; b=Yl1zpuvyAmRKoRG3G07g0vDRaezKeGg5qagskBWvSJlj2MFuTDzdAgbIgJp8hsm/U0 +C3S+h7oR78k7WSitbDFqfAWTw9Zp+KWiAq3MwVlt0lqtOy+PqFykgoHqyY1neX8wmxs xVAyeiiX1s+cmnJ9ZZrx5N6GH4qFGv+BIhZ0oEzRN0qRBya5QTP0Bvgh8n9Egq4YiPch VpQvFqPBFpKyMhgXTEUJmnu5h79ebR0fnZGKohEeegCso2r7bDLCwz/HYWtRhx9Yg6qs YxMjzwBX95DAfIP+F+ZHm9khHXJibHikcUrWb6JHayztlEKSvtB+D3iKWkVKgIkzg4kf MTgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=0wTx6HrxfkD9C1CpaWBUaDtIiVFCbom7h7ZwVRCk6QQ=; b=s90KWyZx6OPrZhA6W56sjT728TDp240j4ob2UYskZnl7n63p6jiusT7DPa5KMVexg4 Dnsxzswjb7gAStMWAVmypN/d6EeftNLptG5VPbfwpARAbBmJbXYKW750NaWPEjAdMk/2 rl/pwk03Mzi1WtvqPN3Kv18ojnY4CQh5JjAADnv9Q4uXw6CoSmMXRQ8OusjehslVh8o0 9KurItEy1T4uplnZUb6cs/5FAal7dy9Rzq3P89gUqkDGS0jDEICjtZ5Xa9qC59vBn5C+ uidVmLsh5uZhaoN5VIZcbE8IEgE8cReBwSirxpNlsZv6M63NVQNaojrL0/Hcyre2n81E Zr1g== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w18-v6si2472136pfl.359.2018.05.16.03.44.09; Wed, 16 May 2018 03:44:24 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752312AbeEPKmt (ORCPT + 99 others); Wed, 16 May 2018 06:42:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44270 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752119AbeEPKmr (ORCPT ); Wed, 16 May 2018 06:42:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36FE2401EF07; Wed, 16 May 2018 10:42:47 +0000 (UTC) Received: from gondolin (ovpn-117-216.ams2.redhat.com [10.36.117.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B8942026E0E; Wed, 16 May 2018 10:42:43 +0000 (UTC) Date: Wed, 16 May 2018 12:42:40 +0200 From: Cornelia Huck To: Tony Krowiak Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, freude@de.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, borntraeger@de.ibm.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 Subject: Re: [PATCH v5 05/13] s390: vfio-ap: register matrix device with VFIO mdev framework Message-ID: <20180516124240.42dcd426.cohuck@redhat.com> In-Reply-To: <1525705912-12815-6-git-send-email-akrowiak@linux.vnet.ibm.com> References: <1525705912-12815-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1525705912-12815-6-git-send-email-akrowiak@linux.vnet.ibm.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 16 May 2018 10:42:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 16 May 2018 10:42:47 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'cohuck@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 7 May 2018 11:11:44 -0400 Tony Krowiak wrote: > 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 | 106 +++++++++++++++++++++++++++++++++ > drivers/s390/crypto/vfio_ap_private.h | 17 +++++ > 5 files changed, 134 insertions(+), 1 deletions(-) > create mode 100644 drivers/s390/crypto/vfio_ap_ops.c > diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c > new file mode 100644 > index 0000000..d7d36fb > --- /dev/null > +++ b/drivers/s390/crypto/vfio_ap_ops.c > @@ -0,0 +1,106 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Adjunct processor matrix VFIO device driver callbacks. > + * > + * Copyright IBM Corp. 2017 Should be '2018' (also in some other files in this series; please double check.) > + * 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--; Shouldn't the code check whether available_instances is actually > 0? > + > + 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); Move this with the declaration? > + > + 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 cf23675..afd8dbc 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 One, or at most one? Or one for every guest using ap devices? > + * 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_ */