Skip to contentSkip to conversation

design: design doc for shared memory on a dom0less system

PATCH In review Penny Zheng 4 participants 7 messages Jan 26, 2022 – Mar 11, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 design: design doc for shared memory on a dom0less system

This commit provides a design doc for static shared memory on a dom0less system.

---
 design/shm-dom0less.md | 182 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 182 insertions(+)
 create mode 100644 design/shm-dom0less.md
design/shm-dom0less.md new file +182 -0
new file mode 100644
index 0000000..b46199d
@@ -0,0 +1,182 @@
+# Static Shared Memory between domains on a dom0less system
+
+This design aims to provide an overview of the new feature: setting up static
+shared memory between domains on a dom0less system, through device tree
+configuration.
+
+The new feature is driven by the need of finding a way to build up
+communication channels on dom0less system, since the legacy ways including
+grant table, etc are all absent there.
+
+It was inspired by the patch serie of "xl/libxl-based shared memory", see
+[1] for more details.
+
+# Static Shared Memory Device Tree Configuration
+
+The static shared memory device tree nodes allow users to statically set up
+shared memory among a group of dom0less DomUs and Dom0, enabling domains
+to do shm-based communication.
+
+- compatible
+
+    "xen,domain-shared-memory-v1"
+
+- xen,shm-id
+
+    An u32 value represents the unique identifier of the shared memory region.
+    User valuing per shared memory region shall follow the ascending order,
+    starting from xen,shm-id = <0x0>, to the maximum identifier
+    xen,shm-id = <0x126>. The special xen,shm-id = <0x127> is reserved for
+    INVALID_SHMID.
+
+- xen,shared-mem
+
+    An array takes a physical address, which is the base address of the
+    shared memory region in host physical address space, a size, and a guest
+    physical address, as the target address of the mapping.
+
+- role(Optional)
+
+    A string property specifying the ownership of a shared memory region,
+    the value must be one of the following: "owner", or "borrower"
+    A shared memory region could be explicitly backed by one domain, which is
+    called "owner domain", and all the other domains who are also sharing
+    this region are called "borrower domain".
+    If not specified, the default value is "borrower" and owner is
+    "dom_shared", a system domain.
+
+## Example
+
+chosen {
+    #address-cells = <0x1>;
+    #size-cells = <0x1>;
+    xen,xen-bootargs = "console=dtuart dtuart=serial0 bootscrub=0";
+
+    ......
+
+    /* this is for Dom0 */
+    dom0-shared-mem@10000000 {
+        compatible = "xen,domain-shared-memory-v1";
+        xen,shm-id = <0x0>;
+        role = "owner";
+        xen,shared-mem = <0x10000000 0x10000000 0x10000000>;
+    }
+
+    domU1 {
+        compatible = "xen,domain";
+        #address-cells = <0x1>;
+        #size-cells = <0x1>;
+        memory = <0 131072>;
+        cpus = <2>;
+        vpl011;
+
+        /*
+         * shared memory region identified as 0x0(xen,shm-id = <0x0>)
+         * shared between dom0.
+         */
+        domU1-shared-mem@10000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x0>;
+            role = "borrower";
+            xen,shared-mem = <0x10000000 0x10000000 0x50000000>;
+        }
+
+        domU1-shared-mem@50000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x1>;
+            xen,shared-mem = <0x50000000 0x20000000 0x60000000>;
+        }
+
+        ......
+
+    };
+
+    domU2 {
+        compatible = "xen,domain";
+        #address-cells = <0x1>;
+        #size-cells = <0x1>;
+        memory = <0 65536>;
+        cpus = <1>;
+
+        /*
+         * shared memory region identified as 0x1(xen,shm-id = <0x1>)
+         * shared between domU1.
+         */
+        domU2-shared-mem@50000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x1>;
+            xen,shared-mem = <0x50000000 0x20000000 0x70000000>;
+        }
+
+        ......
+    };
+};
+
+It is the example of two static shared memory regions.
+
+In terms of shared memory region identified as 0x0, host physical address
+starting at 0x10000000 of 256MB will be reserved to be shared between Dom0
+and DomU1. It will get mapped at 0x10000000 in Dom0 guest physical address
+space, and at 0x50000000 in DomU1 guest physical address space. Dom0 is the
+owner domain, and domU1 is the borrower domain.
+
+And in terms of shared memory region identified as 0x1, host physical address
+starting at 0x50000000 of 512MB will be reserved to be shared between DomU1
+and DomU2. It will get mapped at 0x60000000 in DomU1 guest physical address
+space, and at 0x70000000 in DomU2 guest physical address space. Since no owner
+domain is explicitly defined, the default "dom_shared" is the owner domain,
+and both domU1 and domU2 are the borrower domains.
+
+# Overview of Static Shared Memory Flow
+
+Static Shared Memory working flow could be classified into the following
+steps:
+ - Carve out a range of memory in host physical address space to be used
+for sharing. Define it in device tree configuration, then parse and reserve
+it to avoid other use.
+ - Create a special domain "dom_shared". It will be the owner domain which
+is owning the statically shared pages, if "role" property is not specified.
+ - Per shared memory region could be shared with multiple domains. For
+owner domain, it acquires statically shared pages and assign them to itself,
+in the same way with static memory. And other than owner domain, the others
+who are also sharing are called "borrower domain", for which foreign memory
+map of statically shared pages is required.
+ - Expose the shared memory to the domU using the "xen,shared-memory-v1"
+reserved-memory binding. See
+Documentation/devicetree/bindings/reserved-memory/xen,shared-memory.txt
+in Linux for the corresponding device tree binding.
+
+# Memory management of Shared Memory Region
+
+Each memory page needs to have an "owner" and it is likely that in many cases
+the user don't care who the owner is, so it makes sense that users don't
+need to specify the "role" in device tree if they don't want to, in which
+scenario, a default domain shall be the owner domain.
+
+We propose a new system domain "dom_shared" to be the default domain owning all
+statically unowned shared pages, assigning it dom_id 0x7FF5(DOMID_SHARED).
+
+"dom_shared" domain shall get constructed before domain construction and after
+"setup_virt_paging", during system boot-time, so it could successfully do
+p2m initialization.
+
+Owner domain acquires statically shared pages and assign them to itself,
+while borrower domains get and take reference of them, then do foreign memory
+map of these statically shared pages.
+
+When destroying or rebooting a domain, if it is a borrower domain, other than
+removing foreign memory map of statically shared pages in P2M table, we also
+need to drop according gained reference. And if it is an owner domain, since
+statically shared pages are allocated as guest normal ram, it is not needed to
+do extra removing.
+
+However if owner domain is not the default "dom_shared" domain, but specified
+explicitly in device tree, stopping itself will make shared memory region
+unaccessible to all borrower domains, so we need to remove foreign memory map
+for all borrower domains. Notice that all borrowers domains should be stopped
+before stopping the owner domain.
+
+"dom_shared" domain is destroyed when the whole system shuts down, so its
+owning statically shared pages are only freed at system shutdown.
+
+[1] https://marc.info/?l=xen-devel&m=154404821731186
Signature · 1 line
2.25.1
#1 lore raw

