Skip to content

Instantly share code, notes, and snippets.

@vejeta
Created May 16, 2023 12:43
Show Gist options
  • Save vejeta/9078219f082d2bfd62b08b6eada780e6 to your computer and use it in GitHub Desktop.
Save vejeta/9078219f082d2bfd62b08b6eada780e6 to your computer and use it in GitHub Desktop.
Tentative fix for nvidia-legacy-340xx-kernel-dkms 340.108-18 module for Linux 6.3.x
unchanged:
--- a/nv-mmap.c 2023-05-16 13:39:04.867479247 +0200
+++ b/nv-mmap.c 2023-05-16 13:47:10.858833967 +0200
@@ -312,7 +312,7 @@ int nvidia_mmap(
goto done;
}
- vma->vm_flags |= VM_IO;
+ vm_flags_set(vma, VM_IO);
}
else
{
@@ -363,8 +363,8 @@ int nvidia_mmap(
NV_PRINT_AT(NV_DBG_MEMINFO, at);
- vma->vm_flags |= (VM_IO | VM_LOCKED | VM_RESERVED);
- vma->vm_flags |= (VM_DONTEXPAND | VM_DONTDUMP);
+ vm_flags_set(vma, (VM_IO | VM_LOCKED | VM_RESERVED));
+ vm_flags_set(vma, (VM_DONTEXPAND | VM_DONTDUMP));
}
if (status == 0)
@@ -374,8 +374,8 @@ int nvidia_mmap(
if ((prot & NV_PROTECT_WRITEABLE) == 0)
{
vma->vm_page_prot = NV_PGPROT_READ_ONLY(vma->vm_page_prot);
- vma->vm_flags &= ~VM_WRITE;
- vma->vm_flags &= ~VM_MAYWRITE;
+ vm_flags_clear(vma, VM_WRITE);
+ vm_flags_clear(vma, VM_MAYWRITE);
}
vma->vm_ops = &nv_vm_ops;
only in patch2:
unchanged:
--- a/uvm/nvidia_uvm_lite.c 2023-05-16 14:12:38.752334301 +0200
+++ b/uvm/nvidia_uvm_lite.c 2023-05-16 14:20:31.667111795 +0200
@@ -1537,9 +1537,9 @@ static int uvmlite_mmap(struct file * fi
vma->vm_ops = &uvmlite_vma_ops;
// Prohibit copying the vma on fork().
- vma->vm_flags |= VM_DONTCOPY;
+ vm_flags_set(vma, VM_DONTCOPY);
// Prohibt mremap() that would expand the vma.
- vma->vm_flags |= VM_DONTEXPAND;
+ vm_flags_set(vma, VM_DONTEXPAND);
// Other cases of vma modification are detected in _mmap_open().
@@ -1558,9 +1558,9 @@ static int uvmlite_mmap(struct file * fi
return -EINVAL;
vma->vm_ops = &counters_vma_ops;
- vma->vm_flags &= ~VM_MAYWRITE;
+ vm_flags_clear(vma, VM_MAYWRITE);
// prevent vm_insert_page from modifying the vma's flags:
- vma->vm_flags |= VM_MIXEDMAP;
+ vm_flags_set(vma, VM_MIXEDMAP);
ret = 0;
}
UVM_DBG_PRINT_RL("vma 0x%p [0x%p, 0x%p) ret %d pgoff"
@@ -2539,8 +2539,9 @@ static void _set_vma_inaccessible(struct
// Subsequent access from userspace after the pages are unmapped will cause
// a SIGSEGV.
//
- vma->vm_flags &= ~(VM_READ|VM_MAYREAD);
- vma->vm_flags &= ~(VM_WRITE|VM_MAYWRITE);
+ vm_flags_clear(vma, (VM_READ|VM_MAYREAD));
+ vm_flags_clear(vma, (VM_WRITE|VM_MAYWRITE));
+
}
//
@@ -2548,8 +2549,9 @@ static void _set_vma_inaccessible(struct
//
static void _set_vma_accessible(struct vm_area_struct * vma)
{
- vma->vm_flags |= (VM_READ|VM_MAYREAD);
- vma->vm_flags |= (VM_WRITE|VM_MAYWRITE);
+ vm_flags_set(vma, (VM_READ|VM_MAYREAD));
+ vm_flags_set(vma, (VM_WRITE|VM_MAYWRITE));
+
}
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment