From: Sebastian Ott <sebott@redhat.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Marc Zyngier <maz@kernel.org>, Oliver Upton <oliver.upton@linux.dev>
Subject: [PATCH 4/4] KVM: selftests: aarch64: add tool to dump registers
Date: Mon, 18 Mar 2024 12:16:36 +0100 [thread overview]
Message-ID: <20240318111636.10613-5-sebott@redhat.com> (raw)
In-Reply-To: <20240318111636.10613-1-sebott@redhat.com>
Iterate over registers obtained via KVM_GET_REG_LIST, dump
their values and writable masks.
Signed-off-by: Sebastian Ott <sebott@redhat.com>
---
tools/testing/selftests/kvm/Makefile | 1 +
.../testing/selftests/kvm/aarch64/dump_regs.c | 72 +++++++++++++++++++
2 files changed, 73 insertions(+)
create mode 100644 tools/testing/selftests/kvm/aarch64/dump_regs.c
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 492e937fab00..3bbb163abb1e 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -145,6 +145,7 @@ TEST_GEN_PROGS_EXTENDED_x86_64 += x86_64/nx_huge_pages_test
TEST_GEN_PROGS_aarch64 += aarch64/aarch32_id_regs
TEST_GEN_PROGS_aarch64 += aarch64/arch_timer
TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions
+TEST_GEN_PROGS_aarch64 += aarch64/dump_regs
TEST_GEN_PROGS_aarch64 += aarch64/hypercalls
TEST_GEN_PROGS_aarch64 += aarch64/page_fault_test
TEST_GEN_PROGS_aarch64 += aarch64/psci_test
diff --git a/tools/testing/selftests/kvm/aarch64/dump_regs.c b/tools/testing/selftests/kvm/aarch64/dump_regs.c
new file mode 100644
index 000000000000..390b4629ca12
--- /dev/null
+++ b/tools/testing/selftests/kvm/aarch64/dump_regs.c
@@ -0,0 +1,72 @@
+#include <stdint.h>
+#include "kvm_util.h"
+#include "processor.h"
+#include "test_util.h"
+#include <linux/bitfield.h>
+
+static uint64_t masks[KVM_ARM_FEATURE_ID_RANGE_SIZE];
+
+static void guest_code(void)
+{
+}
+
+static void get_writable_masks(struct kvm_vm *vm)
+{
+ struct reg_mask_range range = {
+ .addr = (__u64)masks,
+ };
+
+ memset(range.reserved, 0, sizeof(range.reserved));
+ vm_ioctl(vm, KVM_ARM_GET_REG_WRITABLE_MASKS, &range);
+}
+
+#define kvm_sys_reg_Op0(id) (((id) & KVM_REG_ARM64_SYSREG_OP0_MASK) >> KVM_REG_ARM64_SYSREG_OP0_SHIFT)
+#define kvm_sys_reg_Op1(id) (((id) & KVM_REG_ARM64_SYSREG_OP1_MASK) >> KVM_REG_ARM64_SYSREG_OP1_SHIFT)
+#define kvm_sys_reg_CRn(id) (((id) & KVM_REG_ARM64_SYSREG_CRN_MASK) >> KVM_REG_ARM64_SYSREG_CRN_SHIFT)
+#define kvm_sys_reg_CRm(id) (((id) & KVM_REG_ARM64_SYSREG_CRM_MASK) >> KVM_REG_ARM64_SYSREG_CRM_SHIFT)
+#define kvm_sys_reg_Op2(id) (((id) & KVM_REG_ARM64_SYSREG_OP2_MASK) >> KVM_REG_ARM64_SYSREG_OP2_SHIFT)
+
+static bool reg_in_feature_id_range(uint64_t reg)
+{
+ return kvm_sys_reg_Op0(reg) == 3 &&
+ kvm_sys_reg_Op1(reg) >= 0 && kvm_sys_reg_Op1(reg) <= 3 &&
+ kvm_sys_reg_CRn(reg) == 0 &&
+ kvm_sys_reg_CRm(reg) >= 0 && kvm_sys_reg_CRm(reg) <= 7 &&
+ kvm_sys_reg_Op2(reg) >= 0 && kvm_sys_reg_Op2(reg) <= 7;
+}
+
+static uint64_t reg_get_mask(uint64_t reg)
+{
+ int idx = KVM_ARM_FEATURE_ID_RANGE_IDX(kvm_sys_reg_Op0(reg), kvm_sys_reg_Op1(reg),
+ kvm_sys_reg_CRn(reg), kvm_sys_reg_CRm(reg),
+ kvm_sys_reg_Op2(reg));
+
+ return reg_in_feature_id_range(reg) ? masks[idx] : 0;
+}
+
+static void dump_regs(struct kvm_vcpu *vcpu)
+{
+ struct kvm_reg_list *reg_list = vcpu_get_reg_list(vcpu);
+ uint64_t reg, val[8];
+ int i, ret;
+
+ for (i = 0; i < reg_list->n; i++) {
+ reg = reg_list->reg[i];
+ ret = __vcpu_get_reg(vcpu, reg, val);
+ if (!ret)
+ pr_info("%lx : %16lx %lx\n", reg, val[0], reg_get_mask(reg));
+ }
+
+ free(reg_list);
+}
+
+int main(void)
+{
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+
+ vm = vm_create_with_one_vcpu(&vcpu, guest_code);
+ get_writable_masks(vm);
+ dump_regs(vcpu);
+ kvm_vm_free(vm);
+}
--
2.42.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-03-18 11:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-18 11:16 [RFC] [PATCH 0/4] KVM: arm64: emulation for CTR_EL0 Sebastian Ott
2024-03-18 11:16 ` [PATCH 1/4] KVM: arm64: add emulation for CTR_EL0 register Sebastian Ott
2024-03-18 11:45 ` Marc Zyngier
2024-03-18 11:16 ` [PATCH 2/4] KVM: arm64: ensure guest access to CTR_EL0 is trapped Sebastian Ott
2024-03-18 11:47 ` Marc Zyngier
2024-03-18 11:16 ` [PATCH 3/4] KVM: arm64: show writable masks for feature registers Sebastian Ott
2024-03-18 12:03 ` Marc Zyngier
2024-03-18 18:20 ` Sebastian Ott
2024-03-19 9:50 ` Marc Zyngier
2024-03-18 18:22 ` Sebastian Ott
2024-03-18 11:16 ` Sebastian Ott [this message]
2024-03-18 15:24 ` [RFC] [PATCH 0/4] KVM: arm64: emulation for CTR_EL0 Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240318111636.10613-5-sebott@redhat.com \
--to=sebott@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).