Skip to contentSkip to conversation

null_blk: execute complete callback for fake timeout request

PATCH In review Akinobu Mita 3 participants 5 messages Mar 12, 2023 – Mar 14, 2023 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 null_blk: execute complete callback for fake timeout request

When injecting a fake timeout into the null_blk driver by fail_io_timeout, the request timeout handler doen't execute blk_mq_complete_request(), so the complete callback will never be executed for that timed out request.

The null_blk driver also has a driver-specific fake timeout mechanism and does not have the problem that occur when using the generic one. Fix the problem by doing similar to what the driver-specific one does.

Fixes de3510e52b0a ("null_blk: fix command timeout completion handling")
Cc Damien Le Moal <[email protected]>
Cc Jens Axboe <[email protected]>
---
 drivers/block/null_blk/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/block/null_blk/main.c +3 -1
index 4c601ca9552a..69250b3cfecd 100644
@@ -1413,7 +1413,9 @@ static inline void nullb_complete_cmd(struct nullb_cmd *cmd)
 	case NULL_IRQ_SOFTIRQ:
 		switch (cmd->nq->dev->queue_mode) {
 		case NULL_Q_MQ:
-			if (likely(!blk_should_fake_timeout(cmd->rq->q)))
+			if (unlikely(blk_should_fake_timeout(cmd->rq->q)))
+				cmd->fake_timeout = true;
+			else
 				blk_mq_complete_request(cmd->rq);
 			break;
 		case NULL_Q_BIO:
Signature · 1 line
2.34.1
#1 lore raw
Quoted 21 lines · Akinobu Mita

When injecting a fake timeout into the null_blk driver by fail_io_timeout, the request timeout handler doen't execute blk_mq_complete_request(), so the complete callback will never be executed for that timed out request.

The null_blk driver also has a driver-specific fake timeout mechanism and does not have the problem that occur when using the generic one. Fix the problem by doing similar to what the driver-specific one does.

Fixes de3510e52b0a ("null_blk: fix command timeout completion handling")
Cc Damien Le Moal <[email protected]>
Cc Jens Axboe <[email protected]>
---
 drivers/block/null_blk/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/block/null_blk/main.c +0 -0
index 4c601ca9552a..69250b3cfecd 100644

drivers/block/null_blk/main.c static inline void nullb_complete_cmd(struct nullb_cmd *cmd) · line 1421

Quoted 10 lines
drivers/block/null_blk/main.c +3 -1
@@ -1413,7 +1413,9 @@ static inline void nullb_complete_cmd(struct nullb_cmd *cmd)
 	case NULL_IRQ_SOFTIRQ:
 		switch (cmd->nq->dev->queue_mode) {
 		case NULL_Q_MQ:
-			if (likely(!blk_should_fake_timeout(cmd->rq->q)))
+			if (unlikely(blk_should_fake_timeout(cmd->rq->q)))
+				cmd->fake_timeout = true;
+			else
 				blk_mq_complete_request(cmd->rq);
 			break;
 		case NULL_Q_BIO:

I have not checked, but does this work ?

drivers/block/null_blk/main.c +3 -2
index 4c601ca9552a..52d689aa3171 100644
@@ -1413,7 +1413,7 @@ static inline void nullb_complete_cmd(struct nullb_cmd *cmd)
        case NULL_IRQ_SOFTIRQ:
                switch (cmd->nq->dev->queue_mode) {
                case NULL_Q_MQ:
-                       if (likely(!blk_should_fake_timeout(cmd->rq->q)))
+                       if (!cmd->fake_timeout)
                                blk_mq_complete_request(cmd->rq);
                        break;
                case NULL_Q_BIO:
@@ -1675,7 +1675,8 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
        cmd->rq = bd->rq;
        cmd->error = BLK_STS_OK;
        cmd->nq = nq;
-       cmd->fake_timeout = should_timeout_request(bd->rq);
+       cmd->fake_timeout = should_timeout_request(bd->rq) ||
+               blk_should_fake_timeout(bd->rq->q);
 
        blk_mq_start_request(bd->rq);
 

It is I think cleaner as it unifies the internal fake timeout and blk_should_fake_timeout().

Signature · 2 lines
Damien Le Moal
Western Digital Research
author Tested-by
#2 lore raw

2023年3月13日(月) 10:00 Damien Le Moal <[email protected]>:

Quoted 27 lines · Akinobu Mita
Quoted 25 lines

When injecting a fake timeout into the null_blk driver by fail_io_timeout, the request timeout handler doen't execute blk_mq_complete_request(), so the complete callback will never be executed for that timed out request.

The null_blk driver also has a driver-specific fake timeout mechanism and does not have the problem that occur when using the generic one. Fix the problem by doing similar to what the driver-specific one does.

Fixes de3510e52b0a ("null_blk: fix command timeout completion handling")
Cc Damien Le Moal <[email protected]>
Cc Jens Axboe <[email protected]>
---
 drivers/block/null_blk/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/block/null_blk/main.c +0 -1
index 4c601ca9552a..69250b3cfecd 100644
@@ -1413,7 +1413,9 @@ static inline void nullb_complete_cmd(struct nullb_cmd *cmd)
      case NULL_IRQ_SOFTIRQ:
              switch (cmd->nq->dev->queue_mode) {
              case NULL_Q_MQ:
-                     if (likely(!blk_should_fake_timeout(cmd->rq->q)))
Quoted 8 lines

drivers/block/null_blk/main.c static inline void nullb_complete_cmd(struct nullb_cmd *cmd) · line 1419

Quoted 6 lines
drivers/block/null_blk/main.c +3 -0
+                     if (unlikely(blk_should_fake_timeout(cmd->rq->q)))
+                             cmd->fake_timeout = true;
+                     else
                              blk_mq_complete_request(cmd->rq);
                      break;
              case NULL_Q_BIO:

I have not checked, but does this work ?

Yes it worked.

Quoted 24 lines
drivers/block/null_blk/main.c +3 -2
index 4c601ca9552a..52d689aa3171 100644
@@ -1413,7 +1413,7 @@ static inline void nullb_complete_cmd(struct nullb_cmd *cmd)
        case NULL_IRQ_SOFTIRQ:
                switch (cmd->nq->dev->queue_mode) {
                case NULL_Q_MQ:
-                       if (likely(!blk_should_fake_timeout(cmd->rq->q)))
+                       if (!cmd->fake_timeout)
                                blk_mq_complete_request(cmd->rq);
                        break;
                case NULL_Q_BIO:
@@ -1675,7 +1675,8 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
        cmd->rq = bd->rq;
        cmd->error = BLK_STS_OK;
        cmd->nq = nq;
-       cmd->fake_timeout = should_timeout_request(bd->rq);
+       cmd->fake_timeout = should_timeout_request(bd->rq) ||
+               blk_should_fake_timeout(bd->rq->q);
 
        blk_mq_start_request(bd->rq);
 
Quoted 2 lines

It is I think cleaner as it unifies the internal fake timeout and blk_should_fake_timeout().

I also prefer this one.

#3 lore raw
In reply to Damien Le Moal

drivers/block/null_blk/main.c static inline void nullb_complete_cmd(struct nullb_cmd *cmd) · line 1417

Quoted 13 lines · Damien Le Moal

On 3/12/23 21:35, Akinobu Mita wrote:

drivers/block/null_blk/main.c +1 -1
index 4c601ca9552a..52d689aa3171 100644
@@ -1413,7 +1413,7 @@ static inline void nullb_complete_cmd(struct nullb_cmd *cmd)
        case NULL_IRQ_SOFTIRQ:
                switch (cmd->nq->dev->queue_mode) {
                case NULL_Q_MQ:
-                       if (likely(!blk_should_fake_timeout(cmd->rq->q)))
+                       if (!cmd->fake_timeout)
                                blk_mq_complete_request(cmd->rq);

I think you can remove the fake_timeout check from here now since this function is never called when it's true.

Quoted 11 lines
drivers/block/null_blk/main.c +2 -1
                        break;
                case NULL_Q_BIO:
@@ -1675,7 +1675,8 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
        cmd->rq = bd->rq;
        cmd->error = BLK_STS_OK;
        cmd->nq = nq;
-       cmd->fake_timeout = should_timeout_request(bd->rq);
+       cmd->fake_timeout = should_timeout_request(bd->rq) ||
+               blk_should_fake_timeout(bd->rq->q);
 
        blk_mq_start_request(bd->rq);
#4 lore raw
Quoted 17 lines · Keith Busch

drivers/block/null_blk/main.c static inline void nullb_complete_cmd(struct nullb_cmd *cmd) · line 1417

Quoted 13 lines · Damien Le Moal

On 3/12/23 21:35, Akinobu Mita wrote:

drivers/block/null_blk/main.c +1 -1
index 4c601ca9552a..52d689aa3171 100644
@@ -1413,7 +1413,7 @@ static inline void nullb_complete_cmd(struct nullb_cmd *cmd)
        case NULL_IRQ_SOFTIRQ:
                switch (cmd->nq->dev->queue_mode) {
                case NULL_Q_MQ:
-                       if (likely(!blk_should_fake_timeout(cmd->rq->q)))
+                       if (!cmd->fake_timeout)
                                blk_mq_complete_request(cmd->rq);

I think you can remove the fake_timeout check from here now since this function is never called when it's true.

Right. Sending a proper patch with that.

Signature · 2 lines
Damien Le Moal
Western Digital Research