Skip to contentSkip to conversation

xen/arm: Unbreak ACPI

PATCH In review Julien Grall 4 participants 26 messages Oct 23, 2020 – Nov 23, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover xen/arm: Unbreak ACPI

From: Julien Grall <[email protected]>

Hi all,

Xen on ARM has been broken for quite a while on ACPI systems. This series aims to fix it.

This series also introduced support for ACPI 5.1. This allows Xen to boot on QEMU.

I have only build tested the x86 side so far.

Cheers,

Julien Grall (7):
xen/acpi: Rework acpi_os_map_memory() and acpi_os_unmap_memory() xen/arm: acpi: The fixmap area should always be cleared during
failure/unmap
xen/arm: Check if the platform is not using ACPI before initializing
Dom0less
xen/arm: Introduce fw_unreserved_regions() and use it xen/arm: acpi: add BAD_MADT_GICC_ENTRY() macro
xen/arm: gic-v2: acpi: Use the correct length for the GICC structure xen/arm: acpi: Allow Xen to boot with ACPI 5.1

 xen/arch/arm/acpi/boot.c    |  6 +--
 xen/arch/arm/acpi/lib.c     | 79 ++++++++++++++++++++++++++++++-------
 xen/arch/arm/gic-v2.c       |  5 ++-
 xen/arch/arm/gic-v3.c       |  2 +-
 xen/arch/arm/kernel.c       |  2 +-
 xen/arch/arm/setup.c        | 25 +++++++++---
 xen/arch/x86/acpi/lib.c     | 18 +++++++++
 xen/drivers/acpi/osl.c      | 34 ++++++++--------
 xen/include/asm-arm/acpi.h  |  8 ++++
 xen/include/asm-arm/setup.h |  3 +-
 xen/include/xen/acpi.h      |  1 +
 11 files changed, 139 insertions(+), 44 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/7 xen/acpi: Rework acpi_os_map_memory() and acpi_os_unmap_memory()

From: Julien Grall <[email protected]>

The functions acpi_os_{un,}map_memory() are meant to be arch-agnostic while the __acpi_os_{un,}map_memory() are meant to be arch-specific.

Currently, the former are still containing x86 specific code.

To avoid this rather strange split, the generic helpers are reworked so they are arch-agnostic. This requires the introduction of a new helper __acpi_os_unmap_memory() that will undo any mapping done by __acpi_os_map_memory().

Currently, the arch-helper for unmap is basically a no-op so it only returns whether the mapping was arch specific. But this will change in the future.

Note that the x86 version of acpi_os_map_memory() was already able to able the 1MB region. Hence why there is no addition of new code.

---
Changes in v2:
- Constify ptr in __acpi_unmap_table()
- Coding style fixes
- Fix build on arm64
- Use PAGE_OFFSET() rather than open-coding it
- Add Rahul's tested-by and reviewed-by

---
 xen/arch/arm/acpi/lib.c | 12 ++++++++++++
 xen/arch/x86/acpi/lib.c | 18 ++++++++++++++++++
 xen/drivers/acpi/osl.c  | 34 ++++++++++++++++++----------------
 xen/include/xen/acpi.h  |  1 +
 4 files changed, 49 insertions(+), 16 deletions(-)
xen/arch/arm/acpi/lib.c +12 -0
index 4fc6e17322c1..fcc186b03399 100644
@@ -30,6 +30,10 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
     unsigned long base, offset, mapped_size;
     int idx;
 
+    /* No arch specific implementation after early boot */
+    if ( system_state >= SYS_STATE_boot )
+        return NULL;
+
     offset = phys & (PAGE_SIZE - 1);
     mapped_size = PAGE_SIZE - offset;
     set_fixmap(FIXMAP_ACPI_BEGIN, maddr_to_mfn(phys), PAGE_HYPERVISOR);
@@ -49,6 +53,14 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
     return ((char *) base + offset);
 }
 
+bool __acpi_unmap_table(const void *ptr, unsigned long size)
+{
+    vaddr_t vaddr = (vaddr_t)ptr;
+
+    return ((vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) &&
+            (vaddr < (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE)));
+}
+
 /* True to indicate PSCI 0.2+ is implemented */
 bool __init acpi_psci_present(void)
 {
xen/arch/x86/acpi/lib.c +18 -0
index 265b9ad81905..a22414a05c13 100644
@@ -46,6 +46,10 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
 	if ((phys + size) <= (1 * 1024 * 1024))
 		return __va(phys);
 
+	/* No further arch specific implementation after early boot */
+	if (system_state >= SYS_STATE_boot)
+		return NULL;
+
 	offset = phys & (PAGE_SIZE - 1);
 	mapped_size = PAGE_SIZE - offset;
 	set_fixmap(FIX_ACPI_END, phys);
@@ -66,6 +70,20 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
 	return ((char *) base + offset);
 }
 
+bool __acpi_unmap_table(const void *ptr, unsigned long size)
+{
+	unsigned long vaddr = (unsigned long)ptr;
+
+	if ((vaddr >= DIRECTMAP_VIRT_START) &&
+	    (vaddr < DIRECTMAP_VIRT_END)) {
+		ASSERT(!((__pa(ptr) + size - 1) >> 20));
+		return true;
+	}
+
+	return ((vaddr >= __fix_to_virt(FIX_ACPI_END)) &&
+		(vaddr < (__fix_to_virt(FIX_ACPI_BEGIN) + PAGE_SIZE)));
+}
+
 unsigned int acpi_get_processor_id(unsigned int cpu)
 {
 	unsigned int acpiid, apicid;
xen/drivers/acpi/osl.c +18 -16
index 4c8bb7839eda..389505f78666 100644
@@ -92,27 +92,29 @@ acpi_physical_address __init acpi_os_get_root_pointer(void)
 void __iomem *
 acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
 {
-	if (system_state >= SYS_STATE_boot) {
-		mfn_t mfn = _mfn(PFN_DOWN(phys));
-		unsigned int offs = phys & (PAGE_SIZE - 1);
-
-		/* The low first Mb is always mapped on x86. */
-		if (IS_ENABLED(CONFIG_X86) && !((phys + size - 1) >> 20))
-			return __va(phys);
-		return __vmap(&mfn, PFN_UP(offs + size), 1, 1,
-			      ACPI_MAP_MEM_ATTR, VMAP_DEFAULT) + offs;
-	}
-	return __acpi_map_table(phys, size);
+	void *ptr;
+	mfn_t mfn = _mfn(PFN_DOWN(phys));
+	unsigned int offs = PAGE_OFFSET(phys);
+
+	/* Try the arch specific implementation first */
+	ptr = __acpi_map_table(phys, size);
+	if (ptr)
+		return ptr;
+
+	/* No common implementation for early boot map */
+	if (unlikely(system_state < SYS_STATE_boot))
+		return NULL;
+
+	ptr = __vmap(&mfn, PFN_UP(offs + size), 1, 1,
+		     ACPI_MAP_MEM_ATTR, VMAP_DEFAULT);
+
+	return !ptr ? NULL : (ptr + offs);
 }
 
 void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
 {
-	if (IS_ENABLED(CONFIG_X86) &&
-	    (unsigned long)virt >= DIRECTMAP_VIRT_START &&
-	    (unsigned long)virt < DIRECTMAP_VIRT_END) {
-		ASSERT(!((__pa(virt) + size - 1) >> 20));
+	if (__acpi_unmap_table(virt, size))
 		return;
-	}
 
 	if (system_state >= SYS_STATE_boot)
 		vunmap((void *)((unsigned long)virt & PAGE_MASK));
xen/include/xen/acpi.h +1 -0
index c945ab05c864..21d5e9feb5ae 100644
@@ -68,6 +68,7 @@ typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, co
 
 unsigned int acpi_get_processor_id (unsigned int cpu);
 char * __acpi_map_table (paddr_t phys_addr, unsigned long size);
+bool __acpi_unmap_table(const void *ptr, unsigned long size);
 int acpi_boot_init (void);
 int acpi_boot_table_init (void);
 int acpi_numa_init (void);
Signature · 1 line
2.17.1
Reviewed-by on v2 1/7
#2 lore raw

Re: [PATCH v2 1/7] xen/acpi: Rework acpi_os_map_memory() and acpi_os_unmap_memory()

Quoted 16 lines · Julien Grall

From: Julien Grall <[email protected]>

The functions acpi_os_{un,}map_memory() are meant to be arch-agnostic while the __acpi_os_{un,}map_memory() are meant to be arch-specific.

Currently, the former are still containing x86 specific code.

To avoid this rather strange split, the generic helpers are reworked so they are arch-agnostic. This requires the introduction of a new helper __acpi_os_unmap_memory() that will undo any mapping done by __acpi_os_map_memory().

Currently, the arch-helper for unmap is basically a no-op so it only returns whether the mapping was arch specific. But this will change in the future.

Quoted 6 lines

Note that the x86 version of acpi_os_map_memory() was already able to able the 1MB region. Hence why there is no addition of new code.

Non-Arm parts

Jan

Acked-by on v2 1/7
#3 lore raw

Re: [PATCH v2 1/7] xen/acpi: Rework acpi_os_map_memory() and acpi_os_unmap_memory()

In reply to Julien Grall
Quoted 16 lines · Julien Grall

From: Julien Grall <[email protected]>

The functions acpi_os_{un,}map_memory() are meant to be arch-agnostic while the __acpi_os_{un,}map_memory() are meant to be arch-specific.

Currently, the former are still containing x86 specific code.

To avoid this rather strange split, the generic helpers are reworked so they are arch-agnostic. This requires the introduction of a new helper __acpi_os_unmap_memory() that will undo any mapping done by __acpi_os_map_memory().

Currently, the arch-helper for unmap is basically a no-op so it only returns whether the mapping was arch specific. But this will change in the future.

Quoted 6 lines

Note that the x86 version of acpi_os_map_memory() was already able to able the 1MB region. Hence why there is no addition of new code.

Quoted 145 lines

---
Changes in v2:
- Constify ptr in __acpi_unmap_table()
- Coding style fixes
- Fix build on arm64
- Use PAGE_OFFSET() rather than open-coding it
- Add Rahul's tested-by and reviewed-by

---
 xen/arch/arm/acpi/lib.c | 12 ++++++++++++
 xen/arch/x86/acpi/lib.c | 18 ++++++++++++++++++
 xen/drivers/acpi/osl.c  | 34 ++++++++++++++++++----------------
 xen/include/xen/acpi.h  |  1 +
 4 files changed, 49 insertions(+), 16 deletions(-)
xen/arch/arm/acpi/lib.c +12 -0
index 4fc6e17322c1..fcc186b03399 100644
@@ -30,6 +30,10 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
     unsigned long base, offset, mapped_size;
     int idx;
 
+    /* No arch specific implementation after early boot */
+    if ( system_state >= SYS_STATE_boot )
+        return NULL;
+
     offset = phys & (PAGE_SIZE - 1);
     mapped_size = PAGE_SIZE - offset;
     set_fixmap(FIXMAP_ACPI_BEGIN, maddr_to_mfn(phys), PAGE_HYPERVISOR);
@@ -49,6 +53,14 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
     return ((char *) base + offset);
 }
 
+bool __acpi_unmap_table(const void *ptr, unsigned long size)
+{
+    vaddr_t vaddr = (vaddr_t)ptr;
+
+    return ((vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) &&
+            (vaddr < (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE)));
+}
+
 /* True to indicate PSCI 0.2+ is implemented */
 bool __init acpi_psci_present(void)
 {
xen/arch/x86/acpi/lib.c +18 -0
index 265b9ad81905..a22414a05c13 100644
@@ -46,6 +46,10 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
 	if ((phys + size) <= (1 * 1024 * 1024))
 		return __va(phys);
 
+	/* No further arch specific implementation after early boot */
+	if (system_state >= SYS_STATE_boot)
+		return NULL;
+
 	offset = phys & (PAGE_SIZE - 1);
 	mapped_size = PAGE_SIZE - offset;
 	set_fixmap(FIX_ACPI_END, phys);
@@ -66,6 +70,20 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
 	return ((char *) base + offset);
 }
 
+bool __acpi_unmap_table(const void *ptr, unsigned long size)
+{
+	unsigned long vaddr = (unsigned long)ptr;
+
+	if ((vaddr >= DIRECTMAP_VIRT_START) &&
+	    (vaddr < DIRECTMAP_VIRT_END)) {
+		ASSERT(!((__pa(ptr) + size - 1) >> 20));
+		return true;
+	}
+
+	return ((vaddr >= __fix_to_virt(FIX_ACPI_END)) &&
+		(vaddr < (__fix_to_virt(FIX_ACPI_BEGIN) + PAGE_SIZE)));
+}
+
 unsigned int acpi_get_processor_id(unsigned int cpu)
 {
 	unsigned int acpiid, apicid;
xen/drivers/acpi/osl.c +18 -16
index 4c8bb7839eda..389505f78666 100644
@@ -92,27 +92,29 @@ acpi_physical_address __init acpi_os_get_root_pointer(void)
 void __iomem *
 acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
 {
-	if (system_state >= SYS_STATE_boot) {
-		mfn_t mfn = _mfn(PFN_DOWN(phys));
-		unsigned int offs = phys & (PAGE_SIZE - 1);
-
-		/* The low first Mb is always mapped on x86. */
-		if (IS_ENABLED(CONFIG_X86) && !((phys + size - 1) >> 20))
-			return __va(phys);
-		return __vmap(&mfn, PFN_UP(offs + size), 1, 1,
-			      ACPI_MAP_MEM_ATTR, VMAP_DEFAULT) + offs;
-	}
-	return __acpi_map_table(phys, size);
+	void *ptr;
+	mfn_t mfn = _mfn(PFN_DOWN(phys));
+	unsigned int offs = PAGE_OFFSET(phys);
+
+	/* Try the arch specific implementation first */
+	ptr = __acpi_map_table(phys, size);
+	if (ptr)
+		return ptr;
+
+	/* No common implementation for early boot map */
+	if (unlikely(system_state < SYS_STATE_boot))
+		return NULL;
+
+	ptr = __vmap(&mfn, PFN_UP(offs + size), 1, 1,
+		     ACPI_MAP_MEM_ATTR, VMAP_DEFAULT);
+
+	return !ptr ? NULL : (ptr + offs);
 }
 
 void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
 {
-	if (IS_ENABLED(CONFIG_X86) &&
-	    (unsigned long)virt >= DIRECTMAP_VIRT_START &&
-	    (unsigned long)virt < DIRECTMAP_VIRT_END) {
-		ASSERT(!((__pa(virt) + size - 1) >> 20));
+	if (__acpi_unmap_table(virt, size))
 		return;
-	}
 
 	if (system_state >= SYS_STATE_boot)
 		vunmap((void *)((unsigned long)virt & PAGE_MASK));
xen/include/xen/acpi.h +1 -0
index c945ab05c864..21d5e9feb5ae 100644
@@ -68,6 +68,7 @@ typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, co
 
 unsigned int acpi_get_processor_id (unsigned int cpu);
 char * __acpi_map_table (paddr_t phys_addr, unsigned long size);
+bool __acpi_unmap_table(const void *ptr, unsigned long size);
 int acpi_boot_init (void);
 int acpi_boot_table_init (void);
 int acpi_numa_init (void);
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH v2 1/7] xen/acpi: Rework acpi_os_map_memory() and acpi_os_unmap_memory()

In reply to Julien Grall
Quoted 16 lines · Julien Grall

From: Julien Grall <[email protected]>

The functions acpi_os_{un,}map_memory() are meant to be arch-agnostic while the __acpi_os_{un,}map_memory() are meant to be arch-specific.

Currently, the former are still containing x86 specific code.

To avoid this rather strange split, the generic helpers are reworked so they are arch-agnostic. This requires the introduction of a new helper __acpi_os_unmap_memory() that will undo any mapping done by __acpi_os_map_memory().

Currently, the arch-helper for unmap is basically a no-op so it only returns whether the mapping was arch specific. But this will change in the future.

Quoted 6 lines

Note that the x86 version of acpi_os_map_memory() was already able to able the 1MB region. Hence why there is no addition of new code.

This change breaks shutdown on x86. Either Dom0 no longer requests S5 (in which case I'd expect some data collection there to fail), or Xen refuses the request. As a result, things go the machine_halt() path instead. I've looked over the change again, but couldn't spot anything yet which might explain the behavior. Yet reverting (just the non-Arm parts, so I wouldn't have to revert multiple commits) made things work again.

Jan

#5 lore raw

Re: [PATCH v2 1/7] xen/acpi: Rework acpi_os_map_memory() and acpi_os_unmap_memory()

Hi Jan,

Quoted 24 lines · Jan Beulich
Quoted 16 lines · Julien Grall

From: Julien Grall <[email protected]>

The functions acpi_os_{un,}map_memory() are meant to be arch-agnostic while the __acpi_os_{un,}map_memory() are meant to be arch-specific.

Currently, the former are still containing x86 specific code.

To avoid this rather strange split, the generic helpers are reworked so they are arch-agnostic. This requires the introduction of a new helper __acpi_os_unmap_memory() that will undo any mapping done by __acpi_os_map_memory().

Currently, the arch-helper for unmap is basically a no-op so it only returns whether the mapping was arch specific. But this will change in the future.

Quoted 6 lines

Note that the x86 version of acpi_os_map_memory() was already able to able the 1MB region. Hence why there is no addition of new code.

Quoted 7 lines

This change breaks shutdown on x86. Either Dom0 no longer requests S5 (in which case I'd expect some data collection there to fail), or Xen refuses the request. As a result, things go the machine_halt() path instead. I've looked over the change again, but couldn't spot anything yet which might explain the behavior. Yet reverting (just the non-Arm parts, so I wouldn't have to revert multiple commits) made things work again.

Thank you for the report and sorry for the breakage.

When changing the behavior of __acpi_map_table(), I failed to realize that some x86 code will call it directly rather than acpi_os_map_memory(). This is the case of acpi_fadt_parse_sleep_info() which detects whether ACPI can be used to put the system in sleep state.

I am tempted to require all the callers requiring to map memory to use the generic implementation acpi_os_{, un}map_memory().

However, AFAICT, some of the callers (such as acpi_sleep_prepare()) are using __acpi_map_table() because the function never failed before. By using the generic function, all mappings after boot will be using vmap() which may fail.

Would this new behavior be acceptable to you?

Cheers,

Signature · 1 line
Julien Grall
#6 lore raw

Re: [PATCH v2 1/7] xen/acpi: Rework acpi_os_map_memory() and acpi_os_unmap_memory()

Quoted 42 lines · Julien Grall

Hi Jan,

Quoted 24 lines · Jan Beulich
Quoted 16 lines · Julien Grall

From: Julien Grall <[email protected]>

The functions acpi_os_{un,}map_memory() are meant to be arch-agnostic while the __acpi_os_{un,}map_memory() are meant to be arch-specific.

Currently, the former are still containing x86 specific code.

To avoid this rather strange split, the generic helpers are reworked so they are arch-agnostic. This requires the introduction of a new helper __acpi_os_unmap_memory() that will undo any mapping done by __acpi_os_map_memory().

Currently, the arch-helper for unmap is basically a no-op so it only returns whether the mapping was arch specific. But this will change in the future.

Quoted 6 lines

Note that the x86 version of acpi_os_map_memory() was already able to able the 1MB region. Hence why there is no addition of new code.

Quoted 7 lines

This change breaks shutdown on x86. Either Dom0 no longer requests S5 (in which case I'd expect some data collection there to fail), or Xen refuses the request. As a result, things go the machine_halt() path instead. I've looked over the change again, but couldn't spot anything yet which might explain the behavior. Yet reverting (just the non-Arm parts, so I wouldn't have to revert multiple commits) made things work again.

Thank you for the report and sorry for the breakage.

When changing the behavior of __acpi_map_table(), I failed to realize that some x86 code will call it directly rather than acpi_os_map_memory(). This is the case of acpi_fadt_parse_sleep_info() which detects whether ACPI can be used to put the system in sleep state.

Quoted 7 lines

I am tempted to require all the callers requiring to map memory to use the generic implementation acpi_os_{, un}map_memory().

However, AFAICT, some of the callers (such as acpi_sleep_prepare()) are using __acpi_map_table() because the function never failed before. By using the generic function, all mappings after boot will be using vmap() which may fail.

The FACS mapping can (and perhaps should long have been) be switched to acpi_os_map_memory(). The other two direct uses of the function, however, will require more care. I'm in the process or making a series, also noticing some further shortcomings of the FACS handling.

Jan

#7 lore raw

PATCH v2 2/7 xen/arm: acpi: The fixmap area should always be cleared during failure/unmap

In reply to Julien Grall

From: Julien Grall <[email protected]>

Commit 022387ee1ad3 "xen/arm: mm: Don't open-code Xen PT update in {set, clear}_fixmap()" enforced that each set_fixmap() should be paired with a clear_fixmap(). Any failure to follow the model would result to a platform crash.

Unfortunately, the use of fixmap in the ACPI code was overlooked as it is calling set_fixmap() but not clear_fixmap().

The function __acpi_os_map_table() is reworked so:
- We know before the mapping whether the fixmap region is big enough for the mapping.
- It will fail if the fixmap is already in use. This is not a change of behavior but clarifying the current expectation to avoid hitting a BUG().

The function __acpi_os_unmap_table() will now call clear_fixmap().

---

The discussion on the original thread [1] suggested to also zap it on x86. This is technically not necessary today, so it is left alone for now.

I looked at making the fixmap code common but the index are inverted between Arm and x86.

Changes in v2:
- Clarify the commit message
- Fix the size computation in __acpi_unmap_table()

[1] https://lore.kernel.org/xen-devel/[email protected]/

---
 xen/arch/arm/acpi/lib.c | 73 +++++++++++++++++++++++++++++++----------
 1 file changed, 56 insertions(+), 17 deletions(-)
xen/arch/arm/acpi/lib.c +56 -17
index fcc186b03399..b755620e67b5 100644
@@ -25,40 +25,79 @@
 #include <xen/init.h>
 #include <xen/mm.h>
 
+static bool fixmap_inuse;
+
 char *__acpi_map_table(paddr_t phys, unsigned long size)
 {
-    unsigned long base, offset, mapped_size;
-    int idx;
+    unsigned long base, offset;
+    mfn_t mfn;
+    unsigned int idx;
 
     /* No arch specific implementation after early boot */
     if ( system_state >= SYS_STATE_boot )
         return NULL;
 
     offset = phys & (PAGE_SIZE - 1);
-    mapped_size = PAGE_SIZE - offset;
-    set_fixmap(FIXMAP_ACPI_BEGIN, maddr_to_mfn(phys), PAGE_HYPERVISOR);
-    base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
+    base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN) + offset;
+
+    /* Check the fixmap is big enough to map the region */
+    if ( (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE - base) < size )
+        return NULL;
+
+    /* With the fixmap, we can only map one region at the time */
+    if ( fixmap_inuse )
+        return NULL;
 
-    /* Most cases can be covered by the below. */
+    fixmap_inuse = true;
+
+    size += offset;
+    mfn = maddr_to_mfn(phys);
     idx = FIXMAP_ACPI_BEGIN;
-    while ( mapped_size < size )
-    {
-        if ( ++idx > FIXMAP_ACPI_END )
-            return NULL;    /* cannot handle this */
-        phys += PAGE_SIZE;
-        set_fixmap(idx, maddr_to_mfn(phys), PAGE_HYPERVISOR);
-        mapped_size += PAGE_SIZE;
-    }
 
-    return ((char *) base + offset);
+    do {
+        set_fixmap(idx, mfn, PAGE_HYPERVISOR);
+        size -= min(size, (unsigned long)PAGE_SIZE);
+        mfn = mfn_add(mfn, 1);
+        idx++;
+    } while ( size > 0 );
+
+    return (char *)base;
 }
 
 bool __acpi_unmap_table(const void *ptr, unsigned long size)
 {
     vaddr_t vaddr = (vaddr_t)ptr;
+    unsigned int idx;
+
+    /* We are only handling fixmap address in the arch code */
+    if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
+         (vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END)) )
+        return false;
+
+    /*
+     * __acpi_map_table() will always return a pointer in the first page
+     * for the ACPI fixmap region. The caller is expected to free with
+     * the same address.
+     */
+    ASSERT((vaddr & PAGE_MASK) == FIXMAP_ADDR(FIXMAP_ACPI_BEGIN));
+
+    /* The region allocated fit in the ACPI fixmap region. */
+    ASSERT(size < (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE - vaddr));
+    ASSERT(fixmap_inuse);
+
+    fixmap_inuse = false;
+
+    size += vaddr - FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
+    idx = FIXMAP_ACPI_BEGIN;
+
+    do
+    {
+        clear_fixmap(idx);
+        size -= min(size, (unsigned long)PAGE_SIZE);
+        idx++;
+    } while ( size > 0 );
 
