Re: [PATCH] mshv_vtl: Add a per-CPU transition statistics ioctl
From: Naman Jain
Date: Wed Dec 02 2026 - 23:51:11 EST
On 12/3/2026 7:35 AM, Hardik Garg wrote:
On 11/17/2026 12:12 AM, Naman Jain wrote:
The VTL driver does not expose per-CPU transition counts or timing.
This information is important to track number of VTL transitions based
on the use-case, debug issues where a VP gets stuck in VTL2 etc.
Add MSHV_GET_VTL_STATS IOCTL so userspace can query them and print this
information periodically or on error handling paths. Report entry and
return counts, the latest timestamps, and total and maximum interval
durations. Include the last observed state so userspace
can calculate the age of an unfinished interval. These are elapsed times,
not exclusive CPU execution times.
While at it, remove the unused num_vtl0_transitions counter.
Add documentation in a generic VTL interface file. Documentation for
existing ioctls is outside the scope of this patch.
Signed-off-by: Naman Jain<namjain@xxxxxxxxxxxxxxxxxxx>
---
Documentation/virt/hyperv/index.rst | 1 +
Documentation/virt/hyperv/mshv-vtl.rst | 98 ++++++++++++++++++++++++++
drivers/hv/mshv_vtl_main.c | 72 ++++++++++++++++++-
include/uapi/linux/mshv.h | 35 +++++++++
4 files changed, 204 insertions(+), 2 deletions(-)
create mode 100644 Documentation/virt/hyperv/mshv-vtl.rst
<snip>
+nit: the per-CPU variable is named after the uapi struct
+static DEFINE_PER_CPU(struct mshv_vtl_cpu_stats, mshv_vtl_stats) = {
+ .lock = __RAW_SPIN_LOCK_UNLOCKED(mshv_vtl_stats.lock),
+};
(struct mshv_vtl_stats) rather than its own type, which makes
mshv_vtl_ioctl_get_stats() a bit confusing to read and grep:
struct mshv_vtl_stats stats;
...
cpu_stats = per_cpu_ptr(&mshv_vtl_stats, cpu);
Could it be mshv_vtl_cpu_stats, matching how mshv_vtl_poll_file and
mshv_vtl_per_cpu are named?
Acked. I'll change this in v2.
+
static DEFINE_PER_CPU(struct mshv_vtl_per_cpu, mshv_vtl_per_cpu);
static const union hv_input_vtl input_vtl_zero;
@@ -649,6 +660,36 @@ static int mshv_vtl_get_set_reg(struct hv_register_assoc *regs, bool set)
return 1;
}
<snip>
struct mshv_vtl_hvcall_setup {Why use 0x41 here?
__u64 bitmap_array_size; /* stores number of bytes */
__u64 allow_bitmap_ptr;
@@ -392,6 +426,7 @@ struct mshv_sint_mask {
#define MSHV_ADD_VTL0_MEMORY _IOW(MSHV_IOCTL, 0x21, struct mshv_vtl_ram_disposition)
#define MSHV_SET_POLL_FILE _IOW(MSHV_IOCTL, 0x25, struct mshv_vtl_set_poll_file)
#define MSHV_RETURN_TO_LOWER_VTL _IO(MSHV_IOCTL, 0x27)
+#define MSHV_GET_VTL_STATS _IOWR(MSHV_IOCTL, 0x41, struct mshv_vtl_stats)
The VTL fd ioctls in this header currently end at 0x27, and the comment
at the top of the file asks for monotonically increasing numbers per
fd. Could you explain in the commit message why this jumps to 0x41
instead of using 0x28?
This was to avoid a clash with IOCTL numbers already in use by
downstream OpenVMM. On checking further, even 0x41 was reserved for ARM
usecases in OpenVMM, so I would reserve the first available 0x46 for this IOCTL and use it here. I'll also add a note in the commit msg for
the same.
Thanks for reviewing.
Regards,
Naman
#define MSHV_GET_VP_REGISTERS _IOWR(MSHV_IOCTL, 0x05, struct mshv_vp_registers)Thanks,
#define MSHV_SET_VP_REGISTERS _IOW(MSHV_IOCTL, 0x06, struct mshv_vp_registers)
Hardik