Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1013282imm; Wed, 15 Aug 2018 09:53:29 -0700 (PDT) X-Google-Smtp-Source: AA+uWPx4DZItPEgv8VrQMNPL06B4wIJd05PrsM228skEL0fz2STT8B0qbUMR5rfrhOb0EIKdz0hF X-Received: by 2002:a63:2906:: with SMTP id p6-v6mr26533616pgp.204.1534352009804; Wed, 15 Aug 2018 09:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534352009; cv=none; d=google.com; s=arc-20160816; b=VzUhxwrSnkw+Hdhact19GtaN61yI+vAP1RkRAMKBo56nkWHhvLlTszidrhJxHQgvSg ivl1guUUFy3tiGkMHnNM63BpJh03sbth6olZYPtXV+Pwuol0bFq1ysCOnzokfNp3He+I 3chxR55/1iYPkLQg3NKNvLv81AGyh4uLfkQPwyEht48dPo0zm9SzQxs+Vlm6ZGS2Cw3b onbOL+s9fe5r67pUAE4hPqplKvvEceVAuq3hakatH3SqhiAmezTOnDvr9IsgSzrz/Eh9 Ch0ngh6CAIgs5gIhKR/CZrLaFfTuJUeGU55pYBpD1h7fa2OiPY4EFBacrEGi+NpRkTWA /AVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :from:references:cc:to:subject:arc-authentication-results; bh=wr6fyBYdc5XMccR4/jXsgdI6uTwJajjPO3coaBLek3Q=; b=Th4kI+InRIAlhCdeYdFIg5216+GAjKtX7C+UpW8v2GkAOOZqIFWyWQVAHl+FJLk3Qk eAEMxyQxPyp8LiiyzjssrQQYsRLz/Z2Of1r1S9fAp7lWixg0jVYoTlgRId/ooo2Ub6vq RUilWW5nzfYgrq17bP4kQjBWYGJ3zDHH2tOz1U8fq2INjlFrdbYeQ56Q19BmKDXOIf2A r9gNN4q5sv23xuHDuN6dwJ1U7dnCS9cyF+AS3wQr+bC3jadLAQYS96T+tHxKhjKIGG+j a0hj6AkzqMgTe93bYvJ1RUJp2DTa5Gwbx2TiaQOHf+v117DvTbP33tGgXbYlifX2H6UC Hatg== 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 q30-v6si22963623pgk.253.2018.08.15.09.53.14; Wed, 15 Aug 2018 09:53:29 -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 S1730124AbeHOTo6 (ORCPT + 99 others); Wed, 15 Aug 2018 15:44:58 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38212 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729527AbeHOTo6 (ORCPT ); Wed, 15 Aug 2018 15:44:58 -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 w7FGd4Q1066814 for ; Wed, 15 Aug 2018 12:52:02 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2kvqf11fj9-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 Aug 2018 12:52:01 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 15 Aug 2018 10:52:01 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 15 Aug 2018 10:51:58 -0600 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w7FGptSp524762 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 15 Aug 2018 09:51:55 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 117B4136053; Wed, 15 Aug 2018 10:51:55 -0600 (MDT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 76DCF13604F; Wed, 15 Aug 2018 10:51:51 -0600 (MDT) Received: from oc8043147753.ibm.com (unknown [9.85.175.5]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 15 Aug 2018 10:51:51 -0600 (MDT) Subject: Re: [PATCH v9 09/22] s390: vfio-ap: register matrix device with VFIO mdev framework To: Cornelia Huck , 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 References: <1534196899-16987-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1534196899-16987-10-git-send-email-akrowiak@linux.vnet.ibm.com> <20180814131929.37d4b530.cohuck@redhat.com> From: Tony Krowiak Date: Wed, 15 Aug 2018 12:51:50 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20180814131929.37d4b530.cohuck@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 18081516-0004-0000-0000-00001476FBA3 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009549; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01073944; UDB=6.00553399; IPR=6.00853903; MB=3.00022736; MTD=3.00000008; XFM=3.00000015; UTC=2018-08-15 16:52:00 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18081516-0005-0000-0000-00008877FC80 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-08-15_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808150177 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/14/2018 07:19 AM, Cornelia Huck wrote: > 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? I am going to remove this check. Since we have added a mutex to lock the matrix_dev, I see no need for the available_instances to be an atomic_t type because we can update it while holding the matrix_dev lock when the other updates are made to the matrix_dev. > >> + >> + mutex_lock(&matrix_dev.lock); >> + list_add(&matrix_mdev->list, &matrix_dev.mdev_list); >> + mutex_unlock(&matrix_dev.lock); >> + >> + return 0; >> +}