From patchwork Fri Jan 26 14:35:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason J. Herne" X-Patchwork-Id: 192631 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp705091dyb; Fri, 26 Jan 2024 06:46:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKJhR0qpSPXFJbXNSfARd1TFGVO3O3MYVkhBk1fLwWN3vvRe5DuQGnyA/28SKQpSmo5Sfz X-Received: by 2002:a17:906:33d3:b0:a2e:4ba2:d9e5 with SMTP id w19-20020a17090633d300b00a2e4ba2d9e5mr1013450eja.65.1706280400637; Fri, 26 Jan 2024 06:46:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706280400; cv=pass; d=google.com; s=arc-20160816; b=bbYShkW3zXe+5delJifOMskBuV8Cqj+Ym5HKrFKvVPJcTiwrhqFqfOLxNiki3DMCCI lVCbq4CgyDR9iQvZ23CjDp+SEsBX1oYkHF5pxCsJNroXpnKxswJnLRAhnNFa/W35ytS1 mF4cN2ZSqKSJO5QowV+/VWRoa+nm0XlGk6/dLdEGMMsT1QbBKM/hqhSygGN594iB6A/+ D5ZKDAE7QmPqO55Zu7Ohw9RC3Qzqye16O4PrEWGw/FzeGELV+teyYDXbvBuBk6JUz3T5 Rk/8P530dp8YbJnSJZkbwKewhDdhNtM8zO5Cku/acrxM9rWwp6MhuLf/LHF3/GEw/+LW cwWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=f5V34d+v+9WtCrL/6crwi8C/ZZrO1PefzMKrgvPQbDI=; fh=u2UeGpNSiWWmtUqIVVYd+415jgQ/1DHIUxh//DTdyOU=; b=dQ3L55C1apCngh2ttKAXmlqd7HHup567kHgOGxTFe70zZBIlhCDeHaSVoScJiCZC9m nQj/rTYGedNEeJ8gnSUPXaPtNCLr/bHcfV4HBnoyC2nFCnaW7+xAaU8jeiFoKOg9+Hbx IkZGeeiQxKVSSV4qWSdW/w2QoZRSHx7yudNrwY0eig/AkRtfREcQWN5O9xLAy5SU5ioe x9eerYaGhSTqaOJXmrOv8+1+nc6dYwz9BlJWtEo/gWB28Zwd1pXrqlW+AnoU5idVIjet RU9XGbrEwTIFu/OfN4YhEfLdo7HmoC77u0uzJFsBl33N4uK85iNsB8E01o2TWhlce3c9 T4Cw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=lV+hW9D2; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-40192-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40192-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u14-20020a1709063b8e00b00a30f936a555si611201ejf.665.2024.01.26.06.46.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 06:46:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40192-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=lV+hW9D2; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-40192-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40192-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 685901F28DFC for ; Fri, 26 Jan 2024 14:36:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6A791CFB2; Fri, 26 Jan 2024 14:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="lV+hW9D2" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF2A31C2A6; Fri, 26 Jan 2024 14:35:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706279738; cv=none; b=FtyDcvJzgBsU1wQFCnLywcl85ro1MahRxHPdbSk0Z8QoV+iPZ3BynO/CHljHBKy/RSW8G2IdcHrg9ma9RX9ROQvybW9tOoOFglh3I44EHnAXKmOf+FaKIuzcUL+2xRZbeMsPBspDkyjxqFOjgmWeXHI4g+KWjt7CH/Ho/OWtv8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706279738; c=relaxed/simple; bh=VS1AQhdQTxNirNpomKjqTD6WT1P/vvqx1Hx55sOh2ko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aIzRByltL6l+WPR3xOo/QIwK634sHCIm0TZyeReS7np/IY1QHwbh4TTKZjIC5qJIw2Tgoo4sPIrTP9t3cE/sBRZoxy7SOH8mQ3MNhN/yuAnLan3jtMBZWt0H+7WgSzhVIy/i3eOPzsiRQgSekokloAA341kLl24M6NQRj3aq1zY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=lV+hW9D2; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40QEWUh0016460; Fri, 26 Jan 2024 14:35:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=f5V34d+v+9WtCrL/6crwi8C/ZZrO1PefzMKrgvPQbDI=; b=lV+hW9D2sT2PV1vy+tIwi1buXeF0+41mezYTYKf31qZIRars5uk8cHcHA5pdMOPPqUWm kHhCziMs7Dt4zK0Md452cZN+G98NZnkmRIPoYZRT35vsGSlVMXb0t9JI3TGQ4s0bnfxe tRRE3tswzXsJdUi8uD0Gt941G7wz8m7b5TdSgNQP53IL7YjM4XA3iKcH00b6kYEw5mGn 1IjcbDgrVN3rmFXyWhgRCbWhHZSbYtTxadvxOd4HAfoVUPQcTsHG3WUiYJh6n+6D/TtG ShaUgs6CE1ZJ7ZmF3xcsiIx8ZFctKK3WpDgVwM+oac32tjgPCsFyrANT4quVqFZSzhC9 xQ== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vvek903e0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jan 2024 14:35:36 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 40QDQGlY028254; Fri, 26 Jan 2024 14:35:35 GMT Received: from smtprelay06.dal12v.mail.ibm.com ([172.16.1.8]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vru732ss7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jan 2024 14:35:35 +0000 Received: from smtpav04.dal12v.mail.ibm.com (smtpav04.dal12v.mail.ibm.com [10.241.53.103]) by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40QEZYEG2098156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Jan 2024 14:35:34 GMT Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DBDC58062; Fri, 26 Jan 2024 14:35:34 +0000 (GMT) Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 14E2B58056; Fri, 26 Jan 2024 14:35:34 +0000 (GMT) Received: from li-4795344c-3451-11b2-a85c-ab40c30bcc43.ibm.com (unknown [9.61.37.129]) by smtpav04.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 26 Jan 2024 14:35:33 +0000 (GMT) From: "Jason J. Herne" To: linux-s390@vger.kernel.org Cc: linux-kernel@vger.kernel.org, pasic@linux.ibm.com, akrowiak@linux.ibm.com Subject: [PATCH 1/3] s390/ap: Externalize AP bus specific bitmap reading function Date: Fri, 26 Jan 2024 09:35:31 -0500 Message-ID: <20240126143533.14043-2-jjherne@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240126143533.14043-1-jjherne@linux.ibm.com> References: <20240126143533.14043-1-jjherne@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: lt6NTaDY5pmxB3G-vShctZj47sUMv0hI X-Proofpoint-ORIG-GUID: lt6NTaDY5pmxB3G-vShctZj47sUMv0hI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-25_14,2024-01-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 clxscore=1011 lowpriorityscore=0 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 mlxscore=0 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401260106 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789164677340727011 X-GMAIL-MSGID: 1789164677340727011 Rename hex2bitmap() to ap_hex2bitmap() and export it for external use. This function will be used by the implementation of the vfio-ap queue_configuration sysfs attribute. Signed-off-by: Jason J. Herne Reviewed-by: Tony Krowiak Reviewed-by: Harald Freudenberger --- drivers/s390/crypto/ap_bus.c | 13 +++---------- drivers/s390/crypto/ap_bus.h | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c index f46dd6abacd7..5d8e379eff44 100644 --- a/drivers/s390/crypto/ap_bus.c +++ b/drivers/s390/crypto/ap_bus.c @@ -1035,15 +1035,7 @@ void ap_bus_cfg_chg(void) ap_bus_force_rescan(); } -/* - * hex2bitmap() - parse hex mask string and set bitmap. - * Valid strings are "0x012345678" with at least one valid hex number. - * Rest of the bitmap to the right is padded with 0. No spaces allowed - * within the string, the leading 0x may be omitted. - * Returns the bitmask with exactly the bits set as given by the hex - * string (both in big endian order). - */ -static int hex2bitmap(const char *str, unsigned long *bitmap, int bits) +int ap_hex2bitmap(const char *str, unsigned long *bitmap, int bits) { int i, n, b; @@ -1070,6 +1062,7 @@ static int hex2bitmap(const char *str, unsigned long *bitmap, int bits) return -EINVAL; return 0; } +EXPORT_SYMBOL(ap_hex2bitmap); /* * modify_bitmap() - parse bitmask argument and modify an existing @@ -1135,7 +1128,7 @@ static int ap_parse_bitmap_str(const char *str, unsigned long *bitmap, int bits, rc = modify_bitmap(str, newmap, bits); } else { memset(newmap, 0, size); - rc = hex2bitmap(str, newmap, bits); + rc = ap_hex2bitmap(str, newmap, bits); } return rc; } diff --git a/drivers/s390/crypto/ap_bus.h b/drivers/s390/crypto/ap_bus.h index 98814839ef30..954f8d36c2d9 100644 --- a/drivers/s390/crypto/ap_bus.h +++ b/drivers/s390/crypto/ap_bus.h @@ -343,6 +343,28 @@ int ap_parse_mask_str(const char *str, unsigned long *bitmap, int bits, struct mutex *lock); +/* + * ap_hex2bitmap() - Convert a string containing a hexadecimal number (str) + * into a bitmap (bitmap) with bits set that correspond to the bits represented + * by the hex string. Input and output data is in big endian order. + * + * str - Input hex string of format "0x1234abcd". The leading "0x" is optional. + * At least one digit is required. Must be large enough to hold the number of + * bits represented by the bits parameter. + * + * bitmap - Pointer to a bitmap. Upon successful completion of this function, + * this bitmap will have bits set to match the value of str. If bitmap is longer + * than str, then the rightmost bits of bitmap are padded with zeros. Must be + * large enough to hold the number of bits represented by the bits parameter. + * + * bits - Length, in bits, of the bitmap represented by str. Must be a multiple + * of 8. + * + * Returns: 0 on success + * -EINVAL If str format is invalid or bits is not a multiple of 8. + */ +int ap_hex2bitmap(const char *str, unsigned long *bitmap, int bits); + /* * Interface to wait for the AP bus to have done one initial ap bus * scan and all detected APQNs have been bound to device drivers. From patchwork Fri Jan 26 14:35:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason J. Herne" X-Patchwork-Id: 192616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp699507dyb; Fri, 26 Jan 2024 06:36:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBDaEmsZf6hUf8NrMgS9e6F2hbxZMCsGG/n/ikfJjZBg1rPRXzEzdBcHLygIwNXdbQmo+t X-Received: by 2002:a05:6214:d88:b0:683:815f:61f9 with SMTP id e8-20020a0562140d8800b00683815f61f9mr1665155qve.73.1706279791073; Fri, 26 Jan 2024 06:36:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706279791; cv=pass; d=google.com; s=arc-20160816; b=kRfzakvNULPkLiWY+RhU7H7ZahbpXiZp6eiVQCXZohg9q4VX6nf8G0e7aAY2rrS/yN h/BFQ8XcXKTomJPWWp3kPao9d9ijQsmh6GndYrm1L1KEq3z/iCsbc+QE1qatL20KxDSw ad4xtOQDrgogZTDY+SOBkqKS0g3gM4KvAEQyvxsNMpCPqGmfLd1now/SChohE2rocl+b TH90QLHjCGnLyoV0D5x0w0qjq7R7CxXO9cq2/2QfFaziyf+NNMMyF2i2cNIStJRgR6tC ED8fFpiAn4YpfZvmNqUUHeG4Ew9ushAdz7lwNyIiYc4B3pLWRCgcSZn1uK0L7B2d+nD2 HUDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=AAtVdCLgElC7PvjzVIgz+2EULBdJfRACXXrd0e9tuuU=; fh=u2UeGpNSiWWmtUqIVVYd+415jgQ/1DHIUxh//DTdyOU=; b=jPpXefJgK2yH7X5xjCF/DN8+VvGh/4zfiE0cLY4PHpiN9bzqxu5IOeLIpOuPFKGRvE sQ/7vvPbyNgsXCkdFJqwiCt+oL03ErYzjhmdD9K0Mn+vTnNMqfj1j4SCBA1DIPmkGMB5 5uu3zXBtml74EsU/QL1OOEAkU9lhR2U81c5zKBAm484Qru9CAsQNp4ER+QdQthcREdiH I0FVp6YrnQjFU5Jczr9nneWLw3tjq91b2pa9+nHfG1FxQ7rnPCOajy0jM7YivzOr/Vfc 2SW84fodCPhpOqBZjxAOkCL18NsEix21FVMg0T4hDfGw3+Jugi+Jc5Z4+F6WlwE95evB Zn+Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=UPKbboBm; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-40194-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40194-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jf10-20020a0562142a4a00b00681865a7979si1403198qvb.327.2024.01.26.06.36.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 06:36:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40194-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=UPKbboBm; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-40194-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40194-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BC8671C20E9C for ; Fri, 26 Jan 2024 14:36:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B77391D527; Fri, 26 Jan 2024 14:35:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="UPKbboBm" Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0D701C693; Fri, 26 Jan 2024 14:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706279739; cv=none; b=F48WAIqWlRPsQWm8858mFKgCA2ZDlhOqpJv3B9cPjGZjDIZDfA2AtHXCgZvv/SugTKJbHhE3Ph4CnOKG0WnVX9LHYA1XEr5tjVBWaXqms6eAs1ooM9V/xr07Hyvd6/QblTVSqy+d23Pj3TcRT+KBiSPkniKvdDt/2OlY7hnBNAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706279739; c=relaxed/simple; bh=00iuVnMhBqyr7kI4JUWMIzqhsTGDKdX5ZMcXxJXFZXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TWDq8P6Wm3I1qHdoXsx8eEiy+T12STSrdyHgy4ZrZ736tJiXd8+RvSVuymHrCA/5fsNYrCY2e5lne3ObzIL9FTzdmZer1seSG8Vm/RxxKfBkhXe2cavq2elm6rQwYlr5BIKW8W9HJ2v7+KN2wu94ITSSdzaO/EAX87n6ld39j/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=UPKbboBm; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40QENFLV028908; Fri, 26 Jan 2024 14:35:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=AAtVdCLgElC7PvjzVIgz+2EULBdJfRACXXrd0e9tuuU=; b=UPKbboBm5o/GmShhMrxt4s1ehYfgJu7Sg1H6jaeG2/Qj7b6JtGgvIbmk+xzzlTegNOA2 OhEtheqON0/WGVyx/tLos8NPgBByLsGLslBPgjSFQI5c10nozZhhT5C6jTP7fubKXa/g Y5BoEx0rP1Y/0BdwR/4c3e+ULFGCwhQWcBInhVgQXkaniMj4vbYW6ma9v3VsxfzVvkzq HxJduBC7tY5lgx7b1CHgA/Z6hyErbgn6+w5Rlqx081ADe/CtKecyAKPTH0M35dzge9UZ bGrLG+fcp83ntH7uZjieABDIeVUT8OAG06yg8MtG9+RB2kOmmkRH/wH8YQXiHanhmwAz OQ== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vveeugdgf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jan 2024 14:35:36 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 40QBMNoY010854; Fri, 26 Jan 2024 14:35:36 GMT Received: from smtprelay06.dal12v.mail.ibm.com ([172.16.1.8]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vrrw0basu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jan 2024 14:35:35 +0000 Received: from smtpav04.dal12v.mail.ibm.com (smtpav04.dal12v.mail.ibm.com [10.241.53.103]) by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40QEZY7K57082352 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Jan 2024 14:35:35 GMT Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E1DC05805E; Fri, 26 Jan 2024 14:35:34 +0000 (GMT) Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8AC6358065; Fri, 26 Jan 2024 14:35:34 +0000 (GMT) Received: from li-4795344c-3451-11b2-a85c-ab40c30bcc43.ibm.com (unknown [9.61.37.129]) by smtpav04.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 26 Jan 2024 14:35:34 +0000 (GMT) From: "Jason J. Herne" To: linux-s390@vger.kernel.org Cc: linux-kernel@vger.kernel.org, pasic@linux.ibm.com, akrowiak@linux.ibm.com Subject: [PATCH 2/3] s390/vfio-ap: Add sysfs attr, queue_configuration, to export mdev state Date: Fri, 26 Jan 2024 09:35:32 -0500 Message-ID: <20240126143533.14043-3-jjherne@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240126143533.14043-1-jjherne@linux.ibm.com> References: <20240126143533.14043-1-jjherne@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: yjoNoCCVQS0v0kHK1USf5QXm4i1TeEUs X-Proofpoint-ORIG-GUID: yjoNoCCVQS0v0kHK1USf5QXm4i1TeEUs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-25_14,2024-01-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 clxscore=1015 suspectscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401260106 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789164037815637940 X-GMAIL-MSGID: 1789164037815637940 Add ap_config sysfs attribute. This will provide the means for setting or displaying the adapters, domains and control domains assigned to the vfio-ap mediated device in a single operation. This sysfs attribute is comprised of three masks: One for adapters, one for domains, and one for control domains. This attribute is intended to be used by mdevctl to query a vfio-ap mediated device's state. Signed-off-by: Jason J. Herne Reviewed-by: Anthony Krowiak --- drivers/s390/crypto/vfio_ap_ops.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 243d252bc631..96293683b939 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -1508,6 +1508,32 @@ static ssize_t guest_matrix_show(struct device *dev, } static DEVICE_ATTR_RO(guest_matrix); +static ssize_t write_ap_bitmap(unsigned long *bitmap, char *buf, int offset, char sep) +{ + return sysfs_emit_at(buf, offset, "0x%016lx%016lx%016lx%016lx%c", + bitmap[0], bitmap[1], bitmap[2], bitmap[3], sep); +} + +static ssize_t ap_config_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev); + int idx = 0; + + idx += write_ap_bitmap(matrix_mdev->matrix.apm, buf, idx, ','); + idx += write_ap_bitmap(matrix_mdev->matrix.aqm, buf, idx, ','); + idx += write_ap_bitmap(matrix_mdev->matrix.adm, buf, idx, '\n'); + + return idx; +} + +static ssize_t ap_config_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + return count; +} +static DEVICE_ATTR_RW(ap_config); + static struct attribute *vfio_ap_mdev_attrs[] = { &dev_attr_assign_adapter.attr, &dev_attr_unassign_adapter.attr, @@ -1515,6 +1541,7 @@ static struct attribute *vfio_ap_mdev_attrs[] = { &dev_attr_unassign_domain.attr, &dev_attr_assign_control_domain.attr, &dev_attr_unassign_control_domain.attr, + &dev_attr_ap_config.attr, &dev_attr_control_domains.attr, &dev_attr_matrix.attr, &dev_attr_guest_matrix.attr, From patchwork Fri Jan 26 14:35:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason J. Herne" X-Patchwork-Id: 192617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp699641dyb; Fri, 26 Jan 2024 06:36:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFY+0PDb3d00LMWNG8ZctPwBIj4HE2fxDivFI4DMl/eJoR8INh5aSFPilvgXo2NFd/4E2QK X-Received: by 2002:a05:6358:5d84:b0:176:9e87:412c with SMTP id s4-20020a0563585d8400b001769e87412cmr1762938rwm.7.1706279805531; Fri, 26 Jan 2024 06:36:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706279805; cv=pass; d=google.com; s=arc-20160816; b=V002knN3e79xrnC8rS9TrFwurNKtClqo8Me5/JBykWVCvebWJ4WxCwZ8P9Y8dmuwI5 ywFBFkqjaYXepCuPInsOgEaljYjS5i7MtEog0n1yD7Z4zVIuhHFr0WCRZV1y2szqmx68 mxT7b4fFed3T8NB9QpkOrgG2DaOQ9RKrr4FwRRm+/7cjo2zPP6+mdl+/kG/n62hsQZaV xf+4CQ5bu9RNujPez5XWqAtWaiodWOAquCNhXam9BW+J22FUYfbT3LUBDo7ZOfFiUZUQ ONOsEPdeQtn9m4uMarIvXl8YzQBCxd7vwNfYILwUNrgz8DTbbQgLH1GZrzpSrDuS51M/ 9RNA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=8KQwGGE1OoEUuwhYZNpCz1AaEgoGOn7O9IUjthmazM0=; fh=u2UeGpNSiWWmtUqIVVYd+415jgQ/1DHIUxh//DTdyOU=; b=YasDQ3W/ffllmy+JYvVjv1IFHxBg9ev8tn79siqxXlZXCE2CnxRC3V2cQymA9OOcVb 4xnJwbOXirEZY4ueR4pQf6WjqCi8k8QPa+mgdh3gbuGCmQSU8ZjsYYu6CDFREIIO61p3 pvuBm0aM+vmvcvCI0sYk6trwVoIbs0hTZXnWhCRstUbJGQAa51yDwn+KY8GKSCs9BQSk THJzlBxlN2rh6MxQupW7TUJ3g5ojvHGZej4wahm0sgHYK+dWlAT3CwOHaaoeZARDnQ/O /5Rh4wNU4rWIIAzsg3Svi0xfNhpGFHzgVb5/yywGs/T4y5OIhQ3+vQ8P7eOLBfHDrZIc AXEA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=IMAcA0KE; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-40195-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40195-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l70-20020a639149000000b005cd816aaf02si1231865pge.3.2024.01.26.06.36.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 06:36:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40195-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=IMAcA0KE; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-40195-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40195-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3A505286480 for ; Fri, 26 Jan 2024 14:36:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 027751C694; Fri, 26 Jan 2024 14:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="IMAcA0KE" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E7B81C291; Fri, 26 Jan 2024 14:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706279771; cv=none; b=u+z13hEUttcblMJ1Hx8f4cr9L7mQ9xsFSq16fk/ZgLK5bYjfEiPbNtBwWtI3+pIJyVL7smO3R4Bc6SxjuJ8REmbhwQJ+JzK0xA3ELVLAJQ4KRU4xq5AQr+Fu6mkTGgN0K+SKfUBbfz70kI0MTJmtKm+oigEWPDEdTiEdybTTXKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706279771; c=relaxed/simple; bh=JfmPStXRRuk+e/C6LsDVMx3sKK3BV8TqGCQNeAqR3rg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TjP3S5t8uz8QwADCzfspyJ/CdUGppbEou7kdK4zFhE9YowaANltO6oJoUZgW53yyCUWOxkBDgUkcQ7aOT8T6UYa0uz6N//vL68eAW47oqm2evi0LxDDFhQ5RonVS/O5MhtMqIel6QrY3AmMHWTSG7XQ+PtYrIo8g19MheoA6on4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=IMAcA0KE; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40QDNiXp009094; Fri, 26 Jan 2024 14:36:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=8KQwGGE1OoEUuwhYZNpCz1AaEgoGOn7O9IUjthmazM0=; b=IMAcA0KEPhXc7qTBqVTMmjDOC+hGaEKRRLbHQMCP98wqgeOjn2rewyM4Rb7oMO+ECtHM m9rUWarhdtlLLS6AVYlEtAxC95keHirSX0vDbY9pYQy+V6gux+4mA6kvXJio4DWX+n4p ES4pYQ/nbyK9IeY0BVZpslXRV34PTppab4gEOEQg7NWuDnsHCAB6Ydl5yDzV7KsGxyFC 4ppSj6aVpoD2f22EfeahWx6WkfeRG8I22bT2GxR2ClBAhs6YdX7worCSJdAZme5log9D QHRUsdJPMz8VmbsSlCyifSL/qrk2tLbQI7mAK39aeP+/N3s+sbn0+gnijEoKxxx28YNm NQ== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vvbxumcua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jan 2024 14:36:07 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 40QDJKRt028225; Fri, 26 Jan 2024 14:35:37 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vru732ssc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jan 2024 14:35:37 +0000 Received: from smtpav04.dal12v.mail.ibm.com (smtpav04.dal12v.mail.ibm.com [10.241.53.103]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40QEZZac32375476 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Jan 2024 14:35:35 GMT Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5FDAC58063; Fri, 26 Jan 2024 14:35:35 +0000 (GMT) Received: from smtpav04.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0797F58062; Fri, 26 Jan 2024 14:35:35 +0000 (GMT) Received: from li-4795344c-3451-11b2-a85c-ab40c30bcc43.ibm.com (unknown [9.61.37.129]) by smtpav04.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 26 Jan 2024 14:35:34 +0000 (GMT) From: "Jason J. Herne" To: linux-s390@vger.kernel.org Cc: linux-kernel@vger.kernel.org, pasic@linux.ibm.com, akrowiak@linux.ibm.com Subject: [PATCH 3/3] s390/vfio-ap: Add write support to sysfs attr ap_config Date: Fri, 26 Jan 2024 09:35:33 -0500 Message-ID: <20240126143533.14043-4-jjherne@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240126143533.14043-1-jjherne@linux.ibm.com> References: <20240126143533.14043-1-jjherne@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: hj_KC82IzEPCJTd51iI75CP7Zfb9NZRD X-Proofpoint-ORIG-GUID: hj_KC82IzEPCJTd51iI75CP7Zfb9NZRD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-25_14,2024-01-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 adultscore=0 mlxlogscore=999 impostorscore=0 mlxscore=0 suspectscore=0 clxscore=1015 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401260107 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789164053735448064 X-GMAIL-MSGID: 1789164053735448064 Allow writing a complete set of masks to ap_config. Doing so will cause the vfio-ap driver to replace the vfio-ap mediated device's entire state with the given set of masks. If the given state cannot be set, then no changes are made to the vfio-ap mediated device. The format of the data written to ap_config is as follows: {amask},{dmask},{cmask}\n \n is a newline character. amask, dmask, and cmask are masks identifying which adapters, domains, and control domains should be assigned to the mediated device. The format of a mask is as follows: 0xNN..NN Where NN..NN is 64 hexadecimal characters representing a 256-bit value. The leftmost (highest order) bit represents adapter/domain 0. For an example set of masks that represent your mdev's current configuration, simply cat ap_config. This attribute is intended to be used by an mdevctl callout script supporting the mdev type vfio_ap-passthrough to atomically update a vfio-ap mediated device's state. Signed-off-by: Jason J. Herne --- Documentation/arch/s390/vfio-ap.rst | 27 ++++ drivers/s390/crypto/vfio_ap_ops.c | 188 +++++++++++++++++++++++--- drivers/s390/crypto/vfio_ap_private.h | 6 +- 3 files changed, 197 insertions(+), 24 deletions(-) diff --git a/Documentation/arch/s390/vfio-ap.rst b/Documentation/arch/s390/vfio-ap.rst index 929ee1c1c940..a94f13916dea 100644 --- a/Documentation/arch/s390/vfio-ap.rst +++ b/Documentation/arch/s390/vfio-ap.rst @@ -380,6 +380,33 @@ matrix device. control_domains: A read-only file for displaying the control domain numbers assigned to the vfio_ap mediated device. + ap_config: + A read/write file that, when written to, allows the entire vfio_ap mediated + device's ap configuration to be replaced in one shot. Three masks are given, + one for adapters, one for domains, and one for control domains. If the + given state cannot be set, then no changes are made to the vfio-ap + mediated device. + + The format of the data written to ap_config is as follows: + {amask},{dmask},{cmask}\n + + \n is a newline character. + + amask, dmask, and cmask are masks identifying which adapters, domains, + and control domains should be assigned to the mediated device. + + The format of a mask is as follows: + 0xNN..NN + + Where NN..NN is 64 hexadecimal characters representing a 256-bit value. + The leftmost (highest order) bit represents adapter/domain 0. + + For an example set of masks that represent your mdev's current + configuration, simply cat ap_config. + + This attribute is intended to be used by automation. End users would be + better served using the respective assign/unassign attributes for adapters + and domains. * functions: diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 96293683b939..5ad134c1d5e6 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -764,10 +764,11 @@ static int vfio_ap_mdev_probe(struct mdev_device *mdev) static void vfio_ap_mdev_link_queue(struct ap_matrix_mdev *matrix_mdev, struct vfio_ap_queue *q) { - if (q) { - q->matrix_mdev = matrix_mdev; - hash_add(matrix_mdev->qtable.queues, &q->mdev_qnode, q->apqn); - } + if (!q || vfio_ap_mdev_get_queue(matrix_mdev, q->apqn)) + return; + + q->matrix_mdev = matrix_mdev; + hash_add(matrix_mdev->qtable.queues, &q->mdev_qnode, q->apqn); } static void vfio_ap_mdev_link_apqn(struct ap_matrix_mdev *matrix_mdev, int apqn) @@ -1048,21 +1049,25 @@ static void vfio_ap_mdev_unlink_adapter(struct ap_matrix_mdev *matrix_mdev, } } -static void vfio_ap_mdev_hot_unplug_adapter(struct ap_matrix_mdev *matrix_mdev, - unsigned long apid) +static void vfio_ap_mdev_hot_unplug_adapters(struct ap_matrix_mdev *matrix_mdev, + unsigned long *apids) { - int loop_cursor; - struct vfio_ap_queue *q; struct ap_queue_table *qtable = kzalloc(sizeof(*qtable), GFP_KERNEL); + struct vfio_ap_queue *q; + unsigned long apid; + int loop_cursor; hash_init(qtable->queues); - vfio_ap_mdev_unlink_adapter(matrix_mdev, apid, qtable); - if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm)) { - clear_bit_inv(apid, matrix_mdev->shadow_apcb.apm); - vfio_ap_mdev_update_guest_apcb(matrix_mdev); + for_each_set_bit_inv(apid, apids, AP_DEVICES) { + vfio_ap_mdev_unlink_adapter(matrix_mdev, apid, qtable); + + if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm)) + clear_bit_inv(apid, matrix_mdev->shadow_apcb.apm); } + vfio_ap_mdev_update_guest_apcb(matrix_mdev); + vfio_ap_mdev_reset_queues(qtable); hash_for_each(qtable->queues, loop_cursor, q, mdev_qnode) { @@ -1073,6 +1078,15 @@ static void vfio_ap_mdev_hot_unplug_adapter(struct ap_matrix_mdev *matrix_mdev, kfree(qtable); } +static void vfio_ap_mdev_hot_unplug_adapter(struct ap_matrix_mdev *matrix_mdev, + unsigned long apid) +{ + DECLARE_BITMAP(apids, AP_DEVICES); + + set_bit_inv(apid, apids); + vfio_ap_mdev_hot_unplug_adapters(matrix_mdev, apids); +} + /** * unassign_adapter_store - parses the APID from @buf and clears the * corresponding bit in the mediated matrix device's APM @@ -1235,21 +1249,24 @@ static void vfio_ap_mdev_unlink_domain(struct ap_matrix_mdev *matrix_mdev, } } -static void vfio_ap_mdev_hot_unplug_domain(struct ap_matrix_mdev *matrix_mdev, - unsigned long apqi) +static void vfio_ap_mdev_hot_unplug_domains(struct ap_matrix_mdev *matrix_mdev, + unsigned long *apqis) { - int loop_cursor; - struct vfio_ap_queue *q; struct ap_queue_table *qtable = kzalloc(sizeof(*qtable), GFP_KERNEL); + struct vfio_ap_queue *q; + unsigned long apqi; + int loop_cursor; hash_init(qtable->queues); - vfio_ap_mdev_unlink_domain(matrix_mdev, apqi, qtable); - if (test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm)) { - clear_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm); - vfio_ap_mdev_update_guest_apcb(matrix_mdev); + for_each_set_bit_inv(apqi, apqis, AP_DOMAINS) { + vfio_ap_mdev_unlink_domain(matrix_mdev, apqi, qtable); + + if (test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm)) + clear_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm); } + vfio_ap_mdev_update_guest_apcb(matrix_mdev); vfio_ap_mdev_reset_queues(qtable); hash_for_each(qtable->queues, loop_cursor, q, mdev_qnode) { @@ -1260,6 +1277,15 @@ static void vfio_ap_mdev_hot_unplug_domain(struct ap_matrix_mdev *matrix_mdev, kfree(qtable); } +static void vfio_ap_mdev_hot_unplug_domain(struct ap_matrix_mdev *matrix_mdev, + unsigned long apqi) +{ + DECLARE_BITMAP(apqis, AP_DOMAINS); + + set_bit_inv(apqi, apqis); + vfio_ap_mdev_hot_unplug_domains(matrix_mdev, apqis); +} + /** * unassign_domain_store - parses the APQI from @buf and clears the * corresponding bit in the mediated matrix device's AQM @@ -1527,10 +1553,130 @@ static ssize_t ap_config_show(struct device *dev, struct device_attribute *attr, return idx; } +/* Number of characters needed for a complete hex mask representing the bits in .. */ +#define AP_DEVICES_STRLEN (AP_DEVICES/4 + 3) +#define AP_DOMAINS_STRLEN (AP_DOMAINS/4 + 3) +#define AP_CONFIG_STRLEN (AP_DEVICES_STRLEN + 2 * AP_DOMAINS_STRLEN) + +static int parse_bitmap(char **strbufptr, unsigned long *bitmap, int nbits) +{ + char *curmask; + + curmask = strsep(strbufptr, ",\n"); + if (!curmask) + return -EINVAL; + + bitmap_clear(bitmap, 0, nbits); + return ap_hex2bitmap(curmask, bitmap, nbits); +} + +static int ap_matrix_length_check(struct ap_matrix_mdev *matrix_mdev) +{ + unsigned long bit; + + for_each_set_bit_inv(bit, matrix_mdev->matrix.apm, AP_DEVICES) { + if (bit > matrix_mdev->matrix.apm_max) + return -ENODEV; + } + + for_each_set_bit_inv(bit, matrix_mdev->matrix.aqm, AP_DOMAINS) { + if (bit > matrix_mdev->matrix.aqm_max) + return -ENODEV; + } + + for_each_set_bit_inv(bit, matrix_mdev->matrix.adm, AP_DOMAINS) { + if (bit > matrix_mdev->matrix.adm_max) + return -ENODEV; + } + + return 0; +} + +static void ap_matrix_copy(struct ap_matrix *dst, struct ap_matrix *src) +{ + bitmap_copy(dst->apm, src->apm, AP_DEVICES); + bitmap_copy(dst->aqm, src->aqm, AP_DOMAINS); + bitmap_copy(dst->adm, src->adm, AP_DOMAINS); +} + static ssize_t ap_config_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - return count; + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev); + struct ap_matrix m_new, m_old, m_added, m_removed; + unsigned long newbit; + char *newbuf, *rest; + int rc = count; + bool do_update; + + newbuf = rest = kstrndup(buf, AP_CONFIG_STRLEN, GFP_KERNEL); + if (!newbuf) + return -ENOMEM; + + mutex_lock(&ap_perms_mutex); + get_update_locks_for_mdev(matrix_mdev); + + /* Save old state */ + ap_matrix_copy(&m_old, &matrix_mdev->matrix); + + if (parse_bitmap(&rest, m_new.apm, AP_DEVICES) || + parse_bitmap(&rest, m_new.aqm, AP_DOMAINS) || + parse_bitmap(&rest, m_new.adm, AP_DOMAINS)) { + rc = -EINVAL; + goto out; + } + + bitmap_andnot(m_removed.apm, m_old.apm, m_new.apm, AP_DEVICES); + bitmap_andnot(m_removed.aqm, m_old.aqm, m_new.aqm, AP_DOMAINS); + bitmap_andnot(m_added.apm, m_new.apm, m_old.apm, AP_DEVICES); + bitmap_andnot(m_added.aqm, m_new.aqm, m_old.aqm, AP_DOMAINS); + + /* Need new bitmaps in matrix_mdev for validation */ + ap_matrix_copy(&matrix_mdev->matrix, &m_new); + + /* Ensure new state is valid, else undo new state */ + rc = vfio_ap_mdev_validate_masks(matrix_mdev); + if (rc) { + ap_matrix_copy(&matrix_mdev->matrix, &m_old); + goto out; + } + rc = ap_matrix_length_check(matrix_mdev); + if (rc) { + ap_matrix_copy(&matrix_mdev->matrix, &m_old); + goto out; + } + rc = count; + + /* Need old bitmaps in matrix_mdev for unplug/unlink */ + ap_matrix_copy(&matrix_mdev->matrix, &m_old); + + /* Unlink removed adapters/domains */ + vfio_ap_mdev_hot_unplug_adapters(matrix_mdev, m_removed.apm); + vfio_ap_mdev_hot_unplug_domains(matrix_mdev, m_removed.aqm); + + /* Need new bitmaps in matrix_mdev for linking new adapters/domains */ + ap_matrix_copy(&matrix_mdev->matrix, &m_new); + + /* Link newly added adapters */ + for_each_set_bit_inv(newbit, m_added.apm, AP_DEVICES) + vfio_ap_mdev_link_adapter(matrix_mdev, newbit); + + for_each_set_bit_inv(newbit, m_added.aqm, AP_DOMAINS) + vfio_ap_mdev_link_domain(matrix_mdev, newbit); + + /* filter resources not bound to vfio-ap */ + do_update = vfio_ap_mdev_filter_matrix(matrix_mdev->matrix.apm, + matrix_mdev->matrix.aqm, matrix_mdev); + do_update |= vfio_ap_mdev_filter_cdoms(matrix_mdev); + + /* Apply changes to shadow apbc if things changed */ + if (do_update) + vfio_ap_mdev_update_guest_apcb(matrix_mdev); +out: + release_update_locks_for_mdev(matrix_mdev); + mutex_unlock(&ap_perms_mutex); + kfree(newbuf); + return rc; } static DEVICE_ATTR_RW(ap_config); diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h index 88aff8b81f2f..e2cf07c184bf 100644 --- a/drivers/s390/crypto/vfio_ap_private.h +++ b/drivers/s390/crypto/vfio_ap_private.h @@ -75,11 +75,11 @@ extern struct ap_matrix_dev *matrix_dev; */ struct ap_matrix { unsigned long apm_max; - DECLARE_BITMAP(apm, 256); + DECLARE_BITMAP(apm, AP_DEVICES); unsigned long aqm_max; - DECLARE_BITMAP(aqm, 256); + DECLARE_BITMAP(aqm, AP_DOMAINS); unsigned long adm_max; - DECLARE_BITMAP(adm, 256); + DECLARE_BITMAP(adm, AP_DOMAINS); }; /**