-    return ((vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) &&
-            (vaddr < (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE)));
+    return true;
 }
 
 /* True to indicate PSCI 0.2+ is implemented */
Signature · 1 line
2.17.1
#8 lore raw

Re: [PATCH v2 2/7] xen/arm: acpi: The fixmap area should always be cleared during failure/unmap

Quoted 100 lines · Julien Grall

From: Julien Grall <[email protected]>

Commit 022387ee1ad3 "xen/arm: mm: Don't open-code Xen PT update in {set, clear}_fixmap()" enforced that each set_fixmap() should be paired with a clear_fixmap(). Any failure to follow the model would result to a platform crash.

Unfortunately, the use of fixmap in the ACPI code was overlooked as it is calling set_fixmap() but not clear_fixmap().

The function __acpi_os_map_table() is reworked so:
- We know before the mapping whether the fixmap region is big enough for the mapping.
- It will fail if the fixmap is already in use. This is not a change of behavior but clarifying the current expectation to avoid hitting a BUG().

The function __acpi_os_unmap_table() will now call clear_fixmap().

---

The discussion on the original thread [1] suggested to also zap it on x86. This is technically not necessary today, so it is left alone for now.

I looked at making the fixmap code common but the index are inverted between Arm and x86.

Changes in v2:
- Clarify the commit message
- Fix the size computation in __acpi_unmap_table()

