Skip to contentSkip to conversation

dm ebs: drop dirty bufio state when discarding blocks

PATCH Superseded Samuel Moelius 2 participants 3 messages Jun 3 – Jun 8 Device mapper

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm ebs: drop dirty bufio state when discarding blocks

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
---
 drivers/md/dm-ebs-target.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/md/dm-ebs-target.c +6 -2
index 1e52bde48b91..9fece535a0b3 100644
@@ -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)
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 25 lines · Samuel Moelius

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
---
 drivers/md/dm-ebs-target.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/md/dm-ebs-target.c +0 -1
index 1e52bde48b91..9fece535a0b3 100644
@@ -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);

drivers/md/dm-ebs-target.c static void __ebs_process_bios(struct work_struct *ws) · line 223

Quoted 10 lines
drivers/md/dm-ebs-target.c +6 -1
-			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

#2 lore raw
Quoted 43 lines · Mikulas Patocka
Quoted 25 lines · Samuel Moelius

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
---
 drivers/md/dm-ebs-target.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/md/dm-ebs-target.c +0 -1
index 1e52bde48b91..9fece535a0b3 100644
@@ -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);

drivers/md/dm-ebs-target.c static void __ebs_process_bios(struct work_struct *ws) · line 223

Quoted 10 lines
drivers/md/dm-ebs-target.c +6 -1
-                     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

Quoted 7 lines

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.