@@ -816,8 +816,8 @@ int __init make_memory_node(const struct domain *d,
return res;
}
-static int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,
- void *data)
+int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,
+ void *data)
{
struct membanks *ext_regions = data;
paddr_t start, size;
@@ -990,6 +990,8 @@ static int __init handle_pci_range(const struct dt_device_node *dev,
* - MMIO
* - Host RAM
* - PCI aperture
+ * - Static shared memory regions, which are described by special property
+ * "xen,shared-mem"
*/
static int __init find_memory_holes(const struct kernel_info *kinfo,
struct membanks *ext_regions)
@@ -1017,6 +1019,11 @@ static int __init find_memory_holes(const struct kernel_info *kinfo,
goto out;
}
+ /* Remove static shared memory regions */
+ res = remove_shm_from_rangeset(kinfo, mem_holes);
+ if ( res )
+ goto out;
+
/*
* Remove regions described by "reg" and "ranges" properties where
* the memory is addressable (MMIO, RAM, PCI BAR, etc).
@@ -1109,7 +1116,10 @@ static int __init find_domU_holes(const struct kernel_info *kinfo,
res = 0;
}
- return res;
+ if ( res )
+ return res;
+
+ return remove_shm_holes_for_domU(kinfo, ext_regions);
}
int __init make_hypervisor_node(struct domain *d,
@@ -51,6 +51,8 @@ static inline int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
int prepare_acpi(struct domain *d, struct kernel_info *kinfo);
#endif
+int add_ext_regions(unsigned long s_gfn, unsigned long e_gfn, void *data);
+
#endif
/*
@@ -28,6 +28,12 @@ void early_print_info_shmem(void);
void init_sharedmem_pages(void);
+int remove_shm_from_rangeset(const struct kernel_info *kinfo,
+ struct rangeset *rangeset);
+
+int remove_shm_holes_for_domU(const struct kernel_info *kinfo,
+ struct membanks *ext_regions);
+
#else /* !CONFIG_STATIC_SHM */
static inline int make_resv_memory_node(const struct kernel_info *kinfo,
@@ -59,6 +65,18 @@ static inline void early_print_info_shmem(void) {};
static inline void init_sharedmem_pages(void) {};
+static inline int remove_shm_from_rangeset(const struct kernel_info *kinfo,
+ struct rangeset *rangeset)
+{
+ return 0;
+}
+
+static inline int remove_shm_holes_for_domU(const struct kernel_info *kinfo,
+ struct membanks *ext_regions)
+{
+ return 0;
+}
+
#endif /* CONFIG_STATIC_SHM */
#endif /* __ASM_STATIC_SHMEM_H_ */
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <xen/libfdt/libfdt.h>
+#include <xen/rangeset.h>
#include <xen/sched.h>
#include <asm/domain_build.h>
@@ -574,6 +575,99 @@ void __init init_sharedmem_pages(void)
init_staticmem_bank(&shmem->bank[bank]);
}
+int __init remove_shm_from_rangeset(const struct kernel_info *kinfo,
+ struct rangeset *rangeset)
+{
+ const struct membanks *shm_mem = &kinfo->shm_mem.common;
+ unsigned int i;
+
+ /* Remove static shared memory regions */
+ for ( i = 0; i < shm_mem->nr_banks; i++ )
+ {
+ paddr_t start, end;
+ int res;
+
+ start = shm_mem->bank[i].start;
+ end = shm_mem->bank[i].start + shm_mem->bank[i].size;
+ res = rangeset_remove_range(rangeset, PFN_DOWN(start),
+ PFN_DOWN(end - 1));
+ if ( res )
+ {
+ printk(XENLOG_ERR
+ "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr", error: %d\n",
+ start, end, res);
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
+int __init remove_shm_holes_for_domU(const struct kernel_info *kinfo,
+ struct membanks *ext_regions)
+{
+ const struct membanks *shm_mem = &kinfo->shm_mem.common;
+ struct rangeset *guest_holes;
+ unsigned int i;
+ paddr_t start;
+ paddr_t end;
+ int res;
+
+ /* No static shared memory region. */
+ if ( shm_mem->nr_banks == 0 )
+ return 0;
+
+ dt_dprintk("Remove static shared memory holes from extended regions of DomU\n");
+
+ guest_holes = rangeset_new(NULL, NULL, 0);
+ if ( !guest_holes )
+ return -ENOMEM;
+
+ /* Copy extended regions sets into the rangeset */
+ for ( i = 0; i < ext_regions->nr_banks; i++ )
+ {
+ start = ext_regions->bank[i].start;
+ end = start + ext_regions->bank[i].size;
+
+ res = rangeset_add_range(guest_holes, PFN_DOWN(start),
+ PFN_DOWN(end - 1));
+ if ( res )
+ {
+ printk(XENLOG_ERR
+ "Failed to add: %#"PRIpaddr"->%#"PRIpaddr", error: %d\n",
+ start, end, res);
+ goto out;
+ }
+ }
+
+ /* Remove static shared memory regions */
+ res = remove_shm_from_rangeset(kinfo, guest_holes);
+ if ( res )
+ goto out;
+
+ /*
+ * Take the interval of memory starting from the first extended region bank
+ * start address and ending to the end of the last extended region bank.
+ */
+ i = ext_regions->nr_banks - 1;
+ start = ext_regions->bank[0].start;
+ end = ext_regions->bank[i].start + ext_regions->bank[i].size - 1;
+
+ /* Reset original extended regions to hold new value */
+ ext_regions->nr_banks = 0;
+ res = rangeset_report_ranges(guest_holes, PFN_DOWN(start), PFN_DOWN(end),
+ add_ext_regions, ext_regions);
+ if ( res )
+ ext_regions->nr_banks = 0;
+ else if ( !ext_regions->nr_banks )
+ res = -ENOENT;
+
+ out:
+ rangeset_destroy(guest_holes);
+
+ return res;
+}
+
/*
* Local variables:
* mode: C