[1] https://lore.kernel.org/xen-devel/[email protected]/

---
 xen/arch/arm/acpi/lib.c | 73 +++++++++++++++++++++++++++++++----------
 1 file changed, 56 insertions(+), 17 deletions(-)
xen/arch/arm/acpi/lib.c +26 -15
index fcc186b03399..b755620e67b5 100644
@@ -25,40 +25,79 @@
 #include <xen/init.h>
 #include <xen/mm.h>
 
+static bool fixmap_inuse;
+
 char *__acpi_map_table(paddr_t phys, unsigned long size)
 {
-    unsigned long base, offset, mapped_size;
-    int idx;
+    unsigned long base, offset;
+    mfn_t mfn;
+    unsigned int idx;
 
     /* No arch specific implementation after early boot */
     if ( system_state >= SYS_STATE_boot )
         return NULL;
 
     offset = phys & (PAGE_SIZE - 1);
-    mapped_size = PAGE_SIZE - offset;
-    set_fixmap(FIXMAP_ACPI_BEGIN, maddr_to_mfn(phys), PAGE_HYPERVISOR);
-    base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
+    base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN) + offset;
+
+    /* Check the fixmap is big enough to map the region */
+    if ( (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE - base) < size )
+        return NULL;
+
+    /* With the fixmap, we can only map one region at the time */
+    if ( fixmap_inuse )
+        return NULL;
 
-    /* Most cases can be covered by the below. */
+    fixmap_inuse = true;
+
+    size += offset;
+    mfn = maddr_to_mfn(phys);
     idx = FIXMAP_ACPI_BEGIN;
-    while ( mapped_size < size )
-    {
-        if ( ++idx > FIXMAP_ACPI_END )
-            return NULL;    /* cannot handle this */
-        phys += PAGE_SIZE;
-        set_fixmap(idx, maddr_to_mfn(phys), PAGE_HYPERVISOR);
-        mapped_size += PAGE_SIZE;
-    }
 
-    return ((char *) base + offset);
+    do {
+        set_fixmap(idx, mfn, PAGE_HYPERVISOR);
+        size -= min(size, (unsigned long)PAGE_SIZE);
+        mfn = mfn_add(mfn, 1);
+        idx++;
+    } while ( size > 0 );
+
+    return (char *)base;

xen/arch/arm/acpi/lib.c line 74

Quoted 10 lines
xen/arch/arm/acpi/lib.c +5 -0
 }
 
 bool __acpi_unmap_table(const void *ptr, unsigned long size)
 {
     vaddr_t vaddr = (vaddr_t)ptr;
+    unsigned int idx;
+
+    /* We are only handling fixmap address in the arch code */
+    if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
+         (vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END)) )

Is it missing "+ PAGE_SIZE"?

if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
(vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE) )

Quoted 31 lines
xen/arch/arm/acpi/lib.c +25 -2
+        return false;
+
+    /*
+     * __acpi_map_table() will always return a pointer in the first page
+     * for the ACPI fixmap region. The caller is expected to free with
+     * the same address.
+     */
+    ASSERT((vaddr & PAGE_MASK) == FIXMAP_ADDR(FIXMAP_ACPI_BEGIN));
+
+    /* The region allocated fit in the ACPI fixmap region. */
+    ASSERT(size < (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE - vaddr));
+    ASSERT(fixmap_inuse);
+
+    fixmap_inuse = false;
+
+    size += vaddr - FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
+    idx = FIXMAP_ACPI_BEGIN;
+
+    do
+    {
+        clear_fixmap(idx);
+        size -= min(size, (unsigned long)PAGE_SIZE);
+        idx++;
+    } while ( size > 0 );
 
-    return ((vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) &&
-            (vaddr < (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE)));
+    return true;
 }
 
 /* True to indicate PSCI 0.2+ is implemented */
#9 lore raw

Re: [PATCH v2 2/7] xen/arm: acpi: The fixmap area should always be cleared during failure/unmap

Hi Stefano,

Quoted 10 lines · Stefano Stabellini

xen/arch/arm/acpi/lib.c line 74

Quoted 8 lines · Julien Grall
  bool __acpi_unmap_table(const void *ptr, unsigned long size)
  {
      vaddr_t vaddr = (vaddr_t)ptr;
xen/arch/arm/acpi/lib.c +5 -0
+    unsigned int idx;
+
+    /* We are only handling fixmap address in the arch code */
+    if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
+         (vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END)) )
Quoted 4 lines

Is it missing "+ PAGE_SIZE"?

if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
(vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE) )

Yes it should be + PAGE_SIZE. Do you mind if I fix it on commit?

Cheers,

Signature · 1 line
Julien Grall
#10 lore raw

Re: [PATCH v2 2/7] xen/arm: acpi: The fixmap area should always be cleared during failure/unmap

Quoted 13 lines · Julien Grall

Hi Stefano,

Quoted 10 lines · Stefano Stabellini
Quoted 8 lines · Julien Grall
  bool __acpi_unmap_table(const void *ptr, unsigned long size)
  {
      vaddr_t vaddr = (vaddr_t)ptr;
xen/arch/arm/acpi/lib.c +5 -0
+    unsigned int idx;
+
+    /* We are only handling fixmap address in the arch code */
+    if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
+         (vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END)) )
Quoted 6 lines
Quoted 4 lines

Is it missing "+ PAGE_SIZE"?

if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
(vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE) )

Yes it should be + PAGE_SIZE. Do you mind if I fix it on commit?

No, I don't mind. Go ahead.

#11 lore raw

Re: [PATCH v2 2/7] xen/arm: acpi: The fixmap area should always be cleared during failure/unmap

Hi,

Quoted 14 lines · Stefano Stabellini
Quoted 13 lines · Julien Grall

Hi Stefano,

Quoted 10 lines · Stefano Stabellini
Quoted 8 lines · Julien Grall
   bool __acpi_unmap_table(const void *ptr, unsigned long size)
   {
       vaddr_t vaddr = (vaddr_t)ptr;
xen/arch/arm/acpi/lib.c +5 -0
+    unsigned int idx;
+
+    /* We are only handling fixmap address in the arch code */
+    if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
+         (vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END)) )
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Is it missing "+ PAGE_SIZE"?

