Skip to content

Commit a381884

Browse files
committed
Merge tag 'for-linus-20180608' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "A few fixes for this merge window, where some of them should go in sooner rather than later, hence a new pull this week. This pull request contains: - Set of NVMe fixes, mostly follow up cleanups/fixes to the queue changes, but also teardown/removal and misc changes (Christop/Dan/ Johannes/Sagi/Steve). - Two lightnvm fixes for issues that showed up in this window (Colin/Wei). - Failfast/driver flags inheritance for flush requests (Hannes). - The md device put sanitization and fix (Kent). - dm bio_set inheritance fix (me). - nbd discard granularity fix (Josef). - nbd consistency in command printing (Kevin). - Loop recursion validation fix (Ted). - Partition overlap check (Wang)" [ .. and now my build is warning-free again thanks to the md fix - Linus ] * tag 'for-linus-20180608' of git://git.kernel.dk/linux-block: (22 commits) nvme: cleanup double shift issue nvme-pci: make CMB SQ mod-param read-only nvme-pci: unquiesce dead controller queues nvme-pci: remove HMB teardown on reset nvme-pci: queue creation fixes nvme-pci: remove unnecessary completion doorbell check nvme-pci: remove unnecessary nested locking nvmet: filter newlines from user input nvme-rdma: correctly check for target keyed sgl support nvme: don't hold nvmf_transports_rwsem for more than transport lookups nvmet: return all zeroed buffer when we can't find an active namespace md: Unify mddev destruction paths dm: use bioset_init_from_src() to copy bio_set block: add bioset_init_from_src() helper block: always set partition number to '0' in blk_partition_remap() block: pass failfast and driver-specific flags to flush requests nbd: set discard_alignment to the granularity nbd: Consistently use request pointer in debug messages. block: add verifier for cmdline partition lightnvm: pblk: fix resource leak of invalid_bitmap ...
2 parents 68cc38f + 7701619 commit a381884

19 files changed

Lines changed: 204 additions & 124 deletions

File tree

‎block/bio.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,24 @@ int bioset_init(struct bio_set *bs,
19971997
}
19981998
EXPORT_SYMBOL(bioset_init);
19991999

2000+
/*
2001+
* Initialize and setup a new bio_set, based on the settings from
2002+
* another bio_set.
2003+
*/
2004+
int bioset_init_from_src(struct bio_set *bs, struct bio_set *src)
2005+
{
2006+
int flags;
2007+
2008+
flags = 0;
2009+
if (src->bvec_pool.min_nr)
2010+
flags |= BIOSET_NEED_BVECS;
2011+
if (src->rescue_workqueue)
2012+
flags |= BIOSET_NEED_RESCUER;
2013+
2014+
return bioset_init(bs, src->bio_pool.min_nr, src->front_pad, flags);
2015+
}
2016+
EXPORT_SYMBOL(bioset_init_from_src);
2017+
20002018
#ifdef CONFIG_BLK_CGROUP
20012019

20022020
/**

‎block/blk-core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2220,10 +2220,10 @@ static inline int blk_partition_remap(struct bio *bio)
22202220
if (bio_check_eod(bio, part_nr_sects_read(p)))
22212221
goto out;
22222222
bio->bi_iter.bi_sector += p->start_sect;
2223-
bio->bi_partno = 0;
22242223
trace_block_bio_remap(bio->bi_disk->queue, bio, part_devt(p),
22252224
bio->bi_iter.bi_sector - p->start_sect);
22262225
}
2226+
bio->bi_partno = 0;
22272227
ret = 0;
22282228
out:
22292229
rcu_read_unlock();

‎block/blk-flush.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ enum {
9494
};
9595

9696
static bool blk_kick_flush(struct request_queue *q,
97-
struct blk_flush_queue *fq);
97+
struct blk_flush_queue *fq, unsigned int flags);
9898

9999
static unsigned int blk_flush_policy(unsigned long fflags, struct request *rq)
100100
{
@@ -212,7 +212,7 @@ static bool blk_flush_complete_seq(struct request *rq,
212212
BUG();
213213
}
214214

215-
kicked = blk_kick_flush(q, fq);
215+
kicked = blk_kick_flush(q, fq, rq->cmd_flags);
216216
return kicked | queued;
217217
}
218218

@@ -281,6 +281,7 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
281281
* blk_kick_flush - consider issuing flush request
282282
* @q: request_queue being kicked
283283
* @fq: flush queue
284+
* @flags: cmd_flags of the original request
284285
*
285286
* Flush related states of @q have changed, consider issuing flush request.
286287
* Please read the comment at the top of this file for more info.
@@ -291,7 +292,8 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
291292
* RETURNS:
292293
* %true if flush was issued, %false otherwise.
293294
*/
294-
static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq)
295+
static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
296+
unsigned int flags)
295297
{
296298
struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
297299
struct request *first_rq =
@@ -346,6 +348,7 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq)
346348
}
347349

