Skip to contentSkip to conversation

mshv: Debugfs interface for mshv_root

PATCH Applied Nuno Das Neves 4 participants 11 messages Jan 28 – Feb 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v6 cover mshv: Debugfs interface for mshv_root

Expose hypervisor, logical processor, partition, and virtual processor statistics via debugfs. These are provided by mapping 'stats' pages via hypercall.

Patch #1: Update hv_call_map_stats_page() to return success when
HV_STATS_AREA_PARENT is unavailable, which is the case on some hypervisor versions, where it can fall back to HV_STATS_AREA_SELF
Patch #2: Use struct hv_stats_page pointers instead of void * Patch #3: Make mshv_vp_stats_map/unmap() more flexible to use with debugfs
code
Patch #4: Always map vp stats page regardless of scheduler, to reuse in
debugfs
Patch #5: Change to hv_stats_page definition and
VpRootDispatchThreadBlocked
Patch #6: Introduce the definitions needed for the various stats pages Patch #7: Add mshv_debugfs.c, and integrate it with the mshv_root driver to
expose the partition and VP stats.

---
Changes in v6:
- Fix whitespace and other checkpatch issues [Michael]

Changes in v5:
- Rename hv_counters.c to mshv_debugfs_counters.c [Michael]
- Clarify unusual inclusion of mshv_debugfs_counters.c with comment. After discussion it is still included directly to keep things simple. Including arrays with unspecified size via a header means sizeof() cannot be used on the array.
- Error if mshv_debugfs_counters.c is included elsewhere than mshv_debugfs.c
- Use array index as stats page index to save space [Stanislav]
- Enforce HV_STATS_AREA_PARENT and SELF fit in NUM_STATS_AREAS with static_assert and clarify with comment [Michael]
- Return to using lp count from hv stats page for mshv_lps_count [Michael]
- Use nr_cpu_ids instead of num_possible_cpus() [Michael]
- Set mshv_lps_stats[idx] and the array itself to NULL on unmap and cleanup [Michael]
- Rename HvLogicalProcessors and VpRootDispatchThreadBlocked to Linux style
- Translate Linux cpu index to vp index via hv_vp_index on partition destroy [Michael]
- Minor formatting cleanups [Michael]

Changes in v4:
- Put the counters definitions in static arrays in hv_counters.c, instead of as enums in hvhdk.h [Michael]
- Due to the above, add an additional patch (#5) to simplify hv_stats_page, and retain the enum definition at the top of mshv_root_main.c for use with VpRootDispatchThreadBlocked. That is the only remaining use of the counter enum.
- Due to the above, use num_present_cpus() as the number of LPs to map stats pages for - this number shouldn't change at runtime because the hypervisor doesn't support hotplug for root partition.

Changes in v3:
- Add 3 small refactor/cleanup patches (patches 2,3,4) from Stanislav. These simplify some of the debugfs code, and fix issues with mapping VP stats on L1VH.
- Fix cleanup of parent stats dentries on module removal (via squashing some internal patches into patch #6) [Praveen]
- Remove unused goto label [Stanislav, kernel bot]
- Use struct hv_stats_page * instead of void * in mshv_debugfs.c [Stanislav]
- Remove some redundant variables [Stanislav]
- Rename debugfs dentry fields for brevity [Stanislav]
- Use ERR_CAST() for the dentry error pointer returned from lp_debugfs_stats_create() [Stanislav]
- Fix leak of pages allocated for lp stats mappings by storing them in an array [Michael]
- Add comments to clarify PARENT vs SELF usage and edge cases [Michael]
- Add VpLoadAvg for x86 and print the stat [Michael]
- Add NUM_STATS_AREAS for array sizing in mshv_debugfs.c [Michael]

Changes in v2:
- Remove unnecessary pr_debug_once() in patch 1 [Stanislav Kinsburskii]
- CONFIG_X86 -> CONFIG_X86_64 in patch 2 [Stanislav Kinsburskii]

---
Nuno Das Neves (3):
mshv: Update hv_stats_page definitions
mshv: Add data for printing stats page counters
mshv: Add debugfs to view hypervisor statistics

Purna Pavan Chandra Aekkaladevi (1):
mshv: Ignore second stats page map result failure

Stanislav Kinsburskii (3):
mshv: Use typed hv_stats_page pointers
mshv: Improve mshv_vp_stats_map/unmap(), add them to mshv_root.h
mshv: Always map child vp stats pages regardless of scheduler type

 drivers/hv/Makefile                |   1 +
 drivers/hv/mshv_debugfs.c          | 726 +++++++++++++++++++++++++++++
 drivers/hv/mshv_debugfs_counters.c | 490 +++++++++++++++++++
 drivers/hv/mshv_root.h             |  49 +-
 drivers/hv/mshv_root_hv_call.c     |  64 ++-
 drivers/hv/mshv_root_main.c        | 140 +++---
 include/hyperv/hvhdk.h             |   7 +
 7 files changed, 1412 insertions(+), 65 deletions(-)
 create mode 100644 drivers/hv/mshv_debugfs.c
 create mode 100644 drivers/hv/mshv_debugfs_counters.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v6 1/7 mshv: Ignore second stats page map result failure

From: Purna Pavan Chandra Aekkaladevi <[email protected]>

Older versions of the hypervisor do not have a concept of separate SELF and PARENT stats areas. In this case, mapping the HV_STATS_AREA_SELF page is sufficient - it's the only page and it contains all available stats.

Mapping HV_STATS_AREA_PARENT returns HV_STATUS_INVALID_PARAMETER which currently causes module init to fail on older hypevisor versions.

Detect this case and gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped SELF page.

Add comments to clarify the behavior, including a clarification of why this isn't needed for hv_call_map_stats_page2() which always supports PARENT and SELF areas.

---
 drivers/hv/mshv_root_hv_call.c | 52 +++++++++++++++++++++++++++++++---
 drivers/hv/mshv_root_main.c    |  3 ++
 2 files changed, 51 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_hv_call.c +48 -4
index 598eaff4ff29..1f93b94d7580 100644
@@ -813,6 +813,13 @@ hv_call_notify_port_ring_empty(u32 sint_index)
 	return hv_result_to_errno(status);
 }
 
+/*
+ * Equivalent of hv_call_map_stats_page() for cases when the caller provides
+ * the map location.
+ *
+ * NOTE: This is a newer hypercall that always supports SELF and PARENT stats
+ * areas, unlike hv_call_map_stats_page().
+ */
 static int hv_call_map_stats_page2(enum hv_stats_object_type type,
 				   const union hv_stats_object_identity *identity,
 				   u64 map_location)
@@ -855,6 +862,34 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
 	return ret;
 }
 
+static int
+hv_stats_get_area_type(enum hv_stats_object_type type,
+		       const union hv_stats_object_identity *identity)
+{
+	switch (type) {
+	case HV_STATS_OBJECT_HYPERVISOR:
+		return identity->hv.stats_area_type;
+	case HV_STATS_OBJECT_LOGICAL_PROCESSOR:
+		return identity->lp.stats_area_type;
+	case HV_STATS_OBJECT_PARTITION:
+		return identity->partition.stats_area_type;
+	case HV_STATS_OBJECT_VP:
+		return identity->vp.stats_area_type;
+	}
+
+	return -EINVAL;
+}
+
+/*
+ * Map a stats page, where the page location is provided by the hypervisor.
+ *
+ * NOTE: The concept of separate SELF and PARENT stats areas does not exist on
+ * older hypervisor versions. All the available stats information can be found
+ * on the SELF page. When attempting to map the PARENT area on a hypervisor
+ * that doesn't support it, return "success" but with a NULL address. The
+ * caller should check for this case and instead fallback to the SELF area
+ * alone.
+ */
 static int hv_call_map_stats_page(enum hv_stats_object_type type,
 				  const union hv_stats_object_identity *identity,
 				  void **addr)
@@ -863,7 +898,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
 	struct hv_input_map_stats_page *input;
 	struct hv_output_map_stats_page *output;
 	u64 status, pfn;
