shared-mem: introduce page alignment restrictions
v2 cover shared-mem: introduce page alignment restrictions
There's an incresing number of machines supporting multiple page sizes and, on these machines, the host and a guest can be running with different pages sizes.
In addition to this, there might be devices that have a required and/or preferred page size for mapping memory.
In this series we extend the "Shared Memory Regions" with a subsection explaining the posible existence of page alignment restrictions.
For the device to provide the page size information to the driver, we need to extend the PCI and MMIO transports. For the former, we borrow 8 bits from the 16 bit padding in virtio_pci_cap to hold a page_shift field which can be used to derive the page size by using the following
formula: (page_size = 1 << (page_shift + 12)).
For MMIO, we add a the SHMPageShift register at offset 0x0c4, also holding the page_shift value. Since MMIO registers are 32 bit wide, we could have asked the device to directly provide page_size instead of page_shift, but seems reasonable to be consistent across transports.
An implementation of the changes proposed in this series has been published as an RFC to the LKML, to be used as a reference:
https://lore.kernel.org/all/[email protected]/
v2:
- Remove the VIRTIO_F_SHM_PAGE_SIZE feature bit, exposing page_shift in the transports unconditionally (thanks Parav Pandit).
- Didn't pick up R-b due to the significant change between revisions.
Sergio Lopez (3):
shared-mem: introduce page alignment restrictions
transport-pci: introduce page_shift field for SHM
transport-mmio: introduce SHMPageShift register
shared-mem.tex | 6 ++++++ transport-mmio.tex | 8 ++++++++ transport-pci.tex | 10 +++++++++- 3 files changed, 23 insertions(+), 1 deletion(-)
Signature · 1 line
2.49.0
PATCH v2 1/3 shared-mem: introduce page alignment restrictions
Add a subsection for page alignment restrictions.
--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)
shared-mem.tex +6 -0
@@ -34,6 +34,12 @@ \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the reference. +\subsection{Page alignment restrictions}\label{sec:Basic Facilities of a Virtio Device / Shared Memory Regions / Page alignment restrictions} + +When requesting the device to map memory into a shared memory region +the driver MUST obtain the page size information from the transport +and honor the page alignment constrains derived from that page size. + \devicenormative{\subsection}{Shared Memory Regions}{Basic Facilities of a Virtio Device / Shared Memory Regions} Shared memory regions MUST NOT expose shared memory regions which
Signature · 1 line
2.49.0
Quoted 12 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)shared-mem.tex +0
-0
shared-mem.tex \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De · line 42
Quoted 9 lines
shared-mem.tex +6
-0@@ -34,6 +34,12 @@ \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the reference. +\subsection{Page alignment restrictions}\label{sec:Basic Facilities of a Virtio Device / Shared Memory Regions / Page alignment restrictions} + +When requesting the device to map memory into a shared memory region +the driver MUST obtain the page size information from the transport +and honor the page alignment constrains derived from that page size. +
will make existing drivers autmatically incompliant with new devices.
we generally avoid things like this.
Quoted 5 lines
shared-mem.tex +0
-0\devicenormative{\subsection}{Shared Memory Regions}{Basic Facilities of a Virtio Device / Shared Memory Regions} Shared memory regions MUST NOT expose shared memory regions whichSignature · 1 line
2.49.0
Quoted 25 lines · Michael S. Tsirkin
Quoted 12 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)shared-mem.tex +0
-0shared-mem.tex \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De · line 42
Quoted 9 lines
shared-mem.tex +6
-0@@ -34,6 +34,12 @@ \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the reference. +\subsection{Page alignment restrictions}\label{sec:Basic Facilities of a Virtio Device / Shared Memory Regions / Page alignment restrictions} + +When requesting the device to map memory into a shared memory region +the driver MUST obtain the page size information from the transport +and honor the page alignment constrains derived from that page size. +will make existing drivers autmatically incompliant with new devices.
Quoted 1 line
we generally avoid things like this.
This is the reason why in v1 this was gated behind VIRTIO_F_SHM_PAGE_SIZE. But from the discussion on that thread, I understood that, at least for the PCI transport, it was preferred to have the page_shift field unconditionally:
Did I misunderstand the conclusions?
Sergio.
Quoted 34 lines · Sergio Lopez Pascual
Quoted 25 lines · Michael S. Tsirkin
Quoted 12 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)shared-mem.tex +0
-0shared-mem.tex \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De · line 42
Quoted 9 lines
shared-mem.tex +6
-0@@ -34,6 +34,12 @@ \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the reference. +\subsection{Page alignment restrictions}\label{sec:Basic Facilities of a Virtio Device / Shared Memory Regions / Page alignment restrictions} + +When requesting the device to map memory into a shared memory region +the driver MUST obtain the page size information from the transport +and honor the page alignment constrains derived from that page size. +will make existing drivers autmatically incompliant with new devices.
Quoted 1 line
we generally avoid things like this.
This is the reason why in v1 this was gated behind
VIRTIO_F_SHM_PAGE_SIZE. But from the discussion on that thread, I understood that, at least for the PCI transport, it was preferred to have thepage_shiftfield unconditionally:
Quoted 5 lines
Did I misunderstand the conclusions?
Sergio.
I think Parav missed this compatibility implication when he said:
So to obtain a free information, feature bit is not necessary, this can be self- described in the pci capability itself.
Parav, this is about the MUST requirement referring to honoring alignment, not about obtaining the information which indeed can be done without.
Signature · 1 line
MST
Quoted 51 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 2:45 PMQuoted 10 lines · Sergio Lopez Pascual
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
shared-mem.tex index 6e6f6c4..2021083 renamed from shared-mem.tex +0
-0100644
shared-mem.tex +0
-0@@ -34,6 +34,12 @@ \subsection{Addressing withinregions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the
reference.
Quoted 8 lines
Quoted 8 lines
shared-mem.tex
Quoted 8 lines
+\subsection{Page alignment restrictions}\label{sec:Basic
shared-mem.tex +6
-0+Facilities of a Virtio Device / Shared Memory Regions / Page +alignment restrictions} + +When requesting the device to map memory into a shared memory +region the driver MUST obtain the page size information from the +transport and honor the page alignment constrains derived from thatpage size.
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
will make existing drivers autmatically incompliant with new devices.
Quoted 8 lines
Quoted 1 line
we generally avoid things like this.
This is the reason why in v1 this was gated behind
VIRTIO_F_SHM_PAGE_SIZE. But from the discussion on that thread, I understood that, at least for the PCI transport, it was preferred to have thepage_shiftfield unconditionally:comment/CY8PR12MB71950314C5683EB7CFF081
Quoted 5 lines
Did I misunderstand the conclusions?
Sergio.
Quoted 9 lines
I think Parav missed this compatibility implication when he said:
So to obtain a free information, feature bit is not necessary, this can
be self-
described in the pci capability itself.Parav, this is about the MUST requirement referring to honoring alignment, not about obtaining the information which indeed can be done without.
It can't be MUST requirement as it breaks the driver which will not negotiate this feature bit.
So my understanding is, the device indicates one or multiple alignments it supports and driver can choose which alignment it wants to use to get better performance.
Quoted 56 lines · Parav Pandit
Quoted 56 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 2:45 PMQuoted 10 lines · Sergio Lopez Pascual
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
shared-mem.tex index 6e6f6c4..2021083 renamed from shared-mem.tex +0
-0100644
shared-mem.tex +0
-0@@ -34,6 +34,12 @@ \subsection{Addressing withinregions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the
reference.
Quoted 8 lines
Quoted 8 lines
shared-mem.tex
Quoted 8 lines
+\subsection{Page alignment restrictions}\label{sec:Basic
shared-mem.tex +6
-0+Facilities of a Virtio Device / Shared Memory Regions / Page +alignment restrictions} + +When requesting the device to map memory into a shared memory +region the driver MUST obtain the page size information from the +transport and honor the page alignment constrains derived from thatpage size.
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
will make existing drivers autmatically incompliant with new devices.
Quoted 8 lines
Quoted 1 line
we generally avoid things like this.
This is the reason why in v1 this was gated behind
VIRTIO_F_SHM_PAGE_SIZE. But from the discussion on that thread, I understood that, at least for the PCI transport, it was preferred to have thepage_shiftfield unconditionally:comment/CY8PR12MB71950314C5683EB7CFF081
Quoted 5 lines
Did I misunderstand the conclusions?
Sergio.
I think Parav missed this compatibility implication when he said:
So to obtain a free information, feature bit is not necessary, this can
be self-
described in the pci capability itself.
Quoted 5 lines
Quoted 3 lines
Parav, this is about the MUST requirement referring to honoring alignment, not about obtaining the information which indeed can be done without.
It can't be MUST requirement as it breaks the driver which will not negotiate this feature bit.
So my understanding is, the device indicates one or multiple alignments it supports and driver can choose which alignment it wants to use to get better performance.
Not exactly. The device indicates its supported page size (just one), which implies the driver needs to honor the alignment restrictions derived from that page size.
Just to clarify, this is not a performance improvement. Today, there are devices (i.e. virtio-gpu) that doesn't work when the host (device) is running with on a system with a bigger page size than the guest (driver).
Thanks,
Sergio.
Quoted 69 lines
From: Sergio Lopez Pascual <[email protected]>
Sent: Tuesday, April 1, 2025 3:04 PMQuoted 53 lines · Parav Pandit
Quoted 53 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 2:45 PMQuoted 10 lines · Sergio Lopez Pascual
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
shared-mem.tex index renamed from shared-mem.tex +0
-06e6f6c4..2021083
100644shared-mem.tex +0
-0@@ -34,6 +34,12 @@ \subsection{Addressing withinregions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the
reference.
Quoted 9 lines
Quoted 9 lines
shared-mem.tex
Quoted 9 lines
+\subsection{Page alignment restrictions}\label{sec:Basic
shared-mem.tex +7
-0+Facilities of a Virtio Device / Shared Memory Regions / Page +alignment restrictions} + +When requesting the device to map memory into a shared memory +region the driver MUST obtain the page size information from +the transport and honor the page alignment constrains derived +from thatpage size.
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
will make existing drivers autmatically incompliant with new devices.
Quoted 8 lines
Quoted 1 line
we generally avoid things like this.
This is the reason why in v1 this was gated behind
VIRTIO_F_SHM_PAGE_SIZE. But from the discussion on that thread, I understood that, at least for the PCI transport, it was preferred to have thepage_shiftfield unconditionally:comment/CY8PR12MB71950314C5683EB7CFF081
Quoted 5 lines
Did I misunderstand the conclusions?
Sergio.
Quoted 8 lines
Quoted 8 lines
I think Parav missed this compatibility implication when he said:
So to obtain a free information, feature bit is not necessary, this
can be self-
described in the pci capability itself.Parav, this is about the MUST requirement referring to honoring alignment, not about obtaining the information which indeed can be done
without.
Quoted 2 lines
Quoted 1 line
It can't be MUST requirement as it breaks the driver which will not negotiate
Quoted 9 lines
this feature bit.
Quoted 1 line
So my understanding is, the device indicates one or multiple alignments it
supports and driver can choose which alignment it wants to use to get better performance.
Not exactly. The device indicates its supported page size (just one), which implies the driver needs to honor the alignment restrictions derived from that page size.
A device may not know on which OS flavor or which cpu flavor it may run.
So it is better for the device to expose multiple supported page sizes alignment and driver can choose one configured on the driver side. Keep in mind that often device != host (device can be actual device too).
When the driver page size is bigger, it can always align to the smaller page size told by the device, no?
Quoted 6 lines
Just to clarify, this is not a performance improvement. Today, there are devices (i.e. virtio-gpu) that doesn't work when the host (device) is running with on a system with a bigger page size than the guest (driver).
Thanks,
Sergio.
Quoted 74 lines · Parav Pandit
Quoted 74 lines
From: Sergio Lopez Pascual <[email protected]>
Sent: Tuesday, April 1, 2025 3:04 PMQuoted 53 lines · Parav Pandit
Quoted 53 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 2:45 PMQuoted 10 lines · Sergio Lopez Pascual
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
shared-mem.tex index renamed from shared-mem.tex +0
-06e6f6c4..2021083
100644shared-mem.tex +0
-0@@ -34,6 +34,12 @@ \subsection{Addressing withinregions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the
reference.
Quoted 9 lines
Quoted 9 lines
shared-mem.tex
Quoted 9 lines
+\subsection{Page alignment restrictions}\label{sec:Basic
shared-mem.tex +7
-0+Facilities of a Virtio Device / Shared Memory Regions / Page +alignment restrictions} + +When requesting the device to map memory into a shared memory +region the driver MUST obtain the page size information from +the transport and honor the page alignment constrains derived +from thatpage size.
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
will make existing drivers autmatically incompliant with new devices.
Quoted 8 lines
Quoted 1 line
we generally avoid things like this.
This is the reason why in v1 this was gated behind
VIRTIO_F_SHM_PAGE_SIZE. But from the discussion on that thread, I understood that, at least for the PCI transport, it was preferred to have thepage_shiftfield unconditionally:comment/CY8PR12MB71950314C5683EB7CFF081
Quoted 5 lines
Did I misunderstand the conclusions?
Sergio.
Quoted 8 lines
Quoted 8 lines
I think Parav missed this compatibility implication when he said:
So to obtain a free information, feature bit is not necessary, this
can be self-
described in the pci capability itself.Parav, this is about the MUST requirement referring to honoring alignment, not about obtaining the information which indeed can be done
without.
Quoted 2 lines
Quoted 1 line
It can't be MUST requirement as it breaks the driver which will not negotiate
this feature bit.
Quoted 1 line
So my understanding is, the device indicates one or multiple alignments it
supports and driver can choose which alignment it wants to use to get better performance.
Quoted 6 lines
Quoted 4 lines
Not exactly. The device indicates its supported page size (just one), which implies the driver needs to honor the alignment restrictions derived from that page size.
A device may not know on which OS flavor or which cpu flavor it may run.
So it is better for the device to expose multiple supported page sizes alignment and driver can choose one configured on the driver side.
I doubt it's a thing though. Device has minimal alignment it can support and that's it. What are "multiple page sizes" and why would device care?
Quoted 3 lines
Keep in mind that often device != host (device can be actual device too).
When the driver page size is bigger, it can always align to the smaller page size told by the device, no?
What if it's smaller?
Quoted 7 lines
Quoted 6 lines
Just to clarify, this is not a performance improvement. Today, there are devices (i.e. virtio-gpu) that doesn't work when the host (device) is running with on a system with a bigger page size than the guest (driver).
Thanks,
Sergio.
Quoted 88 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 3:48 PMQuoted 9 lines · Parav Pandit
Quoted 9 lines
From: Sergio Lopez Pascual <[email protected]>
Sent: Tuesday, April 1, 2025 3:04 PMQuoted 4 lines · Parav Pandit
Quoted 4 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 2:45 PMOn Mon, Mar 31, 2025 at 09:40:37AM -0700, Sergio Lopez Pascual
Quoted 30 lines · wrote:
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 10 lines
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
shared-mem.tex index renamed from shared-mem.tex +0
-06e6f6c4..2021083
100644shared-mem.tex +0
-0@@ -34,6 +34,12 @@ \subsection{Addressing withinregions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the
reference.
Quoted 9 lines
Quoted 9 lines
shared-mem.tex
Quoted 9 lines
+\subsection{Page alignment restrictions}\label{sec:Basic
shared-mem.tex +7
-0+Facilities of a Virtio Device / Shared Memory Regions / +Page alignment restrictions} + +When requesting the device to map memory into a shared +memory region the driver MUST obtain the page size +information from the transport and honor the page alignment +constrains derived from thatpage size.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
will make existing drivers autmatically incompliant with new
devices.
Quoted 39 lines
Quoted 39 lines
Quoted 18 lines
Quoted 18 lines
Quoted 9 lines
Quoted 2 lines
we generally avoid things like this.
This is the reason why in v1 this was gated behind
VIRTIO_F_SHM_PAGE_SIZE. But from the discussion on that thread, I understood that, at least for the PCI transport, it was preferred to have thepage_shiftfield unconditionally:comment/CY8PR12MB71950314C5683EB7CFF081
Quoted 5 lines
Did I misunderstand the conclusions?
Sergio.
I think Parav missed this compatibility implication when he said:
Quoted 7 lines
Quoted 7 lines
So to obtain a free information, feature bit is not necessary,
this can be self-
described in the pci capability itself.Parav, this is about the MUST requirement referring to honoring alignment, not about obtaining the information which indeed can be done
without.
Quoted 3 lines
Quoted 1 line
It can't be MUST requirement as it breaks the driver which will not negotiate
this feature bit.
Quoted 2 lines
So my understanding is, the device indicates one or multiple alignments it
supports and driver can choose which alignment it wants to use to get better performance.
Not exactly. The device indicates its supported page size (just one), which implies the driver needs to honor the alignment restrictions derived from that page size.
Quoted 7 lines
Quoted 2 lines
A device may not know on which OS flavor or which cpu flavor it may run. So it is better for the device to expose multiple supported page sizes
alignment and driver can choose one configured on the driver side.
I doubt it's a thing though. Device has minimal alignment it can support and that's it. What are "multiple page sizes" and why would device care?
Since Sergio posted v3, I replied to the latest patches.
I am bit confused on what exactly is the problem and how this solves the problem. I asked him in v3.
Quoted 8 lines
Quoted 4 lines
Keep in mind that often device != host (device can be actual device too).
When the driver page size is bigger, it can always align to the smaller page
size told by the device, no?
What if it's smaller?
I assume you meant, driver page size is smaller than device. If so, it can access the bigger pages of the device.
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Just to clarify, this is not a performance improvement. Today, there are devices (i.e. virtio-gpu) that doesn't work when the host (device) is running with on a system with a bigger page size than the guest
(driver).
Quoted 4 lines
Quoted 3 lines
Thanks,
Sergio.
Quoted 41 lines · Michael S. Tsirkin
Quoted 34 lines · Sergio Lopez Pascual
Quoted 25 lines · Michael S. Tsirkin
Quoted 12 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)shared-mem.tex +0
-0shared-mem.tex \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De · line 42
Quoted 9 lines
shared-mem.tex +6
-0@@ -34,6 +34,12 @@ \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the reference. +\subsection{Page alignment restrictions}\label{sec:Basic Facilities of a Virtio Device / Shared Memory Regions / Page alignment restrictions} + +When requesting the device to map memory into a shared memory region +the driver MUST obtain the page size information from the transport +and honor the page alignment constrains derived from that page size. +will make existing drivers autmatically incompliant with new devices.
Quoted 1 line
we generally avoid things like this.
This is the reason why in v1 this was gated behind
VIRTIO_F_SHM_PAGE_SIZE. But from the discussion on that thread, I understood that, at least for the PCI transport, it was preferred to have thepage_shiftfield unconditionally:Quoted 5 lines
Did I misunderstand the conclusions?
Sergio.
Quoted 8 lines
I think Parav missed this compatibility implication when he said:
So to obtain a free information, feature bit is not necessary, this can be self- described in the pci capability itself.
Parav, this is about the MUST requirement referring to honoring alignment, not about obtaining the information which indeed can be done without.
Would it be reasonable to expose page_shift in the transports unconditionally but only require drivers to honor the page alignment restrictions if VIRTIO_F_SHM_PAGE_SIZE has been negotiated?
Personally, from a device/driver implementator PoV, I'd prefer to have everything (the page_shift field in PCI, the SHMPageShift register in MMIO and the requirement to honor page alignment) gated behind VIRTIO_F_SHM_PAGE_SIZE, but if there's a reason to prefer the approach mentioned above, I'm fine with it.
Thanks,
Sergio.
Quoted 56 lines · Sergio Lopez Pascual
Quoted 41 lines · Michael S. Tsirkin
Quoted 34 lines · Sergio Lopez Pascual
Quoted 25 lines · Michael S. Tsirkin
Quoted 12 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)shared-mem.tex +0
-0shared-mem.tex \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De · line 42
Quoted 9 lines
shared-mem.tex +6
-0@@ -34,6 +34,12 @@ \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the reference. +\subsection{Page alignment restrictions}\label{sec:Basic Facilities of a Virtio Device / Shared Memory Regions / Page alignment restrictions} + +When requesting the device to map memory into a shared memory region +the driver MUST obtain the page size information from the transport +and honor the page alignment constrains derived from that page size. +will make existing drivers autmatically incompliant with new devices.
Quoted 1 line
we generally avoid things like this.
This is the reason why in v1 this was gated behind
VIRTIO_F_SHM_PAGE_SIZE. But from the discussion on that thread, I understood that, at least for the PCI transport, it was preferred to have thepage_shiftfield unconditionally:Quoted 5 lines
Did I misunderstand the conclusions?
Sergio.
Quoted 8 lines
I think Parav missed this compatibility implication when he said:
So to obtain a free information, feature bit is not necessary, this can be self- described in the pci capability itself.
Parav, this is about the MUST requirement referring to honoring alignment, not about obtaining the information which indeed can be done without.
Would it be reasonable to expose
page_shiftin the transports unconditionally but only require drivers to honor the page alignment restrictions ifVIRTIO_F_SHM_PAGE_SIZEhas been negotiated?
Quoted 8 lines
Personally, from a device/driver implementator PoV, I'd prefer to have everything (the
page_shiftfield in PCI, the SHMPageShift register in MMIO and the requirement to honor page alignment) gated behindVIRTIO_F_SHM_PAGE_SIZE, but if there's a reason to prefer the approach mentioned above, I'm fine with it.Thanks,
Sergio.
It's unclear when is it ok to access the field then, or what is the value if accessed when feature bit is not negotiated. On this I think I agree it is easier to just have it there unconditionally.
Signature · 1 line
MST
Quoted 63 lines · Michael S. Tsirkin
Quoted 62 lines · Sergio Lopez Pascual
Quoted 41 lines · Michael S. Tsirkin
Quoted 34 lines · Sergio Lopez Pascual
Quoted 25 lines · Michael S. Tsirkin
Quoted 12 lines · Sergio Lopez
Add a subsection for page alignment restrictions.
Signed-off-by Sergio Lopez <[email protected]>--- shared-mem.tex | 6 ++++++ 1 file changed, 6 insertions(+)shared-mem.tex +0
-0shared-mem.tex \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De · line 42
Quoted 9 lines
shared-mem.tex +6
-0@@ -34,6 +34,12 @@ \subsection{Addressing within regions}\label{sec:Basic Facilities of a Virtio De The \field{shmid} may be explicit or may be inferred from the context of the reference. +\subsection{Page alignment restrictions}\label{sec:Basic Facilities of a Virtio Device / Shared Memory Regions / Page alignment restrictions} + +When requesting the device to map memory into a shared memory region +the driver MUST obtain the page size information from the transport +and honor the page alignment constrains derived from that page size. +will make existing drivers autmatically incompliant with new devices.
Quoted 1 line
we generally avoid things like this.
This is the reason why in v1 this was gated behind
VIRTIO_F_SHM_PAGE_SIZE. But from the discussion on that thread, I understood that, at least for the PCI transport, it was preferred to have thepage_shiftfield unconditionally:Quoted 5 lines
Did I misunderstand the conclusions?
Sergio.
Quoted 8 lines
I think Parav missed this compatibility implication when he said:
So to obtain a free information, feature bit is not necessary, this can be self- described in the pci capability itself.
Parav, this is about the MUST requirement referring to honoring alignment, not about obtaining the information which indeed can be done without.
Would it be reasonable to expose
page_shiftin the transports unconditionally but only require drivers to honor the page alignment restrictions ifVIRTIO_F_SHM_PAGE_SIZEhas been negotiated?Personally, from a device/driver implementator PoV, I'd prefer to have everything (the
page_shiftfield in PCI, the SHMPageShift register in MMIO and the requirement to honor page alignment) gated behindVIRTIO_F_SHM_PAGE_SIZE, but if there's a reason to prefer the approach mentioned above, I'm fine with it.
Quoted 6 lines
Quoted 2 lines
Thanks,
Sergio.It's unclear when is it ok to access the field then, or what is the value if accessed when feature bit is not negotiated. On this I think I agree it is easier to just have it there unconditionally.
Got it. Let's do that in v3.
Thanks!
Sergio.
PATCH v2 2/3 transport-pci: introduce page_shift field for SHM
In reply to Sergio LopezBorrowing 8 bits from the 16 bit padding in virtio_pci_cap to hold a page_shift field which is used to derive the page size supported by the device.
--- transport-pci.tex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
transport-pci.tex +9 -1
@@ -147,7 +147,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option u8 cfg_type; /* Identifies the structure. */ u8 bar; /* Where to find it. */ u8 id; /* Multiple capabilities of the same type */ - u8 padding[2]; /* Pad to full dword. */ + u8 page_shift; /* Page shift for this shared memory region. */ + u8 padding[1]; /* Pad to full dword. */ le32 offset; /* Offset within bar. */ le32 length; /* Length of the structure, in bytes. */ };
@@ -222,6 +223,13 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option of a certain type. If the device type does not specify the meaning of this field, its contents are undefined. +\item[\field{page_shift}] + If \field{cfg_type} is set to VIRTIO_PCI_CAP_SHARED_MEMORY_CFG, the + device MUST provide the page shift derived from the supported page size + for this shared memory region. The page shift is derived from the page + size by using this formula: + $page size = 1 << (page shift + 12)$. + See also \ref {sec:Basic Facilities of a Virtio Device / Shared Memory Regions / Page alignment restrictions}. \item[\field{offset}] indicates where the structure begins relative to the base address associated
Signature · 1 line
2.49.0
PATCH v2 3/3 transport-mmio: introduce SHMPageShift register
In reply to Sergio LopezIntroduce the "SHMPageShift" register which, when read, returns the page shift value that can be used to derive the page size value supported by the shared memory regions in the device.
--- transport-mmio.tex | 8 ++++++++ 1 file changed, 8 insertions(+)
transport-mmio.tex +8 -0
@@ -242,6 +242,14 @@ \subsection{MMIO Device Register Layout}\label{sec:Virtio Transport Options / Vi apply to the queue selected by writing to \field{QueueSel}. } \hline + \mmioreg{SHMPageShift}{Shared memory region page shift 8 bit long}{0x0c4}{R}{% + Reading from this register returns the page shift derived from the supported + page size for the memory region selected by the \field{SHMSel} register. The + page shift is derived from the page size by using this formula: + $page size = 1 << (page shift + 12)$. + See also \ref {sec:Basic Facilities of a Virtio Device / Shared Memory Regions / Page alignment restrictions}. + } + \hline \mmioreg{ConfigGeneration}{Configuration atomicity value}{0x0fc}{R}{ Reading from this register returns a value describing a version of the device-specific configuration space (see \field{Config}). The driver can then access the configuration space and, when finished, read \field{ConfigGeneration} again.
Signature · 1 line
2.49.0