From patchwork Thu Dec 17 16:31:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 7874301 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A20649F3CD for ; Thu, 17 Dec 2015 16:36:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 76A5F20444 for ; Thu, 17 Dec 2015 16:36:28 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 348712042C for ; Thu, 17 Dec 2015 16:36:25 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1a9bUr-00038T-2W; Thu, 17 Dec 2015 16:33:41 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1a9bUo-00038G-VB for xen-devel@lists.xenproject.org; Thu, 17 Dec 2015 16:33:39 +0000 Received: from [85.158.139.211] by server-4.bemta-5.messagelabs.com id EB/20-24856-2E3E2765; Thu, 17 Dec 2015 16:33:38 +0000 X-Env-Sender: prvs=78612b3c6=julien.grall@citrix.com X-Msg-Ref: server-5.tower-206.messagelabs.com!1450370016!11438791!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 42918 invoked from network); 17 Dec 2015 16:33:37 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-5.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 17 Dec 2015 16:33:37 -0000 X-IronPort-AV: E=Sophos;i="5.20,441,1444694400"; d="scan'208";a="320056730" From: Julien Grall To: Date: Thu, 17 Dec 2015 16:31:59 +0000 Message-ID: <1450369919-22989-4-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1450369919-22989-1-git-send-email-julien.grall@citrix.com> References: <1450369919-22989-1-git-send-email-julien.grall@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Keir Fraser , ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, Andrew Cooper , Julien Grall , Stefano Stabellini , Jan Beulich Subject: [Xen-devel] [RFC 3/3] xen/common: memory: Move steal_page in common code X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The implementation of steal_page for ARM and x86 would be the same. Rather than duplicating the x86 function, move it in common code. Also introduce missing define PRtype_info for ARM in order to compile the code. Signed-off-by: Julien Grall --- Cc: Ian Campbell Cc: Stefano Stabellini Cc: Keir Fraser Cc: Jan Beulich Cc: Andrew Cooper Note that this patch *shouldn't* be applied before the rest of the series. This is because the callers of this function are not fully fixed for ARM and could possibly introduce security issue. steal_page was always returning an error which lead the rest of the code to not be executed for ARM. TODO: - Check that all the callers of steal_page are properly working for ARM. --- xen/arch/arm/mm.c | 6 ------ xen/arch/x86/mm.c | 51 ------------------------------------------------ xen/common/page_alloc.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/mm.h | 4 ++-- xen/include/asm-x86/mm.h | 2 -- xen/include/xen/mm.h | 3 +++ 6 files changed, 56 insertions(+), 61 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 47bfb27..b2e6682 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -989,12 +989,6 @@ int donate_page(struct domain *d, struct page_info *page, unsigned int memflags) return -ENOSYS; } -int steal_page( - struct domain *d, struct page_info *page, unsigned int memflags) -{ - return -1; -} - int page_is_ram_type(unsigned long mfn, unsigned long mem_type) { ASSERT(0); diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 92df36f..8508d9e 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4253,57 +4253,6 @@ int donate_page( return -1; } -int steal_page( - struct domain *d, struct page_info *page, unsigned int memflags) -{ - unsigned long x, y; - bool_t drop_dom_ref = 0; - const struct domain *owner = dom_xen; - - spin_lock(&d->page_alloc_lock); - - if ( is_xen_heap_page(page) || ((owner = page_get_owner(page)) != d) ) - goto fail; - - /* - * We require there is just one reference (PGC_allocated). We temporarily - * drop this reference now so that we can safely swizzle the owner. - */ - y = page->count_info; - do { - x = y; - if ( (x & (PGC_count_mask|PGC_allocated)) != (1 | PGC_allocated) ) - goto fail; - y = cmpxchg(&page->count_info, x, x & ~PGC_count_mask); - } while ( y != x ); - - /* Swizzle the owner then reinstate the PGC_allocated reference. */ - page_set_owner(page, NULL); - y = page->count_info; - do { - x = y; - BUG_ON((x & (PGC_count_mask|PGC_allocated)) != PGC_allocated); - } while ( (y = cmpxchg(&page->count_info, x, x | 1)) != x ); - - /* Unlink from original owner. */ - if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1) ) - drop_dom_ref = 1; - page_list_del(page, &d->page_list); - - spin_unlock(&d->page_alloc_lock); - if ( unlikely(drop_dom_ref) ) - put_domain(d); - return 0; - - fail: - spin_unlock(&d->page_alloc_lock); - MEM_LOG("Bad page %lx: ed=%d sd=%d caf=%08lx taf=%" PRtype_info, - page_to_mfn(page), d->domain_id, - owner ? owner->domain_id : DOMID_INVALID, - page->count_info, page->u.inuse.type_info); - return -1; -} - static int __do_update_va_mapping( unsigned long va, u64 val64, unsigned long flags, struct domain *pg_owner) { diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 624a266..7c9d66e 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1786,6 +1786,57 @@ int assign_pages( return -1; } +int steal_page( + struct domain *d, struct page_info *page, unsigned int memflags) +{ + unsigned long x, y; + bool_t drop_dom_ref = 0; + const struct domain *owner = dom_xen; + + spin_lock(&d->page_alloc_lock); + + if ( is_xen_heap_page(page) || ((owner = page_get_owner(page)) != d) ) + goto fail; + + /* + * We require there is just one reference (PGC_allocated). We temporarily + * drop this reference now so that we can safely swizzle the owner. + */ + y = page->count_info; + do { + x = y; + if ( (x & (PGC_count_mask|PGC_allocated)) != (1 | PGC_allocated) ) + goto fail; + y = cmpxchg(&page->count_info, x, x & ~PGC_count_mask); + } while ( y != x ); + + /* Swizzle the owner then reinstate the PGC_allocated reference. */ + page_set_owner(page, NULL); + y = page->count_info; + do { + x = y; + BUG_ON((x & (PGC_count_mask|PGC_allocated)) != PGC_allocated); + } while ( (y = cmpxchg(&page->count_info, x, x | 1)) != x ); + + /* Unlink from original owner. */ + if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1) ) + drop_dom_ref = 1; + page_list_del(page, &d->page_list); + + spin_unlock(&d->page_alloc_lock); + if ( unlikely(drop_dom_ref) ) + put_domain(d); + return 0; + + fail: + spin_unlock(&d->page_alloc_lock); + gdprintk(XENLOG_WARNING, + "Bad page %lx: ed=%d sd=%d caf=%08lx taf=%" PRtype_info, + page_to_mfn(page), d->domain_id, + owner ? owner->domain_id : DOMID_INVALID, + page->count_info, page->u.inuse.type_info); + return -1; +} struct page_info *alloc_domheap_pages( struct domain *d, unsigned int order, unsigned int memflags) diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 2e9d0b2..d212d39 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -73,6 +73,8 @@ struct page_info u64 pad; }; +#define PRtype_info "016lx"/* should only be used for printk's */ + #define PG_shift(idx) (BITS_PER_LONG - (idx)) #define PG_mask(x, idx) (x ## UL << PG_shift(idx)) @@ -319,8 +321,6 @@ static inline int relinquish_shared_pages(struct domain *d) /* Arch-specific portion of memory_op hypercall. */ long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg); -int steal_page( - struct domain *d, struct page_info *page, unsigned int memflags); int donate_page( struct domain *d, struct page_info *page, unsigned int memflags); diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 67b34c6..769552e 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -531,8 +531,6 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg); int compat_arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void)); int compat_subarch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void)); -int steal_page( - struct domain *d, struct page_info *page, unsigned int memflags); int donate_page( struct domain *d, struct page_info *page, unsigned int memflags); diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 5d4b64b..4fafd88 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -139,6 +139,9 @@ int assign_pages( unsigned int order, unsigned int memflags); +int steal_page( + struct domain *d, struct page_info *page, unsigned int memflags); + /* Dump info to serial console */ void arch_dump_shared_mem_info(void);