Skip to content

Commit 569c3a2

Browse files
committed
Merge tag 'block-6.2-2022-12-19' of git://git.kernel.dk/linux
Pull block fixes from Jens Axboe: - Various fixes for BFQ (Yu, Yuwei) - Fix for loop command line parsing (Isaac) - No need to specifically clear REQ_ALLOC_CACHE on IOPOLL downgrade anymore (me) - blk-iocost enum fix for newer gcc (Jiri) - UAF fix for queue release (Ming) - blk-iolatency error handling memory leak fix (Tejun) * tag 'block-6.2-2022-12-19' of git://git.kernel.dk/linux: block: don't clear REQ_ALLOC_CACHE for non-polled requests block: fix use-after-free of q->q_usage_counter block, bfq: only do counting of pending-request for BFQ_GROUP_IOSCHED blk-iolatency: Fix memory leak on add_disk() failures loop: Fix the max_loop commandline argument treatment when it is set to 0 block/blk-iocost (gcc13): keep large values in a new enum block, bfq: replace 0/1 with false/true in bic apis block, bfq: don't return bfqg from __bfq_bic_change_cgroup() block, bfq: fix possible uaf for 'bfqq->bic'
2 parents 5d4740f + 53eab8e commit 569c3a2

File tree

9 files changed

+47
-38
lines changed

9 files changed

+47
-38
lines changed

block/bfq-cgroup.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,19 +724,19 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
724724
* sure that the reference to cgroup is valid across the call (see
725725
* comments in bfq_bic_update_cgroup on this issue)
726726
*/
727-
static void *__bfq_bic_change_cgroup(struct bfq_data *bfqd,
728-
struct bfq_io_cq *bic,
729-
struct bfq_group *bfqg)
727+
static void __bfq_bic_change_cgroup(struct bfq_data *bfqd,
728+
struct bfq_io_cq *bic,
729+
struct bfq_group *bfqg)
730730
{
731-
struct bfq_queue *async_bfqq = bic_to_bfqq(bic, 0);
732-
struct bfq_queue *sync_bfqq = bic_to_bfqq(bic, 1);
731+
struct bfq_queue *async_bfqq = bic_to_bfqq(bic, false);
732+
struct bfq_queue *sync_bfqq = bic_to_bfqq(bic, true);
733733
struct bfq_entity *entity;
734734

735735
if (async_bfqq) {
736736
entity = &async_bfqq->entity;
737737

738738
if (entity->sched_data != &bfqg->sched_data) {
739-
bic_set_bfqq(bic, NULL, 0);
739+
bic_set_bfqq(bic, NULL, false);
740740
bfq_release_process_ref(bfqd, async_bfqq);
741741
}
742742
}
@@ -772,12 +772,10 @@ static void *__bfq_bic_change_cgroup(struct bfq_data *bfqd,
772772
*/
773773
bfq_put_cooperator(sync_bfqq);
774774
bfq_release_process_ref(bfqd, sync_bfqq);
775-
bic_set_bfqq(bic, NULL, 1);
775+
bic_set_bfqq(bic, NULL, true);
776776
}
777777
}
778778
}
779-
780-
return bfqg;
781779
}
782780

783781
void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio)

block/bfq-iosched.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ static void bfq_put_stable_ref(struct bfq_queue *bfqq);
386386

387387
void bic_set_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq, bool is_sync)
388388
{
389+
struct bfq_queue *old_bfqq = bic->bfqq[is_sync];
390+
391+
/* Clear bic pointer if bfqq is detached from this bic */
392+
if (old_bfqq && old_bfqq->bic == bic)
393+
old_bfqq->bic = NULL;
394+
389395
/*
390396
* If bfqq != NULL, then a non-stable queue merge between
391397
* bic->bfqq and bfqq is happening here. This causes troubles
@@ -3108,7 +3114,7 @@ bfq_merge_bfqqs(struct bfq_data *bfqd, struct bfq_io_cq *bic,
31083114
/*
31093115
* Merge queues (that is, let bic redirect its requests to new_bfqq)
31103116
*/
3111-
bic_set_bfqq(bic, new_bfqq, 1);
3117+
bic_set_bfqq(bic, new_bfqq, true);
31123118
bfq_mark_bfqq_coop(new_bfqq);
31133119
/*
31143120
* new_bfqq now belongs to at least two bics (it is a shared queue):
@@ -5311,7 +5317,6 @@ static void bfq_exit_icq_bfqq(struct bfq_io_cq *bic, bool is_sync)
53115317
unsigned long flags;
53125318

53135319
spin_lock_irqsave(&bfqd->lock, flags);
5314-
bfqq->bic = NULL;
53155320
bfq_exit_bfqq(bfqd, bfqq);
53165321
bic_set_bfqq(bic, NULL, is_sync);
53175322
spin_unlock_irqrestore(&bfqd->lock, flags);
@@ -6557,7 +6562,7 @@ bfq_split_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq)
65576562
return bfqq;
65586563
}
65596564

6560-
bic_set_bfqq(bic, NULL, 1);
6565+
bic_set_bfqq(bic, NULL, true);
65616566

65626567
bfq_put_cooperator(bfqq);
65636568

@@ -7058,7 +7063,9 @@ static int bfq_init_queue(struct request_queue *q, struct elevator_type *e)
70587063
bfqd->idle_slice_timer.function = bfq_idle_slice_timer;
70597064

70607065
bfqd->queue_weights_tree = RB_ROOT_CACHED;
7066+
#ifdef CONFIG_BFQ_GROUP_IOSCHED
70617067
bfqd->num_groups_with_pending_reqs = 0;
7068+
#endif
70627069

70637070
INIT_LIST_HEAD(&bfqd->active_list);
70647071
INIT_LIST_HEAD(&bfqd->idle_list);

block/bfq-iosched.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,10 @@ struct bfq_entity {
197197
/* flag, set to request a weight, ioprio or ioprio_class change */
198198
int prio_changed;
199199

200+
#ifdef CONFIG_BFQ_GROUP_IOSCHED
200201
/* flag, set if the entity is counted in groups_with_pending_reqs */
201202
bool in_groups_with_pending_reqs;
203+
#endif
202204

203205
/* last child queue of entity created (for non-leaf entities) */
204206
struct bfq_queue *last_bfqq_created;
@@ -491,6 +493,7 @@ struct bfq_data {
491493
*/
492494
struct rb_root_cached queue_weights_tree;
493495

496+
#ifdef CONFIG_BFQ_GROUP_IOSCHED
494497
/*
495498
* Number of groups with at least one process that
496499
* has at least one request waiting for completion. Note that
@@ -538,6 +541,7 @@ struct bfq_data {
538541
* with no request waiting for completion.
539542
*/
540543
unsigned int num_groups_with_pending_reqs;
544+
#endif
541545

542546
/*
543547
* Per-class (RT, BE, IDLE) number of bfq_queues containing

block/bfq-wf2q.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,28 +1612,28 @@ void bfq_requeue_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq,
16121612

16131613
void bfq_add_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq)
16141614
{
1615+
#ifdef CONFIG_BFQ_GROUP_IOSCHED
16151616
struct bfq_entity *entity = &bfqq->entity;
16161617

16171618
if (!entity->in_groups_with_pending_reqs) {
16181619
entity->in_groups_with_pending_reqs = true;
1619-
#ifdef CONFIG_BFQ_GROUP_IOSCHED
16201620
if (!(bfqq_group(bfqq)->num_queues_with_pending_reqs++))
16211621
bfqq->bfqd->num_groups_with_pending_reqs++;
1622-
#endif
16231622
}
1623+
#endif
16241624
}
16251625

16261626
void bfq_del_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq)
16271627
{
1628+
#ifdef CONFIG_BFQ_GROUP_IOSCHED
16281629
struct bfq_entity *entity = &bfqq->entity;
16291630

16301631
if (entity->in_groups_with_pending_reqs) {
16311632
entity->in_groups_with_pending_reqs = false;
1632-
#ifdef CONFIG_BFQ_GROUP_IOSCHED
16331633
if (!(--bfqq_group(bfqq)->num_queues_with_pending_reqs))
16341634
bfqq->bfqd->num_groups_with_pending_reqs--;
1635-
#endif
16361635
}
1636+
#endif
16371637
}
16381638

16391639
/*

block/blk-cgroup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "blk-cgroup.h"
3434
#include "blk-ioprio.h"
3535
#include "blk-throttle.h"
36+
#include "blk-rq-qos.h"
3637

3738
/*
3839
* blkcg_pol_mutex protects blkcg_policy[] and policy [de]activation.
@@ -1322,6 +1323,7 @@ int blkcg_init_disk(struct gendisk *disk)
13221323
void blkcg_exit_disk(struct gendisk *disk)
13231324
{
13241325
blkg_destroy_all(disk);
1326+
rq_qos_exit(disk->queue);
13251327
blk_throtl_exit(disk);
13261328
}
13271329

block/blk-core.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,15 @@ EXPORT_SYMBOL_GPL(blk_clear_pm_only);
254254

255255
static void blk_free_queue_rcu(struct rcu_head *rcu_head)
256256
{
257-
kmem_cache_free(blk_requestq_cachep,
258-
container_of(rcu_head, struct request_queue, rcu_head));
257+
struct request_queue *q = container_of(rcu_head,
258+
struct request_queue, rcu_head);
259+
260+
percpu_ref_exit(&q->q_usage_counter);
261+
kmem_cache_free(blk_requestq_cachep, q);
259262
}
260263

261264
static void blk_free_queue(struct request_queue *q)
262265
{
263-
percpu_ref_exit(&q->q_usage_counter);
264-
265266
if (q->poll_stat)
266267
blk_stat_remove_callback(q, q->poll_cb);
267268
blk_stat_free_callback(q->poll_cb);

block/blk-iocost.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ enum {
232232

233233
/* 1/64k is granular enough and can easily be handled w/ u32 */
234234
WEIGHT_ONE = 1 << 16,
235+
};
235236

237+
enum {
236238
/*
237239
* As vtime is used to calculate the cost of each IO, it needs to
238240
* be fairly high precision. For example, it should be able to

drivers/block/loop.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,16 @@ static const struct block_device_operations lo_fops = {
17731773
/*
17741774
* And now the modules code and kernel interface.
17751775
*/
1776-
static int max_loop;
1776+
1777+
/*
1778+
* If max_loop is specified, create that many devices upfront.
1779+
* This also becomes a hard limit. If max_loop is not specified,
1780+
* create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module
1781+
* init time. Loop devices can be requested on-demand with the
1782+
* /dev/loop-control interface, or be instantiated by accessing
1783+
* a 'dead' device node.
1784+
*/
1785+
static int max_loop = CONFIG_BLK_DEV_LOOP_MIN_COUNT;
17771786
module_param(max_loop, int, 0444);
17781787
MODULE_PARM_DESC(max_loop, "Maximum number of loop devices");
17791788
module_param(max_part, int, 0444);
@@ -2181,7 +2190,7 @@ MODULE_ALIAS("devname:loop-control");
21812190

21822191
static int __init loop_init(void)
21832192
{
2184-
int i, nr;
2193+
int i;
21852194
int err;
21862195

21872196
part_shift = 0;
@@ -2209,19 +2218,6 @@ static int __init loop_init(void)
22092218
goto err_out;
22102219
}
22112220

2212-
/*
2213-
* If max_loop is specified, create that many devices upfront.
2214-
* This also becomes a hard limit. If max_loop is not specified,
2215-
* create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module
2216-
* init time. Loop devices can be requested on-demand with the
2217-
* /dev/loop-control interface, or be instantiated by accessing
2218-
* a 'dead' device node.
2219-
*/
2220-
if (max_loop)
2221-
nr = max_loop;
2222-
else
2223-
nr = CONFIG_BLK_DEV_LOOP_MIN_COUNT;
2224-
22252221
err = misc_register(&loop_misc);
22262222
if (err < 0)
22272223
goto err_out;
@@ -2233,7 +2229,7 @@ static int __init loop_init(void)
22332229
}
22342230

22352231
/* pre-create number of devices given by config or max_loop */
2236-
for (i = 0; i < nr; i++)
2232+
for (i = 0; i < max_loop; i++)
22372233
loop_add(i);
22382234

22392235
printk(KERN_INFO "loop: module loaded\n");

include/linux/bio.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,7 @@ static inline void bio_set_polled(struct bio *bio, struct kiocb *kiocb)
782782

783783
static inline void bio_clear_polled(struct bio *bio)
784784
{
785-
/* can't support alloc cache if we turn off polling */
786-
bio->bi_opf &= ~(REQ_POLLED | REQ_ALLOC_CACHE);
785+
bio->bi_opf &= ~REQ_POLLED;
787786
}
788787

789788
struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,

0 commit comments

Comments
 (0)