From patchwork Fri Oct 13 17:38:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Krowiak X-Patchwork-Id: 10005515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A62A060230 for ; Fri, 13 Oct 2017 17:43:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9926F29105 for ; Fri, 13 Oct 2017 17:43:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DC9829109; Fri, 13 Oct 2017 17:43:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29D5C29105 for ; Fri, 13 Oct 2017 17:43:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753121AbdJMRne (ORCPT ); Fri, 13 Oct 2017 13:43:34 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50778 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752896AbdJMRkF (ORCPT ); Fri, 13 Oct 2017 13:40:05 -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 v9DHctme120875 for ; Fri, 13 Oct 2017 13:40:05 -0400 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dk0j6udu4-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 13 Oct 2017 13:40:04 -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:03 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) 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:01 -0400 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9DHe01U49741934; Fri, 13 Oct 2017 17:40:00 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0F8182803F; Fri, 13 Oct 2017 13:39:53 -0400 (EDT) Received: from localhost.localdomain (unknown [9.85.201.79]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTPS id 2C1A92804C; Fri, 13 Oct 2017 13:39:52 -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 10/19] s390/zcrypt: sysfs interfaces supporting AP domain assignment Date: Fri, 13 Oct 2017 13:38:55 -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-0000027B9CC6 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:03 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17101317-0037-0000-0000-000042117047 Message-Id: <1507916344-3896-11-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: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provides the sysfs interfaces for assigning an AP usage domain to and unassigning a usage domain from a mediated matrix device. The relevant sysfs structures are: /sys/devices/ap_matrix ... [matrix] ...... [mdev_supported_types] ......... [ap_matrix-passthrough] ............ [devices] ...............[$uuid] .................. assign_domain .................. domains .................. unassign_domain To assign a domain to the $uuid mediated matrix device, write its domain ID (hex value) to the assign_domain file. To unassign a domain, write its domain ID (hex value) to the unassign_domain file. To view a list of domains which have been assigned, print the contents of the domains file For example, to assign domain 0x04 to the $uuid mediated matrix device: echo 4 > assign_domain To unassign domain 0x04: echo 4 > unassign_domain To see the list of domains assigned: cat domains Signed-off-by: Tony Krowiak --- drivers/s390/crypto/vfio_ap_matrix_ops.c | 80 ++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) diff --git a/drivers/s390/crypto/vfio_ap_matrix_ops.c b/drivers/s390/crypto/vfio_ap_matrix_ops.c index 2e63d1b..f54285c 100644 --- a/drivers/s390/crypto/vfio_ap_matrix_ops.c +++ b/drivers/s390/crypto/vfio_ap_matrix_ops.c @@ -329,10 +329,90 @@ static ssize_t ap_matrix_adapters_show(struct device *dev, } static DEVICE_ATTR(adapters, 0644, ap_matrix_adapters_show, NULL); +static ssize_t ap_matrix_domain_assign(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + unsigned int apqi; + struct mdev_device *mdev = mdev_from_dev(dev); + struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); + + ret = ap_matrix_parse_id(buf, &apqi); + if (ret) + return ret; + + set_bit_inv((unsigned long)apqi, + (unsigned long *)matrix_mdev->masks.aqm); + + return count; +} +static DEVICE_ATTR(assign_domain, 0644, NULL, ap_matrix_domain_assign); + +static ssize_t ap_matrix_domain_unassign(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + unsigned int apqi; + struct mdev_device *mdev = mdev_from_dev(dev); + struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); + + ret = ap_matrix_parse_id(buf, &apqi); + if (ret) + return ret; + + clear_bit_inv((unsigned long)apqi, + (unsigned long *)matrix_mdev->masks.aqm); + + return count; +} +static DEVICE_ATTR(unassign_domain, 0644, NULL, ap_matrix_domain_unassign); + +static ssize_t ap_matrix_domains_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct mdev_device *mdev = mdev_from_dev(dev); + struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); + unsigned long *aqm = (unsigned long *)matrix_mdev->masks.aqm; + unsigned long id; + unsigned long nbits = 256; + char *bufpos = buf; + int nchars = 0; + int n; + + id = find_first_bit_inv(aqm, nbits); + while (id < nbits) { + if (nchars) { + n = sprintf(bufpos, ","); + bufpos += n; + nchars += n; + } + + n = sprintf(bufpos, "%04lx", id); + bufpos += n; + nchars += n; + id = find_next_bit_inv(aqm, nbits, id + 1); + } + + n = sprintf(bufpos, "\n"); + bufpos += n; + nchars += n; + + return nchars; +} + +static DEVICE_ATTR(domains, 0644, ap_matrix_domains_show, + NULL); + static struct attribute *ap_matrix_mdev_attrs[] = { &dev_attr_assign_adapter.attr, &dev_attr_unassign_adapter.attr, &dev_attr_adapters.attr, + &dev_attr_assign_domain.attr, + &dev_attr_unassign_domain.attr, + &dev_attr_domains.attr, NULL };