mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] block: Don't allow illegal discard requests
@ 2015-11-04  9:18 Jan Kara
  2015-11-04 10:46 ` kbuild test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Jan Kara @ 2015-11-04  9:18 UTC (permalink / raw)
  To: axboe; +Cc: LKML, linux-fsdevel, Jan Kara

Currently blkdev_issue_discard() doesn't check that submitted discard
request matches granularity required by the underlying device.
Submitting such requests to the device can have unexpected consequences
(e.g. brd driver just discards more / less data depending on how exactly
the request is aligned). So test that submitted discard request has the
granularity required by the driver.

Signed-off-by: Jan Kara <jack@suse.com>
---
 block/blk-lib.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index bd40292e5009..7170d02e9e9a 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -61,6 +61,13 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 	if (!blk_queue_discard(q))
 		return -EOPNOTSUPP;
 
+	if (q->limits.discard_granularity) {
+		unsigned int gran_sect = q->limits.discard_granularity >> 9;
+
+		if (sector % gran_sect || nr_sects % gran_sect)
+			return -EINVAL;
+	}
+
 	if (flags & BLKDEV_DISCARD_SECURE) {
 		if (!blk_queue_secdiscard(q))
 			return -EOPNOTSUPP;
-- 
2.1.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Don't allow illegal discard requests
  2015-11-04  9:18 [PATCH] block: Don't allow illegal discard requests Jan Kara
@ 2015-11-04 10:46 ` kbuild test robot
  2015-11-04 10:48 ` kbuild test robot
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2015-11-04 10:46 UTC (permalink / raw)
  To: Jan Kara; +Cc: kbuild-all, axboe, LKML, linux-fsdevel, Jan Kara

[-- Attachment #1: Type: text/plain, Size: 1299 bytes --]

Hi Jan,

[auto build test ERROR on: ext3/for_next]
[cannot apply to: v4.3 next-20151103]

url:    https://github.com/0day-ci/linux/commits/Jan-Kara/block-Don-t-allow-illegal-discard-requests/20151104-172203
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git for_next
config: arm-prima2_defconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=arm 

All errors (new ones prefixed by >>):

   block/built-in.o: In function `blkdev_issue_discard':
>> block/blk-lib.c:67: undefined reference to `__aeabi_uldivmod'
>> block/blk-lib.c:67: undefined reference to `__aeabi_uldivmod'

vim +67 block/blk-lib.c

    61		if (!blk_queue_discard(q))
    62			return -EOPNOTSUPP;
    63	
    64		if (q->limits.discard_granularity) {
    65			unsigned int gran_sect = q->limits.discard_granularity >> 9;
    66	
  > 67			if (sector % gran_sect || nr_sects % gran_sect)
    68				return -EINVAL;
    69		}
    70	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 12211 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Don't allow illegal discard requests
  2015-11-04  9:18 [PATCH] block: Don't allow illegal discard requests Jan Kara
  2015-11-04 10:46 ` kbuild test robot
@ 2015-11-04 10:48 ` kbuild test robot
  2015-11-04 10:53 ` kbuild test robot
  2015-11-04 11:30 ` Christoph Hellwig
  3 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2015-11-04 10:48 UTC (permalink / raw)
  To: Jan Kara; +Cc: kbuild-all, axboe, LKML, linux-fsdevel, Jan Kara

[-- Attachment #1: Type: text/plain, Size: 908 bytes --]

Hi Jan,

[auto build test ERROR on: ext3/for_next]
[cannot apply to: v4.3 next-20151103]

url:    https://github.com/0day-ci/linux/commits/Jan-Kara/block-Don-t-allow-illegal-discard-requests/20151104-172203
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git for_next
config: avr32-atngw100_defconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=avr32 

All errors (new ones prefixed by >>):

   block/built-in.o: In function `ll_back_merge_fn':
>> (.text+0x90dc): undefined reference to `__avr32_umod64'

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 11783 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Don't allow illegal discard requests
  2015-11-04  9:18 [PATCH] block: Don't allow illegal discard requests Jan Kara
  2015-11-04 10:46 ` kbuild test robot
  2015-11-04 10:48 ` kbuild test robot
@ 2015-11-04 10:53 ` kbuild test robot
  2015-11-04 11:30 ` Christoph Hellwig
  3 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2015-11-04 10:53 UTC (permalink / raw)
  To: Jan Kara; +Cc: kbuild-all, axboe, LKML, linux-fsdevel, Jan Kara

[-- Attachment #1: Type: text/plain, Size: 947 bytes --]

Hi Jan,

[auto build test ERROR on: ext3/for_next]
[cannot apply to: v4.3 next-20151103]

url:    https://github.com/0day-ci/linux/commits/Jan-Kara/block-Don-t-allow-illegal-discard-requests/20151104-172203
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git for_next
config: arm-sa1100 (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=arm 

All errors (new ones prefixed by >>):

   block/built-in.o: In function `blkdev_issue_discard':
>> :(.text+0xcdf4): undefined reference to `__umoddi3'
   :(.text+0xce0c): undefined reference to `__umoddi3'

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 21731 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Don't allow illegal discard requests
  2015-11-04  9:18 [PATCH] block: Don't allow illegal discard requests Jan Kara
                   ` (2 preceding siblings ...)
  2015-11-04 10:53 ` kbuild test robot
@ 2015-11-04 11:30 ` Christoph Hellwig
  2015-11-04 14:17   ` Jan Kara
  3 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2015-11-04 11:30 UTC (permalink / raw)
  To: Jan Kara; +Cc: axboe, LKML, linux-fsdevel

On Wed, Nov 04, 2015 at 10:18:41AM +0100, Jan Kara wrote:
> Currently blkdev_issue_discard() doesn't check that submitted discard
> request matches granularity required by the underlying device.
> Submitting such requests to the device can have unexpected consequences
> (e.g. brd driver just discards more / less data depending on how exactly
> the request is aligned). So test that submitted discard request has the
> granularity required by the driver.

How is this going to work with stacked drivers?  I think brd needs to
be fixed to take care of the granularity itself, just like we did for
request based drivers.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Don't allow illegal discard requests
  2015-11-04 11:30 ` Christoph Hellwig
@ 2015-11-04 14:17   ` Jan Kara
  0 siblings, 0 replies; 6+ messages in thread
From: Jan Kara @ 2015-11-04 14:17 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jan Kara, axboe, LKML, linux-fsdevel

On Wed 04-11-15 03:30:19, Christoph Hellwig wrote:
> On Wed, Nov 04, 2015 at 10:18:41AM +0100, Jan Kara wrote:
> > Currently blkdev_issue_discard() doesn't check that submitted discard
> > request matches granularity required by the underlying device.
> > Submitting such requests to the device can have unexpected consequences
> > (e.g. brd driver just discards more / less data depending on how exactly
> > the request is aligned). So test that submitted discard request has the
> > granularity required by the driver.
> 
> How is this going to work with stacked drivers?  I think brd needs to
> be fixed to take care of the granularity itself, just like we did for
> request based drivers.

So you mean that a stacked driver would split a discard request so that it
is no longer of the required granularity? OK, makes sense. I'll add the
check directly into brd itself.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-11-04 14:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-04  9:18 [PATCH] block: Don't allow illegal discard requests Jan Kara
2015-11-04 10:46 ` kbuild test robot
2015-11-04 10:48 ` kbuild test robot
2015-11-04 10:53 ` kbuild test robot
2015-11-04 11:30 ` Christoph Hellwig
2015-11-04 14:17   ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome