Skip to contentSkip to conversation

shared-mem: introduce page alignment restrictions

PATCH Superseded Sergio Lopez 3 participants 15 messages Mar 31, 2025 – Apr 2, 2025

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 6e6f6c4..2021083 100644
@@ -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
#2 lore raw
Quoted 12 lines · Sergio Lopez

Add a subsection for page alignment restrictions.

---
 shared-mem.tex | 6 ++++++
 1 file changed, 6 insertions(+)
shared-mem.tex +0 -0
index 6e6f6c4..2021083 100644

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 which
Signature · 1 line
2.49.0
#3 lore raw
Quoted 25 lines · Michael S. Tsirkin
Quoted 12 lines · Sergio Lopez

Add a subsection for page alignment restrictions.

---
 shared-mem.tex | 6 ++++++
 1 file changed, 6 insertions(+)
shared-mem.tex +0 -0
index 6e6f6c4..2021083 100644

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.

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:

https://lore.kernel.org/virtio-comment/CY8PR12MB71950314C5683EB7CFF0815BDCCA2@CY8PR12MB7195.namprd12.prod.outlook.com/

Did I misunderstand the conclusions?

Sergio.

#4 lore raw
Quoted 34 lines · Sergio Lopez Pascual
Quoted 25 lines · Michael S. Tsirkin
Quoted 12 lines · Sergio Lopez

Add a subsection for page alignment restrictions.

---
 shared-mem.tex | 6 ++++++
 1 file changed, 6 insertions(+)
shared-mem.tex +0 -0
index 6e6f6c4..2021083 100644

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.

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:

Quoted 5 lines

https://lore.kernel.org/virtio-comment/CY8PR12MB71950314C5683EB7CFF0815BDCCA2@CY8PR12MB7195.namprd12.prod.outlook.com/

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
#5 lore raw
Quoted 51 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 2:45 PM

Quoted 10 lines · Sergio Lopez Pascual
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Sergio Lopez

Add a subsection for page alignment restrictions.

---
 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 -0

100644

shared-mem.tex +0 -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.

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 that

page 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 the page_shift field unconditionally:

https://lore.kernel.org/virtio-

comment/CY8PR12MB71950314C5683EB7CFF081

Quoted 5 lines

[email protected]/

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.

#6 lore raw
Quoted 56 lines · Parav Pandit
Quoted 56 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 2:45 PM

Quoted 10 lines · Sergio Lopez Pascual
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Sergio Lopez

Add a subsection for page alignment restrictions.

---
 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 -0

100644

shared-mem.tex +0 -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.

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 that

page 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 the page_shift field unconditionally:

https://lore.kernel.org/virtio-

comment/CY8PR12MB71950314C5683EB7CFF081

Quoted 5 lines

[email protected]/

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.

#7 lore raw
Quoted 69 lines

From: Sergio Lopez Pascual <[email protected]>
Sent: Tuesday, April 1, 2025 3:04 PM

Quoted 53 lines · Parav Pandit
Quoted 53 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 2:45 PM

Quoted 10 lines · Sergio Lopez Pascual
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Sergio Lopez

Add a subsection for page alignment restrictions.

---
 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 -0

6e6f6c4..2021083
100644

shared-mem.tex +0 -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.

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 that

page 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 the page_shift field unconditionally:

https://lore.kernel.org/virtio-

comment/CY8PR12MB71950314C5683EB7CFF081

Quoted 5 lines

[email protected]/

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.

#8 lore raw
Quoted 74 lines · Parav Pandit
Quoted 74 lines

From: Sergio Lopez Pascual <[email protected]>
Sent: Tuesday, April 1, 2025 3:04 PM

Quoted 53 lines · Parav Pandit
Quoted 53 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 2:45 PM

Quoted 10 lines · Sergio Lopez Pascual
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Sergio Lopez

Add a subsection for page alignment restrictions.

---
 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 -0

6e6f6c4..2021083
100644

shared-mem.tex +0 -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.

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 that

page 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 the page_shift field unconditionally:

https://lore.kernel.org/virtio-

comment/CY8PR12MB71950314C5683EB7CFF081

Quoted 5 lines

[email protected]/

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.

#9 lore raw
Quoted 88 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 3:48 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Sergio Lopez Pascual <[email protected]>
Sent: Tuesday, April 1, 2025 3:04 PM

Quoted 4 lines · Parav Pandit
Quoted 4 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, April 1, 2025 2:45 PM

On 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.

---
 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 -0

6e6f6c4..2021083
100644

shared-mem.tex +0 -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.

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 that

page 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 the page_shift field unconditionally:

https://lore.kernel.org/virtio-

comment/CY8PR12MB71950314C5683EB7CFF081

Quoted 5 lines

[email protected]/

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.

#10 lore raw
In reply to Michael S. Tsirkin
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.

---
 shared-mem.tex | 6 ++++++
 1 file changed, 6 insertions(+)
shared-mem.tex +0 -0
index 6e6f6c4..2021083 100644

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.

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:

Quoted 5 lines

https://lore.kernel.org/virtio-comment/CY8PR12MB71950314C5683EB7CFF0815BDCCA2@CY8PR12MB7195.namprd12.prod.outlook.com/

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.

#11 lore raw
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.

---
 shared-mem.tex | 6 ++++++
 1 file changed, 6 insertions(+)
shared-mem.tex +0 -0
index 6e6f6c4..2021083 100644

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.

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:

Quoted 5 lines

https://lore.kernel.org/virtio-comment/CY8PR12MB71950314C5683EB7CFF0815BDCCA2@CY8PR12MB7195.namprd12.prod.outlook.com/

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?

Quoted 8 lines

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.

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
#12 lore raw
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.

---
 shared-mem.tex | 6 ++++++
 1 file changed, 6 insertions(+)
shared-mem.tex +0 -0
index 6e6f6c4..2021083 100644

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.

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:

Quoted 5 lines

https://lore.kernel.org/virtio-comment/CY8PR12MB71950314C5683EB7CFF0815BDCCA2@CY8PR12MB7195.namprd12.prod.outlook.com/

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.

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.

#13 lore raw

PATCH v2 2/3 transport-pci: introduce page_shift field for SHM

In reply to Sergio Lopez

Borrowing 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
index a5c6719..efb174a 100644
@@ -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
#14 lore raw

PATCH v2 3/3 transport-mmio: introduce SHMPageShift register

In reply to Sergio Lopez

Introduce 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
index 94a93a1..042a82c 100644
@@ -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