Skip to content

Commit 9221222

Browse files
committed
xen: allow mapping ACPI data using a different physical address
When running as a Xen PV dom0 the system needs to map ACPI data of the host using host physical addresses, while those addresses can conflict with the guest physical addresses of the loaded linux kernel. The same problem might apply in case a PV guest is configured to use the host memory map. This conflict can be solved by mapping the ACPI data to a different guest physical address, but mapping the data via acpi_os_ioremap() must still be possible using the host physical address, as this address might be generated by AML when referencing some of the ACPI data. When configured to support running as a Xen PV domain, have an implementation of acpi_os_ioremap() being aware of the possibility to need above mentioned translation of a host physical address to the guest physical address. This modification requires to #include linux/acpi.h in some sources which need to include asm/acpi.h directly. Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Jan Beulich <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent d05208c commit 9221222

File tree

8 files changed

+59
-1
lines changed

8 files changed

+59
-1
lines changed

arch/x86/include/asm/acpi.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ void acpi_generic_reduced_hw_init(void);
174174
void x86_default_set_root_pointer(u64 addr);
175175
u64 x86_default_get_root_pointer(void);
176176

177+
#ifdef CONFIG_XEN_PV
178+
/* A Xen PV domain needs a special acpi_os_ioremap() handling. */
179+
extern void __iomem * (*acpi_os_ioremap)(acpi_physical_address phys,
180+
acpi_size size);
181+
void __iomem *x86_acpi_os_ioremap(acpi_physical_address phys, acpi_size size);
182+
#define acpi_os_ioremap acpi_os_ioremap
183+
#endif
184+
177185
#else /* !CONFIG_ACPI */
178186

179187
#define acpi_lapic 0

arch/x86/kernel/acpi/boot.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,3 +1778,14 @@ u64 x86_default_get_root_pointer(void)
17781778
{
17791779
return boot_params.acpi_rsdp_addr;
17801780
}
1781+
1782+
#ifdef CONFIG_XEN_PV
1783+
void __iomem *x86_acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
1784+
{
1785+
return ioremap_cache(phys, size);
1786+
}
1787+
1788+
void __iomem * (*acpi_os_ioremap)(acpi_physical_address phys, acpi_size size) =
1789+
x86_acpi_os_ioremap;
1790+
EXPORT_SYMBOL_GPL(acpi_os_ioremap);
1791+
#endif

arch/x86/kernel/jailhouse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/kernel.h>
1313
#include <linux/reboot.h>
1414
#include <linux/serial_8250.h>
15+
#include <linux/acpi.h>
1516
#include <asm/apic.h>
1617
#include <asm/io_apic.h>
1718
#include <asm/acpi.h>

arch/x86/kernel/mmconf-fam10h_64.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/pci.h>
1010
#include <linux/dmi.h>
1111
#include <linux/range.h>
12+
#include <linux/acpi.h>
1213

1314
#include <asm/pci-direct.h>
1415
#include <linux/sort.h>

arch/x86/kernel/smpboot.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <linux/stackprotector.h>
6161
#include <linux/cpuhotplug.h>
6262
#include <linux/mc146818rtc.h>
63+
#include <linux/acpi.h>
6364

6465
#include <asm/acpi.h>
6566
#include <asm/cacheinfo.h>

arch/x86/kernel/x86_init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/ioport.h>
99
#include <linux/export.h>
1010
#include <linux/pci.h>
11+
#include <linux/acpi.h>
1112

1213
#include <asm/acpi.h>
1314
#include <asm/bios_ebda.h>

arch/x86/xen/p2m.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include <linux/memblock.h>
7171
#include <linux/slab.h>
7272
#include <linux/vmalloc.h>
73+
#include <linux/acpi.h>
7374

7475
#include <asm/cache.h>
7576
#include <asm/setup.h>
@@ -834,6 +835,34 @@ void __init xen_do_remap_nonram(void)
834835
pr_info("Remapped %u non-RAM page(s)\n", remapped);
835836
}
836837

838+
#ifdef CONFIG_ACPI
839+
/*
840+
* Xen variant of acpi_os_ioremap() taking potentially remapped non-RAM
841+
* regions into account.
842+
* Any attempt to map an area crossing a remap boundary will produce a
843+
* WARN() splat.
844+
* phys is related to remap->maddr on input and will be rebased to remap->paddr.
845+
*/
846+
static void __iomem *xen_acpi_os_ioremap(acpi_physical_address phys,
847+
acpi_size size)
848+
{
849+
unsigned int i;
850+
const struct nonram_remap *remap = xen_nonram_remap;
851+
852+
for (i = 0; i < nr_nonram_remap; i++) {
853+
if (phys + size > remap->maddr &&
854+
phys < remap->maddr + remap->size) {
855+
WARN_ON(phys < remap->maddr ||
856+
phys + size > remap->maddr + remap->size);
857+
phys += remap->paddr - remap->maddr;
858+
break;
859+
}
860+
}
861+
862+
return x86_acpi_os_ioremap(phys, size);
863+
}
864+
#endif /* CONFIG_ACPI */
865+
837866
/*
838867
* Add a new non-RAM remap entry.
839868
* In case of no free entry found, just crash the system.
@@ -848,6 +877,12 @@ void __init xen_add_remap_nonram(phys_addr_t maddr, phys_addr_t paddr,
848877
BUG();
849878
}
850879

880+
#ifdef CONFIG_ACPI
881+
/* Switch to the Xen acpi_os_ioremap() variant. */
882+
if (nr_nonram_remap == 0)
883+
acpi_os_ioremap = xen_acpi_os_ioremap;
884+
#endif
885+
851886
xen_nonram_remap[nr_nonram_remap].maddr = maddr;
852887
xen_nonram_remap[nr_nonram_remap].paddr = paddr;
853888
xen_nonram_remap[nr_nonram_remap].size = size;

arch/x86/xen/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
#include <linux/cpuidle.h>
1616
#include <linux/cpufreq.h>
1717
#include <linux/memory_hotplug.h>
18+
#include <linux/acpi.h>
1819

1920
#include <asm/elf.h>
2021
#include <asm/vdso.h>
2122
#include <asm/e820/api.h>
2223
#include <asm/setup.h>
23-
#include <asm/acpi.h>
2424
#include <asm/numa.h>
2525
#include <asm/idtentry.h>
2626
#include <asm/xen/hypervisor.h>

0 commit comments

Comments
 (0)