KVM: s390: arm64: System Registers
Steffen Eiden
reviewerv4 cover KVM: s390: arm64: System Registers
Add system register handling for KVM/arm64 on s390. Share KVM/arm64 code, introduce ARM guest management functions for s390 hosts, and implement host system register & exception handling.
This is the second series on the way to arm64 guests on s390. The first series laid the KVM foundation (basic module, vCPU run, simple page faults) and is included in v7.4. This series builds the system register layer on top and closes the biggest of the remaining gaps towards a functional guest support.
On top of master this series requires one patch[1] not yet merged in order to build clean.
The series applies without those patches on master but the build will fail or trigger warnings w/o those patches.
Regarding merging:
Patches 1-10 can/should go via the KVM/arm64 tree. Note that PATCH 8 is an s390 patch but is is required so be at this position. Otherwise, s390 will not compile when patch 10 is applied until patch 18. And I cannot palce it before as the patch needs some stuff from the just shared headers in PATCH 07.
Patches 11-25 can then be picked by KVM/s390. Those require the perquisite patch [1] mentioned above.
A branch with the prerequisite and this series is available at kernel.org [2]. Another series may be added on top to that branch soon.
Changes in detail:
arm64:
Refactor the id register fields in arch_vcpu into a dedicated structure such that it can be reused by s390. Refactor detection of the number of sysregs. Mark sysreg related code as shared.
A few code pieces are moved inside arm headers/code to reduce the amount of shared sections. This adds a bit of churn in the diff but reduces the shared marker __churn__ at the end.
The shared regions deliberately contain more code and more headers than s390 currently needs. Larger contiguous regions mean less churn whenever the surrounding arm64 code changes. Some of this code will be used by later series anyways. Some of the shared code will probably never be reused by s390 at all. I trust the compiler to remove it. The reduced churn outweighs this drawback. Since unused function checking is disabled for shared code [3], sharing more than required does not introduce warnings once everything is merged.
s390:
Add s390 instruction support for ARM guest management: easr/sasr for system register access, QAAF for feature queries, and ptff extensions for guest time handling.
Implement complete sysreg handling for s390 including feature sanitisation, register enumeration and access, exception injection, and finalized page fault handling. For now s390 maintains its own sysreg table but I intend to share the table with arm as soon as possible.
Emulation:
Guest accesses to ID registers are trapped and served from a sanitized copy of the QAAF query results, using the ID register sanitisation and finalisation infrastructure shared with arm64. Userspace sees and controls guest ID registers with the usual semantics. After the first vCPU run the values are final. All other system registers live in the SAE save area and are accessed by the host via EASR/SASR, either on guest traps or through the one-reg/two-reg UAPI. The save area itself is initialized from the QAAF-provided initial save area.
Exception handling:
Unsupported or invalid guest actions now raise proper arm64 exceptions instead of failing exits. Page faults beyond the guest's address limits are injected as address size faults or synchronous external aborts, mirroring arm64's kvm_handle_guest_abort() injected faults re-enter the guest with the pending exception instead of exiting to userspace.
Features and userspace:
SVE is offered to guests at 128-bit vector length, backed by s390's Vector Extension. Pointer authentication is passed through where hardware support exists. The AEF capabilities are reported under /sys/firmware/aef/, including the raw QAAF query results.
Steffen
[1] https://lore.kernel.org/all/[email protected]
[2] https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git/log/?h=sae
---
Changes in v4:
arm64:
- split up id register refactroing into two: defineing helpers, then creating the new struct (marc)
- New patch "arm64: vdso: Define ARM64_S390_COMMON=1 for all vdso builds" to fix the arm64 (compat) vDSO build, which dies on -Wundef/-Werror when the sharing marker is unset.
- OSLSR conversion: also update the tools copy of sysreg.h
s390:
- The guest PT offset (EPD) is now tracked per-VM instead of per-vcpu.
- vcpu_reset_hcrx() is now non-static, runs after the feature set has been restricted (vcpu run pid change), and sets HCRX_EL2_MSCEn unconditionally, depending on MOPS
- Feature sanitisation: ARM64_HAS_HCR_NV1 no longer probes ID_AA64MMFR4_EL1.E2H0 and reports false, matching the other non-emulatable capabilities.
- AEF sysfs: dropped the redundant sae_avail/ptff_avail/edat2_avail attributes
- Authorship fixes: range-check asm macro patch is solely authored by Jens Remus. SVE patch authorship now credits Friedrich Welter.
- more smaller issues resolved
- Collected Reviewed-by tags from Joey Goulyand rebased onto master
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- rebase into 7.4-rc2 (including the first batch of arm on s390 patches)
- guard style changed from #ifdef ARM64_S390_COMMON to #if ARM64_S390_COMMON == 1
- Improve and clarify commit messages
arm64:
- generate OSLSR definitions
- consolidate more shared sections by:
- moving some code in beforehand
- deliberately adding more code/header than required.
due to [3] there will not be any unused warnings when merged.
- reduce sharing churn
s390
- streamline sasr/easr instruction generation and use
- aef_info() aggregate removed; new minimal aef_usable()/aef_gisrsa() API
- qaaf enum numbering reorganized, on reserved field was incorrectly identified as a register.
- aef.c no longer aggregates or gates on CONFIG_KVM_S390_ARM64.
- spectre.c stubs replaced with real queries of sanitized ID regs.
- Many new sys_reg_descs entries
- QAAF init save area: save area now memcpy'd from cached aef_gisrsa() instead of kvm_vcpu_init_save_area()
- improved pagefault handling
- reworked SVE helpers
- fixed various smaller bugs
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- rework the entire sharing code concept to use marker instead of moving code.
---
Friedrich Welter (1):
KVM: s390: arm64: Implement SVE for arm guests
Jens Remus (1):
s390: Add range check asm macro
Steffen Eiden (23):
KVM: arm64: Route VM ID register accesses through helpers
KVM: arm64: Refactor idreg caching into dedicated structure
KVM: arm64: Extract number of sys_reg_desc into a constant
arm64: sysreg: Convert OSLSR to automatic register generation
arm64: vdso: Define ARM64_S390_COMMON=1 for all vdso builds
arm64: Prepare headers for sysreg sharing with s390
arm64: Share system register related headers and functions with s390
KVM: s390: arm64: Prepare for sharing arm64 SVE and ftr-reg code
KVM: arm64: Prepare sys_regs.c for sharing with s390
KVM: arm64: Share system register code with s390
s390: tools: Share arm64/kvm headers
s390: Read/write ARM system registers
s390: Query arm guest time
KVM: s390: arm64: Query Available Arm features
KVM: s390: arm64: Verify machine feature set before loading
KVM: s390: arm64: Implement feature sanitisation
KVM: s390: arm64: Implement arm system register managing infrastructure
KVM: s390: arm64: Integrate system registers into the host
KVM: s390: arm64: Use QAAF init save area
KVM: s390: arm64: Implement exception injection
KVM: s390: arm64: Finalize page fault handling
KVM: s390: arm64: Promote PTRAUTH capability
s390: Report AEF features to sysfs
Documentation/ABI/testing/sysfs-firmware-aef | 51 ++ arch/arm64/include/asm/cache.h | 3 + arch/arm64/include/asm/cputype.h | 3 + arch/arm64/include/asm/kvm_emulate.h | 5 +- arch/arm64/include/asm/kvm_host.h | 101 +++- arch/arm64/include/asm/spectre.h | 13 +- arch/arm64/include/asm/sysreg.h | 12 +- arch/arm64/kernel/vdso32/Makefile | 2 + arch/arm64/kvm/arm.c | 3 + arch/arm64/kvm/config.c | 12 +- arch/arm64/kvm/guest.c | 11 +- arch/arm64/kvm/hyp/nvhe/pkvm.c | 10 +- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 5 +- arch/arm64/kvm/sys_regs.c | 113 ++-- arch/arm64/kvm/sys_regs.h | 1 + arch/arm64/tools/sysreg | 14 + arch/s390/include/arm64/kvm_emulate.h | 2 + arch/s390/include/arm64/kvm_hyp.h | 18 + arch/s390/include/arm64/kvm_nested.h | 5 + arch/s390/include/arm64/sys_regs.h | 9 + arch/s390/include/asm/aef.h | 12 + arch/s390/include/asm/insn-common-asm.h | 28 + arch/s390/include/asm/kvm_host_arm64.h | 238 +++++++- arch/s390/include/asm/kvm_host_arm64_types.h | 115 ++++ arch/s390/include/asm/sae-asm.h | 45 ++ arch/s390/include/asm/sae.h | 93 +++ arch/s390/include/asm/timex.h | 53 ++ arch/s390/kernel/Makefile | 2 +- arch/s390/kernel/aef.c | 192 +++++++ arch/s390/kernel/dis.c | 1 + arch/s390/kvm/arm64/Makefile | 7 +- arch/s390/kvm/arm64/Makefile.gen | 3 +- arch/s390/kvm/arm64/arm.c | 107 +++- arch/s390/kvm/arm64/exception.c | 109 ++++ arch/s390/kvm/arm64/feature.c | 178 ++++++ arch/s390/kvm/arm64/feature.h | 97 ++++ arch/s390/kvm/arm64/guest.c | 268 ++++++++- arch/s390/kvm/arm64/handle_exit.c | 1 + arch/s390/kvm/arm64/inject_fault.c | 65 ++- arch/s390/kvm/arm64/mmu.c | 74 ++- arch/s390/kvm/arm64/qaaf.c | 85 +++ arch/s390/kvm/arm64/qaaf.h | 12 + arch/s390/kvm/arm64/reset.c | 72 +++ arch/s390/kvm/arm64/spectre.c | 51 ++ arch/s390/kvm/arm64/sys_regs.c | 831 +++++++++++++++++++++++++++ arch/s390/kvm/arm64/trace.h | 50 ++ arch/s390/tools/Makefile.arm64h | 11 +- arch/s390/tools/opcodes.txt | 3 + include/kvm/arm_arch_timer.h | 3 + tools/arch/arm64/include/asm/sysreg.h | 12 +- 50 files changed, 3052 insertions(+), 159 deletions(-)
base-commit: 9437ee8b6cf607e883b36e44bd755968daaebd48
change-id: 20261106-sysreg-d6adf0cd34d4
prerequisite-message-id: [email protected]
prerequisite-patch-id: ed28ef94c9056cb81bb738f1b54745d012cb613f
Steffen Eiden
reviewerPATCH v4 1/25 KVM: arm64: Route VM ID register accesses through helpers
VM-scoped ID registers are currently accessed in a mix of ways: the kvm_read_vm_id_reg() macro, open-coded kvm->arch.id_regs[] array accesses, and direct writes to the ctr_el0 and midr_el1 fields in pKVM.
Add a small accessor family on top of __vm_id_reg() and the new __vm_ftr_reg_by_idx() to streamline the handling of the feature registers.
Convert all open-coded accesses so the mapping from ID register (or index) to its storage lives in exactly one place. This is a prerequisite for sharing the feature register code with s390's kvm_arm64.
--- arch/arm64/include/asm/kvm_host.h | 41 +++++++++++++++++++++++++++++++++++--- arch/arm64/kvm/config.c | 12 ++++++----- arch/arm64/kvm/hyp/nvhe/pkvm.c | 7 +++++-- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 5 ++--- arch/arm64/kvm/sys_regs.c | 6 ++---- 5 files changed, 54 insertions(+), 17 deletions(-)
arch/arm64/include/asm/kvm_host.h +38 -3
@@ -1637,11 +1637,16 @@ void kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu);bool kvm_arm_vcpu_stopped (struct kvm_vcpu *vcpu);bool kvm_pkvm_vcpu_is_powered_off (struct kvm_vcpu *vcpu); +static inline u64 *__vm_ftr_reg_by_idx (struct kvm_arch *ka,u32 idx) +{ +return &ka->id_regs[idx]; +} +static inline u64 *__vm_id_reg (struct kvm_arch *ka,u32 reg) {switch (reg) { case sys_reg(3, 0, 0, 1, 0) ... sys_reg(3, 0, 0, 7, 7): -return &ka->id_regs[IDREG_IDX (reg)]; +return __vm_ftr_reg_by_idx (ka,IDREG_IDX (reg));case SYS_CTR_EL0 :return &ka->ctr_el0;case SYS_MIDR_EL1 :
@@ -1656,8 +1661,38 @@ static inline u64 *__vm_id_reg(struct kvm_arch *ka, u32 reg) } } -#define kvm_read_vm_id_reg (kvm, reg) \ - ({ u64 __val = *__vm_id_reg(&(kvm)->arch, reg); __val; }) +#define kvm_get_vm_ftr_reg_by_idx (kvm, idx) \ + ({ \ + u64 *__valp = __vm_ftr_reg_by_idx(&(kvm)->arch, idx); \ + __valp; \ + }) + +#define kvm_get_vm_id_reg (kvm, reg) \ + ({ \ + u64 *__valp = __vm_id_reg(&(kvm)->arch, reg); \ + __valp; \ + }) + +#define kvm_read_vm_id_reg (kvm, reg) \ + ({ \ + u64 __val = *kvm_get_vm_id_reg(kvm, reg); \ + __val; \ + }) + +#ifdef __KVM_NVHE_HYPERVISOR__ +#define __kvm_set_vm_id_reg (kvm, reg, val) \ + ({ \ + u64 *__p = kvm_get_vm_id_reg(kvm, reg); \ + *__p = val; \ + }) +#else +#define __kvm_set_vm_id_reg (kvm, reg, val) \ + ({ \ + u64 *__p = kvm_get_vm_id_reg(kvm, reg); \ + if (!KVM_BUG_ON(!__p, kvm)) \ + *__p = val; \ + }) +#endif /* __KVM_NVHE_HYPERVISOR__ */ void kvm_set_vm_id_reg (struct kvm *kvm,u32 reg,u64 val);
arch/arm64/kvm/config.c +7 -5
@@ -1560,6 +1560,7 @@ static const struct reg_feat_map_desc *idreg_feat_maps[] = {static bool idreg_apply_deps (struct kvm *kvm,const struct reg_feat_map_desc *r) {struct resx resx = {}; +u64 *valp;u64 val;for (int i =0 ; i < r->bit_feat_map_sz; i++) {
@@ -1568,11 +1569,12 @@ static bool idreg_apply_deps(struct kvm *kvm, const struct reg_feat_map_desc *r) resx.res0 |=reg_feat_map_bits (&r->bit_feat_map[i]); } - val = kvm->arch.id_regs[r->idreg_idx]; - kvm->arch.id_regs[r->idreg_idx] &= ~resx.res0; - kvm->arch.id_regs[r->idreg_idx] |= resx.res1; + valp =kvm_get_vm_ftr_reg_by_idx (kvm, r->idreg_idx); + val = *valp; + *valp &= ~resx.res0; + *valp |= resx.res1; -return val != kvm->arch.id_regs[r->idreg_idx]; +return val != *valp; }void kvm_idregs_enforce_dependencies (struct kvm *kvm)
@@ -1589,7 +1591,7 @@ void kvm_idregs_enforce_dependencies(struct kvm *kvm)static bool idreg_feat_match (struct kvm *kvm,const struct reg_bits_to_feat_map *map) { -u64 regval = kvm->arch.id_regs[map->regidx]; +u64 regval = *kvm_get_vm_ftr_reg_by_idx (kvm, map->regidx);u64 regfld = (regval >> map->shift) &GENMASK (map->width -1 ,0 );if (map->sign) {
arch/arm64/kvm/hyp/nvhe/pkvm.c +5 -2
@@ -413,7 +413,8 @@ static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const strucDECLARE_BITMAP (allowed_features,KVM_VCPU_MAX_FEATURES );/* CTR_EL0 is always under host control, even for protected VMs. */ - hyp_vm->kvm.arch.ctr_el0 = host_kvm->arch.ctr_el0; +__kvm_set_vm_id_reg (kvm,SYS_CTR_EL0 , + *kvm_get_vm_id_reg ((struct kvm *)host_kvm,SYS_CTR_EL0 ));/* * pKVM runs only GICv3. Anything else becomes 0, the model of a VM
@@ -433,7 +434,9 @@ static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const struc KVM_VCPU_MAX_FEATURES);if (test_bit (KVM_ARCH_FLAG_WRITABLE_IMP_ID_REGS , &host_arch_flags)) - hyp_vm->kvm.arch.midr_el1 = host_kvm->arch.midr_el1; +__kvm_set_vm_id_reg (kvm,SYS_MIDR_EL1 , + *kvm_get_vm_id_reg ((struct kvm *)host_kvm, +SYS_MIDR_EL1 )); goto out; }
arch/arm64/kvm/hyp/nvhe/sys_regs.c +2 -3
@@ -296,7 +296,7 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,return 0 ;if (reg >=sys_reg (3 ,0 ,0 ,1 ,0 ) && reg <=sys_reg (3 ,0 ,0 ,7 ,7 )) -return kvm->arch.id_regs[IDREG_IDX (reg)]; +return *kvm_get_vm_id_reg (kvm, reg);return 0 ; }
@@ -594,7 +594,6 @@ void kvm_reset_pvm_sys_regs(struct kvm_vcpu *vcpu)void kvm_init_pvm_id_regs (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm; -struct kvm_arch *ka = &kvm->arch;u32 r;hyp_assert_lock_held (&vm_table_lock);
@@ -607,7 +606,7 @@ void kvm_init_pvm_id_regs(struct kvm_vcpu *vcpu)* for protected VMs. */ for (r =sys_reg (3 ,0 ,0 ,4 ,0 ); r <=sys_reg (3 ,0 ,0 ,7 ,7 ); r +=sys_reg (0 ,0 ,0 ,0 ,1 )) - ka->id_regs[IDREG_IDX (r)] =pvm_calc_id_reg (vcpu, r); + *kvm_get_vm_ftr_reg_by_idx (kvm,IDREG_IDX (r)) =pvm_calc_id_reg (vcpu, r);set_bit (KVM_ARCH_FLAG_ID_REGS_INITIALIZED , &kvm->arch.flags); }
arch/arm64/kvm/sys_regs.c +2 -4
@@ -2543,14 +2543,12 @@ static int set_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,void kvm_set_vm_id_reg (struct kvm *kvm,u32 reg,u64 val) { -u64 *p =__vm_id_reg (&kvm->arch, reg); -lockdep_assert_held (&kvm->arch.config_lock); -if (KVM_BUG_ON (kvm_id_regs_final (kvm) || !p, kvm)) +if (KVM_BUG_ON (kvm_id_regs_final (kvm), kvm))return ; - *p = val; +__kvm_set_vm_id_reg (kvm, reg, val); } static int get_raz_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 2/25 KVM: arm64: Refactor idreg caching into dedicated structure
In reply to Steffen EidenMove VM-wide ID register emulation fields from struct kvm_arch into a new struct kvm_vm_id_regs. The new struct is placed in a shared region. Update the helper function and one memcopy in pkvm to use the new structure;
No functional changes.
--- arch/arm64/include/asm/kvm_host.h | 56 +++++++++++++++++++++------------------ arch/arm64/kvm/hyp/nvhe/pkvm.c | 3 ++- 2 files changed, 32 insertions(+), 27 deletions(-)
arch/arm64/include/asm/kvm_host.h +30 -26
@@ -105,6 +105,25 @@ struct vcpu_reset_state { bool reset; }; +struct kvm_vm_id_regs { +/* +* Emulated CPU ID registers per VM +* (Op0, Op1, CRn, CRm, Op2) of the ID registers to be saved in it +* is (3, 0, 0, crm, op2), where 1<=crm<8, 0<=op2<8. +* +* These emulated idregs are VM-wide, but accessed from the context of a vCPU. +* Atomic access to multiple idregs are guarded by kvm_arch.config_lock. +*/ +#define IDREG_IDX (id) (((sys_reg_CRm(id) - 1) << 3) | sys_reg_Op2(id)) +#define KVM_ARM_ID_REG_NUM (IDREG_IDX(sys_reg(3, 0, 0, 7, 7)) + 1) +u64 ftr_regs[KVM_ARM_ID_REG_NUM ]; + +u64 midr_el1; +u64 revidr_el1; +u64 aidr_el1; +u64 ctr_el0; +}; +#endif /* ARM64_S390_COMMON == 1 */ #define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
@@ -478,22 +497,7 @@ struct kvm_arch {struct kvm_smccc_features smccc_feat;struct maple_tree smccc_filter; -/* -* Emulated CPU ID registers per VM -* (Op0, Op1, CRn, CRm, Op2) of the ID registers to be saved in it -* is (3, 0, 0, crm, op2), where 1<=crm<8, 0<=op2<8. -* -* These emulated idregs are VM-wide, but accessed from the context of a vCPU. -* Atomic access to multiple idregs are guarded by kvm_arch.config_lock. -*/ -#define IDREG_IDX (id) (((sys_reg_CRm(id) - 1) << 3) | sys_reg_Op2(id)) -#define KVM_ARM_ID_REG_NUM (IDREG_IDX(sys_reg(3, 0, 0, 7, 7)) + 1) -u64 id_regs[KVM_ARM_ID_REG_NUM ]; - -u64 midr_el1; -u64 revidr_el1; -u64 aidr_el1; -u64 ctr_el0; +struct kvm_vm_id_regs id_regs;/* Masks for VNCR-backed and general EL2 sysregs */ struct kvm_sysreg_masks *sysreg_masks;
@@ -1637,24 +1641,24 @@ void kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu);bool kvm_arm_vcpu_stopped (struct kvm_vcpu *vcpu);bool kvm_pkvm_vcpu_is_powered_off (struct kvm_vcpu *vcpu); -static inline u64 *__vm_ftr_reg_by_idx (struct kvm_arch *ka,u32 idx) +static inline u64 *__vm_ftr_reg_by_idx (struct kvm_vm_id_regs *id_regs,u32 idx) { -return &ka->id_regs[idx]; +return &id_regs->ftr_regs[idx]; } -static inline u64 *__vm_id_reg (struct kvm_arch *ka,u32 reg) +static inline u64 *__vm_id_reg (struct kvm_vm_id_regs *id_regs,u32 reg) {switch (reg) { case sys_reg(3, 0, 0, 1, 0) ... sys_reg(3, 0, 0, 7, 7): -return __vm_ftr_reg_by_idx (ka,IDREG_IDX (reg)); +return __vm_ftr_reg_by_idx (id_regs,IDREG_IDX (reg));case SYS_CTR_EL0 : -return &ka->ctr_el0; +return &id_regs->ctr_el0;case SYS_MIDR_EL1 : -return &ka->midr_el1; +return &id_regs->midr_el1;case SYS_REVIDR_EL1 : -return &ka->revidr_el1; +return &id_regs->revidr_el1;case SYS_AIDR_EL1 : -return &ka->aidr_el1; +return &id_regs->aidr_el1;default :WARN_ON_ONCE (1 );return NULL ;
@@ -1663,13 +1667,13 @@ static inline u64 *__vm_id_reg(struct kvm_arch *ka, u32 reg)#define kvm_get_vm_ftr_reg_by_idx (kvm, idx) \ ({ \ - u64 *__valp = __vm_ftr_reg_by_idx(&(kvm)->arch, idx); \ + u64 *__valp = __vm_ftr_reg_by_idx(&(kvm)->arch.id_regs, idx); \ __valp; \ })#define kvm_get_vm_id_reg (kvm, reg) \ ({ \ - u64 *__valp = __vm_id_reg(&(kvm)->arch, reg); \ + u64 *__valp = __vm_id_reg(&(kvm)->arch.id_regs, reg); \ __valp; \ })
arch/arm64/kvm/hyp/nvhe/pkvm.c +2 -1
@@ -591,7 +591,8 @@ static int vm_copy_id_regs(struct pkvm_hyp_vcpu *hyp_vcpu)if (test_and_set_bit (KVM_ARCH_FLAG_ID_REGS_INITIALIZED , &kvm->arch.flags))return 0 ; -memcpy (kvm->arch.id_regs, host_kvm->arch.id_regs,sizeof (kvm->arch.id_regs)); +memcpy (kvm->arch.id_regs.ftr_regs, host_kvm->arch.id_regs.ftr_regs, +sizeof (kvm->arch.id_regs.ftr_regs));return 0 ; }
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 3/25 KVM: arm64: Extract number of sys_reg_desc into a constant
In reply to Steffen EidenDefine the constant num_sys_reg_descs which stores the number of elements in the sys_reg_descs array. Replace all occurrences of ARRAY_SIZE(sys_reg_descs) with the new constant.
This refactoring eases the integration of handling system registers for arm on s390. s390 needs code from the shared code to define the sys_reg_descs. But also the shared code needs the definition of the sys_reg_array and we cannot forward declare arrays and use their size before it is properly defined. This patch solves this chicken or egg problem. For the time being s390 cannot process the full arm64 defined sys_reg_descs array.
--- arch/arm64/kvm/sys_regs.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
arch/arm64/kvm/sys_regs.c +14 -12
@@ -3992,6 +3992,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { EL2_REG(SP_EL2, NULL, reset_unknown, 0), }; +static const size_t num_sys_reg_descs =ARRAY_SIZE (sys_reg_descs); +static bool handle_at_s1e01 (struct kvm_vcpu *vcpu,struct sys_reg_params *p,const struct sys_reg_desc *r) {
@@ -5217,7 +5219,7 @@ static bool emulate_sys_reg(struct kvm_vcpu *vcpu, {const struct sys_reg_desc *r; - r =find_reg (params, sys_reg_descs,ARRAY_SIZE (sys_reg_descs)); + r =find_reg (params, sys_reg_descs, num_sys_reg_descs);if (likely (r)) {perform_access (vcpu, params, r);return true;
@@ -5235,7 +5237,7 @@ static const struct sys_reg_desc *idregs_debug_find(struct kvm *kvm, loff_t pos) {unsigned long i, idreg_idx =0 ; -for (i =0 ; i <ARRAY_SIZE (sys_reg_descs); i++) { +for (i =0 ; i < num_sys_reg_descs; i++) {const struct sys_reg_desc *r = &sys_reg_descs[i];if (!is_vm_ftr_id_reg (reg_to_encoding (r)))
@@ -5298,7 +5300,7 @@ static const struct sys_reg_desc *sr_resx_find(struct kvm *kvm, loff_t pos) {unsigned long i, sr_idx =0 ; -for (i =0 ; i <ARRAY_SIZE (sys_reg_descs); i++) { +for (i =0 ; i < num_sys_reg_descs; i++) {const struct sys_reg_desc *r = &sys_reg_descs[i];if (r->reg < __SANITISED_REG_START__)
@@ -5400,7 +5402,7 @@ void kvm_reset_sys_regs(struct kvm_vcpu *vcpu)struct kvm *kvm = vcpu->kvm;unsigned long i; -for (i =0 ; i <ARRAY_SIZE (sys_reg_descs); i++) { +for (i =0 ; i < num_sys_reg_descs; i++) {const struct sys_reg_desc *r = &sys_reg_descs[i];if (!r->reset)
@@ -5624,8 +5626,8 @@ int kvm_arm_sys_reg_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *regif ((reg->id &KVM_REG_ARM_COPROC_MASK ) ==KVM_REG_ARM_DEMUX )return demux_c15_get (vcpu, reg->id, uaddr); -return kvm_sys_reg_get_user (vcpu, reg, - sys_reg_descs,ARRAY_SIZE (sys_reg_descs)); +return kvm_sys_reg_get_user (vcpu, reg, sys_reg_descs, + num_sys_reg_descs); } int kvm_sys_reg_set_user(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg,
@@ -5664,8 +5666,8 @@ int kvm_arm_sys_reg_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *regif ((reg->id &KVM_REG_ARM_COPROC_MASK ) ==KVM_REG_ARM_DEMUX )return demux_c15_set (vcpu, reg->id, uaddr); -return kvm_sys_reg_set_user (vcpu, reg, - sys_reg_descs,ARRAY_SIZE (sys_reg_descs)); +return kvm_sys_reg_set_user (vcpu, reg, sys_reg_descs, + num_sys_reg_descs); }static unsigned int num_demux_regs (void )
@@ -5753,7 +5755,7 @@ static int walk_sys_regs(struct kvm_vcpu *vcpu, u64 __user *uind)int err; i2 = sys_reg_descs; - end2 = sys_reg_descs +ARRAY_SIZE (sys_reg_descs); + end2 = sys_reg_descs + num_sys_reg_descs;while (i2 != end2) { err =walk_one_sys_reg (vcpu, i2++, &uind, &total);
@@ -5802,7 +5804,7 @@ int kvm_vm_ioctl_get_reg_writable_masks(struct kvm *kvm, struct reg_mask_range *if (clear_user (masks,KVM_ARM_FEATURE_ID_RANGE_SIZE *sizeof (__u64)))return -EFAULT ; -for (int i =0 ; i <ARRAY_SIZE (sys_reg_descs); i++) { +for (int i =0 ; i < num_sys_reg_descs; i++) {const struct sys_reg_desc *reg = &sys_reg_descs[i];u32 encoding =reg_to_encoding (reg);u64 val;
@@ -6004,7 +6006,7 @@ int __init kvm_sys_reg_table_init(void)int ret =0 ;/* Make sure tables are unique and in order. */ - valid &=check_sysreg_table (sys_reg_descs,ARRAY_SIZE (sys_reg_descs), true); + valid &=check_sysreg_table (sys_reg_descs, num_sys_reg_descs, true); valid &=check_sysreg_table (cp14_regs,ARRAY_SIZE (cp14_regs), false); valid &=check_sysreg_table (cp14_64_regs,ARRAY_SIZE (cp14_64_regs), false); valid &=check_sysreg_table (cp15_regs,ARRAY_SIZE (cp15_regs), false);
@@ -6027,7 +6029,7 @@ int __init kvm_sys_reg_table_init(void)check_feature_map (); -for (i =0 ; !ret && i <ARRAY_SIZE (sys_reg_descs); i++) +for (i =0 ; !ret && i < num_sys_reg_descs; i++) ret =populate_sysreg_config (sys_reg_descs + i, i,needs_nv_trap (sys_reg_descs + i));
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 4/25 arm64: sysreg: Convert OSLSR to automatic register generation
In reply to Steffen EidenConvert OSLSR to automatic register generation as per DDI0601. As OSLSR_OLSM is a composite field using bit 0 and bit 3 the combined values are still defined manually. While at it rename OSLSR_EL1_OSLM_IMPLEMENTED to OSLSR_EL1_OSLM_IMP to be consistent with the rest of the system register values.
No functional change.
--- arch/arm64/include/asm/sysreg.h | 12 +++++++----- arch/arm64/kvm/sys_regs.c | 2 +- arch/arm64/tools/sysreg | 14 ++++++++++++++ tools/arch/arm64/include/asm/sysreg.h | 12 +++++++----- 4 files changed, 29 insertions(+), 11 deletions(-)
arch/arm64/include/asm/sysreg.h +7 -5
@@ -186,11 +186,13 @@#define SYS_DBGWCRn_EL1 (n) sys_reg(2, 0, 0, n, 7)#define SYS_MDRAR_EL1 sys_reg(2, 0, 1, 0, 0) -#define SYS_OSLSR_EL1 sys_reg(2, 0, 1, 1, 4) -#define OSLSR_EL1_OSLM_MASK (BIT(3) | BIT(0)) -#define OSLSR_EL1_OSLM_NI 0 -#define OSLSR_EL1_OSLM_IMPLEMENTED BIT(3) -#define OSLSR_EL1_OSLK BIT(1) +#define OSLSR_EL1_OSLM_MASK (OSLSR_EL1_OSLM0_MASK | OSLSR_EL1_OSLM1_MASK) +#define OSLSR_EL1_OSLM_NI \ + ((OSLSR_EL1_OSLM1_NI << OSLSR_EL1_OSLM1_SHIFT) | \ + (OSLSR_EL1_OSLM0_VAL_0 << OSLSR_EL1_OSLM0_SHIFT)) +#define OSLSR_EL1_OSLM_IMP \ + ((OSLSR_EL1_OSLM1_IMP << OSLSR_EL1_OSLM1_SHIFT) | \ + (OSLSR_EL1_OSLM0_VAL_0 << OSLSR_EL1_OSLM0_SHIFT))#define SYS_OSDLR_EL1 sys_reg(2, 0, 1, 3, 4)#define SYS_DBGPRCR_EL1 sys_reg(2, 0, 1, 4, 4)
arch/arm64/kvm/sys_regs.c +1 -1
@@ -3324,7 +3324,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_MDRAR_EL1), trap_raz_wi }, { SYS_DESC(SYS_OSLAR_EL1), trap_oslar_el1 }, { SYS_DESC(SYS_OSLSR_EL1), trap_oslsr_el1, reset_val, OSLSR_EL1, - OSLSR_EL1_OSLM_IMPLEMENTED, .set_user = set_oslsr_el1, }, + OSLSR_EL1_OSLM_IMP, .set_user = set_oslsr_el1, }, { SYS_DESC(SYS_OSDLR_EL1), trap_raz_wi }, { SYS_DESC(SYS_DBGPRCR_EL1), trap_raz_wi }, { SYS_DESC(SYS_DBGCLAIMSET_EL1), trap_raz_wi },
arch/arm64/tools/sysreg +14 -0
@@ -122,6 +122,20 @@ Res0 63:1 Field 0 OSLK EndSysreg +Sysreg OSLSR_EL1 2 0 1 1 4 +Res0 63:4 +UnsignedEnum 3 OSLM1 + 0b0 NI + 0b1 IMP +EndEnum +UnsignedEnum 2 nTT +EndEnum +Field 1 OSLK +UnsignedEnum 0 OSLM0 + 0b0 VAL_0 +EndEnum +EndSysreg + Sysreg SPMACCESSR_EL1 2 0 9 13 3 UnsignedEnum 63:62 P31 0b00 TRAP_RW
tools/arch/arm64/include/asm/sysreg.h +7 -5
@@ -183,11 +183,13 @@#define SYS_DBGWCRn_EL1 (n) sys_reg(2, 0, 0, n, 7)#define SYS_MDRAR_EL1 sys_reg(2, 0, 1, 0, 0) -#define SYS_OSLSR_EL1 sys_reg(2, 0, 1, 1, 4) -#define OSLSR_EL1_OSLM_MASK (BIT(3) | BIT(0)) -#define OSLSR_EL1_OSLM_NI 0 -#define OSLSR_EL1_OSLM_IMPLEMENTED BIT(3) -#define OSLSR_EL1_OSLK BIT(1) +#define OSLSR_EL1_OSLM_MASK (OSLSR_EL1_OSLM0_MASK | OSLSR_EL1_OSLM1_MASK) +#define OSLSR_EL1_OSLM_NI \ + ((OSLSR_EL1_OSLM1_NI << OSLSR_EL1_OSLM1_SHIFT) | \ + (OSLSR_EL1_OSLM0_VAL_0 << OSLSR_EL1_OSLM0_SHIFT)) +#define OSLSR_EL1_OSLM_IMP \ + ((OSLSR_EL1_OSLM1_IMP << OSLSR_EL1_OSLM1_SHIFT) | \ + (OSLSR_EL1_OSLM0_VAL_0 << OSLSR_EL1_OSLM0_SHIFT))#define SYS_OSDLR_EL1 sys_reg(2, 0, 1, 3, 4)#define SYS_DBGPRCR_EL1 sys_reg(2, 0, 1, 4, 4)
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 5/25 arm64: vdso: Define ARM64_S390_COMMON=1 for all vdso builds
In reply to Steffen EidenThe compat vDSO builds with LINUXINCLUDE but without KBUILD_CPPFLAGS, where -DARM64_S390_COMMON is defined. Future marker in e,g, asm/cache.h will hide definitions or break the build at the prepare stage if Werror & Wundef is defined. Define the marker for the 32-bit vDSO build as well.
--- arch/arm64/kernel/vdso32/Makefile | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/kernel/vdso32/Makefile +2 -0
@@ -33,6 +33,8 @@ cc32-option = $(call try-run,\ VDSO_CPPFLAGS := -DBUILD_VDSO -D__KERNEL__ -nostdinc VDSO_CPPFLAGS += -isystem $(shell $(CC_COMPAT) -print-file-name=include 2>/dev/null) VDSO_CPPFLAGS += $(LINUXINCLUDE) +# arch/arm64/Makefile puts this in KBUILD_CPPFLAGS, which is not used here +VDSO_CPPFLAGS += -DARM64_S390_COMMON=1 # Common C and assembly flags # From top-level Makefile
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 6/25 arm64: Prepare headers for sysreg sharing with s390
In reply to Steffen EidenMove the get-spectre-state functions to a convenient location. Guard GICv5 headers away from s390 for arm_arch_timer.h.
--- arch/arm64/include/asm/spectre.h | 10 +++++----- include/kvm/arm_arch_timer.h | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-)
arch/arm64/include/asm/spectre.h +5 -5
@@ -26,6 +26,11 @@ enum mitigation_state { SPECTRE_VULNERABLE, }; +enum mitigation_state arm64_get_spectre_v2_state (void ); +enum mitigation_state arm64_get_spectre_v4_state (void ); +enum mitigation_state arm64_get_meltdown_state (void ); +enum mitigation_state arm64_get_spectre_bhb_state (void ); +struct pt_regs ;struct task_struct ;
@@ -81,21 +86,16 @@ static __always_inline void arm64_apply_bp_hardening(void) d->fn (); } -enum mitigation_state arm64_get_spectre_v2_state (void );bool has_spectre_v2 (const struct arm64_cpu_capabilities *cap,int scope);void spectre_v2_enable_mitigation (const struct arm64_cpu_capabilities *__unused);bool has_spectre_v3a (const struct arm64_cpu_capabilities *cap,int scope);void spectre_v3a_enable_mitigation (const struct arm64_cpu_capabilities *__unused); -enum mitigation_state arm64_get_spectre_v4_state (void );bool has_spectre_v4 (const struct arm64_cpu_capabilities *cap,int scope);void spectre_v4_enable_mitigation (const struct arm64_cpu_capabilities *__unused);void spectre_v4_enable_task_mitigation (struct task_struct *tsk); -enum mitigation_state arm64_get_meltdown_state (void ); - -enum mitigation_state arm64_get_spectre_bhb_state (void );bool is_spectre_bhb_affected (const struct arm64_cpu_capabilities *entry,int scope);extern bool __nospectre_bhb;u8 get_spectre_bhb_loop_value (void );
include/kvm/arm_arch_timer.h +3 -0
@@ -10,7 +10,10 @@#include <linux/clocksource.h> #include <linux/hrtimer.h> +/* no GICv5 for s390 */ +#ifndef __s390__#include <linux/irqchip/arm-gic-v5.h> +#endif /* !__s390__ */ enum kvm_arch_timers {TIMER_PTIMER ,
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 7/25 arm64: Share system register related headers and functions with s390
In reply to Steffen EidenMark more headers as shared or move definitions to an already shared location if the context is similar. The new shared headers cover cover CPU identification, Exception emulation, ID register state, Mitigation state, and the kvm system register management infrastructure. Also add definitions useful for later feature additions to reduce further churn.
With these headers s390 is able to implement system register handling for its arm64 guests.
--- arch/arm64/include/asm/cache.h | 3 +++ arch/arm64/include/asm/cputype.h | 3 +++ arch/arm64/include/asm/kvm_emulate.h | 5 ++++- arch/arm64/include/asm/kvm_host.h | 14 +++++++------- arch/arm64/include/asm/spectre.h | 3 +++ arch/arm64/kvm/sys_regs.h | 1 + 6 files changed, 21 insertions(+), 8 deletions(-)
arch/arm64/include/asm/cache.h +3 -0
@@ -8,6 +8,7 @@#define L1_CACHE_SHIFT (6)#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) +#if ARM64_S390_COMMON ==1 #define CLIDR_LOUU_SHIFT 27#define CLIDR_LOC_SHIFT 24#define CLIDR_LOUIS_SHIFT 21
@@ -25,6 +26,8 @@/* Ttypen, bits [2(n - 1) + 34 : 2(n - 1) + 33], for n = 1 to 7 */ #define CLIDR_TTYPE_SHIFT (level) (2 * ((level) - 1) + CLIDR_EL1_Ttypen_SHIFT) +#endif /* ARM64_S390_COMMON == 1 */ +/* * Memory returned by kmalloc() may be used for DMA, so we must make * sure that all such allocations are cache aligned. Otherwise,
arch/arm64/include/asm/cputype.h +3 -0
@@ -5,6 +5,7 @@#ifndef __ASM_CPUTYPE_H#define __ASM_CPUTYPE_H +#if ARM64_S390_COMMON ==1 #define INVALID_HWID ULONG_MAX#define MPIDR_UP_BITMASK (0x1 << 30)
@@ -289,6 +290,8 @@#define MIDR_FUJITSU_ERRATUM_010001_MASK (~MIDR_CPU_VAR_REV(1, 0))#define TCR_CLEAR_FUJITSU_ERRATUM_010001 (TCR_EL1_NFD1 | TCR_EL1_NFD0) +#endif /* ARM64_S390_COMMON == 1 */ +#ifndef __ASSEMBLER__#include <asm/sysreg.h>
arch/arm64/include/asm/kvm_emulate.h +4 -1
@@ -23,6 +23,7 @@#include <asm/cputype.h> #include <asm/virt.h> +#if ARM64_S390_COMMON ==1 #define CURRENT_EL_SP_EL0_VECTOR 0x0#define CURRENT_EL_SP_ELx_VECTOR 0x200#define LOWER_EL_AArch64_VECTOR 0x400
@@ -35,6 +36,8 @@ enum exception_type { except_type_serror = 0x180, }; +#endif /* ARM64_S390_COMMON == 1 */ +#define kvm_exception_type_names \ { except_type_sync, "SYNC" }, \ { except_type_irq, "IRQ" }, \
@@ -507,13 +510,13 @@ static __always_inline bool kvm_vcpu_abt_issea(const struct kvm_vcpu *vcpu)return esr_abt_is_sea (kvm_vcpu_get_esr (vcpu)); } +#if ARM64_S390_COMMON ==1 static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu) {u64 esr =kvm_vcpu_get_esr (vcpu);return ESR_ELx_SYS64_ISS_RT (esr); } -#if ARM64_S390_COMMON ==1 static inline bool esr_abt_is_write_fault (unsigned long esr) {if (esr_abt_is_s1ptw (esr)) {
arch/arm64/include/asm/kvm_host.h +7 -7
@@ -1335,9 +1335,6 @@ u64 kvm_vcpu_apply_reg_masks(const struct kvm_vcpu *, enum vcpu_sysreg, u64); __v; \ }) -u64 vcpu_read_sys_reg (const struct kvm_vcpu *,enum vcpu_sysreg ); -void vcpu_write_sys_reg (struct kvm_vcpu *,u64 ,enum vcpu_sysreg ); -struct kvm_vm_stat {struct kvm_vm_stat_generic generic; };
@@ -1374,11 +1371,9 @@ int kvm_handle_cp14_32(struct kvm_vcpu *vcpu);int kvm_handle_cp14_64 (struct kvm_vcpu *vcpu);int kvm_handle_cp15_32 (struct kvm_vcpu *vcpu);int kvm_handle_cp15_64 (struct kvm_vcpu *vcpu); -int kvm_handle_sys_reg (struct kvm_vcpu *vcpu);int kvm_handle_cp10_id (struct kvm_vcpu *vcpu);void kvm_sys_regs_create_debugfs (struct kvm *kvm); -void kvm_reset_sys_regs (struct kvm_vcpu *vcpu);int __init kvm_sys_reg_table_init (void );struct sys_reg_desc ;
@@ -1389,6 +1384,11 @@ int __init populate_nv_trap_config(void);void kvm_calculate_traps (struct kvm_vcpu *vcpu);#if ARM64_S390_COMMON ==1 +u64 vcpu_read_sys_reg (const struct kvm_vcpu *,enum vcpu_sysreg ); +void vcpu_write_sys_reg (struct kvm_vcpu *,u64 ,enum vcpu_sysreg ); +int kvm_handle_sys_reg (struct kvm_vcpu *vcpu); +void kvm_reset_sys_regs (struct kvm_vcpu *vcpu); +unsigned long kvm_arm_num_regs (struct kvm_vcpu *vcpu);int kvm_arm_copy_reg_indices (struct kvm_vcpu *vcpu,u64 __user *indices);int kvm_arm_get_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg);
@@ -1626,8 +1626,6 @@ static inline bool __vcpu_has_feature(const struct kvm_arch *ka, int feature)#define kvm_vcpu_initialized (v) vcpu_get_flag(v, VCPU_INITIALIZED) -#endif /* ARM64_S390_COMMON == 1 */ -int kvm_trng_call (struct kvm_vcpu *vcpu);#ifdef CONFIG_KVM extern phys_addr_t hyp_mem_base;
@@ -1749,6 +1747,8 @@ void kvm_set_vm_id_reg(struct kvm *kvm, u32 reg, u64 val); (kvm_cmp_feat(kvm, id, fld, >=, min) && \ kvm_cmp_feat(kvm, id, fld, <=, max)) +#endif /* ARM64_S390_COMMON == 1 */ +/* Check for a given level of PAuth support */ #define kvm_has_pauth (k, l) \ ({ \
arch/arm64/include/asm/spectre.h +3 -0
@@ -19,6 +19,7 @@#include <asm/cpufeature.h> #include <asm/virt.h> +#if ARM64_S390_COMMON ==1 /* Watch out, ordering is important here. */ enum mitigation_state { SPECTRE_UNAFFECTED,
@@ -31,6 +32,8 @@ enum mitigation_state arm64_get_spectre_v4_state(void);enum mitigation_state arm64_get_meltdown_state (void );enum mitigation_state arm64_get_spectre_bhb_state (void ); +#endif /* ARM64_S390_COMMON == 1 */ +struct pt_regs ;struct task_struct ;
arch/arm64/kvm/sys_regs.h +1 -0
@@ -7,6 +7,7 @@* Copyright (C) 2012 - Virtual Open Systems and Columbia University * Authors: Christoffer Dall <[email protected]> */ +/* Whole file is shared with s390 */ #ifndef __ARM64_KVM_SYS_REGS_LOCAL_H__#define __ARM64_KVM_SYS_REGS_LOCAL_H__
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 8/25 KVM: s390: arm64: Prepare for sharing arm64 SVE and ftr-reg code
In reply to Steffen EidenAdd required SVE and feature-register definitions to the arm64 on s390 host code. The definitions are required to be able to build shared SVE related code.
--- arch/s390/kvm/arm64/arm.c | 2 ++ arch/s390/kvm/arm64/guest.c | 6 ++++++ 2 files changed, 8 insertions(+)
arch/s390/kvm/arm64/arm.c +2 -0
@@ -8,6 +8,7 @@#include <linux/kvm_host.h> #include <linux/cleanup.h> #include <linux/fpu.h> +#include <linux/bitfield.h> #include <asm/access-regs.h>
@@ -24,6 +25,7 @@#include "trace.h" static unsigned long system_supported_vcpu_features (struct kvm_vcpu *vcpu); +#define read_sanitised_ftr_reg (_id) 0#define __INCL_GEN_ARM_FILE#include "generated/arm.inc"
arch/s390/kvm/arm64/guest.c +6 -0
@@ -5,6 +5,12 @@#include <arm64/kvm_emulate.h> #include <arm64/kvm_nested.h> +#define SVE_VQ_MIN __SVE_VQ_MIN +#define SVE_NUM_ZREGS KVM_ARM64_SVE_NUM_ZREGS +#define SVE_NUM_PREGS KVM_ARM64_SVE_NUM_PREGS + +#define vcpu_sve_slices (_vcpu) 1 +#define __INCL_GEN_ARM_FILE#include "generated/guest.inc" #undef __INCL_GEN_ARM_FILE
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 9/25 KVM: arm64: Prepare sys_regs.c for sharing with s390
In reply to Steffen EidenPrepare sharing of sys_regs.c with s390 by moving reset_{vm,vcpu}_ftr_id_regs just before the UAPI definitions. Also, move kvm_handle_cp14_load_store to other cp functions. This small refactoring allows to have less shared sections.
--- arch/arm64/kvm/sys_regs.c | 52 +++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 24 deletions(-)
arch/arm64/kvm/sys_regs.c +28 -24
@@ -4885,12 +4885,6 @@ static bool check_sysreg_table(const struct sys_reg_desc *table, unsigned int n,return true; } -int kvm_handle_cp14_load_store (struct kvm_vcpu *vcpu) -{ -kvm_inject_undefined (vcpu); -return 1 ; -} -static void perform_access (struct kvm_vcpu *vcpu,struct sys_reg_params *params,const struct sys_reg_desc *r)
@@ -4918,6 +4912,12 @@ static void perform_access(struct kvm_vcpu *vcpu,kvm_incr_pc (vcpu); } +int kvm_handle_cp14_load_store (struct kvm_vcpu *vcpu) +{ +kvm_inject_undefined (vcpu); +return 1 ; +} +/* * emulate_cp -- tries to match a sys_reg access in a handling table, and * call the corresponding trap handler.
@@ -5370,25 +5370,9 @@ void kvm_sys_regs_create_debugfs(struct kvm *kvm) &sr_resx_fops); } -static void reset_vm_ftr_id_reg (struct kvm_vcpu *vcpu,const struct sys_reg_desc *reg) -{ -u32 id =reg_to_encoding (reg); -struct kvm *kvm = vcpu->kvm; - -if (test_bit (KVM_ARCH_FLAG_ID_REGS_INITIALIZED , &kvm->arch.flags)) -return ; - -kvm_set_vm_id_reg (kvm, id, reg->reset (vcpu, reg)); -} - +static void reset_vm_ftr_id_reg (struct kvm_vcpu *vcpu,const struct sys_reg_desc *reg);static void reset_vcpu_ftr_id_reg (struct kvm_vcpu *vcpu, -const struct sys_reg_desc *reg) -{ -if (kvm_vcpu_initialized (vcpu)) -return ; - - reg->reset (vcpu, reg); -} +const struct sys_reg_desc *reg);/** * kvm_reset_sys_regs - sets system registers to reset value
@@ -5462,6 +5446,26 @@ int kvm_handle_sys_reg(struct kvm_vcpu *vcpu)return 1 ; } +static void reset_vm_ftr_id_reg (struct kvm_vcpu *vcpu,const struct sys_reg_desc *reg) +{ +u32 id =reg_to_encoding (reg); +struct kvm *kvm = vcpu->kvm; + +if (test_bit (KVM_ARCH_FLAG_ID_REGS_INITIALIZED , &kvm->arch.flags)) +return ; + +kvm_set_vm_id_reg (kvm, id, reg->reset (vcpu, reg)); +} + +static void reset_vcpu_ftr_id_reg (struct kvm_vcpu *vcpu, +const struct sys_reg_desc *reg) +{ +if (kvm_vcpu_initialized (vcpu)) +return ; + + reg->reset (vcpu, reg); +} +/****************************************************************************** * Userspace API *****************************************************************************/
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 10/25 KVM: arm64: Share system register code with s390
In reply to Steffen EidenMark functions that s390 can use to implement system registers for arm on s390 guests as shared functions. The new shared functionality covers system register infrastructure for KVM, Pointer auth checks and shareable parts of the SVE register API. In order to reduce the number of shared sections more code than s390 requires is shared. This is no problem as for the shared code unused function checking is disabled.
--- arch/arm64/kvm/arm.c | 3 +++ arch/arm64/kvm/guest.c | 11 +++++++---- arch/arm64/kvm/sys_regs.c | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-)
arch/arm64/kvm/arm.c +3 -0
@@ -361,6 +361,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)kvm_arm_teardown_hypercalls (kvm); } +#if ARM64_S390_COMMON ==1 static bool kvm_has_full_ptr_auth (void ) {bool apa, gpa, api, gpi, apa3, gpa3;
@@ -395,6 +396,8 @@ static bool kvm_has_full_ptr_auth(void) (apa + api + apa3) == 1); } +#endif /* ARM64_S390_COMMON == 1 */ +int kvm_vm_ioctl_check_extension (struct kvm *kvm,long ext) {int r;
arch/arm64/kvm/guest.c +7 -4
@@ -307,12 +307,12 @@ static int set_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) return err; } -#endif /* ARM64_S390_COMMON == 1 */ -#define vq_word (vq) (((vq) - SVE_VQ_MIN) / 64)#define vq_mask (vq) ((u64)1 << ((vq) - SVE_VQ_MIN) % 64)#define vq_present (vqs, vq) (!!((vqs)[vq_word(vq)] & vq_mask(vq))) +#endif /* ARM64_S390_COMMON == 1 */ +static int get_sve_vls (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg) {unsigned int max_vq, vq;
@@ -383,6 +383,7 @@ static int set_sve_vls(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)return 0 ; } +#if ARM64_S390_COMMON ==1 #define SVE_REG_SLICE_SHIFT 0#define SVE_REG_SLICE_BITS 5#define SVE_REG_ID_SHIFT (SVE_REG_SLICE_SHIFT + SVE_REG_SLICE_BITS)
@@ -399,6 +400,8 @@ static int set_sve_vls(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)#define KVM_SVE_ZREG_SIZE KVM_REG_SIZE(KVM_REG_ARM64_SVE_ZREG(0, 0))#define KVM_SVE_PREG_SIZE KVM_REG_SIZE(KVM_REG_ARM64_SVE_PREG(0, 0)) +#endif /* ARM64_S390_COMMON == 1 */ +/* * Number of register slices required to cover each whole SVE register. * NOTE: Only the first slice every exists, for now.
@@ -595,8 +598,6 @@ static unsigned long num_core_regs(const struct kvm_vcpu *vcpu)return copy_core_reg_indices (vcpu,NULL ); } -#endif /* ARM64_S390_COMMON == 1 */ -static unsigned long num_sve_regs (const struct kvm_vcpu *vcpu) {const unsigned int slices =vcpu_sve_slices (vcpu);
@@ -658,6 +659,8 @@ static int copy_sve_reg_indices(const struct kvm_vcpu *vcpu, return num_regs; } +#endif /* ARM64_S390_COMMON == 1 */ +/** * kvm_arm_num_regs - how many registers do we present via KVM_GET_ONE_REG * @vcpu: the vCPU pointer
arch/arm64/kvm/sys_regs.c +27 -0
@@ -45,6 +45,7 @@* 64bit interface. */ +#if ARM64_S390_COMMON ==1 static u64 sys_reg_to_index (const struct sys_reg_desc *reg);static int set_id_reg (struct kvm_vcpu *vcpu,const struct sys_reg_desc *rd,u64 val);
@@ -82,6 +83,8 @@ static bool write_to_read_only(struct kvm_vcpu *vcpu, "sys_reg write to read-only register"); } +#endif /* ARM64_S390_COMMON == 1 */ +enum sr_loc_attr {SR_LOC_MEMORY =0 ,/* Register definitely in memory */ SR_LOC_LOADED =BIT (0 ),/* Register on CPU, unless it cannot */
@@ -428,6 +431,7 @@ void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, enum vcpu_sysreg reg)__vcpu_assign_sys_reg (vcpu, reg, val); } +#if ARM64_S390_COMMON ==1 /* CSSELR values; used to index KVM_REG_ARM_DEMUX_ID_CCSIDR */ #define CSSELR_MAX 14
@@ -533,6 +537,8 @@ static bool access_rw(struct kvm_vcpu *vcpu, return true; } +#endif /* ARM64_S390_COMMON == 1 */ +/* * See note at ARMv7 ARM B1.14.4 (TL;DR: S/W ops are not easily virtualized). */
@@ -800,6 +806,7 @@ static bool access_gicv5_ppi_enabler(struct kvm_vcpu *vcpu,return true; } +#if ARM64_S390_COMMON ==1 static bool trap_raz_wi (struct kvm_vcpu *vcpu,struct sys_reg_params *p,const struct sys_reg_desc *r)
@@ -853,6 +860,8 @@ static bool trap_oslsr_el1(struct kvm_vcpu *vcpu, return true; } +#endif /* ARM64_S390_COMMON == 1 */ +static int set_oslsr_el1 (struct kvm_vcpu *vcpu,const struct sys_reg_desc *rd,u64 val) {
@@ -1012,6 +1021,7 @@ static u64 reset_actlr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)return actlr; } +#if ARM64_S390_COMMON ==1 static u64 reset_mpidr (struct kvm_vcpu *vcpu,const struct sys_reg_desc *r) {u64 mpidr =kvm_calculate_mpidr (vcpu);
@@ -1020,6 +1030,8 @@ static u64 reset_mpidr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) return mpidr; } +#endif /* ARM64_S390_COMMON == 1 */ +static unsigned int hidden_visibility (const struct kvm_vcpu *vcpu,const struct sys_reg_desc *r) {
@@ -1589,6 +1601,7 @@ static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r,#define AMU_AMEVCNTR1_EL0 (n) { SYS_DESC(SYS_AMEVCNTR1_EL0(n)), undef_access }#define AMU_AMEVTYPER1_EL0 (n) { SYS_DESC(SYS_AMEVTYPER1_EL0(n)), undef_access } +#if ARM64_S390_COMMON ==1 static unsigned int ptrauth_visibility (const struct kvm_vcpu *vcpu,const struct sys_reg_desc *rd) {
@@ -1609,6 +1622,8 @@ static unsigned int ptrauth_visibility(const struct kvm_vcpu *vcpu, __PTRAUTH_KEY(k ## KEYLO_EL1), \ __PTRAUTH_KEY(k ## KEYHI_EL1) +#endif /* ARM64_S390_COMMON == 1 */ +static bool access_arch_timer (struct kvm_vcpu *vcpu,struct sys_reg_params *p,const struct sys_reg_desc *r)
@@ -1906,6 +1921,7 @@ static int arm64_check_features(struct kvm_vcpu *vcpu,return 0 ; } +#if ARM64_S390_COMMON ==1 static u8 pmuver_to_perfmon (u8 pmuver) {switch (pmuver) {
@@ -2838,6 +2854,8 @@ static bool bad_redir_trap(struct kvm_vcpu *vcpu, .val = 0, \ } +#endif /* ARM64_S390_COMMON == 1 */ +static bool access_sp_el1 (struct kvm_vcpu *vcpu,struct sys_reg_params *p,const struct sys_reg_desc *r)
@@ -3219,6 +3237,7 @@ static void init_imp_id_regs(void) boot_cpu_aidr_val =read_sysreg (aidr_el1); } +#if ARM64_S390_COMMON ==1 static u64 reset_imp_id_reg (struct kvm_vcpu *vcpu,const struct sys_reg_desc *r) {switch (reg_to_encoding (r)) {
@@ -3276,6 +3295,8 @@ static int set_imp_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, .val = mask, \ } +#endif /* ARM64_S390_COMMON == 1 */ +static u64 reset_mdcr (struct kvm_vcpu *vcpu,const struct sys_reg_desc *r) {__vcpu_assign_sys_reg (vcpu, r->reg, vcpu->kvm->arch.nr_pmu_counters);
@@ -4863,6 +4884,7 @@ static const struct sys_reg_desc cp15_64_regs[] = { { SYS_DESC(SYS_AARCH32_CNTVCTSS), access_arch_timer }, }; +#if ARM64_S390_COMMON == 1 static bool check_sysreg_table(const struct sys_reg_desc *table, unsigned int n, bool reset_check) {
@@ -4912,6 +4934,8 @@ static void perform_access(struct kvm_vcpu *vcpu, kvm_incr_pc(vcpu); } +#endif /* ARM64_S390_COMMON == 1 */ +int kvm_handle_cp14_load_store (struct kvm_vcpu *vcpu) {kvm_inject_undefined (vcpu);
@@ -5446,6 +5470,7 @@ int kvm_handle_sys_reg(struct kvm_vcpu *vcpu)return 1 ; } +#if ARM64_S390_COMMON ==1 static void reset_vm_ftr_id_reg (struct kvm_vcpu *vcpu,const struct sys_reg_desc *reg) {u32 id =reg_to_encoding (reg);
@@ -5787,6 +5812,8 @@ int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) return write_demux_regids(uindices); } +#endif /* ARM64_S390_COMMON == 1 */ +#define KVM_ARM_FEATURE_ID_RANGE_INDEX (r) \ KVM_ARM_FEATURE_ID_RANGE_IDX(sys_reg_Op0(r), \ sys_reg_Op1(r), \
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH v4 10/25] KVM: arm64: Share system register code with s390
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] KVM: arm64: piecemeal sys_regs.c sharing and mixed PAuth/SVE changes --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] KVM: arm64: piecemeal sys_regs.c sharing and mixed PAuth/SVE changes
--
commit 674857ecf2e2398c1a40ecd629858a2ef61bc1be
Author: Steffen Eiden <[email protected]>
KVM: arm64: Share system register code with s390
This commit wraps selected system register helpers, pointer authentication checks, and SVE register definitions in ARM64_S390_COMMON guards so they can be compiled into the s390 KVM implementation for arm64 guests.
Quoted 38 lines
arch/arm64/kvm/arm.c +3
-0@@ -361,6 +361,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)kvm_arm_teardown_hypercalls (kvm); } +#if ARM64_S390_COMMON ==1 static bool kvm_has_full_ptr_auth (void ) {bool apa, gpa, api, gpi, apa3, gpa3;@@ -395,6 +396,8 @@ static bool kvm_has_full_ptr_auth(void) (apa + api + apa3) == 1); } +#endif /* ARM64_S390_COMMON == 1 */ +int kvm_vm_ioctl_check_extension (struct kvm *kvm,long ext) {int r;arch/arm64/kvm/guest.c +2
-2@@ -307,12 +307,12 @@ static int set_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) return err; } -#endif /* ARM64_S390_COMMON == 1 */ -#define vq_word (vq) (((vq) - SVE_VQ_MIN) / 64)#define vq_mask (vq) ((u64)1 << ((vq) - SVE_VQ_MIN) % 64)#define vq_present (vqs, vq) (!!((vqs)[vq_word(vq)] & vq_mask(vq))) +#endif /* ARM64_S390_COMMON == 1 */ +static int get_sve_vls (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg)
[ ... ]
Quoted 4 lines
arch/arm64/kvm/sys_regs.c +0
-0
[ ... ]
Quoted 17 lines
arch/arm64/kvm/sys_regs.c +3
-0@@ -3219,6 +3237,7 @@ static void init_imp_id_regs(void) boot_cpu_aidr_val =read_sysreg (aidr_el1); } +#if ARM64_S390_COMMON ==1 static u64 reset_imp_id_reg (struct kvm_vcpu *vcpu,const struct sys_reg_desc *r) {switch (reg_to_encoding (r)) {@@ -3276,6 +3295,8 @@ static int set_imp_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, .val = mask, \ } +#endif /* ARM64_S390_COMMON == 1 */ +static u64 reset_mdcr (struct kvm_vcpu *vcpu,const struct sys_reg_desc *r) {__vcpu_assign_sys_reg (vcpu, r->reg, vcpu->kvm->arch.nr_pmu_counters);
[ ... ]
Quoted 9 lines
arch/arm64/kvm/sys_regs.c +1
-0@@ -5446,6 +5470,7 @@ int kvm_handle_sys_reg(struct kvm_vcpu *vcpu)return 1 ; } +#if ARM64_S390_COMMON ==1 static void reset_vm_ftr_id_reg (struct kvm_vcpu *vcpu,const struct sys_reg_desc *reg) {u32 id =reg_to_encoding (reg);
arch/arm64/kvm/sys_regs.c int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) · line 5817
Quoted 6 lines
arch/arm64/kvm/sys_regs.c +2
-0@@ -5787,6 +5812,8 @@ int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) return write_demux_regids(uindices); } +#endif /* ARM64_S390_COMMON == 1 */ +#define KVM_ARM_FEATURE_ID_RANGE_INDEX (r) \
[Severity: Medium]
As reported by Marc Zyngier on v2 [1], why does this patch slice arch/arm64/kvm/sys_regs.c into nine scattered ARM64_S390_COMMON blocks instead of sharing the file and sys_reg_descs as a whole through state access indirection?
Leaving sys_reg_descs, kvm_reset_sys_regs(), kvm_handle_sys_reg(), arm64_check_features(), and finalize_sys_regs() outside the shared sections causes commit "KVM: s390: arm64: Implement arm system register managing infrastructure" to duplicate the architectural system register table and core handling logic in arch/s390/kvm/arm64/sys_regs.c.
In addition, bundling kvm_has_full_ptr_auth() in arch/arm64/kvm/arm.c and SVE helpers in arch/arm64/kvm/guest.c into this commit mixes unrelated pointer authentication and SVE changes (including moving ARM64_S390_COMMON markers added earlier in commit "KVM: arm64: Share arm64 code with s390") with system register sharing.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Steffen Eiden
reviewerPATCH v4 11/25 s390: tools: Share arm64/kvm headers
In reply to Steffen EidenIn addition to sharing headers in arch/arm64/include/{asm, uapi/asm} also allow to share headers in arch/arm64/kvm which provide local KVM definitions.
--- arch/s390/tools/Makefile.arm64h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/s390/tools/Makefile.arm64h +5 -2
@@ -7,10 +7,11 @@ arm64api := $(objtree)/arch/$(ARCH)/include/generated/arm64 arm64uapi := $(objtree)/arch/$(ARCH)/include/generated/uapi/arm64 # List of ARM64 headers to share with s390 KVM -# Format: [uapi:]header.h or header-gen.h +# Format: [uapi:|kvm:]header.h or header-gen.h # # * header.h - from arch/arm64/include/asm/ to arm64/ # * uapi:header.h - from arch/arm64/include/uapi/asm/ to uapi/arm64/ +# * kvm:header.h - from arch/arm64/kvm/ to arm64/ # * header-gen.h - generated as header-gen.h from ARM64 header header.h # If a header contains partial markers (#if ARM64_S390_COMMON == 1) only this part will be copied. # If the file does not contain any markers the whole file will be copied.
@@ -36,7 +37,9 @@ arm64-type = $(firstword $(subst :, ,$(1))) arm64-base = $(or $(word 2,$(subst :, ,$(1))),$(1)) arm64-src-base = $(patsubst %-gen.h,%.h,$(call arm64-base,$(1))) -arm64-src = $(srctree)/arch/arm64/include/$(if $(filter uapi,$(call arm64-type,$(1))),uapi/)asm/$(call arm64-src-base,$(1)) +arm64-src = $(if $(filter kvm,$(call arm64-type,$(1))),\ + $(srctree)/arch/arm64/kvm/$(call arm64-src-base,$(1)),\ + $(srctree)/arch/arm64/include/$(if $(filter uapi,$(call arm64-type,$(1))),uapi/)asm/$(call arm64-src-base,$(1))) arm64-dst = $(if $(filter uapi,$(call arm64-type,$(1))),$(arm64uapi),$(arm64api))/$(call arm64-base,$(1)) $(foreach hdr,$(ARM64_SHARED_HEADERS),\
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 12/25 s390: Add range check asm macro
In reply to Steffen EidenFrom: Jens Remus <[email protected]>
The range check macro turns cryptic assembler errors into an easy to understand error if e.g. someone mistypes an input value in an asm macro.
Add an asm macro that verifies that a given input value is in a specific range. Add macros which check for ranges often used when creating instructions. While at it, add a range check for the register numbers in the GR_NUM and VX_NUM macro.
--- arch/s390/include/asm/insn-common-asm.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
arch/s390/include/asm/insn-common-asm.h +28 -0
@@ -9,6 +9,32 @@#ifdef __ASSEMBLER__ +.macro RANGECHECK min max val + .if (\val < \min) || (\val > \max) + .error "operand out of range (\val is not between \min and \max)" + .endif +.endm + +.macro ASSERT_U16 val + RANGECHECK 0, 65535, \val +.endm + +.macro ASSERT_S16 val + RANGECHECK -32768, 32767, \val +.endm + +.macro ASSERT_U8 val + RANGECHECK 0, 255, \val +.endm + +.macro ASSERT_U4 val + RANGECHECK 0, 15, \val +.endm + +.macro ASSERT_U5 val + RANGECHECK 0, 31, \val +.endm +/* * GR_NUM - Retrieve general-purpose register number *
@@ -24,6 +50,7 @@ .endr .if \opd == 255 \opd = \gr + ASSERT_U4 \opd .endif .endm
@@ -46,6 +73,7 @@ .endr .if \opd == 255 \opd = \vxr + ASSERT_U5 \opd .endif .endm
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 13/25 s390: Read/write ARM system registers
In reply to Steffen EidenIntroduce Extract Arm System Register and Set Arm System Register to enable s390 hosts to read and write system registers for arm64 guests. The new instructions use the new RIE_H instruction format. Add assembler macros to create instructions in RIE_H format manually. Add Support for disassembling the new instructions.
--- arch/s390/include/asm/sae-asm.h | 45 +++++++++++++++++++++++++++ arch/s390/include/asm/sae.h | 67 +++++++++++++++++++++++++++++++++++++++++ arch/s390/kernel/dis.c | 1 + arch/s390/tools/opcodes.txt | 2 ++ 4 files changed, 115 insertions(+)
arch/s390/include/asm/sae-asm.h new file +45 -0
@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_S390_SAE_ASM_H +#define __ASM_S390_SAE_ASM_H + +#ifndef __ASM_S390_SAE_H +#error only <asm/sae.h> can be included directly +#endif + +#include <asm/insn-common-asm.h> + +#ifdef __ASSEMBLER__ + +/* + * INSN_RIE_H - RIE-h instruction format + * + * RIE-h format: <insn> R1, R3, I2, M4 + * +--------+----+----+----+-----------------+----+--------+ + * | OpCode | R1 |////| R3 | I2 | M4 | Opcode | + * +--------+----+----+----+-----------------+----+--------+ + * 0 8 12 16 20 36 40 47 + */ +.macro INSN_RIE_H opc, gr1, gr3, imm2, m4 + GR_NUM r1, \gr1 + GR_NUM r3, \gr3 + ASSERT_U16 \opc + ASSERT_U16 \imm2 + ASSERT_U4 \m4 + .byte (\opc & 0xff00) >> 8 + .byte r1 << 4 + .byte (r3 << 4) | ((\imm2 & 0xf000) >> 12) + .byte ((\imm2 & 0x0ff0) >> 4) + .byte ((\imm2 & 0x000f) << 4) | (\m4 & 0xf) + .byte \opc & 0xff +.endm + +.macro SASR r1, r3, i2, m4 + INSN_RIE_H 0xed99, \r1, \r3, \i2, \m4 +.endm + +.macro EASR r1, r3, i2, m4 + INSN_RIE_H 0xed9b, \r1, \r3, \i2, \m4 +.endm + +#endif /* __ASSEMBLER__ */ +#endif /* __ASM_S390_SAE_ASM_H */
arch/s390/include/asm/sae.h +67 -0
79 lines not on this page · raw message
arch/s390/kernel/dis.c +1 -0
@@ -208,6 +208,7 @@ static const unsigned char formats[][6] = { [INSTR_RIE_RUI0] = { R_8, I16_16, U4_12, 0, 0, 0 }, [INSTR_RIE_RUPI] = { R_8, I8_32, U4_12, J16_16, 0, 0 }, [INSTR_RIE_RUPU] = { R_8, U8_32, U4_12, J16_16, 0, 0 }, + [INSTR_RIE_R0RUU] = { R_8, R_16, U16_20, U4_36, 0, 0 }, [INSTR_RIL_RI] = { R_8, I32_16, 0, 0, 0, 0 }, [INSTR_RIL_RP] = { R_8, J32_16, 0, 0, 0, 0 }, [INSTR_RIL_RU] = { R_8, U32_16, 0, 0, 0, 0 },
arch/s390/tools/opcodes.txt +2 -0
@@ -1255,6 +1255,8 @@ ed64 ley RXY_FRRD ed65 ldy RXY_FRRD ed66 stey RXY_FRRD ed67 stdy RXY_FRRD +ed99 sasr RIE_R0RUU +ed9b easr RIE_R0RUU eda8 czdt RSL_LRDFU eda9 czxt RSL_LRDFU edaa cdzt RSL_LRDFU
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 14/25 s390: Query arm guest time
In reply to Steffen EidenAdd functions to convert between ARM guest time (LSB0) and s390 host time (MSB0) using new ptff function codes.
--- arch/s390/include/asm/timex.h | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
arch/s390/include/asm/timex.h +53 -0
@@ -81,6 +81,8 @@ extern unsigned char ptff_function_mask[16];#define PTFF_QSI 0x02/* query steering information */ #define PTFF_QPT 0x03/* query physical clock */ #define PTFF_QUI 0x04/* query UTC information */ +#define PTFF_QAGTO 0x10/* query arm guest time offset */ +#define PTFF_QAGPT 0x11/* query arm guest physical time */ #define PTFF_ATO 0x40/* adjust tod offset */ #define PTFF_STO 0x41/* set tod offset */ #define PTFF_SFS 0x42/* set fine steering rate */
@@ -118,6 +120,17 @@ struct ptff_qui {unsigned int pad_0x5c[41 ]; } __packed; +/* +* Query Arm Guest Time +* used for: +* - Query Arm Guest Time Offset +* - Query Arm Guest Physical Time +*/ +struct ptff_qagt { +u64 in; +u64 out; +}; +/* * ptff - Perform timing facility function * @ptff_block: Pointer to ptff parameter block
@@ -266,4 +279,44 @@ static inline int tod_after_eq(unsigned long a, unsigned long b) return a >= b; } +/* +* ptff_qagto() - Query Arm Guest Time Offset +* +* @physical_time: Arm guest physical time +* +* Converts the Arm guest physical time into the Arm guest time offset. +* +* The caller must ensure that this PTFF function is available, +* before calling this function. The condition code is discarded. +* +* Return: Arm guest time offset +*/ +static inline u64 ptff_qagto (u64 physical_time) +{ +struct ptff_qagt qagto = { .in = physical_time }; + +ptff (&qagto,sizeof (qagto),PTFF_QAGTO ); +return qagto.out; +} + +/* +* ptff_qagpt() - Query Arm Guest Physical Time +* +* @guest_time_offset: Arm guest time offset +* +* Converts the Arm guest time offset into the Arm guest physical time. +* +* The caller must ensure that this PTFF function is available, +* before calling this function. The condition code is discarded. +* +* Return: Arm guest physical time +*/ +static inline u64 ptff_qagpt (u64 guest_time_offset) +{ +struct ptff_qagt qagpt = { .in = guest_time_offset }; + +ptff (&qagpt,sizeof (qagpt),PTFF_QAGPT ); +return qagpt.out; +} +#endif
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 15/25 KVM: s390: arm64: Query Available Arm features
In reply to Steffen EidenQAAF enables s390 hosts to gain information about the support and handling of various arm features supported by the machine.
Function code 1 provides general information about available formats, machine defined content of system/id register, and other various information for running arm guests.
Function code 2 provides a initialised save area.
--- arch/s390/include/asm/aef.h | 12 +++ arch/s390/include/asm/kvm_host_arm64_types.h | 115 +++++++++++++++++++++++++++ arch/s390/include/asm/sae.h | 26 ++++++ arch/s390/kernel/Makefile | 2 +- arch/s390/kernel/aef.c | 94 ++++++++++++++++++++++ arch/s390/kvm/arm64/Makefile | 1 + arch/s390/kvm/arm64/arm.c | 6 +- arch/s390/kvm/arm64/qaaf.c | 83 +++++++++++++++++++ arch/s390/kvm/arm64/qaaf.h | 12 +++ arch/s390/tools/opcodes.txt | 1 + 10 files changed, 350 insertions(+), 2 deletions(-)
arch/s390/include/asm/aef.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_S390_AEF_H +#define _ASM_S390_AEF_H + +#include <asm/kvm_host_arm64_types.h> + +const struct kvm_sae_save_area *aef_gisrsa (void ); +const struct qaaf_qmc_block *aef_qmc (void ); +bool aef_usable (void ); + +#endif /* _ASM_S390_AEF_H */
arch/s390/include/asm/kvm_host_arm64_types.h +115 -0
119 lines not on this page · raw message
arch/s390/include/asm/sae.h +26 -0
@@ -12,6 +12,7 @@ asmlinkage void sae(phys_addr_t sae_block_phys);#include <linux/io.h> +#include <asm/extable.h> #include <asm/kvm_host_arm64_types.h> #include <asm/insn-common-asm-emit.h>
@@ -112,5 +113,30 @@ static __always_inline void lasrm(struct kvm_sae_save_area *save_area) ); } +/** +* qaaf() - Query Available Arm Features +* @gr0: QAAF function code +* @qaaf_block: Pointer to the page for the output +* +* Perform QAAF. The result is written to qaaf_block. +*/ +static __always_inline int qaaf(u64 gr0, union qaaf_block *qaaf_block) +{ +int exception =1 ; + + asm_inline volatile( + " lgr 0,%[r0]\n" + "0: .insn rre,0xb9ad0000,%[r1],0\n" + " lhi %[exc],0\n" + "1:\n" + EX_TABLE_INSN(0b, 1b) + : "=m" (*qaaf_block), [exc] "+d" (exception) + : [r1] "a" (qaaf_block), [r0] "d" (gr0) + : "0" + ); + +return exception; +} +#endif /* !__ASSEMBLER__ */ #endif /* __ASM_S390_SAE_H */
arch/s390/kernel/Makefile +1 -1
@@ -46,7 +46,7 @@ obj-y += runtime_instr.o cache.o fpu.o dumpstack.o guarded_storage.o sthyi.o obj-y += entry.o reipl.o kdebugfs.o alternative.o skey.o obj-y += nospec-branch.o ipl_vmparm.o machine_kexec_reloc.o unwind_bc.o obj-y += smp.o text_amode31.o stacktrace.o abs_lowcore.o facility.o uv.o wti.o -obj-y += diag/ +obj-y += diag/ aef.o always-$(KBUILD_BUILTIN) += vmlinux.lds
arch/s390/kernel/aef.c new file +94 -0
94 lines not on this page · raw message
arch/s390/kvm/arm64/Makefile +1 -0
@@ -16,6 +16,7 @@ kvm-arm64-local := \ inject_fault.o \ mmio.o \ mmu.o \ + qaaf.o \ reset.o kvm-arm64-obj := $(kvm-arm64-local)
arch/s390/kvm/arm64/arm.c +5 -1
@@ -11,6 +11,7 @@#include <linux/bitfield.h> #include <asm/access-regs.h> +#include <asm/aef.h> #include <arm64/kvm_emulate.h> #include <arm64/sysreg.h>
@@ -20,6 +21,7 @@#include "arm.h" #include "handle_exit.h" +#include "qaaf.h" #define CREATE_TRACE_POINTS #include "trace.h"
@@ -741,9 +743,11 @@ long kvm_arch_vcpu_unlocked_ioctl(struct file *filp, unsigned int ioctl,static int __init kvm_s390_arm64_init (void ) { -if (!sclp.has_aef) +if (!sclp.has_aef || !aef_usable ())return -ENODEV ; +kvm_init_qaaf (); +return kvm_init (sizeof (struct kvm_vcpu ),0 ,THIS_MODULE ); }
arch/s390/kvm/arm64/qaaf.c new file +83 -0
83 lines not on this page · raw message
arch/s390/kvm/arm64/qaaf.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef ARCH_S390_KVM_ARM64_QAAF_H +#define ARCH_S390_KVM_ARM64_QAAF_H + +#include <asm/aef.h> + +__init void kvm_init_qaaf (void ); +struct qaaf_qmc_block *kvm_qaaf_qmc (void ); +u64 kvm_qaaf_read_ftr_reg (u32 id); + +#endif
arch/s390/tools/opcodes.txt +1 -0
@@ -600,6 +600,7 @@ b9a7 stiasrm RRE_R0 b9aa lptea RRF_RURR2 b9ab essa RRF_U0RR b9ac irbm RRE_RR +b9ad qaaf RRE_R0 b9ae rrbm RRE_RR b9af pfmf RRE_RR b9b0 cu14 RRF_U0RR
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 16/25 KVM: s390: arm64: Verify machine feature set before loading
In reply to Steffen EidenArm guests on s390 need more than the Arm Execution Facility alone. In addition, the PTFF time conversion functions are required. In addition the guest mapping relies on EDAT2 for large pages.
Verify that these features are present before loading the kvm_arm64 module. Every machine having the aef facility present should also support those. Print an error message if this is not the case.
--- arch/s390/kvm/arm64/arm.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
arch/s390/kvm/arm64/arm.c +20 -1
@@ -741,9 +741,28 @@ long kvm_arch_vcpu_unlocked_ioctl(struct file *filp, unsigned int ioctl,return -ENOIOCTLCMD ; } +static bool __init machine_supports_arm64_kvm (void ) +{ +if (!sclp.has_aef || !aef_usable ()) { +pr_info ("ARM Execution Facility not available\n" ); +return false; + } + +if (!ptff_query (PTFF_QAGTO ) || !ptff_query (PTFF_QAGPT )) { +pr_err ("No ARM time conversion functions available (unexpected machine feature set)\n" ); +return false; + } +if (!cpu_has_edat2 ()) { +pr_err ("No EDAT2 facility available (unexpected machine feature set)\n" ); +return false; + } + +return true; +} +static int __init kvm_s390_arm64_init (void ) { -if (!sclp.has_aef || !aef_usable ()) +if (!machine_supports_arm64_kvm ())return -ENODEV ;kvm_init_qaaf ();
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 17/25 KVM: s390: arm64: Implement feature sanitisation
In reply to Steffen EidenImplement feature detection and sanitization for arm64 KVM guests on s390.
Query hardware capabilities using QAAF instruction and sanitize arm64 ID registers. Provide accessor functions for queried capabilities and integrate feature detection into module initialization sequence.
--- arch/s390/include/asm/kvm_host_arm64.h | 13 +++ arch/s390/kvm/arm64/Makefile | 1 + arch/s390/kvm/arm64/arm.c | 2 +- arch/s390/kvm/arm64/feature.c | 153 +++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/feature.h | 86 ++++++++++++++++++ arch/s390/kvm/arm64/qaaf.c | 2 + 6 files changed, 256 insertions(+), 1 deletion(-)
arch/s390/include/asm/kvm_host_arm64.h +13 -0
@@ -15,6 +15,19 @@ enum vcpu_sysreg;#include <asm/sae.h> +enum { +ARM64_HAS_WFXT , +ARM64_HAS_RASV1P1_EXTN , +ARM64_HAS_STAGE2_FWB , +ARM64_HAS_RAS_EXTN , +ARM64_HAS_EVT , +ARM64_HAS_HCR_NV1 , +ARM64_MISMATCHED_CACHE_TYPE , +ARM64_HAS_ECV_CNTPOFF , +}; + +bool cpus_have_final_cap (unsigned int num); +#define KVM_HAVE_MMU_RWLOCK #define KVM_MAX_VCPUS 1#define __KVM_HAVE_VCPU_RUN_PID_CHANGE
arch/s390/kvm/arm64/Makefile +1 -0
@@ -11,6 +11,7 @@ ccflags-y += -I $(src) -I $(objtree)/$(obj) -I$(srctree)/arch/$(SRCARCH)/kvm/gma kvm-arm64-local := \ arm.o \ + feature.o \ guest.o \ handle_exit.o \ inject_fault.o \
arch/s390/kvm/arm64/arm.c +1 -1
@@ -20,6 +20,7 @@#include <kvm_mmu.h> #include "arm.h" +#include "feature.h" #include "handle_exit.h" #include "qaaf.h"
@@ -27,7 +28,6 @@#include "trace.h" static unsigned long system_supported_vcpu_features (struct kvm_vcpu *vcpu); -#define read_sanitised_ftr_reg (_id) 0#define __INCL_GEN_ARM_FILE#include "generated/arm.inc"
arch/s390/kvm/arm64/feature.c new file +153 -0
153 lines not on this page · raw message
arch/s390/kvm/arm64/feature.h new file +86 -0
86 lines not on this page · raw message
arch/s390/kvm/arm64/qaaf.c +2 -0
@@ -3,6 +3,7 @@#include <linux/kvm_host.h> #include <asm/aef.h> #include "qaaf.h" +#include "feature.h" static struct qaaf_qmc_block qmc_sanitized;
@@ -17,6 +18,7 @@ struct qaaf_qmc_block *kvm_qaaf_qmc(void)void __init kvm_init_qaaf (void ) { qmc_sanitized = *aef_qmc (); +kvm_arm_host_sanitize_features (&qmc_sanitized); }#define _qaaf_reg_case (id) case SYS_##id: return qmc_sanitized.regs[QAAF_REG_##id]
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH v4 17/25] KVM: s390: arm64: Implement feature sanitisation
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] KVM: s390: missing ID_AFR0_EL1 masking in kvm_arm_host_sanitize_features() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] KVM: s390: missing ID_AFR0_EL1 masking in kvm_arm_host_sanitize_features()
--
commit 1121664ab9b9682fba8b52f02bbdb9eec39e1d2d
Author: Steffen Eiden <[email protected]>
KVM: s390: arm64: Implement feature sanitisation
This commit implements feature detection and ID register sanitization for arm64 KVM guests on s390 using the QAAF instruction.
Quoted 6 lines
arch/s390/kvm/arm64/feature.c new file +0
-0@@ -0,0 +1,153 @@
[ ... ]
Quoted 2 lines
arch/s390/kvm/arm64/feature.c new file +2
-0+void __init kvm_arm_host_sanitize_features (struct qaaf_qmc_block *qaaf_qmc) +{
[ ... ]
arch/s390/kvm/arm64/feature.c line 85
Quoted 8 lines
arch/s390/kvm/arm64/feature.c new file +8
-0+MASK_RESERVED (qaaf_qmc,ID_PFR0_EL1 ); +MASK_RESERVED (qaaf_qmc,ID_PFR1_EL1 ); +MASK_RESERVED (qaaf_qmc,ID_PFR2_EL1 ); + +MASK_RESERVED (qaaf_qmc,ID_DFR0_EL1 ); +MASK_RESERVED (qaaf_qmc,ID_DFR1_EL1 ); + +MASK_RESERVED (qaaf_qmc,ID_MMFR0_EL1 );
[Severity: Low]
Should ID_AFR0_EL1 also be sanitized with MASK_RESERVED() here? kvm_qaaf_read_ftr_reg() exposes QAAF_REG_ID_AFR0_EL1 for SYS_ID_AFR0_EL1, so omitting it leaves reserved bits [63:16] unmasked when queried via read_sanitised_ftr_reg().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
Steffen Eiden
reviewerPATCH v4 18/25 KVM: s390: arm64: Implement arm system register managing infrastructure
In reply to Steffen EidenImplement the infrastructures for the s390 host to read and write the arm64 guest system register. The host can access and modify (non-id) system registers through the new instructions EASR/SASR or their multiple variant. Guest accesses to ID registers are trapped and handled by KVM. KVM gets the data form the result of QAAF and sanitizes it using the shared infrastructure with arm64. Sanitizing userspace id values is very basic and needs to be extended in the future. So if userspace wants to shoot itself in the foot it may.
--- arch/s390/include/arm64/kvm_hyp.h | 18 + arch/s390/include/arm64/kvm_nested.h | 5 + arch/s390/include/arm64/sys_regs.h | 9 + arch/s390/include/asm/kvm_host_arm64.h | 211 ++++++++- arch/s390/kvm/arm64/Makefile | 4 +- arch/s390/kvm/arm64/Makefile.gen | 3 +- arch/s390/kvm/arm64/mmu.c | 22 + arch/s390/kvm/arm64/spectre.c | 51 ++ arch/s390/kvm/arm64/sys_regs.c | 825 +++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/trace.h | 50 ++ arch/s390/tools/Makefile.arm64h | 4 + 11 files changed, 1199 insertions(+), 3 deletions(-)
arch/s390/include/arm64/kvm_hyp.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __S390_ARM64_KVM_HYP_H__ +#define __S390_ARM64_KVM_HYP_H__ + +#include <linux/compiler.h> + +static __always_inline bool has_vhe(void) +{ +return true; +} + +static __always_inline bool is_protected_kvm_enabled(void) +{ +return false; +} + +#endif /* __S390_ARM64_KVM_HYP_H__ */
arch/s390/include/arm64/kvm_nested.h +5 -0
@@ -8,4 +8,9 @@ static inline bool vcpu_has_nv(const struct kvm_vcpu *vcpu) return false; } +static inline u64 limit_nv_id_reg (struct kvm *kvm,u32 id,u64 val) +{ +return val; +} +#endif /* ASM_KVM_NESTED_H */
arch/s390/include/arm64/sys_regs.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __S390_ARM64_SYS_REGS_H__ +#define __S390_ARM64_SYS_REGS_H__ + +#include <arm64/cputype.h> +#include <arm64/sys_regs-gen.h> + +#endif /* __S390_ARM64_SYS_REGS_H__ */
arch/s390/include/asm/kvm_host_arm64.h +210 -1
261 lines not on this page · raw message
arch/s390/kvm/arm64/Makefile +3 -1
@@ -18,7 +18,9 @@ kvm-arm64-local := \ mmio.o \ mmu.o \ qaaf.o \ - reset.o + reset.o \ + spectre.o \ + sys_regs.o kvm-arm64-obj := $(kvm-arm64-local) kvm-arm64-obj += $(patsubst %.o,%-arm64.o,$(kvm-y))
arch/s390/kvm/arm64/Makefile.gen +2 -1
@@ -7,7 +7,8 @@ ARM64_CFILES := \ arm.c \ guest.c \ - mmio.c + mmio.c \ + sys_regs.c quiet_cmd_extract_inc = GEN $@ cmd_extract_inc = mkdir -p $(dir $@); \
arch/s390/kvm/arm64/mmu.c +22 -0
@@ -70,6 +70,28 @@ static int kvm_handle_pic(struct kvm_vcpu *vcpu, bool *translation)return 0 ; } +size_t kvm_parange_to_address_sanitized (u32 id_parange) +{ +static u32 ranges_map[8 ] = { + [ID_AA64MMFR0_EL1_PARANGE_32 ] =32 , + [ID_AA64MMFR0_EL1_PARANGE_36 ] =36 , + [ID_AA64MMFR0_EL1_PARANGE_40 ] =40 , + [ID_AA64MMFR0_EL1_PARANGE_42 ] =42 , + [ID_AA64MMFR0_EL1_PARANGE_44 ] =44 , + [ID_AA64MMFR0_EL1_PARANGE_48 ] =48 , + [ID_AA64MMFR0_EL1_PARANGE_52 ] =52 , + [ID_AA64MMFR0_EL1_PARANGE_56 ] =56 , + }; +u32 parange; + +/* +* Future values must be higher than we know already. +* See ARM DDI 0487C.a. Return a safe limit. +*/ + parange = ranges_map[min (id_parange,ID_AA64MMFR0_EL1_PARANGE_56 )]; +return BIT_ULL (parange); +} +int kvm_handle_guest_abort (struct kvm_vcpu *vcpu) {struct kvm_memory_slot *memslot;
arch/s390/kvm/arm64/spectre.c new file +51 -0
51 lines not on this page · raw message
arch/s390/kvm/arm64/sys_regs.c new file +825 -0
825 lines not on this page · raw message
arch/s390/kvm/arm64/trace.h +50 -0
62 lines not on this page · raw message
arch/s390/tools/Makefile.arm64h +4 -0
@@ -17,12 +17,16 @@ arm64uapi := $(objtree)/arch/$(ARCH)/include/generated/uapi/arm64 # If the file does not contain any markers the whole file will be copied. ARM64_SHARED_HEADERS := \ brk-imm.h \ + cache.h \ + cputype.h \ esr.h \ kvm_arm.h \ kvm_emulate-gen.h \ kvm_host.h \ ptrace-gen.h \ sysreg-gen.h \ + spectre.h \ + kvm:sys_regs-gen.h \ uapi:hwcap.h \ uapi:kvm.h \ uapi:ptrace.h \
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH v4 18/25] KVM: s390: arm64: Implement arm system register managing infrastructure
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] KVM: s390: arm64: check SYS_CTR_EL0 against host_val in arm64_check_features() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] KVM: s390: arm64: check SYS_CTR_EL0 against host_val in arm64_check_features()
--
commit 1217d103aa61e7d71cfb3221749c5c2dc344fb25
Author: Steffen Eiden <[email protected]>
KVM: s390: arm64: Implement arm system register managing infrastructure
This commit implements the infrastructure for the s390 KVM host to read, write, trap, and sanitize arm64 guest system registers.
Quoted 6 lines
arch/s390/kvm/arm64/sys_regs.c new file +0
-0@@ -0,0 +1,825 @@
[ ... ]
Quoted 30 lines
arch/s390/kvm/arm64/sys_regs.c new file +30
-0+static int arm64_check_features (struct kvm_vcpu *vcpu, +const struct sys_reg_desc *rd,u64 val) +{ +u32 id =reg_to_encoding (rd); +u64 host_val; +u64 old_val; + +/* +* This is a very minimal implementation to sanitise only the craziest +* shenanigans we could get from userspace. The final goal is to share +* the sanitisation with arm as well but this needs access to arm +* (core) kernel code for which there is no suitable solution yet. TODO +*/ + +/* +* If the register is RAZ we know the only safe value is 0. +*/ +if (sysreg_visible_as_raz (vcpu, rd)) +return val ? -E2BIG :0 ; + + host_val =read_sanitised_ftr_reg (id); + +switch (id) { +case SYS_ID_AA64MMFR0_EL1 : +/* Forbid PARANGE values larger than the host supports */ +if (SYS_FIELD_GET (ID_AA64MMFR0_EL1 ,PARANGE , val) > +SYS_FIELD_GET (ID_AA64MMFR0_EL1 ,PARANGE , host_val)) +return -E2BIG ; + if (kvm_parange_to_address_sanitized( + SYS_FIELD_GET(ID_AA64MMFR0_EL1, PARANGE, val)) <
arch/s390/kvm/arm64/sys_regs.c line 332
Quoted 10 lines
arch/s390/kvm/arm64/sys_regs.c new file +10
-0+ vcpu->kvm->arch.guest_phys_size) +return -E2BIG ; +break ; +case SYS_CTR_EL0 : +/* forbid upgrading from VIPT to PIPT */ + old_val =read_id_reg (vcpu, rd); +if (SYS_FIELD_GET (CTR_EL0 , L1Ip, old_val) == CTR_EL0_L1Ip_VIPT && +SYS_FIELD_GET (CTR_EL0 , L1Ip, val) == CTR_EL0_L1Ip_PIPT) +return -E2BIG ; +break ;
[Severity: Low]
Should SYS_CTR_EL0 check L1Ip against host_val rather than read_id_reg(vcpu, rd)? read_id_reg() returns the mutable per-VM value in vcpu->kvm->arch.id_regs, so if userspace writes CTR_EL0_L1Ip_VIPT and later writes CTR_EL0_L1Ip_PIPT on a PIPT-capable host before the VM is finalized, the second write is rejected with -E2BIG (-EINVAL).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
Steffen Eiden
reviewerPATCH v4 19/25 KVM: s390: arm64: Integrate system registers into the host
In reply to Steffen EidenIntegrate the previously established system register managing infrastructure into the host. Initialize system registers during vcpu init. Finalize system registers on PID change, Initialize sysreg table on kvm init, report availability to userspace and let userspace read&modify guest system register.
--- arch/s390/include/arm64/kvm_emulate.h | 2 ++ arch/s390/kvm/arm64/arm.c | 35 ++++++++++++++++++++++++++++ arch/s390/kvm/arm64/guest.c | 12 ++++++---- arch/s390/kvm/arm64/handle_exit.c | 1 + arch/s390/kvm/arm64/reset.c | 43 +++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 4 deletions(-)
arch/s390/include/arm64/kvm_emulate.h +2 -0
@@ -125,6 +125,8 @@ static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu) vcpu->arch.sae_block.fpcr = 0; } +void vcpu_reset_hcrx (struct kvm_vcpu *vcpu); +#include <arm64/kvm_emulate-gen.h> #endif /* __S390_ARM64_KVM_EMULATE_H__ */
arch/s390/kvm/arm64/arm.c +35 -0
@@ -15,6 +15,7 @@#include <arm64/kvm_emulate.h> #include <arm64/sysreg.h> +#include <arm64/sys_regs.h> #include <gmap.h> #include <kvm_mmu.h>
@@ -50,6 +51,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)break ;case KVM_CAP_IOEVENTFD :case KVM_CAP_PRE_FAULT_MEMORY : +case KVM_CAP_ONE_REG : ret =1 ;break ;default :
@@ -136,6 +138,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) goto out_err; kvm->arch.mem_limit = kvm->arch.guest_phys_size; + kvm->arch.epd =ptff_qagto (0 ); +VM_EVENT (kvm,3 ,"vm created with type %lu" , type);return 0 ;
@@ -193,6 +197,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) sae_block->mso =0L ; sae_block->msl = vcpu->kvm->arch.mem_limit -1 ; sae_block->save_area =virt_to_phys (save_area); + sae_block->gpto = vcpu->kvm->arch.epd; VM_EVENT(vcpu->kvm, 3, "create cpu %d at 0x%p, sae block at 0x%p, satellite at 0x%p",
@@ -207,6 +212,7 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)void kvm_arch_vcpu_destroy (struct kvm_vcpu *vcpu) { +kfree (vcpu->arch.ccsidr);kvm_s390_free_mmu_cache (vcpu->arch.mc);VCPU_EVENT (vcpu,3 ,"%s" ,"free cpu" );
@@ -218,6 +224,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) vcpu->cpu = cpu;lasrm (&vcpu->arch.save_area); + + vcpu->arch.sae_block.gpto = vcpu->kvm->arch.epd; }void kvm_arch_vcpu_put (struct kvm_vcpu *vcpu)
@@ -261,6 +269,7 @@ bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)int kvm_arch_vcpu_run_pid_change (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm; +int ret;if (!kvm_vcpu_initialized (vcpu))return -ENOEXEC ;
@@ -271,6 +280,16 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)if (likely (READ_ONCE (vcpu->pid)))return 0 ; + ret =kvm_vcpu_finalize_sys_regs (vcpu); +if (ret) +return ret; + +/* +* This needs to happen after any restriction has been applied +* to the feature set. +*/ +vcpu_reset_hcrx (vcpu); + scoped_guard(mutex, &kvm->arch.config_lock)set_bit (KVM_ARCH_FLAG_HAS_RAN_ONCE , &kvm->arch.flags);
@@ -477,9 +496,17 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)trace_kvm_entry (*vcpu_pc (vcpu));adjust_pc (vcpu); +vcpu_write_host_sys_reg (vcpu, vcpu->arch.hcr_el2,SYS_HCR_EL2 ); +vcpu_write_host_sys_reg (vcpu, vcpu->arch.hcrx_el2,SYS_HCRX_EL2 ); +vcpu_write_host_sys_reg (vcpu, vcpu->arch.mpidr,SYS_VMPIDR_EL2 ); +_vcpu_write_sys_reg (vcpu, vcpu->arch.ctxt.elr_el1,SYS_ELR_EL1 ); +_vcpu_write_sys_reg (vcpu, vcpu->arch.ctxt.spsr_el1,SYS_SPSR_EL1 );arm_vcpu_enter_exit (virt_to_phys (&vcpu->arch.sae_block)); + vcpu->arch.ctxt.elr_el1 =_vcpu_read_sys_reg (vcpu,SYS_ELR_EL1 ); + vcpu->arch.ctxt.spsr_el1 =_vcpu_read_sys_reg (vcpu,SYS_SPSR_EL1 ); + vcpu->mode =OUTSIDE_GUEST_MODE ; vcpu->stat.exits++;
@@ -762,11 +789,19 @@ static bool __init machine_supports_arm64_kvm(void)static int __init kvm_s390_arm64_init (void ) { +int ret; +if (!machine_supports_arm64_kvm ())return -ENODEV ;kvm_init_qaaf (); + ret =kvm_sys_reg_table_init (); +if (ret) { +kvm_info ("Error initializing system register tables\n" ); +return ret; + } +return kvm_init (sizeof (struct kvm_vcpu ),0 ,THIS_MODULE ); }
arch/s390/kvm/arm64/guest.c +8 -4
@@ -4,6 +4,7 @@#include <arm64/kvm_emulate.h> #include <arm64/kvm_nested.h> +#include <arm64/sys_regs.h> #define SVE_VQ_MIN __SVE_VQ_MIN#define SVE_NUM_ZREGS KVM_ARM64_SVE_NUM_ZREGS
@@ -60,12 +61,15 @@ int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)return ret; uindices += ret; -return 0 ; +return kvm_arm_copy_sys_reg_indices (vcpu, uindices); }unsigned long kvm_arm_num_regs (struct kvm_vcpu *vcpu) { -return num_core_regs (vcpu); +unsigned long num =num_core_regs (vcpu); + + num +=kvm_arm_num_sys_reg_descs (vcpu); +return num; }int kvm_arm_get_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg)
@@ -78,7 +82,7 @@ int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)case KVM_REG_ARM_CORE :return get_core_reg (vcpu, reg);default : -return -EINVAL ; +return kvm_arm_sys_reg_get_reg (vcpu, reg); } }
@@ -92,7 +96,7 @@ int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)case KVM_REG_ARM_CORE :return set_core_reg (vcpu, reg);default : -return -EINVAL ; +return kvm_arm_sys_reg_set_reg (vcpu, reg); } }
arch/s390/kvm/arm64/handle_exit.c +1 -0
@@ -62,6 +62,7 @@ static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu)static exit_handle_fn arm_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec, [ESR_ELx_EC_HVC64] = handle_hvc, + [ESR_ELx_EC_SYS64] = kvm_handle_sys_reg, [ESR_ELx_EC_IABT_LOW] = kvm_handle_guest_abort, [ESR_ELx_EC_DABT_LOW] = kvm_handle_guest_abort, };
arch/s390/kvm/arm64/reset.c +43 -0
64 lines not on this page · raw message
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 20/25 KVM: s390: arm64: Use QAAF init save area
In reply to Steffen EidenUse the (cached) result of QAAF fc2 (Generate Initial System-Registers-Save Area) to initialize the Save Area.
--- arch/s390/kvm/arm64/arm.c | 1 - arch/s390/kvm/arm64/reset.c | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-)
arch/s390/kvm/arm64/arm.c +0 -1
@@ -377,7 +377,6 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,int ret; sae_block->save_area =virt_to_phys (save_area); - save_area->sdo =virt_to_phys (sae_block); ret =kvm_vcpu_set_target (vcpu, init);if (ret)
arch/s390/kvm/arm64/reset.c +5 -0
@@ -3,6 +3,8 @@#include <linux/kvm_host.h> #include <linux/fpu.h> +#include <asm/aef.h> +#include <arm64/kvm_emulate.h> #include <arm64/kvm_nested.h> #include <arm64/sys_regs.h>
@@ -80,6 +82,9 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)if (loaded)vcpu_put (vcpu); +memcpy (&vcpu->arch.save_area,aef_gisrsa (),sizeof (vcpu->arch.save_area)); + vcpu->arch.save_area.sdo =virt_to_phys (&vcpu->arch.sae_block); +kvm_reset_vcpu_core (vcpu);kvm_reset_sys_regs (vcpu);
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 21/25 KVM: s390: arm64: Implement exception injection
In reply to Steffen EidenAdd exception injection support for s390 KVM arm64 architecture. This implements the core exception entry mechanism and fault injection functions needed for proper guest exception handling.
--- arch/s390/include/asm/kvm_host_arm64.h | 1 + arch/s390/kvm/arm64/Makefile | 1 + arch/s390/kvm/arm64/arm.c | 15 ++--- arch/s390/kvm/arm64/exception.c | 109 +++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/inject_fault.c | 65 +++++++++++++++++++- 5 files changed, 178 insertions(+), 13 deletions(-)
arch/s390/include/asm/kvm_host_arm64.h +1 -0
@@ -427,5 +427,6 @@ static inline bool vgic_host_has_gicv5(void) }size_t kvm_parange_to_address_sanitized (u32 id_parange); +void kvm_adjust_pc (struct kvm_vcpu *vcpu);#endif /* ASM_KVM_HOST_ARM64_H */
arch/s390/kvm/arm64/Makefile +1 -0
@@ -11,6 +11,7 @@ ccflags-y += -I $(src) -I $(objtree)/$(obj) -I$(srctree)/arch/$(SRCARCH)/kvm/gma kvm-arm64-local := \ arm.o \ + exception.o \ feature.o \ guest.o \ handle_exit.o \
arch/s390/kvm/arm64/arm.c +4 -11
@@ -396,14 +396,6 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,return -EINVAL ; } -static void adjust_pc (struct kvm_vcpu *vcpu) -{ -if (vcpu_get_flag (vcpu,INCREMENT_PC )) { -kvm_skip_instr (vcpu); -vcpu_clear_flag (vcpu,INCREMENT_PC ); - } -} - static noinstr void arm_vcpu_enter_exit(phys_addr_t sae_block) {guest_timing_enter_irqoff ();
@@ -494,7 +486,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)trace_kvm_entry (*vcpu_pc (vcpu)); -adjust_pc (vcpu); +kvm_adjust_pc (vcpu);vcpu_write_host_sys_reg (vcpu, vcpu->arch.hcr_el2,SYS_HCR_EL2 );vcpu_write_host_sys_reg (vcpu, vcpu->arch.hcrx_el2,SYS_HCRX_EL2 );vcpu_write_host_sys_reg (vcpu, vcpu->arch.mpidr,SYS_VMPIDR_EL2 );
@@ -517,8 +509,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)kvm_sigset_deactivate (vcpu); out: -if (unlikely (vcpu_get_flag (vcpu,INCREMENT_PC ))) -adjust_pc (vcpu); +if (unlikely (vcpu_get_flag (vcpu,PENDING_EXCEPTION ) || +vcpu_get_flag (vcpu,INCREMENT_PC ))) +kvm_adjust_pc (vcpu);save_vx_regs (vcpu->arch.ctxt.vregs);kernel_fpu_end (&fpu_save,KERNEL_FPC |KERNEL_VXR );
arch/s390/kvm/arm64/exception.c new file +109 -0
109 lines not on this page · raw message
arch/s390/kvm/arm64/inject_fault.c +63 -2
80 lines not on this page · raw message
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH v4 21/25] KVM: s390: arm64: Implement exception injection
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] KVM: s390: arm64: unsigned gltl overflow in inject_abt64() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] KVM: s390: arm64: unsigned gltl overflow in inject_abt64() --
commit 9e41f0d307b22656ebad8b0615877db473136b55
Author: Steffen Eiden <[email protected]>
KVM: s390: arm64: Implement exception injection
This commit adds guest exception entry and fault injection support for s390 KVM arm64 guests.
Quoted 13 lines
arch/s390/kvm/arm64/inject_fault.c +5
-0@@ -2,6 +2,38 @@#include <arm64/kvm_emulate.h> +static void pend_sync_exception (struct kvm_vcpu *vcpu) +{ +kvm_pend_exception (vcpu,EXCEPT_AA64_EL1_SYNC ); +} +
arch/s390/kvm/arm64/inject_fault.c line 19
Quoted 10 lines
arch/s390/kvm/arm64/inject_fault.c +10
-0+static void inject_abt64 (struct kvm_vcpu *vcpu,bool is_iabt,unsigned long addr) +{ +unsigned long cpsr = *vcpu_cpsr (vcpu); +bool is_aarch32 =vcpu_mode_is_32bit (vcpu); +u64 esr =0 ; + +if (kvm_vcpu_abt_iss1tw (vcpu)) + esr |=ESR_ELx_FSC_SEA_TTW (kvm_vcpu_abt_gltl (vcpu)); +else + esr |= ESR_ELx_FSC_EXTABT;
[Severity: Medium]
Can ESR_ELx_FSC_SEA_TTW(kvm_vcpu_abt_gltl(vcpu)) overflow the 6-bit FSC field into bit 8 of ESR_EL1 on a level -1 Stage-1 translation table walk fault?
ESR_ELx_FSC_SEA_TTW(n) expands to (0x14 + (n)), expecting a signed walk level down to -1 for FEAT_LPA2 5-level page tables. Because sae_block.hai.gltl is declared as u8 and kvm_vcpu_abt_gltl() returns it as an int without sign-extending it, a level -1 walk encoded as 0xff becomes 255:
arch/s390/include/arm64/kvm_emulate.h:kvm_vcpu_abt_gltl() {
return vcpu->arch.sae_block.hai.gltl;
}0x14 + 255 evaluates to 0x113, setting bit 8 (ESR_ELx_CM for data aborts or a RES0 bit for instruction aborts) in the guest's ESR_EL1. That extra bit also survives kvm_inject_size_fault(), which only clears GENMASK_ULL(5, 0) after calling __kvm_inject_sea().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
Steffen Eiden
reviewerPATCH v4 22/25 KVM: s390: arm64: Finalize page fault handling
In reply to Steffen EidenReplace the temporary -ENOEXEC returns of the arm64-on-s390 page fault handling with exception injection into the guest, mirroring arm64's kvm_handle_guest_abort().
Translation faults beyond the physical address range are injected as an address size fault, while faults falling between the VM's IPA size and that range are injected as a synchronous external abort. Instruction aborts and stage-1 walk faults on host addresses that back no guest page are injected as synchronous external aborts as well, and a PGM-addressing from the fault-in path is injected as an address size fault, the closest arm64 equivalent. Injected faults return 1 so the vCPU re-enters the guest with the pending exception instead of exiting to userspace.
--- arch/s390/kvm/arm64/arm.c | 6 ++++++ arch/s390/kvm/arm64/mmu.c | 52 ++++++++++++++++++++++++++--------------------- 2 files changed, 35 insertions(+), 23 deletions(-)
arch/s390/kvm/arm64/arm.c +6 -0
@@ -63,9 +63,15 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)static u64 kvm_max_guest_address (void ) { +u64 mmfr0 =read_sanitised_ftr_reg (SYS_ID_AA64MMFR0_EL1 ); +u64 id_pa_addr;u64 max_addr; + id_pa_addr =kvm_parange_to_address_sanitized ( +SYS_FIELD_GET (ID_AA64MMFR0_EL1 ,PARANGE , mmfr0)); + max_addr =min_t (u64,TASK_SIZE_MAX , sclp.hamax); + max_addr =min_t (u64, max_addr, id_pa_addr); max_addr =max_t (u64, max_addr,SZ_1G -1 );return ALIGN_DOWN (max_addr +1 ,SZ_1G ) -1 ; }
arch/s390/kvm/arm64/mmu.c +29 -23
93 lines not on this page · raw message
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 23/25 KVM: s390: arm64: Implement SVE for arm guests
In reply to Steffen EidenFrom: Friedrich Welter <[email protected]>
Add support for Scalable Vector Extension (SVE) in ARM64 guests running on s390 hardware, providing 128-bit vector operations backed by s390's Vector Extension (VX).
The implementation is limited to 128-bit vectors (VQ=1) matching s390 VX register width. Z registers reuse existing FP/SIMD register space (vregs), while P registers and FFR are stored in the SAE block.
--- arch/s390/include/asm/kvm_host_arm64.h | 5 +- arch/s390/kvm/arm64/arm.c | 6 + arch/s390/kvm/arm64/feature.c | 9 +- arch/s390/kvm/arm64/feature.h | 6 + arch/s390/kvm/arm64/guest.c | 250 +++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/reset.c | 24 ++++ 6 files changed, 297 insertions(+), 3 deletions(-)
arch/s390/include/asm/kvm_host_arm64.h +3 -2
@@ -34,7 +34,9 @@ bool cpus_have_final_cap(unsigned int num);#define KVM_MAX_VCPUS 1#define __KVM_HAVE_VCPU_RUN_PID_CHANGE -#define KVM_S390_ARM64_IMPL_FEATURES 0 +#define KVM_S390_ARM64_IMPL_FEATURES ( \ + BIT(KVM_ARM_VCPU_SVE) \ +)#define KVM_HALT_POLL_NS_DEFAULT 50000#define KVM_S390_MANAGES_S390_GUEST 0
@@ -130,7 +132,6 @@ struct kvm_vcpu_stat { };#define kvm_has_mte (_kvm) false -#define vcpu_has_sve (_vcpu) false#define vcpu_has_ptrauth (_vcpu) false#define kvm_has_fpmr (kvm) \
arch/s390/kvm/arm64/arm.c +6 -0
@@ -54,6 +54,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_ONE_REG : ret =1 ;break ; +case KVM_CAP_ARM_SVE : + ret =system_supports_sve (); +break ;default : ret =0 ; }
@@ -264,6 +267,9 @@ static unsigned long system_supported_vcpu_features(struct kvm_vcpu *vcpu) {unsigned long features =KVM_S390_ARM64_IMPL_FEATURES ; +if (!system_supports_sve ()) +clear_bit (KVM_ARM_VCPU_SVE , &features); +return features; }
arch/s390/kvm/arm64/feature.c +8 -1
@@ -56,7 +56,6 @@ void __init kvm_arm_host_sanitize_features(struct qaaf_qmc_block *qaaf_qmc)MASK_RESERVED (qaaf_qmc,ID_AA64MMFR4_EL1 );MODIFY (qaaf_qmc,ID_AA64PFR0_EL1 ,SEL2 ,NI ); -MODIFY (qaaf_qmc,ID_AA64PFR0_EL1 ,SVE ,NI );MASK_RESERVED (qaaf_qmc,ID_AA64PFR0_EL1 );MASK_RESERVED (qaaf_qmc,ID_AA64PFR1_EL1 );MASK_RESERVED (qaaf_qmc,ID_AA64PFR2_EL1 );
@@ -151,3 +150,11 @@ bool cpus_have_final_cap(unsigned int num)return false; } } + +bool system_supports_sve (void ) +{ +return cpu_has_vx () && +SYS_FIELD_GET (ID_AA64PFR0_EL1 ,SVE , +read_sanitised_ftr_reg (SYS_ID_AA64PFR0_EL1 )) == +ID_AA64PFR0_EL1_SVE_IMP ; +}
arch/s390/kvm/arm64/feature.h +6 -0
@@ -83,4 +83,10 @@ static inline u64 kvm_sae_irptc(void)#define kvm_vcpu_has_pmu (_v) false +#define vcpu_has_sve (_vcpu) \ + (system_supports_sve() && \ + test_bit(KVM_ARCH_FLAG_GUEST_HAS_SVE, &((_vcpu)->kvm)->arch.flags)) + +bool system_supports_sve (void ); +#endif /* ARCH_S390_KVM_FEATURE_H */
arch/s390/kvm/arm64/guest.c +250 -0
286 lines not on this page · raw message
arch/s390/kvm/arm64/reset.c +24 -0
@@ -2,6 +2,7 @@#include <linux/kvm_host.h> #include <linux/fpu.h> +#include <linux/cpufeature.h> #include <asm/aef.h>
@@ -12,8 +13,13 @@#include <clocksource/arm_arch_timer.h> +#include "feature.h" +bool kvm_arm_vcpu_is_finalized (struct kvm_vcpu *vcpu) { +if (vcpu_has_sve (vcpu) && !kvm_arm_vcpu_sve_finalized (vcpu)) +return false; +return true; }
@@ -77,6 +83,14 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)*/ preempt_disable (); +if (!vcpu_get_flag (vcpu,VCPU_SVE_FINALIZED )) { +if (vcpu_has_feature (vcpu,KVM_ARM_VCPU_SVE )) +set_bit (KVM_ARCH_FLAG_GUEST_HAS_SVE , &vcpu->kvm->arch.flags); + }else if (vcpu_has_sve (vcpu)) { +memset (vcpu->arch.sae_block.sve_pregs,0 ,sizeof (vcpu->arch.sae_block.sve_pregs)); + vcpu->arch.sae_block.sve_ffr =0 ; + } +/* The reset must run with an unloaded save area */ loaded =vcpu_is_loaded (vcpu);if (loaded)
@@ -115,5 +129,15 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)int kvm_arm_vcpu_finalize (struct kvm_vcpu *vcpu,int feature) { +switch (feature) { +case KVM_ARM_VCPU_SVE : +if (!vcpu_has_sve (vcpu)) +return -EINVAL ; +if (vcpu_get_flag (vcpu,VCPU_SVE_FINALIZED )) +return -EPERM ; +vcpu_set_flag (vcpu,VCPU_SVE_FINALIZED ); +return 0 ; + } +return -EINVAL ; }
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 24/25 KVM: s390: arm64: Promote PTRAUTH capability
In reply to Steffen EidenPromote the pointer authentication capability if supported by hardware and allow userspace to access those.
--- arch/s390/include/asm/kvm_host_arm64.h | 12 ++++-------- arch/s390/kvm/arm64/arm.c | 17 +++++++++++++++++ arch/s390/kvm/arm64/feature.c | 18 ++++++++++++++++++ arch/s390/kvm/arm64/feature.h | 5 +++++ arch/s390/kvm/arm64/sys_regs.c | 10 ++++++++-- 5 files changed, 52 insertions(+), 10 deletions(-)
arch/s390/include/asm/kvm_host_arm64.h +4 -8
@@ -34,8 +34,10 @@ bool cpus_have_final_cap(unsigned int num);#define KVM_MAX_VCPUS 1#define __KVM_HAVE_VCPU_RUN_PID_CHANGE -#define KVM_S390_ARM64_IMPL_FEATURES ( \ - BIT(KVM_ARM_VCPU_SVE) \ +#define KVM_S390_ARM64_IMPL_FEATURES ( \ + BIT(KVM_ARM_VCPU_PTRAUTH_ADDRESS) | \ + BIT(KVM_ARM_VCPU_PTRAUTH_GENERIC) | \ + BIT(KVM_ARM_VCPU_SVE) \ )#define KVM_HALT_POLL_NS_DEFAULT 50000
@@ -132,7 +134,6 @@ struct kvm_vcpu_stat { };#define kvm_has_mte (_kvm) false -#define vcpu_has_ptrauth (_vcpu) false#define kvm_has_fpmr (kvm) \ kvm_has_feat((kvm), ID_AA64PFR2_EL1, FPMR, IMP)
@@ -173,11 +174,6 @@ struct kvm_vm_stat {struct kvm_vm_stat_generic generic; }; -static inline bool system_has_full_ptr_auth (void ) -{ -return true; -} -#define kvm_vm_is_protected (_kvm) false#define vcpu_is_protected (_vcpu) false
arch/s390/kvm/arm64/arm.c +17 -0
@@ -57,6 +57,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_ARM_SVE : ret =system_supports_sve ();break ; +case KVM_CAP_ARM_PTRAUTH_ADDRESS : +case KVM_CAP_ARM_PTRAUTH_GENERIC : + ret =kvm_has_full_ptr_auth (); +break ;default : ret =0 ; }
@@ -227,6 +231,12 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)VCPU_EVENT (vcpu,3 ,"%s" ,"free cpu" ); } +static void vcpu_set_pauth_traps (struct kvm_vcpu *vcpu) +{ +if (vcpu_has_ptrauth (vcpu)) + vcpu->arch.hcr_el2 |= (HCR_EL2_API |HCR_EL2_APK ); +} +void kvm_arch_vcpu_load (struct kvm_vcpu *vcpu,int cpu) {save_access_regs (&vcpu->arch.host_acrs[0 ]);
@@ -235,6 +245,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)lasrm (&vcpu->arch.save_area); vcpu->arch.sae_block.gpto = vcpu->kvm->arch.epd; + +vcpu_set_pauth_traps (vcpu); }void kvm_arch_vcpu_put (struct kvm_vcpu *vcpu)
@@ -270,6 +282,11 @@ static unsigned long system_supported_vcpu_features(struct kvm_vcpu *vcpu)if (!system_supports_sve ())clear_bit (KVM_ARM_VCPU_SVE , &features); +if (!kvm_has_full_ptr_auth ()) { +clear_bit (KVM_ARM_VCPU_PTRAUTH_ADDRESS , &features); +clear_bit (KVM_ARM_VCPU_PTRAUTH_GENERIC , &features); + } +return features; }
arch/s390/kvm/arm64/feature.c +18 -0
@@ -158,3 +158,21 @@ bool system_supports_sve(void) read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1)) ==ID_AA64PFR0_EL1_SVE_IMP ; } + +bool system_has_full_ptr_auth (void ) +{ +u64 isar1 =read_sanitised_ftr_reg (SYS_ID_AA64ISAR1_EL1 ); +u64 isar2 =read_sanitised_ftr_reg (SYS_ID_AA64ISAR2_EL1 ); +bool address_auth; +bool generic_auth; + + address_auth =SYS_FIELD_GET (ID_AA64ISAR1_EL1 ,APA , isar1) >= ID_AA64ISAR1_EL1_APA_PAuth || +SYS_FIELD_GET (ID_AA64ISAR1_EL1 ,API , isar1) >= ID_AA64ISAR1_EL1_API_PAuth || +SYS_FIELD_GET (ID_AA64ISAR2_EL1 ,APA3 , isar2) >= ID_AA64ISAR2_EL1_APA3_PAuth; + + generic_auth =SYS_FIELD_GET (ID_AA64ISAR1_EL1 ,GPA , isar1) >=ID_AA64ISAR1_EL1_GPA_IMP || +SYS_FIELD_GET (ID_AA64ISAR1_EL1 ,GPI , isar1) >=ID_AA64ISAR1_EL1_GPI_IMP || +SYS_FIELD_GET (ID_AA64ISAR2_EL1 ,GPA3 , isar2) >=ID_AA64ISAR2_EL1_GPA3_IMP ; + +return address_auth && generic_auth; +}
arch/s390/kvm/arm64/feature.h +5 -0
@@ -89,4 +89,9 @@ static inline u64 kvm_sae_irptc(void)bool system_supports_sve (void ); +#define vcpu_has_ptrauth (vcpu) \ + (vcpu_has_feature(vcpu, KVM_ARM_VCPU_PTRAUTH_ADDRESS) || \ + vcpu_has_feature(vcpu, KVM_ARM_VCPU_PTRAUTH_GENERIC)) +bool system_has_full_ptr_auth (void ); +#endif /* ARCH_S390_KVM_FEATURE_H */
arch/s390/kvm/arm64/sys_regs.c +8 -2
@@ -33,7 +33,6 @@ static u64 __ro_after_init boot_cpu_aidr_val;#undef __INCL_GEN_ARM_FILEDEFINE_STATIC_KEY_FALSE (broken_cntvoff_key); -#define SR_INVALID 0x8badf00d8badf00denum sr_loc_attr {
@@ -639,6 +638,14 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_TTBR1_EL1), access_rw, reset_val, TTBR1_EL1, 0 }, { SYS_DESC(SYS_TCR_EL1), access_rw, reset_val, TCR_EL1, 0 }, +/* CRm = 1 */ +PTRAUTH_KEY (APIA ), +PTRAUTH_KEY (APIB ), +/* CRm = 2 */ +PTRAUTH_KEY (APDA ), +PTRAUTH_KEY (APDB ), +/* CRm = 3 */ +PTRAUTH_KEY (APGA ),/* CRn = 5 */ { SYS_DESC(SYS_AFSR0_EL1), access_rw, reset_unknown, AFSR0_EL1 }, { SYS_DESC(SYS_AFSR1_EL1), access_rw, reset_unknown, AFSR1_EL1 },
@@ -647,7 +654,6 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_FAR_EL1), access_rw, reset_unknown, FAR_EL1 },/* CRn = 7 */ { SYS_DESC(SYS_PAR_EL1), access_rw, reset_unknown, PAR_EL1 }, - { SYS_DESC(SYS_PMMIR_EL1), trap_raz_wi },/* CRn = 10 */ { SYS_DESC(SYS_MAIR_EL1), NULL, reset_unknown, MAIR_EL1 },
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH v4 25/25 s390: Report AEF features to sysfs
In reply to Steffen EidenDisplay various information about the Arm execution Facility (AEF) to userspace. The files are located in /sys/firmware/aef/. Show if the feature is available and usable for the host, which formats are available, and how many arm vCPUS per guest are supported by the machine. Additionally, provide the raw binary output of QAAF fc1 (Query Model Capabilities) in the file qmc and fc2 (Initial System-Registers-Save Area) in the file save_area.
--- Documentation/ABI/testing/sysfs-firmware-aef | 51 +++++++++++++++ arch/s390/kernel/aef.c | 98 ++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+)
Documentation/ABI/testing/sysfs-firmware-aef new file +51 -0
@@ -0,0 +1,51 @@ +What: /sys/firmware/aef/ +KernelVersion: 7.5 +Contact: [email protected] +Description: Various interfaces to query information about the ARM + Execution Facility (AEF). + + The directory is present only on machines that provide + the AEF (SCLP facility bit). + +What: /sys/firmware/aef/arm_guest_supp +KernelVersion: 7.5 +Contact: [email protected] +Description: Read-only, decimal boolean. Reports 1 if all requirements + for running arm64 KVM guests (KVM module kvm_arm64) are + satisfied by the machine, 0 otherwise. + +What: /sys/firmware/aef/query/ +KernelVersion: 7.5 +Contact: [email protected] +Description: Raw machine characteristics as reported by the QAAF + instruction. + +What: /sys/firmware/aef/query/supp_state_desc_formats +KernelVersion: 7.5 +Contact: [email protected] +Description: Read-only, 0x-prefixed hexadecimal bitmask. Bitmask of + the SAE state description formats supported by the machine. + +What: /sys/firmware/aef/query/supp_save_area_formats +KernelVersion: 7.5 +Contact: [email protected] +Description: Read-only, 0x-prefixed hexadecimal bitmask. Bitmask of + the SAE save area formats supported by the machine. + +What: /sys/firmware/aef/query/max_num_vcpu +KernelVersion: 7.5 +Contact: [email protected] +Description: Read-only, decimal number. Maximum number of guest CPUs + per VM. + +What: /sys/firmware/aef/query/qmc +KernelVersion: 7.5 +Contact: [email protected] +Description: Read-only binary attribute, 4096 bytes. Contains the + unmodified, machine specific QMC response block. + +What: /sys/firmware/aef/query/save_area +KernelVersion: 7.5 +Contact: [email protected] +Description: Read-only binary attribute, 4096 bytes. Contains the + unmodified, machine specific GISRSA block.
arch/s390/kernel/aef.c +98 -0
125 lines not on this page · raw message
Signature · 1 line
2.56.1
[email protected]
AI reviewSashiko has finished reviewing this 25-patch series:
Sashiko has finished reviewing this 25-patch series:
- Patches 1-9, 11-16, 19, 20, and 22-25: no issues found.
- Patch 10 ("KVM: arm64: Share system register code with s390"): 1 potential issue (1 Medium)
- Patch 17 ("KVM: s390: arm64: Implement feature sanitisation"): 1 potential issue (1 Low)
- Patch 18 ("KVM: s390: arm64: Implement arm system register mana..."):
1 potential issue (1 Low)
- Patch 21 ("KVM: s390: arm64: Implement exception injection"): 1 potential issue (1 Medium)
Detailed reviews have been sent as separate replies to patches 10, 17, 18, and 21.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]