diff options
author | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2013-05-13 15:29:11 -0400 |
---|---|---|
committer | Ian Campbell <ian.campbell@citrix.com> | 2013-05-14 10:01:50 +0100 |
commit | bec8f17e48439ee5b8370f4e431ccd9a9514bee7 (patch) | |
tree | 59b77ff052dcef3826e1f54a5eb183ae5ceac18a /xen | |
parent | abf04cf04f5b6f2ce22e9f7966d63303b9487d81 (diff) | |
download | xen-bec8f17e48439ee5b8370f4e431ccd9a9514bee7.tar.gz xen-bec8f17e48439ee5b8370f4e431ccd9a9514bee7.tar.bz2 xen-bec8f17e48439ee5b8370f4e431ccd9a9514bee7.zip |
hypervisor/xen/tools: Remove the XENMEM_get_oustanding_pages and provide the data via xc_phys_info
During the review of the patches it was noticed that there exists
a race wherein the 'free_memory' value consists of information from
two hypercalls. That is the XEN_SYSCTL_physinfo and XENMEM_get_outstanding_pages.
The free memory the host has available for guest is the difference between
the 'free_pages' (from XEN_SYSCTL_physinfo) and 'outstanding_pages'. As they
are two hypercalls many things can happen in between the execution of them.
This patch resolves this by eliminating the XENMEM_get_outstanding_pages
hypercall and providing the free_pages and outstanding_pages information
via the xc_phys_info structure.
It also removes the XSM hooks and adds locking as needed.
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Tim Deegan <tim@xen.org>
Acked-by: Keir Fraser <keir.xen@gmail.com>
Diffstat (limited to 'xen')
-rw-r--r-- | xen/common/memory.c | 8 | ||||
-rw-r--r-- | xen/common/page_alloc.c | 7 | ||||
-rw-r--r-- | xen/common/sysctl.c | 3 | ||||
-rw-r--r-- | xen/include/public/memory.h | 7 | ||||
-rw-r--r-- | xen/include/public/sysctl.h | 3 | ||||
-rw-r--r-- | xen/include/xen/mm.h | 2 | ||||
-rw-r--r-- | xen/include/xsm/dummy.h | 6 | ||||
-rw-r--r-- | xen/include/xsm/xsm.h | 6 | ||||
-rw-r--r-- | xen/xsm/dummy.c | 1 | ||||
-rw-r--r-- | xen/xsm/flask/hooks.c | 7 | ||||
-rw-r--r-- | xen/xsm/flask/policy/access_vectors | 2 |
11 files changed, 11 insertions, 41 deletions
diff --git a/xen/common/memory.c b/xen/common/memory.c index 3239d53978..06a0d0ac4c 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -737,14 +737,6 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) break; - case XENMEM_get_outstanding_pages: - rc = xsm_xenmem_get_outstanding_pages(XSM_PRIV); - - if ( !rc ) - rc = get_outstanding_claims(); - - break; - default: rc = arch_memory_op(op, arg); break; diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 203f77a485..2162ef14d4 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -380,9 +380,12 @@ out: return ret; } -long get_outstanding_claims(void) +void get_outstanding_claims(uint64_t *free_pages, uint64_t *outstanding_pages) { - return outstanding_claims; + spin_lock(&heap_lock); + *outstanding_pages = outstanding_claims; + *free_pages = avail_domheap_pages(); + spin_unlock(&heap_lock); } static unsigned long init_node_heap(int node, unsigned long mfn, diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c index 31f9650ecc..117e095a35 100644 --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -264,7 +264,8 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) pi->max_node_id = MAX_NUMNODES-1; pi->max_cpu_id = nr_cpu_ids - 1; pi->total_pages = total_pages; - pi->free_pages = avail_domheap_pages(); + /* Protected by lock */ + get_outstanding_claims(&pi->free_pages, &pi->outstanding_pages); pi->scrub_pages = 0; pi->cpu_khz = cpu_khz; arch_do_physinfo(pi); diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 51d5254933..7a26dee008 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -459,13 +459,6 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t); * The zero value is appropiate. */ -/* - * Get the number of pages currently claimed (but not yet "possessed") - * across all domains. The caller must be privileged but otherwise - * the call never fails. - */ -#define XENMEM_get_outstanding_pages 25 - #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ #endif /* __XEN_PUBLIC_MEMORY_H__ */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 03710d896f..8437d31e18 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -34,7 +34,7 @@ #include "xen.h" #include "domctl.h" -#define XEN_SYSCTL_INTERFACE_VERSION 0x00000009 +#define XEN_SYSCTL_INTERFACE_VERSION 0x0000000A /* * Read console content from Xen buffer ring. @@ -101,6 +101,7 @@ struct xen_sysctl_physinfo { uint64_aligned_t total_pages; uint64_aligned_t free_pages; uint64_aligned_t scrub_pages; + uint64_aligned_t outstanding_pages; uint32_t hw_cap[8]; /* XEN_SYSCTL_PHYSCAP_??? */ diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index efc45c78f1..4f5795c28b 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -59,7 +59,7 @@ void destroy_xen_mappings(unsigned long v, unsigned long e); /* Claim handling */ unsigned long domain_adjust_tot_pages(struct domain *d, long pages); int domain_set_outstanding_pages(struct domain *d, unsigned long pages); -long get_outstanding_claims(void); +void get_outstanding_claims(uint64_t *free_pages, uint64_t *outstanding_pages); /* Domain suballocator. These functions are *not* interrupt-safe.*/ void init_domheap_pages(paddr_t ps, paddr_t pe); diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index a87205661d..cc0a5a8301 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -259,12 +259,6 @@ static XSM_INLINE int xsm_claim_pages(XSM_DEFAULT_ARG struct domain *d) return xsm_default_action(action, current->domain, d); } -static XSM_INLINE int xsm_xenmem_get_outstanding_pages(XSM_DEFAULT_VOID) -{ - XSM_ASSERT_ACTION(XSM_PRIV); - return xsm_default_action(action, current->domain, NULL); -} - static XSM_INLINE int xsm_evtchn_unbound(XSM_DEFAULT_ARG struct domain *d, struct evtchn *chn, domid_t id2) { diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 58a4fbb1d1..193945323e 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -93,7 +93,6 @@ struct xsm_operations { int (*add_to_physmap) (struct domain *d1, struct domain *d2); int (*remove_from_physmap) (struct domain *d1, struct domain *d2); int (*claim_pages) (struct domain *d); - int (*xenmem_get_outstanding_pages) (void); int (*console_io) (struct domain *d, int cmd); @@ -360,11 +359,6 @@ static inline int xsm_claim_pages(xsm_default_t def, struct domain *d) return xsm_ops->claim_pages(d); } -static inline int xsm_xenmem_get_outstanding_pages(xsm_default_t def) -{ - return xsm_ops->xenmem_get_outstanding_pages(); -} - static inline int xsm_console_io (xsm_default_t def, struct domain *d, int cmd) { return xsm_ops->console_io(d, cmd); diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c index 937761f095..31e4f739b3 100644 --- a/xen/xsm/dummy.c +++ b/xen/xsm/dummy.c @@ -67,7 +67,6 @@ void xsm_fixup_ops (struct xsm_operations *ops) set_to_dummy_if_null(ops, memory_stat_reservation); set_to_dummy_if_null(ops, memory_pin_page); set_to_dummy_if_null(ops, claim_pages); - set_to_dummy_if_null(ops, xenmem_get_outstanding_pages); set_to_dummy_if_null(ops, console_io); diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index bb10de3ae8..fa0589a2d7 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -422,12 +422,6 @@ static int flask_claim_pages(struct domain *d) return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SETCLAIM); } -static int flask_xenmem_get_outstanding_pages(void) -{ - return avc_current_has_perm(SECINITSID_XEN, SECCLASS_XEN, - XEN__HEAP, NULL); -} - static int flask_console_io(struct domain *d, int cmd) { u32 perm; @@ -1504,7 +1498,6 @@ static struct xsm_operations flask_ops = { .memory_stat_reservation = flask_memory_stat_reservation, .memory_pin_page = flask_memory_pin_page, .claim_pages = flask_claim_pages, - .xenmem_get_outstanding_pages = flask_xenmem_get_outstanding_pages, .console_io = flask_console_io, diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/access_vectors index 544c3bae0f..5dfe13b016 100644 --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -54,7 +54,7 @@ class xen debug # XEN_SYSCTL_getcpuinfo, XENPF_get_cpu_version, XENPF_get_cpuinfo getcpuinfo -# XEN_SYSCTL_availheap, XENMEM_get_outstanding_pages +# XEN_SYSCTL_availheap heap # XEN_SYSCTL_get_pmstat, XEN_SYSCTL_pm_op, XENPF_set_processor_pminfo, # XENPF_core_parking |