From patchwork Thu Jun 11 22:30:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 11600991 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35F5F913 for ; Thu, 11 Jun 2020 22:30:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 017672074B for ; Thu, 11 Jun 2020 22:30:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="W26cncJy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 017672074B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 34E768D00AA; Thu, 11 Jun 2020 18:30:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2D7B58D00A0; Thu, 11 Jun 2020 18:30:50 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A0098D00AA; Thu, 11 Jun 2020 18:30:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id F2B458D00A0 for ; Thu, 11 Jun 2020 18:30:49 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id AFE4F181ABE8B for ; Thu, 11 Jun 2020 22:30:49 +0000 (UTC) X-FDA: 76918377018.08.stew49_5900b9426dd7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 77DFA181ADB5F for ; Thu, 11 Jun 2020 22:30:49 +0000 (UTC) X-Spam-Summary: 2,0,0,8c6826af27535535,d41d8cd98f00b204,hughd@google.com,,RULES_HIT:41:355:379:800:960:966:973:988:989:1260:1277:1313:1314:1345:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2553:2559:2562:3138:3139:3140:3141:3142:3152:3354:3743:3865:3866:3867:3868:3870:3871:3872:3874:4321:4385:5007:6119:6261:6653:6742:7808:7875:7903:8660:8957:9108:9592:10004:10400:11026:11232:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12740:12895:12986:13148:13230:13439:14096:14097:14181:14394:14659:14721:21080:21212:21444:21451:21627:21939:30054:30070:30090,0,RBL:209.85.210.65:@google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: stew49_5900b9426dd7 X-Filterd-Recvd-Size: 5731 Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Thu, 11 Jun 2020 22:30:49 +0000 (UTC) Received: by mail-ot1-f65.google.com with SMTP id 97so5876552otg.3 for ; Thu, 11 Jun 2020 15:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=+EahI0YlQUT1/wBvgRJFQZcHP3obsCOagtKe7ySyhrM=; b=W26cncJyLH/i2zSIOMrO837pRs3uf2BxQU7IzrLdCgttozbazIeNDlQgCyQFiYpUyY Ms4olROFTxfvmQAdemlh52vDy0Ftr89GQMQrDXOir38oNwY8+8gPiDMnQChh/qPvfhj1 iUsIdILczYmCpO1xqBDBaFflxA4qJYGotgpCt1+gBdruUxe14ckzTnM3+9z+NR3Qkckp 8bXFzj6IhT3p8E6ZtAmnlH8HwiB/X34paleeTrwi7sO8xUPY1QHO1EqXGNShfQxJUmTK oNomeUpR4hUAyI5seihocIFNBhP5T0Ojn22FOBFdo6AgdYqo+CShth6zOvtf4oEc8vZn S8fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=+EahI0YlQUT1/wBvgRJFQZcHP3obsCOagtKe7ySyhrM=; b=eNIOTck/QpT+zfJF4aVTP4GCOh7lZUvUbLeTWxa4GQ7ic/h5C/KB55N8sDYSMbw95T rjfSin58jgvPlZE0Hlqqg7+ZJYx9Y0tdnzWrI/rhJjyRhhDSpVA3UOYsZVAvTri9D5nC 2yDvRuRU8iLb72tCfD0CCmmw7ugNJX6+AuzanD7AiKCXVdE69S8d2f4peMqg0gZmLq2s dccJVI/6Sf4Jp3Boe8LN4EZ7vJ8QVJ6AE1ubS9SO1OR72V0ysludg34q56OJ9Pk3vS8i yczXQQfr8leGx04z0w0uY+MXKLcmwDXIKp5YkfE55uSm2V2zCkBudBdESBCyriOeOfWX QowA== X-Gm-Message-State: AOAM533e6qekjU2pO22ZiycPKP93kJ7cIN3kU7JeuiIJz6J8fAWurx3h 1DhjA5XySlETxsRs6Wr0pQj3jw== X-Google-Smtp-Source: ABdhPJzEon9DZKGa7Vpn9RDUNP7chh++P+QM4RhU5y/VWUIMVZUMKcU4pCYumWLy9ZXhRooe4mHeuA== X-Received: by 2002:a05:6830:1dba:: with SMTP id z26mr8682022oti.180.1591914648150; Thu, 11 Jun 2020 15:30:48 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id r15sm978948oot.5.2020.06.11.15.30.45 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Thu, 11 Jun 2020 15:30:47 -0700 (PDT) Date: Thu, 11 Jun 2020 15:30:45 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Alex Shi cc: akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, yang.shi@linux.alibaba.com, willy@infradead.org, hannes@cmpxchg.org, lkp@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, shakeelb@google.com, iamjoonsoo.kim@lge.com, richard.weiyang@gmail.com Subject: [PATCH alexv12 2/2] mm/compaction: fix call to __isolate_lru_page_prepare() Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-Rspamd-Queue-Id: 77DFA181ADB5F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: isolate_migratepages_block() is calling __isolate_lru_page_prepare() at a point when it has not yet acquired a reference to the page, and may not yet hold the right lruvec lock: it has no hold on the page. trylock_page() is not safe to use at this time: its setting PG_locked can race with the page being freed or allocated ("Bad page"), and can also erase flags being set by one of those "sole owners" of a freshly allocated page who use non-atomic __SetPageFlag(). Though I have tried rcu_read_lock() instead of trylock_page() there (like in page_evictable()), 054f1d1faaed ("mm/swap_state.c: simplify total_swapcache_pages() with get_swap_device()") stopped the freeing of swapper_spaces by RCU; and races against setting PageSwapCache, and the dereference of mapping->a_ops, and the lack of any page reference: all make that a more dubious approach. Just move the call to __isolate_lru_page_prepare() after the call to get_page_unless_zero(), when using trylock_page() has become safe (safe given __isolate's check for PageLRU - unsafe without that). Signed-off-by: Hugh Dickins --- I had envisaged this as a separate patch; but once it came down to just moving the call inside isolate_migratepages_block(), it's probably best folded into 10/16 or 12/16 (needs isolate_fail_put). I shall probably want to come along later, to clean up or eliminate __isolate_lru_page_prepare(): which I found before to have almost nothing in common between its use by isolate_migratepages_block() and its use by isolate_lru_pages(). We can then do its safer checks before the get_page_unless_zero(). But trying that cleanup right now would just get in the way of this series. mm/compaction.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- alexv12/mm/compaction.c 2020-06-11 13:48:10.437046025 -0700 +++ hughd/mm/compaction.c 2020-06-11 13:49:05.570579095 -0700 @@ -960,9 +960,6 @@ isolate_migratepages_block(struct compac if (!(cc->gfp_mask & __GFP_FS) && page_mapping(page)) goto isolate_fail; - if (__isolate_lru_page_prepare(page, isolate_mode) != 0) - goto isolate_fail; - /* * Be careful not to clear PageLRU until after we're * sure the page is not being freed elsewhere -- the @@ -971,6 +968,9 @@ isolate_migratepages_block(struct compac if (unlikely(!get_page_unless_zero(page))) goto isolate_fail; + if (__isolate_lru_page_prepare(page, isolate_mode) != 0) + goto isolate_fail_put; + /* Try isolate the page */ if (!TestClearPageLRU(page)) goto isolate_fail_put;