if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
(vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE) )

Yes it should be + PAGE_SIZE. Do you mind if I fix it on commit?

No, I don't mind. Go ahead.

I technically don't have a ack for this patch. Can I consider this as a Acked-by? :)

Cheers,

Signature · 1 line
Julien Grall
#12 lore raw

Re: [PATCH v2 2/7] xen/arm: acpi: The fixmap area should always be cleared during failure/unmap

Quoted 22 lines · Julien Grall

Hi,

Quoted 19 lines · Stefano Stabellini
Quoted 18 lines · Julien Grall

Hi Stefano,

Quoted 14 lines · Stefano Stabellini

xen/arch/arm/acpi/lib.c line 74

Quoted 8 lines · Julien Grall
   bool __acpi_unmap_table(const void *ptr, unsigned long size)
   {
       vaddr_t vaddr = (vaddr_t)ptr;
xen/arch/arm/acpi/lib.c +5 -0
+    unsigned int idx;
+
+    /* We are only handling fixmap address in the arch code */
+    if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
+         (vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END)) )

Is it missing "+ PAGE_SIZE"?

if ( (vaddr < FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) ||
(vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE) )

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Yes it should be + PAGE_SIZE. Do you mind if I fix it on commit?

No, I don't mind. Go ahead.

I technically don't have a ack for this patch. Can I consider this as a Acked-by? :)

#13 lore raw

PATCH v2 3/7 xen/arm: Check if the platform is not using ACPI before initializing Dom0less

In reply to Julien Grall

From: Julien Grall <[email protected]>

Dom0less requires a device-tree. However, since commit 6e3e77120378 "xen/arm: setup: Relocate the Device-Tree later on in the boot", the device-tree will not get unflatten when using ACPI.

This will lead to a crash during boot.

Given the complexity to setup dom0less with ACPI (for instance how to assign device?), we should skip any code related to Dom0less when using ACPI.

---
Changes in v2:
- Add Rahul's tested-by and reviewed-by
- Add Stefano's reviewed-by

---
 xen/arch/arm/setup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/arm/setup.c +2 -1
index f16b33fa87a2..35e5bee04efa 100644
@@ -987,7 +987,8 @@ void __init start_xen(unsigned long boot_phys_offset,
 
     system_state = SYS_STATE_active;
 
-    create_domUs();
+    if ( acpi_disabled )
+        create_domUs();
 
     domain_unpause_by_systemcontroller(dom0);
 
Signature · 1 line
2.17.1
#14 lore raw

PATCH v2 4/7 xen/arm: Introduce fw_unreserved_regions() and use it

In reply to Julien Grall

From: Julien Grall <[email protected]>

Since commit 6e3e77120378 "xen/arm: setup: Relocate the Device-Tree later on in the boot", the device-tree will not be kept mapped when using ACPI.

However, a few places are calling dt_unreserved_regions() which expects a valid DT. This will lead to a crash.

As the DT should not be used for ACPI (other than for detecting the modules), a new function fw_unreserved_regions() is introduced.

It will behave the same way on DT system. On ACPI system, it will unreserve the whole region.

Take the opportunity to clarify that bootinfo.reserved_mem is only used when booting using Device-Tree.

---

Is there any region we should exclude on ACPI?

Changes in v2:
- Add a comment on top of bootinfo.reserved_mem.

---
 xen/arch/arm/kernel.c       |  2 +-
 xen/arch/arm/setup.c        | 22 +++++++++++++++++-----
 xen/include/asm-arm/setup.h |  3 ++-
 3 files changed, 20 insertions(+), 7 deletions(-)
xen/arch/arm/kernel.c +1 -1
index 032923853f2c..ab78689ed2a6 100644
@@ -307,7 +307,7 @@ static __init int kernel_decompress(struct bootmodule *mod)
      * Free the original kernel, update the pointers to the
      * decompressed kernel
      */
-    dt_unreserved_regions(addr, addr + size, init_domheap_pages, 0);
+    fw_unreserved_regions(addr, addr + size, init_domheap_pages, 0);
 
     return 0;
 }
xen/arch/arm/setup.c +17 -5
index 35e5bee04efa..7fcff9af2a7e 100644
@@ -196,8 +196,9 @@ static void __init processor_id(void)
     processor_setup();
 }
 
-void __init dt_unreserved_regions(paddr_t s, paddr_t e,
-                                  void (*cb)(paddr_t, paddr_t), int first)
+static void __init dt_unreserved_regions(paddr_t s, paddr_t e,
+                                         void (*cb)(paddr_t, paddr_t),
+                                         int first)
 {
     int i, nr = fdt_num_mem_rsv(device_tree_flattened);
 
@@ -244,6 +245,17 @@ void __init dt_unreserved_regions(paddr_t s, paddr_t e,
     cb(s, e);
 }
 
+void __init fw_unreserved_regions(paddr_t s, paddr_t e,
+                                  void (*cb)(paddr_t, paddr_t), int first)
+{
+    if ( acpi_disabled )
+        dt_unreserved_regions(s, e, cb, first);
+    else
+        cb(s, e);
+}
+
+
+
 struct bootmodule __init *add_boot_module(bootmodule_kind kind,
                                           paddr_t start, paddr_t size,
                                           bool domU)
@@ -405,7 +417,7 @@ void __init discard_initial_modules(void)
              !mfn_valid(maddr_to_mfn(e)) )
             continue;
 
-        dt_unreserved_regions(s, e, init_domheap_pages, 0);
+        fw_unreserved_regions(s, e, init_domheap_pages, 0);
     }
 
     mi->nr_mods = 0;
@@ -712,7 +724,7 @@ static void __init setup_mm(void)
                 n = mfn_to_maddr(mfn_add(xenheap_mfn_start, xenheap_pages));
             }
 
-            dt_unreserved_regions(s, e, init_boot_pages, 0);
+            fw_unreserved_regions(s, e, init_boot_pages, 0);
 
             s = n;
         }
@@ -765,7 +777,7 @@ static void __init setup_mm(void)
             if ( e > bank_end )
                 e = bank_end;
 
-            dt_unreserved_regions(s, e, init_boot_pages, 0);
+            fw_unreserved_regions(s, e, init_boot_pages, 0);
             s = n;
         }
     }
