Skip to content

Commit 1a61820

Browse files
reijiw-kvmMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Use FIELD_GET() to extract ID register fields
Use FIELD_GET() macro to extract ID register fields for existing aarch64 selftests code. No functional change intended. Signed-off-by: Reiji Watanabe <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 30a0b95 commit 1a61820

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "kvm_util.h"
1414
#include "processor.h"
1515
#include "test_util.h"
16+
#include <linux/bitfield.h>
1617

1718
#define BAD_ID_REG_VAL 0x1badc0deul
1819

@@ -145,7 +146,7 @@ static bool vcpu_aarch64_only(struct kvm_vcpu *vcpu)
145146

146147
vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1), &val);
147148

148-
el0 = (val & ARM64_FEATURE_MASK(ID_AA64PFR0_EL0)) >> ID_AA64PFR0_EL0_SHIFT;
149+
el0 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL0), val);
149150
return el0 == ID_AA64PFR0_ELx_64BIT_ONLY;
150151
}
151152

tools/testing/selftests/kvm/aarch64/debug-exceptions.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <test_util.h>
33
#include <kvm_util.h>
44
#include <processor.h>
5+
#include <linux/bitfield.h>
56

67
#define MDSCR_KDE (1 << 13)
78
#define MDSCR_MDE (1 << 15)
@@ -284,7 +285,7 @@ static int debug_version(struct kvm_vcpu *vcpu)
284285
uint64_t id_aa64dfr0;
285286

286287
vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &id_aa64dfr0);
287-
return id_aa64dfr0 & 0xf;
288+
return FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), id_aa64dfr0);
288289
}
289290

290291
static void test_guest_debug_exceptions(void)

tools/testing/selftests/kvm/lib/aarch64/processor.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "guest_modes.h"
1212
#include "kvm_util.h"
1313
#include "processor.h"
14+
#include <linux/bitfield.h>
1415

1516
#define DEFAULT_ARM64_GUEST_STACK_VADDR_MIN 0xac0000
1617

@@ -486,9 +487,9 @@ void aarch64_get_supported_page_sizes(uint32_t ipa,
486487
err = ioctl(vcpu_fd, KVM_GET_ONE_REG, &reg);
487488
TEST_ASSERT(err == 0, KVM_IOCTL_ERROR(KVM_GET_ONE_REG, vcpu_fd));
488489

489-
*ps4k = ((val >> 28) & 0xf) != 0xf;
490-
*ps64k = ((val >> 24) & 0xf) == 0;
491-
*ps16k = ((val >> 20) & 0xf) != 0;
490+
*ps4k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN4), val) != 0xf;
491+
*ps64k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN64), val) == 0;
492+
*ps16k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN16), val) != 0;
492493

493494
close(vcpu_fd);
494495
close(vm_fd);

0 commit comments

Comments
 (0)