Skip to contentSkip to conversation

fixup! Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs

PATCH In review Nuno Das Neves 2 participants 2 messages Mar 20, 2025

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

PATCH 1/1 fixup! Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs

---
 drivers/hv/mshv_root.h         |  3 ++
 drivers/hv/mshv_root_hv_call.c |  7 +--
 drivers/hv/mshv_root_main.c    | 91 +++++++++++++---------------------
 drivers/hv/mshv_synic.c        |  2 +-
 include/uapi/linux/mshv.h      | 32 ++++++------
 5 files changed, 60 insertions(+), 75 deletions(-)
drivers/hv/mshv_root.h +3 -0
index e83b484b8ed8..e3931b0f1269 100644
@@ -14,6 +14,7 @@
 #include <linux/wait.h>
 #include <linux/hashtable.h>
 #include <linux/dev_printk.h>
+#include <linux/build_bug.h>
 #include <uapi/linux/mshv.h>
 
 /*
@@ -23,6 +24,8 @@
 #define MSHV_HV_MIN_VERSION		(27744)
 #define MSHV_HV_MAX_VERSION		(27751)
 
+static_assert(HV_HYP_PAGE_SIZE == MSHV_HV_PAGE_SIZE);
+
 #define MSHV_MAX_VPS			256
 
 #define MSHV_PARTITIONS_HASH_BITS	9
drivers/hv/mshv_root_hv_call.c +4 -3
index b72b59a5068b..a222a16107f6 100644
@@ -341,7 +341,7 @@ int hv_call_get_gpa_access_states(u64 partition_id, u32 count, u64 gpa_base_pfn,
 	int completed = 0;
 	unsigned long remaining = count;
 	int rep_count, i;
-	u64 status;
+	u64 status = 0;
 	unsigned long flags;
 
 	*written_total = 0;
@@ -731,7 +731,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;
+	int ret = 0;
 
 	do {
 		local_irq_save(flags);
@@ -747,9 +747,10 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
 
 		local_irq_restore(flags);
 		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+			ret = hv_result_to_errno(status);
 			if (hv_result_success(status))
 				break;
-			return hv_result_to_errno(status);
+			return ret;
 		}
 
 		ret = hv_call_deposit_pages(NUMA_NO_NODE,
drivers/hv/mshv_root_main.c +34 -57

250 lines not on this page · raw message

drivers/hv/mshv_synic.c +1 -1
index a3daedd680ff..b9f74df0db93 100644
@@ -226,7 +226,7 @@ handle_bitset_message(const struct hv_vp_signal_bitset_scheduler_message *msg)
 			if (vp_bank_idx == vp_bank_size)
 				break;
 
-			vp_index = (bank_idx << HV_GENERIC_SET_SHIFT) + vp_bank_idx;
+			vp_index = (bank_idx * vp_bank_size) + vp_bank_idx;
 
 			/* This shouldn't happen, but just in case. */
 			if (unlikely(vp_index >= MSHV_MAX_VPS)) {
include/uapi/linux/mshv.h +18 -14
index 9468f66c5658..876bfe4e4227 100644
@@ -74,12 +74,16 @@ enum {
 
 #define MSHV_SET_MEM_FLAGS_MASK ((1 << MSHV_SET_MEM_BIT_COUNT) - 1)
 
+/* The hypervisor's "native" page size */
+#define MSHV_HV_PAGE_SIZE	0x1000
+
 /**
  * struct mshv_user_mem_region - arguments for MSHV_SET_GUEST_MEMORY
- * @size: Size of the memory region (bytes). Must be aligned to PAGE_SIZE
+ * @size: Size of the memory region (bytes). Must be aligned to
+ *        MSHV_HV_PAGE_SIZE
  * @guest_pfn: Base guest page number to map
  * @userspace_addr: Base address of userspace memory. Must be aligned to
- *                  PAGE_SIZE
+ *                  MSHV_HV_PAGE_SIZE
  * @flags: Bitmask of 1 << MSHV_SET_MEM_BIT_*. If (1 << MSHV_SET_MEM_BIT_UNMAP)
  *         is set, ignore other bits.
  * @rsvd: MBZ
@@ -143,13 +147,13 @@ struct mshv_user_irq_table {
 };
 
 enum {
-	MSHV_GPAP_ACCESS_TYPE_ACCESSED = 0,
+	MSHV_GPAP_ACCESS_TYPE_ACCESSED,
 	MSHV_GPAP_ACCESS_TYPE_DIRTY,
 	MSHV_GPAP_ACCESS_TYPE_COUNT		/* Count of enum members */
 };
 
 enum {
-	MSHV_GPAP_ACCESS_OP_NOOP = 0,
+	MSHV_GPAP_ACCESS_OP_NOOP,
 	MSHV_GPAP_ACCESS_OP_CLEAR,
 	MSHV_GPAP_ACCESS_OP_SET,
 	MSHV_GPAP_ACCESS_OP_COUNT		/* Count of enum members */
@@ -163,8 +167,7 @@ enum {
  *             the access states in the range, after retrieving the current
  *             states.
  * @rsvd: MBZ
- * @page_count: in: number of pages
- *              out: on error, number of states successfully written to bitmap
+ * @page_count: Number of pages
  * @gpap_base: Base gpa page number
  * @bitmap_ptr: Output buffer for bitmap, at least (page_count + 7) / 8 bytes
  *
@@ -185,8 +188,8 @@ struct mshv_gpap_access_bitmap {
  * @code: Hypercall code (HVCALL_*)
  * @reps: in: Rep count ('repcount')
  *	  out: Reps completed ('repcomp'). MBZ unless rep hvcall
- * @in_sz: Size of input incl rep data. <= HV_HYP_PAGE_SIZE
- * @out_sz: Size of output buffer. <= HV_HYP_PAGE_SIZE. MBZ if out_ptr is 0
+ * @in_sz: Size of input incl rep data. <= MSHV_HV_PAGE_SIZE
+ * @out_sz: Size of output buffer. <= MSHV_HV_PAGE_SIZE. MBZ if out_ptr is 0
  * @status: in: MBZ
  *	    out: HV_STATUS_* from hypercall
  * @rsvd: MBZ
@@ -225,13 +228,14 @@ struct mshv_root_hvcall {
 #define MSHV_RUN_VP_BUF_SZ 256
 
 /*
- * Map various VP state pages to userspace.
- * Multiply the offset by PAGE_SIZE before being passed as the 'offset'
- * argument to mmap().
+ * VP state pages may be mapped to userspace via mmap().
+ * To specify which state page, use MSHV_VP_MMAP_OFFSET_ values multiplied by
+ * the system page size.
  * e.g.
- * void *reg_page = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE,
+ * long page_size = sysconf(_SC_PAGE_SIZE);
+ * void *reg_page = mmap(NULL, MSHV_HV_PAGE_SIZE, PROT_READ|PROT_WRITE,
  *                       MAP_SHARED, vp_fd,
- *                       MSHV_VP_MMAP_OFFSET_REGISTERS * PAGE_SIZE);
+ *                       MSHV_VP_MMAP_OFFSET_REGISTERS * page_size);
  */
 enum {
 	MSHV_VP_MMAP_OFFSET_REGISTERS,
@@ -259,7 +263,7 @@ enum {
 };
 
 /**
- * struct mshv_get_set_vp_hvcall - arguments for MSHV_[GET,SET]_VP_STATE
+ * struct mshv_get_set_vp_state - arguments for MSHV_[GET,SET]_VP_STATE
  * @type: MSHV_VP_STATE_*
  * @rsvd: MBZ
  * @buf_sz: in: 4k page-aligned size of buffer
Signature · 1 line
2.34.1