From ca611e4d0e144e94d4f87b078fe6bbfd68c2af12 Mon Sep 17 00:00:00 2001 From: Allen Martin Date: Mon, 3 Dec 2018 15:51:40 -0800 Subject: [PATCH] gpu: nvgpu: verify usermode mapping is at least PAGE_SIZE This is part of a move to 64KiB for usermode mapping to fix failures when the system page size is 64KiB. When remapping or zapping the vma, use the existing size, not hardcoded size. Also change the verification of the size when creating the mapping to verify it is at least as big as PAGE_SIZE. This allows 4KiB mappings to continue to work until nvrm_gpu is changed to use 64KiB mappings. Bug 2441531 Change-Id: I447ef8e9f84e6d70bbe96b527e267ec41c5630b8 Signed-off-by: Allen Martin Reviewed-on: https://git-master.nvidia.com/r/1964687 Reviewed-by: svc-mobile-coverity GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c index 4381c378a..90e506fc6 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c @@ -1957,7 +1957,7 @@ int gk20a_ctrl_dev_mmap(struct file *filp, struct vm_area_struct *vma) if (priv->usermode_vma.vma != NULL) return -EBUSY; - if (vma->vm_end - vma->vm_start != SZ_4K) + if (vma->vm_end - vma->vm_start < PAGE_SIZE) return -EINVAL; if (vma->vm_pgoff != 0UL) @@ -2007,7 +2007,8 @@ static void alter_usermode_mapping(struct gk20a *g, down_write(&vma->vm_mm->mmap_sem); if (poweroff) { - err = zap_vma_ptes(vma, vma->vm_start, SZ_4K); + err = zap_vma_ptes(vma, vma->vm_start, + vma->vm_end - vma->vm_start); if (err == 0) { vma->vm_flags = VM_NONE; } else { @@ -2017,7 +2018,7 @@ static void alter_usermode_mapping(struct gk20a *g, vma->vm_flags = priv->usermode_vma.flags; err = io_remap_pfn_range(vma, vma->vm_start, l->usermode_regs_bus_addr >> PAGE_SHIFT, - SZ_4K, vma->vm_page_prot); + vma->vm_end - vma->vm_start, vma->vm_page_prot); if (err != 0) { nvgpu_err(g, "can't restore usermode mapping"); vma->vm_flags = VM_NONE;