Skip to contentSkip to conversation

drm/hyperv: address worthwhile gaps

PATCH In review Hamza Mahfooz 2 participants 6 messages Nov 13 – Nov 17

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

cover drm/hyperv: address worthwhile gaps

I was doing a deep dive into the host spec and noticed some gaps. So, I went ahead and hacked together the patches in this series for items that seemed worthwhile to address.

Hamza Mahfooz (2):
drm/hyperv: add modes for all resolutions offered by the host drm/hyperv: batch dirty rectangles

 drivers/gpu/drm/hyperv/hyperv_drm.h         | 15 ++++
 drivers/gpu/drm/hyperv/hyperv_drm_drv.c     |  4 ++
 drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 32 ++++++++-
 drivers/gpu/drm/hyperv/hyperv_drm_proto.c   | 79 ++++++++++++++++-----
 4 files changed, 110 insertions(+), 20 deletions(-)
Signature · 1 line
2.56.0
#1 lore raw

PATCH 1/2 drm/hyperv: add modes for all resolutions offered by the host

The host reports the resolutions it supports, which depend on the VM's
configuration: a list of standard resolutions by default, those up to a maximum plus the maximum itself, or a single resolution. The driver only takes the largest and the default resolution from the list, and offers the DMT modes of up to 60 Hz that fit. Resolutions without such a mode are thus missing (e.g. 1152x864, for which DMT only has a 75 Hz mode). A VM set to 2560x1440 even ends up without a preferred mode, as DMT has no 2560x1440 mode at all.

So, keep the list and add a 60 Hz CVT mode for every resolution in it that lacks a mode of its size, so that all of them can be used. CVT rounds the width down to a multiple of 8 while the host only requires an even width (e.g. 1366x768), so restore the width afterwards.

---
 drivers/gpu/drm/hyperv/hyperv_drm.h         |  9 +++++++
 drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 29 +++++++++++++++++++++
 drivers/gpu/drm/hyperv/hyperv_drm_proto.c   | 10 +++----
 3 files changed, 42 insertions(+), 6 deletions(-)
drivers/gpu/drm/hyperv/hyperv_drm.h +9 -0
index df03185a2e19..6006d665343b 100644
@@ -19,6 +19,13 @@
 #define SYNTHVID_CURSOR_MAX_SIZE (SYNTHVID_CURSOR_MAX_X * \
 	SYNTHVID_CURSOR_MAX_Y * SYNTHVID_CURSOR_ARGB_PIXEL_SIZE)
 
+#define SYNTHVID_MAX_RESOLUTION_COUNT 64
+
+struct hvd_screen_info {
+	u16 width;
+	u16 height;
+} __packed;
+
 /*
  * Copy of the cursor last handed to the host, so that it can be sent again
  * when needed, e.g. after a VM Connection window was opened.
@@ -55,6 +62,8 @@ struct hv_drm_device {
 	u32 preferred_width;
 	u32 preferred_height;
 	u32 screen_depth;
+	struct hvd_screen_info resolutions[SYNTHVID_MAX_RESOLUTION_COUNT];
+	unsigned int resolution_count;
 
 	/* hw */
 	struct resource *mem;
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +29 -0
index 48d7751c0bdd..177f804dca0c 100644
@@ -46,14 +46,43 @@ static int hv_drm_blit_to_vram_rect(struct drm_framebuffer *fb,
 	return 0;
 }
 
