Skip to contentSkip to conversation

linux: xenbus_be currently doesn't build properly as a module

PATCH In review Jan Beulich 2 participants 6 messages Apr 20, 2006 – Apr 25, 2006 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux: xenbus_be currently doesn't build properly as a module

It depends on the non-exported symbols vmlist and vmlist_lock. As exporting these doesn't seem reasonable, the patch disables the ability to build this as a module for now.

From: [email protected]
Subject: xenbus_be currently doesn't build properly as a module

It depends on the non-exported symbols vmlist and vmlist_lock.

drivers/xen/xenbus/Makefile +2 -1
Index: head-2006-04-20/drivers/xen/xenbus/Makefile
===================================================================
@@ -1,5 +1,6 @@
 obj-y	+= xenbus.o
-obj-$(CONFIG_XEN_BACKEND) += xenbus_be.o
+#obj-$(CONFIG_XEN_BACKEND) += xenbus_be.o
+obj-y   += xenbus_be.o
 
 xenbus_be-objs =
 xenbus_be-objs += xenbus_backend_client.o

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 4 lines · Jan Beulich

It depends on the non-exported symbols vmlist and vmlist_lock. As exporting these doesn't seem reasonable, the patch disables the ability to build this as a module for now.

A better fix is for xenbus_map_ring_valloc() to have the prototype:
struct vm_struct *xenbus_map_ring_valloc(struct xenbus_device *, int);

It then returns the vmarea that is allocated, or ERR_PTR() on error.

Then xenbus_unmap_ring_vfree() takes the vmarea rather than vaddr and we avoid the nasty vmlist scan that cannot be modularised.

There's only one user of these functions right now, so the patch for this proper fix won't be very big.

-- Keir

#2 lore raw
Quoted 13 lines
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 20.04.06 15:08:28 >>>

Quoted 5 lines · Jan Beulich

It depends on the non-exported symbols vmlist and vmlist_lock. As exporting these doesn't seem reasonable, the patch disables the ability to build this as a module for now.

A better fix is for xenbus_map_ring_valloc() to have the prototype:
struct vm_struct *xenbus_map_ring_valloc(struct xenbus_device *, int);

Quoted 7 lines

It then returns the vmarea that is allocated, or ERR_PTR() on error.

Then xenbus_unmap_ring_vfree() takes the vmarea rather than vaddr and we avoid the nasty vmlist scan that cannot be modularised.

There's only one user of these functions right now, so the patch for this proper fix won't be very big.

I specifically didn't do it this proper way because of the comment in the function saying doing it the raw way would be so much simpler - but if that in fact doesn't apply...

Jan

#3 lore raw
Quoted 6 lines · Jan Beulich
Quoted 2 lines

There's only one user of these functions right now, so the patch for this proper fix won't be very big.

I specifically didn't do it this proper way because of the comment in the function saying doing it the raw way would be so much simpler - but if that in fact doesn't apply...

The disadvantage of exposing the vmarea at the interface is outweighed by the advantage of being able to build as a module imo. Unless there is ever going to be a find_vm_area() call, this has to be considered the proper long-term fix to make it buildable as a module.

-- Keir

#4 lore raw
In reply to Keir Fraser

So here's the adjusted patch. Jan

Quoted 1 line
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 20.04.06 15:08:28 >>>

Quoted 5 lines · Jan Beulich

It depends on the non-exported symbols vmlist and vmlist_lock. As exporting these doesn't seem reasonable, the patch disables the ability to build this as a module for now.

A better fix is for xenbus_map_ring_valloc() to have the prototype:
struct vm_struct *xenbus_map_ring_valloc(struct xenbus_device *, int);

It then returns the vmarea that is allocated, or ERR_PTR() on error.

Then xenbus_unmap_ring_vfree() takes the vmarea rather than vaddr and we avoid the nasty vmlist scan that cannot be modularised.

There's only one user of these functions right now, so the patch for this proper fix won't be very big.

-- Keir

drivers/xen/pciback/pciback.h +1 -0
Index: head-2006-04-24/drivers/xen/pciback/pciback.h
===================================================================
@@ -29,6 +29,7 @@ struct pciback_device {
 
 	int evtchn_irq;
 
+	struct vm_struct *sh_area;
 	struct xen_pci_sharedinfo *sh_info;
 };
 
drivers/xen/pciback/xenbus.c +10 -5
Index: head-2006-04-24/drivers/xen/pciback/xenbus.c
===================================================================
@@ -26,6 +26,7 @@ static struct pciback_device *alloc_pdev
 
 	spin_lock_init(&pdev->dev_lock);
 
+	pdev->sh_area = NULL;
 	pdev->sh_info = NULL;
 	pdev->evtchn_irq = INVALID_EVTCHN_IRQ;
 	pdev->be_watching = 0;
