]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
add page_get_owner_and_reference() related ASSERT()s
authorJan Beulich <jbeulich@suse.com>
Thu, 13 Aug 2015 12:47:06 +0000 (14:47 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 13 Aug 2015 12:47:06 +0000 (14:47 +0200)
The function shouldn't return NULL after having obtained a reference,
or else the caller won't know to drop it.

Also its result shouldn't be ignored - if calling code is certain that
a page already has a non-zero refcount, it better ASSERT()s so.

Finally this as well as get_page() and put_page() are required to be
available on all architectures - move the declarations to xen/mm.h.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Tim Deegan <tim@xen.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Release-acked-by: Wei Liu <wei.liu2@citrix.com>
xen/arch/arm/guestcopy.c
xen/arch/arm/mm.c
xen/arch/x86/mm.c
xen/common/grant_table.c
xen/include/asm-arm/mm.h
xen/include/asm-x86/mm.h
xen/include/xen/mm.h

index 7dbaeca9d26fb97208015774d645c578592f01b2..ce1c3c3dff7dd1c50a3a7ad0c844de9a44f7b7ea 100644 (file)
@@ -1,10 +1,8 @@
-#include <xen/config.h>
 #include <xen/lib.h>
 #include <xen/domain_page.h>
+#include <xen/mm.h>
 #include <xen/sched.h>
 #include <asm/current.h>
-
-#include <asm/mm.h>
 #include <asm/guest_access.h>
 
 static unsigned long raw_copy_to_guest_helper(void *to, const void *from,
index ae0f34c3c4801ec352fac7e9860f8b2a03345e53..d6f64cc97f65386e90b5f14ffac4e16c91b4688e 100644 (file)
@@ -1170,6 +1170,7 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)
 struct domain *page_get_owner_and_reference(struct page_info *page)
 {
     unsigned long x, y = page->count_info;
+    struct domain *owner;
 
     do {
         x = y;
@@ -1182,7 +1183,10 @@ struct domain *page_get_owner_and_reference(struct page_info *page)
     }
     while ( (y = cmpxchg(&page->count_info, x, x + 1)) != x );
 
-    return page_get_owner(page);
+    owner = page_get_owner(page);
+    ASSERT(owner);
+
+    return owner;
 }
 
 void put_page(struct page_info *page)
index 4b76587d420f293b334bb0d5ca15c18da7a49bca..358eb3a9d700e2548b666897ea5e85e50cedf5d2 100644 (file)
@@ -2038,6 +2038,7 @@ void put_page(struct page_info *page)
 struct domain *page_get_owner_and_reference(struct page_info *page)
 {
     unsigned long x, y = page->count_info;
+    struct domain *owner;
 
     do {
         x = y;
@@ -2051,7 +2052,10 @@ struct domain *page_get_owner_and_reference(struct page_info *page)
     }
     while ( (y = cmpxchg(&page->count_info, x, x + 1)) != x );
 
-    return page_get_owner(page);
+    owner = page_get_owner(page);
+    ASSERT(owner);
+
+    return owner;
 }
 
 
index f2ed64af31da9af38179cfaa088e5f6f26d07b96..2b449d56453bcff3de72a14cb70553ff5c513d2e 100644 (file)
@@ -2244,7 +2244,12 @@ __acquire_grant_for_copy(
     {
         ASSERT(mfn_valid(act->frame));
         *page = mfn_to_page(act->frame);
-        (void)page_get_owner_and_reference(*page);
+        td = page_get_owner_and_reference(*page);
+        /*
+         * act->pin being non-zero should guarantee the page to have a
+         * non-zero refcount and hence a valid owner.
+         */
+        ASSERT(td);
     }
 
     act->pin += readonly ? GNTPIN_hstr_inc : GNTPIN_hstw_inc;
index 2e1f21aaa12dc714daf92b7200b507e9c57b47d6..a95082e5004a16cd5c952f570e8a787c9e15cc17 100644 (file)
@@ -275,10 +275,6 @@ static inline void *page_to_virt(const struct page_info *pg)
     return mfn_to_virt(page_to_mfn(pg));
 }
 
-struct domain *page_get_owner_and_reference(struct page_info *page);
-void put_page(struct page_info *page);
-int  get_page(struct page_info *page, struct domain *domain);
-
 struct page_info *get_page_from_gva(struct domain *d, vaddr_t va,
                                     unsigned long flags);
 
index 8595c38f2c7c7092ef7f37d333343f54f0276a28..67b34c65a3dad4779d78fe739026975359a23120 100644 (file)
@@ -352,9 +352,6 @@ const unsigned long *get_platform_badpages(unsigned int *array_size);
 int page_lock(struct page_info *page);
 void page_unlock(struct page_info *page);
 
-struct domain *page_get_owner_and_reference(struct page_info *page);
-void put_page(struct page_info *page);
-int  get_page(struct page_info *page, struct domain *domain);
 void put_page_type(struct page_info *page);
 int  get_page_type(struct page_info *page, unsigned long type);
 int  put_page_type_preemptible(struct page_info *page);
index 876d37035ca8686746837b932591e9193da93c64..5d4b64b6d067c7bd79d17616c2db46dac75a6d9f 100644 (file)
@@ -45,6 +45,7 @@
 #ifndef __XEN_MM_H__
 #define __XEN_MM_H__
 
+#include <xen/compiler.h>
 #include <xen/types.h>
 #include <xen/list.h>
 #include <xen/spinlock.h>
@@ -77,9 +78,12 @@ TYPE_SAFE(unsigned long, pfn);
 #undef pfn_t
 #endif
 
-struct domain;
 struct page_info;
 
+void put_page(struct page_info *);
+int get_page(struct page_info *, struct domain *);
+struct domain *__must_check page_get_owner_and_reference(struct page_info *);
+
 /* Boot-time allocator. Turns into generic allocator after bootstrap. */
 void init_boot_pages(paddr_t ps, paddr_t pe);
 unsigned long alloc_boot_pages(