Skip to content

Commit f9d5895

Browse files
author
Marc Zyngier
committed
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>
1 parent 0879478 commit f9d5895

3 files changed

Lines changed: 20 additions & 18 deletions

File tree

arch/arm64/include/asm/kvm_host.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,21 @@ struct kvm_sysreg_masks {
635635
struct resx mask[NR_SYS_REGS - __SANITISED_REG_START__];
636636
};
637637

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+
638653
static inline void __kvm_set_sysreg_resx(struct kvm_arch *arch,
639654
enum vcpu_sysreg sr, struct resx resx)
640655
{

arch/arm64/kvm/emulate-nested.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,15 +2427,7 @@ static enum trap_behaviour compute_trap_behaviour(struct kvm_vcpu *vcpu,
24272427

24282428
static u64 kvm_get_sysreg_res0(struct kvm *kvm, enum vcpu_sysreg sr)
24292429
{
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;
24392431
}
24402432

24412433
static bool check_fgt_bit(struct kvm_vcpu *vcpu, enum vcpu_sysreg sr,

arch/arm64/kvm/nested.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,16 +1669,11 @@ u64 limit_nv_id_reg(struct kvm *kvm, u32 reg, u64 val)
16691669
u64 kvm_vcpu_apply_reg_masks(const struct kvm_vcpu *vcpu,
16701670
enum vcpu_sysreg sr, u64 v)
16711671
{
1672-
struct kvm_sysreg_masks *masks;
1673-
1674-
masks = vcpu->kvm->arch.sysreg_masks;
1675-
1676-
if (masks) {
1677-
sr -= __SANITISED_REG_START__;
1672+
struct resx resx;
16781673

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;
16821677

16831678
return v;
16841679
}

0 commit comments

Comments
 (0)