s390x queue for 11.2
Subsystems (2)
[PULL 09/33] target/s390x: Support AES CBC for cpacf kmc instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Support the subfunctions CPACF_KMC_AES_128, CPACF_KMC_AES_192 and CPACF_KMC_AES_256 for the cpacf kmc instruction.
--- target/s390x/gen-features.c | 3 ++ target/s390x/tcg/cpacf.h | 4 ++ target/s390x/tcg/cpacf_aes.c | 91 ++++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 24 +++++++++ 4 files changed, 122 insertions(+)
target/s390x/gen-features.c +3 -0
@@ -932,6 +932,9 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KM_AES_128 ,S390_FEAT_KM_AES_192 ,S390_FEAT_KM_AES_256 , +S390_FEAT_KMC_AES_128 , +S390_FEAT_KMC_AES_192 , + S390_FEAT_KMC_AES_256, };/****** END FEATURE DEFS ******/
target/s390x/tcg/cpacf.h +4 -0
@@ -23,5 +23,9 @@ int cpacf_aes_ecb(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint64_t param_addr, uint64_t *dst_ptr_reg, uint64_t *src_ptr_reg, uint64_t *src_len_reg, uint32_t type, uint8_t fc, uint8_t mod); +int cpacf_aes_cbc (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *dst_ptr_reg, +uint64_t *src_ptr_reg,uint64_t *src_len_reg, +uint32_t type,uint8_t fc,uint8_t mod);#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c +91 -0
94 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +24 -0
@@ -119,6 +119,27 @@ static int cpacf_km(CPUS390XState *env, const int mmu_idx, uintptr_t ra,return rc; } +static int cpacf_kmc (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint32_t r1,uint32_t r2,uint32_t r3, +uint8_t fc,uint8_t mod) +{ +int rc =0 ; + +switch (fc) { +case CPACF_KMC_AES_128 : +case CPACF_KMC_AES_192 : +case CPACF_KMC_AES_256 : + rc =cpacf_aes_cbc (env, mmu_idx, ra, env->regs[1 ], + &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], +S390_FEAT_TYPE_KMC , fc, mod); +break ; +default : +tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); + } + +return rc; +} +static int cpacf_ppno (CPUS390XState *env,const int mmu_idx,uintptr_t ra,uint32_t r1,uint32_t r2,uint32_t r3,uint8_t fc) {
@@ -190,6 +211,9 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,case S390_FEAT_TYPE_KM : rc =cpacf_km (env, mmu_idx, ra, r1, r2, r3, fc, mod);break ; +case S390_FEAT_TYPE_KMC : + rc =cpacf_kmc (env, mmu_idx, ra, r1, r2, r3, fc, mod); +break ;case S390_FEAT_TYPE_PPNO : rc =cpacf_ppno (env, mmu_idx, ra, r1, r2, r3, fc);break ;
Signature · 1 line
2.55.0
[PULL 13/33] target/s390x: Base support for cpacf protected keys and pckmo
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Add base support for cpacf protected key handling.
Add support for the pckmo subfunctions PCKMO-Encrypt-AES-128-Key, PCKMO-Encrypt-AES-192-Key and PCKMO-Encrypt-AES-256-Key which deal with protected keys. These pckmo subfunctions derive a protected key from an AES clear key by encrypting it with an internal AES wrapping key. More details about protected keys can be found in the "z/Architecture Prinziples of Operation" document.
The qemu version provided here is only a fake intended to make protected key available for developing and testing purpose:
* The protected key is 'derived' from the clear key by xoring the fixed pattern 0xAAAA... onto the key value.
* The AES Wrapping Key Verification Pattern is a fixed value of 32 bytes 0x0F0A0C0E0F0A0C0E...
Add preprocessor defines for the xor pattern and wkvp used to construct ('encrypt') a protected key from a clear key value with this implementation. Also add some static functions to 'encrypt' from clear key to protected key and 'decrypt' back to cpacf_aes.c.
The preprocessor defines shall be used later in testcases to construct and decode protected keys.
--- target/s390x/gen-features.c | 3 ++ target/s390x/tcg/cpacf-arch.h | 25 +++++++++++++ target/s390x/tcg/cpacf.h | 2 + target/s390x/tcg/cpacf_aes.c | 64 ++++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 21 +++++++++++ target/s390x/tcg/translate.c | 14 +++++-- 6 files changed, 126 insertions(+), 3 deletions(-)
target/s390x/gen-features.c +3 -0
@@ -942,6 +942,9 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KMCTR_AES_256 ,S390_FEAT_PCC_XTS_AES_128 ,S390_FEAT_PCC_XTS_AES_256 , +S390_FEAT_PCKMO_AES_128 , +S390_FEAT_PCKMO_AES_192 , + S390_FEAT_PCKMO_AES_256, };/****** END FEATURE DEFS ******/
target/s390x/tcg/cpacf-arch.h +25 -0
@@ -223,4 +223,29 @@#define CPACF_KDSA_PSIGN_ED25519 48#define CPACF_KDSA_PSIGN_ED448 52 +/* +* Support for protected key cpacf functions. Note that this is +* a fake implementation intended for debugging and development. +* Do not use for production load ! +*/ + +/* +* Hard coded pattern xored with the AES clear key +* to 'produce' the protected key. +*/ +#define PROTKEY_XOR_PATTERN { \ + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, \ + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, \ + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, \ + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA } + +/* +* Hard coded wkvp ("Wrapping Key Verification Pattern") +*/ +#define PROTKEY_WKVP { \ + 0x0F, 0x0A, 0x0C, 0x0E, 0x0F, 0x0A, 0x0C, 0x0E, \ + 0x0F, 0x0A, 0x0C, 0x0E, 0x0F, 0x0A, 0x0C, 0x0E, \ + 0x0F, 0x0A, 0x0C, 0x0E, 0x0F, 0x0A, 0x0C, 0x0E, \ + 0x0F, 0x0A, 0x0C, 0x0E, 0x0F, 0x0A, 0x0C, 0x0E } +#endif /* S390X_CPACF_ARCH_H */
target/s390x/tcg/cpacf.h +2 -0
@@ -38,5 +38,7 @@ int cpacf_aes_xts(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint64_t param_addr, uint64_t *dst_ptr_reg, uint64_t *src_ptr_reg, uint64_t *src_len_reg, uint32_t type, uint8_t fc, uint8_t mod); +int cpacf_aes_pckmo (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint8_t fc);#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c +64 -0
67 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +21 -0
@@ -205,6 +205,24 @@ static int cpacf_pcc(CPUS390XState *env, const int mmu_idx, uintptr_t ra,return rc; } +static int cpacf_pckmo (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint8_t fc) +{ +int rc =0 ; + +switch (fc) { +case CPACF_PCKMO_ENC_AES_128_KEY : +case CPACF_PCKMO_ENC_AES_192_KEY : +case CPACF_PCKMO_ENC_AES_256_KEY : + rc =cpacf_aes_pckmo (env, mmu_idx, ra, env->regs[1 ], fc); +break ; +default : +tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); + } + +return rc; +} +uint32_t HELPER (msa )(CPUS390XState *env,uint32_t r1,uint32_t r2,uint32_t r3,uint32_t type) {
@@ -264,6 +282,9 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,case S390_FEAT_TYPE_PCC : rc =cpacf_pcc (env, mmu_idx, ra, fc);break ; +case S390_FEAT_TYPE_PCKMO : + rc =cpacf_pckmo (env, mmu_idx, ra, fc); +break ;case S390_FEAT_TYPE_PPNO : rc =cpacf_ppno (env, mmu_idx, ra, r1, r2, r3, fc);break ;
target/s390x/tcg/translate.c +11 -3
@@ -2558,6 +2558,7 @@ static DisasJumpType op_msa(DisasContext *s, DisasOps *o)int r2 =have_field (s, r2) ?get_field (s, r2) :0 ;int r3 =have_field (s, r3) ?get_field (s, r3) :0 ;TCGv_i32 t_r1, t_r2, t_r3, type; +bool update_cc = true;switch (s->insn->data) {case S390_FEAT_TYPE_KMA :
@@ -2590,8 +2591,10 @@ static DisasJumpType op_msa(DisasContext *s, DisasOps *o)gen_program_exception (s,PGM_SPECIFICATION );return DISAS_NORETURN ; } -/* FALL THROUGH */ +break ;case S390_FEAT_TYPE_PCKMO : + update_cc = false; +/* FALL THROUGH */ case S390_FEAT_TYPE_PCC :break ;default :
@@ -2602,8 +2605,13 @@ static DisasJumpType op_msa(DisasContext *s, DisasOps *o) t_r2 =tcg_constant_i32 (r2); t_r3 =tcg_constant_i32 (r3); type =tcg_constant_i32 (s->insn->data); -gen_helper_msa (cc_op, tcg_env, t_r1, t_r2, t_r3, type); -set_cc_static (s); +if (update_cc) { +gen_helper_msa (cc_op, tcg_env, t_r1, t_r2, t_r3, type); +set_cc_static (s); + }else { +TCGv_i32 cc_dummy =tcg_temp_new_i32 (); +gen_helper_msa (cc_dummy, tcg_env, t_r1, t_r2, t_r3, type); + }return DISAS_NEXT ; }
Signature · 1 line
2.55.0
[PULL 28/33] pc-bios/s390-ccw: Abstract virtio_run() for generic use
In reply to Eric FarmanFrom: Jared Rossi <[email protected]>
The existing virtio_ccw_run() actually has no dependency on CCW. Rather than add a case for non-ccw devices, we can just put the main logic right in the virtio_run() call so that it can be used for other bus types directly.
--- pc-bios/s390-ccw/virtio-ccw.c | 17 ----------------- pc-bios/s390-ccw/virtio-ccw.h | 1 - pc-bios/s390-ccw/virtio.c | 16 +++++++++++----- 3 files changed, 11 insertions(+), 23 deletions(-)
pc-bios/s390-ccw/virtio-ccw.c +0 -17
@@ -107,23 +107,6 @@ long virtio_ccw_notify(SubChannelId schid, int vq_idx, long cookie) vq_idx, cookie); } -int virtio_ccw_run (VDev *vdev,int vqid,VirtioCmd *cmd) -{ -VRing *vr = &vdev->vrings[vqid]; -int i =0 ; - -do { -vring_send_buf (vr, cmd[i].data, cmd[i].size, - cmd[i].flags | (i ?VRING_HIDDEN_IS_CHAIN :0 )); - }while (cmd[i++].flags &VRING_DESC_F_NEXT ); - -vring_wait_reply (); -if (drain_irqs ()) { -return -1 ; - } -return 0 ; -} -int virtio_ccw_reset (VDev *vdev) {return run_ccw (vdev,CCW_CMD_VDEV_RESET ,NULL ,0 , false);
pc-bios/s390-ccw/virtio-ccw.h +0 -1
@@ -16,7 +16,6 @@ extern SubChannelId blk_schid;/* virtio-ccw.c */ int drain_irqs_ccw (SubChannelId schid);bool virtio_ccw_is_supported (VDev *vdev); -int virtio_ccw_run (VDev *vdev,int vqid,VirtioCmd *cmd);long virtio_ccw_notify (SubChannelId schid,int vq_idx,long cookie);int virtio_ccw_setup (VDev *vdev);int virtio_ccw_reset (VDev *vdev);
pc-bios/s390-ccw/virtio.c +11 -5
@@ -70,13 +70,19 @@ int drain_irqs(void)int virtio_run (VDev *vdev,int vqid,VirtioCmd *cmd) { -switch (vdev->ipl_type) { -case S390_IPL_TYPE_QEMU_SCSI : -case S390_IPL_TYPE_CCW : -return virtio_ccw_run (vdev, vqid, cmd); -default : +VRing *vr = &vdev->vrings[vqid]; +int i =0 ; + +do { +vring_send_buf (vr, cmd[i].data, cmd[i].size, + cmd[i].flags | (i ?VRING_HIDDEN_IS_CHAIN :0 )); + }while (cmd[i++].flags &VRING_DESC_F_NEXT ); + +vring_wait_reply (); +if (drain_irqs ()) {return -1 ; } +return 0 ; }void vring_init (VRing *vr,VqInfo *info)
Signature · 1 line
2.55.0
[PULL 32/33] s390x/pci: fix DMA slot leak on I/O TLB entry replacement
In reply to Eric FarmanFrom: Omar Elghoul <[email protected]>
When s390_pci_update_iotlb() does a mapping update for an IOVA that has an already-existing TLB entry with different permissions or translated address, it unmaps then remaps it. However, at the end of the map path, it unconditionally decrements the available DMA slot counter without a corresponding increment in the intermediate unmap branch.
This causes the DMA slot count to be decremented on every remapping of an active IOVA, leading to a permanent DMA slot leak. This remapping without a prior invalidation and sync is not seen today in well-behaved guests but is allowed by the architecture. Fix it by only decrementing available DMA slots when inserting a brand new mapping.
--- hw/s390x/s390-pci-inst.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-inst.c +4 -1
@@ -655,6 +655,7 @@ static uint32_t s390_pci_update_iotlb(S390PCIIOMMU *iommu, goto out; }else {if (cache) { +/* valid->valid transitions reuse the DMA slot */ if (cache->perm == entry->perm && cache->translated_addr == entry->translated_addr) { goto out;
@@ -665,6 +666,9 @@ static uint32_t s390_pci_update_iotlb(S390PCIIOMMU *iommu,memory_region_notify_iommu (&iommu->iommu_mr,0 , event); event.type =IOMMU_NOTIFIER_MAP ; event.entry.perm = entry->perm; + }else { +/* invalid->valid transitions consume a new DMA slot */ +dec_dma_avail (iommu); } cache =g_new (S390IOTLBEntry,1 );
@@ -673,7 +677,6 @@ static uint32_t s390_pci_update_iotlb(S390PCIIOMMU *iommu, cache->len =TARGET_PAGE_SIZE ; cache->perm = entry->perm;g_hash_table_replace (iommu->iotlb, &cache->iova, cache); -dec_dma_avail (iommu); }/*
Signature · 1 line
2.55.0
[PULL 27/33] s390x/ipl: Add PCI and bus fields to IplBlockQemuScsi
In reply to Eric FarmanFrom: Jared Rossi <[email protected]>
Rather than add a second non-architected IPLB type for scsi-pci devices, let's add the relevant fields to the existing struct so that it can handle both PCI and CCW scsi controllers.
The PCI and CCW fields of the IplBlockQemuScsi are aligned with same offsets as the corresponding fields in IplBlockPci and IplBlockCcw for potential union access.
Add comments for PCI/CCW specifics and also denote that the S390IplType enum values must fit in uint8_t.
--- hw/s390x/ipl.c | 1 + hw/s390x/ipl.h | 2 ++ include/hw/s390x/ipl/qipl.h | 13 +++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-)
hw/s390x/ipl.c +1 -0
@@ -563,6 +563,7 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb) iplb->scsi.lun =cpu_to_be32 (sd->lun); iplb->scsi.target =cpu_to_be16 (sd->id); iplb->scsi.channel =cpu_to_be16 (sd->channel); + iplb->scsi.bus =S390_IPL_TYPE_CCW ; iplb->scsi.devno =cpu_to_be16 (ccw_dev->sch->devno); iplb->scsi.ssid = ccw_dev->sch->ssid &3 ;break ;
hw/s390x/ipl.h +2 -0
@@ -86,6 +86,8 @@ struct S390IPLState {uint16_t devno; };QEMU_BUILD_BUG_MSG (offsetof(S390IPLState , iplb) &3 ,"alignment of iplb wrong" ); +QEMU_BUILD_BUG_MSG (offsetof(IplBlockQemuScsi , fid) != offsetof(IplBlockPci , fid), +"iplb fields misaligned across bus types" );static inline bool iplb_valid_len (IplParameterBlock *iplb) {
include/hw/s390x/ipl/qipl.h +9 -4
@@ -29,7 +29,7 @@ enum S390IplType {S390_IPL_TYPE_CCW =0x02 ,S390_IPL_TYPE_PCI =0x04 ,S390_IPL_TYPE_PV =0x05 , - S390_IPL_TYPE_QEMU_SCSI = 0xff + S390_IPL_TYPE_QEMU_SCSI = 0xff /* Max value, must fit in uint8_t */ };typedef enum S390IplType S390IplType ;
@@ -123,9 +123,14 @@ struct IplBlockQemuScsi {uint32_t lun;uint16_t target;uint16_t channel; -uint8_t reserved0[77 ]; -uint8_t ssid; -uint16_t devno; +uint8_t bus; +uint8_t reserved0[76 ]; +uint8_t ssid;/* CCW only */ +uint16_t devno;/* CCW only */ +uint8_t reserved1[216 ]; +uint8_t opt;/* PCI only */ +uint8_t reserved2[3 ]; +uint32_t fid;/* PCI only */ }QEMU_PACKED ;typedef struct IplBlockQemuScsi IplBlockQemuScsi ;
Signature · 1 line
2.55.0
[PULL 08/33] target/s390x: Support AES ECB for cpacf km instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Support the subfunctions CPACF_KM_AES_128, CPACF_KM_AES_192 and CPACF_KM_AES_256 for the cpacf km instruction.
--- target/s390x/gen-features.c | 3 + target/s390x/tcg/cpacf.h | 6 ++ target/s390x/tcg/cpacf_aes.c | 137 +++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 24 ++++++ target/s390x/tcg/meson.build | 1 + 5 files changed, 171 insertions(+) create mode 100644 target/s390x/tcg/cpacf_aes.c
target/s390x/gen-features.c +3 -0
@@ -929,6 +929,9 @@ static uint16_t qemu_MAX[] = {S390_FEAT_CERT_STORE ,S390_FEAT_SIPL ,S390_FEAT_SCLAF , +S390_FEAT_KM_AES_128 , +S390_FEAT_KM_AES_192 , + S390_FEAT_KM_AES_256, };/****** END FEATURE DEFS ******/
target/s390x/tcg/cpacf.h +6 -0
@@ -18,4 +18,10 @@ int cpacf_sha512(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint64_t param_addr, uint64_t *message_reg, uint64_t *len_reg, uint32_t type); +/* from cpacf_aes.c */ +int cpacf_aes_ecb (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *dst_ptr_reg, +uint64_t *src_ptr_reg,uint64_t *src_len_reg, +uint32_t type,uint8_t fc,uint8_t mod); +#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c new file +137 -0
137 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +24 -0
@@ -98,6 +98,27 @@ static int cpacf_klmd(CPUS390XState *env, const int mmu_idx, const uintptr_t ra,return rc; } +static int cpacf_km (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint32_t r1,uint32_t r2,uint32_t r3, +uint8_t fc,uint8_t mod) +{ +int rc =0 ; + +switch (fc) { +case CPACF_KM_AES_128 : +case CPACF_KM_AES_192 : +case CPACF_KM_AES_256 : + rc =cpacf_aes_ecb (env, mmu_idx, ra, env->regs[1 ], + &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], +S390_FEAT_TYPE_KM , fc, mod); +break ; +default : +tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); + } + +return rc; +} +static int cpacf_ppno (CPUS390XState *env,const int mmu_idx,uintptr_t ra,uint32_t r1,uint32_t r2,uint32_t r3,uint8_t fc) {
@@ -166,6 +187,9 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,case S390_FEAT_TYPE_KLMD : rc =cpacf_klmd (env, mmu_idx, ra, r1, r2, r3, fc);break ; +case S390_FEAT_TYPE_KM : + rc =cpacf_km (env, mmu_idx, ra, r1, r2, r3, fc, mod); +break ;case S390_FEAT_TYPE_PPNO : rc =cpacf_ppno (env, mmu_idx, ra, r1, r2, r3, fc);break ;
target/s390x/tcg/meson.build +1 -0
@@ -5,6 +5,7 @@ s390x_ss.add(when: 'CONFIG_TCG', if_true: files( )) s390x_common_ss.add(when: 'CONFIG_TCG', if_true: files( 'cc_helper.c', + 'cpacf_aes.c', 'cpacf_sha256.c', 'cpacf_sha512.c', 'crypto_helper.c',
Signature · 1 line
2.55.0
[PULL 14/33] target/s390x: Support protected key AES ECB for cpacf km instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Support the subfunctions CPACF_KM_PAES_128, CPACF_KM_PAES_192 and CPACF_KM_PAES_256 for the cpacf km instruction.
--- target/s390x/gen-features.c | 3 + target/s390x/tcg/cpacf.h | 4 ++ target/s390x/tcg/cpacf_aes.c | 103 +++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 7 +++ 4 files changed, 117 insertions(+)
target/s390x/gen-features.c +3 -0
@@ -932,6 +932,9 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KM_AES_128 ,S390_FEAT_KM_AES_192 ,S390_FEAT_KM_AES_256 , +S390_FEAT_KM_EAES_128 , +S390_FEAT_KM_EAES_192 , +S390_FEAT_KM_EAES_256 ,S390_FEAT_KM_XTS_AES_128 ,S390_FEAT_KM_XTS_AES_256 , S390_FEAT_KMC_AES_128,
target/s390x/tcg/cpacf.h +4 -0
@@ -40,5 +40,9 @@ int cpacf_aes_xts(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint32_t type, uint8_t fc, uint8_t mod);int cpacf_aes_pckmo (CPUS390XState *env,const int mmu_idx,uintptr_t ra,uint64_t param_addr,uint8_t fc); +int cpacf_paes_ecb (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *dst_ptr_reg, +uint64_t *src_ptr_reg,uint64_t *src_len_reg, +uint32_t type,uint8_t fc,uint8_t mod);#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c +103 -0
112 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +7 -0
@@ -112,6 +112,13 @@ static int cpacf_km(CPUS390XState *env, const int mmu_idx, uintptr_t ra, &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], S390_FEAT_TYPE_KM, fc, mod);break ; +case CPACF_KM_PAES_128 : +case CPACF_KM_PAES_192 : +case CPACF_KM_PAES_256 : + rc =cpacf_paes_ecb (env, mmu_idx, ra, env->regs[1 ], + &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], +S390_FEAT_TYPE_KM , fc, mod); +break ;case CPACF_KM_XTS_128 :case CPACF_KM_XTS_256 : rc = cpacf_aes_xts(env, mmu_idx, ra, env->regs[1],
Signature · 1 line
2.55.0
[PULL 33/33] pc-bios/s390-ccw.img: update s390x bios
In reply to Eric FarmanRebuild bios to include:
- [email protected]
- [email protected]
--- pc-bios/s390-ccw.img | Bin 112408 -> 112408 bytes 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-ccw.img binary +0 -0
Signature · 1 line
2.55.0
[PULL 01/33] target/s390x: Fix missing privileged flag at PCKMO instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
The CPACF instruction PCKMO is a privileged instruction. So set the IF_PRIV flag in insn-data.h.inc to reflect this.
--- target/s390x/tcg/insn-data.h.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/tcg/insn-data.h.inc +1 -1
@@ -1007,7 +1007,7 @@ /* MSA Instructions */ D(0xb91e, KMAC, RRE, MSA, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_KMAC) - D(0xb928, PCKMO, RRE, MSA3, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_PCKMO) + E(0xb928, PCKMO, RRE, MSA3, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_PCKMO, IF_PRIV) D(0xb92a, KMF, RRE, MSA4, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_KMF) D(0xb92b, KMO, RRE, MSA4, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_KMO) D(0xb92c, PCC, RRE, MSA4, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_PCC)
Signature · 1 line
2.55.0
[PULL 22/33] tests/functional/s390x/test_secure_ipl: Skip test if SIPL not supported by hypervisor
In reply to Eric FarmanFrom: Joshua Daley <[email protected]>
Currently, if secure IPL is not supported by the hypervisor, the test will fail because "Verified component" never appears. One must inspect the console log to observe the cause of the failure.
Add a check that skips the test if the host CPU model is missing the secure IPL facilities.
--- tests/functional/s390x/test_secure_ipl.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
tests/functional/s390x/test_secure_ipl.py +18 -0
@@ -29,6 +29,22 @@ def __init__(self, *args, **kwargs): self.cert_path = None self.prompt = None + def _require_host_secure_ipl_support(self, vm): + """ + Skip the test if the host CPU model does not expose the Secure IPL + facilities (sipl, sclaf, cstore). + """ + props = vm.cmd('query-cpu-model-expansion', + model={'name': 'host'}, + type='full')['model']['props'] + missing = [f for f in ('sipl', 'sclaf', 'cstore') + if not props.get(f)] + if missing: + self.skipTest( + f"Host CPU does not support Secure IPL: " + f"missing feature(s): {', '.join(missing)}. " + f"Secure IPL requires a z16+ host.") + def _create_certificate(self, vm): """Generate x509 certificate""" exec_command_and_wait_for_pattern(self,
@@ -107,6 +123,8 @@ def setup_s390x_secure_ipl(self): '-device', 'virtio-blk-ccw,drive=drive0,bootindex=1') temp_vm.launch() + self._require_host_secure_ipl_support(temp_vm) + # Initial root account setup (Fedora first boot screen) self.root_password = 'fedora40password' wait_for_console_pattern(self, 'Please make a selection from the above',
Signature · 1 line
2.55.0
[PULL 15/33] target/s390x: Support protected key AES CBC for cpacf kmc instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Support the subfunctions CPACF_KMC_PAES_128, CPACF_KMC_PAES_192 and CPACF_KMC_PAES_256 for the cpacf kmc instruction.
--- target/s390x/gen-features.c | 3 + target/s390x/tcg/cpacf.h | 4 ++ target/s390x/tcg/cpacf_aes.c | 102 +++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 7 +++ 4 files changed, 116 insertions(+)
target/s390x/gen-features.c +3 -0
@@ -940,6 +940,9 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KMC_AES_128 ,S390_FEAT_KMC_AES_192 ,S390_FEAT_KMC_AES_256 , +S390_FEAT_KMC_EAES_128 , +S390_FEAT_KMC_EAES_192 , +S390_FEAT_KMC_EAES_256 ,S390_FEAT_KMCTR_AES_128 ,S390_FEAT_KMCTR_AES_192 , S390_FEAT_KMCTR_AES_256,
target/s390x/tcg/cpacf.h +4 -0
@@ -44,5 +44,9 @@ int cpacf_paes_ecb(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint64_t param_addr, uint64_t *dst_ptr_reg, uint64_t *src_ptr_reg, uint64_t *src_len_reg, uint32_t type, uint8_t fc, uint8_t mod); +int cpacf_paes_cbc (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *dst_ptr_reg, +uint64_t *src_ptr_reg,uint64_t *src_len_reg, +uint32_t type,uint8_t fc,uint8_t mod);#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c +102 -0
105 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +7 -0
@@ -146,6 +146,13 @@ static int cpacf_kmc(CPUS390XState *env, const int mmu_idx, uintptr_t ra, &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], S390_FEAT_TYPE_KMC, fc, mod);break ; +case CPACF_KMC_PAES_128 : +case CPACF_KMC_PAES_192 : +case CPACF_KMC_PAES_256 : + rc =cpacf_paes_cbc (env, mmu_idx, ra, env->regs[1 ], + &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], +S390_FEAT_TYPE_KMC , fc, mod); +break ;default :tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); }
Signature · 1 line
2.55.0
[PULL 19/33] docs/s390: Document CPACF instructions support
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Add a first document covering the Qemu s390 CPACF instructions and functions supported.
--- docs/system/s390x/cpacf.rst | 143 +++++++++++++++++++++++++++++++++++ docs/system/target-s390x.rst | 1 + 2 files changed, 144 insertions(+) create mode 100644 docs/system/s390x/cpacf.rst
docs/system/s390x/cpacf.rst new file +143 -0
@@ -0,0 +1,143 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +CPACF Support +============= + +CPACF +----- + +CP Assist for Cryptographic Function (CPACF) is a hardware-integrated +coprocessor feature built into every processor core of IBM Z and +LinuxONE mainframes (s390x architecture). It provides high-speed, +hardware-accelerated encryption and hashing directly on the CPU. + +CPACF provides a set of z/Architecture instructions (known as Message +Security Assist or MSA) that execute cryptographic operations +synchronously with the main processor. + +- Symmetric Encryption: Support for AES (128, 192, 256-bit), DES, and + Triple-DES (TDES). +- Hashing: Acceleration for SHA-1, SHA-2 (up to SHA-512), SHA-3 and + SHAKE. +- Random Number Generation: Pseudo Random Number Generator (PRNG) and + a hardware-based True Random Number Generator (TRNG). +- Asymmetric Support: Elliptic Curve Cryptography (ECC) primitives + P-256, P-384, P-521, Montgomery/Edwards curves (e.g., Ed25519). + +Documentation about CPACF instructions is publicly available and +can be found in the "z/Architecture Principles of Operation" +accessible at the IBM documentation hub https://www.ibm.com/docs/en. +For example the latest version as a pdf is available here: +https://www.ibm.com/support/pages/zvm/library/other/22783214.pdf + + +CPACF instructions +------------------ + +Here is a list of implemented CPACF instructions and the supported +functions for each instruction: + +KDSA (COMPUTE DIGITAL SIGNATURE AUTHENTICATION) +- Function code 0x00 - Function Query + +KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST) +- Function code 0x00 - Function Query +- Function code 0x02 - CPACF_KIMD_SHA_256 +- Function code 0x03 - CPACF_KIMD_SHA_512 + +KLMD (COMPUTE LAST MESSAGE DIGEST) +- Function code 0x00 - Function Query +- Function code 0x02 - CPACF_KLMD_SHA_256 +- Function code 0x03 - CPACF_KLMD_SHA_512 + +KM (CIPHER MESSAGE) +- Function code 0x00 - Function Query +- Function code 0x12 - CPACF_KM_AES_128 +- Function code 0x13 - CPACF_KM_AES_192 +- Function code 0x14 - CPACF_KM_AES_256 +- Function code 0x1a - CPACF_KM_PAES_128 +- Function code 0x1b - CPACF_KM_PAES_192 +- Function code 0x1c - CPACF_KM_PAES_256 +- Function code 0x32 - CPACF_KM_XTS_128 +- Function code 0x34 - CPACF_KM_XTS_256 +- Function code 0x3a - CPACF_KM_PXTS_128 +- Function code 0x3c - CPACF_KM_PXTS_256 + +KMAC (COMPUTE MESSAGE AUTHENTICATION CODE) +- Function code 0x00 - Function Query + +KMC (CIPHER MESSAGE WITH CHAINING) +- Function code 0x00 - Function Query +- Function code 0x12 - CPACF_KMC_AES_128 +- Function code 0x13 - CPACF_KMC_AES_192 +- Function code 0x14 - CPACF_KMC_AES_256 +- Function code 0x1a - CPACF_KMC_PAES_128 +- Function code 0x1b - CPACF_KMC_PAES_192 +- Function code 0x1c - CPACF_KMC_PAES_256 + +KMCTR (CIPHER MESSAGE WITH COUNTER) +- Function code 0x00 - Function Query +- Function code 0x12 - CPACF_KMCTR_AES_128 +- Function code 0x13 - CPACF_KMCTR_AES_192 +- Function code 0x14 - CPACF_KMCTR_AES_256 +- Function code 0x1a - CPACF_KMCTR_PAES_128 +- Function code 0x1b - CPACF_KMCTR_PAES_192 +- Function code 0x1c - CPACF_KMCTR_PAES_256 + +KMF (CIPHER MESSAGE WITH CIPHER FEEDBACK) +- not supported + +KMO (CIPHER MESSAGE WITH OUTPUT FEEDBACK) +- not supported + +PCC (PERFORM CRYPTOGRAPHIC COMPUTATION) +- Function code 0x00 - Function Query +- Function code 0x32 - compute XTS param AES-128 +- Function code 0x34 - compute XTS param AES-256 +- Function code 0x3a - compute XTS param Encrypted AES-128 +- Function code 0x3c - compute XTS param Encrypted AES-256 + +PCKMO (PERFORM CRYPTOGRAPHIC KEY MANAGEMENT OPERATION) +- Function code 0x00 - Function Query +- Function code 0x12 - CPACF_PCKMO_ENC_AES_128_KEY +- Function code 0x13 - CPACF_PCKMO_ENC_AES_192_KEY +- Function code 0x14 - CPACF_PCKMO_ENC_AES_256_KEY + +PRNO (PERFORM RANDOM NUMBER OPERATION) +- Function code 0x00 - Function Query +- Function code 0x72 - CPACF_PRNO_TRNG + +Not listed CPACF instructions (KMA) cause an Operation Exception when +used. Instructions with only query function support (KMF, KMO, KDSA) +perform register validation and raise a Specification Exception for +invalid registers or non-query function codes. The query function for +these instructions will return a function status word with all but the +query function bit set to 0. + + +Protected key support +--------------------- + +The qemu version for protected key support is only a fake provided +here for developing and testing purpose: + +- The protected key is _derived_ from the clear key by xoring the + fixed pattern 0xAAAA... onto the key value. +- The AES Wrapping Key Verification Pattern is a fixed value of 32 + bytes 0x0F0A0C0E0F0A0C0E... + +The PCKMO instruction implementation does exactly this - _derive_ a +_protected_ key from the clear key given by xor 0xAAAA... and writing +the fixed value for the WKVP of 0x0F0A0C0E0F0A0C0E... into the blob. +The other subfunctions of the CPACF instructions dealing with +protected key treat the protected key blob by first checking for the +WKVP (against the fixed value of 0x0F0A0C0E0F0A0C0E...) and second +_decrypting_ the key value by xoring 0xAAAA... and then execute the +clear key operation with the decrypted key value. +This is suitable for testing purpose but such keys are not for real +production load and would open up a huge security breach! + +For more details about protected keys see the "z/Architecture +Principles of Operation" document chapter "General Instructions" +sub-chapter "Protection of Cryptographic Keys" and again the +implementation here does NOT implement what is explained there.
docs/system/target-s390x.rst +1 -0
@@ -36,3 +36,4 @@ Architectural features s390x/protvirt s390x/cpu-topology s390x/secure-ipl + s390x/cpacf
Signature · 1 line
2.55.0
[PULL 23/33] tests/functional/s390x/test_secure_ipl: Add virtio-blk-pci boot dev case
In reply to Eric FarmanFrom: Joshua Daley <[email protected]>
Split test_s390x_secure_ipl() into two subtests. Each tests with a different boot device: virtio-blk-ccw or virtio-blk-pci. Use class-level variables and a temporary shared workdir such that the time-consuming setup is not run multiple times.
--- tests/functional/s390x/test_secure_ipl.py | 139 +++++++++++++++------- 1 file changed, 95 insertions(+), 44 deletions(-)
tests/functional/s390x/test_secure_ipl.py +95 -44
@@ -8,6 +8,9 @@ secure-boot enabled, and verifying cryptographic validation results. """ +import os +import shutil +import tempfile from subprocess import check_call, DEVNULL from qemu_test import QemuSystemTest, Asset, get_qemu_img
@@ -22,12 +25,25 @@ class S390xSecureIpl(QemuSystemTest): 'Fedora-Server-KVM-40-1.14.s390x.qcow2'), '091c232a7301be14e19c76ce9a0c1cbd2be2c4157884a731e1fc4f89e7455a5f') - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.root_password = None - self.qcow2_path = None - self.cert_path = None - self.prompt = None + _shared_workdir = None + _root_password = None + _qcow2_path = None + _cert_path = None + _prompt = None + _setup_done = None + _host_lacks_sipl_support = False + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls._shared_workdir = tempfile.mkdtemp(prefix='qemu_sipl_') + + @classmethod + def tearDownClass(cls): + if cls._shared_workdir is not None: + shutil.rmtree(cls._shared_workdir, ignore_errors=True) + cls._shared_workdir = None + super().tearDownClass() def _require_host_secure_ipl_support(self, vm): """
@@ -40,6 +56,7 @@ def _require_host_secure_ipl_support(self, vm): missing = [f for f in ('sipl', 'sclaf', 'cstore') if not props.get(f)] if missing: + S390xSecureIpl._host_lacks_sipl_support = True self.skipTest( f"Host CPU does not support Secure IPL: " f"missing feature(s): {', '.join(missing)}. "
@@ -62,7 +79,7 @@ def _sign_binaries(self, vm): exec_command_and_wait_for_pattern(self, 'sudo dnf install kernel-devel-$(uname -r) -y', 'Complete!', vm=vm) - wait_for_console_pattern(self, self.prompt, vm=vm) + wait_for_console_pattern(self, S390xSecureIpl._prompt, vm=vm) exec_command_and_wait_for_pattern(self, 'ls /usr/src/kernels/$(uname -r)/scripts/', 'sign-file', vm=vm)
@@ -71,11 +88,11 @@ def _sign_binaries(self, vm): exec_command(self, '/usr/src/kernels/$(uname -r)/scripts/sign-file ' 'sha256 mykey.pem mycert.pem /lib/s390-tools/stage3.bin', vm=vm) - wait_for_console_pattern(self, self.prompt, vm=vm) + wait_for_console_pattern(self, S390xSecureIpl._prompt, vm=vm) exec_command(self, '/usr/src/kernels/$(uname -r)/scripts/sign-file ' 'sha256 mykey.pem mycert.pem /boot/vmlinuz-$(uname -r)', vm=vm) - wait_for_console_pattern(self, self.prompt, vm=vm) + wait_for_console_pattern(self, S390xSecureIpl._prompt, vm=vm) def _run_zipl_secure(self, vm): """Run zipl to prepare for secure boot"""
@@ -91,10 +108,11 @@ def _extract_certificate(self, vm): cert = "\n".join(out.decode("utf-8").splitlines()[1:]) self.log.info("%s", cert) - self.cert_path = self.scratch_file("mycert.pem") + cert_path = os.path.join(S390xSecureIpl._shared_workdir, "mycert.pem") - with open(self.cert_path, 'w', encoding="utf-8") as file_object: + with open(cert_path, 'w', encoding="utf-8") as file_object: file_object.write(cert) + S390xSecureIpl._cert_path = cert_path def setup_s390x_secure_ipl(self): """
@@ -109,39 +127,42 @@ def setup_s390x_secure_ipl(self): temp_vm.set_machine('s390-ccw-virtio') asset_path = self.ASSET_F40_QCOW2.fetch() - self.qcow2_path = self.scratch_file('f40.qcow2') + qcow2_path = os.path.join(S390xSecureIpl._shared_workdir, 'f40.qcow2') qemu_img = get_qemu_img(self) check_call([qemu_img, 'create', '-f', 'qcow2', '-b', asset_path, - '-F', 'qcow2', self.qcow2_path], stdout=DEVNULL, stderr=DEVNULL) + '-F', 'qcow2', qcow2_path], stdout=DEVNULL, stderr=DEVNULL) + S390xSecureIpl._qcow2_path = qcow2_path temp_vm.set_console() temp_vm.add_args('-nographic', '-accel', 'kvm', '-m', '1024', '-drive', - f'id=drive0,if=none,format=qcow2,file={self.qcow2_path}', + f'id=drive0,if=none,format=qcow2,file={qcow2_path}', '-device', 'virtio-blk-ccw,drive=drive0,bootindex=1') temp_vm.launch() self._require_host_secure_ipl_support(temp_vm) # Initial root account setup (Fedora first boot screen) - self.root_password = 'fedora40password' + S390xSecureIpl._root_password = 'fedora40password' wait_for_console_pattern(self, 'Please make a selection from the above', vm=temp_vm) exec_command_and_wait_for_pattern(self, '4', 'Password:', vm=temp_vm) - exec_command_and_wait_for_pattern(self, self.root_password, + exec_command_and_wait_for_pattern(self, S390xSecureIpl._root_password, 'Password (confirm):', vm=temp_vm) - exec_command_and_wait_for_pattern(self, self.root_password, + exec_command_and_wait_for_pattern(self, S390xSecureIpl._root_password, 'Please make a selection from the above', vm=temp_vm) # Login as root - self.prompt = '[root@localhost ~]#' - exec_command_and_wait_for_pattern(self, 'c', 'localhost login:', vm=temp_vm) - exec_command_and_wait_for_pattern(self, 'root', 'Password:', vm=temp_vm) - exec_command_and_wait_for_pattern(self, self.root_password, self.prompt, + S390xSecureIpl._prompt = '[root@localhost ~]#' + exec_command_and_wait_for_pattern(self, 'c', 'localhost login:', vm=temp_vm) + exec_command_and_wait_for_pattern(self, 'root', 'Password:', + vm=temp_vm) + exec_command_and_wait_for_pattern(self, S390xSecureIpl._root_password, + S390xSecureIpl._prompt, vm=temp_vm) self._create_certificate(temp_vm) self._sign_binaries(temp_vm)
@@ -150,41 +171,71 @@ def setup_s390x_secure_ipl(self): # Shutdown temp vm temp_vm.shutdown() + S390xSecureIpl._setup_done = True - @skipBigDataTest() - def test_s390x_secure_ipl(self): + def verify_s390x_secure_ipl(self, boot_dev_bus: str): """ Verify secure boot validation during s390x guest boot. Expects two "Verified component" messages and confirms /sys/firmware/ipl/secure reports secure boot is active. """ - self.require_accelerator('kvm') - self.setup_s390x_secure_ipl() - - self.set_machine('s390-ccw-virtio') - - self.vm.set_console() - self.vm.add_args('-nographic', - '-machine', 's390-ccw-virtio,secure-boot=on,' - f'boot-certs.0.path={self.cert_path}', - '-accel', 'kvm', - '-m', '1024', - '-drive', - f'id=drive1,if=none,format=qcow2,file={self.qcow2_path}', - '-device', 'virtio-blk-ccw,drive=drive1,bootindex=1') - self.vm.launch() + if boot_dev_bus not in ['ccw', 'pci']: + raise ValueError( + f"boot_dev_bus must be 'ccw' or 'pci', got {boot_dev_bus}") + + vm = self.get_vm(name=f'sipl_test_vblk_{boot_dev_bus}') + vm.set_machine('s390-ccw-virtio') + + vm.set_console() + vm.add_args('-nographic', + '-machine', 's390-ccw-virtio,secure-boot=on,' + f'boot-certs.0.path={S390xSecureIpl._cert_path}', + '-accel', 'kvm', + '-m', '1024', + '-drive', + f'id=drive1,if=none,format=qcow2,' + f'file={S390xSecureIpl._qcow2_path}', + '-device', + f'virtio-blk-{boot_dev_bus},drive=drive1,bootindex=1') + vm.launch() # Expect two verified components verified_output = "Verified component" - wait_for_console_pattern(self, verified_output) - wait_for_console_pattern(self, verified_output) + wait_for_console_pattern(self, verified_output, vm=vm) + wait_for_console_pattern(self, verified_output, vm=vm) # Login and verify the vm is booted using secure boot - wait_for_console_pattern(self, 'localhost login:') - exec_command_and_wait_for_pattern(self, 'root', 'Password:') - exec_command_and_wait_for_pattern(self, self.root_password, self.prompt) - exec_command_and_wait_for_pattern(self, 'cat /sys/firmware/ipl/secure', '1') + wait_for_console_pattern(self, 'localhost login:', vm=vm) + exec_command_and_wait_for_pattern(self, 'root', 'Password:', vm=vm) + exec_command_and_wait_for_pattern( + self, S390xSecureIpl._root_password, S390xSecureIpl._prompt, vm=vm) + exec_command_and_wait_for_pattern( + self, 'cat /sys/firmware/ipl/secure', '1', vm=vm) + + vm.shutdown() + + @skipBigDataTest() + def test_s390x_secure_ipl_ccw(self): + """Test secure IPL with a virtio-blk-ccw boot device.""" + self.require_accelerator('kvm') + if S390xSecureIpl._host_lacks_sipl_support: + self.skipTest("Host CPU does not support Secure IPL. " + "Secure IPL requires a z16+ host.") + if not S390xSecureIpl._setup_done: + self.setup_s390x_secure_ipl() + self.verify_s390x_secure_ipl('ccw') + + @skipBigDataTest() + def test_s390x_secure_ipl_pci(self): + """Test secure IPL with a virtio-blk-pci boot device.""" + self.require_accelerator('kvm') + if S390xSecureIpl._host_lacks_sipl_support: + self.skipTest("Host CPU does not support Secure IPL. " + "Secure IPL requires a z16+ host.") + if not S390xSecureIpl._setup_done: + self.setup_s390x_secure_ipl() + self.verify_s390x_secure_ipl('pci') if __name__ == '__main__': QemuSystemTest.main()
Signature · 1 line
2.55.0
[PULL 02/33] target/s390x: Rework s390 cpacf implementations
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Fix missing parts for MSA 9 kdsa and rework the cpacf handling code so that further extensions can be made in a clean and structured way.
Introduce a new header file cpacf-arch.h to hold defines, structs and function prototypes around s390 cpacf. Use the cpcaf function defines in the existing code.
--- target/s390x/tcg/cpacf-arch.h | 226 +++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 101 +++++++++++--- target/s390x/tcg/insn-data.h.inc | 1 + target/s390x/tcg/translate.c | 2 + 4 files changed, 311 insertions(+), 19 deletions(-) create mode 100644 target/s390x/tcg/cpacf-arch.h
target/s390x/tcg/cpacf-arch.h new file +226 -0
@@ -0,0 +1,226 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* s390x cpacf-arch +* +*/ + +#ifndef S390X_CPACF_ARCH_H +#define S390X_CPACF_ARCH_H + +/* +* Function codes for the KM instruction +*/ +#define CPACF_KM_QUERY 0x00 +#define CPACF_KM_DEA 0x01 +#define CPACF_KM_TDEA_128 0x02 +#define CPACF_KM_TDEA_192 0x03 +#define CPACF_KM_AES_128 0x12 +#define CPACF_KM_AES_192 0x13 +#define CPACF_KM_AES_256 0x14 +#define CPACF_KM_PAES_128 0x1a +#define CPACF_KM_PAES_192 0x1b +#define CPACF_KM_PAES_256 0x1c +#define CPACF_KM_XTS_128 0x32 +#define CPACF_KM_XTS_256 0x34 +#define CPACF_KM_PXTS_128 0x3a +#define CPACF_KM_PXTS_256 0x3c +#define CPACF_KM_FULL_XTS_128 0x52 +#define CPACF_KM_FULL_XTS_256 0x54 +#define CPACF_KM_FULL_PXTS_128 0x5a +#define CPACF_KM_FULL_PXTS_256 0x5c + +/* +* Function codes for the KMC instruction +*/ +#define CPACF_KMC_QUERY 0x00 +#define CPACF_KMC_DEA 0x01 +#define CPACF_KMC_TDEA_128 0x02 +#define CPACF_KMC_TDEA_192 0x03 +#define CPACF_KMC_AES_128 0x12 +#define CPACF_KMC_AES_192 0x13 +#define CPACF_KMC_AES_256 0x14 +#define CPACF_KMC_PAES_128 0x1a +#define CPACF_KMC_PAES_192 0x1b +#define CPACF_KMC_PAES_256 0x1c +#define CPACF_KMC_PRNG 0x43 + +/* +* Function codes for the KMCTR instruction +*/ +#define CPACF_KMCTR_QUERY 0x00 +#define CPACF_KMCTR_DEA 0x01 +#define CPACF_KMCTR_TDEA_128 0x02 +#define CPACF_KMCTR_TDEA_192 0x03 +#define CPACF_KMCTR_AES_128 0x12 +#define CPACF_KMCTR_AES_192 0x13 +#define CPACF_KMCTR_AES_256 0x14 +#define CPACF_KMCTR_PAES_128 0x1a +#define CPACF_KMCTR_PAES_192 0x1b +#define CPACF_KMCTR_PAES_256 0x1c + +/* +* Function codes for the KIMD instruction +*/ +#define CPACF_KIMD_QUERY 0x00 +#define CPACF_KIMD_SHA_1 0x01 +#define CPACF_KIMD_SHA_256 0x02 +#define CPACF_KIMD_SHA_512 0x03 +#define CPACF_KIMD_SHA3_224 0x20 +#define CPACF_KIMD_SHA3_256 0x21 +#define CPACF_KIMD_SHA3_384 0x22 +#define CPACF_KIMD_SHA3_512 0x23 +#define CPACF_KIMD_SHAKE_128 0x24 +#define CPACF_KIMD_SHAKE_256 0x25 +#define CPACF_KIMD_GHASH 0x41 + +/* +* Function codes for the KLMD instruction +*/ +#define CPACF_KLMD_QUERY 0x00 +#define CPACF_KLMD_SHA_1 0x01 +#define CPACF_KLMD_SHA_256 0x02 +#define CPACF_KLMD_SHA_512 0x03 +#define CPACF_KLMD_SHA3_224 0x20 +#define CPACF_KLMD_SHA3_256 0x21 +#define CPACF_KLMD_SHA3_384 0x22 +#define CPACF_KLMD_SHA3_512 0x23 +#define CPACF_KLMD_SHAKE_128 0x24 +#define CPACF_KLMD_SHAKE_256 0x25 + +/* +* function codes for the KMAC instruction +*/ +#define CPACF_KMAC_QUERY 0x00 +#define CPACF_KMAC_DEA 0x01 +#define CPACF_KMAC_TDEA_128 0x02 +#define CPACF_KMAC_TDEA_192 0x03 +#define CPACF_KMAC_AES_128 0x12 +#define CPACF_KMAC_AES_192 0x13 +#define CPACF_KMAC_AES_256 0x14 +#define CPACF_KMAC_PAES_128 0x1A +#define CPACF_KMAC_PAES_192 0x1B +#define CPACF_KMAC_PAES_256 0x1C +#define CPACF_KMAC_HMAC_SHA_224 0x70 +#define CPACF_KMAC_HMAC_SHA_256 0x71 +#define CPACF_KMAC_HMAC_SHA_384 0x72 +#define CPACF_KMAC_HMAC_SHA_512 0x73 +#define CPACF_KMAC_PHMAC_SHA_224 0x78 +#define CPACF_KMAC_PHMAC_SHA_256 0x79 +#define CPACF_KMAC_PHMAC_SHA_384 0x7a +#define CPACF_KMAC_PHMAC_SHA_512 0x7b + +/* +* Function codes for the PCKMO instruction +*/ +#define CPACF_PCKMO_QUERY 0x00 +#define CPACF_PCKMO_ENC_DES_KEY 0x01 +#define CPACF_PCKMO_ENC_TDES_128_KEY 0x02 +#define CPACF_PCKMO_ENC_TDES_192_KEY 0x03 +#define CPACF_PCKMO_ENC_AES_128_KEY 0x12 +#define CPACF_PCKMO_ENC_AES_192_KEY 0x13 +#define CPACF_PCKMO_ENC_AES_256_KEY 0x14 +#define CPACF_PCKMO_ENC_AES_XTS_128_DOUBLE_KEY 0x15 +#define CPACF_PCKMO_ENC_AES_XTS_256_DOUBLE_KEY 0x16 +#define CPACF_PCKMO_ENC_ECC_P256_KEY 0x20 +#define CPACF_PCKMO_ENC_ECC_P384_KEY 0x21 +#define CPACF_PCKMO_ENC_ECC_P521_KEY 0x22 +#define CPACF_PCKMO_ENC_ECC_ED25519_KEY 0x28 +#define CPACF_PCKMO_ENC_ECC_ED448_KEY 0x29 +#define CPACF_PCKMO_ENC_HMAC_512_KEY 0x76 +#define CPACF_PCKMO_ENC_HMAC_1024_KEY 0x7a + +/* +* Function codes for the PRNO instruction +*/ +#define CPACF_PRNO_QUERY 0x00 +#define CPACF_PRNO_SHA512_DRNG_GEN 0x03 +#define CPACF_PRNO_SHA512_DRNG_SEED 0x83 +#define CPACF_PRNO_TRNG_Q_R2C_RATIO 0x70 +#define CPACF_PRNO_TRNG 0x72 + +/* +* Function codes for the KMA instruction +*/ +#define CPACF_KMA_QUERY 0x00 +#define CPACF_KMA_GCM_AES_128 0x12 +#define CPACF_KMA_GCM_AES_192 0x13 +#define CPACF_KMA_GCM_AES_256 0x14 +#define CPACF_KMA_GCM_PAES_128 0x1A +#define CPACF_KMA_GCM_PAES_192 0x1B +#define CPACF_KMA_GCM_PAES_256 0x1C + +/* +* Function codes for the KMF instruction +*/ +#define CPACF_KMF_QUERY 0 +#define CPACF_KMF_DEA 1 +#define CPACF_KMF_TDEA_128 2 +#define CPACF_KMF_TDEA_192 3 +#define CPACF_KMF_AES_128 18 +#define CPACF_KMF_AES_192 19 +#define CPACF_KMF_AES_256 20 +#define CPACF_KMF_PAES_128 26 +#define CPACF_KMF_PAES_192 27 +#define CPACF_KMF_PAES_256 28 + +/* +* Function codes for the KMO instruction +*/ +#define CPACF_KMO_QUERY 0 +#define CPACF_KMO_DEA 1 +#define CPACF_KMO_TDEA_128 2 +#define CPACF_KMO_TDEA_192 3 +#define CPACF_KMO_AES_128 18 +#define CPACF_KMO_AES_192 19 +#define CPACF_KMO_AES_256 20 +#define CPACF_KMO_PAES_128 26 +#define CPACF_KMO_PAES_192 27 +#define CPACF_KMO_PAES_256 28 + +/* +* Function codes for the PCC instruction +*/ +#define CPACF_PCC_QUERY 0 +#define CPACF_PCC_CMAC_DEA 1 +#define CPACF_PCC_CMAC_TDEA_128 2 +#define CPACF_PCC_CMAC_TDEA_192 3 +#define CPACF_PCC_CMAC_AES_128 18 +#define CPACF_PCC_CMAC_AES_192 19 +#define CPACF_PCC_CMAC_AES_256 20 +#define CPACF_PCC_CMAC_PAES_128 26 +#define CPACF_PCC_CMAC_PAES_192 27 +#define CPACF_PCC_CMAC_PAES_256 28 +#define CPACF_PCC_XTS_AES_128 50 +#define CPACF_PCC_XTS_AES_256 52 +#define CPACF_PCC_XTS_PAES_128 58 +#define CPACF_PCC_XTS_PAES_256 60 +#define CPACF_PCC_SM_P256 64 +#define CPACF_PCC_SM_P384 65 +#define CPACF_PCC_SM_P521 66 +#define CPACF_PCC_SM_ED25519 72 +#define CPACF_PCC_SM_ED448 73 +#define CPACF_PCC_SM_X25519 80 +#define CPACF_PCC_SM_X448 81 + +/* +* Function codes for the KDSA instruction +*/ +#define CPACF_KDSA_QUERY 0 +#define CPACF_KDSA_VERIFY_P256 1 +#define CPACF_KDSA_VERIFY_P384 2 +#define CPACF_KDSA_VERIFY_P521 3 +#define CPACF_KDSA_SIGN_P256 9 +#define CPACF_KDSA_SIGN_P384 10 +#define CPACF_KDSA_SIGN_P521 11 +#define CPACF_KDSA_PSIGN_P256 17 +#define CPACF_KDSA_PSIGN_P384 18 +#define CPACF_KDSA_PSIGN_P521 19 +#define CPACF_KDSA_VERIFY_ED25519 32 +#define CPACF_KDSA_VERIFY_ED448 36 +#define CPACF_KDSA_SIGN_ED25519 40 +#define CPACF_KDSA_SIGN_ED448 44 +#define CPACF_KDSA_PSIGN_ED25519 48 +#define CPACF_KDSA_PSIGN_ED448 52 + +#endif /* S390X_CPACF_ARCH_H */
target/s390x/tcg/crypto_helper.c +82 -19
137 lines not on this page · raw message
target/s390x/tcg/insn-data.h.inc +1 -0
@@ -1015,6 +1015,7 @@ D(0xb92e, KM, RRE, MSA, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_KM) D(0xb92f, KMC, RRE, MSA, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_KMC) D(0xb929, KMA, RRF_b, MSA8, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_KMA) + D(0xb93a, KDSA, RRE, MSA9, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_KDSA) E(0xb93c, PPNO, RRE, MSA5, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_PPNO, IF_IO) D(0xb93e, KIMD, RRE, MSA, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_KIMD) D(0xb93f, KLMD, RRE, MSA, 0, 0, 0, 0, msa, 0, S390_FEAT_TYPE_KLMD)
target/s390x/tcg/translate.c +2 -0
@@ -2585,6 +2585,7 @@ static DisasJumpType op_msa(DisasContext *s, DisasOps *o)case S390_FEAT_TYPE_KMAC :case S390_FEAT_TYPE_KIMD :case S390_FEAT_TYPE_KLMD : +case S390_FEAT_TYPE_KDSA :if (r2 &1 || !r2) {gen_program_exception (s,PGM_SPECIFICATION );return DISAS_NORETURN ;
@@ -5969,6 +5970,7 @@ enum DisasInsnEnum {#define FAC_MSA4 S390_FEAT_MSA_EXT_4/* msa-extension-4 facility */ #define FAC_MSA5 S390_FEAT_MSA_EXT_5/* msa-extension-5 facility */ #define FAC_MSA8 S390_FEAT_MSA_EXT_8/* msa-extension-8 facility */ +#define FAC_MSA9 S390_FEAT_MSA_EXT_9/* msa-extension-9 facility */ #define FAC_ECT S390_FEAT_EXTRACT_CPU_TIME#define FAC_PCI S390_FEAT_ZPCI/* z/PCI facility */ #define FAC_AIS S390_FEAT_ADAPTER_INT_SUPPRESSION
Signature · 1 line
2.55.0
[PULL 29/33] pc-bios/s390-ccw: Add support for virtio-scsi-pci IPL
In reply to Eric FarmanFrom: Jared Rossi <[email protected]>
Read virtio-pci configuration and configure virt-queue for scsi devices.
Also add check for virtio setup failures when doing scsi setup and return early if it fails instead of waiting for subsequent failure.
--- pc-bios/s390-ccw/main.c | 3 ++- pc-bios/s390-ccw/virtio-pci.c | 30 ++++++++++++++++++++++++++++++ pc-bios/s390-ccw/virtio-scsi.c | 18 +++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-)
pc-bios/s390-ccw/main.c +2 -1
@@ -273,6 +273,7 @@ static bool find_boot_device(void) }break ;case S390_IPL_TYPE_PCI : + vdev->scsi_device_selected = false; found =find_fid (iplb->pci.fid);break ;default :
@@ -333,13 +334,13 @@ static void ipl_pci_device(void) {VDev *vdev =virtio_get_device (); vdev->is_cdrom = false; - vdev->scsi_device_selected = false;if (virtio_pci_setup_device ()) {return ; }switch (vdev->dev_type) { +case VIRTIO_ID_SCSI :case VIRTIO_ID_BLOCK :if (virtio_setup () ==0 ) {zipl_load ();/* only return on error */
pc-bios/s390-ccw/virtio-pci.c +30 -0
@@ -52,6 +52,10 @@ void virtio_pci_id2type(VDev *vdev, uint16_t device_id)case 0x1001 : vdev->dev_type =VIRTIO_ID_BLOCK ;break ; +case 0x1048 : +case 0x1004 : + vdev->dev_type =VIRTIO_ID_SCSI ; +break ;default : vdev->dev_type =0 ; }
@@ -199,6 +203,26 @@ static int virtio_pci_get_blk_config(void)return rc; } +static int virtio_pci_get_scsi_config (void ) +{ +VirtioScsiConfig *cfg = &virtio_get_device ()->config.scsi; +int rc =vpci_read_flex (d_cap.off, d_cap.bar, cfg,sizeof (VirtioScsiConfig)); + +/* all fields of scsi config must be byte swapped */ + cfg->num_queues =bswap32 (cfg->num_queues); + cfg->seg_max =bswap32 (cfg->seg_max); + cfg->max_sectors =bswap32 (cfg->max_sectors); + cfg->cmd_per_lun =bswap32 (cfg->cmd_per_lun); + cfg->event_info_size =bswap32 (cfg->event_info_size); + cfg->sense_size =bswap32 (cfg->sense_size); + cfg->cdb_size =bswap32 (cfg->cdb_size); + cfg->max_channel =bswap16 (cfg->max_channel); + cfg->max_target =bswap16 (cfg->max_target); + cfg->max_lun =bswap32 (cfg->max_lun); + +return rc; +} +static int virtio_pci_negotiate (void ) {int i, rc;
@@ -330,6 +354,7 @@ bool virtio_pci_is_supported(VDev *vdev)if (vdev->vendor_id ==PCI_VENDOR_VIRTIO ) {switch (vdev->dev_type) {case VIRTIO_ID_BLOCK : +case VIRTIO_ID_SCSI :return true;default :return false;
@@ -384,6 +409,11 @@ int virtio_pci_setup(VDev *vdev) vdev->cmd_vr_idx =0 ;virtio_pci_get_blk_config ();break ; +case VIRTIO_ID_SCSI : + vdev->nr_vqs =3 ; + vdev->cmd_vr_idx =2 ; +virtio_pci_get_scsi_config (); +break ;default :puts ("Unsupported virtio device" );return -ENODEV ;
pc-bios/s390-ccw/virtio-scsi.c +17 -1
@@ -16,6 +16,7 @@#include "scsi.h" #include "virtio-scsi.h" #include "virtio-ccw.h" +#include "virtio-pci.h" #include "s390-time.h" #include "helper.h"
@@ -479,7 +480,22 @@ static int virtio_scsi_setup(VDev *vdev)int virtio_scsi_setup_device (VDev *vdev) { -virtio_ccw_setup (vdev); +switch (vdev->ipl_type) { +case S390_IPL_TYPE_CCW : +if (virtio_ccw_setup (vdev)) { +puts ("Setup failed for virtio-scsi-ccw" ); +return 1 ; + } +break ; +case S390_IPL_TYPE_PCI : +if (virtio_pci_setup (vdev)) { +puts ("Setup failed for virtio-scsi-pci" ); +return 1 ; + } +break ; +default : +return 1 ; + }if (vdev->config.scsi.sense_size !=VIRTIO_SCSI_SENSE_SIZE ) {puts ("Config: sense size mismatch" );
Signature · 1 line
2.55.0
[PULL 10/33] target/s390x: Support AES CTR for cpacf kmctr instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Support the subfunctions CPACF_KMCTR_AES_128, CPACF_KMCTR_AES_192 and CPACF_KMCTR_AES_256 for the cpacf kmctr instruction.
--- target/s390x/gen-features.c | 3 ++ target/s390x/tcg/cpacf.h | 5 ++ target/s390x/tcg/cpacf_aes.c | 82 ++++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 24 ++++++++++ 4 files changed, 114 insertions(+)
target/s390x/gen-features.c +3 -0
@@ -935,6 +935,9 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KMC_AES_128 ,S390_FEAT_KMC_AES_192 ,S390_FEAT_KMC_AES_256 , +S390_FEAT_KMCTR_AES_128 , +S390_FEAT_KMCTR_AES_192 , + S390_FEAT_KMCTR_AES_256, };/****** END FEATURE DEFS ******/
target/s390x/tcg/cpacf.h +5 -0
@@ -27,5 +27,10 @@ int cpacf_aes_cbc(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint64_t param_addr, uint64_t *dst_ptr_reg, uint64_t *src_ptr_reg, uint64_t *src_len_reg, uint32_t type, uint8_t fc, uint8_t mod); +int cpacf_aes_ctr (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *dst_ptr_reg, +uint64_t *src_ptr_reg,uint64_t *src_len_reg, +uint64_t *ctr_ptr_reg,uint32_t type, +uint8_t fc,uint8_t mod);#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c +82 -0
85 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +24 -0
@@ -140,6 +140,27 @@ static int cpacf_kmc(CPUS390XState *env, const int mmu_idx, uintptr_t ra,return rc; } +static int cpacf_kmctr (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint32_t r1,uint32_t r2,uint32_t r3, +uint8_t fc,uint8_t mod) +{ +int rc =0 ; + +switch (fc) { +case CPACF_KMCTR_AES_128 : +case CPACF_KMCTR_AES_192 : +case CPACF_KMCTR_AES_256 : + rc =cpacf_aes_ctr (env, mmu_idx, ra, env->regs[1 ], + &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], + &env->regs[r3],S390_FEAT_TYPE_KMCTR , fc, mod); +break ; +default : +tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); + } + +return rc; +} +static int cpacf_ppno (CPUS390XState *env,const int mmu_idx,uintptr_t ra,uint32_t r1,uint32_t r2,uint32_t r3,uint8_t fc) {
@@ -214,6 +235,9 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,case S390_FEAT_TYPE_KMC : rc =cpacf_kmc (env, mmu_idx, ra, r1, r2, r3, fc, mod);break ; +case S390_FEAT_TYPE_KMCTR : + rc =cpacf_kmctr (env, mmu_idx, ra, r1, r2, r3, fc, mod); +break ;case S390_FEAT_TYPE_PPNO : rc =cpacf_ppno (env, mmu_idx, ra, r1, r2, r3, fc);break ;
Signature · 1 line
2.55.0
[PULL 21/33] hw/s390x/ipl: Add secure boot support to PCI dev IPLB builder
In reply to Eric FarmanFrom: Joshua Daley <[email protected]>
In the PCI boot device case of s390_build_iplb(), call s390_apply_secure_boot() to update the IPLB when secure boot or audit mode are enabled.
Secure IPL is now supported for virtio-blk-pci boot devices.
--- hw/s390x/ipl.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
hw/s390x/ipl.c +3 -5
@@ -599,11 +599,6 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb) pbdev =s390_get_pci_device (dev_st, &devtype);if (pbdev) { -if (s390_secure_boot_enabled () ||s390_has_certificate ()) { -error_report ("Virtio pci boot device does not support secure boot!" ); -exit (1 ); - } - pci_lp =object_property_get_str (OBJECT (pbdev->pdev),"loadparm" ,NULL );if (pci_lp &&strlen (pci_lp) >0 ) { lp = pci_lp;
@@ -625,6 +620,9 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)s390_ipl_convert_loadparm ((char *)lp, iplb->loadparm); iplb->flags |=DIAG308_FLAGS_LP_VALID ; +s390_apply_secure_boot (iplb, devtype,s390_secure_boot_enabled (), +s390_has_certificate ()); +return true; }
Signature · 1 line
2.55.0
[PULL 24/33] pc-bios/s390-ccw: Check if a PCI function is already enabled before trying to enable it
In reply to Eric FarmanFrom: Jared Rossi <[email protected]>
Enabling a PCI function that is already configured will result in an error. Simply check if the device has already been enabled, and if so, return without doing anything further; otherwise, enable it as usual.
Also, because enable_pci_function() prints its own message, let's remove the duplicate message emitted during the virtio PCI setup steps.
--- pc-bios/s390-ccw/clp.c | 4 ++++ pc-bios/s390-ccw/virtio-pci.c | 1 - 2 files changed, 4 insertions(+), 1 deletion(-)
pc-bios/s390-ccw/clp.c +4 -0
@@ -82,6 +82,10 @@ int enable_pci_function(uint32_t *fhandle) {ClpReqRspSetPci rrb; +if (*fhandle &CLP_FHLIST_MASK_CONFIG ) { +return 0 ;/* already enabled */ + } + rrb.request.hdr.len =sizeof (ClpReqSetPci); rrb.request.hdr.cmd =0x05 ; rrb.request.fh = *fhandle;
pc-bios/s390-ccw/virtio-pci.c +0 -1
@@ -452,7 +452,6 @@ int virtio_pci_setup_device(void)VDev *vdev =virtio_get_device ();if (enable_pci_function (&vdev->pci_fh)) { -puts ("Failed to enable PCI function" );return -ENODEV ; }
Signature · 1 line
2.55.0
[PULL 16/33] target/s390x: Support protected key AES CTR for cpacf kmctr instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Support the subfunctions CPACF_KMCTR_PAES_128, CPACF_KMCTR_PAES_192 and CPACF_KMCTR_PAES_256 for the cpacf kmctr instruction.
--- target/s390x/gen-features.c | 3 ++ target/s390x/tcg/cpacf.h | 5 ++ target/s390x/tcg/cpacf_aes.c | 92 ++++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 7 +++ 4 files changed, 107 insertions(+)
target/s390x/gen-features.c +3 -0
@@ -946,6 +946,9 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KMCTR_AES_128 ,S390_FEAT_KMCTR_AES_192 ,S390_FEAT_KMCTR_AES_256 , +S390_FEAT_KMCTR_EAES_128 , +S390_FEAT_KMCTR_EAES_192 , +S390_FEAT_KMCTR_EAES_256 ,S390_FEAT_PCC_XTS_AES_128 ,S390_FEAT_PCC_XTS_AES_256 , S390_FEAT_PCKMO_AES_128,
target/s390x/tcg/cpacf.h +5 -0
@@ -48,5 +48,10 @@ int cpacf_paes_cbc(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint64_t param_addr, uint64_t *dst_ptr_reg, uint64_t *src_ptr_reg, uint64_t *src_len_reg, uint32_t type, uint8_t fc, uint8_t mod); +int cpacf_paes_ctr (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *dst_ptr_reg, +uint64_t *src_ptr_reg,uint64_t *src_len_reg, +uint64_t *ctr_ptr_reg,uint32_t type, +uint8_t fc,uint8_t mod);#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c +92 -0
95 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +7 -0
@@ -174,6 +174,13 @@ static int cpacf_kmctr(CPUS390XState *env, const int mmu_idx, uintptr_t ra, &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], &env->regs[r3], S390_FEAT_TYPE_KMCTR, fc, mod);break ; +case CPACF_KMCTR_PAES_128 : +case CPACF_KMCTR_PAES_192 : +case CPACF_KMCTR_PAES_256 : + rc =cpacf_paes_ctr (env, mmu_idx, ra, env->regs[1 ], + &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], + &env->regs[r3],S390_FEAT_TYPE_KMCTR , fc, mod); +break ;default :tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); }
Signature · 1 line
2.55.0
[PULL 25/33] hw/s390x/ipl: Fix incorrect PCI IPL block lengths
In reply to Eric FarmanFrom: Jared Rossi <[email protected]>
The length of the PCI IPLB is calculated by size of the IplBlockPci struct plus the number of bytes used for common IPLB fields.
Fix the S390_IPLB_MIN_PCI_LEN to reflect this, and assign a valid blk0_len while we are at it.
--- hw/s390x/ipl.c | 2 ++ include/hw/s390x/ipl/qipl.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +2 -0
@@ -610,6 +610,8 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)switch (devtype) {case PCI_DEVTYPE_VIRTIO : iplb->len =cpu_to_be32 (S390_IPLB_MIN_PCI_LEN ); + iplb->blk0_len = +cpu_to_be32 (S390_IPLB_MIN_PCI_LEN -S390_IPLB_HEADER_LEN ); iplb->pbt =S390_IPL_TYPE_PCI ; iplb->pci.fid =cpu_to_be32 (pbdev->fid);break ;
include/hw/s390x/ipl/qipl.h +1 -1
@@ -39,7 +39,7 @@ typedef enum S390IplType S390IplType;#define S390_IPLB_MIN_PV_LEN 148#define S390_IPLB_MIN_CCW_LEN 200#define S390_IPLB_MIN_FCP_LEN 384 -#define S390_IPLB_MIN_PCI_LEN 376 +#define S390_IPLB_MIN_PCI_LEN (offsetof(IplParameterBlock, pci) + sizeof(IplBlockPci))#define S390_IPLB_MIN_QEMU_SCSI_LEN 200#define S390_IPLB_MAX_LEN 4096
Signature · 1 line
2.55.0
[PULL 05/33] target/s390x: Add helper functions for copy memory to and from guest
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Add some simple helper functions to copy memory from guest to a local buffer and the other way around:
- read_guest_wrap_u8()
- write_guest_wrap_u8()
- read_guest_wrap_u32()
- write_guest_wrap_u32()
- read_guest_wrap_u64()
- write_guest_wrap_u64()
The reader functions read from guest memory into an array of u8/u32/u64 with BE conversion. Similar the writer functions write an array of u8/u32/u64 into guest memory with BE conversion.
All these functions are intended to be used for the crypto implementations thus are located in crypto_helper.h.
Rework and simplify the sha 256 and sha 512 implementations to use these helper functions.
--- target/s390x/tcg/cpacf_sha256.c | 63 ++++--------------- target/s390x/tcg/cpacf_sha512.c | 63 ++++--------------- target/s390x/tcg/crypto_helper.c | 1 + target/s390x/tcg/crypto_helper.h | 100 +++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+), 104 deletions(-) create mode 100644 target/s390x/tcg/crypto_helper.h
target/s390x/tcg/cpacf_sha256.c +11 -52
@@ -19,6 +19,7 @@#include "accel/tcg/cpu-mmu-index.h" #include "target/s390x/tcg/cpacf-arch.h" #include "target/s390x/tcg/cpacf.h" +#include "target/s390x/tcg/crypto_helper.h" static uint32_t R (uint32_t x,int c) {
@@ -104,53 +105,13 @@ static void sha256_bda_be32(uint32_t a[8], uint32_t w[16])sha256_bda (a, t); } -static void sha256_read_icv (CPUS390XState *env,const int mmu_idx, -uint64_t addr,uint32_t a[8 ],uintptr_t ra) -{ -const MemOpIdx oi =make_memop_idx (MO_BE |MO_32 |MO_UNALN , mmu_idx); - -for (int i =0 ; i <8 ; i++, addr +=4 ) { - a[i] =cpu_ldl_mmu (env,wrap_address (env, addr), oi, ra); - } -} - -static void sha256_write_ocv (CPUS390XState *env,const int mmu_idx, -uint64_t addr,uint32_t a[8 ],uintptr_t ra) -{ -const MemOpIdx oi =make_memop_idx (MO_BE |MO_32 |MO_UNALN , mmu_idx); - -for (int i =0 ; i <8 ; i++, addr +=4 ) { -cpu_stl_mmu (env,wrap_address (env, addr), a[i], oi, ra); - } -} - -static void sha256_read_block (CPUS390XState *env,const int mmu_idx, -uint64_t addr,uint32_t a[16 ],uintptr_t ra) -{ -const MemOpIdx oi =make_memop_idx (MO_BE |MO_32 |MO_UNALN , mmu_idx); - -for (int i =0 ; i <16 ; i++, addr +=4 ) { - a[i] =cpu_ldl_mmu (env,wrap_address (env, addr), oi, ra); - } -} - -static void sha256_read_mbl_be32 (CPUS390XState *env,const int mmu_idx, -uint64_t addr,uint8_t a[8 ],uintptr_t ra) -{ -const MemOpIdx oi =make_memop_idx (MO_8 , mmu_idx); - -for (int i =0 ; i <8 ; i++, addr +=1 ) { - a[i] =cpu_ldb_mmu (env,wrap_address (env, addr), oi, ra); - } -} -int cpacf_sha256 (CPUS390XState *env,const int mmu_idx,uintptr_t ra,uint64_t param_addr,uint64_t *message_reg,uint64_t *len_reg,uint32_t type) {enum {MAX_BLOCKS_PER_RUN =128 };/* 128 * 64 = 8K */ uint64_t len = *len_reg, processed =0 ; -int i, message_reg_len =64 ; +int message_reg_len =64 ;uint32_t a[8 ];g_assert (type ==S390_FEAT_TYPE_KIMD || type ==S390_FEAT_TYPE_KLMD );
@@ -165,7 +126,8 @@ int cpacf_sha256(CPUS390XState *env, const int mmu_idx, uintptr_t ra,tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); } -sha256_read_icv (env, mmu_idx, param_addr, a, ra); +/* read icv (8 * u32) */ +read_guest_wrap_u32 (env, mmu_idx, ra, param_addr, a,8 );/* Process full blocks first. */ for (; len >=64 ; len -=64 , processed +=64 ) {
@@ -175,21 +137,18 @@ int cpacf_sha256(CPUS390XState *env, const int mmu_idx, uintptr_t ra,break ; } -sha256_read_block (env, mmu_idx, *message_reg + processed, w, ra); +/* read sha256 block (16 * u32) */ +read_guest_wrap_u32 (env, mmu_idx, ra, *message_reg + processed, w,16 );sha256_bda (a, w); }/* KLMD: Process partial/empty block last. */ if (type ==S390_FEAT_TYPE_KLMD && len <64 ) { -const MemOpIdx oi =make_memop_idx (MO_8 , mmu_idx);uint8_t x[64 ]; -/* Read the remainder of the message byte-per-byte. */ -for (i =0 ; i < len; i++) { -uint64_t addr =wrap_address (env, *message_reg + processed + i); +/* Read the remainder of the message. */ +read_guest_wrap_u8 (env, mmu_idx, ra, *message_reg + processed, x, len); - x[i] =cpu_ldb_mmu (env, addr, oi, ra); - }/* Pad the remainder with zero and set the top bit. */ memset (x + len,0 ,64 - len); x[len] =0x80 ;
@@ -199,13 +158,13 @@ int cpacf_sha256(CPUS390XState *env, const int mmu_idx, uintptr_t ra,* or use an additional one. */ if (len <56 ) { -sha256_read_mbl_be32 (env, mmu_idx, param_addr +32 , x +56 , ra); +read_guest_wrap_u8 (env, mmu_idx, ra, param_addr +32 , x +56 ,8 ); }sha256_bda_be32 (a, (uint32_t *)x);if (len >=56 ) {memset (x,0 ,56 ); -sha256_read_mbl_be32 (env, mmu_idx, param_addr +32 , x +56 , ra); +read_guest_wrap_u8 (env, mmu_idx, ra, param_addr +32 , x +56 ,8 );sha256_bda_be32 (a, (uint32_t *)x); }
@@ -220,7 +179,7 @@ int cpacf_sha256(CPUS390XState *env, const int mmu_idx, uintptr_t ra,* TODO: if writing fails halfway through (e.g., when crossing page * boundaries), we're in trouble. We'd need something like access_prepare(). */ -sha256_write_ocv (env, mmu_idx, param_addr, a, ra); +write_guest_wrap_u32 (env, mmu_idx, ra, param_addr, a,8 ); *message_reg =deposit64 (*message_reg,0 , message_reg_len, *message_reg + processed); *len_reg -= processed;
target/s390x/tcg/cpacf_sha512.c +11 -52
118 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +1 -0
@@ -22,6 +22,7 @@#include "accel/tcg/cpu-mmu-index.h" #include "target/s390x/tcg/cpacf-arch.h" #include "target/s390x/tcg/cpacf.h" +#include "target/s390x/tcg/crypto_helper.h" static int fill_buf_random (CPUS390XState *env,const int mmu_idx,uintptr_t ra,uint64_t *buf_reg,uint64_t *len_reg)
target/s390x/tcg/crypto_helper.h new file +100 -0
100 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 12/33] target/s390x: Support AES XTS for cpacf km instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Support the subfunctions XTS-AES-128 and XTS-AES-256 for the cpacf km instruction.
--- target/s390x/gen-features.c | 2 + target/s390x/tcg/cpacf.h | 4 ++ target/s390x/tcg/cpacf_aes.c | 93 ++++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 6 +++ 4 files changed, 105 insertions(+)
target/s390x/gen-features.c +2 -0
@@ -932,6 +932,8 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KM_AES_128 ,S390_FEAT_KM_AES_192 ,S390_FEAT_KM_AES_256 , +S390_FEAT_KM_XTS_AES_128 , +S390_FEAT_KM_XTS_AES_256 ,S390_FEAT_KMC_AES_128 ,S390_FEAT_KMC_AES_192 , S390_FEAT_KMC_AES_256,
target/s390x/tcg/cpacf.h +4 -0
@@ -34,5 +34,9 @@ int cpacf_aes_ctr(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint8_t fc, uint8_t mod);int cpacf_aes_pcc (CPUS390XState *env,const int mmu_idx,uintptr_t ra,uint64_t param_addr,uint8_t fc); +int cpacf_aes_xts (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *dst_ptr_reg, +uint64_t *src_ptr_reg,uint64_t *src_len_reg, +uint32_t type,uint8_t fc,uint8_t mod);#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c +93 -0
96 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +6 -0
@@ -112,6 +112,12 @@ static int cpacf_km(CPUS390XState *env, const int mmu_idx, uintptr_t ra, &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], S390_FEAT_TYPE_KM, fc, mod);break ; +case CPACF_KM_XTS_128 : +case CPACF_KM_XTS_256 : + rc =cpacf_aes_xts (env, mmu_idx, ra, env->regs[1 ], + &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], +S390_FEAT_TYPE_KM , fc, mod); +break ;default :tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); }
Signature · 1 line
2.55.0
The following changes since commit c1c18d1e640b64292859ce9f30f3c344edfb0294:
Merge tag 'virtio-snd-migrate-pr-v2' of https://gitlab.com/epilys/qemu into staging (2026-09-19 10:41:53 -1000)
are available in the Git repository at:
https://gitlab.com/efarman/qemu.git tags/s390x-20260921
for you to fetch changes up to 96bd689997443a15f259fa99a6a672eb1f65062c:
pc-bios/s390-ccw.img: update s390x bios (2026-09-21 11:46:02 -0400)
----------------------------------------------------------------
New s390x features for 11.2
- extend CPACF support
- enable secure IPL for virtio-blk-pci
- enable boot from virtio-scsi-pci
- regenerate s390-ccw.img
----------------------------------------------------------------
Eric Farman (1):
pc-bios/s390-ccw.img: update s390x bios
Harald Freudenberger (20):
target/s390x: Fix missing privileged flag at PCKMO instruction target/s390x: Rework s390 cpacf implementations target/s390x: Move cpacf sha512 code into a new file target/s390x: Support cpacf sha256
target/s390x: Add helper functions for copy memory to and from guest target/s390x: Adjust addressing mode checks for sha512 and sha256
crypto: Add aes-helpers file to support some AES modes target/s390x: Support AES ECB for cpacf km instruction target/s390x: Support AES CBC for cpacf kmc instruction target/s390x: Support AES CTR for cpacf kmctr instruction target/s390x: Minimal AES XTS support for cpacf pcc instruction target/s390x: Support AES XTS for cpacf km instruction target/s390x: Base support for cpacf protected keys and pckmo target/s390x: Support protected key AES ECB for cpacf km instruction target/s390x: Support protected key AES CBC for cpacf kmc instruction target/s390x: Support protected key AES CTR for cpacf kmctr
instruction
target/s390x: Minimal protected key AES XTS support for cpacf pcc
instruction
target/s390x: Support protected key AES XTS for cpacf km instruction docs/s390: Document CPACF instructions support tests/tcg/s390x: Add tests for CPACF instructions
Jared Rossi (8):
pc-bios/s390-ccw: Check if a PCI function is already enabled before
trying to enable it
hw/s390x/ipl: Fix incorrect PCI IPL block lengths pc-bios/s390-ccw: Use bus specific IPL_TYPE directly for scsi IPL s390x/ipl: Add PCI and bus fields to IplBlockQemuScsi pc-bios/s390-ccw: Abstract virtio_run() for generic use pc-bios/s390-ccw: Add support for virtio-scsi-pci IPL
s390x: Find scsi-pci boot device and build IPLB tests/qtest: Add s390x PCI SCSI fallback test to cdrom-test.c
Joshua Daley (3):
hw/s390x/ipl: Add secure boot support to PCI dev IPLB builder tests/functional/s390x/test_secure_ipl: Skip test if SIPL not
supported by hypervisor
tests/functional/s390x/test_secure_ipl: Add virtio-blk-pci boot dev
case
Omar Elghoul (1):
s390x/pci: fix DMA slot leak on I/O TLB entry replacement
crypto/aes-helpers.c | 106 +++ crypto/meson.build | 1 + docs/system/s390x/cpacf.rst | 143 ++++ docs/system/target-s390x.rst | 1 + hw/s390x/ipl.c | 48 +- hw/s390x/ipl.h | 2 + hw/s390x/s390-pci-inst.c | 5 +- include/crypto/aes-helpers.h | 109 +++ include/hw/s390x/ipl/qipl.h | 15 +- pc-bios/s390-ccw.img | Bin 112408 -> 112408 bytes pc-bios/s390-ccw/clp.c | 4 + pc-bios/s390-ccw/main.c | 19 +- pc-bios/s390-ccw/virtio-blkdev.c | 1 - pc-bios/s390-ccw/virtio-ccw.c | 17 - pc-bios/s390-ccw/virtio-ccw.h | 1 - pc-bios/s390-ccw/virtio-pci.c | 31 +- pc-bios/s390-ccw/virtio-scsi.c | 18 +- pc-bios/s390-ccw/virtio.c | 21 +- target/s390x/gen-features.c | 31 + target/s390x/tcg/cpacf-arch.h | 251 ++++++ target/s390x/tcg/cpacf.h | 63 ++ target/s390x/tcg/cpacf_aes.c | 986 ++++++++++++++++++++++ target/s390x/tcg/cpacf_sha256.c | 197 +++++ target/s390x/tcg/cpacf_sha512.c | 211 +++++ target/s390x/tcg/crypto_helper.c | 445 +++++----- target/s390x/tcg/crypto_helper.h | 100 +++ target/s390x/tcg/insn-data.h.inc | 3 +- target/s390x/tcg/meson.build | 3 + target/s390x/tcg/translate.c | 16 +- tests/functional/s390x/test_secure_ipl.py | 157 +++- tests/qtest/cdrom-test.c | 8 + tests/tcg/s390x/cpacf-kdsa.c | 58 ++ tests/tcg/s390x/cpacf-kimd.c | 166 ++++ tests/tcg/s390x/cpacf-klmd.c | 206 +++++ tests/tcg/s390x/cpacf-km.c | 590 +++++++++++++ tests/tcg/s390x/cpacf-kmac.c | 58 ++ tests/tcg/s390x/cpacf-kmc.c | 351 ++++++++ tests/tcg/s390x/cpacf-kmctr.c | 360 ++++++++ tests/tcg/s390x/cpacf-pcc.c | 245 ++++++ tests/tcg/s390x/cpacf-pckmo.c | 45 + tests/tcg/s390x/cpacf-prno.c | 131 +++ tests/tcg/s390x/cpacf.h | 570 +++++++++++++ tests/tcg/s390x/meson.build | 10 + 43 files changed, 5487 insertions(+), 316 deletions(-) create mode 100644 crypto/aes-helpers.c create mode 100644 docs/system/s390x/cpacf.rst create mode 100644 include/crypto/aes-helpers.h create mode 100644 target/s390x/tcg/cpacf-arch.h create mode 100644 target/s390x/tcg/cpacf.h create mode 100644 target/s390x/tcg/cpacf_aes.c create mode 100644 target/s390x/tcg/cpacf_sha256.c create mode 100644 target/s390x/tcg/cpacf_sha512.c create mode 100644 target/s390x/tcg/crypto_helper.h create mode 100644 tests/tcg/s390x/cpacf-kdsa.c create mode 100644 tests/tcg/s390x/cpacf-kimd.c create mode 100644 tests/tcg/s390x/cpacf-klmd.c create mode 100644 tests/tcg/s390x/cpacf-km.c create mode 100644 tests/tcg/s390x/cpacf-kmac.c create mode 100644 tests/tcg/s390x/cpacf-kmc.c create mode 100644 tests/tcg/s390x/cpacf-kmctr.c create mode 100644 tests/tcg/s390x/cpacf-pcc.c create mode 100644 tests/tcg/s390x/cpacf-pckmo.c create mode 100644 tests/tcg/s390x/cpacf-prno.c create mode 100644 tests/tcg/s390x/cpacf.h
Signature · 1 line
2.55.0
[PULL 04/33] target/s390x: Support cpacf sha256
From: Harald Freudenberger <[email protected]>
Add a new file cpacf_sha256.c which implements sha256. Add support for the sha256 subfuction for CPACF kimd and klmd.
--- target/s390x/gen-features.c | 2 + target/s390x/tcg/cpacf.h | 5 + target/s390x/tcg/cpacf_sha256.c | 228 +++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 8 ++ target/s390x/tcg/meson.build | 1 + 5 files changed, 244 insertions(+) create mode 100644 target/s390x/tcg/cpacf_sha256.c
target/s390x/gen-features.c +2 -0
@@ -920,7 +920,9 @@ static uint16_t qemu_V7_1[] = {*/ static uint16_t qemu_MAX[] = {S390_FEAT_MSA_EXT_5 , +S390_FEAT_KIMD_SHA_256 ,S390_FEAT_KIMD_SHA_512 , +S390_FEAT_KLMD_SHA_256 ,S390_FEAT_KLMD_SHA_512 ,S390_FEAT_PRNO_TRNG ,S390_FEAT_EXTENDED_LENGTH_SCCB ,
target/s390x/tcg/cpacf.h +5 -0
@@ -8,6 +8,11 @@#ifndef S390X_CPACF_H #define S390X_CPACF_H +/* from cpacf_sha256.c */ +int cpacf_sha256 (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *message_reg,uint64_t *len_reg, +uint32_t type); +/* from cpacf_sha512.c */ int cpacf_sha512(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint64_t param_addr, uint64_t *message_reg, uint64_t *len_reg,
target/s390x/tcg/cpacf_sha256.c new file +228 -0
228 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +8 -0
@@ -61,6 +61,10 @@ static int cpacf_kimd(CPUS390XState *env, const int mmu_idx, const uintptr_t ra,int rc =0 ;switch (fc) { +case CPACF_KIMD_SHA_256 : + rc =cpacf_sha256 (env, mmu_idx, ra, env->regs[1 ], &env->regs[r2], + &env->regs[r2 +1 ],S390_FEAT_TYPE_KIMD ); +break ;case CPACF_KIMD_SHA_512 : rc =cpacf_sha512 (env, mmu_idx, ra, env->regs[1 ], &env->regs[r2], &env->regs[r2 +1 ],S390_FEAT_TYPE_KIMD );
@@ -78,6 +82,10 @@ static int cpacf_klmd(CPUS390XState *env, const int mmu_idx, const uintptr_t ra,int rc =0 ;switch (fc) { +case CPACF_KLMD_SHA_256 : + rc =cpacf_sha256 (env, mmu_idx, ra, env->regs[1 ], &env->regs[r2], + &env->regs[r2 +1 ],S390_FEAT_TYPE_KLMD ); +break ;case CPACF_KLMD_SHA_512 : rc =cpacf_sha512 (env, mmu_idx, ra, env->regs[1 ], &env->regs[r2], &env->regs[r2 +1 ],S390_FEAT_TYPE_KLMD );
target/s390x/tcg/meson.build +1 -0
@@ -5,6 +5,7 @@ s390x_ss.add(when: 'CONFIG_TCG', if_true: files( )) s390x_common_ss.add(when: 'CONFIG_TCG', if_true: files( 'cc_helper.c', + 'cpacf_sha256.c', 'cpacf_sha512.c', 'crypto_helper.c', 'excp_helper.c',
Signature · 1 line
2.55.0
[PULL 30/33] s390x: Find scsi-pci boot device and build IPLB
In reply to Eric FarmanFrom: Jared Rossi <[email protected]>
Add logic to identify a virtio-pci scsi controller and target lun with assigned bootindex, then build IPLB for it.
Unfence PCI case for scsi devices in BIOS.
--- hw/s390x/ipl.c | 37 +++++++++++++++++++++++++++++++++++++ pc-bios/s390-ccw/main.c | 3 +++ 2 files changed, 40 insertions(+)
hw/s390x/ipl.c +37 -0
@@ -402,6 +402,7 @@ static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype) }#define PCI_DEVTYPE_VIRTIO 0x05 +#define PCI_DEVTYPE_SCSI 0x06static S390PCIBusDevice *s390_get_pci_device (DeviceState *dev_st,int *devtype) {
@@ -417,6 +418,26 @@ static S390PCIBusDevice *s390_get_pci_device(DeviceState *dev_st, int *devtype)if (pbdev) { tmp_dt =PCI_DEVTYPE_VIRTIO ; } + }else { +SCSIDevice *sd = (SCSIDevice *) +object_dynamic_cast (OBJECT (dev_st),TYPE_SCSI_DEVICE ); +if (sd) { +SCSIBus *sbus =scsi_bus_from_device (sd); +VirtIODevice *vdev = (VirtIODevice *) +object_dynamic_cast (OBJECT (sbus->qbus.parent), +TYPE_VIRTIO_DEVICE ); +if (vdev) { + pci_dev = (PCIDevice *) +object_dynamic_cast (OBJECT (qdev_get_parent_bus (DEVICE (vdev))->parent), +TYPE_PCI_DEVICE ); +if (pci_dev) { + pbdev =s390_pci_find_dev_by_pci (s390_get_phb (), pci_dev); +if (pbdev) { + tmp_dt =PCI_DEVTYPE_SCSI ; + } + } + } + } } }if (devtype) {
@@ -616,6 +637,22 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb) iplb->pbt =S390_IPL_TYPE_PCI ; iplb->pci.fid =cpu_to_be32 (pbdev->fid);break ; +case PCI_DEVTYPE_SCSI : + sd =SCSI_DEVICE (dev_st); + scsi_lp =object_property_get_str (OBJECT (sd),"loadparm" ,NULL ); +if (scsi_lp &&strlen (scsi_lp) >0 ) { + lp = scsi_lp; + } + iplb->len =cpu_to_be32 (S390_IPLB_MIN_PCI_LEN ); + iplb->blk0_len = +cpu_to_be32 (S390_IPLB_MIN_PCI_LEN -S390_IPLB_HEADER_LEN ); + iplb->pbt =S390_IPL_TYPE_QEMU_SCSI ; + iplb->scsi.lun =cpu_to_be32 (sd->lun); + iplb->scsi.target =cpu_to_be16 (sd->id); + iplb->scsi.channel =cpu_to_be16 (sd->channel); + iplb->scsi.bus =S390_IPL_TYPE_PCI ; + iplb->scsi.fid =cpu_to_be32 (pbdev->fid); +break ;default :return false; }
pc-bios/s390-ccw/main.c +3 -0
@@ -267,6 +267,9 @@ static bool find_boot_device(void) blk_schid.ssid = iplb->scsi.ssid &0x3 ; found =find_subch (iplb->scsi.devno);break ; +case S390_IPL_TYPE_PCI : + found =find_fid (iplb->scsi.fid); +break ;default :puts ("Unrecognized SCSI controller" );break ;
Signature · 1 line
2.55.0
[PULL 17/33] target/s390x: Minimal protected key AES XTS support for cpacf pcc instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Support CPACF pcc subfunctions PCC-Compute-XTS-Parameter-Encrypted-AES-128 and PCC-Compute-XTS-Parameter-Encrypted-AES-128 but only for the special case block sequential number is 0. However, this covers the s390 PAES XTS implementation in the Linux kernel.
--- target/s390x/gen-features.c | 2 + target/s390x/tcg/cpacf.h | 2 + target/s390x/tcg/cpacf_aes.c | 64 ++++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 4 ++ 4 files changed, 72 insertions(+)
target/s390x/gen-features.c +2 -0
@@ -951,6 +951,8 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KMCTR_EAES_256 ,S390_FEAT_PCC_XTS_AES_128 ,S390_FEAT_PCC_XTS_AES_256 , +S390_FEAT_PCC_XTS_EAES_128 , +S390_FEAT_PCC_XTS_EAES_256 ,S390_FEAT_PCKMO_AES_128 ,S390_FEAT_PCKMO_AES_192 , S390_FEAT_PCKMO_AES_256,
target/s390x/tcg/cpacf.h +2 -0
@@ -53,5 +53,7 @@ int cpacf_paes_ctr(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint64_t *src_ptr_reg, uint64_t *src_len_reg, uint64_t *ctr_ptr_reg, uint32_t type, uint8_t fc, uint8_t mod); +int cpacf_paes_pcc (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint8_t fc);#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c +64 -0
67 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +4 -0
@@ -219,6 +219,10 @@ static int cpacf_pcc(CPUS390XState *env, const int mmu_idx, uintptr_t ra,case CPACF_PCC_XTS_AES_256 : rc =cpacf_aes_pcc (env, mmu_idx, ra, env->regs[1 ], fc);break ; +case CPACF_PCC_XTS_PAES_128 : +case CPACF_PCC_XTS_PAES_256 : + rc =cpacf_paes_pcc (env, mmu_idx, ra, env->regs[1 ], fc); +break ;default :tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); }
Signature · 1 line
2.55.0
[PULL 26/33] pc-bios/s390-ccw: Use bus specific IPL_TYPE directly for scsi IPL
In reply to Eric FarmanFrom: Jared Rossi <[email protected]>
All existing switch cases that handle S390_IPL_TYPE_QEMU_SCSI directly fall through to S390_IPL_TYPE_CCW. Rather than always fall through, reassign vdev->ipl_type to the appropriate bus for the scsi controller and proceed as usual, where the bus is designated by the "bus" field and set during the IPLB build.
Because S390_IPL_TYPE_QEMU_SCSI should not appear as an ipl_type once the device is found, remove that specific case from other existing switches and allow it to land in the default case, which will generally result in an immediate error.
--- pc-bios/s390-ccw/main.c | 13 ++++++++++--- pc-bios/s390-ccw/virtio-blkdev.c | 1 - pc-bios/s390-ccw/virtio.c | 5 ----- 3 files changed, 10 insertions(+), 9 deletions(-)
pc-bios/s390-ccw/main.c +10 -3
@@ -261,8 +261,16 @@ static bool find_boot_device(void) vdev->selected_scsi_device.channel = iplb->scsi.channel; vdev->selected_scsi_device.target = iplb->scsi.target; vdev->selected_scsi_device.lun = iplb->scsi.lun; - blk_schid.ssid = iplb->scsi.ssid &0x3 ; - found =find_subch (iplb->scsi.devno); + vdev->ipl_type = iplb->scsi.bus; +switch (vdev->ipl_type) { +case S390_IPL_TYPE_CCW : + blk_schid.ssid = iplb->scsi.ssid &0x3 ; + found =find_subch (iplb->scsi.devno); +break ; +default : +puts ("Unrecognized SCSI controller" ); +break ; + }break ;case S390_IPL_TYPE_PCI : found =find_fid (iplb->pci.fid);
@@ -346,7 +354,6 @@ static void ipl_pci_device(void)static void ipl_boot_device (void ) {switch (virtio_get_device ()->ipl_type) { -case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW :ipl_ccw_device ();break ;
pc-bios/s390-ccw/virtio-blkdev.c +0 -1
@@ -253,7 +253,6 @@ int virtio_blk_setup_device(VDev *vdev)puts ("Using virtio-blk." );switch (vdev->ipl_type) { -case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW :return virtio_ccw_setup (vdev);case S390_IPL_TYPE_PCI :
pc-bios/s390-ccw/virtio.c +0 -5
@@ -61,7 +61,6 @@ char *virtio_get_ring_area(int ring_num)int drain_irqs (void ) {switch (vdev.ipl_type) { -case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW :return drain_irqs_ccw (vdev.schid);default :
@@ -109,7 +108,6 @@ void vring_init(VRing *vr, VqInfo *info)bool vring_notify (VRing *vr) {switch (vdev.ipl_type) { -case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW : vr->cookie =virtio_ccw_notify (vdev.schid, vr->id, vr->cookie);break ;
@@ -130,7 +128,6 @@ bool vring_notify(VRing *vr)bool be_ipl (void ) {switch (virtio_get_device ()->ipl_type) { -case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW :return true;case S390_IPL_TYPE_PCI :
@@ -231,7 +228,6 @@ int vring_wait_reply(void)int virtio_reset (VDev *vdev) {switch (vdev->ipl_type) { -case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW :return virtio_ccw_reset (vdev);case S390_IPL_TYPE_PCI :
@@ -244,7 +240,6 @@ int virtio_reset(VDev *vdev)bool virtio_is_supported (VDev *vdev) {switch (vdev->ipl_type) { -case S390_IPL_TYPE_QEMU_SCSI :case S390_IPL_TYPE_CCW :return virtio_ccw_is_supported (vdev);case S390_IPL_TYPE_PCI :
Signature · 1 line
2.55.0
[PULL 31/33] tests/qtest: Add s390x PCI SCSI fallback test to cdrom-test.c
In reply to Eric FarmanFrom: Jared Rossi <[email protected]>
Add a test to verify that a guest can use a PCI controlled CD as a fallback boot device after a failed CCW IPL.
--- tests/qtest/cdrom-test.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tests/qtest/cdrom-test.c +8 -0
@@ -272,6 +272,14 @@ static void add_s390x_tests(void)"-drive if=none,id=d1,media=cdrom,file=" , test_cdboot); } +if (qtest_has_device ("virtio-scsi-pci" )) { +qtest_add_data_func ("cdrom/boot/pci-scsi-fallback-from-blk-ccw" , +"-device virtio-scsi-pci -device virtio-serial " +"-device virtio-blk-ccw,drive=d1,bootindex=1 " +"-drive driver=null-co,read-zeroes=on,if=none,id=d1 " +"-device scsi-cd,drive=d2,bootindex=2 " +"-drive if=none,id=d2,media=cdrom,file=" , test_cdboot); + } }int main (int argc,char **argv)
Signature · 1 line
2.55.0
[PULL 07/33] crypto: Add aes-helpers file to support some AES modes
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Add a new file crypto/aes-helpers.c with simple functions to support some AES modes:
- AES cbc: AES_cbc_encrypt() AES_cbc_decrypt()
- AES ctr: AES_ctr_encrypt()
- AES xts: AES_xts_encrypt() AES_xts_decrypt()
and some AES related helpers:
- AES_xor()
- AES_xts_prep_next_tweak()
Add header file include/crypto/aes-helpers.h for these functions
--- crypto/aes-helpers.c | 106 ++++++++++++++++++++++++++++++++++ crypto/meson.build | 1 + include/crypto/aes-helpers.h | 109 +++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 crypto/aes-helpers.c create mode 100644 include/crypto/aes-helpers.h
crypto/aes-helpers.c new file +106 -0
@@ -0,0 +1,106 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* AES helper functions and mode implementations +* +* Authors: +* Harald Freudenberger <[email protected]> +*/ + +#include "qemu/osdep.h" +#include "crypto/aes.h" +#include "crypto/aes-helpers.h" + +void AES_xor (const unsigned char *src1,const unsigned char *src2, +unsigned char *dst) +{ +int i; + +for (i =0 ; i <AES_BLOCK_SIZE ; i++) { + dst[i] = src1[i] ^ src2[i]; + } +} + +void AES_cbc_encrypt (const unsigned char *in,unsigned char *out, +unsigned char *iv,const AES_KEY *key) +{ +unsigned char buf[AES_BLOCK_SIZE ]; + +/* in xor iv => buf */ +AES_xor (in, iv, buf); +/* encrypt buf => out */ +AES_encrypt (buf, out, key); +/* prep iv for next round */ +memcpy (iv, out,AES_BLOCK_SIZE ); +} + +void AES_cbc_decrypt (const unsigned char *in,unsigned char *out, +unsigned char *iv,const AES_KEY *key) +{ +unsigned char buf[AES_BLOCK_SIZE ]; + +/* decrypt in => buf */ +AES_decrypt (in, buf, key); +/* buf xor iv => out */ +AES_xor (buf, iv, out); +/* prep iv for next round */ +memcpy (iv, in,AES_BLOCK_SIZE ); +} + +void AES_ctr_encrypt (const unsigned char *in,unsigned char *out, +const unsigned char *ctr,const AES_KEY *key) +{ +unsigned char buf[AES_BLOCK_SIZE ]; + +/* encrypt ctr => buf */ +AES_encrypt (ctr, buf, key); +/* exor input data with encrypted ctr => out */ +AES_xor (in, buf, out); +} + +/* +* Tweak calculation for AES XTS. +* Multiply tweak by α (x) in GF(2^128) per IEEE 1619-2007. The tweak +* is a 128-bit little-endian integer (tweak[0]=LSB, tweak[15]=MSB). +* This implementation has been verified on little and big endian. +*/ +void AES_xts_prep_next_tweak (unsigned char *tweak) +{ +unsigned char carry; +int i; + + carry = tweak[AES_BLOCK_SIZE -1 ] >>7 ; + +for (i =AES_BLOCK_SIZE -1 ; i >0 ; i--) { + tweak[i] = (unsigned char )((tweak[i] <<1 ) | (tweak[i -1 ] >>7 )); + } + + tweak[i] = (unsigned char )(tweak[i] <<1 ); + tweak[i] ^= (unsigned char )(0x87 & (unsigned char )(-(unsigned char )carry)); +} + +void AES_xts_encrypt (const unsigned char *in,unsigned char *out, +const unsigned char *tweak,const AES_KEY *key) +{ +unsigned char buf1[AES_BLOCK_SIZE ], buf2[AES_BLOCK_SIZE ]; + +/* in xor tweak => buf1 */ +AES_xor (in, tweak, buf1); +/* encrypt buf1 => buf2 */ +AES_encrypt (buf1, buf2, key); +/* buf2 xor tweak => out */ +AES_xor (buf2, tweak, out); +} + +void AES_xts_decrypt (const unsigned char *in,unsigned char *out, +const unsigned char *tweak,const AES_KEY *key) +{ +unsigned char buf1[AES_BLOCK_SIZE ], buf2[AES_BLOCK_SIZE ]; + +/* in xor tweak => buf1 */ +AES_xor (in, tweak, buf1); +/* encrypt buf1 => buf2 */ +AES_decrypt (buf1, buf2, key); +/* buf2 xor tweak => out */ +AES_xor (buf2, tweak, out); +}
crypto/meson.build +1 -0
@@ -55,6 +55,7 @@ system_ss.add(when: gnutls, if_true: files('tls-cipher-suites.c')) util_ss.add(files( 'aes.c', + 'aes-helpers.c', 'clmul.c', 'init.c', 'sm4.c',
include/crypto/aes-helpers.h new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.55.0
[PULL 03/33] target/s390x: Move cpacf sha512 code into a new file
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Move the cpacf sha512 implementation into a new file cpacf_sha512.c. Add this new file to the build. Introduce a new header file cpacf.h which holds function prototypes and other things around cpacf local to the tcg directory.
--- target/s390x/tcg/cpacf.h | 16 ++ target/s390x/tcg/cpacf_sha512.c | 242 +++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 223 +--------------------------- target/s390x/tcg/meson.build | 1 + 4 files changed, 260 insertions(+), 222 deletions(-) create mode 100644 target/s390x/tcg/cpacf.h create mode 100644 target/s390x/tcg/cpacf_sha512.c
target/s390x/tcg/cpacf.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* s390x cpacf +* +*/ + +#ifndef S390X_CPACF_H +#define S390X_CPACF_H + +/* from cpacf_sha512.c */ +int cpacf_sha512 (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *message_reg,uint64_t *len_reg, +uint32_t type); + +#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_sha512.c new file +242 -0
242 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +1 -222
229 lines not on this page · raw message
target/s390x/tcg/meson.build +1 -0
@@ -5,6 +5,7 @@ s390x_ss.add(when: 'CONFIG_TCG', if_true: files( )) s390x_common_ss.add(when: 'CONFIG_TCG', if_true: files( 'cc_helper.c', + 'cpacf_sha512.c', 'crypto_helper.c', 'excp_helper.c', 'fpu_helper.c',
Signature · 1 line
2.55.0
[PULL 11/33] target/s390x: Minimal AES XTS support for cpacf pcc instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Support CPACF pcc subfunctions PCC-Compute-XTS-Parameter-AES-128 and PCC-Compute-XTS-Parameter-AES-245 but only for the special case block sequential number is 0. However, this covers the s390 AES XTS implementation in the Linux kernel and Libica and thus also Opencryptoki clear key via Libica.
--- target/s390x/gen-features.c | 2 ++ target/s390x/tcg/cpacf.h | 2 ++ target/s390x/tcg/cpacf_aes.c | 53 ++++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 20 ++++++++++++ 4 files changed, 77 insertions(+)
target/s390x/gen-features.c +2 -0
@@ -938,6 +938,8 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KMCTR_AES_128 ,S390_FEAT_KMCTR_AES_192 ,S390_FEAT_KMCTR_AES_256 , +S390_FEAT_PCC_XTS_AES_128 , + S390_FEAT_PCC_XTS_AES_256, };/****** END FEATURE DEFS ******/
target/s390x/tcg/cpacf.h +2 -0
@@ -32,5 +32,7 @@ int cpacf_aes_ctr(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint64_t *src_ptr_reg, uint64_t *src_len_reg, uint64_t *ctr_ptr_reg, uint32_t type, uint8_t fc, uint8_t mod); +int cpacf_aes_pcc (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint8_t fc);#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c +53 -0
56 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +20 -0
@@ -182,6 +182,23 @@ static int cpacf_ppno(CPUS390XState *env, const int mmu_idx, uintptr_t ra,return rc; } +static int cpacf_pcc (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint8_t fc) +{ +int rc =0 ; + +switch (fc) { +case CPACF_PCC_XTS_AES_128 : +case CPACF_PCC_XTS_AES_256 : + rc =cpacf_aes_pcc (env, mmu_idx, ra, env->regs[1 ], fc); +break ; +default : +tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); + } + +return rc; +} +uint32_t HELPER (msa )(CPUS390XState *env,uint32_t r1,uint32_t r2,uint32_t r3,uint32_t type) {
@@ -238,6 +255,9 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,case S390_FEAT_TYPE_KMCTR : rc =cpacf_kmctr (env, mmu_idx, ra, r1, r2, r3, fc, mod);break ; +case S390_FEAT_TYPE_PCC : + rc =cpacf_pcc (env, mmu_idx, ra, fc); +break ;case S390_FEAT_TYPE_PPNO : rc =cpacf_ppno (env, mmu_idx, ra, r1, r2, r3, fc);break ;
Signature · 1 line
2.55.0
[PULL 20/33] tests/tcg/s390x: Add tests for CPACF instructions
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Add simple tests for the CPACF instructions implemented:
- kdsa - minimal as only query is implemented
- kimd - query, sha256, sha512
- klmd - query, sha256, sha512
- km - query, aes 128, 192, 256 with clear and prot key
- kmac - minimal as only query is implemented
- kmc - query, aes 128, 192, 256 with clear and prot key
- kmctr - query, aes 128, 192, 256 with clear and prot key
- pcc - query, xts aes 128, 256 and prot key xts aes 128, 256
- pckmo - run query and check for SIGILL
- prno - query, trng
No test for kma, kmf, kmo as these instructions are currently not implemented at all.
--- tests/tcg/s390x/cpacf-kdsa.c | 58 ++++ tests/tcg/s390x/cpacf-kimd.c | 166 ++++++++++ tests/tcg/s390x/cpacf-klmd.c | 206 ++++++++++++ tests/tcg/s390x/cpacf-km.c | 590 ++++++++++++++++++++++++++++++++++ tests/tcg/s390x/cpacf-kmac.c | 58 ++++ tests/tcg/s390x/cpacf-kmc.c | 351 ++++++++++++++++++++ tests/tcg/s390x/cpacf-kmctr.c | 360 +++++++++++++++++++++ tests/tcg/s390x/cpacf-pcc.c | 245 ++++++++++++++ tests/tcg/s390x/cpacf-pckmo.c | 45 +++ tests/tcg/s390x/cpacf-prno.c | 131 ++++++++ tests/tcg/s390x/cpacf.h | 570 ++++++++++++++++++++++++++++++++ tests/tcg/s390x/meson.build | 10 + 12 files changed, 2790 insertions(+) create mode 100644 tests/tcg/s390x/cpacf-kdsa.c create mode 100644 tests/tcg/s390x/cpacf-kimd.c create mode 100644 tests/tcg/s390x/cpacf-klmd.c create mode 100644 tests/tcg/s390x/cpacf-km.c create mode 100644 tests/tcg/s390x/cpacf-kmac.c create mode 100644 tests/tcg/s390x/cpacf-kmc.c create mode 100644 tests/tcg/s390x/cpacf-kmctr.c create mode 100644 tests/tcg/s390x/cpacf-pcc.c create mode 100644 tests/tcg/s390x/cpacf-pckmo.c create mode 100644 tests/tcg/s390x/cpacf-prno.c create mode 100644 tests/tcg/s390x/cpacf.h
tests/tcg/s390x/cpacf-kdsa.c new file +58 -0
@@ -0,0 +1,58 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* Simple test for the CPACF KDSA instruction +*/ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "cpacf.h" + +#define QUERY_BLOCK_SIZE 16 + +/* expected kdsa query block */ +static uint8_t exp_query_block[QUERY_BLOCK_SIZE ] = { +0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +}; + +static int test_kdsa_query (void ) +{ +uint8_t query_block[QUERY_BLOCK_SIZE ] = {0 }; +unsigned long cc =0 ; +int i, rc =0 ; + +cpacf_kdsa (CPACF_KDSA_QUERY , query_block,NULL ,0 , &cc); + +/* compare with expected query block */ +for (i =0 ; i <QUERY_BLOCK_SIZE ; i++) { +if ((query_block[i] & exp_query_block[i]) != exp_query_block[i]) { + rc++; +break ; + } + } + +if (rc) { +printf ("%s failed\n" , __func__); + } + +return rc; +} + +int main (void ) +{ +int rc; + +/* Test query function */ + rc =test_kdsa_query (); + +/* As of now only KDSA query is implemented */ + +if (rc) { +printf ("cpacf-kdsa: %d failures\n" , rc); + } + +return rc ?EXIT_FAILURE :EXIT_SUCCESS ; +}
tests/tcg/s390x/cpacf-kimd.c new file +166 -0
166 lines not on this page · raw message
tests/tcg/s390x/cpacf-klmd.c new file +206 -0
206 lines not on this page · raw message
tests/tcg/s390x/cpacf-km.c new file +590 -0
590 lines not on this page · raw message
tests/tcg/s390x/cpacf-kmac.c new file +58 -0
58 lines not on this page · raw message
tests/tcg/s390x/cpacf-kmc.c new file +351 -0
351 lines not on this page · raw message
tests/tcg/s390x/cpacf-kmctr.c new file +360 -0
360 lines not on this page · raw message
tests/tcg/s390x/cpacf-pcc.c new file +245 -0
245 lines not on this page · raw message
tests/tcg/s390x/cpacf-pckmo.c new file +45 -0
45 lines not on this page · raw message
tests/tcg/s390x/cpacf-prno.c new file +131 -0
131 lines not on this page · raw message
tests/tcg/s390x/cpacf.h new file +570 -0
570 lines not on this page · raw message
tests/tcg/s390x/meson.build +10 -0
@@ -74,6 +74,16 @@ tests += { 'ts.c': {}, 'ex-smc.c': {'cflags': ['-Wl,--no-warn-rwx-segments']}, 'load-store-reversed.c': {}, + 'cpacf-kdsa.c': {}, + 'cpacf-kimd.c': {}, + 'cpacf-klmd.c': {}, + 'cpacf-km.c': {}, + 'cpacf-kmac.c': {}, + 'cpacf-kmc.c': {}, + 'cpacf-kmctr.c': {}, + 'cpacf-pcc.c': {}, + 'cpacf-pckmo.c': {}, + 'cpacf-prno.c': {}, } foreach src: tests_s390x_pgm
Signature · 1 line
2.55.0
[PULL 06/33] target/s390x: Adjust addressing mode checks for sha512 and sha256
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
The handling for different addressing modes in the both sha implementations cpacf sha256 and sha512 was incomplete. Rework this addressing checking to clearly have support for s390 64 bit and 32 bit addressing mode but raise an exception otherwise.
Also bail out early (for KIMD only) if length is 0.
--- target/s390x/tcg/cpacf_sha256.c | 16 +++++++++++++--- target/s390x/tcg/cpacf_sha512.c | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-)
target/s390x/tcg/cpacf_sha256.c +13 -3
@@ -111,14 +111,24 @@ int cpacf_sha256(CPUS390XState *env, const int mmu_idx, uintptr_t ra, {enum {MAX_BLOCKS_PER_RUN =128 };/* 128 * 64 = 8K */ uint64_t len = *len_reg, processed =0 ; -int message_reg_len =64 ; +int message_reg_len;uint32_t a[8 ];g_assert (type ==S390_FEAT_TYPE_KIMD || type ==S390_FEAT_TYPE_KLMD ); -if (!(env->psw.mask &PSW_MASK_64 )) { +/* check addressing mode, raise exception if not supported here */ +if (env->psw.mask &PSW_MASK_64 ) { + message_reg_len =64 ; + }else if (env->psw.mask &PSW_MASK_32 ) { + message_reg_len =32 ; len = (uint32_t )len; - message_reg_len = (env->psw.mask &PSW_MASK_32 ) ?32 :24 ; + }else { +tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); + } + +/* for KIMD only: early bail out if length is zero */ +if (type ==S390_FEAT_TYPE_KIMD && !len) { +return 0 ; }/* KIMD: length has to be properly aligned. */
target/s390x/tcg/cpacf_sha512.c +13 -3
@@ -126,13 +126,23 @@ int cpacf_sha512(CPUS390XState *env, const int mmu_idx, uintptr_t ra, {enum {MAX_BLOCKS_PER_RUN =64 };/* Arbitrary: keep interactivity. */ uint64_t len = *len_reg, a[8 ], processed =0 ; -int message_reg_len =64 ; +int message_reg_len;g_assert (type ==S390_FEAT_TYPE_KIMD || type ==S390_FEAT_TYPE_KLMD ); -if (!(env->psw.mask &PSW_MASK_64 )) { +/* check addressing mode, raise exception if not supported here */ +if (env->psw.mask &PSW_MASK_64 ) { + message_reg_len =64 ; + }else if (env->psw.mask &PSW_MASK_32 ) { + message_reg_len =32 ; len = (uint32_t )len; - message_reg_len = (env->psw.mask &PSW_MASK_32 ) ?32 :24 ; + }else { +tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); + } + +/* for KIMD only: early bail out if length is zero */ +if (type ==S390_FEAT_TYPE_KIMD && !len) { +return 0 ; }/* KIMD: length has to be properly aligned. */
Signature · 1 line
2.55.0
[PULL 18/33] target/s390x: Support protected key AES XTS for cpacf km instruction
In reply to Eric FarmanFrom: Harald Freudenberger <[email protected]>
Support the subfunctions CPACF_KM_PXTS_128 and CPACF_KM_PXTS_256 for the cpacf km instruction.
--- target/s390x/gen-features.c | 2 + target/s390x/tcg/cpacf.h | 4 ++ target/s390x/tcg/cpacf_aes.c | 105 +++++++++++++++++++++++++++++++ target/s390x/tcg/crypto_helper.c | 6 ++ 4 files changed, 117 insertions(+)
target/s390x/gen-features.c +2 -0
@@ -937,6 +937,8 @@ static uint16_t qemu_MAX[] = {S390_FEAT_KM_EAES_256 ,S390_FEAT_KM_XTS_AES_128 ,S390_FEAT_KM_XTS_AES_256 , +S390_FEAT_KM_XTS_EAES_128 , +S390_FEAT_KM_XTS_EAES_256 ,S390_FEAT_KMC_AES_128 ,S390_FEAT_KMC_AES_192 , S390_FEAT_KMC_AES_256,
target/s390x/tcg/cpacf.h +4 -0
@@ -55,5 +55,9 @@ int cpacf_paes_ctr(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint8_t fc, uint8_t mod);int cpacf_paes_pcc (CPUS390XState *env,const int mmu_idx,uintptr_t ra,uint64_t param_addr,uint8_t fc); +int cpacf_paes_xts (CPUS390XState *env,const int mmu_idx,uintptr_t ra, +uint64_t param_addr,uint64_t *dst_ptr_reg, +uint64_t *src_ptr_reg,uint64_t *src_len_reg, +uint32_t type,uint8_t fc,uint8_t mod);#endif /* S390X_CPACF_H */
target/s390x/tcg/cpacf_aes.c +105 -0
108 lines not on this page · raw message
target/s390x/tcg/crypto_helper.c +6 -0
@@ -125,6 +125,12 @@ static int cpacf_km(CPUS390XState *env, const int mmu_idx, uintptr_t ra, &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], S390_FEAT_TYPE_KM, fc, mod);break ; +case CPACF_KM_PXTS_128 : +case CPACF_KM_PXTS_256 : + rc =cpacf_paes_xts (env, mmu_idx, ra, env->regs[1 ], + &env->regs[r1], &env->regs[r2], &env->regs[r2 +1 ], +S390_FEAT_TYPE_KM , fc, mod); +break ;default :tcg_s390_program_interrupt (env,PGM_SPECIFICATION , ra); }
Signature · 1 line
2.55.0
Richard Henderson
AppliedQuoted 10 lines · Eric Farman
The following changes since commit
c1c18d1e640b64292859ce9f30f3c344edfb0294:Merge tag 'virtio-snd-migrate-pr-v2' ofhttps://gitlab.com/epilys/qemu into staging (2026-09-19 10:41:53 -1000)are available in the Git repository at:
https://gitlab.com/efarman/qemu.git tags/s390x-20260921for you to fetch changes up to
96bd689997443a15f259fa99a6a672eb1f65062c:
Quoted 8 lines
pc-bios/s390-ccw.img: update s390x bios (2026-09-21 11:46:02 -0400)----------------------------------------------------------------
New s390x features for 11.2
- extend CPACF support
- enable secure IPL for virtio-blk-pci
- enable boot from virtio-scsi-pci
- regenerate s390-ccw.img
Applied, thanks.
r~