Skip to contentSkip to conversation

dm-verity: use softirq context only when !need_resched()

PATCH In review Eric Biggers 2 participants 2 messages Apr 22, 2025 – Apr 23, 2025 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm-verity: use softirq context only when !need_resched()

From: Eric Biggers <[email protected]>

Further limit verification in softirq (a.k.a. BH) context to cases where rescheduling of the interrupted task is not pending.

This helps prevent the CPU from spending too long in softirq context.

Note that handle_softirqs() in kernel/softirq.c already stops running softirqs in this same case. However, that check is too coarse-grained, since many I/O requests can be processed in a single BLOCK_SOFTIRQ.

---
 drivers/md/dm-verity-target.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-verity-target.c +2 -1
index 3c427f18a04b3..4de2c226ac9db 100644
@@ -680,11 +680,12 @@ static void verity_bh_work(struct work_struct *w)
 }
 
 static inline bool verity_use_bh(unsigned int bytes, unsigned short ioprio)
 {
 	return ioprio <= IOPRIO_CLASS_IDLE &&
-		bytes <= READ_ONCE(dm_verity_use_bh_bytes[ioprio]);
+		bytes <= READ_ONCE(dm_verity_use_bh_bytes[ioprio]) &&
+		!need_resched();
 }
 
 static void verity_end_io(struct bio *bio)
 {
 	struct dm_verity_io *io = bio->bi_private;

base-commit: a33b5a08cbbdd7aadff95f40cbb45ab86841679e

Signature · 1 line
2.49.0
maintainer
#1 lore raw

OK, Accepted.

Mikulas

Quoted 39 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Further limit verification in softirq (a.k.a. BH) context to cases where rescheduling of the interrupted task is not pending.

This helps prevent the CPU from spending too long in softirq context.

Note that handle_softirqs() in kernel/softirq.c already stops running softirqs in this same case. However, that check is too coarse-grained, since many I/O requests can be processed in a single BLOCK_SOFTIRQ.

---
 drivers/md/dm-verity-target.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-verity-target.c +2 -1
index 3c427f18a04b3..4de2c226ac9db 100644
@@ -680,11 +680,12 @@ static void verity_bh_work(struct work_struct *w)
 }
 
 static inline bool verity_use_bh(unsigned int bytes, unsigned short ioprio)
 {
 	return ioprio <= IOPRIO_CLASS_IDLE &&
-		bytes <= READ_ONCE(dm_verity_use_bh_bytes[ioprio]);
+		bytes <= READ_ONCE(dm_verity_use_bh_bytes[ioprio]) &&
+		!need_resched();
 }
 
 static void verity_end_io(struct bio *bio)
 {
 	struct dm_verity_io *io = bio->bi_private;

base-commit: a33b5a08cbbdd7aadff95f40cbb45ab86841679e

Signature · 1 line
2.49.0