From patchwork Thu Sep 26 08:48:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Wool X-Patchwork-Id: 11161979 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 80A0C13B1 for ; Thu, 26 Sep 2019 08:48:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4729B222BE for ; Thu, 26 Sep 2019 08:48:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AWYQiVhm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4729B222BE 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 41BA96B0006; Thu, 26 Sep 2019 04:48:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3A4796B0008; Thu, 26 Sep 2019 04:48:49 -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 2452C6B000A; Thu, 26 Sep 2019 04:48:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id F03426B0006 for ; Thu, 26 Sep 2019 04:48:48 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 9238D180AD802 for ; Thu, 26 Sep 2019 08:48:48 +0000 (UTC) X-FDA: 75976446336.26.crack72_69f7091539e2b X-Spam-Summary: 2,0,0,17d633e916b1a3a2,d41d8cd98f00b204,vitalywool@gmail.com,::linux-kernel@vger.kernel.org:akpm@linux-foundation.org:markus.linnala@gmail.com:stable@kernel.org:ddstreet@ieee.org:vbabka@suse.cz,RULES_HIT:41:355:379:541:800:960:965:966:973:988:989:1260:1277:1311:1313:1314:1345:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3874:4321:4385:4390:4395:5007:6117:6261:6653:7514:7903:9413:10004:10400:10450:10455:11026:11658:11914:12043:12297:12438:12517:12519:12555:12760:12895:12986:13069:13161:13221:13229:13311:13357:13439:14096:14097:14181:14394:14659:14687:14721:14824:19904:19999:21080:21094:21323:21444:21451:21627:21666:30054:30090:30091,0,RBL:209.85.167.65:@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:24,LUA_SUM MARY:non X-HE-Tag: crack72_69f7091539e2b X-Filterd-Recvd-Size: 4780 Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Sep 2019 08:48:48 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id r22so1089639lfm.1 for ; Thu, 26 Sep 2019 01:48:47 -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=VXH3Ua8oN6gJFR5T3GpYv9HdGvkWILtcOQDXfdZ+hho=; b=AWYQiVhmU49sBPZnlWVKUJLtD5J5kkDajluEr8cbxdB7n8QKDQV1snnf9VCQNxWf++ 8/71iNzmhwEf8m8tEVAIQ6p+8GOqd2m5n8xkYNrrlM+AiNDOI0LSIZiCDx2aTMAe359h Gt7gmb/K/B+/EcOTJDPWh5//R9rBQulHY2hpe2ppcUjaP8NfKEHQKyTZQ397ACmfOJh3 4dFhTA0hqxLVIhWCcqrYlv5XiN9ZkWQxN4GuWciVIVg9UIkSBZ9KHd7S/iPapzVSwk/b 1WJAf2wsB73RosaSF5VPUc8hDm7Y+jaed1XCEDpl1KPTi0g++DzFCvV3nEBvvBIOkBbU NNmA== 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=VXH3Ua8oN6gJFR5T3GpYv9HdGvkWILtcOQDXfdZ+hho=; b=DIBMRrXQ6jdicT1yq9C+8QApjzRvugP3vjMyWerX08dU8Pl25XiXrmZD/FFJp6Q4pq Zm/dz6jVp0YC3Y6O+W7F34NJGK3codNpG4xwo2DXriFKKCNX2BgjJV+kLLpz+XtbJXIQ aGnIvxf+Lg83BM/22kteba3wi6p6+ItbLU2MFi/wGNczOEUQDrwvN9pELaJCA6tEEVF6 XRNz7BYFmWABe1Ru0CoxkBcA+oyKUtxKKlcuookzpRI9Gnre+WxuQBY/DNSCbKz+KvQI c/I6YX3Fc3LewG4bAwI29Wk7wOWZjQigpovXSz/Tv8DgIdVqhNjAnGVF5KK8O6TRlLv+ SZYQ== X-Gm-Message-State: APjAAAUKMM0Ev2LM6cAva48g4nWCjG5PSJR/J6KQ+s8vahtPWdepLI6u BQJmW4mCXTTp5w4x94n/edCwHL+JTts= X-Google-Smtp-Source: APXvYqz5ZssKzszNAZn1K3Xua7hwoz9w1G7LyD7AicTX0rheTwnzMtbinDXbqBwmudxqjb2WUvH/9w== X-Received: by 2002:a19:f817:: with SMTP id a23mr1430709lff.18.1569487726227; Thu, 26 Sep 2019 01:48:46 -0700 (PDT) Received: from seldlx21914.corpusers.net ([37.139.156.40]) by smtp.gmail.com with ESMTPSA id g21sm362202lje.67.2019.09.26.01.48.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Sep 2019 01:48:45 -0700 (PDT) Date: Thu, 26 Sep 2019 10:48:44 +0200 From: Vitaly Wool To: Linux-MM , linux-kernel@vger.kernel.org Cc: Andrew Morton , Markus Linnala , stable@kernel.org, Dan Streetman , Vlastimil Babka Subject: [PATCH] z3fold: claim page in the beginning of free Message-Id: <20190926104844.4f0c6efa1366b8f5741eaba9@gmail.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; x86_64-unknown-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(). Reported-by: Markus Linnala Signed-off-by: Vitaly Wool --- mm/z3fold.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index 05bdf90646e7..01b87c78b984 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); spin_unlock(&pool->lock); @@ -1044,7 +1046,7 @@ 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) { z3fold_page_unlock(zhdr); return; }