348350
flush_rq->cmd_flags = REQ_OP_FLUSH | REQ_PREFLUSH;
351+
flush_rq->cmd_flags |= (flags & REQ_DRV) | (flags & REQ_FAILFAST_MASK);
349352
flush_rq->rq_flags |= RQF_FLUSH_SEQ;
350353
flush_rq->rq_disk = first_rq->rq_disk;
351354
flush_rq->end_io = flush_end_io;

‎block/partitions/cmdline.c‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,62 @@ static int __init cmdline_parts_setup(char *s)
5858
}
5959
__setup("blkdevparts=", cmdline_parts_setup);
6060

61+
static bool has_overlaps(sector_t from, sector_t size,
62+
sector_t from2, sector_t size2)
63+
{
64+
sector_t end = from + size;
65+
sector_t end2 = from2 + size2;
66+
67+
if (from >= from2 && from < end2)
68+
return true;
69+
70+
if (end > from2 && end <= end2)
71+
return true;
72+
73+
if (from2 >= from && from2 < end)
74+
return true;
75+
76+
if (end2 > from && end2 <= end)
77+
return true;
78+
79+
return false;
80+
}
81+
82+
static inline void overlaps_warns_header(void)
83+
{
84+
pr_warn("Overlapping partitions are used in command line partitions.");
85+
pr_warn("Don't use filesystems on overlapping partitions:");
86+
}
87+
88+
static void cmdline_parts_verifier(int slot, struct parsed_partitions *state)
89+
{
90+
int i;
91+
bool header = true;
92+
93+
for (; slot < state->limit && state->parts[slot].has_info; slot++) {
94+
for (i = slot+1; i < state->limit && state->parts[i].has_info;
95+
i++) {
96+
if (has_overlaps(state->parts[slot].from,
97+
state->parts[slot].size,
98+
state->parts[i].from,
99+
state->parts[i].size)) {
100+
if (header) {
101+
header = false;
102+
overlaps_warns_header();
103+
}
104+
pr_warn("%s[%llu,%llu] overlaps with "
105+
"%s[%llu,%llu].",
106+
state->parts[slot].info.volname,
107+
(u64)state->parts[slot].from << 9,
108+
(u64)state->parts[slot].size << 9,
109+
state->parts[i].info.volname,
110+
(u64)state->parts[i].from << 9,
111+
(u64)state->parts[i].size << 9);
112+
}
113+
}
114+
}
115+
}
116+
61117
/*
62118
* Purpose: allocate cmdline partitions.
63119
* Returns:
@@ -93,6 +149,7 @@ int cmdline_partition(struct parsed_partitions *state)
93149
disk_size = get_capacity(state->bdev->bd_disk) << 9;
94150

95151
cmdline_parts_set(parts, disk_size, 1, add_part, (void *)state);
152+
cmdline_parts_verifier(1, state);
96153

97154
strlcat(state->pp_buf, "\n", PAGE_SIZE);
98155

‎drivers/block/loop.c‎

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,36 @@ static void loop_reread_partitions(struct loop_device *lo,
647647
__func__, lo->lo_number, lo->lo_file_name, rc);
648648
}
649649

650+
static inline int is_loop_device(struct file *file)
651+
{
652+
struct inode *i = file->f_mapping->host;
653+
654+
return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
655+
}
656+
657+
static int loop_validate_file(struct file *file, struct block_device *bdev)
658+
{
659+
struct inode *inode = file->f_mapping->host;
660+
struct file *f = file;
661+
662+
/* Avoid recursion */
663+
while (is_loop_device(f)) {
664+
struct loop_device *l;
665+
666+
if (f->f_mapping->host->i_bdev == bdev)
667+
return -EBADF;
668+
669+
l = f->f_mapping->host->i_bdev->bd_disk->private_data;
670+
if (l->lo_state == Lo_unbound) {
671+
return -EINVAL;
672+
}
673+
f = l->lo_backing_file;
674+
}
675+
if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
676+
return -EINVAL;
677+
return 0;
678+
}
679+
650680
/*
651681
* loop_change_fd switched the backing store of a loopback device to
652682
* a new file. This is useful for operating system installers to free up
@@ -676,14 +706,15 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
676706
if (!file)
677707
goto out;
678708

709+
error = loop_validate_file(file, bdev);
710+
if (error)
711+
goto out_putf;
712+
679713
inode = file->f_mapping->host;
680714
old_file = lo->lo_backing_file;
681715

682716
error = -EINVAL;
683717

684-
if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
685-
goto out_putf;
686-
687718
/* size of the new backing store needs to be the same */
688719
if (get_loop_size(lo, file) != get_loop_size(lo, old_file))
689720
goto out_putf;
@@ -709,13 +740,6 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
709740
return error;
710741
}
711742

712-
static inline int is_loop_device(struct file *file)
713-
{
714-
struct inode *i = file->f_mapping->host;
715-
716-
return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
717-
}
718-
719743
/* loop sysfs attributes */
720744

721745
static ssize_t loop_attr_show(struct device *dev, char *page,
@@ -881,7 +905,7 @@ static int loop_prepare_queue(struct loop_device *lo)
881905
static int loop_set_fd(struct loop_device *lo, fmode_t mode,
882906
struct block_device *bdev, unsigned int arg)
883907
{
884-
struct file *file, *f;
908+
struct file *file;
885909
struct inode *inode;
886910
struct address_space *mapping;
887911
int lo_flags = 0;
@@ -900,29 +924,13 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
900924
if (lo->lo_state != Lo_unbound)
901925
goto out_putf;
902926

903-
/* Avoid recursion */
904-
f = file;
905-
while (is_loop_device(f)) {
906-
struct loop_device *l;
907-
908-
if (f->f_mapping->host->i_bdev == bdev)
909-
goto out_putf;
910-
911-
l = f->f_mapping->host->i_bdev->bd_disk->private_data;
912-
if (l->lo_state == Lo_unbound) {
913-
error = -EINVAL;
914-
goto out_putf;
915-
}
916-
f = l->lo_backing_file;
917-
}
927+
error = loop_validate_file(file, bdev);
928+
if (error)
929+
goto out_putf;
918930

919931
mapping = file->f_mapping;
920932
inode = mapping->host;
921933

922-
error = -EINVAL;
923-
if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
924-
goto out_putf;
925-
926934
if (!(file->f_mode & FMODE_WRITE) || !(mode & FMODE_WRITE) ||
927935
!file->f_op->write_iter)
928936
lo_flags |= LO_FLAGS_READ_ONLY;

‎drivers/block/nbd.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ static void nbd_size_update(struct nbd_device *nbd)
246246

247247
if (config->flags & NBD_FLAG_SEND_TRIM) {
248248
nbd->disk->queue->limits.discard_granularity = config->blksize;
249+
nbd->disk->queue->limits.discard_alignment = config->blksize;
249250
blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX);
250251
}
251252
blk_queue_logical_block_size(nbd->disk->queue, config->blksize);
@@ -275,7 +276,7 @@ static void nbd_complete_rq(struct request *req)
275276
{
276277
struct nbd_cmd *cmd = blk_mq_rq_to_pdu(req);
277278

278-
dev_dbg(nbd_to_dev(cmd->nbd), "request %p: %s\n", cmd,
279+
dev_dbg(nbd_to_dev(cmd->nbd), "request %p: %s\n", req,
279280
cmd->status ? "failed" : "done");
280281

281282
blk_mq_end_request(req, cmd->status);
@@ -482,7 +483,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
482483
memcpy(request.handle, &tag, sizeof(tag));
483484

484485
dev_dbg(nbd_to_dev(nbd), "request %p: sending control (%s@%llu,%uB)\n",
485-
cmd, nbdcmd_to_ascii(type),
486+
req, nbdcmd_to_ascii(type),
486487
(unsigned long long)blk_rq_pos(req) << 9, blk_rq_bytes(req));
487488
result = sock_xmit(nbd, index, 1, &from,
488489
(type == NBD_CMD_WRITE) ? MSG_MORE : 0, &sent);
@@ -518,7 +519,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
518519
int flags = is_last ? 0 : MSG_MORE;
519520

520521
dev_dbg(nbd_to_dev(nbd), "request %p: sending %d bytes data\n",
521-
cmd, bvec.bv_len);
522+
req, bvec.bv_len);
522523
iov_iter_bvec(&from, ITER_BVEC | WRITE,
523524
&bvec, 1, bvec.bv_len);
524525
if (skip) {
@@ -610,7 +611,7 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index)
610611
return cmd;
611612
}
612613

613-
dev_dbg(nbd_to_dev(nbd), "request %p: got reply\n", cmd);
614+
dev_dbg(nbd_to_dev(nbd), "request %p: got reply\n", req);
614615
if (rq_data_dir(req) != WRITE) {
615616
struct req_iterator iter;
616617
struct bio_vec bvec;
@@ -637,7 +638,7 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index)
637638
return ERR_PTR(-EIO);
638639
}
639640
dev_dbg(nbd_to_dev(nbd), "request %p: got %d bytes data\n",
640-
cmd, bvec.bv_len);
641+
req, bvec.bv_len);
641642
}
642643
} else {
643644
/* See the comment in nbd_queue_rq. */
@@ -1062,6 +1063,7 @@ static void nbd_config_put(struct nbd_device *nbd)
10621063

10631064
nbd->tag_set.timeout = 0;
10641065
nbd->disk->queue->limits.discard_granularity = 0;
1066+
nbd->disk->queue->limits.discard_alignment = 0;
10651067
blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX);
10661068
blk_queue_flag_clear(QUEUE_FLAG_DISCARD, nbd->disk->queue);
10671069