Hi,

Quoted 15 lines · Penny Zheng

This commit provides a design doc for static shared memory on a dom0less system.

---
  design/shm-dom0less.md | 182 +++++++++++++++++++++++++++++++++++++++++
  1 file changed, 182 insertions(+)

create mode 100644 design/shm-dom0less.md

design/shm-dom0less.md new file +0 -0
new file mode 100644
index 0000000..b46199d

design/shm-dom0less.md line 9

Quoted 9 lines
design/shm-dom0less.md new file +9 -0
@@ -0,0 +1,182 @@
+# Static Shared Memory between domains on a dom0less system
+
+This design aims to provide an overview of the new feature: setting up static
+shared memory between domains on a dom0less system, through device tree
+configuration.
+
+The new feature is driven by the need of finding a way to build up
+communication channels on dom0less system, since the legacy ways including
+grant table, etc are all absent there.

Stefano has a series to add support for grant-table [2]. So I think you want to justify it differently.

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+
+It was inspired by the patch serie of "xl/libxl-based shared memory", see
+[1] for more details.
+
+# Static Shared Memory Device Tree Configuration

design/shm-dom0less.md line 24

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+The static shared memory device tree nodes allow users to statically set up
+shared memory among a group of dom0less DomUs and Dom0, enabling domains
+to do shm-based communication.
+
+- compatible
+
+    "xen,domain-shared-memory-v1"
+
+- xen,shm-id

From the document, it is not clear to me what is the purpose of the identifier. Could you clarify it?

design/shm-dom0less.md

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+
+    An u32 value represents the unique identifier of the shared memory region.
+    User valuing per shared memory region shall follow the ascending order,
+    starting from xen,shm-id = <0x0>, to the maximum identifier
+    xen,shm-id = <0x126>.

Why is it limit to 0x126? And also, why do they have to be allocated in ascending order?

Quoted 2 lines

The special xen,shm-id = <0x127> is reserved for
+ INVALID_SHMID.

Why do we need to reserve invalid?

design/shm-dom0less.md line 36

Quoted 6 lines
design/shm-dom0less.md new file +6 -0
+
+- xen,shared-mem
+
+    An array takes a physical address, which is the base address of the
+    shared memory region in host physical address space, a size, and a guest
+    physical address, as the target address of the mapping.

I think shared memory is useful without static allocation. So I think we want to make the host physical address optional.

design/shm-dom0less.md line 46

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+- role(Optional)
+
+    A string property specifying the ownership of a shared memory region,
+    the value must be one of the following: "owner", or "borrower"
+    A shared memory region could be explicitly backed by one domain, which is
+    called "owner domain", and all the other domains who are also sharing
+    this region are called "borrower domain".
+    If not specified, the default value is "borrower" and owner is
+    "dom_shared", a system domain.

I don't particularly like adding another system domain. Instead, it would be better to always specify the owner.

Quoted 25 lines
design/shm-dom0less.md new file +25 -0
+
+## Example
+
+chosen {
+    #address-cells = <0x1>;
+    #size-cells = <0x1>;
+    xen,xen-bootargs = "console=dtuart dtuart=serial0 bootscrub=0";
+
+    ......
+
+    /* this is for Dom0 */
+    dom0-shared-mem@10000000 {
+        compatible = "xen,domain-shared-memory-v1";
+        xen,shm-id = <0x0>;
+        role = "owner";
+        xen,shared-mem = <0x10000000 0x10000000 0x10000000>;
+    }
+
+    domU1 {
+        compatible = "xen,domain";
+        #address-cells = <0x1>;
+        #size-cells = <0x1>;
+        memory = <0 131072>;
+        cpus = <2>;
+        vpl011;

design/shm-dom0less.md line 81

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+        /*
+         * shared memory region identified as 0x0(xen,shm-id = <0x0>)
+         * shared between dom0.
+         */
+        domU1-shared-mem@10000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x0>;
+            role = "borrower";
+            xen,shared-mem = <0x10000000 0x10000000 0x50000000>;

Technically, you already know the physical address from the owner. In fact, it will only increase the risk to get the wrong binding. So I would like to suggest a different binding.

1) Reserve the region in the host memory using reserved-memory binding
2) Create a binding per domain that contains a phandle to the host memory and the role.

The advantage with this is we could easily support region that are not backed by a reserved-memory.

Quoted 70 lines
design/shm-dom0less.md new file +70 -0
+        }
+
+        domU1-shared-mem@50000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x1>;
+            xen,shared-mem = <0x50000000 0x20000000 0x60000000>;
+        }
+
+        ......
+
+    };
+
+    domU2 {
+        compatible = "xen,domain";
+        #address-cells = <0x1>;
+        #size-cells = <0x1>;
+        memory = <0 65536>;
+        cpus = <1>;
+
+        /*
+         * shared memory region identified as 0x1(xen,shm-id = <0x1>)
+         * shared between domU1.
+         */
+        domU2-shared-mem@50000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x1>;
+            xen,shared-mem = <0x50000000 0x20000000 0x70000000>;
+        }
+
+        ......
+    };
+};
+
+It is the example of two static shared memory regions.
+
+In terms of shared memory region identified as 0x0, host physical address
+starting at 0x10000000 of 256MB will be reserved to be shared between Dom0
+and DomU1. It will get mapped at 0x10000000 in Dom0 guest physical address
+space, and at 0x50000000 in DomU1 guest physical address space. Dom0 is the
+owner domain, and domU1 is the borrower domain.
+
+And in terms of shared memory region identified as 0x1, host physical address
+starting at 0x50000000 of 512MB will be reserved to be shared between DomU1
+and DomU2. It will get mapped at 0x60000000 in DomU1 guest physical address
+space, and at 0x70000000 in DomU2 guest physical address space. Since no owner
+domain is explicitly defined, the default "dom_shared" is the owner domain,
+and both domU1 and domU2 are the borrower domains.
+
+# Overview of Static Shared Memory Flow
+
+Static Shared Memory working flow could be classified into the following
+steps:
+ - Carve out a range of memory in host physical address space to be used
+for sharing. Define it in device tree configuration, then parse and reserve
+it to avoid other use.
+ - Create a special domain "dom_shared". It will be the owner domain which
+is owning the statically shared pages, if "role" property is not specified.
+ - Per shared memory region could be shared with multiple domains. For
+owner domain, it acquires statically shared pages and assign them to itself,
+in the same way with static memory. And other than owner domain, the others
+who are also sharing are called "borrower domain", for which foreign memory
+map of statically shared pages is required.
+ - Expose the shared memory to the domU using the "xen,shared-memory-v1"
+reserved-memory binding. See
+Documentation/devicetree/bindings/reserved-memory/xen,shared-memory.txt
+in Linux for the corresponding device tree binding.
+
+# Memory management of Shared Memory Region
+
+Each memory page needs to have an "owner" and it is likely that in many cases

