Skip to content

Commit

Permalink
Merge tag 'for-linus-6.12-rc1-tag' of git://git.kernel.org/pub/scm/li…
Browse files Browse the repository at this point in the history
…nux/kernel/git/xen/tip

Pull xen updates from Juergen Gross:

 - fix a boot problem as a Xen dom0 on some AMD systems

 - fix Xen PVH boot problems with KASAN enabled

 - fix for a build warning

 - fixes to swiotlb-xen

* tag 'for-linus-6.12-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip:
  xen/swiotlb: fix allocated size
  xen/swiotlb: add alignment check for dma buffers
  xen/pci: Avoid -Wflex-array-member-not-at-end warning
  xen/xenbus: Convert to use ERR_CAST()
  xen, pvh: fix unbootable VMs by inlining memset() in xen_prepare_pvh()
  x86/cpu: fix unbootable VMs by inlining memcmp() in hypervisor_cpuid_base()
  xen, pvh: fix unbootable VMs (PVH + KASAN - AMD_MEM_ENCRYPT)
  xen: tolerate ACPI NVS memory overlapping with Xen allocated memory
  xen: allow mapping ACPI data using a different physical address
  xen: add capability to remap non-RAM pages to different PFNs
  xen: move max_pfn in xen_memory_setup() out of function scope
  xen: move checks for e820 conflicts further up
  xen: introduce generic helper checking for memory map conflicts
  xen: use correct end address of kernel for conflict checking
  • Loading branch information
Linus Torvalds committed Sep 19, 2024
2 parents 1d7bb2b + c3dea3d commit 19a519c
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 66 deletions.
8 changes: 8 additions & 0 deletions arch/x86/include/asm/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ void acpi_generic_reduced_hw_init(void);
void x86_default_set_root_pointer(u64 addr);
u64 x86_default_get_root_pointer(void);

#ifdef CONFIG_XEN_PV
/* A Xen PV domain needs a special acpi_os_ioremap() handling. */
extern void __iomem * (*acpi_os_ioremap)(acpi_physical_address phys,
acpi_size size);
void __iomem *x86_acpi_os_ioremap(acpi_physical_address phys, acpi_size size);
#define acpi_os_ioremap acpi_os_ioremap
#endif

#else /* !CONFIG_ACPI */

#define acpi_lapic 0
Expand Down
7 changes: 6 additions & 1 deletion arch/x86/include/asm/cpuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
for_each_possible_hypervisor_cpuid_base(base) {
cpuid(base, &eax, &signature[0], &signature[1], &signature[2]);

if (!memcmp(sig, signature, 12) &&
/*
* This must not compile to "call memcmp" because it's called
* from PVH early boot code before instrumentation is set up
* and memcmp() itself may be instrumented.
*/
if (!__builtin_memcmp(sig, signature, 12) &&
(leaves == 0 || ((eax - base) >= leaves)))
return base;
}
Expand Down
11 changes: 11 additions & 0 deletions arch/x86/kernel/acpi/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1778,3 +1778,14 @@ u64 x86_default_get_root_pointer(void)
{
return boot_params.acpi_rsdp_addr;
}

#ifdef CONFIG_XEN_PV
void __iomem *x86_acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
{
return ioremap_cache(phys, size);
}

void __iomem * (*acpi_os_ioremap)(acpi_physical_address phys, acpi_size size) =
x86_acpi_os_ioremap;
EXPORT_SYMBOL_GPL(acpi_os_ioremap);
#endif
1 change: 1 addition & 0 deletions arch/x86/kernel/jailhouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <linux/kernel.h>
#include <linux/reboot.h>
#include <linux/serial_8250.h>
#include <linux/acpi.h>
#include <asm/apic.h>
#include <asm/io_apic.h>
#include <asm/acpi.h>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/mmconf-fam10h_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <linux/pci.h>
#include <linux/dmi.h>
#include <linux/range.h>
#include <linux/acpi.h>

#include <asm/pci-direct.h>
#include <linux/sort.h>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/smpboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <linux/stackprotector.h>
#include <linux/cpuhotplug.h>
#include <linux/mc146818rtc.h>
#include <linux/acpi.h>

#include <asm/acpi.h>
#include <asm/cacheinfo.h>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/x86_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <linux/ioport.h>
#include <linux/export.h>
#include <linux/pci.h>
#include <linux/acpi.h>

#include <asm/acpi.h>
#include <asm/bios_ebda.h>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/platform/pvh/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
OBJECT_FILES_NON_STANDARD_head.o := y
KASAN_SANITIZE := n

obj-$(CONFIG_PVH) += enlighten.o
obj-$(CONFIG_PVH) += head.o
6 changes: 5 additions & 1 deletion arch/x86/platform/pvh/enlighten.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ void __init xen_prepare_pvh(void)
BUG();
}

