Skip to content

Commit bea82c8

Browse files
committed
Merge tag 'block-6.19-20260102' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux
Pull block fixes from Jens Axboe: - Scan partition tables asynchronously for ublk, similarly to how nvme does it. This avoids potential deadlocks, which is why nvme does it that way too. Includes a set of selftests as well. - MD pull request via Yu: - Fix null-pointer dereference in raid5 sysfs group_thread_cnt store (Tuo Li) - Fix possible mempool corruption during raid1 raid_disks update via sysfs (FengWei Shih) - Fix logical_block_size configuration being overwritten during super_1_validate() (Li Nan) - Fix forward incompatibility with configurable logical block size: arrays assembled on new kernels could not be assembled on older kernels (v6.18 and before) due to non-zero reserved pad rejection (Li Nan) - Fix static checker warning about iterator not incremented (Li Nan) - Skip CPU offlining notifications on unmapped hardware queues - bfq-iosched block stats fix - Fix outdated comment in bfq-iosched * tag 'block-6.19-20260102' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux: block, bfq: update outdated comment blk-mq: skip CPU offline notify on unmapped hctx selftests/ublk: fix Makefile to rebuild on header changes selftests/ublk: add test for async partition scan ublk: scan partition in async way block,bfq: fix aux stat accumulation destination md: Fix forward incompatibility from configurable logical block size md: Fix logical_block_size configuration being overwritten md: suspend array while updating raid_disks via sysfs md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt() md: Fix static checker warning in analyze_sbs
2 parents 509b5b1 + 69153e8 commit bea82c8

9 files changed

Lines changed: 174 additions & 27 deletions

File tree

block/bfq-cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static void bfqg_stats_add_aux(struct bfqg_stats *to, struct bfqg_stats *from)
380380
blkg_rwstat_add_aux(&to->merged, &from->merged);
381381
blkg_rwstat_add_aux(&to->service_time, &from->service_time);
382382
blkg_rwstat_add_aux(&to->wait_time, &from->wait_time);
383-
bfq_stat_add_aux(&from->time, &from->time);
383+
bfq_stat_add_aux(&to->time, &from->time);
384384
bfq_stat_add_aux(&to->avg_queue_size_sum, &from->avg_queue_size_sum);
385385
bfq_stat_add_aux(&to->avg_queue_size_samples,
386386
&from->avg_queue_size_samples);

block/bfq-iosched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ struct bfq_group_data {
984984
* unused for the root group. Used to know whether there
985985
* are groups with more than one active @bfq_entity
986986
* (see the comments to the function
987-
* bfq_bfqq_may_idle()).
987+
* bfq_better_to_idle()).
988988
* @rq_pos_tree: rbtree sorted by next_request position, used when
989989
* determining if two or more queues have interleaving
990990
* requests (see bfq_find_close_cooperator()).

block/blk-mq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3721,7 +3721,7 @@ static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node)
37213721
struct blk_mq_hw_ctx, cpuhp_online);
37223722
int ret = 0;
37233723

3724-
if (blk_mq_hctx_has_online_cpu(hctx, cpu))
3724+
if (!hctx->nr_ctx || blk_mq_hctx_has_online_cpu(hctx, cpu))
37253725
return 0;
37263726

37273727
/*

drivers/block/ublk_drv.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ struct ublk_device {
237237
bool canceling;
238238
pid_t ublksrv_tgid;
239239
struct delayed_work exit_work;
240+
struct work_struct partition_scan_work;
240241

241242
struct ublk_queue *queues[];
242243
};
@@ -254,6 +255,20 @@ static inline struct request *__ublk_check_and_get_req(struct ublk_device *ub,
254255
u16 q_id, u16 tag, struct ublk_io *io, size_t offset);
255256
static inline unsigned int ublk_req_build_flags(struct request *req);
256257

258+
static void ublk_partition_scan_work(struct work_struct *work)
259+
{
260+
struct ublk_device *ub =
261+
container_of(work, struct ublk_device, partition_scan_work);
262+
263+
if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN,
264+
&ub->ub_disk->state)))
265+
return;
266+
267+
mutex_lock(&ub->ub_disk->open_mutex);
268+
bdev_disk_changed(ub->ub_disk, false);
269+
mutex_unlock(&ub->ub_disk->open_mutex);
270+
}
271+
257272
static inline struct ublksrv_io_desc *
258273
ublk_get_iod(const struct ublk_queue *ubq, unsigned tag)
259274
{
@@ -2026,6 +2041,7 @@ static void ublk_stop_dev(struct ublk_device *ub)
20262041
mutex_lock(&ub->mutex);
20272042
ublk_stop_dev_unlocked(ub);
20282043
mutex_unlock(&ub->mutex);
2044+
flush_work(&ub->partition_scan_work);
20292045
ublk_cancel_dev(ub);
20302046
}
20312047

@@ -2954,9 +2970,17 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
29542970

29552971
ublk_apply_params(ub);
29562972

2957-
/* don't probe partitions if any daemon task is un-trusted */
2958-
if (ub->unprivileged_daemons)
2959-
set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
2973+
/*
2974+
* Suppress partition scan to avoid potential IO hang.
2975+
*
2976+
* If ublk server error occurs during partition scan, the IO may
2977+
* wait while holding ub->mutex, which can deadlock with other
2978+
* operations that need the mutex. Defer partition scan to async
2979+
* work.
2980+
* For unprivileged daemons, keep GD_SUPPRESS_PART_SCAN set
2981+
* permanently.
2982+
*/
2983+
set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
29602984

