Skip to contentSkip to conversation

mshv: Fixes for stats and vp state page mappings

PATCH Superseded Nuno Das Neves 5 participants 36 messages Aug 29, 2025 – Sep 9, 2025

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover mshv: Fixes for stats and vp state page mappings

There are some differences in how L1VH partitions must map stats and vp state pages, some of which are due to differences across hypervisor versions. Detect and handle these cases.

Patch 1:
Fix for the logic of when to map the vp stats page.

Patch 2:
Compatibility fix for configurations where hypervisor does not provide a "PARENT" stats area, only "SELF". Fall back to just using "SELF".

Patches 3-6:
On newer hypervisors L1VH partitions must allocate and free stats and vp state pages, and use a new hypercall HVCALL_MAP_VP_STATS_PAGE2 to map the stats page.

Add HVCALL_GET_PARTITION_PROPERTY_EX to query a feature bit to determine whether to allocate the pages and use the new stats hypercall.

Jinank Jain (2):
mshv: Allocate vp state page for HVCALL_MAP_VP_STATE_PAGE on L1VH
mshv: Introduce new hypercall to map stats page for L1VH partitions

Nuno Das Neves (1):
mshv: Only map vp->vp_stats_pages if on root scheduler

Purna Pavan Chandra Aekkaladevi (3):
mshv: Ignore second stats page map result failure
mshv: Add the HVCALL_GET_PARTITION_PROPERTY_EX hypercall
mshv: Get the vmm capabilities offered by the hypervisor

 drivers/hv/mshv_root.h         |  24 ++--
 drivers/hv/mshv_root_hv_call.c | 227 ++++++++++++++++++++++++++++++---
 drivers/hv/mshv_root_main.c    | 140 ++++++++++++--------
 include/hyperv/hvgdk_mini.h    |   2 +
 include/hyperv/hvhdk.h         |  40 ++++++
 include/hyperv/hvhdk_mini.h    |  33 +++++
 6 files changed, 390 insertions(+), 76 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/6 mshv: Only map vp->vp_stats_pages if on root scheduler

This mapping is only used for checking if the dispatch thread is blocked. This is only relevant for the root scheduler, so check the scheduler type to determine whether to map/unmap these pages, instead of the current check, which is incorrect.

---
 drivers/hv/mshv_root_main.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_main.c +8 -4
index e4ee9beddaf5..bbdefe8a2e9c 100644
@@ -987,7 +987,11 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 			goto unmap_register_page;
 	}
 
-	if (hv_parent_partition()) {
+	/*
+	 * This mapping of the stats page is for detecting if dispatch thread
+	 * is blocked - only relevant for root scheduler
+	 */
+	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT) {
 		ret = mshv_vp_stats_map(partition->pt_id, args.vp_index,
 					stats_pages);
 		if (ret)
@@ -1016,7 +1020,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available())
 		vp->vp_ghcb_page = page_to_virt(ghcb_page);
 
-	if (hv_parent_partition())
+	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
 		memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));
 
 	/*
@@ -1039,7 +1043,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 free_vp:
 	kfree(vp);
 unmap_stats_pages:
-	if (hv_parent_partition())
+	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
 		mshv_vp_stats_unmap(partition->pt_id, args.vp_index);
 unmap_ghcb_page:
 	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available()) {
@@ -1793,7 +1797,7 @@ static void destroy_partition(struct mshv_partition *partition)
 			if (!vp)
 				continue;
 
-			if (hv_parent_partition())
+			if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
 				mshv_vp_stats_unmap(partition->pt_id, vp->vp_index);
 
 			if (vp->vp_register_page) {
Signature · 1 line
2.34.1
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] mshv: Only map vp->vp_stats_pages if on root scheduler

Quoted 57 lines · Nuno Das Neves

This mapping is only used for checking if the dispatch thread is blocked. This is only relevant for the root scheduler, so check the scheduler type to determine whether to map/unmap these pages, instead of the current check, which is incorrect.

---
 drivers/hv/mshv_root_main.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_main.c +8 -4
index e4ee9beddaf5..bbdefe8a2e9c 100644
@@ -987,7 +987,11 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 			goto unmap_register_page;
 	}
 
-	if (hv_parent_partition()) {
+	/*
+	 * This mapping of the stats page is for detecting if dispatch thread
+	 * is blocked - only relevant for root scheduler
+	 */
+	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT) {
 		ret = mshv_vp_stats_map(partition->pt_id, args.vp_index,
 					stats_pages);
 		if (ret)
@@ -1016,7 +1020,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available())
 		vp->vp_ghcb_page = page_to_virt(ghcb_page);
 
-	if (hv_parent_partition())
+	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
 		memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));
 
 	/*
@@ -1039,7 +1043,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 free_vp:
 	kfree(vp);
 unmap_stats_pages:
-	if (hv_parent_partition())
+	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
 		mshv_vp_stats_unmap(partition->pt_id, args.vp_index);
 unmap_ghcb_page:
 	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available()) {
@@ -1793,7 +1797,7 @@ static void destroy_partition(struct mshv_partition *partition)
 			if (!vp)
 				continue;
 
-			if (hv_parent_partition())
+			if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
 				mshv_vp_stats_unmap(partition->pt_id, vp->vp_index);
 
 			if (vp->vp_register_page) {
Signature · 1 line
2.34.1
Reviewed-by on v1 1/6
#3 lore raw

Re: [PATCH 1/6] mshv: Only map vp->vp_stats_pages if on root scheduler

In reply to Nuno Das Neves
Quoted 46 lines · Nuno Das Neves

This mapping is only used for checking if the dispatch thread is blocked. This is only relevant for the root scheduler, so check the scheduler type to determine whether to map/unmap these pages, instead of the current check, which is incorrect.

---
  drivers/hv/mshv_root_main.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_main.c +7 -3
index e4ee9beddaf5..bbdefe8a2e9c 100644
@@ -987,7 +987,11 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
  			goto unmap_register_page;
  	}
 
-	if (hv_parent_partition()) {
+	/*
+	 * This mapping of the stats page is for detecting if dispatch thread
+	 * is blocked - only relevant for root scheduler
+	 */
+	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT) {
  		ret = mshv_vp_stats_map(partition->pt_id, args.vp_index,
  					stats_pages);
  		if (ret)
@@ -1016,7 +1020,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
  	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available())
  		vp->vp_ghcb_page = page_to_virt(ghcb_page);
 
-	if (hv_parent_partition())
+	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
  		memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));
 
  	/*
@@ -1039,7 +1043,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
  free_vp:
  	kfree(vp);
  unmap_stats_pages:
-	if (hv_parent_partition())
+	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
  		mshv_vp_stats_unmap(partition->pt_id, args.vp_index);
  unmap_ghcb_page:
  	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available()) {

drivers/hv/mshv_root_main.c static void destroy_partition(struct mshv_partition *partition) · line 1803

Quoted 8 lines
drivers/hv/mshv_root_main.c +1 -1
@@ -1793,7 +1797,7 @@ static void destroy_partition(struct mshv_partition *partition)
  			if (!vp)
  				continue;
 
-			if (hv_parent_partition())
+			if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
  				mshv_vp_stats_unmap(partition->pt_id, vp->vp_index);
 
  			if (vp->vp_register_page) {
Reviewed-by on v1 1/6
#4 lore raw

Re: [PATCH 1/6] mshv: Only map vp->vp_stats_pages if on root scheduler

In reply to Nuno Das Neves
Quoted 9 lines · Nuno Das Neves

This mapping is only used for checking if the dispatch thread is blocked. This is only relevant for the root scheduler, so check the scheduler type to determine whether to map/unmap these pages, instead of the current check, which is incorrect.

---
 drivers/hv/mshv_root_main.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

<snip>

Reviewed-by on v1 1/6
#5 lore raw

Re: [PATCH 1/6] mshv: Only map vp->vp_stats_pages if on root scheduler

In reply to Nuno Das Neves
Quoted 56 lines · Nuno Das Neves

This mapping is only used for checking if the dispatch thread is blocked. This is only relevant for the root scheduler, so check the scheduler type to determine whether to map/unmap these pages, instead of the current check, which is incorrect.

---
 drivers/hv/mshv_root_main.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_main.c +8 -5
index e4ee9beddaf5..bbdefe8a2e9c 100644
@@ -987,7 +987,11 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
                        goto unmap_register_page;
        }
 
-       if (hv_parent_partition()) {
+       /*
+        * This mapping of the stats page is for detecting if dispatch thread
+        * is blocked - only relevant for root scheduler
+        */
+       if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT) {
                ret = mshv_vp_stats_map(partition->pt_id, args.vp_index,
                                        stats_pages);
                if (ret)
@@ -1016,7 +1020,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
        if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available())
                vp->vp_ghcb_page = page_to_virt(ghcb_page);
 
-       if (hv_parent_partition())
+       if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
                memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));
 
        /*
@@ -1039,7 +1043,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 free_vp:
        kfree(vp);
 unmap_stats_pages:
-       if (hv_parent_partition())
+       if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
                mshv_vp_stats_unmap(partition->pt_id, args.vp_index);
 unmap_ghcb_page:
        if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available()) {
@@ -1793,7 +1797,7 @@ static void destroy_partition(struct mshv_partition *partition)
                        if (!vp)
                                continue;
 
-                       if (hv_parent_partition())
+                       if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
                                mshv_vp_stats_unmap(partition->pt_id, vp->vp_index);
 
                        if (vp->vp_register_page) {
--
Quoted 3 lines

2.34.1

Signature · 2 lines
Thanks
Tianyu Lan
#6 lore raw

PATCH 2/6 mshv: Ignore second stats page map result failure

In reply to Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

This results a failure in module init. Instead of failing, gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped stats_pages[HV_STATS_AREA_SELF].

---
 drivers/hv/mshv_root_hv_call.c | 43 ++++++++++++++++++++++++++++++----
 drivers/hv/mshv_root_main.c    |  3 +++
 2 files changed, 42 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_hv_call.c +39 -4
index c9c274f29c3c..1c38576a673c 100644
@@ -724,6 +724,24 @@ hv_call_notify_port_ring_empty(u32 sint_index)
 	return hv_result_to_errno(status);
 }
 
+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;
+}
+
 int hv_call_map_stat_page(enum hv_stats_object_type type,
 			  const union hv_stats_object_identity *identity,
 			  void **addr)
@@ -732,7 +750,7 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
 	struct hv_input_map_stats_page *input;
 	struct hv_output_map_stats_page *output;
 	u64 status, pfn;
-	int ret = 0;
+	int hv_status, ret = 0;
 
 	do {
 		local_irq_save(flags);
@@ -747,11 +765,28 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
 		pfn = output->map_location;
 
 		local_irq_restore(flags);
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
-			ret = hv_result_to_errno(status);
+
+		hv_status = hv_result(status);
+		if (hv_status != HV_STATUS_INSUFFICIENT_MEMORY) {
 			if (hv_result_success(status))
 				break;
-			return ret;
+
+			/*
+			 * Some versions of the hypervisor do not support the
+			 * PARENT stats area. In this case return "success" but
+			 * set the page to NULL. The caller checks for this
+			 * case instead just uses the SELF area.
+			 */
+			if (hv_stats_get_area_type(type, identity) == HV_STATS_AREA_PARENT &&
+			    hv_status == HV_STATUS_INVALID_PARAMETER) {
+				pr_debug_once("%s: PARENT area type is unsupported\n",
+					      __func__);
+				*addr = NULL;
+				return 0;
+			}
+
+			hv_status_debug(status, "\n");
+			return hv_result_to_errno(status);
 		}
 
 		ret = hv_call_deposit_pages(NUMA_NO_NODE,
drivers/hv/mshv_root_main.c +3 -0
index bbdefe8a2e9c..56ababab57ce 100644
@@ -929,6 +929,9 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
 	if (err)
 		goto unmap_self;
 
+	if (!stats_pages[HV_STATS_AREA_PARENT])
+		stats_pages[HV_STATS_AREA_PARENT] = stats_pages[HV_STATS_AREA_SELF];
+
 	return 0;
 
 unmap_self:
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH 2/6] mshv: Ignore second stats page map result failure

Quoted 6 lines · Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

Is this behavior limited to VP stats? Or does it extend to other stats (hypervisor, partition, etc) as well?

Quoted 1 line

This results a failure in module init. Instead of failing, gracefully

nit: s/This results in a failure during module init/> fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the

Quoted 93 lines

already-mapped stats_pages[HV_STATS_AREA_SELF].

---
  drivers/hv/mshv_root_hv_call.c | 43 ++++++++++++++++++++++++++++++----
  drivers/hv/mshv_root_main.c    |  3 +++
  2 files changed, 42 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_hv_call.c +39 -4
index c9c274f29c3c..1c38576a673c 100644
@@ -724,6 +724,24 @@ hv_call_notify_port_ring_empty(u32 sint_index)
  	return hv_result_to_errno(status);
  }
 
+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;
+}
+
  int hv_call_map_stat_page(enum hv_stats_object_type type,
  			  const union hv_stats_object_identity *identity,
  			  void **addr)
@@ -732,7 +750,7 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
  	struct hv_input_map_stats_page *input;
  	struct hv_output_map_stats_page *output;
  	u64 status, pfn;
