Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KVM: arm64: Extend unified RESx handling to runtime sanitisation

Add a new helper to retrieve the RESx values for a given system
register, and use it for the runtime sanitisation.

This results in slightly better code generation for a fairly hot
path in the hypervisor, and additionally covers all sanitised
registers in all conditions, not just the VNCR-based ones.

Reviewed-by: Fuad Tabba <tabba@google.com>
Tested-by: Fuad Tabba <tabba@google.com>
Link: https://patch.msgid.link/20260202184329.2724080-6-maz@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>

+20 -18
+15
arch/arm64/include/asm/kvm_host.h
··· 635 635 struct resx mask[NR_SYS_REGS - __SANITISED_REG_START__]; 636 636 }; 637 637 638 + static inline struct resx __kvm_get_sysreg_resx(struct kvm_arch *arch, 639 + enum vcpu_sysreg sr) 640 + { 641 + struct kvm_sysreg_masks *masks; 642 + 643 + masks = arch->sysreg_masks; 644 + if (likely(masks && 645 + sr >= __SANITISED_REG_START__ && sr < NR_SYS_REGS)) 646 + return masks->mask[sr - __SANITISED_REG_START__]; 647 + 648 + return (struct resx){}; 649 + } 650 + 651 + #define kvm_get_sysreg_resx(k, sr) __kvm_get_sysreg_resx(&(k)->arch, (sr)) 652 + 638 653 static inline void __kvm_set_sysreg_resx(struct kvm_arch *arch, 639 654 enum vcpu_sysreg sr, struct resx resx) 640 655 {
+1 -9
arch/arm64/kvm/emulate-nested.c
··· 2427 2427 2428 2428 static u64 kvm_get_sysreg_res0(struct kvm *kvm, enum vcpu_sysreg sr) 2429 2429 { 2430 - struct kvm_sysreg_masks *masks; 2431 - 2432 - /* Only handle the VNCR-backed regs for now */ 2433 - if (sr < __VNCR_START__) 2434 - return 0; 2435 - 2436 - masks = kvm->arch.sysreg_masks; 2437 - 2438 - return masks->mask[sr - __SANITISED_REG_START__].res0; 2430 + return kvm_get_sysreg_resx(kvm, sr).res0; 2439 2431 } 2440 2432 2441 2433 static bool check_fgt_bit(struct kvm_vcpu *vcpu, enum vcpu_sysreg sr,
+4 -9
arch/arm64/kvm/nested.c
··· 1669 1669 u64 kvm_vcpu_apply_reg_masks(const struct kvm_vcpu *vcpu, 1670 1670 enum vcpu_sysreg sr, u64 v) 1671 1671 { 1672 - struct kvm_sysreg_masks *masks; 1672 + struct resx resx; 1673 1673 1674 - masks = vcpu->kvm->arch.sysreg_masks; 1675 - 1676 - if (masks) { 1677 - sr -= __SANITISED_REG_START__; 1678 - 1679 - v &= ~masks->mask[sr].res0; 1680 - v |= masks->mask[sr].res1; 1681 - } 1674 + resx = kvm_get_sysreg_resx(vcpu->kvm, sr); 1675 + v &= ~resx.res0; 1676 + v |= resx.res1; 1682 1677 1683 1678 return v; 1684 1679 }