From patchwork Thu Dec 9 07:19:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12665957 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF298C433F5 for ; Thu, 9 Dec 2021 07:19:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1589D6B0071; Thu, 9 Dec 2021 02:19:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 109496B0073; Thu, 9 Dec 2021 02:19:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3A936B0074; Thu, 9 Dec 2021 02:19:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0171.hostedemail.com [216.40.44.171]) by kanga.kvack.org (Postfix) with ESMTP id E56426B0071 for ; Thu, 9 Dec 2021 02:19:32 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A258A89545 for ; Thu, 9 Dec 2021 07:19:22 +0000 (UTC) X-FDA: 78897404964.21.A11E305 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by imf23.hostedemail.com (Postfix) with ESMTP id 6B528140002 for ; Thu, 9 Dec 2021 07:19:21 +0000 (UTC) Received: by mail-qt1-f174.google.com with SMTP id o17so4539578qtk.1 for ; Wed, 08 Dec 2021 23:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version; bh=wp7bsIiEGq1v0UzZDarToFJILpj4ru1SGwyQaMb3p4E=; b=n+ugZQ1C7dMkoFU9ez645n+AJqXmFaYJgGVuTfIepCmJyDDnCohuhijGr9jGafo/wy ke5ok+6E3zz7kA5TnbpKDDfzpnH1mUlESdrcsPQX3rQ/5EWkuzqbXbOcU7kKOUckIgth O3HHcGIovw7KB4FOWO0jiUkVl5qccjHYAntQnRbxWffMfENTLHdEbWcJPbTowO9D36lh 64hdvosY2W7EEQR7dNWhu7EJiIi92GFTNn8C83HMjh4dkXwoXA66KkTp40tVE3kupDAq JMqxYPzhj9IyRHZAsGhQpuTwy2HT4CE1oPWh6CbJnqiZk+a9EqxqpKmrpdtx6oHOyez0 QR3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version; bh=wp7bsIiEGq1v0UzZDarToFJILpj4ru1SGwyQaMb3p4E=; b=sEEjcnOJQvkWVAwaNYy4ybQr0E3bwTifHIxmpTeepqO+5sans7TipyP8iuBw06/ZPH cbdHFr6CEbX/egVYpEeduqZlih81vQY0r/Rvgoun/YBXbyIevtq7LbOzxuANoE9lodH1 ULiJgnLtLSI3ket60pzW408MJEzRJY5giQtAbF0m4hP6e5c/faflKX/J2WJbRHKVMUYA s8tNLE6p57AxFbjDWn5fLJ6ufhtLc0CdmYsod7U/C8/t7izCguXtOH9ohXkZHRanN7KT Su1Povqgb/WSoNxTboW0TuCDUh+clv8E60Qqo7PrPS2jk6z20OUjbpdZ1pmSB4OoNsCj 78BQ== X-Gm-Message-State: AOAM532kweWQHRw0kvikXM7yJr5U852AB6I/98fNsn9no2MTyVDnlWBl 4fCc2BBJTiWLVWvH0/wFEZoAMg== X-Google-Smtp-Source: ABdhPJyDk5gwcYkseNoR8GrR8PAhZjoMS9Xyrz93qdo0YVs5eDJPx98/mF7EChyYF/5No6CJchsA8g== X-Received: by 2002:ac8:580b:: with SMTP id g11mr14831442qtg.268.1639034361429; Wed, 08 Dec 2021 23:19:21 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id z4sm3382336qtj.42.2021.12.08.23.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 23:19:20 -0800 (PST) Date: Wed, 8 Dec 2021 23:19:18 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Matthew Wilcox cc: Andrew Morton , Vlastimil Babka , William Kucharski , Christoph Hellwig , "Kirill A. Shutemov" , Mike Rapoport , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mm: delete unsafe BUG from page_cache_add_speculative() Message-ID: <8b98fc6f-3439-8614-c3f3-945c659a1aba@google.com> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6B528140002 X-Stat-Signature: d1nyzp7i6zqo8x6dejqj1tdrjtxgh1qq Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=n+ugZQ1C; spf=pass (imf23.hostedemail.com: domain of hughd@google.com designates 209.85.160.174 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1639034361-719720 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: It is not easily reproducible, but on 5.16-rc I have several times hit the VM_BUG_ON_PAGE(PageTail(page), page) in page_cache_add_speculative(): usually from filemap_get_read_batch() for an ext4 read, yesterday from next_uptodate_page() from filemap_map_pages() for a shmem fault. That BUG used to be placed where page_ref_add_unless() had succeeded, but now it is placed before folio_ref_add_unless() is attempted: that is not safe, since it is only the acquired reference which makes the page safe from racing THP collapse or split. We could keep the BUG, checking PageTail only when folio_ref_try_add_rcu() has succeeded; but I don't think it adds much value - just delete it. Fixes: 020853b6f5ea ("mm: Add folio_try_get_rcu()") Signed-off-by: Hugh Dickins Acked-by: Kirill A. Shutemov Reviewed-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 1 - 1 file changed, 1 deletion(-) --- 5.16-rc4/include/linux/pagemap.h +++ linux/include/linux/pagemap.h @@ -285,7 +285,6 @@ static inline struct inode *folio_inode( static inline bool page_cache_add_speculative(struct page *page, int count) { - VM_BUG_ON_PAGE(PageTail(page), page); return folio_ref_try_add_rcu((struct folio *)page, count); }