design/shm-dom0less.md line 161

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+the user don't care who the owner is, so it makes sense that users don't
+need to specify the "role" in device tree if they don't want to, in which
+scenario, a default domain shall be the owner domain.
+
+We propose a new system domain "dom_shared" to be the default domain owning all
+statically unowned shared pages, assigning it dom_id 0x7FF5(DOMID_SHARED).
+
+"dom_shared" domain shall get constructed before domain construction and after
+"setup_virt_paging", during system boot-time, so it could successfully do
+p2m initialization.

IHMO, this is going too much into details for a design document. The goal is to abstract the feature rather than mentioning the implementation (which may change during review or in the future).

design/shm-dom0less.md line 165

Quoted 4 lines
design/shm-dom0less.md new file +4 -0
+
+Owner domain acquires statically shared pages and assign them to itself,
+while borrower domains get and take reference of them, then do foreign memory
+map of these statically shared pages.

What happens if the borrower is seen before the owner?

design/shm-dom0less.md line 177

Quoted 12 lines
design/shm-dom0less.md new file +12 -0
+
+When destroying or rebooting a domain, if it is a borrower domain, other than
+removing foreign memory map of statically shared pages in P2M table, we also
+need to drop according gained reference. And if it is an owner domain, since
+statically shared pages are allocated as guest normal ram, it is not needed to
+do extra removing.
+
+However if owner domain is not the default "dom_shared" domain, but specified
+explicitly in device tree, stopping itself will make shared memory region
+unaccessible to all borrower domains, so we need to remove foreign memory map
+for all borrower domains. Notice that all borrowers domains should be stopped
+before stopping the owner domain.

How will you enforce that?

design/shm-dom0less.md line 182

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+
+"dom_shared" domain is destroyed when the whole system shuts down, so its
+owning statically shared pages are only freed at system shutdown.
+
+[1] https://marc.info/?l=xen-devel&m=154404821731186

[2] <alpine.DEB.2.22.394.2201121646290.19362@ubuntu-linux-20-04-desktop>

Signature · 1 line
Julien Grall
#2 lore raw

Hi Julien,

Thanks a lot for the quick feedback.

Quoted 70 lines · Julien Grall

Hi,

Quoted 13 lines · Penny Zheng

This commit provides a design doc for static shared memory on a dom0less system.

---
 design/shm-dom0less.md | 182 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 182 insertions(+)
 create mode 100644 design/shm-dom0less.md
design/shm-dom0less.md new file +0 -0
new file mode 100644
index 0000000..b46199d

design/shm-dom0less.md line 9

Quoted 9 lines
design/shm-dom0less.md new file +9 -0
@@ -0,0 +1,182 @@
+# Static Shared Memory between domains on a dom0less system
+
+This design aims to provide an overview of the new feature: setting up static
+shared memory between domains on a dom0less system, through device tree
+configuration.
+
+The new feature is driven by the need of finding a way to build up
+communication channels on dom0less system, since the legacy ways including
+grant table, etc are all absent there.

Stefano has a series to add support for grant-table [2]. So I think you want to justify it differently.

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+
+It was inspired by the patch serie of "xl/libxl-based shared memory", see
+[1] for more details.
+
+# Static Shared Memory Device Tree Configuration

design/shm-dom0less.md line 24

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+The static shared memory device tree nodes allow users to statically set up
+shared memory among a group of dom0less DomUs and Dom0, enabling domains
+to do shm-based communication.
+
+- compatible
+
+    "xen,domain-shared-memory-v1"
+
+- xen,shm-id

From the document, it is not clear to me what is the purpose of the identifier. Could you clarify it?

design/shm-dom0less.md

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+
+    An u32 value represents the unique identifier of the shared memory region.
+    User valuing per shared memory region shall follow the ascending order,
+    starting from xen,shm-id = <0x0>, to the maximum identifier
+    xen,shm-id = <0x126>.

Why is it limit to 0x126? And also, why do they have to be allocated in ascending order?

Quoted 2 lines

The special xen,shm-id = <0x127> is reserved for
+ INVALID_SHMID.

Why do we need to reserve invalid?

design/shm-dom0less.md line 36

Quoted 6 lines
design/shm-dom0less.md new file +6 -0
+
+- xen,shared-mem
+
+    An array takes a physical address, which is the base address of the
+    shared memory region in host physical address space, a size, and a guest
+    physical address, as the target address of the mapping.

I think shared memory is useful without static allocation. So I think we want to make the host physical address optional.

Quoted 12 lines

design/shm-dom0less.md line 46

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+- role(Optional)
+
+    A string property specifying the ownership of a shared memory region,
+    the value must be one of the following: "owner", or "borrower"
+    A shared memory region could be explicitly backed by one domain, which is
+    called "owner domain", and all the other domains who are also sharing
+    this region are called "borrower domain".
+    If not specified, the default value is "borrower" and owner is
+    "dom_shared", a system domain.

I don't particularly like adding another system domain. Instead, it would be better to always specify the owner.

Having an owner which is not Xen is creating a dependency so restart the owner you would need to restart the borrowers. To remove this dependency and allow use cases where any domain having access can be restarted without the other side needing to, having Xen as the owner is required.

Initial discussion started between Penny and Stefano went the way you said and I asked to modify it like this to have something more looking like a standard shared memory with only users but no “owner”.
Also it fits to some of our use cases.

And it also solve some of the issues you found ...