-	int ret = 0;
+	int hv_status, ret = 0;
 
 	do {
 		local_irq_save(flags);
@@ -878,11 +913,20 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
 		pfn = output->map_location;
 
 		local_irq_restore(flags);
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
-			ret = hv_result_to_errno(status);
+
+		hv_status = hv_result(status);
+		if (hv_status != HV_STATUS_INSUFFICIENT_MEMORY) {
 			if (hv_result_success(status))
 				break;
-			return ret;
+
+			if (hv_stats_get_area_type(type, identity) == HV_STATS_AREA_PARENT &&
+			    hv_status == HV_STATUS_INVALID_PARAMETER) {
+				*addr = NULL;
+				return 0;
+			}
+
+			hv_status_debug(status, "\n");
+			return hv_result_to_errno(status);
 		}
 
 		ret = hv_call_deposit_pages(NUMA_NO_NODE,
drivers/hv/mshv_root_main.c +3 -0
index 1134a82c7881..1777778f84b8 100644
@@ -992,6 +992,9 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
 	if (err)
 		goto unmap_self;
 
+	if (!stats_pages[HV_STATS_AREA_PARENT])
+		stats_pages[HV_STATS_AREA_PARENT] = stats_pages[HV_STATS_AREA_SELF];
+
 	return 0;
 
 unmap_self:
Signature · 1 line
2.34.1
#2 lore raw

PATCH v6 2/7 mshv: Use typed hv_stats_page pointers

In reply to Nuno Das Neves

From: Stanislav Kinsburskii <[email protected]>

Refactor all relevant functions to use struct hv_stats_page pointers instead of void pointers for stats page mapping and unmapping thus improving type safety and code clarity across the Hyper-V stats mapping APIs.

---
 drivers/hv/mshv_root.h         |  5 +++--
 drivers/hv/mshv_root_hv_call.c | 12 +++++++-----
 drivers/hv/mshv_root_main.c    |  8 ++++----
 3 files changed, 14 insertions(+), 11 deletions(-)
drivers/hv/mshv_root.h +3 -2
index 3c1d88b36741..05ba1f716f9e 100644
@@ -307,8 +307,9 @@ int hv_call_disconnect_port(u64 connection_partition_id,
 int hv_call_notify_port_ring_empty(u32 sint_index);
 int hv_map_stats_page(enum hv_stats_object_type type,
 		      const union hv_stats_object_identity *identity,
-		      void **addr);
-int hv_unmap_stats_page(enum hv_stats_object_type type, void *page_addr,
+		      struct hv_stats_page **addr);
+int hv_unmap_stats_page(enum hv_stats_object_type type,
+			struct hv_stats_page *page_addr,
 			const union hv_stats_object_identity *identity);
 int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
 				   u64 page_struct_count, u32 host_access,
drivers/hv/mshv_root_hv_call.c +7 -5
index 1f93b94d7580..daee036e48bc 100644
@@ -890,9 +890,10 @@ hv_stats_get_area_type(enum hv_stats_object_type type,
  * caller should check for this case and instead fallback to the SELF area
  * alone.
  */
-static int hv_call_map_stats_page(enum hv_stats_object_type type,
-				  const union hv_stats_object_identity *identity,
-				  void **addr)
+static int
+hv_call_map_stats_page(enum hv_stats_object_type type,
+		       const union hv_stats_object_identity *identity,
+		       struct hv_stats_page **addr)
 {
 	unsigned long flags;
 	struct hv_input_map_stats_page *input;
@@ -942,7 +943,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
 
 int hv_map_stats_page(enum hv_stats_object_type type,
 		      const union hv_stats_object_identity *identity,
-		      void **addr)
+		      struct hv_stats_page **addr)
 {
 	int ret;
 	struct page *allocated_page = NULL;
@@ -990,7 +991,8 @@ static int hv_call_unmap_stats_page(enum hv_stats_object_type type,
 	return hv_result_to_errno(status);
 }
 
-int hv_unmap_stats_page(enum hv_stats_object_type type, void *page_addr,
+int hv_unmap_stats_page(enum hv_stats_object_type type,
+			struct hv_stats_page *page_addr,
 			const union hv_stats_object_identity *identity)
 {
 	int ret;
drivers/hv/mshv_root_main.c +4 -4
index 1777778f84b8..be5ad0fbfbee 100644
@@ -957,7 +957,7 @@ mshv_vp_release(struct inode *inode, struct file *filp)
 }
 
 static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index,
-				void *stats_pages[])
+				struct hv_stats_page *stats_pages[])
 {
 	union hv_stats_object_identity identity = {
 		.vp.partition_id = partition_id,
@@ -972,7 +972,7 @@ static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index,
 }
 
 static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
-			     void *stats_pages[])
+			     struct hv_stats_page *stats_pages[])
 {
 	union hv_stats_object_identity identity = {
 		.vp.partition_id = partition_id,
@@ -1010,7 +1010,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 	struct mshv_create_vp args;
 	struct mshv_vp *vp;
 	struct page *intercept_msg_page, *register_page, *ghcb_page;
-	void *stats_pages[2];
+	struct hv_stats_page *stats_pages[2];
 	long ret;
 
 	if (copy_from_user(&args, arg, sizeof(args)))
@@ -1729,7 +1729,7 @@ static void destroy_partition(struct mshv_partition *partition)
 
 			if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
 				mshv_vp_stats_unmap(partition->pt_id, vp->vp_index,
-						    (void **)vp->vp_stats_pages);
+						    vp->vp_stats_pages);
 
 			if (vp->vp_register_page) {
 				(void)hv_unmap_vp_state_page(partition->pt_id,
Signature · 1 line
2.34.1
#3 lore raw

PATCH v6 3/7 mshv: Improve mshv_vp_stats_map/unmap(), add them to mshv_root.h

In reply to Nuno Das Neves

From: Stanislav Kinsburskii <[email protected]>

These functions are currently only used to map child partition VP stats, on root partition. However, they will soon be used on L1VH, and also used for mapping the host's own VP stats.

Introduce a helper is_l1vh_parent() to determine whether we are mapping our own VP stats. In this case, do not attempt to map the PARENT area. Note this is a different case than mapping PARENT on an older hypervisor where it is not available at all, so must be handled separately.

On unmap, pass the stats pages since on L1VH the kernel allocates them and they must be freed in hv_unmap_stats_page().

---
 drivers/hv/mshv_root.h      | 10 ++++++
 drivers/hv/mshv_root_main.c | 61 ++++++++++++++++++++++++++-----------
 2 files changed, 54 insertions(+), 17 deletions(-)
drivers/hv/mshv_root.h +10 -0
index 05ba1f716f9e..e4912b0618fa 100644
@@ -254,6 +254,16 @@ struct mshv_partition *mshv_partition_get(struct mshv_partition *partition);
 void mshv_partition_put(struct mshv_partition *partition);
 struct mshv_partition *mshv_partition_find(u64 partition_id) __must_hold(RCU);
 
+static inline bool is_l1vh_parent(u64 partition_id)
+{
+	return hv_l1vh_partition() && (partition_id == HV_PARTITION_ID_SELF);
+}
+
+int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
+		      struct hv_stats_page **stats_pages);
+void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index,
+			 struct hv_stats_page **stats_pages);
+
 /* hypercalls */
 
 int hv_call_withdraw_memory(u64 count, int node, u64 partition_id);
drivers/hv/mshv_root_main.c +44 -17

90 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

PATCH v6 4/7 mshv: Always map child vp stats pages regardless of scheduler type

In reply to Nuno Das Neves

From: Stanislav Kinsburskii <[email protected]>

Currently vp->vp_stats_pages is only used by the root scheduler for fast interrupt injection.

Soon, vp_stats_pages will also be needed for exposing child VP stats to userspace via debugfs. Mapping the pages a second time to a different address causes an error on L1VH.

Remove the scheduler requirement and always map the vp stats pages.

---
 drivers/hv/mshv_root_main.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)
drivers/hv/mshv_root_main.c +8 -17
index faca3cc63e79..fbfc9e7d9fa4 100644
@@ -1077,16 +1077,10 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 			goto unmap_register_page;
 	}
 
-	/*
-	 * This mapping of the stats page is for detecting if dispatch thread
-	 * is blocked - only relevant for root scheduler
-	 */
-	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT) {
-		ret = mshv_vp_stats_map(partition->pt_id, args.vp_index,
-					stats_pages);
-		if (ret)
-			goto unmap_ghcb_page;
-	}
+	ret = mshv_vp_stats_map(partition->pt_id, args.vp_index,
+				stats_pages);
+	if (ret)
+		goto unmap_ghcb_page;
 
 	vp = kzalloc(sizeof(*vp), GFP_KERNEL);
 	if (!vp)
@@ -1110,8 +1104,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available())
 		vp->vp_ghcb_page = page_to_virt(ghcb_page);
 
-	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
-		memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));
+	memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));
 
 	/*
 	 * Keep anon_inode_getfd last: it installs fd in the file struct and
@@ -1133,8 +1126,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 free_vp:
 	kfree(vp);
 unmap_stats_pages:
-	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
-		mshv_vp_stats_unmap(partition->pt_id, args.vp_index, stats_pages);
+	mshv_vp_stats_unmap(partition->pt_id, args.vp_index, stats_pages);
 unmap_ghcb_page:
 	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available())
 		hv_unmap_vp_state_page(partition->pt_id, args.vp_index,
@@ -1754,9 +1746,8 @@ static void destroy_partition(struct mshv_partition *partition)
 			if (!vp)
 				continue;
 
-			if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
-				mshv_vp_stats_unmap(partition->pt_id, vp->vp_index,
-						    vp->vp_stats_pages);
+			mshv_vp_stats_unmap(partition->pt_id, vp->vp_index,
+					    vp->vp_stats_pages);
 
 			if (vp->vp_register_page) {
 				(void)hv_unmap_vp_state_page(partition->pt_id,
Signature · 1 line
2.34.1
#5 lore raw

PATCH v6 5/7 mshv: Update hv_stats_page definitions

In reply to Nuno Das Neves

hv_stats_page belongs in hvhdk.h, move it there.

It does not require a union to access the data for different counters, just use a single u64 array for simplicity and to match the Windows definitions.

While at it, correct the ARM64 value for VpRootDispatchThreadBlocked.

---
 drivers/hv/mshv_root_main.c | 27 ++++++++-------------------
 include/hyperv/hvhdk.h      |  7 +++++++
 2 files changed, 15 insertions(+), 19 deletions(-)
drivers/hv/mshv_root_main.c +8 -19
index fbfc9e7d9fa4..414d9cee5252 100644
@@ -39,22 +39,12 @@ MODULE_AUTHOR("Microsoft");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface /dev/mshv");
 
-/* TODO move this to another file when debugfs code is added */
-enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
-#if defined(CONFIG_X86)
-	VpRootDispatchThreadBlocked			= 202,
+/* HV_THREAD_COUNTER */
+#if defined(CONFIG_X86_64)
+#define HV_VP_COUNTER_ROOT_DISPATCH_THREAD_BLOCKED 202
 #elif defined(CONFIG_ARM64)
-	VpRootDispatchThreadBlocked			= 94,
+#define HV_VP_COUNTER_ROOT_DISPATCH_THREAD_BLOCKED 95
 #endif
-	VpStatsMaxCounter
-};
-
-struct hv_stats_page {
-	union {
-		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
-		u8 data[HV_HYP_PAGE_SIZE];
-	};
-} __packed;
 
 struct mshv_root mshv_root;
 
@@ -485,12 +475,11 @@ static u64 mshv_vp_interrupt_pending(struct mshv_vp *vp)
 static bool mshv_vp_dispatch_thread_blocked(struct mshv_vp *vp)
 {
 	struct hv_stats_page **stats = vp->vp_stats_pages;
-	u64 *self_vp_cntrs = stats[HV_STATS_AREA_SELF]->vp_cntrs;
-	u64 *parent_vp_cntrs = stats[HV_STATS_AREA_PARENT]->vp_cntrs;
+	u64 *self_vp_cntrs = stats[HV_STATS_AREA_SELF]->data;
+	u64 *parent_vp_cntrs = stats[HV_STATS_AREA_PARENT]->data;
 
-	if (self_vp_cntrs[VpRootDispatchThreadBlocked])
-		return self_vp_cntrs[VpRootDispatchThreadBlocked];
-	return parent_vp_cntrs[VpRootDispatchThreadBlocked];
+	return parent_vp_cntrs[HV_VP_COUNTER_ROOT_DISPATCH_THREAD_BLOCKED] ||
+	       self_vp_cntrs[HV_VP_COUNTER_ROOT_DISPATCH_THREAD_BLOCKED];
 }
 
 static int
include/hyperv/hvhdk.h +7 -0
index 469186df7826..d87cfdb7d360 100644
@@ -10,6 +10,13 @@
 #include "hvhdk_mini.h"
 #include "hvgdk.h"
 
+/*
+ * Hypervisor statistics page format
+ */
+struct hv_stats_page {
+	u64 data[HV_HYP_PAGE_SIZE / sizeof(u64)];
+} __packed;
+
 /* Bits for dirty mask of hv_vp_register_page */
 #define HV_X64_REGISTER_CLASS_GENERAL	0
 #define HV_X64_REGISTER_CLASS_IP	1
Signature · 1 line
2.34.1
#6 lore raw

PATCH v6 6/7 mshv: Add data for printing stats page counters

In reply to Nuno Das Neves

Introduce mshv_debugfs_counters.c, containing static data corresponding to HV_*_COUNTER enums in the hypervisor source. Defining the enum members as an array instead makes more sense, since it will be iterated over to print counter information to debugfs.

Include hypervisor, logical processor, partition, and virtual processor counters.

---
 drivers/hv/mshv_debugfs_counters.c | 490 +++++++++++++++++++++++++++++
 1 file changed, 490 insertions(+)
 create mode 100644 drivers/hv/mshv_debugfs_counters.c
drivers/hv/mshv_debugfs_counters.c new file +490 -0
new file mode 100644
index 000000000000..978536ba691f
@@ -0,0 +1,490 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2026, Microsoft Corporation.
+ *
+ * Data for printing stats page counters via debugfs.
+ *
+ * Authors: Microsoft Linux virtualization team
+ */
+
+/*
+ * For simplicity, this file is included directly in mshv_debugfs.c.
+ * If these are ever needed elsewhere they should be compiled separately.
+ * Ensure this file is not used twice by accident.
+ */
+#ifndef MSHV_DEBUGFS_C
+#error "This file should only be included in mshv_debugfs.c"
+#endif
+
+/* HV_HYPERVISOR_COUNTER */
+static char *hv_hypervisor_counters[] = {
+	[1] = "HvLogicalProcessors",
+	[2] = "HvPartitions",
+	[3] = "HvTotalPages",
+	[4] = "HvVirtualProcessors",
+	[5] = "HvMonitoredNotifications",
+	[6] = "HvModernStandbyEntries",
+	[7] = "HvPlatformIdleTransitions",
+	[8] = "HvHypervisorStartupCost",
+
+	[10] = "HvIOSpacePages",
+	[11] = "HvNonEssentialPagesForDump",
+	[12] = "HvSubsumedPages",
+};
+
+/* HV_CPU_COUNTER */
+static char *hv_lp_counters[] = {
+	[1] = "LpGlobalTime",
+	[2] = "LpTotalRunTime",
+	[3] = "LpHypervisorRunTime",
+	[4] = "LpHardwareInterrupts",
+	[5] = "LpContextSwitches",
+	[6] = "LpInterProcessorInterrupts",
+	[7] = "LpSchedulerInterrupts",
+	[8] = "LpTimerInterrupts",
+	[9] = "LpInterProcessorInterruptsSent",
+	[10] = "LpProcessorHalts",
+	[11] = "LpMonitorTransitionCost",
+	[12] = "LpContextSwitchTime",
+	[13] = "LpC1TransitionsCount",
+	[14] = "LpC1RunTime",
+	[15] = "LpC2TransitionsCount",
+	[16] = "LpC2RunTime",
+	[17] = "LpC3TransitionsCount",
+	[18] = "LpC3RunTime",
+	[19] = "LpRootVpIndex",
+	[20] = "LpIdleSequenceNumber",
+	[21] = "LpGlobalTscCount",
+	[22] = "LpActiveTscCount",
+	[23] = "LpIdleAccumulation",
+	[24] = "LpReferenceCycleCount0",
+	[25] = "LpActualCycleCount0",
+	[26] = "LpReferenceCycleCount1",
+	[27] = "LpActualCycleCount1",
+	[28] = "LpProximityDomainId",
+	[29] = "LpPostedInterruptNotifications",
+	[30] = "LpBranchPredictorFlushes",
+#if IS_ENABLED(CONFIG_X86_64)
+	[31] = "LpL1DataCacheFlushes",
+	[32] = "LpImmediateL1DataCacheFlushes",
+	[33] = "LpMbFlushes",
+	[34] = "LpCounterRefreshSequenceNumber",
+	[35] = "LpCounterRefreshReferenceTime",
+	[36] = "LpIdleAccumulationSnapshot",
+	[37] = "LpActiveTscCountSnapshot",
+	[38] = "LpHwpRequestContextSwitches",
+	[39] = "LpPlaceholder1",
+	[40] = "LpPlaceholder2",
+	[41] = "LpPlaceholder3",
+	[42] = "LpPlaceholder4",
+	[43] = "LpPlaceholder5",
+	[44] = "LpPlaceholder6",
+	[45] = "LpPlaceholder7",
+	[46] = "LpPlaceholder8",
+	[47] = "LpPlaceholder9",
+	[48] = "LpSchLocalRunListSize",
+	[49] = "LpReserveGroupId",
+	[50] = "LpRunningPriority",
+	[51] = "LpPerfmonInterruptCount",
+#elif IS_ENABLED(CONFIG_ARM64)
+	[31] = "LpCounterRefreshSequenceNumber",
+	[32] = "LpCounterRefreshReferenceTime",
+	[33] = "LpIdleAccumulationSnapshot",
+	[34] = "LpActiveTscCountSnapshot",
+	[35] = "LpHwpRequestContextSwitches",
+	[36] = "LpPlaceholder2",
+	[37] = "LpPlaceholder3",
+	[38] = "LpPlaceholder4",
+	[39] = "LpPlaceholder5",
+	[40] = "LpPlaceholder6",
+	[41] = "LpPlaceholder7",
+	[42] = "LpPlaceholder8",
+	[43] = "LpPlaceholder9",
+	[44] = "LpSchLocalRunListSize",
+	[45] = "LpReserveGroupId",
+	[46] = "LpRunningPriority",
+#endif
+};
+
+/* HV_PROCESS_COUNTER */
+static char *hv_partition_counters[] = {
+	[1] = "PtVirtualProcessors",
+
+	[3] = "PtTlbSize",
+	[4] = "PtAddressSpaces",
+	[5] = "PtDepositedPages",
+	[6] = "PtGpaPages",
+	[7] = "PtGpaSpaceModifications",
+	[8] = "PtVirtualTlbFlushEntires",
+	[9] = "PtRecommendedTlbSize",
+	[10] = "PtGpaPages4K",
+	[11] = "PtGpaPages2M",
+	[12] = "PtGpaPages1G",
+	[13] = "PtGpaPages512G",
+	[14] = "PtDevicePages4K",
+	[15] = "PtDevicePages2M",
+	[16] = "PtDevicePages1G",
+	[17] = "PtDevicePages512G",
+	[18] = "PtAttachedDevices",
+	[19] = "PtDeviceInterruptMappings",
+	[20] = "PtIoTlbFlushes",
+	[21] = "PtIoTlbFlushCost",
+	[22] = "PtDeviceInterruptErrors",
+	[23] = "PtDeviceDmaErrors",
+	[24] = "PtDeviceInterruptThrottleEvents",
+	[25] = "PtSkippedTimerTicks",
+	[26] = "PtPartitionId",
+#if IS_ENABLED(CONFIG_X86_64)
+	[27] = "PtNestedTlbSize",
+	[28] = "PtRecommendedNestedTlbSize",
+	[29] = "PtNestedTlbFreeListSize",
+	[30] = "PtNestedTlbTrimmedPages",
+	[31] = "PtPagesShattered",
+	[32] = "PtPagesRecombined",
+	[33] = "PtHwpRequestValue",
+	[34] = "PtAutoSuspendEnableTime",
+	[35] = "PtAutoSuspendTriggerTime",
+	[36] = "PtAutoSuspendDisableTime",
+	[37] = "PtPlaceholder1",
+	[38] = "PtPlaceholder2",
+	[39] = "PtPlaceholder3",
+	[40] = "PtPlaceholder4",
+	[41] = "PtPlaceholder5",
+	[42] = "PtPlaceholder6",
+	[43] = "PtPlaceholder7",
+	[44] = "PtPlaceholder8",
+	[45] = "PtHypervisorStateTransferGeneration",
+	[46] = "PtNumberofActiveChildPartitions",
+#elif IS_ENABLED(CONFIG_ARM64)
+	[27] = "PtHwpRequestValue",
+	[28] = "PtAutoSuspendEnableTime",
+	[29] = "PtAutoSuspendTriggerTime",
+	[30] = "PtAutoSuspendDisableTime",
+	[31] = "PtPlaceholder1",
+	[32] = "PtPlaceholder2",
+	[33] = "PtPlaceholder3",
+	[34] = "PtPlaceholder4",
+	[35] = "PtPlaceholder5",
+	[36] = "PtPlaceholder6",
+	[37] = "PtPlaceholder7",
+	[38] = "PtPlaceholder8",
+	[39] = "PtHypervisorStateTransferGeneration",
+	[40] = "PtNumberofActiveChildPartitions",
+#endif
+};
+
+/* HV_THREAD_COUNTER */
+static char *hv_vp_counters[] = {
+	[1] = "VpTotalRunTime",
+	[2] = "VpHypervisorRunTime",
+	[3] = "VpRemoteNodeRunTime",
+	[4] = "VpNormalizedRunTime",
+	[5] = "VpIdealCpu",
+
+	[7] = "VpHypercallsCount",
+	[8] = "VpHypercallsTime",
+#if IS_ENABLED(CONFIG_X86_64)
+	[9] = "VpPageInvalidationsCount",
+	[10] = "VpPageInvalidationsTime",
+	[11] = "VpControlRegisterAccessesCount",
+	[12] = "VpControlRegisterAccessesTime",
+	[13] = "VpIoInstructionsCount",
+	[14] = "VpIoInstructionsTime",
+	[15] = "VpHltInstructionsCount",
+	[16] = "VpHltInstructionsTime",
+	[17] = "VpMwaitInstructionsCount",
+	[18] = "VpMwaitInstructionsTime",
+	[19] = "VpCpuidInstructionsCount",
+	[20] = "VpCpuidInstructionsTime",
+	[21] = "VpMsrAccessesCount",
+	[22] = "VpMsrAccessesTime",
+	[23] = "VpOtherInterceptsCount",
+	[24] = "VpOtherInterceptsTime",
+	[25] = "VpExternalInterruptsCount",
+	[26] = "VpExternalInterruptsTime",
+	[27] = "VpPendingInterruptsCount",
+	[28] = "VpPendingInterruptsTime",
+	[29] = "VpEmulatedInstructionsCount",
+	[30] = "VpEmulatedInstructionsTime",
+	[31] = "VpDebugRegisterAccessesCount",
+	[32] = "VpDebugRegisterAccessesTime",
+	[33] = "VpPageFaultInterceptsCount",
+	[34] = "VpPageFaultInterceptsTime",
+	[35] = "VpGuestPageTableMaps",
+	[36] = "VpLargePageTlbFills",
+	[37] = "VpSmallPageTlbFills",
+	[38] = "VpReflectedGuestPageFaults",
+	[39] = "VpApicMmioAccesses",
+	[40] = "VpIoInterceptMessages",
+	[41] = "VpMemoryInterceptMessages",
+	[42] = "VpApicEoiAccesses",
+	[43] = "VpOtherMessages",
+	[44] = "VpPageTableAllocations",
+	[45] = "VpLogicalProcessorMigrations",
+	[46] = "VpAddressSpaceEvictions",
+	[47] = "VpAddressSpaceSwitches",
+	[48] = "VpAddressDomainFlushes",
+	[49] = "VpAddressSpaceFlushes",
+	[50] = "VpGlobalGvaRangeFlushes",
+	[51] = "VpLocalGvaRangeFlushes",
+	[52] = "VpPageTableEvictions",
+	[53] = "VpPageTableReclamations",
+	[54] = "VpPageTableResets",
+	[55] = "VpPageTableValidations",
+	[56] = "VpApicTprAccesses",
+	[57] = "VpPageTableWriteIntercepts",
+	[58] = "VpSyntheticInterrupts",
+	[59] = "VpVirtualInterrupts",
+	[60] = "VpApicIpisSent",
+	[61] = "VpApicSelfIpisSent",
+	[62] = "VpGpaSpaceHypercalls",
+	[63] = "VpLogicalProcessorHypercalls",
+	[64] = "VpLongSpinWaitHypercalls",
+	[65] = "VpOtherHypercalls",
+	[66] = "VpSyntheticInterruptHypercalls",
+	[67] = "VpVirtualInterruptHypercalls",
+	[68] = "VpVirtualMmuHypercalls",
+	[69] = "VpVirtualProcessorHypercalls",
+	[70] = "VpHardwareInterrupts",
+	[71] = "VpNestedPageFaultInterceptsCount",
+	[72] = "VpNestedPageFaultInterceptsTime",
+	[73] = "VpPageScans",
+	[74] = "VpLogicalProcessorDispatches",
+	[75] = "VpWaitingForCpuTime",
+	[76] = "VpExtendedHypercalls",
+	[77] = "VpExtendedHypercallInterceptMessages",
+	[78] = "VpMbecNestedPageTableSwitches",
+	[79] = "VpOtherReflectedGuestExceptions",
+	[80] = "VpGlobalIoTlbFlushes",
+	[81] = "VpGlobalIoTlbFlushCost",
+	[82] = "VpLocalIoTlbFlushes",
+	[83] = "VpLocalIoTlbFlushCost",
+	[84] = "VpHypercallsForwardedCount",
+	[85] = "VpHypercallsForwardingTime",
+	[86] = "VpPageInvalidationsForwardedCount",
+	[87] = "VpPageInvalidationsForwardingTime",
+	[88] = "VpControlRegisterAccessesForwardedCount",
+	[89] = "VpControlRegisterAccessesForwardingTime",
+	[90] = "VpIoInstructionsForwardedCount",
+	[91] = "VpIoInstructionsForwardingTime",
+	[92] = "VpHltInstructionsForwardedCount",
+	[93] = "VpHltInstructionsForwardingTime",
+	[94] = "VpMwaitInstructionsForwardedCount",
+	[95] = "VpMwaitInstructionsForwardingTime",
+	[96] = "VpCpuidInstructionsForwardedCount",
+	[97] = "VpCpuidInstructionsForwardingTime",
+	[98] = "VpMsrAccessesForwardedCount",
+	[99] = "VpMsrAccessesForwardingTime",
+	[100] = "VpOtherInterceptsForwardedCount",
+	[101] = "VpOtherInterceptsForwardingTime",
+	[102] = "VpExternalInterruptsForwardedCount",
+	[103] = "VpExternalInterruptsForwardingTime",
+	[104] = "VpPendingInterruptsForwardedCount",
+	[105] = "VpPendingInterruptsForwardingTime",
+	[106] = "VpEmulatedInstructionsForwardedCount",
+	[107] = "VpEmulatedInstructionsForwardingTime",
+	[108] = "VpDebugRegisterAccessesForwardedCount",
+	[109] = "VpDebugRegisterAccessesForwardingTime",
+	[110] = "VpPageFaultInterceptsForwardedCount",
+	[111] = "VpPageFaultInterceptsForwardingTime",
+	[112] = "VpVmclearEmulationCount",
+	[113] = "VpVmclearEmulationTime",
+	[114] = "VpVmptrldEmulationCount",
+	[115] = "VpVmptrldEmulationTime",
+	[116] = "VpVmptrstEmulationCount",
+	[117] = "VpVmptrstEmulationTime",
+	[118] = "VpVmreadEmulationCount",
+	[119] = "VpVmreadEmulationTime",
+	[120] = "VpVmwriteEmulationCount",
+	[121] = "VpVmwriteEmulationTime",
+	[122] = "VpVmxoffEmulationCount",
+	[123] = "VpVmxoffEmulationTime",
+	[124] = "VpVmxonEmulationCount",
+	[125] = "VpVmxonEmulationTime",
+	[126] = "VpNestedVMEntriesCount",
+	[127] = "VpNestedVMEntriesTime",
+	[128] = "VpNestedSLATSoftPageFaultsCount",
+	[129] = "VpNestedSLATSoftPageFaultsTime",
+	[130] = "VpNestedSLATHardPageFaultsCount",
+	[131] = "VpNestedSLATHardPageFaultsTime",
+	[132] = "VpInvEptAllContextEmulationCount",
+	[133] = "VpInvEptAllContextEmulationTime",
+	[134] = "VpInvEptSingleContextEmulationCount",
+	[135] = "VpInvEptSingleContextEmulationTime",
+	[136] = "VpInvVpidAllContextEmulationCount",
+	[137] = "VpInvVpidAllContextEmulationTime",
+	[138] = "VpInvVpidSingleContextEmulationCount",
+	[139] = "VpInvVpidSingleContextEmulationTime",
+	[140] = "VpInvVpidSingleAddressEmulationCount",
+	[141] = "VpInvVpidSingleAddressEmulationTime",
+	[142] = "VpNestedTlbPageTableReclamations",
+	[143] = "VpNestedTlbPageTableEvictions",
+	[144] = "VpFlushGuestPhysicalAddressSpaceHypercalls",
+	[145] = "VpFlushGuestPhysicalAddressListHypercalls",
+	[146] = "VpPostedInterruptNotifications",
+	[147] = "VpPostedInterruptScans",
+	[148] = "VpTotalCoreRunTime",
+	[149] = "VpMaximumRunTime",
+	[150] = "VpHwpRequestContextSwitches",
+	[151] = "VpWaitingForCpuTimeBucket0",
+	[152] = "VpWaitingForCpuTimeBucket1",
+	[153] = "VpWaitingForCpuTimeBucket2",
+	[154] = "VpWaitingForCpuTimeBucket3",
+	[155] = "VpWaitingForCpuTimeBucket4",
+	[156] = "VpWaitingForCpuTimeBucket5",
+	[157] = "VpWaitingForCpuTimeBucket6",
+	[158] = "VpVmloadEmulationCount",
+	[159] = "VpVmloadEmulationTime",
+	[160] = "VpVmsaveEmulationCount",
+	[161] = "VpVmsaveEmulationTime",
+	[162] = "VpGifInstructionEmulationCount",
+	[163] = "VpGifInstructionEmulationTime",
+	[164] = "VpEmulatedErrataSvmInstructions",
+	[165] = "VpPlaceholder1",
+	[166] = "VpPlaceholder2",
+	[167] = "VpPlaceholder3",
+	[168] = "VpPlaceholder4",
+	[169] = "VpPlaceholder5",
+	[170] = "VpPlaceholder6",
+	[171] = "VpPlaceholder7",
+	[172] = "VpPlaceholder8",
+	[173] = "VpContentionTime",
+	[174] = "VpWakeUpTime",
+	[175] = "VpSchedulingPriority",
+	[176] = "VpRdpmcInstructionsCount",
+	[177] = "VpRdpmcInstructionsTime",
+	[178] = "VpPerfmonPmuMsrAccessesCount",
+	[179] = "VpPerfmonLbrMsrAccessesCount",
+	[180] = "VpPerfmonIptMsrAccessesCount",
+	[181] = "VpPerfmonInterruptCount",
+	[182] = "VpVtl1DispatchCount",
+	[183] = "VpVtl2DispatchCount",
+	[184] = "VpVtl2DispatchBucket0",
+	[185] = "VpVtl2DispatchBucket1",
+	[186] = "VpVtl2DispatchBucket2",
+	[187] = "VpVtl2DispatchBucket3",
+	[188] = "VpVtl2DispatchBucket4",
+	[189] = "VpVtl2DispatchBucket5",
+	[190] = "VpVtl2DispatchBucket6",
+	[191] = "VpVtl1RunTime",
+	[192] = "VpVtl2RunTime",
+	[193] = "VpIommuHypercalls",
+	[194] = "VpCpuGroupHypercalls",
+	[195] = "VpVsmHypercalls",
+	[196] = "VpEventLogHypercalls",
+	[197] = "VpDeviceDomainHypercalls",
+	[198] = "VpDepositHypercalls",
+	[199] = "VpSvmHypercalls",
+	[200] = "VpBusLockAcquisitionCount",
+	[201] = "VpLoadAvg",
+	[202] = "VpRootDispatchThreadBlocked",
+	[203] = "VpIdleCpuTime",
+	[204] = "VpWaitingForCpuTimeBucket7",
+	[205] = "VpWaitingForCpuTimeBucket8",
+	[206] = "VpWaitingForCpuTimeBucket9",
+	[207] = "VpWaitingForCpuTimeBucket10",
+	[208] = "VpWaitingForCpuTimeBucket11",
+	[209] = "VpWaitingForCpuTimeBucket12",
+	[210] = "VpHierarchicalSuspendTime",
+	[211] = "VpExpressSchedulingAttempts",
+	[212] = "VpExpressSchedulingCount",
+#elif IS_ENABLED(CONFIG_ARM64)
+	[9] = "VpSysRegAccessesCount",
+	[10] = "VpSysRegAccessesTime",
+	[11] = "VpSmcInstructionsCount",
+	[12] = "VpSmcInstructionsTime",
+	[13] = "VpOtherInterceptsCount",
+	[14] = "VpOtherInterceptsTime",
+	[15] = "VpExternalInterruptsCount",
+	[16] = "VpExternalInterruptsTime",
+	[17] = "VpPendingInterruptsCount",
+	[18] = "VpPendingInterruptsTime",
+	[19] = "VpGuestPageTableMaps",
+	[20] = "VpLargePageTlbFills",
+	[21] = "VpSmallPageTlbFills",
+	[22] = "VpReflectedGuestPageFaults",
+	[23] = "VpMemoryInterceptMessages",
+	[24] = "VpOtherMessages",
+	[25] = "VpLogicalProcessorMigrations",
+	[26] = "VpAddressDomainFlushes",
+	[27] = "VpAddressSpaceFlushes",
+	[28] = "VpSyntheticInterrupts",
+	[29] = "VpVirtualInterrupts",
+	[30] = "VpApicSelfIpisSent",
+	[31] = "VpGpaSpaceHypercalls",
+	[32] = "VpLogicalProcessorHypercalls",
+	[33] = "VpLongSpinWaitHypercalls",
+	[34] = "VpOtherHypercalls",
+	[35] = "VpSyntheticInterruptHypercalls",
+	[36] = "VpVirtualInterruptHypercalls",
+	[37] = "VpVirtualMmuHypercalls",
+	[38] = "VpVirtualProcessorHypercalls",
+	[39] = "VpHardwareInterrupts",
+	[40] = "VpNestedPageFaultInterceptsCount",
+	[41] = "VpNestedPageFaultInterceptsTime",
+	[42] = "VpLogicalProcessorDispatches",
+	[43] = "VpWaitingForCpuTime",
+	[44] = "VpExtendedHypercalls",
+	[45] = "VpExtendedHypercallInterceptMessages",
+	[46] = "VpMbecNestedPageTableSwitches",
+	[47] = "VpOtherReflectedGuestExceptions",
+	[48] = "VpGlobalIoTlbFlushes",
+	[49] = "VpGlobalIoTlbFlushCost",
+	[50] = "VpLocalIoTlbFlushes",
+	[51] = "VpLocalIoTlbFlushCost",
+	[52] = "VpFlushGuestPhysicalAddressSpaceHypercalls",
+	[53] = "VpFlushGuestPhysicalAddressListHypercalls",
+	[54] = "VpPostedInterruptNotifications",
+	[55] = "VpPostedInterruptScans",
+	[56] = "VpTotalCoreRunTime",
+	[57] = "VpMaximumRunTime",
+	[58] = "VpWaitingForCpuTimeBucket0",
+	[59] = "VpWaitingForCpuTimeBucket1",
+	[60] = "VpWaitingForCpuTimeBucket2",
+	[61] = "VpWaitingForCpuTimeBucket3",
+	[62] = "VpWaitingForCpuTimeBucket4",
+	[63] = "VpWaitingForCpuTimeBucket5",
+	[64] = "VpWaitingForCpuTimeBucket6",
+	[65] = "VpHwpRequestContextSwitches",
+	[66] = "VpPlaceholder2",
+	[67] = "VpPlaceholder3",
+	[68] = "VpPlaceholder4",
+	[69] = "VpPlaceholder5",
+	[70] = "VpPlaceholder6",
+	[71] = "VpPlaceholder7",
+	[72] = "VpPlaceholder8",
+	[73] = "VpContentionTime",
+	[74] = "VpWakeUpTime",
+	[75] = "VpSchedulingPriority",
+	[76] = "VpVtl1DispatchCount",
+	[77] = "VpVtl2DispatchCount",
+	[78] = "VpVtl2DispatchBucket0",
+	[79] = "VpVtl2DispatchBucket1",
+	[80] = "VpVtl2DispatchBucket2",
+	[81] = "VpVtl2DispatchBucket3",
+	[82] = "VpVtl2DispatchBucket4",
+	[83] = "VpVtl2DispatchBucket5",
+	[84] = "VpVtl2DispatchBucket6",
+	[85] = "VpVtl1RunTime",
+	[86] = "VpVtl2RunTime",
+	[87] = "VpIommuHypercalls",
+	[88] = "VpCpuGroupHypercalls",
+	[89] = "VpVsmHypercalls",
+	[90] = "VpEventLogHypercalls",
+	[91] = "VpDeviceDomainHypercalls",
+	[92] = "VpDepositHypercalls",
+	[93] = "VpSvmHypercalls",
+	[94] = "VpLoadAvg",
+	[95] = "VpRootDispatchThreadBlocked",
+	[96] = "VpIdleCpuTime",
+	[97] = "VpWaitingForCpuTimeBucket7",
+	[98] = "VpWaitingForCpuTimeBucket8",
+	[99] = "VpWaitingForCpuTimeBucket9",
+	[100] = "VpWaitingForCpuTimeBucket10",
+	[101] = "VpWaitingForCpuTimeBucket11",
+	[102] = "VpWaitingForCpuTimeBucket12",
+	[103] = "VpHierarchicalSuspendTime",
+	[104] = "VpExpressSchedulingAttempts",
+	[105] = "VpExpressSchedulingCount",
+#endif
+};
Signature · 1 line
2.34.1
#7 lore raw

