Received: by 10.223.164.221 with SMTP id h29csp1050215wrb; Fri, 13 Oct 2017 10:45:01 -0700 (PDT) X-Google-Smtp-Source: AOwi7QD84lfBD0atc47WaNO5jaKbRVrJ7+/vhTnpNyD/xSidWmmAUsyTJaC1yWcGV956TmA3FFBb X-Received: by 10.84.142.101 with SMTP id 92mr2020785plw.254.1507916701181; Fri, 13 Oct 2017 10:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507916701; cv=none; d=google.com; s=arc-20160816; b=DJR6S182QpEsU/WIFi10W7fGXl3McEYtrbuzIN2GclaavRcu088K1sDB5WwXv1l3OR 37LKUFu/tvS8T2fYQk4HM4WFbpNSBTtkIJZ8Jec+275reaGJOwtKlTCqKQZDlIe8tqUh aH9cavrh1uBaBw8qoyVAv7HcPWwim5gUTMR4EeglqOPiXT1mp7KR8NKzxC8fVMe5F6sh DRJ/Jpv+FXHFOmziDMHJKHPOrFRtn9ko7jiJ5F8dAR8ZJKQK7IdfPZcrNGIte0KT+VSz jA5KLJU4PpVnvB1+jGhRycgdQa6pUhNkaBZT/BpTTA3AMdyLBGaW0yo/LoGedQVwbaAa WnaA== 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=Kukvq5nU/tPgztFSAhXbnFXPRtq1aiGzyx/fCMgeryE=; b=kUHerN6nny+PMUGWdGBn0q8VJQ7FWdYRsJSKnfQ1bAGOA0n6O3hjUpcSSUG57xrV7W Cvbo5gzk/SjA9DMOL0pEwdx1cf9eYPKJ+W58ufzYHCGe5ni1BboVlpmBFhGOGHKYp5M2 pNxgR8E1bd/7H+rCfWtEhPESRQXJYX33iZ/JTK0lKFyLmOmNJa0DWIdV4KJfDAB3iTtt frQoyqWWfRqmVHCmbRdhiC2o4fbfd6Owa9Bew/tifbqiEQagp+9GRvvoNs+cf0E/zomY WL+6Nvgtpon7OpjyCR2bRnw1r3xvFAl3j6cSsq6vDOL7cuBUdrhNRf3KFX/b5YEnSexG tEWQ== 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 n9si888403plk.292.2017.10.13.10.44.47; Fri, 13 Oct 2017 10:45:01 -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 S1753213AbdJMRkH (ORCPT + 99 others); Fri, 13 Oct 2017 13:40:07 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54042 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752899AbdJMRkE (ORCPT ); Fri, 13 Oct 2017 13:40:04 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9DHcui7012603 for ; Fri, 13 Oct 2017 13:40:04 -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 2djynd60am-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 13 Oct 2017 13:40:03 -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:40:03 -0400 Received: from b01cxnp23033.gho.pok.ibm.com (9.57.198.28) 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:59 -0400 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9DHdwUQ3539218; Fri, 13 Oct 2017 17:39:58 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 31E562803F; Fri, 13 Oct 2017 13:39:51 -0400 (EDT) Received: from localhost.localdomain (unknown [9.85.201.79]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTPS id 4C9412804A; Fri, 13 Oct 2017 13:39:50 -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 08/19] s390/zcrypt: support for assigning adapters to matrix mdev Date: Fri, 13 Oct 2017 13:38:53 -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-000003B293AA 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:40:01 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17101317-0041-0000-0000-000007A7970F Message-Id: <1507916344-3896-9-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 Provides the sysfs interfaces for assigning an adapter to and unassigning an AP adapter from a mediated matrix device. The IDs of the AP adapters assigned to the mediated matrix device are stored in a bit mask. The bits in the mask, from left to right, correspond to AP adapter numbers 0 to 255. The bit corresponding to the ID of the adapter being assigned will be set in the bit mask. The relevant sysfs structures are: /sys/devices/ap_matrix ... [matrix] ...... [mdev_supported_types] ......... [ap_matrix-passthrough] ............ [devices] ...............[$uuid] .................. adapters .................. assign_adapter .................. unassign_adapter To assign an adapter to the $uuid mediated matrix device, write ID of the adapter (hex value) to the assign_adapter file. To unassign an adapter, write the ID of the adapter (hex value) to the unassign_adapter file. The list of adapters that have been assigned can be viewed by displaying the contents of the adapters file. For example, to assign adapter 0xad to mediated matrix device $uuid: echo ad > assign_adapter To unassign adapter 0xad: echo ad > unassign_adapter To see the list of adapters assigned: cat adapters Signed-off-by: Tony Krowiak --- arch/s390/include/asm/ap-config.h | 13 +++ drivers/s390/crypto/vfio_ap_matrix_ops.c | 147 ++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 0 deletions(-) diff --git a/arch/s390/include/asm/ap-config.h b/arch/s390/include/asm/ap-config.h index 8491b5f..3064215 100644 --- a/arch/s390/include/asm/ap-config.h +++ b/arch/s390/include/asm/ap-config.h @@ -9,4 +9,17 @@ #ifndef _ASM_KVM_AP_CONFIG_H_ #define _ASM_KVM_AP_CONFIG_H_ +#include + +#define AP_MATRIX_MAX_MASK_BITS 256 +#define AP_MATRIX_MASK_INDICES (AP_MATRIX_MAX_MASK_BITS / \ + (sizeof(u64) * 8)) +#define AP_MATRIX_MAX_MASK_BYTES (AP_MATRIX_MASK_INDICES * sizeof(u64)) + +struct ap_config_masks { + u64 apm[AP_MATRIX_MASK_INDICES]; + u64 aqm[AP_MATRIX_MASK_INDICES]; + u64 adm[AP_MATRIX_MASK_INDICES]; +}; + #endif /* _ASM_KVM_AP_CONFIG_H_ */ diff --git a/drivers/s390/crypto/vfio_ap_matrix_ops.c b/drivers/s390/crypto/vfio_ap_matrix_ops.c index 7d01f18..e4b1236 100644 --- a/drivers/s390/crypto/vfio_ap_matrix_ops.c +++ b/drivers/s390/crypto/vfio_ap_matrix_ops.c @@ -23,6 +23,7 @@ struct ap_matrix_mdev { struct mdev_device *mdev; struct list_head node; + struct ap_config_masks masks; }; struct ap_matrix *matrix; @@ -136,9 +137,155 @@ static ssize_t device_api_show(struct kobject *kobj, struct device *dev, NULL, }; +static int ap_matrix_id_is_xnum(char *id) +{ + size_t i; + + for (i = 0; i < strlen(id); i++) { + if (!isxdigit(id[i])) + return 0; + } + + return 1; +} + +static int ap_matrix_parse_id(const char *buf, unsigned int *id) +{ + int ret; + char *bufcpy; + char *id_str; + + if ((strlen(buf) == 0) || (*buf == '\n')) { + pr_err("%s: input buffer '%s' contains no valid hex values", + VFIO_AP_MATRIX_MODULE_NAME, buf); + return -EINVAL; + } + + bufcpy = kzalloc(strlen(buf) + 1, GFP_KERNEL); + if (!bufcpy) + return -ENOMEM; + + strcpy(bufcpy, buf); + id_str = strim(bufcpy); + + if (!ap_matrix_id_is_xnum(id_str)) { + pr_err("%s: input id '%s' contains an invalid hex value '%s'", + VFIO_AP_MATRIX_MODULE_NAME, buf, id_str); + ret = -EINVAL; + goto done; + } + + ret = kstrtouint (id_str, 16, id); + if (ret || (*id >= AP_MATRIX_MAX_MASK_BITS)) { + pr_err("%s: input id '%s' is not a value from 0 to %x", + VFIO_AP_MATRIX_MODULE_NAME, buf, + AP_MATRIX_MAX_MASK_BITS); + ret = -EINVAL; + goto done; + } + + ret = 0; + +done: + kfree(bufcpy); + return ret; +} + +static ssize_t ap_matrix_adapters_assign(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + unsigned int apid; + struct mdev_device *mdev = mdev_from_dev(dev); + struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); + + ret = ap_matrix_parse_id(buf, &apid); + if (ret) + return ret; + + set_bit_inv((unsigned long)apid, + (unsigned long *)matrix_mdev->masks.apm); + + return count; +} +static DEVICE_ATTR(assign_adapter, 0644, NULL, ap_matrix_adapters_assign); + +static ssize_t ap_matrix_adapters_unassign(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + unsigned int apid; + struct mdev_device *mdev = mdev_from_dev(dev); + struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); + + ret = ap_matrix_parse_id(buf, &apid); + if (ret) + return ret; + + clear_bit_inv((unsigned long)apid, + (unsigned long *)matrix_mdev->masks.apm); + + return count; +} +static DEVICE_ATTR(unassign_adapter, 0644, NULL, ap_matrix_adapters_unassign); + +static ssize_t ap_matrix_adapters_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 *apm = (unsigned long *)matrix_mdev->masks.apm; + unsigned long id; + unsigned long nbits = 256; + char *bufpos = buf; + int nchars = 0; + int n; + + id = find_first_bit_inv(apm, nbits); + while (id < nbits) { + if (nchars) { + n = sprintf(bufpos, ","); + bufpos += n; + nchars += n; + } + + n = sprintf(bufpos, "%02lx", id); + bufpos += n; + nchars += n; + id = find_next_bit_inv(apm, nbits, id + 1); + } + + n = sprintf(bufpos, "\n"); + bufpos += n; + nchars += n; + + return nchars; +} +static DEVICE_ATTR(adapters, 0644, ap_matrix_adapters_show, NULL); + +static struct attribute *ap_matrix_mdev_attrs[] = { + &dev_attr_assign_adapter.attr, + &dev_attr_unassign_adapter.attr, + &dev_attr_adapters.attr, + NULL +}; + +static struct attribute_group ap_matrix_mdev_attr_group = { + .attrs = ap_matrix_mdev_attrs +}; + +static const struct attribute_group *ap_matrix_mdev_attr_groups[] = { + &ap_matrix_mdev_attr_group, + NULL +}; + static const struct mdev_parent_ops vfio_ap_matrix_ops = { .owner = THIS_MODULE, .supported_type_groups = ap_matrix_mdev_type_groups, + .mdev_attr_groups = ap_matrix_mdev_attr_groups, .create = ap_matrix_mdev_create, .remove = ap_matrix_mdev_remove, }; -- 1.7.1 From 1584872937556752437@xxx Thu Nov 23 15:56:55 +0000 2017 X-GM-THRID: 1584872937556752437 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread