ia64/xen-unstable

changeset 8790:c9edeb3bd652

Use /dev/kmem to map dom0 xenstore page instead of abusing the foreign mapping interface.
Change /proc/xen/xsd_mfn to /proc/xen/xsd_kva containing the kernel
virtual address of the dom0 xenstore page. Update xenstored to use
/proc/xen/xsd_kva.

Signed-off-by: Keir Fraser <keir@xensource.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Wed Feb 08 12:03:52 2006 +0000 (2006-02-08)
parents bc2ac5e87f99
children 1a2e7cd58ca0
files linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c tools/xenstore/xenstored_domain.c tools/xenstore/xenstored_proc.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c	Wed Feb 08 11:10:52 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c	Wed Feb 08 12:03:52 2006 +0000
     1.3 @@ -122,6 +122,9 @@ int direct_remap_pfn_range(struct vm_are
     1.4  	/* Same as remap_pfn_range(). */
     1.5  	vma->vm_flags |= VM_IO | VM_RESERVED;
     1.6  
     1.7 +	if (domid == DOMID_SELF)
     1.8 +		return -EINVAL;
     1.9 +
    1.10  	return __direct_remap_pfn_range(
    1.11  		vma->vm_mm, address, mfn, size, prot, domid);
    1.12  }
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Wed Feb 08 11:10:52 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Wed Feb 08 12:03:52 2006 +0000
     2.3 @@ -163,7 +163,12 @@ static int privcmd_ioctl(struct inode *i
     2.4  			goto batch_err;
     2.5  		}
     2.6  
     2.7 -		vma = find_vma( current->mm, m.addr );
     2.8 +		if (m.dom == DOMID_SELF) {
     2.9 +			ret = -EINVAL;
    2.10 +			goto batch_err;
    2.11 +		}
    2.12 +
    2.13 +		vma = find_vma(current->mm, m.addr);
    2.14  		if (!vma) {
    2.15  			ret = -EINVAL;
    2.16  			goto batch_err;
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Wed Feb 08 11:10:52 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Wed Feb 08 12:03:52 2006 +0000
     3.3 @@ -863,16 +863,16 @@ EXPORT_SYMBOL(xenbus_resume);
     3.4  
     3.5  
     3.6  /* A flag to determine if xenstored is 'ready' (i.e. has started) */
     3.7 -int xenstored_ready = 0; 
     3.8 +int xenstored_ready = 0;
     3.9  
    3.10  
    3.11  int register_xenstore_notifier(struct notifier_block *nb)
    3.12  {
    3.13  	int ret = 0;
    3.14  
    3.15 -	if (xenstored_ready > 0) 
    3.16 +	if (xenstored_ready > 0)
    3.17  		ret = nb->notifier_call(nb, 0, NULL);
    3.18 -	else 
    3.19 +	else
    3.20  		notifier_chain_register(&xenstore_chain, nb);
    3.21  
    3.22  	return ret;
    3.23 @@ -889,7 +889,7 @@ EXPORT_SYMBOL(unregister_xenstore_notifi
    3.24  
    3.25  void xenbus_probe(void *unused)
    3.26  {
    3.27 -	BUG_ON((xenstored_ready <= 0)); 
    3.28 +	BUG_ON((xenstored_ready <= 0));
    3.29  
    3.30  	/* Enumerate devices in xenstore. */
    3.31  	xenbus_probe_devices(&xenbus_frontend);
    3.32 @@ -904,27 +904,27 @@ void xenbus_probe(void *unused)
    3.33  }
    3.34  
    3.35  
    3.36 -static struct proc_dir_entry *xsd_mfn_intf;
    3.37 +static struct proc_dir_entry *xsd_kva_intf;
    3.38  static struct proc_dir_entry *xsd_port_intf;
    3.39  
    3.40  
    3.41 -static int xsd_mfn_read(char *page, char **start, off_t off,
    3.42 +static int xsd_kva_read(char *page, char **start, off_t off,
    3.43                          int count, int *eof, void *data)
    3.44  {
    3.45 -	int len; 
    3.46 -	len  = sprintf(page, "%ld", xen_start_info->store_mfn); 
    3.47 -	*eof = 1; 
    3.48 -	return len; 
    3.49 +	int len;
    3.50 +	len  = sprintf(page, "0x%p", mfn_to_virt(xen_start_info->store_mfn));
    3.51 +	*eof = 1;
    3.52 +	return len;
    3.53  }
    3.54  
    3.55  static int xsd_port_read(char *page, char **start, off_t off,
    3.56  			 int count, int *eof, void *data)
    3.57  {
    3.58 -	int len; 
    3.59 +	int len;
    3.60  
    3.61 -	len  = sprintf(page, "%d", xen_start_info->store_evtchn); 
    3.62 -	*eof = 1; 
    3.63 -	return len; 
    3.64 +	len  = sprintf(page, "%d", xen_start_info->store_evtchn);
    3.65 +	*eof = 1;
    3.66 +	return len;
    3.67  }
    3.68  
    3.69  
    3.70 @@ -959,8 +959,8 @@ static int __init xenbus_probe_init(void
    3.71  
    3.72  		/* Allocate page. */
    3.73  		page = get_zeroed_page(GFP_KERNEL);
    3.74 -		if (!page) 
    3.75 -			return -ENOMEM; 
    3.76 +		if (!page)
    3.77 +			return -ENOMEM;
    3.78  
    3.79  		/* We don't refcnt properly, so set reserved on page.
    3.80  		 * (this allocation is permanent) */
    3.81 @@ -973,25 +973,25 @@ static int __init xenbus_probe_init(void
    3.82  		/* Next allocate a local port which xenstored can bind to */
    3.83  		op.cmd = EVTCHNOP_alloc_unbound;
    3.84  		op.u.alloc_unbound.dom        = DOMID_SELF;
    3.85 -		op.u.alloc_unbound.remote_dom = 0; 
    3.86 +		op.u.alloc_unbound.remote_dom = 0;
    3.87  
    3.88  		ret = HYPERVISOR_event_channel_op(&op);
    3.89 -		BUG_ON(ret); 
    3.90 +		BUG_ON(ret);
    3.91  		xen_start_info->store_evtchn = op.u.alloc_unbound.port;
    3.92  
    3.93  		/* And finally publish the above info in /proc/xen */
    3.94 -		if((xsd_mfn_intf = create_xen_proc_entry("xsd_mfn", 0400)))
    3.95 -			xsd_mfn_intf->read_proc = xsd_mfn_read; 
    3.96 +		if((xsd_kva_intf = create_xen_proc_entry("xsd_kva", 0400)))
    3.97 +			xsd_kva_intf->read_proc = xsd_kva_read;
    3.98  		if((xsd_port_intf = create_xen_proc_entry("xsd_port", 0400)))
    3.99  			xsd_port_intf->read_proc = xsd_port_read;
   3.100  	}
   3.101  
   3.102  	/* Initialize the interface to xenstore. */
   3.103 -	err = xs_init(); 
   3.104 +	err = xs_init();
   3.105  	if (err) {
   3.106  		printk(KERN_WARNING
   3.107  		       "XENBUS: Error initializing xenstore comms: %i\n", err);
   3.108 -		return err; 
   3.109 +		return err;
   3.110  	}
   3.111  
   3.112  	if (!dom0) {
     4.1 --- a/tools/xenstore/xenstored_domain.c	Wed Feb 08 11:10:52 2006 +0100
     4.2 +++ b/tools/xenstore/xenstored_domain.c	Wed Feb 08 12:03:52 2006 +0000
     4.3 @@ -27,6 +27,7 @@
     4.4  #include <sys/types.h>
     4.5  #include <sys/stat.h>
     4.6  #include <fcntl.h>
     4.7 +#include <paths.h>
     4.8  
     4.9  //#define DEBUG
    4.10  #include "utils.h"
    4.11 @@ -256,7 +257,7 @@ static char *talloc_domain_path(void *co
    4.12  }
    4.13  
    4.14  static struct domain *new_domain(void *context, unsigned int domid,
    4.15 -				 unsigned long mfn, int port)
    4.16 +				 int port)
    4.17  {
    4.18  	struct domain *domain;
    4.19  	struct ioctl_evtchn_bind_interdomain bind;
    4.20 @@ -268,11 +269,6 @@ static struct domain *new_domain(void *c
    4.21  	domain->shutdown = 0;
    4.22  	domain->domid = domid;
    4.23  	domain->path = talloc_domain_path(domain, domid);
    4.24 -	domain->interface = xc_map_foreign_range(
    4.25 -		*xc_handle, domain->domid,
    4.26 -		getpagesize(), PROT_READ|PROT_WRITE, mfn);
    4.27 -	if (!domain->interface)
    4.28 -		return NULL;
    4.29  
    4.30  	list_add(&domain->list, &domains);
    4.31  	talloc_set_destructor(domain, destroy_domain);
    4.32 @@ -290,7 +286,6 @@ static struct domain *new_domain(void *c
    4.33  	domain->conn->id = domid;
    4.34  
    4.35  	domain->remote_port = port;
    4.36 -	domain->mfn = mfn;
    4.37  
    4.38  	return domain;
    4.39  }
    4.40 @@ -341,11 +336,19 @@ void do_introduce(struct connection *con
    4.41  
    4.42  	if (domain == NULL) {
    4.43  		/* Hang domain off "in" until we're finished. */
    4.44 -		domain = new_domain(in, domid, mfn, port);
    4.45 +		domain = new_domain(in, domid, port);
    4.46  		if (!domain) {
    4.47  			send_error(conn, errno);
    4.48  			return;
    4.49  		}
    4.50 +		domain->interface = xc_map_foreign_range(
    4.51 +			*xc_handle, domid,
    4.52 +			getpagesize(), PROT_READ|PROT_WRITE, mfn);
    4.53 +		if (!domain->interface) {
    4.54 +			send_error(conn, errno);
    4.55 +			return;
    4.56 +		}
    4.57 +		domain->mfn = mfn;
    4.58  
    4.59  		/* Now domain belongs to its connection. */
    4.60  		talloc_steal(domain->conn, domain);
    4.61 @@ -463,11 +466,11 @@ static int dom0_init(void)
    4.62  { 
    4.63  	int rc, fd;
    4.64  	evtchn_port_t port; 
    4.65 -	unsigned long mfn; 
    4.66 +	unsigned long kva; 
    4.67  	char str[20]; 
    4.68  	struct domain *dom0; 
    4.69  
    4.70 -	fd = open(XENSTORED_PROC_MFN, O_RDONLY); 
    4.71 +	fd = open(XENSTORED_PROC_KVA, O_RDONLY); 
    4.72  	if (fd == -1)
    4.73  		return -1;
    4.74  
    4.75 @@ -475,7 +478,7 @@ static int dom0_init(void)
    4.76  	if (rc == -1)
    4.77  		goto outfd;
    4.78  	str[rc] = '\0'; 
    4.79 -	mfn = strtoul(str, NULL, 0); 
    4.80 +	kva = strtoul(str, NULL, 0); 
    4.81  
    4.82  	close(fd); 
    4.83  
    4.84 @@ -491,7 +494,19 @@ static int dom0_init(void)
    4.85  
    4.86  	close(fd); 
    4.87  
    4.88 -	dom0 = new_domain(NULL, 0, mfn, port); 
    4.89 +	dom0 = new_domain(NULL, 0, port); 
    4.90 +
    4.91 +	fd = open(_PATH_KMEM, O_RDWR);
    4.92 +	if (fd == -1)
    4.93 +		return -1;
    4.94 +
    4.95 +	dom0->interface = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
    4.96 +			       MAP_SHARED, fd, kva);
    4.97 +	if (dom0->interface == MAP_FAILED)
    4.98 +		goto outfd;
    4.99 +
   4.100 +	close(fd);
   4.101 +
   4.102  	talloc_steal(dom0->conn, dom0); 
   4.103  
   4.104  	evtchn_notify(dom0->port); 
     5.1 --- a/tools/xenstore/xenstored_proc.h	Wed Feb 08 11:10:52 2006 +0100
     5.2 +++ b/tools/xenstore/xenstored_proc.h	Wed Feb 08 12:03:52 2006 +0000
     5.3 @@ -20,7 +20,7 @@
     5.4  #ifndef _XENSTORED_PROC_H
     5.5  #define _XENSTORED_PROC_H
     5.6  
     5.7 -#define XENSTORED_PROC_MFN  "/proc/xen/xsd_mfn"
     5.8 +#define XENSTORED_PROC_KVA  "/proc/xen/xsd_kva"
     5.9  #define XENSTORED_PROC_PORT "/proc/xen/xsd_port"
    5.10  
    5.11