-	int ret = 0;
+	int hv_status, ret = 0;
 
  	do {
  		local_irq_save(flags);
@@ -747,11 +765,28 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
  		pfn = output->map_location;
 
  		local_irq_restore(flags);
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
-			ret = hv_result_to_errno(status);
+
+		hv_status = hv_result(status);
+		if (hv_status != HV_STATUS_INSUFFICIENT_MEMORY) {
  			if (hv_result_success(status))
  				break;
-			return ret;
+
+			/*
+			 * Some versions of the hypervisor do not support the
+			 * PARENT stats area. In this case return "success" but
+			 * set the page to NULL. The caller checks for this
+			 * case instead just uses the SELF area.
+			 */
+			if (hv_stats_get_area_type(type, identity) == HV_STATS_AREA_PARENT &&
+			    hv_status == HV_STATUS_INVALID_PARAMETER) {
+				pr_debug_once("%s: PARENT area type is unsupported\n",
+					      __func__);
+				*addr = NULL;
+				return 0;
+			}
+
+			hv_status_debug(status, "\n");
+			return hv_result_to_errno(status);
  		}
 
  		ret = hv_call_deposit_pages(NUMA_NO_NODE,
drivers/hv/mshv_root_main.c +3 -0
index bbdefe8a2e9c..56ababab57ce 100644
@@ -929,6 +929,9 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
  	if (err)
  		goto unmap_self;
 
+	if (!stats_pages[HV_STATS_AREA_PARENT])
+		stats_pages[HV_STATS_AREA_PARENT] = stats_pages[HV_STATS_AREA_SELF];
+
  	return 0;
 
  unmap_self:
Signature · 2 lines
Regards,
Praveen K Paladugu
#8 lore raw

Re: [PATCH 2/6] mshv: Ignore second stats page map result failure

Quoted 12 lines · Praveen K Paladugu
Quoted 6 lines · Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

Is this behavior limited to VP stats? Or does it extend to other stats (hypervisor, partition, etc) as well?

In practice we will only need to worry about partition and VP.

In the current code in hyperv-next, it's only VP stats. Upcoming patches to add debugfs code will also need it for partition stats.

Quoted 2 lines
Quoted 1 line

This results a failure in module init. Instead of failing, gracefully

nit: s/This results in a failure during module init/

Thanks, I'll change it for v2

Nuno

Quoted 89 lines
Quoted 88 lines

fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped stats_pages[HV_STATS_AREA_SELF].

---
  drivers/hv/mshv_root_hv_call.c | 43 ++++++++++++++++++++++++++++++---- drivers/hv/mshv_root_main.c    |  3 +++

  2 files changed, 42 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_hv_call.c +0 -0
index c9c274f29c3c..1c38576a673c 100644
@@ -724,6 +724,24 @@ hv_call_notify_port_ring_empty(u32 sint_index)
       return hv_result_to_errno(status);
   }

  +static int

drivers/hv/mshv_root_hv_call.c +17 -0
+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;
+}
+

  int hv_call_map_stat_page(enum hv_stats_object_type type, const union hv_stats_object_identity *identity, void **addr)

drivers/hv/mshv_root_hv_call.c +21 -4
@@ -732,7 +750,7 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
       struct hv_input_map_stats_page *input;
       struct hv_output_map_stats_page *output;
       u64 status, pfn;
-    int ret = 0;
+    int hv_status, ret = 0;
         do {
           local_irq_save(flags);
@@ -747,11 +765,28 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
           pfn = output->map_location;
             local_irq_restore(flags);
-        if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
-            ret = hv_result_to_errno(status);
+
+        hv_status = hv_result(status);
+        if (hv_status != HV_STATUS_INSUFFICIENT_MEMORY) {
               if (hv_result_success(status))
                   break;
-            return ret;
+
+            /*
+             * Some versions of the hypervisor do not support the
+             * PARENT stats area. In this case return "success" but
+             * set the page to NULL. The caller checks for this
+             * case instead just uses the SELF area.
+             */
+            if (hv_stats_get_area_type(type, identity) == HV_STATS_AREA_PARENT &&
+                hv_status == HV_STATUS_INVALID_PARAMETER) {
+                pr_debug_once("%s: PARENT area type is unsupported\n",
+                          __func__);
+                *addr = NULL;
+                return 0;
+            }
+
+            hv_status_debug(status, "\n");
+            return hv_result_to_errno(status);
           }
             ret = hv_call_deposit_pages(NUMA_NO_NODE,
drivers/hv/mshv_root_main.c +2 -0
index bbdefe8a2e9c..56ababab57ce 100644
@@ -929,6 +929,9 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
       if (err)
           goto unmap_self;
   +    if (!stats_pages[HV_STATS_AREA_PARENT])
+        stats_pages[HV_STATS_AREA_PARENT] = stats_pages[HV_STATS_AREA_SELF];
+
       return 0;

    unmap_self:

#9 lore raw

Re: [PATCH 2/6] mshv: Ignore second stats page map result failure

In reply to Nuno Das Neves
Quoted 9 lines · Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

This results a failure in module init. Instead of failing, gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped stats_pages[HV_STATS_AREA_SELF].

What's the impact of this graceful fallback? It occurs to me that if a stats accumulator, in userspace perhaps, expected to get stats from the 2 pages, it'd get incorrect values.

Quoted 13 lines
---
 drivers/hv/mshv_root_hv_call.c | 43 ++++++++++++++++++++++++++++++----
 drivers/hv/mshv_root_main.c    |  3 +++
 2 files changed, 42 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_hv_call.c +0 -0
index c9c274f29c3c..1c38576a673c 100644

drivers/hv/mshv_root_hv_call.c hv_call_notify_port_ring_empty(u32 sint_index) · line 728

Quoted 5 lines
drivers/hv/mshv_root_hv_call.c +2 -0
@@ -724,6 +724,24 @@ hv_call_notify_port_ring_empty(u32 sint_index)
 	return hv_result_to_errno(status);
 }
 
+static int
+hv_stats_get_area_type(enum hv_stats_object_type type,

One line please, i.e.

static int hv_stats_get_area_type(...)

<snip>

Thanks,
Easwar (he/him)

#10 lore raw

Re: [PATCH 2/6] mshv: Ignore second stats page map result failure

Quoted 7 lines · Easwar Hariharan
Quoted 6 lines · Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

Quoted 8 lines
Quoted 3 lines

This results a failure in module init. Instead of failing, gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped stats_pages[HV_STATS_AREA_SELF].

What's the impact of this graceful fallback? It occurs to me that if a stats accumulator, in userspace perhaps, expected to get stats from the 2 pages, it'd get incorrect values.

This is going out of scope of this series a bit but I'll explain briefly.

When we do add the code to expose these stats to userspace, the SELF and PARENT pages won't be exposed separately, there is no duplication.

For each stat counter in the page, we'll expose either the SELF or PARENT value, depending on whether there is anything in that slot (whether it's zero or not).

Some stats are available via the SELF page, and some via the PARENT page, but the counters in the page have the same layout. So some counters in the SELF page will all stay zero while on the PARENT page they are updated, and vice versa.

I believe the hypervisor takes this strange approach for the purpose of backward compatibility. Introducing L1VH created the need for this SELF/PARENT distinction.

Hope that makes some kind of sense...it will be clearer when we post the mshv debugfs code itself.

To put it another way, falling back to the SELF page won't cause any impact to userspace because the distinction between the pages is all handled in the driver, and we only read each stat value from either SELF or PARENT.

Nuno

Quoted 27 lines
Quoted 13 lines
---
 drivers/hv/mshv_root_hv_call.c | 43 ++++++++++++++++++++++++++++++----
 drivers/hv/mshv_root_main.c    |  3 +++
 2 files changed, 42 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_hv_call.c +0 -0
index c9c274f29c3c..1c38576a673c 100644

drivers/hv/mshv_root_hv_call.c hv_call_notify_port_ring_empty(u32 sint_index) · line 728

Quoted 5 lines
drivers/hv/mshv_root_hv_call.c +2 -0
@@ -724,6 +724,24 @@ hv_call_notify_port_ring_empty(u32 sint_index)
 	return hv_result_to_errno(status);
 }
 
+static int
+hv_stats_get_area_type(enum hv_stats_object_type type,

One line please, i.e.

static int hv_stats_get_area_type(...)

<snip>

Thanks,
Easwar (he/him)

#11 lore raw

Re: [PATCH 2/6] mshv: Ignore second stats page map result failure

Quoted 34 lines · Nuno Das Neves
Quoted 7 lines · Easwar Hariharan
Quoted 6 lines · Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

Quoted 8 lines
Quoted 3 lines

This results a failure in module init. Instead of failing, gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped stats_pages[HV_STATS_AREA_SELF].

What's the impact of this graceful fallback? It occurs to me that if a stats accumulator, in userspace perhaps, expected to get stats from the 2 pages, it'd get incorrect values.

This is going out of scope of this series a bit but I'll explain briefly.

When we do add the code to expose these stats to userspace, the SELF and PARENT pages won't be exposed separately, there is no duplication.

For each stat counter in the page, we'll expose either the SELF or PARENT value, depending on whether there is anything in that slot (whether it's zero or not).

Some stats are available via the SELF page, and some via the PARENT page, but the counters in the page have the same layout. So some counters in the SELF page will all stay zero while on the PARENT page they are updated, and vice versa.

I believe the hypervisor takes this strange approach for the purpose of backward compatibility. Introducing L1VH created the need for this SELF/PARENT distinction.

Quoted 8 lines

Hope that makes some kind of sense...it will be clearer when we post the mshv debugfs code itself.

To put it another way, falling back to the SELF page won't cause any impact to userspace because the distinction between the pages is all handled in the driver, and we only read each stat value from either SELF or PARENT.

Nuno

Thank you for that explanation, it sorta makes sense.

I think it'd be better if this patch is part of the series that exposes the stats to userspace, so that it can be reviewed in context with the rest of the code in the driver that manages the pick-and-choose of a stat value from the SELF/PARENT page.

Unless there's an active problem now in the upstream kernel that this patch solves? i.e. are the versions of the hypervisor that don't support the PARENT stats page available in the wild?

Thanks,
Easwar (he/him)

#12 lore raw

Re: [PATCH 2/6] mshv: Ignore second stats page map result failure

Quoted 42 lines · Easwar Hariharan
Quoted 41 lines · Nuno Das Neves
Quoted 7 lines · Easwar Hariharan
Quoted 6 lines · Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

Quoted 8 lines
Quoted 3 lines

This results a failure in module init. Instead of failing, gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped stats_pages[HV_STATS_AREA_SELF].

What's the impact of this graceful fallback? It occurs to me that if a stats accumulator, in userspace perhaps, expected to get stats from the 2 pages, it'd get incorrect values.

This is going out of scope of this series a bit but I'll explain briefly.

When we do add the code to expose these stats to userspace, the SELF and PARENT pages won't be exposed separately, there is no duplication.

For each stat counter in the page, we'll expose either the SELF or PARENT value, depending on whether there is anything in that slot (whether it's zero or not).

Some stats are available via the SELF page, and some via the PARENT page, but the counters in the page have the same layout. So some counters in the SELF page will all stay zero while on the PARENT page they are updated, and vice versa.

I believe the hypervisor takes this strange approach for the purpose of backward compatibility. Introducing L1VH created the need for this SELF/PARENT distinction.

Hope that makes some kind of sense...it will be clearer when we post the mshv debugfs code itself.

To put it another way, falling back to the SELF page won't cause any impact to userspace because the distinction between the pages is all handled in the driver, and we only read each stat value from either SELF or PARENT.

Quoted 9 lines
Quoted 1 line

Nuno

Thank you for that explanation, it sorta makes sense.

I think it'd be better if this patch is part of the series that exposes the stats to userspace, so that it can be reviewed in context with the rest of the code in the driver that manages the pick-and-choose of a stat value from the SELF/PARENT page.

Good idea, I think I'll do that. Thanks!

Quoted 4 lines

Unless there's an active problem now in the upstream kernel that this patch solves? i.e. are the versions of the hypervisor that don't support the PARENT stats page available in the wild?

I thought there was, but on reflection, no it doesn't solve a problem that exists in the code today.

Nuno

Quoted 2 lines

Thanks,
Easwar (he/him)

#13 lore raw

Re: [PATCH 2/6] mshv: Ignore second stats page map result failure

Quoted 54 lines · Nuno Das Neves
Quoted 42 lines · Easwar Hariharan
Quoted 41 lines · Nuno Das Neves
Quoted 7 lines · Easwar Hariharan
Quoted 6 lines · Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

Quoted 8 lines
Quoted 3 lines

This results a failure in module init. Instead of failing, gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped stats_pages[HV_STATS_AREA_SELF].

What's the impact of this graceful fallback? It occurs to me that if a stats accumulator, in userspace perhaps, expected to get stats from the 2 pages, it'd get incorrect values.

This is going out of scope of this series a bit but I'll explain briefly.

When we do add the code to expose these stats to userspace, the SELF and PARENT pages won't be exposed separately, there is no duplication.

For each stat counter in the page, we'll expose either the SELF or PARENT value, depending on whether there is anything in that slot (whether it's zero or not).

Some stats are available via the SELF page, and some via the PARENT page, but the counters in the page have the same layout. So some counters in the SELF page will all stay zero while on the PARENT page they are updated, and vice versa.

I believe the hypervisor takes this strange approach for the purpose of backward compatibility. Introducing L1VH created the need for this SELF/PARENT distinction.

Hope that makes some kind of sense...it will be clearer when we post the mshv debugfs code itself.

To put it another way, falling back to the SELF page won't cause any impact to userspace because the distinction between the pages is all handled in the driver, and we only read each stat value from either SELF or PARENT.

Quoted 9 lines
Quoted 1 line

Nuno

Thank you for that explanation, it sorta makes sense.

I think it'd be better if this patch is part of the series that exposes the stats to userspace, so that it can be reviewed in context with the rest of the code in the driver that manages the pick-and-choose of a stat value from the SELF/PARENT page.

Good idea, I think I'll do that. Thanks!

Quoted 9 lines
Quoted 4 lines

Unless there's an active problem now in the upstream kernel that this patch solves? i.e. are the versions of the hypervisor that don't support the PARENT stats page available in the wild?

I thought there was, but on reflection, no it doesn't solve a problem that exists in the code today.

Nuno

The usecases for stats exposed by the hypervisor are:
1) used within the kernel by root scheduler
2) exposed to userspace via debugfs.

I thought we are addressing the first use-case here (patch1 in this series). If root scheduler support was upstreamed then this patchset does solve a problem in upstream code.

Quoted 4 lines
Quoted 2 lines

Thanks,
Easwar (he/him)

Signature · 2 lines
Regards,
Praveen K Paladugu
#14 lore raw

Re: [PATCH 2/6] mshv: Ignore second stats page map result failure

Quoted 64 lines · Praveen K Paladugu
Quoted 61 lines · Nuno Das Neves
Quoted 42 lines · Easwar Hariharan
Quoted 41 lines · Nuno Das Neves
Quoted 7 lines · Easwar Hariharan
Quoted 6 lines · Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

Quoted 8 lines
Quoted 3 lines

This results a failure in module init. Instead of failing, gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped stats_pages[HV_STATS_AREA_SELF].

What's the impact of this graceful fallback? It occurs to me that if a stats accumulator, in userspace perhaps, expected to get stats from the 2 pages, it'd get incorrect values.

This is going out of scope of this series a bit but I'll explain briefly.

When we do add the code to expose these stats to userspace, the SELF and PARENT pages won't be exposed separately, there is no duplication.

For each stat counter in the page, we'll expose either the SELF or PARENT value, depending on whether there is anything in that slot (whether it's zero or not).

Some stats are available via the SELF page, and some via the PARENT page, but the counters in the page have the same layout. So some counters in the SELF page will all stay zero while on the PARENT page they are updated, and vice versa.

I believe the hypervisor takes this strange approach for the purpose of backward compatibility. Introducing L1VH created the need for this SELF/PARENT distinction.

Hope that makes some kind of sense...it will be clearer when we post the mshv debugfs code itself.

