All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Farman <farman@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: qemu-s390x@nongnu.org, Matthew Rosato <mjrosato@linux.ibm.com>,
	Cornelia Huck <cohuck@redhat.com>,
	Zhuoying Cai <zycai@linux.ibm.com>,
	Eric Farman <farman@linux.ibm.com>
Subject: [PULL 20/37] hw/s390x/ipl: Rework s390_ipl_map_iplb_chain for certificate storage
Date: Wed, 26 Aug 2026 08:51:55 -0400	[thread overview]
Message-ID: <20260826125213.1901252-21-farman@linux.ibm.com> (raw)
In-Reply-To: <20260826125213.1901252-1-farman@linux.ibm.com>

From: Zhuoying Cai <zycai@linux.ibm.com>

Rework s390_ipl_map_iplb_chain to always allocate maximum memory for
the IPLB chain, regardless of the number of boot devices. This space
is also used to store certificates during secure boot, providing a
safe location for certificates until the kernel reads them during boot.

Rename next_iplb to ipl_data to better reflect its multiple purposes:
storing both IPLB chains and certificate data.

Signed-off-by: Zhuoying Cai <zycai@linux.ibm.com>
Reviewed-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20260730214624.2328883-19-zycai@linux.ibm.com
Signed-off-by: Eric Farman <farman@linux.ibm.com>
---
 hw/s390x/ipl.c              | 18 ++++++++++++++----
 hw/s390x/ipl.h              |  2 --
 include/hw/s390x/ipl/qipl.h |  5 ++++-
 pc-bios/s390-ccw/iplb.h     |  4 ++--
 4 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
index 627544b361..85fe2d3cb4 100644
--- a/hw/s390x/ipl.c
+++ b/hw/s390x/ipl.c
@@ -426,10 +426,9 @@ static S390PCIBusDevice *s390_get_pci_device(DeviceState *dev_st, int *devtype)
     return pbdev;
 }
 
-static uint64_t s390_ipl_map_iplb_chain(IplParameterBlock *iplb_chain)
+static uint64_t s390_ipl_map_iplb_chain(IplParameterBlock *iplb_chain, uint16_t count)
 {
     S390IPLState *ipl = get_ipl_device();
-    uint16_t count = be16_to_cpu(ipl->qipl.chain_len);
     uint64_t len = sizeof(IplParameterBlock) * count;
     uint64_t chain_addr = find_iplb_chain_addr(ipl->bios_start_addr, count);
 
@@ -593,7 +592,7 @@ void s390_rebuild_iplb(uint16_t dev_index, IplParameterBlock *iplb)
 static bool s390_init_all_iplbs(S390IPLState *ipl)
 {
     int iplb_num = 0;
-    IplParameterBlock iplb_chain[7];
+    IplParameterBlock iplb_chain[MAX_BOOT_DEVS - 1] = { 0 };
     DeviceState *dev_st = get_boot_device(0);
     Object *machine = qdev_get_machine();
 
@@ -639,13 +638,24 @@ static bool s390_init_all_iplbs(S390IPLState *ipl)
             dev_st = get_boot_device(i);
             s390_build_iplb(dev_st, &iplb_chain[i - 1]);
         }
+    }
 
-        ipl->qipl.next_iplb = cpu_to_be64(s390_ipl_map_iplb_chain(iplb_chain));
+    /*
+     * Allocate maximum space for IPLB chain and/or certificate storage.
+     * Once a valid boot device is found, this space will be used to store
+     * certificates if secure boot is enabled.
+     */
+    if (iplb_num > 1 || s390_has_certificate()) {
+        ipl->qipl.ipl_data = cpu_to_be64(s390_ipl_map_iplb_chain(iplb_chain,
+                                                                 MAX_BOOT_DEVS - 1));
     }
 
     return iplb_num;
 }
 
