Skip to content

ublk: don't dispatch to canceled io commands

Ming Lei linux-block stable 3 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest12 patches 2 repliesApplied
  2. v211 patches 0 repliesSuperseded
  3. v18 patches 1 replySuperseded

Changes in v3 from the cover letter

- rebase on for-7.4/block
- add Li RongQing's "ublk: use global index for reported zones" (patch 12)

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/12ublk: keep a canceled FETCH round canceling until the server is gonedrivers/block/ublk_drv.c+33 -210 replies
2/12ublk: mark the io command cancelable before publishing itdrivers/block/ublk_drv.c+21 -60 replies
3/12ublk: mark the batch fetch command cancelable before linking itdrivers/block/ublk_drv.c+18 -60 replies
4/12ublk: reset the FETCH round in release also without a diskdrivers/block/ublk_drv.c+5 -50 replies
5/12ublk: reset the FETCH round under ub->mutexdrivers/block/ublk_drv.c+10 -60 replies
6/12ublk: allow a NULL io->cmd in the cancel callbackdrivers/block/ublk_drv.c+4 -10 replies
7/12ublk: let STOP_DEV cancel the server's commands before its releaseDocumentation/block/ublk.rst drivers/block/ublk_drv.c+79 -80 replies
8/12ublk: refuse to go live after an io command was canceledDocumentation/block/ublk.rst drivers/block/ublk_drv.c+44 -40 replies
9/12selftests: ublk: move the control command helpers into ctrl.ctools/testing/selftests/ublk/ctrl.c tools/testing/selftests/ublk/kublk.c tools/testing/selftests/ublk/kublk.h+300 -2710 replies
10/12selftests: ublk: stop a batch thread when PREP_IO_CMDS failstools/testing/selftests/ublk/batch.c+10 -30 replies
11/12selftests: ublk: add test for going live over canceled io commandstools/testing/selftests/ublk/.gitignore tools/testing/selftests/ublk/Makefile tools/testing/selftests/ublk/test_generic_18.sh +1 more+1031 -20 replies
12/12ublk: use global index for reported zonesdrivers/block/ublk_drv.c+1 -10 replies

Reviews trailers per patch

2 of 12 patches have a Reviewed-by or Acked-by.

PatchJosef BacikMing Lei
1/12T-b
2/12T-b
3/12T-b
4/12T-b
5/12T-b
6/12T-b
7/12T-b
8/12R-b
9/12
10/12
11/12
12/12R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 00/12] ublk: don't dispatch to canceled io commands

Hi,

Josef reported three ways in which ublk dispatches a request to a canceled io command, which oopses on the NULL io->cmd in ublk_queue_cmd() [1]:

1) STOP_DEV, then START_DEV
2) partial FETCH: a task fetches some tags and exits, then another task fetches the rest
3) user recovery: one queue's task exits before all queues are ready

This series fixes them in a simpler way, without extra locking in the I/O path:

- patch 1: a FETCH round which saw a cancel stays canceling until the server is gone (2, 3)
- patch 2-3: an io command is marked cancelable before it is published
- patch 4-5: the release resets the FETCH round, also without a disk and under ub->mutex
- patch 6: don't warn when the cancel callback finds io->cmd taken by a cancel from the control path
- patch 7: STOP_DEV holds a reference on /dev/ublkcN while it cancels, so no START_DEV, FETCH or new server can slip in (1)
- patch 8 (Josef): START_DEV and END_USER_RECOVERY refuse to go live after an io command was canceled (2, 3)
- patch 9-11: selftests
- patch 12 (Li RongQing): ublk_report_zones() passes a per-chunk index to disk_report_zone(); use the index in the whole report

Tested with all ublk selftests under lockdep on for-7.4/block; v1 was also tested under KASAN.

V3:
- rebase on for-7.4/block
- add Li RongQing's "ublk: use global index for reported zones" (patch 12)

V2:
- add Josef's "ublk: refuse to go live after an io command was canceled", so routes 2 and 3 get -EBUSY instead of a live device failing every request
- split the cancel callback's WARN change out of the STOP_DEV patch (patch 6)
- document in ublk.rst what a server sees after STOP_DEV (Josef)
- kublk: stop a batch thread when PREP_IO_CMDS is aborted, instead of asserting and leaving kublk add waiting forever (Josef)
- selftest: partial_fetch and recovery expect -EBUSY; add a batch STOP_DEV race mode with kublk
- commit log fixes (patch 4, patch 7)
- add Josef's Tested-by

The release work deciding "no disk" before ub->mutex (Josef's point 4) needs a START_DEV for a server which has already exited: no new server can open /dev/ublkcN until that work is done, and patch 8 refuses such a START_DEV with -EBUSY, so it gets no extra patch.

V2: https://lore.kernel.org/linux-block/[email protected]/
V1: https://lore.kernel.org/linux-block/[email protected]/

[1] https://lore.kernel.org/linux-block/[email protected]/

Thanks,
Ming

Josef Bacik (1):
ublk: refuse to go live after an io command was canceled

Li RongQing (1):
ublk: use global index for reported zones

Ming Lei (10):
ublk: keep a canceled FETCH round canceling until the server is gone
ublk: mark the io command cancelable before publishing it
ublk: mark the batch fetch command cancelable before linking it
ublk: reset the FETCH round in release also without a disk
ublk: reset the FETCH round under ub->mutex
ublk: allow a NULL io->cmd in the cancel callback
ublk: let STOP_DEV cancel the server's commands before its release
selftests: ublk: move the control command helpers into ctrl.c
selftests: ublk: stop a batch thread when PREP_IO_CMDS fails
selftests: ublk: add test for going live over canceled io commands

 Documentation/block/ublk.rst                  |  17 +-
 drivers/block/ublk_drv.c                      | 246 ++++-
 tools/testing/selftests/ublk/.gitignore       |   1 +
 tools/testing/selftests/ublk/Makefile         |   6 +-
 tools/testing/selftests/ublk/batch.c          |  13 +-
 tools/testing/selftests/ublk/ctrl.c           | 268 +++++
 tools/testing/selftests/ublk/kublk.c          | 271 -----
 tools/testing/selftests/ublk/kublk.h          |  32 +
 .../testing/selftests/ublk/test_generic_18.sh |  69 ++
 .../selftests/ublk/ublk_cancel_ready.c        | 957 ++++++++++++++++++
 10 files changed, 1551 insertions(+), 329 deletions(-)
 create mode 100644 tools/testing/selftests/ublk/ctrl.c
 create mode 100755 tools/testing/selftests/ublk/test_generic_18.sh
 create mode 100644 tools/testing/selftests/ublk/ublk_cancel_ready.c

base-commit: 69ae59173a5668d015ab2733c8628ed542f00ccc

Signature · 1 line
2.55.0