To put it another way, falling back to the SELF page won't cause any impact to userspace because the distinction between the pages is all handled in the driver, and we only read each stat value from either SELF or PARENT.

Quoted 9 lines
Quoted 1 line

Nuno

Thank you for that explanation, it sorta makes sense.

I think it'd be better if this patch is part of the series that exposes the stats to userspace, so that it can be reviewed in context with the rest of the code in the driver that manages the pick-and-choose of a stat value from the SELF/PARENT page.

Good idea, I think I'll do that. Thanks!

Quoted 4 lines

Unless there's an active problem now in the upstream kernel that this patch solves? i.e. are the versions of the hypervisor that don't support the PARENT stats page available in the wild?

I thought there was, but on reflection, no it doesn't solve a problem that exists in the code today.

Quoted 9 lines
Quoted 2 lines

Nuno

The usecases for stats exposed by the hypervisor are:
1) used within the kernel by root scheduler
2) exposed to userspace via debugfs.

I thought we are addressing the first use-case here (patch1 in this series). If root scheduler support was upstreamed then this patchset does solve a problem in upstream code.

Sorry about the long context, I couldn't figure out a good spot to snip.

Thanks for calling that out. I think root scheduler support has been upstreamed if I'm reading root_scheduler_init() right, Nuno can confirm.

With the series applied, I don't see any of the code that picks and chooses the stats from the PARENT/SELF pages even for the kernel case, rather there's a straight memcpy of the stats pages in the create_vp ioctl.

Is the kernel usage with the root scheduler somehow immune from the problem userspace would face with the duplicated pages? If not, I'd say that it's an argument for dropping patch 1 and 2, instead of including patch 2, or to fold them together. We don't want a state in the upstream kernel where a commit introduces a known problem just to be solved by the following commit.

Thanks,
Easwar (he/him)

#15 lore raw

Re: [PATCH 2/6] mshv: Ignore second stats page map result failure

Quoted 72 lines · Easwar Hariharan
Quoted 71 lines · Praveen K Paladugu
Quoted 54 lines · Nuno Das Neves
Quoted 42 lines · Easwar Hariharan
Quoted 41 lines · Nuno Das Neves
Quoted 7 lines · Easwar Hariharan
Quoted 6 lines · Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

Quoted 8 lines
Quoted 3 lines

This results a failure in module init. Instead of failing, gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped stats_pages[HV_STATS_AREA_SELF].

What's the impact of this graceful fallback? It occurs to me that if a stats accumulator, in userspace perhaps, expected to get stats from the 2 pages, it'd get incorrect values.

This is going out of scope of this series a bit but I'll explain briefly.

When we do add the code to expose these stats to userspace, the SELF and PARENT pages won't be exposed separately, there is no duplication.

For each stat counter in the page, we'll expose either the SELF or PARENT value, depending on whether there is anything in that slot (whether it's zero or not).

Some stats are available via the SELF page, and some via the PARENT page, but the counters in the page have the same layout. So some counters in the SELF page will all stay zero while on the PARENT page they are updated, and vice versa.

I believe the hypervisor takes this strange approach for the purpose of backward compatibility. Introducing L1VH created the need for this SELF/PARENT distinction.

Hope that makes some kind of sense...it will be clearer when we post the mshv debugfs code itself.

To put it another way, falling back to the SELF page won't cause any impact to userspace because the distinction between the pages is all handled in the driver, and we only read each stat value from either SELF or PARENT.

Quoted 9 lines
Quoted 1 line

Nuno

Thank you for that explanation, it sorta makes sense.

I think it'd be better if this patch is part of the series that exposes the stats to userspace, so that it can be reviewed in context with the rest of the code in the driver that manages the pick-and-choose of a stat value from the SELF/PARENT page.

Good idea, I think I'll do that. Thanks!

Quoted 9 lines
Quoted 4 lines

Unless there's an active problem now in the upstream kernel that this patch solves? i.e. are the versions of the hypervisor that don't support the PARENT stats page available in the wild?

I thought there was, but on reflection, no it doesn't solve a problem that exists in the code today.

Nuno

The usecases for stats exposed by the hypervisor are:
1) used within the kernel by root scheduler
2) exposed to userspace via debugfs.

Quoted 8 lines
Quoted 2 lines

I thought we are addressing the first use-case here (patch1 in this series). If root scheduler support was upstreamed then this patchset does solve a problem in upstream code.

Sorry about the long context, I couldn't figure out a good spot to snip.

Thanks for calling that out. I think root scheduler support has been upstreamed if I'm reading root_scheduler_init() right, Nuno can confirm.

Correct. But the user of the PARENT == SELF workaround is L1VH, which doesn't support root scheduler today. So technically the fix doesn't do anything if we're just talking about the stats mapping used by the root scheduler code.

Quoted 4 lines

With the series applied, I don't see any of the code that picks and chooses the stats from the PARENT/SELF pages even for the kernel case, rather there's a straight memcpy of the stats pages in the create_vp ioctl.

This memcpy:
memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));

Is not copying the contents of the pages. It's copying array of pointers to the SELF and PARENT pages:

struct mshv_vp{
/* ... */

	struct hv_stats_page *vp_stats_pages[2];

/* ... */
};

Quoted 6 lines

Is the kernel usage with the root scheduler somehow immune from the problem userspace would face with the duplicated pages? If not, I'd say that it's an argument for dropping patch 1 and 2, instead of including patch 2, or to fold them together. We don't want a state in the upstream kernel where a commit introduces a known problem just to be solved by the following commit.

Yes, it's immune. Nothing is being accumulated and therefore double-counted. There's a signal value in the stats page which is used to determine if the dispatch thread is blocked. It's just a boolean. See mshv_vp_dispatch_thread_blocked().

Thanks
Nuno

Quoted 2 lines

Thanks,
Easwar (he/him)

Reviewed-by on v1 2/6
#16 lore raw

Re: [PATCH 2/6] mshv: Ignore second stats page map result failure

In reply to Nuno Das Neves
Quoted 11 lines · Nuno Das Neves

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

Some versions of the hypervisor do not support HV_STATUS_AREA_PARENT and return HV_STATUS_INVALID_PARAMETER for the second stats page mapping request.

This results a failure in module init. Instead of failing, gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped stats_pages[HV_STATS_AREA_SELF].

Quoted 7 lines
---
 drivers/hv/mshv_root_hv_call.c | 43 ++++++++++++++++++++++++++++++----
 drivers/hv/mshv_root_main.c    |  3 +++
 2 files changed, 42 insertions(+), 4 deletions(-)
Quoted 88 lines
drivers/hv/mshv_root_hv_call.c +39 -4
index c9c274f29c3c..1c38576a673c 100644
@@ -724,6 +724,24 @@ hv_call_notify_port_ring_empty(u32 sint_index)
        return hv_result_to_errno(status);
 }
 
+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;
+}
+
 int hv_call_map_stat_page(enum hv_stats_object_type type,
                          const union hv_stats_object_identity *identity,
                          void **addr)
@@ -732,7 +750,7 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
        struct hv_input_map_stats_page *input;
        struct hv_output_map_stats_page *output;
        u64 status, pfn;
-       int ret = 0;
+       int hv_status, ret = 0;
 
        do {
                local_irq_save(flags);
@@ -747,11 +765,28 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
                pfn = output->map_location;
 
                local_irq_restore(flags);
-               if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
-                       ret = hv_result_to_errno(status);
+
+               hv_status = hv_result(status);
+               if (hv_status != HV_STATUS_INSUFFICIENT_MEMORY) {
                        if (hv_result_success(status))
                                break;
-                       return ret;
+
+                       /*
+                        * Some versions of the hypervisor do not support the
+                        * PARENT stats area. In this case return "success" but
+                        * set the page to NULL. The caller checks for this
+                        * case instead just uses the SELF area.
+                        */
+                       if (hv_stats_get_area_type(type, identity) == HV_STATS_AREA_PARENT &&
+                           hv_status == HV_STATUS_INVALID_PARAMETER) {
+                               pr_debug_once("%s: PARENT area type is unsupported\n",
+                                             __func__);
+                               *addr = NULL;
+                               return 0;
+                       }
+
+                       hv_status_debug(status, "\n");
+                       return hv_result_to_errno(status);
                }
 
                ret = hv_call_deposit_pages(NUMA_NO_NODE,
drivers/hv/mshv_root_main.c +3 -1
index bbdefe8a2e9c..56ababab57ce 100644
@@ -929,6 +929,9 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
        if (err)
                goto unmap_self;
 
+       if (!stats_pages[HV_STATS_AREA_PARENT])
+               stats_pages[HV_STATS_AREA_PARENT] = stats_pages[HV_STATS_AREA_SELF];
+
        return 0;
 
 unmap_self:
--

2.34.1

Signature · 2 lines
Thanks
Tianyu Lan
#17 lore raw

PATCH 3/6 mshv: Add the HVCALL_GET_PARTITION_PROPERTY_EX hypercall

In reply to Nuno Das Neves

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

This hypercall can be used to fetch extended properties of a partition. Extended properties are properties with values larger than a u64. Some of these also need additional input arguments.

Add helper function for using the hypercall in the mshv_root driver.

---
 drivers/hv/mshv_root.h         |  2 ++
 drivers/hv/mshv_root_hv_call.c | 31 ++++++++++++++++++++++++++
 include/hyperv/hvgdk_mini.h    |  1 +
 include/hyperv/hvhdk.h         | 40 ++++++++++++++++++++++++++++++++++
 include/hyperv/hvhdk_mini.h    | 26 ++++++++++++++++++++++
 5 files changed, 100 insertions(+)
drivers/hv/mshv_root.h +2 -0
index e3931b0f1269..4aeb03bea6b6 100644
@@ -303,6 +303,8 @@ int hv_call_unmap_stat_page(enum hv_stats_object_type type,
 int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
 				   u64 page_struct_count, u32 host_access,
 				   u32 flags, u8 acquire);
+int hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
+				      void *property_value, size_t property_value_sz);
 
 extern struct mshv_root mshv_root;
 extern enum hv_scheduler_type hv_scheduler_type;
drivers/hv/mshv_root_hv_call.c +31 -0
index 1c38576a673c..7589b1ff3515 100644
@@ -590,6 +590,37 @@ int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
 	return hv_result_to_errno(status);
 }
 
+int
+hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
+				  void *property_value, size_t property_value_sz)
+{
+	u64 status;
+	unsigned long flags;
+	struct hv_input_get_partition_property_ex *input;
+	struct hv_output_get_partition_property_ex *output;
+
+	local_irq_save(flags);
+	input = *this_cpu_ptr(hyperv_pcpu_input_arg);
+	output = *this_cpu_ptr(hyperv_pcpu_output_arg);
+
+	memset(input, 0, sizeof(*input));
+	input->partition_id = partition_id;
+	input->property_code = property_code;
+	input->arg = arg;
+	status = hv_do_hypercall(HVCALL_GET_PARTITION_PROPERTY_EX, input, output);
+
+	if (!hv_result_success(status)) {
+		hv_status_debug(status, "\n");
+		local_irq_restore(flags);
+		return hv_result_to_errno(status);
+	}
+	memcpy(property_value, &output->property_value, property_value_sz);
+
+	local_irq_restore(flags);
+
+	return 0;
+}
+
 int
 hv_call_clear_virtual_interrupt(u64 partition_id)
 {
include/hyperv/hvgdk_mini.h +1 -0
index 79b7324e4ef5..1bde0aa102ec 100644
@@ -490,6 +490,7 @@ union hv_vp_assist_msr_contents {	 /* HV_REGISTER_VP_ASSIST_PAGE */
 #define HVCALL_GET_VP_STATE				0x00e3
 #define HVCALL_SET_VP_STATE				0x00e4
 #define HVCALL_GET_VP_CPUID_VALUES			0x00f4
+#define HVCALL_GET_PARTITION_PROPERTY_EX		0x0101
 #define HVCALL_MMIO_READ				0x0106
 #define HVCALL_MMIO_WRITE				0x0107
 
include/hyperv/hvhdk.h +40 -0
index 57f3f9c2a685..fd3555def008 100644
@@ -411,6 +411,46 @@ struct hv_input_set_partition_property {
 	u64 property_value;
 } __packed;
 
+union hv_partition_property_arg {
+	u64 as_uint64;
+	struct {
+		union {
+			u32 arg;
+			u32 vp_index;
+		};
+		u16 reserved0;
+		u8 reserved1;
+		u8 object_type;
+	};
+} __packed;
+
+struct hv_input_get_partition_property_ex {
+	u64 partition_id;
+	u32 property_code; /* enum hv_partition_property_code */
+	u32 padding;
+	union {
+		union hv_partition_property_arg arg_data;
+		u64 arg;
+	};
+} __packed;
+
+/*
+ * NOTE: Should use hv_input_set_partition_property_ex_header to compute this
+ * size, but hv_input_get_partition_property_ex is identical so it suffices
+ */
+#define HV_PARTITION_PROPERTY_EX_MAX_VAR_SIZE \
+	(HV_HYP_PAGE_SIZE - sizeof(struct hv_input_get_partition_property_ex))
+
+union hv_partition_property_ex {
+	u8 buffer[HV_PARTITION_PROPERTY_EX_MAX_VAR_SIZE];
+	struct hv_partition_property_vmm_capabilities vmm_capabilities;
+	/* More fields to be filled in when needed */
+} __packed;
+
+struct hv_output_get_partition_property_ex {
+	union hv_partition_property_ex property_value;
+} __packed;
+
 enum hv_vp_state_page_type {
 	HV_VP_STATE_PAGE_REGISTERS = 0,
 	HV_VP_STATE_PAGE_INTERCEPT_MESSAGE = 1,
include/hyperv/hvhdk_mini.h +26 -0
index 858f6a3925b3..bf2ce27dfcc5 100644
@@ -96,8 +96,34 @@ enum hv_partition_property_code {
 	HV_PARTITION_PROPERTY_XSAVE_STATES                      = 0x00060007,
 	HV_PARTITION_PROPERTY_MAX_XSAVE_DATA_SIZE		= 0x00060008,
 	HV_PARTITION_PROPERTY_PROCESSOR_CLOCK_FREQUENCY		= 0x00060009,
+
+	/* Extended properties with larger property values */
+	HV_PARTITION_PROPERTY_VMM_CAPABILITIES			= 0x00090007,
 };
 
+#define HV_PARTITION_VMM_CAPABILITIES_BANK_COUNT		1
+#define HV_PARTITION_VMM_CAPABILITIES_RESERVED_BITFIELD_COUNT	59
+
+struct hv_partition_property_vmm_capabilities {
+	u16 bank_count;
+	u16 reserved[3];
+	union {
+		u64 as_uint64[HV_PARTITION_VMM_CAPABILITIES_BANK_COUNT];
+		struct {
+			u64 map_gpa_preserve_adjustable: 1;
+			u64 vmm_can_provide_overlay_gpfn: 1;
+			u64 vp_affinity_property: 1;
+#if IS_ENABLED(CONFIG_ARM64)
+			u64 vmm_can_provide_gic_overlay_locations: 1;
+#else
+			u64 reservedbit3: 1;
+#endif
+			u64 assignable_synthetic_proc_features: 1;
+			u64 reserved0: HV_PARTITION_VMM_CAPABILITIES_RESERVED_BITFIELD_COUNT;
+		} __packed;
+	};
+} __packed;
+
 enum hv_snp_status {
 	HV_SNP_STATUS_NONE = 0,
 	HV_SNP_STATUS_AVAILABLE = 1,
Signature · 1 line
2.34.1
Reviewed-by on v1 3/6
#18 lore raw

Re: [PATCH 3/6] mshv: Add the HVCALL_GET_PARTITION_PROPERTY_EX hypercall

Quoted 178 lines · Nuno Das Neves

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

This hypercall can be used to fetch extended properties of a partition. Extended properties are properties with values larger than a u64. Some of these also need additional input arguments.

Add helper function for using the hypercall in the mshv_root driver.

---
 drivers/hv/mshv_root.h         |  2 ++
 drivers/hv/mshv_root_hv_call.c | 31 ++++++++++++++++++++++++++
 include/hyperv/hvgdk_mini.h    |  1 +
 include/hyperv/hvhdk.h         | 40 ++++++++++++++++++++++++++++++++++
 include/hyperv/hvhdk_mini.h    | 26 ++++++++++++++++++++++
 5 files changed, 100 insertions(+)
drivers/hv/mshv_root.h +2 -0
index e3931b0f1269..4aeb03bea6b6 100644
@@ -303,6 +303,8 @@ int hv_call_unmap_stat_page(enum hv_stats_object_type type,
 int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
 				   u64 page_struct_count, u32 host_access,
 				   u32 flags, u8 acquire);
+int hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
+				      void *property_value, size_t property_value_sz);
 
 extern struct mshv_root mshv_root;
 extern enum hv_scheduler_type hv_scheduler_type;
drivers/hv/mshv_root_hv_call.c +31 -0
index 1c38576a673c..7589b1ff3515 100644
@@ -590,6 +590,37 @@ int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
 	return hv_result_to_errno(status);
 }
 
+int
+hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
+				  void *property_value, size_t property_value_sz)
+{
+	u64 status;
+	unsigned long flags;
+	struct hv_input_get_partition_property_ex *input;
+	struct hv_output_get_partition_property_ex *output;
+
+	local_irq_save(flags);
+	input = *this_cpu_ptr(hyperv_pcpu_input_arg);
+	output = *this_cpu_ptr(hyperv_pcpu_output_arg);
+
+	memset(input, 0, sizeof(*input));
+	input->partition_id = partition_id;
+	input->property_code = property_code;
+	input->arg = arg;
+	status = hv_do_hypercall(HVCALL_GET_PARTITION_PROPERTY_EX, input, output);
+
+	if (!hv_result_success(status)) {
+		hv_status_debug(status, "\n");
+		local_irq_restore(flags);
+		return hv_result_to_errno(status);
+	}
+	memcpy(property_value, &output->property_value, property_value_sz);
+
+	local_irq_restore(flags);
+
+	return 0;
+}
+
 int
 hv_call_clear_virtual_interrupt(u64 partition_id)
 {
include/hyperv/hvgdk_mini.h +1 -0
index 79b7324e4ef5..1bde0aa102ec 100644
@@ -490,6 +490,7 @@ union hv_vp_assist_msr_contents {	 /* HV_REGISTER_VP_ASSIST_PAGE */
 #define HVCALL_GET_VP_STATE				0x00e3
 #define HVCALL_SET_VP_STATE				0x00e4
 #define HVCALL_GET_VP_CPUID_VALUES			0x00f4
+#define HVCALL_GET_PARTITION_PROPERTY_EX		0x0101
 #define HVCALL_MMIO_READ				0x0106
 #define HVCALL_MMIO_WRITE				0x0107
 
include/hyperv/hvhdk.h +40 -0
index 57f3f9c2a685..fd3555def008 100644
@@ -411,6 +411,46 @@ struct hv_input_set_partition_property {
 	u64 property_value;
 } __packed;
 
+union hv_partition_property_arg {
+	u64 as_uint64;
+	struct {
+		union {
+			u32 arg;
+			u32 vp_index;
+		};
+		u16 reserved0;
+		u8 reserved1;
+		u8 object_type;
+	};
+} __packed;
+
+struct hv_input_get_partition_property_ex {
+	u64 partition_id;
+	u32 property_code; /* enum hv_partition_property_code */
+	u32 padding;
+	union {
+		union hv_partition_property_arg arg_data;
+		u64 arg;
+	};
+} __packed;
+
+/*
+ * NOTE: Should use hv_input_set_partition_property_ex_header to compute this
+ * size, but hv_input_get_partition_property_ex is identical so it suffices
+ */
+#define HV_PARTITION_PROPERTY_EX_MAX_VAR_SIZE \
+	(HV_HYP_PAGE_SIZE - sizeof(struct hv_input_get_partition_property_ex))
+
+union hv_partition_property_ex {
+	u8 buffer[HV_PARTITION_PROPERTY_EX_MAX_VAR_SIZE];
+	struct hv_partition_property_vmm_capabilities vmm_capabilities;
+	/* More fields to be filled in when needed */
+} __packed;
+
+struct hv_output_get_partition_property_ex {
+	union hv_partition_property_ex property_value;
+} __packed;
+
 enum hv_vp_state_page_type {
 	HV_VP_STATE_PAGE_REGISTERS = 0,
 	HV_VP_STATE_PAGE_INTERCEPT_MESSAGE = 1,
include/hyperv/hvhdk_mini.h +26 -0
index 858f6a3925b3..bf2ce27dfcc5 100644
@@ -96,8 +96,34 @@ enum hv_partition_property_code {
 	HV_PARTITION_PROPERTY_XSAVE_STATES                      = 0x00060007,
 	HV_PARTITION_PROPERTY_MAX_XSAVE_DATA_SIZE		= 0x00060008,
 	HV_PARTITION_PROPERTY_PROCESSOR_CLOCK_FREQUENCY		= 0x00060009,
+
+	/* Extended properties with larger property values */
+	HV_PARTITION_PROPERTY_VMM_CAPABILITIES			= 0x00090007,
 };
 
+#define HV_PARTITION_VMM_CAPABILITIES_BANK_COUNT		1
+#define HV_PARTITION_VMM_CAPABILITIES_RESERVED_BITFIELD_COUNT	59
+
+struct hv_partition_property_vmm_capabilities {
+	u16 bank_count;
+	u16 reserved[3];
+	union {
+		u64 as_uint64[HV_PARTITION_VMM_CAPABILITIES_BANK_COUNT];
+		struct {
+			u64 map_gpa_preserve_adjustable: 1;
+			u64 vmm_can_provide_overlay_gpfn: 1;
+			u64 vp_affinity_property: 1;
+#if IS_ENABLED(CONFIG_ARM64)
+			u64 vmm_can_provide_gic_overlay_locations: 1;
+#else
+			u64 reservedbit3: 1;
+#endif
+			u64 assignable_synthetic_proc_features: 1;
+			u64 reserved0: HV_PARTITION_VMM_CAPABILITIES_RESERVED_BITFIELD_COUNT;
+		} __packed;
+	};
+} __packed;
+
 enum hv_snp_status {
 	HV_SNP_STATUS_NONE = 0,
 	HV_SNP_STATUS_AVAILABLE = 1,
Signature · 1 line
2.34.1
Reviewed-by on v1 3/6
#19 lore raw

Re: [PATCH 3/6] mshv: Add the HVCALL_GET_PARTITION_PROPERTY_EX hypercall

In reply to Nuno Das Neves
Quoted 165 lines · Nuno Das Neves

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

This hypercall can be used to fetch extended properties of a partition. Extended properties are properties with values larger than a u64. Some of these also need additional input arguments.

Add helper function for using the hypercall in the mshv_root driver.

---
  drivers/hv/mshv_root.h         |  2 ++
  drivers/hv/mshv_root_hv_call.c | 31 ++++++++++++++++++++++++++
  include/hyperv/hvgdk_mini.h    |  1 +
  include/hyperv/hvhdk.h         | 40 ++++++++++++++++++++++++++++++++++
  include/hyperv/hvhdk_mini.h    | 26 ++++++++++++++++++++++
  5 files changed, 100 insertions(+)
drivers/hv/mshv_root.h +2 -0
index e3931b0f1269..4aeb03bea6b6 100644
@@ -303,6 +303,8 @@ int hv_call_unmap_stat_page(enum hv_stats_object_type type,
  int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
  				   u64 page_struct_count, u32 host_access,
  				   u32 flags, u8 acquire);
+int hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
+				      void *property_value, size_t property_value_sz);
 
  extern struct mshv_root mshv_root;
  extern enum hv_scheduler_type hv_scheduler_type;
drivers/hv/mshv_root_hv_call.c +31 -0
index 1c38576a673c..7589b1ff3515 100644
@@ -590,6 +590,37 @@ int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
  	return hv_result_to_errno(status);
  }
 
+int
+hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
+				  void *property_value, size_t property_value_sz)
+{
+	u64 status;
+	unsigned long flags;
+	struct hv_input_get_partition_property_ex *input;
+	struct hv_output_get_partition_property_ex *output;
+
+	local_irq_save(flags);
+	input = *this_cpu_ptr(hyperv_pcpu_input_arg);
+	output = *this_cpu_ptr(hyperv_pcpu_output_arg);
+
+	memset(input, 0, sizeof(*input));
+	input->partition_id = partition_id;
+	input->property_code = property_code;
+	input->arg = arg;
+	status = hv_do_hypercall(HVCALL_GET_PARTITION_PROPERTY_EX, input, output);
+
+	if (!hv_result_success(status)) {
+		hv_status_debug(status, "\n");
+		local_irq_restore(flags);
+		return hv_result_to_errno(status);
+	}
+	memcpy(property_value, &output->property_value, property_value_sz);
+
+	local_irq_restore(flags);
+
+	return 0;
+}
+
  int
  hv_call_clear_virtual_interrupt(u64 partition_id)
  {
include/hyperv/hvgdk_mini.h +1 -0
index 79b7324e4ef5..1bde0aa102ec 100644
@@ -490,6 +490,7 @@ union hv_vp_assist_msr_contents {	 /* HV_REGISTER_VP_ASSIST_PAGE */
  #define HVCALL_GET_VP_STATE				0x00e3
  #define HVCALL_SET_VP_STATE				0x00e4
  #define HVCALL_GET_VP_CPUID_VALUES			0x00f4
+#define HVCALL_GET_PARTITION_PROPERTY_EX		0x0101
  #define HVCALL_MMIO_READ				0x0106
  #define HVCALL_MMIO_WRITE				0x0107
 
include/hyperv/hvhdk.h +40 -0
index 57f3f9c2a685..fd3555def008 100644
@@ -411,6 +411,46 @@ struct hv_input_set_partition_property {
  	u64 property_value;
  } __packed;
 
+union hv_partition_property_arg {
+	u64 as_uint64;
+	struct {
+		union {
+			u32 arg;
+			u32 vp_index;
+		};
+		u16 reserved0;
+		u8 reserved1;
+		u8 object_type;
+	};
+} __packed;
+
+struct hv_input_get_partition_property_ex {
+	u64 partition_id;
+	u32 property_code; /* enum hv_partition_property_code */
+	u32 padding;
+	union {
+		union hv_partition_property_arg arg_data;
+		u64 arg;
+	};
+} __packed;
+
+/*
+ * NOTE: Should use hv_input_set_partition_property_ex_header to compute this
+ * size, but hv_input_get_partition_property_ex is identical so it suffices
+ */
+#define HV_PARTITION_PROPERTY_EX_MAX_VAR_SIZE \
+	(HV_HYP_PAGE_SIZE - sizeof(struct hv_input_get_partition_property_ex))
+
+union hv_partition_property_ex {
+	u8 buffer[HV_PARTITION_PROPERTY_EX_MAX_VAR_SIZE];
+	struct hv_partition_property_vmm_capabilities vmm_capabilities;
+	/* More fields to be filled in when needed */
+} __packed;
+
+struct hv_output_get_partition_property_ex {
+	union hv_partition_property_ex property_value;
+} __packed;
+
  enum hv_vp_state_page_type {
  	HV_VP_STATE_PAGE_REGISTERS = 0,
  	HV_VP_STATE_PAGE_INTERCEPT_MESSAGE = 1,
include/hyperv/hvhdk_mini.h +19 -0
index 858f6a3925b3..bf2ce27dfcc5 100644
@@ -96,8 +96,34 @@ enum hv_partition_property_code {
  	HV_PARTITION_PROPERTY_XSAVE_STATES                      = 0x00060007,
  	HV_PARTITION_PROPERTY_MAX_XSAVE_DATA_SIZE		= 0x00060008,
  	HV_PARTITION_PROPERTY_PROCESSOR_CLOCK_FREQUENCY		= 0x00060009,
+
+	/* Extended properties with larger property values */
+	HV_PARTITION_PROPERTY_VMM_CAPABILITIES			= 0x00090007,
  };
 
+#define HV_PARTITION_VMM_CAPABILITIES_BANK_COUNT		1
+#define HV_PARTITION_VMM_CAPABILITIES_RESERVED_BITFIELD_COUNT	59
+
+struct hv_partition_property_vmm_capabilities {
+	u16 bank_count;
+	u16 reserved[3];
+	union {
+		u64 as_uint64[HV_PARTITION_VMM_CAPABILITIES_BANK_COUNT];
+		struct {
+			u64 map_gpa_preserve_adjustable: 1;
+			u64 vmm_can_provide_overlay_gpfn: 1;
+			u64 vp_affinity_property: 1;
+#if IS_ENABLED(CONFIG_ARM64)
+			u64 vmm_can_provide_gic_overlay_locations: 1;
+#else
+			u64 reservedbit3: 1;

include/hyperv/hvhdk_mini.h enum hv_partition_property_code { · line 129

Quoted 10 lines
include/hyperv/hvhdk_mini.h +7 -0
+#endif
+			u64 assignable_synthetic_proc_features: 1;
+			u64 reserved0: HV_PARTITION_VMM_CAPABILITIES_RESERVED_BITFIELD_COUNT;
+		} __packed;
+	};
+} __packed;
+
  enum hv_snp_status {
  	HV_SNP_STATUS_NONE = 0,
  	HV_SNP_STATUS_AVAILABLE = 1,
#20 lore raw

Re: [PATCH 3/6] mshv: Add the HVCALL_GET_PARTITION_PROPERTY_EX hypercall

In reply to Nuno Das Neves
Quoted 36 lines · Nuno Das Neves

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

This hypercall can be used to fetch extended properties of a partition. Extended properties are properties with values larger than a u64. Some of these also need additional input arguments.

Add helper function for using the hypercall in the mshv_root driver.

---
 drivers/hv/mshv_root.h         |  2 ++
 drivers/hv/mshv_root_hv_call.c | 31 ++++++++++++++++++++++++++
 include/hyperv/hvgdk_mini.h    |  1 +
 include/hyperv/hvhdk.h         | 40 ++++++++++++++++++++++++++++++++++
 include/hyperv/hvhdk_mini.h    | 26 ++++++++++++++++++++++
 5 files changed, 100 insertions(+)
drivers/hv/mshv_root.h +2 -0
index e3931b0f1269..4aeb03bea6b6 100644
@@ -303,6 +303,8 @@ int hv_call_unmap_stat_page(enum hv_stats_object_type type,
 int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
 				   u64 page_struct_count, u32 host_access,
 				   u32 flags, u8 acquire);
+int hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
+				      void *property_value, size_t property_value_sz);
 
 extern struct mshv_root mshv_root;
 extern enum hv_scheduler_type hv_scheduler_type;
drivers/hv/mshv_root_hv_call.c +0 -0
index 1c38576a673c..7589b1ff3515 100644

drivers/hv/mshv_root_hv_call.c int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type, · line 594

Quoted 5 lines
drivers/hv/mshv_root_hv_call.c +2 -0
@@ -590,6 +590,37 @@ int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
 	return hv_result_to_errno(status);
 }
 
+int
+hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,

One line like in patch 2..

<snip>

Thanks,
Easwar (he/him)

#21 lore raw

Re: [PATCH 3/6] mshv: Add the HVCALL_GET_PARTITION_PROPERTY_EX hypercall

Quoted 40 lines · Easwar Hariharan
Quoted 39 lines · Nuno Das Neves

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

This hypercall can be used to fetch extended properties of a partition. Extended properties are properties with values larger than a u64. Some of these also need additional input arguments.

Add helper function for using the hypercall in the mshv_root driver.

---
 drivers/hv/mshv_root.h         |  2 ++
 drivers/hv/mshv_root_hv_call.c | 31 ++++++++++++++++++++++++++
 include/hyperv/hvgdk_mini.h    |  1 +
 include/hyperv/hvhdk.h         | 40 ++++++++++++++++++++++++++++++++++
 include/hyperv/hvhdk_mini.h    | 26 ++++++++++++++++++++++
 5 files changed, 100 insertions(+)
drivers/hv/mshv_root.h +2 -0
index e3931b0f1269..4aeb03bea6b6 100644
@@ -303,6 +303,8 @@ int hv_call_unmap_stat_page(enum hv_stats_object_type type,
 int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
 				   u64 page_struct_count, u32 host_access,
 				   u32 flags, u8 acquire);
+int hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
+				      void *property_value, size_t property_value_sz);
 
 extern struct mshv_root mshv_root;
 extern enum hv_scheduler_type hv_scheduler_type;
drivers/hv/mshv_root_hv_call.c +0 -0
index 1c38576a673c..7589b1ff3515 100644
@@ -590,6 +590,37 @@ int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
 	return hv_result_to_errno(status);
 }
 
Quoted 4 lines

drivers/hv/mshv_root_hv_call.c int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type, · line 594

Quoted 2 lines
drivers/hv/mshv_root_hv_call.c +2 -0
+int
+hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,

One line like in patch 2..

Ack, thanks>

Quoted 4 lines

<snip>

Thanks,
Easwar (he/him)

#22 lore raw

PATCH 4/6 mshv: Get the vmm capabilities offered by the hypervisor

In reply to Nuno Das Neves

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

Some newer hypervisor APIs are gated by feature bits in the so-called "vmm capabilities" partition property. Store the capabilities on mshv_root module init, using HVCALL_GET_PARTITION_PROPERTY_EX.

---
 drivers/hv/mshv_root.h      |  1 +
 drivers/hv/mshv_root_main.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
drivers/hv/mshv_root.h +1 -0
index 4aeb03bea6b6..0cb1e2589fe1 100644
@@ -178,6 +178,7 @@ struct mshv_root {
 	struct hv_synic_pages __percpu *synic_pages;
 	spinlock_t pt_ht_lock;
 	DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS);
+	struct hv_partition_property_vmm_capabilities vmm_caps;
 };
 
 /*
drivers/hv/mshv_root_main.c +28 -0
index 56ababab57ce..29f61ecc9771 100644
@@ -2327,6 +2327,28 @@ static int __init mshv_root_partition_init(struct device *dev)
 	return err;
 }
 
+static int mshv_init_vmm_caps(struct device *dev)
+{
+	int ret;
+
+	memset(&mshv_root.vmm_caps, 0, sizeof(mshv_root.vmm_caps));
+	ret = hv_call_get_partition_property_ex(HV_PARTITION_ID_SELF,
+						HV_PARTITION_PROPERTY_VMM_CAPABILITIES,
+						0, &mshv_root.vmm_caps,
+						sizeof(mshv_root.vmm_caps));
+
+	/*
+	 * HV_PARTITION_PROPERTY_VMM_CAPABILITIES is not supported in
+	 * older hyperv. Ignore the -EIO error code.
+	 */
+	if (ret && ret != -EIO)
+		return ret;
+
+	dev_dbg(dev, "vmm_caps=0x%llx\n", mshv_root.vmm_caps.as_uint64[0]);
+
+	return 0;
+}
+
 static int __init mshv_parent_partition_init(void)
 {
 	int ret;
@@ -2377,6 +2399,12 @@ static int __init mshv_parent_partition_init(void)
 	if (ret)
 		goto remove_cpu_state;
 
+	ret = mshv_init_vmm_caps(dev);
+	if (ret) {
+		dev_err(dev, "Failed to get VMM capabilities\n");
+		goto exit_partition;
+	}
+
 	ret = mshv_irqfd_wq_init();
 	if (ret)
 		goto exit_partition;
Signature · 1 line
2.34.1
Reviewed-by on v1 4/6
#23 lore raw

Re: [PATCH 4/6] mshv: Get the vmm capabilities offered by the hypervisor

Quoted 4 lines · Nuno Das Neves

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

Some newer hypervisor APIs are gated by feature bits in the so-called "vmm capabilities" partition property. Store the capabilities on

nit: s/xx/Some hypervisor APIs are gated by feature bits exposed in
"vmm capabilities" partition property./g> mshv_root module init, using HVCALL_GET_PARTITION_PROPERTY_EX.

Quoted 56 lines
---
  drivers/hv/mshv_root.h      |  1 +
  drivers/hv/mshv_root_main.c | 28 ++++++++++++++++++++++++++++
  2 files changed, 29 insertions(+)
drivers/hv/mshv_root.h +1 -0
index 4aeb03bea6b6..0cb1e2589fe1 100644
@@ -178,6 +178,7 @@ struct mshv_root {
  	struct hv_synic_pages __percpu *synic_pages;
  	spinlock_t pt_ht_lock;
  	DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS);
+	struct hv_partition_property_vmm_capabilities vmm_caps;
  };
 
  /*
drivers/hv/mshv_root_main.c +22 -0
index 56ababab57ce..29f61ecc9771 100644
@@ -2327,6 +2327,28 @@ static int __init mshv_root_partition_init(struct device *dev)
  	return err;
  }
 
+static int mshv_init_vmm_caps(struct device *dev)
+{
+	int ret;
+
+	memset(&mshv_root.vmm_caps, 0, sizeof(mshv_root.vmm_caps));
+	ret = hv_call_get_partition_property_ex(HV_PARTITION_ID_SELF,
+						HV_PARTITION_PROPERTY_VMM_CAPABILITIES,
+						0, &mshv_root.vmm_caps,
+						sizeof(mshv_root.vmm_caps));
+
+	/*
+	 * HV_PARTITION_PROPERTY_VMM_CAPABILITIES is not supported in
+	 * older hyperv. Ignore the -EIO error code.
+	 */
+	if (ret && ret != -EIO)
+		return ret;
+
+	dev_dbg(dev, "vmm_caps=0x%llx\n", mshv_root.vmm_caps.as_uint64[0]);
+
+	return 0;
+}
+
  static int __init mshv_parent_partition_init(void)
  {
  	int ret;
@@ -2377,6 +2399,12 @@ static int __init mshv_parent_partition_init(void)
  	if (ret)
  		goto remove_cpu_state;

drivers/hv/mshv_root_main.c static int __init mshv_parent_partition_init(void) · line 2410

Quoted 10 lines
drivers/hv/mshv_root_main.c +6 -0
 
+	ret = mshv_init_vmm_caps(dev);
+	if (ret) {
+		dev_err(dev, "Failed to get VMM capabilities\n");
+		goto exit_partition;
+	}
+
  	ret = mshv_irqfd_wq_init();
  	if (ret)
  		goto exit_partition;
Signature · 2 lines
Regards,
Praveen K Paladugu
#24 lore raw

Re: [PATCH 4/6] mshv: Get the vmm capabilities offered by the hypervisor

Quoted 9 lines · Praveen K Paladugu
Quoted 4 lines · Nuno Das Neves

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

Some newer hypervisor APIs are gated by feature bits in the so-called "vmm capabilities" partition property. Store the capabilities on

nit: s/xx/Some hypervisor APIs are gated by feature bits exposed in "vmm capabilities" partition property./g

Thanks, I'll update it for v2

Nuno

Quoted 65 lines
Quoted 53 lines

mshv_root module init, using HVCALL_GET_PARTITION_PROPERTY_EX.

Quoted 1 line
Quoted 1 line

---
  drivers/hv/mshv_root.h      |  1 + drivers/hv/mshv_root_main.c | 28 ++++++++++++++++++++++++++++

  2 files changed, 29 insertions(+)
drivers/hv/mshv_root.h +1 -0
index 4aeb03bea6b6..0cb1e2589fe1 100644
@@ -178,6 +178,7 @@ struct mshv_root {
       struct hv_synic_pages __percpu *synic_pages;
       spinlock_t pt_ht_lock;
       DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS);
+    struct hv_partition_property_vmm_capabilities vmm_caps;
   };
     /*
drivers/hv/mshv_root_main.c +21 -0
index 56ababab57ce..29f61ecc9771 100644
@@ -2327,6 +2327,28 @@ static int __init mshv_root_partition_init(struct device *dev)
       return err;
   }
   +static int mshv_init_vmm_caps(struct device *dev)
+{
+    int ret;
+
+    memset(&mshv_root.vmm_caps, 0, sizeof(mshv_root.vmm_caps));
+    ret = hv_call_get_partition_property_ex(HV_PARTITION_ID_SELF,
+                        HV_PARTITION_PROPERTY_VMM_CAPABILITIES,
+                        0, &mshv_root.vmm_caps,
+                        sizeof(mshv_root.vmm_caps));
+
+    /*
+     * HV_PARTITION_PROPERTY_VMM_CAPABILITIES is not supported in
+     * older hyperv. Ignore the -EIO error code.
+     */
+    if (ret && ret != -EIO)
+        return ret;
+
+    dev_dbg(dev, "vmm_caps=0x%llx\n", mshv_root.vmm_caps.as_uint64[0]);
+
+    return 0;
+}
+
   static int __init mshv_parent_partition_init(void)
   {
       int ret;
@@ -2377,6 +2399,12 @@ static int __init mshv_parent_partition_init(void)
       if (ret)

drivers/hv/mshv_root_main.c static int __init mshv_parent_partition_init(void) · line 2409

Quoted 10 lines
drivers/hv/mshv_root_main.c +5 -0
           goto remove_cpu_state;
   +    ret = mshv_init_vmm_caps(dev);
+    if (ret) {
+        dev_err(dev, "Failed to get VMM capabilities\n");
+        goto exit_partition;
+    }
+
       ret = mshv_irqfd_wq_init();
       if (ret)
           goto exit_partition;
#25 lore raw

Re: [PATCH 4/6] mshv: Get the vmm capabilities offered by the hypervisor

In reply to Nuno Das Neves
Quoted 59 lines · Nuno Das Neves

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

Some newer hypervisor APIs are gated by feature bits in the so-called "vmm capabilities" partition property. Store the capabilities on mshv_root module init, using HVCALL_GET_PARTITION_PROPERTY_EX.

---
 drivers/hv/mshv_root.h      |  1 +
 drivers/hv/mshv_root_main.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
drivers/hv/mshv_root.h +1 -0
index 4aeb03bea6b6..0cb1e2589fe1 100644
@@ -178,6 +178,7 @@ struct mshv_root {
 	struct hv_synic_pages __percpu *synic_pages;
 	spinlock_t pt_ht_lock;
 	DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS);
+	struct hv_partition_property_vmm_capabilities vmm_caps;
 };
 
 /*
drivers/hv/mshv_root_main.c +22 -0
index 56ababab57ce..29f61ecc9771 100644
@@ -2327,6 +2327,28 @@ static int __init mshv_root_partition_init(struct device *dev)
 	return err;
 }
 
+static int mshv_init_vmm_caps(struct device *dev)
+{
+	int ret;
+
+	memset(&mshv_root.vmm_caps, 0, sizeof(mshv_root.vmm_caps));
+	ret = hv_call_get_partition_property_ex(HV_PARTITION_ID_SELF,
+						HV_PARTITION_PROPERTY_VMM_CAPABILITIES,
+						0, &mshv_root.vmm_caps,
+						sizeof(mshv_root.vmm_caps));
+
+	/*
+	 * HV_PARTITION_PROPERTY_VMM_CAPABILITIES is not supported in
+	 * older hyperv. Ignore the -EIO error code.
+	 */
+	if (ret && ret != -EIO)
+		return ret;
+
+	dev_dbg(dev, "vmm_caps=0x%llx\n", mshv_root.vmm_caps.as_uint64[0]);
+
+	return 0;
+}
+
 static int __init mshv_parent_partition_init(void)
 {
 	int ret;

drivers/hv/mshv_root_main.c static int __init mshv_parent_partition_init(void) · line 2405

Quoted 7 lines
drivers/hv/mshv_root_main.c +4 -0
@@ -2377,6 +2399,12 @@ static int __init mshv_parent_partition_init(void)
 	if (ret)
 		goto remove_cpu_state;
 
+	ret = mshv_init_vmm_caps(dev);
+	if (ret) {
+		dev_err(dev, "Failed to get VMM capabilities\n");
+		goto exit_partition;

Should this really be treated as a failure here? We could still offer /dev/mshv albeit with potentially limited capabilities.

Thanks,
Anirudh.

Quoted 8 lines
drivers/hv/mshv_root_main.c +2 -0
+	}
+
 	ret = mshv_irqfd_wq_init();
 	if (ret)
 		goto exit_partition;
Signature · 1 line
2.34.1
#26 lore raw

Re: [PATCH 4/6] mshv: Get the vmm capabilities offered by the hypervisor

Quoted 63 lines · Anirudh Rayabharam
Quoted 62 lines · Nuno Das Neves

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

Some newer hypervisor APIs are gated by feature bits in the so-called "vmm capabilities" partition property. Store the capabilities on mshv_root module init, using HVCALL_GET_PARTITION_PROPERTY_EX.

---
 drivers/hv/mshv_root.h      |  1 +
 drivers/hv/mshv_root_main.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
drivers/hv/mshv_root.h +1 -0
index 4aeb03bea6b6..0cb1e2589fe1 100644
@@ -178,6 +178,7 @@ struct mshv_root {
 	struct hv_synic_pages __percpu *synic_pages;
 	spinlock_t pt_ht_lock;
 	DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS);
+	struct hv_partition_property_vmm_capabilities vmm_caps;
 };
 
 /*
drivers/hv/mshv_root_main.c +22 -0
index 56ababab57ce..29f61ecc9771 100644
@@ -2327,6 +2327,28 @@ static int __init mshv_root_partition_init(struct device *dev)
 	return err;
 }
 
+static int mshv_init_vmm_caps(struct device *dev)
+{
+	int ret;
+
+	memset(&mshv_root.vmm_caps, 0, sizeof(mshv_root.vmm_caps));
+	ret = hv_call_get_partition_property_ex(HV_PARTITION_ID_SELF,
+						HV_PARTITION_PROPERTY_VMM_CAPABILITIES,
+						0, &mshv_root.vmm_caps,
+						sizeof(mshv_root.vmm_caps));
+
+	/*
+	 * HV_PARTITION_PROPERTY_VMM_CAPABILITIES is not supported in
+	 * older hyperv. Ignore the -EIO error code.
+	 */
+	if (ret && ret != -EIO)
+		return ret;
+
+	dev_dbg(dev, "vmm_caps=0x%llx\n", mshv_root.vmm_caps.as_uint64[0]);
+
+	return 0;
+}
+
 static int __init mshv_parent_partition_init(void)
 {
 	int ret;
@@ -2377,6 +2399,12 @@ static int __init mshv_parent_partition_init(void)
 	if (ret)
 		goto remove_cpu_state;
 
Quoted 8 lines

drivers/hv/mshv_root_main.c static int __init mshv_parent_partition_init(void) · line 2405

Quoted 4 lines
drivers/hv/mshv_root_main.c +4 -0
+	ret = mshv_init_vmm_caps(dev);
+	if (ret) {
+		dev_err(dev, "Failed to get VMM capabilities\n");
+		goto exit_partition;

Should this really be treated as a failure here? We could still offer /dev/mshv albeit with potentially limited capabilities.

I agree. It can continue with vmm_caps set to zero, and print an error.

The check for -EIO is meant to achieve something similar but it's kind of unreliable since so many HV_STATUS's map to EIO. So this idea is better, thanks.

Nuno

Quoted 11 lines

Thanks,
Anirudh.

Quoted 8 lines
drivers/hv/mshv_root_main.c +2 -0
+	}
+
 	ret = mshv_irqfd_wq_init();
 	if (ret)
 		goto exit_partition;
Signature · 1 line
2.34.1
Reviewed-by on v1 4/6
#27 lore raw

Re: [PATCH 4/6] mshv: Get the vmm capabilities offered by the hypervisor

In reply to Nuno Das Neves
Quoted 6 lines · Nuno Das Neves

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

Some newer hypervisor APIs are gated by feature bits in the so-called "vmm capabilities" partition property. Store the capabilities on mshv_root module init, using HVCALL_GET_PARTITION_PROPERTY_EX.

Quoted 6 lines
---
 drivers/hv/mshv_root.h      |  1 +
 drivers/hv/mshv_root_main.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

Looks good to me.

Reviewed-by on v1 4/6
#28 lore raw

Re: [PATCH 4/6] mshv: Get the vmm capabilities offered by the hypervisor

In reply to Nuno Das Neves
Quoted 10 lines · Nuno Das Neves

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

Some newer hypervisor APIs are gated by feature bits in the so-called "vmm capabilities" partition property. Store the capabilities on mshv_root module init, using HVCALL_GET_PARTITION_PROPERTY_EX.

---

Quoted 66 lines
 drivers/hv/mshv_root.h      |  1 +
 drivers/hv/mshv_root_main.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
drivers/hv/mshv_root.h +1 -0
index 4aeb03bea6b6..0cb1e2589fe1 100644
@@ -178,6 +178,7 @@ struct mshv_root {
        struct hv_synic_pages __percpu *synic_pages;
        spinlock_t pt_ht_lock;
        DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS);
+       struct hv_partition_property_vmm_capabilities vmm_caps;
 };
 
 /*
drivers/hv/mshv_root_main.c +28 -1
index 56ababab57ce..29f61ecc9771 100644
@@ -2327,6 +2327,28 @@ static int __init mshv_root_partition_init(struct device *dev)
        return err;
 }
 
+static int mshv_init_vmm_caps(struct device *dev)
+{
+       int ret;
+
+       memset(&mshv_root.vmm_caps, 0, sizeof(mshv_root.vmm_caps));
+       ret = hv_call_get_partition_property_ex(HV_PARTITION_ID_SELF,
+                                               HV_PARTITION_PROPERTY_VMM_CAPABILITIES,
+                                               0, &mshv_root.vmm_caps,
+                                               sizeof(mshv_root.vmm_caps));
+
+       /*
+        * HV_PARTITION_PROPERTY_VMM_CAPABILITIES is not supported in
+        * older hyperv. Ignore the -EIO error code.
+        */
+       if (ret && ret != -EIO)
+               return ret;
+
+       dev_dbg(dev, "vmm_caps=0x%llx\n", mshv_root.vmm_caps.as_uint64[0]);
+
+       return 0;
+}
+
 static int __init mshv_parent_partition_init(void)
 {
        int ret;
@@ -2377,6 +2399,12 @@ static int __init mshv_parent_partition_init(void)
        if (ret)
                goto remove_cpu_state;
 
+       ret = mshv_init_vmm_caps(dev);
+       if (ret) {
+               dev_err(dev, "Failed to get VMM capabilities\n");
+               goto exit_partition;
+       }
+
        ret = mshv_irqfd_wq_init();
        if (ret)
                goto exit_partition;
--

2.34.1

Signature · 2 lines
Thanks
Tianyu Lan
#29 lore raw

PATCH 5/6 mshv: Allocate vp state page for HVCALL_MAP_VP_STATE_PAGE on L1VH

In reply to Nuno Das Neves

From: Jinank Jain <[email protected]>

Introduce mshv_use_overlay_gpfn() to check if a page needs to be allocated and passed to the hypervisor to map VP state pages. This is only needed on L1VH, and only on some (newer) versions of the hypervisor, hence the need to check vmm_capabilities.

Introduce functions hv_map/unmap_vp_state_page() to handle the allocation and freeing.

---
 drivers/hv/mshv_root.h         | 11 +++---
 drivers/hv/mshv_root_hv_call.c | 61 +++++++++++++++++++++++++---
 drivers/hv/mshv_root_main.c    | 72 +++++++++++++++++-----------------
 3 files changed, 96 insertions(+), 48 deletions(-)
drivers/hv/mshv_root.h +6 -5
index 0cb1e2589fe1..d7c9520ef788 100644
@@ -279,11 +279,12 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
 			 /* Choose between pages and bytes */
 			 struct hv_vp_state_data state_data, u64 page_count,
 			 struct page **pages, u32 num_bytes, u8 *bytes);
