Received: by 10.223.164.221 with SMTP id h29csp1048787wrb; Fri, 13 Oct 2017 10:43:13 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDSVWkgTgxp04yb4/1ajmMXvFBZln9xfSMM3Z+rtiv60fCluLAJqyNzfwTPTrNn1l4DwdY4 X-Received: by 10.101.88.70 with SMTP id s6mr1948854pgr.216.1507916593113; Fri, 13 Oct 2017 10:43:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507916593; cv=none; d=google.com; s=arc-20160816; b=ZrgNjlu9EUM3O+5N1pTHTNEDAfXmS8FNYhL2FU6UVy5YurEazHL+VvJFQuGDx5sIvG br4R/8SAxix7pQaZfyinJX0Nd+v++uJ5BY0d6JfUMc39R9DVREcGPh6FcBt3zmDt9dXH Vo3dEJFRULRpTlWfyj2Ctt159QVamIT7+eWQcafmfOMoITtVcvuQ0QfRtxdT9xEfAr8l T7mHz+MfzfUsIpy7ueCcZlO9irQ5PA3gACLgnyhjKomLLFJyDaATAZoQv32HjCLCm6Bt tuGHoNOtgZL9yzhC9hRAQ5tjlGABpjVmZfA988rXMnoR2XAYjoa3wAefP+cniJhiQbzX g12g== 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=7oRtR1r3bF0CeodCbRkJkQToPfE0GLyGT8cSuSZXoYk=; b=DY/I6Wn5JuCTP+lrFWH5GNfCZLI6B8Dj9zHpDUM+LBdMyzXwZP61NNFKmWu5thPE0V +re/F+nxOGDWknvxR0cpg1jrfs6WPY2fyntlhBxViGScXY+g/W/F06lxvQhb62rSWX4j iSP/m20h3HdgwDj7gD2U6C8KqDTXA24XDie7a5jn7LPTl1Aw/c9PIJbqjNqDBuaVKowh /jVIafp3dDhDtGm76RDYWN3k6jeZNs4RQGzOdCqLZf0+KM7npCA8/Bo2UKtuK4479Hbh cueyWIYyUwfzUS9LCHGwi+dvPEfPRWtw/O3YFatsLlP5r8xgyyaHNjjOMZEyFEmW3vnz dcuw== 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 a12si842998pfc.167.2017.10.13.10.42.59; Fri, 13 Oct 2017 10:43:13 -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 S1752885AbdJMRl0 (ORCPT + 99 others); Fri, 13 Oct 2017 13:41:26 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37564 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753294AbdJMRkN (ORCPT ); Fri, 13 Oct 2017 13:40:13 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9DHdZuL114822 for ; Fri, 13 Oct 2017 13:40:13 -0400 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0b-001b2d01.pphosted.com with ESMTP id 2djy2rfh7c-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 13 Oct 2017 13:40:13 -0400 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 13 Oct 2017 13:40:12 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 13 Oct 2017 13:40:08 -0400 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9DHe7bS38142116; Fri, 13 Oct 2017 17:40:07 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9A6812803A; Fri, 13 Oct 2017 13:40:00 -0400 (EDT) Received: from localhost.localdomain (unknown [9.85.201.79]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTPS id B382A2803F; Fri, 13 Oct 2017 13:39:59 -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 18/19] KVM: s390: New ioctl to configure KVM guest's AP matrix Date: Fri, 13 Oct 2017 13:39:03 -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-0036-0000-0000-0000027B9CCB 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.00468500; 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:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17101317-0037-0000-0000-00004211705E Message-Id: <1507916344-3896-19-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 Implements an ioctl to configure the adapters, usage domains and control domains to which a KVM guest will be granted access. The ioctl is invoked using the VFIO mediated matrix device's file descriptor. Guest access to AP adapters, usage domains and control domains is controlled by three bit masks referenced from the guest's SIE state description: The AP Mask (APM) controls access to the AP adapters; the AP Queue Mask (AQM) controls access to the AP usage domains; and the AP Domain Mask (ADM) controls access to the AP control domains. Each bit in the APM represents an adapter, from left to right, starting with adapter 0. Each bit in the AQM represents a usage domain, from left to right, starting with domain 0. Each bit in the ADM represents a control domain, from left to right, starting with domain 0. The APM, AQM and ADM bit masks will be populated from the bit masks stored in the corresponding mediated matrix device's sysfs files. The bit masks will also be returned by the ioctl call to the caller. Signed-off-by: Tony Krowiak --- drivers/s390/crypto/vfio_ap_matrix_ops.c | 68 +++++++++++++++++++++++++++++- include/uapi/linux/vfio.h | 20 +++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_matrix_ops.c b/drivers/s390/crypto/vfio_ap_matrix_ops.c index 74ea8db..d81e3ab 100644 --- a/drivers/s390/crypto/vfio_ap_matrix_ops.c +++ b/drivers/s390/crypto/vfio_ap_matrix_ops.c @@ -160,8 +160,69 @@ static int ap_matrix_mdev_get_device_info(unsigned long arg) 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) +static int ap_matrix_configure(struct mdev_device *mdev) +{ + int ret; + struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); + + ret = ap_config_matrix(matrix_mdev->kvm, &matrix_mdev->masks); + if (ret) + return ret; + + return 0; +} + +static int ap_matrix_copy_to_user(struct mdev_device *mdev, + struct vfio_ap_matrix_config *mcfg, + unsigned long arg) +{ + size_t i; + struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); + + + for (i = 0; i < AP_MATRIX_MASK_INDICES; i++) { + if (i < VFIO_AP_MATRIX_MASK_INDICES) { + mcfg->apm[i] = matrix_mdev->masks.apm[i]; + mcfg->aqm[i] = matrix_mdev->masks.aqm[i]; + mcfg->adm[i] = matrix_mdev->masks.adm[i]; + } + } + + if (copy_to_user((void __user *)arg, &mcfg, sizeof(mcfg))) + return -EFAULT; + + return 0; +} + +static ssize_t ap_matrix_mdev_configure(struct mdev_device *mdev, + unsigned long arg) +{ + int ret; + unsigned long minsz; + struct vfio_ap_matrix_config mcfg; + + minsz = offsetofend(struct vfio_ap_matrix_config, adm); + + if (copy_from_user(&mcfg, (void __user *)arg, minsz)) + return -EFAULT; + + if (mcfg.argsz < minsz) { + pr_err("%s: Argument size %u less than min size %li", + VFIO_AP_MATRIX_MODULE_NAME, mcfg.argsz, minsz); + return -EINVAL; + } + + ret = ap_matrix_configure(mdev); + if (ret) + return ret; + + ret = ap_matrix_copy_to_user(mdev, &mcfg, arg); + + return 0; +} + +static long ap_matrix_mdev_ioctl(struct mdev_device *mdev, + unsigned int cmd, unsigned long arg) { int ret; @@ -169,6 +230,9 @@ static ssize_t ap_matrix_mdev_ioctl(struct mdev_device *mdev, case VFIO_DEVICE_GET_INFO: ret = ap_matrix_mdev_get_device_info(arg); break; + case VFIO_AP_MATRIX_CONFIGURE: + ret = ap_matrix_mdev_configure(mdev, arg); + break; default: pr_err("%s: ioctl command %d is not a supported command", VFIO_AP_MATRIX_MODULE_NAME, cmd); diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 08f1ab4..2d96c57 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -716,6 +716,26 @@ struct vfio_iommu_spapr_tce_remove { }; #define VFIO_IOMMU_SPAPR_TCE_REMOVE _IO(VFIO_TYPE, VFIO_BASE + 20) +/** + * VFIO_AP_MATRIX_CONFIGURE _IO(VFIO_TYPE, VFIO_BASE + 21 + * + * Configure the AP matrix for a KVM guest. + */ +#define VFIO_AP_MATRIX_CONFIGURE _IO(VFIO_TYPE, VFIO_BASE + 21) + +#define VFIO_AP_MATRIX_MASK_INDICES 4 +#define VFIO_AP_MATTRIX_MASK_BYTES (VFIO_AP_MATRIX_MASK_INDICES * \ + sizeof(__u64)) +#define VFIO_AP_MATRIX_MASK_BITS (VFIO_AP_MATTRIX_MASK_BYTES * 8) + +struct vfio_ap_matrix_config { + __u32 argsz; + __u32 flags; + /* out */ + __u64 apm[VFIO_AP_MATRIX_MASK_INDICES]; + __u64 aqm[VFIO_AP_MATRIX_MASK_INDICES]; + __u64 adm[VFIO_AP_MATRIX_MASK_INDICES]; +}; /* ***************************************************************** */ #endif /* _UAPIVFIO_H */ -- 1.7.1 From 1583036507186822015@xxx Fri Nov 03 09:27:38 +0000 2017 X-GM-THRID: 1582840593921048574 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread