nvme: Discard workaround for non-conformant devices
authorEduard Hasenleithner <eduard@hasenleithner.at>
Tue, 12 Nov 2019 20:55:01 +0000 (21:55 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 31 Dec 2019 15:45:24 +0000 (16:45 +0100)
commit8b0acb768a06083b0d28bace1481c1f6679e76f4
treefb8df6e6ae21180a4090ae6f85d6cee3a65fb52f
parenta09579b0c2e882f49e2a4d7ae40dbd5c1a4eb4bb
nvme: Discard workaround for non-conformant devices

[ Upstream commit 530436c45ef2e446c12538a400e465929a0b3ade ]

Users observe IOMMU related errors when performing discard on nvme from
non-compliant nvme devices reading beyond the end of the DMA mapped
ranges to discard.

Two different variants of this behavior have been observed: SM22XX
controllers round up the read size to a multiple of 512 bytes, and Phison
E12 unconditionally reads the maximum discard size allowed by the spec
(256 segments or 4kB).

Make nvme_setup_discard unconditionally allocate the maximum DSM buffer
so the driver DMA maps a memory range that will always succeed.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=202665
Signed-off-by: Eduard Hasenleithner <eduard@hasenleithner.at>
[changelog, use existing define, kernel coding style]
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/host/core.c