-int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
-			      union hv_input_vtl input_vtl,
-			      struct page **state_page);
-int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
-				union hv_input_vtl input_vtl);
+int hv_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
+			 union hv_input_vtl input_vtl,
+			 struct page **state_page);
+int hv_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
+			   void *page_addr,
+			   union hv_input_vtl input_vtl);
 int hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
 			u64 connection_partition_id, struct hv_port_info *port_info,
 			u8 port_vtl, u8 min_connection_vtl, int node);
drivers/hv/mshv_root_hv_call.c +55 -6

85 lines not on this page · raw message

drivers/hv/mshv_root_main.c +35 -37

108 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v1 5/6
#30 lore raw

Re: [PATCH 5/6] mshv: Allocate vp state page for HVCALL_MAP_VP_STATE_PAGE on L1VH

Quoted 238 lines · Nuno Das Neves

From: Jinank Jain <[email protected]>

Introduce mshv_use_overlay_gpfn() to check if a page needs to be allocated and passed to the hypervisor to map VP state pages. This is only needed on L1VH, and only on some (newer) versions of the hypervisor, hence the need to check vmm_capabilities.

Introduce functions hv_map/unmap_vp_state_page() to handle the allocation and freeing.

---
  drivers/hv/mshv_root.h         | 11 +++---
  drivers/hv/mshv_root_hv_call.c | 61 +++++++++++++++++++++++++---
  drivers/hv/mshv_root_main.c    | 72 +++++++++++++++++-----------------
  3 files changed, 96 insertions(+), 48 deletions(-)