@@ -48,7 +49,7 @@ static void free_pdev(struct pciback_dev
 		unbind_from_irqhandler(pdev->evtchn_irq, pdev);
 
 	if (pdev->sh_info)
-		xenbus_unmap_ring_vfree(pdev->xdev, pdev->sh_info);
+		xenbus_unmap_ring_vfree(pdev->xdev, pdev->sh_area);
 
 	pciback_release_devices(pdev);
 
@@ -63,15 +64,19 @@ static int pciback_do_attach(struct pcib
 {
 	int err = 0;
 	int evtchn;
+	struct vm_struct *area;
+
 	dev_dbg(&pdev->xdev->dev,
 		"Attaching to frontend resources - gnt_ref=%d evtchn=%d\n",
 		gnt_ref, remote_evtchn);
 
-	err =
-	    xenbus_map_ring_valloc(pdev->xdev, gnt_ref,
-				   (void **)&pdev->sh_info);
-	if (err)
+	area = xenbus_map_ring_valloc(pdev->xdev, gnt_ref);
+	if (IS_ERR(area)) {
+		err = PTR_ERR(area);
 		goto out;
+	}
+	pdev->sh_area = area;
+	pdev->sh_info = area->addr;
 
 	err = xenbus_bind_evtchn(pdev->xdev, remote_evtchn, &evtchn);
 	if (err)
drivers/xen/xenbus/xenbus_backend_client.c +7 -28
Index: head-2006-04-24/drivers/xen/xenbus/xenbus_backend_client.c
===================================================================
@@ -30,21 +30,20 @@
  * IN THE SOFTWARE.
  */
 
+#include <linux/err.h>
 #include <xen/gnttab.h>
 #include <xen/xenbus.h>
 #include <xen/driver_util.h>
 
 /* Based on Rusty Russell's skeleton driver's map_page */
-int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
+struct vm_struct *xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref)
 {
 	struct gnttab_map_grant_ref op;
 	struct vm_struct *area;
 
-	*vaddr = NULL;
-
 	area = alloc_vm_area(PAGE_SIZE);
 	if (!area)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
 	gnttab_set_map_op(&op, (unsigned long)area->addr, GNTMAP_host_map,
 			  gnt_ref, dev->otherend_id);
@@ -58,14 +57,14 @@ int xenbus_map_ring_valloc(struct xenbus
 		xenbus_dev_fatal(dev, op.status,
 				 "mapping in shared page %d from domain %d",
 				 gnt_ref, dev->otherend_id);
-		return op.status;
+		BUG_ON(!IS_ERR(ERR_PTR(op.status)));
+		return ERR_PTR(op.status);
 	}
 
 	/* Stuff the handle in an unused field */
 	area->phys_addr = (unsigned long)op.handle;
 
-	*vaddr = area->addr;
-	return 0;
+	return area;
 }
 EXPORT_SYMBOL_GPL(xenbus_map_ring_valloc);
 
@@ -92,30 +91,10 @@ EXPORT_SYMBOL_GPL(xenbus_map_ring);
 
 
 /* Based on Rusty Russell's skeleton driver's unmap_page */
-int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
+int xenbus_unmap_ring_vfree(struct xenbus_device *dev, struct vm_struct *area)
 {
-	struct vm_struct *area;
 	struct gnttab_unmap_grant_ref op;
 
-	/* It'd be nice if linux/vmalloc.h provided a find_vm_area(void *addr)
-	 * method so that we don't have to muck with vmalloc internals here.
-	 * We could force the user to hang on to their struct vm_struct from
-	 * xenbus_map_ring_valloc, but these 6 lines considerably simplify
-	 * this API.
-	 */
-	read_lock(&vmlist_lock);
-	for (area = vmlist; area != NULL; area = area->next) {
-		if (area->addr == vaddr)
-			break;
-	}
-	read_unlock(&vmlist_lock);
-
-	if (!area) {
-		xenbus_dev_error(dev, -ENOENT,
-				 "can't find mapped virtual address %p", vaddr);
-		return GNTST_bad_virt_addr;
-	}
-
 	gnttab_set_unmap_op(&op, (unsigned long)vaddr, GNTMAP_host_map,
 			    (grant_handle_t)area->phys_addr);
 
include/xen/xenbus.h +3 -3
Index: head-2006-04-24/include/xen/xenbus.h
===================================================================
@@ -228,8 +228,8 @@ int xenbus_grant_ring(struct xenbus_devi
  * or -ENOMEM on error. If an error is returned, device will switch to
  * XenbusStateClosing and the error message will be saved in XenStore.
  */
-int xenbus_map_ring_valloc(struct xenbus_device *dev,
-			   int gnt_ref, void **vaddr);
+struct vm_struct *xenbus_map_ring_valloc(struct xenbus_device *dev,
+					 int gnt_ref);
 int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
 			   grant_handle_t *handle, void *vaddr);
 
@@ -241,7 +241,7 @@ int xenbus_map_ring(struct xenbus_device
  * Returns 0 on success and returns GNTST_* on error
  * (see xen/include/interface/grant_table.h).
  */
-int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr);
+int xenbus_unmap_ring_vfree(struct xenbus_device *dev, struct vm_struct *);
 int xenbus_unmap_ring(struct xenbus_device *dev,
 		      grant_handle_t handle, void *vaddr);
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw
Quoted 1 line · Jan Beulich

So here's the adjusted patch. Jan

Looks good, I'll check it in.

Thanks,
Keir