Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.2/patches/2233183/?format=api
{ "id": 2233183, "url": "http://patchwork.ozlabs.org/api/1.2/patches/2233183/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260505201905.997996-22-zycai@linux.ibm.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/1.2/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260505201905.997996-22-zycai@linux.ibm.com>", "list_archive_url": null, "date": "2026-05-05T20:18:53", "name": "[v11,21/32] pc-bios/s390-ccw: Add signature verification for secure IPL in audit mode", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "959db5d005f12e12eccd8ca56ac2ed039c93631a", "submitter": { "id": 90643, "url": "http://patchwork.ozlabs.org/api/1.2/people/90643/?format=api", "name": "Zhuoying Cai", "email": "zycai@linux.ibm.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260505201905.997996-22-zycai@linux.ibm.com/mbox/", "series": [ { "id": 502896, "url": "http://patchwork.ozlabs.org/api/1.2/series/502896/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=502896", "date": "2026-05-05T20:18:37", "name": "Secure IPL Support for SCSI Scheme of virtio-blk/virtio-scsi Devices", "version": 11, "mbox": "http://patchwork.ozlabs.org/series/502896/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2233183/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2233183/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256\n header.s=pp1 header.b=cZ8R+ozT;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g98z33yrJz1yK2\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 06:20:47 +1000 (AEST)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wKMFf-0000nb-Qx; Tue, 05 May 2026 16:20:19 -0400", "from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <zycai@linux.ibm.com>)\n id 1wKMFc-0000XD-IU; Tue, 05 May 2026 16:20:16 -0400", "from mx0b-001b2d01.pphosted.com ([148.163.158.5])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <zycai@linux.ibm.com>)\n id 1wKMFY-0000JN-SS; Tue, 05 May 2026 16:20:16 -0400", "from pps.filterd (m0360072.ppops.net [127.0.0.1])\n by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 645AEZ6c144785; Tue, 5 May 2026 20:19:48 GMT", "from ppma12.dal12v.mail.ibm.com\n (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220])\n by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dw9y4n72q-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);\n Tue, 05 May 2026 20:19:48 +0000 (GMT)", "from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1])\n by ppma12.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id\n 645K9Q9o031250;\n Tue, 5 May 2026 20:19:47 GMT", "from smtprelay01.wdc07v.mail.ibm.com ([172.16.1.68])\n by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4dwukqbfu3-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);\n Tue, 05 May 2026 20:19:47 +0000 (GMT)", "from smtpav02.wdc07v.mail.ibm.com (smtpav02.wdc07v.mail.ibm.com\n [10.39.53.229])\n by smtprelay01.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id\n 645KJj2V4653998\n (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK);\n Tue, 5 May 2026 20:19:46 GMT", "from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1])\n by IMSVA (Postfix) with ESMTP id CD6295805B;\n Tue, 5 May 2026 20:19:45 +0000 (GMT)", "from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1])\n by IMSVA (Postfix) with ESMTP id 3A2CE58059;\n Tue, 5 May 2026 20:19:44 +0000 (GMT)", "from fedora-workstation.pok.ibm.com (unknown [9.12.79.241])\n by smtpav02.wdc07v.mail.ibm.com (Postfix) with ESMTP;\n Tue, 5 May 2026 20:19:44 +0000 (GMT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc\n :content-transfer-encoding:date:from:in-reply-to:message-id\n :mime-version:references:subject:to; s=pp1; bh=BCOkrBfNZexpqPizi\n KemnH35bGj2vU5rLn/7Htx18F0=; b=cZ8R+ozTPBCCN6Fhv1TWM1/n4JHPL8RBw\n v7VZnv4ZZbkBKCFO0JLIIsM0hd1ZKMg7V4wpjAznLp3ygmSPPcgMLk4u5EKJ27fM\n KsH9rbErRxxOhOpdhFqrj2Vrx/h4qs+DtG74T/0SxrbCG5oZwmVrgERfXrJXLcCC\n kml/rVCEmMlQG1FehPh7cDuJPK0Ix6PXvUyAm5gaksNotuxl/pfmRSWxIXKy6VAh\n izRZL670cs6L7MfNKPAyyeA5Fi/M3nfDbPC9Lv5g0n59FIGlAktiMDRCi/HvQXPL\n 6RP81yz49JOSUBRaYqUdG0RmrQBg8Kfabvibu8yMJB3wVb5zJeegg==", "From": "Zhuoying Cai <zycai@linux.ibm.com>", "To": "qemu-s390x@nongnu.org, qemu-devel@nongnu.org", "Cc": "jrossi@linux.ibm.com, cohuck@redhat.com, berrange@redhat.com,\n richard.henderson@linaro.org, david@kernel.org, walling@linux.ibm.com,\n jjherne@linux.ibm.com, pasic@linux.ibm.com, borntraeger@linux.ibm.com,\n farman@linux.ibm.com, mjrosato@linux.ibm.com, iii@linux.ibm.com,\n eblake@redhat.com, armbru@redhat.com, zycai@linux.ibm.com,\n alifm@linux.ibm.com, brueckner@linux.ibm.com,\n pierrick.bouvier@oss.qualcomm.com, jdaley@linux.ibm.com", "Subject": "[PATCH v11 21/32] pc-bios/s390-ccw: Add signature verification for\n secure IPL in audit mode", "Date": "Tue, 5 May 2026 16:18:53 -0400", "Message-ID": "<20260505201905.997996-22-zycai@linux.ibm.com>", "X-Mailer": "git-send-email 2.54.0", "In-Reply-To": "<20260505201905.997996-1-zycai@linux.ibm.com>", "References": "<20260505201905.997996-1-zycai@linux.ibm.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-TM-AS-GCONF": "00", "X-Proofpoint-Spam-Details-Enc": "AW1haW4tMjYwNTA1MDE5NSBTYWx0ZWRfX9ByqhxFBXiBY\n goTIQS30hf4bjcWBQ8DktMjHHYdRulRwAydRAJ0c4EOaYUSlMKFFTerz4l6QHRM+b5urw7ZMovd\n P+5ZmyLquvngPhP0ddnap4qqI4vyxwz0cO9dr9exbm0HSVJ2XtbC/WwXrpNLDpG3rxnHW16gLFJ\n 7DoVwboP/ZhVXbYSzJwghrQiLJorXMdscOBwiurxCkfAu6ISNoecnSxNTOUfyzEG1FRxSwqw022\n 6k1+OxKAZH4VCOvzBauxgzIPI3UX8v0E2pU54zvGLDDAoMuVGDsWMmzEolJJ9kce9VgKD1riJvQ\n 0FiHwFfIkg4A4sGKo/9wzdtfRmVLegwnKcZ4r7BNw1Am6GIUFS/c57JrfX36JLKGN6usr6ICWVp\n tXHTPCXs6KPn1UBA3BKtqd2yOHrjzP9kidg4+NSI06MEZ/V6JFW6cEqlMkegqt+QimUphFOJ8C3\n elzkrxNoaOp7NE4s0Cw==", "X-Authority-Analysis": "v=2.4 cv=J4GaKgnS c=1 sm=1 tr=0 ts=69fa50e4 cx=c_pps\n a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17\n a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22\n a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=ae5O-m4cEUc7-qk3VwEA:9", "X-Proofpoint-GUID": "alDxQC5EfdgTfmQaM63ZLxaP4mf5oQMK", "X-Proofpoint-ORIG-GUID": "alDxQC5EfdgTfmQaM63ZLxaP4mf5oQMK", "X-Proofpoint-Virus-Version": "vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-05-05_02,2026-04-30_02,2025-10-01_01", "X-Proofpoint-Spam-Details": "rule=outbound_notspam policy=outbound score=0\n impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 suspectscore=0\n priorityscore=1501 spamscore=0 phishscore=0 adultscore=0 lowpriorityscore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605050195", "Received-SPF": "pass client-ip=148.163.158.5; envelope-from=zycai@linux.ibm.com;\n helo=mx0b-001b2d01.pphosted.com", "X-Spam_score_int": "-26", "X-Spam_score": "-2.7", "X-Spam_bar": "--", "X-Spam_report": "(-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7,\n RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=ham autolearn_force=no", "X-Spam_action": "no action", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "qemu development <qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org" }, "content": "Enable secure IPL in audit mode, which performs signature verification,\nbut any error does not terminate the boot process. Only warnings will be\nlogged to the console instead.\n\nAdd a comp_len variable to store the length of a segment in\nzipl_load_segment. comp_len variable is necessary to store the\ncalculated segment length and is used during signature verification.\nReturn the length on success, or a negative return code on failure.\n\nSecure IPL in audit mode requires at least one certificate provided in\nthe key store along with necessary facilities (Secure IPL Facility,\nCertificate Store Facility and secure IPL extension support).\n\nNote: Secure IPL in audit mode is implemented for the SCSI scheme of\nvirtio-blk/virtio-scsi devices.\n\nSigned-off-by: Zhuoying Cai <zycai@linux.ibm.com>\n---\n docs/system/s390x/secure-ipl.rst | 15 ++\n pc-bios/s390-ccw/Makefile | 2 +-\n pc-bios/s390-ccw/bootmap.c | 16 ++\n pc-bios/s390-ccw/bootmap.h | 9 +\n pc-bios/s390-ccw/main.c | 10 +-\n pc-bios/s390-ccw/s390-ccw.h | 24 ++\n pc-bios/s390-ccw/sclp.c | 27 +++\n pc-bios/s390-ccw/sclp.h | 6 +\n pc-bios/s390-ccw/secure-ipl.c | 364 +++++++++++++++++++++++++++++++\n pc-bios/s390-ccw/secure-ipl.h | 113 ++++++++++\n 10 files changed, 584 insertions(+), 2 deletions(-)\n create mode 100644 pc-bios/s390-ccw/secure-ipl.c\n create mode 100644 pc-bios/s390-ccw/secure-ipl.h", "diff": "diff --git a/docs/system/s390x/secure-ipl.rst b/docs/system/s390x/secure-ipl.rst\nindex 9d7d33f5ed..cf6ccf5d57 100644\n--- a/docs/system/s390x/secure-ipl.rst\n+++ b/docs/system/s390x/secure-ipl.rst\n@@ -39,3 +39,18 @@ Configuration:\n .. code-block:: shell\n \n qemu-system-s390x -machine s390-ccw-virtio ...\n+\n+Audit Mode\n+^^^^^^^^^^\n+\n+When the certificate store is populated with at least one certificate\n+and no additional secure IPL parameters are provided on the command\n+line, then secure IPL will proceed in \"audit mode\". All secure IPL\n+operations will be performed with signature verification errors reported\n+as non-disruptive warnings.\n+\n+Configuration:\n+\n+.. code-block:: shell\n+\n+ qemu-system-s390x -machine s390-ccw-virtio,boot-certs.0.path=/.../qemu/certs,boot-certs.1.path=/another/path/cert.pem ...\ndiff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile\nindex 3e5dfb64d5..2109d16781 100644\n--- a/pc-bios/s390-ccw/Makefile\n+++ b/pc-bios/s390-ccw/Makefile\n@@ -35,7 +35,7 @@ QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d\n \n OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o netmain.o \\\n \t virtio.o virtio-net.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o \\\n-\t virtio-ccw.o clp.o pci.o virtio-pci.o\n+\t virtio-ccw.o clp.o pci.o virtio-pci.o secure-ipl.o\n \n SLOF_DIR := $(SRC_PATH)/../../roms/SLOF\n \ndiff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c\nindex 667a69f80d..a300fba8cd 100644\n--- a/pc-bios/s390-ccw/bootmap.c\n+++ b/pc-bios/s390-ccw/bootmap.c\n@@ -15,6 +15,7 @@\n #include \"bootmap.h\"\n #include \"virtio.h\"\n #include \"bswap.h\"\n+#include \"secure-ipl.h\"\n \n #ifdef DEBUG\n /* #define DEBUG_FALLBACK */\n@@ -737,6 +738,9 @@ static int zipl_run(ScsiBlockPtr *pte)\n case ZIPL_BOOT_MODE_NORMAL:\n rc = zipl_run_normal(&entry, tmp_sec);\n break;\n+ case ZIPL_BOOT_MODE_SECURE_AUDIT:\n+ rc = zipl_run_secure(&entry, tmp_sec);\n+ break;\n default:\n panic(\"Unknown boot mode\");\n }\n@@ -1107,6 +1111,18 @@ static int zipl_load_vscsi(void)\n * IPL starts here\n */\n \n+ZiplBootMode get_boot_mode(uint8_t hdr_flags)\n+{\n+ bool sipl_set = hdr_flags & DIAG308_IPIB_FLAGS_SIPL;\n+ bool iplir_set = hdr_flags & DIAG308_IPIB_FLAGS_IPLIR;\n+\n+ if (!sipl_set && iplir_set) {\n+ return ZIPL_BOOT_MODE_SECURE_AUDIT;\n+ }\n+\n+ return ZIPL_BOOT_MODE_NORMAL;\n+}\n+\n void zipl_load(void)\n {\n VDev *vdev = virtio_get_device();\ndiff --git a/pc-bios/s390-ccw/bootmap.h b/pc-bios/s390-ccw/bootmap.h\nindex 8d61ac383c..1e00454a1f 100644\n--- a/pc-bios/s390-ccw/bootmap.h\n+++ b/pc-bios/s390-ccw/bootmap.h\n@@ -88,9 +88,18 @@ typedef struct BootMapTable {\n BootMapPointer entry[];\n } __attribute__ ((packed)) BootMapTable;\n \n+#define DER_SIGNATURE_FORMAT 1\n+\n+typedef struct SignatureInformation {\n+ uint8_t format;\n+ uint8_t reserved[3];\n+ uint32_t sig_len;\n+} SignatureInformation;\n+\n typedef union ComponentEntryData {\n uint64_t load_psw;\n uint64_t load_addr;\n+ SignatureInformation sig_info;\n } ComponentEntryData;\n \n typedef struct ComponentEntry {\ndiff --git a/pc-bios/s390-ccw/main.c b/pc-bios/s390-ccw/main.c\nindex 66544f75f5..0bcd32b059 100644\n--- a/pc-bios/s390-ccw/main.c\n+++ b/pc-bios/s390-ccw/main.c\n@@ -394,7 +394,15 @@ void main(void)\n probe_boot_device();\n }\n \n- boot_mode = ZIPL_BOOT_MODE_NORMAL;\n+ boot_mode = get_boot_mode(iplb->hdr_flags);\n+ switch (boot_mode) {\n+ case ZIPL_BOOT_MODE_SECURE_AUDIT:\n+ if (!secure_ipl_supported()) {\n+ panic(\"Unable to boot in audit mode\");\n+ }\n+ default:\n+ break;\n+ }\n \n while (have_iplb) {\n boot_setup();\ndiff --git a/pc-bios/s390-ccw/s390-ccw.h b/pc-bios/s390-ccw/s390-ccw.h\nindex 5420443ad2..b66a9b50bf 100644\n--- a/pc-bios/s390-ccw/s390-ccw.h\n+++ b/pc-bios/s390-ccw/s390-ccw.h\n@@ -40,6 +40,22 @@ typedef unsigned long long u64;\n ((b) == 0 ? (a) : (MIN(a, b))))\n #endif\n \n+/*\n+ * Round number down to multiple. Requires that d be a power of 2.\n+ * Works even if d is a smaller type than n.\n+ */\n+#ifndef ROUND_DOWN\n+#define ROUND_DOWN(n, d) ((n) & -(0 ? (n) : (d)))\n+#endif\n+\n+/*\n+ * Round number up to multiple. Requires that d be a power of 2.\n+ * Works even if d is a smaller type than n.\n+ */\n+#ifndef ROUND_UP\n+#define ROUND_UP(n, d) ROUND_DOWN((n) + (d) - 1, (d))\n+#endif\n+\n #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))\n \n #include \"cio.h\"\n@@ -64,6 +80,8 @@ void sclp_print(const char *string);\n void sclp_set_write_mask(uint32_t receive_mask, uint32_t send_mask);\n void sclp_setup(void);\n void sclp_get_loadparm_ascii(char *loadparm);\n+bool sclp_is_diag320_on(void);\n+bool sclp_is_fac_ipl_flag_on(uint16_t fac_ipl_flag);\n int sclp_read(char *str, size_t count);\n \n /* bootmap.c */\n@@ -71,10 +89,16 @@ void zipl_load(void);\n \n typedef enum ZiplBootMode {\n ZIPL_BOOT_MODE_NORMAL = 0,\n+ ZIPL_BOOT_MODE_SECURE_AUDIT = 1,\n } ZiplBootMode;\n \n extern ZiplBootMode boot_mode;\n \n+ZiplBootMode get_boot_mode(uint8_t hdr_flags);\n+\n+/* secure-ipl.c */\n+bool secure_ipl_supported(void);\n+\n /* jump2ipl.c */\n void write_reset_psw(uint64_t psw);\n int jump_to_IPL_code(uint64_t address);\ndiff --git a/pc-bios/s390-ccw/sclp.c b/pc-bios/s390-ccw/sclp.c\nindex 4a07de018d..48bdfedf1f 100644\n--- a/pc-bios/s390-ccw/sclp.c\n+++ b/pc-bios/s390-ccw/sclp.c\n@@ -113,6 +113,33 @@ void sclp_get_loadparm_ascii(char *loadparm)\n }\n }\n \n+bool sclp_is_diag320_on(void)\n+{\n+ ReadInfo *sccb = (void *)_sccb;\n+\n+ memset((char *)_sccb, 0, sizeof(ReadInfo));\n+ sccb->h.length = SCCB_SIZE;\n+ if (!sclp_service_call(SCLP_CMDW_READ_SCP_INFO, sccb)) {\n+ return sccb->fac134 & SCCB_FAC134_DIAG320_BIT;\n+ }\n+\n+ return 0;\n+}\n+\n+/* check if specified IPL facility flag is enabled */\n+bool sclp_is_fac_ipl_flag_on(uint16_t fac_ipl_flag)\n+{\n+ ReadInfo *sccb = (void *)_sccb;\n+\n+ memset((char *)_sccb, 0, sizeof(ReadInfo));\n+ sccb->h.length = SCCB_SIZE;\n+ if (!sclp_service_call(SCLP_CMDW_READ_SCP_INFO, sccb)) {\n+ return sccb->fac_ipl & fac_ipl_flag;\n+ }\n+\n+ return 0;\n+}\n+\n int sclp_read(char *str, size_t count)\n {\n ReadEventData *sccb = (void *)_sccb;\ndiff --git a/pc-bios/s390-ccw/sclp.h b/pc-bios/s390-ccw/sclp.h\nindex 64b53cad29..a8a41cd004 100644\n--- a/pc-bios/s390-ccw/sclp.h\n+++ b/pc-bios/s390-ccw/sclp.h\n@@ -50,6 +50,8 @@ typedef struct SCCBHeader {\n } __attribute__((packed)) SCCBHeader;\n \n #define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader))\n+#define SCCB_FAC134_DIAG320_BIT 0x4\n+#define SCCB_FAC_IPL_SIPL_BIT 0x4000\n \n typedef struct ReadInfo {\n SCCBHeader h;\n@@ -57,6 +59,10 @@ typedef struct ReadInfo {\n uint8_t rnsize;\n uint8_t reserved[13];\n uint8_t loadparm[LOADPARM_LEN];\n+ uint8_t reserved1[102];\n+ uint8_t fac134;\n+ uint8_t reserved2;\n+ uint16_t fac_ipl;\n } __attribute__((packed)) ReadInfo;\n \n typedef struct SCCB {\ndiff --git a/pc-bios/s390-ccw/secure-ipl.c b/pc-bios/s390-ccw/secure-ipl.c\nnew file mode 100644\nindex 0000000000..6e943446a7\n--- /dev/null\n+++ b/pc-bios/s390-ccw/secure-ipl.c\n@@ -0,0 +1,364 @@\n+/*\n+ * S/390 Secure IPL\n+ *\n+ * Functions to support IPL in secure boot mode (DIAG 320, DIAG 508,\n+ * signature verification, and certificate handling).\n+ *\n+ * For secure IPL overview: docs/system/s390x/secure-ipl.rst\n+ * For secure IPL technical: docs/specs/s390x-secure-ipl.rst\n+ *\n+ * Copyright 2025 IBM Corp.\n+ * Author(s): Zhuoying Cai <zycai@linux.ibm.com>\n+ *\n+ * SPDX-License-Identifier: GPL-2.0-or-later\n+ */\n+\n+#include <stdlib.h>\n+#include <string.h>\n+#include <stdio.h>\n+#include \"bootmap.h\"\n+#include \"s390-ccw.h\"\n+#include \"sclp.h\"\n+#include \"secure-ipl.h\"\n+\n+static VCStorageSizeBlock vcssb __attribute__((__aligned__(8)));\n+\n+VCStorageSizeBlock *zipl_secure_get_vcssb(void)\n+{\n+ /* avoid retrieving vcssb multiple times */\n+ if (vcssb.length == VCSSB_MIN_LEN) {\n+ return &vcssb;\n+ }\n+\n+ vcssb.length = VCSSB_MIN_LEN;\n+ if (_diag320(&vcssb, DIAG_320_SUBC_QUERY_VCSI) != DIAG_320_RC_OK) {\n+ vcssb.length = 0;\n+ return NULL;\n+ }\n+\n+ return &vcssb;\n+}\n+\n+static uint32_t get_total_certs_length(void)\n+{\n+ if (zipl_secure_get_vcssb() == NULL) {\n+ return 0;\n+ }\n+\n+ return vcssb.total_vcb_len - sizeof(VCBlockHeader) -\n+ vcssb.total_vc_ct * sizeof(VCEntryHeader);\n+}\n+\n+static uint32_t request_certificate(uint8_t *cert_buf, uint8_t index)\n+{\n+ VCEntryHeader *vce_hdr;\n+ struct vcb {\n+ VCBlockHeader vcb_hdr;\n+ struct vce {\n+ VCEntryHeader vce_hdr;\n+ uint8_t cert_buf[CERT_BUF_MAX_LEN];\n+ } vce;\n+ } __attribute__((__aligned__(4096))) vcb = { 0 };\n+\n+ /* Get Verification Certificate Storage Size block with DIAG320 subcode 1 */\n+ if (zipl_secure_get_vcssb() == NULL) {\n+ return 0;\n+ }\n+\n+ /*\n+ * Request single entry\n+ * Fill input fields of single-entry VCB\n+ *\n+ * First and last index must be equal because only one\n+ * VCE per VCB is currently supported\n+ */\n+ vcb.vcb_hdr.in_len = ROUND_UP(vcssb.max_single_vcb_len, PAGE_SIZE);\n+ vcb.vcb_hdr.first_vc_index = index;\n+ vcb.vcb_hdr.last_vc_index = index;\n+\n+ if (_diag320(&vcb, DIAG_320_SUBC_STORE_VC) != DIAG_320_RC_OK) {\n+ return 0;\n+ }\n+\n+ if (vcb.vcb_hdr.out_len == sizeof(VCBlockHeader)) {\n+ puts(\"No certificate entry\");\n+ return 0;\n+ }\n+\n+ if (vcb.vcb_hdr.remain_ct != 0) {\n+ panic(\"Not enough memory to store all requested certificates\");\n+ }\n+\n+ vce_hdr = &vcb.vce.vce_hdr;\n+ if (!(vce_hdr->flags & DIAG_320_VCE_FLAGS_VALID)) {\n+ puts(\"Invalid certificate\");\n+ return 0;\n+ }\n+\n+ memcpy(cert_buf, (uint8_t *)&vcb.vce + vce_hdr->cert_offset, vce_hdr->cert_len);\n+\n+ return vce_hdr->cert_len;\n+}\n+\n+static int cert_list_add(IplSignatureCertificateList *cert_list,\n+ uint8_t *cert_buf, uint64_t cert_len)\n+{\n+ static bool warned;\n+ int cert_entry_idx;\n+\n+ cert_entry_idx = (cert_list->ipl_info_header.len - sizeof(IplInfoBlockHeader)) /\n+ sizeof(IplSignatureCertificateEntry);\n+ if (cert_entry_idx > MAX_CERTIFICATES - 1) {\n+ if (!warned) {\n+ printf(\"Warning: only %d cert entries are supported;\"\n+ \" additional entries are ignored\\n\",\n+ MAX_CERTIFICATES);\n+ warned = true;\n+ }\n+ return cert_entry_idx;\n+ }\n+\n+ cert_list->cert_entries[cert_entry_idx].addr = (uint64_t)cert_buf;\n+ cert_list->cert_entries[cert_entry_idx].len = cert_len;\n+ cert_list->ipl_info_header.len += sizeof(IplSignatureCertificateEntry);\n+\n+ return cert_entry_idx;\n+}\n+\n+static void comp_list_add(IplDeviceComponentList *comp_list,\n+ SecureIplCompEntryInfo comp_entry_info)\n+{\n+ int comp_entry_idx;\n+\n+ comp_entry_idx = (comp_list->ipl_info_header.len - sizeof(IplInfoBlockHeader)) /\n+ sizeof(IplDeviceComponentEntry);\n+ if (comp_entry_idx > MAX_COMP_ENTRIES - 1) {\n+ printf(\"Warning: only %d component entries are supported\\n\",\n+ MAX_COMP_ENTRIES);\n+ panic(\"The device component list has reached its maximum capacity\");\n+ }\n+\n+ comp_list->device_entries[comp_entry_idx].addr = comp_entry_info.addr;\n+ comp_list->device_entries[comp_entry_idx].len = comp_entry_info.len;\n+ comp_list->device_entries[comp_entry_idx].flags = comp_entry_info.flags;\n+ /* cert index field is meaningful only when S390_IPL_DEV_COMP_FLAG_SC is set */\n+ if (comp_entry_info.flags & S390_IPL_DEV_COMP_FLAG_SC) {\n+ comp_list->device_entries[comp_entry_idx].cert_index =\n+ comp_entry_info.cert_index;\n+ }\n+ comp_list->ipl_info_header.len += sizeof(IplDeviceComponentEntry);\n+}\n+\n+static void update_iirb(IplDeviceComponentList *comp_list,\n+ IplSignatureCertificateList *cert_list)\n+{\n+ IplInfoReportBlock *iirb;\n+ IplDeviceComponentList *iirb_comps;\n+ IplSignatureCertificateList *iirb_certs;\n+ uint32_t iirb_hdr_len;\n+ uint32_t comps_len;\n+ uint32_t certs_len;\n+\n+ if (iplb->len % 8 != 0) {\n+ panic(\"IPL parameter block length field value is not multiple of 8 bytes\");\n+ }\n+\n+ iirb_hdr_len = sizeof(IplInfoReportBlockHeader);\n+ comps_len = comp_list->ipl_info_header.len;\n+ certs_len = cert_list->ipl_info_header.len;\n+ if ((comps_len + certs_len + iirb_hdr_len) > sizeof(IplInfoReportBlock)) {\n+ panic(\"Not enough space to hold all components and certificates in IIRB\");\n+ }\n+\n+ /* IIRB immediately follows IPLB */\n+ iirb = &ipl_data.iirb;\n+ iirb->hdr.len = iirb_hdr_len;\n+\n+ /* Copy IPL device component list after IIRB Header */\n+ iirb_comps = (IplDeviceComponentList *) iirb->info_blks;\n+ memcpy(iirb_comps, comp_list, comps_len);\n+\n+ /* Update IIRB length */\n+ iirb->hdr.len += comps_len;\n+\n+ /* Copy IPL sig cert list after IPL device component list */\n+ iirb_certs = (IplSignatureCertificateList *) (iirb->info_blks +\n+ iirb_comps->ipl_info_header.len);\n+ memcpy(iirb_certs, cert_list, certs_len);\n+\n+ /* Update IIRB length */\n+ iirb->hdr.len += certs_len;\n+}\n+\n+bool secure_ipl_supported(void)\n+{\n+ if (!sclp_is_fac_ipl_flag_on(SCCB_FAC_IPL_SIPL_BIT)) {\n+ puts(\"Secure IPL Facility is not supported by the hypervisor!\");\n+ return false;\n+ }\n+\n+ if (!is_signature_verif_supported()) {\n+ puts(\"Secure IPL extensions are not supported by the hypervisor!\");\n+ return false;\n+ }\n+\n+ if (!is_cert_store_facility_supported()) {\n+ puts(\"Certificate Store Facility is not supported by the hypervisor!\");\n+ return false;\n+ }\n+\n+ return true;\n+}\n+\n+static void init_lists(IplDeviceComponentList *comp_list,\n+ IplSignatureCertificateList *cert_list)\n+{\n+ comp_list->ipl_info_header.type = IPL_INFO_BLOCK_TYPE_COMPONENTS;\n+ comp_list->ipl_info_header.len = sizeof(IplInfoBlockHeader);\n+\n+ cert_list->ipl_info_header.type = IPL_INFO_BLOCK_TYPE_CERTIFICATES;\n+ cert_list->ipl_info_header.len = sizeof(IplInfoBlockHeader);\n+}\n+\n+static int zipl_load_signature(ComponentEntry *entry, uint64_t sig)\n+{\n+ if (entry->compdat.sig_info.format != DER_SIGNATURE_FORMAT) {\n+ puts(\"Signature is not in DER format\");\n+ return -1;\n+ }\n+\n+ if (zipl_load_segment(entry->data.blockno, sig) < 0) {\n+ return -1;\n+ }\n+\n+ return entry->compdat.sig_info.sig_len;\n+}\n+\n+int zipl_run_secure(ComponentEntry **entry_ptr, uint8_t *tmp_sec)\n+{\n+ IplDeviceComponentList comp_list = { 0 };\n+ IplSignatureCertificateList cert_list = { 0 };\n+ SecureIplCompEntryInfo sig_entry_info = { 0 };\n+ SecureIplCompEntryInfo comp_entry_info;\n+ ComponentEntry *entry = *entry_ptr;\n+ uint8_t *cert_buf = NULL;\n+ int sig_len = 0;\n+ int comp_len;\n+ int cert_entry_idx;\n+ uint64_t comp_addr;\n+ uint64_t cert_len;\n+ uint8_t cert_table_idx;\n+ bool verified;\n+ /*\n+ * Keep track of which certificate store indices correspond to the\n+ * certificate data entries within the IplSignatureCertificateList to\n+ * prevent allocating space for the same certificate multiple times.\n+ *\n+ * The array index corresponds to the certificate's cert-store index.\n+ *\n+ * The array value corresponds to the certificate's entry within the\n+ * IplSignatureCertificateList (with a value of -1 denoting no entry\n+ * exists for the certificate).\n+ */\n+ int cert_list_table[MAX_CERTIFICATES] = { [0 ... MAX_CERTIFICATES - 1] = -1 };\n+ int signed_count = 0;\n+\n+ init_lists(&comp_list, &cert_list);\n+ cert_buf = malloc(get_total_certs_length());\n+ sig_entry_info.addr = (uint64_t)malloc(MAX_SECTOR_SIZE);\n+\n+ while (entry->component_type != ZIPL_COMP_ENTRY_EXEC) {\n+ switch (entry->component_type) {\n+ case ZIPL_COMP_ENTRY_SIGNATURE:\n+ if (sig_entry_info.len) {\n+ goto out;\n+ }\n+\n+ sig_len = zipl_load_signature(entry, sig_entry_info.addr);\n+ if (sig_len < 0) {\n+ goto out;\n+ }\n+\n+ sig_entry_info.len = sig_len;\n+ break;\n+ case ZIPL_COMP_ENTRY_LOAD:\n+ comp_addr = entry->compdat.load_addr;\n+ comp_len = zipl_load_segment(entry->data.blockno, comp_addr);\n+ if (comp_len < 0) {\n+ goto out;\n+ }\n+\n+ comp_entry_info = (SecureIplCompEntryInfo){ 0 };\n+ comp_entry_info.addr = comp_addr;\n+ comp_entry_info.len = (uint64_t)comp_len;\n+\n+ /* no signature present (unsigned component) */\n+ if (!sig_entry_info.len) {\n+ break;\n+ }\n+\n+ /*\n+ * Initialize with SC flag (signed component)\n+ * CSV flag set upon successful verification\n+ */\n+ comp_entry_info.flags = S390_IPL_DEV_COMP_FLAG_SC;\n+\n+ verified = verify_signature(comp_entry_info, sig_entry_info,\n+ &cert_len, &cert_table_idx);\n+\n+ if (verified) {\n+ if (cert_list_table[cert_table_idx] == -1) {\n+ if (!request_certificate(cert_buf, cert_table_idx)) {\n+ puts(\"Could not get certificate\");\n+ goto out;\n+ }\n+\n+ cert_entry_idx = cert_list_add(&cert_list, cert_buf, cert_len);\n+ /* map cert-store index to cert-list entry index */\n+ cert_list_table[cert_table_idx] = cert_entry_idx;\n+ /* increment for the next certificate */\n+ cert_buf += cert_len;\n+ }\n+\n+ comp_entry_info.cert_index = cert_list_table[cert_table_idx];\n+ comp_entry_info.flags |= S390_IPL_DEV_COMP_FLAG_CSV;\n+ puts(\"Verified component\");\n+ } else {\n+ zipl_secure_error(\"Could not verify component\");\n+ }\n+\n+ comp_list_add(&comp_list, comp_entry_info);\n+\n+ signed_count += 1;\n+ /* After a signature is used another new one can be accepted */\n+ sig_entry_info.len = 0;\n+ break;\n+ default:\n+ puts(\"Unknown component entry type\");\n+ return -1;\n+ }\n+\n+ entry++;\n+\n+ if ((uint8_t *)(&entry[1]) > tmp_sec + MAX_SECTOR_SIZE) {\n+ puts(\"Wrong entry value\");\n+ return -EINVAL;\n+ }\n+ }\n+\n+ if (signed_count == 0) {\n+ zipl_secure_error(\"Secure boot is on, but components are not signed\");\n+ }\n+\n+ update_iirb(&comp_list, &cert_list);\n+\n+ *entry_ptr = entry;\n+ free((void *)sig_entry_info.addr);\n+\n+ return 0;\n+out:\n+ free(cert_buf);\n+ free((void *)sig_entry_info.addr);\n+\n+ return -1;\n+}\ndiff --git a/pc-bios/s390-ccw/secure-ipl.h b/pc-bios/s390-ccw/secure-ipl.h\nnew file mode 100644\nindex 0000000000..cc0302f56b\n--- /dev/null\n+++ b/pc-bios/s390-ccw/secure-ipl.h\n@@ -0,0 +1,113 @@\n+/*\n+ * S/390 Secure IPL\n+ *\n+ * Copyright 2025 IBM Corp.\n+ * Author(s): Zhuoying Cai <zycai@linux.ibm.com>\n+ *\n+ * SPDX-License-Identifier: GPL-2.0-or-later\n+ */\n+\n+#ifndef _PC_BIOS_S390_CCW_SECURE_IPL_H\n+#define _PC_BIOS_S390_CCW_SECURE_IPL_H\n+\n+#include <diag320.h>\n+#include <diag508.h>\n+\n+VCStorageSizeBlock *zipl_secure_get_vcssb(void);\n+int zipl_run_secure(ComponentEntry **entry_ptr, uint8_t *tmp_sec);\n+\n+/* Custom struct for secure IPL component entry information */\n+typedef struct SecureIplCompEntryInfo {\n+ uint64_t addr;\n+ uint64_t len;\n+ uint16_t cert_index;\n+ uint8_t flags;\n+} SecureIplCompEntryInfo;\n+\n+static inline void zipl_secure_error(const char *message)\n+{\n+ switch (boot_mode) {\n+ case ZIPL_BOOT_MODE_SECURE_AUDIT:\n+ printf(\"AUDIT MODE WARNING: %s\\n\", message);\n+ break;\n+ default:\n+ break;\n+ }\n+}\n+\n+static inline uint64_t _diag320(void *data, unsigned long subcode)\n+{\n+ register unsigned long addr asm(\"0\") = (unsigned long)data;\n+ register unsigned long rc asm(\"1\") = 0;\n+\n+ asm volatile (\"diag %0,%2,0x320\\n\"\n+ : \"+d\" (addr), \"+d\" (rc)\n+ : \"d\" (subcode)\n+ : \"memory\", \"cc\");\n+ return rc;\n+}\n+\n+static inline bool is_cert_store_facility_supported(void)\n+{\n+ uint32_t d320_ism;\n+\n+ if (!sclp_is_diag320_on()) {\n+ return false;\n+ }\n+\n+ if (_diag320(&d320_ism, DIAG_320_SUBC_QUERY_ISM) != DIAG_320_RC_OK) {\n+ return false;\n+ }\n+\n+ return d320_ism & (DIAG_320_ISM_QUERY_VCSI | DIAG_320_ISM_STORE_VC);\n+}\n+\n+static inline uint64_t _diag508(void *data, unsigned long subcode)\n+{\n+ register unsigned long addr asm(\"0\") = (unsigned long)data;\n+ register unsigned long rc asm(\"1\") = 0;\n+\n+ asm volatile (\"diag %0,%2,0x508\\n\"\n+ : \"+d\" (addr), \"+d\" (rc)\n+ : \"d\" (subcode)\n+ : \"memory\", \"cc\");\n+ return rc;\n+}\n+\n+static inline bool is_signature_verif_supported(void)\n+{\n+ uint64_t d508_subcodes;\n+\n+ d508_subcodes = _diag508(NULL, DIAG_508_SUBC_QUERY_SUBC);\n+ return d508_subcodes & DIAG_508_SUBC_SIG_VERIF;\n+}\n+\n+static inline bool verify_signature(SecureIplCompEntryInfo comp_entry_info,\n+ SecureIplCompEntryInfo sig_entry_info,\n+ uint64_t *cert_len, uint8_t *cert_idx)\n+{\n+ Diag508SigVerifBlock svb;\n+\n+ svb.length = sizeof(Diag508SigVerifBlock);\n+ svb.version = 0;\n+ svb.comp_len = comp_entry_info.len;\n+ svb.comp_addr = comp_entry_info.addr;\n+ svb.sig_len = sig_entry_info.len;\n+ svb.sig_addr = sig_entry_info.addr;\n+\n+ if (_diag508(&svb, DIAG_508_SUBC_SIG_VERIF) == DIAG_508_RC_OK) {\n+ *cert_len = svb.cert_len;\n+ /*\n+ * DIAG 508 utilizes an index origin of 0 when indexing the cert store.\n+ * The cert_idx will be used for DIAG 320 data structures, which expects\n+ * an index origin of 1. Account for the offset here so it's easier to\n+ * manage later.\n+ */\n+ *cert_idx = svb.cert_store_index + 1;\n+ return true;\n+ }\n+\n+ return false;\n+}\n+\n+#endif /* _PC_BIOS_S390_CCW_SECURE_IPL_H */\n", "prefixes": [ "v11", "21/32" ] }