block: loop: set discard granularity and alignment for block device backed loop
Ming Lei authored
In case of block device backend, if the backend supports write zeros, the
loop device will set queue flag of QUEUE_FLAG_DISCARD. However,
limits.discard_granularity isn't setup, and this way is wrong,
see the following description in Documentation/ABI/testing/sysfs-block:

	A discard_granularity of 0 means that the device does not support
	discard functionality.

Especially 9b15d109 ("block: improve discard bio alignment in
__blkdev_issue_discard()") starts to take q->limits.discard_granularity
for computing max discard sectors. And zero discard granularity may cause
kernel oops, or fail discard request even though the loop queue claims
discard support via QUEUE_FLAG_DISCARD.

Fix the issue by setup discard granularity and alignment.

Fixes: c52abf56

 ("loop: Better discard support for block devices")
Signed-off-by: default avatarMing Lei <ming.lei@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarColy Li <colyli@suse.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Xiao Ni <xni@redhat.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Evan Green <evgreen@chromium.org>
Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Cc: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
bcb21c8c
Name Last commit Last update
Documentation Merge tag 'x86-urgent-2020-08-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
LICENSES LICENSES: Rename other to deprecated
arch parisc: fix PMD pages allocation by restoring pmd_alloc_one()
block blk-mq: order adding requests to hctx->dispatch and checking SCHED_RESTART
certs .gitignore: add SPDX License Identifier
crypto Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
drivers block: loop: set discard granularity and alignment for block device backed loop
fs Merge tag 'io_uring-5.9-2020-08-15' of git://git.kernel.dk/linux-block
include Merge tag 'io_uring-5.9-2020-08-15' of git://git.kernel.dk/linux-block
init Merge tag 'for-linus' of git://github.com/openrisc/linux
ipc ipc/shm.c: remove the superfluous break
kernel Merge tag 'io_uring-5.9-2020-08-15' of git://git.kernel.dk/linux-block
lib iomap: constify ioreadX() iomem argument (as in generic implementation)
mm Merge branch 'akpm' (patches from Andrew)
net Merge tag '9p-for-5.9-rc1' of git://github.com/martinetd/linux
samples Merge tag 'kbuild-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
scripts Merge tag 'kconfig-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
security Merge branch 'akpm' (patches from Andrew)
sound Merge tag 'sound-fix-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
tools Merge tag 'sh-for-5.9' of git://git.libc.org/linux-sh
usr Merge branch 'work.fdpic' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
virt Merge branch 'akpm' (patches from Andrew)
.clang-format block: add bio_for_each_bvec_all()
.cocciconfig scripts: add Linux .cocciconfig for coccinelle
.get_maintainer.ignore Opt out of scripts/get_maintainer.pl
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.