From patchwork Sat Sep 28 09:34:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Wool X-Patchwork-Id: 11165389 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 B06971599 for ; Sat, 28 Sep 2019 09:35:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 72A852075C for ; Sat, 28 Sep 2019 09:35:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TW7KPlSq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 72A852075C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 993E16B0003; Sat, 28 Sep 2019 05:35:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 96C356B0005; Sat, 28 Sep 2019 05:35:02 -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 859678E0001; Sat, 28 Sep 2019 05:35:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id 5F33D6B0003 for ; Sat, 28 Sep 2019 05:35:02 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id E54938243771 for ; Sat, 28 Sep 2019 09:35:01 +0000 (UTC) X-FDA: 75983820402.28.crown50_2bd7e4d22e923 X-Spam-Summary: 2,0,0,940b77339e69a1c6,d41d8cd98f00b204,vitalywool@gmail.com,::akpm@linux-foundation.org:linux-kernel@vger.kernel.org:markus.linnala@gmail.com:ddstreet@ieee.org:vbabka@suse.cz:stable@vger.kernel.org,RULES_HIT:41:355:379:541:800:960:965:966:973:988:989:1260:1277:1311:1313:1314:1345:1437:1515:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3874:4385:4390:4395:5007:6117:6261:6653:7514:7653:7903:8957:9413:10004:10400:10450:10455:11026:11658:11914:12043:12297:12438:12517:12519:12555:12760:12895:13161:13221:13229:13439:14096:14097:14181:14394:14659:14687:14721:14824:19904:19999:21080:21094:21323:21444:21451:21627:21666:21740:30054:30090:30091,0,RBL:209.85.167.68:@gmail.com:.lbl8.mailshell.net-62.18.175.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:26,LUA_S UMMARY:n X-HE-Tag: crown50_2bd7e4d22e923 X-Filterd-Recvd-Size: 5565 Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Sat, 28 Sep 2019 09:35:01 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id r22so3665882lfm.1 for ; Sat, 28 Sep 2019 02:35:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version :content-transfer-encoding; bh=sqzpIJTUSyMjvNLNtMpXjO9U+cAbapAxKF1UKLPlejs=; b=TW7KPlSqAa6wsClwUUOFxv1pU8gsHgaqMzCgLKlROwfWVCIOZI/H1Hd+e5H9ihsl2S 213aT5DDG6Dx+LzKxT83l3BQyPRmpPOEk0r9PTLDz1pxWx010Zkp3FWEydjxO0M60emn uXzE1ZIGNwm84dmDSwyvYl9tckI0DDrh7nqI6KrmJguW3EVMB6B2gHdY25J2Ym9A7Vt8 4hsfZ7s+jYwC2dwpDvxAX5kvPKuQGPzVSQtFWU7fH5jG/zkKomUd+kILFUsSyTWiBWue 6yA5hOEQ9e07M2IN5Req/JsvKAsjG/AKWxNg6F/hr/+OWUQ4nWXgbeDrT9dt69hayOnq S3Qw== 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:mime-version :content-transfer-encoding; bh=sqzpIJTUSyMjvNLNtMpXjO9U+cAbapAxKF1UKLPlejs=; b=ok0GkzUMG1uuP33DRH3iP1O74uWe0t64iKfLdOoxuHu49cFWY2C8ZReCOnEXfCmYil lr0w79EQDxooWgI4FP3iPh5uEs5X8OPyAHH4DidQglv1BSQ5OIYXjxfgJdTlXRI2VR+1 yu4XeVn6ul5Gq7CcW/yzI2/+lHy/2VShKDS3dpT/FnCmOW9YaLK4RtHXtuw2CA6IousN X8MPn2g7ZKLXeyY/yrtgkP3hlHCiVpUOENJxYzSd4eVkE7vAXEerBYmsrKtB2WYZvyDR fu3U984TZNunYHGf6Q2p5geauteKiCzf7O0PS0DInGvpYudUDGLdn0hHfxLlJ04uPOhZ jYvA== X-Gm-Message-State: APjAAAUpY+YzcLnj/nB1K9MChA881v89PQAVrhtEBrGHrkjLWZ7lda57 xnhog0XvRcvp6pAs/pwIzvgkiIqcb/k= X-Google-Smtp-Source: APXvYqwwuh1GjfIdsBSxb/r0rjF6N074kvqQ1/3Wn9VOkGtT9HtjiGXMAQChZMByZxxHrjibevm+Cg== X-Received: by 2002:a19:641e:: with SMTP id y30mr5789536lfb.148.1569663299262; Sat, 28 Sep 2019 02:34:59 -0700 (PDT) Received: from bigdell (2.69.152.136.mobile.tre.se. [2.69.152.136]) by smtp.gmail.com with ESMTPSA id m15sm1247655ljg.97.2019.09.28.02.34.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Sep 2019 02:34:59 -0700 (PDT) Date: Sat, 28 Sep 2019 11:34:56 +0200 From: Vitaly Wool To: Linux-MM , Andrew Morton Cc: linux-kernel@vger.kernel.org, Markus Linnala , Dan Streetman , Vlastimil Babka , Stable Subject: [PATCH v2] z3fold: claim page in the beginning of free Message-ID: <20190928113456.152742cf@bigdell> X-Mailer: Claws Mail 3.17.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 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: There's a really hard to reproduce race in z3fold between z3fold_free() and z3fold_reclaim_page(). z3fold_reclaim_page() can claim the page after z3fold_free() has checked if the page was claimed and z3fold_free() will then schedule this page for compaction which may in turn lead to random page faults (since that page would have been reclaimed by then). Fix that by claiming page in the beginning of z3fold_free() and not forgetting to clear the claim in the end. Reported-by: Markus Linnala Signed-off-by: Vitaly Wool Cc: --- mm/z3fold.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) spin_unlock(&pool->lock); @@ -1044,13 +1046,15 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) atomic64_dec(&pool->pages_nr); return; } - if (test_bit(PAGE_CLAIMED, &page->private)) { + if (page_claimed) { + /* the page has not been claimed by us */ z3fold_page_unlock(zhdr); return; } if (unlikely(PageIsolated(page)) || test_and_set_bit(NEEDS_COMPACTING, &page->private)) { z3fold_page_unlock(zhdr); + clear_bit(PAGE_CLAIMED, &page->private); return; } if (zhdr->cpu < 0 || !cpu_online(zhdr->cpu)) { @@ -1060,10 +1064,12 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) zhdr->cpu = -1; kref_get(&zhdr->refcount); do_compact_page(zhdr, true); + clear_bit(PAGE_CLAIMED, &page->private); return; } kref_get(&zhdr->refcount); queue_work_on(zhdr->cpu, pool->compact_wq, &zhdr->work); + clear_bit(PAGE_CLAIMED, &page->private); z3fold_page_unlock(zhdr); } diff --git a/mm/z3fold.c b/mm/z3fold.c index 05bdf90646e7..6d3d3f698ebb 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -998,9 +998,11 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) struct z3fold_header *zhdr; struct page *page; enum buddy bud; + bool page_claimed; zhdr = handle_to_z3fold_header(handle); page = virt_to_page(zhdr); + page_claimed = test_and_set_bit(PAGE_CLAIMED, &page->private); if (test_bit(PAGE_HEADLESS, &page->private)) { /* if a headless page is under reclaim, just leave. @@ -1008,7 +1010,7 @@ static void z3fold_free(struct z3fold_pool *pool, unsigned long handle) * has not been set before, we release this page * immediately so we don't care about its value any more. */ - if (!test_and_set_bit(PAGE_CLAIMED, &page->private)) { + if (!page_claimed) { spin_lock(&pool->lock); list_del(&page->lru);