Received: by 2002:a4a:3008:0:0:0:0:0 with SMTP id q8-v6csp3444406oof; Mon, 10 Sep 2018 15:00:29 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYgL7U0SCQwiey4bp9Y4wobDYporRlzwap3L1GPe4JYqc1skeZGpt+Q3aORoSDy+ZMSdRcJ X-Received: by 2002:a63:740f:: with SMTP id p15-v6mr25118557pgc.395.1536616829382; Mon, 10 Sep 2018 15:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536616829; cv=none; d=google.com; s=arc-20160816; b=QJrGeqPf3cUoZRbctp8TxrDqu3RO+CtJqMYlip62jGpGc1duR3u6LX3sQDiIt50T9D pDJ/f7qDDt3rBZNvhGs6GqnnwwtPsI7dCc49TFWq0dpR4Ce5QoAJKVKj99UMAD/RG/2Y QvDWLjKmbkj7F1HyN1ja60qUmjSEHJdFU+pq+zjr+PVLO8J48stMLQv2o5wqCfejeha8 BP+Ji0KqnJOSf3+BBSk5PWGNuMeK56AqgvbrByqN/J78xZRVDA9jnEWMQtEO5uimEOPu 00n9BCIjLBgG1lCI/XWiqEFjJieUoHMdKNojxkYV1HIsL6JPYWJ3vlmGPfv0ViCEsGAH zvZA== 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-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject; bh=jlLVEXgj4HzBBsEDty2faeifpgOqKpvqdtA7S6f84/Q=; b=KoaT+je5szzLRGIJIzfP8DFmA/rOMh5/VpRAo/GhXQ0VFatTopxJmh32iLYOZZp78g J93bWbvHHUOtfRnv4CuSm0SRinqbpV0avAYy9vmkQknfkgzbBbk4+3m2jAb6fpcWLj0h 3A2G0p77d12Gytvrzxzgqh8PzdG+VSSZFB2JYD8oVCYnLhBFoMa4pkiMAYlwhvc//6kw gWEjnyz4c6kdWERNN8igKv1dXtDqRPwODGYvkcU/rNNfXBTsPuobxZTV6hXf2ifLWkFY a8DFROmdVWk3TWoNtI2EX3902WH09Fh6RxCd8fhsIIaSJ6wxqeaIYhSRRTCS2oI6yPZq Ni4w== 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 15-v6si19396280pld.157.2018.09.10.15.00.13; Mon, 10 Sep 2018 15:00: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 S1727417AbeIKC4A (ORCPT + 99 others); Mon, 10 Sep 2018 22:56:00 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:56806 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726191AbeIKCz7 (ORCPT ); Mon, 10 Sep 2018 22:55:59 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8ALrsSO064946 for ; Mon, 10 Sep 2018 17:59:52 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2mdyqutq20-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 10 Sep 2018 17:59:52 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 10 Sep 2018 22:59:50 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 10 Sep 2018 22:59:47 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w8ALwVR256557620 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 10 Sep 2018 21:58:31 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA1BB5204F; Tue, 11 Sep 2018 00:58:20 +0100 (BST) Received: from oc0155643701.ibm.com (unknown [9.145.148.229]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id AE17D52050; Tue, 11 Sep 2018 00:58:19 +0100 (BST) Subject: Re: [PATCH v9 09/22] s390: vfio-ap: register matrix device with VFIO mdev framework To: Tony Krowiak , pmorel@linux.ibm.com, Tony Krowiak , 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, 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> From: Halil Pasic Date: Mon, 10 Sep 2018 23:58:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 18091021-0016-0000-0000-000002035FE9 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18091021-0017-0000-0000-0000325A1EB4 Message-Id: <8f40992c-5dbe-92a2-2b9d-d29bd3647567@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-10_10:,, 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-1809100216 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/10/2018 03:38 PM, Tony Krowiak wrote: > On 09/06/2018 04:49 AM, Pierre Morel wrote: >> On 13/08/2018 23:48, 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/MAINTAINERS b/MAINTAINERS >>> index e84c559..f60dd56 100644 >>> --- a/MAINTAINERS >>> +++ b/MAINTAINERS >>> @@ -12427,6 +12427,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 5069580..fa04c5a 100644 >>> --- a/drivers/s390/crypto/vfio_ap_drv.c >>> +++ b/drivers/s390/crypto/vfio_ap_drv.c >>> @@ -11,6 +11,7 @@ >>>   #include >>>   #include >>>   #include >>> +#include >>>   #include "vfio_ap_private.h" >>> >>>   #define VFIO_AP_ROOT_NAME "vfio_ap" >>> @@ -65,6 +66,19 @@ static int vfio_ap_matrix_dev_init(void) >>>           return ret; >>>       } >>> >>> +    mutex_init(&matrix_dev.lock); >>> +    INIT_LIST_HEAD(&matrix_dev.mdev_list); >>> + >>> +    /* Test if PQAP(QCI) instruction is available */ >>> +    if (test_facility(12)) { >>> +        ret = ap_qci(&matrix_dev.info); >>> +        if (ret) { >>> +            root_device_unregister(root_device); >>> +            return ret; >>> +        } >>> +    } >>> + >>> +    atomic_set(&matrix_dev.available_instances, MAX_ZDEV_ENTRIES_EXT); >>>       matrix_dev.device.type = &vfio_ap_dev_type; >>>       dev_set_name(&matrix_dev.device, "%s", VFIO_AP_DEV_NAME); >>>       matrix_dev.device.type = &vfio_ap_dev_type; >>> @@ -105,11 +119,20 @@ int __init vfio_ap_init(void) >>>           return ret; >>>       } >>> >>> +    ret = vfio_ap_mdev_register(); >>> +    if (ret) { >>> +        ap_driver_unregister(&vfio_ap_drv); >>> +        vfio_ap_matrix_dev_destroy(); >>> + >>> +        return ret; >>> +    } >>> + >>>       return 0; >>>   } >>> >>>   void __exit vfio_ap_exit(void) >>>   { >>> +    vfio_ap_mdev_unregister(); >>>       ap_driver_unregister(&vfio_ap_drv); >>>       vfio_ap_matrix_dev_destroy(); >>>   } >>> 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; >>> +    } >>> + >>> +    mutex_lock(&matrix_dev.lock); >>> +    list_add(&matrix_mdev->list, &matrix_dev.mdev_list); >>> +    mutex_unlock(&matrix_dev.lock); >>> + >> Hi Tony, >> >> You need to initialize the matrix_mdev->list before >> using it. > > Why? Initialization only sets its prev and next pointers to point to itself. The > list_add immediately sets those pointers to insert it into the matrix_dev.mdev_list, > so what would be the purose? > I think the source of the confusion is that matrix_mdev->list a new element to be added to the matrix_dev.mdev_list and not a sentinel node of some list (which in a sense stands for the list as a whole). Regards, Halil