Skip to contentSkip to conversation

arm/acpi: Add __acpi_unmap_table function for ARM

PATCH In review Wei Xu 4 participants 9 messages Jan 21, 2020 – Jan 22, 2020

lore
Share & tools
lore

Wei Xu

author
#0 lore raw

PATCH 1/1 arm/acpi: Add __acpi_unmap_table function for ARM

Add __acpi_unmap_table function for ARM and invoke it at acpi_os_unmap_memory to make sure the related fixmap has been cleared before using it for a different mapping.

---
 xen/arch/arm/acpi/lib.c | 25 +++++++++++++++++++++++++
 xen/drivers/acpi/osl.c  |  2 ++
 xen/include/xen/acpi.h  |  1 +
 3 files changed, 28 insertions(+)
xen/arch/arm/acpi/lib.c +25 -0
index 4fc6e17..69e87ec 100644
@@ -49,6 +49,31 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
     return ((char *) base + offset);
 }
 
+void __acpi_unmap_table(void __iomem * virt, unsigned long size)
+{
+    unsigned long base, end;
+    int idx;
+
+    base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
+    end = FIXMAP_ADDR(FIXMAP_ACPI_END);
+
+    if ( (unsigned long)virt < base || (unsigned long)virt > end )
+    {
+        return;
+    }
+
+    idx = FIXMAP_ACPI_BEGIN + ((unsigned long)virt - base) / PAGE_SIZE;
+    clear_fixmap(idx);
+
+    while ( size > PAGE_SIZE )
+    {
+        if ( ++idx > FIXMAP_ACPI_END )
+            return;
+        clear_fixmap(idx);
+        size -= PAGE_SIZE;
+    }
+}
+
 /* True to indicate PSCI 0.2+ is implemented */
 bool __init acpi_psci_present(void)
 {
xen/drivers/acpi/osl.c +2 -0
index 4c8bb78..18666c7 100644
@@ -114,6 +114,8 @@ void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
 		return;
 	}
 
+	__acpi_unmap_table(virt, size);
+
 	if (system_state >= SYS_STATE_boot)
 		vunmap((void *)((unsigned long)virt & PAGE_MASK));
 }
xen/include/xen/acpi.h +1 -0
index 5cfa060..acb00a2 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);
+void __acpi_unmap_table(void __iomem * virt, unsigned long size);
 int acpi_boot_init (void);
 int acpi_boot_table_init (void);
 int acpi_numa_init (void);

-- 2.8.1 .

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#1 lore raw
Quoted 16 lines · Wei Xu

Add __acpi_unmap_table function for ARM and invoke it at acpi_os_unmap_memory to make sure the related fixmap has been cleared before using it for a different mapping.

---
  xen/arch/arm/acpi/lib.c | 25 +++++++++++++++++++++++++
  xen/drivers/acpi/osl.c  |  2 ++
  xen/include/xen/acpi.h  |  1 +
  3 files changed, 28 insertions(+)
xen/arch/arm/acpi/lib.c +0 -0
index 4fc6e17..69e87ec 100644

xen/arch/arm/acpi/lib.c char *__acpi_map_table(paddr_t phys, unsigned long size) · line 52

Quoted 4 lines
xen/arch/arm/acpi/lib.c +1 -0
@@ -49,6 +49,31 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
      return ((char *) base + offset);
  }
 
+void __acpi_unmap_table(void __iomem * virt, unsigned long size)

You have a stray space here after "*"

xen/arch/arm/acpi/lib.c char *__acpi_map_table(paddr_t phys, unsigned long size) · line 58

Quoted 6 lines
xen/arch/arm/acpi/lib.c +6 -0
+{
+    unsigned long base, end;
+    int idx;
+
+    base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
+    end = FIXMAP_ADDR(FIXMAP_ACPI_END);

Maybe the initialization can be moved to the declaration?

Alex
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#2 lore raw

Hi Alexandru,

Quoted 22 lines · Alexandru Stefan ISAILA
Quoted 19 lines · Wei Xu

Add __acpi_unmap_table function for ARM and invoke it at acpi_os_unmap_memory to make sure the related fixmap has been cleared before using it for a different mapping.

---
  xen/arch/arm/acpi/lib.c | 25 +++++++++++++++++++++++++
  xen/drivers/acpi/osl.c  |  2 ++
  xen/include/xen/acpi.h  |  1 +
  3 files changed, 28 insertions(+)
xen/arch/arm/acpi/lib.c +0 -0
index 4fc6e17..69e87ec 100644
@@ -49,6 +49,31 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
      return ((char *) base + offset);
  }
 
