LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [patch 00/18] remove nopage
@ 2007-12-05  7:15 npiggin
  2007-12-05  7:15 ` [patch 01/18] ia64: ia32 nopage npiggin
                   ` (16 more replies)
  0 siblings, 17 replies; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

This patchset removes the 'nopage' from the tree.

I've gone through all the drivers and converted them to use fault as best
I can. When using fault, I've also tried to use vmf->pgoff rather than the
virtual address to index the content (which is preferred). Mostly it has
been OK, but DRM is a bit difficult, as it seems to use vma->vm_pgoff as
a 2nd dimension of addressing, so it remains unconverted.

I've also done some other things while going through at the code...

Converted incorrect OOM returns to SIGBUS.  OOM should only be returned as a
result of a memory allocation failure. We will actually want the fault path OOM
handling to be unified with the normal OOM killing path in future, and so
OOMing when we should be SIGBUSing means the box will panic if panic_on_oom is
set, or it will oom-kill random processes before retrying the fault, etc.
SIGBUS means something like "physical address (ie. after translation) does not
exist", which is appropriate AFAIKS in all cases I've converted.

Got rid of some bogus looking "disallow mremap" checks that just check for
address > vma->vm_end. Presumably this is supposed to prevent an mremap
expanding the mapping outside the limit of the underlying resource, but
actually mremap will update vma->vm_end, and anyway this condition is already
checked in the page fault code. Others seem to get this right by checking the
underlying resource itself. Others don't seem to even care.

There looks like a fair number of corruption / security problems with mremap,
so I've done an audit of the tree and tried to plug them.

-- 



^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 01/18] ia64: ia32 nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-05  7:15 ` [patch 02/18] relay: nopage npiggin
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: tony.luck, linux-ia64, linux-kernel

[-- Attachment #1: ia64-ia32-nopage.patch --]
[-- Type: text/plain, Size: 1721 bytes --]

Convert ia64's ia32 support from nopage to fault.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: tony.luck@intel.com
Cc: linux-ia64@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 arch/ia64/ia32/binfmt_elf32.c |   34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

Index: linux-2.6/arch/ia64/ia32/binfmt_elf32.c
===================================================================
--- linux-2.6.orig/arch/ia64/ia32/binfmt_elf32.c
+++ linux-2.6/arch/ia64/ia32/binfmt_elf32.c
@@ -52,33 +52,29 @@ extern struct page *ia32_shared_page[];
 extern unsigned long *ia32_gdt;
 extern struct page *ia32_gate_page;
 
-struct page *
-ia32_install_shared_page (struct vm_area_struct *vma, unsigned long address, int *type)
+int
+ia32_install_shared_page (struct vm_area_struct *vma, struct vm_fault *vmf)
 {
-	struct page *pg = ia32_shared_page[smp_processor_id()];
-	get_page(pg);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return pg;
-}
-
-struct page *
-ia32_install_gate_page (struct vm_area_struct *vma, unsigned long address, int *type)
-{
-	struct page *pg = ia32_gate_page;
-	get_page(pg);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return pg;
+	vmf->page = ia32_shared_page[smp_processor_id()];
+	get_page(vmf->page);
+	return 0;
+}
+
+int
+ia32_install_gate_page (struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+	vmf->page = ia32_gate_page;
+	get_page(vmf->page);
+	return 0;
 }
 
 
 static struct vm_operations_struct ia32_shared_page_vm_ops = {
-	.nopage = ia32_install_shared_page
+	.fault = ia32_install_shared_page
 };
 
 static struct vm_operations_struct ia32_gate_page_vm_ops = {
-	.nopage = ia32_install_gate_page
+	.fault = ia32_install_gate_page
 };
 
 void

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 02/18] relay: nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
  2007-12-05  7:15 ` [patch 01/18] ia64: ia32 nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-05  7:15 ` [patch 03/18] drm: nopage npiggin
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: zanussi, karim, linux-kernel

[-- Attachment #1: relay-nopage.patch --]
[-- Type: text/plain, Size: 1692 bytes --]

Convert relay from nopage to fault.
Remove redundant vma range checks.
Switch from OOM to SIGBUS if the resource is not available.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: zanussi@us.ibm.com
Cc: karim@opersys.com
Cc: linux-kernel@vger.kernel.org
---
 kernel/relay.c |   24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

Index: linux-2.6/kernel/relay.c
===================================================================
--- linux-2.6.orig/kernel/relay.c
+++ linux-2.6/kernel/relay.c
@@ -37,37 +37,31 @@ static void relay_file_mmap_close(struct
 }
 
 /*
- * nopage() vm_op implementation for relay file mapping.
+ * fault() vm_op implementation for relay file mapping.
  */
-static struct page *relay_buf_nopage(struct vm_area_struct *vma,
-				     unsigned long address,
-				     int *type)
+static int relay_buf_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	struct page *page;
 	struct rchan_buf *buf = vma->vm_private_data;
-	unsigned long offset = address - vma->vm_start;
+	pgoff_t pgoff = vmf->pgoff;
 
-	if (address > vma->vm_end)
-		return NOPAGE_SIGBUS; /* Disallow mremap */
 	if (!buf)
-		return NOPAGE_OOM;
+		return VM_FAULT_OOM;
 
-	page = vmalloc_to_page(buf->start + offset);
+	page = vmalloc_to_page(buf->start + (pgoff << PAGE_SHIFT));
 	if (!page)
-		return NOPAGE_OOM;
+		return VM_FAULT_SIGBUS;
 	get_page(page);
+	vmf->page = page;
 
-	if (type)
-		*type = VM_FAULT_MINOR;
-
-	return page;
+	return 0;
 }
 
 /*
  * vm_ops for relay file mappings.
  */
 static struct vm_operations_struct relay_file_mmap_ops = {
-	.nopage = relay_buf_nopage,
+	.fault = relay_buf_fault,
 	.close = relay_file_mmap_close,
 };
 

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 03/18] drm: nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
  2007-12-05  7:15 ` [patch 01/18] ia64: ia32 nopage npiggin
  2007-12-05  7:15 ` [patch 02/18] relay: nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-05  9:05   ` Dave Airlie
  2007-12-05  7:15 ` [patch 04/18] uio: nopage npiggin
                   ` (13 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: airlied, linux-kernel

[-- Attachment #1: drm-nopage.patch --]
[-- Type: text/plain, Size: 10348 bytes --]

Convert drm from nopage to fault.
Remove redundant vma range checks.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: airlied@linux.ie
Cc: linux-kernel@vger.kernel.org
---
 drivers/char/drm/drm_vm.c |  131 +++++++++++++++++++++-------------------------
 1 file changed, 61 insertions(+), 70 deletions(-)

Index: linux-2.6/drivers/char/drm/drm_vm.c
===================================================================
--- linux-2.6.orig/drivers/char/drm/drm_vm.c
+++ linux-2.6/drivers/char/drm/drm_vm.c
@@ -66,7 +66,7 @@ static pgprot_t drm_io_prot(uint32_t map
 }
 
 /**
- * \c nopage method for AGP virtual memory.
+ * \c fault method for AGP virtual memory.
  *
  * \param vma virtual memory area.
  * \param address access address.
@@ -76,8 +76,8 @@ static pgprot_t drm_io_prot(uint32_t map
  * map, get the page, increment the use count and return it.
  */
 #if __OS_HAS_AGP
-static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
-						unsigned long address)
+static __inline__ int drm_do_vm_fault(struct vm_area_struct *vma,
+						struct vm_fault *vmf)
 {
 	struct drm_file *priv = vma->vm_file->private_data;
 	struct drm_device *dev = priv->head->dev;
@@ -89,19 +89,24 @@ static __inline__ struct page *drm_do_vm
 	 * Find the right map
 	 */
 	if (!drm_core_has_AGP(dev))
-		goto vm_nopage_error;
+		goto vm_fault_error;
 
 	if (!dev->agp || !dev->agp->cant_use_aperture)
-		goto vm_nopage_error;
+		goto vm_fault_error;
 
 	if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash))
-		goto vm_nopage_error;
+		goto vm_fault_error;
 
 	r_list = drm_hash_entry(hash, struct drm_map_list, hash);
 	map = r_list->map;
 
 	if (map && map->type == _DRM_AGP) {
-		unsigned long offset = address - vma->vm_start;
+		/*
+		 * Using vm_pgoff as a selector forces us to use this unusual
+		 * addressing scheme.
+		 */
+		unsigned long offset = (unsigned long)vmf->virtual_address -
+								vma->vm_start;
 		unsigned long baddr = map->offset + offset;
 		struct drm_agp_mem *agpmem;
 		struct page *page;
@@ -123,7 +128,7 @@ static __inline__ struct page *drm_do_vm
 		}
 
 		if (!agpmem)
-			goto vm_nopage_error;
+			goto vm_fault_error;
 
 		/*
 		 * Get the page, inc the use count, and return it
@@ -131,27 +136,28 @@ static __inline__ struct page *drm_do_vm
 		offset = (baddr - agpmem->bound) >> PAGE_SHIFT;
 		page = virt_to_page(__va(agpmem->memory->memory[offset]));
 		get_page(page);
+		vmf->page = page;
 
 		DRM_DEBUG
 		    ("baddr = 0x%lx page = 0x%p, offset = 0x%lx, count=%d\n",
 		     baddr, __va(agpmem->memory->memory[offset]), offset,
 		     page_count(page));
 
-		return page;
+		return 0;
 	}
-      vm_nopage_error:
-	return NOPAGE_SIGBUS;	/* Disallow mremap */
+      vm_fault_error:
+	return VM_FAULT_SIGBUS;	/* Disallow mremap */
 }
 #else				/* __OS_HAS_AGP */
-static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
-						unsigned long address)
+static __inline__ int drm_do_vm_fault(struct vm_area_struct *vma,
+						struct vm_fault *vmf)
 {
-	return NOPAGE_SIGBUS;
+	return VM_FAULT_SIGBUS;
 }
 #endif				/* __OS_HAS_AGP */
 
 /**
- * \c nopage method for shared virtual memory.
+ * \c fault method for shared virtual memory.
  *
  * \param vma virtual memory area.
  * \param address access address.
@@ -160,28 +166,27 @@ static __inline__ struct page *drm_do_vm
  * Get the mapping, find the real physical page to map, get the page, and
  * return it.
  */
-static __inline__ struct page *drm_do_vm_shm_nopage(struct vm_area_struct *vma,
-						    unsigned long address)
+static __inline__ int drm_do_vm_shm_fault(struct vm_area_struct *vma,
+						    struct vm_fault *vmf)
 {
 	struct drm_map *map = (struct drm_map *) vma->vm_private_data;
 	unsigned long offset;
 	unsigned long i;
 	struct page *page;
 
-	if (address > vma->vm_end)
-		return NOPAGE_SIGBUS;	/* Disallow mremap */
 	if (!map)
-		return NOPAGE_SIGBUS;	/* Nothing allocated */
+		return VM_FAULT_SIGBUS;	/* Nothing allocated */
 
-	offset = address - vma->vm_start;
+	offset = (unsigned long)vmf->virtual_address - vma->vm_start;
 	i = (unsigned long)map->handle + offset;
 	page = vmalloc_to_page((void *)i);
 	if (!page)
-		return NOPAGE_SIGBUS;
+		return VM_FAULT_SIGBUS;
 	get_page(page);
+	vmf->page = page;
 
-	DRM_DEBUG("shm_nopage 0x%lx\n", address);
-	return page;
+	DRM_DEBUG("shm_fault 0x%lx\n", offset);
+	return 0;
 }
 
 /**
@@ -263,7 +268,7 @@ static void drm_vm_shm_close(struct vm_a
 }
 
 /**
- * \c nopage method for DMA virtual memory.
+ * \c fault method for DMA virtual memory.
  *
  * \param vma virtual memory area.
  * \param address access address.
@@ -271,8 +276,8 @@ static void drm_vm_shm_close(struct vm_a
  *
  * Determine the page number from the page offset and get it from drm_device_dma::pagelist.
  */
-static __inline__ struct page *drm_do_vm_dma_nopage(struct vm_area_struct *vma,
-						    unsigned long address)
+static __inline__ int drm_do_vm_dma_fault(struct vm_area_struct *vma,
+						    struct vm_fault *vmf)
 {
 	struct drm_file *priv = vma->vm_file->private_data;
 	struct drm_device *dev = priv->head->dev;
@@ -282,24 +287,23 @@ static __inline__ struct page *drm_do_vm
 	struct page *page;
 
 	if (!dma)
-		return NOPAGE_SIGBUS;	/* Error */
-	if (address > vma->vm_end)
-		return NOPAGE_SIGBUS;	/* Disallow mremap */
+		return VM_FAULT_SIGBUS;	/* Error */
 	if (!dma->pagelist)
-		return NOPAGE_SIGBUS;	/* Nothing allocated */
+		return VM_FAULT_SIGBUS;	/* Nothing allocated */
 
-	offset = address - vma->vm_start;	/* vm_[pg]off[set] should be 0 */
-	page_nr = offset >> PAGE_SHIFT;
+	offset = (unsigned long)vmf->virtual_address - vma->vm_start;	/* vm_[pg]off[set] should be 0 */
+	page_nr = offset >> PAGE_SHIFT; /* page_nr could just be vmf->pgoff */
 	page = virt_to_page((dma->pagelist[page_nr] + (offset & (~PAGE_MASK))));
 
 	get_page(page);
+	vmf->page = page;
 
-	DRM_DEBUG("dma_nopage 0x%lx (page %lu)\n", address, page_nr);
-	return page;
+	DRM_DEBUG("dma_fault 0x%lx (page %lu)\n", offset, page_nr);
+	return 0;
 }
 
 /**
- * \c nopage method for scatter-gather virtual memory.
+ * \c fault method for scatter-gather virtual memory.
  *
  * \param vma virtual memory area.
  * \param address access address.
@@ -307,8 +311,8 @@ static __inline__ struct page *drm_do_vm
  *
  * Determine the map offset from the page offset and get it from drm_sg_mem::pagelist.
  */
-static __inline__ struct page *drm_do_vm_sg_nopage(struct vm_area_struct *vma,
-						   unsigned long address)
+static __inline__ int drm_do_vm_sg_fault(struct vm_area_struct *vma,
+						   struct vm_fault *vmf)
 {
 	struct drm_map *map = (struct drm_map *) vma->vm_private_data;
 	struct drm_file *priv = vma->vm_file->private_data;
@@ -320,77 +324,64 @@ static __inline__ struct page *drm_do_vm
 	struct page *page;
 
 	if (!entry)
-		return NOPAGE_SIGBUS;	/* Error */
-	if (address > vma->vm_end)
-		return NOPAGE_SIGBUS;	/* Disallow mremap */
+		return VM_FAULT_SIGBUS;	/* Error */
 	if (!entry->pagelist)
-		return NOPAGE_SIGBUS;	/* Nothing allocated */
+		return VM_FAULT_SIGBUS;	/* Nothing allocated */
 
-	offset = address - vma->vm_start;
+	offset = (unsigned long)vmf->virtual_address - vma->vm_start;
 	map_offset = map->offset - (unsigned long)dev->sg->virtual;
 	page_offset = (offset >> PAGE_SHIFT) + (map_offset >> PAGE_SHIFT);
 	page = entry->pagelist[page_offset];
 	get_page(page);
+	vmf->page = page;
 
-	return page;
+	return 0;
 }
 
-static struct page *drm_vm_nopage(struct vm_area_struct *vma,
-				  unsigned long address, int *type)
+static int drm_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return drm_do_vm_nopage(vma, address);
+	return drm_do_vm_fault(vma, vmf);
 }
 
-static struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
-				      unsigned long address, int *type)
+static int drm_vm_shm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return drm_do_vm_shm_nopage(vma, address);
+	return drm_do_vm_shm_fault(vma, vmf);
 }
 
-static struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
-				      unsigned long address, int *type)
+static int drm_vm_dma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return drm_do_vm_dma_nopage(vma, address);
+	return drm_do_vm_dma_fault(vma, vmf);
 }
 
-static struct page *drm_vm_sg_nopage(struct vm_area_struct *vma,
-				     unsigned long address, int *type)
+static int drm_vm_sg_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return drm_do_vm_sg_nopage(vma, address);
+	return drm_do_vm_sg_fault(vma, vmf);
 }
 
 /** AGP virtual memory operations */
 static struct vm_operations_struct drm_vm_ops = {
-	.nopage = drm_vm_nopage,
+	.fault = drm_vm_fault,
 	.open = drm_vm_open,
 	.close = drm_vm_close,
 };
 
 /** Shared virtual memory operations */
 static struct vm_operations_struct drm_vm_shm_ops = {
-	.nopage = drm_vm_shm_nopage,
+	.fault = drm_vm_shm_fault,
 	.open = drm_vm_open,
 	.close = drm_vm_shm_close,
 };
 
 /** DMA virtual memory operations */
 static struct vm_operations_struct drm_vm_dma_ops = {
-	.nopage = drm_vm_dma_nopage,
+	.fault = drm_vm_dma_fault,
 	.open = drm_vm_open,
 	.close = drm_vm_close,
 };
 
 /** Scatter-gather virtual memory operations */
 static struct vm_operations_struct drm_vm_sg_ops = {
-	.nopage = drm_vm_sg_nopage,
+	.fault = drm_vm_sg_fault,
 	.open = drm_vm_open,
 	.close = drm_vm_close,
 };