@@ -1516,6 +1518,7 @@ static int nbd_dev_add(int index)
15161518
blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
15171519
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, disk->queue);
15181520
disk->queue->limits.discard_granularity = 0;
1521+
disk->queue->limits.discard_alignment = 0;
15191522
blk_queue_max_discard_sectors(disk->queue, 0);
15201523
blk_queue_max_segment_size(disk->queue, UINT_MAX);
15211524
blk_queue_max_segments(disk->queue, USHRT_MAX);

‎drivers/lightnvm/pblk-gc.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static void pblk_gc_line_prepare_ws(struct work_struct *work)
203203
if (!lba_list) {
204204
pr_err("pblk: could not interpret emeta (line %d)\n",
205205
line->id);
206-
goto fail_free_ws;
206+
goto fail_free_invalid_bitmap;
207207
}
208208
}
209209

@@ -280,6 +280,7 @@ static void pblk_gc_line_prepare_ws(struct work_struct *work)
280280
kfree(gc_rq);
281281
fail_free_lba_list:
282282
pblk_mfree(lba_list, l_mg->emeta_alloc_type);
283+
fail_free_invalid_bitmap:
283284
kfree(invalid_bitmap);
284285
fail_free_ws:
285286
kfree(line_ws);

‎drivers/lightnvm/pblk-init.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "pblk.h"
2222

23-
unsigned int write_buffer_size;
23+
static unsigned int write_buffer_size;
2424

2525
module_param(write_buffer_size, uint, 0644);
2626
MODULE_PARM_DESC(write_buffer_size, "number of entries in a write buffer");

0 commit comments

Comments
 (0)