Commit 26f84532 authored by David Matlack's avatar David Matlack Committed by Sean Christopherson
Browse files

KVM: selftests: Use u64 instead of uint64_t



Use u64 instead of uint64_t to make the KVM selftests code more concise
and more similar to the kernel (since selftests are primarily developed
by kernel developers).

This commit was generated with the following command:

  git ls-files tools/testing/selftests/kvm | xargs sed -i 's/uint64_t/u64/g'

Then by manually adjusting whitespace to make checkpatch.pl happy.

Include <linux/types.h> in include/kvm_util_types.h, iinclude/test_util.h,
and include/x86/pmu.h to pick up the tools-defined u64.  Arguably, all
headers (especially kvm_util_types.h) should have already been including
stdint.h to get uint64_t from the libc headers, but the missing dependency
only rears its head once KVM uses u64 instead of uint64_t.

No functional change intended.

Signed-off-by: default avatarDavid Matlack <dmatlack@google.com>
[sean: rename pread_uint64() => pread_u64, expand on types.h include]
Link: https://patch.msgid.link/20260420212004.3938325-5-seanjc@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 6d349425
Loading
Loading
Loading
Loading
+22 −22
Original line number Diff line number Diff line
@@ -101,15 +101,15 @@ struct test_params {
	enum vm_mem_backing_src_type backing_src;

	/* The amount of memory to allocate for each vCPU. */
	uint64_t vcpu_memory_bytes;
	u64 vcpu_memory_bytes;

	/* The number of vCPUs to create in the VM. */
	int nr_vcpus;
};

