Commit 0460e09
ublk: fix deadlock when reading partition table
[ Upstream commit c258f5c ]
When one process(such as udev) opens ublk block device (e.g., to read
the partition table via bdev_open()), a deadlock[1] can occur:
1. bdev_open() grabs disk->open_mutex
2. The process issues read I/O to ublk backend to read partition table
3. In __ublk_complete_rq(), blk_update_request() or blk_mq_end_request()
runs bio->bi_end_io() callbacks
4. If this triggers fput() on file descriptor of ublk block device, the
work may be deferred to current task's task work (see fput() implementation)
5. This eventually calls blkdev_release() from the same context
6. blkdev_release() tries to grab disk->open_mutex again
7. Deadlock: same task waiting for a mutex it already holds
The fix is to run blk_update_request() and blk_mq_end_request() with bottom
halves disabled. This forces blkdev_release() to run in kernel work-queue
context instead of current task work context, and allows ublk server to make
forward progress, and avoids the deadlock.
Fixes: 71f28f3 ("ublk_drv: add io_uring based userspace block driver")
Link: ublk-org/ublksrv#170 [1]
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Caleb Sander Mateos <csander@purestorage.com>
[axboe: rewrite comment in ublk]
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 474cf21 commit 0460e09
1 file changed
+28
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1146 | 1146 | | |
1147 | 1147 | | |
1148 | 1148 | | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
1149 | 1156 | | |
1150 | 1157 | | |
1151 | 1158 | | |
1152 | 1159 | | |
1153 | 1160 | | |
1154 | 1161 | | |
| 1162 | + | |
1155 | 1163 | | |
1156 | 1164 | | |
1157 | 1165 | | |
| |||
1183 | 1191 | | |
1184 | 1192 | | |
1185 | 1193 | | |
1186 | | - | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
1187 | 1211 | | |
1188 | 1212 | | |
1189 | 1213 | | |
1190 | 1214 | | |
1191 | 1215 | | |
1192 | 1216 | | |
1193 | | - | |
| 1217 | + | |
1194 | 1218 | | |
1195 | 1219 | | |
1196 | 1220 | | |
| |||
1230 | 1254 | | |
1231 | 1255 | | |
1232 | 1256 | | |
1233 | | - | |
| 1257 | + | |
1234 | 1258 | | |
1235 | 1259 | | |
1236 | 1260 | | |
| |||
1275 | 1299 | | |
1276 | 1300 | | |
1277 | 1301 | | |
1278 | | - | |
| 1302 | + | |
1279 | 1303 | | |
1280 | 1304 | | |
1281 | 1305 | | |
| |||
0 commit comments