Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4354922ooa; Tue, 14 Aug 2018 05:01:05 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwLhyRJ7DyNpUfKq4E/vfN/qjyKjItInW+TkODwcNxsDCwilaSj38vLRJf9DoyOGyosoqnO X-Received: by 2002:a63:844:: with SMTP id 65-v6mr21357015pgi.406.1534248065010; Tue, 14 Aug 2018 05:01:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534248064; cv=none; d=google.com; s=arc-20160816; b=Nj66Qphc9vumtwPDeCYdUEvYgxkCI/IEs1Spj1tTPZkEg+aIsASnJdpPLZraV5joOW BBdJyNJQkzXo00mhKNSoOqJvDM/ZX9rOKvBywMVzqLp8wW1Gq1tHGAiD+YRioq6A+AMR H49E9G+jp5gbhjR/Ri8U16jh7vjl0vhswXHDH6a151Uw5jyW4+c7gu711KkWFGqIpzRC MzFjeuYsu5CEfMkFeAY69RXsqkA05O6/W6driIGaDJceQ8puJzUX5o3JfbwRJsb+HOzX EDFQwtTHyQBfUcZsSxRttRcpoKkUE1FtNZKLcKYtpkNUH+QycVDB2Zdaf/WkcBJggR6X oStg== 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=/CkARozJjjpRj9TnyVLdyeeur4op26yRNSI9fBPWTMo=; b=vHdHrTElFC14KA9sX673iNnKgH8msrmptz6KUlwsjavc3G2pZYn7QIjus6S2R4xoNA aLmWev6rBhLNxJQd5uKlJkwCk2LxqVzXYtDhpxUOOFGik8rM9nXCUCYjg2nBrvkqxBe3 yDUilW/ZjzLpSQ1EB4xiN8D0zMJ9g8zloYI7Hl387Fl/8uJxUsGF/jzb+wLTOI7cuBZg Tsu4j12/71d9HOdwbsI/eATAvSkzTzqab7itxsuvp11BOB5jEILQA+YtwiD7rtBN2Ph7 51ZzrxeaEB0u0ingRCjDzA9ptCaYJy9el5Ouf/MS/5G1CeDcA6KRwGTnYS2pSnFjojFg iPwQ== 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 11-v6si19041966plb.383.2018.08.14.05.00.48; Tue, 14 Aug 2018 05:01:04 -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 S1732069AbeHNOGV (ORCPT + 99 others); Tue, 14 Aug 2018 10:06:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37038 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730923AbeHNOGU (ORCPT ); Tue, 14 Aug 2018 10:06:20 -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 C63B840203F2; Tue, 14 Aug 2018 11:19:35 +0000 (UTC) Received: from gondolin (ovpn-117-136.ams2.redhat.com [10.36.117.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 444842026D7E; Tue, 14 Aug 2018 11:19:32 +0000 (UTC) Date: Tue, 14 Aug 2018 13:19:29 +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, frankja@linux.ibm.com, Tony Krowiak Subject: Re: [PATCH v9 09/22] s390: vfio-ap: register matrix device with VFIO mdev framework Message-ID: <20180814131929.37d4b530.cohuck@redhat.com> In-Reply-To: <1534196899-16987-10-git-send-email-akrowiak@linux.vnet.ibm.com> References: <1534196899-16987-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1534196899-16987-10-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]); Tue, 14 Aug 2018 11:19:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 14 Aug 2018 11:19:35 +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, 13 Aug 2018 17:48:06 -0400 Tony Krowiak wrote: > From: Tony Krowiak > > 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] > > A symbolic link to the mediated device will also be created > in the vfio_ap matrix's directory: > > /sys/devices/vfio_ap/matrix/[$uuid] > > Signed-off-by: Tony Krowiak > Reviewed-by: Halil Pasic > Tested-by: Michael Mueller > Tested-by: Farhan Ali > Signed-off-by: Christian Borntraeger > --- > MAINTAINERS | 1 + > drivers/s390/crypto/Makefile | 2 +- > drivers/s390/crypto/vfio_ap_drv.c | 23 ++++++ > drivers/s390/crypto/vfio_ap_ops.c | 124 +++++++++++++++++++++++++++++++++ > drivers/s390/crypto/vfio_ap_private.h | 45 ++++++++++++ > include/uapi/linux/vfio.h | 1 + > 6 files changed, 195 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..8018c2d > --- /dev/null > +++ b/drivers/s390/crypto/vfio_ap_ops.c > @@ -0,0 +1,124 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Adjunct processor matrix VFIO device driver callbacks. > + * > + * Copyright IBM Corp. 2018 > + * > + * Author(s): Tony Krowiak > + * Halil Pasic > + * Pierre Morel > + */ > +#include > +#include > +#include > +#include > +#include > + > +#include "vfio_ap_private.h" > + > +#define VFIO_AP_MDEV_TYPE_HWVIRT "passthrough" > +#define VFIO_AP_MDEV_NAME_HWVIRT "VFIO AP Passthrough Device" > + > +static void vfio_ap_matrix_init(struct ap_config_info *info, > + struct ap_matrix *matrix) > +{ > + matrix->apm_max = info->apxa ? info->Na : 63; > + matrix->aqm_max = info->apxa ? info->Nd : 15; > + matrix->adm_max = info->apxa ? info->Nd : 15; > +} > + > +static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev) > +{ > + struct ap_matrix_mdev *matrix_mdev; > + > + matrix_mdev = kzalloc(sizeof(*matrix_mdev), GFP_KERNEL); > + if (!matrix_mdev) > + return -ENOMEM; > + > + matrix_mdev->name = dev_name(mdev_dev(mdev)); > + vfio_ap_matrix_init(&matrix_dev.info, &matrix_mdev->matrix); > + mdev_set_drvdata(mdev, matrix_mdev); > + > + if (atomic_dec_if_positive(&matrix_dev.available_instances) < 0) { > + kfree(matrix_mdev); > + return -EPERM; > + } Maybe move this check to the top of the function? > + > + mutex_lock(&matrix_dev.lock); > + list_add(&matrix_mdev->list, &matrix_dev.mdev_list); > + mutex_unlock(&matrix_dev.lock); > + > + return 0; > +}