Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mspec: convert nopfn to fault

[akpm@linux-foundation.org: remove unused variable]
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Nick Piggin and committed by
Linus Torvalds
efe9e779 ffc6421f

+14 -9
+14 -9
drivers/char/mspec.c
··· 193 193 } 194 194 195 195 /* 196 - * mspec_nopfn 196 + * mspec_fault 197 197 * 198 198 * Creates a mspec page and maps it to user space. 199 199 */ 200 - static unsigned long 201 - mspec_nopfn(struct vm_area_struct *vma, unsigned long address) 200 + static int 201 + mspec_fault(struct vm_area_struct *vma, struct vm_fault *vmf) 202 202 { 203 203 unsigned long paddr, maddr; 204 204 unsigned long pfn; 205 - int index; 205 + pgoff_t index = vmf->pgoff; 206 206 struct vma_data *vdata = vma->vm_private_data; 207 207 208 - BUG_ON(address < vdata->vm_start || address >= vdata->vm_end); 209 - index = (address - vdata->vm_start) >> PAGE_SHIFT; 210 208 maddr = (volatile unsigned long) vdata->maddr[index]; 211 209 if (maddr == 0) { 212 210 maddr = uncached_alloc_page(numa_node_id(), 1); 213 211 if (maddr == 0) 214 - return NOPFN_OOM; 212 + return VM_FAULT_OOM; 215 213 216 214 spin_lock(&vdata->lock); 217 215 if (vdata->maddr[index] == 0) { ··· 229 231 230 232 pfn = paddr >> PAGE_SHIFT; 231 233 232 - return pfn; 234 + /* 235 + * vm_insert_pfn can fail with -EBUSY, but in that case it will 236 + * be because another thread has installed the pte first, so it 237 + * is no problem. 238 + */ 239 + vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, pfn); 240 + 241 + return VM_FAULT_NOPAGE; 233 242 } 234 243 235 244 static struct vm_operations_struct mspec_vm_ops = { 236 245 .open = mspec_open, 237 246 .close = mspec_close, 238 - .nopfn = mspec_nopfn 247 + .fault = mspec_fault, 239 248 }; 240 249 241 250 /*