Re: [PATCH v2 02/14] KVM: selftests: Add helper functions for IRQ testing

Sean Christopherson
2026-04-01T18:26:04Z

On Tue, Mar 31, 2026, Josh Hilke wrote:
> diff --git a/tools/testing/selftests/kvm/include/irq_util.h b/tools/testing/selftests/kvm/include/irq_util.h
> new file mode 100644
> index 000000000000..a5d6b63b30da
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/include/irq_util.h
> @@ -0,0 +1,11 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef SELFTEST_KVM_PROC_UTIL_H
> +#define SELFTEST_KVM_PROC_UTIL_H
> +
> +#include <stdint.h>
> +
> +int get_irq_number(const char *device_bdf, int msi);
> +uint64_t get_irq_count(int irq);
> +uint64_t get_irq_count_by_name(const char *name);

These are far too generic. I'm also not convinced these should exist at all.
I'll add more context in the next patch.

> +#endif /* SELFTEST_KVM_PROC_UTIL_H */
> diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
> index 8b39cb919f4f..8be02e7980eb 100644
> --- a/tools/testing/selftests/kvm/include/kvm_util.h
> +++ b/tools/testing/selftests/kvm/include/kvm_util.h
> @@ -1144,6 +1144,17 @@ vm_adjust_num_guest_pages(enum vm_guest_mode mode, unsigned int num_guest_pages)
> memcpy(&(g), _p, sizeof(g)); \
> })
>
> +#define READ_FROM_GUEST(_vm, _variable) ({ \
> + sync_global_from_guest(_vm, _variable); \
> + READ_ONCE(_variable); \
> +})
> +
> +#define WRITE_TO_GUEST(_vm, _variable, _value) do { \
> + WRITE_ONCE(_variable, _value); \
> + sync_global_to_guest(_vm, _variable); \
> +} while (0)

These belong in a separate patch. I also think we should convert as many users
as possible when they're introduced.

We might want a better name than WRITE_TO_GUEST(), because that suggests it _just_
writes to guest, but it also writes to the host value. Maybe SYNC_FROM_GUEST_AND_READ()
and WRITE_AND_SYNC_TO_GUEST()? Stupidly verbose, but IMO it doesn't look too weird
in the code.

> +
> +

Unnecessary newline.

> /*
> * Write a global value, but only in the VM's (guest's) domain. Primarily used
> * for "globals" that hold per-VM values (VMs always duplicate code and global