public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Boris Burkov <boris@bur.io>
Cc: David Sterba <dsterba@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/7] btrfs: accessors: inline eb bounds check and factor out the error report
Date: Thu, 3 Jul 2025 23:16:33 +0200	[thread overview]
Message-ID: <20250703211633.GY31241@suse.cz> (raw)
In-Reply-To: <20250702180055.GB2308047@zen.localdomain>

On Wed, Jul 02, 2025 at 11:00:55AM -0700, Boris Burkov wrote:
> > @@ -56,7 +51,10 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb,		\
> >  	const int part = eb->folio_size - oil;				\
> >  	u8 lebytes[sizeof(u##bits)];					\
> >  									\
> > -	ASSERT(check_setget_bounds(eb, ptr, off, sizeof(u##bits)));	\
> > +	if (unlikely(member_offset + sizeof(u##bits) > eb->len)) {	\
> > +		report_setget_bounds(eb, ptr, off, sizeof(u##bits));	\
> 
> For full no-change compatibility would it make sense to also ASSERT
> here? (or stuff it in report, these are the only two users)

I'm not claiming no-change here and it's implied by the changelog that
the behaviour and outcome depend on CONFIG_BTRFS_ASSEERT which I wanted
to unify.

I see the point that it should keep the assert here when things go
wrong, during development. However, the type of errors it would catch is
quite rare. Most btree items are accessed by the set/get helpers with
fixed sizes, or the read_extent_buffer/write_extent_buffer with variable
length (and they have their own bounds checks and reports).

I can add an assert or rather a debug warning to the report function so
we get a noisy report. The reason I'd like use DEBUG_WARN for that is
that we get a noisy report but don't crash so we can also observe what
happens if the function returns a this is what would happen with
non-assert configs.

For future plans, this error case will also somehow mark the filesystem
as "we have a serious problem" and let it shut down. Qu has some work
for that pending so I'll connect the two once it's done.

My idea, before the shutdown works, was to set a filesystem bit and
detect it at transaction commit to abort early. The reason is that the
set/get helpers are used everywhere without error checking, so it would
be more sensible to catch that in some selected points.

> > @@ -76,7 +74,10 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr,	\
> >  	const int part = eb->folio_size - oil;				\
> >  	u8 lebytes[sizeof(u##bits)];					\
> >  									\
> > -	ASSERT(check_setget_bounds(eb, ptr, off, sizeof(u##bits)));	\
> > +	if (unlikely(member_offset + sizeof(u##bits) > eb->len)) {	\
> > +		report_setget_bounds(eb, ptr, off, sizeof(u##bits));	\
> > +		return;							\
> > +	}								\
> 
> Would a helper macro to reduce this duplication be useful? Seems
> borderline but worth mentioning. Next time you improve it you won't
> have to hit two spots.

I don't see much reason for that, the definitions are next to each
other and once the token versions got removed the code it's basically on
one screen, hard to miss the other location.

  reply	other threads:[~2025-07-03 21:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-01 17:23 [PATCH 0/7] Set/get accessor speedups David Sterba
2025-07-01 17:23 ` [PATCH 1/7] btrfs: accessors: simplify folio bounds checks David Sterba
2025-07-01 17:23 ` [PATCH 2/7] btrfs: accessors: use type sizeof constants directly David Sterba
2025-07-02 17:58   ` Boris Burkov
2025-07-03 21:20     ` David Sterba
2025-07-07 14:25       ` David Sterba
2025-07-01 17:23 ` [PATCH 3/7] btrfs: accessors: inline eb bounds check and factor out the error report David Sterba
2025-07-02 18:00   ` Boris Burkov
2025-07-03 21:16     ` David Sterba [this message]
2025-07-01 17:23 ` [PATCH 4/7] btrfs: accessors: compile-time fast path for u8 David Sterba
2025-07-01 17:23 ` [PATCH 5/7] btrfs: accessors: compile-time fast path for u16 David Sterba
2025-07-01 17:23 ` [PATCH 6/7] btrfs: accessors: set target address at initialization David Sterba
2025-07-01 17:23 ` [PATCH 7/7] btrfs: accessors: factor out split memcpy with two sources David Sterba
2025-07-02 18:53   ` Boris Burkov
2025-07-03 20:57     ` David Sterba
2025-07-02 18:54 ` [PATCH 0/7] Set/get accessor speedups Boris Burkov

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=20250703211633.GY31241@suse.cz \
    --to=dsterba@suse.cz \
    --cc=boris@bur.io \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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