Subject: [PATCH v2] vmbus: retrieve connection-id from DeviceTree

From: Hardik Garg
Date: Tue Jun 03 2025 - 17:01:13 EST


The connection-id determines which hypervisor communication channel the
guest should use to talk to the VMBus host. This patch adds support to
read this value from the DeviceTree where it exists as a property under
the vmbus node with the compatible ID "microsoft,message-connection-id".
The property name follows the format <vendor>,<field> where
"vendor": "microsoft" and "field": "message-connection-id"

Reading from DeviceTree allows platforms to specify their preferred
communication channel, making it more flexible. If the property is
not found in the DeviceTree, use the default connection ID
(VMBUS_MESSAGE_CONNECTION_ID or VMBUS_MESSAGE_CONNECTION_ID_4
based on protocol version).

Signed-off-by: Hardik Garg <hargar@xxxxxxxxxxxxxxxxxxx>
---
v2:
- Rebased on hyperv-next branch as requested by maintainers
- Added details about the property name format in the commit message

v1: https://lore.kernel.org/all/6acee4bf-cb04-43b9-9476-e8d811d26dfd@xxxxxxxxxxxxxxxxxxx/

 drivers/hv/connection.c |  6 ++++--
 drivers/hv/vmbus_drv.c  | 13 +++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index be490c598785..c444c943c1d4 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -99,12 +99,14 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)
     if (version >= VERSION_WIN10_V5) {
         msg->msg_sint = VMBUS_MESSAGE_SINT;
         msg->msg_vtl = ms_hyperv.vtl;
-        vmbus_connection.msg_conn_id = VMBUS_MESSAGE_CONNECTION_ID_4;
     } else {
         msg->interrupt_page = virt_to_phys(vmbus_connection.int_page);
-        vmbus_connection.msg_conn_id = VMBUS_MESSAGE_CONNECTION_ID;
     }

+    /* Set default connection ID if not provided via DeviceTree */
+    if (!vmbus_connection.msg_conn_id)
+        vmbus_connection.msg_conn_id = (version >= VERSION_WIN10_V5) ?
+            VMBUS_MESSAGE_CONNECTION_ID_4 : VMBUS_MESSAGE_CONNECTION_ID;
     /*
      * shared_gpa_boundary is zero in non-SNP VMs, so it's safe to always
      * bitwise OR it
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index c236081d0a87..6a886611c448 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -2541,10 +2541,23 @@ static int vmbus_device_add(struct platform_device *pdev)
     struct of_range range;
     struct of_range_parser parser;
     struct device_node *np = pdev->dev.of_node;
+    unsigned int conn_id;
     int ret;

     vmbus_root_device = &pdev->dev;

+    /*
+     * Read connection ID from DeviceTree. The property name follows the
+     * format <vendor>,<field> where:
+     * - vendor: "microsoft"
+     * - field: "message-connection-id"
+     */
+    ret = of_property_read_u32(np, "microsoft,message-connection-id", &conn_id);
+    if (!ret) {
+        pr_info("VMBus message connection ID: %u\n", conn_id);
+        vmbus_connection.msg_conn_id = conn_id;
+    }
+
     ret = of_range_parser_init(&parser, np);
     if (ret)
         return ret;
--
2.40.4