Quoted 128 lines
Quoted 26 lines
design/shm-dom0less.md new file +25 -0
+
+## Example
+
+chosen {
+    #address-cells = <0x1>;
+    #size-cells = <0x1>;
+    xen,xen-bootargs = "console=dtuart dtuart=serial0 bootscrub=0";
+
+    ......
+
+    /* this is for Dom0 */
+    dom0-shared-mem@10000000 {
+        compatible = "xen,domain-shared-memory-v1";
+        xen,shm-id = <0x0>;
+        role = "owner";
+        xen,shared-mem = <0x10000000 0x10000000 0x10000000>;
+    }
+
+    domU1 {
+        compatible = "xen,domain";
+        #address-cells = <0x1>;
+        #size-cells = <0x1>;
+        memory = <0 131072>;
+        cpus = <2>;
+        vpl011;

design/shm-dom0less.md line 81

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+        /*
+         * shared memory region identified as 0x0(xen,shm-id = <0x0>)
+         * shared between dom0.
+         */
+        domU1-shared-mem@10000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x0>;
+            role = "borrower";
+            xen,shared-mem = <0x10000000 0x10000000 0x50000000>;

Technically, you already know the physical address from the owner. In fact, it will only increase the risk to get the wrong binding. So I would like to suggest a different binding.

1) Reserve the region in the host memory using reserved-memory binding
2) Create a binding per domain that contains a phandle to the host memory and the role.

The advantage with this is we could easily support region that are not backed by a reserved-memory.

Quoted 70 lines
design/shm-dom0less.md new file +70 -0
+        }
+
+        domU1-shared-mem@50000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x1>;
+            xen,shared-mem = <0x50000000 0x20000000 0x60000000>;
+        }
+
+        ......
+
+    };
+
+    domU2 {
+        compatible = "xen,domain";
+        #address-cells = <0x1>;
+        #size-cells = <0x1>;
+        memory = <0 65536>;
+        cpus = <1>;
+
+        /*
+         * shared memory region identified as 0x1(xen,shm-id = <0x1>)
+         * shared between domU1.
+         */
+        domU2-shared-mem@50000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x1>;
+            xen,shared-mem = <0x50000000 0x20000000 0x70000000>;
+        }
+
+        ......
+    };
+};
+
+It is the example of two static shared memory regions.
+
+In terms of shared memory region identified as 0x0, host physical address
+starting at 0x10000000 of 256MB will be reserved to be shared between Dom0
+and DomU1. It will get mapped at 0x10000000 in Dom0 guest physical address
+space, and at 0x50000000 in DomU1 guest physical address space. Dom0 is the
+owner domain, and domU1 is the borrower domain.
+
+And in terms of shared memory region identified as 0x1, host physical address
+starting at 0x50000000 of 512MB will be reserved to be shared between DomU1
+and DomU2. It will get mapped at 0x60000000 in DomU1 guest physical address
+space, and at 0x70000000 in DomU2 guest physical address space. Since no owner
+domain is explicitly defined, the default "dom_shared" is the owner domain,
+and both domU1 and domU2 are the borrower domains.
+
+# Overview of Static Shared Memory Flow
+
+Static Shared Memory working flow could be classified into the following
+steps:
+ - Carve out a range of memory in host physical address space to be used
+for sharing. Define it in device tree configuration, then parse and reserve
+it to avoid other use.
+ - Create a special domain "dom_shared". It will be the owner domain which
+is owning the statically shared pages, if "role" property is not specified.
+ - Per shared memory region could be shared with multiple domains. For
+owner domain, it acquires statically shared pages and assign them to itself,
+in the same way with static memory. And other than owner domain, the others
+who are also sharing are called "borrower domain", for which foreign memory
+map of statically shared pages is required.
+ - Expose the shared memory to the domU using the "xen,shared-memory-v1"
+reserved-memory binding. See
+Documentation/devicetree/bindings/reserved-memory/xen,shared-memory.txt
+in Linux for the corresponding device tree binding.
+
+# Memory management of Shared Memory Region
+
+Each memory page needs to have an "owner" and it is likely that in many cases

design/shm-dom0less.md line 161

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+the user don't care who the owner is, so it makes sense that users don't
+need to specify the "role" in device tree if they don't want to, in which
+scenario, a default domain shall be the owner domain.
+
+We propose a new system domain "dom_shared" to be the default domain owning all
+statically unowned shared pages, assigning it dom_id 0x7FF5(DOMID_SHARED).
+
+"dom_shared" domain shall get constructed before domain construction and after
+"setup_virt_paging", during system boot-time, so it could successfully do
+p2m initialization.

IHMO, this is going too much into details for a design document. The goal is to abstract the feature rather than mentioning the implementation (which may change during review or in the future).

Quoted 6 lines

design/shm-dom0less.md line 165

Quoted 4 lines
design/shm-dom0less.md new file +4 -0
+
+Owner domain acquires statically shared pages and assign them to itself,
+while borrower domains get and take reference of them, then do foreign memory
+map of these statically shared pages.

What happens if the borrower is seen before the owner?

This is not an issue if Xen is the owner.

Quoted 15 lines

design/shm-dom0less.md line 177

Quoted 13 lines
design/shm-dom0less.md new file +12 -0
+
+When destroying or rebooting a domain, if it is a borrower domain, other than
+removing foreign memory map of statically shared pages in P2M table, we also
+need to drop according gained reference. And if it is an owner domain, since
+statically shared pages are allocated as guest normal ram, it is not needed to
+do extra removing.
+
+However if owner domain is not the default "dom_shared" domain, but specified
+explicitly in device tree, stopping itself will make shared memory region
+unaccessible to all borrower domains, so we need to remove foreign memory map
+for all borrower domains. Notice that all borrowers domains should be stopped
+before stopping the owner domain.

How will you enforce that?

And this either.

Cheers
Bertrand

Quoted 11 lines

design/shm-dom0less.md line 182

Quoted 6 lines
design/shm-dom0less.md new file +5 -0
+
+"dom_shared" domain is destroyed when the whole system shuts down, so its
+owning statically shared pages are only freed at system shutdown.
+
+[1] https://marc.info/?l=xen-devel&m=154404821731186

[2] <alpine.DEB.2.22.394.2201121646290.19362@ubuntu-linux-20-04-desktop>

Signature · 1 line
Julien Grall
#3 lore raw

Hi Bertrand,

Quoted 83 lines · Bertrand Marquis
Quoted 70 lines · Julien Grall

Hi,

Quoted 13 lines · Penny Zheng

This commit provides a design doc for static shared memory on a dom0less system.

---
  design/shm-dom0less.md | 182 +++++++++++++++++++++++++++++++++++++++++
  1 file changed, 182 insertions(+)

create mode 100644 design/shm-dom0less.md

design/shm-dom0less.md new file +0 -0
new file mode 100644
index 0000000..b46199d

design/shm-dom0less.md line 9

