On Mon, Aug 17, 2020 at 06:01:30PM +0800, Ming Lei wrote:
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 9b15d109a6b2 ("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.
This patch looks good:
Reviewed-by: Christoph Hellwig hch@lst.de
If you have a few spare cycles, can you kill QUEUE_FLAG_DISCARD and just key off discard support based on checking discard_granularity to avoid problems like this in the future?