xen-devel
[Xen-devel] [patch 18/20] XEN-paravirt: Add Xen driver utility functions
To: |
Andrew Morton <akpm@xxxxxxxx> |
Subject: |
[Xen-devel] [patch 18/20] XEN-paravirt: Add Xen driver utility functions. |
From: |
Jeremy Fitzhardinge <jeremy@xxxxxxxx> |
Date: |
Fri, 12 Jan 2007 17:45:57 -0800 |
Cc: |
xen-devel@xxxxxxxxxxxxxxxxxxx, Ian Pratt <ian.pratt@xxxxxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, Jan Beulich <JBeulich@xxxxxxxxxx>, Chris Wright <chrisw@xxxxxxxxxxxx>, virtualization@xxxxxxxxxxxxxx, Christian Limpach <Christian.Limpach@xxxxxxxxxxxx> |
Delivery-date: |
Sat, 13 Jan 2007 15:16:12 -0800 |
Envelope-to: |
www-data@xxxxxxxxxxxxxxxxxx |
List-help: |
<mailto:xen-devel-request@lists.xensource.com?subject=help> |
List-id: |
Xen developer discussion <xen-devel.lists.xensource.com> |
List-post: |
<mailto:xen-devel@lists.xensource.com> |
List-subscribe: |
<http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe> |
List-unsubscribe: |
<http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe> |
References: |
<20070113014539.408244126@xxxxxxxx> |
Sender: |
xen-devel-bounces@xxxxxxxxxxxxxxxxxxx |
User-agent: |
quilt/0.46-1 |
Allocate/destroy a 'vmalloc' VM area: alloc_vm_area and free_vm_area
The alloc function ensures that page tables are constructed for the
region of kernel virtual address space and mapped into init_mm.
Lock an area so that PTEs are accessible in the current address space:
lock_vm_area and unlock_vm_area
The lock function prevents context switches to a lazy mm that doesn't
have the area mapped into its page tables. It also ensures that the
page tables are mapped into the current mm by causing the page fault
handler to copy the page directory pointers from init_mm into the
current mm.
Signed-off-by: Ian Pratt <ian.pratt@xxxxxxxxxxxxx>
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>
Signed-off-by: Chris Wright <chrisw@xxxxxxxxxxxx>
Cc: "Jan Beulich" <JBeulich@xxxxxxxxxx>
---
drivers/xen/Makefile | 2 +
drivers/xen/util.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++
include/xen/driver_util.h | 16 ++++++++++
3 files changed, 88 insertions(+)
===================================================================
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -1,2 +1,4 @@ obj-y += core/
+obj-y += util.o
+
obj-y += core/
obj-y += console/
===================================================================
--- /dev/null
+++ b/drivers/xen/util.c
@@ -0,0 +1,69 @@
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+#include <asm/uaccess.h>
+#include <xen/driver_util.h>
+
+static int f(pte_t *pte, struct page *pmd_page, unsigned long addr, void *data)
+{
+ /* apply_to_page_range() does all the hard work. */
+ return 0;
+}
+
+struct vm_struct *alloc_vm_area(unsigned long size)
+{
+ struct vm_struct *area;
+
+ area = get_vm_area(size, VM_IOREMAP);
+ if (area == NULL)
+ return NULL;
+
+ /*
+ * This ensures that page tables are constructed for this region
+ * of kernel virtual address space and mapped into init_mm.
+ */
+ if (apply_to_page_range(&init_mm, (unsigned long)area->addr,
+ area->size, f, NULL)) {
+ free_vm_area(area);
+ return NULL;
+ }
+
+ return area;
+}
+EXPORT_SYMBOL_GPL(alloc_vm_area);
+
+void free_vm_area(struct vm_struct *area)
+{
+ struct vm_struct *ret;
+ ret = remove_vm_area(area->addr);
+ BUG_ON(ret != area);
+ kfree(area);
+}
+EXPORT_SYMBOL_GPL(free_vm_area);
+
+void lock_vm_area(struct vm_struct *area)
+{
+ unsigned long i;
+ char c;
+
+ /*
+ * Prevent context switch to a lazy mm that doesn't have this area
+ * mapped into its page tables.
+ */
+ preempt_disable();
+
+ /*
+ * Ensure that the page tables are mapped into the current mm. The
+ * page-fault path will copy the page directory pointers from init_mm.
+ */
+ for (i = 0; i < area->size; i += PAGE_SIZE)
+ (void)__get_user(c, (char __user *)area->addr + i);
+}
+EXPORT_SYMBOL_GPL(lock_vm_area);
+
+void unlock_vm_area(struct vm_struct *area)
+{
+ preempt_enable();
+}
+EXPORT_SYMBOL_GPL(unlock_vm_area);
===================================================================
--- /dev/null
+++ b/include/xen/driver_util.h
@@ -0,0 +1,15 @@
+
+#ifndef __ASM_XEN_DRIVER_UTIL_H__
+#define __ASM_XEN_DRIVER_UTIL_H__
+
+#include <linux/vmalloc.h>
+
+/* Allocate/destroy a 'vmalloc' VM area. */
+extern struct vm_struct *alloc_vm_area(unsigned long size);
+extern void free_vm_area(struct vm_struct *area);
+
+/* Lock an area so that PTEs are accessible in the current address space. */
+extern void lock_vm_area(struct vm_struct *area);
+extern void unlock_vm_area(struct vm_struct *area);
+
+#endif /* __ASM_XEN_DRIVER_UTIL_H__ */
--
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
<Prev in Thread] |
Current Thread |
[Next in Thread>
|
- [Xen-devel] [patch 06/20] XEN-paravirt: remove pgd ctor, (continued)
- [Xen-devel] [patch 06/20] XEN-paravirt: remove pgd ctor, Jeremy Fitzhardinge
- [Xen-devel] [patch 12/20] XEN-paravirt: Xen: Add nosegneg capability to the vsyscall page notes, Jeremy Fitzhardinge
- [Xen-devel] [patch 08/20] XEN-paravirt: paravirt pgd allocation alignment, Jeremy Fitzhardinge
- [Xen-devel] [patch 11/20] XEN-paravirt: Add apply_to_page_range() which applies a function to a pte range., Jeremy Fitzhardinge
- [Xen-devel] [patch 10/20] XEN-paravirt: mm lifetime hooks, Jeremy Fitzhardinge
- [Xen-devel] [patch 16/20] XEN-paravirt: Add the Xen virtual console driver., Jeremy Fitzhardinge
- [Xen-devel] [patch 18/20] XEN-paravirt: Add Xen driver utility functions.,
Jeremy Fitzhardinge <=
- [Xen-devel] [patch 17/20] XEN-paravirt: Add Xen grant table support, Jeremy Fitzhardinge
- [Xen-devel] [patch 15/20] XEN-paravirt: Xen: core paravirt guest changes, Jeremy Fitzhardinge
- [Xen-devel] [patch 13/20] XEN-paravirt: Xen: Add config options and disable unsupported config options., Jeremy Fitzhardinge
- [Xen-devel] [patch 20/20] XEN-paravirt: Add Xen virtual block device driver., Jeremy Fitzhardinge
|
|
|