+static int hv_drm_connector_add_mode(struct drm_connector *connector,
+				     u16 width, u16 height)
+{
+	struct drm_display_mode *mode;
+
+	list_for_each_entry(mode, &connector->probed_modes, head) {
+		if (mode->hdisplay == width && mode->vdisplay == height)
+			return 0;
+	}
+
+	mode = drm_cvt_mode(connector->dev, width, height, 60, false, false,
+			    false);
+	if (!mode)
+		return 0;
+
+	/* CVT rounds the width down to a multiple of 8, the host does not */
+	mode->hdisplay = width;
+	mode->type |= DRM_MODE_TYPE_DRIVER;
+	drm_mode_set_name(mode);
+	drm_mode_probed_add(connector, mode);
+
+	return 1;
+}
+
 static int hv_drm_connector_get_modes(struct drm_connector *connector)
 {
 	struct hv_drm_device *hv = to_hv_drm(connector->dev);
+	unsigned int i;
 	int count;
 
 	count = drm_add_modes_noedid(connector,
 				     connector->dev->mode_config.max_width,
 				     connector->dev->mode_config.max_height);
+	for (i = 0; i < hv->resolution_count; i++)
+		count += hv_drm_connector_add_mode(connector,
+						   hv->resolutions[i].width,
+						   hv->resolutions[i].height);
 	drm_set_preferred_mode(connector, hv->preferred_width,
 			       hv->preferred_height);
 
drivers/gpu/drm/hyperv/hyperv_drm_proto.c +4 -6
index 99e036576929..81ffb88ba6a1 100644
@@ -56,11 +56,6 @@ struct pipe_msg_hdr {
 	u32 size; /* size of message after this field */
 } __packed;
 
-struct hvd_screen_info {
-	u16 width;
-	u16 height;
-} __packed;
-
 struct synthvid_msg_hdr {
 	u32 type;
 	u32 size;  /* size of this header + payload after this field */
@@ -145,7 +140,6 @@ struct synthvid_dirt {
 } __packed;
 
 #define SYNTHVID_EDID_BLOCK_SIZE	128
-#define	SYNTHVID_MAX_RESOLUTION_COUNT	64
 
 struct synthvid_supported_resolution_req {
 	u8 maximum_resolution_count;
@@ -522,6 +516,10 @@ static int hv_drm_get_supported_resolution(struct hv_device *hdev)
 	hv->preferred_height =
 		msg->resolution_resp.supported_resolution[index].height;
 
+	hv->resolution_count = msg->resolution_resp.resolution_count;
+	memcpy(hv->resolutions, msg->resolution_resp.supported_resolution,
+	       hv->resolution_count * sizeof(hv->resolutions[0]));
+
 	return 0;
 }
 
Signature · 1 line
2.56.0
#2 lore raw

PATCH 2/2 drm/hyperv: batch dirty rectangles

In reply to Hamza Mahfooz

Every damage clip of a primary plane update is sent to the host in a dirt message of its own, although a dirt message can hold up to 255 rectangles and updates may come with many clips, e.g. up to 256 from the DIRTYFB ioctl.

So, collect the clips of an update in one message instead, and send it once all of them were copied to VRAM, or earlier whenever it is full. The panic handler keeps sending a message of its own, as it may interrupt a plane update.

---
 drivers/gpu/drm/hyperv/hyperv_drm.h         |  6 ++
 drivers/gpu/drm/hyperv/hyperv_drm_drv.c     |  4 ++
 drivers/gpu/drm/hyperv/hyperv_drm_modeset.c |  3 +-
 drivers/gpu/drm/hyperv/hyperv_drm_proto.c   | 69 +++++++++++++++++----
 4 files changed, 68 insertions(+), 14 deletions(-)
drivers/gpu/drm/hyperv/hyperv_drm.h +6 -0
index 6006d665343b..c17f06f18232 100644
@@ -47,6 +47,8 @@ struct hv_drm_cursor {
 	u8 msg_buf[VMBUS_MAX_PACKET_SIZE];
 };
 
+struct synthvid_msg;
+
 struct hv_drm_device {
 	/* drm */
 	struct drm_device dev;
@@ -73,6 +75,7 @@ struct hv_drm_device {
 	struct completion wait;
 	u32 mmio_megabytes;
 	bool dirt_needed;
+	struct synthvid_msg *dirt_msg;
 
 	u8 init_buf[VMBUS_MAX_PACKET_SIZE];
 	u8 recv_buf[VMBUS_MAX_PACKET_SIZE];
@@ -96,6 +99,9 @@ int hv_drm_cursor_init(struct hv_drm_device *hv);
 void hv_drm_cursor_set_hidden(struct hv_drm_cursor *cursor);
 void hv_drm_update_cursor(struct hv_drm_device *hv, bool shape);
 void hv_drm_restore_cursor(struct hv_drm_device *hv);
+int hv_drm_dirt_init(struct hv_drm_device *hv);
+void hv_drm_flush_dirt(struct hv_drm_device *hv);
+void hv_drm_add_dirt(struct hv_drm_device *hv, const struct drm_rect *rect);
 int hv_drm_update_dirt(struct hv_device *hdev, struct drm_rect *rect);
 int hv_drm_connect_vsp(struct hv_device *hdev);
 void hv_drm_disconnect_vsp(struct hv_device *hdev);
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +4 -0
index 21e5fcc3eb68..56995eaec4d1 100644
@@ -124,6 +124,10 @@ static int hv_drm_vmbus_probe(struct hv_device *hdev,
 	if (ret)
 		goto err_hv_set_drv_data;
 
+	ret = hv_drm_dirt_init(hv);
+	if (ret)
+		goto err_hv_set_drv_data;
+
 	ret = hv_drm_connect_vsp(hdev);
 	if (ret) {
 		drm_err(dev, "Failed to connect to vmbus.\n");
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +2 -1
index 177f804dca0c..b04b0a30a1c1 100644
@@ -217,8 +217,9 @@ static void hv_drm_plane_atomic_update(struct drm_plane *plane,
 			continue;
 
 		hv_drm_blit_to_vram_rect(new_state->fb, &shadow_plane_state->data[0], &damage);
-		hv_drm_update_dirt(hv->hdev, &damage);
+		hv_drm_add_dirt(hv, &damage);
 	}
+	hv_drm_flush_dirt(hv);
 }
 
 static int hv_drm_plane_get_scanout_buffer(struct drm_plane *plane,
drivers/gpu/drm/hyperv/hyperv_drm_proto.c +56 -13

90 lines not on this page · raw message

Signature · 1 line
2.56.0
#3 lore raw
In reply to Hamza Mahfooz

From: Hamza Mahfooz <[email protected]> Sent: Friday, November 13, 2026 1:59 PM

Quoted 4 lines

I was doing a deep dive into the host spec and noticed some gaps. So, I went ahead and hacked together the patches in this series for items that seemed worthwhile to address.

Are you (or someone on the Microsoft side) testing these changes in a Generation 1 VM, as well as on back revs of the Hyper-V host? Testing should go back to Windows Server 2016/Windows 10 for both Gen1 and Gen2.

Same questions apply to your earlier cursor plane support. I just did basic smoke testing of the cursor plane support on both Gen1 and Gen2 VMs using vmconnect.exe on an up-to-date Windows 11 host -- no obvious problems. But I don't have access to older hosts like WS2016/Win10 to do the back rev testing.

There are multiple frame buffer differences in Gen1 and Gen2 VMs, but most (or all?) are in the lowest layer in how the frame buffer is allocated and mapped. Hopefully these higher-level changes you are making are agnostic of the VM generation, but thoroughness would dictate testing both.

I'm less sure about what might have changed in current Hyper-V versions and WS2016 from 10 years ago. My general impression is that very little, if anything, has changed in the Hyper-V frame buffer support, but again it would be better to not get a bad surprise after the code has gone in.

Michael

Quoted 13 lines

Hamza Mahfooz (2):
drm/hyperv: add modes for all resolutions offered by the host drm/hyperv: batch dirty rectangles

 drivers/gpu/drm/hyperv/hyperv_drm.h         | 15 ++++
 drivers/gpu/drm/hyperv/hyperv_drm_drv.c     |  4 ++
 drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 32 ++++++++-
 drivers/gpu/drm/hyperv/hyperv_drm_proto.c   | 79 ++++++++++++++++-----
 4 files changed, 110 insertions(+), 20 deletions(-)

--
2.56.0

#4 lore raw
Quoted 8 lines · Michael Kelley

From: Hamza Mahfooz <[email protected]> Sent: Friday, November 13, 2026 1:59 PM

Quoted 4 lines

I was doing a deep dive into the host spec and noticed some gaps. So, I went ahead and hacked together the patches in this series for items that seemed worthwhile to address.

Are you (or someone on the Microsoft side) testing these changes in a Generation 1 VM, as well as on back revs of the Hyper-V host?

Ya, I have smoke tested all of these patches on WS2016 (both gen1 and gen2). Also, I have it on good authority that they should be good at least as far back as VMBus v3.0, so it should cover everything that is currently supported.

Quoted 36 lines

Testing should go back to Windows Server 2016/Windows 10 for both Gen1 and Gen2.

Same questions apply to your earlier cursor plane support. I just did basic smoke testing of the cursor plane support on both Gen1 and Gen2 VMs using vmconnect.exe on an up-to-date Windows 11 host -- no obvious problems. But I don't have access to older hosts like WS2016/Win10 to do the back rev testing.

There are multiple frame buffer differences in Gen1 and Gen2 VMs, but most (or all?) are in the lowest layer in how the frame buffer is allocated and mapped. Hopefully these higher-level changes you are making are agnostic of the VM generation, but thoroughness would dictate testing both.

I'm less sure about what might have changed in current Hyper-V versions and WS2016 from 10 years ago. My general impression is that very little, if anything, has changed in the Hyper-V frame buffer support, but again it would be better to not get a bad surprise after the code has gone in.

Michael

Quoted 13 lines

Hamza Mahfooz (2):
drm/hyperv: add modes for all resolutions offered by the host drm/hyperv: batch dirty rectangles

 drivers/gpu/drm/hyperv/hyperv_drm.h         | 15 ++++
 drivers/gpu/drm/hyperv/hyperv_drm_drv.c     |  4 ++
 drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 32 ++++++++-
 drivers/gpu/drm/hyperv/hyperv_drm_proto.c   | 79 ++++++++++++++++-----
 4 files changed, 110 insertions(+), 20 deletions(-)

--
2.56.0

#5 lore raw

From: Hamza Mahfooz <[email protected]> Sent: Monday, November 16, 2026 7:02 AM

Quoted 9 lines · Michael Kelley
Quoted 1 line

From: Hamza Mahfooz <[email protected]> Sent: Friday,

November 13, 2026 1:59 PM

Quoted 5 lines
Quoted 4 lines

I was doing a deep dive into the host spec and noticed some gaps. So, I went ahead and hacked together the patches in this series for items that seemed worthwhile to address.

Quoted 7 lines
Quoted 2 lines

Are you (or someone on the Microsoft side) testing these changes in a Generation 1 VM, as well as on back revs of the Hyper-V host?

Ya, I have smoke tested all of these patches on WS2016 (both gen1 and gen2). Also, I have it on good authority that they should be good at least as far back as VMBus v3.0, so it should cover everything that is currently supported.

Excellent. Thanks.

Michael

Quoted 37 lines
Quoted 37 lines

Testing should go back to Windows Server 2016/Windows 10 for both Gen1 and Gen2.

Same questions apply to your earlier cursor plane support. I just did basic smoke testing of the cursor plane support on both Gen1 and Gen2 VMs using vmconnect.exe on an up-to-date Windows 11 host -- no obvious problems. But I don't have access to older hosts like WS2016/Win10 to do the back rev testing.

There are multiple frame buffer differences in Gen1 and Gen2 VMs, but most (or all?) are in the lowest layer in how the frame buffer is allocated and mapped. Hopefully these higher-level changes you are making are agnostic of the VM generation, but thoroughness would dictate testing both.

I'm less sure about what might have changed in current Hyper-V versions and WS2016 from 10 years ago. My general impression is that very little, if anything, has changed in the Hyper-V frame buffer support, but again it would be better to not get a bad surprise after the code has gone in.

Michael

Quoted 13 lines

Hamza Mahfooz (2):
drm/hyperv: add modes for all resolutions offered by the host drm/hyperv: batch dirty rectangles

 drivers/gpu/drm/hyperv/hyperv_drm.h         | 15 ++++
 drivers/gpu/drm/hyperv/hyperv_drm_drv.c     |  4 ++
 drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 32 ++++++++-
 drivers/gpu/drm/hyperv/hyperv_drm_proto.c   | 79 ++++++++++++++++-----
 4 files changed, 110 insertions(+), 20 deletions(-)

--
2.56.0