From patchwork Mon Sep 11 04:38:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A7AEE603F4 for ; Mon, 11 Sep 2017 04:41:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DD36289DE for ; Mon, 11 Sep 2017 04:41:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9292228AD7; Mon, 11 Sep 2017 04:41:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1F19D28ABE for ; Mon, 11 Sep 2017 04:41:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGVf-0002NF-TV; Mon, 11 Sep 2017 04:39:47 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGVf-0002Lh-GJ for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:39:47 +0000 Received: from [193.109.254.147] by server-2.bemta-6.messagelabs.com id F6/42-15060-29316B95; Mon, 11 Sep 2017 04:39:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsXS1tYhojtBeFu kwfWT3BZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8brWQ1sBe06FVcnH2FuYGxT6mLk4hASmM4o 0XftBEsXIyeHhACvxJFlM1gh7ACJfz+a2SCKehklJn89zwiSYBPQl1jx+CBYkYiAtMS1z5cZQ YqYBdYxSZxbfY4JJCEsECHxZfdKNhCbRUBV4s+dBrA4r4CdxJGVv5ghNshL7Gq7CDaIEyh+8O U7sLiQgK3EgtMLWCcw8i5gZFjFqFGcWlSWWqRrZK6XVJSZnlGSm5iZo2toYKaXm1pcnJiempO YVKyXnJ+7iREYEgxAsINx8drAQ4ySHExKorzvjm+JFOJLyk+pzEgszogvKs1JLT7EKMPBoSTB qyK0LVJIsCg1PbUiLTMHGJwwaQkOHiUR3iiQNG9xQWJucWY6ROoUoy5Hx827f5iEWPLy81Klx HnlQIoEQIoySvPgRsAi5RKjrJQwLyPQUUI8BalFuZklqPKvGMU5GJWEeSNApvBk5pXAbXoFdA QT0BE8l7aAHFGSiJCSamAUvvD9oPRRvg3TSha8lpa1WKp88AhfGudWv8VNyhJdDA/u15rlx25 O6fvrFORg9czpfs2r5Oc3/kz/r8HFvu7vh2azT/9/8Fo/1jiRWfh6a3pxB1O1ruuGG42GBZol fkHSmx4d3ix3LG/Ni4XXj/19vGLjxohAeVuGpV9fMKgcWPj+nGM60yFGJZbijERDLeai4kQAj k30B48CAAA= X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!22 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50536 invoked from network); 11 Sep 2017 04:39:43 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-2.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Sep 2017 04:39:43 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:39:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078528" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:39:41 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:38:08 +0800 Message-Id: <20170911043820.14617-28-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911043820.14617-1-haozhong.zhang@intel.com> References: <20170911043820.14617-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , George Dunlap , Andrew Cooper , Jan Beulich , Chao Peng , Dan Williams Subject: [Xen-devel] [RFC XEN PATCH v3 27/39] xen/pmem: release PMEM pages on HVM domain destruction X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP A new step RELMEM_pmem is added and taken before RELMEM_xen to release all PMEM pages mapped to a HVM domain. Signed-off-by: Haozhong Zhang --- Cc: Jan Beulich Cc: Andrew Cooper Cc: George Dunlap --- xen/arch/x86/domain.c | 32 ++++++++++++++++++++++++++++---- xen/arch/x86/mm.c | 9 +++++++-- xen/common/pmem.c | 10 ++++++++++ xen/include/asm-x86/domain.h | 1 + xen/include/xen/pmem.h | 6 ++++++ 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index dbddc536d3..1c4e788780 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1755,11 +1755,15 @@ static int relinquish_memory( { struct page_info *page; unsigned long x, y; + bool is_pmem_list = (list == &d->pmem_page_list); int ret = 0; /* Use a recursive lock, as we may enter 'free_domheap_page'. */ spin_lock_recursive(&d->page_alloc_lock); + if ( is_pmem_list ) + spin_lock(&d->pmem_lock); + while ( (page = page_list_remove_head(list)) ) { /* Grab a reference to the page so it won't disappear from under us. */ @@ -1841,8 +1845,9 @@ static int relinquish_memory( } } - /* Put the page on the list and /then/ potentially free it. */ - page_list_add_tail(page, &d->arch.relmem_list); + if ( !is_pmem_list ) + /* Put the page on the list and /then/ potentially free it. */ + page_list_add_tail(page, &d->arch.relmem_list); put_page(page); if ( hypercall_preempt_check() ) @@ -1852,10 +1857,13 @@ static int relinquish_memory( } } - /* list is empty at this point. */ - page_list_move(list, &d->arch.relmem_list); + if ( !is_pmem_list ) + /* list is empty at this point. */ + page_list_move(list, &d->arch.relmem_list); out: + if ( is_pmem_list ) + spin_unlock(&d->pmem_lock); spin_unlock_recursive(&d->page_alloc_lock); return ret; } @@ -1922,13 +1930,29 @@ int domain_relinquish_resources(struct domain *d) return ret; } +#ifndef CONFIG_NVDIMM_PMEM d->arch.relmem = RELMEM_xen; +#else + d->arch.relmem = RELMEM_pmem; +#endif spin_lock(&d->page_alloc_lock); page_list_splice(&d->arch.relmem_list, &d->page_list); INIT_PAGE_LIST_HEAD(&d->arch.relmem_list); spin_unlock(&d->page_alloc_lock); +#ifdef CONFIG_NVDIMM_PMEM + /* Fallthrough. Relinquish every page of PMEM. */ + case RELMEM_pmem: + if ( is_hvm_domain(d) ) + { + ret = relinquish_memory(d, &d->pmem_page_list, ~0UL); + if ( ret ) + return ret; + } + d->arch.relmem = RELMEM_xen; +#endif + /* Fallthrough. Relinquish every page of memory. */ case RELMEM_xen: ret = relinquish_memory(d, &d->xenpage_list, ~0UL); diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 93ccf198c9..26f9e5a13e 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -106,6 +106,7 @@ #include #include #include +#include #include #include #include @@ -2341,8 +2342,12 @@ void put_page(struct page_info *page) if ( unlikely((nx & PGC_count_mask) == 0) ) { - if ( !is_pmem_page(page) /* PMEM page is not allocated from Xen heap. */ - && cleanup_page_cacheattr(page) == 0 ) +#ifdef CONFIG_NVDIMM_PMEM + if ( is_pmem_page(page) ) + pmem_page_cleanup(page); + else +#endif + if ( cleanup_page_cacheattr(page) == 0 ) free_domheap_page(page); else gdprintk(XENLOG_WARNING, diff --git a/xen/common/pmem.c b/xen/common/pmem.c index 2f9ad64a26..8b9378dce6 100644 --- a/xen/common/pmem.c +++ b/xen/common/pmem.c @@ -741,6 +741,16 @@ int pmem_populate(struct xen_pmem_map_args *args) return rc; } +void pmem_page_cleanup(struct page_info *page) +{ + ASSERT(is_pmem_page(page)); + ASSERT((page->count_info & PGC_count_mask) == 0); + + page->count_info = PGC_pmem_page | PGC_state_free; + page_set_owner(page, NULL); + set_gpfn_from_mfn(page_to_mfn(page), INVALID_M2P_ENTRY); +} + int __init pmem_dom0_setup_permission(struct domain *d) { struct list_head *cur; diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index fb8bf17458..8322546b5d 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -303,6 +303,7 @@ struct arch_domain enum { RELMEM_not_started, RELMEM_shared, + RELMEM_pmem, RELMEM_xen, RELMEM_l4, RELMEM_l3, diff --git a/xen/include/xen/pmem.h b/xen/include/xen/pmem.h index 2dab90530b..dfbc412065 100644 --- a/xen/include/xen/pmem.h +++ b/xen/include/xen/pmem.h @@ -21,6 +21,7 @@ #ifdef CONFIG_NVDIMM_PMEM #include +#include #include int pmem_register(unsigned long smfn, unsigned long emfn, unsigned int pxm); @@ -46,6 +47,7 @@ struct xen_pmem_map_args { }; int pmem_populate(struct xen_pmem_map_args *args); +void pmem_page_cleanup(struct page_info *page); #else /* !CONFIG_X86 */ @@ -64,6 +66,10 @@ static inline int pmem_populate(...) return -ENOSYS; } +static inline void pmem_page_cleanup(...) +{ +} + #endif /* CONFIG_X86 */ #endif /* CONFIG_NVDIMM_PMEM */