Received: by 10.223.164.221 with SMTP id h29csp1051169wrb; Fri, 13 Oct 2017 10:46:07 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBlkbnrP/kxSmCtoiGOOMEWtiQFuQni8AVn69eMweS2C06B5NwJQxkM6NBtuID3WweI2Rnv X-Received: by 10.101.72.65 with SMTP id i1mr1919060pgs.436.1507916767798; Fri, 13 Oct 2017 10:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507916767; cv=none; d=google.com; s=arc-20160816; b=QMartR5TiaY7aqbFMiXigtIdRg4EQCAkAErKsLB3rEPmtojh1bq5GUev6fEd8WAVVv IWdE0BR8wtALlVS4Q0yFpvDYauJqHZB15lg1Zu9PLfiV9UZTD4d1oJqMm3RW5lCdFl3l /n2nuWm9PKC7W822zHkSsetd6BWcIVh+tPFH8FzsViX6U3MqfMYWUeU3APWKZx+kntt6 6pZ8ZI+SI111CchjS8UxVHP4B2VmwoaFxkKImShkDpS9ps35YQvO1vVaBRJIrLYbRvQZ /uZ8rWPGtnKzc+ebDsH0vfWGsoQ1fQFoJN93ut4RStq2t8SxHTcc7WveeJmx/cO9Ds1B r76w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=ukiNGTGOsfy9bSCxVFtnmn2xwdOE3AM0qSMyHK/WmEY=; b=rTU32gr1s8WAV3wHogqHdAKsACGCMhl0CmOXm2f4UhRntf/08TBdgbpvUFlCR9CP/I SeRxtzCoC+8ER3gTVhnQrJaSjcBGcoMUHdiUqqiND/HPEWLocDGZFKLGSK56lzTM3Hqt tq/Ui8mh/RtOInx7VpH2iZ79p8xMP48FKT7bZlhMm1Mz506a1H2+t6pmq9ptgjcxbomL 1SVC+/DnDbF71n+00xX8WEPlFF09HkSb6GT9xOjIa4ZZEeGXpUzrTsRA3Ll+Mw7e83xw 1nZjE7QuWQ6907iOqpfB+2FiQYg7D85k8gtjJ/twXpO2blYd/QwOGZ/oNwIKGr1QbGto DfFw== 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 e71si824268pgc.143.2017.10.13.10.45.53; Fri, 13 Oct 2017 10:46:07 -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 S1753362AbdJMRpS (ORCPT + 99 others); Fri, 13 Oct 2017 13:45:18 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50320 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752920AbdJMRkB (ORCPT ); Fri, 13 Oct 2017 13:40:01 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9DHct6D120866 for ; Fri, 13 Oct 2017 13:40:01 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dk0j6udrf-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 13 Oct 2017 13:40:00 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 13 Oct 2017 13:39:59 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 13 Oct 2017 13:39:56 -0400 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9DHdt9h41549842; Fri, 13 Oct 2017 17:39:55 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 53E2C28046; Fri, 13 Oct 2017 13:39:48 -0400 (EDT) Received: from localhost.localdomain (unknown [9.85.201.79]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTPS id 6563D2803F; Fri, 13 Oct 2017 13:39:47 -0400 (EDT) From: Tony Krowiak To: 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, qemu-s390x@nongnu.org, jjherne@linux.vnet.ibm.com, thuth@redhat.com, pasic@linux.vnet.ibm.com, Tony Krowiak Subject: [RFC 05/19] s390/zcrypt: base implementation of AP matrix device driver Date: Fri, 13 Oct 2017 13:38:50 -0400 X-Mailer: git-send-email 1.7.1 In-Reply-To: <1507916344-3896-1-git-send-email-akrowiak@linux.vnet.ibm.com> References: <1507916344-3896-1-git-send-email-akrowiak@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17101317-0040-0000-0000-000003B293A9 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007892; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000236; SDB=6.00930643; UDB=6.00468501; IPR=6.00710909; BA=6.00005636; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017529; XFM=3.00000015; UTC=2017-10-13 17:39:58 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17101317-0041-0000-0000-000007A7970E Message-Id: <1507916344-3896-6-git-send-email-akrowiak@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-10-13_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710130244 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduces a new AP matrix device driver. This device driver will ultimately perform the following functions: * Register with the AP bus to let it know that the matrix driver can control AP queue devices. This will allow an administrator to unbind an AP queue device from its device driver and bind it to the matrix device driver. This is how AP queue devices will be reserved for use by guest machines. * Register the matrix device created by the AP matrix bus with the VFIO mediated device framework. This will create the sysfs entries needed to create mediated matrix devices. Each mediated matrix device can be configured with a matrix of adapters, usage domains and control domains that can be accessed by a guest machine. * Process requests via ioctl calls defined for the mediated matrix device. The guest can access the ioctl calls via the mediated device's file descriptor to: * Grant access to the adapters, usage domains and control domains configured for the mediated matrix device. This device driver is built on the VFIO mediated device framework. The VFIO mediated device framework allows a mediated device to be dedicated exclusively to a single guest VM. Signed-off-by: Tony Krowiak --- MAINTAINERS | 2 + arch/s390/Kconfig | 13 +++ arch/s390/configs/default_defconfig | 1 + arch/s390/configs/gcov_defconfig | 1 + arch/s390/configs/performance_defconfig | 1 + arch/s390/defconfig | 1 + drivers/s390/crypto/Makefile | 6 +- drivers/s390/crypto/ap_matrix_bus.c | 8 ++ drivers/s390/crypto/ap_matrix_bus.h | 2 +- drivers/s390/crypto/vfio_ap_matrix_drv.c | 102 ++++++++++++++++++++++++++ drivers/s390/crypto/vfio_ap_matrix_private.h | 47 ++++++++++++ 11 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 drivers/s390/crypto/vfio_ap_matrix_drv.c create mode 100644 drivers/s390/crypto/vfio_ap_matrix_private.h diff --git a/MAINTAINERS b/MAINTAINERS index cbd6f7c..115965e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11718,6 +11718,8 @@ W: http://www.ibm.com/developerworks/linux/linux390/ S: Supported F: drivers/s390/crypto/ap_matrix_bus.h F: drivers/s390/crypto/ap_matrix_bus.c +F: drivers/s390/crypto/vfio_ap_matrix_drv.c +F: drivers/s390/crypto/vfio_ap_matrix_private.h S390 ZFCP DRIVER M: Steffen Maier diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index 48af970..411c19a 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -722,6 +722,19 @@ config VFIO_CCW To compile this driver as a module, choose M here: the module will be called vfio_ccw. +config VFIO_AP_MATRIX + def_tristate m + prompt "Support for Adjunct Processor Matrix device interface" + depends on ZCRYPT + select VFIO + select MDEV + select VFIO_MDEV + select VFIO_MDEV_DEVICE + select IOMMU_API + help + driver grants access to Adjunct Processor (AP) devices + via the VFIO mediated device interface. + endmenu menu "Dump support" diff --git a/arch/s390/configs/default_defconfig b/arch/s390/configs/default_defconfig index 2820722..d913042 100644 --- a/arch/s390/configs/default_defconfig +++ b/arch/s390/configs/default_defconfig @@ -725,3 +725,4 @@ CONFIG_APPLDATA_BASE=y CONFIG_KVM=m CONFIG_KVM_S390_UCONTROL=y CONFIG_VHOST_NET=m +CONFIG_VFIO_AP_MATRIX=m diff --git a/arch/s390/configs/gcov_defconfig b/arch/s390/configs/gcov_defconfig index 3c6b781..5f08278 100644 --- a/arch/s390/configs/gcov_defconfig +++ b/arch/s390/configs/gcov_defconfig @@ -666,3 +666,4 @@ CONFIG_APPLDATA_BASE=y CONFIG_KVM=m CONFIG_KVM_S390_UCONTROL=y CONFIG_VHOST_NET=m +CONFIG_VFIO_AP_MATRIX=m diff --git a/arch/s390/configs/performance_defconfig b/arch/s390/configs/performance_defconfig index 653d72b..4b77519 100644 --- a/arch/s390/configs/performance_defconfig +++ b/arch/s390/configs/performance_defconfig @@ -664,3 +664,4 @@ CONFIG_APPLDATA_BASE=y CONFIG_KVM=m CONFIG_KVM_S390_UCONTROL=y CONFIG_VHOST_NET=m +CONFIG_VFIO_AP_MATRIX=m diff --git a/arch/s390/defconfig b/arch/s390/defconfig index 20244a3..aa46cb5 100644 --- a/arch/s390/defconfig +++ b/arch/s390/defconfig @@ -242,3 +242,4 @@ CONFIG_CRC7=m # CONFIG_XZ_DEC_ARMTHUMB is not set # CONFIG_XZ_DEC_SPARC is not set CONFIG_CMM=m +CONFIG_VFIO_AP_MATRIX=m diff --git a/drivers/s390/crypto/Makefile b/drivers/s390/crypto/Makefile index 87646ca..1983afa 100644 --- a/drivers/s390/crypto/Makefile +++ b/drivers/s390/crypto/Makefile @@ -13,4 +13,8 @@ obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o # pkey kernel module pkey-objs := pkey_api.o -obj-$(CONFIG_PKEY) += pkey.o \ No newline at end of file +obj-$(CONFIG_PKEY) += pkey.o + +# adjunct processor matrix +vfio_ap_matrix-objs := vfio_ap_matrix_drv.o +obj-$(CONFIG_VFIO_AP_MATRIX) += vfio_ap_matrix.o diff --git a/drivers/s390/crypto/ap_matrix_bus.c b/drivers/s390/crypto/ap_matrix_bus.c index 4eb1e3c..66bfa54 100644 --- a/drivers/s390/crypto/ap_matrix_bus.c +++ b/drivers/s390/crypto/ap_matrix_bus.c @@ -75,10 +75,18 @@ static int ap_matrix_dev_create(void) return 0; } +struct ap_matrix *ap_matrix_get_device(void) +{ + return matrix; +} +EXPORT_SYMBOL(ap_matrix_get_device); + int __init ap_matrix_init(void) { int ret; + matrix = NULL; + ap_matrix_root_device = root_device_register(AP_MATRIX_BUS_NAME); ret = PTR_RET(ap_matrix_root_device); if (ret) diff --git a/drivers/s390/crypto/ap_matrix_bus.h b/drivers/s390/crypto/ap_matrix_bus.h index 225db4f..c2aff23 100644 --- a/drivers/s390/crypto/ap_matrix_bus.h +++ b/drivers/s390/crypto/ap_matrix_bus.h @@ -16,6 +16,6 @@ struct ap_matrix { struct device device; }; -int ap_matrix_init(void); +struct ap_matrix *ap_matrix_get_device(void); #endif /* _AP_MATRIX_BUS_H_ */ diff --git a/drivers/s390/crypto/vfio_ap_matrix_drv.c b/drivers/s390/crypto/vfio_ap_matrix_drv.c new file mode 100644 index 0000000..760ed56 --- /dev/null +++ b/drivers/s390/crypto/vfio_ap_matrix_drv.c @@ -0,0 +1,102 @@ +/* + * VFIO based AP Matrix device driver + * + * Copyright IBM Corp. 2017 + * + * Author(s): Tony Krowiak + */ + +#include +#include +#include + +#include "ap_bus.h" +#include "ap_matrix_bus.h" +#include "vfio_ap_matrix_private.h" + +#define VFIO_AP_MATRIX_DRV_NAME "vfio_ap_queue" + +MODULE_AUTHOR("IBM Corporation"); +MODULE_DESCRIPTION("AP Matrix device driver, Copyright IBM Corp. 2017"); +MODULE_LICENSE("GPL v2"); + +static struct ap_device_id ap_queue_ids[] = { + { .dev_type = AP_DEVICE_TYPE_CEX4, + .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE }, + { .dev_type = AP_DEVICE_TYPE_CEX5, + .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE }, + { .dev_type = AP_DEVICE_TYPE_CEX6, + .match_flags = AP_DEVICE_ID_MATCH_QUEUE_TYPE }, + { /* end of list */ }, +}; + +MODULE_DEVICE_TABLE(ap_matrix, ap_queue_ids); + +static struct ap_matrix_driver { + struct ap_driver ap_drv; + struct ap_matrix *ap_matrix; +} vfio_ap_matrix_drv; + +static int ap_matrix_queue_dev_probe(struct ap_device *apdev) +{ + struct vfio_ap_queue *vapq; + struct ap_queue *apq = to_ap_queue(&apdev->device); + struct ap_matrix *ap_matrix = vfio_ap_matrix_drv.ap_matrix; + + vapq = kzalloc(sizeof(*vapq), GFP_KERNEL); + if (!vapq) + return -ENOMEM; + + INIT_LIST_HEAD(&vapq->list); + vapq->queue = apq; + spin_lock_bh(&ap_matrix->qlock); + list_add_tail(&vapq->list, &ap_matrix->queues); + spin_unlock_bh(&ap_matrix->qlock); + + return 0; +} + +static void ap_matrix_queue_dev_remove(struct ap_device *apdev) +{ + struct vfio_ap_queue *vapq; + struct ap_queue *apq = to_ap_queue(&apdev->device); + struct ap_matrix *ap_matrix = vfio_ap_matrix_drv.ap_matrix; + + vapq = find_vapq(ap_matrix, apq->qid); + + if (vapq) { + spin_lock_bh(&ap_matrix->qlock); + list_del_init(&vapq->list); + spin_unlock_bh(&ap_matrix->qlock); + kfree(vapq); + } +} + +int __init ap_matrix_init(void) +{ + + int ret; + + vfio_ap_matrix_drv.ap_matrix = ap_matrix_get_device(); + if (!vfio_ap_matrix_drv.ap_matrix) + return -ENODEV; + + vfio_ap_matrix_drv.ap_drv.probe = ap_matrix_queue_dev_probe; + vfio_ap_matrix_drv.ap_drv.remove = ap_matrix_queue_dev_remove; + vfio_ap_matrix_drv.ap_drv.ids = ap_queue_ids; + + ret = ap_driver_register(&vfio_ap_matrix_drv.ap_drv, + THIS_MODULE, VFIO_AP_MATRIX_DRV_NAME); + if (ret) + return ret; + + return ret; +} + +void __exit ap_matrix_exit(void) +{ + ap_driver_unregister(&vfio_ap_matrix_drv.ap_drv); +} + +module_init(ap_matrix_init); +module_exit(ap_matrix_exit); diff --git a/drivers/s390/crypto/vfio_ap_matrix_private.h b/drivers/s390/crypto/vfio_ap_matrix_private.h new file mode 100644 index 0000000..11c5e02 --- /dev/null +++ b/drivers/s390/crypto/vfio_ap_matrix_private.h @@ -0,0 +1,47 @@ +/* + * Private data and functions for adjunct processor VFIO matrix driver. + * + * Copyright IBM Corp. 2016 + * Author(s): Tony Krowiak + */ + +#ifndef _VFIO_AP_PRIVATE_H_ +#define _VFIO_AP_PRIVATE_H_ + +#include + +#include "ap_bus.h" +#include "ap_matrix_bus.h" + +#define VFIO_AP_MATRIX_MODULE_NAME "vfio_ap_matrix" + +struct vfio_ap_queue { + struct ap_queue *queue; + struct list_head list; +}; + +static inline struct vfio_ap_queue *to_vapq(struct ap_device *ap_dev) +{ + struct ap_queue *ap_queue = to_ap_queue(&ap_dev->device); + struct vfio_ap_queue *vapq; + + vapq = container_of(&ap_queue, struct vfio_ap_queue, queue); + + return vapq; +} + +static inline struct vfio_ap_queue *find_vapq(struct ap_matrix *ap_matrix, + ap_qid_t qid) +{ + struct vfio_ap_queue *vapq; + + if (!list_empty(&ap_matrix->queues)) { + list_for_each_entry(vapq, &ap_matrix->queues, list) + if (vapq->queue->qid == qid) + return vapq; + } + + return NULL; +} + +#endif /* _VFIO_AP_PRIVATE_H_ */ -- 1.7.1 From 1584605859606801236@xxx Mon Nov 20 17:11:49 +0000 2017 X-GM-THRID: 1584605859606801236 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread