From nobody Sun Feb 8 06:22:51 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C73EE258EDB; Mon, 26 Jan 2026 20:56:04 +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=1769460966; cv=none; b=jfEAxUEHHI+aJ8XKsU+LmAu3ROW78Vv6Izwi9lR4mvCfEp/uYd4CpTngYif+KlHV526xnL/y9nn1TNztYlRC0JLVrmSdJX0LdyQ/t9wF489yRt1tqKzNTKuOTIntNXYpmzkpxlyEWZRALrrEqtFKs1Xarw23ZwYN3R5edaUac/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769460966; c=relaxed/simple; bh=uzeRuEk6mtsIaTnRbzrMVlLOgjMqQcPry4umGAax9Uw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=taGOrzRh5vx6D/7AF+NoIN9ZKOm9CPm6GBo3KSGs9OiqZwJQiU+HPaCojmabXFGYvZycNUYj+m+v7Kn5kEZGFi/pY1erLq51n1tAQs2hBzw5r0QIuAUlwTzHHYsr3SeEWsErLm2xwnBf5nN+eWbuA8wfHO3gkzZr/XEXL9BXmo8= 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=eDwaG/BX; 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="eDwaG/BX" Received: by linux.microsoft.com (Postfix, from userid 1032) id CD7FD20B7167; Mon, 26 Jan 2026 12:56:04 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CD7FD20B7167 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769460964; bh=z2o6YdqfB0oQMRtuk5ZapbPpFV9AcJv3FrMTfcI1w9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eDwaG/BXm+XurSqo6TYHSNozb7gzTwmhT9zG4//zHptMP2/K+aeyUOBihfDgB8e7s Xxhs7DWlxYqLUHmk4AjTwOCgSVPIeOwZfnjOHjW2Fosqf2nim+frBiZcfT/ZYmfyHM vpjwc3T4B+ctsI5PXakXN4F+abWkNPZZjkeXYU10= 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 v5 1/7] mshv: Ignore second stats page map result failure Date: Mon, 26 Jan 2026 12:55:57 -0800 Message-ID: <20260126205603.404655-2-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260126205603.404655-1-nunodasneves@linux.microsoft.com> References: <20260126205603.404655-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 --- 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 Sun Feb 8 06:22:51 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3491C3B2BA; Mon, 26 Jan 2026 20:56:05 +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=1769460966; cv=none; b=gMlkkJNhD8xH1Z6WJ7y3V4LkDGYIXbSnYS094E2o5bbv6BKBaMlSodi1ntpQkECtaCPbbloLRbavEQhgDALMUwOjsaYeSOF7JcO16vgFFcZXZiCOWuK3i7cE6J3V96TlQB8dMyrTTUhXDTw/67NM6pyJHUDf5+VAvmqAzqDicGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769460966; c=relaxed/simple; bh=HFNNVSweFvuB84DU2B4ROhCi6CUVW6aVVK9SMK14epw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dwYnAeuzlv/W2u85ajZ/JQz5fyPtusI8PpHHUxRRdGoj5Uh7w7c7+S0wTrKSflRf0Z5seAOdZHP6t/rpE4rTp4TApimG7gCZDraF5+68J+I5Fnq+XA0RKOUWuAgdN6NzcsiXLkA9y4bdomczSrfrTF4aOea8tVvot9R4gXWwPtk= 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=HIfKaWSU; 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="HIfKaWSU" Received: by linux.microsoft.com (Postfix, from userid 1032) id 190C620B7168; Mon, 26 Jan 2026 12:56:05 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 190C620B7168 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769460965; bh=ARHwRQoJMl3xBLyBPZgcJm/EEXDHa34ijHjF+rMvoPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HIfKaWSUHNLUNFC9uBoTG5FWZsbeGhfrqL63aGFy6oLhLF+A+opBDEgnw1MYHS5s5 nu9gaArGr8ZfzmGC9C3XkWFvWj8OWfAEtAws8YUNu+wooUGOZxUY//ATOabtL9EhfP jZX2WjNKtMGa1R612KjdJXGoMVmg5scRiMTqiyoQ= 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 v5 2/7] mshv: Use typed hv_stats_page pointers Date: Mon, 26 Jan 2026 12:55:58 -0800 Message-ID: <20260126205603.404655-3-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260126205603.404655-1-nunodasneves@linux.microsoft.com> References: <20260126205603.404655-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 --- 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 Sun Feb 8 06:22:51 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E8CC2877DC; Mon, 26 Jan 2026 20:56:05 +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=1769460966; cv=none; b=PBuzx3V35aXPRKvVwLZUaNR35c8CBYX+0f/6rstm2EIJp8zGYLjWMGT487MSB2a2gicCSDfVKZ8lwT/wCwg4L5NaNngcwBBTku4+h0BAuYOzt14D1KAipTc6FOEkM0ncm+p6jN9DIOj2x4IW+bKV/OihRlK4S4hd0RsI0G5tJRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769460966; c=relaxed/simple; bh=2s9lIeHsh8FM2pqJpMLaCsT4ujORbpAFNEZIFfRk+Y0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NEd3bTgrLgSr24l36L1aeffUk4FkF14EnlkA0flKM8clujl8xT5McKDLOysgYdMrMMSDcae2ucRkKZrXI8tfKy9On5sM7arGgZWg+6St8DQSWao6SruwCTaKbKjKm1bSrMjWhtYsSLdjE66WqiaUXI9wdX7UpacGZi67UrV+fms= 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=LNYn8vZX; 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="LNYn8vZX" Received: by linux.microsoft.com (Postfix, from userid 1032) id 5261F20B7169; Mon, 26 Jan 2026 12:56:05 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5261F20B7169 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769460965; bh=9BzoOa0wVBQB143I2PH957+WYxTAU/R3jKcGrn898r4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LNYn8vZXv6mbOQkujHwTbz0cLkrvurtmZzZzrFKelNxxwejK9XD1zZJ7pPwCEbGnF gBo5dW4yDBUb2UBAQ/QE47EDp4gGQap2vFSA9DlUrF1abreLdmbeW4851eV6jUkxDI ZLOUylwHpK8gGI3KRUevRvno50E7mFeygJqeENwY= 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 v5 3/7] mshv: Improve mshv_vp_stats_map/unmap(), add them to mshv_root.h Date: Mon, 26 Jan 2026 12:55:59 -0800 Message-ID: <20260126205603.404655-4-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260126205603.404655-1-nunodasneves@linux.microsoft.com> References: <20260126205603.404655-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 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 --- 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 Sun Feb 8 06:22:51 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 849162BEFEE; Mon, 26 Jan 2026 20:56:05 +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=1769460966; cv=none; b=SYPhS95ZNpMcWd76AKA7130h+rgsBO9qnTaoYzojV8DlO9XxhqfW3PKSzPK+DCpcd6sndY+SfGwrzwnh+ssuPAhuCZQgIhFk9MD/cWNzaQyQKZMLXOkmNWc1gXox663hY6zwanrt/OjW6qka9g/W8wKnDCQWdw9Z9kyAP8zBegA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769460966; c=relaxed/simple; bh=L4E1wo8/6fKvJEozXW8vtzU2hTEpjK6jREA7Bfv0oJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TDIERa/BvB4HDaU2NOj5w4VIUnZw5nh8u9YFuZugN5u5TlYl4gZOovlajRocrTOHNAtyKNba9LObib7b/WoIN4DFOR5yjImIrVCsbwJIyuP0ae90rQxfkstCtbfXQU4k4LZ33/+bZAIWodbIWs13BrBS0LWL3JprqE2EgUn94u4= 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=ZiC1QIBo; 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="ZiC1QIBo" Received: by linux.microsoft.com (Postfix, from userid 1032) id 8D8D020B716A; Mon, 26 Jan 2026 12:56:05 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8D8D020B716A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769460965; bh=uE6yNFSdJktjcXi31tIk+NXAAyXVgXT3CJcMYC5oQGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZiC1QIBowXMMXqmbZiZiHJK8UN+hnot+SN9WjOdm9gIdMjTDKvP8GXSuLhGcfsKPK lJOF4ugfHNbeenje8b64EbtYq44ByJmgW+mFlXeF4errb+QCEX/XgM6xaeD4uSD3Pg ycHBp5FDPK6w5hDe/vEHo+ODpCQBxfeVZLRR4m5c= 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 v5 4/7] mshv: Always map child vp stats pages regardless of scheduler type Date: Mon, 26 Jan 2026 12:56:00 -0800 Message-ID: <20260126205603.404655-5-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260126205603.404655-1-nunodasneves@linux.microsoft.com> References: <20260126205603.404655-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 --- 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 Sun Feb 8 06:22:51 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 369E12D879C; Mon, 26 Jan 2026 20:56:06 +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=1769460967; cv=none; b=ucF3jLA7cydg/PIpvE3VgBRUesGW1YUkcqfi62t2aDQrU7MN9fwQvDA9iqzoGp3Ol1a5AZ1gczLkUrdn8+96tEOyfKedyv3VTrj7rmPuq2l1mer3nPpo/p4PiYWEnPNckzJOdZHfR7mqYF/voNiAB3ER0GcJLFir4Vij0QLz96Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769460967; c=relaxed/simple; bh=Nobfny3EPvSX02TlfzwBxI4xnbjdZkbLbTvxNRmD95E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z9yPAffytsMoIKOsYWPMqoIqABTc3XLTH6IBT4mTd9m/ML2tsH5Ozd+gTP7Ru+7BOo5T51ed4r/5CEt+SZBhW8H5ecJNXQtU3HcK9YrCt8izByAeXfuVOPqc7OhNxfDs95iNkMRv0siYAI6iAMHvA3zBTZMDQ79o2Hfuf0/+ZRM= 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=GQDx6KmX; 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="GQDx6KmX" Received: by linux.microsoft.com (Postfix, from userid 1032) id 2D0BB20B716B; Mon, 26 Jan 2026 12:56:06 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2D0BB20B716B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769460966; bh=TwV8k/JQjbJYmYUQItWcVn2FbTjZy0L5HeBULhqi7T4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GQDx6KmX/KODawarO0GJ7Uh+ilZzCNHWu78IAaFDskaeo9LcnLpQ352Jd3EbTP40U lXvHFWkG50CYhmyVhpTNOM4UiJG5gZNg5R9tnniebIHVWIGJ1EAtUIiKBxKS20Ufw6 3AVWh7TMOwDp2JkeUd/kfqmVJtqf+Pl6O1LrVATY= 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 v5 5/7] mshv: Update hv_stats_page definitions Date: Mon, 26 Jan 2026 12:56:01 -0800 Message-ID: <20260126205603.404655-6-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260126205603.404655-1-nunodasneves@linux.microsoft.com> References: <20260126205603.404655-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 --- drivers/hv/mshv_root_main.c | 27 ++++++++------------------- include/hyperv/hvhdk.h | 8 ++++++++ 2 files changed, 16 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..ac501969105c 100644 --- a/include/hyperv/hvhdk.h +++ b/include/hyperv/hvhdk.h @@ -10,6 +10,14 @@ #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 Sun Feb 8 06:22:51 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 932232D94B0; Mon, 26 Jan 2026 20:56:06 +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=1769460968; cv=none; b=LLNzXeA/bu/s1Weov5iWg0GfZDKAcAtuNW1Go7IOeL5Ps8Aaz0gEoT4H/+cWTOJvtfYjnQjNACryRr0MM2353w3fECVPZQLMN/ViBFRc0EnMQ/dt938mghQWxWTHnHHv+CT9qVtjQY7vUj/GDJfBapb5ID12cVegqfR/hyTCCCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769460968; c=relaxed/simple; bh=bL+GjY+6kSdseXlmacyPtt/tkE0Dwxmuc4bPM61gQZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tLaZHnXKrZn1Cahq9ZwXbkWbURHpl0zdgPYyby8h6fzjbamL/kNhDyPWToPUZ/kesvnUYxPgBm4MePHH4jJoIn8eFBxL0NpwCKj/AQIgko6ciojYXXuxa5OVQcluzWt4MlaT21Fttg3NcbmcjF/3s6FtYduFiv2DKECT4p8JJhg= 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=TDs1Zb3Q; 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="TDs1Zb3Q" Received: by linux.microsoft.com (Postfix, from userid 1032) id 9AECA20B716C; Mon, 26 Jan 2026 12:56:06 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9AECA20B716C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769460966; bh=/jeSCL044D3RarJ1mBPkSmMa+MkLBoSircR76TJs2LE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TDs1Zb3Qcal8XKV7dEmhN6dy5DGZhKfxsWkMKEXLkd4ftXbwQOugM3B0RDRc7y3Rf Wg56AbJ1nBbZU8ls3iCO5ZQqemFnzcOKramE/z2GSSpUhjieVfsF10EkghkuOBDRR9 WRfPo2uoe7MxT0MUzM58cD0HzJEeV+4eYuqXt6oo= 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 v5 6/7] mshv: Add data for printing stats page counters Date: Mon, 26 Jan 2026 12:56:02 -0800 Message-ID: <20260126205603.404655-7-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260126205603.404655-1-nunodasneves@linux.microsoft.com> References: <20260126205603.404655-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 --- 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..838af4673dd1 --- /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",=09 +#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",=09 +#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",=09 +#endif +}; --=20 2.34.1 From nobody Sun Feb 8 06:22:51 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1AE482D9EEC; Mon, 26 Jan 2026 20:56:07 +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=1769460969; cv=none; b=LQ6uMSnxfUtfa6PP0LlBpVOQtI18jVcYOZIsCMXMv45yKqhE+1Iblj1aBLCAp+ch/ZSTDw4da21dJSiPexn39IJHxAOVRdxh/PzWTEdQAjLDr6QkDEgmDTPgNe2BdnBmqxJoYJDZo5tQl3NBxk1/NXoCQH8b18Kowl7EsXDDX/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769460969; c=relaxed/simple; bh=+P10XApdy/ttFptXElH5VjKZJUS+4MArBT59eNERt6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f9thNh6B1M5R6GCc+2J5WSUehxcnKTGVodpaR4c7pIoCxmPp8LPCP3FwqzOYBGqFm8KXD8c0d1x6Vbf4xDg9oQBxgsU2fP/bh1xCnTmvnk2XiFMNnY9P2HV2v7N7UvS4MWyo4liIbd0wos+NewFSH3r2Q1Y5Zi2j+EvDxfHUAx4= 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=XOsTbMOq; 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="XOsTbMOq" Received: by linux.microsoft.com (Postfix, from userid 1032) id 284EC20B716D; Mon, 26 Jan 2026 12:56:07 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 284EC20B716D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1769460967; bh=feGsppMUwnMaHYvtllNSMuZ52sxsXXKlyMWLAM5cmGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XOsTbMOqva4n5qdX2/g2jD+1PjiKqE0Lml0j/jXZ32eG5TFLUGWbuLlHs+QbgiRpW JoN0P13nL89Yo6lCJpcdEiz3P56Yn90Vr1pXFBm1VJGLAKyLIWp06XTQrHdjoEDTRB zUMB7UpKpwz2s0AZEVNcMrDENvnRd8n45yMeQ/Qc= 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 v5 7/7] mshv: Add debugfs to view hypervisor statistics Date: Mon, 26 Jan 2026 12:56:03 -0800 Message-ID: <20260126205603.404655-8-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260126205603.404655-1-nunodasneves@linux.microsoft.com> References: <20260126205603.404655-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 --- 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..4553163e8665 --- /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