From: Jiufei Xue <jiufei.xue@linux.alibaba.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Shaohua Li <shli@kernel.org>, Jens Axboe <axboe@kernel.dk>,
linux-block <linux-block@vger.kernel.org>,
caspar@linux.alibaba.com, Joseph Qi <joseph.qi@linux.alibaba.com>
Subject: Re: [PATCH 2/4] block: bio_check_eod() needs to consider partition
Date: Thu, 1 Mar 2018 09:23:06 +0800 [thread overview]
Message-ID: <431e8dd7-1e44-2dea-8e48-4f2400e01e1e@linux.alibaba.com> (raw)
In-Reply-To: <20180228174809.GA18158@lst.de>
Hi Christoph,
thanks for your quick reply.
On 2018/3/1 上午1:48, Christoph Hellwig wrote:
> Hmm. I'd rather just kill off bio_check_eod and move the check
> to blk_partition_remap so that we only have to check once.
>
I think the check should be done twice if the bi_partno is not zero,
one for the partition, and another for the whole disk after remap which
is add in the commit 5ddfe9691c91
("md: check bio address after mapping through partitions").
Thanks,
Jiufei
> What do you think of this version? Probably needs to be split into
> one or two prep patches and the real change.
>
> diff --git a/block/blk-core.c b/block/blk-core.c
> index 3ba4326a63b5..36a3cb042ca7 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -2009,7 +2009,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)
> return BLK_QC_T_NONE;
> }
>
> -static void handle_bad_sector(struct bio *bio)
> +static void handle_bad_sector(struct bio *bio, sector_t maxsector)
> {
> char b[BDEVNAME_SIZE];
>
> @@ -2017,7 +2017,7 @@ static void handle_bad_sector(struct bio *bio)
> printk(KERN_INFO "%s: rw=%d, want=%Lu, limit=%Lu\n",
> bio_devname(bio, b), bio->bi_opf,
> (unsigned long long)bio_end_sector(bio),
> - (long long)get_capacity(bio->bi_disk));
> + (long long)maxsector);
> }
>
> #ifdef CONFIG_FAIL_MAKE_REQUEST
> @@ -2060,57 +2060,47 @@ static inline bool should_fail_request(struct hd_struct *part,
> */
> static inline int blk_partition_remap(struct bio *bio)
> {
> - struct hd_struct *p;
> - int ret = 0;
> + sector_t maxsector = get_capacity(bio->bi_disk);
> + int nr_sectors = bio_sectors(bio);
>
> /*
> * Zone reset does not include bi_size so bio_sectors() is always 0.
> * Include a test for the reset op code and perform the remap if needed.
> */
> - if (!bio->bi_partno ||
> - (!bio_sectors(bio) && bio_op(bio) != REQ_OP_ZONE_RESET))
> + if (!nr_sectors && bio_op(bio) != REQ_OP_ZONE_RESET)
> return 0;
>
> - rcu_read_lock();
> - p = __disk_get_part(bio->bi_disk, bio->bi_partno);
> - if (likely(p && !should_fail_request(p, bio->bi_iter.bi_size))) {
> + if (bio->bi_partno) {
> + struct hd_struct *p;
> +
> + rcu_read_lock();
> + p = __disk_get_part(bio->bi_disk, bio->bi_partno);
> + if (unlikely(!p ||
> + should_fail_request(p, bio->bi_iter.bi_size))) {
> + rcu_read_unlock();
> + pr_info("%s: fail for partition %d\n",
> + __func__, bio->bi_partno);
> + return -EIO;
> + }
> +
> bio->bi_iter.bi_sector += p->start_sect;
> bio->bi_partno = 0;
> trace_block_bio_remap(bio->bi_disk->queue, bio, part_devt(p),
> bio->bi_iter.bi_sector - p->start_sect);
> - } else {
> - printk("%s: fail for partition %d\n", __func__, bio->bi_partno);
> - ret = -EIO;
> + maxsector = part_nr_sects_read(p);
> + rcu_read_unlock();
> }
> - rcu_read_unlock();
>
> - return ret;
> -}
> -
> -/*
> - * Check whether this bio extends beyond the end of the device.
> - */
> -static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
> -{
> - sector_t maxsector;
> -
> - if (!nr_sectors)
> - return 0;
> -
> - /* Test device or partition size, when known. */
> - maxsector = get_capacity(bio->bi_disk);
> - if (maxsector) {
> - sector_t sector = bio->bi_iter.bi_sector;
> -
> - if (maxsector < nr_sectors || maxsector - nr_sectors < sector) {
> - /*
> - * This may well happen - the kernel calls bread()
> - * without checking the size of the device, e.g., when
> - * mounting a device.
> - */
> - handle_bad_sector(bio);
> - return 1;
> - }
> + /*
> + * Check whether this bio extends beyond the end of the device or
> + * partition. This may well happen - the kernel calls bread() without
> + * checking the size of the device, e.g., when mounting a file system.
> + */
> + if (nr_sectors && maxsector &&
> + (nr_sectors > maxsector ||
> + bio->bi_iter.bi_sector > maxsector - nr_sectors)) {
> + handle_bad_sector(bio, maxsector);
> + return -EIO;
> }
>
> return 0;
> @@ -2126,9 +2116,6 @@ generic_make_request_checks(struct bio *bio)
>
> might_sleep();
>
> - if (bio_check_eod(bio, nr_sectors))
> - goto end_io;
> -
> q = bio->bi_disk->queue;
> if (unlikely(!q)) {
> printk(KERN_ERR
> @@ -2152,9 +2139,6 @@ generic_make_request_checks(struct bio *bio)
> if (blk_partition_remap(bio))
> goto end_io;
>
> - if (bio_check_eod(bio, nr_sectors))
> - goto end_io;
> -
> /*
> * Filter flush bio's early so that make_request based
> * drivers without flush support don't have to worry
>
next prev parent reply other threads:[~2018-03-01 1:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-27 12:07 [PATCH V2 0/4] fix a few problems in block layer Jiufei Xue
2018-02-27 12:10 ` [PATCH 1/4] block: fix the count of PGPGOUT for WRITE_SAME Jiufei Xue
2018-02-27 12:10 ` [PATCH 3/4] block: display the correct diskname for bio Jiufei Xue
2018-02-28 17:07 ` Christoph Hellwig
2018-02-27 12:10 ` [PATCH 4/4] block: fix a typo Jiufei Xue
2018-02-28 17:07 ` Christoph Hellwig
2018-02-27 12:11 ` [PATCH 2/4] block: bio_check_eod() needs to consider partition Jiufei Xue
2018-02-28 17:48 ` Christoph Hellwig
2018-03-01 1:23 ` Jiufei Xue [this message]
2018-03-08 7:44 ` Christoph Hellwig
2018-03-01 15:41 ` [PATCH V2 0/4] fix a few problems in block layer Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2018-02-26 12:01 [PATCH " Jiufei Xue
2018-02-26 12:04 ` [PATCH 2/4] block: bio_check_eod() needs to consider partition Jiufei Xue
2018-02-26 21:03 ` Omar Sandoval
2018-02-27 0:11 ` Christoph Hellwig
2018-02-27 4:51 ` Jiufei Xue
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=431e8dd7-1e44-2dea-8e48-4f2400e01e1e@linux.alibaba.com \
--to=jiufei.xue@linux.alibaba.com \
--cc=axboe@kernel.dk \
--cc=caspar@linux.alibaba.com \
--cc=hch@lst.de \
--cc=joseph.qi@linux.alibaba.com \
--cc=linux-block@vger.kernel.org \
--cc=shli@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox