From patchwork Wed Sep 6 15:33:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 9941021 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 33D4A6035F for ; Wed, 6 Sep 2017 15:33:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2015128885 for ; Wed, 6 Sep 2017 15:33:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14DEB28C16; Wed, 6 Sep 2017 15:33:16 +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 8FCDF28885 for ; Wed, 6 Sep 2017 15:33:15 +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 1dpcIB-0007BM-FB; Wed, 06 Sep 2017 15:31:03 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dpcIA-0007B8-I3 for xen-devel@lists.xen.org; Wed, 06 Sep 2017 15:31:02 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id B3/53-06889-5B410B95; Wed, 06 Sep 2017 15:31:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKLMWRWlGSWpSXmKPExsUyZ7p8oO5WkQ2 RBqvmC1os+biYxYHR4+ju30wBjFGsmXlJ+RUJrBkPlnxgLJgmU9H0oYOxgfGVSBcjF4eQwCQm iedzG9m6GDmBnD+MEocbkiASGxglTjffZ4FwehgljmzdDlbFJmAkcfbodEYQW0RAWuLa58uMI EXMAg1Ao84dBEsIC4RLvDjYzApiswioSjTsmcIEYvMKeEk8nr4OzJYQUJCY8vA9M4RtLNH+9i LbBEaeBYwMqxg1ilOLylKLdA0N9ZKKMtMzSnITM3N0DQ1M9XJTi4sT01NzEpOK9ZLzczcxAr3 PAAQ7GFe2Ox9ilORgUhLlvay2PlKILyk/pTIjsTgjvqg0J7X4EKMMB4eSBO9m4Q2RQoJFqemp FWmZOcAwhElLcPAoifCuFAJK8xYXJOYWZ6ZDpE4xKkqJ88aC9AmAJDJK8+DaYKF/iVFWSpiXE egQIZ6C1KLczBJU+VeM4hyMSsK87CBTeDLzSuCmvwJazAS0uOrlGpDFJYkIKakGxp09U9blik 1ff4Mxm/1neeHJvOSIe4vmzSrztVnrtdJlhdHZ1nzTy/PvR9rtT7Ar/7q096lm2VS9tB6D186 VDXNvFB/9/lJiXvTk2Idn606IxB2M4Yz+oCRnbLVm1k6ORN+u5daXeoQ3egkxd/itvi7Ia5v4 8tD120xH3wbqKvy3mmKTEVFjpMRSnJFoqMVcVJwIAAX4glV4AgAA X-Env-Sender: boris.ostrovsky@oracle.com X-Msg-Ref: server-2.tower-206.messagelabs.com!1504711859!89780719!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13763 invoked from network); 6 Sep 2017 15:31:00 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-2.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 6 Sep 2017 15:31:00 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v86FUpXu028021 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Sep 2017 15:30:52 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v86FUphK023354 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Sep 2017 15:30:51 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v86FUpuq004762; Wed, 6 Sep 2017 15:30:51 GMT Received: from ovs104.us.oracle.com (/10.149.76.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Sep 2017 08:30:50 -0700 From: Boris Ostrovsky To: xen-devel@lists.xen.org Date: Wed, 6 Sep 2017 11:33:52 -0400 Message-Id: <1504712032-27706-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 v3] 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 Reviewed-by: Jan Beulich --- v3: * Call check_one_page() only if _PGC_need_scrub is not set. * After more thinking I decided to keep scub_debug check: the false positive issue that I was concerned about is bogus: we are checking whether an unscrubbed page is accidentally given out so the only potential problem here would be us missing the case where a guest filled a page with clean pattern *and* we for some reason didn't scrub it. So the test is not perfect in that respect, but that's it. xen/common/page_alloc.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index dbad1e1..b5243fc 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,38 @@ 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); + } + else 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);