memset(&pvh_bootparams, 0, sizeof(pvh_bootparams));
/*
* This must not compile to "call memset" because memset() may be
* instrumented.
*/
__builtin_memset(&pvh_bootparams, 0, sizeof(pvh_bootparams));

hypervisor_specific_init(xen_guest);

Expand Down
5 changes: 1 addition & 4 deletions arch/x86/xen/mmu_pv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2018,10 +2018,7 @@ void __init xen_reserve_special_pages(void)

void __init xen_pt_check_e820(void)
{
if (xen_is_e820_reserved(xen_pt_base, xen_pt_size)) {
xen_raw_console_write("Xen hypervisor allocated page table memory conflicts with E820 map\n");
BUG();
}
xen_chk_is_e820_usable(xen_pt_base, xen_pt_size, "page table");
}

static unsigned char dummy_mapping[PAGE_SIZE] __page_aligned_bss;
Expand Down
98 changes: 98 additions & 0 deletions arch/x86/xen/p2m.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include <linux/memblock.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/acpi.h>

#include <asm/cache.h>
#include <asm/setup.h>
Expand All @@ -80,6 +81,7 @@
#include <asm/xen/hypervisor.h>
#include <xen/balloon.h>
#include <xen/grant_table.h>
#include <xen/hvc-console.h>

#include "xen-ops.h"

Expand Down Expand Up @@ -792,6 +794,102 @@ int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
return ret;
}

/* Remapped non-RAM areas */
#define NR_NONRAM_REMAP 4
static struct nonram_remap {
phys_addr_t maddr;
phys_addr_t paddr;
size_t size;
} xen_nonram_remap[NR_NONRAM_REMAP] __ro_after_init;
static unsigned int nr_nonram_remap __ro_after_init;

/*
* Do the real remapping of non-RAM regions as specified in the
* xen_nonram_remap[] array.
* In case of an error just crash the system.
*/
void __init xen_do_remap_nonram(void)
{
unsigned int i;
unsigned int remapped = 0;
const struct nonram_remap *remap = xen_nonram_remap;
unsigned long pfn, mfn, end_pfn;

for (i = 0; i < nr_nonram_remap; i++) {
end_pfn = PFN_UP(remap->paddr + remap->size);
pfn = PFN_DOWN(remap->paddr);
mfn = PFN_DOWN(remap->maddr);
while (pfn < end_pfn) {
if (!set_phys_to_machine(pfn, mfn))
panic("Failed to set p2m mapping for pfn=%lx mfn=%lx\n",
pfn, mfn);

pfn++;
mfn++;
remapped++;
}

remap++;
}

pr_info("Remapped %u non-RAM page(s)\n", remapped);
}

#ifdef CONFIG_ACPI
/*
* Xen variant of acpi_os_ioremap() taking potentially remapped non-RAM
* regions into account.
* Any attempt to map an area crossing a remap boundary will produce a
* WARN() splat.
* phys is related to remap->maddr on input and will be rebased to remap->paddr.
*/
static void __iomem *xen_acpi_os_ioremap(acpi_physical_address phys,
acpi_size size)
{
unsigned int i;
const struct nonram_remap *remap = xen_nonram_remap;

for (i = 0; i < nr_nonram_remap; i++) {
if (phys + size > remap->maddr &&
phys < remap->maddr + remap->size) {
WARN_ON(phys < remap->maddr ||
phys + size > remap->maddr + remap->size);
phys += remap->paddr - remap->maddr;
break;
}
}

return x86_acpi_os_ioremap(phys, size);
}
#endif /* CONFIG_ACPI */

/*
* Add a new non-RAM remap entry.
* In case of no free entry found, just crash the system.
*/
void __init xen_add_remap_nonram(phys_addr_t maddr, phys_addr_t paddr,
unsigned long size)
{
BUG_ON((maddr & ~PAGE_MASK) != (paddr & ~PAGE_MASK));

if (nr_nonram_remap == NR_NONRAM_REMAP) {
xen_raw_console_write("Number of required E820 entry remapping actions exceed maximum value\n");
BUG();
}

#ifdef CONFIG_ACPI
/* Switch to the Xen acpi_os_ioremap() variant. */
if (nr_nonram_remap == 0)
acpi_os_ioremap = xen_acpi_os_ioremap;
#endif

xen_nonram_remap[nr_nonram_remap].maddr = maddr;
xen_nonram_remap[nr_nonram_remap].paddr = paddr;
xen_nonram_remap[nr_nonram_remap].size = size;

nr_nonram_remap++;
}

#ifdef CONFIG_XEN_DEBUG_FS
#include <linux/debugfs.h>
static int p2m_dump_show(struct seq_file *m, void *v)
Expand Down
Loading

0 comments on commit 19a519c

Please sign in to comment.