docs: vhost-user: Add custom memory mapping support
Resend - for some reason my email didn't make it out.
----- Forwarded message from Stefan Hajnoczi <[email protected]> -----
Date: Tue, 21 Feb 2023 10:17:01 -0500
From: Stefan Hajnoczi <[email protected]>
To: Viresh Kumar <[email protected]>
Cc: [email protected], [email protected], "Michael S. Tsirkin" <[email protected]>, Vincent Guittot <[email protected]>, Alex Bennée <[email protected]>,
[email protected], Oleksandr Tyshchenko <[email protected]>, [email protected], Andrew Cooper <[email protected]>, Juergen Gross <[email protected]>, Sebastien Boeuf <[email protected]>, Liu Jiang <[email protected]>, Mathieu Poirier <[email protected]>
Subject: Re: [virtio-dev] [RFC QEMU] docs: vhost-user: Add custom memory mapping support
Message-ID: <Y/TgbZLY894p4a1S@fedora>
Quoted 20 lines · Viresh Kumar
The current model of memory mapping at the back-end works fine with Qemu, where a standard call to
mmap()for the respective file descriptor, passed from front-end, is generally all we need to do before the front-end can start accessing the guest memory.There are other complex cases though, where we need more information at the backend and need to do more than just an
mmap()call. For example, Xen, a type-1 hypervisor, currently supports memory mapping via two different methods, foreign-mapping (via/dev/privcmd) and grant-dev (via/dev/gntdev). In both these cases, the back-end needs to callmmap()followed by anioctl()(or vice-versa), and need to pass extra information via theioctl(), like the Xen domain-id of the guest whose memory we are trying to map.Add a new protocol feature, '
VHOST_USER_PROTOCOL_F_CUSTOM_MMAP', which lets the back-end know about the additional memory mapping requirements. When this feature is negotiated, the front-end can send the 'VHOST_USER_CUSTOM_MMAP' message type to provide the additional information to the back-end.
Quoted 4 lines
Signed-off-by Viresh Kumar <[email protected]>--- docs/interop/vhost-user.rst | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
The alternative to an in-band approach is to configure these details out-of-band. For example, via command-line options to the vhost-user back-end:
$ my-xen-device --mapping-type=foreign-mapping --domain-id=123
I was thinking about both approaches and don't see an obvious reason to choose one or the other. What do you think?
Quoted 14 lines
docs/interop/vhost-user.rst +6
-0@@ -258,6 +258,23 @@ Inflight description :queue size: a 16-bit size of virtqueues +Custom mmap description +^^^^^^^^^^^^^^^^^^^^^^^ + ++-------+-------+ +| flags | value | ++-------+-------+
docs/interop/vhost-user.rst Inflight description · line 276
Quoted 10 lines
docs/interop/vhost-user.rst +10
-0+ +:flags: 64-bit bit field + +- Bit 0 is Xen foreign memory access flag - needs Xen foreign memory mapping. +- Bit 1 is Xen grant memory access flag - needs Xen grant memory mapping. + +:value: a 64-bit hypervisor specific value. + +- For Xen foreign or grant memory access, this is set with guest's xen domain + id.
This is highly Xen-specific. How about naming the feature XEN_MMAP instead of CUSTOM_MMAP? If someone needs to add other mmap data later, they should define their own struct instead of trying to squeeze into the same fields as Xen.
There is an assumption in this design that a single VHOST_USER_CUSTOM_MMAP message provides the information necessary for all mmaps. Are you sure the limitation that every mmap belongs to the same domain will be workable in the future?
Quoted 13 lines
docs/interop/vhost-user.rst +2
-0+ C structure -----------@@ -867,6 +884,7 @@ Protocol features #define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14 #define VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS 15 #define VHOST_USER_PROTOCOL_F_STATUS 16 + #define VHOST_USER_PROTOCOL_F_CUSTOM_MMAP 17 Front-end message types -----------------------
docs/interop/vhost-user.rst Front-end message types · line 1443
Quoted 4 lines
docs/interop/vhost-user.rst +1
-0@@ -1422,6 +1440,20 @@ Front-end message types query the back-end for its device status as defined in the Virtio specification. +``VHOST_USER_CUSTOM_MMAP``
Most vhost-user protocol messages have a verb like get/set/close/add/listen/etc. I suggest renaming this to VHOST_USER_SET_XEN_MMAP_INFO.
Quoted 24 lines
docs/interop/vhost-user.rst +13
-0+ :id: 41 + :equivalent ioctl: N/A + :request payload: Custom mmap description + :reply payload: N/A + + When the ``VHOST_USER_PROTOCOL_F_CUSTOM_MMAP`` protocol feature has been + successfully negotiated, this message is submitted by the front-end to + notify the back-end of the special memory mapping requirements, that the + back-end needs to take care of, while mapping any memory regions sent + over by the front-end. The front-end must send this message before + any memory-regions are sent to the back-end via ``VHOST_USER_SET_MEM_TABLE`` + or ``VHOST_USER_ADD_MEM_REG`` message types. + Back-end message types ----------------------Signature · 6 lines
2.31.1.272.g89b43f80a514 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
----- End forwarded message -----
Quoted 45 lines · Stefan Hajnoczi
[[PGP Signed Part:Undecided]]
Resend - for some reason my email didn't make it out.From: Stefan Hajnoczi <[email protected]>
Subject: Re: [virtio-dev] [RFC QEMU] docs: vhost-user: Add custom memory
mapping support
To: Viresh Kumar <[email protected]>
Cc: [email protected], [email protected], "Michael S.
Tsirkin" <[email protected]>, Vincent Guittot <[email protected]>, Alex Bennée <[email protected]>,
[email protected], Oleksandr Tyshchenko
<[email protected]>, [email protected], Andrew Cooper <[email protected]>, Juergen Gross <[email protected]>, Sebastien Boeuf
<[email protected]>, Liu Jiang <[email protected]>, Mathieu
Poirier <[email protected]>
Date: Tue, 21 Feb 2023 10:17:01 -0500 (1 week, 1 day, 1 hour ago)
Flags: seen, signed, personalQuoted 20 lines · Viresh Kumar
The current model of memory mapping at the back-end works fine with Qemu, where a standard call to
mmap()for the respective file descriptor, passed from front-end, is generally all we need to do before the front-end can start accessing the guest memory.There are other complex cases though, where we need more information at the backend and need to do more than just an
mmap()call. For example, Xen, a type-1 hypervisor, currently supports memory mapping via two different methods, foreign-mapping (via/dev/privcmd) and grant-dev (via/dev/gntdev). In both these cases, the back-end needs to callmmap()followed by anioctl()(or vice-versa), and need to pass extra information via theioctl(), like the Xen domain-id of the guest whose memory we are trying to map.Add a new protocol feature, '
VHOST_USER_PROTOCOL_F_CUSTOM_MMAP', which lets the back-end know about the additional memory mapping requirements. When this feature is negotiated, the front-end can send the 'VHOST_USER_CUSTOM_MMAP' message type to provide the additional information to the back-end.Quoted 4 lines
Signed-off-by Viresh Kumar <[email protected]>--- docs/interop/vhost-user.rst | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
Quoted 8 lines
The alternative to an in-band approach is to configure these details out-of-band. For example, via command-line options to the vhost-user back-end:
$ my-xen-device --mapping-type=foreign-mapping --domain-id=123I was thinking about both approaches and don't see an obvious reason to choose one or the other. What do you think?
In-band has the nice property of being dynamic and not having to have some other thing construct command lines. We are also trying to keep the daemons from being Xen specific and keep the type of mmap as an implementation detail that is mostly elided by the rust-vmm memory traits.
Quoted 22 lines
Quoted 22 lines
docs/interop/vhost-user.rst +13
-0@@ -258,6 +258,23 @@ Inflight description :queue size: a 16-bit size of virtqueues +Custom mmap description +^^^^^^^^^^^^^^^^^^^^^^^ + ++-------+-------+ +| flags | value | ++-------+-------+ + +:flags: 64-bit bit field + +- Bit 0 is Xen foreign memory access flag - needs Xen foreign memory mapping. +- Bit 1 is Xen grant memory access flag - needs Xen grant memory mapping. + +:value: a 64-bit hypervisor specific value.
Quoted 8 lines
docs/interop/vhost-user.rst Inflight description · line 276
Quoted 3 lines
docs/interop/vhost-user.rst +3
-0+ +- For Xen foreign or grant memory access, this is set with guest's xen domain + id.This is highly Xen-specific. How about naming the feature
XEN_MMAPinstead ofCUSTOM_MMAP? If someone needs to add other mmap data later, they should define their own struct instead of trying to squeeze into the same fields as Xen.
We hope to support additional mmap mechanisms in the future - one proposal is to use the hypervisor specific interface to support an ioctl() that creates a domain specific device which can then be treated more generically.
Could we not declare the message as flag + n bytes of domain specific message as defined my msglen?
Quoted 4 lines
There is an assumption in this design that a single
VHOST_USER_CUSTOM_MMAPmessage provides the information necessary for all mmaps. Are you sure the limitation that every mmap belongs to the same domain will be workable in the future?
Like a daemon servicing multiple VMs? Won't those still be separate vhost-user control channels though?
Quoted 17 lines
Quoted 17 lines
docs/interop/vhost-user.rst +2
-0+ C structure -----------@@ -867,6 +884,7 @@ Protocol features #define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14 #define VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS 15 #define VHOST_USER_PROTOCOL_F_STATUS 16 + #define VHOST_USER_PROTOCOL_F_CUSTOM_MMAP 17 Front-end message types -----------------------@@ -1422,6 +1440,20 @@ Front-end message types query the back-end for its device status as defined in the Virtio specification.
Quoted 5 lines
docs/interop/vhost-user.rst Front-end message types · line 1443
Quoted 1 line
docs/interop/vhost-user.rst +1
-0+``VHOST_USER_CUSTOM_MMAP``Most vhost-user protocol messages have a verb like get/set/close/add/listen/etc. I suggest renaming this to
VHOST_USER_SET_XEN_MMAP_INFO.
VHOST_USER_CONFIG_MMAP_QUIRKS?
VHOST_USER_CONFIG_MMAP_TYPE?
Quoted 31 lines
Quoted 25 lines
docs/interop/vhost-user.rst +13
-0+ :id: 41 + :equivalent ioctl: N/A + :request payload: Custom mmap description + :reply payload: N/A + + When the ``VHOST_USER_PROTOCOL_F_CUSTOM_MMAP`` protocol feature has been + successfully negotiated, this message is submitted by the front-end to + notify the back-end of the special memory mapping requirements, that the + back-end needs to take care of, while mapping any memory regions sent + over by the front-end. The front-end must send this message before + any memory-regions are sent to the back-end via ``VHOST_USER_SET_MEM_TABLE`` + or ``VHOST_USER_ADD_MEM_REG`` message types. + Back-end message types ----------------------Signature · 6 lines
2.31.1.272.g89b43f80a514 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]----------
[[End of PGP Signed Part]]
Signature · 6 lines
Alex Bennée Virtualisation Tech Lead @ Linaro --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Quoted 54 lines · Alex Bennée
Quoted 51 lines · Stefan Hajnoczi
[[PGP Signed Part:Undecided]]
Resend - for some reason my email didn't make it out.From: Stefan Hajnoczi <[email protected]>
Subject: Re: [virtio-dev] [RFC QEMU] docs: vhost-user: Add custom memory
mapping support
To: Viresh Kumar <[email protected]>
Cc: [email protected], [email protected], "Michael S.
Tsirkin" <[email protected]>, Vincent Guittot <[email protected]>, Alex Bennée <[email protected]>,
[email protected], Oleksandr Tyshchenko
<[email protected]>, [email protected], Andrew Cooper <[email protected]>, Juergen Gross <[email protected]>, Sebastien Boeuf
<[email protected]>, Liu Jiang <[email protected]>, Mathieu
Poirier <[email protected]>
Date: Tue, 21 Feb 2023 10:17:01 -0500 (1 week, 1 day, 1 hour ago)
Flags: seen, signed, personalQuoted 20 lines · Viresh Kumar
The current model of memory mapping at the back-end works fine with Qemu, where a standard call to
mmap()for the respective file descriptor, passed from front-end, is generally all we need to do before the front-end can start accessing the guest memory.There are other complex cases though, where we need more information at the backend and need to do more than just an
mmap()call. For example, Xen, a type-1 hypervisor, currently supports memory mapping via two different methods, foreign-mapping (via/dev/privcmd) and grant-dev (via/dev/gntdev). In both these cases, the back-end needs to callmmap()followed by anioctl()(or vice-versa), and need to pass extra information via theioctl(), like the Xen domain-id of the guest whose memory we are trying to map.Add a new protocol feature, '
VHOST_USER_PROTOCOL_F_CUSTOM_MMAP', which lets the back-end know about the additional memory mapping requirements. When this feature is negotiated, the front-end can send the 'VHOST_USER_CUSTOM_MMAP' message type to provide the additional information to the back-end.Quoted 4 lines
Signed-off-by Viresh Kumar <[email protected]>--- docs/interop/vhost-user.rst | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)The alternative to an in-band approach is to configure these details out-of-band. For example, via command-line options to the vhost-user back-end:
$ my-xen-device --mapping-type=foreign-mapping --domain-id=123
Quoted 8 lines
Quoted 2 lines
I was thinking about both approaches and don't see an obvious reason to choose one or the other. What do you think?
In-band has the nice property of being dynamic and not having to have some other thing construct command lines. We are also trying to keep the daemons from being Xen specific and keep the type of mmap as an implementation detail that is mostly elided by the rust-vmm memory traits.
Okay.
Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
docs/interop/vhost-user.rst +13
-0@@ -258,6 +258,23 @@ Inflight description :queue size: a 16-bit size of virtqueues +Custom mmap description +^^^^^^^^^^^^^^^^^^^^^^^ + ++-------+-------+ +| flags | value | ++-------+-------+ + +:flags: 64-bit bit field + +- Bit 0 is Xen foreign memory access flag - needs Xen foreign memory mapping. +- Bit 1 is Xen grant memory access flag - needs Xen grant memory mapping. + +:value: a 64-bit hypervisor specific value.Quoted 8 lines
docs/interop/vhost-user.rst Inflight description · line 276
Quoted 3 lines
docs/interop/vhost-user.rst +3
-0+ +- For Xen foreign or grant memory access, this is set with guest's xen domain + id.This is highly Xen-specific. How about naming the feature
XEN_MMAPinstead ofCUSTOM_MMAP? If someone needs to add other mmap data later, they should define their own struct instead of trying to squeeze into the same fields as Xen.
Quoted 7 lines
We hope to support additional mmap mechanisms in the future - one proposal is to use the hypervisor specific interface to support an
ioctl()that creates a domain specific device which can then be treated more generically.Could we not declare the message as flag + n bytes of domain specific message as defined my msglen?
What is the advantage over defining separate messages? Separate messages are cleaner and more typesafe.
Quoted 7 lines
Quoted 4 lines
There is an assumption in this design that a single
VHOST_USER_CUSTOM_MMAPmessage provides the information necessary for all mmaps. Are you sure the limitation that every mmap belongs to the same domain will be workable in the future?Like a daemon servicing multiple VMs? Won't those still be separate vhost-user control channels though?
I don't have a concrete example, but was thinking of a guest that shares memory with other guests (like the experimental virtio-vhost-user device). Maybe there would be a scenario where some memory belongs to one domain and some belongs to another (but has been mapped into the first domain), and the vhost-user back-end needs to access both.
The other thing that comes to mind is that the spec must clearly state which mmaps are affected by the Xen domain information. For example, just mem table memory regions and not the VHOST_USER_PROTOCOL_F_LOG_SHMFD feature?
Quoted 23 lines
Quoted 17 lines
Quoted 17 lines
docs/interop/vhost-user.rst +2
-0+ C structure -----------@@ -867,6 +884,7 @@ Protocol features #define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14 #define VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS 15 #define VHOST_USER_PROTOCOL_F_STATUS 16 + #define VHOST_USER_PROTOCOL_F_CUSTOM_MMAP 17 Front-end message types -----------------------@@ -1422,6 +1440,20 @@ Front-end message types query the back-end for its device status as defined in the Virtio specification.Quoted 5 lines
docs/interop/vhost-user.rst Front-end message types · line 1443
Quoted 1 line
docs/interop/vhost-user.rst +1
-0+``VHOST_USER_CUSTOM_MMAP``Most vhost-user protocol messages have a verb like get/set/close/add/listen/etc. I suggest renaming this to
VHOST_USER_SET_XEN_MMAP_INFO.
Quoted 3 lines
VHOST_USER_CONFIG_MMAP_QUIRKS?
VHOST_USER_CONFIG_MMAP_TYPE?
SET is the verb that's often used when the front-end provides configuration parameters to the back-end (e.g. VHOST_USER_SET_MEM_TABLE, VHOST_USER_SET_FEATURES, etc).
Stefan
Quoted 2 lines · Stefan Hajnoczi
What is the advantage over defining separate messages? Separate messages are cleaner and more typesafe.
I thought we wanted to keep single message for one kind of functionality, which is mmap related quirks here. And so it would be better if we can reuse the same for next hypervisor which may need this.
The value parameter is not fixed and is hypervisor specific, for Xen this is the domain id, for others it may mean something else.
Quoted 5 lines
I don't have a concrete example, but was thinking of a guest that shares memory with other guests (like the experimental virtio-vhost-user device). Maybe there would be a scenario where some memory belongs to one domain and some belongs to another (but has been mapped into the first domain), and the vhost-user back-end needs to access both.
These look tricky (and real) and I am not sure how we would want to handle these. Maybe wait until we have a real use-case ?
Quoted 4 lines
The other thing that comes to mind is that the spec must clearly state which mmaps are affected by the Xen domain information. For example, just mem table memory regions and not the
VHOST_USER_PROTOCOL_F_LOG_SHMFDfeature?
Maybe we can mention that only the mmap's performed via /dev/xen/privcmd and /dev/xen/gntdev files are affected by this ?
Signature · 1 line
viresh
Quoted 10 lines · Viresh Kumar
Quoted 2 lines · Stefan Hajnoczi
What is the advantage over defining separate messages? Separate messages are cleaner and more typesafe.
I thought we wanted to keep single message for one kind of functionality, which is mmap related quirks here. And so it would be better if we can reuse the same for next hypervisor which may need this.
The value parameter is not fixed and is hypervisor specific, for Xen this is the domain id, for others it may mean something else.
mmap-related quirks have no parameters or behavior in common so there's no advantage in sharing a single vhost-user protocol message. Sharing the same message just makes it awkward to build and parse the message.
Quoted 8 lines
Quoted 5 lines
I don't have a concrete example, but was thinking of a guest that shares memory with other guests (like the experimental virtio-vhost-user device). Maybe there would be a scenario where some memory belongs to one domain and some belongs to another (but has been mapped into the first domain), and the vhost-user back-end needs to access both.
These look tricky (and real) and I am not sure how we would want to handle these. Maybe wait until we have a real use-case ?
A way to deal with that is to include mmap information every time fds are passed with a message instead of sending one global message at the start of the vhost-user connection. This would allow each mmap to associate extra information instead of forcing them all to use the same information.
Quoted 7 lines
Quoted 4 lines
The other thing that comes to mind is that the spec must clearly state which mmaps are affected by the Xen domain information. For example, just mem table memory regions and not the
VHOST_USER_PROTOCOL_F_LOG_SHMFDfeature?Maybe we can mention that only the mmap's performed via
/dev/xen/privcmdand/dev/xen/gntdevfiles are affected by this ?
No, this doesn't explain when mmap must be performed via /dev/xen/privcmd and /dev/xen/gntdev. The spec should be explicit about this instead of assuming that the device implementer already knows this.
Stefan
Quoted 1 line · Stefan Hajnoczi
Resend - for some reason my email didn't make it out.
How about this (will send a formal patch later).
Author: Viresh Kumar <[email protected]> Date: Tue Feb 21 14:36:30 2023 +0530
docs: vhost-user: Add Xen specific memory mapping support
The current model of memory mapping at the back-end works fine where a standard call to mmap() (for the respective file descriptor) is enough before the front-end can start accessing the guest memory.
There are other complex cases though where the back-end needs more information and simple mmap() isn't enough. For example Xen, a type-1 hypervisor, currently supports memory mapping via two different methods, foreign-mapping (via /dev/privcmd) and grant-dev (via /dev/gntdev). In both these cases, the back-end needs to call mmap() and ioctl(), and need to pass extra information via the ioctl(), like the Xen domain-id of the guest whose memory we are trying to map.
Add a new protocol feature, 'VHOST_USER_PROTOCOL_F_XEN_MMAP', which lets the back-end know about the additional memory mapping requirements. When this feature is negotiated, the front-end can send the 'VHOST_USER_SET_XEN_MMAP' message type to provide the additional information to the back-end.
--- docs/interop/vhost-user.rst | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
docs/interop/vhost-user.rst +36 -0
@@ -258,6 +258,24 @@ Inflight description :queue size: a 16-bit size of virtqueues +Xen mmap description +^^^^^^^^^^^^^^^^^^^^ + ++-------+-------+ +| flags | domid | ++-------+-------+ + +:flags: 64-bit bit field + +- Bit 0 is set for Xen foreign memory memory mapping. +- Bit 1 is set for Xen grant memory memory mapping. +- Bit 2 is set if the back-end can directly map additional memory (like + descriptor buffers or indirect descriptors, which aren't part of already + shared memory regions) without the need of front-end sending an additional + memory region first. + +:domid: a 64-bit Xen hypervisor specific domain id. + C structure -----------
@@ -867,6 +885,7 @@ Protocol features #define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14 #define VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS 15 #define VHOST_USER_PROTOCOL_F_STATUS 16 + #define VHOST_USER_PROTOCOL_F_XEN_MMAP 17 Front-end message types -----------------------
@@ -1422,6 +1441,23 @@ Front-end message types query the back-end for its device status as defined in the Virtio specification. +``VHOST_USER_SET_XEN_MMAP`` + :id: 41 + :equivalent ioctl: N/A + :request payload: Xen mmap description + :reply payload: N/A + + When the ``VHOST_USER_PROTOCOL_F_XEN_MMAP`` protocol feature has been + successfully negotiated, this message is submitted by the front-end to set the + Xen hypervisor specific memory mapping configurations at the back-end. These + configurations should be used to mmap memory regions, virtqueues, descriptors + and descriptor buffers. The front-end must send this message before any + memory-regions are sent to the back-end via ``VHOST_USER_SET_MEM_TABLE`` or + ``VHOST_USER_ADD_MEM_REG`` message types. The front-end can send this message + multiple times, if different mmap configurations are required for different + memory regions, where the most recent ``VHOST_USER_SET_XEN_MMAP`` must be used + by the back-end to map any newly shared memory regions. + Back-end message types ----------------------
Signature · 5 lines
viresh --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]