xen/include/asm-arm/setup.h +2 -1
index 2f8f24e286ed..28bf622aa196 100644
@@ -67,6 +67,7 @@ struct bootcmdlines {
 
 struct bootinfo {
     struct meminfo mem;
+    /* The reserved regions are only used when booting using Device-Tree */
     struct meminfo reserved_mem;
     struct bootmodules modules;
     struct bootcmdlines cmdlines;
@@ -96,7 +97,7 @@ int construct_dom0(struct domain *d);
 void create_domUs(void);
 
 void discard_initial_modules(void);
-void dt_unreserved_regions(paddr_t s, paddr_t e,
+void fw_unreserved_regions(paddr_t s, paddr_t e,
                            void (*cb)(paddr_t, paddr_t), int first);
 
 size_t boot_fdt_info(const void *fdt, paddr_t paddr);
Signature · 1 line
2.17.1
Reviewed-by on v2 4/7
#15 lore raw

Re: [PATCH v2 4/7] xen/arm: Introduce fw_unreserved_regions() and use it

Quoted 12 lines · Julien Grall

From: Julien Grall <[email protected]>

Since commit 6e3e77120378 "xen/arm: setup: Relocate the Device-Tree later on in the boot", the device-tree will not be kept mapped when using ACPI.

However, a few places are calling dt_unreserved_regions() which expects a valid DT. This will lead to a crash.

As the DT should not be used for ACPI (other than for detecting the modules), a new function fw_unreserved_regions() is introduced.

Quoted 7 lines

It will behave the same way on DT system. On ACPI system, it will unreserve the whole region.

Take the opportunity to clarify that bootinfo.reserved_mem is only used when booting using Device-Tree.

Quoted 110 lines

---

Is there any region we should exclude on ACPI?

Changes in v2:
- Add a comment on top of bootinfo.reserved_mem.

---
 xen/arch/arm/kernel.c       |  2 +-
 xen/arch/arm/setup.c        | 22 +++++++++++++++++-----
 xen/include/asm-arm/setup.h |  3 ++-
 3 files changed, 20 insertions(+), 7 deletions(-)
xen/arch/arm/kernel.c +1 -1
index 032923853f2c..ab78689ed2a6 100644
@@ -307,7 +307,7 @@ static __init int kernel_decompress(struct bootmodule *mod)
      * Free the original kernel, update the pointers to the
      * decompressed kernel
      */
-    dt_unreserved_regions(addr, addr + size, init_domheap_pages, 0);
+    fw_unreserved_regions(addr, addr + size, init_domheap_pages, 0);
 
     return 0;
 }
xen/arch/arm/setup.c +17 -5
index 35e5bee04efa..7fcff9af2a7e 100644
@@ -196,8 +196,9 @@ static void __init processor_id(void)
     processor_setup();
 }
 
-void __init dt_unreserved_regions(paddr_t s, paddr_t e,
-                                  void (*cb)(paddr_t, paddr_t), int first)
+static void __init dt_unreserved_regions(paddr_t s, paddr_t e,
+                                         void (*cb)(paddr_t, paddr_t),
+                                         int first)
 {
     int i, nr = fdt_num_mem_rsv(device_tree_flattened);
 
@@ -244,6 +245,17 @@ void __init dt_unreserved_regions(paddr_t s, paddr_t e,
     cb(s, e);
 }
 
+void __init fw_unreserved_regions(paddr_t s, paddr_t e,
+                                  void (*cb)(paddr_t, paddr_t), int first)
+{
+    if ( acpi_disabled )
+        dt_unreserved_regions(s, e, cb, first);
+    else
+        cb(s, e);
+}
+
+
+
 struct bootmodule __init *add_boot_module(bootmodule_kind kind,
                                           paddr_t start, paddr_t size,
                                           bool domU)
@@ -405,7 +417,7 @@ void __init discard_initial_modules(void)
              !mfn_valid(maddr_to_mfn(e)) )
             continue;
 
-        dt_unreserved_regions(s, e, init_domheap_pages, 0);
+        fw_unreserved_regions(s, e, init_domheap_pages, 0);
     }
 
     mi->nr_mods = 0;
@@ -712,7 +724,7 @@ static void __init setup_mm(void)
                 n = mfn_to_maddr(mfn_add(xenheap_mfn_start, xenheap_pages));
             }
 
-            dt_unreserved_regions(s, e, init_boot_pages, 0);
+            fw_unreserved_regions(s, e, init_boot_pages, 0);
 
             s = n;
         }
@@ -765,7 +777,7 @@ static void __init setup_mm(void)
             if ( e > bank_end )
                 e = bank_end;
 
-            dt_unreserved_regions(s, e, init_boot_pages, 0);
+            fw_unreserved_regions(s, e, init_boot_pages, 0);
             s = n;
         }
     }