Quoted 3 lines

xen/arch/arm/acpi/lib.c char *__acpi_map_table(paddr_t phys, unsigned long size) · line 52

Quoted 1 line
xen/arch/arm/acpi/lib.c +1 -0
+void __acpi_unmap_table(void __iomem * virt, unsigned long size)

You have a stray space here after "*"

Sorry, I will remove it.

Quoted 9 lines

xen/arch/arm/acpi/lib.c char *__acpi_map_table(paddr_t phys, unsigned long size) · line 58

Quoted 7 lines
xen/arch/arm/acpi/lib.c +6 -0
+{
+    unsigned long base, end;
+    int idx;
+
+    base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
+    end = FIXMAP_ADDR(FIXMAP_ACPI_END);

Maybe the initialization can be moved to the declaration?

OK.
I will move it.

Thanks!

Best Regards,
Wei

Quoted 4 lines

Alex

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
In reply to Wei Xu
Quoted 3 lines · Wei Xu

Add __acpi_unmap_table function for ARM and invoke it at acpi_os_unmap_memory to make sure the related fixmap has been cleared before using it for a different mapping.

How can it possibly be that this is needed for Arm only?

xen/arch/arm/acpi/lib.c char *__acpi_map_table(paddr_t phys, unsigned long size) · line 55

Quoted 10 lines
xen/arch/arm/acpi/lib.c +4 -0
@@ -49,6 +49,31 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
      return ((char *) base + offset);
  }
 
+void __acpi_unmap_table(void __iomem * virt, unsigned long size)
+{
+    unsigned long base, end;
+    int idx;

unsigned int

xen/arch/arm/acpi/lib.c char *__acpi_map_table(paddr_t phys, unsigned long size) · line 63

Quoted 7 lines
xen/arch/arm/acpi/lib.c +7 -0
+    base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
+    end = FIXMAP_ADDR(FIXMAP_ACPI_END);
+
+    if ( (unsigned long)virt < base || (unsigned long)virt > end )
+    {
+        return;
+    }

Stray braces.

xen/drivers/acpi/osl.c void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) · line 120

Quoted 10 lines
xen/drivers/acpi/osl.c +2 -0
@@ -114,6 +114,8 @@ void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
  		return;
  	}
 
+	__acpi_unmap_table(virt, size);
+
  	if (system_state >= SYS_STATE_boot)
  		vunmap((void *)((unsigned long)virt & PAGE_MASK));

How can it possibly be correct to call both vunmap() and your new function? And how is this, having jsut an Arm implementation, going to compile for x86? Seeing that x86 gets away without this, may I suggest that you look at the x86 code to see why that is, and then consider whether the same model makes sense for Arm? And if it doesn't, check whether the new Arm model would make sense to also use on x86?

xen/include/xen/acpi.h typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, co · line 74

Quoted 10 lines
xen/include/xen/acpi.h +1 -0
@@ -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);
+void __acpi_unmap_table(void __iomem * virt, unsigned long size);
  int acpi_boot_init (void);
  int acpi_boot_table_init (void);
  int acpi_numa_init (void);

Best noticable here, your mailer has mangled the patch. The way of this mangling makes me guess you used Thunderbird to send the patch, in which case you'll need to adjust its settings (iirc it was mailnews.wraplength which needed setting to zero).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

Hi Jan,

Quoted 6 lines · Jan Beulich
Quoted 3 lines · Wei Xu

Add __acpi_unmap_table function for ARM and invoke it at acpi_os_unmap_memory to make sure the related fixmap has been cleared before using it for a different mapping.

How can it possibly be that this is needed for Arm only?

Let me give some background (I will let Wei dealing with the rest of the patches). On Arm, I made the decision to forbid a mapping replacement in the page-tables code. This means that if you want to re-use the same fixmap, then you need to clear it first.

The reason for the requirement is quite simple. On Arm, you need to use a break-before-make sequence any time you replace a valid entry by another valid entry (there is a couple of case where it is not needed).

As the sequence name suggests it, we will have a small window where the virtual address will point to nothing. This may result to an abort if another CPU is accessing the address at the same time.

In the fixmap case below, this should never happen. But now imagine shattering a superpage...

So rather than trying to allow in some cases the modification of a mapping, we just forbid for everything but permission changes. This is much simpler to reason and a much saner interface.

Similarly, I think this is much saner to call have a clear_fixmap() for each set_fixmap().

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
author
#5 lore raw

Hi Julien,

Quoted 14 lines · Julien Grall

Hi Jan,

Quoted 6 lines · Jan Beulich
Quoted 3 lines · Wei Xu

Add __acpi_unmap_table function for ARM and invoke it at acpi_os_unmap_memory to make sure the related fixmap has been cleared before using it for a different mapping.

How can it possibly be that this is needed for Arm only?

Let me give some background (I will let Wei dealing with the rest of the patches). On Arm, I made the decision to forbid a mapping replacement in the page-tables code. This means that if you want to re-use the same fixmap, then you need to clear it first.

The reason for the requirement is quite simple. On Arm, you need to use a break-before-make sequence any time you replace a valid entry by another valid entry (there is a couple of case where it is not needed).

Quoted 7 lines

As the sequence name suggests it, we will have a small window where the virtual address will point to nothing. This may result to an abort if another CPU is accessing the address at the same time.

In the fixmap case below, this should never happen. But now imagine shattering a superpage...

So rather than trying to allow in some cases the modification of a mapping, we just forbid for everything but permission changes. This is much simpler to reason and a much saner interface.

Similarly, I think this is much saner to call have a clear_fixmap() for each set_fixmap().

Thanks to explain!

Best Regards,
Wei

Quoted 3 lines

Cheers,

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#6 lore raw
In reply to Jan Beulich

Hi Jan,

Quoted 6 lines · Jan Beulich
Quoted 3 lines · Wei Xu

Add __acpi_unmap_table function for ARM and invoke it at acpi_os_unmap_memory to make sure the related fixmap has been cleared before using it for a different mapping.

How can it possibly be that this is needed for Arm only?

Sorry, I think Julien has helped to explain this.

Quoted 7 lines
Quoted 7 lines
xen/arch/arm/acpi/lib.c +0 -0
@@ -49,6 +49,31 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
      return ((char *) base + offset);
  }
 
Quoted 6 lines

xen/arch/arm/acpi/lib.c char *__acpi_map_table(paddr_t phys, unsigned long size) · line 55

Quoted 4 lines
xen/arch/arm/acpi/lib.c +4 -0
+void __acpi_unmap_table(void __iomem * virt, unsigned long size)
+{
+    unsigned long base, end;
+    int idx;

unsigned int

OK.
I will change the type.

Quoted 10 lines

xen/arch/arm/acpi/lib.c char *__acpi_map_table(paddr_t phys, unsigned long size) · line 63

Quoted 8 lines
xen/arch/arm/acpi/lib.c +7 -0
+    base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
+    end = FIXMAP_ADDR(FIXMAP_ACPI_END);
+
+    if ( (unsigned long)virt < base || (unsigned long)virt > end )
+    {
+        return;
+    }

Stray braces.

OK.
I will remove the braces.

Quoted 7 lines
Quoted 7 lines
xen/drivers/acpi/osl.c +0 -0
@@ -114,6 +114,8 @@ void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
  		return;
  	}
 
Quoted 13 lines

xen/drivers/acpi/osl.c void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) · line 120

Quoted 4 lines
xen/drivers/acpi/osl.c +2 -0
+	__acpi_unmap_table(virt, size);
+
  	if (system_state >= SYS_STATE_boot)
  		vunmap((void *)((unsigned long)virt & PAGE_MASK));

How can it possibly be correct to call both vunmap() and your new function? And how is this, having jsut an Arm implementation, going to compile for x86? Seeing that x86 gets away without this, may I suggest that you look at the x86 code to see why that is, and then consider whether the same model makes sense for Arm? And if it doesn't, check whether the new Arm model would make sense to also use on x86?

Sorry, I thought acpi_os_unmap_memory is specific for ARM.
Just now I checked map_pages_to_xen in arch/x86/mm.c and did not find any place to forbid the modification of a mapping. Maybe clearing mapping before modification is not necessary for X86. Do you think is it OK to add a empty stub function for the other cases except ARM and invoke it after vunmap as following?

	diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c
	--- a/xen/drivers/acpi/osl.c
	+++ b/xen/drivers/acpi/osl.c
	@@ -114,10 +114,10 @@ void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
					return;
			}

			if (system_state >= SYS_STATE_boot)
					vunmap((void *)((unsigned long)virt & PAGE_MASK));
	+
	+       __acpi_unmap_table(virt, size);
	 }

	 acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
	diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h
	--- a/xen/include/xen/acpi.h
	+++ b/xen/include/xen/acpi.h
	@@ -68,7 +68,13 @@ 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);
	+
	+#ifdef CONFIG_ARM
	+void __acpi_unmap_table(void __iomem *virt, unsigned long size);
	+#else
	+void __acpi_unmap_table(void __iomem *virt, unsigned long size) { }
	+#endif /* CONFIG_ARM */