drivers/hv/mshv_root.h +6 -5
index 0cb1e2589fe1..d7c9520ef788 100644
@@ -279,11 +279,12 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
  			 /* Choose between pages and bytes */
  			 struct hv_vp_state_data state_data, u64 page_count,
  			 struct page **pages, u32 num_bytes, u8 *bytes);
-int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
-			      union hv_input_vtl input_vtl,
-			      struct page **state_page);
-int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
-				union hv_input_vtl input_vtl);
+int hv_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
+			 union hv_input_vtl input_vtl,
+			 struct page **state_page);
+int hv_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
+			   void *page_addr,
+			   union hv_input_vtl input_vtl);
  int hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
  			u64 connection_partition_id, struct hv_port_info *port_info,
  			u8 port_vtl, u8 min_connection_vtl, int node);
drivers/hv/mshv_root_hv_call.c +55 -6
index 7589b1ff3515..1882cc90f2f5 100644
@@ -526,9 +526,9 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
  	return ret;
  }
 
-int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
-			      union hv_input_vtl input_vtl,
-			      struct page **state_page)
+static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
+				     union hv_input_vtl input_vtl,
+				     struct page **state_page)
  {
  	struct hv_input_map_vp_state_page *input;
  	struct hv_output_map_vp_state_page *output;
@@ -547,7 +547,14 @@ int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
  		input->type = type;
  		input->input_vtl = input_vtl;
 
-		status = hv_do_hypercall(HVCALL_MAP_VP_STATE_PAGE, input, output);
+		if (*state_page) {
+			input->flags.map_location_provided = 1;
+			input->requested_map_location =
+				page_to_pfn(*state_page);
+		}
+
+		status = hv_do_hypercall(HVCALL_MAP_VP_STATE_PAGE, input,
+					 output);
 
  		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
  			if (hv_result_success(status))
@@ -565,8 +572,39 @@ int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
  	return ret;
  }
 
-int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
-				union hv_input_vtl input_vtl)
+static bool mshv_use_overlay_gpfn(void)
+{
+	return hv_l1vh_partition() &&
+	       mshv_root.vmm_caps.vmm_can_provide_overlay_gpfn;
+}
+
+int hv_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
+			 union hv_input_vtl input_vtl,
+			 struct page **state_page)
+{
+	int ret = 0;
+	struct page *allocated_page = NULL;
+
+	if (mshv_use_overlay_gpfn()) {
+		allocated_page = alloc_page(GFP_KERNEL);
+		if (!allocated_page)
+			return -ENOMEM;
+		*state_page = allocated_page;
+	} else {
+		*state_page = NULL;
+	}
+
+	ret = hv_call_map_vp_state_page(partition_id, vp_index, type, input_vtl,
+					state_page);
+
+	if (ret && allocated_page)
+		__free_page(allocated_page);
+
+	return ret;
+}
+
+static int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
+				       union hv_input_vtl input_vtl)
  {
  	unsigned long flags;
  	u64 status;
@@ -590,6 +628,17 @@ int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
  	return hv_result_to_errno(status);
  }
 
+int hv_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
+			   void *page_addr, union hv_input_vtl input_vtl)
+{
+	int ret = hv_call_unmap_vp_state_page(partition_id, vp_index, type, input_vtl);
+
+	if (mshv_use_overlay_gpfn() && page_addr)
+		__free_page(virt_to_page(page_addr));
+
+	return ret;
+}
+
  int
  hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
  				  void *property_value, size_t property_value_sz)
drivers/hv/mshv_root_main.c +30 -35
index 29f61ecc9771..f91880cc9e29 100644
@@ -964,28 +964,25 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
  	if (ret)
  		return ret;
 
-	ret = hv_call_map_vp_state_page(partition->pt_id, args.vp_index,
-					HV_VP_STATE_PAGE_INTERCEPT_MESSAGE,
-					input_vtl_zero,
-					&intercept_message_page);
+	ret = hv_map_vp_state_page(partition->pt_id, args.vp_index,
+				   HV_VP_STATE_PAGE_INTERCEPT_MESSAGE,
+				   input_vtl_zero, &intercept_message_page);
  	if (ret)
  		goto destroy_vp;
 
  	if (!mshv_partition_encrypted(partition)) {
-		ret = hv_call_map_vp_state_page(partition->pt_id, args.vp_index,
-						HV_VP_STATE_PAGE_REGISTERS,
-						input_vtl_zero,
-						&register_page);
+		ret = hv_map_vp_state_page(partition->pt_id, args.vp_index,
+					   HV_VP_STATE_PAGE_REGISTERS,
+					   input_vtl_zero, &register_page);
  		if (ret)
  			goto unmap_intercept_message_page;
  	}
 
  	if (mshv_partition_encrypted(partition) &&
  	    is_ghcb_mapping_available()) {
-		ret = hv_call_map_vp_state_page(partition->pt_id, args.vp_index,
-						HV_VP_STATE_PAGE_GHCB,
-						input_vtl_normal,
-						&ghcb_page);
+		ret = hv_map_vp_state_page(partition->pt_id, args.vp_index,
+					   HV_VP_STATE_PAGE_GHCB,
+					   input_vtl_normal, &ghcb_page);
  		if (ret)
  			goto unmap_register_page;
  	}
@@ -1049,21 +1046,19 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
  	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
  		mshv_vp_stats_unmap(partition->pt_id, args.vp_index);
  unmap_ghcb_page:
-	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available()) {
-		hv_call_unmap_vp_state_page(partition->pt_id, args.vp_index,
-					    HV_VP_STATE_PAGE_GHCB,
-					    input_vtl_normal);
-	}
+	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available())
+		hv_unmap_vp_state_page(partition->pt_id, args.vp_index,
+				       HV_VP_STATE_PAGE_GHCB, vp->vp_ghcb_page,
+				       input_vtl_normal);
  unmap_register_page:
-	if (!mshv_partition_encrypted(partition)) {
-		hv_call_unmap_vp_state_page(partition->pt_id, args.vp_index,
-					    HV_VP_STATE_PAGE_REGISTERS,
-					    input_vtl_zero);
-	}
+	if (!mshv_partition_encrypted(partition))
+		hv_unmap_vp_state_page(partition->pt_id, args.vp_index,
+				       HV_VP_STATE_PAGE_REGISTERS,
+				       vp->vp_register_page, input_vtl_zero);
  unmap_intercept_message_page:
-	hv_call_unmap_vp_state_page(partition->pt_id, args.vp_index,
-				    HV_VP_STATE_PAGE_INTERCEPT_MESSAGE,
-				    input_vtl_zero);
+	hv_unmap_vp_state_page(partition->pt_id, args.vp_index,
+			       HV_VP_STATE_PAGE_INTERCEPT_MESSAGE,
+			       vp->vp_intercept_msg_page, input_vtl_zero);
  destroy_vp:
  	hv_call_delete_vp(partition->pt_id, args.vp_index);
  	return ret;
@@ -1804,24 +1799,27 @@ static void destroy_partition(struct mshv_partition *partition)
  				mshv_vp_stats_unmap(partition->pt_id, vp->vp_index);
 
  			if (vp->vp_register_page) {
-				(void)hv_call_unmap_vp_state_page(partition->pt_id,
-								  vp->vp_index,
-								  HV_VP_STATE_PAGE_REGISTERS,
-								  input_vtl_zero);
+				(void)hv_unmap_vp_state_page(partition->pt_id,
+							     vp->vp_index,
+							     HV_VP_STATE_PAGE_REGISTERS,
+							     vp->vp_register_page,
+							     input_vtl_zero);
  				vp->vp_register_page = NULL;
  			}
 
-			(void)hv_call_unmap_vp_state_page(partition->pt_id,
-							  vp->vp_index,
-							  HV_VP_STATE_PAGE_INTERCEPT_MESSAGE,
-							  input_vtl_zero);
+			(void)hv_unmap_vp_state_page(partition->pt_id,
+						     vp->vp_index,
+						     HV_VP_STATE_PAGE_INTERCEPT_MESSAGE,
+						     vp->vp_intercept_msg_page,
+						     input_vtl_zero);
  			vp->vp_intercept_msg_page = NULL;
 
  			if (vp->vp_ghcb_page) {
-				(void)hv_call_unmap_vp_state_page(partition->pt_id,
-								  vp->vp_index,

drivers/hv/mshv_root_main.c static void destroy_partition(struct mshv_partition *partition) · line 1825

Quoted 10 lines
drivers/hv/mshv_root_main.c +5 -2
-								  HV_VP_STATE_PAGE_GHCB,
-								  input_vtl_normal);
+				(void)hv_unmap_vp_state_page(partition->pt_id,
+							     vp->vp_index,
+							     HV_VP_STATE_PAGE_GHCB,
+							     vp->vp_ghcb_page,
+							     input_vtl_normal);
  				vp->vp_ghcb_page = NULL;
  			}
 
Reviewed-by on v1 5/6
#31 lore raw

Re: [PATCH 5/6] mshv: Allocate vp state page for HVCALL_MAP_VP_STATE_PAGE on L1VH

In reply to Nuno Das Neves
Quoted 17 lines · Nuno Das Neves

From: Jinank Jain <[email protected]>

Introduce mshv_use_overlay_gpfn() to check if a page needs to be allocated and passed to the hypervisor to map VP state pages. This is only needed on L1VH, and only on some (newer) versions of the hypervisor, hence the need to check vmm_capabilities.

Introduce functions hv_map/unmap_vp_state_page() to handle the allocation and freeing.

---
 drivers/hv/mshv_root.h         | 11 +++---
 drivers/hv/mshv_root_hv_call.c | 61 +++++++++++++++++++++++++---
 drivers/hv/mshv_root_main.c    | 72 +++++++++++++++++-----------------
 3 files changed, 96 insertions(+), 48 deletions(-)

<snip>

#32 lore raw

PATCH 6/6 mshv: Introduce new hypercall to map stats page for L1VH partitions

In reply to Nuno Das Neves

From: Jinank Jain <[email protected]>

Introduce HVCALL_MAP_STATS_PAGE2 which provides a map location (GPFN) to map the stats to. This hypercall is required for L1VH partitions, depending on the hypervisor version. This uses the same check as the state page map location; mshv_use_overlay_gpfn().

Add mshv_map_vp_state_page() helpers to use this new hypercall or the old one depending on availability.

For unmapping, the original HVCALL_UNMAP_STATS_PAGE works for both cases.

---
 drivers/hv/mshv_root.h         | 10 ++--
 drivers/hv/mshv_root_hv_call.c | 92 ++++++++++++++++++++++++++++++++--
 drivers/hv/mshv_root_main.c    | 25 +++++----
 include/hyperv/hvgdk_mini.h    |  1 +
 include/hyperv/hvhdk_mini.h    |  7 +++
 5 files changed, 115 insertions(+), 20 deletions(-)
drivers/hv/mshv_root.h +5 -5
index d7c9520ef788..d16a020ae0ee 100644
@@ -297,11 +297,11 @@ int hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
 int hv_call_disconnect_port(u64 connection_partition_id,
 			    union hv_connection_id connection_id);
 int hv_call_notify_port_ring_empty(u32 sint_index);
-int hv_call_map_stat_page(enum hv_stats_object_type type,
-			  const union hv_stats_object_identity *identity,
-			  void **addr);
-int hv_call_unmap_stat_page(enum hv_stats_object_type type,
-			    const union hv_stats_object_identity *identity);
+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,
+			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,
 				   u32 flags, u8 acquire);
drivers/hv/mshv_root_hv_call.c +87 -5

116 lines not on this page · raw message

drivers/hv/mshv_root_main.c +15 -10
index f91880cc9e29..1699423cc524 100644
@@ -894,7 +894,8 @@ mshv_vp_release(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index)
+static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index,
+				void *stats_pages[])
 {
 	union hv_stats_object_identity identity = {
 		.vp.partition_id = partition_id,
@@ -902,10 +903,13 @@ static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index)
 	};
 
 	identity.vp.stats_area_type = HV_STATS_AREA_SELF;
-	hv_call_unmap_stat_page(HV_STATS_OBJECT_VP, &identity);
+	hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity);
+
+	if (stats_pages[HV_STATS_AREA_PARENT] == stats_pages[HV_STATS_AREA_SELF])
+		return;
 
 	identity.vp.stats_area_type = HV_STATS_AREA_PARENT;
-	hv_call_unmap_stat_page(HV_STATS_OBJECT_VP, &identity);
+	hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity);
 }
 
 static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
@@ -918,14 +922,14 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
 	int err;
 
 	identity.vp.stats_area_type = HV_STATS_AREA_SELF;
-	err = hv_call_map_stat_page(HV_STATS_OBJECT_VP, &identity,
-				    &stats_pages[HV_STATS_AREA_SELF]);
+	err = hv_map_stats_page(HV_STATS_OBJECT_VP, &identity,
+				&stats_pages[HV_STATS_AREA_SELF]);
 	if (err)
 		return err;
 
 	identity.vp.stats_area_type = HV_STATS_AREA_PARENT;
-	err = hv_call_map_stat_page(HV_STATS_OBJECT_VP, &identity,
-				    &stats_pages[HV_STATS_AREA_PARENT]);
+	err = hv_map_stats_page(HV_STATS_OBJECT_VP, &identity,
+				&stats_pages[HV_STATS_AREA_PARENT]);
 	if (err)
 		goto unmap_self;
 
@@ -936,7 +940,7 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
 
 unmap_self:
 	identity.vp.stats_area_type = HV_STATS_AREA_SELF;
-	hv_call_unmap_stat_page(HV_STATS_OBJECT_VP, &identity);
+	hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity);
 	return err;
 }
 
@@ -1044,7 +1048,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 	kfree(vp);
 unmap_stats_pages:
 	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
-		mshv_vp_stats_unmap(partition->pt_id, args.vp_index);
+		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,
@@ -1796,7 +1800,8 @@ static void destroy_partition(struct mshv_partition *partition)
 				continue;
 
 			if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
-				mshv_vp_stats_unmap(partition->pt_id, vp->vp_index);
+				mshv_vp_stats_unmap(partition->pt_id, vp->vp_index,
+						    (void **)vp->vp_stats_pages);
 
 			if (vp->vp_register_page) {
 				(void)hv_unmap_vp_state_page(partition->pt_id,
include/hyperv/hvgdk_mini.h +1 -0
index 1bde0aa102ec..27652785e3f2 100644
@@ -493,6 +493,7 @@ union hv_vp_assist_msr_contents {	 /* HV_REGISTER_VP_ASSIST_PAGE */
 #define HVCALL_GET_PARTITION_PROPERTY_EX		0x0101
 #define HVCALL_MMIO_READ				0x0106
 #define HVCALL_MMIO_WRITE				0x0107
+#define HVCALL_MAP_STATS_PAGE2				0x0131
 
 /* HV_HYPERCALL_INPUT */
 #define HV_HYPERCALL_RESULT_MASK	GENMASK_ULL(15, 0)
include/hyperv/hvhdk_mini.h +7 -0
index bf2ce27dfcc5..064bf735cab6 100644
@@ -177,6 +177,13 @@ struct hv_input_map_stats_page {
 	union hv_stats_object_identity identity;
 } __packed;
 
+struct hv_input_map_stats_page2 {
+	u32 type; /* enum hv_stats_object_type */
+	u32 padding;
+	union hv_stats_object_identity identity;
+	u64 map_location;
+} __packed;
+
 struct hv_output_map_stats_page {
 	u64 map_location;
 } __packed;
Signature · 1 line
2.34.1
#33 lore raw

Re: [PATCH 6/6] mshv: Introduce new hypercall to map stats page for L1VH partitions

Quoted 49 lines · Nuno Das Neves

From: Jinank Jain <[email protected]>

Introduce HVCALL_MAP_STATS_PAGE2 which provides a map location (GPFN) to map the stats to. This hypercall is required for L1VH partitions, depending on the hypervisor version. This uses the same check as the state page map location; mshv_use_overlay_gpfn().

Add mshv_map_vp_state_page() helpers to use this new hypercall or the old one depending on availability.

For unmapping, the original HVCALL_UNMAP_STATS_PAGE works for both cases.

---
 drivers/hv/mshv_root.h         | 10 ++--
 drivers/hv/mshv_root_hv_call.c | 92 ++++++++++++++++++++++++++++++++--
 drivers/hv/mshv_root_main.c    | 25 +++++----
 include/hyperv/hvgdk_mini.h    |  1 +
 include/hyperv/hvhdk_mini.h    |  7 +++
 5 files changed, 115 insertions(+), 20 deletions(-)
drivers/hv/mshv_root.h +5 -5
index d7c9520ef788..d16a020ae0ee 100644
@@ -297,11 +297,11 @@ int hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
 int hv_call_disconnect_port(u64 connection_partition_id,
 			    union hv_connection_id connection_id);
 int hv_call_notify_port_ring_empty(u32 sint_index);
-int hv_call_map_stat_page(enum hv_stats_object_type type,
-			  const union hv_stats_object_identity *identity,
-			  void **addr);
-int hv_call_unmap_stat_page(enum hv_stats_object_type type,
-			    const union hv_stats_object_identity *identity);
+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,
+			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,
 				   u32 flags, u8 acquire);
drivers/hv/mshv_root_hv_call.c +0 -0
index 1882cc90f2f5..44013751cfc1 100644

drivers/hv/mshv_root_hv_call.c hv_call_notify_port_ring_empty(u32 sint_index) · line 808

Quoted 5 lines
drivers/hv/mshv_root_hv_call.c +2 -0
@@ -804,6 +804,45 @@ hv_call_notify_port_ring_empty(u32 sint_index)
 	return hv_result_to_errno(status);
 }
 
+static int
+hv_call_map_stats_page2(enum hv_stats_object_type type,

Again, one line please. Also below.

Quoted 51 lines
drivers/hv/mshv_root_hv_call.c +41 -3
+			const union hv_stats_object_identity *identity,
+			u64 map_location)
+{
+	unsigned long flags;
+	struct hv_input_map_stats_page2 *input;
+	u64 status;
+	int ret;
+
+	if (!map_location || !mshv_use_overlay_gpfn())
+		return -EINVAL;
+
+	do {
+		local_irq_save(flags);
+		input = *this_cpu_ptr(hyperv_pcpu_input_arg);
+
+		memset(input, 0, sizeof(*input));
+		input->type = type;
+		input->identity = *identity;
+		input->map_location = map_location;
+
+		status = hv_do_hypercall(HVCALL_MAP_STATS_PAGE2, input, NULL);
+
+		local_irq_restore(flags);
+		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+			if (hv_result_success(status))
+				break;
+			hv_status_debug(status, "\n");
+			return hv_result_to_errno(status);
+		}
+
+		ret = hv_call_deposit_pages(NUMA_NO_NODE,
+					    hv_current_partition_id, 1);
+	} while (!ret);
+
+	return ret;
+}
+
 static int
 hv_stats_get_area_type(enum hv_stats_object_type type,
 		       const union hv_stats_object_identity *identity)
@@ -822,9 +861,10 @@ hv_stats_get_area_type(enum hv_stats_object_type type,
 	return -EINVAL;
 }
 
-int hv_call_map_stat_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,
+		       void **addr)

...

Quoted 39 lines

{

drivers/hv/mshv_root_hv_call.c +30 -2
 	unsigned long flags;
 	struct hv_input_map_stats_page *input;
@@ -880,8 +920,37 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
 	return ret;
 }
 
