From nobody Sat Feb 7 07:24:56 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 197502737E0; Wed, 28 Jan 2026 18:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623909; cv=none; b=fV67jP5doCyR5JU5Wgo17Ucw+nWhIeUJ94o+tFRMGYqbRklFwYoTLqgfXoA8xAvrPQJ/eVSEX8xoXQSvAAMHMjFgcBVccqiW+KJteE5Hw+gETKRasqt2M+Re5KdsCHuKRSMoJZpkl4GIsSWuzPbD4JMZ9rskaUB079lXPHTJ4OY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623909; c=relaxed/simple; bh=uzeRuEk6mtsIaTnRbzrMVlLOgjMqQcPry4umGAax9Uw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MizgtXn8N+OakOAZpn8gnN1abrzu2VeLr5GLJ094CdTCKj/+iOB33p4Fb/KENYk2tc/492+HeCp/WIbyYMiPvPFOdK2tIp1siwpZsgCawqS1TU4HkSVZP/XwKJPPOCnehrMLBuT48MwCzjAtPgAYEIq0/e0/hpWVmk7ANuhVznw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=p6qqXKpl; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="p6qqXKpl" Received: by linux.microsoft.com (Postfix, from userid 1032) id 09DD120B7167; Wed, 28 Jan 2026 10:11:48 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 09DD120B7167 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769623908; bh=z2o6YdqfB0oQMRtuk5ZapbPpFV9AcJv3FrMTfcI1w9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p6qqXKpl30xZz0Png5Og4ezy3ietOj0YGVmwTC4op1nmRdjfvTbVVuchWLUBs+2to L6CfRiEio82mGRlLwkDN+BqEY+IigmGd8rMapgsIlE1u7s4fiHCTmAYQumd6Bm0Bno oWdp/fCX3R2FU5Y53I8AusbUZYVWAJbh3+wqmF5E= From: Nuno Das Neves To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, mhklinux@outlook.com, skinsburskii@linux.microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com, prapal@linux.microsoft.com, mrathor@linux.microsoft.com, paekkaladevi@linux.microsoft.com, Nuno Das Neves Subject: [PATCH v6 1/7] mshv: Ignore second stats page map result failure Date: Wed, 28 Jan 2026 10:11:40 -0800 Message-ID: <20260128181146.517708-2-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> References: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Purna Pavan Chandra Aekkaladevi 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. Signed-off-by: Purna Pavan Chandra Aekkaladevi Signed-off-by: Nuno Das Neves Reviewed-by: Stanislav Kinsburskii Acked-by: Stanislav Kinsburskii --- drivers/hv/mshv_root_hv_call.c | 52 +++++++++++++++++++++++++++++++--- drivers/hv/mshv_root_main.c | 3 ++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c index 598eaff4ff29..1f93b94d7580 100644 --- a/drivers/hv/mshv_root_hv_call.c +++ b/drivers/hv/mshv_root_hv_call.c @@ -813,6 +813,13 @@ hv_call_notify_port_ring_empty(u32 sint_index) return hv_result_to_errno(status); } =20 +/* + * Equivalent of hv_call_map_stats_page() for cases when the caller provid= es + * the map location. + * + * NOTE: This is a newer hypercall that always supports SELF and PARENT st= ats + * 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_objec= t_type type, return ret; } =20 +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 exis= t on + * older hypervisor versions. All the available stats information can be f= ound + * 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 =3D 0; + int hv_status, ret =3D 0; =20 do { local_irq_save(flags); @@ -878,11 +913,20 @@ static int hv_call_map_stats_page(enum hv_stats_objec= t_type type, pfn =3D output->map_location; =20 local_irq_restore(flags); - if (hv_result(status) !=3D HV_STATUS_INSUFFICIENT_MEMORY) { - ret =3D hv_result_to_errno(status); + + hv_status =3D hv_result(status); + if (hv_status !=3D HV_STATUS_INSUFFICIENT_MEMORY) { if (hv_result_success(status)) break; - return ret; + + if (hv_stats_get_area_type(type, identity) =3D=3D HV_STATS_AREA_PARENT = && + hv_status =3D=3D HV_STATUS_INVALID_PARAMETER) { + *addr =3D NULL; + return 0; + } + + hv_status_debug(status, "\n"); + return hv_result_to_errno(status); } =20 ret =3D hv_call_deposit_pages(NUMA_NO_NODE, diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 1134a82c7881..1777778f84b8 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -992,6 +992,9 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_i= ndex, if (err) goto unmap_self; =20 + if (!stats_pages[HV_STATS_AREA_PARENT]) + stats_pages[HV_STATS_AREA_PARENT] =3D stats_pages[HV_STATS_AREA_SELF]; + return 0; =20 unmap_self: --=20 2.34.1 From nobody Sat Feb 7 07:24:56 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 334122BEC2E; Wed, 28 Jan 2026 18:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623909; cv=none; b=Rz5viB/xjpIwvuyW/jTbk700nmp/2R/s4BpYBa87jy60CNw8iRMqnoN+srI6vke482MSjAuvfXhonLaHr3U1lN6xppnST0AYhDegSv/rtP0c/rwzuQkdQef2PpRwmwmEyXJaLKnzpbBaGNd14u1LlHN8+HMmlGDI8kMJ0GktJgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623909; c=relaxed/simple; bh=HFNNVSweFvuB84DU2B4ROhCi6CUVW6aVVK9SMK14epw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kiiHBYX9YHJIAweYP2P3RglNNIIAoOVD3uhiMFgcYuOfV+tESct0P21BsUuGkSnpP7G95FM58DVy8iHBVmFlfi+2BTVzYuhEcuX87EjcC6KVInUO9b4wmvjDc9it5UJRqjvGjGfssBGOXpBRUhmUpBffeNO9JzJ12FvsD1uf2qg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=EMCkIVnX; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="EMCkIVnX" Received: by linux.microsoft.com (Postfix, from userid 1032) id 4665820B7168; Wed, 28 Jan 2026 10:11:48 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4665820B7168 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769623908; bh=ARHwRQoJMl3xBLyBPZgcJm/EEXDHa34ijHjF+rMvoPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EMCkIVnXlJUkQAeYL5v1rfH9ziaQKDiNQG4etyZRGAkMg8V5/TOqd4PkTVKxOboxU DJghxzSITzYu3m0UII91OS80HSHYhJ051BbZfypobe11gaR5ST32Nqh1yOiFrO36ic rxobBTWsLU/Et4q9e2Pcf6lu7vjEx2L36kJ50Z+I= From: Nuno Das Neves To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, mhklinux@outlook.com, skinsburskii@linux.microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com, prapal@linux.microsoft.com, mrathor@linux.microsoft.com, paekkaladevi@linux.microsoft.com, Nuno Das Neves Subject: [PATCH v6 2/7] mshv: Use typed hv_stats_page pointers Date: Wed, 28 Jan 2026 10:11:41 -0800 Message-ID: <20260128181146.517708-3-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> References: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Stanislav Kinsburskii 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. Signed-off-by: Stanislav Kinsburskii Signed-off-by: Nuno Das Neves Acked-by: Stanislav Kinsburskii --- 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(-) diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h index 3c1d88b36741..05ba1f716f9e 100644 --- a/drivers/hv/mshv_root.h +++ b/drivers/hv/mshv_root.h @@ -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, diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c index 1f93b94d7580..daee036e48bc 100644 --- a/drivers/hv/mshv_root_hv_call.c +++ b/drivers/hv/mshv_root_hv_call.c @@ -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, =20 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 =3D NULL; @@ -990,7 +991,8 @@ static int hv_call_unmap_stats_page(enum hv_stats_objec= t_type type, return hv_result_to_errno(status); } =20 -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; diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 1777778f84b8..be5ad0fbfbee 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -957,7 +957,7 @@ mshv_vp_release(struct inode *inode, struct file *filp) } =20 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 =3D { .vp.partition_id =3D partition_id, @@ -972,7 +972,7 @@ static void mshv_vp_stats_unmap(u64 partition_id, u32 v= p_index, } =20 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 =3D { .vp.partition_id =3D 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; =20 if (copy_from_user(&args, arg, sizeof(args))) @@ -1729,7 +1729,7 @@ static void destroy_partition(struct mshv_partition *= partition) =20 if (hv_scheduler_type =3D=3D HV_SCHEDULER_TYPE_ROOT) mshv_vp_stats_unmap(partition->pt_id, vp->vp_index, - (void **)vp->vp_stats_pages); + vp->vp_stats_pages); =20 if (vp->vp_register_page) { (void)hv_unmap_vp_state_page(partition->pt_id, --=20 2.34.1 From nobody Sat Feb 7 07:24:56 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 514A12FE58D; Wed, 28 Jan 2026 18:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623909; cv=none; b=rfqH2eyZ1qZu+GjI2xfpAqxsRAyP4RLQdcwnaCBLG+uBbKZ07dlZkxDzDsGk6D6OtTfYEbdNZ1zz/ux6uzHz4Lsn75JmvqIKI4GjNeJuMV0Lay/7NMAguEftwl4VfOaE0H6SirAlvk8pKil6uAF+WDMNfr5xIM+nB6tZs47KNz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623909; c=relaxed/simple; bh=XoWr9E6GpJVfiqW5j7TGfpouzFnYRVdh59ggwDHSzrU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TQyZWTWuNS/a+7Cno5qaKHj4Sp7h/6rbTtrT+dF+kQBYoL2+hfHyhh6ARXQHUf7eZLYz6YNFsmRDuBokJBEwAih3vNRYdKWYCVhollmaDv+zKM9wfe/ZiMtLdEAiiMkji3vgovSd80EUkqw8+XgcFZFohvyOXq3MgncSjZOp5Q4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=HYkCrrRk; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="HYkCrrRk" Received: by linux.microsoft.com (Postfix, from userid 1032) id 685AA20B7169; Wed, 28 Jan 2026 10:11:48 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 685AA20B7169 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769623908; bh=LLskYnn36sZloCu/fmiglMXyDQHLYorP70jSLnEIhig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HYkCrrRkHwd+9RpnENrKsrlQbUQSPB9zSzP0onXiqxkfx65V8dfl0A9DZyLc27NH8 1DBRBZe+uGEYOJdqC9FNKVySGREVFzZTtwNptg7GnqEJ1u1tY/JWLDeIAPfehQ8FAM c/DR9Ae30X78JUfCG3aPvcZtuNfcR+Y05HbLkZNs= From: Nuno Das Neves To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, mhklinux@outlook.com, skinsburskii@linux.microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com, prapal@linux.microsoft.com, mrathor@linux.microsoft.com, paekkaladevi@linux.microsoft.com, Nuno Das Neves Subject: [PATCH v6 3/7] mshv: Improve mshv_vp_stats_map/unmap(), add them to mshv_root.h Date: Wed, 28 Jan 2026 10:11:42 -0800 Message-ID: <20260128181146.517708-4-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> References: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Stanislav Kinsburskii 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(). Signed-off-by: Stanislav Kinsburskii Signed-off-by: Nuno Das Neves Acked-by: Stanislav Kinsburskii --- drivers/hv/mshv_root.h | 10 ++++++ drivers/hv/mshv_root_main.c | 61 ++++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h index 05ba1f716f9e..e4912b0618fa 100644 --- a/drivers/hv/mshv_root.h +++ b/drivers/hv/mshv_root.h @@ -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(R= CU); =20 +static inline bool is_l1vh_parent(u64 partition_id) +{ + return hv_l1vh_partition() && (partition_id =3D=3D 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 */ =20 int hv_call_withdraw_memory(u64 count, int node, u64 partition_id); diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index be5ad0fbfbee..faca3cc63e79 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -956,23 +956,36 @@ mshv_vp_release(struct inode *inode, struct file *fil= p) return 0; } =20 -static void mshv_vp_stats_unmap(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[]) { union hv_stats_object_identity identity =3D { .vp.partition_id =3D partition_id, .vp.vp_index =3D vp_index, }; + int err; =20 identity.vp.stats_area_type =3D HV_STATS_AREA_SELF; - hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity); - - identity.vp.stats_area_type =3D HV_STATS_AREA_PARENT; - hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity); + err =3D hv_unmap_stats_page(HV_STATS_OBJECT_VP, + stats_pages[HV_STATS_AREA_SELF], + &identity); + if (err) + pr_err("%s: failed to unmap partition %llu vp %u self stats, err: %d\n", + __func__, partition_id, vp_index, err); + + if (stats_pages[HV_STATS_AREA_PARENT] !=3D stats_pages[HV_STATS_AREA_SELF= ]) { + identity.vp.stats_area_type =3D HV_STATS_AREA_PARENT; + err =3D hv_unmap_stats_page(HV_STATS_OBJECT_VP, + stats_pages[HV_STATS_AREA_PARENT], + &identity); + if (err) + pr_err("%s: failed to unmap partition %llu vp %u parent stats, err: %d\= n", + __func__, partition_id, vp_index, err); + } } =20 -static int mshv_vp_stats_map(u64 partition_id, u32 vp_index, - struct hv_stats_page *stats_pages[]) +int mshv_vp_stats_map(u64 partition_id, u32 vp_index, + struct hv_stats_page *stats_pages[]) { union hv_stats_object_identity identity =3D { .vp.partition_id =3D partition_id, @@ -983,23 +996,37 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp= _index, identity.vp.stats_area_type =3D HV_STATS_AREA_SELF; err =3D hv_map_stats_page(HV_STATS_OBJECT_VP, &identity, &stats_pages[HV_STATS_AREA_SELF]); - if (err) + if (err) { + pr_err("%s: failed to map partition %llu vp %u self stats, err: %d\n", + __func__, partition_id, vp_index, err); return err; + } =20 - identity.vp.stats_area_type =3D HV_STATS_AREA_PARENT; - err =3D hv_map_stats_page(HV_STATS_OBJECT_VP, &identity, - &stats_pages[HV_STATS_AREA_PARENT]); - if (err) - goto unmap_self; - - if (!stats_pages[HV_STATS_AREA_PARENT]) + /* + * L1VH partition cannot access its vp stats in parent area. + */ + if (is_l1vh_parent(partition_id)) { stats_pages[HV_STATS_AREA_PARENT] =3D stats_pages[HV_STATS_AREA_SELF]; + } else { + identity.vp.stats_area_type =3D HV_STATS_AREA_PARENT; + err =3D hv_map_stats_page(HV_STATS_OBJECT_VP, &identity, + &stats_pages[HV_STATS_AREA_PARENT]); + if (err) { + pr_err("%s: failed to map partition %llu vp %u parent stats, err: %d\n", + __func__, partition_id, vp_index, err); + goto unmap_self; + } + if (!stats_pages[HV_STATS_AREA_PARENT]) + stats_pages[HV_STATS_AREA_PARENT] =3D stats_pages[HV_STATS_AREA_SELF]; + } =20 return 0; =20 unmap_self: identity.vp.stats_area_type =3D HV_STATS_AREA_SELF; - hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity); + hv_unmap_stats_page(HV_STATS_OBJECT_VP, + stats_pages[HV_STATS_AREA_SELF], + &identity); return err; } =20 --=20 2.34.1 From nobody Sat Feb 7 07:24:56 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93E2030DD03; Wed, 28 Jan 2026 18:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623909; cv=none; b=EaEbN1Umnt4Rut1Eu/T6E6h6a8WxIrD0j+tGOo9L8YaJBl8U2k7Xb2nZxTXP8rzUN9LeeUwjTmu1M9ToReMsYJzqS2hiEmJduBbv9c+qrP3YbFKfINcrb7RKZJYsb17EoaQ54ZVjefS6jifnrMSviWLftqoiV0qGXwFcQi2le6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623909; c=relaxed/simple; bh=L4E1wo8/6fKvJEozXW8vtzU2hTEpjK6jREA7Bfv0oJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZyBJzX84k/UvHCnGrNVofE+P73Wa1p6IPh2dc3hdEJBesXiTF6OAJVBIx1X7sJBsunE3e9g0/rvTxLOc3mZh7V3K1yjXylXIXtHYi2sPfByCDi8q6OUakBuQx28DoO9M1K/wDgFljxAtMlIwdiwsfcYVz3z/lL+i2ShS/Y3gPVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=bC7bYxjB; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="bC7bYxjB" Received: by linux.microsoft.com (Postfix, from userid 1032) id AC38A20B716A; Wed, 28 Jan 2026 10:11:48 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AC38A20B716A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769623908; bh=uE6yNFSdJktjcXi31tIk+NXAAyXVgXT3CJcMYC5oQGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bC7bYxjBQBCrgzTJZ0LBNetaU2vUYgAYoNGyHXno1kzrohE7yF8Mwhu1cHQc2hYC7 tW976ZRpONWqj2P7jXQaxSmwSO/2ZvEKTG+n86X1+aURFvjNWVW7WNyRo2rnU0HcRC at8YEqWPR/CUrlos9bTUxS9t28kX+5msEvpc4xgA= From: Nuno Das Neves To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, mhklinux@outlook.com, skinsburskii@linux.microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com, prapal@linux.microsoft.com, mrathor@linux.microsoft.com, paekkaladevi@linux.microsoft.com, Nuno Das Neves Subject: [PATCH v6 4/7] mshv: Always map child vp stats pages regardless of scheduler type Date: Wed, 28 Jan 2026 10:11:43 -0800 Message-ID: <20260128181146.517708-5-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> References: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Stanislav Kinsburskii 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. Signed-off-by: Stanislav Kinsburskii Signed-off-by: Nuno Das Neves Acked-by: Stanislav Kinsburskii --- drivers/hv/mshv_root_main.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index faca3cc63e79..fbfc9e7d9fa4 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -1077,16 +1077,10 @@ mshv_partition_ioctl_create_vp(struct mshv_partitio= n *partition, goto unmap_register_page; } =20 - /* - * This mapping of the stats page is for detecting if dispatch thread - * is blocked - only relevant for root scheduler - */ - if (hv_scheduler_type =3D=3D HV_SCHEDULER_TYPE_ROOT) { - ret =3D mshv_vp_stats_map(partition->pt_id, args.vp_index, - stats_pages); - if (ret) - goto unmap_ghcb_page; - } + ret =3D mshv_vp_stats_map(partition->pt_id, args.vp_index, + stats_pages); + if (ret) + goto unmap_ghcb_page; =20 vp =3D 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 =3D page_to_virt(ghcb_page); =20 - if (hv_scheduler_type =3D=3D HV_SCHEDULER_TYPE_ROOT) - memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages)); + memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages)); =20 /* * 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 =3D=3D 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; =20 - if (hv_scheduler_type =3D=3D 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); =20 if (vp->vp_register_page) { (void)hv_unmap_vp_state_page(partition->pt_id, --=20 2.34.1 From nobody Sat Feb 7 07:24:56 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B5FD36EAB6; Wed, 28 Jan 2026 18:11:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623910; cv=none; b=tBA/1g8ao569RhaNTnVMwR63Vu2hQyPnPjCNACYcB7yTUwIwbTh4JgqOXhuBAJFYNONm8AKhaSau57cY6K+2pLCU0gpu4Ah1LIRp7V9HWLzUvgJRzQwrMjLLvfTiekKvpUpWgCEyjU1yRhs4M9xu4B0f9JIv0FNe0K9SgoWhKjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623910; c=relaxed/simple; bh=vIRH8VDWdNsEhFXuPSCq00V3pn3IFa1wRT7mYXnnmj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DDUyEHGt8D4/E3bzx3Bu3483TFh83cw3FtWtT+bZBmHtBXUnWxm5GjTodC4XYltIPDD1/D2ZFYEfg3aCTInFJtSc9jJi5RGWWLvJ7VglKqZ5q5uK3pk+4Q8cqd/SQHnQvtutojieG9FgWtdGcsVcsHpLq9FdvecjY+VdRS5a55U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=rP4Cocqg; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="rP4Cocqg" Received: by linux.microsoft.com (Postfix, from userid 1032) id DAD0020B716B; Wed, 28 Jan 2026 10:11:48 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DAD0020B716B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769623908; bh=ep4GmkV6PrsxU5Ez3hsswpTJDjwvDSgFu/tErSVW+YE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rP4CocqgcDEaKApNBbMJlbCEyhW3bMFGKmkJwDO5KAErDdI8aGywYFP+89ySON0+l Ipik9JNFV7ddhpcN9/LpSOroIgTnYc2L7ljTixpRXc0FLkglPIKXdnuP8V14OBHUyh /7eUu7/Bv4nAqHqM6tL4ZLL4f+piGwdmzlwx4QXA= From: Nuno Das Neves To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, mhklinux@outlook.com, skinsburskii@linux.microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com, prapal@linux.microsoft.com, mrathor@linux.microsoft.com, paekkaladevi@linux.microsoft.com, Nuno Das Neves Subject: [PATCH v6 5/7] mshv: Update hv_stats_page definitions Date: Wed, 28 Jan 2026 10:11:44 -0800 Message-ID: <20260128181146.517708-6-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> References: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Nuno Das Neves Acked-by: Stanislav Kinsburskii --- drivers/hv/mshv_root_main.c | 27 ++++++++------------------- include/hyperv/hvhdk.h | 7 +++++++ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index fbfc9e7d9fa4..414d9cee5252 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -39,22 +39,12 @@ MODULE_AUTHOR("Microsoft"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface /dev/ms= hv"); =20 -/* TODO move this to another file when debugfs code is added */ -enum hv_stats_vp_counters { /* HV_THREAD_COUNTER */ -#if defined(CONFIG_X86) - VpRootDispatchThreadBlocked =3D 202, +/* HV_THREAD_COUNTER */ +#if defined(CONFIG_X86_64) +#define HV_VP_COUNTER_ROOT_DISPATCH_THREAD_BLOCKED 202 #elif defined(CONFIG_ARM64) - VpRootDispatchThreadBlocked =3D 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; =20 struct mshv_root mshv_root; =20 @@ -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 =3D vp->vp_stats_pages; - u64 *self_vp_cntrs =3D stats[HV_STATS_AREA_SELF]->vp_cntrs; - u64 *parent_vp_cntrs =3D stats[HV_STATS_AREA_PARENT]->vp_cntrs; + u64 *self_vp_cntrs =3D stats[HV_STATS_AREA_SELF]->data; + u64 *parent_vp_cntrs =3D stats[HV_STATS_AREA_PARENT]->data; =20 - 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]; } =20 static int diff --git a/include/hyperv/hvhdk.h b/include/hyperv/hvhdk.h index 469186df7826..d87cfdb7d360 100644 --- a/include/hyperv/hvhdk.h +++ b/include/hyperv/hvhdk.h @@ -10,6 +10,13 @@ #include "hvhdk_mini.h" #include "hvgdk.h" =20 +/* + * 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 --=20 2.34.1 From nobody Sat Feb 7 07:24:56 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B68536F418; Wed, 28 Jan 2026 18:11:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623911; cv=none; b=BJnSWjTS4S9lpBwJhb/pwTO+MsaMKHS078EX31Eg0EODkJW6gy9o/yuPkEMS/8egZA80wLDKN5pvkhCjUOE+niqQDm7wR/Z941qpDxazJsoV6XeeA/jUXRDEpQyWhtFYCm/IuMzfm80dHsDBEvjjNdzhE0Md8becmAYSP3IwiM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623911; c=relaxed/simple; bh=qb6F6pahYHkxyNoSN0tagZwnPObujXZH8LBa1jSt/5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uglHHG3SgrQP603R4mU7inhU2hun5aMg+hqfPZjFR5KRkxA0l+gJXRleCWhLpdDBfrTABhemAH/Lro823ON56kQV8lSkLFx8Tu9KYLWlRKVzjjTCd2BLJgnxdUlGZriOMD36zFCY4N7/SOZJfo6SAQkh3/8CsxuZEmOzMOm7nWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=iPur6vrA; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="iPur6vrA" Received: by linux.microsoft.com (Postfix, from userid 1032) id 1323020B716C; Wed, 28 Jan 2026 10:11:49 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1323020B716C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769623909; bh=VhykpXRd2RJmYlq5I0euhkx7hoXhpjbrk8wu/IXvGcA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iPur6vrAVXKq+KqiWEaaJlhKFGdVGIiqmMPE23VGz4Gf9eXRMg0OUKL+xoMj5oc3c RzpZYGDybWzwWP4So/KFS+3/mlQmFmpraAONMGjRuxr31RiJigFbSmV2Wb/gCK8Io0 /85WUZxgfK0H7ClJqw03nSnpxO97AvmEsu7b/wyY= From: Nuno Das Neves To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, mhklinux@outlook.com, skinsburskii@linux.microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com, prapal@linux.microsoft.com, mrathor@linux.microsoft.com, paekkaladevi@linux.microsoft.com, Nuno Das Neves Subject: [PATCH v6 6/7] mshv: Add data for printing stats page counters Date: Wed, 28 Jan 2026 10:11:45 -0800 Message-ID: <20260128181146.517708-7-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> References: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Nuno Das Neves Acked-by: Stanislav Kinsburskii --- drivers/hv/mshv_debugfs_counters.c | 490 +++++++++++++++++++++++++++++ 1 file changed, 490 insertions(+) create mode 100644 drivers/hv/mshv_debugfs_counters.c diff --git a/drivers/hv/mshv_debugfs_counters.c b/drivers/hv/mshv_debugfs_c= ounters.c new file mode 100644 index 000000000000..978536ba691f --- /dev/null +++ b/drivers/hv/mshv_debugfs_counters.c @@ -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[] =3D { + [1] =3D "HvLogicalProcessors", + [2] =3D "HvPartitions", + [3] =3D "HvTotalPages", + [4] =3D "HvVirtualProcessors", + [5] =3D "HvMonitoredNotifications", + [6] =3D "HvModernStandbyEntries", + [7] =3D "HvPlatformIdleTransitions", + [8] =3D "HvHypervisorStartupCost", + + [10] =3D "HvIOSpacePages", + [11] =3D "HvNonEssentialPagesForDump", + [12] =3D "HvSubsumedPages", +}; + +/* HV_CPU_COUNTER */ +static char *hv_lp_counters[] =3D { + [1] =3D "LpGlobalTime", + [2] =3D "LpTotalRunTime", + [3] =3D "LpHypervisorRunTime", + [4] =3D "LpHardwareInterrupts", + [5] =3D "LpContextSwitches", + [6] =3D "LpInterProcessorInterrupts", + [7] =3D "LpSchedulerInterrupts", + [8] =3D "LpTimerInterrupts", + [9] =3D "LpInterProcessorInterruptsSent", + [10] =3D "LpProcessorHalts", + [11] =3D "LpMonitorTransitionCost", + [12] =3D "LpContextSwitchTime", + [13] =3D "LpC1TransitionsCount", + [14] =3D "LpC1RunTime", + [15] =3D "LpC2TransitionsCount", + [16] =3D "LpC2RunTime", + [17] =3D "LpC3TransitionsCount", + [18] =3D "LpC3RunTime", + [19] =3D "LpRootVpIndex", + [20] =3D "LpIdleSequenceNumber", + [21] =3D "LpGlobalTscCount", + [22] =3D "LpActiveTscCount", + [23] =3D "LpIdleAccumulation", + [24] =3D "LpReferenceCycleCount0", + [25] =3D "LpActualCycleCount0", + [26] =3D "LpReferenceCycleCount1", + [27] =3D "LpActualCycleCount1", + [28] =3D "LpProximityDomainId", + [29] =3D "LpPostedInterruptNotifications", + [30] =3D "LpBranchPredictorFlushes", +#if IS_ENABLED(CONFIG_X86_64) + [31] =3D "LpL1DataCacheFlushes", + [32] =3D "LpImmediateL1DataCacheFlushes", + [33] =3D "LpMbFlushes", + [34] =3D "LpCounterRefreshSequenceNumber", + [35] =3D "LpCounterRefreshReferenceTime", + [36] =3D "LpIdleAccumulationSnapshot", + [37] =3D "LpActiveTscCountSnapshot", + [38] =3D "LpHwpRequestContextSwitches", + [39] =3D "LpPlaceholder1", + [40] =3D "LpPlaceholder2", + [41] =3D "LpPlaceholder3", + [42] =3D "LpPlaceholder4", + [43] =3D "LpPlaceholder5", + [44] =3D "LpPlaceholder6", + [45] =3D "LpPlaceholder7", + [46] =3D "LpPlaceholder8", + [47] =3D "LpPlaceholder9", + [48] =3D "LpSchLocalRunListSize", + [49] =3D "LpReserveGroupId", + [50] =3D "LpRunningPriority", + [51] =3D "LpPerfmonInterruptCount", +#elif IS_ENABLED(CONFIG_ARM64) + [31] =3D "LpCounterRefreshSequenceNumber", + [32] =3D "LpCounterRefreshReferenceTime", + [33] =3D "LpIdleAccumulationSnapshot", + [34] =3D "LpActiveTscCountSnapshot", + [35] =3D "LpHwpRequestContextSwitches", + [36] =3D "LpPlaceholder2", + [37] =3D "LpPlaceholder3", + [38] =3D "LpPlaceholder4", + [39] =3D "LpPlaceholder5", + [40] =3D "LpPlaceholder6", + [41] =3D "LpPlaceholder7", + [42] =3D "LpPlaceholder8", + [43] =3D "LpPlaceholder9", + [44] =3D "LpSchLocalRunListSize", + [45] =3D "LpReserveGroupId", + [46] =3D "LpRunningPriority", +#endif +}; + +/* HV_PROCESS_COUNTER */ +static char *hv_partition_counters[] =3D { + [1] =3D "PtVirtualProcessors", + + [3] =3D "PtTlbSize", + [4] =3D "PtAddressSpaces", + [5] =3D "PtDepositedPages", + [6] =3D "PtGpaPages", + [7] =3D "PtGpaSpaceModifications", + [8] =3D "PtVirtualTlbFlushEntires", + [9] =3D "PtRecommendedTlbSize", + [10] =3D "PtGpaPages4K", + [11] =3D "PtGpaPages2M", + [12] =3D "PtGpaPages1G", + [13] =3D "PtGpaPages512G", + [14] =3D "PtDevicePages4K", + [15] =3D "PtDevicePages2M", + [16] =3D "PtDevicePages1G", + [17] =3D "PtDevicePages512G", + [18] =3D "PtAttachedDevices", + [19] =3D "PtDeviceInterruptMappings", + [20] =3D "PtIoTlbFlushes", + [21] =3D "PtIoTlbFlushCost", + [22] =3D "PtDeviceInterruptErrors", + [23] =3D "PtDeviceDmaErrors", + [24] =3D "PtDeviceInterruptThrottleEvents", + [25] =3D "PtSkippedTimerTicks", + [26] =3D "PtPartitionId", +#if IS_ENABLED(CONFIG_X86_64) + [27] =3D "PtNestedTlbSize", + [28] =3D "PtRecommendedNestedTlbSize", + [29] =3D "PtNestedTlbFreeListSize", + [30] =3D "PtNestedTlbTrimmedPages", + [31] =3D "PtPagesShattered", + [32] =3D "PtPagesRecombined", + [33] =3D "PtHwpRequestValue", + [34] =3D "PtAutoSuspendEnableTime", + [35] =3D "PtAutoSuspendTriggerTime", + [36] =3D "PtAutoSuspendDisableTime", + [37] =3D "PtPlaceholder1", + [38] =3D "PtPlaceholder2", + [39] =3D "PtPlaceholder3", + [40] =3D "PtPlaceholder4", + [41] =3D "PtPlaceholder5", + [42] =3D "PtPlaceholder6", + [43] =3D "PtPlaceholder7", + [44] =3D "PtPlaceholder8", + [45] =3D "PtHypervisorStateTransferGeneration", + [46] =3D "PtNumberofActiveChildPartitions", +#elif IS_ENABLED(CONFIG_ARM64) + [27] =3D "PtHwpRequestValue", + [28] =3D "PtAutoSuspendEnableTime", + [29] =3D "PtAutoSuspendTriggerTime", + [30] =3D "PtAutoSuspendDisableTime", + [31] =3D "PtPlaceholder1", + [32] =3D "PtPlaceholder2", + [33] =3D "PtPlaceholder3", + [34] =3D "PtPlaceholder4", + [35] =3D "PtPlaceholder5", + [36] =3D "PtPlaceholder6", + [37] =3D "PtPlaceholder7", + [38] =3D "PtPlaceholder8", + [39] =3D "PtHypervisorStateTransferGeneration", + [40] =3D "PtNumberofActiveChildPartitions", +#endif +}; + +/* HV_THREAD_COUNTER */ +static char *hv_vp_counters[] =3D { + [1] =3D "VpTotalRunTime", + [2] =3D "VpHypervisorRunTime", + [3] =3D "VpRemoteNodeRunTime", + [4] =3D "VpNormalizedRunTime", + [5] =3D "VpIdealCpu", + + [7] =3D "VpHypercallsCount", + [8] =3D "VpHypercallsTime", +#if IS_ENABLED(CONFIG_X86_64) + [9] =3D "VpPageInvalidationsCount", + [10] =3D "VpPageInvalidationsTime", + [11] =3D "VpControlRegisterAccessesCount", + [12] =3D "VpControlRegisterAccessesTime", + [13] =3D "VpIoInstructionsCount", + [14] =3D "VpIoInstructionsTime", + [15] =3D "VpHltInstructionsCount", + [16] =3D "VpHltInstructionsTime", + [17] =3D "VpMwaitInstructionsCount", + [18] =3D "VpMwaitInstructionsTime", + [19] =3D "VpCpuidInstructionsCount", + [20] =3D "VpCpuidInstructionsTime", + [21] =3D "VpMsrAccessesCount", + [22] =3D "VpMsrAccessesTime", + [23] =3D "VpOtherInterceptsCount", + [24] =3D "VpOtherInterceptsTime", + [25] =3D "VpExternalInterruptsCount", + [26] =3D "VpExternalInterruptsTime", + [27] =3D "VpPendingInterruptsCount", + [28] =3D "VpPendingInterruptsTime", + [29] =3D "VpEmulatedInstructionsCount", + [30] =3D "VpEmulatedInstructionsTime", + [31] =3D "VpDebugRegisterAccessesCount", + [32] =3D "VpDebugRegisterAccessesTime", + [33] =3D "VpPageFaultInterceptsCount", + [34] =3D "VpPageFaultInterceptsTime", + [35] =3D "VpGuestPageTableMaps", + [36] =3D "VpLargePageTlbFills", + [37] =3D "VpSmallPageTlbFills", + [38] =3D "VpReflectedGuestPageFaults", + [39] =3D "VpApicMmioAccesses", + [40] =3D "VpIoInterceptMessages", + [41] =3D "VpMemoryInterceptMessages", + [42] =3D "VpApicEoiAccesses", + [43] =3D "VpOtherMessages", + [44] =3D "VpPageTableAllocations", + [45] =3D "VpLogicalProcessorMigrations", + [46] =3D "VpAddressSpaceEvictions", + [47] =3D "VpAddressSpaceSwitches", + [48] =3D "VpAddressDomainFlushes", + [49] =3D "VpAddressSpaceFlushes", + [50] =3D "VpGlobalGvaRangeFlushes", + [51] =3D "VpLocalGvaRangeFlushes", + [52] =3D "VpPageTableEvictions", + [53] =3D "VpPageTableReclamations", + [54] =3D "VpPageTableResets", + [55] =3D "VpPageTableValidations", + [56] =3D "VpApicTprAccesses", + [57] =3D "VpPageTableWriteIntercepts", + [58] =3D "VpSyntheticInterrupts", + [59] =3D "VpVirtualInterrupts", + [60] =3D "VpApicIpisSent", + [61] =3D "VpApicSelfIpisSent", + [62] =3D "VpGpaSpaceHypercalls", + [63] =3D "VpLogicalProcessorHypercalls", + [64] =3D "VpLongSpinWaitHypercalls", + [65] =3D "VpOtherHypercalls", + [66] =3D "VpSyntheticInterruptHypercalls", + [67] =3D "VpVirtualInterruptHypercalls", + [68] =3D "VpVirtualMmuHypercalls", + [69] =3D "VpVirtualProcessorHypercalls", + [70] =3D "VpHardwareInterrupts", + [71] =3D "VpNestedPageFaultInterceptsCount", + [72] =3D "VpNestedPageFaultInterceptsTime", + [73] =3D "VpPageScans", + [74] =3D "VpLogicalProcessorDispatches", + [75] =3D "VpWaitingForCpuTime", + [76] =3D "VpExtendedHypercalls", + [77] =3D "VpExtendedHypercallInterceptMessages", + [78] =3D "VpMbecNestedPageTableSwitches", + [79] =3D "VpOtherReflectedGuestExceptions", + [80] =3D "VpGlobalIoTlbFlushes", + [81] =3D "VpGlobalIoTlbFlushCost", + [82] =3D "VpLocalIoTlbFlushes", + [83] =3D "VpLocalIoTlbFlushCost", + [84] =3D "VpHypercallsForwardedCount", + [85] =3D "VpHypercallsForwardingTime", + [86] =3D "VpPageInvalidationsForwardedCount", + [87] =3D "VpPageInvalidationsForwardingTime", + [88] =3D "VpControlRegisterAccessesForwardedCount", + [89] =3D "VpControlRegisterAccessesForwardingTime", + [90] =3D "VpIoInstructionsForwardedCount", + [91] =3D "VpIoInstructionsForwardingTime", + [92] =3D "VpHltInstructionsForwardedCount", + [93] =3D "VpHltInstructionsForwardingTime", + [94] =3D "VpMwaitInstructionsForwardedCount", + [95] =3D "VpMwaitInstructionsForwardingTime", + [96] =3D "VpCpuidInstructionsForwardedCount", + [97] =3D "VpCpuidInstructionsForwardingTime", + [98] =3D "VpMsrAccessesForwardedCount", + [99] =3D "VpMsrAccessesForwardingTime", + [100] =3D "VpOtherInterceptsForwardedCount", + [101] =3D "VpOtherInterceptsForwardingTime", + [102] =3D "VpExternalInterruptsForwardedCount", + [103] =3D "VpExternalInterruptsForwardingTime", + [104] =3D "VpPendingInterruptsForwardedCount", + [105] =3D "VpPendingInterruptsForwardingTime", + [106] =3D "VpEmulatedInstructionsForwardedCount", + [107] =3D "VpEmulatedInstructionsForwardingTime", + [108] =3D "VpDebugRegisterAccessesForwardedCount", + [109] =3D "VpDebugRegisterAccessesForwardingTime", + [110] =3D "VpPageFaultInterceptsForwardedCount", + [111] =3D "VpPageFaultInterceptsForwardingTime", + [112] =3D "VpVmclearEmulationCount", + [113] =3D "VpVmclearEmulationTime", + [114] =3D "VpVmptrldEmulationCount", + [115] =3D "VpVmptrldEmulationTime", + [116] =3D "VpVmptrstEmulationCount", + [117] =3D "VpVmptrstEmulationTime", + [118] =3D "VpVmreadEmulationCount", + [119] =3D "VpVmreadEmulationTime", + [120] =3D "VpVmwriteEmulationCount", + [121] =3D "VpVmwriteEmulationTime", + [122] =3D "VpVmxoffEmulationCount", + [123] =3D "VpVmxoffEmulationTime", + [124] =3D "VpVmxonEmulationCount", + [125] =3D "VpVmxonEmulationTime", + [126] =3D "VpNestedVMEntriesCount", + [127] =3D "VpNestedVMEntriesTime", + [128] =3D "VpNestedSLATSoftPageFaultsCount", + [129] =3D "VpNestedSLATSoftPageFaultsTime", + [130] =3D "VpNestedSLATHardPageFaultsCount", + [131] =3D "VpNestedSLATHardPageFaultsTime", + [132] =3D "VpInvEptAllContextEmulationCount", + [133] =3D "VpInvEptAllContextEmulationTime", + [134] =3D "VpInvEptSingleContextEmulationCount", + [135] =3D "VpInvEptSingleContextEmulationTime", + [136] =3D "VpInvVpidAllContextEmulationCount", + [137] =3D "VpInvVpidAllContextEmulationTime", + [138] =3D "VpInvVpidSingleContextEmulationCount", + [139] =3D "VpInvVpidSingleContextEmulationTime", + [140] =3D "VpInvVpidSingleAddressEmulationCount", + [141] =3D "VpInvVpidSingleAddressEmulationTime", + [142] =3D "VpNestedTlbPageTableReclamations", + [143] =3D "VpNestedTlbPageTableEvictions", + [144] =3D "VpFlushGuestPhysicalAddressSpaceHypercalls", + [145] =3D "VpFlushGuestPhysicalAddressListHypercalls", + [146] =3D "VpPostedInterruptNotifications", + [147] =3D "VpPostedInterruptScans", + [148] =3D "VpTotalCoreRunTime", + [149] =3D "VpMaximumRunTime", + [150] =3D "VpHwpRequestContextSwitches", + [151] =3D "VpWaitingForCpuTimeBucket0", + [152] =3D "VpWaitingForCpuTimeBucket1", + [153] =3D "VpWaitingForCpuTimeBucket2", + [154] =3D "VpWaitingForCpuTimeBucket3", + [155] =3D "VpWaitingForCpuTimeBucket4", + [156] =3D "VpWaitingForCpuTimeBucket5", + [157] =3D "VpWaitingForCpuTimeBucket6", + [158] =3D "VpVmloadEmulationCount", + [159] =3D "VpVmloadEmulationTime", + [160] =3D "VpVmsaveEmulationCount", + [161] =3D "VpVmsaveEmulationTime", + [162] =3D "VpGifInstructionEmulationCount", + [163] =3D "VpGifInstructionEmulationTime", + [164] =3D "VpEmulatedErrataSvmInstructions", + [165] =3D "VpPlaceholder1", + [166] =3D "VpPlaceholder2", + [167] =3D "VpPlaceholder3", + [168] =3D "VpPlaceholder4", + [169] =3D "VpPlaceholder5", + [170] =3D "VpPlaceholder6", + [171] =3D "VpPlaceholder7", + [172] =3D "VpPlaceholder8", + [173] =3D "VpContentionTime", + [174] =3D "VpWakeUpTime", + [175] =3D "VpSchedulingPriority", + [176] =3D "VpRdpmcInstructionsCount", + [177] =3D "VpRdpmcInstructionsTime", + [178] =3D "VpPerfmonPmuMsrAccessesCount", + [179] =3D "VpPerfmonLbrMsrAccessesCount", + [180] =3D "VpPerfmonIptMsrAccessesCount", + [181] =3D "VpPerfmonInterruptCount", + [182] =3D "VpVtl1DispatchCount", + [183] =3D "VpVtl2DispatchCount", + [184] =3D "VpVtl2DispatchBucket0", + [185] =3D "VpVtl2DispatchBucket1", + [186] =3D "VpVtl2DispatchBucket2", + [187] =3D "VpVtl2DispatchBucket3", + [188] =3D "VpVtl2DispatchBucket4", + [189] =3D "VpVtl2DispatchBucket5", + [190] =3D "VpVtl2DispatchBucket6", + [191] =3D "VpVtl1RunTime", + [192] =3D "VpVtl2RunTime", + [193] =3D "VpIommuHypercalls", + [194] =3D "VpCpuGroupHypercalls", + [195] =3D "VpVsmHypercalls", + [196] =3D "VpEventLogHypercalls", + [197] =3D "VpDeviceDomainHypercalls", + [198] =3D "VpDepositHypercalls", + [199] =3D "VpSvmHypercalls", + [200] =3D "VpBusLockAcquisitionCount", + [201] =3D "VpLoadAvg", + [202] =3D "VpRootDispatchThreadBlocked", + [203] =3D "VpIdleCpuTime", + [204] =3D "VpWaitingForCpuTimeBucket7", + [205] =3D "VpWaitingForCpuTimeBucket8", + [206] =3D "VpWaitingForCpuTimeBucket9", + [207] =3D "VpWaitingForCpuTimeBucket10", + [208] =3D "VpWaitingForCpuTimeBucket11", + [209] =3D "VpWaitingForCpuTimeBucket12", + [210] =3D "VpHierarchicalSuspendTime", + [211] =3D "VpExpressSchedulingAttempts", + [212] =3D "VpExpressSchedulingCount", +#elif IS_ENABLED(CONFIG_ARM64) + [9] =3D "VpSysRegAccessesCount", + [10] =3D "VpSysRegAccessesTime", + [11] =3D "VpSmcInstructionsCount", + [12] =3D "VpSmcInstructionsTime", + [13] =3D "VpOtherInterceptsCount", + [14] =3D "VpOtherInterceptsTime", + [15] =3D "VpExternalInterruptsCount", + [16] =3D "VpExternalInterruptsTime", + [17] =3D "VpPendingInterruptsCount", + [18] =3D "VpPendingInterruptsTime", + [19] =3D "VpGuestPageTableMaps", + [20] =3D "VpLargePageTlbFills", + [21] =3D "VpSmallPageTlbFills", + [22] =3D "VpReflectedGuestPageFaults", + [23] =3D "VpMemoryInterceptMessages", + [24] =3D "VpOtherMessages", + [25] =3D "VpLogicalProcessorMigrations", + [26] =3D "VpAddressDomainFlushes", + [27] =3D "VpAddressSpaceFlushes", + [28] =3D "VpSyntheticInterrupts", + [29] =3D "VpVirtualInterrupts", + [30] =3D "VpApicSelfIpisSent", + [31] =3D "VpGpaSpaceHypercalls", + [32] =3D "VpLogicalProcessorHypercalls", + [33] =3D "VpLongSpinWaitHypercalls", + [34] =3D "VpOtherHypercalls", + [35] =3D "VpSyntheticInterruptHypercalls", + [36] =3D "VpVirtualInterruptHypercalls", + [37] =3D "VpVirtualMmuHypercalls", + [38] =3D "VpVirtualProcessorHypercalls", + [39] =3D "VpHardwareInterrupts", + [40] =3D "VpNestedPageFaultInterceptsCount", + [41] =3D "VpNestedPageFaultInterceptsTime", + [42] =3D "VpLogicalProcessorDispatches", + [43] =3D "VpWaitingForCpuTime", + [44] =3D "VpExtendedHypercalls", + [45] =3D "VpExtendedHypercallInterceptMessages", + [46] =3D "VpMbecNestedPageTableSwitches", + [47] =3D "VpOtherReflectedGuestExceptions", + [48] =3D "VpGlobalIoTlbFlushes", + [49] =3D "VpGlobalIoTlbFlushCost", + [50] =3D "VpLocalIoTlbFlushes", + [51] =3D "VpLocalIoTlbFlushCost", + [52] =3D "VpFlushGuestPhysicalAddressSpaceHypercalls", + [53] =3D "VpFlushGuestPhysicalAddressListHypercalls", + [54] =3D "VpPostedInterruptNotifications", + [55] =3D "VpPostedInterruptScans", + [56] =3D "VpTotalCoreRunTime", + [57] =3D "VpMaximumRunTime", + [58] =3D "VpWaitingForCpuTimeBucket0", + [59] =3D "VpWaitingForCpuTimeBucket1", + [60] =3D "VpWaitingForCpuTimeBucket2", + [61] =3D "VpWaitingForCpuTimeBucket3", + [62] =3D "VpWaitingForCpuTimeBucket4", + [63] =3D "VpWaitingForCpuTimeBucket5", + [64] =3D "VpWaitingForCpuTimeBucket6", + [65] =3D "VpHwpRequestContextSwitches", + [66] =3D "VpPlaceholder2", + [67] =3D "VpPlaceholder3", + [68] =3D "VpPlaceholder4", + [69] =3D "VpPlaceholder5", + [70] =3D "VpPlaceholder6", + [71] =3D "VpPlaceholder7", + [72] =3D "VpPlaceholder8", + [73] =3D "VpContentionTime", + [74] =3D "VpWakeUpTime", + [75] =3D "VpSchedulingPriority", + [76] =3D "VpVtl1DispatchCount", + [77] =3D "VpVtl2DispatchCount", + [78] =3D "VpVtl2DispatchBucket0", + [79] =3D "VpVtl2DispatchBucket1", + [80] =3D "VpVtl2DispatchBucket2", + [81] =3D "VpVtl2DispatchBucket3", + [82] =3D "VpVtl2DispatchBucket4", + [83] =3D "VpVtl2DispatchBucket5", + [84] =3D "VpVtl2DispatchBucket6", + [85] =3D "VpVtl1RunTime", + [86] =3D "VpVtl2RunTime", + [87] =3D "VpIommuHypercalls", + [88] =3D "VpCpuGroupHypercalls", + [89] =3D "VpVsmHypercalls", + [90] =3D "VpEventLogHypercalls", + [91] =3D "VpDeviceDomainHypercalls", + [92] =3D "VpDepositHypercalls", + [93] =3D "VpSvmHypercalls", + [94] =3D "VpLoadAvg", + [95] =3D "VpRootDispatchThreadBlocked", + [96] =3D "VpIdleCpuTime", + [97] =3D "VpWaitingForCpuTimeBucket7", + [98] =3D "VpWaitingForCpuTimeBucket8", + [99] =3D "VpWaitingForCpuTimeBucket9", + [100] =3D "VpWaitingForCpuTimeBucket10", + [101] =3D "VpWaitingForCpuTimeBucket11", + [102] =3D "VpWaitingForCpuTimeBucket12", + [103] =3D "VpHierarchicalSuspendTime", + [104] =3D "VpExpressSchedulingAttempts", + [105] =3D "VpExpressSchedulingCount", +#endif +}; --=20 2.34.1 From nobody Sat Feb 7 07:24:56 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7811371065; Wed, 28 Jan 2026 18:11:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623912; cv=none; b=KQAUnD19lOUg0qgPI67nhq+1hm514y1fR/HgUmnSU4Qni7vjPSGTNH9eLj61WSOlkvTw7KM1TB+ujUQu2LCQveP3N1qmEWTP/5iZ4ViI4jIUTjlqh1QstqYpvtdcUM6jSN1fq9Rxt7+B2SD5oYPc6Rtm+1aQ/AwO+pZF3KgBDYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769623912; c=relaxed/simple; bh=z+4jYHc9rrfYSyc9V99ZLhGU6EsV2Bu8Lm/9X4RQpXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IN3gIcXU5BpgUoTY4aH8cRBxKHKzGaGVmxO+sEMbwwY/gtbfiMPb9vkON85z91QR4DeCCpaWKQL6x0ayXujQbfENuWcjsYpNqt01ijfC0Spy5A5asX4IU4A522z6rn/DWl8JJGuIjfigN2Uzh7CcxP+/eKjPr7Z2dXBjsiPGbxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=IBpuyK/y; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="IBpuyK/y" Received: by linux.microsoft.com (Postfix, from userid 1032) id 3D9D620B716E; Wed, 28 Jan 2026 10:11:49 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3D9D620B716E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769623909; bh=XktaTb79CBAxA44Dt4ZFpyBuHnfZtfaw/0FSCkZZAqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IBpuyK/ynLayLGGdvQqQHzvLdcvnJUjBOqIHiv4e4yztWwvrnHTvksFNEmTyDm1j7 r295eQH5Warn32noMWUJjRYxLw4U01WsexRJXvDGjxrM9qjtO4ypSe8JFXfvg21qpk +ZMhKdDseL6C7MJl9sB3xzXo1CoTlUEDq6WDe3c4= From: Nuno Das Neves To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, mhklinux@outlook.com, skinsburskii@linux.microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com, prapal@linux.microsoft.com, mrathor@linux.microsoft.com, paekkaladevi@linux.microsoft.com, Nuno Das Neves , Jinank Jain Subject: [PATCH v6 7/7] mshv: Add debugfs to view hypervisor statistics Date: Wed, 28 Jan 2026 10:11:46 -0800 Message-ID: <20260128181146.517708-8-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> References: <20260128181146.517708-1-nunodasneves@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Co-developed-by: Stanislav Kinsburskii Signed-off-by: Stanislav Kinsburskii Co-developed-by: Praveen K Paladugu Signed-off-by: Praveen K Paladugu Co-developed-by: Mukesh Rathor Signed-off-by: Mukesh Rathor Co-developed-by: Purna Pavan Chandra Aekkaladevi Signed-off-by: Purna Pavan Chandra Aekkaladevi Co-developed-by: Jinank Jain Signed-off-by: Jinank Jain Signed-off-by: Nuno Das Neves Reviewed-by: Stanislav Kinsburskii Acked-by: Stanislav Kinsburskii --- 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 diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile index a49f93c2d245..2593711c3628 100644 --- a/drivers/hv/Makefile +++ b/drivers/hv/Makefile @@ -15,6 +15,7 @@ hv_vmbus-$(CONFIG_HYPERV_TESTING) +=3D hv_debugfs.o hv_utils-y :=3D hv_util.o hv_kvp.o hv_snapshot.o hv_utils_transport.o mshv_root-y :=3D 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) +=3D mshv_debugfs.o mshv_vtl-y :=3D mshv_vtl_main.o =20 # Code that must be built-in diff --git a/drivers/hv/mshv_debugfs.c b/drivers/hv/mshv_debugfs.c new file mode 100644 index 000000000000..ebf2549eb44d --- /dev/null +++ b/drivers/hv/mshv_debugfs.c @@ -0,0 +1,726 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2026, Microsoft Corporation. + * + * The /sys/kernel/debug/mshv directory contents. + * Contains various statistics data, provided by the hypervisor. + * + * Authors: Microsoft Linux virtualization team + */ + +#include +#include +#include +#include + +#include "mshv.h" +#include "mshv_root.h" + +/* Ensure this file is not used elsewhere by accident */ +#define MSHV_DEBUGFS_C +#include "mshv_debugfs_counters.c" + +#define U32_BUF_SZ 11 +#define U64_BUF_SZ 21 +/* Only support SELF and PARENT areas */ +#define NUM_STATS_AREAS 2 +static_assert(HV_STATS_AREA_SELF =3D=3D 0 && HV_STATS_AREA_PARENT =3D=3D 1, + "SELF and PARENT areas must be usable as indices into an array of s= ize NUM_STATS_AREAS"); +/* HV_HYPERVISOR_COUNTER */ +#define HV_HYPERVISOR_COUNTER_LOGICAL_PROCESSORS 1 + +static struct dentry *mshv_debugfs; +static struct dentry *mshv_debugfs_partition; +static struct dentry *mshv_debugfs_lp; +static struct dentry **parent_vp_stats; +static struct dentry *parent_partition_stats; + +static u64 mshv_lps_count; +static struct hv_stats_page **mshv_lps_stats; + +static int lp_stats_show(struct seq_file *m, void *v) +{ + const struct hv_stats_page *stats =3D m->private; + int idx; + + for (idx =3D 0; idx < ARRAY_SIZE(hv_lp_counters); idx++) { + char *name =3D hv_lp_counters[idx]; + + if (!name) + continue; + seq_printf(m, "%-32s: %llu\n", name, stats->data[idx]); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(lp_stats); + +static void mshv_lp_stats_unmap(u32 lp_index) +{ + union hv_stats_object_identity identity =3D { + .lp.lp_index =3D lp_index, + .lp.stats_area_type =3D HV_STATS_AREA_SELF, + }; + int err; + + err =3D hv_unmap_stats_page(HV_STATS_OBJECT_LOGICAL_PROCESSOR, + mshv_lps_stats[lp_index], &identity); + if (err) + pr_err("%s: failed to unmap logical processor %u stats, err: %d\n", + __func__, lp_index, err); + + mshv_lps_stats[lp_index] =3D NULL; +} + +static struct hv_stats_page * __init mshv_lp_stats_map(u32 lp_index) +{ + union hv_stats_object_identity identity =3D { + .lp.lp_index =3D lp_index, + .lp.stats_area_type =3D HV_STATS_AREA_SELF, + }; + struct hv_stats_page *stats; + int err; + + err =3D hv_map_stats_page(HV_STATS_OBJECT_LOGICAL_PROCESSOR, &identity, + &stats); + if (err) { + pr_err("%s: failed to map logical processor %u stats, err: %d\n", + __func__, lp_index, err); + return ERR_PTR(err); + } + mshv_lps_stats[lp_index] =3D stats; + + return stats; +} + +static struct hv_stats_page * __init lp_debugfs_stats_create(u32 lp_index, + struct dentry *parent) +{ + struct dentry *dentry; + struct hv_stats_page *stats; + + stats =3D mshv_lp_stats_map(lp_index); + if (IS_ERR(stats)) + return stats; + + dentry =3D debugfs_create_file("stats", 0400, parent, + stats, &lp_stats_fops); + if (IS_ERR(dentry)) { + mshv_lp_stats_unmap(lp_index); + return ERR_CAST(dentry); + } + return stats; +} + +static int __init lp_debugfs_create(u32 lp_index, struct dentry *parent) +{ + struct dentry *idx; + char lp_idx_str[U32_BUF_SZ]; + struct hv_stats_page *stats; + int err; + + sprintf(lp_idx_str, "%u", lp_index); + + idx =3D debugfs_create_dir(lp_idx_str, parent); + if (IS_ERR(idx)) + return PTR_ERR(idx); + + stats =3D lp_debugfs_stats_create(lp_index, idx); + if (IS_ERR(stats)) { + err =3D PTR_ERR(stats); + goto remove_debugfs_lp_idx; + } + + return 0; + +remove_debugfs_lp_idx: + debugfs_remove_recursive(idx); + return err; +} + +static void mshv_debugfs_lp_remove(void) +{ + int lp_index; + + debugfs_remove_recursive(mshv_debugfs_lp); + + for (lp_index =3D 0; lp_index < mshv_lps_count; lp_index++) + mshv_lp_stats_unmap(lp_index); + + kfree(mshv_lps_stats); + mshv_lps_stats =3D NULL; +} + +static int __init mshv_debugfs_lp_create(struct dentry *parent) +{ + struct dentry *lp_dir; + int err, lp_index; + + mshv_lps_stats =3D kcalloc(mshv_lps_count, + sizeof(*mshv_lps_stats), + GFP_KERNEL_ACCOUNT); + + if (!mshv_lps_stats) + return -ENOMEM; + + lp_dir =3D debugfs_create_dir("lp", parent); + if (IS_ERR(lp_dir)) { + err =3D PTR_ERR(lp_dir); + goto free_lp_stats; + } + + for (lp_index =3D 0; lp_index < mshv_lps_count; lp_index++) { + err =3D lp_debugfs_create(lp_index, lp_dir); + if (err) + goto remove_debugfs_lps; + } + + mshv_debugfs_lp =3D lp_dir; + + return 0; + +remove_debugfs_lps: + for (lp_index -=3D 1; lp_index >=3D 0; lp_index--) + mshv_lp_stats_unmap(lp_index); + debugfs_remove_recursive(lp_dir); +free_lp_stats: + kfree(mshv_lps_stats); + mshv_lps_stats =3D NULL; + + return err; +} + +static int vp_stats_show(struct seq_file *m, void *v) +{ + const struct hv_stats_page **pstats =3D m->private; + u64 parent_val, self_val; + int idx; + + /* + * For VP and partition stats, there may be two stats areas mapped, + * SELF and PARENT. These refer to the privilege level of the data in + * each page. Some fields may be 0 in SELF and nonzero in PARENT, or + * vice versa. + * + * Hence, prioritize printing from the PARENT page (more privileged + * data), but use the value from the SELF page if the PARENT value is + * 0. + */ + + for (idx =3D 0; idx < ARRAY_SIZE(hv_vp_counters); idx++) { + char *name =3D hv_vp_counters[idx]; + + if (!name) + continue; + + parent_val =3D pstats[HV_STATS_AREA_PARENT]->data[idx]; + self_val =3D pstats[HV_STATS_AREA_SELF]->data[idx]; + seq_printf(m, "%-43s: %llu\n", name, + parent_val ? parent_val : self_val); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(vp_stats); + +static void vp_debugfs_remove(struct dentry *vp_stats) +{ + debugfs_remove_recursive(vp_stats->d_parent); +} + +static int vp_debugfs_create(u64 partition_id, u32 vp_index, + struct hv_stats_page **pstats, + struct dentry **vp_stats_ptr, + struct dentry *parent) +{ + struct dentry *vp_idx_dir, *d; + char vp_idx_str[U32_BUF_SZ]; + int err; + + sprintf(vp_idx_str, "%u", vp_index); + + vp_idx_dir =3D debugfs_create_dir(vp_idx_str, parent); + if (IS_ERR(vp_idx_dir)) + return PTR_ERR(vp_idx_dir); + + d =3D debugfs_create_file("stats", 0400, vp_idx_dir, + pstats, &vp_stats_fops); + if (IS_ERR(d)) { + err =3D PTR_ERR(d); + goto remove_debugfs_vp_idx; + } + + *vp_stats_ptr =3D d; + + return 0; + +remove_debugfs_vp_idx: + debugfs_remove_recursive(vp_idx_dir); + return err; +} + +static int partition_stats_show(struct seq_file *m, void *v) +{ + const struct hv_stats_page **pstats =3D m->private; + u64 parent_val, self_val; + int idx; + + for (idx =3D 0; idx < ARRAY_SIZE(hv_partition_counters); idx++) { + char *name =3D hv_partition_counters[idx]; + + if (!name) + continue; + + parent_val =3D pstats[HV_STATS_AREA_PARENT]->data[idx]; + self_val =3D pstats[HV_STATS_AREA_SELF]->data[idx]; + seq_printf(m, "%-37s: %llu\n", name, + parent_val ? parent_val : self_val); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(partition_stats); + +static void mshv_partition_stats_unmap(u64 partition_id, + struct hv_stats_page *stats_page, + enum hv_stats_area_type stats_area_type) +{ + union hv_stats_object_identity identity =3D { + .partition.partition_id =3D partition_id, + .partition.stats_area_type =3D stats_area_type, + }; + int err; + + err =3D hv_unmap_stats_page(HV_STATS_OBJECT_PARTITION, stats_page, + &identity); + if (err) + pr_err("%s: failed to unmap partition %lld %s stats, err: %d\n", + __func__, partition_id, + (stats_area_type =3D=3D HV_STATS_AREA_SELF) ? "self" : "parent", + err); +} + +static struct hv_stats_page *mshv_partition_stats_map(u64 partition_id, + enum hv_stats_area_type stats_area_type) +{ + union hv_stats_object_identity identity =3D { + .partition.partition_id =3D partition_id, + .partition.stats_area_type =3D stats_area_type, + }; + struct hv_stats_page *stats; + int err; + + err =3D hv_map_stats_page(HV_STATS_OBJECT_PARTITION, &identity, &stats); + if (err) { + pr_err("%s: failed to map partition %lld %s stats, err: %d\n", + __func__, partition_id, + (stats_area_type =3D=3D HV_STATS_AREA_SELF) ? "self" : "parent", + err); + return ERR_PTR(err); + } + return stats; +} + +static int mshv_debugfs_partition_stats_create(u64 partition_id, + struct dentry **partition_stats_ptr, + struct dentry *parent) +{ + struct dentry *dentry; + struct hv_stats_page **pstats; + int err; + + pstats =3D kcalloc(NUM_STATS_AREAS, sizeof(struct hv_stats_page *), + GFP_KERNEL_ACCOUNT); + if (!pstats) + return -ENOMEM; + + pstats[HV_STATS_AREA_SELF] =3D mshv_partition_stats_map(partition_id, + HV_STATS_AREA_SELF); + if (IS_ERR(pstats[HV_STATS_AREA_SELF])) { + err =3D PTR_ERR(pstats[HV_STATS_AREA_SELF]); + goto cleanup; + } + + /* + * L1VH partition cannot access its partition stats in parent area. + */ + if (is_l1vh_parent(partition_id)) { + pstats[HV_STATS_AREA_PARENT] =3D pstats[HV_STATS_AREA_SELF]; + } else { + pstats[HV_STATS_AREA_PARENT] =3D mshv_partition_stats_map(partition_id, + HV_STATS_AREA_PARENT); + if (IS_ERR(pstats[HV_STATS_AREA_PARENT])) { + err =3D PTR_ERR(pstats[HV_STATS_AREA_PARENT]); + goto unmap_self; + } + if (!pstats[HV_STATS_AREA_PARENT]) + pstats[HV_STATS_AREA_PARENT] =3D pstats[HV_STATS_AREA_SELF]; + } + + dentry =3D debugfs_create_file("stats", 0400, parent, + pstats, &partition_stats_fops); + if (IS_ERR(dentry)) { + err =3D PTR_ERR(dentry); + goto unmap_partition_stats; + } + + *partition_stats_ptr =3D dentry; + return 0; + +unmap_partition_stats: + if (pstats[HV_STATS_AREA_PARENT] !=3D pstats[HV_STATS_AREA_SELF]) + mshv_partition_stats_unmap(partition_id, pstats[HV_STATS_AREA_PARENT], + HV_STATS_AREA_PARENT); +unmap_self: + mshv_partition_stats_unmap(partition_id, pstats[HV_STATS_AREA_SELF], + HV_STATS_AREA_SELF); +cleanup: + kfree(pstats); + return err; +} + +static void partition_debugfs_remove(u64 partition_id, struct dentry *dent= ry) +{ + struct hv_stats_page **pstats =3D NULL; + + pstats =3D dentry->d_inode->i_private; + + debugfs_remove_recursive(dentry->d_parent); + + if (pstats[HV_STATS_AREA_PARENT] !=3D pstats[HV_STATS_AREA_SELF]) { + mshv_partition_stats_unmap(partition_id, + pstats[HV_STATS_AREA_PARENT], + HV_STATS_AREA_PARENT); + } + + mshv_partition_stats_unmap(partition_id, + pstats[HV_STATS_AREA_SELF], + HV_STATS_AREA_SELF); + + kfree(pstats); +} + +static int partition_debugfs_create(u64 partition_id, + struct dentry **vp_dir_ptr, + struct dentry **partition_stats_ptr, + struct dentry *parent) +{ + char part_id_str[U64_BUF_SZ]; + struct dentry *part_id_dir, *vp_dir; + int err; + + if (is_l1vh_parent(partition_id)) + sprintf(part_id_str, "self"); + else + sprintf(part_id_str, "%llu", partition_id); + + part_id_dir =3D debugfs_create_dir(part_id_str, parent); + if (IS_ERR(part_id_dir)) + return PTR_ERR(part_id_dir); + + vp_dir =3D debugfs_create_dir("vp", part_id_dir); + if (IS_ERR(vp_dir)) { + err =3D PTR_ERR(vp_dir); + goto remove_debugfs_partition_id; + } + + err =3D mshv_debugfs_partition_stats_create(partition_id, + partition_stats_ptr, + part_id_dir); + if (err) + goto remove_debugfs_partition_id; + + *vp_dir_ptr =3D vp_dir; + + return 0; + +remove_debugfs_partition_id: + debugfs_remove_recursive(part_id_dir); + return err; +} + +static void parent_vp_debugfs_remove(u32 vp_index, + struct dentry *vp_stats_ptr) +{ + struct hv_stats_page **pstats; + + pstats =3D vp_stats_ptr->d_inode->i_private; + vp_debugfs_remove(vp_stats_ptr); + mshv_vp_stats_unmap(hv_current_partition_id, vp_index, pstats); + kfree(pstats); +} + +static void mshv_debugfs_parent_partition_remove(void) +{ + int idx; + + for_each_online_cpu(idx) + parent_vp_debugfs_remove(hv_vp_index[idx], + parent_vp_stats[idx]); + + partition_debugfs_remove(hv_current_partition_id, + parent_partition_stats); + kfree(parent_vp_stats); + parent_vp_stats =3D NULL; + parent_partition_stats =3D NULL; +} + +static int __init parent_vp_debugfs_create(u32 vp_index, + struct dentry **vp_stats_ptr, + struct dentry *parent) +{ + struct hv_stats_page **pstats; + int err; + + pstats =3D kcalloc(NUM_STATS_AREAS, sizeof(struct hv_stats_page *), + GFP_KERNEL_ACCOUNT); + if (!pstats) + return -ENOMEM; + + err =3D mshv_vp_stats_map(hv_current_partition_id, vp_index, pstats); + if (err) + goto cleanup; + + err =3D vp_debugfs_create(hv_current_partition_id, vp_index, pstats, + vp_stats_ptr, parent); + if (err) + goto unmap_vp_stats; + + return 0; + +unmap_vp_stats: + mshv_vp_stats_unmap(hv_current_partition_id, vp_index, pstats); +cleanup: + kfree(pstats); + return err; +} + +static int __init mshv_debugfs_parent_partition_create(void) +{ + struct dentry *vp_dir; + int err, idx, i; + + mshv_debugfs_partition =3D debugfs_create_dir("partition", + mshv_debugfs); + if (IS_ERR(mshv_debugfs_partition)) + return PTR_ERR(mshv_debugfs_partition); + + err =3D partition_debugfs_create(hv_current_partition_id, + &vp_dir, + &parent_partition_stats, + mshv_debugfs_partition); + if (err) + goto remove_debugfs_partition; + + parent_vp_stats =3D kcalloc(nr_cpu_ids, sizeof(*parent_vp_stats), + GFP_KERNEL); + if (!parent_vp_stats) { + err =3D -ENOMEM; + goto remove_debugfs_partition; + } + + for_each_online_cpu(idx) { + err =3D parent_vp_debugfs_create(hv_vp_index[idx], + &parent_vp_stats[idx], + vp_dir); + if (err) + goto remove_debugfs_partition_vp; + } + + return 0; + +remove_debugfs_partition_vp: + for_each_online_cpu(i) { + if (i >=3D idx) + break; + parent_vp_debugfs_remove(i, parent_vp_stats[i]); + } + partition_debugfs_remove(hv_current_partition_id, + parent_partition_stats); + + kfree(parent_vp_stats); + parent_vp_stats =3D NULL; + parent_partition_stats =3D NULL; + +remove_debugfs_partition: + debugfs_remove_recursive(mshv_debugfs_partition); + mshv_debugfs_partition =3D NULL; + return err; +} + +static int hv_stats_show(struct seq_file *m, void *v) +{ + const struct hv_stats_page *stats =3D m->private; + int idx; + + for (idx =3D 0; idx < ARRAY_SIZE(hv_hypervisor_counters); idx++) { + char *name =3D hv_hypervisor_counters[idx]; + + if (!name) + continue; + seq_printf(m, "%-27s: %llu\n", name, stats->data[idx]); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(hv_stats); + +static void mshv_hv_stats_unmap(void) +{ + union hv_stats_object_identity identity =3D { + .hv.stats_area_type =3D HV_STATS_AREA_SELF, + }; + int err; + + err =3D hv_unmap_stats_page(HV_STATS_OBJECT_HYPERVISOR, NULL, &identity); + if (err) + pr_err("%s: failed to unmap hypervisor stats: %d\n", + __func__, err); +} + +static void * __init mshv_hv_stats_map(void) +{ + union hv_stats_object_identity identity =3D { + .hv.stats_area_type =3D HV_STATS_AREA_SELF, + }; + struct hv_stats_page *stats; + int err; + + err =3D hv_map_stats_page(HV_STATS_OBJECT_HYPERVISOR, &identity, &stats); + if (err) { + pr_err("%s: failed to map hypervisor stats: %d\n", + __func__, err); + return ERR_PTR(err); + } + return stats; +} + +static int __init mshv_debugfs_hv_stats_create(struct dentry *parent) +{ + struct dentry *dentry; + u64 *stats; + int err; + + stats =3D mshv_hv_stats_map(); + if (IS_ERR(stats)) + return PTR_ERR(stats); + + dentry =3D debugfs_create_file("stats", 0400, parent, + stats, &hv_stats_fops); + if (IS_ERR(dentry)) { + err =3D PTR_ERR(dentry); + pr_err("%s: failed to create hypervisor stats dentry: %d\n", + __func__, err); + goto unmap_hv_stats; + } + + mshv_lps_count =3D stats[HV_HYPERVISOR_COUNTER_LOGICAL_PROCESSORS]; + + return 0; + +unmap_hv_stats: + mshv_hv_stats_unmap(); + return err; +} + +int mshv_debugfs_vp_create(struct mshv_vp *vp) +{ + struct mshv_partition *p =3D vp->vp_partition; + + if (!mshv_debugfs) + return 0; + + return vp_debugfs_create(p->pt_id, vp->vp_index, + vp->vp_stats_pages, + &vp->vp_stats_dentry, + p->pt_vp_dentry); +} + +void mshv_debugfs_vp_remove(struct mshv_vp *vp) +{ + if (!mshv_debugfs) + return; + + vp_debugfs_remove(vp->vp_stats_dentry); +} + +int mshv_debugfs_partition_create(struct mshv_partition *partition) +{ + int err; + + if (!mshv_debugfs) + return 0; + + err =3D partition_debugfs_create(partition->pt_id, + &partition->pt_vp_dentry, + &partition->pt_stats_dentry, + mshv_debugfs_partition); + if (err) + return err; + + return 0; +} + +void mshv_debugfs_partition_remove(struct mshv_partition *partition) +{ + if (!mshv_debugfs) + return; + + partition_debugfs_remove(partition->pt_id, + partition->pt_stats_dentry); +} + +int __init mshv_debugfs_init(void) +{ + int err; + + mshv_debugfs =3D debugfs_create_dir("mshv", NULL); + if (IS_ERR(mshv_debugfs)) { + pr_err("%s: failed to create debugfs directory\n", __func__); + return PTR_ERR(mshv_debugfs); + } + + if (hv_root_partition()) { + err =3D mshv_debugfs_hv_stats_create(mshv_debugfs); + if (err) + goto remove_mshv_dir; + + err =3D mshv_debugfs_lp_create(mshv_debugfs); + if (err) + goto unmap_hv_stats; + } + + err =3D mshv_debugfs_parent_partition_create(); + if (err) + goto unmap_lp_stats; + + return 0; + +unmap_lp_stats: + if (hv_root_partition()) { + mshv_debugfs_lp_remove(); + mshv_debugfs_lp =3D NULL; + } +unmap_hv_stats: + if (hv_root_partition()) + mshv_hv_stats_unmap(); +remove_mshv_dir: + debugfs_remove_recursive(mshv_debugfs); + mshv_debugfs =3D NULL; + return err; +} + +void mshv_debugfs_exit(void) +{ + mshv_debugfs_parent_partition_remove(); + + if (hv_root_partition()) { + mshv_debugfs_lp_remove(); + mshv_debugfs_lp =3D NULL; + mshv_hv_stats_unmap(); + } + + debugfs_remove_recursive(mshv_debugfs); + mshv_debugfs =3D NULL; + mshv_debugfs_partition =3D NULL; +} diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h index e4912b0618fa..7332d9af8373 100644 --- a/drivers/hv/mshv_root.h +++ b/drivers/hv/mshv_root.h @@ -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 }; =20 #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 }; =20 #define pt_fmt(fmt) "p%llu: " fmt @@ -327,6 +334,33 @@ int hv_call_modify_spa_host_access(u64 partition_id, s= truct 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); =20 +#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 *par= tition) +{ + return 0; +} +static inline void mshv_debugfs_partition_remove(struct mshv_partition *pa= rtition) { } +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; diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 414d9cee5252..3a43e41e16a1 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -1095,6 +1095,10 @@ mshv_partition_ioctl_create_vp(struct mshv_partition= *partition, =20 memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages)); =20 + ret =3D 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 =3D anon_inode_getfd("mshv_vp", &mshv_vp_fops, vp, O_RDWR | O_CLOEXEC); if (ret < 0) - goto put_partition; + goto remove_debugfs_vp; =20 /* 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, =20 return ret; =20 +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_partiti= on *partition) if (ret) goto withdraw_mem; =20 + ret =3D mshv_debugfs_partition_create(partition); + if (ret) + goto finalize_partition; + partition->pt_initialized =3D true; =20 return 0; =20 +finalize_partition: + hv_call_finalize_partition(partition->pt_id); withdraw_mem: hv_call_withdraw_memory(U64_MAX, NUMA_NO_NODE, partition->pt_id); =20 @@ -1735,6 +1747,7 @@ static void destroy_partition(struct mshv_partition *= partition) if (!vp) continue; =20 + mshv_debugfs_vp_remove(vp); mshv_vp_stats_unmap(partition->pt_id, vp->vp_index, vp->vp_stats_pages); =20 @@ -1768,6 +1781,8 @@ static void destroy_partition(struct mshv_partition *= partition) partition->pt_vp_array[i] =3D NULL; } =20 + mshv_debugfs_partition_remove(partition); + /* Deallocates and unmaps everything including vcpus, GPA mappings etc */ hv_call_finalize_partition(partition->pt_id); =20 @@ -2313,10 +2328,14 @@ static int __init mshv_parent_partition_init(void) =20 mshv_init_vmm_caps(dev); =20 - ret =3D mshv_irqfd_wq_init(); + ret =3D mshv_debugfs_init(); if (ret) goto exit_partition; =20 + ret =3D mshv_irqfd_wq_init(); + if (ret) + goto exit_debugfs; + spin_lock_init(&mshv_root.pt_ht_lock); hash_init(mshv_root.pt_htable); =20 @@ -2324,6 +2343,8 @@ static int __init mshv_parent_partition_init(void) =20 return 0; =20 +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()) --=20 2.34.1