Quoted 9 lines
design/shm-dom0less.md new file +9 -0
@@ -0,0 +1,182 @@
+# Static Shared Memory between domains on a dom0less system
+
+This design aims to provide an overview of the new feature: setting up static
+shared memory between domains on a dom0less system, through device tree
+configuration.
+
+The new feature is driven by the need of finding a way to build up
+communication channels on dom0less system, since the legacy ways including
+grant table, etc are all absent there.

Stefano has a series to add support for grant-table [2]. So I think you want to justify it differently.

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+
+It was inspired by the patch serie of "xl/libxl-based shared memory", see
+[1] for more details.
+
+# Static Shared Memory Device Tree Configuration

design/shm-dom0less.md line 24

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+The static shared memory device tree nodes allow users to statically set up
+shared memory among a group of dom0less DomUs and Dom0, enabling domains
+to do shm-based communication.
+
+- compatible
+
+    "xen,domain-shared-memory-v1"
+
+- xen,shm-id

From the document, it is not clear to me what is the purpose of the identifier. Could you clarify it?

design/shm-dom0less.md

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+
+    An u32 value represents the unique identifier of the shared memory region.
+    User valuing per shared memory region shall follow the ascending order,
+    starting from xen,shm-id = <0x0>, to the maximum identifier
+    xen,shm-id = <0x126>.

Why is it limit to 0x126? And also, why do they have to be allocated in ascending order?

Quoted 2 lines

The special xen,shm-id = <0x127> is reserved for
+ INVALID_SHMID.

Why do we need to reserve invalid?

design/shm-dom0less.md line 36

Quoted 6 lines
design/shm-dom0less.md new file +6 -0
+
+- xen,shared-mem
+
+    An array takes a physical address, which is the base address of the
+    shared memory region in host physical address space, a size, and a guest
+    physical address, as the target address of the mapping.

I think shared memory is useful without static allocation. So I think we want to make the host physical address optional.

Quoted 12 lines

design/shm-dom0less.md line 46

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+- role(Optional)
+
+    A string property specifying the ownership of a shared memory region,
+    the value must be one of the following: "owner", or "borrower"
+    A shared memory region could be explicitly backed by one domain, which is
+    called "owner domain", and all the other domains who are also sharing
+    this region are called "borrower domain".
+    If not specified, the default value is "borrower" and owner is
+    "dom_shared", a system domain.

I don't particularly like adding another system domain. Instead, it would be better to always specify the owner.

Quoted 1 line

Having an owner which is not Xen is creating a dependency so restart the owner you would need to restart the borrowers.

You don't necessarily have to. You can keep the "struct domain" and the shared pages in place and wipe everything else.

Quoted 6 lines

To remove this dependency and allow use cases where any domain having access can be restarted without the other side needing to, having Xen as the owner is required.

Initial discussion started between Penny and Stefano went the way you said and I asked to modify it like this to have something more looking like a standard shared memory with only users but no “owner”.

My main concern with dom_shared is the permissions. How do you make sure that a given page is only shared with the proper domain?

Quoted 1 line

Also it fits to some of our use cases.

Would you mind to briefly describe them?

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw

Hi Julien,

Quoted 87 lines · Julien Grall

Hi Bertrand,

Quoted 82 lines · Bertrand Marquis
Quoted 82 lines · Julien Grall

Hi,

Quoted 13 lines · Penny Zheng

This commit provides a design doc for static shared memory on a dom0less system.

---
 design/shm-dom0less.md | 182 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 182 insertions(+)
 create mode 100644 design/shm-dom0less.md
design/shm-dom0less.md new file +0 -0
new file mode 100644
index 0000000..b46199d

design/shm-dom0less.md line 9

Quoted 9 lines
design/shm-dom0less.md new file +9 -0
@@ -0,0 +1,182 @@
+# Static Shared Memory between domains on a dom0less system
+
+This design aims to provide an overview of the new feature: setting up static
+shared memory between domains on a dom0less system, through device tree
+configuration.
+
+The new feature is driven by the need of finding a way to build up
+communication channels on dom0less system, since the legacy ways including
+grant table, etc are all absent there.

Stefano has a series to add support for grant-table [2]. So I think you want to justify it differently.

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+
+It was inspired by the patch serie of "xl/libxl-based shared memory", see
+[1] for more details.
+
+# Static Shared Memory Device Tree Configuration

design/shm-dom0less.md line 24

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+The static shared memory device tree nodes allow users to statically set up
+shared memory among a group of dom0less DomUs and Dom0, enabling domains
+to do shm-based communication.
+
+- compatible
+
+    "xen,domain-shared-memory-v1"
+
+- xen,shm-id

From the document, it is not clear to me what is the purpose of the identifier. Could you clarify it?

design/shm-dom0less.md

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+
+    An u32 value represents the unique identifier of the shared memory region.
+    User valuing per shared memory region shall follow the ascending order,
+    starting from xen,shm-id = <0x0>, to the maximum identifier
+    xen,shm-id = <0x126>.

Why is it limit to 0x126? And also, why do they have to be allocated in ascending order?

Quoted 2 lines

The special xen,shm-id = <0x127> is reserved for
+ INVALID_SHMID.

Why do we need to reserve invalid?

design/shm-dom0less.md line 36

Quoted 6 lines
design/shm-dom0less.md new file +6 -0
+
+- xen,shared-mem
+
+    An array takes a physical address, which is the base address of the
+    shared memory region in host physical address space, a size, and a guest
+    physical address, as the target address of the mapping.

I think shared memory is useful without static allocation. So I think we want to make the host physical address optional.

design/shm-dom0less.md line 46

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+- role(Optional)
+
+    A string property specifying the ownership of a shared memory region,
+    the value must be one of the following: "owner", or "borrower"
+    A shared memory region could be explicitly backed by one domain, which is
+    called "owner domain", and all the other domains who are also sharing
+    this region are called "borrower domain".
+    If not specified, the default value is "borrower" and owner is
+    "dom_shared", a system domain.

I don't particularly like adding another system domain. Instead, it would be better to always specify the owner.

Quoted 3 lines
Quoted 1 line

Having an owner which is not Xen is creating a dependency so restart the owner you would need to restart the borrowers.

You don't necessarily have to. You can keep the "struct domain" and the shared pages in place and wipe everything else.

But you need to wipe everything.

Quoted 8 lines
Quoted 6 lines

To remove this dependency and allow use cases where any domain having access can be restarted without the other side needing to, having Xen as the owner is required.

Initial discussion started between Penny and Stefano went the way you said and I asked to modify it like this to have something more looking like a standard shared memory with only users but no “owner”.

