diff mbox series

[ImageBuilder,2/2] uboot-script-gen: Add support for static shared memory

Message ID 20230302044606.136130-3-jiamei.xie@arm.com (mailing list archive)
State Superseded
Headers show
Series uboot-script-gen: Add support for static heap and shared memory | expand

Commit Message

Jiamei Xie March 2, 2023, 4:46 a.m. UTC
Introduce support for creating shared-mem node for dom0less domUs in
the device tree. Add the following options:
- DOMU_SHARED_MEM[number]="HPA GPA size"
  if specified, indicates the host physical address HPA will get mapped
  at guest address GPA in domU and the memory of size will be reserved
  to be shared memory.
- DOMU_SHARED_MEM_ID[number]
  An arbitrary string that represents the unique identifier of the shared
  memory region, with a strict limit on the number of characters(\0
  included)

The static shared memory is used between two dom0less domUs.

Below is an example:
NUM_DOMUS=2
DOMU_SHARED_MEM[0]="0x50000000 0x6000000 0x10000000"
DOMU_SHARED_MEM_ID[0]="my-shared-mem-0"
DOMU_SHARED_MEM[1]="0x50000000 0x6000000 0x10000000"
DOMU_SHARED_MEM_ID[1]="my-shared-mem-0"

This static shared memory region is identified as "my-shared-mem-0", host
physical address starting at 0x50000000 of 256MB will be reserved to be
shared between two domUs. It will get mapped at 0x6000000 in both guest
physical address space. Both DomUs are the borrower domain, the owner
domain is the default owner domain DOMID_IO.

Signed-off-by: jiamei.xie <jiamei.xie@arm.com>
---
 README.md                | 18 ++++++++++++++++++
 scripts/uboot-script-gen | 26 ++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

Comments

Stefano Stabellini March 2, 2023, 11:48 p.m. UTC | #1
On Thu, 2 Mar 2023, jiamei.xie wrote:
> Introduce support for creating shared-mem node for dom0less domUs in
> the device tree. Add the following options:
> - DOMU_SHARED_MEM[number]="HPA GPA size"
>   if specified, indicates the host physical address HPA will get mapped
>   at guest address GPA in domU and the memory of size will be reserved
>   to be shared memory.
> - DOMU_SHARED_MEM_ID[number]
>   An arbitrary string that represents the unique identifier of the shared
>   memory region, with a strict limit on the number of characters(\0
>   included)
> 
> The static shared memory is used between two dom0less domUs.
> 
> Below is an example:
> NUM_DOMUS=2
> DOMU_SHARED_MEM[0]="0x50000000 0x6000000 0x10000000"
> DOMU_SHARED_MEM_ID[0]="my-shared-mem-0"
> DOMU_SHARED_MEM[1]="0x50000000 0x6000000 0x10000000"
> DOMU_SHARED_MEM_ID[1]="my-shared-mem-0"

Rather than two separate properties, do you think it would make sense to
just use one as follows?

NUM_DOMUS=2
DOMU_SHARED_MEM[0]="my-shared-mem-0 0x50000000 0x6000000 0x10000000"
DOMU_SHARED_MEM[1]="my-shared-mem-0 0x50000000 0x6000000 0x10000000"

The good thing about bash is that it doesn't care if they are numbers or
strings :-)


