Skip to contentSkip to conversation

Xen on ARM: fix 64-bit and add 32-bit

PATCH In review Christopher Clark 2 participants 5 messages Aug 19, 2018 – Aug 20, 2018

lore
Share & tools
lore
#0 lore raw

cover Xen on ARM: fix 64-bit and add 32-bit

From: Christopher Clark <[email protected]>

This series fixes the Xen build for 64-bit ARM targets with gcc 8.2 with a minor patch to correct static string lengths, already reviewed upstream:
https://lists.xenproject.org/archives/html/xen-devel/2018-08/msg01367.html

and introduces 32-bit ARM compatibility, verified by testing with a cubietruck. This currently requires another tiny patch to suppress a new (false positive) compiler warning.

Christopher Clark (3):
xen: Fix build on arm64 w/ gcc 8.2
xen: fix truncation warning in tools build for ARM 32-bit
xen: enable 32-bit ARM builds

 .../xen-4.11-arm-acpi-fix-string-lengths.patch     | 101 +++++++++++++++++++++
 .../xen/files/xen-tools-xenpmd-snprintf.patch      |  78 ++++++++++++++++
 recipes-extended/xen/xen.inc                       |   7 +-
 recipes-extended/xen/xen_4.11.0.bb                 |   2 +
 4 files changed, 187 insertions(+), 1 deletion(-)
 create mode 100644 recipes-extended/xen/files/xen-4.11-arm-acpi-fix-string-lengths.patch
 create mode 100644 recipes-extended/xen/files/xen-tools-xenpmd-snprintf.patch
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 xen: fix build on aarch64 w/ gcc 8.2

Adds patch for compatibility with gcc 8.2, to fix string lengths for copied values to prevent array-bounds warnings.

---
 .../xen-4.11-arm-acpi-fix-string-lengths.patch     | 101 +++++++++++++++++++++
 recipes-extended/xen/xen_4.11.0.bb                 |   1 +
 2 files changed, 102 insertions(+)
 create mode 100644 recipes-extended/xen/files/xen-4.11-arm-acpi-fix-string-lengths.patch
recipes-extended/xen/files/xen-4.11-arm-acpi-fix-string-lengths.patch new file +101 -0
new file mode 100644
index 0000000..ece6407
@@ -0,0 +1,101 @@
+From 5e1a00969afe98a713bf14d1ba1902403b60e287 Mon Sep 17 00:00:00 2001
+From: Christopher Clark <[email protected]>
+Date: Thu, 16 Aug 2018 13:04:52 -0700
+Subject: [PATCH v2] libxl/arm: Fix build on arm64 + acpi w/ gcc 8.2
+To: [email protected]
+Cc: [email protected],
+    [email protected],
+    [email protected],
+    [email protected]
+
+[modified for Xen 4.11 to add required: #include <xen-tools/libs.h>]
+
+Add zero-padding to #defined ACPI table strings that are copied.
+Provides sufficient characters to satisfy the length required to
+fully populate the destination and prevent array-bounds warnings.
+Add BUILD_BUG_ON sizeof checks for compile-time length checking.
+
+Signed-off-by: Christopher Clark <[email protected]>
+Reviewed-by: Stefano Stabellini <[email protected]>
+Acked-by: Wei Liu <[email protected]>
+---
+v2: add BUILD_BUG_ON length checks, requested by Wei.
+
+v1: Please add this patch to the backport list for the next minor
+    4.11 release.
+
+Prior to this: gcc 8.2 objects to memcpy past bounds:
+
+| libxl_arm_acpi.c: In function 'make_acpi_header':
+| libxl_arm_acpi.c:208:5: error: 'memcpy' forming offset [5, 6] is out
+of the bounds [0, 4] [-Werror=array-bounds]
+|      memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id));
+|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+| libxl_arm_acpi.c:209:5: error: 'memcpy' forming offset [5, 8] is out
+of the bounds [0, 4] [-Werror=array-bounds]
+|      memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID,
+sizeof(h->oem_table_id));
+|
+^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+| libxl_arm_acpi.c:211:5: error: 'memcpy' forming offset 4 is out of the
+bounds [0, 3] [-Werror=array-bounds]
+|      memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID,
+|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+|             sizeof(h->asl_compiler_id));
+|             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+| In function 'make_acpi_rsdp.isra.4',
+|     inlined from 'libxl__prepare_acpi' at libxl_arm_acpi.c:389:5:
+| libxl_arm_acpi.c:193:5: error: 'memcpy' forming offset [5, 6] is out
+of the bounds [0, 4] [-Werror=array-bounds]
+|      memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id));
+|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ tools/libxl/libxl_arm_acpi.c | 10 +++++++---
+ 1 file changed, 7 insertions(+), 3 deletions(-)
+
+diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
+index 636f724..8924396 100644
+--- a/tools/libxl/libxl_arm_acpi.c
++++ b/tools/libxl/libxl_arm_acpi.c
+@@ -29,6 +29,7 @@ typedef int64_t s64;
+ 
+ #include <acpi/acconfig.h>
+ #include <acpi/actbl.h>
++#include <xen-tools/libs.h>
+ 
+ #ifndef BITS_PER_LONG
+ #ifdef _LP64
+@@ -48,9 +49,9 @@ extern const unsigned char dsdt_anycpu_arm[];
+ _hidden
+ extern const int dsdt_anycpu_arm_len;
+ 
+-#define ACPI_OEM_ID "Xen"
+-#define ACPI_OEM_TABLE_ID "ARM"
+-#define ACPI_ASL_COMPILER_ID "XL"
++#define ACPI_OEM_ID "Xen\0\0"
++#define ACPI_OEM_TABLE_ID "ARM\0\0\0\0"
++#define ACPI_ASL_COMPILER_ID "XL\0"
+ 
+ enum {
+     RSDP,
+@@ -190,6 +191,7 @@ static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom,
+     struct acpi_table_rsdp *rsdp = (void *)dom->acpi_modules[0].data + offset;
+ 
+     memcpy(rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
++    BUILD_BUG_ON(sizeof(ACPI_OEM_ID) != sizeof(rsdp->oem_id));
+     memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id));
+     rsdp->length = acpitables[RSDP].size;
+     rsdp->revision = 0x02;
+@@ -205,9 +207,12 @@ static void make_acpi_header(struct acpi_table_header *h, const char *sig,
+     memcpy(h->signature, sig, 4);
+     h->length = len;
+     h->revision = rev;
++    BUILD_BUG_ON(sizeof(ACPI_OEM_ID) != sizeof(h->oem_id));
+     memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id));
++    BUILD_BUG_ON(sizeof(ACPI_OEM_TABLE_ID) != sizeof(h->oem_table_id));
+     memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID, sizeof(h->oem_table_id));
+     h->oem_revision = 0;
++    BUILD_BUG_ON(sizeof(ACPI_ASL_COMPILER_ID) != sizeof(h->asl_compiler_id));
+     memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID,
+            sizeof(h->asl_compiler_id));
+     h->asl_compiler_revision = 0;
recipes-extended/xen/xen_4.11.0.bb +1 -0
index 7884194..d7cff32 100644
@@ -4,6 +4,7 @@ require xen.inc
 SRC_URI = " \
     https://downloads.xenproject.org/release/xen/${PV}/xen-${PV}.tar.gz \
     file://tools-xentop-vwprintw.patch \
+    file://xen-4.11-arm-acpi-fix-string-lengths.patch \
     "
 
 SRC_URI[md5sum] = "cbec0600284921744bc14119f4ed3fff"
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/3 xen: fix truncation warning in tools build for ARM 32-bit

