* [PATCH] dm ebs: drop dirty bufio state when discarding blocks
@ 2026-06-03 17:51 Samuel Moelius
2026-06-08 14:16 ` Mikulas Patocka
0 siblings, 1 reply; 3+ messages in thread
From: Samuel Moelius @ 2026-06-03 17:51 UTC (permalink / raw)
To: Alasdair Kergon
Cc: Samuel Moelius, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski,
open list:DEVICE-MAPPER (LVM), open list
dm-ebs can discard a block while a dirty dm-bufio buffer for the
same block is still cached. If that buffer is later written back,
stale data can be written over the discarded state.
That resurrects data that userspace explicitly discarded and breaks
the expected discard semantics of the target.
Invalidate or clean the matching bufio state when processing discards
so that old dirty buffers cannot be written back after the discard.
Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
---
drivers/md/dm-ebs-target.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-ebs-target.c b/drivers/md/dm-ebs-target.c
index 1e52bde48b91..9fece535a0b3 100644
--- a/drivers/md/dm-ebs-target.c
+++ b/drivers/md/dm-ebs-target.c
@@ -212,8 +212,12 @@ static void __ebs_process_bios(struct work_struct *ws)
write = true;
r = __ebs_rw_bio(ec, REQ_OP_WRITE, bio);
} else if (bio_op(bio) == REQ_OP_DISCARD) {
- __ebs_forget_bio(ec, bio);
- r = __ebs_discard_bio(ec, bio);
+ if (write)
+ r = dm_bufio_write_dirty_buffers(ec->bufio);
+ if (!r) {
+ __ebs_forget_bio(ec, bio);
+ r = __ebs_discard_bio(ec, bio);
+ }
}
if (r < 0)
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] dm ebs: drop dirty bufio state when discarding blocks
2026-06-03 17:51 [PATCH] dm ebs: drop dirty bufio state when discarding blocks Samuel Moelius
@ 2026-06-08 14:16 ` Mikulas Patocka
2026-06-08 16:03 ` Samuel Moelius
0 siblings, 1 reply; 3+ messages in thread
From: Mikulas Patocka @ 2026-06-08 14:16 UTC (permalink / raw)
To: Samuel Moelius
Cc: Alasdair Kergon, Mike Snitzer, Benjamin Marzinski,
Heinz Mauelshagen, open list:DEVICE-MAPPER (LVM), open list
On Wed, 3 Jun 2026, Samuel Moelius wrote:
> dm-ebs can discard a block while a dirty dm-bufio buffer for the
> same block is still cached. If that buffer is later written back,
> stale data can be written over the discarded state.
>
> That resurrects data that userspace explicitly discarded and breaks
> the expected discard semantics of the target.
>
> Invalidate or clean the matching bufio state when processing discards
> so that old dirty buffers cannot be written back after the discard.
>
> Assisted-by: Codex:gpt-5.5-cyber-preview
> Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
> ---
> drivers/md/dm-ebs-target.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/md/dm-ebs-target.c b/drivers/md/dm-ebs-target.c
> index 1e52bde48b91..9fece535a0b3 100644
> --- a/drivers/md/dm-ebs-target.c
> +++ b/drivers/md/dm-ebs-target.c
> @@ -212,8 +212,12 @@ static void __ebs_process_bios(struct work_struct *ws)
> write = true;
> r = __ebs_rw_bio(ec, REQ_OP_WRITE, bio);
> } else if (bio_op(bio) == REQ_OP_DISCARD) {
> - __ebs_forget_bio(ec, bio);
> - r = __ebs_discard_bio(ec, bio);
> + if (write)
> + r = dm_bufio_write_dirty_buffers(ec->bufio);
> + if (!r) {
> + __ebs_forget_bio(ec, bio);
> + r = __ebs_discard_bio(ec, bio);
> + }
> }
>
> if (r < 0)
Hi
There's a bug in the patch - when the "write" variable is false, "r" is
equal to -EIO, thus __ebs_forget_bio and __ebs_discard_bio is skipped at
all.
If dm_bufio_write_dirty_buffers returns non-zero, the error is erroneously
reported on the discard bio (that is innocent) and not on the write bios
that triggered the error.
Mikulas
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] dm ebs: drop dirty bufio state when discarding blocks
2026-06-08 14:16 ` Mikulas Patocka
@ 2026-06-08 16:03 ` Samuel Moelius
0 siblings, 0 replies; 3+ messages in thread
From: Samuel Moelius @ 2026-06-08 16:03 UTC (permalink / raw)
To: Mikulas Patocka
Cc: Alasdair Kergon, Mike Snitzer, Benjamin Marzinski,
Heinz Mauelshagen, open list:DEVICE-MAPPER (LVM), open list
On Mon, Jun 8, 2026 at 10:16 AM Mikulas Patocka <mpatocka@redhat.com> wrote:
>
>
>
> On Wed, 3 Jun 2026, Samuel Moelius wrote:
>
> > dm-ebs can discard a block while a dirty dm-bufio buffer for the
> > same block is still cached. If that buffer is later written back,
> > stale data can be written over the discarded state.
> >
> > That resurrects data that userspace explicitly discarded and breaks
> > the expected discard semantics of the target.
> >
> > Invalidate or clean the matching bufio state when processing discards
> > so that old dirty buffers cannot be written back after the discard.
> >
> > Assisted-by: Codex:gpt-5.5-cyber-preview
> > Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
> > ---
> > drivers/md/dm-ebs-target.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/md/dm-ebs-target.c b/drivers/md/dm-ebs-target.c
> > index 1e52bde48b91..9fece535a0b3 100644
> > --- a/drivers/md/dm-ebs-target.c
> > +++ b/drivers/md/dm-ebs-target.c
> > @@ -212,8 +212,12 @@ static void __ebs_process_bios(struct work_struct *ws)
> > write = true;
> > r = __ebs_rw_bio(ec, REQ_OP_WRITE, bio);
> > } else if (bio_op(bio) == REQ_OP_DISCARD) {
> > - __ebs_forget_bio(ec, bio);
> > - r = __ebs_discard_bio(ec, bio);
> > + if (write)
> > + r = dm_bufio_write_dirty_buffers(ec->bufio);
> > + if (!r) {
> > + __ebs_forget_bio(ec, bio);
> > + r = __ebs_discard_bio(ec, bio);
> > + }
> > }
> >
> > if (r < 0)
>
> Hi
>
> There's a bug in the patch - when the "write" variable is false, "r" is
> equal to -EIO, thus __ebs_forget_bio and __ebs_discard_bio is skipped at
> all.
>
> If dm_bufio_write_dirty_buffers returns non-zero, the error is erroneously
> reported on the discard bio (that is innocent) and not on the write bios
> that triggered the error.
v2 forthcoming.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-08 16:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 17:51 [PATCH] dm ebs: drop dirty bufio state when discarding blocks Samuel Moelius
2026-06-08 14:16 ` Mikulas Patocka
2026-06-08 16:03 ` Samuel Moelius
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.