Commit 179fd7e3 authored by Marc Zyngier's avatar Marc Zyngier Committed by Oliver Upton
Browse files

KVM: arm64: Make ID_REG_LIMIT_FIELD_ENUM() more widely available



ID_REG_LIMIT_FIELD_ENUM() is a useful macro to limit the idreg
features exposed to guest and userspace, and the NV code can
make use of it.

Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Reviewed-by: default avatarJoey Gouly <joey.gouly@arm.com>
Link: https://lore.kernel.org/r/20250220134907.554085-8-maz@kernel.org


Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
parent 57e7de26
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -1803,16 +1803,6 @@ static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
	return val;
}

#define ID_REG_LIMIT_FIELD_ENUM(val, reg, field, limit)			       \
({									       \
	u64 __f_val = FIELD_GET(reg##_##field##_MASK, val);		       \
	(val) &= ~reg##_##field##_MASK;					       \
	(val) |= FIELD_PREP(reg##_##field##_MASK,			       \
			    min(__f_val,				       \
				(u64)SYS_FIELD_VALUE(reg, field, limit)));     \
	(val);								       \
})

static u64 sanitise_id_aa64dfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
{
	val = ID_REG_LIMIT_FIELD_ENUM(val, ID_AA64DFR0_EL1, DebugVer, V8P8);
+10 −0
Original line number Diff line number Diff line
@@ -247,4 +247,14 @@ int kvm_finalize_sys_regs(struct kvm_vcpu *vcpu);
	CRn(sys_reg_CRn(reg)), CRm(sys_reg_CRm(reg)),	\
	Op2(sys_reg_Op2(reg))

#define ID_REG_LIMIT_FIELD_ENUM(val, reg, field, limit)			       \
({									       \
	u64 __f_val = FIELD_GET(reg##_##field##_MASK, val);		       \
	(val) &= ~reg##_##field##_MASK;					       \
	(val) |= FIELD_PREP(reg##_##field##_MASK,			       \
			    min(__f_val,				       \
				(u64)SYS_FIELD_VALUE(reg, field, limit)));     \
	(val);								       \
})

#endif /* __ARM64_KVM_SYS_REGS_LOCAL_H__ */