From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C7F2C433F5 for ; Thu, 30 Sep 2021 00:41:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ACB0061507 for ; Thu, 30 Sep 2021 00:41:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org ACB0061507 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3F93F940076; Wed, 29 Sep 2021 20:41:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 359C194003A; Wed, 29 Sep 2021 20:41:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24861940076; Wed, 29 Sep 2021 20:41:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0147.hostedemail.com [216.40.44.147]) by kanga.kvack.org (Postfix) with ESMTP id 0CA8C94003A for ; Wed, 29 Sep 2021 20:41:57 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CBB5A39F45 for ; Thu, 30 Sep 2021 00:41:56 +0000 (UTC) X-FDA: 78642387432.22.4385D4D Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf29.hostedemail.com (Postfix) with ESMTP id 71619900026B for ; Thu, 30 Sep 2021 00:41:56 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 98448615E1 for ; Thu, 30 Sep 2021 00:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632962515; bh=PzetvSIBH0nHpjCfkosGz8w0xF2AGOfvYn0PYl9uTnA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tHvGnAUf2p03b4VuiJlJfEM+cqdXsba27y9R93f4IpUYRSkbLucFCoC9EPQCA81sy oe6z4UkdAJMLpSJV8fLHNExXRrNozxgkA2WouD9CbJjHYyfJxh9DHj7dvLmrzdb2Lp kt2+H+IDJ0er4JQ/Jw5JblySNWGW1m00bwLXSsoOMSwlJIVt6iEzJ1Yo6CbRr+96Oc zfi8yWT4clw0Zl6t696CARtj4As/eWMBpcf86/LMty9qE1xGUNU+iVgkLq0Ej7vemh AKjSTIgiYe4vOZ7xquPcFGNYQoujqZw1q+OZoDCpAzYkhKiWYmB4XOTU8hJASdO+0Y 7CZqIaglHXUVg== Received: by mail-lf1-f41.google.com with SMTP id b15so17867845lfe.7 for ; Wed, 29 Sep 2021 17:41:55 -0700 (PDT) X-Gm-Message-State: AOAM530ABwcFG2+dNceE5M4uRi9hezJAZhU5nYwkWMPvpvU7esxLOsHP U2gopAXTwWq7hykoej/qi7K3F1enDAQ4MpgXk2k= X-Google-Smtp-Source: ABdhPJyU9LE9+AHlG14cUPmwptUw4qZfXBv+4L08C0l2TA+wwHe38NDg2yVT4ofzU924KGEOpJ5pkWYk5EglNPXQuy0= X-Received: by 2002:ac2:5617:: with SMTP id v23mr2775768lfd.114.1632962513928; Wed, 29 Sep 2021 17:41:53 -0700 (PDT) MIME-Version: 1.0 References: <20210923194343.ca0f29e1c4d361170343a6f2@linux-foundation.org> <9e41661d-9919-d556-8c49-610dae157553@linux.alibaba.com> <68737431-01d2-e6e3-5131-7d7c731e49ae@linux.alibaba.com> In-Reply-To: From: Song Liu Date: Wed, 29 Sep 2021 17:41:42 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] mm, thp: check page mapping when truncating page cache To: Matthew Wilcox Cc: Rongwei Wang , Andrew Morton , Linux MM , Linux Kernel Mailing List , William Kucharski , Hugh Dickins Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 71619900026B X-Stat-Signature: 7d5r7zf4dasafwkkpc1rmg4os37957n1 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tHvGnAUf; spf=pass (imf29.hostedemail.com: domain of song@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=song@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1632962516-430128 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: On Wed, Sep 29, 2021 at 5:02 PM Matthew Wilcox wrote: > > On Wed, Sep 29, 2021 at 04:41:48PM -0700, Song Liu wrote: > > The issue is NOT caused by concurrent khugepaged:collapse_file() and > > truncate_pagecache(inode, 0). With some printks, we can see a clear > > time gap (>2 second ) between collapse_file() finishes, and > > truncate_pagecache() (which crashes soon). Therefore, my earlier > > suggestion that adds deny_write_access() to collapse_file() does NOT > > work. > > > > The crash is actually caused by concurrent truncate_pagecache(inode, 0). > > If I change the number of write thread in stress_madvise_dso.c to one, > > (IOW, one thread_read and one thread_write), I cannot reproduce the > > crash anymore. > > > > I think this means we cannot fix this issue in collapse_file(), because it > > finishes long before the crash. > > Ah! So are we missing one or more of these locks: > > inode_lock(inode); > filemap_invalidate_lock(mapping); > > in the open path? The following fixes the crash in my test. But I am not sure whether this is the best fix. Rongwei, could you please run more tests on it? Thanks, Song diff --git i/fs/open.c w/fs/open.c index daa324606a41f..d13c4668b2e53 100644 --- i/fs/open.c +++ w/fs/open.c @@ -856,8 +856,11 @@ static int do_dentry_open(struct file *f, * of THPs into the page cache will fail. */ smp_mb(); - if (filemap_nr_thps(inode->i_mapping)) + if (filemap_nr_thps(inode->i_mapping)) { + filemap_invalidate_lock(inode->i_mapping); truncate_pagecache(inode, 0); + filemap_invalidate_unlock(inode->i_mapping); + } } return 0;