My main concern with dom_shared is the permissions. How do you make sure that a given page is only shared with the proper domain?

That is by configuration as you define those area in your config and say who has access to it. Or maybe I misunderstood your question ?

Quoted 4 lines
Quoted 2 lines

Also it fits to some of our use cases.

Would you mind to briefly describe them?

Sure:
- one domain real time domain writing some logs in the shared memory that is polled and stored on a storage by an other domain. Real-time domain might reboot and wipe the logs and this could be acceptable, Linux might reboot and restart where it left.
- lockless fifo between 2 domains. If one restarts it can start over from where it left (Only need a one time initialiser at boot)
- redundancy system, for example 2 domains providing a position through different means, you do not care who provides you just need the latest info so one could override the data from the other one, the reader would not mind.
- configuration data storage. One domain reads the config and then stops until it is restarted to update it, other domains can read the config

I hope those are helping, I am open to provide others if you need.

Cheers
Bertrand

Quoted 5 lines

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw
In reply to Julien Grall
Quoted 6 lines · Julien Grall
Quoted 6 lines
design/shm-dom0less.md new file +6 -0
+
+- role(Optional)
+
+    A string property specifying the ownership of a shared memory region,
+    the value must be one of the following: "owner", or "borrower"
+    A shared memory region could be explicitly backed by one domain, which
Quoted 8 lines

design/shm-dom0less.md line 46

Quoted 5 lines

is

design/shm-dom0less.md new file +4 -0
+    called "owner domain", and all the other domains who are also sharing
+    this region are called "borrower domain".
+    If not specified, the default value is "borrower" and owner is
+    "dom_shared", a system domain.

I don't particularly like adding another system domain. Instead, it would be better to always specify the owner.

I wonder if we could reuse one of the existing system domains. DOM_IO looks very close to what we need here, except that the current description doesn't quite fit:

"DOMID_IO is used to restrict page-table updates to mapping I/O memory."

Also DOMID_XEN doesn't fit:

"DOMID_XEN is used to allow privileged domains to map restricted parts of Xen's heap space (e.g., the machine_to_phys table)."

On the other hand the description of DOMID_COW seems to be exactly what we want:

"DOMID_COW is used as the owner of sharable pages"

This is technically the description of what we need :-D However, we know that DOMID_COW was introduced with a different goal in mind.

Quoted 40 lines
Quoted 25 lines
design/shm-dom0less.md new file +25 -0
+
+## Example
+
+chosen {
+    #address-cells = <0x1>;
+    #size-cells = <0x1>;
+    xen,xen-bootargs = "console=dtuart dtuart=serial0 bootscrub=0";
+
+    ......
+
+    /* this is for Dom0 */
+    dom0-shared-mem@10000000 {
+        compatible = "xen,domain-shared-memory-v1";
+        xen,shm-id = <0x0>;
+        role = "owner";
+        xen,shared-mem = <0x10000000 0x10000000 0x10000000>;
+    }
+
+    domU1 {
+        compatible = "xen,domain";
+        #address-cells = <0x1>;
+        #size-cells = <0x1>;
+        memory = <0 131072>;
+        cpus = <2>;
+        vpl011;

design/shm-dom0less.md line 81

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+        /*
+         * shared memory region identified as 0x0(xen,shm-id = <0x0>)
+         * shared between dom0.
+         */
+        domU1-shared-mem@10000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x0>;
+            role = "borrower";
+            xen,shared-mem = <0x10000000 0x10000000 0x50000000>;

Technically, you already know the physical address from the owner. In fact, it will only increase the risk to get the wrong binding. So I would like to suggest a different binding.

Quoted 6 lines

1) Reserve the region in the host memory using reserved-memory binding
2) Create a binding per domain that contains a phandle to the host memory and the role.

The advantage with this is we could easily support region that are not backed by a reserved-memory.

I see what you mean but given that we have to specify the guest physical address anyway I don't think that replacing the physical address with a phandle would make things easier. We would still need to specify guest physical address and maybe size. We already have xen,reg that also works similarly. So I think it would be best to follow the same format as xen,reg.

That would also handle the case where the shared memory region is an sram region: we just need to use an address range that corresponds to mmio-sram instead of memory. Note that with a phandle we would have the problem that we could only share the entire sram region and not a part of it (because we could only link to the full mmio-sram node and not to a subset of it).

We just need to clearly specify the number of address cells and size cells to use. We could introduce #shared-mem-address-cells or reuse #address-cells. Either way parsing it should be easy.

If we wanted to use a phandle, I think it should point to a reserved-memory region outside of /reserved-memory. Long explanation follows.

Reserved-memory is a bit tricky to get right because reserved-memory is a configuration node and we don't have a way to tell who the reserved-memory configuration is for. Is it for Xen? Or for dom0? Or for domUs? When discussing system device tree topics (system device tree is very similar to device tree with Xen domain nodes) reserved-memory was one of the firsts concerns that Rob raised. The solution for system device tree was that each domain node should have its own reserved-memory sub-node instead of using /reserved-memory (e.g. /chosen/domU/reserved-memory).

Going back to Xen, if we take domUs out of the picture, who is /reserved-memory for? In practice, as most drivers are in dom0, we have been assuming /reserved-memory is for dom0. Xen copies reserved-memory nodes to dom0.

This is why I would like to suggest that if we want to use the phandle model then I think we should use a new and different reserved-memory node to specify the shared memory. E.g. /chosen/reserved-memory. We could call it differently and/or have an unambiguous compatible string:

chosen {
    reserved-memory {
        compatible = "xen,domains-reserved-memory-v1";

        ...
    };

This way we clearly distinguish it from /reserved-memory and we avoid ownership conflicts with dom0.

Quoted 32 lines
Quoted 32 lines
design/shm-dom0less.md new file +32 -0
+        }
+
+        domU1-shared-mem@50000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x1>;
+            xen,shared-mem = <0x50000000 0x20000000 0x60000000>;
+        }
+
+        ......
+
+    };
+
+    domU2 {
+        compatible = "xen,domain";
+        #address-cells = <0x1>;
+        #size-cells = <0x1>;
+        memory = <0 65536>;
+        cpus = <1>;
+
+        /*
+         * shared memory region identified as 0x1(xen,shm-id = <0x1>)
+         * shared between domU1.
+         */
+        domU2-shared-mem@50000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x1>;
+            xen,shared-mem = <0x50000000 0x20000000 0x70000000>;
+        }
+
+        ......
+    };
+};
#6 lore raw
In reply to Julien Grall

Hi Julien

Sorry for the late response, Since I'm considering sending the code together for better understanding.