> This static shared memory region is identified as "my-shared-mem-0", host
> physical address starting at 0x50000000 of 256MB will be reserved to be
> shared between two domUs. It will get mapped at 0x6000000 in both guest
> physical address space. Both DomUs are the borrower domain, the owner
> domain is the default owner domain DOMID_IO.
> 
> Signed-off-by: jiamei.xie <jiamei.xie@arm.com>
> ---
>  README.md                | 18 ++++++++++++++++++
>  scripts/uboot-script-gen | 26 ++++++++++++++++++++++++++
>  2 files changed, 44 insertions(+)
> 
> diff --git a/README.md b/README.md
> index 787f413..48044ee 100644
> --- a/README.md
> +++ b/README.md
> @@ -192,6 +192,24 @@ Where:
>    if specified, indicates the host physical address regions
>    [baseaddr, baseaddr + size) to be reserved to the VM for static allocation.
>  
> +- DOMU_SHARED_MEM[number]="HPA GPA size" and DOMU_SHARED_MEM_ID[number]
> +  if specified, indicate the host physical address HPA will get mapped at
> +  guest address GPA in domU and the memory of size will be reserved to be
> +  shared memory. The shared memory is used between two dom0less domUs.
> +
> +  Below is an example:
> +  NUM_DOMUS=2
> +  DOMU_SHARED_MEM[0]="0x50000000 0x6000000 0x10000000"
> +  DOMU_SHARED_MEM_ID[0]="my-shared-mem-0"
> +  DOMU_SHARED_MEM[1]="0x50000000 0x6000000 0x10000000"
> +  DOMU_SHARED_MEM_ID[1]="my-shared-mem-0"
> +
> +  This static shared memory region is identified as "my-shared-mem-0", host
> +  physical address starting at 0x50000000 of 256MB will be reserved to be
> +  shared between two domUs. It will get mapped at 0x6000000 in both guest
> +  physical address space. Both DomUs are the borrower domain, the owner
> +  domain is the default owner domain DOMID_IO.
> +
>  - DOMU_DIRECT_MAP[number] can be set to 1 or 0.
>    If set to 1, the VM is direct mapped. The default is 1.
>    This is only applicable when DOMU_STATIC_MEM is specified.
> diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
> index 4775293..46215c8 100755
> --- a/scripts/uboot-script-gen
> +++ b/scripts/uboot-script-gen
> @@ -204,6 +204,27 @@ function add_device_tree_static_heap()
>      dt_set "$path" "xen,static-heap" "hex" "${cells[*]}"
>  }
>  
> +function add_device_tree_static_shared_mem()
> +{
> +    local path=$1
> +    local domid=$2
> +    local regions=$3
> +    local SHARED_MEM_ID=$4
> +    local cells=()
> +    local SHARED_MEM_HOST=${regions%% *}
> +
> +    dt_mknode "${path}" "domU${domid}-shared-mem@${SHARED_MEM_HOST}"
> +
> +    for val in ${regions[@]}
> +    do
> +        cells+=("$(printf "0x%x 0x%x" $(($val >> 32)) $(($val & ((1 << 32) - 1))))")
> +    done
> +
> +    dt_set "${path}/domU${domid}-shared-mem@${SHARED_MEM_HOST}" "compatible" "str" "xen,domain-shared-memory-v1"
> +    dt_set "${path}/domU${domid}-shared-mem@${SHARED_MEM_HOST}" "xen,shm-id" "str" "${SHARED_MEM_ID}"
> +    dt_set "${path}/domU${domid}-shared-mem@${SHARED_MEM_HOST}" "xen,shared-mem" "hex" "${cells[*]}"
> +}
> +
>  function add_device_tree_cpupools()
>  {
>      local cpu
> @@ -329,6 +350,11 @@ function xen_device_tree_editing()
>              dt_set "/chosen/domU$i" "xen,enhanced" "str" "enabled"
>          fi
>  
> +        if test -n "${DOMU_SHARED_MEM[i]}" -a -n "${DOMU_SHARED_MEM_ID[i]}"
> +        then
> +                add_device_tree_static_shared_mem "/chosen/domU${i}" "${i}" "${DOMU_SHARED_MEM[i]}" "${DOMU_SHARED_MEM_ID[i]}"
> +        fi
> +
>          if test "${DOMU_COLORS[$i]}"
>          then
>              local startcolor=$(echo "${DOMU_COLORS[$i]}"  | cut -d "-" -f 1)
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/README.md b/README.md
index 787f413..48044ee 100644
--- a/README.md
+++ b/README.md
@@ -192,6 +192,24 @@  Where:
   if specified, indicates the host physical address regions
   [baseaddr, baseaddr + size) to be reserved to the VM for static allocation.
 
+- DOMU_SHARED_MEM[number]="HPA GPA size" and DOMU_SHARED_MEM_ID[number]
+  if specified, indicate the host physical address HPA will get mapped at
+  guest address GPA in domU and the memory of size will be reserved to be
+  shared memory. The shared memory is used between two dom0less domUs.
+
+  Below is an example:
+  NUM_DOMUS=2
+  DOMU_SHARED_MEM[0]="0x50000000 0x6000000 0x10000000"
+  DOMU_SHARED_MEM_ID[0]="my-shared-mem-0"
+  DOMU_SHARED_MEM[1]="0x50000000 0x6000000 0x10000000"
+  DOMU_SHARED_MEM_ID[1]="my-shared-mem-0"
+
+  This static shared memory region is identified as "my-shared-mem-0", host
+  physical address starting at 0x50000000 of 256MB will be reserved to be
+  shared between two domUs. It will get mapped at 0x6000000 in both guest
+  physical address space. Both DomUs are the borrower domain, the owner
+  domain is the default owner domain DOMID_IO.
+
 - DOMU_DIRECT_MAP[number] can be set to 1 or 0.
   If set to 1, the VM is direct mapped. The default is 1.
   This is only applicable when DOMU_STATIC_MEM is specified.
diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index 4775293..46215c8 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -204,6 +204,27 @@  function add_device_tree_static_heap()
     dt_set "$path" "xen,static-heap" "hex" "${cells[*]}"
 }
 
+function add_device_tree_static_shared_mem()
+{
+    local path=$1
+    local domid=$2
+    local regions=$3
+    local SHARED_MEM_ID=$4
+    local cells=()
+    local SHARED_MEM_HOST=${regions%% *}
+
+    dt_mknode "${path}" "domU${domid}-shared-mem@${SHARED_MEM_HOST}"
+
+    for val in ${regions[@]}
+    do
+        cells+=("$(printf "0x%x 0x%x" $(($val >> 32)) $(($val & ((1 << 32) - 1))))")
+    done
+
+    dt_set "${path}/domU${domid}-shared-mem@${SHARED_MEM_HOST}" "compatible" "str" "xen,domain-shared-memory-v1"
+    dt_set "${path}/domU${domid}-shared-mem@${SHARED_MEM_HOST}" "xen,shm-id" "str" "${SHARED_MEM_ID}"
+    dt_set "${path}/domU${domid}-shared-mem@${SHARED_MEM_HOST}" "xen,shared-mem" "hex" "${cells[*]}"
+}
+
 function add_device_tree_cpupools()
 {
     local cpu
@@ -329,6 +350,11 @@  function xen_device_tree_editing()
             dt_set "/chosen/domU$i" "xen,enhanced" "str" "enabled"
         fi
 
+        if test -n "${DOMU_SHARED_MEM[i]}" -a -n "${DOMU_SHARED_MEM_ID[i]}"
+        then
+                add_device_tree_static_shared_mem "/chosen/domU${i}" "${i}" "${DOMU_SHARED_MEM[i]}" "${DOMU_SHARED_MEM_ID[i]}"
+        fi
+
         if test "${DOMU_COLORS[$i]}"
         then
             local startcolor=$(echo "${DOMU_COLORS[$i]}"  | cut -d "-" -f 1)