xen/include/asm-arm/setup.h +2 -1
index 2f8f24e286ed..28bf622aa196 100644
@@ -67,6 +67,7 @@ struct bootcmdlines {
 
 struct bootinfo {
     struct meminfo mem;
+    /* The reserved regions are only used when booting using Device-Tree */
     struct meminfo reserved_mem;
     struct bootmodules modules;
     struct bootcmdlines cmdlines;
@@ -96,7 +97,7 @@ int construct_dom0(struct domain *d);
 void create_domUs(void);
 
 void discard_initial_modules(void);
-void dt_unreserved_regions(paddr_t s, paddr_t e,
+void fw_unreserved_regions(paddr_t s, paddr_t e,
                            void (*cb)(paddr_t, paddr_t), int first);
 
 size_t boot_fdt_info(const void *fdt, paddr_t paddr);
Signature · 1 line
2.17.1
#16 lore raw

PATCH v2 5/7 xen/arm: acpi: add BAD_MADT_GICC_ENTRY() macro

In reply to Julien Grall

From: Julien Grall <[email protected]>

Imported from Linux commit b6cfb277378ef831c0fa84bcff5049307294adc6:

The BAD_MADT_ENTRY() macro is designed to work for all of the subtables of the MADT. In the ACPI 5.1 version of the spec, the struct for the GICC subtable (struct acpi_madt_generic_interrupt) is 76 bytes long; in ACPI 6.0, the struct is 80 bytes long. But, there is only one definition in ACPICA for this struct -- and that is the 6.0 version. Hence, when BAD_MADT_ENTRY() compares the struct size to the length in the GICC subtable, it fails if 5.1 structs are in use, and there are systems in the wild that have them.

This patch adds the BAD_MADT_GICC_ENTRY() that checks the GICC subtable only, accounting for the difference in specification versions that are possible. The BAD_MADT_ENTRY() will continue to work as is for all other MADT subtables.

This code is being added to an arm64 header file since that is currently the only architecture using the GICC subtable of the MADT. As a GIC is specific to ARM, it is also unlikely the subtable will be used elsewhere.

Fixes aeb823bbacc2 ("ACPICA: ACPI 6.0: Add changes for FADT table.")
[[email protected]: extra brackets around macro arguments]

---

Changes in v2:
- Patch added

We may want to consider to also import:

commit 9eb1c92b47c73249465d388eaa394fe436a3b489

Author: Jeremy Linton <[email protected]>
Date:   Tue Nov 27 17:59:12 2018 +0000

arm64: acpi: Prepare for longer MADTs

The BAD_MADT_GICC_ENTRY check is a little too strict because it rejects MADT entries that don't match the currently known lengths. We should remove this restriction to avoid problems if the table length changes. Future code which might depend on additional fields should be written to validate those fields before using them, rather than trying to globally check known MADT version lengths.

---
 xen/include/asm-arm/acpi.h | 8 ++++++++
 1 file changed, 8 insertions(+)
xen/include/asm-arm/acpi.h +8 -0
index 50340281a917..b52ae2d6ef72 100644
@@ -54,6 +54,14 @@ void acpi_smp_init_cpus(void);
  */
 paddr_t acpi_get_table_offset(struct membank tbl_add[], EFI_MEM_RES index);
 
+/* Macros for consistency checks of the GICC subtable of MADT */
+#define ACPI_MADT_GICC_LENGTH	\
+    (acpi_gbl_FADT.header.revision < 6 ? 76 : 80)
+
+#define BAD_MADT_GICC_ENTRY(entry, end)						\
+    (!(entry) || (unsigned long)(entry) + sizeof(*(entry)) > (end) ||	\
+     (entry)->header.length != ACPI_MADT_GICC_LENGTH)
+
 #ifdef CONFIG_ACPI
 extern bool acpi_disabled;
 /* Basic configuration for ACPI */
Signature · 1 line
2.17.1
Acked-by on v2 5/7
#17 lore raw

Re: [PATCH v2 5/7] xen/arm: acpi: add BAD_MADT_GICC_ENTRY() macro

Quoted 29 lines · Julien Grall

From: Julien Grall <[email protected]>

Imported from Linux commit b6cfb277378ef831c0fa84bcff5049307294adc6:

The BAD_MADT_ENTRY() macro is designed to work for all of the subtables of the MADT. In the ACPI 5.1 version of the spec, the struct for the GICC subtable (struct acpi_madt_generic_interrupt) is 76 bytes long; in ACPI 6.0, the struct is 80 bytes long. But, there is only one definition in ACPICA for this struct -- and that is the 6.0 version. Hence, when BAD_MADT_ENTRY() compares the struct size to the length in the GICC subtable, it fails if 5.1 structs are in use, and there are systems in the wild that have them.

This patch adds the BAD_MADT_GICC_ENTRY() that checks the GICC subtable only, accounting for the difference in specification versions that are possible. The BAD_MADT_ENTRY() will continue to work as is for all other MADT subtables.

This code is being added to an arm64 header file since that is currently the only architecture using the GICC subtable of the MADT. As a GIC is specific to ARM, it is also unlikely the subtable will be used elsewhere.

Fixes aeb823bbacc2 ("ACPICA: ACPI 6.0: Add changes for FADT table.")
[[email protected]: extra brackets around macro arguments]
Quoted 3 lines
Quoted 10 lines

---

Changes in v2:
- Patch added

We may want to consider to also import:

commit 9eb1c92b47c73249465d388eaa394fe436a3b489

Author: Jeremy Linton <[email protected]>
Date:   Tue Nov 27 17:59:12 2018 +0000

Sure

Quoted 46 lines

arm64: acpi: Prepare for longer MADTs

The BAD_MADT_GICC_ENTRY check is a little too strict because it rejects MADT entries that don't match the currently known lengths. We should remove this restriction to avoid problems if the table length changes. Future code which might depend on additional fields should be written to validate those fields before using them, rather than trying to globally check known MADT version lengths.

---
 xen/include/asm-arm/acpi.h | 8 ++++++++
 1 file changed, 8 insertions(+)
xen/include/asm-arm/acpi.h +8 -0
index 50340281a917..b52ae2d6ef72 100644
@@ -54,6 +54,14 @@ void acpi_smp_init_cpus(void);
  */
 paddr_t acpi_get_table_offset(struct membank tbl_add[], EFI_MEM_RES index);
 
+/* Macros for consistency checks of the GICC subtable of MADT */
+#define ACPI_MADT_GICC_LENGTH	\
+    (acpi_gbl_FADT.header.revision < 6 ? 76 : 80)
+
+#define BAD_MADT_GICC_ENTRY(entry, end)						\
+    (!(entry) || (unsigned long)(entry) + sizeof(*(entry)) > (end) ||	\
+     (entry)->header.length != ACPI_MADT_GICC_LENGTH)
+
 #ifdef CONFIG_ACPI
 extern bool acpi_disabled;
 /* Basic configuration for ACPI */
Signature · 1 line
2.17.1
#18 lore raw

Re: [PATCH v2 5/7] xen/arm: acpi: add BAD_MADT_GICC_ENTRY() macro

Hi Stefano,

Quoted 30 lines · Stefano Stabellini
Quoted 29 lines · Julien Grall

From: Julien Grall <[email protected]>

Imported from Linux commit b6cfb277378ef831c0fa84bcff5049307294adc6:

The BAD_MADT_ENTRY() macro is designed to work for all of the subtables of the MADT. In the ACPI 5.1 version of the spec, the struct for the GICC subtable (struct acpi_madt_generic_interrupt) is 76 bytes long; in ACPI 6.0, the struct is 80 bytes long. But, there is only one definition in ACPICA for this struct -- and that is the 6.0 version. Hence, when BAD_MADT_ENTRY() compares the struct size to the length in the GICC subtable, it fails if 5.1 structs are in use, and there are systems in the wild that have them.

This patch adds the BAD_MADT_GICC_ENTRY() that checks the GICC subtable only, accounting for the difference in specification versions that are possible. The BAD_MADT_ENTRY() will continue to work as is for all other MADT subtables.

This code is being added to an arm64 header file since that is currently the only architecture using the GICC subtable of the MADT. As a GIC is specific to ARM, it is also unlikely the subtable will be used elsewhere.

Fixes aeb823bbacc2 ("ACPICA: ACPI 6.0: Add changes for FADT table.")
[[email protected]: extra brackets around macro arguments]
Quoted 5 lines
Quoted 3 lines

Thanks!

Quoted 5 lines
Quoted 5 lines

---

Changes in v2:
- Patch added

Quoted 7 lines
Quoted 5 lines

We may want to consider to also import:

commit 9eb1c92b47c73249465d388eaa394fe436a3b489

Author: Jeremy Linton <[email protected]>
Date:   Tue Nov 27 17:59:12 2018 +0000

Sure

I will add it in my todo list of further improvement.

Cheers,

Signature · 1 line
Julien Grall
#19 lore raw

PATCH v2 6/7 xen/arm: gic-v2: acpi: Use the correct length for the GICC structure

In reply to Julien Grall

From: Julien Grall <[email protected]>

The length of the GICC structure in the MADT ACPI table differs between version 5.1 and 6.0, although there are no other relevant differences.

Use the BAD_MADT_GICC_ENTRY macro, which was specifically designed to overcome this issue.

---
Changes in v2:
- Patch added

---
 xen/arch/arm/acpi/boot.c | 2 +-
 xen/arch/arm/gic-v2.c    | 5 +++--
 xen/arch/arm/gic-v3.c    | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)
xen/arch/arm/acpi/boot.c +1 -1
index 30e4bd1bc5a7..55c3e5cbc834 100644
@@ -131,7 +131,7 @@ acpi_parse_gic_cpu_interface(struct acpi_subtable_header *header,
     struct acpi_madt_generic_interrupt *processor =
                container_of(header, struct acpi_madt_generic_interrupt, header);
 
-    if ( BAD_MADT_ENTRY(processor, end) )
+    if ( BAD_MADT_GICC_ENTRY(processor, end) )
         return -EINVAL;
 
     acpi_table_print_madt_entry(header);
xen/arch/arm/gic-v2.c +3 -2
index 0f747538dbcd..0e5f23201974 100644
@@ -1136,7 +1136,8 @@ static int gicv2_make_hwdom_madt(const struct domain *d, u32 offset)
 
     host_gicc = container_of(header, struct acpi_madt_generic_interrupt,
                              header);
-    size = sizeof(struct acpi_madt_generic_interrupt);
+
+    size = ACPI_MADT_GICC_LENGTH;
     /* Add Generic Interrupt */
     for ( i = 0; i < d->max_vcpus; i++ )
     {
@@ -1165,7 +1166,7 @@ gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header,
     struct acpi_madt_generic_interrupt *processor =
                container_of(header, struct acpi_madt_generic_interrupt, header);
 
-    if ( BAD_MADT_ENTRY(processor, end) )
+    if ( BAD_MADT_GICC_ENTRY(processor, end) )
         return -EINVAL;
 
     /* Read from APIC table and fill up the GIC variables */
xen/arch/arm/gic-v3.c +1 -1
index 0f6cbf6224e9..ce202402c0ed 100644
@@ -1558,7 +1558,7 @@ gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header,
     struct acpi_madt_generic_interrupt *processor =
                container_of(header, struct acpi_madt_generic_interrupt, header);
 
-    if ( BAD_MADT_ENTRY(processor, end) )
+    if ( BAD_MADT_GICC_ENTRY(processor, end) )
         return -EINVAL;
 
     /* Read from APIC table and fill up the GIC variables */
Signature · 1 line
2.17.1
Reviewed-by on v2 6/7
#20 lore raw

Re: [PATCH v2 6/7] xen/arm: gic-v2: acpi: Use the correct length for the GICC structure

Quoted 11 lines · Julien Grall

From: Julien Grall <[email protected]>

The length of the GICC structure in the MADT ACPI table differs between version 5.1 and 6.0, although there are no other relevant differences.

Use the BAD_MADT_GICC_ENTRY macro, which was specifically designed to overcome this issue.

Quoted 61 lines

---
Changes in v2:
- Patch added

---
 xen/arch/arm/acpi/boot.c | 2 +-
 xen/arch/arm/gic-v2.c    | 5 +++--
 xen/arch/arm/gic-v3.c    | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)
xen/arch/arm/acpi/boot.c +1 -1
index 30e4bd1bc5a7..55c3e5cbc834 100644
@@ -131,7 +131,7 @@ acpi_parse_gic_cpu_interface(struct acpi_subtable_header *header,
     struct acpi_madt_generic_interrupt *processor =
                container_of(header, struct acpi_madt_generic_interrupt, header);
 
-    if ( BAD_MADT_ENTRY(processor, end) )
+    if ( BAD_MADT_GICC_ENTRY(processor, end) )
         return -EINVAL;
 
     acpi_table_print_madt_entry(header);
xen/arch/arm/gic-v2.c +3 -2
index 0f747538dbcd..0e5f23201974 100644
@@ -1136,7 +1136,8 @@ static int gicv2_make_hwdom_madt(const struct domain *d, u32 offset)
 
     host_gicc = container_of(header, struct acpi_madt_generic_interrupt,
                              header);
-    size = sizeof(struct acpi_madt_generic_interrupt);
+
+    size = ACPI_MADT_GICC_LENGTH;
     /* Add Generic Interrupt */
     for ( i = 0; i < d->max_vcpus; i++ )
     {
@@ -1165,7 +1166,7 @@ gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header,
     struct acpi_madt_generic_interrupt *processor =
                container_of(header, struct acpi_madt_generic_interrupt, header);
 
-    if ( BAD_MADT_ENTRY(processor, end) )
+    if ( BAD_MADT_GICC_ENTRY(processor, end) )
         return -EINVAL;
 
     /* Read from APIC table and fill up the GIC variables */
xen/arch/arm/gic-v3.c +1 -1
index 0f6cbf6224e9..ce202402c0ed 100644
@@ -1558,7 +1558,7 @@ gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header,
     struct acpi_madt_generic_interrupt *processor =
                container_of(header, struct acpi_madt_generic_interrupt, header);
 
-    if ( BAD_MADT_ENTRY(processor, end) )
+    if ( BAD_MADT_GICC_ENTRY(processor, end) )
         return -EINVAL;
 
     /* Read from APIC table and fill up the GIC variables */
Signature · 1 line
2.17.1
#21 lore raw

Re: [PATCH v2 6/7] xen/arm: gic-v2: acpi: Use the correct length for the GICC structure

Quoted 6 lines · Stefano Stabellini
Quoted 5 lines · Julien Grall

From: Julien Grall <[email protected]>

The length of the GICC structure in the MADT ACPI table differs between version 5.1 and 6.0, although there are no other relevant differences.

Quoted 8 lines
Quoted 6 lines

Use the BAD_MADT_GICC_ENTRY macro, which was specifically designed to overcome this issue.

Actually it looks we need to do substitutions in a couple of other places:

- xen/arch/arm/gic-v3.c:gicv3_make_hwdom_madt
- xen/arch/arm/gic-v3.c:gic_acpi_get_madt_cpu_num
- xen/arch/arm/gic.c:gic_get_hwdom_madt_size

Quoted 61 lines
Quoted 60 lines

Changes in v2:
- Patch added

---
 xen/arch/arm/acpi/boot.c | 2 +-
 xen/arch/arm/gic-v2.c    | 5 +++--
 xen/arch/arm/gic-v3.c    | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)
xen/arch/arm/acpi/boot.c +1 -1
index 30e4bd1bc5a7..55c3e5cbc834 100644
@@ -131,7 +131,7 @@ acpi_parse_gic_cpu_interface(struct acpi_subtable_header *header,
     struct acpi_madt_generic_interrupt *processor =
                container_of(header, struct acpi_madt_generic_interrupt, header);
 
-    if ( BAD_MADT_ENTRY(processor, end) )
+    if ( BAD_MADT_GICC_ENTRY(processor, end) )
         return -EINVAL;
 
     acpi_table_print_madt_entry(header);
xen/arch/arm/gic-v2.c +3 -2
index 0f747538dbcd..0e5f23201974 100644
@@ -1136,7 +1136,8 @@ static int gicv2_make_hwdom_madt(const struct domain *d, u32 offset)
 
     host_gicc = container_of(header, struct acpi_madt_generic_interrupt,
                              header);
-    size = sizeof(struct acpi_madt_generic_interrupt);
+
+    size = ACPI_MADT_GICC_LENGTH;
     /* Add Generic Interrupt */
     for ( i = 0; i < d->max_vcpus; i++ )
     {
@@ -1165,7 +1166,7 @@ gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header,
     struct acpi_madt_generic_interrupt *processor =
                container_of(header, struct acpi_madt_generic_interrupt, header);
 
-    if ( BAD_MADT_ENTRY(processor, end) )
+    if ( BAD_MADT_GICC_ENTRY(processor, end) )
         return -EINVAL;
 
     /* Read from APIC table and fill up the GIC variables */
xen/arch/arm/gic-v3.c +1 -1
index 0f6cbf6224e9..ce202402c0ed 100644
@@ -1558,7 +1558,7 @@ gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header,
     struct acpi_madt_generic_interrupt *processor =
                container_of(header, struct acpi_madt_generic_interrupt, header);
 
-    if ( BAD_MADT_ENTRY(processor, end) )
+    if ( BAD_MADT_GICC_ENTRY(processor, end) )
         return -EINVAL;
 
     /* Read from APIC table and fill up the GIC variables */
Signature · 1 line
2.17.1
#22 lore raw

Re: [PATCH v2 6/7] xen/arm: gic-v2: acpi: Use the correct length for the GICC structure

Hi Stefano,

I just realized the title says "gic-v2" when I also modified "gic-v3". I will update the title on the next version.

Quoted 14 lines · Stefano Stabellini
Quoted 13 lines · Stefano Stabellini
Quoted 11 lines · Julien Grall

From: Julien Grall <[email protected]>

The length of the GICC structure in the MADT ACPI table differs between version 5.1 and 6.0, although there are no other relevant differences.

Use the BAD_MADT_GICC_ENTRY macro, which was specifically designed to overcome this issue.

Quoted 7 lines
Quoted 1 line

Actually it looks we need to do substitutions in a couple of other places:

- xen/arch/arm/gic-v3.c:gicv3_make_hwdom_madt
- xen/arch/arm/gic-v3.c:gic_acpi_get_madt_cpu_num
- xen/arch/arm/gic.c:gic_get_hwdom_madt_size

I will update the 3 and resend the series.

Cheers,

Signature · 1 line
Julien Grall
#23 lore raw

PATCH v2 7/7 xen/arm: acpi: Allow Xen to boot with ACPI 5.1

In reply to Julien Grall

From: Julien Grall <[email protected]>

At the moment Xen requires the FADT ACPI table to be at least version 6.0, apparently because of some reliance on other ACPI v6.0 features.

But actually this is overzealous, and Xen works now fine with ACPI v5.1.

Let's relax the version check for the FADT table to allow QEMU to run the hypervisor with ACPI.

---
Changes in v2:
- Patch added

---
 xen/arch/arm/acpi/boot.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/acpi/boot.c +2 -2
index 55c3e5cbc834..7ea2990cb82c 100644
@@ -181,8 +181,8 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
      * we only deal with ACPI 6.0 or newer revision to get GIC and SMP
      * boot protocol configuration data, or we will disable ACPI.
      */
-    if ( table->revision > 6
-         || (table->revision == 6 && fadt->minor_revision >= 0) )
+    if ( table->revision > 5
+         || (table->revision == 5 && fadt->minor_revision >= 1) )
         return 0;
 
     printk("Unsupported FADT revision %d.%d, should be 6.0+, will disable ACPI\n",
Signature · 1 line
2.17.1
Acked-by on v2 7/7
#24 lore raw

Re: [PATCH v2 7/7] xen/arm: acpi: Allow Xen to boot with ACPI 5.1

Quoted 5 lines · Julien Grall

From: Julien Grall <[email protected]>

At the moment Xen requires the FADT ACPI table to be at least version 6.0, apparently because of some reliance on other ACPI v6.0 features.

Quoted 8 lines

But actually this is overzealous, and Xen works now fine with ACPI v5.1.

Let's relax the version check for the FADT table to allow QEMU to run the hypervisor with ACPI.

Quoted 25 lines

---
Changes in v2:
- Patch added

---
 xen/arch/arm/acpi/boot.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/acpi/boot.c +2 -2
index 55c3e5cbc834..7ea2990cb82c 100644
@@ -181,8 +181,8 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
      * we only deal with ACPI 6.0 or newer revision to get GIC and SMP
      * boot protocol configuration data, or we will disable ACPI.
      */
-    if ( table->revision > 6
-         || (table->revision == 6 && fadt->minor_revision >= 0) )
+    if ( table->revision > 5
+         || (table->revision == 5 && fadt->minor_revision >= 1) )
         return 0;
 
     printk("Unsupported FADT revision %d.%d, should be 6.0+, will disable ACPI\n",
Signature · 1 line
2.17.1
Tested-by on the v2 series
#25 lore raw
In reply to Julien Grall
Quoted 7 lines · Julien Grall

Xen on ARM has been broken for quite a while on ACPI systems. This series aims to fix it.

This series also introduced support for ACPI 5.1. This allows Xen to boot on QEMU.

I have only build tested the x86 side so far.

On a Tianocore-utilizing Raspberry PI 4B, this series allows successful boot (some other distinct issues remain). As such, for the series on an ARM device:

Signature · 4 lines
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |         [email protected]  PGP 87145445         |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445