Skip to content

Commit d05208c

Browse files
committed
xen: add capability to remap non-RAM pages to different PFNs
When running as a Xen PV dom0 it can happen that the kernel is being loaded to a guest physical address conflicting with the host memory map. In order to be able to resolve this conflict, add the capability to remap non-RAM areas to different guest PFNs. A function to use this remapping information for other purposes than doing the remap will be added when needed. As the number of conflicts should be rather low (currently only machines with max. 1 conflict are known), save the remap data in a small statically allocated array. Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Jan Beulich <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 43dc2a0 commit d05208c

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

arch/x86/xen/p2m.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#include <asm/xen/hypervisor.h>
8181
#include <xen/balloon.h>
8282
#include <xen/grant_table.h>
83+
#include <xen/hvc-console.h>
8384

8485
#include "xen-ops.h"
8586

@@ -792,6 +793,68 @@ int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
792793
return ret;
793794
}
794795

796+
/* Remapped non-RAM areas */
797+
#define NR_NONRAM_REMAP 4
798+
static struct nonram_remap {
799+
phys_addr_t maddr;
800+
phys_addr_t paddr;
801+
size_t size;
802+
} xen_nonram_remap[NR_NONRAM_REMAP] __ro_after_init;
803+
static unsigned int nr_nonram_remap __ro_after_init;
804+
805+
/*
806+
* Do the real remapping of non-RAM regions as specified in the
807+
* xen_nonram_remap[] array.
808+
* In case of an error just crash the system.
809+
*/
810+
void __init xen_do_remap_nonram(void)
811+
{
812+
unsigned int i;
813+
unsigned int remapped = 0;
814+
const struct nonram_remap *remap = xen_nonram_remap;
815+
unsigned long pfn, mfn, end_pfn;
816+
817+
for (i = 0; i < nr_nonram_remap; i++) {
818+
end_pfn = PFN_UP(remap->paddr + remap->size);
819+
pfn = PFN_DOWN(remap->paddr);
820+
mfn = PFN_DOWN(remap->maddr);
821+
while (pfn < end_pfn) {
822+
if (!set_phys_to_machine(pfn, mfn))
823+
panic("Failed to set p2m mapping for pfn=%lx mfn=%lx\n",
824+
pfn, mfn);
825+
826+
pfn++;
827+
mfn++;
828+
remapped++;
829+
}
830+
831+
remap++;
832+
}
833+
834+
pr_info("Remapped %u non-RAM page(s)\n", remapped);
835+
}
836+
837+
/*
838+
* Add a new non-RAM remap entry.
839+
* In case of no free entry found, just crash the system.
840+
*/
841+
void __init xen_add_remap_nonram(phys_addr_t maddr, phys_addr_t paddr,
842+
unsigned long size)
843+
{
844+
BUG_ON((maddr & ~PAGE_MASK) != (paddr & ~PAGE_MASK));
845+
846+
if (nr_nonram_remap == NR_NONRAM_REMAP) {
847+
xen_raw_console_write("Number of required E820 entry remapping actions exceed maximum value\n");
848+
BUG();
849+
}
850+
851+
xen_nonram_remap[nr_nonram_remap].maddr = maddr;
852+
xen_nonram_remap[nr_nonram_remap].paddr = paddr;
853+
xen_nonram_remap[nr_nonram_remap].size = size;
854+
855+
nr_nonram_remap++;
856+
}
857+
795858
#ifdef CONFIG_XEN_DEBUG_FS
796859
#include <linux/debugfs.h>
797860
static int p2m_dump_show(struct seq_file *m, void *v)

arch/x86/xen/xen-ops.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ void xen_mm_unpin_all(void);
4747
#ifdef CONFIG_X86_64
4848
void __init xen_relocate_p2m(void);
4949
#endif
50+
void __init xen_do_remap_nonram(void);
51+
void __init xen_add_remap_nonram(phys_addr_t maddr, phys_addr_t paddr,
52+
unsigned long size);
5053

5154
void __init xen_chk_is_e820_usable(phys_addr_t start, phys_addr_t size,
5255
const char *component);

0 commit comments

Comments
 (0)