On Mon, Jan 11, 2021 at 07:43:35AM -0800, Marc Orr wrote:
This patch updates dma_direct_unmap_sg() to mark each scatter/gather entry invalid, after it's unmapped. This fixes two issues:
- It makes the unmapping code able to tolerate a double unmap.
- It prevents the NVMe driver from erroneously treating an unmapped DMA
address as mapped.
The bug that motivated this patch was the following sequence, which occurred within the NVMe driver, with the kernel flag `swiotlb=force`.
- NVMe driver calls dma_direct_map_sg()
- dma_direct_map_sg() fails part way through the scatter gather/list
- dma_direct_map_sg() calls dma_direct_unmap_sg() to unmap any entries succeeded.
- NVMe driver calls dma_direct_unmap_sg(), redundantly, leading to a double unmap, which is a bug.
With this patch, a hadoop workload running on a cluster of three AMD SEV VMs, is able to succeed. Without the patch, the hadoop workload suffers application-level and even VM-level failures.
Tested-by: Jianxiong Gao jxgao@google.com Tested-by: Marc Orr marcorr@google.com Reviewed-by: Jianxiong Gao jxgao@google.com Signed-off-by: Marc Orr marcorr@google.com
kernel/dma/direct.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read: https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html for how to do this properly.
</formletter>