PATCH v6 7/7 mshv: Add debugfs to view hypervisor statistics

In reply to Nuno Das Neves

Introduce a debugfs interface to expose root and child partition stats when running with mshv_root.

Create a debugfs directory "mshv" containing 'stats' files organized by type and id. A stats file contains a number of counters depending on its type. e.g. an excerpt from a VP stats file:

TotalRunTime : 1997602722
HypervisorRunTime : 649671371
RemoteNodeRunTime : 0
NormalizedRunTime : 1997602721
IdealCpu : 0
HypercallsCount : 1708169
HypercallsTime : 111914774
PageInvalidationsCount : 0
PageInvalidationsTime : 0

On a root partition with some active child partitions, the entire directory structure may look like:

mshv/

  stats             # hypervisor stats
  lp/               # logical processors
    0/              # LP id
      stats         # LP 0 stats
    1/
    2/
    3/
  partition/        # partition stats
    1/              # root partition id
      stats         # root partition stats
      vp/           # root virtual processors
        0/          # root VP id
          stats     # root VP 0 stats
        1/
        2/
        3/
    42/             # child partition id
      stats         # child partition stats
      vp/           # child VPs
        0/          # child VP id
          stats     # child VP 0 stats
        1/
    43/
    55/

On L1VH, some stats are not present as it does not own the hardware like the root partition does:
- The hypervisor and lp stats are not present
- L1VH's partition directory is named "self" because it can't get its own id
- Some of L1VH's partition and VP stats fields are not populated, because it can't map its own HV_STATS_AREA_PARENT page.

---
 drivers/hv/Makefile         |   1 +
 drivers/hv/mshv_debugfs.c   | 726 ++++++++++++++++++++++++++++++++++++
 drivers/hv/mshv_root.h      |  34 ++
 drivers/hv/mshv_root_main.c |  26 +-
 4 files changed, 785 insertions(+), 2 deletions(-)
 create mode 100644 drivers/hv/mshv_debugfs.c
drivers/hv/Makefile +1 -0
index a49f93c2d245..2593711c3628 100644
@@ -15,6 +15,7 @@ hv_vmbus-$(CONFIG_HYPERV_TESTING)	+= hv_debugfs.o
 hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_utils_transport.o
 mshv_root-y := mshv_root_main.o mshv_synic.o mshv_eventfd.o mshv_irq.o \
 	       mshv_root_hv_call.o mshv_portid_table.o mshv_regions.o
+mshv_root-$(CONFIG_DEBUG_FS) += mshv_debugfs.o
 mshv_vtl-y := mshv_vtl_main.o
 
 # Code that must be built-in
drivers/hv/mshv_debugfs.c new file +726 -0

726 lines not on this page · raw message

drivers/hv/mshv_root.h +34 -0
index e4912b0618fa..7332d9af8373 100644
@@ -52,6 +52,9 @@ struct mshv_vp {
 		unsigned int kicked_by_hv;
 		wait_queue_head_t vp_suspend_queue;
 	} run;
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+	struct dentry *vp_stats_dentry;
+#endif
 };
 
 #define vp_fmt(fmt) "p%lluvp%u: " fmt
@@ -136,6 +139,10 @@ struct mshv_partition {
 	u64 isolation_type;
 	bool import_completed;
 	bool pt_initialized;
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+	struct dentry *pt_stats_dentry;
+	struct dentry *pt_vp_dentry;
+#endif
 };
 
 #define pt_fmt(fmt) "p%llu: " fmt
@@ -327,6 +334,33 @@ int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
 int hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
 				      void *property_value, size_t property_value_sz);
 
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+int __init mshv_debugfs_init(void);
+void mshv_debugfs_exit(void);
+
+int mshv_debugfs_partition_create(struct mshv_partition *partition);
+void mshv_debugfs_partition_remove(struct mshv_partition *partition);
+int mshv_debugfs_vp_create(struct mshv_vp *vp);
+void mshv_debugfs_vp_remove(struct mshv_vp *vp);
+#else
+static inline int __init mshv_debugfs_init(void)
+{
+	return 0;
+}
+static inline void mshv_debugfs_exit(void) { }
+
+static inline int mshv_debugfs_partition_create(struct mshv_partition *partition)
+{
+	return 0;
+}
+static inline void mshv_debugfs_partition_remove(struct mshv_partition *partition) { }
+static inline int mshv_debugfs_vp_create(struct mshv_vp *vp)
+{
+	return 0;
+}
+static inline void mshv_debugfs_vp_remove(struct mshv_vp *vp) { }
+#endif
+
 extern struct mshv_root mshv_root;
 extern enum hv_scheduler_type hv_scheduler_type;
 extern u8 * __percpu *hv_synic_eventring_tail;
drivers/hv/mshv_root_main.c +24 -2
index 414d9cee5252..3a43e41e16a1 100644
@@ -1095,6 +1095,10 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 
 	memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));
 
+	ret = mshv_debugfs_vp_create(vp);
+	if (ret)
+		goto put_partition;
+
 	/*
 	 * Keep anon_inode_getfd last: it installs fd in the file struct and
 	 * thus makes the state accessible in user space.
@@ -1102,7 +1106,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 	ret = anon_inode_getfd("mshv_vp", &mshv_vp_fops, vp,
 			       O_RDWR | O_CLOEXEC);
 	if (ret < 0)
-		goto put_partition;
+		goto remove_debugfs_vp;
 
 	/* already exclusive with the partition mutex for all ioctls */
 	partition->pt_vp_count++;
@@ -1110,6 +1114,8 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 
 	return ret;
 
+remove_debugfs_vp:
+	mshv_debugfs_vp_remove(vp);
 put_partition:
 	mshv_partition_put(partition);
 free_vp:
@@ -1552,10 +1558,16 @@ mshv_partition_ioctl_initialize(struct mshv_partition *partition)
 	if (ret)
 		goto withdraw_mem;
 
+	ret = mshv_debugfs_partition_create(partition);
+	if (ret)
+		goto finalize_partition;
+
 	partition->pt_initialized = true;
 
 	return 0;
 
+finalize_partition:
+	hv_call_finalize_partition(partition->pt_id);
 withdraw_mem:
 	hv_call_withdraw_memory(U64_MAX, NUMA_NO_NODE, partition->pt_id);
 
@@ -1735,6 +1747,7 @@ static void destroy_partition(struct mshv_partition *partition)
 			if (!vp)
 				continue;
 
+			mshv_debugfs_vp_remove(vp);
 			mshv_vp_stats_unmap(partition->pt_id, vp->vp_index,
 					    vp->vp_stats_pages);
 
@@ -1768,6 +1781,8 @@ static void destroy_partition(struct mshv_partition *partition)
 			partition->pt_vp_array[i] = NULL;
 		}
 
+		mshv_debugfs_partition_remove(partition);
+
 		/* Deallocates and unmaps everything including vcpus, GPA mappings etc */
 		hv_call_finalize_partition(partition->pt_id);
 
@@ -2313,10 +2328,14 @@ static int __init mshv_parent_partition_init(void)
 
 	mshv_init_vmm_caps(dev);
 
-	ret = mshv_irqfd_wq_init();
+	ret = mshv_debugfs_init();
 	if (ret)
 		goto exit_partition;
 
+	ret = mshv_irqfd_wq_init();
+	if (ret)
+		goto exit_debugfs;
+
 	spin_lock_init(&mshv_root.pt_ht_lock);
 	hash_init(mshv_root.pt_htable);
 
@@ -2324,6 +2343,8 @@ static int __init mshv_parent_partition_init(void)
 
 	return 0;
 
+exit_debugfs:
+	mshv_debugfs_exit();
 exit_partition:
 	if (hv_root_partition())
 		mshv_root_partition_exit();