Quoted 4 lines
Quoted 4 lines
xen/include/xen/acpi.h +0 -0
@@ -68,6 +68,7 @@ typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, co
 
Quoted 11 lines

xen/include/xen/acpi.h typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, co · line 74

Quoted 6 lines
xen/include/xen/acpi.h +1 -0
  unsigned int acpi_get_processor_id (unsigned int cpu);
  char * __acpi_map_table (paddr_t phys_addr, unsigned long size);
+void __acpi_unmap_table(void __iomem * virt, unsigned long size);
  int acpi_boot_init (void);
  int acpi_boot_table_init (void);
  int acpi_numa_init (void);

Best noticable here, your mailer has mangled the patch. The way of this mangling makes me guess you used Thunderbird to send the patch, in which case you'll need to adjust its settings (iirc it was mailnews.wraplength which needed setting to zero).

Yes, I used Thunderbird and did not set that :(.
Thanks!

Best Regards,
Wei

Quoted 5 lines

Jan

.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw
Quoted 22 lines · Wei Xu
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Wei Xu
xen/drivers/acpi/osl.c +0 -0
@@ -114,6 +114,8 @@ void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
  		return;
  	}
 
Quoted 13 lines

xen/drivers/acpi/osl.c void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) · line 120

Quoted 4 lines
xen/drivers/acpi/osl.c +2 -0
+	__acpi_unmap_table(virt, size);
+
  	if (system_state >= SYS_STATE_boot)
  		vunmap((void *)((unsigned long)virt & PAGE_MASK));

How can it possibly be correct to call both vunmap() and your new function? And how is this, having jsut an Arm implementation, going to compile for x86? Seeing that x86 gets away without this, may I suggest that you look at the x86 code to see why that is, and then consider whether the same model makes sense for Arm? And if it doesn't, check whether the new Arm model would make sense to also use on x86?

Quoted 5 lines

Sorry, I thought acpi_os_unmap_memory is specific for ARM.
Just now I checked map_pages_to_xen in arch/x86/mm.c and did not find any place to forbid the modification of a mapping. Maybe clearing mapping before modification is not necessary for X86. Do you think is it OK to add a empty stub function for the other cases except ARM and invoke it after vunmap as following?

No. This is still doing two unmaps when system_state >= SYS_STATE_boot. At the very least this need to go in an "else" block to the existing if(). There also shouldn't be a blanket empty stub function. Even on x86 it would be _better_ (albeit not strictly needed) if the unmap indeed zapped the fixmap mappings. And for potential future ports it would be outright dangerous to have such an empty stub.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#8 lore raw

Hi Jan,

Quoted 29 lines · Jan Beulich
Quoted 22 lines · Wei Xu
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Wei Xu
xen/drivers/acpi/osl.c +0 -0
@@ -114,6 +114,8 @@ void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
  		return;
  	}
 
Quoted 13 lines

xen/drivers/acpi/osl.c void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) · line 120

Quoted 4 lines
xen/drivers/acpi/osl.c +2 -0
+	__acpi_unmap_table(virt, size);
+
  	if (system_state >= SYS_STATE_boot)
  		vunmap((void *)((unsigned long)virt & PAGE_MASK));

How can it possibly be correct to call both vunmap() and your new function? And how is this, having jsut an Arm implementation, going to compile for x86? Seeing that x86 gets away without this, may I suggest that you look at the x86 code to see why that is, and then consider whether the same model makes sense for Arm? And if it doesn't, check whether the new Arm model would make sense to also use on x86?

Quoted 5 lines

Sorry, I thought acpi_os_unmap_memory is specific for ARM.
Just now I checked map_pages_to_xen in arch/x86/mm.c and did not find any place to forbid the modification of a mapping. Maybe clearing mapping before modification is not necessary for X86. Do you think is it OK to add a empty stub function for the other cases except ARM and invoke it after vunmap as following?

Quoted 6 lines

No. This is still doing two unmaps when system_state >= SYS_STATE_boot. At the very least this need to go in an "else" block to the existing if(). There also shouldn't be a blanket empty stub function. Even on x86 it would be _better_ (albeit not strictly needed) if the unmap indeed zapped the fixmap mappings. And for potential future ports it would be outright dangerous to have such an empty stub.

Got it.
I will check how to clear the fixmap on X86.
Thanks!

Best Regards,
Wei

Quoted 5 lines

Jan

.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel