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 X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FD22C433FE for ; Sat, 18 Sep 2021 00:07:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4B55A60F51 for ; Sat, 18 Sep 2021 00:07:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4B55A60F51 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 2B7606B0071; Fri, 17 Sep 2021 20:07:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 266A36B0072; Fri, 17 Sep 2021 20:07:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15549900002; Fri, 17 Sep 2021 20:07:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 0693D6B0071 for ; Fri, 17 Sep 2021 20:07:17 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A8EBA184900E8 for ; Sat, 18 Sep 2021 00:07:16 +0000 (UTC) X-FDA: 78598754472.34.5F003D0 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by imf09.hostedemail.com (Postfix) with ESMTP id 72F343000100 for ; Sat, 18 Sep 2021 00:07:16 +0000 (UTC) Received: by mail-ed1-f43.google.com with SMTP id v24so35884491eda.3 for ; Fri, 17 Sep 2021 17:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qCb02rFz7zrEJnzskA+LIE5W9dQmHkdeni2ADocJtPo=; b=O7/GDEztr/60U84WfYPkaOQcGWE3UdXreZuQ1YXIctUX7g1+zicIfj4dYCCTUA5fFB gQpMrt7FpMZJhi82EItITiVYbkNCsZ3pTVHm6h8D6FgrZ4B0dCU9Odw/b5B3tJA6nq/2 Oayy6hN5K5xcT/W4o7K3ef7QBTO32t/mDspATsEUcE8Oq3B+HBFow/ePSlVRgQ+zoGuc VUQVW0gu0H4cUbHYwMOWBYcoOHTRfi3G57Hubg5LK2KfKFI63zFzhWy34cD7ZRkLU7m+ tkTktg1ihwdp0beAVG10bTZighDXFmmH4tYe8ksi4orUY4r8cJelNUdjdZE1vm9d9KRN UbVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qCb02rFz7zrEJnzskA+LIE5W9dQmHkdeni2ADocJtPo=; b=IKNzQlo4QTJlo6gwmUt2SWW183OVcEpmHdxzP43jVfMo+xHeH/BPJi5UQ8PGIIDdtl 0DRzl8O1yf/lfsFAlyabSfmRHBuskg0j4M93+KR0tyflNUYqLJGxheUPTx0Oyr5kWF8b 8hdVb6zPMKqkwX9F+VTGe30GowA35YjFHf6pOtIEBECeWTVvhux3eIp+5OphD/VjwsJ3 f/18MMR3qPfOntG5kXdPQSTqiTtejEMAxdc9h36tpIWRz0tpFvrfcBnGCHsc1QD9PAYA OEbzEgoz3YEDdmlWZEfYkcsfZ+roHDiVNIiYac5YqDIrbvtKGPsAdhv1sjacNGO6aDyN WjBw== X-Gm-Message-State: AOAM533yQmB3s86nOGP32noii1BZNW5eun7A3n5R2FkeU64qF2xAHPd/ fEfUccbd8RRRKfbvb+njEldIky1azPdoBvOOKy0= X-Google-Smtp-Source: ABdhPJznflaA3g55kqFdCiBRdu8gODjPXte0QNfteEawuyjCIgDeO6ZmlayWZkYv4MboUWElfR1/90yh4yRwzZBQ7Nc= X-Received: by 2002:aa7:cd96:: with SMTP id x22mr15419773edv.46.1631923635126; Fri, 17 Sep 2021 17:07:15 -0700 (PDT) MIME-Version: 1.0 References: <20210917205731.262693-1-shy828301@gmail.com> In-Reply-To: <20210917205731.262693-1-shy828301@gmail.com> From: Yang Shi Date: Fri, 17 Sep 2021 17:07:03 -0700 Message-ID: Subject: Re: [PATCH] fs: buffer: check huge page size instead of single page for invalidatepage To: Matthew Wilcox , Hugh Dickins , cfijalkovich@google.com, song@kernel.org, Andrew Morton , Hao Sun Cc: Linux MM , Linux FS-devel Mailing List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 72F343000100 X-Stat-Signature: bs41qucrxhw89ckt7g8xxrwfsi8u3mxm Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="O7/GDEzt"; spf=pass (imf09.hostedemail.com: domain of shy828301@gmail.com designates 209.85.208.43 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1631923636-726653 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: Cc to the reporter. Sorry for missing Hao Sun in the first place. On Fri, Sep 17, 2021 at 1:57 PM Yang Shi wrote: > > Hao Sun reported the below BUG on v5.15-rc1 kernel: > > kernel BUG at fs/buffer.c:1510! > invalid opcode: 0000 [#1] PREEMPT SMP > CPU: 0 PID: 5 Comm: kworker/0:0 Not tainted 5.14.0+ #15 > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS > rel-1.12.0-59-gc9ba5276e321-prebuilt.qemu.org 04/01/2014 > Workqueue: events delayed_fput > RIP: 0010:block_invalidatepage+0x27f/0x2a0 -origin/fs/buffer.c:1510 > Code: ff ff e8 b4 07 d7 ff b9 02 00 00 00 be 02 00 00 00 4c 89 ff 48 > c7 c2 40 4e 25 84 e8 2b c2 c4 02 e9 c9 fe ff ff e8 91 07 d7 ff <0f> 0b > e8 8a 07 d7 ff 0f 0b e8 83 07 d7 ff 48 8d 5d ff e9 57 ff ff > RSP: 0018:ffffc9000065bb60 EFLAGS: 00010293 > RAX: 0000000000000000 RBX: ffffea0000670000 RCX: 0000000000000000 > RDX: ffff8880097fa240 RSI: ffffffff81608a9f RDI: ffffea0000670000 > RBP: ffffea0000670000 R08: 0000000000000001 R09: 0000000000000000 > R10: ffffc9000065b9f8 R11: 0000000000000003 R12: ffffffff81608820 > R13: ffffc9000065bc68 R14: 0000000000000000 R15: ffffc9000065bbf0 > FS: 0000000000000000(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: 00007f4aef93fb08 CR3: 0000000108cf2000 CR4: 0000000000750ef0 > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > PKRU: 55555554 > Call Trace: > do_invalidatepage -origin/mm/truncate.c:157 [inline] > truncate_cleanup_page+0x15c/0x280 -origin/mm/truncate.c:176 > truncate_inode_pages_range+0x169/0xc30 -origin/mm/truncate.c:325 > kill_bdev.isra.29+0x28/0x30 > blkdev_flush_mapping+0x4c/0x130 -origin/block/bdev.c:658 > blkdev_put_whole+0x54/0x60 -origin/block/bdev.c:689 > blkdev_put+0x6f/0x210 -origin/block/bdev.c:953 > blkdev_close+0x25/0x30 -origin/block/fops.c:459 > __fput+0xdf/0x380 -origin/fs/file_table.c:280 > delayed_fput+0x25/0x40 -origin/fs/file_table.c:308 > process_one_work+0x359/0x850 -origin/kernel/workqueue.c:2297 > worker_thread+0x41/0x4d0 -origin/kernel/workqueue.c:2444 > kthread+0x178/0x1b0 -origin/kernel/kthread.c:319 > ret_from_fork+0x1f/0x30 -origin/arch/x86/entry/entry_64.S:295 > Modules linked in: > Dumping ftrace buffer: > (ftrace buffer empty) > ---[ end trace 9dbb8f58f2109f10 ]--- > RIP: 0010:block_invalidatepage+0x27f/0x2a0 -origin/fs/buffer.c:1510 > Code: ff ff e8 b4 07 d7 ff b9 02 00 00 00 be 02 00 00 00 4c 89 ff 48 > c7 c2 40 4e 25 84 e8 2b c2 c4 02 e9 c9 fe ff ff e8 91 07 d7 ff <0f> 0b > e8 8a 07 d7 ff 0f 0b e8 83 07 d7 ff 48 8d 5d ff e9 57 ff ff > RSP: 0018:ffffc9000065bb60 EFLAGS: 00010293 > RAX: 0000000000000000 RBX: ffffea0000670000 RCX: 0000000000000000 > RDX: ffff8880097fa240 RSI: ffffffff81608a9f RDI: ffffea0000670000 > RBP: ffffea0000670000 R08: 0000000000000001 R09: 0000000000000000 > R10: ffffc9000065b9f8 R11: 0000000000000003 R12: ffffffff81608820 > R13: ffffc9000065bc68 R14: 0000000000000000 R15: ffffc9000065bbf0 > FS: 0000000000000000(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: 00007ff98674f000 CR3: 0000000106b2e000 CR4: 0000000000750ef0 > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > PKRU: 55555554 > > The debugging showed the page passed to invalidatepage is a huge page > and the length is the size of huge page instead of single page due to > read only FS THP support. But block_invalidatepage() would throw BUG if > the size is greater than single page. > > However there is actually a bigger problem in invalidatepage(). All the > implementations are *NOT* THP aware and hardcoded PAGE_SIZE. Some triggers > BUG(), like block_invalidatepage(), some just returns error if length is > greater than PAGE_SIZE. > > Converting PAGE_SIZE to thp_size() actually is not enough since the actual > invalidation part just assumes single page is passed in. Since other subpages > may have private too because PG_private is per subpage so there may be > multiple subpages have private. This may prevent the THP from splitting > and reclaiming since the extra refcount pins from private of subpages. > > The complete fix seems not trivial and involve how to deal with huge > page in page cache. So the scope of this patch is limited to close the > BUG at the moment. > > Fixes: eb6ecbed0aa2 ("mm, thp: relax the VM_DENYWRITE constraint on file-backed THPs") > Reported-by: Hao Sun > Tested-by: Hao Sun > Cc: > Signed-off-by: Yang Shi > --- > fs/buffer.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/buffer.c b/fs/buffer.c > index ab7573d72dd7..4bcb54c4d1be 100644 > --- a/fs/buffer.c > +++ b/fs/buffer.c > @@ -1507,7 +1507,7 @@ void block_invalidatepage(struct page *page, unsigned int offset, > /* > * Check for overflow > */ > - BUG_ON(stop > PAGE_SIZE || stop < length); > + BUG_ON(stop > thp_size(page) || stop < length); > > head = page_buffers(page); > bh = head; > @@ -1535,7 +1535,7 @@ void block_invalidatepage(struct page *page, unsigned int offset, > * The get_block cached value has been unconditionally invalidated, > * so real IO is not possible anymore. > */ > - if (length == PAGE_SIZE) > + if (length >= PAGE_SIZE) > try_to_release_page(page, 0); > out: > return; > -- > 2.26.2 >