virtio: Add support for Virtio message transport
Subsystems (2)
cover virtio: Add support for Virtio message transport
Hello,
This RFC series introduces support for a new Virtio transport type:
"virtio-msg", as proposed in [1]. Unlike existing transport types like virtio-mmio or virtio-pci, which rely on memory-mapped registers, virtio-msg implements transport operations via structured messages. Those messages can be transported through different mechanisms such as mailboxes, shared memory based FIFO or specific protocols such as FF-A on Arm.
This series includes:
- Core virtio-msg transport support.
- Two message transport bus implementations:
- virtio-msg-ffa: based on ARM's Firmware Framework for Arm (FF-A).
- virtio-msg-loopback: a loopback device for testing and validation.
The code is available here for reference: [2] and virtio-msg loopback and FF-A test setups are explained here: [3] and [4].
This series is based on v6.16 and depends on commit [5].
### Memory Mapping and Reserved Memory Usage
The first two patches enhance the reserved-memory subsystem to support attaching struct device`s that do not originate from DT nodes — essential for virtual or dynamically discovered devices like the FF-A or loopback buses.
This reserved-memory region enables:
- Restricting all DMA-coherent and streaming DMA memory to a controlled range.
- Allowing the remote endpoint to pre-map this memory, reducing runtime overhead.
- Preventing unintentional data leaks, since memory is typically shared at page granularity.
- For the loopback bus, it restricts the portion of kernel memory that can be mapped into userspace, improving safety.
Device association with reserved-memory regions is based on DT node naming conventions, such as vmsglb@ or vmsgffa@, similar to the remoteproc framework’s approach.
Feedback on the design, API, and approach is welcome.
--
Viresh
[1] https://lore.kernel.org/all/[email protected]/
[2] git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/linux.git virtio/msg-rfc-v1
[3] https://linaro.atlassian.net/wiki/spaces/HVAC/pages/30104092673
[4] https://linaro.atlassian.net/wiki/spaces/HVAC/pages/29657792513
[5] From linux-next: 5be53630b4f0 virtio-mmio: Remove virtqueue list from mmio device
Viresh Kumar (6):
of: reserved-memory: Add reserved_mem_device_init()
of: reserved-memory: Add of_reserved_mem_lookup_by_name
virtio: Add support for virtio-msg transport
virtio-msg: Add optional userspace interface for message I/O
virtio-msg: Add support for FF-A (Firmware Framework for Arm) bus
virtio-msg: Add support for loopback bus
MAINTAINERS | 7 + drivers/of/of_reserved_mem.c | 91 +++- drivers/virtio/Kconfig | 34 ++ drivers/virtio/Makefile | 5 + drivers/virtio/virtio_msg.c | 655 +++++++++++++++++++++++++++ drivers/virtio/virtio_msg_ffa.c | 505 +++++++++++++++++++++ drivers/virtio/virtio_msg_internal.h | 88 ++++ drivers/virtio/virtio_msg_loopback.c | 323 +++++++++++++ drivers/virtio/virtio_msg_user.c | 140 ++++++ include/linux/of_reserved_mem.h | 13 + include/uapi/linux/virtio_msg.h | 213 +++++++++ include/uapi/linux/virtio_msg_ffa.h | 94 ++++ include/uapi/linux/virtio_msg_lb.h | 22 + 13 files changed, 2166 insertions(+), 24 deletions(-) create mode 100644 drivers/virtio/virtio_msg.c create mode 100644 drivers/virtio/virtio_msg_ffa.c create mode 100644 drivers/virtio/virtio_msg_internal.h create mode 100644 drivers/virtio/virtio_msg_loopback.c create mode 100644 drivers/virtio/virtio_msg_user.c create mode 100644 include/uapi/linux/virtio_msg.h create mode 100644 include/uapi/linux/virtio_msg_ffa.h create mode 100644 include/uapi/linux/virtio_msg_lb.h
Signature · 1 line
2.31.1.272.g89b43f80a514
RFC PATCH 1/6 of: reserved-memory: Add reserved_mem_device_init()
This adds reserved_mem_device_init() helper to attach the specified reserved-memory region to the device.
This is required to attach a reserved-memory region with a non-DT device.
--- drivers/of/of_reserved_mem.c | 64 ++++++++++++++++++++------------- include/linux/of_reserved_mem.h | 7 ++++ 2 files changed, 47 insertions(+), 24 deletions(-)
drivers/of/of_reserved_mem.c +40 -24
@@ -606,6 +606,45 @@ struct rmem_assigned_device {static LIST_HEAD (of_rmem_assigned_device_list);static DEFINE_MUTEX (of_rmem_assigned_device_mutex); +/** +* reserved_mem_device_init() - assign reserved memory region to given device +* @dev: Pointer to the device to configure +* @rmem: Pointer to the reserved memory region +* +* This function assigns the @rmem reserved memory region to the @dev device. +* +* Returns error code or zero on success. +*/ +int reserved_mem_device_init (struct device *dev,struct reserved_mem *rmem) +{ +struct rmem_assigned_device *rd; +int ret; + +if (!dev || !rmem || !rmem->ops || !rmem->ops->device_init) +return -EINVAL ; + + rd =kmalloc (sizeof (*rd),GFP_KERNEL ); +if (!rd) +return -ENOMEM ; + + ret = rmem->ops->device_init (rmem, dev); +if (ret ==0 ) { + rd->dev = dev; + rd->rmem = rmem; + +mutex_lock (&of_rmem_assigned_device_mutex); +list_add (&rd->list, &of_rmem_assigned_device_list); +mutex_unlock (&of_rmem_assigned_device_mutex); + +dev_info (dev,"assigned reserved memory node %s\n" , rmem->name); + }else { +kfree (rd); + } + +return ret; +} +EXPORT_SYMBOL_GPL (reserved_mem_device_init); +/** * of_reserved_mem_device_init_by_idx() - assign reserved memory region to * given device
@@ -624,10 +663,8 @@ static DEFINE_MUTEX(of_rmem_assigned_device_mutex);int of_reserved_mem_device_init_by_idx (struct device *dev,struct device_node *np,int idx) { -struct rmem_assigned_device *rd;struct device_node *target;struct reserved_mem *rmem; -int ret;if (!np || !dev)return -EINVAL ;
@@ -644,28 +681,7 @@ int of_reserved_mem_device_init_by_idx(struct device *dev, rmem =of_reserved_mem_lookup (target);of_node_put (target); -if (!rmem || !rmem->ops || !rmem->ops->device_init) -return -EINVAL ; - - rd =kmalloc (sizeof (struct rmem_assigned_device ),GFP_KERNEL ); -if (!rd) -return -ENOMEM ; - - ret = rmem->ops->device_init (rmem, dev); -if (ret ==0 ) { - rd->dev = dev; - rd->rmem = rmem; - -mutex_lock (&of_rmem_assigned_device_mutex); -list_add (&rd->list, &of_rmem_assigned_device_list); -mutex_unlock (&of_rmem_assigned_device_mutex); - -dev_info (dev,"assigned reserved memory node %s\n" , rmem->name); - }else { -kfree (rd); - } - -return ret; +return reserved_mem_device_init (dev, rmem); }EXPORT_SYMBOL_GPL (of_reserved_mem_device_init_by_idx);
include/linux/of_reserved_mem.h +7 -0
@@ -37,6 +37,7 @@ int of_reserved_mem_device_init_by_idx(struct device *dev,int of_reserved_mem_device_init_by_name (struct device *dev,struct device_node *np,const char *name); +int reserved_mem_device_init (struct device *dev,struct reserved_mem *rmem);void of_reserved_mem_device_release (struct device *dev);struct reserved_mem *of_reserved_mem_lookup (struct device_node *np);
@@ -64,6 +65,12 @@ static inline int of_reserved_mem_device_init_by_name(struct device *dev,return -ENOSYS ; } +static inline int reserved_mem_device_init (struct device *dev, +struct reserved_mem *rmem) +{ +return -ENOSYS ; +} +static inline void of_reserved_mem_device_release (struct device *pdev) { }static inline struct reserved_mem *of_reserved_mem_lookup (struct device_node *np)
Signature · 1 line
2.31.1.272.g89b43f80a514
RFC PATCH 2/6 of: reserved-memory: Add of_reserved_mem_lookup_by_name
In reply to Viresh KumarThis adds of_reserved_mem_lookup_by_name() helper to get a reserved-memory region based on the DT node name.
--- drivers/of/of_reserved_mem.c | 27 +++++++++++++++++++++++++++ include/linux/of_reserved_mem.h | 6 ++++++ 2 files changed, 33 insertions(+)
drivers/of/of_reserved_mem.c +27 -0
@@ -758,6 +758,33 @@ struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) }EXPORT_SYMBOL_GPL (of_reserved_mem_lookup); +/** +* of_reserved_mem_lookup_by_name() - acquire reserved_mem from node name +* @name: node name +* +* This function allows drivers to acquire a reference to the reserved_mem +* struct based on a reserved-memory node name. +* +* Returns a reserved_mem reference, or NULL on error. +*/ +struct reserved_mem *of_reserved_mem_lookup_by_name (const char *name) +{ + struct device_node *np __free(device_node) = +of_find_node_by_path ("/reserved-memory" ); + struct device_node *child __free(device_node) = NULL; + +if (!np) +return ERR_PTR (-ENODEV ); + +for_each_child_of_node (np, child) { +if (of_node_name_eq (child, name)) +return of_reserved_mem_lookup (child); + } + +return ERR_PTR (-ENODEV ); +} +EXPORT_SYMBOL_GPL (of_reserved_mem_lookup_by_name); +/** * of_reserved_mem_region_to_resource() - Get a reserved memory region as a resource * @np: node containing 'memory-region' property
include/linux/of_reserved_mem.h +6 -0
@@ -41,6 +41,7 @@ int reserved_mem_device_init(struct device *dev, struct reserved_mem *rmem);void of_reserved_mem_device_release (struct device *dev);struct reserved_mem *of_reserved_mem_lookup (struct device_node *np); +struct reserved_mem *of_reserved_mem_lookup_by_name (const char *name);int of_reserved_mem_region_to_resource (const struct device_node *np,unsigned int idx,struct resource *res); int of_reserved_mem_region_to_resource_byname(const struct device_node *np,
@@ -78,6 +79,11 @@ static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *npreturn NULL ; } +static inline struct reserved_mem *of_reserved_mem_lookup_by_name (const char *name) +{ +return NULL ; +} +static inline int of_reserved_mem_region_to_resource (const struct device_node *np,unsigned int idx,struct resource *res)
Signature · 1 line
2.31.1.272.g89b43f80a514
RFC PATCH 3/6 virtio: Add support for virtio-msg transport
In reply to Viresh KumarThis introduces support for a new Virtio transport type: "virtio-msg". Unlike existing transport types like virtio-mmio or virtio-pci which rely on memory-mapped registers, virtio-msg implements transport operations via structured message exchanges using standard virtqueues.
It separates bus-level functionality (e.g., device enumeration, hotplug events) from device-specific operations (e.g., feature negotiation, virtqueue setup), ensuring that a single, generic transport layer can be reused across multiple bus implementations (like ARM Firmware Framework (FF-A), IPC, etc.).
--- MAINTAINERS | 7 + drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_msg.c | 655 +++++++++++++++++++++++++++ drivers/virtio/virtio_msg_internal.h | 56 +++ include/uapi/linux/virtio_msg.h | 213 +++++++++ 6 files changed, 939 insertions(+) create mode 100644 drivers/virtio/virtio_msg.c create mode 100644 drivers/virtio/virtio_msg_internal.h create mode 100644 include/uapi/linux/virtio_msg.h
MAINTAINERS +7 -0
@@ -26358,6 +26358,13 @@ W: https://virtio-mem.gitlab.io/ F: drivers/virtio/virtio_mem.c F: include/uapi/linux/virtio_mem.h +VIRTIO MSG TRANSPORT +M: Viresh Kumar <[email protected]> +L: [email protected] +S: Maintained +F: drivers/virtio/virtio_msg* +F: include/uapi/linux/virtio_msg* + VIRTIO PMEM DRIVER M: Pankaj Gupta <[email protected]> L: [email protected]
drivers/virtio/Kconfig +7 -0
@@ -171,6 +171,13 @@ config VIRTIO_MMIO_CMDLINE_DEVICES If unsure, say 'N'. +config VIRTIO_MSG + tristate + select VIRTIO + help + This enables support for Virtio message transport. This option is + selected by any driver which implements the virtio message bus. + config VIRTIO_DMA_SHARED_BUFFER tristate depends on DMA_SHARED_BUFFER
drivers/virtio/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_VIRTIO_ANCHOR) += virtio_anchor.o obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o +obj-$(CONFIG_VIRTIO_MSG) += virtio_msg.o obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o
drivers/virtio/virtio_msg.c new file +655 -0
655 lines not on this page · raw message
drivers/virtio/virtio_msg_internal.h new file +56 -0
56 lines not on this page · raw message
include/uapi/linux/virtio_msg.h new file +213 -0
213 lines not on this page · raw message
Signature · 1 line
2.31.1.272.g89b43f80a514
RFC PATCH 4/6 virtio-msg: Add optional userspace interface for message I/O
In reply to Viresh KumarAdd support for an optional userspace interface to the virtio-msg transport via a per-bus miscdevice. When enabled by a bus implementation, this interface allows userspace to send and receive virtio messages through a character device node.
A separate device node is created for each bus that registers for userspace access, e.g., /dev/virtio-msg-N. This enables backend-side components or test tools to interact with the transport layer directly from userspace.
Bus implementations that do not require userspace interaction can omit this interface entirely.
--- drivers/virtio/Kconfig | 8 ++ drivers/virtio/Makefile | 4 +- drivers/virtio/virtio_msg_internal.h | 32 ++++++ drivers/virtio/virtio_msg_user.c | 140 +++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 drivers/virtio/virtio_msg_user.c
drivers/virtio/Kconfig +8 -0
@@ -178,6 +178,14 @@ config VIRTIO_MSG This enables support for Virtio message transport. This option is selected by any driver which implements the virtio message bus. +config VIRTIO_MSG_USER + tristate "Userspace interface for virtio message transport" + depends on VIRTIO_MSG + help + This enables userspace interface for Virtio message transport. This + can be used to read / write messages over virtio-msg transport from + userspace. + config VIRTIO_DMA_SHARED_BUFFER tristate depends on DMA_SHARED_BUFFER
drivers/virtio/Makefile +3 -1
@@ -4,7 +4,9 @@ obj-$(CONFIG_VIRTIO_ANCHOR) += virtio_anchor.o obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o -obj-$(CONFIG_VIRTIO_MSG) += virtio_msg.o +virtio_msg_transport-y := virtio_msg.o +virtio_msg_transport-$(CONFIG_VIRTIO_MSG_USER) += virtio_msg_user.o +obj-$(CONFIG_VIRTIO_MSG) += virtio_msg_transport.o obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o
drivers/virtio/virtio_msg_internal.h +32 -0
@@ -9,6 +9,8 @@#ifndef _DRIVERS_VIRTIO_MSG_INTERNAL_H#define _DRIVERS_VIRTIO_MSG_INTERNAL_H +#include <linux/completion.h> +#include <linux/miscdevice.h> #include <linux/virtio.h> #include <uapi/linux/virtio_msg.h>
@@ -53,4 +55,34 @@ void virtio_msg_unregister(struct virtio_msg_device *vmdev);void virtio_msg_prepare (struct virtio_msg *vmsg,u8 msg_id,u16 payload_size);int virtio_msg_event (struct virtio_msg_device *vmdev,struct virtio_msg *vmsg); +/* Virtio msg userspace interface */ +struct virtio_msg_user_device ; + +struct virtio_msg_user_ops { +int (*handle)(struct virtio_msg_user_device *vmudev,struct virtio_msg *vmsg); +}; + +/* Host side device using virtio message */ +struct virtio_msg_user_device { +struct virtio_msg_user_ops *ops; +struct miscdevice misc; +struct completion r_completion; +struct completion w_completion; +struct virtio_msg *vmsg; +struct device *parent; +char name[15 ]; +}; + +#if IS_REACHABLE (CONFIG_VIRTIO_MSG_USER ) +int virtio_msg_user_register (struct virtio_msg_user_device *vmudev); +void virtio_msg_user_unregister (struct virtio_msg_user_device *vmudev); +#else +static inline int virtio_msg_user_register (struct virtio_msg_user_device *vmudev) +{ +return -EOPNOTSUPP ; +} + +static inline void virtio_msg_user_unregister (struct virtio_msg_user_device *vmudev) {} +#endif /* CONFIG_VIRTIO_MSG_USER */ +#endif /* _DRIVERS_VIRTIO_MSG_INTERNAL_H */
drivers/virtio/virtio_msg_user.c new file +140 -0
140 lines not on this page · raw message
Signature · 1 line
2.31.1.272.g89b43f80a514
RFC PATCH 5/6 virtio-msg: Add support for FF-A (Firmware Framework for Arm) bus
In reply to Viresh KumarIntroduce a virtio-msg bus implementation based on the Arm FF-A (Firmware Framework for Arm) communication interface.
This bus enables virtio-msg transport over secure channels typically used between the normal world OS and a secure OS or hypervisor. It leverages the standardized FF-A interface to exchange messages with a remote backend service.
The implementation integrates with the core virtio-msg transport and uses FF-A service calls to transmit and receive messages.
Optionally, this bus supports attaching a reserved-memory region to constrain DMA-coherent and streaming DMA allocations to a well-defined contiguous area. This memory can be pre-mapped on the remote side, reducing runtime overhead and preventing accidental sharing of unrelated pages due to page-granularity mapping.
To enable reserved memory, the following device tree node should be defined (the node must be named "vmsgffa"):
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
ranges; vmsgffa@100000000 {
compatible = "restricted-dma-pool";
reg = <0x00000001 0x00000000 0x0 0x00400000>; /* 4 MiB */
};};
--- drivers/virtio/Kconfig | 12 +- drivers/virtio/Makefile | 1 + drivers/virtio/virtio_msg_ffa.c | 505 ++++++++++++++++++++++++++++ include/uapi/linux/virtio_msg_ffa.h | 94 ++++++ 4 files changed, 611 insertions(+), 1 deletion(-) create mode 100644 drivers/virtio/virtio_msg_ffa.c create mode 100644 include/uapi/linux/virtio_msg_ffa.h
drivers/virtio/Kconfig +11 -1
@@ -176,7 +176,8 @@ config VIRTIO_MSG select VIRTIO help This enables support for Virtio message transport. This option is - selected by any driver which implements the virtio message bus. + selected by any driver which implements the virtio message bus, such + as VIRTIO_MSG_FFA. config VIRTIO_MSG_USER tristate "Userspace interface for virtio message transport"
@@ -186,6 +187,15 @@ config VIRTIO_MSG_USER can be used to read / write messages over virtio-msg transport from userspace. +config VIRTIO_MSG_FFA + tristate "FF-A bus driver for virtio message transport" + depends on ARM_FFA_TRANSPORT + select VIRTIO_MSG + help + This implements a Virtio message bus based on ARM FF-A protocol. + + If unsure, say N. + config VIRTIO_DMA_SHARED_BUFFER tristate depends on DMA_SHARED_BUFFER
drivers/virtio/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o virtio_msg_transport-y := virtio_msg.o virtio_msg_transport-$(CONFIG_VIRTIO_MSG_USER) += virtio_msg_user.o obj-$(CONFIG_VIRTIO_MSG) += virtio_msg_transport.o +obj-$(CONFIG_VIRTIO_MSG_FFA) += virtio_msg_ffa.o obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o
drivers/virtio/virtio_msg_ffa.c new file +505 -0
505 lines not on this page · raw message
include/uapi/linux/virtio_msg_ffa.h new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.31.1.272.g89b43f80a514
RFC PATCH 6/6 virtio-msg: Add support for loopback bus
In reply to Viresh KumarAdd a loopback bus implementation for the virtio-msg transport.
This bus simulates a backend that echoes messages to itself, allowing testing and development of virtio-msg without requiring an actual remote backend or transport hardware.
The loopback bus requires a reserved memory region for its operation. All DMA-coherent and streaming DMA allocations are restricted to this region, enabling safe mapping into user space and helping validate the memory-sharing model.
The reserved-memory region must be named "vmsglb" in the device tree. Example:
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
ranges; vmsglb@100000000 {
compatible = "restricted-dma-pool";
reg = <0x00000001 0x00000000 0x0 0x00400000>; /* 4 MiB */
};};
This bus is primarily intended for functional testing, development, and validation of the virtio-msg transport and its userspace interface.
--- drivers/virtio/Kconfig | 9 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_msg_loopback.c | 323 +++++++++++++++++++++++++++ include/uapi/linux/virtio_msg_lb.h | 22 ++ 4 files changed, 355 insertions(+) create mode 100644 drivers/virtio/virtio_msg_loopback.c create mode 100644 include/uapi/linux/virtio_msg_lb.h
drivers/virtio/Kconfig +9 -0
@@ -196,6 +196,15 @@ config VIRTIO_MSG_FFA If unsure, say N. +config VIRTIO_MSG_LOOPBACK + tristate "Loopback bus driver for virtio message transport" + select VIRTIO_MSG + select VIRTIO_MSG_USER + help + This implements the Loopback bus for Virtio msg transport. + + If unsure, say N. + config VIRTIO_DMA_SHARED_BUFFER tristate depends on DMA_SHARED_BUFFER
drivers/virtio/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o virtio_msg_transport-y := virtio_msg.o virtio_msg_transport-$(CONFIG_VIRTIO_MSG_USER) += virtio_msg_user.o obj-$(CONFIG_VIRTIO_MSG) += virtio_msg_transport.o +obj-$(CONFIG_VIRTIO_MSG_LOOPBACK) += virtio_msg_loopback.o obj-$(CONFIG_VIRTIO_MSG_FFA) += virtio_msg_ffa.o obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
drivers/virtio/virtio_msg_loopback.c new file +323 -0
323 lines not on this page · raw message
include/uapi/linux/virtio_msg_lb.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* +* Virtio message Loopback bus header. +* +* Copyright (C) 2025 Google LLC and Linaro. +* Viresh Kumar <[email protected]> +*/ + +#ifndef _LINUX_VIRTIO_MSG_LB_H +#define _LINUX_VIRTIO_MSG_LB_H + +struct vmsg_lb_dev_info { +unsigned int dev_id; +}; + +#define IOCTL_VMSG_LB_ADD \ + _IOC(_IOC_NONE, 'P', 0, sizeof(struct vmsg_lb_dev_info)) + +#define IOCTL_VMSG_LB_REMOVE \ + _IOC(_IOC_NONE, 'P', 1, sizeof(struct vmsg_lb_dev_info)) + +#endif /* _LINUX_VIRTIO_MSG_LB_H */
Signature · 1 line
2.31.1.272.g89b43f80a514
Re: [RFC PATCH 2/6] of: reserved-memory: Add of_reserved_mem_lookup_by_name
In reply to Viresh KumarQuoted 1 line · Viresh Kumar
This adds
of_reserved_mem_lookup_by_name()helper to get a
Add...
Quoted 5 lines
drivers/of/of_reserved_mem.c +4
-0+/** +* of_reserved_mem_lookup_by_name() - acquire reserved_mem from node name +* @name: node name +*
drivers/of/of_reserved_mem.c struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) · line 774
Quoted 10 lines
drivers/of/of_reserved_mem.c +10
-0+* This function allows drivers to acquire a reference to the reserved_mem +* struct based on a reserved-memory node name. +* +* Returns a reserved_mem reference, or NULL on error. +*/ +struct reserved_mem *of_reserved_mem_lookup_by_name (const char *name) +{ + struct device_node *np __free(device_node) = +of_find_node_by_path ("/reserved-memory" ); + struct device_node *child __free(device_node) = NULL;
This should not be NULL or this should not be cleanup. Follow coding style for cleanup - constructor must be real here. You probably wanted scoped loop below.
drivers/of/of_reserved_mem.c struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) · line 779
Quoted 5 lines
drivers/of/of_reserved_mem.c +5
-0+ +if (!np) +return ERR_PTR (-ENODEV ); + +for_each_child_of_node (np, child) {
Best regards,
Krzysztof
Re: [RFC PATCH 6/6] virtio-msg: Add support for loopback bus
In reply to Viresh KumarQuoted 6 lines · Viresh Kumar
Add a loopback bus implementation for the virtio-msg transport.
This bus simulates a backend that echoes messages to itself, allowing testing and development of virtio-msg without requiring an actual remote backend or transport hardware.
Quoted 6 lines
The loopback bus requires a reserved memory region for its operation. All DMA-coherent and streaming DMA allocations are restricted to this region, enabling safe mapping into user space and helping validate the memory-sharing model.
The reserved-memory region must be named "vmsglb" in the device tree.
No, because I can name regions how I wish. You cannot add undocumented ABI and claim in commit msg, that the commit msg is the ABI.
Either you have ABI documented or you cannot rely on implicit ABI, thus remove above restriction.
This is really poor choice to add such hidden ABI and it already broke several users in the past.
Best regards,
Krzysztof
Re: [RFC PATCH 2/6] of: reserved-memory: Add of_reserved_mem_lookup_by_name
In reply to Krzysztof KozlowskiQuoted 5 lines · Krzysztof Kozlowski
drivers/of/of_reserved_mem.c struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) · line 774
Quoted 1 line · Viresh Kumar
drivers/of/of_reserved_mem.c +1
-0+ struct device_node *child __free(device_node) = NULL;This should not be NULL or this should not be cleanup. Follow coding style for cleanup - constructor must be real here.
I may have misunderstood how cleanup works, but this is what I thought:
The cleanup is defined in of.h as:
DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T))
Doesn't this mean that it handles the case where child is NULL, by not calling of_node_put() ? So it should either be a valid constructor or NULL and not some stale value.
Quoted 1 line
You probably wanted scoped loop below.
Ahh, didn't realize we have that available.
Signature · 1 line
viresh
Re: [RFC PATCH 2/6] of: reserved-memory: Add of_reserved_mem_lookup_by_name
Quoted 10 lines · Viresh Kumar
Quoted 5 lines · Krzysztof Kozlowski
drivers/of/of_reserved_mem.c struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) · line 774
Quoted 1 line · Viresh Kumar
drivers/of/of_reserved_mem.c +1
-0+ struct device_node *child __free(device_node) = NULL;This should not be NULL or this should not be cleanup. Follow coding style for cleanup - constructor must be real here.
I may have misunderstood how cleanup works, but this is what I thought:
Quoted 8 lines
The cleanup is defined in
of.has:
DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T))Doesn't this mean that it handles the case where
childis NULL, by not callingof_node_put()? So it should either be a valid constructor or NULL and not some stale value.
I am speaking about coding style. It's explicitly requested to use only the full constructor syntax (see long time Linus' remark or just read cleanup.h docs).
NULL is allowed in certain cases, but the code here does not look like needing it in the first place.
Best regards,
Krzysztof
Rob Herring
maintainerQuoted 19 lines · Viresh Kumar
Hello,
This RFC series introduces support for a new Virtio transport type:
"virtio-msg", as proposed in [1]. Unlike existing transport types like virtio-mmio or virtio-pci, which rely on memory-mapped registers, virtio-msg implements transport operations via structured messages. Those messages can be transported through different mechanisms such as mailboxes, shared memory based FIFO or specific protocols such as FF-A on Arm.This series includes:
- Core virtio-msg transport support.
- Two message transport bus implementations:
- virtio-msg-ffa: based on ARM's Firmware Framework for Arm (FF-A).
- virtio-msg-loopback: a loopback device for testing and validation.The code is available here for reference: [2] and virtio-msg loopback and FF-A test setups are explained here: [3] and [4].
Quoted 8 lines
This series is based on v6.16 and depends on commit [5].
### Memory Mapping and Reserved Memory Usage
The first two patches enhance the reserved-memory subsystem to support attaching struct device`s that do not originate from DT nodes — essential for virtual or dynamically discovered devices like the FF-A or loopback buses.
We support creating devices from reserved-memory nodes. Just add a compatible which you should do anyways because node names are not supposed to be that specific or an ABI.
Rob
Re: [RFC PATCH 2/6] of: reserved-memory: Add of_reserved_mem_lookup_by_name
In reply to Krzysztof KozlowskiQuoted 3 lines · Krzysztof Kozlowski
I am speaking about coding style. It's explicitly requested to use only the full constructor syntax (see long time Linus' remark or just read
cleanup.hdocs).
Ahh, I wasn't aware of the interdependency problem. Thanks.
Signature · 1 line
viresh
Hi Rob,
Quoted 8 lines · Rob Herring
Quoted 5 lines · Viresh Kumar
### Memory Mapping and Reserved Memory Usage
The first two patches enhance the reserved-memory subsystem to support attaching struct device`s that do not originate from DT nodes — essential for virtual or dynamically discovered devices like the FF-A or loopback buses.
We support creating devices from reserved-memory nodes.
I didn't know about this.
Quoted 3 lines
Just add a
compatible which you should do anyways because node names are not supposed to be that specific or an ABI.
Yeah, I already knew that the node-names thing isn't going to fly as you and Krzysztof rightly pointed out. I just wanted inputs from you guys and so did that as a first implementation to get the discussion started.
I tried something like this now:
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
ranges;
rmem@100000000 {
compatible = "restricted-dma-pool", "virtio-msg,loopback";
reg = <0x00000001 0x00000000 0x0 0x00400000>; /* 4 MiB */
};
};and this works fine. I am adding two compatibles for virtio-msg:
"virtio-msg,loopback" and "virtio-msg,ffa". Yes I will properly document them in the next version.
With this, we don't need the 2nd patch anymore:
of: reserved-memory: Add of_reserved_mem_lookup_by_name
but still need the 1st one:
of: reserved-memory: Add reserved_mem_device_init()
Thanks.
Signature · 1 line
viresh
Rob Herring
maintainerQuoted 26 lines · Viresh Kumar
Hi Rob,
Quoted 8 lines · Rob Herring
Quoted 5 lines · Viresh Kumar
### Memory Mapping and Reserved Memory Usage
The first two patches enhance the reserved-memory subsystem to support attaching struct device`s that do not originate from DT nodes — essential for virtual or dynamically discovered devices like the FF-A or loopback buses.
We support creating devices from reserved-memory nodes.
I didn't know about this.
Quoted 3 lines
Just add a
compatible which you should do anyways because node names are not supposed to be that specific or an ABI.Yeah, I already knew that the node-names thing isn't going to fly as you and Krzysztof rightly pointed out. I just wanted inputs from you guys and so did that as a first implementation to get the discussion started.
I tried something like this now:
Quoted 7 lines
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
ranges;
rmem@100000000 {
compatible = "restricted-dma-pool", "virtio-msg,loopback";The order is wrong here. The 2nd one seems more specific to me. But is "restricted-dma-pool" useful? Should an OS that only understands that and not "virtio-msg,loopback" use it?
The format of compatibles is <vendor>,<device/block/interface> and "virtio-msg" is not a vendor.
Quoted 7 lines
reg = <0x00000001 0x00000000 0x0 0x00400000>; /* 4 MiB */ }; };and this works fine. I am adding two compatibles for virtio-msg:
"virtio-msg,loopback" and "virtio-msg,ffa". Yes I will properly document them in the next version.
Why do you need 2 compatibles? Can't you discover what the remote end is with some message? We only define "virtio-mmio" in DT for example, not that the device is a console, rng, etc.
Rob
Quoted 8 lines · Rob Herring
Quoted 7 lines · Viresh Kumar
I tried something like this now:
reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges;
Quoted 4 lines
Quoted 2 lines
rmem@100000000 { compatible = "restricted-dma-pool", "virtio-msg,loopback";The order is wrong here. The 2nd one seems more specific to me.
Right.
Quoted 1 line
But is "restricted-dma-pool" useful?
I need this to call kernel/dma/swiotlb.c: rmem_swiotlb_setup(), which makes all the memory allocation for the device happen from that area.
Quoted 2 lines
Should an OS that only understands that and not
"virtio-msg,loopback" use it?
Since the reserved memory isn't linked to a device in the DT (via the "memory-region" property), I don't expect an OS to use it without virtio-msg.
Quoted 2 lines
The format of compatibles is <vendor>,<device/block/interface> and "virtio-msg" is not a vendor.
"virtio,msg" is fine then I guess ? Just like "virtio,mmio".
Quoted 11 lines
Quoted 7 lines
reg = <0x00000001 0x00000000 0x0 0x00400000>; /* 4 MiB */ }; };and this works fine. I am adding two compatibles for virtio-msg:
"virtio-msg,loopback" and "virtio-msg,ffa". Yes I will properly document them in the next version.Why do you need 2 compatibles? Can't you discover what the remote end is with some message? We only define "virtio-mmio" in DT for example, not that the device is a console, rng, etc.
In case of virtio-mmio, the reg-range is trapped by the other side and meaningful MMIO messages are exchanged. And so the OS knows the kind of device the DT node is related to.
In this case however, this memory is going to be used for virtqueues and buffers and I don't see a way of communicating the device type here. Maybe I can get rid of two compatibles and add a property that links to a device type ? The memory is otherwise exactly same in both the cases, it is just about which device is using it eventually.
Signature · 1 line
viresh