@@ -2340,6 +2361,7 @@ static void __exit mshv_parent_partition_exit(void)
 {
 	hv_setup_mshv_handler(NULL);
 	mshv_port_table_fini();
+	mshv_debugfs_exit();
 	misc_deregister(&mshv_dev);
 	mshv_irqfd_wq_cleanup();
 	if (hv_root_partition())
Signature · 1 line
2.34.1
Reviewed-by on the v6 series
#8 lore raw
In reply to Nuno Das Neves

From: Nuno Das Neves <[email protected]> Sent: Wednesday, January 28, 2026 10:12 AM

Quoted 100 lines

Expose hypervisor, logical processor, partition, and virtual processor statistics via debugfs. These are provided by mapping 'stats' pages via hypercall.

Patch #1: Update hv_call_map_stats_page() to return success when
HV_STATS_AREA_PARENT is unavailable, which is the case on some hypervisor versions, where it can fall back to HV_STATS_AREA_SELF
Patch #2: Use struct hv_stats_page pointers instead of void * Patch #3: Make mshv_vp_stats_map/unmap() more flexible to use with debugfs
code
Patch #4: Always map vp stats page regardless of scheduler, to reuse in
debugfs
Patch #5: Change to hv_stats_page definition and
VpRootDispatchThreadBlocked
Patch #6: Introduce the definitions needed for the various stats pages Patch #7: Add mshv_debugfs.c, and integrate it with the mshv_root driver to
expose the partition and VP stats.

---
Changes in v6:
- Fix whitespace and other checkpatch issues [Michael]

Changes in v5:
- Rename hv_counters.c to mshv_debugfs_counters.c [Michael]
- Clarify unusual inclusion of mshv_debugfs_counters.c with comment. After discussion it is still included directly to keep things simple. Including arrays with unspecified size via a header means sizeof() cannot be used on the array.
- Error if mshv_debugfs_counters.c is included elsewhere than mshv_debugfs.c
- Use array index as stats page index to save space [Stanislav]
- Enforce HV_STATS_AREA_PARENT and SELF fit in NUM_STATS_AREAS with static_assert and clarify with comment [Michael]
- Return to using lp count from hv stats page for mshv_lps_count [Michael]
- Use nr_cpu_ids instead of num_possible_cpus() [Michael]
- Set mshv_lps_stats[idx] and the array itself to NULL on unmap and cleanup [Michael]
- Rename HvLogicalProcessors and VpRootDispatchThreadBlocked to Linux style
- Translate Linux cpu index to vp index via hv_vp_index on partition destroy [Michael]
- Minor formatting cleanups [Michael]

Changes in v4:
- Put the counters definitions in static arrays in hv_counters.c, instead of as enums in hvhdk.h [Michael]
- Due to the above, add an additional patch (#5) to simplify hv_stats_page, and retain the enum definition at the top of mshv_root_main.c for use with VpRootDispatchThreadBlocked. That is the only remaining use of the counter enum.
- Due to the above, use num_present_cpus() as the number of LPs to map stats pages for - this number shouldn't change at runtime because the hypervisor doesn't support hotplug for root partition.

Changes in v3:
- Add 3 small refactor/cleanup patches (patches 2,3,4) from Stanislav. These simplify some of the debugfs code, and fix issues with mapping VP stats on L1VH.
- Fix cleanup of parent stats dentries on module removal (via squashing some internal patches into patch #6) [Praveen]
- Remove unused goto label [Stanislav, kernel bot]
- Use struct hv_stats_page * instead of void * in mshv_debugfs.c [Stanislav]
- Remove some redundant variables [Stanislav]
- Rename debugfs dentry fields for brevity [Stanislav]
- Use ERR_CAST() for the dentry error pointer returned from lp_debugfs_stats_create() [Stanislav]
- Fix leak of pages allocated for lp stats mappings by storing them in an array [Michael]
- Add comments to clarify PARENT vs SELF usage and edge cases [Michael]
- Add VpLoadAvg for x86 and print the stat [Michael]
- Add NUM_STATS_AREAS for array sizing in mshv_debugfs.c [Michael]

Changes in v2:
- Remove unnecessary pr_debug_once() in patch 1 [Stanislav Kinsburskii]
- CONFIG_X86 -> CONFIG_X86_64 in patch 2 [Stanislav Kinsburskii]

---
Nuno Das Neves (3):
mshv: Update hv_stats_page definitions
mshv: Add data for printing stats page counters
mshv: Add debugfs to view hypervisor statistics

Purna Pavan Chandra Aekkaladevi (1):
mshv: Ignore second stats page map result failure

Stanislav Kinsburskii (3):
mshv: Use typed hv_stats_page pointers
mshv: Improve mshv_vp_stats_map/unmap(), add them to mshv_root.h
mshv: Always map child vp stats pages regardless of scheduler type

 drivers/hv/Makefile                |   1 +
 drivers/hv/mshv_debugfs.c          | 726 +++++++++++++++++++++++++++++
 drivers/hv/mshv_debugfs_counters.c | 490 +++++++++++++++++++
 drivers/hv/mshv_root.h             |  49 +-
 drivers/hv/mshv_root_hv_call.c     |  64 ++-
 drivers/hv/mshv_root_main.c        | 140 +++---
 include/hyperv/hvhdk.h             |   7 +
 7 files changed, 1412 insertions(+), 65 deletions(-)
 create mode 100644 drivers/hv/mshv_debugfs.c
 create mode 100644 drivers/hv/mshv_debugfs_counters.c
Quoted 2 lines

--
2.34.1

Everything looks good to me.

For the entire series,

Acked-by on the v6 series
#9 lore raw
In reply to Nuno Das Neves
Quoted 4 lines · Nuno Das Neves

Expose hypervisor, logical processor, partition, and virtual processor statistics via debugfs. These are provided by mapping 'stats' pages via hypercall.

For the whole series:

Quoted 97 lines

Patch #1: Update hv_call_map_stats_page() to return success when
HV_STATS_AREA_PARENT is unavailable, which is the case on some hypervisor versions, where it can fall back to HV_STATS_AREA_SELF
Patch #2: Use struct hv_stats_page pointers instead of void * Patch #3: Make mshv_vp_stats_map/unmap() more flexible to use with debugfs
code
Patch #4: Always map vp stats page regardless of scheduler, to reuse in
debugfs
Patch #5: Change to hv_stats_page definition and
VpRootDispatchThreadBlocked
Patch #6: Introduce the definitions needed for the various stats pages Patch #7: Add mshv_debugfs.c, and integrate it with the mshv_root driver to
expose the partition and VP stats.

---
Changes in v6:
- Fix whitespace and other checkpatch issues [Michael]

Changes in v5:
- Rename hv_counters.c to mshv_debugfs_counters.c [Michael]
- Clarify unusual inclusion of mshv_debugfs_counters.c with comment. After discussion it is still included directly to keep things simple. Including arrays with unspecified size via a header means sizeof() cannot be used on the array.
- Error if mshv_debugfs_counters.c is included elsewhere than mshv_debugfs.c
- Use array index as stats page index to save space [Stanislav]
- Enforce HV_STATS_AREA_PARENT and SELF fit in NUM_STATS_AREAS with static_assert and clarify with comment [Michael]
- Return to using lp count from hv stats page for mshv_lps_count [Michael]
- Use nr_cpu_ids instead of num_possible_cpus() [Michael]
- Set mshv_lps_stats[idx] and the array itself to NULL on unmap and cleanup [Michael]
- Rename HvLogicalProcessors and VpRootDispatchThreadBlocked to Linux style
- Translate Linux cpu index to vp index via hv_vp_index on partition destroy [Michael]
- Minor formatting cleanups [Michael]

Changes in v4:
- Put the counters definitions in static arrays in hv_counters.c, instead of as enums in hvhdk.h [Michael]
- Due to the above, add an additional patch (#5) to simplify hv_stats_page, and retain the enum definition at the top of mshv_root_main.c for use with VpRootDispatchThreadBlocked. That is the only remaining use of the counter enum.
- Due to the above, use num_present_cpus() as the number of LPs to map stats pages for - this number shouldn't change at runtime because the hypervisor doesn't support hotplug for root partition.

Changes in v3:
- Add 3 small refactor/cleanup patches (patches 2,3,4) from Stanislav. These simplify some of the debugfs code, and fix issues with mapping VP stats on L1VH.
- Fix cleanup of parent stats dentries on module removal (via squashing some internal patches into patch #6) [Praveen]
- Remove unused goto label [Stanislav, kernel bot]
- Use struct hv_stats_page * instead of void * in mshv_debugfs.c [Stanislav]
- Remove some redundant variables [Stanislav]
- Rename debugfs dentry fields for brevity [Stanislav]
- Use ERR_CAST() for the dentry error pointer returned from lp_debugfs_stats_create() [Stanislav]
- Fix leak of pages allocated for lp stats mappings by storing them in an array [Michael]
- Add comments to clarify PARENT vs SELF usage and edge cases [Michael]
- Add VpLoadAvg for x86 and print the stat [Michael]
- Add NUM_STATS_AREAS for array sizing in mshv_debugfs.c [Michael]

Changes in v2:
- Remove unnecessary pr_debug_once() in patch 1 [Stanislav Kinsburskii]
- CONFIG_X86 -> CONFIG_X86_64 in patch 2 [Stanislav Kinsburskii]

---
Nuno Das Neves (3):
mshv: Update hv_stats_page definitions
mshv: Add data for printing stats page counters
mshv: Add debugfs to view hypervisor statistics

Purna Pavan Chandra Aekkaladevi (1):
mshv: Ignore second stats page map result failure

Stanislav Kinsburskii (3):
mshv: Use typed hv_stats_page pointers
mshv: Improve mshv_vp_stats_map/unmap(), add them to mshv_root.h
mshv: Always map child vp stats pages regardless of scheduler type

 drivers/hv/Makefile                |   1 +
 drivers/hv/mshv_debugfs.c          | 726 +++++++++++++++++++++++++++++
 drivers/hv/mshv_debugfs_counters.c | 490 +++++++++++++++++++
 drivers/hv/mshv_root.h             |  49 +-
 drivers/hv/mshv_root_hv_call.c     |  64 ++-
 drivers/hv/mshv_root_main.c        | 140 +++---
 include/hyperv/hvhdk.h             |   7 +
 7 files changed, 1412 insertions(+), 65 deletions(-)
 create mode 100644 drivers/hv/mshv_debugfs.c
 create mode 100644 drivers/hv/mshv_debugfs_counters.c
Signature · 1 line
2.34.1
maintainer Applied
#10 lore raw
In reply to Nuno Das Neves
Quoted 18 lines · Nuno Das Neves

Expose hypervisor, logical processor, partition, and virtual processor statistics via debugfs. These are provided by mapping 'stats' pages via hypercall.

Patch #1: Update hv_call_map_stats_page() to return success when
HV_STATS_AREA_PARENT is unavailable, which is the case on some hypervisor versions, where it can fall back to HV_STATS_AREA_SELF
Patch #2: Use struct hv_stats_page pointers instead of void * Patch #3: Make mshv_vp_stats_map/unmap() more flexible to use with debugfs
code
Patch #4: Always map vp stats page regardless of scheduler, to reuse in
debugfs
Patch #5: Change to hv_stats_page definition and
VpRootDispatchThreadBlocked
Patch #6: Introduce the definitions needed for the various stats pages Patch #7: Add mshv_debugfs.c, and integrate it with the mshv_root driver to
expose the partition and VP stats.

[...]

Quoted 12 lines
 drivers/hv/Makefile                |   1 +
 drivers/hv/mshv_debugfs.c          | 726 +++++++++++++++++++++++++++++
 drivers/hv/mshv_debugfs_counters.c | 490 +++++++++++++++++++
 drivers/hv/mshv_root.h             |  49 +-
 drivers/hv/mshv_root_hv_call.c     |  64 ++-
 drivers/hv/mshv_root_main.c        | 140 +++---
 include/hyperv/hvhdk.h             |   7 +
 7 files changed, 1412 insertions(+), 65 deletions(-)
 create mode 100644 drivers/hv/mshv_debugfs.c
 create mode 100644 drivers/hv/mshv_debugfs_counters.c

Applied to hyperv-next. Thank you!