Skip to content

Commit 179fd7e

Browse files
Marc Zyngieroupton
authored andcommitted
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: Marc Zyngier <maz@kernel.org> Reviewed-by: Joey Gouly <joey.gouly@arm.com> Link: https://lore.kernel.org/r/20250220134907.554085-8-maz@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 57e7de2 commit 179fd7e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,16 +1803,6 @@ static u64 sanitise_id_aa64pfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
18031803
return val;
18041804
}
18051805

1806-
#define ID_REG_LIMIT_FIELD_ENUM(val, reg, field, limit) \
1807-
({ \
1808-
u64 __f_val = FIELD_GET(reg##_##field##_MASK, val); \
1809-
(val) &= ~reg##_##field##_MASK; \
1810-
(val) |= FIELD_PREP(reg##_##field##_MASK, \
1811-
min(__f_val, \
1812-
(u64)SYS_FIELD_VALUE(reg, field, limit))); \
1813-
(val); \
1814-
})
1815-
18161806
static u64 sanitise_id_aa64dfr0_el1(const struct kvm_vcpu *vcpu, u64 val)
18171807
{
18181808
val = ID_REG_LIMIT_FIELD_ENUM(val, ID_AA64DFR0_EL1, DebugVer, V8P8);

arch/arm64/kvm/sys_regs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,14 @@ int kvm_finalize_sys_regs(struct kvm_vcpu *vcpu);
247247
CRn(sys_reg_CRn(reg)), CRm(sys_reg_CRm(reg)), \
248248
Op2(sys_reg_Op2(reg))
249249

250+
#define ID_REG_LIMIT_FIELD_ENUM(val, reg, field, limit) \
251+
({ \
252+
u64 __f_val = FIELD_GET(reg##_##field##_MASK, val); \
253+
(val) &= ~reg##_##field##_MASK; \
254+
(val) |= FIELD_PREP(reg##_##field##_MASK, \
255+
min(__f_val, \
256+
(u64)SYS_FIELD_VALUE(reg, field, limit))); \
257+
(val); \
258+
})
259+
250260
#endif /* __ARM64_KVM_SYS_REGS_LOCAL_H__ */

0 commit comments

Comments
 (0)