-int hv_call_unmap_stat_page(enum hv_stats_object_type type,
-			    const union hv_stats_object_identity *identity)
+int hv_map_stats_page(enum hv_stats_object_type type,
+		      const union hv_stats_object_identity *identity,
+		      void **addr)
+{
+	int ret;
+	struct page *allocated_page = NULL;
+
+	if (!addr)
+		return -EINVAL;
+
+	if (mshv_use_overlay_gpfn()) {
+		allocated_page = alloc_page(GFP_KERNEL);
+		if (!allocated_page)
+			return -ENOMEM;
+
+		ret = hv_call_map_stats_page2(type, identity,
+					      page_to_pfn(allocated_page));
+		*addr = page_address(allocated_page);
+	} else {
+		ret = hv_call_map_stats_page(type, identity, addr);
+	}
+
+	if (ret && allocated_page)
+		__free_page(allocated_page);
+
+	return ret;
+}
+
+static int
+hv_call_unmap_stats_page(enum hv_stats_object_type type,

...

Quoted 55 lines
drivers/hv/mshv_root_hv_call.c +14 -0
+			 const union hv_stats_object_identity *identity)
 {
 	unsigned long flags;
 	struct hv_input_unmap_stats_page *input;
@@ -900,6 +969,19 @@ int hv_call_unmap_stat_page(enum hv_stats_object_type type,
 	return hv_result_to_errno(status);
 }
 
+int hv_unmap_stats_page(enum hv_stats_object_type type, void *page_addr,
+			const union hv_stats_object_identity *identity)
+{
+	int ret;
+
+	ret = hv_call_unmap_stats_page(type, identity);
+
+	if (mshv_use_overlay_gpfn() && page_addr)
+		__free_page(virt_to_page(page_addr));
+
+	return ret;
+}
+
 int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
 				   u64 page_struct_count, u32 host_access,
 				   u32 flags, u8 acquire)
drivers/hv/mshv_root_main.c +7 -3
index f91880cc9e29..1699423cc524 100644
@@ -894,7 +894,8 @@ mshv_vp_release(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index)
+static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index,
+				void *stats_pages[])
 {
 	union hv_stats_object_identity identity = {
 		.vp.partition_id = partition_id,
@@ -902,10 +903,13 @@ static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index)
 	};
 
 	identity.vp.stats_area_type = HV_STATS_AREA_SELF;
-	hv_call_unmap_stat_page(HV_STATS_OBJECT_VP, &identity);
+	hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity);
+
+	if (stats_pages[HV_STATS_AREA_PARENT] == stats_pages[HV_STATS_AREA_SELF])
+		return;
 
 	identity.vp.stats_area_type = HV_STATS_AREA_PARENT;
-	hv_call_unmap_stat_page(HV_STATS_OBJECT_VP, &identity);
+	hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity);
 }
 
 static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,

drivers/hv/mshv_root_main.c static int mshv_vp_stats_map(u64 partition_id, u32 vp_index, · line 926

Quoted 7 lines
drivers/hv/mshv_root_main.c +2 -2
@@ -918,14 +922,14 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
 	int err;
 
 	identity.vp.stats_area_type = HV_STATS_AREA_SELF;
-	err = hv_call_map_stat_page(HV_STATS_OBJECT_VP, &identity,
-				    &stats_pages[HV_STATS_AREA_SELF]);
+	err = hv_map_stats_page(HV_STATS_OBJECT_VP, &identity,
+				&stats_pages[HV_STATS_AREA_SELF]);

Shouldn't this be in the previous patch where the other hv_call_map_stat_page() calls were converted, same below?

Quoted 8 lines
drivers/hv/mshv_root_main.c +2 -2
 	if (err)
 		return err;
 
 	identity.vp.stats_area_type = HV_STATS_AREA_PARENT;
-	err = hv_call_map_stat_page(HV_STATS_OBJECT_VP, &identity,
-				    &stats_pages[HV_STATS_AREA_PARENT]);
+	err = hv_map_stats_page(HV_STATS_OBJECT_VP, &identity,
+				&stats_pages[HV_STATS_AREA_PARENT]);

...

Quoted 12 lines
drivers/hv/mshv_root_main.c +1 -1
 	if (err)
 		goto unmap_self;
@@ -936,7 +940,7 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
 
 unmap_self:
 	identity.vp.stats_area_type = HV_STATS_AREA_SELF;
-	hv_call_unmap_stat_page(HV_STATS_OBJECT_VP, &identity);
+	hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity);
 	return err;
 }
 

<snip>

#34 lore raw

Re: [PATCH 6/6] mshv: Introduce new hypercall to map stats page for L1VH partitions

Quoted 53 lines · Easwar Hariharan
Quoted 52 lines · Nuno Das Neves

From: Jinank Jain <[email protected]>

Introduce HVCALL_MAP_STATS_PAGE2 which provides a map location (GPFN) to map the stats to. This hypercall is required for L1VH partitions, depending on the hypervisor version. This uses the same check as the state page map location; mshv_use_overlay_gpfn().

Add mshv_map_vp_state_page() helpers to use this new hypercall or the old one depending on availability.

For unmapping, the original HVCALL_UNMAP_STATS_PAGE works for both cases.

---
 drivers/hv/mshv_root.h         | 10 ++--
 drivers/hv/mshv_root_hv_call.c | 92 ++++++++++++++++++++++++++++++++--
 drivers/hv/mshv_root_main.c    | 25 +++++----
 include/hyperv/hvgdk_mini.h    |  1 +
 include/hyperv/hvhdk_mini.h    |  7 +++
 5 files changed, 115 insertions(+), 20 deletions(-)
drivers/hv/mshv_root.h +5 -5
index d7c9520ef788..d16a020ae0ee 100644
@@ -297,11 +297,11 @@ int hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
 int hv_call_disconnect_port(u64 connection_partition_id,
 			    union hv_connection_id connection_id);
 int hv_call_notify_port_ring_empty(u32 sint_index);
-int hv_call_map_stat_page(enum hv_stats_object_type type,
-			  const union hv_stats_object_identity *identity,
-			  void **addr);
-int hv_call_unmap_stat_page(enum hv_stats_object_type type,
-			    const union hv_stats_object_identity *identity);
+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,
+			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,
 				   u32 flags, u8 acquire);
drivers/hv/mshv_root_hv_call.c +0 -0
index 1882cc90f2f5..44013751cfc1 100644
@@ -804,6 +804,45 @@ hv_call_notify_port_ring_empty(u32 sint_index)
 	return hv_result_to_errno(status);
 }
 
Quoted 5 lines

drivers/hv/mshv_root_hv_call.c hv_call_notify_port_ring_empty(u32 sint_index) · line 808

Quoted 2 lines
drivers/hv/mshv_root_hv_call.c +2 -0
+static int
+hv_call_map_stats_page2(enum hv_stats_object_type type,

Again, one line please. Also below.

Ack

Quoted 44 lines
Quoted 44 lines
drivers/hv/mshv_root_hv_call.c +37 -0
+			const union hv_stats_object_identity *identity,
+			u64 map_location)
+{
+	unsigned long flags;
+	struct hv_input_map_stats_page2 *input;
+	u64 status;
+	int ret;
+
+	if (!map_location || !mshv_use_overlay_gpfn())
+		return -EINVAL;
+
+	do {
+		local_irq_save(flags);
+		input = *this_cpu_ptr(hyperv_pcpu_input_arg);
+
+		memset(input, 0, sizeof(*input));
+		input->type = type;
+		input->identity = *identity;
+		input->map_location = map_location;
+
+		status = hv_do_hypercall(HVCALL_MAP_STATS_PAGE2, input, NULL);
+
+		local_irq_restore(flags);
+		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+			if (hv_result_success(status))
+				break;
+			hv_status_debug(status, "\n");
+			return hv_result_to_errno(status);
+		}
+
+		ret = hv_call_deposit_pages(NUMA_NO_NODE,
+					    hv_current_partition_id, 1);
+	} while (!ret);
+
+	return ret;
+}
+
 static int
 hv_stats_get_area_type(enum hv_stats_object_type type,
 		       const union hv_stats_object_identity *identity)
@@ -822,9 +861,10 @@ hv_stats_get_area_type(enum hv_stats_object_type type,
 	return -EINVAL;
 }
 
Quoted 10 lines
Quoted 7 lines
drivers/hv/mshv_root_hv_call.c +4 -3
-int hv_call_map_stat_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,
+		       void **addr)

...

ack

Quoted 33 lines
Quoted 33 lines

{

drivers/hv/mshv_root_hv_call.c +24 -2
 	unsigned long flags;
 	struct hv_input_map_stats_page *input;
@@ -880,8 +920,37 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
 	return ret;
 }
 
-int hv_call_unmap_stat_page(enum hv_stats_object_type type,
-			    const union hv_stats_object_identity *identity)
+int hv_map_stats_page(enum hv_stats_object_type type,
+		      const union hv_stats_object_identity *identity,
+		      void **addr)
+{
+	int ret;
+	struct page *allocated_page = NULL;
+
+	if (!addr)
+		return -EINVAL;
+
+	if (mshv_use_overlay_gpfn()) {
+		allocated_page = alloc_page(GFP_KERNEL);
+		if (!allocated_page)
+			return -ENOMEM;
+
+		ret = hv_call_map_stats_page2(type, identity,
+					      page_to_pfn(allocated_page));
+		*addr = page_address(allocated_page);
+	} else {
+		ret = hv_call_map_stats_page(type, identity, addr);
+	}
+
+	if (ret && allocated_page)
+		__free_page(allocated_page);
Quoted 9 lines
Quoted 6 lines
drivers/hv/mshv_root_hv_call.c +6 -0
+
+	return ret;
+}
+
+static int
+hv_call_unmap_stats_page(enum hv_stats_object_type type,

...

ack

Quoted 57 lines
Quoted 57 lines
drivers/hv/mshv_root_hv_call.c +14 -0
+			 const union hv_stats_object_identity *identity)
 {
 	unsigned long flags;
 	struct hv_input_unmap_stats_page *input;
@@ -900,6 +969,19 @@ int hv_call_unmap_stat_page(enum hv_stats_object_type type,
 	return hv_result_to_errno(status);
 }
 
+int hv_unmap_stats_page(enum hv_stats_object_type type, void *page_addr,
+			const union hv_stats_object_identity *identity)
+{
+	int ret;
+
+	ret = hv_call_unmap_stats_page(type, identity);
+
+	if (mshv_use_overlay_gpfn() && page_addr)
+		__free_page(virt_to_page(page_addr));
+
+	return ret;
+}
+
 int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
 				   u64 page_struct_count, u32 host_access,
 				   u32 flags, u8 acquire)
drivers/hv/mshv_root_main.c +7 -3
index f91880cc9e29..1699423cc524 100644
@@ -894,7 +894,8 @@ mshv_vp_release(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index)
+static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index,
+				void *stats_pages[])
 {
 	union hv_stats_object_identity identity = {
 		.vp.partition_id = partition_id,
@@ -902,10 +903,13 @@ static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index)
 	};
 
 	identity.vp.stats_area_type = HV_STATS_AREA_SELF;
-	hv_call_unmap_stat_page(HV_STATS_OBJECT_VP, &identity);
+	hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity);
+
+	if (stats_pages[HV_STATS_AREA_PARENT] == stats_pages[HV_STATS_AREA_SELF])
+		return;
 
 	identity.vp.stats_area_type = HV_STATS_AREA_PARENT;
-	hv_call_unmap_stat_page(HV_STATS_OBJECT_VP, &identity);
+	hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity);
 }
 
 static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
@@ -918,14 +922,14 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
 	int err;
 
Quoted 9 lines

drivers/hv/mshv_root_main.c static int mshv_vp_stats_map(u64 partition_id, u32 vp_index, · line 926

Quoted 5 lines
drivers/hv/mshv_root_main.c +2 -2
 	identity.vp.stats_area_type = HV_STATS_AREA_SELF;
-	err = hv_call_map_stat_page(HV_STATS_OBJECT_VP, &identity,
-				    &stats_pages[HV_STATS_AREA_SELF]);
+	err = hv_map_stats_page(HV_STATS_OBJECT_VP, &identity,
+				&stats_pages[HV_STATS_AREA_SELF]);

Shouldn't this be in the previous patch where the other hv_call_map_stat_page() calls were converted, same below?

The previous patch converts hv_call_(un)map_vp_state_page to hv_(un)map_vp_state_page, i.e. "state" not "stats".

Quoted 25 lines
Quoted 8 lines
drivers/hv/mshv_root_main.c +2 -2
 	if (err)
 		return err;
 
 	identity.vp.stats_area_type = HV_STATS_AREA_PARENT;
-	err = hv_call_map_stat_page(HV_STATS_OBJECT_VP, &identity,
-				    &stats_pages[HV_STATS_AREA_PARENT]);
+	err = hv_map_stats_page(HV_STATS_OBJECT_VP, &identity,
+				&stats_pages[HV_STATS_AREA_PARENT]);

...

Quoted 12 lines
drivers/hv/mshv_root_main.c +1 -1
 	if (err)
 		goto unmap_self;
@@ -936,7 +940,7 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
 
 unmap_self:
 	identity.vp.stats_area_type = HV_STATS_AREA_SELF;
-	hv_call_unmap_stat_page(HV_STATS_OBJECT_VP, &identity);
+	hv_unmap_stats_page(HV_STATS_OBJECT_VP, NULL, &identity);
 	return err;
 }
 

<snip>

#35 lore raw

Re: [PATCH 6/6] mshv: Introduce new hypercall to map stats page for L1VH partitions

Quoted 25 lines · Nuno Das Neves
Quoted 24 lines · Easwar Hariharan
Quoted 23 lines · Nuno Das Neves

From: Jinank Jain <[email protected]>

Introduce HVCALL_MAP_STATS_PAGE2 which provides a map location (GPFN) to map the stats to. This hypercall is required for L1VH partitions, depending on the hypervisor version. This uses the same check as the state page map location; mshv_use_overlay_gpfn().

Add mshv_map_vp_state_page() helpers to use this new hypercall or the old one depending on availability.

For unmapping, the original HVCALL_UNMAP_STATS_PAGE works for both cases.

---
 drivers/hv/mshv_root.h         | 10 ++--
 drivers/hv/mshv_root_hv_call.c | 92 ++++++++++++++++++++++++++++++++--
 drivers/hv/mshv_root_main.c    | 25 +++++----
 include/hyperv/hvgdk_mini.h    |  1 +
 include/hyperv/hvhdk_mini.h    |  7 +++
 5 files changed, 115 insertions(+), 20 deletions(-)

<snip>

Quoted 7 lines
Quoted 4 lines

Shouldn't this be in the previous patch where the other hv_call_map_stat_page() calls were converted, same below?

The previous patch converts hv_call_(un)map_vp_state_page to hv_(un)map_vp_state_page, i.e. "state" not "stats".

Ugh, thanks for the catch. I guess my eyes glazed over a little bit with the diffs.

Thanks,
Easwar (he/him)