All of lore.kernel.org
 help / color / mirror / Atom feed
* [ImageBuilder] [PATCH v3] uboot-script-gen: Add DOMU_STATIC_MEM
@ 2022-06-16  9:56 Xenia Ragiadakou
  2022-06-16 20:59 ` Stefano Stabellini
  0 siblings, 1 reply; 2+ messages in thread
From: Xenia Ragiadakou @ 2022-06-16  9:56 UTC (permalink / raw)
  To: xen-devel; +Cc: sstabellini, viryaos-discuss

Add a new config parameter to configure a dom0less VM with static allocation.
DOMU_STATIC_MEM[number]="baseaddr1 size1 ... baseaddrN sizeN"
The parameter specifies the host physical address regions to be statically
allocated to the VM. Each region is defined by its start address and size.

For instance,
DOMU_STATIC_MEM[0]="0x30000000 0x10000000 0x50000000 0x20000000"
indicates that the host memory regions [0x30000000, 0x40000000) and
[0x50000000, 0x70000000) are statically allocated to the first dom0less VM.

Since currently it is not possible for a VM to have a mix of both statically
and non-statically allocated memory regions, when DOMU_STATIC_MEM is specified,
adjust VM's memory size to equal the amount of statically allocated memory.

Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com>
---

Changes in v2
- in add_device_tree_static_mem(), replace 'i' with 'val' because variable 'i'
  is already in use as an index
Changes in v3
- fix indentation
- in add_device_tree_static_mem(), declare 'cells' and 'val' variables local
  to not mess up any global variables by accident
- add a new function add_device_tree_mem() responsible for setting up
  the memory property in the device tree, as well as for adjusting
  the memory size accordingly when static mem is specified

 README.md                |  4 ++++
 scripts/uboot-script-gen | 48 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 8ce13f0..876e46d 100644
--- a/README.md
+++ b/README.md
@@ -154,6 +154,10 @@ Where:
   automatically at boot as dom0-less guest. It can still be created
   later from Dom0.
 
+- DOMU_STATIC_MEM[number]="baseaddr1 size1 ... baseaddrN sizeN"
+  if specified, indicates the host physical address regions
+  [baseaddr, baseaddr + size) to be reserved to the VM for static allocation.
+
 - LINUX is optional but specifies the Linux kernel for when Xen is NOT
   used.  To enable this set any LINUX\_\* variables and do NOT set the
   XEN variable.
diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen
index 0adf523..7781714 100755
--- a/scripts/uboot-script-gen
+++ b/scripts/uboot-script-gen
@@ -108,6 +108,48 @@ function add_device_tree_passthrough()
     dt_set "$path/module$addr" "reg" "hex"  "0x0 $addr 0x0 $(printf "0x%x" $size)"
 }
 
+function add_device_tree_mem()
+{
+    local path=$1
+    local memory=$2
+
+    # When the DOMU is configured with static allocation,
+    # the size of DOMU's memory must match the size of DOMU's static memory.
+    if test "${DOMU_STATIC_MEM[$i]}"
+    then
+        local array=(${DOMU_STATIC_MEM[$i]})
+        local index
+
+        memory=0
+        for (( index=1; index<${#array[@]}; index+=2 ))
+        do
+            (( memory += ${array[$index]} ))
+        done
+        # The property "memory" is in KB.
+        (( memory >>= 10 ))
+    fi
+
+    dt_set "$path" "memory" "int" "0 $memory"
+}
+
+function add_device_tree_static_mem()
+{
+    local path=$1
+    local regions=$2
+    local cells=()
+    local val
+
+    dt_set "$path" "#xen,static-mem-address-cells" "hex" "0x2"
+    dt_set "$path" "#xen,static-mem-size-cells" "hex" "0x2"
+
+    for val in ${regions[@]}
+    do
+        cells+=("$(printf "0x%x 0x%x" $(($val >> 32)) $(($val & ((1 << 32) - 1))))")
+    done
+
+    dt_set "$path" "xen,static-mem" "hex" "${cells[*]}"
+}
+
 function xen_device_tree_editing()
 {
     dt_set "/chosen" "#address-cells" "hex" "0x2"
@@ -141,8 +183,12 @@ function xen_device_tree_editing()
         dt_set "/chosen/domU$i" "compatible" "str" "xen,domain"
         dt_set "/chosen/domU$i" "#address-cells" "hex" "0x2"
         dt_set "/chosen/domU$i" "#size-cells" "hex" "0x2"
-        dt_set "/chosen/domU$i" "memory" "int" "0 ${DOMU_MEM[$i]}"
+        add_device_tree_mem "/chosen/domU$i" ${DOMU_MEM[$i]}
         dt_set "/chosen/domU$i" "cpus" "int" "${DOMU_VCPUS[$i]}"
+        if test "${DOMU_STATIC_MEM[$i]}"
+        then
+            add_device_tree_static_mem "/chosen/domU$i" "${DOMU_STATIC_MEM[$i]}"
+        fi
         dt_set "/chosen/domU$i" "vpl011" "hex" "0x1"
         add_device_tree_kernel "/chosen/domU$i" ${domU_kernel_addr[$i]} ${domU_kernel_size[$i]} "${DOMU_CMD[$i]}"
         if test "${domU_ramdisk_addr[$i]}"
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [ImageBuilder] [PATCH v3] uboot-script-gen: Add DOMU_STATIC_MEM
  2022-06-16  9:56 [ImageBuilder] [PATCH v3] uboot-script-gen: Add DOMU_STATIC_MEM Xenia Ragiadakou
@ 2022-06-16 20:59 ` Stefano Stabellini
  0 siblings, 0 replies; 2+ messages in thread
From: Stefano Stabellini @ 2022-06-16 20:59 UTC (permalink / raw)
  To: Xenia Ragiadakou; +Cc: xen-devel, sstabellini, viryaos-discuss

On Thu, 16 Jun 2022, Xenia Ragiadakou wrote:
> Add a new config parameter to configure a dom0less VM with static allocation.
> DOMU_STATIC_MEM[number]="baseaddr1 size1 ... baseaddrN sizeN"
> The parameter specifies the host physical address regions to be statically
> allocated to the VM. Each region is defined by its start address and size.
> 
> For instance,
> DOMU_STATIC_MEM[0]="0x30000000 0x10000000 0x50000000 0x20000000"
> indicates that the host memory regions [0x30000000, 0x40000000) and
> [0x50000000, 0x70000000) are statically allocated to the first dom0less VM.
> 
> Since currently it is not possible for a VM to have a mix of both statically
> and non-statically allocated memory regions, when DOMU_STATIC_MEM is specified,
> adjust VM's memory size to equal the amount of statically allocated memory.
> 
> Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com>

Reviewed and committed, thanks!

I added a check for DOMU_MEM != DOMU_STATIC_MEM on commit.

Cheers,

Stefano



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-16 21:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16  9:56 [ImageBuilder] [PATCH v3] uboot-script-gen: Add DOMU_STATIC_MEM Xenia Ragiadakou
2022-06-16 20:59 ` Stefano Stabellini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.