Quoted 32 lines

-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Wednesday, January 26, 2022 6:58 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>
Subject: Re: [PATCH] design: design doc for shared memory on a dom0less system

Hi,

Quoted 6 lines · Penny Zheng

This commit provides a design doc for static shared memory on a dom0less system.

---
  design/shm-dom0less.md | 182

+++++++++++++++++++++++++++++++++++++++++

Quoted 12 lines
  1 file changed, 182 insertions(+)

create mode 100644 design/shm-dom0less.md

design/shm-dom0less.md new file renamed from design/shm-dom0less.md +0 -0

mode 100644 index 0000000..b46199d

design/shm-dom0less.md new file +4 -0
@@ -0,0 +1,182 @@
+# Static Shared Memory between domains on a dom0less system
+
+This design aims to provide an overview of the new feature: setting
+up static shared memory between domains on a dom0less system, through
Quoted 9 lines

design/shm-dom0less.md line 9

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+device tree configuration.
+
+The new feature is driven by the need of finding a way to build up
+communication channels on dom0less system, since the legacy ways
+including grant table, etc are all absent there.

Stefano has a series to add support for grant-table [2]. So I think you want to justify it differently.

The dom0less system I am referring here is that either dom0 is totally missing in the system, or even when dom0 is there, all the other domains are statically configured and CONFIG_XEN is not enabled, so in above scenario, all the legacy ways to communicate between domains are absent. These scenarios are specially applied to ARMv8R, where everything is static.

I think Stefano is trying to enable PV drivers on dom0less guest with CONFIG_XEN still on. TBH, I could not find proper nouns for them, sometimes calling these domains dom0less guests but with dom0 still there makes me confused too. ;/

Quoted 10 lines
Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+It was inspired by the patch serie of "xl/libxl-based shared memory",
+see [1] for more details.
+
+# Static Shared Memory Device Tree Configuration
+
+The static shared memory device tree nodes allow users to statically
+set up shared memory among a group of dom0less DomUs and Dom0,
+enabling domains to do shm-based communication.
+
Quoted 9 lines

design/shm-dom0less.md line 24

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+- compatible
+
+    "xen,domain-shared-memory-v1"
+
+- xen,shm-id

From the document, it is not clear to me what is the purpose of the identifier.
Could you clarify it?

It is more related to the implementation.

I've already pushed an RFC patch for reviewing in community for better understanding. For example, in commit "xen/arm: introduce static shared memory", when parsing shared memory node to reserve it in advance, we notice that a shared memory region could be shared among multiple domains, so in order to prevent iterating over all reserved memory regions each time, we use bitmap there and shm-id is used as the index of the bitmap.

Also, in Linux Doc about xen,shared-memory binding[3], it requires a xen,id property that identifies the shared memory region as specified in the VM config file.

Quoted 10 lines

design/shm-dom0less.md line 26

Quoted 2 lines
design/shm-dom0less.md new file +2 -0
+
+    An u32 value represents the unique identifier of the shared memory

region.

design/shm-dom0less.md

Quoted 3 lines
design/shm-dom0less.md new file +3 -0
+    User valuing per shared memory region shall follow the ascending order,
+    starting from xen,shm-id = <0x0>, to the maximum identifier
+    xen,shm-id = <0x126>.

Why is it limit to 0x126? And also, why do they have to be allocated in ascending order?

In current code, I make it the same number with NR_MEM_BANKS

Quoted 5 lines
Quoted 2 lines

The special xen,shm-id = <0x127> is reserved for
+ INVALID_SHMID.

Why do we need to reserve invalid?

It is removed in current codes.

Quoted 10 lines

design/shm-dom0less.md line 36

Quoted 6 lines
design/shm-dom0less.md new file +6 -0
+
+- xen,shared-mem
+
+    An array takes a physical address, which is the base address of the
+    shared memory region in host physical address space, a size, and a guest
+    physical address, as the target address of the mapping.

I think shared memory is useful without static allocation. So I think we want to make the host physical address optional.

Hmm,, so later,, you want to make one domain as owner, and parts of its guest RAM is shared with other borrower domains? So only GFN is enough here, right?

Quoted 157 lines

design/shm-dom0less.md

Quoted 6 lines
design/shm-dom0less.md new file +6 -0
+
+- role(Optional)
+
+    A string property specifying the ownership of a shared memory region,
+    the value must be one of the following: "owner", or "borrower"
+    A shared memory region could be explicitly backed by one domain, which

is

design/shm-dom0less.md line 46

Quoted 4 lines
design/shm-dom0less.md new file +4 -0
+    called "owner domain", and all the other domains who are also sharing
+    this region are called "borrower domain".
+    If not specified, the default value is "borrower" and owner is
+    "dom_shared", a system domain.

I don't particularly like adding another system domain. Instead, it would be better to always specify the owner.

Quoted 25 lines
design/shm-dom0less.md new file +25 -0
+
+## Example
+
+chosen {
+    #address-cells = <0x1>;
+    #size-cells = <0x1>;
+    xen,xen-bootargs = "console=dtuart dtuart=serial0 bootscrub=0";
+
+    ......
+
+    /* this is for Dom0 */
+    dom0-shared-mem@10000000 {
+        compatible = "xen,domain-shared-memory-v1";
+        xen,shm-id = <0x0>;
+        role = "owner";
+        xen,shared-mem = <0x10000000 0x10000000 0x10000000>;
+    }
+
+    domU1 {
+        compatible = "xen,domain";
+        #address-cells = <0x1>;
+        #size-cells = <0x1>;
+        memory = <0 131072>;
+        cpus = <2>;
+        vpl011;

design/shm-dom0less.md line 81

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+
+        /*
+         * shared memory region identified as 0x0(xen,shm-id = <0x0>)
+         * shared between dom0.
+         */
+        domU1-shared-mem@10000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x0>;
+            role = "borrower";
+            xen,shared-mem = <0x10000000 0x10000000 0x50000000>;

Technically, you already know the physical address from the owner. In fact, it will only increase the risk to get the wrong binding. So I would like to suggest a different binding.

1) Reserve the region in the host memory using reserved-memory binding
2) Create a binding per domain that contains a phandle to the host memory and the role.

The advantage with this is we could easily support region that are not backed by a reserved-memory.