@@ -603,7 +594,7 @@ static int drm_mmap_locked(struct file *
 			/*
 			 * On some platforms we can't talk to bus dma address from the CPU, so for
 			 * memory of type DRM_AGP, we'll deal with sorting out the real physical
-			 * pages and mappings in nopage()
+			 * pages and mappings in fault()
 			 */
 #if defined(__powerpc__)
 			pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
@@ -633,7 +624,7 @@ static int drm_mmap_locked(struct file *
 		break;
 	case _DRM_CONSISTENT:
 		/* Consistent memory is really like shared memory. But
-		 * it's allocated in a different way, so avoid nopage */
+		 * it's allocated in a different way, so avoid fault */
 		if (remap_pfn_range(vma, vma->vm_start,
 		    page_to_pfn(virt_to_page(map->handle)),
 		    vma->vm_end - vma->vm_start, vma->vm_page_prot))

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 04/18] uio: nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (2 preceding siblings ...)
  2007-12-05  7:15 ` [patch 03/18] drm: nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-05 10:04   ` Hans-Jürgen Koch
  2007-12-05  7:15 ` [patch 05/18] kvm: nopage npiggin
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: greg, linux-kernel

[-- Attachment #1: uio-nopage.patch --]
[-- Type: text/plain, Size: 1383 bytes --]

Convert uio from nopage to fault.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: greg@kroah.com
Cc: linux-kernel@vger.kernel.org
---
 drivers/uio/uio.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Index: linux-2.6/drivers/uio/uio.c
===================================================================
--- linux-2.6.orig/drivers/uio/uio.c
+++ linux-2.6/drivers/uio/uio.c
@@ -412,30 +412,28 @@ static void uio_vma_close(struct vm_area
 	idev->vma_count--;
 }
 
-static struct page *uio_vma_nopage(struct vm_area_struct *vma,
-				   unsigned long address, int *type)
+static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	struct uio_device *idev = vma->vm_private_data;
-	struct page* page = NOPAGE_SIGBUS;
+	struct page *page;
 
 	int mi = uio_find_mem_index(vma);
 	if (mi < 0)
-		return page;
+		return VM_FAULT_SIGBUS;
 
 	if (idev->info->mem[mi].memtype == UIO_MEM_LOGICAL)
 		page = virt_to_page(idev->info->mem[mi].addr);
 	else
 		page = vmalloc_to_page((void*)idev->info->mem[mi].addr);
 	get_page(page);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return page;
+	vmf->page = page;
+	return 0;
 }
 
 static struct vm_operations_struct uio_vm_ops = {
 	.open = uio_vma_open,
 	.close = uio_vma_close,
-	.nopage = uio_vma_nopage,
+	.fault = uio_vma_fault,
 };
 
 static int uio_mmap_physical(struct vm_area_struct *vma)

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 05/18] kvm: nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (3 preceding siblings ...)
  2007-12-05  7:15 ` [patch 04/18] uio: nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-05 10:40   ` Avi Kivity
  2007-12-05  7:15 ` [patch 06/18] ieee1394: nopage npiggin
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: kvm-devel, avi, linux-kernel

[-- Attachment #1: kvm-nopage.patch --]
[-- Type: text/plain, Size: 2347 bytes --]

Convert KVM from nopage to fault.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: kvm-devel@lists.sourceforge.net
Cc: avi@qumranet.com
Cc: linux-kernel@vger.kernel.org
---
 drivers/kvm/kvm_main.c |   38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

Index: linux-2.6/drivers/kvm/kvm_main.c
===================================================================
--- linux-2.6.orig/drivers/kvm/kvm_main.c
+++ linux-2.6/drivers/kvm/kvm_main.c
@@ -2533,30 +2533,24 @@ static int kvm_vcpu_ioctl_debug_guest(st
 	return r;
 }
 
-static struct page *kvm_vcpu_nopage(struct vm_area_struct *vma,
-				    unsigned long address,
-				    int *type)
+static int kvm_vcpu_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	struct kvm_vcpu *vcpu = vma->vm_file->private_data;
-	unsigned long pgoff;
 	struct page *page;
 
-	pgoff = ((address - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
-	if (pgoff == 0)
+	if (vmf->pgoff == 0)
 		page = virt_to_page(vcpu->run);
-	else if (pgoff == KVM_PIO_PAGE_OFFSET)
+	else if (vmf->pgoff == KVM_PIO_PAGE_OFFSET)
 		page = virt_to_page(vcpu->pio_data);
 	else
-		return NOPAGE_SIGBUS;
+		return VM_FAULT_SIGBUS;
 	get_page(page);
-	if (type != NULL)
-		*type = VM_FAULT_MINOR;
-
-	return page;
+	vmf->page = page;
+	return 0;
 }
 
 static struct vm_operations_struct kvm_vcpu_vm_ops = {
-	.nopage = kvm_vcpu_nopage,
+	.fault = kvm_vcpu_fault,
 };
 
 static int kvm_vcpu_mmap(struct file *file, struct vm_area_struct *vma)
@@ -3111,27 +3105,21 @@ out:
 	return r;
 }
 
-static struct page *kvm_vm_nopage(struct vm_area_struct *vma,
-				  unsigned long address,
-				  int *type)
+static int kvm_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	struct kvm *kvm = vma->vm_file->private_data;
-	unsigned long pgoff;
 	struct page *page;
 
-	pgoff = ((address - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
-	page = gfn_to_page(kvm, pgoff);
+	page = gfn_to_page(kvm, vmf->pgoff);
 	if (!page)
-		return NOPAGE_SIGBUS;
+		return VM_FAULT_SIGBUS;
 	get_page(page);
-	if (type != NULL)
-		*type = VM_FAULT_MINOR;
-
-	return page;
+	vmf->page = page;
+	return 0;
 }
 
 static struct vm_operations_struct kvm_vm_vm_ops = {
-	.nopage = kvm_vm_nopage,
+	.fault = kvm_vm_fault,
 };
 
 static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 06/18] ieee1394: nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (4 preceding siblings ...)
  2007-12-05  7:15 ` [patch 05/18] kvm: nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-05 13:09   ` Stefan Richter
  2007-12-15 13:01   ` Stefan Richter
  2007-12-05  7:15 ` [patch 07/18] v4l: nopage npiggin
                   ` (10 subsequent siblings)
  16 siblings, 2 replies; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: krh, stefanr, linux1394-devel, linux-kernel

[-- Attachment #1: ieee1394-nopage.patch --]
[-- Type: text/plain, Size: 2301 bytes --]

Convert ieee1394 from nopage to fault.
Remove redundant vma range checks (correct resource range check is retained).

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: krh@redhat.com
Cc: stefanr@s5r6.in-berlin.de
Cc: linux1394-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
---
 drivers/ieee1394/dma.c |   39 +++++++++++++++++----------------------
 1 file changed, 17 insertions(+), 22 deletions(-)

Index: linux-2.6/drivers/ieee1394/dma.c
===================================================================
--- linux-2.6.orig/drivers/ieee1394/dma.c
+++ linux-2.6/drivers/ieee1394/dma.c
@@ -231,37 +231,32 @@ void dma_region_sync_for_device(struct d
 
 #ifdef CONFIG_MMU
 
-/* nopage() handler for mmap access */
+/* fault() handler for mmap access */
 
-static struct page *dma_region_pagefault(struct vm_area_struct *area,
-					 unsigned long address, int *type)
+static int dma_region_pagefault(struct vm_area_struct *vma,
+					struct vm_fault *vmf)
 {
-	unsigned long offset;
 	unsigned long kernel_virt_addr;
-	struct page *ret = NOPAGE_SIGBUS;
 
-	struct dma_region *dma = (struct dma_region *)area->vm_private_data;
+	struct dma_region *dma = (struct dma_region *)vma->vm_private_data;
 
 	if (!dma->kvirt)
-		goto out;
+		goto error;
 
-	if ((address < (unsigned long)area->vm_start) ||
-	    (address >
-	     (unsigned long)area->vm_start + (dma->n_pages << PAGE_SHIFT)))
-		goto out;
-
-	if (type)
-		*type = VM_FAULT_MINOR;
-	offset = address - area->vm_start;
-	kernel_virt_addr = (unsigned long)dma->kvirt + offset;
-	ret = vmalloc_to_page((void *)kernel_virt_addr);
-	get_page(ret);
-      out:
-	return ret;
+	if (vmf->pgoff >= dma->n_pages)
+		goto error;
+
+	kernel_virt_addr = (unsigned long)dma->kvirt + (vmf->pgoff << PAGE_SHIFT);
+	vmf->page = vmalloc_to_page((void *)kernel_virt_addr);
+	get_page(vmf->page);
+	return 0;
+
+      error:
+	return VM_FAULT_SIGBUS;
 }
 
 static struct vm_operations_struct dma_region_vm_ops = {
-	.nopage = dma_region_pagefault,
+	.fault = dma_region_pagefault,
 };
 
 /**
@@ -275,7 +270,7 @@ int dma_region_mmap(struct dma_region *d
 	if (!dma->kvirt)
 		return -EINVAL;
 
-	/* must be page-aligned */
+	/* must be page-aligned (XXX: comment is wrong, we could allow pgoff) */
 	if (vma->vm_pgoff != 0)
 		return -EINVAL;
 

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 07/18] v4l: nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (5 preceding siblings ...)
  2007-12-05  7:15 ` [patch 06/18] ieee1394: nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-08  0:31   ` Andrew Morton
  2007-12-05  7:15 ` [patch 08/18] fb: defio nopage npiggin
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: mchehab, v4l-dvb-maintainer, linux-kernel

[-- Attachment #1: v4l-nopage.patch --]
[-- Type: text/plain, Size: 1729 bytes --]

Convert v4l from nopage to fault.
Remove redundant vma range checks.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: mchehab@infradead.org
Cc: v4l-dvb-maintainer@linuxtv.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/media/video/videobuf-dma-sg.c |   20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Index: linux-2.6/drivers/media/video/videobuf-dma-sg.c
===================================================================
--- linux-2.6.orig/drivers/media/video/videobuf-dma-sg.c
+++ linux-2.6/drivers/media/video/videobuf-dma-sg.c
@@ -385,30 +385,26 @@ videobuf_vm_close(struct vm_area_struct 
  * now ...).  Bounce buffers don't work very well for the data rates
  * video capture has.
  */
-static struct page*
-videobuf_vm_nopage(struct vm_area_struct *vma, unsigned long vaddr,
-		   int *type)
+static int
+videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	struct page *page;
 
-	dprintk(3,"nopage: fault @ %08lx [vma %08lx-%08lx]\n",
-		vaddr,vma->vm_start,vma->vm_end);
-	if (vaddr > vma->vm_end)
-		return NOPAGE_SIGBUS;
+	dprintk(3,"fault: fault @ %08lx [vma %08lx-%08lx]\n",
+		(unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end);
 	page = alloc_page(GFP_USER | __GFP_DMA32);
 	if (!page)
-		return NOPAGE_OOM;
+		return VM_FAULT_OOM;
 	clear_user_page(page_address(page), vaddr, page);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return page;
+	vmf->page = page;
+	return 0;
 }
 
 static struct vm_operations_struct videobuf_vm_ops =
 {
 	.open     = videobuf_vm_open,
 	.close    = videobuf_vm_close,
-	.nopage   = videobuf_vm_nopage,
+	.fault    = videobuf_vm_fault,
 };
 
 /* ---------------------------------------------------------------------

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 08/18] fb: defio nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (6 preceding siblings ...)
  2007-12-05  7:15 ` [patch 07/18] v4l: nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-05  7:15 ` [patch 09/18] agp: alpha nopage npiggin
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: linux-fbdev-devel, jayakumar.lkml, lethal, linux-kernel

[-- Attachment #1: fb-defio-nopage.patch --]
[-- Type: text/plain, Size: 2782 bytes --]

Convert fb defio from nopage to fault.
Switch from OOM to SIGBUS if the resource is not available.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: linux-fbdev-devel@lists.sourceforge.net
Cc: jayakumar.lkml@gmail.com
Cc: lethal@linux-sh.org
Cc: linux-kernel@vger.kernel.org
---
 Documentation/fb/deferred_io.txt |    6 +++---
 drivers/video/fb_defio.c         |   17 ++++++++---------
 2 files changed, 11 insertions(+), 12 deletions(-)

Index: linux-2.6/drivers/video/fb_defio.c
===================================================================
--- linux-2.6.orig/drivers/video/fb_defio.c
+++ linux-2.6/drivers/video/fb_defio.c
@@ -25,8 +25,8 @@
 #include <linux/pagemap.h>
 
 /* this is to find and return the vmalloc-ed fb pages */
-static struct page* fb_deferred_io_nopage(struct vm_area_struct *vma,
-					unsigned long vaddr, int *type)
+static int fb_deferred_io_fault(struct vm_area_struct *vma,
+				struct vm_fault *vmf)
 {
 	unsigned long offset;
 	struct page *page;
@@ -34,18 +34,17 @@ static struct page* fb_deferred_io_nopag
 	/* info->screen_base is in System RAM */
 	void *screen_base = (void __force *) info->screen_base;
 
-	offset = (vaddr - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
+	offset = vmf->pgoff << PAGE_SHIFT;
 	if (offset >= info->fix.smem_len)
-		return NOPAGE_SIGBUS;
+		return VM_FAULT_SIGBUS;
 
 	page = vmalloc_to_page(screen_base + offset);
 	if (!page)
-		return NOPAGE_OOM;
+		return VM_FAULT_SIGBUS;
 
 	get_page(page);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return page;
+	vmf->page = page;
+	return 0;
 }
 
 int fb_deferred_io_fsync(struct file *file, struct dentry *dentry, int datasync)
@@ -84,7 +83,7 @@ static int fb_deferred_io_mkwrite(struct
 }
 
 static struct vm_operations_struct fb_deferred_io_vm_ops = {
-	.nopage   	= fb_deferred_io_nopage,
+	.fault		= fb_deferred_io_fault,
 	.page_mkwrite	= fb_deferred_io_mkwrite,
 };
 
Index: linux-2.6/Documentation/fb/deferred_io.txt
===================================================================
--- linux-2.6.orig/Documentation/fb/deferred_io.txt
+++ linux-2.6/Documentation/fb/deferred_io.txt
@@ -7,10 +7,10 @@ IO. The following example may be a usefu
 works:
 
 - userspace app like Xfbdev mmaps framebuffer
-- deferred IO and driver sets up nopage and page_mkwrite handlers
+- deferred IO and driver sets up fault and page_mkwrite handlers
 - userspace app tries to write to mmaped vaddress
-- we get pagefault and reach nopage handler
-- nopage handler finds and returns physical page
+- we get pagefault and reach fault handler
+- fault handler finds and returns physical page
 - we get page_mkwrite where we add this page to a list
 - schedule a workqueue task to be run after a delay
 - app continues writing to that page with no additional cost. this is

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 09/18] agp: alpha nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (7 preceding siblings ...)
  2007-12-05  7:15 ` [patch 08/18] fb: defio nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-05  7:15 ` [patch 10/18] sg: nopage npiggin
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: rth, ink, linux-kernel

[-- Attachment #1: agp-alpha-nopage.patch --]
[-- Type: text/plain, Size: 1741 bytes --]

Convert AGP alpha driver from nopage to fault.
NULL is NOPAGE_SIGBUS, so we aren't changing behaviour there.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: rth@twiddle.net
Cc: ink@jurassic.park.msu.ru
Cc: linux-kernel@vger.kernel.org
---
 drivers/char/agp/alpha-agp.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

Index: linux-2.6/drivers/char/agp/alpha-agp.c
===================================================================
--- linux-2.6.orig/drivers/char/agp/alpha-agp.c
+++ linux-2.6/drivers/char/agp/alpha-agp.c
@@ -11,29 +11,28 @@
 
 #include "agp.h"
 
-static struct page *alpha_core_agp_vm_nopage(struct vm_area_struct *vma,
-					     unsigned long address,
-					     int *type)
+static int alpha_core_agp_vm_fault(struct vm_area_struct *vma,
+					struct vm_fault *vmf)
 {
 	alpha_agp_info *agp = agp_bridge->dev_private_data;
 	dma_addr_t dma_addr;
 	unsigned long pa;
 	struct page *page;
 
-	dma_addr = address - vma->vm_start + agp->aperture.bus_base;
+	dma_addr = (unsigned long)vmf->virtual_address - vma->vm_start
+						+ agp->aperture.bus_base;
 	pa = agp->ops->translate(agp, dma_addr);
 
 	if (pa == (unsigned long)-EINVAL)
-		return NULL;	/* no translation */
+		return VM_FAULT_SIGBUS;	/* no translation */
 
 	/*
 	 * Get the page, inc the use count, and return it
 	 */
 	page = virt_to_page(__va(pa));
 	get_page(page);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return page;
+	vmf->page = page;
+	return 0;
 }
 
 static struct aper_size_info_fixed alpha_core_agp_sizes[] =
@@ -42,7 +41,7 @@ static struct aper_size_info_fixed alpha
 };
 
 struct vm_operations_struct alpha_core_agp_vm_ops = {
-	.nopage = alpha_core_agp_vm_nopage,
+	.fault = alpha_core_agp_vm_fault,
 };
 
 

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 10/18] sg: nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (8 preceding siblings ...)
  2007-12-05  7:15 ` [patch 09/18] agp: alpha nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2008-02-08  3:45   ` Douglas Gilbert
  2007-12-05  7:15 ` [patch 11/18] ib: nopage npiggin
                   ` (6 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: dgilbert, linux-scsi, linux-kernel

[-- Attachment #1: sg-nopage.patch --]
[-- Type: text/plain, Size: 2001 bytes --]

Convert SG from nopage to fault.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: dgilbert@interlog.com
Cc: linux-scsi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/scsi/sg.c |   23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

Index: linux-2.6/drivers/scsi/sg.c
===================================================================
--- linux-2.6.orig/drivers/scsi/sg.c
+++ linux-2.6/drivers/scsi/sg.c
@@ -1144,23 +1144,22 @@ sg_fasync(int fd, struct file *filp, int
 	return (retval < 0) ? retval : 0;
 }
 
-static struct page *
-sg_vma_nopage(struct vm_area_struct *vma, unsigned long addr, int *type)
+static int
+sg_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	Sg_fd *sfp;
-	struct page *page = NOPAGE_SIGBUS;
 	unsigned long offset, len, sa;
 	Sg_scatter_hold *rsv_schp;
 	struct scatterlist *sg;
 	int k;
 
 	if ((NULL == vma) || (!(sfp = (Sg_fd *) vma->vm_private_data)))
-		return page;
+		return VM_FAULT_SIGBUS;
 	rsv_schp = &sfp->reserve;
-	offset = addr - vma->vm_start;
+	offset = vmf->pgoff << PAGE_SHIFT;
 	if (offset >= rsv_schp->bufflen)
-		return page;
-	SCSI_LOG_TIMEOUT(3, printk("sg_vma_nopage: offset=%lu, scatg=%d\n",
+		return VM_FAULT_SIGBUS;
+	SCSI_LOG_TIMEOUT(3, printk("sg_vma_fault: offset=%lu, scatg=%d\n",
 				   offset, rsv_schp->k_use_sg));
 	sg = rsv_schp->buffer;
 	sa = vma->vm_start;
@@ -1169,21 +1168,21 @@ sg_vma_nopage(struct vm_area_struct *vma
 		len = vma->vm_end - sa;
 		len = (len < sg->length) ? len : sg->length;
 		if (offset < len) {
+			struct page *page;
 			page = virt_to_page(page_address(sg_page(sg)) + offset);
 			get_page(page);	/* increment page count */
-			break;
+			vmf->page = page;
+			return 0; /* success */
 		}
 		sa += len;
 		offset -= len;
 	}
 
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return page;
+	return VM_FAULT_SIGBUS;
 }
 
 static struct vm_operations_struct sg_mmap_vm_ops = {
-	.nopage = sg_vma_nopage,
+	.fault = sg_vma_fault,
 };
 
 static int

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 11/18] ib: nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (9 preceding siblings ...)
  2007-12-05  7:15 ` [patch 10/18] sg: nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-05  7:15 ` [patch 12/18] usb: mon nopage npiggin
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: rolandd, mshefty, hal.rosenstock, general, linux-kernel

[-- Attachment #1: ib-nopage.patch --]
[-- Type: text/plain, Size: 2915 bytes --]

Convert IB from nopage to fault.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: rolandd@cisco.com
Cc: mshefty@ichips.intel.com
Cc: hal.rosenstock@gmail.com
Cc: general@lists.openfabrics.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/infiniband/hw/ipath/ipath_debug.h    |    4 +--
 drivers/infiniband/hw/ipath/ipath_file_ops.c |   29 +++++++++------------------
 2 files changed, 12 insertions(+), 21 deletions(-)

Index: linux-2.6/drivers/infiniband/hw/ipath/ipath_file_ops.c
===================================================================
--- linux-2.6.orig/drivers/infiniband/hw/ipath/ipath_file_ops.c
+++ linux-2.6/drivers/infiniband/hw/ipath/ipath_file_ops.c
@@ -1120,33 +1120,24 @@ bail:
 }
 
 /*
- * ipath_file_vma_nopage - handle a VMA page fault.
+ * ipath_file_vma_fault - handle a VMA page fault.
  */
-static struct page *ipath_file_vma_nopage(struct vm_area_struct *vma,
-					  unsigned long address, int *type)
+static int ipath_file_vma_fault(struct vm_area_struct *vma,
+					struct vm_fault *vmf)
 {
-	unsigned long offset = address - vma->vm_start;
-	struct page *page = NOPAGE_SIGBUS;
-	void *pageptr;
+	struct page *page;
 
-	/*
-	 * Convert the vmalloc address into a struct page.
-	 */
-	pageptr = (void *)(offset + (vma->vm_pgoff << PAGE_SHIFT));
-	page = vmalloc_to_page(pageptr);
+	page = vmalloc_to_page((void *)(vmf->pgoff << PAGE_SHIFT));
 	if (!page)
-		goto out;
-
-	/* Increment the reference count. */
+		return VM_FAULT_SIGBUS;
 	get_page(page);
-	if (type)
-		*type = VM_FAULT_MINOR;
-out:
-	return page;
+	vmf->page = page;
+
+	return 0;
 }
 
 static struct vm_operations_struct ipath_file_vm_ops = {
-	.nopage = ipath_file_vma_nopage,
+	.fault = ipath_file_vma_fault,
 };
 
 static int mmap_kvaddr(struct vm_area_struct *vma, u64 pgaddr,
Index: linux-2.6/drivers/infiniband/hw/ipath/ipath_debug.h
===================================================================
--- linux-2.6.orig/drivers/infiniband/hw/ipath/ipath_debug.h
+++ linux-2.6/drivers/infiniband/hw/ipath/ipath_debug.h
@@ -55,7 +55,7 @@
 #define __IPATH_PKTDBG      0x80	/* print packet data */
 /* print process startup (init)/exit messages */
 #define __IPATH_PROCDBG     0x100
-/* print mmap/nopage stuff, not using VDBG any more */
+/* print mmap/fault stuff, not using VDBG any more */
 #define __IPATH_MMDBG       0x200
 #define __IPATH_ERRPKTDBG   0x400
 #define __IPATH_USER_SEND   0x1000	/* use user mode send */
@@ -81,7 +81,7 @@
 #define __IPATH_VERBDBG   0x0	/* very verbose debug */
 #define __IPATH_PKTDBG    0x0	/* print packet data */
 #define __IPATH_PROCDBG   0x0	/* process startup (init)/exit messages */
-/* print mmap/nopage stuff, not using VDBG any more */
+/* print mmap/fault stuff, not using VDBG any more */
 #define __IPATH_MMDBG     0x0
 #define __IPATH_EPKTDBG   0x0	/* print ethernet packet data */
 #define __IPATH_IPATHDBG  0x0	/* Ethernet (IPATH) table dump on */

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 12/18] usb: mon nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (10 preceding siblings ...)
  2007-12-05  7:15 ` [patch 11/18] ib: nopage npiggin
@ 2007-12-05  7:15 ` npiggin
  2007-12-05 16:39   ` Pete Zaitcev
  2007-12-05  7:16 ` [patch 13/18] alsa: nopage npiggin
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: npiggin @ 2007-12-05  7:15 UTC (permalink / raw)
  To: akpm; +Cc: zaitcev, paolo.abeni, linux-kernel

[-- Attachment #1: usb-mon-nopage.patch --]
[-- Type: text/plain, Size: 1795 bytes --]

Convert USB mon driver from nopage to fault.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: zaitcev@redhat.com
Cc: paolo.abeni@email.it
Cc: linux-kernel@vger.kernel.org
---
 drivers/usb/mon/mon_bin.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Index: linux-2.6/drivers/usb/mon/mon_bin.c
===================================================================
--- linux-2.6.orig/drivers/usb/mon/mon_bin.c
+++ linux-2.6/drivers/usb/mon/mon_bin.c
@@ -1045,33 +1045,31 @@ static void mon_bin_vma_close(struct vm_
 /*
  * Map ring pages to user space.
  */
-struct page *mon_bin_vma_nopage(struct vm_area_struct *vma,
-                                unsigned long address, int *type)
+static int mon_bin_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	struct mon_reader_bin *rp = vma->vm_private_data;
 	unsigned long offset, chunk_idx;
 	struct page *pageptr;
 
-	offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
+	offset = vmf->pgoff << PAGE_SHIFT;
 	if (offset >= rp->b_size)
-		return NOPAGE_SIGBUS;
+		return VM_FAULT_SIGBUS;
 	chunk_idx = offset / CHUNK_SIZE;
 	pageptr = rp->b_vec[chunk_idx].pg;
 	get_page(pageptr);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return pageptr;
+	vmf->page = pageptr;
+	return 0;
 }
 
 struct vm_operations_struct mon_bin_vm_ops = {
 	.open =     mon_bin_vma_open,
 	.close =    mon_bin_vma_close,
-	.nopage =   mon_bin_vma_nopage,
+	.fault =    mon_bin_vma_fault,
 };
 
 int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma)
 {
-	/* don't do anything here: "nopage" will set up page table entries */
+	/* don't do anything here: "fault" will set up page table entries */
 	vma->vm_ops = &mon_bin_vm_ops;
 	vma->vm_flags |= VM_RESERVED;
 	vma->vm_private_data = filp->private_data;

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 13/18] alsa: nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (11 preceding siblings ...)
  2007-12-05  7:15 ` [patch 12/18] usb: mon nopage npiggin
@ 2007-12-05  7:16 ` npiggin
  2007-12-13 15:35   ` Takashi Iwai
  2007-12-05  7:16 ` [patch 14/18] oss: via nopage npiggin
                   ` (3 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: npiggin @ 2007-12-05  7:16 UTC (permalink / raw)
  To: akpm; +Cc: perex, tiwai, alsa-devel, linux-kernel

[-- Attachment #1: alsa-nopage.patch --]
[-- Type: text/plain, Size: 4171 bytes --]

Convert ALSA from nopage to fault.
Switch from OOM to SIGBUS if the resource is not available.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: perex@perex.cz
Cc: tiwai@suse.de
Cc: alsa-devel@alsa-project.org
Cc: linux-kernel@vger.kernel.org
---
 sound/core/pcm_native.c |   59 ++++++++++++++++++++----------------------------
 1 file changed, 25 insertions(+), 34 deletions(-)

Index: linux-2.6/sound/core/pcm_native.c
===================================================================
--- linux-2.6.orig/sound/core/pcm_native.c
+++ linux-2.6/sound/core/pcm_native.c
@@ -3018,26 +3018,23 @@ static unsigned int snd_pcm_capture_poll
 /*
  * mmap status record
  */
-static struct page * snd_pcm_mmap_status_nopage(struct vm_area_struct *area,
-						unsigned long address, int *type)
+static int snd_pcm_mmap_status_fault(struct vm_area_struct *area,
+						struct vm_fault *vmf)
 {
 	struct snd_pcm_substream *substream = area->vm_private_data;
 	struct snd_pcm_runtime *runtime;
-	struct page * page;
 	
 	if (substream == NULL)
-		return NOPAGE_SIGBUS;
+		return VM_FAULT_SIGBUS;
 	runtime = substream->runtime;
-	page = virt_to_page(runtime->status);
-	get_page(page);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return page;
+	vmf->page = virt_to_page(runtime->status);
+	get_page(vmf->page);
+	return 0;
 }
 
 static struct vm_operations_struct snd_pcm_vm_ops_status =
 {
-	.nopage =	snd_pcm_mmap_status_nopage,
+	.fault =	snd_pcm_mmap_status_fault,
 };
 
 static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file,
@@ -3061,26 +3058,23 @@ static int snd_pcm_mmap_status(struct sn
 /*
  * mmap control record
  */
-static struct page * snd_pcm_mmap_control_nopage(struct vm_area_struct *area,
-						 unsigned long address, int *type)
+static int snd_pcm_mmap_control_fault(struct vm_area_struct *area,
+						struct vm_fault *vmf)
 {
 	struct snd_pcm_substream *substream = area->vm_private_data;
 	struct snd_pcm_runtime *runtime;
-	struct page * page;
 	
 	if (substream == NULL)
-		return NOPAGE_SIGBUS;
+		return VM_FAULT_SIGBUS;
 	runtime = substream->runtime;
-	page = virt_to_page(runtime->control);
-	get_page(page);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return page;
+	vmf->page = virt_to_page(runtime->control);
+	get_page(vmf->page);
+	return 0;
 }
 
 static struct vm_operations_struct snd_pcm_vm_ops_control =
 {
-	.nopage =	snd_pcm_mmap_control_nopage,
+	.fault =	snd_pcm_mmap_control_fault,
 };
 
 static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file,
@@ -3117,10 +3111,10 @@ static int snd_pcm_mmap_control(struct s
 #endif /* coherent mmap */
 
 /*
- * nopage callback for mmapping a RAM page
+ * fault callback for mmapping a RAM page
  */
-static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area,
-					     unsigned long address, int *type)
+static int snd_pcm_mmap_data_fault(struct vm_area_struct *area,
+						struct vm_fault *vmf)
 {
 	struct snd_pcm_substream *substream = area->vm_private_data;
 	struct snd_pcm_runtime *runtime;
@@ -3130,33 +3124,30 @@ static struct page *snd_pcm_mmap_data_no
 	size_t dma_bytes;
 	
 	if (substream == NULL)
-		return NOPAGE_SIGBUS;
+		return VM_FAULT_SIGBUS;
 	runtime = substream->runtime;
-	offset = area->vm_pgoff << PAGE_SHIFT;
-	offset += address - area->vm_start;
-	snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_SIGBUS);
+	offset = vmf->pgoff << PAGE_SHIFT;
 	dma_bytes = PAGE_ALIGN(runtime->dma_bytes);
 	if (offset > dma_bytes - PAGE_SIZE)
-		return NOPAGE_SIGBUS;
+		return VM_FAULT_SIGBUS;
 	if (substream->ops->page) {
 		page = substream->ops->page(substream, offset);
-		if (! page)
-			return NOPAGE_OOM; /* XXX: is this really due to OOM? */
+		if (!page)
+			return VM_FAULT_SIGBUS;
 	} else {
 		vaddr = runtime->dma_area + offset;
 		page = virt_to_page(vaddr);
 	}
 	get_page(page);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return page;
+	vmf->page = page;
+	return 0;
 }
 
 static struct vm_operations_struct snd_pcm_vm_ops_data =
 {
 	.open =		snd_pcm_mmap_data_open,
 	.close =	snd_pcm_mmap_data_close,
-	.nopage =	snd_pcm_mmap_data_nopage,
+	.fault =	snd_pcm_mmap_data_fault,
 };
 
 /*

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 14/18] oss: via nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (12 preceding siblings ...)
  2007-12-05  7:16 ` [patch 13/18] alsa: nopage npiggin
@ 2007-12-05  7:16 ` npiggin
  2007-12-05  7:16 ` [patch 15/18] alsa: usx2y nopage npiggin
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 44+ messages in thread
From: npiggin @ 2007-12-05  7:16 UTC (permalink / raw)
  To: akpm; +Cc: jgarzik, linux-kernel

[-- Attachment #1: oss-via-nopage.patch --]
[-- Type: text/plain, Size: 2226 bytes --]

Convert OSS via driver from nopage to fault.
Remove redundant vma range checks.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: jgarzik@pobox.com
Cc: linux-kernel@vger.kernel.org
---
 sound/oss/via82cxxx_audio.c |   28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

Index: linux-2.6/sound/oss/via82cxxx_audio.c
===================================================================
--- linux-2.6.orig/sound/oss/via82cxxx_audio.c
+++ linux-2.6/sound/oss/via82cxxx_audio.c
@@ -2099,8 +2099,7 @@ static void via_dsp_cleanup (struct via_
 }
 
 
-static struct page * via_mm_nopage (struct vm_area_struct * vma,
-				    unsigned long address, int *type)
+static int via_mm_fault (struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	struct via_info *card = vma->vm_private_data;
 	struct via_channel *chan = &card->ch_out;
@@ -2108,22 +2107,14 @@ static struct page * via_mm_nopage (stru
 	unsigned long pgoff;
 	int rd, wr;
 
-	DPRINTK ("ENTER, start %lXh, ofs %lXh, pgoff %ld, addr %lXh\n",
-		 vma->vm_start,
-		 address - vma->vm_start,
-		 (address - vma->vm_start) >> PAGE_SHIFT,
-		 address);
-
-        if (address > vma->vm_end) {
-		DPRINTK ("EXIT, returning NOPAGE_SIGBUS\n");
-		return NOPAGE_SIGBUS; /* Disallow mremap */
-	}
+	DPRINTK ("ENTER, pgoff %ld\n", vmf->pgoff);
+
         if (!card) {
-		DPRINTK ("EXIT, returning NOPAGE_SIGBUS\n");
-		return NOPAGE_SIGBUS;	/* Nothing allocated */
+		DPRINTK ("EXIT, returning VM_FAULT_SIGBUS\n");
+		return VM_FAULT_SIGBUS;	/* Nothing allocated */
 	}
 
-	pgoff = vma->vm_pgoff + ((address - vma->vm_start) >> PAGE_SHIFT);
+	pgoff = vmf->pgoff;
 	rd = card->ch_in.is_mapped;
 	wr = card->ch_out.is_mapped;
 
@@ -2150,9 +2141,8 @@ static struct page * via_mm_nopage (stru
 	DPRINTK ("EXIT, returning page %p for cpuaddr %lXh\n",
 		 dmapage, (unsigned long) chan->pgtbl[pgoff].cpuaddr);
 	get_page (dmapage);
-	if (type)
-		*type = VM_FAULT_MINOR;
-	return dmapage;
+	vmf->page = dmapage;
+	return 0;
 }
 
 
@@ -2165,7 +2155,7 @@ static int via_mm_swapout (struct page *
 
 
 static struct vm_operations_struct via_mm_ops = {
-	.nopage		= via_mm_nopage,
+	.fault		= via_mm_fault,
 
 #ifndef VM_RESERVED
 	.swapout	= via_mm_swapout,

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 15/18] alsa: usx2y nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (13 preceding siblings ...)
  2007-12-05  7:16 ` [patch 14/18] oss: via nopage npiggin
@ 2007-12-05  7:16 ` npiggin
  2007-12-13 15:35   ` Takashi Iwai
  2007-12-05  7:16 ` [patch 16/18] mm: special mapping nopage npiggin
  2007-12-05  7:16 ` [patch 17/18] mm: remove nopage npiggin
  16 siblings, 1 reply; 44+ messages in thread
From: npiggin @ 2007-12-05  7:16 UTC (permalink / raw)
  To: akpm; +Cc: tiwai, annabellesgarden, linux-kernel

[-- Attachment #1: alsa-usx2y-nopage.patch --]
[-- Type: text/plain, Size: 3222 bytes --]

Convert alsa usx2y driver from nopage to fault.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: tiwai@suse.de
Cc: annabellesgarden@yahoo.de
Cc: linux-kernel@vger.kernel.org
---
 sound/usb/usx2y/usX2Yhwdep.c    |   21 ++++++++-------------
 sound/usb/usx2y/usx2yhwdeppcm.c |   19 ++++++-------------
 2 files changed, 14 insertions(+), 26 deletions(-)

Index: linux-2.6/sound/usb/usx2y/usX2Yhwdep.c
===================================================================
--- linux-2.6.orig/sound/usb/usx2y/usX2Yhwdep.c
+++ linux-2.6/sound/usb/usx2y/usX2Yhwdep.c
@@ -34,34 +34,29 @@
 int usX2Y_hwdep_pcm_new(struct snd_card *card);
 
 
-static struct page * snd_us428ctls_vm_nopage(struct vm_area_struct *area, unsigned long address, int *type)
+static int snd_us428ctls_vm_fault(struct vm_area_struct *area, struct vm_fault *vmf)
 {
 	unsigned long offset;
 	struct page * page;
 	void *vaddr;
 
-	snd_printdd("ENTER, start %lXh, ofs %lXh, pgoff %ld, addr %lXh\n",
+	snd_printdd("ENTER, start %lXh, pgoff %ld\n",
 		   area->vm_start,
-		   address - area->vm_start,
-		   (address - area->vm_start) >> PAGE_SHIFT,
-		   address);
+		   vmf->pgoff);
 	
-	offset = area->vm_pgoff << PAGE_SHIFT;
-	offset += address - area->vm_start;
-	snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_SIGBUS);
+	offset = vmf->pgoff << PAGE_SHIFT;
 	vaddr = (char*)((struct usX2Ydev *)area->vm_private_data)->us428ctls_sharedmem + offset;
 	page = virt_to_page(vaddr);
 	get_page(page);
-	snd_printdd( "vaddr=%p made us428ctls_vm_nopage() return %p; offset=%lX\n", vaddr, page, offset);
+	vmf->page = page;
 
-	if (type)
-		*type = VM_FAULT_MINOR;
+	snd_printdd( "vaddr=%p made us428ctls_vm_fault() page %p\n", vaddr, page);
 
-	return page;
+	return 0;
 }
 
 static struct vm_operations_struct us428ctls_vm_ops = {
-	.nopage = snd_us428ctls_vm_nopage,
+	.fault = snd_us428ctls_vm_fault,
 };
 
 static int snd_us428ctls_mmap(struct snd_hwdep * hw, struct file *filp, struct vm_area_struct *area)
Index: linux-2.6/sound/usb/usx2y/usx2yhwdeppcm.c
===================================================================
--- linux-2.6.orig/sound/usb/usx2y/usx2yhwdeppcm.c
+++ linux-2.6/sound/usb/usx2y/usx2yhwdeppcm.c
@@ -683,30 +683,23 @@ static void snd_usX2Y_hwdep_pcm_vm_close
 }
 
 
-static struct page * snd_usX2Y_hwdep_pcm_vm_nopage(struct vm_area_struct *area, unsigned long address, int *type)
+static int snd_usX2Y_hwdep_pcm_vm_fault(struct vm_area_struct *area, struct vm_fault *vmf)
 {
 	unsigned long offset;
-	struct page *page;
 	void *vaddr;
 
-	offset = area->vm_pgoff << PAGE_SHIFT;
-	offset += address - area->vm_start;
-	snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_OOM);
+	offset = vmf->pgoff << PAGE_SHIFT;
 	vaddr = (char*)((struct usX2Ydev *)area->vm_private_data)->hwdep_pcm_shm + offset;
-	page = virt_to_page(vaddr);
-	get_page(page);
-
-	if (type)
-		*type = VM_FAULT_MINOR;
-
-	return page;
+	vmf->page = virt_to_page(vaddr);
+	get_page(vmf->page);
+	return 0;
 }
 
 
 static struct vm_operations_struct snd_usX2Y_hwdep_pcm_vm_ops = {
 	.open = snd_usX2Y_hwdep_pcm_vm_open,
 	.close = snd_usX2Y_hwdep_pcm_vm_close,
-	.nopage = snd_usX2Y_hwdep_pcm_vm_nopage,
+	.fault = snd_usX2Y_hwdep_pcm_vm_fault,
 };
 
 

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 16/18] mm: special mapping nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (14 preceding siblings ...)
  2007-12-05  7:16 ` [patch 15/18] alsa: usx2y nopage npiggin
@ 2007-12-05  7:16 ` npiggin
  2007-12-05  7:16 ` [patch 17/18] mm: remove nopage npiggin
  16 siblings, 0 replies; 44+ messages in thread
From: npiggin @ 2007-12-05  7:16 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel

[-- Attachment #1: special-mapping-nopage.patch --]
[-- Type: text/plain, Size: 2340 bytes --]

Convert special mapping install from nopage to fault. This requires a
small special case in the do_linear_fault calculation in order to handle
vmas without ->vm_file set.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
---
 mm/memory.c |   10 +++++++---
 mm/mmap.c   |   19 +++++++++----------
 2 files changed, 16 insertions(+), 13 deletions(-)

Index: linux-2.6/mm/memory.c
===================================================================
--- linux-2.6.orig/mm/memory.c
+++ linux-2.6/mm/memory.c
@@ -2352,9 +2352,13 @@ static int do_linear_fault(struct mm_str
 		unsigned long address, pte_t *page_table, pmd_t *pmd,
 		int write_access, pte_t orig_pte)
 {
-	pgoff_t pgoff = (((address & PAGE_MASK)
-			- vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
-	unsigned int flags = (write_access ? FAULT_FLAG_WRITE : 0);
+	pgoff_t pgoff;
+	unsigned int flags;
+
+	pgoff = (((address) - vma->vm_start) >> PAGE_SHIFT);
+	if (likely(vma->vm_file))
+		pgoff += vma->vm_pgoff;
+	flags = (write_access ? FAULT_FLAG_WRITE : 0);
 
 	pte_unmap(page_table);
 	return __do_fault(mm, vma, address, pmd, pgoff, flags, orig_pte);
Index: linux-2.6/mm/mmap.c
===================================================================
--- linux-2.6.orig/mm/mmap.c
+++ linux-2.6/mm/mmap.c
@@ -2149,24 +2149,23 @@ int may_expand_vm(struct mm_struct *mm, 
 }
 
 
-static struct page *special_mapping_nopage(struct vm_area_struct *vma,
-					   unsigned long address, int *type)
+static int special_mapping_fault(struct vm_area_struct *vma,
+				struct vm_fault *vmf)
 {
+	pgoff_t pgoff = vmf->pgoff;
 	struct page **pages;
 
-	BUG_ON(address < vma->vm_start || address >= vma->vm_end);
-
-	address -= vma->vm_start;
-	for (pages = vma->vm_private_data; address > 0 && *pages; ++pages)
-		address -= PAGE_SIZE;
+	for (pages = vma->vm_private_data; pgoff && *pages; ++pages)
+		pgoff--;
 
 	if (*pages) {
 		struct page *page = *pages;
 		get_page(page);
-		return page;
+		vmf->page = page;
+		return 0;
 	}
 
-	return NOPAGE_SIGBUS;
+	return VM_FAULT_SIGBUS;
 }
 
 /*
@@ -2178,7 +2177,7 @@ static void special_mapping_close(struct
 
 static struct vm_operations_struct special_mapping_vmops = {
 	.close = special_mapping_close,
-	.nopage	= special_mapping_nopage,
+	.fault = special_mapping_fault,
 };
 
 /*

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch 17/18] mm: remove nopage
  2007-12-05  7:15 [patch 00/18] remove nopage npiggin
                   ` (15 preceding siblings ...)
  2007-12-05  7:16 ` [patch 16/18] mm: special mapping nopage npiggin
@ 2007-12-05  7:16 ` npiggin
  2007-12-05 22:47   ` Andrew Morton
  16 siblings, 1 reply; 44+ messages in thread
From: npiggin @ 2007-12-05  7:16 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel

[-- Attachment #1: mm-remove-nopage.patch --]
[-- Type: text/plain, Size: 7563 bytes --]

Nothing in the tree uses nopage any more. Remove support for it in the
core mm code and documentation (and a few stray references to it in comments).

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
---
 Documentation/feature-removal-schedule.txt |    9 --------
 Documentation/filesystems/Locking          |    3 --
 drivers/media/video/vino.c                 |    2 -
 drivers/video/vermilion/vermilion.c        |    5 ++--
 include/linux/mm.h                         |    8 -------
 mm/memory.c                                |   32 ++++++++++-------------------
 mm/mincore.c                               |    2 -
 mm/mmap.c                                  |   20 +++++++++---------
 mm/rmap.c                                  |    1 
 9 files changed, 27 insertions(+), 55 deletions(-)

Index: linux-2.6/include/linux/mm.h
===================================================================
--- linux-2.6.orig/include/linux/mm.h
+++ linux-2.6/include/linux/mm.h
@@ -162,8 +162,6 @@ struct vm_operations_struct {
 	void (*open)(struct vm_area_struct * area);
 	void (*close)(struct vm_area_struct * area);
 	int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf);
-	struct page *(*nopage)(struct vm_area_struct *area,
-			unsigned long address, int *type);
 	unsigned long (*nopfn)(struct vm_area_struct *area,
 			unsigned long address);
 
@@ -611,12 +609,6 @@ static inline int page_mapped(struct pag
 }
 
 /*
- * Error return values for the *_nopage functions
- */
-#define NOPAGE_SIGBUS	(NULL)
-#define NOPAGE_OOM	((struct page *) (-1))
-
-/*
  * Error return values for the *_nopfn functions
  */
 #define NOPFN_SIGBUS	((unsigned long) -1)
Index: linux-2.6/mm/memory.c
===================================================================
--- linux-2.6.orig/mm/memory.c
+++ linux-2.6/mm/memory.c
@@ -1044,8 +1044,7 @@ int get_user_pages(struct task_struct *t
 		if (pages)
 			foll_flags |= FOLL_GET;
 		if (!write && !(vma->vm_flags & VM_LOCKED) &&
-		    (!vma->vm_ops || (!vma->vm_ops->nopage &&
-					!vma->vm_ops->fault)))
+		    (!vma->vm_ops || !vma->vm_ops->fault))
 			foll_flags |= FOLL_ANON;
 
 		do {
@@ -2218,20 +2217,9 @@ static int __do_fault(struct mm_struct *
 
 	BUG_ON(vma->vm_flags & VM_PFNMAP);
 
-	if (likely(vma->vm_ops->fault)) {
-		ret = vma->vm_ops->fault(vma, &vmf);
-		if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))
-			return ret;
-	} else {
-		/* Legacy ->nopage path */
-		ret = 0;
-		vmf.page = vma->vm_ops->nopage(vma, address & PAGE_MASK, &ret);
-		/* no page was available -- either SIGBUS or OOM */
-		if (unlikely(vmf.page == NOPAGE_SIGBUS))
-			return VM_FAULT_SIGBUS;
-		else if (unlikely(vmf.page == NOPAGE_OOM))
-			return VM_FAULT_OOM;
-	}
+	ret = vma->vm_ops->fault(vma, &vmf);
+	if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))
+		return ret;
 
 	/*
 	 * For consistency in subsequent calls, make the faulted page always
@@ -2471,7 +2459,7 @@ static inline int handle_pte_fault(struc
 	if (!pte_present(entry)) {
 		if (pte_none(entry)) {
 			if (vma->vm_ops) {
-				if (vma->vm_ops->fault || vma->vm_ops->nopage)
+				if (likely(vma->vm_ops->fault))
 					return do_linear_fault(mm, vma, address,
 						pte, pmd, write_access, entry);
 				if (unlikely(vma->vm_ops->nopfn))
Index: linux-2.6/mm/mincore.c
===================================================================
--- linux-2.6.orig/mm/mincore.c
+++ linux-2.6/mm/mincore.c
@@ -33,7 +33,7 @@ static unsigned char mincore_page(struct
 	 * When tmpfs swaps out a page from a file, any process mapping that
 	 * file will not get a swp_entry_t in its pte, but rather it is like
 	 * any other file mapping (ie. marked !present and faulted in with
-	 * tmpfs's .nopage). So swapped out tmpfs mappings are tested here.
+	 * tmpfs's .fault). So swapped out tmpfs mappings are tested here.
 	 *
 	 * However when tmpfs moves the page from pagecache and into swapcache,
 	 * it is still in core, but the find_get_page below won't find it.
Index: linux-2.6/Documentation/feature-removal-schedule.txt
===================================================================
--- linux-2.6.orig/Documentation/feature-removal-schedule.txt
+++ linux-2.6/Documentation/feature-removal-schedule.txt
@@ -172,15 +172,6 @@ Who:	Greg Kroah-Hartman <gregkh@suse.de>
 
 ---------------------------
 
-What:	vm_ops.nopage
-When:	Soon, provided in-kernel callers have been converted
-Why:	This interface is replaced by vm_ops.fault, but it has been around
-	forever, is used by a lot of drivers, and doesn't cost much to
-	maintain.
-Who:	Nick Piggin <npiggin@suse.de>
-
----------------------------
-
 What:	PHYSDEVPATH, PHYSDEVBUS, PHYSDEVDRIVER in the uevent environment
 When:	October 2008
 Why:	The stacking of class devices makes these values misleading and
Index: linux-2.6/Documentation/filesystems/Locking
===================================================================
--- linux-2.6.orig/Documentation/filesystems/Locking
+++ linux-2.6/Documentation/filesystems/Locking
@@ -514,7 +514,6 @@ prototypes:
 	void (*open)(struct vm_area_struct*);
 	void (*close)(struct vm_area_struct*);
 	int (*fault)(struct vm_area_struct*, struct vm_fault *);
-	struct page *(*nopage)(struct vm_area_struct*, unsigned long, int *);
 	int (*page_mkwrite)(struct vm_area_struct *, struct page *);
 
 locking rules:
@@ -522,7 +521,6 @@ locking rules:
 open:		no	yes
 close:		no	yes
 fault:		no	yes
-nopage:		no	yes
 page_mkwrite:	no	yes		no
 
 	->page_mkwrite() is called when a previously read-only page is
@@ -540,4 +538,3 @@ NULL.
 
 ipc/shm.c::shm_delete() - may need BKL.
 ->read() and ->write() in many drivers are (probably) missing BKL.
-drivers/sgi/char/graphics.c::sgi_graphics_nopage() - may need BKL.
Index: linux-2.6/mm/rmap.c
===================================================================
--- linux-2.6.orig/mm/rmap.c
+++ linux-2.6/mm/rmap.c
@@ -623,7 +623,6 @@ void page_remove_rmap(struct page *page,
 			printk (KERN_EMERG "  page->mapping = %p\n", page->mapping);
 			print_symbol (KERN_EMERG "  vma->vm_ops = %s\n", (unsigned long)vma->vm_ops);
 			if (vma->vm_ops) {
-				print_symbol (KERN_EMERG "  vma->vm_ops->nopage = %s\n", (unsigned long)vma->vm_ops->nopage);
 				print_symbol (KERN_EMERG "  vma->vm_ops->fault = %s\n", (unsigned long)vma->vm_ops->fault);
 			}
 			if (vma->vm_file && vma->vm_file->f_op)
Index: linux-2.6/drivers/media/video/vino.c
===================================================================
--- linux-2.6.orig/drivers/media/video/vino.c
+++ linux-2.6/drivers/media/video/vino.c
@@ -13,7 +13,7 @@
 /*
  * TODO:
  * - remove "mark pages reserved-hacks" from memory allocation code
- *   and implement nopage()
+ *   and implement fault()
  * - check decimation, calculating and reporting image size when
  *   using decimation
  * - implement read(), user mode buffers and overlay (?)
Index: linux-2.6/drivers/video/vermilion/vermilion.c
===================================================================
--- linux-2.6.orig/drivers/video/vermilion/vermilion.c
+++ linux-2.6/drivers/video/vermilion/vermilion.c
@@ -114,8 +114,9 @@ static int vmlfb_alloc_vram_area(struct 
 
 	/*
 	 * It seems like __get_free_pages only ups the usage count
-	 * of the first page. This doesn't work with nopage mapping, so
-	 * up the usage count once more.
+	 * of the first page. This doesn't work with fault mapping, so
+	 * up the usage count once more (XXX: should use split_page or
+	 * compound page).
 	 */
 
 	memset((void *)va->logical, 0x00, va->size);

-- 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 03/18] drm: nopage
  2007-12-05  7:15 ` [patch 03/18] drm: nopage npiggin
@ 2007-12-05  9:05   ` Dave Airlie
  2007-12-05  9:17     ` Nick Piggin
  0 siblings, 1 reply; 44+ messages in thread
From: Dave Airlie @ 2007-12-05  9:05 UTC (permalink / raw)
  To: npiggin; +Cc: akpm, linux-kernel


> Convert drm from nopage to fault.
> Remove redundant vma range checks.

Hi Nick,

can you rebase against the -mm tree? or are you pushing this for before 
then? if so can you supply me a patch against -mm?

The drm git tree has a new VM user for the memory manager..

Dave.

> 
> Signed-off-by: Nick Piggin <npiggin@suse.de>
> Cc: airlied@linux.ie
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/char/drm/drm_vm.c |  131 +++++++++++++++++++++-------------------------
>  1 file changed, 61 insertions(+), 70 deletions(-)
> 
> Index: linux-2.6/drivers/char/drm/drm_vm.c
> ===================================================================
> --- linux-2.6.orig/drivers/char/drm/drm_vm.c
> +++ linux-2.6/drivers/char/drm/drm_vm.c
> @@ -66,7 +66,7 @@ static pgprot_t drm_io_prot(uint32_t map
>  }
>  
>  /**
> - * \c nopage method for AGP virtual memory.
> + * \c fault method for AGP virtual memory.
>   *
>   * \param vma virtual memory area.
>   * \param address access address.
> @@ -76,8 +76,8 @@ static pgprot_t drm_io_prot(uint32_t map
>   * map, get the page, increment the use count and return it.
>   */
>  #if __OS_HAS_AGP
> -static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
> -						unsigned long address)
> +static __inline__ int drm_do_vm_fault(struct vm_area_struct *vma,
> +						struct vm_fault *vmf)
>  {
>  	struct drm_file *priv = vma->vm_file->private_data;
>  	struct drm_device *dev = priv->head->dev;
> @@ -89,19 +89,24 @@ static __inline__ struct page *drm_do_vm
>  	 * Find the right map
>  	 */
>  	if (!drm_core_has_AGP(dev))
> -		goto vm_nopage_error;
> +		goto vm_fault_error;
>  
>  	if (!dev->agp || !dev->agp->cant_use_aperture)
> -		goto vm_nopage_error;
> +		goto vm_fault_error;
>  
>  	if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash))
> -		goto vm_nopage_error;
> +		goto vm_fault_error;
>  
>  	r_list = drm_hash_entry(hash, struct drm_map_list, hash);
>  	map = r_list->map;
>  
>  	if (map && map->type == _DRM_AGP) {
> -		unsigned long offset = address - vma->vm_start;
> +		/*
> +		 * Using vm_pgoff as a selector forces us to use this unusual
> +		 * addressing scheme.
> +		 */
> +		unsigned long offset = (unsigned long)vmf->virtual_address -
> +								vma->vm_start;
>  		unsigned long baddr = map->offset + offset;
>  		struct drm_agp_mem *agpmem;
>  		struct page *page;
> @@ -123,7 +128,7 @@ static __inline__ struct page *drm_do_vm
>  		}
>  
>  		if (!agpmem)
> -			goto vm_nopage_error;
> +			goto vm_fault_error;
>  
>  		/*
>  		 * Get the page, inc the use count, and return it
> @@ -131,27 +136,28 @@ static __inline__ struct page *drm_do_vm
>  		offset = (baddr - agpmem->bound) >> PAGE_SHIFT;
>  		page = virt_to_page(__va(agpmem->memory->memory[offset]));
>  		get_page(page);
> +		vmf->page = page;
>  
>  		DRM_DEBUG
>  		    ("baddr = 0x%lx page = 0x%p, offset = 0x%lx, count=%d\n",
>  		     baddr, __va(agpmem->memory->memory[offset]), offset,
>  		     page_count(page));
>  
> -		return page;
> +		return 0;
>  	}
> -      vm_nopage_error:
> -	return NOPAGE_SIGBUS;	/* Disallow mremap */
> +      vm_fault_error:
> +	return VM_FAULT_SIGBUS;	/* Disallow mremap */
>  }
>  #else				/* __OS_HAS_AGP */
> -static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
> -						unsigned long address)
> +static __inline__ int drm_do_vm_fault(struct vm_area_struct *vma,
> +						struct vm_fault *vmf)
>  {
> -	return NOPAGE_SIGBUS;
> +	return VM_FAULT_SIGBUS;
>  }
>  #endif				/* __OS_HAS_AGP */
>  
>  /**
> - * \c nopage method for shared virtual memory.
> + * \c fault method for shared virtual memory.
>   *
>   * \param vma virtual memory area.
>   * \param address access address.
> @@ -160,28 +166,27 @@ static __inline__ struct page *drm_do_vm
>   * Get the mapping, find the real physical page to map, get the page, and
>   * return it.
>   */
> -static __inline__ struct page *drm_do_vm_shm_nopage(struct vm_area_struct *vma,
> -						    unsigned long address)
> +static __inline__ int drm_do_vm_shm_fault(struct vm_area_struct *vma,
> +						    struct vm_fault *vmf)
>  {
>  	struct drm_map *map = (struct drm_map *) vma->vm_private_data;
>  	unsigned long offset;
>  	unsigned long i;
>  	struct page *page;
>  
> -	if (address > vma->vm_end)
> -		return NOPAGE_SIGBUS;	/* Disallow mremap */
>  	if (!map)
> -		return NOPAGE_SIGBUS;	/* Nothing allocated */
> +		return VM_FAULT_SIGBUS;	/* Nothing allocated */
>  
> -	offset = address - vma->vm_start;
> +	offset = (unsigned long)vmf->virtual_address - vma->vm_start;
>  	i = (unsigned long)map->handle + offset;
>  	page = vmalloc_to_page((void *)i);
>  	if (!page)
> -		return NOPAGE_SIGBUS;
> +		return VM_FAULT_SIGBUS;
>  	get_page(page);
> +	vmf->page = page;
>  
> -	DRM_DEBUG("shm_nopage 0x%lx\n", address);
> -	return page;
> +	DRM_DEBUG("shm_fault 0x%lx\n", offset);
> +	return 0;
>  }
>  
>  /**
> @@ -263,7 +268,7 @@ static void drm_vm_shm_close(struct vm_a
>  }
>  
>  /**
> - * \c nopage method for DMA virtual memory.
> + * \c fault method for DMA virtual memory.
>   *
>   * \param vma virtual memory area.
>   * \param address access address.
> @@ -271,8 +276,8 @@ static void drm_vm_shm_close(struct vm_a
>   *
>   * Determine the page number from the page offset and get it from drm_device_dma::pagelist.
>   */
> -static __inline__ struct page *drm_do_vm_dma_nopage(struct vm_area_struct *vma,
> -						    unsigned long address)
> +static __inline__ int drm_do_vm_dma_fault(struct vm_area_struct *vma,
> +						    struct vm_fault *vmf)
>  {
>  	struct drm_file *priv = vma->vm_file->private_data;
>  	struct drm_device *dev = priv->head->dev;
> @@ -282,24 +287,23 @@ static __inline__ struct page *drm_do_vm
>  	struct page *page;
>  
>  	if (!dma)
> -		return NOPAGE_SIGBUS;	/* Error */
> -	if (address > vma->vm_end)
> -		return NOPAGE_SIGBUS;	/* Disallow mremap */
> +		return VM_FAULT_SIGBUS;	/* Error */
>  	if (!dma->pagelist)
> -		return NOPAGE_SIGBUS;	/* Nothing allocated */
> +		return VM_FAULT_SIGBUS;	/* Nothing allocated */
>  
> -	offset = address - vma->vm_start;	/* vm_[pg]off[set] should be 0 */
> -	page_nr = offset >> PAGE_SHIFT;
> +	offset = (unsigned long)vmf->virtual_address - vma->vm_start;	/* vm_[pg]off[set] should be 0 */
> +	page_nr = offset >> PAGE_SHIFT; /* page_nr could just be vmf->pgoff */
>  	page = virt_to_page((dma->pagelist[page_nr] + (offset & (~PAGE_MASK))));
>  
>  	get_page(page);
> +	vmf->page = page;
>  
> -	DRM_DEBUG("dma_nopage 0x%lx (page %lu)\n", address, page_nr);
> -	return page;
> +	DRM_DEBUG("dma_fault 0x%lx (page %lu)\n", offset, page_nr);
> +	return 0;
>  }
>  
>  /**
> - * \c nopage method for scatter-gather virtual memory.
> + * \c fault method for scatter-gather virtual memory.
>   *
>   * \param vma virtual memory area.
>   * \param address access address.
> @@ -307,8 +311,8 @@ static __inline__ struct page *drm_do_vm
>   *
>   * Determine the map offset from the page offset and get it from drm_sg_mem::pagelist.
>   */
> -static __inline__ struct page *drm_do_vm_sg_nopage(struct vm_area_struct *vma,
> -						   unsigned long address)
> +static __inline__ int drm_do_vm_sg_fault(struct vm_area_struct *vma,
> +						   struct vm_fault *vmf)
>  {
>  	struct drm_map *map = (struct drm_map *) vma->vm_private_data;
>  	struct drm_file *priv = vma->vm_file->private_data;
> @@ -320,77 +324,64 @@ static __inline__ struct page *drm_do_vm
>  	struct page *page;
>  
>  	if (!entry)
> -		return NOPAGE_SIGBUS;	/* Error */
> -	if (address > vma->vm_end)
> -		return NOPAGE_SIGBUS;	/* Disallow mremap */
> +		return VM_FAULT_SIGBUS;	/* Error */
>  	if (!entry->pagelist)
> -		return NOPAGE_SIGBUS;	/* Nothing allocated */
> +		return VM_FAULT_SIGBUS;	/* Nothing allocated */
>  
> -	offset = address - vma->vm_start;
> +	offset = (unsigned long)vmf->virtual_address - vma->vm_start;
>  	map_offset = map->offset - (unsigned long)dev->sg->virtual;
>  	page_offset = (offset >> PAGE_SHIFT) + (map_offset >> PAGE_SHIFT);
>  	page = entry->pagelist[page_offset];
>  	get_page(page);
> +	vmf->page = page;
>  
> -	return page;
> +	return 0;
>  }
>  
> -static struct page *drm_vm_nopage(struct vm_area_struct *vma,
> -				  unsigned long address, int *type)
> +static int drm_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
>  {
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -	return drm_do_vm_nopage(vma, address);
> +	return drm_do_vm_fault(vma, vmf);
>  }
>  
> -static struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
> -				      unsigned long address, int *type)
> +static int drm_vm_shm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
>  {
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -	return drm_do_vm_shm_nopage(vma, address);
> +	return drm_do_vm_shm_fault(vma, vmf);
>  }
>  
> -static struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
> -				      unsigned long address, int *type)
> +static int drm_vm_dma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
>  {
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -	return drm_do_vm_dma_nopage(vma, address);
> +	return drm_do_vm_dma_fault(vma, vmf);
>  }
>  
> -static struct page *drm_vm_sg_nopage(struct vm_area_struct *vma,
> -				     unsigned long address, int *type)
> +static int drm_vm_sg_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
>  {
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -	return drm_do_vm_sg_nopage(vma, address);
> +	return drm_do_vm_sg_fault(vma, vmf);
>  }
>  
>  /** AGP virtual memory operations */
>  static struct vm_operations_struct drm_vm_ops = {
> -	.nopage = drm_vm_nopage,
> +	.fault = drm_vm_fault,
>  	.open = drm_vm_open,
>  	.close = drm_vm_close,
>  };
>  
>  /** Shared virtual memory operations */
>  static struct vm_operations_struct drm_vm_shm_ops = {
> -	.nopage = drm_vm_shm_nopage,
> +	.fault = drm_vm_shm_fault,
>  	.open = drm_vm_open,
>  	.close = drm_vm_shm_close,
>  };
>  
>  /** DMA virtual memory operations */
>  static struct vm_operations_struct drm_vm_dma_ops = {
> -	.nopage = drm_vm_dma_nopage,
> +	.fault = drm_vm_dma_fault,
>  	.open = drm_vm_open,
>  	.close = drm_vm_close,
>  };
>  
>  /** Scatter-gather virtual memory operations */
>  static struct vm_operations_struct drm_vm_sg_ops = {
> -	.nopage = drm_vm_sg_nopage,
> +	.fault = drm_vm_sg_fault,
>  	.open = drm_vm_open,
>  	.close = drm_vm_close,
>  };
> @@ -603,7 +594,7 @@ static int drm_mmap_locked(struct file *
>  			/*
>  			 * On some platforms we can't talk to bus dma address from the CPU, so for
>  			 * memory of type DRM_AGP, we'll deal with sorting out the real physical
> -			 * pages and mappings in nopage()
> +			 * pages and mappings in fault()
>  			 */
>  #if defined(__powerpc__)
>  			pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
> @@ -633,7 +624,7 @@ static int drm_mmap_locked(struct file *
>  		break;
>  	case _DRM_CONSISTENT:
>  		/* Consistent memory is really like shared memory. But
> -		 * it's allocated in a different way, so avoid nopage */
> +		 * it's allocated in a different way, so avoid fault */
>  		if (remap_pfn_range(vma, vma->vm_start,
>  		    page_to_pfn(virt_to_page(map->handle)),
>  		    vma->vm_end - vma->vm_start, vma->vm_page_prot))
> 
> 

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 03/18] drm: nopage
  2007-12-05  9:05   ` Dave Airlie
@ 2007-12-05  9:17     ` Nick Piggin
  0 siblings, 0 replies; 44+ messages in thread
From: Nick Piggin @ 2007-12-05  9:17 UTC (permalink / raw)
  To: Dave Airlie; +Cc: akpm, linux-kernel

On Wed, Dec 05, 2007 at 09:05:06AM +0000, Dave Airlie wrote:
> 
> > Convert drm from nopage to fault.
> > Remove redundant vma range checks.
> 
> Hi Nick,
> 
> can you rebase against the -mm tree? or are you pushing this for before 
> then? if so can you supply me a patch against -mm?

I'm not sure where I am in the pecking order, although there are some
security issues (I didn't cc you on that patch, doh). So the patches
are against mainline to give the option of merging them earlier.

All the patches except 17/18 are standalone, however. So if any of them
don't apply for Andrew, I can do another pass to catch the remainders.
I'll definitely help you with the new drm VM one way or the other ;)


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 04/18] uio: nopage
  2007-12-05  7:15 ` [patch 04/18] uio: nopage npiggin
@ 2007-12-05 10:04   ` Hans-Jürgen Koch
  2007-12-05 10:10     ` Nick Piggin
  0 siblings, 1 reply; 44+ messages in thread
From: Hans-Jürgen Koch @ 2007-12-05 10:04 UTC (permalink / raw)
  To: npiggin; +Cc: akpm, greg, linux-kernel

Am Wed, 05 Dec 2007 18:15:51 +1100
schrieb npiggin@suse.de:

> Convert uio from nopage to fault.
> 
> Signed-off-by: Nick Piggin <npiggin@suse.de>
> Cc: greg@kroah.com

Hi Nick,
could you please add me to Cc: for UIO stuff:

Cc: hjk@linutronix.de

The patch itself looks alright to me, but I didn't test with a real
driver.

Acked-by: Hans J Koch <hjk@linutronix.de>

Thanks,
Hans


> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/uio/uio.c |   14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> Index: linux-2.6/drivers/uio/uio.c
> ===================================================================
> --- linux-2.6.orig/drivers/uio/uio.c
> +++ linux-2.6/drivers/uio/uio.c
> @@ -412,30 +412,28 @@ static void uio_vma_close(struct vm_area
>  	idev->vma_count--;
>  }
>  
> -static struct page *uio_vma_nopage(struct vm_area_struct *vma,
> -				   unsigned long address, int *type)
> +static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault
> *vmf) {
>  	struct uio_device *idev = vma->vm_private_data;
> -	struct page* page = NOPAGE_SIGBUS;
> +	struct page *page;
>  
>  	int mi = uio_find_mem_index(vma);
>  	if (mi < 0)
> -		return page;
> +		return VM_FAULT_SIGBUS;
>  
>  	if (idev->info->mem[mi].memtype == UIO_MEM_LOGICAL)
>  		page = virt_to_page(idev->info->mem[mi].addr);
>  	else
>  		page =
> vmalloc_to_page((void*)idev->info->mem[mi].addr); get_page(page);
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -	return page;
> +	vmf->page = page;
> +	return 0;
>  }
>  
>  static struct vm_operations_struct uio_vm_ops = {
>  	.open = uio_vma_open,
>  	.close = uio_vma_close,
> -	.nopage = uio_vma_nopage,
> +	.fault = uio_vma_fault,
>  };
>  
>  static int uio_mmap_physical(struct vm_area_struct *vma)
> 

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 04/18] uio: nopage
  2007-12-05 10:04   ` Hans-Jürgen Koch
@ 2007-12-05 10:10     ` Nick Piggin
  2007-12-05 10:25       ` Hans-Jürgen Koch
  0 siblings, 1 reply; 44+ messages in thread
From: Nick Piggin @ 2007-12-05 10:10 UTC (permalink / raw)
  To: Hans-Jürgen Koch; +Cc: akpm, greg, linux-kernel

On Wed, Dec 05, 2007 at 11:04:08AM +0100, Hans-Jürgen Koch wrote:
> Am Wed, 05 Dec 2007 18:15:51 +1100
> schrieb npiggin@suse.de:
> 
> > Convert uio from nopage to fault.
> > 
> > Signed-off-by: Nick Piggin <npiggin@suse.de>
> > Cc: greg@kroah.com
> 
> Hi Nick,
> could you please add me to Cc: for UIO stuff:
> 
> Cc: hjk@linutronix.de

Sure, I'll try to remember in future. It would be helpful if you could
add an entry to MAINTAINERS?

> 
> The patch itself looks alright to me, but I didn't test with a real
> driver.
> 
> Acked-by: Hans J Koch <hjk@linutronix.de>

Thanks,
Nick



^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 04/18] uio: nopage
  2007-12-05 10:10     ` Nick Piggin
@ 2007-12-05 10:25       ` Hans-Jürgen Koch
  2007-12-05 10:37         ` Nick Piggin
  0 siblings, 1 reply; 44+ messages in thread
From: Hans-Jürgen Koch @ 2007-12-05 10:25 UTC (permalink / raw)
  To: Nick Piggin; +Cc: akpm, greg, linux-kernel

Am Wed, 5 Dec 2007 11:10:42 +0100
schrieb Nick Piggin <npiggin@suse.de>:

> On Wed, Dec 05, 2007 at 11:04:08AM +0100, Hans-Jürgen Koch wrote:
> > Am Wed, 05 Dec 2007 18:15:51 +1100
> > schrieb npiggin@suse.de:
> > 
> > > Convert uio from nopage to fault.
> > > 
> > > Signed-off-by: Nick Piggin <npiggin@suse.de>
> > > Cc: greg@kroah.com
> > 
> > Hi Nick,
> > could you please add me to Cc: for UIO stuff:
> > 
> > Cc: hjk@linutronix.de
> 
> Sure, I'll try to remember in future. It would be helpful if you could
> add an entry to MAINTAINERS?

Well, although I wrote a lot of UIO code and feel a bit responsible for
it, I don't know if I can call myself an UIO maintainer. ATM, I think
it's considered "driver core" and is therefore in Greg's domain.

Thanks,
Hans

> 
> > 
> > The patch itself looks alright to me, but I didn't test with a real
> > driver.
> > 
> > Acked-by: Hans J Koch <hjk@linutronix.de>
> 
> Thanks,
> Nick
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 04/18] uio: nopage
  2007-12-05 10:25       ` Hans-Jürgen Koch
@ 2007-12-05 10:37         ` Nick Piggin
  0 siblings, 0 replies; 44+ messages in thread
From: Nick Piggin @ 2007-12-05 10:37 UTC (permalink / raw)
  To: Hans-Jürgen Koch; +Cc: akpm, greg, linux-kernel

On Wed, Dec 05, 2007 at 11:25:00AM +0100, Hans-Jürgen Koch wrote:
> Am Wed, 5 Dec 2007 11:10:42 +0100
> schrieb Nick Piggin <npiggin@suse.de>:
> 
> > On Wed, Dec 05, 2007 at 11:04:08AM +0100, Hans-Jürgen Koch wrote:
> > > Am Wed, 05 Dec 2007 18:15:51 +1100
> > > schrieb npiggin@suse.de:
> > > 
> > > > Convert uio from nopage to fault.
> > > > 
> > > > Signed-off-by: Nick Piggin <npiggin@suse.de>
> > > > Cc: greg@kroah.com
> > > 
> > > Hi Nick,
> > > could you please add me to Cc: for UIO stuff:
> > > 
> > > Cc: hjk@linutronix.de
> > 
> > Sure, I'll try to remember in future. It would be helpful if you could
> > add an entry to MAINTAINERS?
> 
> Well, although I wrote a lot of UIO code and feel a bit responsible for
> it, I don't know if I can call myself an UIO maintainer. ATM, I think
> it's considered "driver core" and is therefore in Greg's domain.

If you're interested in reviewing patches for it, I think that's
valuable enough that we don't have to worry about formal titles ;)

Also, you can have more than one email address for a given MAINTAINERS
entry. So I'm sure Greg wouldn't mind if you were there too.

Thanks,
Nick


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 05/18] kvm: nopage
  2007-12-05  7:15 ` [patch 05/18] kvm: nopage npiggin
@ 2007-12-05 10:40   ` Avi Kivity
  0 siblings, 0 replies; 44+ messages in thread
From: Avi Kivity @ 2007-12-05 10:40 UTC (permalink / raw)
  To: npiggin; +Cc: akpm, kvm-devel, linux-kernel

npiggin@suse.de wrote:
> Convert KVM from nopage to fault.
>
>   

> @@ -3111,27 +3105,21 @@ out:
>  	return r;
>  }
>  
> -static struct page *kvm_vm_nopage(struct vm_area_struct *vma,
> -				  unsigned long address,
> -				  int *type)
> +static int kvm_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
>  {
>  	struct kvm *kvm = vma->vm_file->private_data;
> -	unsigned long pgoff;
>  	struct page *page;
>  
> -	pgoff = ((address - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
> -	page = gfn_to_page(kvm, pgoff);
> +	page = gfn_to_page(kvm, vmf->pgoff);
>  	if (!page)
> -		return NOPAGE_SIGBUS;
> +		return VM_FAULT_SIGBUS;
>  	get_page(page);
> -	if (type != NULL)
> -		*type = VM_FAULT_MINOR;
> -
> -	return page;
> +	vmf->page = page;
> +	return 0;
>  }
>  
>   

This part has changed in kvm.git, so this won't apply to -mm.  I ported 
it and applied to my tree, so it should arrive in -mm when Andrew 
re-fetches.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 06/18] ieee1394: nopage
  2007-12-05  7:15 ` [patch 06/18] ieee1394: nopage npiggin
@ 2007-12-05 13:09   ` Stefan Richter
  2007-12-05 13:15     ` Stefan Richter
  2007-12-05 23:51     ` Nick Piggin
  2007-12-15 13:01   ` Stefan Richter
  1 sibling, 2 replies; 44+ messages in thread
From: Stefan Richter @ 2007-12-05 13:09 UTC (permalink / raw)
  To: npiggin; +Cc: akpm, krh, linux1394-devel, linux-kernel

npiggin@suse.de wrote:
> Convert ieee1394 from nopage to fault.
> Remove redundant vma range checks (correct resource range check is retained).

I never really looked into that part of the 1394 drivers and I'm too
lazy to figure this out myself, so I ask:  What would trip the .fault
handler?  Would be good if I could runtime-test it.

> Signed-off-by: Nick Piggin <npiggin@suse.de>
> Cc: krh@redhat.com

It's an obscure and unimportant detail but I mention it nevertheless:
It's not necessary to Cc krh on drivers/ieee1394 stuff.  He is more into
drivers/firewire. :-)

> Cc: stefanr@s5r6.in-berlin.de
> Cc: linux1394-devel@lists.sourceforge.net
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/ieee1394/dma.c |   39 +++++++++++++++++----------------------
>  1 file changed, 17 insertions(+), 22 deletions(-)
> 
> Index: linux-2.6/drivers/ieee1394/dma.c
> ===================================================================
> --- linux-2.6.orig/drivers/ieee1394/dma.c
> +++ linux-2.6/drivers/ieee1394/dma.c
> @@ -231,37 +231,32 @@ void dma_region_sync_for_device(struct d
>  
>  #ifdef CONFIG_MMU
>  
> -/* nopage() handler for mmap access */
> +/* fault() handler for mmap access */
>  
> -static struct page *dma_region_pagefault(struct vm_area_struct *area,
> -					 unsigned long address, int *type)
> +static int dma_region_pagefault(struct vm_area_struct *vma,
> +					struct vm_fault *vmf)
>  {
> -	unsigned long offset;
>  	unsigned long kernel_virt_addr;
> -	struct page *ret = NOPAGE_SIGBUS;
>  
> -	struct dma_region *dma = (struct dma_region *)area->vm_private_data;
> +	struct dma_region *dma = (struct dma_region *)vma->vm_private_data;
>  
>  	if (!dma->kvirt)
> -		goto out;
> +		goto error;
>  
> -	if ((address < (unsigned long)area->vm_start) ||
> -	    (address >
> -	     (unsigned long)area->vm_start + (dma->n_pages << PAGE_SHIFT)))
> -		goto out;
> -
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -	offset = address - area->vm_start;
> -	kernel_virt_addr = (unsigned long)dma->kvirt + offset;
> -	ret = vmalloc_to_page((void *)kernel_virt_addr);
> -	get_page(ret);
> -      out:
> -	return ret;
> +	if (vmf->pgoff >= dma->n_pages)
> +		goto error;
> +
> +	kernel_virt_addr = (unsigned long)dma->kvirt + (vmf->pgoff << PAGE_SHIFT);
> +	vmf->page = vmalloc_to_page((void *)kernel_virt_addr);
> +	get_page(vmf->page);
> +	return 0;
> +
> +      error:
> +	return VM_FAULT_SIGBUS;
>  }

Why not replacing the two 'goto error' by 'return VM_FAULT_SIGBUS'?  If
there is no cleanup after that error jump, I find it sensible to return
early.

>  
>  static struct vm_operations_struct dma_region_vm_ops = {
> -	.nopage = dma_region_pagefault,
> +	.fault = dma_region_pagefault,
>  };
>  
>  /**
> @@ -275,7 +270,7 @@ int dma_region_mmap(struct dma_region *d
>  	if (!dma->kvirt)
>  		return -EINVAL;
>  
> -	/* must be page-aligned */
> +	/* must be page-aligned (XXX: comment is wrong, we could allow pgoff) */
>  	if (vma->vm_pgoff != 0)
>  		return -EINVAL;
>  

Are you sure that the comment is wrong?  Could it be that there are
assumptions elsewhere which require page alignment?  (I should be able
to answer that, but I'm not.)
-- 
Stefan Richter
-=====-=-=== ==-- --=-=
http://arcgraph.de/sr/

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 06/18] ieee1394: nopage
  2007-12-05 13:09   ` Stefan Richter
@ 2007-12-05 13:15     ` Stefan Richter
  2007-12-05 23:52       ` Nick Piggin
  2007-12-05 23:51     ` Nick Piggin
  1 sibling, 1 reply; 44+ messages in thread
From: Stefan Richter @ 2007-12-05 13:15 UTC (permalink / raw)
  To: npiggin; +Cc: akpm, krh, linux1394-devel, linux-kernel

> npiggin@suse.de wrote:
>> @@ -275,7 +270,7 @@ int dma_region_mmap(struct dma_region *d
>>  	if (!dma->kvirt)
>>  		return -EINVAL;
>>  
>> -	/* must be page-aligned */
>> +	/* must be page-aligned (XXX: comment is wrong, we could allow pgoff) */
>>  	if (vma->vm_pgoff != 0)
>>  		return -EINVAL;
>>  
> 
> Are you sure that the comment is wrong?  Could it be that there are
> assumptions elsewhere which require page alignment?  (I should be able
> to answer that, but I'm not.)

PS:  Assumed the comment is wrong, is the code wrong then too?
-- 
Stefan Richter
-=====-=-=== ==-- --=-=
http://arcgraph.de/sr/

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 12/18] usb: mon nopage
  2007-12-05  7:15 ` [patch 12/18] usb: mon nopage npiggin
@ 2007-12-05 16:39   ` Pete Zaitcev
  2007-12-05 23:54     ` Nick Piggin
  0 siblings, 1 reply; 44+ messages in thread
From: Pete Zaitcev @ 2007-12-05 16:39 UTC (permalink / raw)
  To: npiggin; +Cc: akpm, paolo.abeni, linux-kernel

On Wed, 05 Dec 2007 18:15:59 +1100, npiggin@suse.de wrote:

> Convert USB mon driver from nopage to fault.

>  	if (offset >= rp->b_size)
> -		return NOPAGE_SIGBUS;
> +		return VM_FAULT_SIGBUS;
>  	chunk_idx = offset / CHUNK_SIZE;
>  	pageptr = rp->b_vec[chunk_idx].pg;
>  	get_page(pageptr);
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -	return pageptr;
> +	vmf->page = pageptr;
> +	return 0;

Looks like a trivial change, I ack this. It's a rarely used API, I have
to run tests to see how it works. I'll collect any failing pieces later
if any.

Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>

-- Pete

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 17/18] mm: remove nopage
  2007-12-05  7:16 ` [patch 17/18] mm: remove nopage npiggin
@ 2007-12-05 22:47   ` Andrew Morton
  2007-12-05 23:23     ` Nick Piggin
  0 siblings, 1 reply; 44+ messages in thread
From: Andrew Morton @ 2007-12-05 22:47 UTC (permalink / raw)
  To: npiggin; +Cc: linux-mm, linux-kernel

On Wed, 05 Dec 2007 18:16:04 +1100
npiggin@suse.de wrote:

> Nothing in the tree uses nopage any more. Remove support for it in the
> core mm code and documentation (and a few stray references to it in comments).

I'll duck this for now.  It's going to take a long time to get all those
other patches merged given my usual ~75% dropped-on-the-floor rate from
subsystem maintainers.  Please resend when mainline is nopage-free.



^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 17/18] mm: remove nopage
  2007-12-05 22:47   ` Andrew Morton
@ 2007-12-05 23:23     ` Nick Piggin
  0 siblings, 0 replies; 44+ messages in thread
From: Nick Piggin @ 2007-12-05 23:23 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel

On Wed, Dec 05, 2007 at 02:47:00PM -0800, Andrew Morton wrote:
> On Wed, 05 Dec 2007 18:16:04 +1100
> npiggin@suse.de wrote:
> 
> > Nothing in the tree uses nopage any more. Remove support for it in the
> > core mm code and documentation (and a few stray references to it in comments).
> 
> I'll duck this for now.  It's going to take a long time to get all those
> other patches merged given my usual ~75% dropped-on-the-floor rate from
> subsystem maintainers.  Please resend when mainline is nopage-free.

Sure, no problem.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 06/18] ieee1394: nopage
  2007-12-05 13:09   ` Stefan Richter
  2007-12-05 13:15     ` Stefan Richter
@ 2007-12-05 23:51     ` Nick Piggin
  2007-12-15 13:04       ` Stefan Richter
  1 sibling, 1 reply; 44+ messages in thread
From: Nick Piggin @ 2007-12-05 23:51 UTC (permalink / raw)
  To: Stefan Richter; +Cc: akpm, krh, linux1394-devel, linux-kernel

On Wed, Dec 05, 2007 at 02:09:48PM +0100, Stefan Richter wrote:
> npiggin@suse.de wrote:
> > Convert ieee1394 from nopage to fault.
> > Remove redundant vma range checks (correct resource range check is retained).
> 
> I never really looked into that part of the 1394 drivers and I'm too
> lazy to figure this out myself, so I ask:  What would trip the .fault
> handler?  Would be good if I could runtime-test it.

mmap()ing a device file for that driver, and accessing the memory.

 
> > Signed-off-by: Nick Piggin <npiggin@suse.de>
> > Cc: krh@redhat.com
> 
> It's an obscure and unimportant detail but I mention it nevertheless:
> It's not necessary to Cc krh on drivers/ieee1394 stuff.  He is more into
> drivers/firewire. :-)

OK, I'll try to keep it straight ;)

> > +	if (vmf->pgoff >= dma->n_pages)
> > +		goto error;
> > +
> > +	kernel_virt_addr = (unsigned long)dma->kvirt + (vmf->pgoff << PAGE_SHIFT);
> > +	vmf->page = vmalloc_to_page((void *)kernel_virt_addr);
> > +	get_page(vmf->page);
> > +	return 0;
> > +
> > +      error:
> > +	return VM_FAULT_SIGBUS;
> >  }
> 
> Why not replacing the two 'goto error' by 'return VM_FAULT_SIGBUS'?  If
> there is no cleanup after that error jump, I find it sensible to return
> early.

Fair enough, I just didn't want to gamut of reactions from maintainers
to my cleanups ;)


> >  static struct vm_operations_struct dma_region_vm_ops = {
> > -	.nopage = dma_region_pagefault,
> > +	.fault = dma_region_pagefault,
> >  };
> >  
> >  /**
> > @@ -275,7 +270,7 @@ int dma_region_mmap(struct dma_region *d
> >  	if (!dma->kvirt)
> >  		return -EINVAL;
> >  
> > -	/* must be page-aligned */
> > +	/* must be page-aligned (XXX: comment is wrong, we could allow pgoff) */
> >  	if (vma->vm_pgoff != 0)
> >  		return -EINVAL;
> >  
> 
> Are you sure that the comment is wrong?  Could it be that there are
> assumptions elsewhere which require page alignment?  (I should be able
> to answer that, but I'm not.)

The file offset given to mmap must be page size multiple, and thus vm_pgoff
is in units of page size (see the fault handler, where it gets shifted).
Removing this restriction would allow the use of offset in mmap(), but if
you want to disallow it for other reasons, then I guess the comment
should be changed to explain why.


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 06/18] ieee1394: nopage
  2007-12-05 13:15     ` Stefan Richter
@ 2007-12-05 23:52       ` Nick Piggin
  0 siblings, 0 replies; 44+ messages in thread
From: Nick Piggin @ 2007-12-05 23:52 UTC (permalink / raw)
  To: Stefan Richter; +Cc: akpm, krh, linux1394-devel, linux-kernel

On Wed, Dec 05, 2007 at 02:15:35PM +0100, Stefan Richter wrote:
> > npiggin@suse.de wrote:
> >> @@ -275,7 +270,7 @@ int dma_region_mmap(struct dma_region *d
> >>  	if (!dma->kvirt)
> >>  		return -EINVAL;
> >>  
> >> -	/* must be page-aligned */
> >> +	/* must be page-aligned (XXX: comment is wrong, we could allow pgoff) */
> >>  	if (vma->vm_pgoff != 0)
> >>  		return -EINVAL;
> >>  
> > 
> > Are you sure that the comment is wrong?  Could it be that there are
> > assumptions elsewhere which require page alignment?  (I should be able
> > to answer that, but I'm not.)
> 
> PS:  Assumed the comment is wrong, is the code wrong then too?

The mmap / fault code _seems_ OK. The check here is only wrong in that it
doesn't prevent non-page-aligned mappings (the core VM code already does).

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 12/18] usb: mon nopage
  2007-12-05 16:39   ` Pete Zaitcev
@ 2007-12-05 23:54     ` Nick Piggin
  0 siblings, 0 replies; 44+ messages in thread
From: Nick Piggin @ 2007-12-05 23:54 UTC (permalink / raw)
  To: Pete Zaitcev; +Cc: akpm, paolo.abeni, linux-kernel

On Wed, Dec 05, 2007 at 08:39:25AM -0800, Pete Zaitcev wrote:
> On Wed, 05 Dec 2007 18:15:59 +1100, npiggin@suse.de wrote:
> 
> > Convert USB mon driver from nopage to fault.
> 
> >  	if (offset >= rp->b_size)
> > -		return NOPAGE_SIGBUS;
> > +		return VM_FAULT_SIGBUS;
> >  	chunk_idx = offset / CHUNK_SIZE;
> >  	pageptr = rp->b_vec[chunk_idx].pg;
> >  	get_page(pageptr);
> > -	if (type)
> > -		*type = VM_FAULT_MINOR;
> > -	return pageptr;
> > +	vmf->page = pageptr;
> > +	return 0;
> 
> Looks like a trivial change, I ack this. It's a rarely used API, I have
> to run tests to see how it works. I'll collect any failing pieces later
> if any.

That would be great, thanks.


> Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>
> 
> -- Pete

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 07/18] v4l: nopage
  2007-12-05  7:15 ` [patch 07/18] v4l: nopage npiggin
@ 2007-12-08  0:31   ` Andrew Morton
  2007-12-08  9:15     ` Ingo Molnar
                       ` (2 more replies)
  0 siblings, 3 replies; 44+ messages in thread
From: Andrew Morton @ 2007-12-08  0:31 UTC (permalink / raw)
  To: npiggin
  Cc: mchehab, v4l-dvb-maintainer, linux-kernel, Ingo Molnar, Andy Whitcroft

On Wed, 05 Dec 2007 18:15:54 +1100
npiggin@suse.de wrote:

> +static int
> +videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
>  {
>  	struct page *page;
>  
> -	dprintk(3,"nopage: fault @ %08lx [vma %08lx-%08lx]\n",
> -		vaddr,vma->vm_start,vma->vm_end);
> -	if (vaddr > vma->vm_end)
> -		return NOPAGE_SIGBUS;
> +	dprintk(3,"fault: fault @ %08lx [vma %08lx-%08lx]\n",
> +		(unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end);
>  	page = alloc_page(GFP_USER | __GFP_DMA32);
>  	if (!page)
> -		return NOPAGE_OOM;
> +		return VM_FAULT_OOM;
>  	clear_user_page(page_address(page), vaddr, page);

This didn't compile on sparc64 because `vaddr' is undefined.


Let us see why:

#define clear_user_page(page, vaddr, pg)	clear_page(page)
#define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)

#define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)

root cause: lack of argument checking on x86 due to stupid macros.


Could someone *please* start a little project of extirpating this utter
brain damage?  Convert those macros to typechecked static inlines on x86
(at least) so this sort of thing (which happens again and again and again)
is lessened?


macros are such miserable things.  I wonder if we could get checkpatch to
help out here?  

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 07/18] v4l: nopage
  2007-12-08  0:31   ` Andrew Morton
@ 2007-12-08  9:15     ` Ingo Molnar
  2007-12-08 10:15       ` Andrew Morton
  2007-12-09 17:10     ` Randy Dunlap
  2007-12-10  5:06     ` [patch] x64/page.h: convert some macros to inlines Randy Dunlap
  2 siblings, 1 reply; 44+ messages in thread
From: Ingo Molnar @ 2007-12-08  9:15 UTC (permalink / raw)
  To: Andrew Morton
  Cc: npiggin, mchehab, v4l-dvb-maintainer, linux-kernel, Andy Whitcroft


* Andrew Morton <akpm@linux-foundation.org> wrote:

> On Wed, 05 Dec 2007 18:15:54 +1100
> npiggin@suse.de wrote:
> 
> > +static int
> > +videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
> >  {
> >  	struct page *page;
> >  
> > -	dprintk(3,"nopage: fault @ %08lx [vma %08lx-%08lx]\n",
> > -		vaddr,vma->vm_start,vma->vm_end);
> > -	if (vaddr > vma->vm_end)
> > -		return NOPAGE_SIGBUS;
> > +	dprintk(3,"fault: fault @ %08lx [vma %08lx-%08lx]\n",
> > +		(unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end);
> >  	page = alloc_page(GFP_USER | __GFP_DMA32);
> >  	if (!page)
> > -		return NOPAGE_OOM;
> > +		return VM_FAULT_OOM;
> >  	clear_user_page(page_address(page), vaddr, page);
> 
> This didn't compile on sparc64 because `vaddr' is undefined.
> 
> 
> Let us see why:
> 
> #define clear_user_page(page, vaddr, pg)	clear_page(page)
> #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
> 
> #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
> 	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
> 
> root cause: lack of argument checking on x86 due to stupid macros.
> 
> 
> Could someone *please* start a little project of extirpating this 
> utter brain damage?  Convert those macros to typechecked static 
> inlines on x86 (at least) so this sort of thing (which happens again 
> and again and again) is lessened?

i wanted to write a reply to suggest a checkpatch policy for this. When 
i noticed this sentence at the end of your mail:

> macros are such miserable things.  I wonder if we could get checkpatch 
> to help out here?

/me too :-)

any policy that gets into checkpatch.pl's default output is a policy for 
arch/x86 patch merging. (as long as it's not a false positive) And 
because we do all these unifications the effects of checkpatch.pl 
permeate basically every aspect of arch/x86.

one approach would be to make new macros in include/* a no-no. That 
would hurt a few of the legitimate uses though, so maybe a useful 
refinement would be to check the structure of macros: are arguments used 
twice (side-effect), are arguments unused (typechecking dager), are 
arguments cast (type-loss danger), etc. Looks very hard to implement 
though :-/ Andy, what do you think?

	Ingo

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 07/18] v4l: nopage
  2007-12-08  9:15     ` Ingo Molnar
@ 2007-12-08 10:15       ` Andrew Morton
  0 siblings, 0 replies; 44+ messages in thread
From: Andrew Morton @ 2007-12-08 10:15 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: npiggin, mchehab, v4l-dvb-maintainer, linux-kernel, Andy Whitcroft

On Sat, 8 Dec 2007 10:15:08 +0100 Ingo Molnar <mingo@elte.hu> wrote:

> 
> * Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> > On Wed, 05 Dec 2007 18:15:54 +1100
> > npiggin@suse.de wrote:
> > 
> > > +static int
> > > +videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
> > >  {
> > >  	struct page *page;
> > >  
> > > -	dprintk(3,"nopage: fault @ %08lx [vma %08lx-%08lx]\n",
> > > -		vaddr,vma->vm_start,vma->vm_end);
> > > -	if (vaddr > vma->vm_end)
> > > -		return NOPAGE_SIGBUS;
> > > +	dprintk(3,"fault: fault @ %08lx [vma %08lx-%08lx]\n",
> > > +		(unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end);
> > >  	page = alloc_page(GFP_USER | __GFP_DMA32);
> > >  	if (!page)
> > > -		return NOPAGE_OOM;
> > > +		return VM_FAULT_OOM;
> > >  	clear_user_page(page_address(page), vaddr, page);
> > 
> > This didn't compile on sparc64 because `vaddr' is undefined.
> > 
> > 
> > Let us see why:
> > 
> > #define clear_user_page(page, vaddr, pg)	clear_page(page)
> > #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
> > 
> > #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
> > 	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
> > 
> > root cause: lack of argument checking on x86 due to stupid macros.
> > 
> > 
> > Could someone *please* start a little project of extirpating this 
> > utter brain damage?  Convert those macros to typechecked static 
> > inlines on x86 (at least) so this sort of thing (which happens again 
> > and again and again) is lessened?

We should fix existing stuff, like this.

> i wanted to write a reply to suggest a checkpatch policy for this. When 
> i noticed this sentence at the end of your mail:
> 
> > macros are such miserable things.  I wonder if we could get checkpatch 
> > to help out here?
> 
> /me too :-)
> 
> any policy that gets into checkpatch.pl's default output is a policy for 
> arch/x86 patch merging. (as long as it's not a false positive) And 
> because we do all these unifications the effects of checkpatch.pl 
> permeate basically every aspect of arch/x86.
> 
> one approach would be to make new macros in include/* a no-no. That 
> would hurt a few of the legitimate uses though, so maybe a useful 
> refinement would be to check the structure of macros: are arguments used 
> twice (side-effect), are arguments unused (typechecking dager), are 
> arguments cast (type-loss danger), etc. Looks very hard to implement 
> though :-/ Andy, what do you think?

I think whining about anything which matches

#define foo(...) bar(

would be a decent start.

grep '^[       ]*#[    ]*define[       ][      ]*[^(]*[(][^)]*[)][      ]*[a-zA-Z]' include/asm-x86/*.h

(hey, that worked on the first attempt)

Lots of falsies tho.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 07/18] v4l: nopage
  2007-12-08  0:31   ` Andrew Morton
  2007-12-08  9:15     ` Ingo Molnar
@ 2007-12-09 17:10     ` Randy Dunlap
  2007-12-10  5:06     ` [patch] x64/page.h: convert some macros to inlines Randy Dunlap
  2 siblings, 0 replies; 44+ messages in thread
From: Randy Dunlap @ 2007-12-09 17:10 UTC (permalink / raw)
  To: Andrew Morton
  Cc: npiggin, mchehab, v4l-dvb-maintainer, linux-kernel, Ingo Molnar,
	Andy Whitcroft

On Fri, 7 Dec 2007 16:31:42 -0800 Andrew Morton wrote:

> On Wed, 05 Dec 2007 18:15:54 +1100
> npiggin@suse.de wrote:
> 
> > +static int
> > +videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
> >  {
> >  	struct page *page;
> >  
> > -	dprintk(3,"nopage: fault @ %08lx [vma %08lx-%08lx]\n",
> > -		vaddr,vma->vm_start,vma->vm_end);
> > -	if (vaddr > vma->vm_end)
> > -		return NOPAGE_SIGBUS;
> > +	dprintk(3,"fault: fault @ %08lx [vma %08lx-%08lx]\n",
> > +		(unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end);
> >  	page = alloc_page(GFP_USER | __GFP_DMA32);
> >  	if (!page)
> > -		return NOPAGE_OOM;
> > +		return VM_FAULT_OOM;
> >  	clear_user_page(page_address(page), vaddr, page);
> 
> This didn't compile on sparc64 because `vaddr' is undefined.
> 
> 
> Let us see why:
> 
> #define clear_user_page(page, vaddr, pg)	clear_page(page)
> #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
> 
> #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
> 	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
> 
> root cause: lack of argument checking on x86 due to stupid macros.

Hm, I would have said that the root cause was that Nick removed the
vaddr parameter from the function parameters:

-static struct page*
-videobuf_vm_nopage(struct vm_area_struct *vma, unsigned long vaddr,
-		   int *type)
+static int
+videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {

Should the function now produce 'vaddr' internally?


> Could someone *please* start a little project of extirpating this utter
> brain damage?  Convert those macros to typechecked static inlines on x86
> (at least) so this sort of thing (which happens again and again and again)
> is lessened?

Yep, unless someone else is already doing so...

> macros are such miserable things.  I wonder if we could get checkpatch to
> help out here?  


---
~Randy
Features and documentation: http://lwn.net/Articles/260136/

^ permalink raw reply	[flat|nested] 44+ messages in thread

* [patch] x64/page.h: convert some macros to inlines
  2007-12-08  0:31   ` Andrew Morton
  2007-12-08  9:15     ` Ingo Molnar
  2007-12-09 17:10     ` Randy Dunlap
@ 2007-12-10  5:06     ` Randy Dunlap
  2007-12-10  8:34       ` Ingo Molnar
  2 siblings, 1 reply; 44+ messages in thread
From: Randy Dunlap @ 2007-12-10  5:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: npiggin, mchehab, v4l-dvb-maintainer, linux-kernel, Ingo Molnar,
	Andy Whitcroft

On Fri, 7 Dec 2007 16:31:42 -0800 Andrew Morton wrote:

> Could someone *please* start a little project of extirpating this utter
> brain damage?  Convert those macros to typechecked static inlines on x86
> (at least) so this sort of thing (which happens again and again and again)
> is lessened?

Here's a start on it.  x86 only and only 4 functions so far.
Builds cleanly for i386 and x86_64.

---

From: Randy Dunlap <randy.dunlap@oracle.com>

Convert clear_page/copy_page macros to inline functions for type-checking.
Andrew wants to extirpate these ugly macros.

Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
---
 include/asm-x86/page_32.h |   39 +++++++++++++++++++++++++++++++++------
 include/asm-x86/page_64.h |   19 +++++++++++++++----
 2 files changed, 48 insertions(+), 10 deletions(-)

--- linux-2.6.24-rc4-git6.orig/include/asm-x86/page_32.h
+++ linux-2.6.24-rc4-git6/include/asm-x86/page_32.h
@@ -12,12 +12,21 @@
 #ifdef __KERNEL__
 #ifndef __ASSEMBLY__
 
+#include <linux/string.h>
+
 #ifdef CONFIG_X86_USE_3DNOW
 
 #include <asm/mmx.h>
 
-#define clear_page(page)	mmx_clear_page((void *)(page))
-#define copy_page(to,from)	mmx_copy_page(to,from)
+static inline void clear_page(void *page)
+{
+	mmx_clear_page(page);
+}
+
+static inline void copy_page(void *to, void *from)
+{
+	mmx_copy_page(to, from);
+}
 
 #else
 
@@ -26,13 +35,31 @@
  *	Maybe the K6-III ?
  */
  
-#define clear_page(page)	memset((void *)(page), 0, PAGE_SIZE)
-#define copy_page(to,from)	memcpy((void *)(to), (void *)(from), PAGE_SIZE)
+static inline void clear_page(void *page)
+{
+	memset(page, 0, PAGE_SIZE);
+}
+
+static inline void copy_page(void *to, void *from)
+{
+	memcpy(to, from, PAGE_SIZE);
+}
 
 #endif
 
-#define clear_user_page(page, vaddr, pg)	clear_page(page)
-#define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
+struct page;
+
+static void inline clear_user_page(void *page, unsigned long vaddr,
+				struct page *pg)
+{
+	clear_page(page);
+}
+
+static void inline copy_user_page(void *to, void *from, unsigned long vaddr,
+				struct page *topage)
+{
+	copy_page(to, from);
+}
 
 #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
 	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
--- linux-2.6.24-rc4-git6.orig/include/asm-x86/page_64.h
+++ linux-2.6.24-rc4-git6/include/asm-x86/page_64.h
@@ -42,11 +42,22 @@
 
 extern unsigned long end_pfn;
 
-void clear_page(void *);
-void copy_page(void *, void *);
+void clear_page(void *page);
+void copy_page(void *to, void *from);
 
-#define clear_user_page(page, vaddr, pg)	clear_page(page)
-#define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
+struct page;
+
+static void inline clear_user_page(void *page, unsigned long vaddr,
+				struct page *pg)
+{
+	clear_page(page);
+}
+
+static void inline copy_user_page(void *to, void *from, unsigned long vaddr,
+				struct page *topage)
+{
+	copy_page(to, from);
+}
 
 #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
 	alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch] x64/page.h: convert some macros to inlines
  2007-12-10  5:06     ` [patch] x64/page.h: convert some macros to inlines Randy Dunlap
@ 2007-12-10  8:34       ` Ingo Molnar
  0 siblings, 0 replies; 44+ messages in thread
From: Ingo Molnar @ 2007-12-10  8:34 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Andrew Morton, npiggin, mchehab, v4l-dvb-maintainer,
	linux-kernel, Andy Whitcroft


* Randy Dunlap <randy.dunlap@oracle.com> wrote:

> > Could someone *please* start a little project of extirpating this 
> > utter brain damage?  Convert those macros to typechecked static 
> > inlines on x86 (at least) so this sort of thing (which happens again 
> > and again and again) is lessened?
> 
> Here's a start on it.  x86 only and only 4 functions so far. Builds 
> cleanly for i386 and x86_64.

great - applied.

	Ingo

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 13/18] alsa: nopage
  2007-12-05  7:16 ` [patch 13/18] alsa: nopage npiggin
@ 2007-12-13 15:35   ` Takashi Iwai
  0 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2007-12-13 15:35 UTC (permalink / raw)
  To: npiggin; +Cc: akpm, perex, alsa-devel, linux-kernel

At Wed, 05 Dec 2007 18:16:00 +1100,
npiggin@suse.de wrote:
> 
> Convert ALSA from nopage to fault.
> Switch from OOM to SIGBUS if the resource is not available.
> 
> Signed-off-by: Nick Piggin <npiggin@suse.de>
> Cc: perex@perex.cz
> Cc: tiwai@suse.de
> Cc: alsa-devel@alsa-project.org
> Cc: linux-kernel@vger.kernel.org

I applied this to ALSA HG tree.


thanks,

Takashi

> ---
>  sound/core/pcm_native.c |   59 ++++++++++++++++++++----------------------------
>  1 file changed, 25 insertions(+), 34 deletions(-)
> 
> Index: linux-2.6/sound/core/pcm_native.c
> ===================================================================
> --- linux-2.6.orig/sound/core/pcm_native.c
> +++ linux-2.6/sound/core/pcm_native.c
> @@ -3018,26 +3018,23 @@ static unsigned int snd_pcm_capture_poll
>  /*
>   * mmap status record
>   */
> -static struct page * snd_pcm_mmap_status_nopage(struct vm_area_struct *area,
> -						unsigned long address, int *type)
> +static int snd_pcm_mmap_status_fault(struct vm_area_struct *area,
> +						struct vm_fault *vmf)
>  {
>  	struct snd_pcm_substream *substream = area->vm_private_data;
>  	struct snd_pcm_runtime *runtime;
> -	struct page * page;
>  	
>  	if (substream == NULL)
> -		return NOPAGE_SIGBUS;
> +		return VM_FAULT_SIGBUS;
>  	runtime = substream->runtime;
> -	page = virt_to_page(runtime->status);
> -	get_page(page);
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -	return page;
> +	vmf->page = virt_to_page(runtime->status);
> +	get_page(vmf->page);
> +	return 0;
>  }
>  
>  static struct vm_operations_struct snd_pcm_vm_ops_status =
>  {
> -	.nopage =	snd_pcm_mmap_status_nopage,
> +	.fault =	snd_pcm_mmap_status_fault,
>  };
>  
>  static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file,
> @@ -3061,26 +3058,23 @@ static int snd_pcm_mmap_status(struct sn
>  /*
>   * mmap control record
>   */
> -static struct page * snd_pcm_mmap_control_nopage(struct vm_area_struct *area,
> -						 unsigned long address, int *type)
> +static int snd_pcm_mmap_control_fault(struct vm_area_struct *area,
> +						struct vm_fault *vmf)
>  {
>  	struct snd_pcm_substream *substream = area->vm_private_data;
>  	struct snd_pcm_runtime *runtime;
> -	struct page * page;
>  	
>  	if (substream == NULL)
> -		return NOPAGE_SIGBUS;
> +		return VM_FAULT_SIGBUS;
>  	runtime = substream->runtime;
> -	page = virt_to_page(runtime->control);
> -	get_page(page);
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -	return page;
> +	vmf->page = virt_to_page(runtime->control);
> +	get_page(vmf->page);
> +	return 0;
>  }
>  
>  static struct vm_operations_struct snd_pcm_vm_ops_control =
>  {
> -	.nopage =	snd_pcm_mmap_control_nopage,
> +	.fault =	snd_pcm_mmap_control_fault,
>  };
>  
>  static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file,
> @@ -3117,10 +3111,10 @@ static int snd_pcm_mmap_control(struct s
>  #endif /* coherent mmap */
>  
>  /*
> - * nopage callback for mmapping a RAM page
> + * fault callback for mmapping a RAM page
>   */
> -static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area,
> -					     unsigned long address, int *type)
> +static int snd_pcm_mmap_data_fault(struct vm_area_struct *area,
> +						struct vm_fault *vmf)
>  {
>  	struct snd_pcm_substream *substream = area->vm_private_data;
>  	struct snd_pcm_runtime *runtime;
> @@ -3130,33 +3124,30 @@ static struct page *snd_pcm_mmap_data_no
>  	size_t dma_bytes;
>  	
>  	if (substream == NULL)
> -		return NOPAGE_SIGBUS;
> +		return VM_FAULT_SIGBUS;
>  	runtime = substream->runtime;
> -	offset = area->vm_pgoff << PAGE_SHIFT;
> -	offset += address - area->vm_start;
> -	snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_SIGBUS);
> +	offset = vmf->pgoff << PAGE_SHIFT;
>  	dma_bytes = PAGE_ALIGN(runtime->dma_bytes);
>  	if (offset > dma_bytes - PAGE_SIZE)
> -		return NOPAGE_SIGBUS;
> +		return VM_FAULT_SIGBUS;
>  	if (substream->ops->page) {
>  		page = substream->ops->page(substream, offset);
> -		if (! page)
> -			return NOPAGE_OOM; /* XXX: is this really due to OOM? */
> +		if (!page)
> +			return VM_FAULT_SIGBUS;
>  	} else {
>  		vaddr = runtime->dma_area + offset;
>  		page = virt_to_page(vaddr);
>  	}
>  	get_page(page);
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -	return page;
> +	vmf->page = page;
> +	return 0;
>  }
>  
>  static struct vm_operations_struct snd_pcm_vm_ops_data =
>  {
>  	.open =		snd_pcm_mmap_data_open,
>  	.close =	snd_pcm_mmap_data_close,
> -	.nopage =	snd_pcm_mmap_data_nopage,
> +	.fault =	snd_pcm_mmap_data_fault,
>  };
>  
>  /*
> 
> -- 
> 

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 15/18] alsa: usx2y nopage
  2007-12-05  7:16 ` [patch 15/18] alsa: usx2y nopage npiggin
@ 2007-12-13 15:35   ` Takashi Iwai
  0 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2007-12-13 15:35 UTC (permalink / raw)
  To: npiggin; +Cc: akpm, annabellesgarden, linux-kernel

At Wed, 05 Dec 2007 18:16:02 +1100,
npiggin@suse.de wrote:
> 
> Convert alsa usx2y driver from nopage to fault.
> 
> Signed-off-by: Nick Piggin <npiggin@suse.de>
> Cc: tiwai@suse.de
> Cc: annabellesgarden@yahoo.de
> Cc: linux-kernel@vger.kernel.org

Applied this one to ALSA tree, too.


thanks,

Takashi

> ---
>  sound/usb/usx2y/usX2Yhwdep.c    |   21 ++++++++-------------
>  sound/usb/usx2y/usx2yhwdeppcm.c |   19 ++++++-------------
>  2 files changed, 14 insertions(+), 26 deletions(-)
> 
> Index: linux-2.6/sound/usb/usx2y/usX2Yhwdep.c
> ===================================================================
> --- linux-2.6.orig/sound/usb/usx2y/usX2Yhwdep.c
> +++ linux-2.6/sound/usb/usx2y/usX2Yhwdep.c
> @@ -34,34 +34,29 @@
>  int usX2Y_hwdep_pcm_new(struct snd_card *card);
>  
>  
> -static struct page * snd_us428ctls_vm_nopage(struct vm_area_struct *area, unsigned long address, int *type)
> +static int snd_us428ctls_vm_fault(struct vm_area_struct *area, struct vm_fault *vmf)
>  {
>  	unsigned long offset;
>  	struct page * page;
>  	void *vaddr;
>  
> -	snd_printdd("ENTER, start %lXh, ofs %lXh, pgoff %ld, addr %lXh\n",
> +	snd_printdd("ENTER, start %lXh, pgoff %ld\n",
>  		   area->vm_start,
> -		   address - area->vm_start,
> -		   (address - area->vm_start) >> PAGE_SHIFT,
> -		   address);
> +		   vmf->pgoff);
>  	
> -	offset = area->vm_pgoff << PAGE_SHIFT;
> -	offset += address - area->vm_start;
> -	snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_SIGBUS);
> +	offset = vmf->pgoff << PAGE_SHIFT;
>  	vaddr = (char*)((struct usX2Ydev *)area->vm_private_data)->us428ctls_sharedmem + offset;
>  	page = virt_to_page(vaddr);
>  	get_page(page);
> -	snd_printdd( "vaddr=%p made us428ctls_vm_nopage() return %p; offset=%lX\n", vaddr, page, offset);
> +	vmf->page = page;
>  
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> +	snd_printdd( "vaddr=%p made us428ctls_vm_fault() page %p\n", vaddr, page);
>  
> -	return page;
> +	return 0;
>  }
>  
>  static struct vm_operations_struct us428ctls_vm_ops = {
> -	.nopage = snd_us428ctls_vm_nopage,
> +	.fault = snd_us428ctls_vm_fault,
>  };
>  
>  static int snd_us428ctls_mmap(struct snd_hwdep * hw, struct file *filp, struct vm_area_struct *area)
> Index: linux-2.6/sound/usb/usx2y/usx2yhwdeppcm.c
> ===================================================================
> --- linux-2.6.orig/sound/usb/usx2y/usx2yhwdeppcm.c
> +++ linux-2.6/sound/usb/usx2y/usx2yhwdeppcm.c
> @@ -683,30 +683,23 @@ static void snd_usX2Y_hwdep_pcm_vm_close
>  }
>  
>  
> -static struct page * snd_usX2Y_hwdep_pcm_vm_nopage(struct vm_area_struct *area, unsigned long address, int *type)
> +static int snd_usX2Y_hwdep_pcm_vm_fault(struct vm_area_struct *area, struct vm_fault *vmf)
>  {
>  	unsigned long offset;
> -	struct page *page;
>  	void *vaddr;
>  
> -	offset = area->vm_pgoff << PAGE_SHIFT;
> -	offset += address - area->vm_start;
> -	snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_OOM);
> +	offset = vmf->pgoff << PAGE_SHIFT;
>  	vaddr = (char*)((struct usX2Ydev *)area->vm_private_data)->hwdep_pcm_shm + offset;
> -	page = virt_to_page(vaddr);
> -	get_page(page);
> -
> -	if (type)
> -		*type = VM_FAULT_MINOR;
> -
> -	return page;
> +	vmf->page = virt_to_page(vaddr);
> +	get_page(vmf->page);
> +	return 0;
>  }
>  
>  
>  static struct vm_operations_struct snd_usX2Y_hwdep_pcm_vm_ops = {
>  	.open = snd_usX2Y_hwdep_pcm_vm_open,
>  	.close = snd_usX2Y_hwdep_pcm_vm_close,
> -	.nopage = snd_usX2Y_hwdep_pcm_vm_nopage,
> +	.fault = snd_usX2Y_hwdep_pcm_vm_fault,
>  };
>  
>  
> 
> -- 
> 

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 06/18] ieee1394: nopage
  2007-12-05  7:15 ` [patch 06/18] ieee1394: nopage npiggin
  2007-12-05 13:09   ` Stefan Richter
@ 2007-12-15 13:01   ` Stefan Richter
  1 sibling, 0 replies; 44+ messages in thread
From: Stefan Richter @ 2007-12-15 13:01 UTC (permalink / raw)
  To: npiggin; +Cc: akpm, linux1394-devel, linux-kernel

On  5 Dec, npiggin@suse.de wrote:
> Convert ieee1394 from nopage to fault.
> Remove redundant vma range checks (correct resource range check is retained).

I finally did a brief runtime test.  Works for me with coriander,
dvgrab, and kino on x86-64.  Committed to linux1394-2.6.git.
-- 
Stefan Richter
-=====-=-=== ==-- -====
http://arcgraph.de/sr/


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 06/18] ieee1394: nopage
  2007-12-05 23:51     ` Nick Piggin
@ 2007-12-15 13:04       ` Stefan Richter
  0 siblings, 0 replies; 44+ messages in thread
From: Stefan Richter @ 2007-12-15 13:04 UTC (permalink / raw)
  To: Nick Piggin; +Cc: akpm, linux1394-devel, linux-kernel

On  6 Dec, Nick Piggin wrote:
> On Wed, Dec 05, 2007 at 02:09:48PM +0100, Stefan Richter wrote:
>> npiggin@suse.de wrote:
>> > +	if (vmf->pgoff >= dma->n_pages)
>> > +		goto error;
>> > +
>> > +	kernel_virt_addr = (unsigned long)dma->kvirt + (vmf->pgoff << PAGE_SHIFT);
>> > +	vmf->page = vmalloc_to_page((void *)kernel_virt_addr);
>> > +	get_page(vmf->page);
>> > +	return 0;
>> > +
>> > +      error:
>> > +	return VM_FAULT_SIGBUS;
>> >  }
>> 
>> Why not replacing the two 'goto error' by 'return VM_FAULT_SIGBUS'?  If
>> there is no cleanup after that error jump, I find it sensible to return
>> early.
> 
> Fair enough, I just didn't want to gamut of reactions from maintainers
> to my cleanups ;)


Subject: ieee1394: small cleanup after "nopage"

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
 drivers/ieee1394/dma.c |   16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

Index: linux/drivers/ieee1394/dma.c
===================================================================
--- linux.orig/drivers/ieee1394/dma.c
+++ linux/drivers/ieee1394/dma.c
@@ -231,28 +231,20 @@ void dma_region_sync_for_device(struct d
 
 #ifdef CONFIG_MMU
 
-/* fault() handler for mmap access */
-
 static int dma_region_pagefault(struct vm_area_struct *vma,
-					struct vm_fault *vmf)
+				struct vm_fault *vmf)
 {
-	unsigned long kernel_virt_addr;
-
 	struct dma_region *dma = (struct dma_region *)vma->vm_private_data;
 
 	if (!dma->kvirt)
-		goto error;
+		return VM_FAULT_SIGBUS;
 
 	if (vmf->pgoff >= dma->n_pages)
-		goto error;
+		return VM_FAULT_SIGBUS;
 
-	kernel_virt_addr = (unsigned long)dma->kvirt + (vmf->pgoff << PAGE_SHIFT);
-	vmf->page = vmalloc_to_page((void *)kernel_virt_addr);
+	vmf->page = vmalloc_to_page(dma->kvirt + (vmf->pgoff << PAGE_SHIFT));
 	get_page(vmf->page);
 	return 0;
-
-      error:
-	return VM_FAULT_SIGBUS;
 }
 
 static struct vm_operations_struct dma_region_vm_ops = {


-- 
Stefan Richter
-=====-=-=== ==-- -====
http://arcgraph.de/sr/


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [patch 10/18] sg: nopage
  2007-12-05  7:15 ` [patch 10/18] sg: nopage npiggin
@ 2008-02-08  3:45   ` Douglas Gilbert
  0 siblings, 0 replies; 44+ messages in thread
From: Douglas Gilbert @ 2008-02-08  3:45 UTC (permalink / raw)
  To: npiggin; +Cc: akpm, linux-scsi, linux-kernel, James Bottomley

For the patch shown below:

Signed-off-by: Douglas Gilbert <dougg@torque.net>



npiggin@suse.de wrote:
Convert SG from nopage to fault.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: dgilbert@interlog.com
Cc: linux-scsi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
  drivers/scsi/sg.c |   23 +++++++++++------------
  1 file changed, 11 insertions(+), 12 deletions(-)

Index: linux-2.6/drivers/scsi/sg.c
===================================================================
--- linux-2.6.orig/drivers/scsi/sg.c
+++ linux-2.6/drivers/scsi/sg.c
@@ -1144,23 +1144,22 @@ sg_fasync(int fd, struct file *filp, int
  	return (retval < 0) ? retval : 0;
  }

-static struct page *
-sg_vma_nopage(struct vm_area_struct *vma, unsigned long addr, int *type)
+static int
+sg_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  {
  	Sg_fd *sfp;
-	struct page *page = NOPAGE_SIGBUS;
  	unsigned long offset, len, sa;
  	Sg_scatter_hold *rsv_schp;
  	struct scatterlist *sg;
  	int k;

  	if ((NULL == vma) || (!(sfp = (Sg_fd *) vma->vm_private_data)))
-		return page;
+		return VM_FAULT_SIGBUS;
  	rsv_schp = &sfp->reserve;
-	offset = addr - vma->vm_start;
+	offset = vmf->pgoff << PAGE_SHIFT;
  	if (offset >= rsv_schp->bufflen)
-		return page;
-	SCSI_LOG_TIMEOUT(3, printk("sg_vma_nopage: offset=%lu, scatg=%d\n",
+		return VM_FAULT_SIGBUS;
+	SCSI_LOG_TIMEOUT(3, printk("sg_vma_fault: offset=%lu, scatg=%d\n",
  				   offset, rsv_schp->k_use_sg));
  	sg = rsv_schp->buffer;
  	sa = vma->vm_start;
@@ -1169,21 +1168,21 @@ sg_vma_nopage(struct vm_area_struct *vma
  		len = vma->vm_end - sa;
  		len = (len < sg->length) ? len : sg->length;
  		if (offset < len) {
+			struct page *page;
  			page = virt_to_page(page_address(sg_page(sg)) + offset);
  			get_page(page);	/* increment page count */
-			break;
+			vmf->page = page;
+			return 0; /* success */
  		}
  		sa += len;
  		offset -= len;
  	}

-	if (type)
-		*type = VM_FAULT_MINOR;
-	return page;
+	return VM_FAULT_SIGBUS;
  }

  static struct vm_operations_struct sg_mmap_vm_ops = {
-	.nopage = sg_vma_nopage,
+	.fault = sg_vma_fault,
  };

  static int



^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2008-02-08  3:45 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-05  7:15 [patch 00/18] remove nopage npiggin
2007-12-05  7:15 ` [patch 01/18] ia64: ia32 nopage npiggin
2007-12-05  7:15 ` [patch 02/18] relay: nopage npiggin
2007-12-05  7:15 ` [patch 03/18] drm: nopage npiggin
2007-12-05  9:05   ` Dave Airlie
2007-12-05  9:17     ` Nick Piggin
2007-12-05  7:15 ` [patch 04/18] uio: nopage npiggin
2007-12-05 10:04   ` Hans-Jürgen Koch
2007-12-05 10:10     ` Nick Piggin
2007-12-05 10:25       ` Hans-Jürgen Koch
2007-12-05 10:37         ` Nick Piggin
2007-12-05  7:15 ` [patch 05/18] kvm: nopage npiggin
2007-12-05 10:40   ` Avi Kivity
2007-12-05  7:15 ` [patch 06/18] ieee1394: nopage npiggin
2007-12-05 13:09   ` Stefan Richter
2007-12-05 13:15     ` Stefan Richter
2007-12-05 23:52       ` Nick Piggin
2007-12-05 23:51     ` Nick Piggin
2007-12-15 13:04       ` Stefan Richter
2007-12-15 13:01   ` Stefan Richter
2007-12-05  7:15 ` [patch 07/18] v4l: nopage npiggin
2007-12-08  0:31   ` Andrew Morton
2007-12-08  9:15     ` Ingo Molnar
2007-12-08 10:15       ` Andrew Morton
2007-12-09 17:10     ` Randy Dunlap
2007-12-10  5:06     ` [patch] x64/page.h: convert some macros to inlines Randy Dunlap
2007-12-10  8:34       ` Ingo Molnar
2007-12-05  7:15 ` [patch 08/18] fb: defio nopage npiggin
2007-12-05  7:15 ` [patch 09/18] agp: alpha nopage npiggin
2007-12-05  7:15 ` [patch 10/18] sg: nopage npiggin
2008-02-08  3:45   ` Douglas Gilbert
2007-12-05  7:15 ` [patch 11/18] ib: nopage npiggin
2007-12-05  7:15 ` [patch 12/18] usb: mon nopage npiggin
2007-12-05 16:39   ` Pete Zaitcev
2007-12-05 23:54     ` Nick Piggin
2007-12-05  7:16 ` [patch 13/18] alsa: nopage npiggin
2007-12-13 15:35   ` Takashi Iwai
2007-12-05  7:16 ` [patch 14/18] oss: via nopage npiggin
2007-12-05  7:16 ` [patch 15/18] alsa: usx2y nopage npiggin
2007-12-13 15:35   ` Takashi Iwai
2007-12-05  7:16 ` [patch 16/18] mm: special mapping nopage npiggin
2007-12-05  7:16 ` [patch 17/18] mm: remove nopage npiggin
2007-12-05 22:47   ` Andrew Morton
2007-12-05 23:23     ` Nick Piggin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).