From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753337AbdJMRkR (ORCPT ); Fri, 13 Oct 2017 13:40:17 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:34910 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753249AbdJMRkK (ORCPT ); Fri, 13 Oct 2017 13:40:10 -0400 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 15/19] s390/zcrypt: introduce ioctl access to VFIO AP Matrix driver Date: Fri, 13 Oct 2017 13:39:00 -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-0008-0000-0000-000002908DA0 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.00930642; 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:40:08 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17101317-0009-0000-0000-000036FF623E Message-Id: <1507916344-3896-16-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 List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduces ioctl access to the VFIO AP Matrix device driver by implementing the VFIO_DEVICE_GET_INFO ioctl. This ioctl provides the VFIO AP Matrix device driver information to the guest machine. Signed-off-by: Tony Krowiak --- drivers/s390/crypto/vfio_ap_matrix_ops.c | 43 ++++++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 1 + 2 files changed, 44 insertions(+), 0 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_matrix_ops.c b/drivers/s390/crypto/vfio_ap_matrix_ops.c index fd36074..74ea8db 100644 --- a/drivers/s390/crypto/vfio_ap_matrix_ops.c +++ b/drivers/s390/crypto/vfio_ap_matrix_ops.c @@ -137,6 +137,48 @@ static void ap_matrix_mdev_release(struct mdev_device *mdev) &matrix_mdev->group_notifier); } +static int ap_matrix_mdev_get_device_info(unsigned long arg) +{ + unsigned long minsz; + struct vfio_device_info info; + + minsz = offsetofend(struct vfio_device_info, num_irqs); + + if (copy_from_user(&info, (void __user *)arg, minsz)) + return -EFAULT; + + if (info.argsz < minsz) { + pr_err("%s: Argument size %u less than min size %li", + VFIO_AP_MATRIX_MODULE_NAME, info.argsz, minsz); + return -EINVAL; + } + + info.flags = VFIO_DEVICE_FLAGS_AP_MATRIX; + info.num_regions = 0; + info.num_irqs = 0; + + return copy_to_user((void __user *)arg, &info, minsz); +} + +static ssize_t ap_matrix_mdev_ioctl(struct mdev_device *mdev, + unsigned int cmd, unsigned long arg) +{ + int ret; + + switch (cmd) { + case VFIO_DEVICE_GET_INFO: + ret = ap_matrix_mdev_get_device_info(arg); + break; + default: + pr_err("%s: ioctl command %d is not a supported command", + VFIO_AP_MATRIX_MODULE_NAME, cmd); + ret = -EOPNOTSUPP; + break; + } + + return ret; +} + static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf) { return sprintf(buf, "%s\n", AP_MATRIX_MDEV_NAME_HWVIRT); @@ -651,6 +693,7 @@ static DEVICE_ATTR(control_domains, 0644, ap_matrix_control_domains_show, .remove = ap_matrix_mdev_remove, .open = ap_matrix_mdev_open, .release = ap_matrix_mdev_release, + .ioctl = ap_matrix_mdev_ioctl, }; diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 743456f..08f1ab4 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -199,6 +199,7 @@ struct vfio_device_info { #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2) /* vfio-platform device */ #define VFIO_DEVICE_FLAGS_AMBA (1 << 3) /* vfio-amba device */ #define VFIO_DEVICE_FLAGS_CCW (1 << 4) /* vfio-ccw device */ +#define VFIO_DEVICE_FLAGS_AP_MATRIX (1 << 5) /* vfio-ap-matrix device */ __u32 num_regions; /* Max region index + 1 */ __u32 num_irqs; /* Max IRQ index + 1 */ }; -- 1.7.1