From nobody Tue Nov 26 11:21:18 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 C74871E6DEE; Fri, 18 Oct 2024 09:15:22 +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=1729242924; cv=none; b=mFYbxW6SF0g7rRGGfubMqKrUNgQ9WGjFkd9ni1t5pL1vBZGyG3yq5aYErggCQReMpuLk3Xnjq4HhQfZUdgt9TMAUQ+5G7reKkUtnCvfF5hVb2Xd2gyCImP6ejbMS/u5JHwIi80FaXK6YgZ/eSOWRYI+hecaL9ThkERGAcijvjJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729242924; c=relaxed/simple; bh=wgCrqlRXi3O+Ks3dP6PikYK5HnEOZ8qwzAQBgQqI7dc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pQQ7RfiwB4px+Paq8HYz5ItDe8GAGYlIKZLw3SB36H9FSc3xOXKRORuP/+eElSH3ukMnQV2VyK0ak1MJWcrPiC25Twj6Uwc0RG+nj5HZUTTySlS8J0nrAd2VWHVE4NIdbFbHL06+DkkIAf6kyyH1Q6kJCtK65aqzNHe5JJCIPi8= 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=Ynskq6xk; 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="Ynskq6xk" 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 49HJSBBK008056; Fri, 18 Oct 2024 09:15:21 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=Ynskq6xkASCzqB34m/gXOAQq9eubcZE0f y32lJA6C/tTvPEAxOKseJqDZgMlAJYHqThnIM9gIkYSgleLary/mZTn1Vkm6PQTL Pvgwq7pPHfRU13moSP4Sn7+qbrZXUyM2Zpe8GKS7qr/DprJFCYjV8hItDdpztBz+ ohv6/EhCDjdH9L3iFbbJXm399u5kGXtV3C/L6/HW1jPihz9U9dnhqIvXW69a1n14 I0dbMEm/AsNTFxbehdfWmYm2lEi1wf7r+9W12knBQ/4dtijC3MZsznSkd9a/uGEa fO6auoqHT901adYKfypxE4KK9JRf2HT/LI2Osh5SRK8fQM7+mItAw== 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 42as8a7f7g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:21 +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 49I61TLI006338; Fri, 18 Oct 2024 09:15:20 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 428651b6cd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:20 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49I9FHlT42729940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Oct 2024 09:15:17 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ED88D2004D; Fri, 18 Oct 2024 09:15:16 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE9542004F; Fri, 18 Oct 2024 09:15:16 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 18 Oct 2024 09:15:16 +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 v4 1/6] s390/boot/uv.c: Use a constant for more-data rc Date: Fri, 18 Oct 2024 11:15:11 +0200 Message-ID: <20241018091516.2167885-2-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018091516.2167885-1-seiden@linux.ibm.com> References: <20241018091516.2167885-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: q8UT5UVrFnjYgBmw4plyajuwe9BU4hWE X-Proofpoint-ORIG-GUID: q8UT5UVrFnjYgBmw4plyajuwe9BU4hWE 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 mlxscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=789 phishscore=0 adultscore=0 impostorscore=0 priorityscore=1501 spamscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410180056 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 Tue Nov 26 11:21:18 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 39A7E1E573B; Fri, 18 Oct 2024 09:15:22 +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=1729242925; cv=none; b=LuzC+7LuBlRjnyko0ISA3pZ12fmSET4Fa6xtbz3cOTjbxuzQTkiKNj580va50KrIz5gs0i46RLK/Ommq+vI2Qg3ERptakapJITiOydKWiB/N7XGW8j3rdKv2k/ZhNftQNa57nH6PkJpkpeaSG1BRkOJl9/ve7sgbEqQ8c9PQl20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729242925; c=relaxed/simple; bh=nBFmNvHPpK9UVOHXt7xhueBG55zBG34LuKpUCaOY2LI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dj73eF75S51N7aKUE+k/o3bv/XiUpxDXRB0aEqPBTlokJAtuQzOKmFCn9TvoDVMaiw5EW4cf9NTWyZxcpSKq/y8RO+XYJFJUSRhHAcdZyixJsz832fdqcoNJ0EIgzxbtvuOUMEkoriFmUUifUKyTNrIjkhvCofp2bSGYBWqYMd4= 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=K/RX7pmz; 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="K/RX7pmz" 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 49I97Ncl013979; Fri, 18 Oct 2024 09:15:22 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=knn0J2L77eZj6lG9A bPNZDm3HVRSfm4Xu42nZp1yAl0=; b=K/RX7pmzs8M98lcfIbva6pwiasxmEDnqw RH8g1Pz4gEjEbhwwOrFA9p8Y9hAsY0j54+5cDIZ3jGBmHOxPphDFJIuz+gnG62nf ERq1lsa/YPjT4TiNpfm+zECufjOFh4Xl/R80ikqmmIPSdllbUdSqRe9yfE+UNVSV 5GGSQyWdllk7ppVASiqEL2WtYol73vUvF6KJLFPfVDQJVDc4t3Zmf3JSiN+AGEE8 Mn1padKCmoHr2tQG5uAQRIM4G6EooMOxI6QBvnhtEWpWkpdXI6CQTLdXU0K2shMN kO8JwTb0amy0vYEea9AJKY1jTBaI2+SdZ1AFJJSWyxj8KK7Y3pshw== 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 42aqk2rdmn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:22 +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 49I8cTBp002452; Fri, 18 Oct 2024 09:15:21 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4284en3jqf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:20 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49I9FH2Y42729942 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Oct 2024 09:15:17 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 23A042004F; Fri, 18 Oct 2024 09:15:17 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F12A72004E; Fri, 18 Oct 2024 09:15:16 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 18 Oct 2024 09:15:16 +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 v4 2/6] s390/uv: Retrieve UV secrets support Date: Fri, 18 Oct 2024 11:15:12 +0200 Message-ID: <20241018091516.2167885-3-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018091516.2167885-1-seiden@linux.ibm.com> References: <20241018091516.2167885-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: qn6wRBzJI_SQs4hr02rRPhjlOHmpqSE_ X-Proofpoint-ORIG-GUID: qn6wRBzJI_SQs4hr02rRPhjlOHmpqSE_ 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 adultscore=0 mlxscore=0 spamscore=0 priorityscore=1501 phishscore=0 clxscore=1015 mlxlogscore=651 impostorscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410180056 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. Signed-off-by: Steffen Eiden Reviewed-by: Christoph Schlameuss --- arch/s390/include/asm/uv.h | 135 ++++++++++++++++++++++++++++++++++++- arch/s390/kernel/uv.c | 129 ++++++++++++++++++++++++++++++++++- 2 files changed, 261 insertions(+), 3 deletions(-) diff --git a/arch/s390/include/asm/uv.h b/arch/s390/include/asm/uv.h index 94ff58336e8e..bc61cf3e689b 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; +}; + +#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]; +}; + +/** + * 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,47 @@ 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(u8 *buf, u16 start_idx, u16 *rc, u16 *rr= c) +{ + 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 +596,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..588caf5d4f0c 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((u8 *)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 Tue Nov 26 11:21:18 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 BEFAF1E6311; Fri, 18 Oct 2024 09:15:22 +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=1729242924; cv=none; b=qzlsp4HJMGiImTLX9otW8sKiWWntNNbR6GFJnTGHYlWdtGWXqnkXCyUFUl7AjtVZ3cy5YD3InbdjNGtSb9PXhZYiOS4UZLeKxxxahhOqkpeFOEpoiAkAZVX/UkadyGBgMa6kSFf4M5Gh9MrFrvc7gndCyhsMUvlhI5p/5JHXE+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729242924; c=relaxed/simple; bh=nfk7dt65jJjWZmAtFjmFG6B7l/XhyncOEeN6Nappz88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PxcvjhRuc4Pt1B2k6tb2MoR+Srg9evbZDBNB149u3Yvo/Qc6sPdoFviOCpSzPShZeWQsqlYcW/a6ksHiD4nRmKVOpn50TobSvwZUiVS6XnubDWjsX+EU1ko61xNakEXBBveqOxpy5BO7UEaFjEppKzF4X9gTRqN0Po8JMN0eX9E= 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=hqp/QdfV; 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="hqp/QdfV" 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 49HJSjch015438; Fri, 18 Oct 2024 09:15:21 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=hqp/QdfVo5LKjJ0mXaNNuTXhdFdgYUon+ gBHiJ6qOX1gAS7T20tVei2Ptb4GwgkBsoUk9s3xCFQ5/NAFsjmX1ADs0hZG7+/B0 mfP/Er/xPHN1vGVOk1ATo9A4lm75kKpHffKCpCewk0ha04AI8ArZdtzC7B9jlw1b ffp54UWfoUWFiaVzdjHHsXl0wrrLfDAtEH+u69/7IpkhrFm4QBgfaH6GWXUOZ/NX 1W4yk5FYgMS7EZgj0emxZjgWeExU2Qfjri3v2gQpckOZlZNYEFAT/OYigJ7Sd844 nbxytlEGFGapuG/KRvI1TDLP4Uc8+C/L1ew4lr4Tb5nfrwJH54XHg== 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 42aqgr7t3p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:21 +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 49I7UkYh006663; Fri, 18 Oct 2024 09:15:20 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4283esbr6p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:20 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49I9FHLb42729944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Oct 2024 09:15:17 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 470302004D; Fri, 18 Oct 2024 09:15:17 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2821F2005A; Fri, 18 Oct 2024 09:15:17 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 18 Oct 2024 09:15:17 +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 v4 3/6] s390/uvdevice: Add Retrieve Secret IOCTL Date: Fri, 18 Oct 2024 11:15:13 +0200 Message-ID: <20241018091516.2167885-4-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018091516.2167885-1-seiden@linux.ibm.com> References: <20241018091516.2167885-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: slrt80rT1_rwY5gnSPtcP_6HRJkBDq53 X-Proofpoint-GUID: slrt80rT1_rwY5gnSPtcP_6HRJkBDq53 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 phishscore=0 mlxlogscore=849 malwarescore=0 clxscore=1015 lowpriorityscore=0 adultscore=0 spamscore=0 mlxscore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410180056 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 Tue Nov 26 11:21:18 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 C15281E6DDE; Fri, 18 Oct 2024 09:15:22 +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=1729242924; cv=none; b=B1cBN0akRKCD7luYGR3LIv1jhmmdxme+crgUIL1IIMwh1j1vM3oHO0hnx71SzcXEg75/w2bTPe4guUuc9bBo1pvV74YYEOztZkbOtXo7ujdUl+4ppCx++Zjf5XjgfAyxc3ytzav941BZOvc+U0LZRqOxRAtWaaYqpMX2Foaj844= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729242924; c=relaxed/simple; bh=rJYwvQYBiSxFwPdqoxzExDV58GG+tnThnCjc+M2GuE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y3ZZXb5iGa3RNqRFeiVnyr0A3Wwjtis7U12dhaEyvoFMsA1vuJYIOmWuV719nJVOFG+K8l8DvQSFM+GLL1WJAueSzTy5nVKn9NYVhK4vEzVlxkVQHe+poOHFB++FzqQP+IGQbgGR8jJCz9sc+2jmQTQvtBxrCzpV+b6iOqv5qUA= 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=kLJ4GYLC; 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="kLJ4GYLC" 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 49HJS9ms013923; Fri, 18 Oct 2024 09:15:22 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=kLJ4GYLCJXe9ZKrrwKqn8pMPMgHN8uFLx B453ZH7yWF6Tclt+W4Z4ozQSazYyarUFGSq0IJMHms103TM6JgrQONvXm1amCXFD khfvqhClFxX7Dm3oUBV/FP8a2WloQS7uOFyCbWh+mMoZPJvPljBmMlZpF7N39X+Y 6Ju3Rn/FeMb2wcuZXGlKUOo7u8trXfig6xAB/2wo3WuHJsIT6FxokgXWswpVsIBk GsJ0nMAictNuSunAjOZsBednlwSj2UviLaU+3OgPqKiblzuSPFt5M3DYSmEzYOUw kyf8CrnbJnHahi44ZWSakG31Wtu7YnEFiuoO06W6nml05am2WJKBA== 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 42aqk2rdmm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:21 +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 49I7DWHo006694; Fri, 18 Oct 2024 09:15:20 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4283esbr6q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:20 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49I9FHa039780614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Oct 2024 09:15:17 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 68FF22004F; Fri, 18 Oct 2024 09:15:17 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4AFE32004E; Fri, 18 Oct 2024 09:15:17 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 18 Oct 2024 09:15:17 +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 v4 4/6] s390/uvdevice: Increase indent in IOCTL definitions Date: Fri, 18 Oct 2024 11:15:14 +0200 Message-ID: <20241018091516.2167885-5-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018091516.2167885-1-seiden@linux.ibm.com> References: <20241018091516.2167885-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: r0Mp9zehldR-k5h_Rfo53iEsp3Tux5vP X-Proofpoint-ORIG-GUID: r0Mp9zehldR-k5h_Rfo53iEsp3Tux5vP 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 adultscore=0 mlxscore=0 spamscore=0 priorityscore=1501 phishscore=0 clxscore=1015 mlxlogscore=865 impostorscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410180056 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 Tue Nov 26 11:21:18 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 8C3BD1E7679; Fri, 18 Oct 2024 09:15:23 +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=1729242925; cv=none; b=JgfhjJM3LMNWRzsqg7hbRE/Wy0etfVM4N7NQjaZjIkp3SUmeSuNbb+bFX3qEoab+C7gN/4G4V1M2Kx1ClIIQfSE6hKyS+KCwzAsFX33/24I9e9BGEOVumWMysii1mW9HKFInzY5+5U4z2/9dlxVIsllMkOEoRe9xTaWOuhiJbDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729242925; c=relaxed/simple; bh=X0lNSp5i0RziXGNOcFt9fGsob4bt2+pxmaZ2WNS/D1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hYVs1Hj7wNqcZtZ9zdKr8sTmvL8IKeOdBZXPqZVyXnFT86OO8GJxLQ19OR5APQg6yyUxmLU5N+EKORdMkNvU2a+31grelZSBA5vxbwwucLyJBNX9e1p9jB04Em88O0aDWd50mkL5rj40iHKUjSdet+zeGTdTUZ9eYn9r1pE21Yk= 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=T3gt0xzh; 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="T3gt0xzh" 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 49I8oFWb007998; Fri, 18 Oct 2024 09:15:22 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=d08ypVT9LBTk7Vtys NIxYzD0+Ptc9czUV8HQyOnJZ/o=; b=T3gt0xzhziKNwYiFmEepImiywpduH9Ws7 vwtB/2RAC9iVIUo7UW8JY7ZAA0Pql9ZqonHtEbqBVCS6gvDVpj5Bnr1AnNWLmmkY TYpW4h5EQOWu6DhR9Qos6GSefhgrwDxSftWLsDOM1BDxppXdg92xBJ6l0jHIaEzW 9dA7Ku0xX/OL35dfbkpp0xx/ovfdQKIgh2krvhplLAv5iDSSxPUpdchAIL+n+/q1 Gi4f8RJpUb5ET/xP0Os1keBtRHHNxNYCSzdKAL87jHgQHm3E2cJPtC5rXjLNpgct aWcD4Nr6d855tFZHcki6NGBQ/7N9UaQMRiCxsWa41kIFXfkNkPcug== 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 42as8a7f7m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:22 +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 49I7UkYi006663; Fri, 18 Oct 2024 09:15:21 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4283esbr6u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:21 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49I9FHxJ41157054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Oct 2024 09:15:17 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 95E192004E; Fri, 18 Oct 2024 09:15:17 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6D7E32005A; Fri, 18 Oct 2024 09:15:17 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 18 Oct 2024 09:15:17 +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 v4 5/6] s390/uvdevice: Add List Secrets Ext IOCTL Date: Fri, 18 Oct 2024 11:15:15 +0200 Message-ID: <20241018091516.2167885-6-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018091516.2167885-1-seiden@linux.ibm.com> References: <20241018091516.2167885-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: 6FU905V6Ut5qVUpVW7c_Mc_GIdauUwAw X-Proofpoint-ORIG-GUID: 6FU905V6Ut5qVUpVW7c_Mc_GIdauUwAw 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 mlxscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 adultscore=0 impostorscore=0 priorityscore=1501 spamscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410180056 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..18bae2d45bf6 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; + u8 *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 (u8 *)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 Tue Nov 26 11:21:18 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 57D3A1E5727; Fri, 18 Oct 2024 09:15:23 +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=1729242926; cv=none; b=JBrM3I3qIklTNgsZdEM7QTc6nQNLW05HZJSkG3fv6+bapLHH4Wa5Z6z0Mtw7YC/YSMTeiBtx+or3/2lmFdny9poK0ksfUebL7T5lKyzYKYC/5UzOisnrAWgxNfc2ZbfwKUlKmubQbQI+y93HznjDyylTcEwF/mq2GTKEYNGFAsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729242926; c=relaxed/simple; bh=lehgYREcn9xsCEAcyXOLVMS1mtwy2z2r2klt2DejUNk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p2AFlV7d3teIZP72aVxw6pTOouPlBln+zZ8rU1i/drTVYOFQGMr/ZuWhidU+yyKnii3OpV11Drw6hs7i88yqiaJJkC9c4PWNT+omkdBu/7W/szLI7zFDHAVmnoWhjN8WjPdu0wB+eHFYjvT4HXVUIthmbXEBpMQriRnriGT30bo= 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=okvrwL//; 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="okvrwL//" 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 49HJSAgW017497; Fri, 18 Oct 2024 09:15:22 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=/WHmbHZNXcwWcAGCw phPiT2Kwm1+tUCRCuVEsmFgkN4=; b=okvrwL//lJKT1wzkg9dFfWraypkzlOcWw vnAWp46rfsEq1DBBbhsOxNt34Qv/Q4/fkt/xdd0XdzPIU4bkwVMwNnVTgg8mNTK3 KPaFCLgyCdTlyLuTPVDbTCnw6njKxR6sWO3KZcFiIZMdWv293Ha2O4VB7hgtmWWQ mc1lFFX+LqFsan1XKhC36xb3azxS4e4VWbbCJpMlmx0yfilAF7vgYH3BIg4gsTzs +vdhqRKIVaUcHGPD5WRH8jdeR3NBiGkR+kBMCJO4npeglTKp1wACj/0zJvz7AkFb B5f2dTIHuR+2MRnSYBw54Oh/AiVyC33VApjxNA0zwGjSa6pkdsD9g== 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 42ar0u7ptr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:22 +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 49I850KA002343; Fri, 18 Oct 2024 09:15:21 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4284en3jqm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Oct 2024 09:15:21 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49I9FHvV42729948 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Oct 2024 09:15:17 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B80B12004D; Fri, 18 Oct 2024 09:15:17 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9A23B2004F; Fri, 18 Oct 2024 09:15:17 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 18 Oct 2024 09:15:17 +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 v4 6/6] s390/uv: Retrieve UV secrets sysfs support Date: Fri, 18 Oct 2024 11:15:16 +0200 Message-ID: <20241018091516.2167885-7-seiden@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018091516.2167885-1-seiden@linux.ibm.com> References: <20241018091516.2167885-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: 4hA4giOO7PCbg8kqnx1IT61zHOqPLQl0 X-Proofpoint-ORIG-GUID: 4hA4giOO7PCbg8kqnx1IT61zHOqPLQl0 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 lowpriorityscore=0 mlxscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxlogscore=861 phishscore=0 suspectscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410180056 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 bc61cf3e689b..371bbaf3dbe9 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 */ @@ -530,7 +531,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 588caf5d4f0c..d6079aa9b57b 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