In reply to Christopher Clark

Adds xen-tools-xenpmd-snprintf.patch to fix string format compiler truncation warning in xenpmd: assists the compiler by masking the value to provide an obvious low upper bound for the value range.

---
 .../xen/files/xen-tools-xenpmd-snprintf.patch      | 78 ++++++++++++++++++++++
 recipes-extended/xen/xen_4.11.0.bb                 |  1 +
 2 files changed, 79 insertions(+)
 create mode 100644 recipes-extended/xen/files/xen-tools-xenpmd-snprintf.patch
recipes-extended/xen/files/xen-tools-xenpmd-snprintf.patch new file +78 -0
new file mode 100644
index 0000000..aac7282
@@ -0,0 +1,78 @@
+From e4d78a67ffbacf30b66464080898227f18f6bf49 Mon Sep 17 00:00:00 2001
+From: Christopher Clark <[email protected]>
+Date: Fri, 17 Aug 2018 17:46:10 -0700
+Subject: [PATCH] xenpmd: prevent format-truncation warning with gcc 8.2 + ARM
+ 32-bit
+To: [email protected]
+Cc: [email protected],
+    [email protected]
+
+xenpmd writes battery information to xenstore, including a string with a
+formatted hex value calculated from summing the lengths of four strings,
+plus some constants.
+
+Each of the four strings has a maximum length of 31 bytes, excluding the
+terminating zero byte. The strings are stored in 32-byte arrays in a
+struct that is zeroed before it is populated, and logic that writes to
+the strings uses strncpy and explicit zero termination.
+
+The maximum value to be supplied to the xenstore string is:
+  (9 * 4) + (31 * 4) + 4 , which is 164, ie. 0xa4.
+
+When used with this value, '%02x' will always fit within 3 bytes, but
+gcc 8.2 is apparently not able to deduce this (observed when building
+for a 32-bit ARM platform).
+
+This commit assists the compiler by applying a mask (0xff) to the value,
+enabling it to observe a lower maximum value and so pass the truncation
+length check.
+
+Prior to this change, building fails with the compiler warning:
+
+| xenpmd.c: In function 'write_battery_info_to_xenstore':
+| xenpmd.c:354:23: error: '%02x' directive output may be truncated
+writing between 2 and 8 bytes into a region of size 3
+[-Werror=format-truncation=]
+|      snprintf(val, 3, "%02x",
+|                        ^~~~
+| xenpmd.c:354:22: note: directive argument in the range [40, 2147483778]
+|      snprintf(val, 3, "%02x",
+|                       ^~~~~~
+| xenpmd.c:354:5: note: 'snprintf' output between 3 and 9 bytes into a
+destination of size 3
+|      snprintf(val, 3, "%02x",
+|      ^~~~~~~~~~~~~~~~~~~~~~~~
+|               (unsigned int)(9*4 +
+|               ~~~~~~~~~~~~~~~~~~~~
+|                              strlen(info->model_number) +
+|                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+|                              strlen(info->serial_number) +
+|                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+|                              strlen(info->battery_type) +
+|                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+|                              strlen(info->oem_info) + 4));
+|                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+| cc1: all warnings being treated as errors
+
+Signed-off-by: Christopher Clark <[email protected]>
+---
+ tools/xenpmd/xenpmd.c | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c
+index 56412a9..0c0787e 100644
+--- a/tools/xenpmd/xenpmd.c
++++ b/tools/xenpmd/xenpmd.c
+@@ -350,8 +350,10 @@ void write_battery_info_to_xenstore(struct battery_info *info)
+    
+     memset(val, 0, 1024);
+     memset(string_info, 0, 256);
+-    /* write 9 dwords (so 9*4) + length of 4 strings + 4 null terminators */
+-    snprintf(val, 3, "%02x", 
++    /* write 9 dwords (so 9*4) + length of 4 strings + 4 null terminators.
++     * mask informs the compiler that format truncation will not occur.
++     */
++    snprintf(val, 3, "%02x", 0xff &
+              (unsigned int)(9*4 +
+                             strlen(info->model_number) +
+                             strlen(info->serial_number) +
recipes-extended/xen/xen_4.11.0.bb +1 -0
index d7cff32..40e7340 100644
@@ -5,6 +5,7 @@ SRC_URI = " \
     https://downloads.xenproject.org/release/xen/${PV}/xen-${PV}.tar.gz \
     file://tools-xentop-vwprintw.patch \
     file://xen-4.11-arm-acpi-fix-string-lengths.patch \
+    file://xen-tools-xenpmd-snprintf.patch \
     "
 
 SRC_URI[md5sum] = "cbec0600284921744bc14119f4ed3fff"
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/3 xen: enable 32-bit ARM builds

In reply to Christopher Clark

Enable recipe for COMPATIBLE_HOST = 'arm-.*-linux-gnueabi' Tested with a cubietruck, upstream's reference device for this class.

---
 recipes-extended/xen/xen.inc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
recipes-extended/xen/xen.inc +6 -1
index 38cecd1..bf4b3c2 100644
@@ -5,7 +5,7 @@ SECTION = "console/tools"
 
 LIC_FILES_CHKSUM = "file://COPYING;md5=bbb4b1bdc2c3b6743da3c39d03249095"
 
-COMPATIBLE_HOST = '(x86_64.*).*-linux|aarch64.*-linux'
+COMPATIBLE_HOST = '(x86_64.*).*-linux|aarch64.*-linux|arm-.*-linux-gnueabi'
 
 inherit autotools-brokensep setuptools update-rc.d systemd deploy
 
@@ -918,6 +918,11 @@ do_post_patch() {
     fi
 }
 
+do_post_patch_append_arm()  {
+    # The hypervisor binary must not be built with the hard floating point ABI.
+    echo "CC := \$(filter-out ${TUNE_CCARGS},\$(CC))" >> ${B}/xen/arch/arm/Rules.mk
+}
+
 addtask post_patch after do_patch before do_configure
 
 do_stubs() {
Signature · 1 line
2.7.4
#4 lore raw
In reply to Christopher Clark

merged.

Bruce

Quoted 27 lines · Christopher Clark

From: Christopher Clark <[email protected]>

This series fixes the Xen build for 64-bit ARM targets with gcc 8.2 with a minor patch to correct static string lengths, already reviewed upstream:
https://lists.xenproject.org/archives/html/xen-devel/2018-08/msg01367.html

and introduces 32-bit ARM compatibility, verified by testing with a cubietruck. This currently requires another tiny patch to suppress a new (false positive) compiler warning.

Christopher Clark (3):
xen: Fix build on arm64 w/ gcc 8.2
xen: fix truncation warning in tools build for ARM 32-bit
xen: enable 32-bit ARM builds

 .../xen-4.11-arm-acpi-fix-string-lengths.patch     | 101 +++++++++++++++++++++
 .../xen/files/xen-tools-xenpmd-snprintf.patch      |  78 ++++++++++++++++
 recipes-extended/xen/xen.inc                       |   7 +-
 recipes-extended/xen/xen_4.11.0.bb                 |   2 +
 4 files changed, 187 insertions(+), 1 deletion(-)
 create mode 100644 recipes-extended/xen/files/xen-4.11-arm-acpi-fix-string-lengths.patch
 create mode 100644 recipes-extended/xen/files/xen-tools-xenpmd-snprintf.patch

--
2.7.4

Signature · 2 lines
"Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end"