Linux filesystem development
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Jan Kara <jack@suse.cz>
Cc: Chao Shi <coshi036@gmail.com>,
	Christian Brauner <brauner@kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org, Theodore Ts'o <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Baokun Li <libaokun@linux.alibaba.com>,
	Ojaswin Mujoo <ojaswin@linux.ibm.com>,
	Ritesh Harjani <ritesh.list@gmail.com>,
	Zhang Yi <yi.zhang@huawei.com>, Bob Copeland <me@bobcopeland.com>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Sungjong Seo <sj1557.seo@samsung.com>,
	Yuezhang Mo <yuezhang.mo@sony.com>,
	OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
	Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
	Joseph Qi <joseph.qi@linux.alibaba.com>,
	Andreas Gruenbacher <agruenba@redhat.com>,
	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
Subject: Re: [PATCH 02/19] buffer: allow a buffer_head to point at memory outside the page cache
Date: Tue, 4 Aug 2026 15:07:00 +0100	[thread overview]
Message-ID: <anHyBATDe8yQEFNi@casper.infradead.org> (raw)
In-Reply-To: <74ts4lwsq73mce3rvc7imisot436742ykzahnogysnbklot45b@q3nhfq55knx3>

On Tue, Aug 04, 2026 at 10:07:39AM +0200, Jan Kara wrote:
> > Yes, agreed.  I think it's fine to add in some 'if (!bh->b_folio)'
> > tests, but only where they're needed for the occasional consumer.  This
> > really is a rare (but legitimate) case.
> 
> Yes. If we were to write this code from scratch, I'd rather push for
> forming and submitting the bio directly instead of trying to bend the bh
> layer for these temporary bhs. Eventually we might want to do this cleanup
> anyway (since bhs don't really buy us much in this path) but not in this
> patch set.

I think that would be better, but it is out of scope.

> > > >  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;
> > 
> > Do we want to call folio_mapping() here?  The only case where I can see
> > this being useful is if we attach a buffer_head to an anonymous folio,
> > and I don't see a good reason to do that.  I think this can just be
> > 
> > 	mapping = bh->b_folio->mapping;
> 
> For all I know yes, bh->b_folio->mapping should be enough here. But I
> thought folio_mapping() is kind of preferred to open-coding?

It rather depends on the path we're talking about.  Looking at the
implementation of folio_mapping(), it's actually mildly dangerous
to call folio_mapping() in this path.  If we were ever to point a
buffer_head at some memory on a page in swap cache, we'd get a pointer
to a swap_address_space.  I think we'd safely crash in that case because
mapping->host would be NULL, but in other contexts doing things to a
swap mapping would be quite bad.

So I think this should just be folio->mapping; don't risk getting a
pointer to a swap mapping.

  reply	other threads:[~2026-08-04 14:07 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-01 22:00 [PATCH 00/19] buffer: stop clearing BH_Uptodate when a write fails Chao Shi
2026-08-01 22:00 ` [PATCH 01/19] buffer_head: Remove b_page Chao Shi
2026-08-03 16:03   ` Jan Kara
2026-08-01 22:00 ` [PATCH 02/19] buffer: allow a buffer_head to point at memory outside the page cache Chao Shi
2026-08-03 16:13   ` Jan Kara
2026-08-03 17:59     ` Matthew Wilcox
2026-08-04  8:07       ` Jan Kara
2026-08-04 14:07         ` Matthew Wilcox [this message]
2026-08-01 22:00 ` [PATCH 03/19] jbd2: point the shadow buffer at the frozen data directly Chao Shi
2026-08-03 18:11   ` Matthew Wilcox
2026-08-04  3:11     ` Matthew Wilcox
2026-08-04  8:28   ` Jan Kara
2026-08-01 22:00 ` [PATCH 04/19] buffer: clear BH_Write_EIO when a buffer is forgotten Chao Shi
2026-08-04  8:29   ` Jan Kara
2026-08-01 22:00 ` [PATCH 05/19] buffer: discard BH_Write_EIO along with the rest of the buffer state Chao Shi
2026-08-04  8:29   ` Jan Kara
2026-08-01 22:00 ` [PATCH 06/19] buffer: detect metadata write errors with buffer_write_io_error() Chao Shi
2026-08-04  8:30   ` Jan Kara
2026-08-01 22:00 ` [PATCH 07/19] adfs: check for a directory write error " Chao Shi
2026-08-01 22:00 ` [PATCH 08/19] ext2: check for an xattr block " Chao Shi
2026-08-04  8:40   ` Jan Kara
2026-08-01 22:00 ` [PATCH 09/19] omfs: check for an inode " Chao Shi
2026-08-01 22:00 ` [PATCH 10/19] exfat: check for a directory " Chao Shi
2026-08-01 22:00 ` [PATCH 11/19] fat: check for a metadata " Chao Shi
2026-08-01 22:00 ` [PATCH 12/19] ext4: " Chao Shi
2026-08-04  8:41   ` Jan Kara
2026-08-01 22:00 ` [PATCH 13/19] ocfs2: " Chao Shi
2026-08-04  8:49   ` Jan Kara
2026-08-01 22:00 ` [PATCH 14/19] ocfs2: check for a stale write error before reusing a metadata buffer Chao Shi
2026-08-04  8:50   ` Jan Kara
2026-08-01 22:00 ` [PATCH 15/19] gfs2: check for a metadata write error with buffer_write_io_error() Chao Shi
2026-08-01 22:01 ` [PATCH 16/19] jbd2: report journal write errors with BH_Write_EIO Chao Shi
2026-08-04  8:54   ` Jan Kara
2026-08-04  9:10     ` Jan Kara
2026-08-01 22:01 ` [PATCH 17/19] jbd2: assert on a failed write, not on a buffer that is not up to date Chao Shi
2026-08-04  9:04   ` Jan Kara
2026-08-01 22:01 ` [PATCH 18/19] ext4, jbd2: report fast commit write errors with BH_Write_EIO Chao Shi
2026-08-04  9:07   ` Jan Kara
2026-08-01 22:01 ` [PATCH 19/19] buffer: stop clearing BH_Uptodate when a write fails Chao Shi
2026-08-04  9:18   ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=anHyBATDe8yQEFNi@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=adilger.kernel@dilger.ca \
    --cc=agruenba@redhat.com \
    --cc=brauner@kernel.org \
    --cc=coshi036@gmail.com \
    --cc=gfs2@lists.linux.dev \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=jack@suse.cz \
    --cc=jlbec@evilplan.org \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=libaokun@linux.alibaba.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-karma-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark@fasheh.com \
    --cc=me@bobcopeland.com \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=sj1557.seo@samsung.com \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yi.zhang@huawei.com \
    --cc=yuezhang.mo@sony.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox