From 5e854efa65da685678e2a618103e6d6d8acd48be Mon Sep 17 00:00:00 2001 From: Nicolin Chen Date: Thu, 27 Feb 2020 11:57:49 -0800 Subject: [PATCH] gpu: nvgpu: Maximize DMA segmentation boundary Linux kernel has a default 32-bit segmentation boundary for any device that doesn't explicitly configure it. When nvgpu tries to allocate a larger memory > 4GB, iommu_dma_map_sg() function in the kernel will take this boundary into account and add an internal padding to the allocated IOVA space: |<---IOVA space 1--->|<---padding--->|<---IOVA space 2--->| When DMA reads/writes the memory using this discountinued IOVA space, it may end up with accessing the padding part, instead of the IOVA space 2. So this patch adds dma_set_seg_boundary() to nvgpu driver, by maximizing the segmentation boundary up to DMA_BIT_MASK to ensure a continued IOVA space. Bug 200558567 Change-Id: I979d56681dddca56f1b02fce83dc81147a6b0d82 Signed-off-by: Nicolin Chen Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2304150 Tested-by: mobile promotions Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Pritesh Raithatha Reviewed-by: Puneet Saxena Reviewed-by: Chris Dragan Reviewed-by: Sachin Nikam Reviewed-by: Alex Waterman Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/os/linux/driver_common.c | 1 + drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/gpu/nvgpu/os/linux/driver_common.c b/drivers/gpu/nvgpu/os/linux/driver_common.c index 74f80fa5b..a1bba9cba 100644 --- a/drivers/gpu/nvgpu/os/linux/driver_common.c +++ b/drivers/gpu/nvgpu/os/linux/driver_common.c @@ -99,6 +99,7 @@ static void nvgpu_init_vars(struct gk20a *g) dma_set_mask(dev, platform->dma_mask); dma_set_coherent_mask(dev, platform->dma_mask); + dma_set_seg_boundary(dev, platform->dma_mask); nvgpu_init_list_node(&g->profiler_objects); diff --git a/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c b/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c index 091e35925..5c99eb35a 100644 --- a/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c +++ b/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c @@ -462,6 +462,7 @@ int vgpu_probe(struct platform_device *pdev) dma_set_mask(dev, platform->dma_mask); dma_set_coherent_mask(dev, platform->dma_mask); + dma_set_seg_boundary(dev, platform->dma_mask); gk20a->poll_timeout_default = NVGPU_DEFAULT_POLL_TIMEOUT_MS; gk20a->timeouts_disabled_by_user = false;