Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp765958imm; Tue, 15 May 2018 08:52:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoC5ey4uUTlAFTKMex6OIUa0DHXl04K/deHrqANesUvq5dssjUYAb5zTMmvjJn071imJQc6 X-Received: by 2002:a62:2043:: with SMTP id g64-v6mr15759279pfg.12.1526399572524; Tue, 15 May 2018 08:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526399572; cv=none; d=google.com; s=arc-20160816; b=zFh0IyrK0/+ntT/OmcnZ9mb4fpOyredY4sSYvQdk6Wls2FbdFxFBdu3mwtOQkM17QH 9gImbHhaBpvyCQ+Ba4m06qcjOuDIBDe8rkM2flZxecf5T0uFdqV5QXlZ1g36Xn4JfqAT N65uL8Ao7Epzkzf/7GoKNNrMG1rx1v4l/j60A8wqeP/rAV6ykId1lP+HGy30KDntTMQV zfEMRCb24fXCdh+YFIprgStdJ+MDo+NAc7D1F6jInRujNZH15Ir4wD4vUvyOYP+arCTx /00uve4acqidkdLegjJ0C0zRCf2E6ShylhHpOWN0Gr3taQlIsQpiwIpfubmd9hpGXWzK u6Jw== 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=CqzSFlRq3r8NAMp+11Egk6WonuwydBqWknEmoSdsbus=; b=CIAkDdLIM/r42xb8lpS5KzZe3v0q2QnImAghWZdHehiZEzgRrlXC86vczmg7y25shP VtcoRCjmoQbHqjy9pIbZJKSHFl0Hp+Ld5y/UQNCizfewTzd/Pb5igaf0xQDplMnIk63H MLqFRDXdTASyS1ZnP9HdvyZ4mZgytv/WzXId6D2pyv2SCs1BnMHVr/GX5YtNcpLXW2SY YydmHIdSZ7Cln9RCIXkKAQCmOeF3iCyXAx5KY0UK/bFKQkXcgpVA/Rae0S+NFZs2Oftq 7dTozcJiguFtSFQpyTlPcTiefWgn+dmrBtUobEKZwyNQpPNCdrHf9QbaVsn5BaC8f+t9 YTSA== 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 h10-v6si331855plr.156.2018.05.15.08.52.38; Tue, 15 May 2018 08:52:52 -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 S1754116AbeEOPQz (ORCPT + 99 others); Tue, 15 May 2018 11:16:55 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:56334 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752622AbeEOPQw (ORCPT ); Tue, 15 May 2018 11:16:52 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4FF6pGO012284 for ; Tue, 15 May 2018 11:16:52 -0400 Received: from e14.ny.us.ibm.com (e14.ny.us.ibm.com [129.33.205.204]) by mx0b-001b2d01.pphosted.com with ESMTP id 2j006getwn-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 15 May 2018 11:16:51 -0400 Received: from localhost by e14.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 15 May 2018 11:16:50 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e14.ny.us.ibm.com (146.89.104.201) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 15 May 2018 11:16:48 -0400 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4FFGkpq48431240; Tue, 15 May 2018 15:16:46 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D1C5312405A; Tue, 15 May 2018 12:18:41 -0400 (EDT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4C4AF12405E; Tue, 15 May 2018 12:18:41 -0400 (EDT) Received: from oc8043147753.ibm.com (unknown [9.60.75.218]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 15 May 2018 12:18:41 -0400 (EDT) Subject: Re: [PATCH v5 05/13] s390: vfio-ap: register matrix device with VFIO mdev framework To: pmorel@linux.ibm.com, Halil Pasic , 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 References: <1525705912-12815-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1525705912-12815-6-git-send-email-akrowiak@linux.vnet.ibm.com> <5471b194-d7ca-c9c6-132e-fa9539fe44f0@linux.ibm.com> <4688078d-3e13-5201-582f-52576b25defa@linux.vnet.ibm.com> <1f9117bd-ed14-bde4-fdbd-cb3733c8c633@linux.ibm.com> From: Tony Krowiak Date: Tue, 15 May 2018 11:16:45 -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: <1f9117bd-ed14-bde4-fdbd-cb3733c8c633@linux.ibm.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: 18051515-0052-0000-0000-000002EEE5F2 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009030; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000260; SDB=6.01032698; UDB=6.00527973; IPR=6.00811829; MB=3.00021127; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-15 15:16:50 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051515-0053-0000-0000-00005CB16B0A Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-15_04:,, 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-1805150154 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/15/2018 10:17 AM, Pierre Morel wrote: > On 14/05/2018 21:42, Tony Krowiak wrote: >> On 05/11/2018 01:18 PM, Halil Pasic wrote: >>> >>> >>> On 05/07/2018 05:11 PM, 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. >>>> >>> [..] >>>> 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 >>>> + * 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; >>>> +} >>>> + >>> >>> The above functions seem to be called with the lock of this >>> auto-generated >>> mdev parent device held. That's why we don't have to care about >>> synchronization >>> ourselves, right? >> >> I would assume as much. The comments for the 'struct mdev_parent_ops' in >> include/linux/mdev.h do not mention anything about synchronization, >> nor did I >> see any locking or synchronization in the vfio_ccw implementation >> after which >> I modeled my code, so frankly it is something I did not consider. >> >>> >>> >>> A small comment in the code could be helpful for mdev non-experts. >>> Hell, I would >>> even consider documenting it for all mdev -- took me some time to >>> figure out. >> >> You may want to bring this up with the VFIO mdev maintainers, but I'd >> be happy to >> include a comment in the functions in question if you think it >> important. >> >>> >>> >>> [..] >>> >>> >>>> +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--; >>> >>> What is this for? I don't understand. >> >> To control the number of mediated devices one can create for the >> matrix device. >> Once the max is reached, the mdev framework will not allow creation >> of another >> mediated device until one is removed. This counter keeps track of the >> number >> of instances that can be created. This is documented with the mediated >> framework. You may want to take a look at: >> >> Documentation/vfio-mediated-device.txt >> Documentation/vfio.txt >> Documentation/virtual/kvm/devices/vfio.txt > > This is what you do in create/remove. > But here in unregister I agree with Halil, it does not seem to be usefull. If that is in fact what Halil was asking, then I misinterpreted his question; I thought he was asking what the available_instances was used for. You are correct, this does not belong here although it makes little difference given this is called only when the driver, which creates the matrix device, is unloaded. It is necessary in the register function to initialize its value, but I'll remove it from here. > > >> >>> >>> >>> Regards, >>> Halil >>> >>>> + mdev_unregister_device(&ap_matrix->device); >>>> +} >> >> >