+QEMU_BUILD_BUG_MSG(sizeof(IplParameterBlock) * (MAX_BOOT_DEVS - 1) != CERT_BUF_SIZE,
+                   "certificate buffer size is wrong");
+
 static void update_machine_ipl_properties(IplParameterBlock *iplb)
 {
     Object *machine = qdev_get_machine();
diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h
index 5d54827b52..772566bb11 100644
--- a/hw/s390x/ipl.h
+++ b/hw/s390x/ipl.h
@@ -23,8 +23,6 @@
 #include "qom/object.h"
 #include "target/s390x/kvm/pv.h"
 
-#define MAX_BOOT_DEVS 8 /* Max number of devices that may have a bootindex */
-
 void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp);
 void s390_ipl_fmt_loadparm(uint8_t *loadparm, char *str, Error **errp);
 void s390_rebuild_iplb(uint16_t index, IplParameterBlock *iplb);
diff --git a/include/hw/s390x/ipl/qipl.h b/include/hw/s390x/ipl/qipl.h
index 6dccc74a9e..5d560a433a 100644
--- a/include/hw/s390x/ipl/qipl.h
+++ b/include/hw/s390x/ipl/qipl.h
@@ -43,7 +43,10 @@ typedef enum S390IplType S390IplType;
 #define S390_IPLB_MIN_QEMU_SCSI_LEN 200
 #define S390_IPLB_MAX_LEN 4096
 
+#define MAX_BOOT_DEVS 8 /* Max number of devices that may have a bootindex */
+
 #define MAX_CERTIFICATES  64
+#define CERT_BUF_SIZE     ((MAX_BOOT_DEVS - 1) * 4096)
 /* largest supported block size - same as VIRTIO_DASD_DEFAULT_BLOCK_SIZE */
 #define VIRTIO_MAX_BLOCK_SIZE   4096
 #define MAX_COMP_ENTRIES        ((VIRTIO_MAX_BLOCK_SIZE - 32) / 32)
@@ -63,7 +66,7 @@ struct QemuIplParameters {
     uint32_t boot_menu_timeout;
     uint8_t  reserved3[2];
     uint16_t chain_len;
-    uint64_t next_iplb;
+    uint64_t ipl_data;
 } QEMU_PACKED;
 typedef struct QemuIplParameters QemuIplParameters;
 
diff --git a/pc-bios/s390-ccw/iplb.h b/pc-bios/s390-ccw/iplb.h
index c92a3d0f0c..c807e7f49b 100644
--- a/pc-bios/s390-ccw/iplb.h
+++ b/pc-bios/s390-ccw/iplb.h
@@ -61,11 +61,11 @@ static inline bool load_next_iplb(void)
     }
 
     qipl.index++;
-    next_iplb = (IplParameterBlock *) qipl.next_iplb;
+    next_iplb = (IplParameterBlock *) qipl.ipl_data;
     memcpy(iplb, next_iplb, sizeof(IplParameterBlock));
 
     qipl.chain_len--;
-    qipl.next_iplb = qipl.next_iplb + sizeof(IplParameterBlock);
+    qipl.ipl_data = qipl.ipl_data + sizeof(IplParameterBlock);
 
     return true;
 }
