From patchwork Tue Sep 5 14:11:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 9939129 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 3527C60350 for ; Tue, 5 Sep 2017 14:11:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD99F28AD2 for ; Tue, 5 Sep 2017 14:11:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC17A28A8A; Tue, 5 Sep 2017 14:11:11 +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, UNPARSEABLE_RELAY 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 692DF28B49 for ; Tue, 5 Sep 2017 14:10:35 +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 1dpEWQ-0005nQ-MG; Tue, 05 Sep 2017 14:08:10 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dpEWO-0005nI-TK for xen-devel@lists.xen.org; Tue, 05 Sep 2017 14:08:09 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id EF/0E-03616-8CFAEA95; Tue, 05 Sep 2017 14:08:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRWlGSWpSXmKPExsXSO6nOVff4+nW RBld+G1ks+biYxYHR4+ju30wBjFGsmXlJ+RUJrBmt+xezF9yRrjj6MrqB8aRIFyMnh5DAJCaJ ua0OXYxcQPYfRonvZ94xQSQ2MEq8vSUBYfcwSrw7BWazCRhJnD06nRHEFhGQlrj2+TIjSDOzQ AOTxPNzB8ESwgLhElear7OD2CwCqhK/56xmAbF5BbwkLt7fBrZAQkBBYsrD98wQtrFE+9uLbB MYeRYwMqxi1ChOLSpLLdI1MtJLKspMzyjJTczM0TU0MNPLTS0uTkxPzUlMKtZLzs/dxAj0OwM Q7GBcMz/wEKMkB5OSKG9o4rpIIb6k/JTKjMTijPii0pzU4kOMMhwcShK8VuuAcoJFqempFWmZ OcAAhElLcPAoifA6rwVK8xYXJOYWZ6ZDpE4xKkqJ83KA9AmAJDJK8+DaYEF/iVFWSpiXEegQI Z6C1KLczBJU+VeM4hyMSsK8iiBTeDLzSuCmvwJazAS0uOrlGpDFJYkIKakGxuSHVfVbX7b1mZ sIJyjf9W+4YCUZwSv5qd/0SIbpnJ/bL+6OZcqbXXn8d+W/W9r3xb//ZF7+7tfxhqVCpyx7FiR MN3sT/Gfi1y8uPWtnp19U5fHmuRzqGSOz/+TmPxLPDV6522/w3cFUvP70htToY+93bncNdtjz x+gwL19XDMvp/DVmCfr2P5VYijMSDbWYi4oTAZ2bDFF1AgAA X-Env-Sender: boris.ostrovsky@oracle.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1504620486!92011622!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7967 invoked from network); 5 Sep 2017 14:08:07 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-10.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Sep 2017 14:08:07 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v85E82Xm019434 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Sep 2017 14:08:02 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v85E82Ve014251 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Sep 2017 14:08:02 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v85E80SN028030; Tue, 5 Sep 2017 14:08:01 GMT Received: from ovs104.us.oracle.com (/10.149.76.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 05 Sep 2017 07:08:00 -0700 From: Boris Ostrovsky To: xen-devel@lists.xen.org Date: Tue, 5 Sep 2017 10:11:01 -0400 Message-Id: <1504620661-26511-1-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Source-IP: aserv0022.oracle.com [141.146.126.234] Cc: sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, jbeulich@suse.com, Boris Ostrovsky Subject: [Xen-devel] [PATCH v2] mm: Don't scrub pages while holding heap lock in alloc_heap_pages() 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 Instead, preserve PGC_need_scrub bit when setting PGC_state_inuse state while still under the lock and clear those pages later. Note that we still need to grub the lock when clearing PGC_need_scrub bit since count_info might be updated during MCE handling in mark_page_offline(). Signed-off-by: Boris Ostrovsky --- I couldn't convince myself that just marking the head as PGC_state_inuse under the lock is safe, mostly because of how MCE handler may write the state while the allocator is walking (lock-free) the buddy. This patch only deals with PGC_need_scrub bit which is outside state bits. _PGC_need_scrub is aliased to _PGC_allocated and I think is safe to use but we could redefine it to something else (PGC_cacheattr_base?). xen/common/page_alloc.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index dbad1e1..d368518 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -860,6 +860,7 @@ static struct page_info *alloc_heap_pages( struct page_info *pg; bool need_tlbflush = false; uint32_t tlbflush_timestamp = 0; + unsigned int dirty_cnt = 0; /* Make sure there are enough bits in memflags for nodeID. */ BUILD_BUG_ON((_MEMF_bits - _MEMF_node) < (8 * sizeof(nodeid_t))); @@ -953,14 +954,11 @@ static struct page_info *alloc_heap_pages( /* Reference count must continuously be zero for free pages. */ BUG_ON((pg[i].count_info & ~PGC_need_scrub) != PGC_state_free); - if ( test_bit(_PGC_need_scrub, &pg[i].count_info) ) - { - if ( !(memflags & MEMF_no_scrub) ) - scrub_one_page(&pg[i]); - node_need_scrub[node]--; - } + /* PGC_need_scrub can only be set if first_dirty is valid */ + ASSERT(first_dirty != INVALID_DIRTY_IDX || !(pg[i].count_info & PGC_need_scrub)); - pg[i].count_info = PGC_state_inuse; + /* Preserve PGC_need_scrub so we can check it after lock is dropped. */ + pg[i].count_info = PGC_state_inuse | (pg[i].count_info & PGC_need_scrub); if ( !(memflags & MEMF_no_tlbflush) ) accumulate_tlbflush(&need_tlbflush, &pg[i], @@ -974,13 +972,39 @@ static struct page_info *alloc_heap_pages( * guest can control its own visibility of/through the cache. */ flush_page_to_ram(page_to_mfn(&pg[i]), !(memflags & MEMF_no_icache_flush)); - - if ( !(memflags & MEMF_no_scrub) ) - check_one_page(&pg[i]); } spin_unlock(&heap_lock); + if ( first_dirty != INVALID_DIRTY_IDX || + (scrub_debug && !(memflags & MEMF_no_scrub)) ) + { + for ( i = 0; i < (1U << order); i++ ) + { + if ( test_bit(_PGC_need_scrub, &pg[i].count_info) ) + { + if ( !(memflags & MEMF_no_scrub) ) + scrub_one_page(&pg[i]); + + dirty_cnt++; + + spin_lock(&heap_lock); + pg[i].count_info &= ~PGC_need_scrub; + spin_unlock(&heap_lock); + } + + if ( !(memflags & MEMF_no_scrub) ) + check_one_page(&pg[i]); + } + + if ( dirty_cnt ) + { + spin_lock(&heap_lock); + node_need_scrub[node] -= dirty_cnt; + spin_unlock(&heap_lock); + } + } + if ( need_tlbflush ) filtered_flush_tlb_mask(tlbflush_timestamp);