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 <amartin@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1964687
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Allen Martin
2018-12-03 15:51:40 -08:00
committed by mobile promotions
parent 0a90a5c5a9
commit ca611e4d0e

View File

@@ -1957,7 +1957,7 @@ int gk20a_ctrl_dev_mmap(struct file *filp, struct vm_area_struct *vma)
if (priv->usermode_vma.vma != NULL) if (priv->usermode_vma.vma != NULL)
return -EBUSY; return -EBUSY;
if (vma->vm_end - vma->vm_start != SZ_4K) if (vma->vm_end - vma->vm_start < PAGE_SIZE)
return -EINVAL; return -EINVAL;
if (vma->vm_pgoff != 0UL) if (vma->vm_pgoff != 0UL)
@@ -2007,7 +2007,8 @@ static void alter_usermode_mapping(struct gk20a *g,
down_write(&vma->vm_mm->mmap_sem); down_write(&vma->vm_mm->mmap_sem);
if (poweroff) { 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) { if (err == 0) {
vma->vm_flags = VM_NONE; vma->vm_flags = VM_NONE;
} else { } else {
@@ -2017,7 +2018,7 @@ static void alter_usermode_mapping(struct gk20a *g,
vma->vm_flags = priv->usermode_vma.flags; vma->vm_flags = priv->usermode_vma.flags;
err = io_remap_pfn_range(vma, vma->vm_start, err = io_remap_pfn_range(vma, vma->vm_start,
l->usermode_regs_bus_addr >> PAGE_SHIFT, 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) { if (err != 0) {
nvgpu_err(g, "can't restore usermode mapping"); nvgpu_err(g, "can't restore usermode mapping");
vma->vm_flags = VM_NONE; vma->vm_flags = VM_NONE;