Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1346132ybp; Thu, 17 Oct 2019 11:23:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwF/nJQhxWUBMpZv1aHe9rrugIz1EnuXZsUFiGieGHLIEjDNcoiO+Pz0fHouw6scoakmpk X-Received: by 2002:a17:906:fcce:: with SMTP id qx14mr4977863ejb.186.1571336583032; Thu, 17 Oct 2019 11:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571336583; cv=none; d=google.com; s=arc-20160816; b=GrXFPyywEy1MzimqDMBCsqGUcYAw3b6Vzk7YLsLJynV9Dt2//M1xQF+eNo5oYeX+rT kZIsSaU6cHITczh/eN607jt5qbxe2pDFDWdb/tQ+j7QN0eIRVfHRHxEn8LJidhupEsrk IRGPScttvNFSgpozpfXgGIOQVDWePzNjWXjwptxmg00Aua2bThUiWmecO5VYYG1yc6oQ zy65664P8rjGLTy27FnXAfREPElDa31ZRve9FJP3vogeZfTz76bfGtvhOnzMZ3VU7Eof ukUEnYq2mg5ye900aNa9kvQV1QTm2lVccyc+jijyldHQBmSuNcR1TtLBrLo2RvXUaJGz jwXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1IAs/DBouw9lVrIS+Dl4eCqJnrBsrrTZ0VW90hmeJPA=; b=v2CPzZfw/jR6iwXq96Lq4opUY28/bNp6fji5EP1Z9nFaKvctT+TIjjoo+KvIoRJzKF dOj6OIiyTq4t0l6E8Th7HIf7g+PeErnn5vxFqYkzWHpzSFUD4qsPFiz7ip7c2Sd0eBvn 7+EGJ8alxUGT/mA+7f2q91UwBEWNrmCQW3vz0aJxD7TYXkygrdorer5zl1jybv125pte tUh8C8VNQ6zUS2DIbdjO126/f/VtJF7+8f9spryS17Jgi2dr24bRLW4aKPPK7EJ1Ou/D SlDrrqb9mS4szoyfEarBCvFNY/TPrN5CsPe1yBm2FLIZJqIPj4kTrTAMelhFfI8hd8Kh OJDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GGZwQXdS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g21si1867160ejk.23.2019.10.17.11.22.40; Thu, 17 Oct 2019 11:23:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GGZwQXdS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438945AbfJPWBF (ORCPT + 99 others); Wed, 16 Oct 2019 18:01:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:55050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438642AbfJPV7t (ORCPT ); Wed, 16 Oct 2019 17:59:49 -0400 Received: from localhost (unknown [192.55.54.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AA90A21D80; Wed, 16 Oct 2019 21:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263188; bh=QBtzNwCVrJp4cN4CQJnMzOVGUpLADOg3yzZ8Zb1kjw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GGZwQXdSVg0OaYgWMAt4W6+yLRyyQz++JlM4tA0aLuIFZYwJI48qkBK1ibw/td2lS ANvdodFWQxFAl8uGYPRbOv9UHPzkE0p1fN1HRpBo7jPuTnZjjabrdpFyGvoq6CVZuE YI7TDrsDNkn7ryvp57dBy3NNvqXaMUy0LvdXTD8k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Wool , Markus Linnala , Dan Streetman , Vlastimil Babka , Henry Burns , Shakeel Butt , Andrew Morton , Linus Torvalds Subject: [PATCH 5.3 076/112] mm/z3fold.c: claim page in the beginning of free Date: Wed, 16 Oct 2019 14:51:08 -0700 Message-Id: <20191016214904.150037983@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214844.038848564@linuxfoundation.org> References: <20191016214844.038848564@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vitaly Wool commit 5b6807de11445c05b537df8324f5d7ab1c2782f9 upstream. 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. [vitalywool@gmail.com: v2] Link: http://lkml.kernel.org/r/20190928113456.152742cf@bigdell Link: http://lkml.kernel.org/r/20190926104844.4f0c6efa1366b8f5741eaba9@gmail.com Signed-off-by: Vitaly Wool Reported-by: Markus Linnala Cc: Dan Streetman Cc: Vlastimil Babka Cc: Henry Burns Cc: Shakeel Butt Cc: Markus Linnala Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/z3fold.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -998,9 +998,11 @@ static void z3fold_free(struct z3fold_po 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_po * 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,13 +1046,15 @@ static void z3fold_free(struct z3fold_po 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_po 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); }