Received: by 10.223.164.202 with SMTP id h10csp350411wrb; Fri, 17 Nov 2017 01:32:35 -0800 (PST) X-Google-Smtp-Source: AGs4zMZEE1vAT/5bR395vM4SyMMw0nKZwrRJRfC1C46RJqdrQ6QXpWbAmOnbtSN/HOF74zTnSA3V X-Received: by 10.159.229.200 with SMTP id t8mr4765341plq.346.1510911155157; Fri, 17 Nov 2017 01:32:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510911155; cv=none; d=google.com; s=arc-20160816; b=UhxPsZNTHq7Q0gr06PKXRJqUyAbuabp64kNTk/OehAtuhdy+3Aw17bNm6CH/HihW9x gfL5X1rf5t0Gipm2Ue0gnnxlQjVuTWyjW/C/2MSP87DvsduDE3115e0/E1G5Te9P0Cvj VllND9TCzKbWCXa3DcrkOf7pJuHXGsRDBV436uUKPa0uL4JKaZap1jSBlXnG9hW2Mt49 4/BM2pAJtWgqvWAvQ5KNtMoYOq6CwmlrevtEvt/sFcYZOozTOh2ZASw/8GhlttLVlJrU 18iUXQfVvMhFxtaQgMtzH25+sbJ3iXUy+7Jy0xX9QbF41iCZc8QS2m1baO5Wu1KCGXAe uHAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :from:references:cc:to:subject:arc-authentication-results; bh=U1JQ6NfuyAdjCe8nlGL/vEP2ILroHTaFH7zq6ETE67w=; b=kcjos9C8Ft0TzSRroku0UzMr+PxLln51x/7wN6OG7KGArmRMXD/k2HlsxwBgGdmmlU 377yLOSRYgoQzRgt/OW6oyEz7XsU6Z4mnK3uSR+QmWO5x8BdcfnJ++wOPS5PEqTnBiPt 4xypEJzbRfTAA30/suYMDKZWaCanW11NUc/E8lRXfoEsSL1r3V78Loph5Gexi1gRel/H nkUm9OyCX87O64zIEfnUKb1lBflooXWqnABbFFsiRqQIBD1rXictVnqSMYLe4Nn2aDlI lyzNJyD6ryxvy+ojlNthILZTYJhtY1ZUlFAhaz6LV+O7j3A0gqpEMRgtimEPmaBcYYjv ZabA== 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 h71si2376945pgc.408.2017.11.17.01.32.21; Fri, 17 Nov 2017 01:32:35 -0800 (PST) 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 S1752143AbdKPXx1 (ORCPT + 92 others); Thu, 16 Nov 2017 18:53:27 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:50108 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752015AbdKPXxR (ORCPT ); Thu, 16 Nov 2017 18:53:17 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGNnGLt100476 for ; Thu, 16 Nov 2017 18:53:17 -0500 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e9gvetd0d-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 18:53:16 -0500 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Nov 2017 16:53:15 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Nov 2017 16:53:11 -0700 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAGNrADC64159854; Thu, 16 Nov 2017 16:53:10 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4F4526E03F; Thu, 16 Nov 2017 16:53:10 -0700 (MST) Received: from oc8043147753.ibm.com (unknown [9.60.75.228]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id 0CA486E040; Thu, 16 Nov 2017 16:53:07 -0700 (MST) Subject: Re: [RFC 08/19] s390/zcrypt: support for assigning adapters to matrix mdev To: Cornelia Huck Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, freude@de.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, borntraeger@de.ibm.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 References: <1507916344-3896-1-git-send-email-akrowiak@linux.vnet.ibm.com> <1507916344-3896-9-git-send-email-akrowiak@linux.vnet.ibm.com> <20171114142244.272d538d.cohuck@redhat.com> From: Tony Krowiak Date: Thu, 16 Nov 2017 18:53:07 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20171114142244.272d538d.cohuck@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 17111623-0028-0000-0000-000008AA0180 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008078; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000240; SDB=6.00946913; UDB=6.00478023; IPR=6.00727205; BA=6.00005696; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018053; XFM=3.00000015; UTC=2017-11-16 23:53:14 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111623-0029-0000-0000-0000385C8EEF Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-16_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711160320 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/14/2017 08:22 AM, Cornelia Huck wrote: > On Fri, 13 Oct 2017 13:38:53 -0400 > Tony Krowiak wrote: > >> 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/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; >> +} > This feels like something for which an utility function should already > exist... See comment below > >> + >> +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; >> +} > Similarly, I suspect you are not the first person with similar parsing > needs. I am going to remove this function > >> + >> +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); I'm going to replace this with a call to kstrtouint (buf, 0, &apid). This will allow the user to enter the adapter ID string using conventional semantics - e.g., 71 or 0x47 - and the function will determine if the value is valid. >> + if (ret) >> + return ret; >> + >> + set_bit_inv((unsigned long)apid, >> + (unsigned long *)matrix_mdev->masks.apm); > Probably needs a comment regarding byte order of the masks somewhere. Okay > >> + >> + return count; >> +} >> +static DEVICE_ATTR(assign_adapter, 0644, NULL, ap_matrix_adapters_assign); From 1584047964066551987@xxx Tue Nov 14 13:24:19 +0000 2017 X-GM-THRID: 1581165262553961473 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread