Skip to content

Commit fb64638

Browse files
committed
Merge tag 'for-linus-20180830' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "Small collection of fixes that should go into this series. This pull contains: - NVMe pull request with three small fixes (via Christoph) - Kill useless NULL check before kmem_cache_destroy (Chengguang Xu) - Xen block driver pull request with persistent grant flushing fixes (Juergen Gross) - Final wbt fixes, wrapping up the changes for this series. These have been heavily tested (me) - cdrom info leak fix (Scott Bauer) - ATA dma quirk for SQ201 (Linus Walleij) - Straight forward bsg refcount_t conversion (John Pittman)" * tag 'for-linus-20180830' of git://git.kernel.dk/linux-block: cdrom: Fix info leak/OOB read in cdrom_ioctl_drive_status nvmet: free workqueue object if module init fails nvme-fcloop: Fix dropped LS's to removed target port nvme-pci: add a memory barrier to nvme_dbbuf_update_and_check_event block: bsg: move atomic_t ref_count variable to refcount API block: remove unnecessary condition check ata: ftide010: Add a quirk for SQ201 blk-wbt: remove dead code blk-wbt: improve waking of tasks blk-wbt: abstract out end IO completion handler xen/blkback: remove unused pers_gnts_lock from struct xen_blkif_ring xen/blkback: move persistent grants flags to bool xen/blkfront: reorder tests in xlblk_init() xen/blkfront: cleanup stale persistent grants xen/blkback: don't keep persistent grants too long
2 parents 9f8f16c + 52bd456 commit fb64638

File tree

12 files changed

+269
-108
lines changed

12 files changed

+269
-108
lines changed

Documentation/ABI/testing/sysfs-driver-xen-blkback

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ Description:
1515
blkback. If the frontend tries to use more than
1616
max_persistent_grants, the LRU kicks in and starts
1717
removing 5% of max_persistent_grants every 100ms.
18+
19+
What: /sys/module/xen_blkback/parameters/persistent_grant_unused_seconds
20+
Date: August 2018
21+
KernelVersion: 4.19
22+
Contact: Roger Pau Monné <roger.pau@citrix.com>
23+
Description:
24+
How long a persistent grant is allowed to remain
25+
allocated without being in use. The time is in
26+
seconds, 0 means indefinitely long.
27+
The default is 60 seconds.

block/blk-wbt.c

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,11 @@ static void rwb_wake_all(struct rq_wb *rwb)
123123
}
124124
}
125125

126-
static void __wbt_done(struct rq_qos *rqos, enum wbt_flags wb_acct)
126+
static void wbt_rqw_done(struct rq_wb *rwb, struct rq_wait *rqw,
127+
enum wbt_flags wb_acct)
127128
{
128-
struct rq_wb *rwb = RQWB(rqos);
129-
struct rq_wait *rqw;
130129
int inflight, limit;
131130

132-
if (!(wb_acct & WBT_TRACKED))
133-
return;
134-
135-
rqw = get_rq_wait(rwb, wb_acct);
136131
inflight = atomic_dec_return(&rqw->inflight);
137132

138133
/*
@@ -166,10 +161,22 @@ static void __wbt_done(struct rq_qos *rqos, enum wbt_flags wb_acct)
166161
int diff = limit - inflight;
167162

168163
if (!inflight || diff >= rwb->wb_background / 2)
169-
wake_up(&rqw->wait);
164+
wake_up_all(&rqw->wait);
170165
}
171166
}
172167

168+
static void __wbt_done(struct rq_qos *rqos, enum wbt_flags wb_acct)
169+
{
170+
struct rq_wb *rwb = RQWB(rqos);
171+
struct rq_wait *rqw;
172+
173+
if (!(wb_acct & WBT_TRACKED))
174+
return;
175+
176+
rqw = get_rq_wait(rwb, wb_acct);
177+
wbt_rqw_done(rwb, rqw, wb_acct);
178+
}
179+
173180
/*
174181
* Called on completion of a request. Note that it's also called when
175182
* a request is merged, when the request gets freed.
@@ -481,6 +488,34 @@ static inline unsigned int get_limit(struct rq_wb *rwb, unsigned long rw)
481488
return limit;
482489
}
483490

491+
struct wbt_wait_data {
492+
struct wait_queue_entry wq;
493+
struct task_struct *task;
494+
struct rq_wb *rwb;
495+
struct rq_wait *rqw;
496+
unsigned long rw;
497+
bool got_token;
498+
};
499+
500+
static int wbt_wake_function(struct wait_queue_entry *curr, unsigned int mode,
501+
int wake_flags, void *key)
502+
{
503+
struct wbt_wait_data *data = container_of(curr, struct wbt_wait_data,
504+
wq);
505+
506+
/*
507+
* If we fail to get a budget, return -1 to interrupt the wake up
508+
* loop in __wake_up_common.
509+
*/
510+
if (!rq_wait_inc_below(data->rqw, get_limit(data->rwb, data->rw)))
511+
return -1;
512+
513+
data->got_token = true;
514+
list_del_init(&curr->entry);
515+
wake_up_process(data->task);
516+
return 1;
517+
}
518+
484519
/*
485520
* Block if we will exceed our limit, or if we are currently waiting for
486521
* the timer to kick off queuing again.
@@ -491,31 +526,52 @@ static void __wbt_wait(struct rq_wb *rwb, enum wbt_flags wb_acct,
491526
__acquires(lock)
492527
{
493528
struct rq_wait *rqw = get_rq_wait(rwb, wb_acct);
494-
DECLARE_WAITQUEUE(wait, current);
529+
struct wbt_wait_data data = {
530+
.wq = {
531+
.func = wbt_wake_function,
532+
.entry = LIST_HEAD_INIT(data.wq.entry),
533+
},
534+
.task = current,
535+
.rwb = rwb,
536+
.rqw = rqw,
537+
.rw = rw,
538+
};
495539
bool has_sleeper;
496540

497541
has_sleeper = wq_has_sleeper(&rqw->wait);
498542
if (!has_sleeper && rq_wait_inc_below(rqw, get_limit(rwb, rw)))
499543
return;
500544

501-
add_wait_queue_exclusive(&rqw->wait, &wait);
545+
prepare_to_wait_exclusive(&rqw->wait, &data.wq, TASK_UNINTERRUPTIBLE);
502546
do {
503-
set_current_state(TASK_UNINTERRUPTIBLE);
547+
if (data.got_token)
548+
break;
504549

505-
if (!has_sleeper && rq_wait_inc_below(rqw, get_limit(rwb, rw)))
550+
if (!has_sleeper &&
551+
rq_wait_inc_below(rqw, get_limit(rwb, rw))) {
552+
finish_wait(&rqw->wait, &data.wq);
553+
554+
/*
555+
* We raced with wbt_wake_function() getting a token,
556+
* which means we now have two. Put our local token
557+
* and wake anyone else potentially waiting for one.
558+
*/
559+
if (data.got_token)
560+
wbt_rqw_done(rwb, rqw, wb_acct);
506561
break;
562+
}
507563

508564
if (lock) {
509565
spin_unlock_irq(lock);
510566
io_schedule();
511567
spin_lock_irq(lock);
512568
} else
513569
io_schedule();
570+
514571
has_sleeper = false;
515572
} while (1);
516573

517-
__set_current_state(TASK_RUNNING);
518-
remove_wait_queue(&rqw->wait, &wait);
574+
finish_wait(&rqw->wait, &data.wq);
519575
}
520576

521577
static inline bool wbt_should_throttle(struct rq_wb *rwb, struct bio *bio)
@@ -580,11 +636,6 @@ static void wbt_wait(struct rq_qos *rqos, struct bio *bio, spinlock_t *lock)
580636
return;
581637
}
582638

583-
if (current_is_kswapd())
584-
flags |= WBT_KSWAPD;
585-
if (bio_op(bio) == REQ_OP_DISCARD)
586-
flags |= WBT_DISCARD;
587-
588639
__wbt_wait(rwb, flags, bio->bi_opf, lock);
589640

590641
if (!blk_stat_is_active(rwb->cb))

block/bsg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct bsg_device {
3737
struct request_queue *queue;
3838
spinlock_t lock;
3939
struct hlist_node dev_list;
40-
atomic_t ref_count;
40+
refcount_t ref_count;
4141
char name[20];
4242
int max_queue;
4343
};
@@ -252,7 +252,7 @@ static int bsg_put_device(struct bsg_device *bd)
252252

253253
mutex_lock(&bsg_mutex);
254254

255-
if (!atomic_dec_and_test(&bd->ref_count)) {
255+
if (!refcount_dec_and_test(&bd->ref_count)) {
256256
mutex_unlock(&bsg_mutex);
257257
return 0;
258258
}
@@ -290,7 +290,7 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
290290

291291
bd->queue = rq;
292292

293-
atomic_set(&bd->ref_count, 1);
293+
refcount_set(&bd->ref_count, 1);
294294
hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode)));
295295

296296
strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1);
@@ -308,7 +308,7 @@ static struct bsg_device *__bsg_get_device(int minor, struct request_queue *q)
308308

309309
hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) {
310310
if (bd->queue == q) {
311-
atomic_inc(&bd->ref_count);
311+
refcount_inc(&bd->ref_count);
312312
goto found;
313313
}
314314
}

block/elevator.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,7 @@ int elv_register(struct elevator_type *e)
895895
spin_lock(&elv_list_lock);
896896
if (elevator_find(e->elevator_name, e->uses_mq)) {
897897
spin_unlock(&elv_list_lock);
898-
if (e->icq_cache)
899-
kmem_cache_destroy(e->icq_cache);
898+
kmem_cache_destroy(e->icq_cache);
900899
return -EBUSY;
901900
}
902901
list_add_tail(&e->list, &elv_list);

drivers/ata/pata_ftide010.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,12 @@ static struct ata_port_operations pata_ftide010_port_ops = {
256256
.qc_issue = ftide010_qc_issue,
257257
};
258258

259-
static struct ata_port_info ftide010_port_info[] = {
260-
{
261-
.flags = ATA_FLAG_SLAVE_POSS,
262-
.mwdma_mask = ATA_MWDMA2,
263-
.udma_mask = ATA_UDMA6,
264-
.pio_mask = ATA_PIO4,
265-
.port_ops = &pata_ftide010_port_ops,
266-
},
259+
static struct ata_port_info ftide010_port_info = {
260+
.flags = ATA_FLAG_SLAVE_POSS,
261+
.mwdma_mask = ATA_MWDMA2,
262+
.udma_mask = ATA_UDMA6,
263+
.pio_mask = ATA_PIO4,
264+
.port_ops = &pata_ftide010_port_ops,
267265
};
268266

269267
#if IS_ENABLED(CONFIG_SATA_GEMINI)
@@ -349,6 +347,7 @@ static int pata_ftide010_gemini_cable_detect(struct ata_port *ap)
349347
}
350348

351349
static int pata_ftide010_gemini_init(struct ftide010 *ftide,
350+
struct ata_port_info *pi,
352351
bool is_ata1)
353352
{
354353
struct device *dev = ftide->dev;
@@ -373,7 +372,13 @@ static int pata_ftide010_gemini_init(struct ftide010 *ftide,
373372

374373
/* Flag port as SATA-capable */
375374
if (gemini_sata_bridge_enabled(sg, is_ata1))
376-
ftide010_port_info[0].flags |= ATA_FLAG_SATA;
375+
pi->flags |= ATA_FLAG_SATA;
376+
377+
/* This device has broken DMA, only PIO works */
378+
if (of_machine_is_compatible("itian,sq201")) {
379+
pi->mwdma_mask = 0;
380+
pi->udma_mask = 0;
381+
}
377382

378383
/*
379384
* We assume that a simple 40-wire cable is used in the PATA mode.
@@ -435,6 +440,7 @@ static int pata_ftide010_gemini_init(struct ftide010 *ftide,
435440
}
436441
#else
437442
static int pata_ftide010_gemini_init(struct ftide010 *ftide,
443+
struct ata_port_info *pi,
438444
bool is_ata1)
439445
{
440446
return -ENOTSUPP;
@@ -446,7 +452,7 @@ static int pata_ftide010_probe(struct platform_device *pdev)
446452
{
447453
struct device *dev = &pdev->dev;
448454
struct device_node *np = dev->of_node;
449-
const struct ata_port_info pi = ftide010_port_info[0];
455+
struct ata_port_info pi = ftide010_port_info;
450456
const struct ata_port_info *ppi[] = { &pi, NULL };
451457
struct ftide010 *ftide;
452458
struct resource *res;
@@ -490,6 +496,7 @@ static int pata_ftide010_probe(struct platform_device *pdev)
490496
* are ATA0. This will also set up the cable types.
491497
*/
492498
ret = pata_ftide010_gemini_init(ftide,
499+
&pi,
493500
(res->start == 0x63400000));
494501
if (ret)
495502
goto err_dis_clk;

0 commit comments

Comments
 (0)