-- 
2.55.0



  parent reply	other threads:[~2026-08-26 12:53 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 12:51 [PULL 00/37] s390x queue Eric Farman
2026-08-26 12:51 ` [PULL 01/37] s390x/sclp: pv: only copy the original SCCB buffer Eric Farman
2026-08-26 12:51 ` [PULL 02/37] s390x/css: Fix css stsch detection to go beyond 8192 devices Eric Farman
2026-08-26 12:51 ` [PULL 03/37] Add boot-certs to s390-ccw-virtio machine type option Eric Farman
2026-08-26 12:51 ` [PULL 04/37] crypto/x509-utils: Refactor with GNUTLS fallback Eric Farman
2026-08-26 12:51 ` [PULL 05/37] crypto/x509-utils: Add helper functions for certificate store Eric Farman
2026-08-26 12:51 ` [PULL 06/37] hw/s390x/ipl: Create " Eric Farman
2026-08-26 12:51 ` [PULL 07/37] s390x/diag: Introduce DIAG 320 for Certificate Store Facility Eric Farman
2026-08-26 12:51 ` [PULL 08/37] s390x/diag: Refactor address validation check from diag308_parm_check Eric Farman
2026-08-26 12:51 ` [PULL 09/37] s390x/diag: Implement DIAG 320 subcode 1 Eric Farman
2026-08-26 12:51 ` [PULL 10/37] crypto/x509-utils: Add helper functions for DIAG 320 subcode 2 Eric Farman
2026-08-26 12:51 ` [PULL 11/37] s390x/diag: Implement " Eric Farman
2026-08-26 12:51 ` [PULL 12/37] hw/s390x: Define finite size for single entry VCEntry Eric Farman
2026-08-26 12:51 ` [PULL 13/37] s390x/diag: Introduce DIAG 508 for secure IPL operations Eric Farman
2026-08-26 12:51 ` [PULL 14/37] crypto/x509-utils: Add helper functions for DIAG 508 subcode 1 Eric Farman
2026-08-26 12:51 ` [PULL 15/37] s390x/diag: Generalize s390_ipl_read/write to accept void * Eric Farman
2026-08-26 12:51 ` [PULL 16/37] s390x/diag: Implement DIAG 508 subcode 1 for signature verification Eric Farman
2026-08-26 12:51 ` [PULL 17/37] s390x/ipl: Introduce IPL Information Report Block (IIRB) Eric Farman
2026-08-26 12:51 ` [PULL 18/37] pc-bios/s390-ccw: Define memory for IPLB and convert IPLB to pointers Eric Farman
2026-08-26 12:51 ` [PULL 19/37] hw/s390x/ipl: Add IPIB flags to IPL Parameter Block Eric Farman
2026-08-26 12:51 ` Eric Farman [this message]
2026-08-26 12:51 ` [PULL 21/37] s390x: Guest support for Secure-IPL Facility Eric Farman
2026-08-26 12:51 ` [PULL 22/37] pc-bios/s390-ccw: Refactor zipl_run() Eric Farman
2026-08-26 12:51 ` [PULL 23/37] pc-bios/s390-ccw: Rework zipl_load_segment function Eric Farman
2026-08-26 12:51 ` [PULL 24/37] pc-bios/s390-ccw: Introduce ZiplBootMode enum for IPL mode selection Eric Farman
2026-08-26 12:52 ` [PULL 25/37] pc-bios/s390-ccw: Add signature verification for secure IPL in audit mode Eric Farman
2026-08-26 12:52 ` [PULL 26/37] pc-bios/s390-ccw: Add signed component address overlap checks Eric Farman
2026-08-26 12:52 ` [PULL 27/37] s390x: Guest support for Secure-IPL Code Loading Attributes Facility (SCLAF) Eric Farman
2026-08-26 12:52 ` [PULL 28/37] pc-bios/s390-ccw: Add additional security checks for secure boot Eric Farman
2026-08-26 12:52 ` [PULL 29/37] Add secure-boot to s390-ccw-virtio machine type option Eric Farman
2026-08-26 12:52 ` [PULL 30/37] hw/s390x/ipl: Set IPIB flags for secure IPL Eric Farman
2026-08-26 12:52 ` [PULL 31/37] pc-bios/s390-ccw: Handle true secure IPL mode Eric Farman
2026-08-26 12:52 ` [PULL 32/37] hw/s390x/ipl: Handle secure boot with multiple boot devices Eric Farman
2026-08-26 12:52 ` [PULL 33/37] tests/functional/s390x: Add secure IPL functional test Eric Farman
2026-08-26 12:52 ` [PULL 34/37] docs/specs: Add secure IPL documentation Eric Farman
2026-08-26 12:52 ` [PULL 35/37] docs/system/s390x: " Eric Farman
2026-08-26 12:52 ` [PULL 36/37] MAINTAINERS: Add secure IPL files to S390-ccw boot group Eric Farman
2026-08-26 12:52 ` [PULL 37/37] pc-bios/s390-ccw.img: update s390x bios Eric Farman
2026-08-27  4:18 ` [PULL 00/37] s390x queue Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260826125213.1901252-21-farman@linux.ibm.com \
    --to=farman@linux.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=zycai@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.