static uint64_t pread_uint64(int fd, const char *filename, uint64_t index)
static u64 pread_u64(int fd, const char *filename, u64 index)
{
	uint64_t value;
	u64 value;
	off_t offset = index * sizeof(value);

	TEST_ASSERT(pread(fd, &value, sizeof(value), offset) == sizeof(value),
@@ -123,13 +123,13 @@ static uint64_t pread_uint64(int fd, const char *filename, uint64_t index)
#define PAGEMAP_PRESENT (1ULL << 63)
#define PAGEMAP_PFN_MASK ((1ULL << 55) - 1)

static uint64_t lookup_pfn(int pagemap_fd, struct kvm_vm *vm, uint64_t gva)
static u64 lookup_pfn(int pagemap_fd, struct kvm_vm *vm, u64 gva)
{
	uint64_t hva = (uint64_t) addr_gva2hva(vm, gva);
	uint64_t entry;
	uint64_t pfn;
	u64 hva = (u64)addr_gva2hva(vm, gva);
	u64 entry;
	u64 pfn;

	entry = pread_uint64(pagemap_fd, "pagemap", hva / getpagesize());
	entry = pread_u64(pagemap_fd, "pagemap", hva / getpagesize());
	if (!(entry & PAGEMAP_PRESENT))
		return 0;

@@ -139,16 +139,16 @@ static uint64_t lookup_pfn(int pagemap_fd, struct kvm_vm *vm, uint64_t gva)
	return pfn;
}

static bool is_page_idle(int page_idle_fd, uint64_t pfn)
static bool is_page_idle(int page_idle_fd, u64 pfn)
{
	uint64_t bits = pread_uint64(page_idle_fd, "page_idle", pfn / 64);
	u64 bits = pread_u64(page_idle_fd, "page_idle", pfn / 64);

	return !!((bits >> (pfn % 64)) & 1);
}

static void mark_page_idle(int page_idle_fd, uint64_t pfn)
static void mark_page_idle(int page_idle_fd, u64 pfn)
{
	uint64_t bits = 1ULL << (pfn % 64);
	u64 bits = 1ULL << (pfn % 64);

	TEST_ASSERT(pwrite(page_idle_fd, &bits, 8, 8 * (pfn / 64)) == 8,
		    "Set page_idle bits for PFN 0x%" PRIx64, pfn);
@@ -174,11 +174,11 @@ static void pageidle_mark_vcpu_memory_idle(struct kvm_vm *vm,
					   struct memstress_vcpu_args *vcpu_args)
{
	int vcpu_idx = vcpu_args->vcpu_idx;
	uint64_t base_gva = vcpu_args->gva;
	uint64_t pages = vcpu_args->pages;
	uint64_t page;
	uint64_t still_idle = 0;
	uint64_t no_pfn = 0;
	u64 base_gva = vcpu_args->gva;
	u64 pages = vcpu_args->pages;
	u64 page;
	u64 still_idle = 0;
	u64 no_pfn = 0;
	int page_idle_fd;
	int pagemap_fd;

@@ -193,8 +193,8 @@ static void pageidle_mark_vcpu_memory_idle(struct kvm_vm *vm,
	TEST_ASSERT(pagemap_fd > 0, "Failed to open pagemap.");

	for (page = 0; page < pages; page++) {
		uint64_t gva = base_gva + page * memstress_args.guest_page_size;
		uint64_t pfn = lookup_pfn(pagemap_fd, vm, gva);
		u64 gva = base_gva + page * memstress_args.guest_page_size;
		u64 pfn = lookup_pfn(pagemap_fd, vm, gva);

		if (!pfn) {
			no_pfn++;
@@ -297,10 +297,10 @@ static void lru_gen_mark_memory_idle(struct kvm_vm *vm)
	lru_gen_last_gen = new_gen;
}

static void assert_ucall(struct kvm_vcpu *vcpu, uint64_t expected_ucall)
static void assert_ucall(struct kvm_vcpu *vcpu, u64 expected_ucall)
{
	struct ucall uc;
	uint64_t actual_ucall = get_ucall(vcpu, &uc);
	u64 actual_ucall = get_ucall(vcpu, &uc);

	TEST_ASSERT(expected_ucall == actual_ucall,
		    "Guest exited unexpectedly (expected ucall %" PRIu64
@@ -417,7 +417,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
	 */
	test_pages = params->nr_vcpus * params->vcpu_memory_bytes /
		      max(memstress_args.guest_page_size,
			  (uint64_t)getpagesize());
			  (u64)getpagesize());

	memstress_start_vcpu_threads(nr_vcpus, vcpu_thread_main);

+7 −7
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ static void test_guest_raz(struct kvm_vcpu *vcpu)
	}
}

static uint64_t raz_wi_reg_ids[] = {
static u64 raz_wi_reg_ids[] = {
	KVM_ARM64_SYS_REG(SYS_ID_PFR0_EL1),
	KVM_ARM64_SYS_REG(SYS_ID_PFR1_EL1),
	KVM_ARM64_SYS_REG(SYS_ID_DFR0_EL1),
@@ -94,8 +94,8 @@ static void test_user_raz_wi(struct kvm_vcpu *vcpu)
	int i;

	for (i = 0; i < ARRAY_SIZE(raz_wi_reg_ids); i++) {
		uint64_t reg_id = raz_wi_reg_ids[i];
		uint64_t val;
		u64 reg_id = raz_wi_reg_ids[i];
		u64 val;

		val = vcpu_get_reg(vcpu, reg_id);
		TEST_ASSERT_EQ(val, 0);
@@ -111,7 +111,7 @@ static void test_user_raz_wi(struct kvm_vcpu *vcpu)
	}
}

static uint64_t raz_invariant_reg_ids[] = {
static u64 raz_invariant_reg_ids[] = {
	KVM_ARM64_SYS_REG(SYS_ID_AFR0_EL1),
	KVM_ARM64_SYS_REG(sys_reg(3, 0, 0, 3, 3)),
	KVM_ARM64_SYS_REG(SYS_ID_DFR1_EL1),
@@ -123,8 +123,8 @@ static void test_user_raz_invariant(struct kvm_vcpu *vcpu)
	int i, r;

	for (i = 0; i < ARRAY_SIZE(raz_invariant_reg_ids); i++) {
		uint64_t reg_id = raz_invariant_reg_ids[i];
		uint64_t val;
		u64 reg_id = raz_invariant_reg_ids[i];
		u64 val;

		val = vcpu_get_reg(vcpu, reg_id);
		TEST_ASSERT_EQ(val, 0);
@@ -142,7 +142,7 @@ static void test_user_raz_invariant(struct kvm_vcpu *vcpu)

static bool vcpu_aarch64_only(struct kvm_vcpu *vcpu)
{
	uint64_t val, el0;
	u64 val, el0;

	val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1));

+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ static void guest_validate_irq(unsigned int intid,
				struct test_vcpu_shared_data *shared_data)
{
	enum guest_stage stage = shared_data->guest_stage;
	uint64_t xcnt = 0, xcnt_diff_us, cval = 0;
	u64 xcnt = 0, xcnt_diff_us, cval = 0;
	unsigned long xctl = 0;
	unsigned int timer_irq = 0;
	unsigned int accessor;
+59 −60
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
#include "vgic.h"

/* Depends on counter width. */
static uint64_t CVAL_MAX;
static u64 CVAL_MAX;
/* tval is a signed 32-bit int. */
static const int32_t TVAL_MAX = INT32_MAX;
static const int32_t TVAL_MIN = INT32_MIN;
@@ -32,7 +32,7 @@ static const int32_t TVAL_MIN = INT32_MIN;
static const uint32_t TIMEOUT_NO_IRQ_US = 50000;

/* Counter value to use as the starting one for most tests. Set to CVAL_MAX/2 */
static uint64_t DEF_CNT;
static u64 DEF_CNT;

/* Number of runs. */
static const uint32_t NR_TEST_ITERS_DEF = 5;
@@ -53,9 +53,9 @@ struct test_args {
	/* Virtual or physical timer and counter tests. */
	enum arch_timer timer;
	/* Delay used for most timer tests. */
	uint64_t wait_ms;
	u64 wait_ms;
	/* Delay used in the test_long_timer_delays test. */
	uint64_t long_wait_ms;
	u64 long_wait_ms;
	/* Number of iterations. */
	int iterations;
	/* Whether to test the physical timer. */
@@ -82,12 +82,12 @@ enum sync_cmd {
	NO_USERSPACE_CMD,
};

typedef void (*sleep_method_t)(enum arch_timer timer, uint64_t usec);
typedef void (*sleep_method_t)(enum arch_timer timer, u64 usec);

static void sleep_poll(enum arch_timer timer, uint64_t usec);
static void sleep_sched_poll(enum arch_timer timer, uint64_t usec);
static void sleep_in_userspace(enum arch_timer timer, uint64_t usec);
static void sleep_migrate(enum arch_timer timer, uint64_t usec);
static void sleep_poll(enum arch_timer timer, u64 usec);
static void sleep_sched_poll(enum arch_timer timer, u64 usec);
static void sleep_in_userspace(enum arch_timer timer, u64 usec);
static void sleep_migrate(enum arch_timer timer, u64 usec);

sleep_method_t sleep_method[] = {
	sleep_poll,
@@ -122,7 +122,7 @@ static void assert_irqs_handled(uint32_t n)
	__GUEST_ASSERT(h == n, "Handled %d IRQS but expected %d", h, n);
}

static void userspace_cmd(uint64_t cmd)
static void userspace_cmd(u64 cmd)
{
	GUEST_SYNC_ARGS(cmd, 0, 0, 0, 0);
}
@@ -132,12 +132,12 @@ static void userspace_migrate_vcpu(void)
	userspace_cmd(USERSPACE_MIGRATE_SELF);
}

static void userspace_sleep(uint64_t usecs)
static void userspace_sleep(u64 usecs)
{
	GUEST_SYNC_ARGS(USERSPACE_USLEEP, usecs, 0, 0, 0);
}

static void set_counter(enum arch_timer timer, uint64_t counter)
static void set_counter(enum arch_timer timer, u64 counter)
{
	GUEST_SYNC_ARGS(SET_COUNTER_VALUE, counter, timer, 0, 0);
}
@@ -146,7 +146,7 @@ static void guest_irq_handler(struct ex_regs *regs)
{
	unsigned int intid = gic_get_and_ack_irq();
	enum arch_timer timer;
	uint64_t cnt, cval;
	u64 cnt, cval;
	uint32_t ctl;
	bool timer_condition, istatus;

@@ -178,7 +178,7 @@ static void guest_irq_handler(struct ex_regs *regs)
	gic_set_eoi(intid);
}

static void set_cval_irq(enum arch_timer timer, uint64_t cval_cycles,
static void set_cval_irq(enum arch_timer timer, u64 cval_cycles,
			 uint32_t ctl)
{
	atomic_set(&shared_data.handled, 0);
@@ -187,7 +187,7 @@ static void set_cval_irq(enum arch_timer timer, uint64_t cval_cycles,
	timer_set_ctl(timer, ctl);
}

static void set_tval_irq(enum arch_timer timer, uint64_t tval_cycles,
static void set_tval_irq(enum arch_timer timer, u64 tval_cycles,
			 uint32_t ctl)
{
	atomic_set(&shared_data.handled, 0);
@@ -196,7 +196,7 @@ static void set_tval_irq(enum arch_timer timer, uint64_t tval_cycles,
	timer_set_ctl(timer, ctl);
}

static void set_xval_irq(enum arch_timer timer, uint64_t xval, uint32_t ctl,
static void set_xval_irq(enum arch_timer timer, u64 xval, uint32_t ctl,
			 enum timer_view tv)
{
	switch (tv) {
@@ -275,13 +275,13 @@ static void wait_migrate_poll_for_irq(void)
 * Sleep for usec microseconds by polling in the guest or in
 * userspace (e.g. userspace_cmd=USERSPACE_SCHEDULE).
 */
static void guest_poll(enum arch_timer test_timer, uint64_t usec,
static void guest_poll(enum arch_timer test_timer, u64 usec,
		       enum sync_cmd usp_cmd)
{
	uint64_t cycles = usec_to_cycles(usec);
	u64 cycles = usec_to_cycles(usec);
	/* Whichever timer we are testing with, sleep with the other. */
	enum arch_timer sleep_timer = 1 - test_timer;
	uint64_t start = timer_get_cntct(sleep_timer);
	u64 start = timer_get_cntct(sleep_timer);

	while ((timer_get_cntct(sleep_timer) - start) < cycles) {
		if (usp_cmd == NO_USERSPACE_CMD)
@@ -291,22 +291,22 @@ static void guest_poll(enum arch_timer test_timer, uint64_t usec,
	}
}

static void sleep_poll(enum arch_timer timer, uint64_t usec)
static void sleep_poll(enum arch_timer timer, u64 usec)
{
	guest_poll(timer, usec, NO_USERSPACE_CMD);
}

static void sleep_sched_poll(enum arch_timer timer, uint64_t usec)
static void sleep_sched_poll(enum arch_timer timer, u64 usec)
{
	guest_poll(timer, usec, USERSPACE_SCHED_YIELD);
}

static void sleep_migrate(enum arch_timer timer, uint64_t usec)
static void sleep_migrate(enum arch_timer timer, u64 usec)
{
	guest_poll(timer, usec, USERSPACE_MIGRATE_SELF);
}

static void sleep_in_userspace(enum arch_timer timer, uint64_t usec)
static void sleep_in_userspace(enum arch_timer timer, u64 usec)
{
	userspace_sleep(usec);
}
@@ -315,15 +315,15 @@ static void sleep_in_userspace(enum arch_timer timer, uint64_t usec)
 * Reset the timer state to some nice values like the counter not being close
 * to the edge, and the control register masked and disabled.
 */
static void reset_timer_state(enum arch_timer timer, uint64_t cnt)
static void reset_timer_state(enum arch_timer timer, u64 cnt)
{
	set_counter(timer, cnt);
	timer_set_ctl(timer, CTL_IMASK);
}

static void test_timer_xval(enum arch_timer timer, uint64_t xval,
static void test_timer_xval(enum arch_timer timer, u64 xval,
			    enum timer_view tv, irq_wait_method_t wm, bool reset_state,
			    uint64_t reset_cnt)
			    u64 reset_cnt)
{
	local_irq_disable();

@@ -348,23 +348,23 @@ static void test_timer_xval(enum arch_timer timer, uint64_t xval,
 * the "runner", like: tools/testing/selftests/kselftest/runner.sh.
 */

static void test_timer_cval(enum arch_timer timer, uint64_t cval,
static void test_timer_cval(enum arch_timer timer, u64 cval,
			    irq_wait_method_t wm, bool reset_state,
			    uint64_t reset_cnt)
			    u64 reset_cnt)
{
	test_timer_xval(timer, cval, TIMER_CVAL, wm, reset_state, reset_cnt);
}

static void test_timer_tval(enum arch_timer timer, int32_t tval,
			    irq_wait_method_t wm, bool reset_state,
			    uint64_t reset_cnt)
			    u64 reset_cnt)
{
	test_timer_xval(timer, (uint64_t) tval, TIMER_TVAL, wm, reset_state,
	test_timer_xval(timer, (u64)tval, TIMER_TVAL, wm, reset_state,
			reset_cnt);
}

static void test_xval_check_no_irq(enum arch_timer timer, uint64_t xval,
				   uint64_t usec, enum timer_view timer_view,
static void test_xval_check_no_irq(enum arch_timer timer, u64 xval,
				   u64 usec, enum timer_view timer_view,
				   sleep_method_t guest_sleep)
{
	local_irq_disable();
@@ -379,17 +379,17 @@ static void test_xval_check_no_irq(enum arch_timer timer, uint64_t xval,
	assert_irqs_handled(0);
}

static void test_cval_no_irq(enum arch_timer timer, uint64_t cval,
			     uint64_t usec, sleep_method_t wm)
static void test_cval_no_irq(enum arch_timer timer, u64 cval,
			     u64 usec, sleep_method_t wm)
{
	test_xval_check_no_irq(timer, cval, usec, TIMER_CVAL, wm);
}

static void test_tval_no_irq(enum arch_timer timer, int32_t tval, uint64_t usec,
static void test_tval_no_irq(enum arch_timer timer, int32_t tval, u64 usec,
			     sleep_method_t wm)
{
	/* tval will be cast to an int32_t in test_xval_check_no_irq */
	test_xval_check_no_irq(timer, (uint64_t) tval, usec, TIMER_TVAL, wm);
	test_xval_check_no_irq(timer, (u64)tval, usec, TIMER_TVAL, wm);
}

/* Test masking/unmasking a timer using the timer mask (not the IRQ mask). */
@@ -488,7 +488,7 @@ static void test_reprogramming_timer(enum arch_timer timer, irq_wait_method_t wm
static void test_reprogram_timers(enum arch_timer timer)
{
	int i;
	uint64_t base_wait = test_args.wait_ms;
	u64 base_wait = test_args.wait_ms;

	for (i = 0; i < ARRAY_SIZE(irq_wait_method); i++) {
		/*
@@ -505,7 +505,7 @@ static void test_reprogram_timers(enum arch_timer timer)
static void test_basic_functionality(enum arch_timer timer)
{
	int32_t tval = (int32_t) msec_to_cycles(test_args.wait_ms);
	uint64_t cval = DEF_CNT + msec_to_cycles(test_args.wait_ms);
	u64 cval = DEF_CNT + msec_to_cycles(test_args.wait_ms);
	int i;

	for (i = 0; i < ARRAY_SIZE(irq_wait_method); i++) {
@@ -593,7 +593,7 @@ static void test_set_cnt_after_tval_max(enum arch_timer timer, irq_wait_method_t
	reset_timer_state(timer, DEF_CNT);

	set_cval_irq(timer,
		     (uint64_t) TVAL_MAX +
		     (u64)TVAL_MAX +
		     msec_to_cycles(test_args.wait_ms) / 2, CTL_ENABLE);

	set_counter(timer, TVAL_MAX);
@@ -608,7 +608,7 @@ static void test_set_cnt_after_tval_max(enum arch_timer timer, irq_wait_method_t
/* Test timers set for: cval = now + TVAL_MAX + wait_ms / 2 */
static void test_timers_above_tval_max(enum arch_timer timer)
{
	uint64_t cval;
	u64 cval;
	int i;

	/*
@@ -638,8 +638,8 @@ static void test_timers_above_tval_max(enum arch_timer timer)
 * sets the counter to cnt_1, the [c|t]val, the counter to cnt_2, and
 * then waits for an IRQ.
 */
static void test_set_cnt_after_xval(enum arch_timer timer, uint64_t cnt_1,
				    uint64_t xval, uint64_t cnt_2,
static void test_set_cnt_after_xval(enum arch_timer timer, u64 cnt_1,
				    u64 xval, u64 cnt_2,
				    irq_wait_method_t wm, enum timer_view tv)
{
	local_irq_disable();
@@ -662,8 +662,8 @@ static void test_set_cnt_after_xval(enum arch_timer timer, uint64_t cnt_1,
 * then waits for an IRQ.
 */
static void test_set_cnt_after_xval_no_irq(enum arch_timer timer,
					   uint64_t cnt_1, uint64_t xval,
					   uint64_t cnt_2,
					   u64 cnt_1, u64 xval,
					   u64 cnt_2,
					   sleep_method_t guest_sleep,
					   enum timer_view tv)
{
@@ -684,31 +684,31 @@ static void test_set_cnt_after_xval_no_irq(enum arch_timer timer,
	timer_set_ctl(timer, CTL_IMASK);
}

static void test_set_cnt_after_tval(enum arch_timer timer, uint64_t cnt_1,
				    int32_t tval, uint64_t cnt_2,
static void test_set_cnt_after_tval(enum arch_timer timer, u64 cnt_1,
				    int32_t tval, u64 cnt_2,
				    irq_wait_method_t wm)
{
	test_set_cnt_after_xval(timer, cnt_1, tval, cnt_2, wm, TIMER_TVAL);
}

static void test_set_cnt_after_cval(enum arch_timer timer, uint64_t cnt_1,
				    uint64_t cval, uint64_t cnt_2,
static void test_set_cnt_after_cval(enum arch_timer timer, u64 cnt_1,
				    u64 cval, u64 cnt_2,
				    irq_wait_method_t wm)
{
	test_set_cnt_after_xval(timer, cnt_1, cval, cnt_2, wm, TIMER_CVAL);
}

static void test_set_cnt_after_tval_no_irq(enum arch_timer timer,
					   uint64_t cnt_1, int32_t tval,
					   uint64_t cnt_2, sleep_method_t wm)
					   u64 cnt_1, int32_t tval,
					   u64 cnt_2, sleep_method_t wm)
{
	test_set_cnt_after_xval_no_irq(timer, cnt_1, tval, cnt_2, wm,
				       TIMER_TVAL);
}

static void test_set_cnt_after_cval_no_irq(enum arch_timer timer,
					   uint64_t cnt_1, uint64_t cval,
					   uint64_t cnt_2, sleep_method_t wm)
					   u64 cnt_1, u64 cval,
					   u64 cnt_2, sleep_method_t wm)
{
	test_set_cnt_after_xval_no_irq(timer, cnt_1, cval, cnt_2, wm,
				       TIMER_CVAL);
@@ -730,8 +730,7 @@ static void test_move_counters_ahead_of_timers(enum arch_timer timer)
		test_set_cnt_after_tval(timer, 0, -1, DEF_CNT + 1, wm);
		test_set_cnt_after_tval(timer, 0, -1, TVAL_MAX, wm);
		tval = TVAL_MAX;
		test_set_cnt_after_tval(timer, 0, tval, (uint64_t) tval + 1,
					wm);
		test_set_cnt_after_tval(timer, 0, tval, (u64)tval + 1, wm);
	}
}

@@ -755,7 +754,7 @@ static void test_move_counters_behind_timers(enum arch_timer timer)
static void test_timers_in_the_past(enum arch_timer timer)
{
	int32_t tval = -1 * (int32_t) msec_to_cycles(test_args.wait_ms);
	uint64_t cval;
	u64 cval;
	int i;

	for (i = 0; i < ARRAY_SIZE(irq_wait_method); i++) {
@@ -791,7 +790,7 @@ static void test_timers_in_the_past(enum arch_timer timer)
static void test_long_timer_delays(enum arch_timer timer)
{
	int32_t tval = (int32_t) msec_to_cycles(test_args.long_wait_ms);
	uint64_t cval = DEF_CNT + msec_to_cycles(test_args.long_wait_ms);
	u64 cval = DEF_CNT + msec_to_cycles(test_args.long_wait_ms);
	int i;

	for (i = 0; i < ARRAY_SIZE(irq_wait_method); i++) {
@@ -862,7 +861,7 @@ static uint32_t next_pcpu(void)
	return next;
}

static void kvm_set_cntxct(struct kvm_vcpu *vcpu, uint64_t cnt,
static void kvm_set_cntxct(struct kvm_vcpu *vcpu, u64 cnt,
			   enum arch_timer timer)
{
	if (timer == PHYSICAL)
@@ -874,7 +873,7 @@ static void kvm_set_cntxct(struct kvm_vcpu *vcpu, uint64_t cnt,
static void handle_sync(struct kvm_vcpu *vcpu, struct ucall *uc)
{
	enum sync_cmd cmd = uc->args[1];
	uint64_t val = uc->args[2];
	u64 val = uc->args[2];
	enum arch_timer timer = uc->args[3];

	switch (cmd) {
@@ -1018,8 +1017,8 @@ static bool parse_args(int argc, char *argv[])

static void set_counter_defaults(void)
{
	const uint64_t MIN_ROLLOVER_SECS = 40ULL * 365 * 24 * 3600;
	uint64_t freq = read_sysreg(CNTFRQ_EL0);
	const u64 MIN_ROLLOVER_SECS = 40ULL * 365 * 24 * 3600;
	u64 freq = read_sysreg(CNTFRQ_EL0);
	int width = ilog2(MIN_ROLLOVER_SECS * freq);

	width = clamp(width, 56, 64);
+27 −27
Original line number Diff line number Diff line
@@ -31,14 +31,14 @@

extern unsigned char sw_bp, sw_bp2, hw_bp, hw_bp2, bp_svc, bp_brk, hw_wp, ss_start, hw_bp_ctx;
extern unsigned char iter_ss_begin, iter_ss_end;
static volatile uint64_t sw_bp_addr, hw_bp_addr;
static volatile uint64_t wp_addr, wp_data_addr;
static volatile uint64_t svc_addr;
static volatile uint64_t ss_addr[4], ss_idx;
#define  PC(v)  ((uint64_t)&(v))
static volatile u64 sw_bp_addr, hw_bp_addr;
static volatile u64 wp_addr, wp_data_addr;
static volatile u64 svc_addr;
static volatile u64 ss_addr[4], ss_idx;
#define  PC(v)  ((u64)&(v))

#define GEN_DEBUG_WRITE_REG(reg_name)			\
static void write_##reg_name(int num, uint64_t val)	\
static void write_##reg_name(int num, u64 val)	\
{							\
	switch (num) {					\
	case 0:						\
@@ -103,7 +103,7 @@ GEN_DEBUG_WRITE_REG(dbgwvr)
static void reset_debug_state(void)
{
	uint8_t brps, wrps, i;
	uint64_t dfr0;
	u64 dfr0;

	asm volatile("msr daifset, #8");

@@ -140,7 +140,7 @@ static void enable_os_lock(void)

static void enable_monitor_debug_exceptions(void)
{
	uint64_t mdscr;
	u64 mdscr;

	asm volatile("msr daifclr, #8");

@@ -149,7 +149,7 @@ static void enable_monitor_debug_exceptions(void)
	isb();
}

static void install_wp(uint8_t wpn, uint64_t addr)
static void install_wp(uint8_t wpn, u64 addr)
{
	uint32_t wcr;

@@ -162,7 +162,7 @@ static void install_wp(uint8_t wpn, uint64_t addr)
	enable_monitor_debug_exceptions();
}

static void install_hw_bp(uint8_t bpn, uint64_t addr)
static void install_hw_bp(uint8_t bpn, u64 addr)
{
	uint32_t bcr;

@@ -174,11 +174,11 @@ static void install_hw_bp(uint8_t bpn, uint64_t addr)
	enable_monitor_debug_exceptions();
}

static void install_wp_ctx(uint8_t addr_wp, uint8_t ctx_bp, uint64_t addr,
			   uint64_t ctx)
static void install_wp_ctx(uint8_t addr_wp, uint8_t ctx_bp, u64 addr,
			   u64 ctx)
{
	uint32_t wcr;
	uint64_t ctx_bcr;
	u64 ctx_bcr;

	/* Setup a context-aware breakpoint for Linked Context ID Match */
	ctx_bcr = DBGBCR_LEN8 | DBGBCR_EXEC | DBGBCR_EL1 | DBGBCR_E |
@@ -196,8 +196,8 @@ static void install_wp_ctx(uint8_t addr_wp, uint8_t ctx_bp, uint64_t addr,
	enable_monitor_debug_exceptions();
}

void install_hw_bp_ctx(uint8_t addr_bp, uint8_t ctx_bp, uint64_t addr,
		       uint64_t ctx)
void install_hw_bp_ctx(uint8_t addr_bp, uint8_t ctx_bp, u64 addr,
		       u64 ctx)
{
	uint32_t addr_bcr, ctx_bcr;

@@ -223,7 +223,7 @@ void install_hw_bp_ctx(uint8_t addr_bp, uint8_t ctx_bp, uint64_t addr,

static void install_ss(void)
{
	uint64_t mdscr;
	u64 mdscr;

	asm volatile("msr daifclr, #8");

@@ -236,7 +236,7 @@ static volatile char write_data;

static void guest_code(uint8_t bpn, uint8_t wpn, uint8_t ctx_bpn)
{
	uint64_t ctx = 0xabcdef;	/* a random context number */
	u64 ctx = 0xabcdef;	/* a random context number */

	/* Software-breakpoint */
	reset_debug_state();
@@ -377,8 +377,8 @@ static void guest_svc_handler(struct ex_regs *regs)

static void guest_code_ss(int test_cnt)
{
	uint64_t i;
	uint64_t bvr, wvr, w_bvr, w_wvr;
	u64 i;
	u64 bvr, wvr, w_bvr, w_wvr;

	for (i = 0; i < test_cnt; i++) {
		/* Bits [1:0] of dbg{b,w}vr are RES0 */
@@ -416,7 +416,7 @@ static void guest_code_ss(int test_cnt)
	GUEST_DONE();
}

static int debug_version(uint64_t id_aa64dfr0)
static int debug_version(u64 id_aa64dfr0)
{
	return FIELD_GET(ID_AA64DFR0_EL1_DebugVer, id_aa64dfr0);
}
@@ -468,8 +468,8 @@ void test_single_step_from_userspace(int test_cnt)
	struct kvm_vm *vm;
	struct ucall uc;
	struct kvm_run *run;
	uint64_t pc, cmd;
	uint64_t test_pc = 0;
	u64 pc, cmd;
	u64 test_pc = 0;
	bool ss_enable = false;
	struct kvm_guest_debug debug = {};

@@ -506,7 +506,7 @@ void test_single_step_from_userspace(int test_cnt)
			    "Unexpected pc 0x%lx (expected 0x%lx)",
			    pc, test_pc);

		if ((pc + 4) == (uint64_t)&iter_ss_end) {
		if ((pc + 4) == (u64)&iter_ss_end) {
			test_pc = 0;
			debug.control = KVM_GUESTDBG_ENABLE;
			ss_enable = false;
@@ -519,8 +519,8 @@ void test_single_step_from_userspace(int test_cnt)
		 * iter_ss_end, the pc for the next KVM_EXIT_DEBUG should
		 * be the current pc + 4.
		 */
		if ((pc >= (uint64_t)&iter_ss_begin) &&
		    (pc < (uint64_t)&iter_ss_end))
		if ((pc >= (u64)&iter_ss_begin) &&
		    (pc < (u64)&iter_ss_end))
			test_pc = pc + 4;
		else
			test_pc = 0;
@@ -533,7 +533,7 @@ void test_single_step_from_userspace(int test_cnt)
 * Run debug testing using the various breakpoint#, watchpoint# and
 * context-aware breakpoint# with the given ID_AA64DFR0_EL1 configuration.
 */
void test_guest_debug_exceptions_all(uint64_t aa64dfr0)
void test_guest_debug_exceptions_all(u64 aa64dfr0)
{
	uint8_t brp_num, wrp_num, ctx_brp_num, normal_brp_num, ctx_brp_base;
	int b, w, c;
@@ -580,7 +580,7 @@ int main(int argc, char *argv[])
	struct kvm_vm *vm;
	int opt;
	int ss_iteration = 10000;
	uint64_t aa64dfr0;
	u64 aa64dfr0;

	vm = vm_create_with_one_vcpu(&vcpu, guest_code);
	aa64dfr0 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1));
Loading