From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CF16247291 for ; Sat, 1 Aug 2026 22:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785621672; cv=none; b=GCqJh/hrkUrkHR7vAZ/62rZlThQSjCCz8aa9+jH1Hero8w+R2m7frcEG7el/DdszTRX3NPw4a7ttUKZ34siAyGBkToOlISbjykOddojXzIexNh6heDGKeP+6k/AtCuRetZ4kN8nXg7FHAlsgPKSsIBKFojeURKmmv3pYC9Ns0c0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785621672; c=relaxed/simple; bh=dHCSXwhqSp5ZYzPgeTI83J3l93w1hXqXrOBDQtAfTkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UdhNpLeUlyDAnhR0vtXX/FrIPpNdWlxdRL2FzlT/O2WKVlQXkK5qNfNbLBAU7JDcjwgBAKaUi6P008G/SyKdEPlEfEEeqC8fDqQtef1s9wK/rNbovnqlixLRpKoP3YxnABPTFgMieyYoZ20ZnXkfMp19leTZ47ZLjwG3yu9bGOw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=rr/zyvdC; arc=none smtp.client-ip=209.85.128.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rr/zyvdC" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-81f36179dd5so30874267b3.2 for ; Sat, 01 Aug 2026 15:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785621670; x=1786226470; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=R/+4h8mFnc0QJGTHkSaUWdLQ44MjYcXD2X7Z3kRsV/c=; b=rr/zyvdCTTUD1h2ADJZFQyniubg/ygk1iHIqyBK4nLEnXoBsBusjzCjmNNhXFvB970 SjkpNJH6ZyKgVLdYEF1589AEsQsXJswezNwrHN4q+2S8xQsq9rHhEc8oA3DmCWFJVpwT 4I7bj9n9FgdU12Ud/vUks/qJwfM+2z2CAu3R3Tjh4loeZEWPkaAfz8DYGFS5Tn2VHFUw IVTqQxvgHU4CnJBcIgMjWXbfNe7sEzxBenigQ4xeBk7WfNdB46emCGxrlTfzAkYb4HA+ 1Kl/VtmbuVZ0DxFuJQzHKIgcD+4dkHXcykF69jid98GhvtXVNpoxHxepa7nmc10XyMiT fc2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785621670; x=1786226470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=R/+4h8mFnc0QJGTHkSaUWdLQ44MjYcXD2X7Z3kRsV/c=; b=I4l6MTfCkD/NuOjQMxhDrudD1Kef5JHneNzRErJHzGlsz2bse60/J413KT7Oq9btP/ 0Zoj/M382HjT6qRnY/9Iwb65Tz4JHj0iVHXkT9gIIzeeFi+S26j+o2CYeJ++5+zIT1B1 OzZfnC7XPBFVP9YqCyrarxa5bXqdAo+o2zu/hq3vAPiKGWZAq20NSVbhHOvuUbmzi5zF cb+uzSrE/OHzbG7Yzf+Kpzsi2xgL1eA4llLCeFdytLG/DuzrDFg6OC3l7AIrzagIINBQ ZhxadtunRTAiFQnRhPyaoJdB0eyh4LOaQ2LMd6koZJid8qCES6wdzoJ0c5qO5TMJPIsn ZKWw== X-Forwarded-Encrypted: i=1; AHgh+RqDoGDpWV/D4LwWvckUAQg85indyFYy6O+AI5jK+hglQZfZk6JgkBggS7ahyGRwP9KoHJur63ljuVXjwnI=@vger.kernel.org X-Gm-Message-State: AOJu0YzfEmGWa7xp8GWoNTa7Z2LSXTvZLu2R3MtdO2bN2KIQfCEuXwSm EgNFX5cpVp87AI1p9vzOOQFEqFQHoNEotRuCxgFYfU1P2dETfy+ae5IP X-Gm-Gg: AR+sD1024Fp0YwdtJYz56brasJCsrSKeqKgh4dSn32Wfa7MvGRkSo9D5wkt/PTpbl4r zvlHyS8BjNwT2aesCGZc0P9GNl7uJakHsQgX7zOFXQYlgxNdP3QLvH4xpN99Y4lvIkkpqEW/u98 JOUgVbAdX5oI92xqGc57U42Q5PMWQCNBShhxttqsz6+BRC2y2iaXIsrWyIu+KtoRYPp9nwBGZ0r IMLTMZAYy9ZPJjURL70qua3la17HnDWe3iPGA+wPCkICZ1H9HFwML0jtKZIxmo4JY7I08xpm2PB ZJJyphZapizTBF5etWmb/N/quSVY+xAk3gw/O9Ub4DhcEjUiLiq/EqYVUWCiqnbRppIAY8e1B21 DUX7fkuO0a4RSgBiTY/ub9azH+roRu3hAxpLcfqWdhetGmxv7/EmH9DEzodsd3XuHUn021EImga sxZX1JYqn7RAMulicvweqhFfA6T1FpGMvBifCu6Dxg18JMvKA/Pjfl0FssPtReNYZp+G0fLGLsx Rafo6OZ9clmZYmCqn5AGO8c2zz+Ew== X-Received: by 2002:a05:690c:6203:b0:80d:c2cc:f673 with SMTP id 00721157ae682-81fd4b72857mr77020067b3.20.1785621669974; Sat, 01 Aug 2026 15:01:09 -0700 (PDT) Received: from syssplab.cs.fiu.edu (nat1.cs.fiu.edu. [131.94.134.89]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81fcd0d6fbbsm29903767b3.25.2026.08.01.15.01.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2026 15:01:09 -0700 (PDT) From: Chao Shi To: Jan Kara , Christian Brauner , Alexander Viro , Matthew Wilcox , linux-fsdevel@vger.kernel.org Cc: Theodore Ts'o , Andreas Dilger , Baokun Li , Ojaswin Mujoo , Ritesh Harjani , Zhang Yi , Bob Copeland , Namjae Jeon , Sungjong Seo , Yuezhang Mo , OGAWA Hirofumi , Mark Fasheh , Joel Becker , Joseph Qi , Andreas Gruenbacher , linux-ext4@vger.kernel.org, ocfs2-devel@lists.linux.dev, gfs2@lists.linux.dev, linux-karma-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Shi Subject: [PATCH 02/19] buffer: allow a buffer_head to point at memory outside the page cache Date: Sat, 1 Aug 2026 18:00:46 -0400 Message-ID: <41c6fee66724e374d4682124a1eb80041e22efb9.1785621505.git.coshi036@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit jbd2 builds a temporary buffer_head to write out the frozen copy of a metadata block, and that copy lives in slab memory. Today jbd2 points the temporary buffer at the slab folio backing it. A slab folio's ->mapping is not an address_space, so anything that follows bh->b_folio->mapping there gets garbage rather than NULL; mark_buffer_write_io_error() does exactly that, and we are about to start calling it on this buffer. Rather than teach every such helper about slab folios, allow bh->b_folio to be NULL and let b_data point straight at the memory. Code that needs the folio has to check. There are two places in this file: - __bh_submit() adds the data by virtual address using bio_add_virt_nofail(), and skips the cgroup accounting: a buffer that is not in the page cache has no owning folio to attribute writeback to. - buffer_set_crypto_ctx() returns early. fscrypt has no interest in a buffer that is not part of a file mapping, which is why it already returns when folio_mapping() comes back NULL. Nothing sets b_folio to NULL yet, so this patch is a no-op on its own. This is deliberately not a general capability. Buffers over highmem have no permanent kernel virtual address, which is why folio_set_bh() records a folio and an offset instead of an address. A folio-less buffer_head is only valid over memory that is always mapped, and must not be passed to bh_offset(). Suggested-by: Matthew Wilcox (Oracle) Signed-off-by: Chao Shi --- fs/buffer.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index be8b57a635cd..04fcc34e4fa6 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -1099,12 +1099,16 @@ EXPORT_SYMBOL(__bforget); static void buffer_set_crypto_ctx(struct bio *bio, const struct buffer_head *bh, gfp_t gfp_mask) { - const struct address_space *mapping = folio_mapping(bh->b_folio); + const struct address_space *mapping; /* * The ext4 journal (jbd2) can submit a buffer_head it directly created - * for a non-pagecache page. fscrypt doesn't care about these. + * for memory that is not in the page cache at all. fscrypt doesn't + * care about these. */ + if (!bh->b_folio) + return; + mapping = folio_mapping(bh->b_folio); if (!mapping) return; fscrypt_set_bio_crypt_ctx(bio, mapping->host, @@ -1142,7 +1146,11 @@ static void __bh_submit(struct buffer_head *bh, blk_opf_t opf, bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9); bio->bi_write_hint = write_hint; - bio_add_folio_nofail(bio, bh->b_folio, bh->b_size, bh_offset(bh)); + if (bh->b_folio) + bio_add_folio_nofail(bio, bh->b_folio, bh->b_size, + bh_offset(bh)); + else + bio_add_virt_nofail(bio, bh->b_data, bh->b_size); bio->bi_end_io = end_bio; bio->bi_private = bh; @@ -1152,7 +1160,8 @@ static void __bh_submit(struct buffer_head *bh, blk_opf_t opf, if (wbc) { wbc_init_bio(wbc, bio); - wbc_account_cgroup_owner(wbc, bh->b_folio, bh->b_size); + if (bh->b_folio) + wbc_account_cgroup_owner(wbc, bh->b_folio, bh->b_size); } blk_crypto_submit_bio(bio); -- 2.43.0