From nobody Mon Nov 25 22:34:20 2024 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 CED8A17B4F6; Thu, 24 Oct 2024 06:26:44 +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=1729751207; cv=none; b=XM0XwnWI48uRYue+O/bWl/sICEqPGTG3vkQiGKnESC7MrnUpsh9hSo8d5jSZkwBDiIF7cNvTmDIbnzN4FMUmH7XA2UMsE1WHJJEMukq7WB3xyGE+kWz7oQHgQHoBAvGSSVxwrmh6yYZ9eQOju98FN0t8mX9XXB4lEn3n8dp7TeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729751207; c=relaxed/simple; bh=wgCrqlRXi3O+Ks3dP6PikYK5HnEOZ8qwzAQBgQqI7dc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IQrUe51pxofvfJWlbHmgwFh7bbrqUDsPdw4SlXAW51IHXFXvsWZxL/kD0+BuBG6g+BnGyA3NgNFO9ho3RlzAlUWCQ5VLHp6BBMD9AZx9ScC1rbv6B5UJc9Ucqpp9WN0uzm4eKHV2R8wxHt+juOG7ifL98PwXQ5YtfDcgiCdshtc= 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=L3XMMOUS; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="L3XMMOUS" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49O3oWYC016802; Thu, 24 Oct 2024 06:26:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=gEjBgVIEcXC0tXkQs qUuxD/tNu7I2RdQzakrVk9yCmE=; b=L3XMMOUSm5w6R5sQ6WvXoG+INvdqyoZZN ZakmdFERKeQjXK1HyczwSmf22cvWkduM4xIDDhhWbMY/xv4LPie2IbufOBTMU9mo QnPAsPLtDhZTcnvcomtCksdudg2kNtGwrgFmr5Wz1+CEhQY0e9abZj0Nk7WS07i4 P1LC8WeECOOTHSmh2ChgZQiC9daaz+sekPUoTObLxc/HlMAzfvZetzqu67ybeKfF OXX4aeHAhTUtQaa+IyCR9iTUSZHMuYcSNLQ9gh+19fwNXt3sVfwMJRWYA2tyvJM3 PIokS0AbLzGRxHTUPJgO4VlC9AD5IzzJGbGEtetaa+KwBkarZZ5dQ== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 42emajptbw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:43 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 49O2jVnD014771; Thu, 24 Oct 2024 06:26:43 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 42emhfpxeu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:43 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49O6Qdkc33686132 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2024 06:26:39 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 184A120040; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EDFDC2004E; Thu, 24 Oct 2024 06:26:38 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Oct 2024 06:26:38 +0000 (GMT) From: Steffen Eiden To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Cc: Ingo Franzki , Harald Freudenberger , Christoph Schlameuss , Janosch Frank , Claudio Imbrenda Subject: [PATCH v5 1/6] s390/uv: Use a constant for more-data rc Date: Thu, 24 Oct 2024 08:26:33 +0200 Message-ID: <20241024062638.1465970-2-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024062638.1465970-1-seiden@linux.ibm.com> References: <20241024062638.1465970-1-seiden@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: NS9lZUbLDUxpEbKN2I_p-CR1KzJZ5qx4 X-Proofpoint-GUID: NS9lZUbLDUxpEbKN2I_p-CR1KzJZ5qx4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 mlxscore=0 phishscore=0 priorityscore=1501 suspectscore=0 impostorscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=746 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410240042 Content-Type: text/plain; charset="utf-8" Add a define for the UVC rc 0x0100 that indicates that a UV-call was successful but may serve more data if called with a larger buffer again. Reviewed-by: Claudio Imbrenda Reviewed-by: Janosch Frank Reviewed-by: Christoph Schlameuss Signed-off-by: Steffen Eiden --- arch/s390/boot/uv.c | 4 ++-- arch/s390/include/asm/uv.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/s390/boot/uv.c b/arch/s390/boot/uv.c index 318e6ba95bfd..2a71e759dc42 100644 --- a/arch/s390/boot/uv.c +++ b/arch/s390/boot/uv.c @@ -22,8 +22,8 @@ void uv_query_info(void) if (!test_facility(158)) return; =20 - /* rc=3D=3D0x100 means that there is additional data we do not process */ - if (uv_call(0, (uint64_t)&uvcb) && uvcb.header.rc !=3D 0x100) + /* Ignore that there might be more data we do not process */ + if (uv_call(0, (uint64_t)&uvcb) && uvcb.header.rc !=3D UVC_RC_MORE_DATA) return; =20 if (IS_ENABLED(CONFIG_KVM)) { diff --git a/arch/s390/include/asm/uv.h b/arch/s390/include/asm/uv.h index 153d93468b77..94ff58336e8e 100644 --- a/arch/s390/include/asm/uv.h +++ b/arch/s390/include/asm/uv.h @@ -28,6 +28,7 @@ #define UVC_RC_INV_STATE 0x0003 #define UVC_RC_INV_LEN 0x0005 #define UVC_RC_NO_RESUME 0x0007 +#define UVC_RC_MORE_DATA 0x0100 #define UVC_RC_NEED_DESTROY 0x8000 =20 #define UVC_CMD_QUI 0x0001 --=20 2.45.2 From nobody Mon Nov 25 22:34:20 2024 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 8236117E016; Thu, 24 Oct 2024 06:26:45 +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=1729751208; cv=none; b=D6/DRjXBLfqHKJKvBm08+abCj0QV+TJL2xx2NQBv9J7zwcGRPaVPyGBlKytsutonpTQJGcZBdYFVtmR3g5y5B8iEZRORXRIyGPjbCukyvTWKSJtpaDGlGicUfJ51TvgqBPP3c/prVwyJCTFTLvS0DaZDreMSE4B5LgmBjoL+tA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729751208; c=relaxed/simple; bh=k9OKe48qASrXfyx949DVS+U/DUt07afEMHXpcHHAUjA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eo7iOzzTbaAkUPKynsVxvNDxaCUT9w2uRyA1qmEQ8K2E2LlO64Cc8HxbP3V9/0UnJY9iia0JsxBC9ch8DTtLooBJ8sNVCpJAJFgy01ojCq8uwck7KA+EkYhsOYoePdDEb2fe/WQImxXEYRVIbhdAKGGUzk90VFqEcq8AAUBYTeg= 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=HnrgWN44; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="HnrgWN44" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49O0v5rD028145; Thu, 24 Oct 2024 06:26:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=pbDVWllb5Ued5pX1d Ab+ymjDkErCfAX4KoycJqg1iyQ=; b=HnrgWN44eAhucDxlxUGzoGn+R+sapX9Wl vfdYQEmBWsHScuMiW6y/xGwkvZ0iGI8RVCzaQrxUgIxdeYk/DaPv1zC5aW+brLPX 9t33kPMrT0dOIud8Ig1rBzFX8YWjkIUdykspk2t4MIt5x0pSepuOVbmPGnYA7PEU ycNXGr93pTS6QPCQea7Ei3nmi8qiKRZDhfzy9Rfo9NhQV9gO660K9A4LfmjKMN5u HeCO5/tUnmPK+0tpMCLt0tt98+pDs1Uid/BvDBxGcYLsR7HMCjabDjZBddA5RudD a3NTbuOVmfsvvkzyEczKuDLrnqxAD7O7G/BmuUcILgcWZyMY5tWlA== 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 42emafpw34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:44 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 49O2k2o9014565; Thu, 24 Oct 2024 06:26:43 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 42emk7xwvf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:43 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49O6Qdi011338206 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2024 06:26:39 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4205D20040; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1C02E20043; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) From: Steffen Eiden To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Cc: Ingo Franzki , Harald Freudenberger , Christoph Schlameuss , Janosch Frank , Claudio Imbrenda Subject: [PATCH v5 2/6] s390/uv: Retrieve UV secrets support Date: Thu, 24 Oct 2024 08:26:34 +0200 Message-ID: <20241024062638.1465970-3-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024062638.1465970-1-seiden@linux.ibm.com> References: <20241024062638.1465970-1-seiden@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: kyTHoP0RE64J3CdEzeyWa3IzKWRK1RYf X-Proofpoint-GUID: kyTHoP0RE64J3CdEzeyWa3IzKWRK1RYf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 mlxscore=0 mlxlogscore=702 adultscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 phishscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410240047 Content-Type: text/plain; charset="utf-8" Provide a kernel API to retrieve secrets from the UV secret store. Add two new functions: * `uv_get_secret_metadata` - get metadata for a given secret identifier * `uv_retrieve_secret` - get the secret value for the secret index With those two functions one can extract the secret for a given secret id, if the secret is retrievable. Reviewed-by: Christoph Schlameuss Signed-off-by: Steffen Eiden --- arch/s390/include/asm/uv.h | 136 ++++++++++++++++++++++++++++++++++++- arch/s390/kernel/uv.c | 129 ++++++++++++++++++++++++++++++++++- 2 files changed, 262 insertions(+), 3 deletions(-) diff --git a/arch/s390/include/asm/uv.h b/arch/s390/include/asm/uv.h index 94ff58336e8e..f063e21d898d 100644 --- a/arch/s390/include/asm/uv.h +++ b/arch/s390/include/asm/uv.h @@ -2,7 +2,7 @@ /* * Ultravisor Interfaces * - * Copyright IBM Corp. 2019, 2022 + * Copyright IBM Corp. 2019, 2024 * * Author(s): * Vasily Gorbik @@ -62,6 +62,7 @@ #define UVC_CMD_ADD_SECRET 0x1031 #define UVC_CMD_LIST_SECRETS 0x1033 #define UVC_CMD_LOCK_SECRETS 0x1034 +#define UVC_CMD_RETR_SECRET 0x1035 =20 /* Bits in installed uv calls */ enum uv_cmds_inst { @@ -95,6 +96,7 @@ enum uv_cmds_inst { BIT_UVC_CMD_ADD_SECRET =3D 29, BIT_UVC_CMD_LIST_SECRETS =3D 30, BIT_UVC_CMD_LOCK_SECRETS =3D 31, + BIT_UVC_CMD_RETR_SECRET =3D 33, }; =20 enum uv_feat_ind { @@ -318,7 +320,6 @@ struct uv_cb_dump_complete { * A common UV call struct for pv guests that contains a single address * Examples: * Add Secret - * List Secrets */ struct uv_cb_guest_addr { struct uv_cb_header header; @@ -327,6 +328,91 @@ struct uv_cb_guest_addr { u64 reserved28[4]; } __packed __aligned(8); =20 +#define UVC_RC_RETR_SECR_BUF_SMALL 0x0109 +#define UVC_RC_RETR_SECR_STORE_EMPTY 0x010f +#define UVC_RC_RETR_SECR_INV_IDX 0x0110 +#define UVC_RC_RETR_SECR_INV_SECRET 0x0111 + +struct uv_cb_retr_secr { + struct uv_cb_header header; + u64 reserved08[2]; + u16 secret_idx; + u16 reserved1a; + u32 buf_size; + u64 buf_addr; + u64 reserved28[4]; +} __packed __aligned(8); + +struct uv_cb_list_secrets { + struct uv_cb_header header; + u64 reserved08[2]; + u8 reserved18[6]; + u16 start_idx; + u64 list_addr; + u64 reserved28[4]; +} __packed __aligned(8); + +enum uv_secret_types { + UV_SECRET_INVAL =3D 0x0, + UV_SECRET_NULL =3D 0x1, + UV_SECRET_ASSOCIATION =3D 0x2, + UV_SECRET_PLAIN =3D 0x3, + UV_SECRET_AES_128 =3D 0x4, + UV_SECRET_AES_192 =3D 0x5, + UV_SECRET_AES_256 =3D 0x6, + UV_SECRET_AES_XTS_128 =3D 0x7, + UV_SECRET_AES_XTS_256 =3D 0x8, + UV_SECRET_HMAC_SHA_256 =3D 0x9, + UV_SECRET_HMAC_SHA_512 =3D 0xa, + /* 0x0b - 0x10 reserved */ + UV_SECRET_ECDSA_P256 =3D 0x11, + UV_SECRET_ECDSA_P384 =3D 0x12, + UV_SECRET_ECDSA_P521 =3D 0x13, + UV_SECRET_ECDSA_ED25519 =3D 0x14, + UV_SECRET_ECDSA_ED448 =3D 0x15, +}; + +/** + * uv_secret_list_item_hdr - UV secret metadata. + * @index: Index of the secret in the secret list. + * @type: Type of the secret. See `enum uv_secret_types`. + * @length: Length of the stored secret. + */ +struct uv_secret_list_item_hdr { + u16 index; + u16 type; + u32 length; +} __packed __aligned(8); + +#define UV_SECRET_ID_LEN 32 +/** + * uv_secret_list_item - UV secret entry. + * @hdr: The metadata of this secret. + * @id: The ID of this secret, not the secret itself. + */ +struct uv_secret_list_item { + struct uv_secret_list_item_hdr hdr; + u64 reserverd08; + u8 id[UV_SECRET_ID_LEN]; +} __packed __aligned(8); + +/** + * uv_secret_list - UV secret-metadata list. + * @num_secr_stored: Number of secrets stored in this list. + * @total_num_secrets: Number of secrets stored in the UV for this guest. + * @next_secret_idx: positive number if there are more secrets available o= r zero. + * @secrets: Up to 85 UV-secret metadata entries. + */ +struct uv_secret_list { + u16 num_secr_stored; + u16 total_num_secrets; + u16 next_secret_idx; + u16 reserved_06; + u64 reserved_08; + struct uv_secret_list_item secrets[85]; +} __packed __aligned(8); +static_assert(sizeof(struct uv_secret_list) =3D=3D PAGE_SIZE); + static inline int __uv_call(unsigned long r1, unsigned long r2) { int cc; @@ -383,6 +469,48 @@ static inline int uv_cmd_nodata(u64 handle, u16 cmd, u= 16 *rc, u16 *rrc) return cc ? -EINVAL : 0; } =20 +/** + * uv_list_secrets() - Do a List Secrets UVC. + * + * @buf: Buffer to write list into; size of one page. + * @start_idx: The smallest index that should be included in the list. + * For the fist invocation use 0. + * @rc: Pointer to store the return code or NULL. + * @rrc: Pointer to store the return reason code or NULL. + * + * This function calls the List Secrets UVC. The result is written into `= buf`, + * that needs to be at least one page of writable memory. + * `buf` consists of: + * * %struct uv_secret_list_hdr + * * %struct uv_secret_list_item (multiple) + * + * For `start_idx` use _0_ for the first call. If there are more secrets = available + * but could not fit into the page then `rc` is `UVC_RC_MORE_DATA`. + * In this case use `uv_secret_list_hdr.next_secret_idx` for `start_idx`. + * + * Context: might sleep. + * + * Return: The UVC condition code. + */ +static inline int uv_list_secrets(struct uv_secret_list *buf, u16 start_id= x, + u16 *rc, u16 *rrc) +{ + struct uv_cb_list_secrets uvcb =3D { + .header.len =3D sizeof(uvcb), + .header.cmd =3D UVC_CMD_LIST_SECRETS, + .start_idx =3D start_idx, + .list_addr =3D (u64)buf, + }; + int cc =3D uv_call_sched(0, (u64)&uvcb); + + if (rc) + *rc =3D uvcb.header.rc; + if (rrc) + *rrc =3D uvcb.header.rrc; + + return cc; +} + struct uv_info { unsigned long inst_calls_list[4]; unsigned long uv_base_stor_len; @@ -469,6 +597,10 @@ static inline int uv_remove_shared(unsigned long addr) return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS); } =20 +int uv_get_secret_metadata(const u8 secret_id[UV_SECRET_ID_LEN], + struct uv_secret_list_item_hdr *secret); +int uv_retrieve_secret(u16 secret_idx, u8 *buf, size_t buf_size); + extern int prot_virt_host; =20 static inline int is_prot_virt_host(void) diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index 9646f773208a..cb9cb3f47471 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -2,7 +2,7 @@ /* * Common Ultravisor functions and initialization * - * Copyright IBM Corp. 2019, 2020 + * Copyright IBM Corp. 2019, 2024 */ #define KMSG_COMPONENT "prot_virt" #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt @@ -787,3 +787,130 @@ static int __init uv_info_init(void) return rc; } device_initcall(uv_info_init); + +/* + * Find the secret with the secret_id in the provided list. + * + * Context: might sleep. + */ +static int find_secret_in_page(const u8 secret_id[UV_SECRET_ID_LEN], + const struct uv_secret_list *list, + struct uv_secret_list_item_hdr *secret) +{ + u16 i; + + for (i =3D 0; i < list->total_num_secrets; i++) { + if (memcmp(secret_id, list->secrets[i].id, UV_SECRET_ID_LEN) =3D=3D 0) { + *secret =3D list->secrets[i].hdr; + return 0; + } + } + return -ENOENT; +} + +/* + * Do the actual search for `uv_get_secret_metadata`. + * + * Context: might sleep. + */ +static int find_secret(const u8 secret_id[UV_SECRET_ID_LEN], + struct uv_secret_list *list, + struct uv_secret_list_item_hdr *secret) +{ + u16 start_idx =3D 0; + u16 list_rc; + int ret; + + do { + uv_list_secrets(list, start_idx, &list_rc, NULL); + if (list_rc !=3D UVC_RC_EXECUTED && list_rc !=3D UVC_RC_MORE_DATA) { + if (list_rc =3D=3D UVC_RC_INV_CMD) + return -ENODEV; + else + return -EIO; + } + ret =3D find_secret_in_page(secret_id, list, secret); + if (ret =3D=3D 0) + return ret; + start_idx =3D list->next_secret_idx; + } while (list_rc =3D=3D UVC_RC_MORE_DATA && start_idx < list->next_secret= _idx); + + return -ENOENT; +} + +/** + * uv_get_secret_metadata() - get secret metadata for a given secret id. + * @secret_id: search pattern. + * @secret: output data, containing the secret's metadata. + * + * Search for a secret with the given secret_id in the Ultravisor secret s= tore. + * + * Context: might sleep. + * + * Return: + * * %0: - Found entry; secret->idx and secret->type are valid. + * * %ENOENT - No entry found. + * * %ENODEV: - Not supported: UV not available or command not available. + * * %EIO: - Other unexpected UV error. + */ +int uv_get_secret_metadata(const u8 secret_id[UV_SECRET_ID_LEN], + struct uv_secret_list_item_hdr *secret) +{ + struct uv_secret_list *buf; + int rc; + + buf =3D kzalloc(sizeof(*buf), GFP_KERNEL); + if (!buf) + return -ENOMEM; + rc =3D find_secret(secret_id, buf, secret); + kfree(buf); + return rc; +} +EXPORT_SYMBOL_GPL(uv_get_secret_metadata); + +/** + * uv_retrieve_secret() - get the secret value for the secret index. + * @secret_idx: Secret index for which the secret should be retrieved. + * @buf: Buffer to store retrieved secret. + * @buf_size: Size of the buffer. The correct buffer size is reported as p= art of + * the result from `uv_get_secret_metadata`. + * + * Calls the Retrieve Secret UVC and translates the UV return code into an= errno. + * + * Context: might sleep. + * + * Return: + * * %0 - Entry found; buffer contains a valid secret. + * * %ENOENT: - No entry found or secret at the index is non-retrievable. + * * %ENODEV: - Not supported: UV not available or command not available. + * * %EINVAL: - Buffer too small for content. + * * %EIO: - Other unexpected UV error. + */ +int uv_retrieve_secret(u16 secret_idx, u8 *buf, size_t buf_size) +{ + struct uv_cb_retr_secr uvcb =3D { + .header.len =3D sizeof(uvcb), + .header.cmd =3D UVC_CMD_RETR_SECRET, + .secret_idx =3D secret_idx, + .buf_addr =3D (u64)buf, + .buf_size =3D buf_size, + }; + + uv_call_sched(0, (u64)&uvcb); + + switch (uvcb.header.rc) { + case UVC_RC_EXECUTED: + return 0; + case UVC_RC_INV_CMD: + return -ENODEV; + case UVC_RC_RETR_SECR_STORE_EMPTY: + case UVC_RC_RETR_SECR_INV_SECRET: + case UVC_RC_RETR_SECR_INV_IDX: + return -ENOENT; + case UVC_RC_RETR_SECR_BUF_SMALL: + return -EINVAL; + default: + return -EIO; + } +} +EXPORT_SYMBOL_GPL(uv_retrieve_secret); --=20 2.45.2 From nobody Mon Nov 25 22:34:20 2024 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 CEDDB17DFE3; Thu, 24 Oct 2024 06:26:44 +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=1729751208; cv=none; b=jQUtT0P1vFrXsuDe8tQ2MtxfEHQ6ebIDmkSQmpmlddLljzq/R10fCFPQcEc2yN90d/AepgcRzfr7GC7mF2ieD11HJ1Mi2Wkb2jRfKJRtBoAcbwC1aGwujajdnLONyOnKdvY7TDVNo/f2jRI5kVPWlEqIC/rVD6O72p7rzZln4SY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729751208; c=relaxed/simple; bh=nfk7dt65jJjWZmAtFjmFG6B7l/XhyncOEeN6Nappz88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TeSdvgnWqm/npL06zxE1JT5j82HCBS1FGJBMfa5IhHVleSJglIPvCf6ITkaEsYvNGAsUeC3xy1fe6zBEwj9FiRgb1JM8bCO97W8zavm6lEs/pGBGQdtD7QqcmMmtA5fYIASv2YsO1sOBOFQTvcNvn7O9Uqgpu1OFOAJwJRYGrvs= 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=KusW2nYV; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="KusW2nYV" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49O0vFdN025385; Thu, 24 Oct 2024 06:26:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=S72ioC8n+E+bZYJOU ZR5Re6bzpqAkyOB+MQF1/vD8z8=; b=KusW2nYVPbh1+OVcf0QlniJbP4cjjKpc8 u7CrbBpknuGHYQocxhI0iMRJTz9a/p6aBJ8ADNP2cXqm/6zu/eECOGqPx1E6zXKj O6qH/XSmXLe7ZSZT7Xeiu/6N7BtfjBQLfHMKVD+tN+PXJ7hoNi5tJRZnkz8opUFF Ay4pIm6i+VT1MYbE1TfpGL3VAPDPg5sHWd8qW4XEYTiuFBEFkXAtLGxdL4bLHDH7 TXecsCWVLt9zLjvzHQxBk9wWXPGPeSUTLmgft8kwcQCjMrj+e66b9JY96pQbVpZQ 3j7uTUhVA9mBr5c7V8BnhsAipuzLUnBIdIFCsnPOe9Cvy3XpPphBg== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 42emaext7v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:43 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 49O2URkO001552; Thu, 24 Oct 2024 06:26:42 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 42emk9ewya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:42 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49O6QdVA11338208 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2024 06:26:39 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 637BC20043; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4603A2004B; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) From: Steffen Eiden To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Cc: Ingo Franzki , Harald Freudenberger , Christoph Schlameuss , Janosch Frank , Claudio Imbrenda Subject: [PATCH v5 3/6] s390/uvdevice: Add Retrieve Secret IOCTL Date: Thu, 24 Oct 2024 08:26:35 +0200 Message-ID: <20241024062638.1465970-4-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024062638.1465970-1-seiden@linux.ibm.com> References: <20241024062638.1465970-1-seiden@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: UskAVhvoO-Ar2qZTkE_4FmdAbj6DZc9i X-Proofpoint-ORIG-GUID: UskAVhvoO-Ar2qZTkE_4FmdAbj6DZc9i X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 phishscore=0 spamscore=0 mlxscore=0 mlxlogscore=847 priorityscore=1501 suspectscore=0 clxscore=1015 impostorscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410240042 Content-Type: text/plain; charset="utf-8" Add a new IOCL number to support the new Retrieve Secret UVC for user-space. User-space provides the index of the secret (u16) to retrieve. The uvdevice calls the Retrieve Secret UVC and copies the secret into the provided buffer if it fits. To get the secret type, index, and size user-space needs to call the List UVC first. Reviewed-by: Christoph Schlameuss Reviewed-by: Janosch Frank Signed-off-by: Steffen Eiden --- arch/s390/include/uapi/asm/uvdevice.h | 6 ++- drivers/s390/char/uvdevice.c | 58 ++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/arch/s390/include/uapi/asm/uvdevice.h b/arch/s390/include/uapi= /asm/uvdevice.h index b9c2f14a6af3..2ee5bfc61800 100644 --- a/arch/s390/include/uapi/asm/uvdevice.h +++ b/arch/s390/include/uapi/asm/uvdevice.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* - * Copyright IBM Corp. 2022 + * Copyright IBM Corp. 2022, 2024 * Author(s): Steffen Eiden */ #ifndef __S390_ASM_UVDEVICE_H @@ -71,6 +71,7 @@ struct uvio_uvdev_info { #define UVIO_ATT_ADDITIONAL_MAX_LEN 0x8000 #define UVIO_ADD_SECRET_MAX_LEN 0x100000 #define UVIO_LIST_SECRETS_LEN 0x1000 +#define UVIO_RETR_SECRET_MAX_LEN 0x2000 =20 #define UVIO_DEVICE_NAME "uv" #define UVIO_TYPE_UVC 'u' @@ -81,6 +82,7 @@ enum UVIO_IOCTL_NR { UVIO_IOCTL_ADD_SECRET_NR, UVIO_IOCTL_LIST_SECRETS_NR, UVIO_IOCTL_LOCK_SECRETS_NR, + UVIO_IOCTL_RETR_SECRET_NR, /* must be the last entry */ UVIO_IOCTL_NUM_IOCTLS }; @@ -91,6 +93,7 @@ enum UVIO_IOCTL_NR { #define UVIO_IOCTL_ADD_SECRET UVIO_IOCTL(UVIO_IOCTL_ADD_SECRET_NR) #define UVIO_IOCTL_LIST_SECRETS UVIO_IOCTL(UVIO_IOCTL_LIST_SECRETS_NR) #define UVIO_IOCTL_LOCK_SECRETS UVIO_IOCTL(UVIO_IOCTL_LOCK_SECRETS_NR) +#define UVIO_IOCTL_RETR_SECRET UVIO_IOCTL(UVIO_IOCTL_RETR_SECRET_NR) =20 #define UVIO_SUPP_CALL(nr) (1ULL << (nr)) #define UVIO_SUPP_UDEV_INFO UVIO_SUPP_CALL(UVIO_IOCTL_UDEV_INFO_NR) @@ -98,5 +101,6 @@ enum UVIO_IOCTL_NR { #define UVIO_SUPP_ADD_SECRET UVIO_SUPP_CALL(UVIO_IOCTL_ADD_SECRET_NR) #define UVIO_SUPP_LIST_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LIST_SECRETS_NR) #define UVIO_SUPP_LOCK_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LOCK_SECRETS_NR) +#define UVIO_SUPP_RETR_SECRET UVIO_SUPP_CALL(UVIO_IOCTL_RETR_SECRET_NR) =20 #endif /* __S390_ASM_UVDEVICE_H */ diff --git a/drivers/s390/char/uvdevice.c b/drivers/s390/char/uvdevice.c index f598edc5f251..1f90976293e8 100644 --- a/drivers/s390/char/uvdevice.c +++ b/drivers/s390/char/uvdevice.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright IBM Corp. 2022 + * Copyright IBM Corp. 2022, 2024 * Author(s): Steffen Eiden * * This file provides a Linux misc device to give userspace access to some @@ -40,6 +40,7 @@ static const u32 ioctl_nr_to_uvc_bit[] __initconst =3D { [UVIO_IOCTL_ADD_SECRET_NR] =3D BIT_UVC_CMD_ADD_SECRET, [UVIO_IOCTL_LIST_SECRETS_NR] =3D BIT_UVC_CMD_LIST_SECRETS, [UVIO_IOCTL_LOCK_SECRETS_NR] =3D BIT_UVC_CMD_LOCK_SECRETS, + [UVIO_IOCTL_RETR_SECRET_NR] =3D BIT_UVC_CMD_RETR_ATTEST, }; =20 static_assert(ARRAY_SIZE(ioctl_nr_to_uvc_bit) =3D=3D UVIO_IOCTL_NUM_IOCTLS= ); @@ -379,6 +380,58 @@ static int uvio_lock_secrets(struct uvio_ioctl_cb *ioc= tl) return 0; } =20 +/** + * uvio_retr_secret() - perform a retrieve secret UVC. + * @uv_ioctl: ioctl control block. + * + * uvio_retr_secret() performs the Retrieve Secret Ultravisor Call. + * The first two bytes of the argument specify the index of the secret to = be + * retrieved. The retrieved secret is copied into the argument buffer if t= here + * is enough space. + * The argument length must be at least two bytes and at max 8192 bytes. + * + * Context: might sleep. + * + * Return: 0 on success or a negative error code on error. + */ +static int uvio_retr_secret(struct uvio_ioctl_cb *uv_ioctl) +{ + u16 __user *user_index =3D (u16 __user *)uv_ioctl->argument_addr; + struct uv_cb_retr_secr uvcb =3D { + .header.len =3D sizeof(uvcb), + .header.cmd =3D UVC_CMD_RETR_SECRET, + }; + u32 buf_len =3D uv_ioctl->argument_len; + void *buf =3D NULL; + int ret; + + if (buf_len > UVIO_RETR_SECRET_MAX_LEN || buf_len < sizeof(*user_index)) + return -EINVAL; + + buf =3D kvzalloc(buf_len, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret =3D -EFAULT; + if (get_user(uvcb.secret_idx, user_index)) + goto err; + + uvcb.buf_addr =3D (u64)buf; + uvcb.buf_size =3D buf_len; + uv_call_sched(0, (u64)&uvcb); + + if (copy_to_user((__user void *)uv_ioctl->argument_addr, buf, buf_len)) + goto err; + + ret =3D 0; + uv_ioctl->uv_rc =3D uvcb.header.rc; + uv_ioctl->uv_rrc =3D uvcb.header.rrc; + +err: + kvfree_sensitive(buf, buf_len); + return ret; +} + static int uvio_copy_and_check_ioctl(struct uvio_ioctl_cb *ioctl, void __u= ser *argp, unsigned long cmd) { @@ -432,6 +485,9 @@ static long uvio_ioctl(struct file *filp, unsigned int = cmd, unsigned long arg) case UVIO_IOCTL_LOCK_SECRETS_NR: ret =3D uvio_lock_secrets(&uv_ioctl); break; + case UVIO_IOCTL_RETR_SECRET_NR: + ret =3D uvio_retr_secret(&uv_ioctl); + break; default: ret =3D -ENOIOCTLCMD; break; --=20 2.45.2 From nobody Mon Nov 25 22:34:20 2024 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 1695817DFE4; Thu, 24 Oct 2024 06:26:44 +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=1729751207; cv=none; b=u/BFxBgLwFgsADTU/1bvWmS81MMxNIc2ahRbGoPhZk2IQ0Jt8Lmc4OqqLuIku9DAGDU/GV8mcZn4SrBdGM5J0XnuY60TuxqNqjNQayTU7rQdsELaPO1WFS6v2pwcT+IJqZ2FUneuCyE2zL7ewTRoA/F8jqWV8Ale/U/nVhd3AM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729751207; c=relaxed/simple; bh=rJYwvQYBiSxFwPdqoxzExDV58GG+tnThnCjc+M2GuE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nfe7WNAcOVAHvD+mP8btGn1r6Je1Z5kv14UQor5n7vvttsT/DAmd8Sp24G2dhvwDJAZM0MYOs5SCCtTJiIGEw9tmOkK8jqIa5xDE2uWZjPSgoCInNOcy5rtlIt61aW89pL97X7x1VHA1BjbzePN2SzLW//pPH94jEOQSwUhRz38= 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=WwJ9DNix; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="WwJ9DNix" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49O3H2tZ014753; Thu, 24 Oct 2024 06:26:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=FaPJQ3yGMCmB2/AaG NKAyEdAEMsaUgUtuU3RAg7gRvo=; b=WwJ9DNixFwsrQ7PGH7m1kZ1lVT8ET78Ig tLujqo+3lMJ0HuZBVGPmps4RlDxIzApri9BNnUZRuLaGpLcZ7HQhPa3av5nMA1g/ pPOeOM2Jp5TZ0Y4qxfOdDH6e/uKGDn0ck/aymF5ugik0gCxLVsBSilTKzDeAstoD mBx5Ti84ssqb47biBQf1cr9I5F2sCbPUYWF23LIoGgfcAl2sg8AjLPCODhzme2pH 6Jol5sG0ciXxu93zNKC3eEN0GD6MTJQ+N8+6z4M0BwWGbKN521k/yvJduITEEdaa r3c9ijonNqivyT4CS7xQ/35fvRwFasQnD8hcr2Zwj3xqEyCbp1o9A== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 42emadxx16-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:43 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 49O2Lk7r012632; Thu, 24 Oct 2024 06:26:43 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 42emhfeyw5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:42 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49O6QdVf11338210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2024 06:26:39 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 84EC920040; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 677342004E; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) From: Steffen Eiden To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Cc: Ingo Franzki , Harald Freudenberger , Christoph Schlameuss , Janosch Frank , Claudio Imbrenda Subject: [PATCH v5 4/6] s390/uvdevice: Increase indent in IOCTL definitions Date: Thu, 24 Oct 2024 08:26:36 +0200 Message-ID: <20241024062638.1465970-5-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024062638.1465970-1-seiden@linux.ibm.com> References: <20241024062638.1465970-1-seiden@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: stM08yFFtOVYBlj9vE8er5Wmauyt2N3z X-Proofpoint-GUID: stM08yFFtOVYBlj9vE8er5Wmauyt2N3z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 phishscore=0 mlxlogscore=855 adultscore=0 spamscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410240047 Content-Type: text/plain; charset="utf-8" Increase the indentations in the IOCTL defines so that we will not have problems with upcoming, longer constant names. While at it, fix a minor typo. Reviewed-by: Janosch Frank Reviewed-by: Christoph Schlameuss Signed-off-by: Steffen Eiden --- arch/s390/include/uapi/asm/uvdevice.h | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/arch/s390/include/uapi/asm/uvdevice.h b/arch/s390/include/uapi= /asm/uvdevice.h index 2ee5bfc61800..4947f26ad9fb 100644 --- a/arch/s390/include/uapi/asm/uvdevice.h +++ b/arch/s390/include/uapi/asm/uvdevice.h @@ -52,7 +52,7 @@ struct uvio_uvdev_info { __u64 supp_uvio_cmds; /* * If bit `n` is set, the Ultravisor(UV) supports the UV-call - * corresponding to the IOCTL with nr `n` in the calling contextx (host + * corresponding to the IOCTL with nr `n` in the calling context (host * or guest). The value is only valid if the corresponding bit in * @supp_uvio_cmds is set as well. */ @@ -87,20 +87,20 @@ enum UVIO_IOCTL_NR { UVIO_IOCTL_NUM_IOCTLS }; =20 -#define UVIO_IOCTL(nr) _IOWR(UVIO_TYPE_UVC, nr, struct uvio_ioctl_cb) -#define UVIO_IOCTL_UVDEV_INFO UVIO_IOCTL(UVIO_IOCTL_UVDEV_INFO_NR) -#define UVIO_IOCTL_ATT UVIO_IOCTL(UVIO_IOCTL_ATT_NR) -#define UVIO_IOCTL_ADD_SECRET UVIO_IOCTL(UVIO_IOCTL_ADD_SECRET_NR) -#define UVIO_IOCTL_LIST_SECRETS UVIO_IOCTL(UVIO_IOCTL_LIST_SECRETS_NR) -#define UVIO_IOCTL_LOCK_SECRETS UVIO_IOCTL(UVIO_IOCTL_LOCK_SECRETS_NR) -#define UVIO_IOCTL_RETR_SECRET UVIO_IOCTL(UVIO_IOCTL_RETR_SECRET_NR) +#define UVIO_IOCTL(nr) _IOWR(UVIO_TYPE_UVC, nr, struct uvio_ioctl_cb) +#define UVIO_IOCTL_UVDEV_INFO UVIO_IOCTL(UVIO_IOCTL_UVDEV_INFO_NR) +#define UVIO_IOCTL_ATT UVIO_IOCTL(UVIO_IOCTL_ATT_NR) +#define UVIO_IOCTL_ADD_SECRET UVIO_IOCTL(UVIO_IOCTL_ADD_SECRET_NR) +#define UVIO_IOCTL_LIST_SECRETS UVIO_IOCTL(UVIO_IOCTL_LIST_SECRETS_NR) +#define UVIO_IOCTL_LOCK_SECRETS UVIO_IOCTL(UVIO_IOCTL_LOCK_SECRETS_NR) +#define UVIO_IOCTL_RETR_SECRET UVIO_IOCTL(UVIO_IOCTL_RETR_SECRET_NR) =20 -#define UVIO_SUPP_CALL(nr) (1ULL << (nr)) -#define UVIO_SUPP_UDEV_INFO UVIO_SUPP_CALL(UVIO_IOCTL_UDEV_INFO_NR) -#define UVIO_SUPP_ATT UVIO_SUPP_CALL(UVIO_IOCTL_ATT_NR) -#define UVIO_SUPP_ADD_SECRET UVIO_SUPP_CALL(UVIO_IOCTL_ADD_SECRET_NR) -#define UVIO_SUPP_LIST_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LIST_SECRETS_NR) -#define UVIO_SUPP_LOCK_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LOCK_SECRETS_NR) -#define UVIO_SUPP_RETR_SECRET UVIO_SUPP_CALL(UVIO_IOCTL_RETR_SECRET_NR) +#define UVIO_SUPP_CALL(nr) (1ULL << (nr)) +#define UVIO_SUPP_UDEV_INFO UVIO_SUPP_CALL(UVIO_IOCTL_UDEV_INFO_NR) +#define UVIO_SUPP_ATT UVIO_SUPP_CALL(UVIO_IOCTL_ATT_NR) +#define UVIO_SUPP_ADD_SECRET UVIO_SUPP_CALL(UVIO_IOCTL_ADD_SECRET_NR) +#define UVIO_SUPP_LIST_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LIST_SECRETS_NR) +#define UVIO_SUPP_LOCK_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LOCK_SECRETS_NR) +#define UVIO_SUPP_RETR_SECRET UVIO_SUPP_CALL(UVIO_IOCTL_RETR_SECRET_NR) =20 #endif /* __S390_ASM_UVDEVICE_H */ --=20 2.45.2 From nobody Mon Nov 25 22:34:20 2024 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 4386517DFFA; Thu, 24 Oct 2024 06:26:44 +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=1729751207; cv=none; b=GUeXeFxS20B1p1z/G5gG6VtV3VtjpKSL0by5Gy4mzjvmosm4KPnbnBTKxsRs3D2lP51zyHu0FRgzhSi7WX+9pBpFzuRvdPO+hOo/vYJ2vSij/xjV/QR6xQQqpF5O2NV8CR+K8BMwiVZNZhPO+X+AFC37qZybsnkyOrk8r4w8hjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729751207; c=relaxed/simple; bh=1KkESMt5nX8qLBtTcLLK0YPTJA1gbHkCobsq0cGqTzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YTCrwt6nsQnQu1COBI8o1VrCfSle/PojV2meygpwKrFKbMomC/nX3jGLUi6yTWLx7qLrovV7GtV/iug1rRMCgr3n1Pu7ruJRzVvfDWq1tvHOdQz2w/FH2oKdFgrFstF+W0uIl0pJFyBs5kwALvhulecswVmvLSOXdFk2emFa/Z0= 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=igNbKiWi; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="igNbKiWi" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49O0CcJJ016697; Thu, 24 Oct 2024 06:26:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=29uaGzJYl98LzQTOv bO+GVD9MSdAKJ25Ib3Hl0r155A=; b=igNbKiWiy5MAubEbt2Lh7rWII2rcDOLha k83vm1tavTlXfNQnwcifbhf5wPvu07CCXaXL8W4Gs2tBxwZdWlNy42pImccW6DHu Suvu8entnSMoDDZsxbPyv3y1pzi/oUPMAlhWiswfzP09GhGHJACeQ0rKUU1Feo6l m79hPWuyQvuqoVxES9AN0D5y7PcygDrdjpaiKDLdjVovaFdeYoEcE4+Cls46pDhh p6s1KDFpnYXfvaBgoFez5XdjVjF0rYXlZnbXW3QqynIa/JVIFIc5Hun87voi8guu NHxMw8J06X/SkJ+zwfHc/wop4KBM8zXfLaLPb+BYOPpx4Lvo4bczA== 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 42emajptbx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:43 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 49O2abEh008851; Thu, 24 Oct 2024 06:26:43 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 42emkapxy9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:43 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49O6QdCS11338212 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2024 06:26:39 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AFA4720043; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 88DE72004B; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) From: Steffen Eiden To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Cc: Ingo Franzki , Harald Freudenberger , Christoph Schlameuss , Janosch Frank , Claudio Imbrenda Subject: [PATCH v5 5/6] s390/uvdevice: Add List Secrets Ext IOCTL Date: Thu, 24 Oct 2024 08:26:37 +0200 Message-ID: <20241024062638.1465970-6-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024062638.1465970-1-seiden@linux.ibm.com> References: <20241024062638.1465970-1-seiden@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: mqTdjN7l4-pjY9ERKOay5DJT2ZXp3NJS X-Proofpoint-GUID: mqTdjN7l4-pjY9ERKOay5DJT2ZXp3NJS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 mlxscore=0 phishscore=0 priorityscore=1501 suspectscore=0 impostorscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410240042 Content-Type: text/plain; charset="utf-8" Add an extended List Secrets IOCTL. In contrast to the first list IOCTL this accepts an index as the first two bytes of the provided page as an input. This index is then taken as the index offset for the list UVC to receive later entries for the list. While at it fix some kernel doc issues with the list function. Reviewed-by: Christoph Schlameuss Signed-off-by: Steffen Eiden --- arch/s390/include/uapi/asm/uvdevice.h | 4 ++ drivers/s390/char/uvdevice.c | 98 +++++++++++++++++++-------- 2 files changed, 74 insertions(+), 28 deletions(-) diff --git a/arch/s390/include/uapi/asm/uvdevice.h b/arch/s390/include/uapi= /asm/uvdevice.h index 4947f26ad9fb..1cfa4e17af03 100644 --- a/arch/s390/include/uapi/asm/uvdevice.h +++ b/arch/s390/include/uapi/asm/uvdevice.h @@ -72,6 +72,7 @@ struct uvio_uvdev_info { #define UVIO_ADD_SECRET_MAX_LEN 0x100000 #define UVIO_LIST_SECRETS_LEN 0x1000 #define UVIO_RETR_SECRET_MAX_LEN 0x2000 +#define UVIO_LIST_SECRETS_EXT_LEN UVIO_LIST_SECRETS_LEN =20 #define UVIO_DEVICE_NAME "uv" #define UVIO_TYPE_UVC 'u' @@ -83,6 +84,7 @@ enum UVIO_IOCTL_NR { UVIO_IOCTL_LIST_SECRETS_NR, UVIO_IOCTL_LOCK_SECRETS_NR, UVIO_IOCTL_RETR_SECRET_NR, + UVIO_IOCTL_LIST_SECRETS_EXT_NR, /* must be the last entry */ UVIO_IOCTL_NUM_IOCTLS }; @@ -94,6 +96,7 @@ enum UVIO_IOCTL_NR { #define UVIO_IOCTL_LIST_SECRETS UVIO_IOCTL(UVIO_IOCTL_LIST_SECRETS_NR) #define UVIO_IOCTL_LOCK_SECRETS UVIO_IOCTL(UVIO_IOCTL_LOCK_SECRETS_NR) #define UVIO_IOCTL_RETR_SECRET UVIO_IOCTL(UVIO_IOCTL_RETR_SECRET_NR) +#define UVIO_IOCTL_LIST_SECRETS_EXT UVIO_IOCTL(UVIO_IOCTL_LIST_SECRETS_EXT= _NR) =20 #define UVIO_SUPP_CALL(nr) (1ULL << (nr)) #define UVIO_SUPP_UDEV_INFO UVIO_SUPP_CALL(UVIO_IOCTL_UDEV_INFO_NR) @@ -102,5 +105,6 @@ enum UVIO_IOCTL_NR { #define UVIO_SUPP_LIST_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LIST_SECRETS_NR) #define UVIO_SUPP_LOCK_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LOCK_SECRETS_NR) #define UVIO_SUPP_RETR_SECRET UVIO_SUPP_CALL(UVIO_IOCTL_RETR_SECRET_NR) +#define UVIO_SUPP_LIST_SECRETS_EXT UVIO_SUPP_CALL(UVIO_IOCTL_LIST_SECRETS_= EXT_NR) =20 #endif /* __S390_ASM_UVDEVICE_H */ diff --git a/drivers/s390/char/uvdevice.c b/drivers/s390/char/uvdevice.c index 1f90976293e8..e28ddbe1b1a8 100644 --- a/drivers/s390/char/uvdevice.c +++ b/drivers/s390/char/uvdevice.c @@ -41,6 +41,7 @@ static const u32 ioctl_nr_to_uvc_bit[] __initconst =3D { [UVIO_IOCTL_LIST_SECRETS_NR] =3D BIT_UVC_CMD_LIST_SECRETS, [UVIO_IOCTL_LOCK_SECRETS_NR] =3D BIT_UVC_CMD_LOCK_SECRETS, [UVIO_IOCTL_RETR_SECRET_NR] =3D BIT_UVC_CMD_RETR_ATTEST, + [UVIO_IOCTL_LIST_SECRETS_EXT_NR] =3D BIT_UVC_CMD_LIST_SECRETS, }; =20 static_assert(ARRAY_SIZE(ioctl_nr_to_uvc_bit) =3D=3D UVIO_IOCTL_NUM_IOCTLS= ); @@ -297,8 +298,39 @@ static int uvio_add_secret(struct uvio_ioctl_cb *uv_io= ctl) return ret; } =20 -/** uvio_list_secrets() - perform a List Secret UVC - * @uv_ioctl: ioctl control block +/* + * The actual list(_ext) IOCTL. + * If list_ext is true, the first two bytes of the user buffer set the sta= rting + * index of the list-UVC. + */ +static int list_secrets(struct uvio_ioctl_cb *uv_ioctl, bool list_ext) +{ + void __user *user_buf_arg =3D (void __user *)uv_ioctl->argument_addr; + u16 __user *user_index =3D (u16 __user *)uv_ioctl->argument_addr; + u16 start_idx =3D 0; + struct uv_secret_list *secrets; + int ret =3D 0; + + BUILD_BUG_ON(UVIO_LIST_SECRETS_LEN !=3D PAGE_SIZE); + if (uv_ioctl->argument_len !=3D UVIO_LIST_SECRETS_LEN) + return -EINVAL; + /* The extended call accepts an u16 index as input */ + if (list_ext && get_user(start_idx, user_index)) + return -EFAULT; + secrets =3D (struct uv_secret_list *)get_zeroed_page(GFP_KERNEL); + if (!secrets) + return -ENOMEM; + uv_list_secrets(secrets, start_idx, &uv_ioctl->uv_rc, &uv_ioctl->uv_rrc); + if (copy_to_user(user_buf_arg, secrets, UVIO_LIST_SECRETS_LEN)) + ret =3D -EFAULT; + + free_page((unsigned long)secrets); + return ret; +} + +/** + * uvio_list_secrets() - perform a List Secret UVC. + * @uv_ioctl: ioctl control block. * * uvio_list_secrets() performs the List Secret Ultravisor Call. It verifi= es * that the given userspace argument address is valid and its size is sane. @@ -312,37 +344,13 @@ static int uvio_add_secret(struct uvio_ioctl_cb *uv_i= octl) * command rc. This won't be fenced in the driver and does not result in a * negative return value. * - * Context: might sleep + * Context: might sleep. * * Return: 0 on success or a negative error code on error. */ static int uvio_list_secrets(struct uvio_ioctl_cb *uv_ioctl) { - void __user *user_buf_arg =3D (void __user *)uv_ioctl->argument_addr; - struct uv_cb_guest_addr uvcb =3D { - .header.len =3D sizeof(uvcb), - .header.cmd =3D UVC_CMD_LIST_SECRETS, - }; - void *secrets =3D NULL; - int ret =3D 0; - - if (uv_ioctl->argument_len !=3D UVIO_LIST_SECRETS_LEN) - return -EINVAL; - - secrets =3D kvzalloc(UVIO_LIST_SECRETS_LEN, GFP_KERNEL); - if (!secrets) - return -ENOMEM; - - uvcb.addr =3D (u64)secrets; - uv_call_sched(0, (u64)&uvcb); - uv_ioctl->uv_rc =3D uvcb.header.rc; - uv_ioctl->uv_rrc =3D uvcb.header.rrc; - - if (copy_to_user(user_buf_arg, secrets, UVIO_LIST_SECRETS_LEN)) - ret =3D -EFAULT; - - kvfree(secrets); - return ret; + return list_secrets(uv_ioctl, false); } =20 /** uvio_lock_secrets() - perform a Lock Secret Store UVC @@ -432,6 +440,37 @@ static int uvio_retr_secret(struct uvio_ioctl_cb *uv_i= octl) return ret; } =20 +/** + * uvio_list_secrets_ext() - perform a List Secret UVC with a starting ind= ex. + * @uv_ioctl: ioctl control block. + * + * uvio_list_secrets_ext() performs the List Secret Ultravisor Call. It ve= rifies + * that the given userspace argument address is valid and its size is sane. + * Every other check is made by the Ultravisor (UV) and won't result in a + * negative return value. It builds the request, performs the UV-call, and + * copies the result to userspace. + * + * The argument specifies the location for the result of the UV-Call. + * The first two bytes of the argument specify the starting index of the l= ist. + * This should be zero for the first IOCTL. If UV reports more data + * (rc UVC_RC_MORE_DATA) another list_ext IOCTL with a higher starting ind= ex + * shows the following entries of the secret list. Choose next_valid_index= from + * the list header as starting index for the list in the following IOCTLs = to + * get a continuous list without holes. + * + * If the List Secrets UV facility is not present, UV will return invalid + * command rc. This won't be fenced in the driver and does not result in a + * negative return value. + * + * Context: might sleep. + * + * Return: 0 on success or a negative error code on error. + */ +static int uvio_list_secrets_ext(struct uvio_ioctl_cb *uv_ioctl) +{ + return list_secrets(uv_ioctl, true); +} + static int uvio_copy_and_check_ioctl(struct uvio_ioctl_cb *ioctl, void __u= ser *argp, unsigned long cmd) { @@ -488,6 +527,9 @@ static long uvio_ioctl(struct file *filp, unsigned int = cmd, unsigned long arg) case UVIO_IOCTL_RETR_SECRET_NR: ret =3D uvio_retr_secret(&uv_ioctl); break; + case UVIO_IOCTL_LIST_SECRETS_EXT_NR: + ret =3D uvio_list_secrets_ext(&uv_ioctl); + break; default: ret =3D -ENOIOCTLCMD; break; --=20 2.45.2 From nobody Mon Nov 25 22:34:20 2024 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 B59BA184101; Thu, 24 Oct 2024 06:26:45 +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=1729751207; cv=none; b=lQ0c1bMosVA3US7rEKkRdxWGxXwD2leM9w5DArq6QFvG5lXZ4qcv8RfDCvAoiDvDO+qMm6oKvQKPiR5IdmOx0rW5gDGgNdykDCS/DYR/PkHMMyC/4kXRXxOVMQEB9xb0ExzSWSqEWChif7YoMFb2umBJA0TWtKmNnX7O2a2uC/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729751207; c=relaxed/simple; bh=wi7DrlcozzdfQQxbJz64FcJgeM+hzTWDnMjNyGx1qvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C/1SPjJ3oxg6fLQkOsVqcqs+6RU7pF0xCNvnTyhrhn9tlqGVvXfaPLfqNC0VbZ4N71XTs8TZ7aPlEkkpUPZ7wBwkMIZGVIf3+XmP8+b2lBTJO1Ev8Xu9ALHPr7anNiGVsbJvriN3p6EUlNGpsLbb3eoIP5whVq26Pq5sERjflQo= 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=XzjhfDM9; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="XzjhfDM9" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49O0e9u8012538; Thu, 24 Oct 2024 06:26:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=pNqU+806yrBGetf5b f5sG94MR4fWhoSVuIHkbtiUnkc=; b=XzjhfDM9a1oStwB2pk3tANbDnaQzKRqHj JISGnOX/niPh+/vA8vHxc35OpLJMSCdD6sRM6jdKfZGvnhdpa7Ly6t07ZycOgLgZ LuC39EQd5WerZ93biivWSq/TgcFBpdjpHxBux3a8qeXNTGkQO/k/y6+yRqqkulci rP/15caNt2LYh1cNEH0fhcpHnJLzGQY0Y3DqIgr8vUUKJmcrDvfmsjsc0b5aEcv3 JEgkrsZcHAPwmo/6OIRrRYhy2mv/jc20boLp6/Jb3Nup1ZkmrHPT6RGe9nLbu6O/ mLdlS8LAWigG90eg4ldJus3CO0hlRKmBdy4GeRo80Hs3DiP4iewUw== 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 42fbw411em-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:44 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 49O305KF014557; Thu, 24 Oct 2024 06:26:43 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 42emk7xwvj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 24 Oct 2024 06:26:43 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49O6QdGR33686138 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2024 06:26:40 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D0D5C20040; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B39F22004E; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 24 Oct 2024 06:26:39 +0000 (GMT) From: Steffen Eiden To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Cc: Ingo Franzki , Harald Freudenberger , Christoph Schlameuss , Janosch Frank , Claudio Imbrenda Subject: [PATCH v5 6/6] s390/uv: Retrieve UV secrets sysfs support Date: Thu, 24 Oct 2024 08:26:38 +0200 Message-ID: <20241024062638.1465970-7-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024062638.1465970-1-seiden@linux.ibm.com> References: <20241024062638.1465970-1-seiden@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 3PJcCV_PogiDJuU7nKS68LfHGZcPyFPU X-Proofpoint-GUID: 3PJcCV_PogiDJuU7nKS68LfHGZcPyFPU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 bulkscore=0 suspectscore=0 spamscore=0 phishscore=0 adultscore=0 priorityscore=1501 clxscore=1015 lowpriorityscore=0 malwarescore=0 mlxlogscore=863 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410240042 Content-Type: text/plain; charset="utf-8" Reflect the updated content in the query information UVC to the sysfs at /sys/firmware/query * new UV-query sysfs entry for the maximum number of retrievable secrets the UV can store for one secure guest. * new UV-query sysfs entry for the maximum number of association secrets the UV can store for one secure guest. * max_secrets contains the sum of max association and max retrievable secrets. Reviewed-by: Christoph Schlameuss Signed-off-by: Steffen Eiden --- arch/s390/boot/uv.c | 3 ++- arch/s390/include/asm/uv.h | 10 ++++++---- arch/s390/kernel/uv.c | 24 +++++++++++++++++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/arch/s390/boot/uv.c b/arch/s390/boot/uv.c index 2a71e759dc42..4568e8f81dac 100644 --- a/arch/s390/boot/uv.c +++ b/arch/s390/boot/uv.c @@ -46,7 +46,8 @@ void uv_query_info(void) uv_info.supp_add_secret_req_ver =3D uvcb.supp_add_secret_req_ver; uv_info.supp_add_secret_pcf =3D uvcb.supp_add_secret_pcf; uv_info.supp_secret_types =3D uvcb.supp_secret_types; - uv_info.max_secrets =3D uvcb.max_secrets; + uv_info.max_assoc_secrets =3D uvcb.max_assoc_secrets; + uv_info.max_retr_secrets =3D uvcb.max_retr_secrets; } =20 if (test_bit_inv(BIT_UVC_CMD_SET_SHARED_ACCESS, (unsigned long *)uvcb.ins= t_calls_list) && diff --git a/arch/s390/include/asm/uv.h b/arch/s390/include/asm/uv.h index f063e21d898d..0f8d107d678c 100644 --- a/arch/s390/include/asm/uv.h +++ b/arch/s390/include/asm/uv.h @@ -143,9 +143,10 @@ struct uv_cb_qui { u64 reservedf0; /* 0x00f0 */ u64 supp_add_secret_req_ver; /* 0x00f8 */ u64 supp_add_secret_pcf; /* 0x0100 */ - u64 supp_secret_types; /* 0x0180 */ - u16 max_secrets; /* 0x0110 */ - u8 reserved112[0x120 - 0x112]; /* 0x0112 */ + u64 supp_secret_types; /* 0x0108 */ + u16 max_assoc_secrets; /* 0x0110 */ + u16 max_retr_secrets; /* 0x0112 */ + u8 reserved114[0x120 - 0x114]; /* 0x0114 */ } __packed __aligned(8); =20 /* Initialize Ultravisor */ @@ -531,7 +532,8 @@ struct uv_info { unsigned long supp_add_secret_req_ver; unsigned long supp_add_secret_pcf; unsigned long supp_secret_types; - unsigned short max_secrets; + unsigned short max_assoc_secrets; + unsigned short max_retr_secrets; }; =20 extern struct uv_info uv_info; diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index cb9cb3f47471..5247c8b0cdff 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -696,12 +696,32 @@ static struct kobj_attribute uv_query_supp_secret_typ= es_attr =3D static ssize_t uv_query_max_secrets(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sysfs_emit(buf, "%d\n", uv_info.max_secrets); + return sysfs_emit(buf, "%d\n", + uv_info.max_assoc_secrets + uv_info.max_retr_secrets); } =20 static struct kobj_attribute uv_query_max_secrets_attr =3D __ATTR(max_secrets, 0444, uv_query_max_secrets, NULL); =20 +static ssize_t uv_query_max_retr_secrets(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%d\n", uv_info.max_retr_secrets); +} + +static struct kobj_attribute uv_query_max_retr_secrets_attr =3D + __ATTR(max_retr_secrets, 0444, uv_query_max_retr_secrets, NULL); + +static ssize_t uv_query_max_assoc_secrets(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%d\n", uv_info.max_assoc_secrets); +} + +static struct kobj_attribute uv_query_max_assoc_secrets_attr =3D + __ATTR(max_assoc_secrets, 0444, uv_query_max_assoc_secrets, NULL); + static struct attribute *uv_query_attrs[] =3D { &uv_query_facilities_attr.attr, &uv_query_feature_indications_attr.attr, @@ -719,6 +739,8 @@ static struct attribute *uv_query_attrs[] =3D { &uv_query_supp_add_secret_pcf_attr.attr, &uv_query_supp_secret_types_attr.attr, &uv_query_max_secrets_attr.attr, + &uv_query_max_assoc_secrets_attr.attr, + &uv_query_max_retr_secrets_attr.attr, NULL, }; =20 --=20 2.45.2