Skip to contentSkip to conversation

arm-autonomy/xen-devicetree: Lower log level for incorrect kernel size

PATCH In review Nathan Dunne 2 participants 5 messages Jan 28, 2021 – Feb 3, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 arm-autonomy/xen-devicetree: Lower log level for incorrect kernel size

From: Nathan Dunne <[email protected]>

Reduced the level at which messages relating to overriding the user provided value for XEN_DEVICETREE_DOM0_SIZE when it is too small are logged at from 'warn' to 'note'

Issue-Id: SCM-2037

Change-Id I1436dac2c347d40c897291220fe30a95a57f2fa1
---
 .../recipes-extended/xen-devicetree/xen-devicetree.bb         | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta-arm-autonomy/recipes-extended/xen-devicetree/xen-devicetree.bb +2 -2
index 0369b96..13afb7a 100644
@@ -91,11 +91,11 @@ python calc_xen_dtb_dom0_size() {
     size_defined = int(d.getVar('XEN_DEVICETREE_DOM0_SIZE'), 16)
 
     if size_required > size_defined:
-        bb.warn ("Wrong kernel size setting inside xen dtb!\n"\
+        bb.note ("Wrong kernel size setting inside xen dtb!\n"\
                  "Required:\t%(req)d (%(req)#010X)\n"\
                  "Requested:\t%(def)d (%(def)#010X)"\
                  % {"req": size_required, "def": size_defined})
-        bb.warn ("Overriding XEN_DEVICETREE_DOM0_SIZE with "\
+        bb.note ("Overriding XEN_DEVICETREE_DOM0_SIZE with "\
                  "%(req)d (%(req)#010X)" % {"req": size_required})
         d.setVar('XEN_DEVICETREE_DOM0_SIZE', hex(size_required))
 }
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/4 arm-autonomy/xen-devicetree: Allow hex or decimal Dom0 Size

From: Nathan Dunne <[email protected]>

Check whether XEN_DEVICETREE_DOM0_SIZE begins '0x' and cast from hex or decimal accordingly, rather than assuming hex.

Issue-Id: SCM-2037

Change-Id I3a1c7c7ae6711b3d645cdb66bcd9c2c27196b054
---
 .../recipes-extended/xen-devicetree/xen-devicetree.bb       | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
meta-arm-autonomy/recipes-extended/xen-devicetree/xen-devicetree.bb +5 -1
index 13afb7a..398385a 100644
@@ -88,7 +88,11 @@ python calc_xen_dtb_dom0_size() {
     bb.note('size in bytes: %d' % size)
     # Ceil to MiB
     size_required = ceil(size / (2 ** 20)) * (2 ** 20)
-    size_defined = int(d.getVar('XEN_DEVICETREE_DOM0_SIZE'), 16)
+    xen_devicetree_dom0_size = d.getVar('XEN_DEVICETREE_DOM0_SIZE')
+    if xen_devicetree_dom0_size[:2] == "0x":
+        size_defined = int(xen_devicetree_dom0_size, 16)
+    else:
+        size_defined = int(xen_devicetree_dom0_size)
 
     if size_required > size_defined:
         bb.note ("Wrong kernel size setting inside xen dtb!\n"\
Signature · 1 line
2.17.1
#2 lore raw

PATCH 3/4 arm-autonomy/xen-devicetree: Check for empty/invalid variable values

In reply to Nathan Dunne

From: Nathan Dunne <[email protected]>

Added check to xen-devicetree to validate values of required variables:
XEN_DEVICETREE_DOM0_ADDR
XEN_DEVICETREE_DOM0_SIZE
XEN_DEVICETREE_DOM0_MEM

Issue-Id: SCM-2037

Change-Id I31bfcdb9d064f6e91beb1500d0a18f2a30a42028
---
 .../documentation/xen-devicetree.md           | 10 +++++---
 .../xen-devicetree/xen-devicetree.bb          | 24 +++++++++++++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)
meta-arm-autonomy/documentation/xen-devicetree.md +7 -3
index a44dca7..0d4466a 100644
@@ -70,7 +70,9 @@ The following parameters are available:
   This variable is only used if XEN_DEVICETREE_XEN_BOOTARGS has a value
   containing "dom0_mem=${XEN_DEVICETREE_DOM0_MEM}" as the memory assigned to
   dom0 is defined using Xen boot arguments.
-  This variable is set by default to "1024M".
+  This variable is set by default to "1024M", and cannot be empty.
+  The value can also be of the form "1024M,max:1024M", as documented here:
+  https://wiki.xenproject.org/wiki/Do%EF%BB%BFm0_Memory_%E2%80%94_Where_It_Has_Not_Gone
 
 - XEN_DEVICETREE_DOM0_BOOTARGS: Boot arguments to pass to Dom0 Linux when
   booting it.
@@ -84,7 +86,8 @@ The following parameters are available:
 - XEN_DEVICETREE_DOM0_ADDR: This is the address from which the Linux kernel to
   be used for Dom0 will be copied. When using u-boot, this is the address at
   which you will load the kernel Image before starting Xen.
-  This variable is set by default to "0x80080000".
+  This variable is set by default to "0x80080000", and cannot be empty.
+  Values for this variable can be in hex (prefixed with '0x') or in decimal.
 
 - XEN_DEVICETREE_DOM0_SIZE: This is the size of the kernel loaded at
   ${XEN_DEVICETREE_DOM0_ADDR}. Xen will copy this amount of data inside the
@@ -92,7 +95,8 @@ The following parameters are available:
   size but can be bigger. You must be careful not to have a value too big as it
   could slow down boot or copy other parts with it (like the DTB).
   You might need to increase this if you use a kernel with a bundled initramfs.
-  This variable is set by default to "0x01000000".
+  This variable is set by default to "0x01000000" and cannot be empty.
+  Values for this variable can be in hex (prefixed with '0x') or in decimal.
 
 - XEN_DEVICETREE_DTSI_MERGE: This variable contains the list of dtsi files that
   must be included inside the generated DTB file. By default the only one
meta-arm-autonomy/recipes-extended/xen-devicetree/xen-devicetree.bb +24 -0
index 398385a..c6a785f 100644
@@ -35,6 +35,30 @@ do_configure[noexec] = "1"
 do_compile[noexec] = "1"
 do_install[noexec] = "1"
 
+# Validate xen devicetree variables
+python __anonymous() {
+
+    # Compare values of a list of variables to a regex pattern
+    def validate_type(pattern, var_list):
+        for varname in var_list:
+            if d.getVar(varname):
+                if not pattern.match(d.getVar(varname)):
+                    raise bb.parse.SkipRecipe(d.getVar(varname) + "' is not a valid value for " + varname + "!")
+            else:
+                raise bb.parse.SkipRecipe('Required variable ' + varname + ' is empty!')
+
+    import re
+
+    num_vars_to_check = ['XEN_DEVICETREE_DOM0_ADDR', 'XEN_DEVICETREE_DOM0_SIZE']
+    size_vars_to_check = ['XEN_DEVICETREE_DOM0_MEM']
+
+    num_pattern = re.compile(r'((0x[0-9a-fA-F]+)|[0-9]+)$')
+    size_pattern = re.compile(r'[0-9]+[MG](,max:[0-9]+[MG])?$')
+
+    validate_type(num_pattern, num_vars_to_check)
+    validate_type(size_pattern, size_vars_to_check)
+}
+
 do_deploy() {
     if [ ! -f ${WORKDIR}/xen.dtsi.in ]; then
         die "xen.dtsi.in does not exist"
Signature · 1 line
2.17.1
#3 lore raw

PATCH 4/4 arm-autonomy/xen-devictree: Update dom0_mem default inline with best practices

In reply to Nathan Dunne

From: Nathan Dunne <[email protected]>

Updated default value for XEN_DEVICETREE_DOM0_MEM from "1024M" to "1024M,max:1024" to match best practice for dom0_mem command line argument. Documentation also updated to refer to new default value

Issue-Id: SCM-2037

Change-Id Ifa7e78bf22b024cb7fe4b782f628860ff44860ad
---
 meta-arm-autonomy/documentation/xen-devicetree.md          | 7 ++++---
 .../recipes-extended/xen-devicetree/xen-devicetree.bb      | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
meta-arm-autonomy/documentation/xen-devicetree.md +4 -3
index 0d4466a..0b3f41b 100644
@@ -70,9 +70,10 @@ The following parameters are available:
   This variable is only used if XEN_DEVICETREE_XEN_BOOTARGS has a value
   containing "dom0_mem=${XEN_DEVICETREE_DOM0_MEM}" as the memory assigned to
   dom0 is defined using Xen boot arguments.
-  This variable is set by default to "1024M", and cannot be empty.
-  The value can also be of the form "1024M,max:1024M", as documented here:
-  https://wiki.xenproject.org/wiki/Do%EF%BB%BFm0_Memory_%E2%80%94_Where_It_Has_Not_Gone
+  This variable is set by default to "1024M,max:1024", and cannot be empty.
+  The value can simply specify a size, e.g. "1024M", but best practice is to
+  also provide a max, documented here:
+  https://wiki.xenproject.org/wiki/Xen_Project_Best_Practices
 
 - XEN_DEVICETREE_DOM0_BOOTARGS: Boot arguments to pass to Dom0 Linux when
   booting it.
meta-arm-autonomy/recipes-extended/xen-devicetree/xen-devicetree.bb +1 -1
index c6a785f..29b8023 100644
@@ -19,7 +19,7 @@ DESCRIPTION = "Add entries in DTB for Xen and Dom0"
 XEN_DEVICETREE_DEPEND_append = " virtual/kernel:do_deploy"
 XEN_DEVICETREE_DTBS ?= "${KERNEL_DEVICETREE}"
 XEN_DEVICETREE_XEN_BOOTARGS ?= "noreboot dom0_mem=${XEN_DEVICETREE_DOM0_MEM}"
-XEN_DEVICETREE_DOM0_MEM ?= "1024M"
+XEN_DEVICETREE_DOM0_MEM ?= "1024M,max:1024M"
 XEN_DEVICETREE_DOM0_BOOTARGS ?= "console=hvc0 earlycon=xen"
 XEN_DEVICETREE_DOM0_ADDR ?= "0x80080000"
 XEN_DEVICETREE_DOM0_SIZE ?= "0x01000000"
Signature · 1 line
2.17.1
#4 lore raw
In reply to Nathan Dunne
Quoted 10 lines · Nathan Dunne

From: Nathan Dunne <[email protected]>

Reduced the level at which messages relating to overriding the user provided value for XEN_DEVICETREE_DOM0_SIZE when it is too small are logged at from 'warn' to 'note'

Issue-Id: SCM-2037

Change-Id I1436dac2c347d40c897291220fe30a95a57f2fa1

---

Series applied to the master branch

Thanks,
Jon

Quoted 28 lines
 .../recipes-extended/xen-devicetree/xen-devicetree.bb         | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta-arm-autonomy/recipes-extended/xen-devicetree/xen-devicetree.bb +2 -2
index 0369b96..13afb7a 100644
@@ -91,11 +91,11 @@ python calc_xen_dtb_dom0_size() {
     size_defined = int(d.getVar('XEN_DEVICETREE_DOM0_SIZE'), 16)
 
     if size_required > size_defined:
-        bb.warn ("Wrong kernel size setting inside xen dtb!\n"\
+        bb.note ("Wrong kernel size setting inside xen dtb!\n"\
                  "Required:\t%(req)d (%(req)#010X)\n"\
                  "Requested:\t%(def)d (%(def)#010X)"\
                  % {"req": size_required, "def": size_defined})
-        bb.warn ("Overriding XEN_DEVICETREE_DOM0_SIZE with "\
+        bb.note ("Overriding XEN_DEVICETREE_DOM0_SIZE with "\
                  "%(req)d (%(req)#010X)" % {"req": size_required})
         d.setVar('XEN_DEVICETREE_DOM0_SIZE', hex(size_required))
 }
Signature · 1 line
2.17.1