From b0dbd314cc1f580668279dd45b754dcd9df6c992 Mon Sep 17 00:00:00 2001 From: Boris Ostrovsky Date: Fri, 15 Sep 2017 16:23:53 -0400 Subject: [PATCH] xen/x86: Add interface for querying amount of host memory A driver (or some other entity in the kernel) may need to know amount of memory available on the host. Provide the interface (for a privileged domain() to obtain this information. Orabug: 26526923 Signed-off-by: Boris Ostrovsky Reviewed-by: Konrad Rzeszutek Wilk --- arch/x86/include/asm/xen/hypervisor.h | 5 ++++ arch/x86/xen/enlighten.c | 36 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/arch/x86/include/asm/xen/hypervisor.h b/arch/x86/include/asm/xen/hypervisor.h index 0c47f1afb3a0..aa1e2f086a80 100644 --- a/arch/x86/include/asm/xen/hypervisor.h +++ b/arch/x86/include/asm/xen/hypervisor.h @@ -45,6 +45,7 @@ static inline uint32_t xen_cpuid_base(void) #ifdef CONFIG_XEN extern bool xen_hvm_need_lapic(void); +extern int xen_get_host_pages(unsigned long *num_pages); static inline bool xen_x2apic_para_available(void) { @@ -55,6 +56,10 @@ static inline bool xen_x2apic_para_available(void) { return (xen_cpuid_base() != 0); } +static inline int xen_get_host_pages(unsigned long *num_pages) +{ + return -EOPNOTSUPP; +} #endif void xen_set_iopl_mask(unsigned mask); diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index 96062f109fbb..6aa28967d7ef 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -1981,3 +1981,39 @@ void xen_arch_unregister_cpu(int num) } EXPORT_SYMBOL(xen_arch_unregister_cpu); #endif + +/* UEK-specific routine */ +int xen_get_host_pages(unsigned long *num_pages) +{ + struct xen_memory_map memmap; + struct e820entry *e820map; + unsigned long sz = 0; + int i, rc; + + if (!xen_domain()) + return -EOPNOTSUPP; + if (!xen_initial_domain()) + return -EPERM; + + memmap.nr_entries = E820_X_MAX; + e820map = kmalloc(sizeof(*e820map) * memmap.nr_entries, GFP_KERNEL); + if (e820map == NULL) + return -ENOMEM; + set_xen_guest_handle(memmap.buffer, e820map); + + rc = HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap); + if (rc) + goto out; + + for (i = 0; i < memmap.nr_entries; i++) { + if (e820map[i].type == E820_RAM) + sz += e820map[i].size; + } + + *num_pages = (sz >> PAGE_SHIFT); + + out: + kfree(e820map); + return rc; +} +EXPORT_SYMBOL(xen_get_host_pages); -- 2.50.1