29612985
ublk_get_device(ub);
29622986
ub->dev_info.state = UBLK_S_DEV_LIVE;
@@ -2973,6 +2997,10 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
29732997

29742998
set_bit(UB_STATE_USED, &ub->state);
29752999

3000+
/* Schedule async partition scan for trusted daemons */
3001+
if (!ub->unprivileged_daemons)
3002+
schedule_work(&ub->partition_scan_work);
3003+
29763004
out_put_cdev:
29773005
if (ret) {
29783006
ublk_detach_disk(ub);
@@ -3138,6 +3166,7 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header)
31383166
mutex_init(&ub->mutex);
31393167
spin_lock_init(&ub->lock);
31403168
mutex_init(&ub->cancel_mutex);
3169+
INIT_WORK(&ub->partition_scan_work, ublk_partition_scan_work);
31413170

31423171
ret = ublk_alloc_dev_number(ub, header->dev_id);
31433172
if (ret < 0)

drivers/md/md.c

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,6 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *freshest, struc
19991999
mddev->layout = le32_to_cpu(sb->layout);
20002000
mddev->raid_disks = le32_to_cpu(sb->raid_disks);
20012001
mddev->dev_sectors = le64_to_cpu(sb->size);
2002-
mddev->logical_block_size = le32_to_cpu(sb->logical_block_size);
20032002
mddev->events = ev1;
20042003
mddev->bitmap_info.offset = 0;
20052004
mddev->bitmap_info.space = 0;
@@ -2015,6 +2014,9 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *freshest, struc
20152014

20162015
mddev->max_disks = (4096-256)/2;
20172016

2017+
if (!mddev->logical_block_size)
2018+
mddev->logical_block_size = le32_to_cpu(sb->logical_block_size);
2019+
20182020
if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) &&
20192021
mddev->bitmap_info.file == NULL) {
20202022
mddev->bitmap_info.offset =
@@ -3882,7 +3884,6 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
38823884

38833885
static int analyze_sbs(struct mddev *mddev)
38843886
{
3885-
int i;
38863887
struct md_rdev *rdev, *freshest, *tmp;
38873888

38883889
freshest = NULL;
@@ -3909,11 +3910,9 @@ static int analyze_sbs(struct mddev *mddev)
39093910
super_types[mddev->major_version].
39103911
validate_super(mddev, NULL/*freshest*/, freshest);
39113912

3912-
i = 0;
39133913
rdev_for_each_safe(rdev, tmp, mddev) {
39143914
if (mddev->max_disks &&
3915-
(rdev->desc_nr >= mddev->max_disks ||
3916-
i > mddev->max_disks)) {
3915+
rdev->desc_nr >= mddev->max_disks) {
39173916
pr_warn("md: %s: %pg: only %d devices permitted\n",
39183917
mdname(mddev), rdev->bdev,
39193918
mddev->max_disks);
@@ -4407,7 +4406,7 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
44074406
if (err < 0)
44084407
return err;
44094408

4410-
err = mddev_lock(mddev);
4409+
err = mddev_suspend_and_lock(mddev);
44114410
if (err)
44124411
return err;
44134412
if (mddev->pers)
@@ -4432,7 +4431,7 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
44324431
} else
44334432
mddev->raid_disks = n;
44344433
out_unlock:
4435-
mddev_unlock(mddev);
4434+
mddev_unlock_and_resume(mddev);
44364435
return err ? err : len;
44374436
}
44384437
static struct md_sysfs_entry md_raid_disks =
@@ -5981,13 +5980,33 @@ lbs_store(struct mddev *mddev, const char *buf, size_t len)
59815980
if (mddev->major_version == 0)
59825981
return -EINVAL;
59835982

5984-
if (mddev->pers)
5985-
return -EBUSY;
5986-
59875983
err = kstrtouint(buf, 10, &lbs);
59885984
if (err < 0)
59895985
return -EINVAL;
59905986

5987+
if (mddev->pers) {
5988+
unsigned int curr_lbs;
5989+
5990+
if (mddev->logical_block_size)
5991+
return -EBUSY;
5992+
/*
5993+
* To fix forward compatibility issues, LBS is not
5994+
* configured for arrays from old kernels (<=6.18) by default.
5995+
* If the user confirms no rollback to old kernels,
5996+
* enable LBS by writing current LBS — to prevent data
5997+
* loss from LBS changes.
5998+
*/
5999+
curr_lbs = queue_logical_block_size(mddev->gendisk->queue);
6000+
if (lbs != curr_lbs)
6001+
return -EINVAL;
6002+
6003+
mddev->logical_block_size = curr_lbs;
6004+
set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
6005+
pr_info("%s: logical block size configured successfully, array will not be assembled in old kernels (<= 6.18)\n",
6006+
mdname(mddev));
6007+
return len;
6008+
}
6009+
59916010
err = mddev_lock(mddev);
59926011
if (err)
59936012
goto unlock;
@@ -6163,7 +6182,27 @@ int mddev_stack_rdev_limits(struct mddev *mddev, struct queue_limits *lim,
61636182
mdname(mddev));
61646183
return -EINVAL;
61656184
}
6166-
mddev->logical_block_size = lim->logical_block_size;
6185+
6186+
/* Only 1.x meta needs to set logical block size */
6187+
if (mddev->major_version == 0)
6188+
return 0;
6189+
6190+
/*
6191+
* Fix forward compatibility issue. Only set LBS by default for
6192+
* new arrays, mddev->events == 0 indicates the array was just
6193+
* created. When assembling an array, read LBS from the superblock
6194+
* instead — LBS is 0 in superblocks created by old kernels.
6195+
*/
6196+
if (!mddev->events) {
6197+
pr_info("%s: array will not be assembled in old kernels that lack configurable LBS support (<= 6.18)\n",
6198+
mdname(mddev));
6199+
mddev->logical_block_size = lim->logical_block_size;
6200+
}
6201+
6202+
if (!mddev->logical_block_size)
6203+
pr_warn("%s: echo current LBS to md/logical_block_size to prevent data loss issues from LBS changes.\n"
6204+
"\tNote: After setting, array will not be assembled in old kernels (<= 6.18)\n",
6205+
mdname(mddev));
61676206

61686207
return 0;
61696208
}

drivers/md/raid5.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7187,12 +7187,14 @@ raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len)
71877187
err = mddev_suspend_and_lock(mddev);
71887188
if (err)
71897189
return err;
7190+
conf = mddev->private;
7191+
if (!conf) {
7192+
mddev_unlock_and_resume(mddev);
7193+
return -ENODEV;
7194+
}
71907195
raid5_quiesce(mddev, true);
71917196

7192-
conf = mddev->private;
7193-
if (!conf)
7194-
err = -ENODEV;
7195-
else if (new != conf->worker_cnt_per_group) {
7197+
if (new != conf->worker_cnt_per_group) {
71967198
old_groups = conf->worker_groups;
71977199
if (old_groups)
71987200
flush_workqueue(raid5_wq);

tools/testing/selftests/ublk/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ TEST_PROGS += test_generic_11.sh
2222
TEST_PROGS += test_generic_12.sh
2323
TEST_PROGS += test_generic_13.sh
2424
TEST_PROGS += test_generic_14.sh
25+
TEST_PROGS += test_generic_15.sh
2526

2627
TEST_PROGS += test_null_01.sh
2728
TEST_PROGS += test_null_02.sh
@@ -50,10 +51,10 @@ TEST_PROGS += test_stress_07.sh
5051

5152
TEST_GEN_PROGS_EXTENDED = kublk
5253

54+
LOCAL_HDRS += $(wildcard *.h)
5355
include ../lib.mk
5456

55-
$(TEST_GEN_PROGS_EXTENDED): kublk.c null.c file_backed.c common.c stripe.c \
56-
fault_inject.c
57+
$(TEST_GEN_PROGS_EXTENDED): $(wildcard *.c)
5758

5859
check:
5960
shellcheck -x -f gcc *.sh

tools/testing/selftests/ublk/test_common.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ _have_feature()
178178
_create_ublk_dev() {
179179
local dev_id;
180180
local cmd=$1
181+
local settle=$2
181182

182-
shift 1
183+
shift 2
183184

184185
if [ ! -c /dev/ublk-control ]; then
185186
return ${UBLK_SKIP_CODE}
@@ -194,7 +195,10 @@ _create_ublk_dev() {
194195
echo "fail to add ublk dev $*"
195196
return 255
196197
fi
197-
udevadm settle
198+
199+
if [ "$settle" = "yes" ]; then
200+
udevadm settle
201+
fi
198202

199203
if [[ "$dev_id" =~ ^[0-9]+$ ]]; then
200204
echo "${dev_id}"
@@ -204,14 +208,18 @@ _create_ublk_dev() {
204208
}
205209

206210
_add_ublk_dev() {
207-
_create_ublk_dev "add" "$@"
211+
_create_ublk_dev "add" "yes" "$@"
212+
}
213+
214+
_add_ublk_dev_no_settle() {
215+
_create_ublk_dev "add" "no" "$@"
208216
}
209217

210218
_recover_ublk_dev() {
211219
local dev_id
212220
local state
213221

214-
dev_id=$(_create_ublk_dev "recover" "$@")
222+
dev_id=$(_create_ublk_dev "recover" "yes" "$@")
215223
for ((j=0;j<20;j++)); do
216224
state=$(_get_ublk_dev_state "${dev_id}")
217225
[ "$state" == "LIVE" ] && break
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5+
6+
TID="generic_15"
7+
ERR_CODE=0
8+
9+
_test_partition_scan_no_hang()
10+
{
11+
local recovery_flag=$1
12+
local expected_state=$2
13+
local dev_id
14+
local state
15+
local daemon_pid
16+
local start_time
17+
local elapsed
18+
19+
# Create ublk device with fault_inject target and very large delay
20+
# to simulate hang during partition table read
21+
# --delay_us 60000000 = 60 seconds delay
22+
# Use _add_ublk_dev_no_settle to avoid udevadm settle hang waiting
23+
# for partition scan events to complete
24+
if [ "$recovery_flag" = "yes" ]; then
25+
echo "Testing partition scan with recovery support..."
26+
dev_id=$(_add_ublk_dev_no_settle -t fault_inject -q 1 -d 1 --delay_us 60000000 -r 1)
27+
else
28+
echo "Testing partition scan without recovery..."
29+
dev_id=$(_add_ublk_dev_no_settle -t fault_inject -q 1 -d 1 --delay_us 60000000)
30+
fi
31+
32+
_check_add_dev "$TID" $?
33+
34+
# The add command should return quickly because partition scan is async.
35+
# Now sleep briefly to let the async partition scan work start and hit
36+
# the delay in the fault_inject handler.
37+
sleep 1
38+
39+
# Kill the ublk daemon while partition scan is potentially blocked
40+
# And check state transitions properly
41+
start_time=${SECONDS}
42+
daemon_pid=$(_get_ublk_daemon_pid "${dev_id}")
43+
state=$(__ublk_kill_daemon "${dev_id}" "${expected_state}")
44+
elapsed=$((SECONDS - start_time))
45+
46+
# Verify the device transitioned to expected state
47+
if [ "$state" != "${expected_state}" ]; then
48+
echo "FAIL: Device state is $state, expected ${expected_state}"
49+
ERR_CODE=255
50+
${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1
51+
return
52+
fi
53+
echo "PASS: Device transitioned to ${expected_state} in ${elapsed}s without hanging"
54+
55+
# Clean up the device
56+
${UBLK_PROG} del -n "${dev_id}" > /dev/null 2>&1
57+
}
58+
59+
_prep_test "partition_scan" "verify async partition scan prevents IO hang"
60+
61+
# Test 1: Without recovery support - should transition to DEAD
62+
_test_partition_scan_no_hang "no" "DEAD"
63+
64+
# Test 2: With recovery support - should transition to QUIESCED
65+
_test_partition_scan_no_hang "yes" "QUIESCED"
66+
67+
_cleanup_test "partition_scan"
68+
_show_result $TID $ERR_CODE

0 commit comments

Comments
 (0)