Quoted 27 lines
design/shm-dom0less.md new file +27 -0
+        }
+
+        domU1-shared-mem@50000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x1>;
+            xen,shared-mem = <0x50000000 0x20000000 0x60000000>;
+        }
+
+        ......
+
+    };
+
+    domU2 {
+        compatible = "xen,domain";
+        #address-cells = <0x1>;
+        #size-cells = <0x1>;
+        memory = <0 65536>;
+        cpus = <1>;
+
+        /*
+         * shared memory region identified as 0x1(xen,shm-id = <0x1>)
+         * shared between domU1.
+         */
+        domU2-shared-mem@50000000 {
+            compatible = "xen,domain-shared-memory-v1";
+            xen,shm-id = <0x1>;
+            xen,shared-mem = <0x50000000 0x20000000 0x70000000>;

design/shm-dom0less.md

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+        }
+
+        ......
+    };
+};
+
+It is the example of two static shared memory regions.
+
+In terms of shared memory region identified as 0x0, host physical address
+starting at 0x10000000 of 256MB will be reserved to be shared between

Dom0

Quoted 1 line

+and DomU1. It will get mapped at 0x10000000 in Dom0 guest physical

address

Quoted 1 line

+space, and at 0x50000000 in DomU1 guest physical address space. Dom0 is

the

design/shm-dom0less.md

Quoted 3 lines
design/shm-dom0less.md new file +3 -0
+owner domain, and domU1 is the borrower domain.
+
+And in terms of shared memory region identified as 0x1, host physical

address

Quoted 1 line

+starting at 0x50000000 of 512MB will be reserved to be shared between

DomU1

Quoted 1 line

+and DomU2. It will get mapped at 0x60000000 in DomU1 guest physical

address

Quoted 1 line

+space, and at 0x70000000 in DomU2 guest physical address space. Since no

owner

Quoted 1 line

+domain is explicitly defined, the default "dom_shared" is the owner

domain,

design/shm-dom0less.md

Quoted 10 lines
design/shm-dom0less.md new file +10 -0
+and both domU1 and domU2 are the borrower domains.
+
+# Overview of Static Shared Memory Flow
+
+Static Shared Memory working flow could be classified into the following
+steps:
+ - Carve out a range of memory in host physical address space to be used
+for sharing. Define it in device tree configuration, then parse and reserve
+it to avoid other use.
+ - Create a special domain "dom_shared". It will be the owner domain

which

design/shm-dom0less.md

Quoted 4 lines
design/shm-dom0less.md new file +4 -0
+is owning the statically shared pages, if "role" property is not specified.
+ - Per shared memory region could be shared with multiple domains. For
+owner domain, it acquires statically shared pages and assign them to itself,
+in the same way with static memory. And other than owner domain, the

others

Quoted 1 line

+who are also sharing are called "borrower domain", for which foreign

memory

Quoted 2 lines

+map of statically shared pages is required.
+ - Expose the shared memory to the domU using the "xen,shared-memory-

v1"

design/shm-dom0less.md

Quoted 2 lines
design/shm-dom0less.md new file +2 -0
+reserved-memory binding. See
+Documentation/devicetree/bindings/reserved-memory/xen,shared-

memory.txt

design/shm-dom0less.md

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+in Linux for the corresponding device tree binding.
+
+# Memory management of Shared Memory Region
+
+Each memory page needs to have an "owner" and it is likely that in many

cases

design/shm-dom0less.md

Quoted 5 lines
design/shm-dom0less.md new file +5 -0
+the user don't care who the owner is, so it makes sense that users don't
+need to specify the "role" in device tree if they don't want to, in which
+scenario, a default domain shall be the owner domain.
+
+We propose a new system domain "dom_shared" to be the default domain

owning all

Quoted 1 line

+statically unowned shared pages, assigning it dom_id

0x7FF5(DOMID_SHARED).

Quoted 2 lines

+
+"dom_shared" domain shall get constructed before domain construction

Quoted 8 lines

and after

Quoted 2 lines

+"setup_virt_paging", during system boot-time, so it could successfully do +p2m initialization.

IHMO, this is going too much into details for a design document. The goal is to abstract the feature rather than mentioning the implementation (which may change during review or in the future).

Sure, I'll delete

Quoted 8 lines

design/shm-dom0less.md

Quoted 3 lines
design/shm-dom0less.md new file +3 -0
+
+Owner domain acquires statically shared pages and assign them to itself,
+while borrower domains get and take reference of them, then do foreign

memory

Quoted 1 line

+map of these statically shared pages.

What happens if the borrower is seen before the owner?

I've a commit specially focusing on this scenario, PLZ see commit " xen/arm: defer foreign memory map in shm_init_late", like I also comment in the codes:
"
In a few scenarios where owner domain, is defined after borrower domain in device tree configuration, statically shared pages haven't been properly allocated if borrower domain here tries to do foreign memory map.
In order to cover such scenario, we defer all borrower domains' foreign memory map after all domain construction finished.
"

Quoted 13 lines

design/shm-dom0less.md

Quoted 2 lines
design/shm-dom0less.md new file +2 -0
+
+When destroying or rebooting a domain, if it is a borrower domain, other

than

Quoted 1 line

+removing foreign memory map of statically shared pages in P2M table, we

also

Quoted 1 line

+need to drop according gained reference. And if it is an owner domain,

since

Quoted 1 line

+statically shared pages are allocated as guest normal ram, it is not needed

to

design/shm-dom0less.md

Quoted 3 lines
design/shm-dom0less.md new file +3 -0
+do extra removing.
+
+However if owner domain is not the default "dom_shared" domain, but

specified

Quoted 9 lines

design/shm-dom0less.md

Quoted 2 lines
design/shm-dom0less.md new file +2 -0
+explicitly in device tree, stopping itself will make shared memory region
+unaccessible to all borrower domains, so we need to remove foreign

memory map

Quoted 1 line

+for all borrower domains. Notice that all borrowers domains should be

stopped

Quoted 1 line

+before stopping the owner domain.

How will you enforce that?

Yes, I agree that we could not enforce that, so in commit "
xen/arm: unmap foreign memory mapping when destroyed domain is owner domain", Now, when destroyed domain is an owner domain of a static shared memory region, we need to ensure that all according borrower domains shall not have the access to this static shared memory region too.

Quoted 9 lines
Quoted 2 lines

+
+"dom_shared" domain is destroyed when the whole system shuts down, so

its

design/shm-dom0less.md line 182

Quoted 3 lines
design/shm-dom0less.md new file +3 -0
+owning statically shared pages are only freed at system shutdown.
+
+[1] https://marc.info/?l=xen-devel&m=154404821731186

[2] <alpine.DEB.2.22.394.2201121646290.19362@ubuntu-linux-20-04-desktop>

[3] https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/reserved-memory/xen%2Cshared-memory.txt

Quoted 2 lines

--
Julien Grall

--
Penny Zheng