aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/xen')
-rw-r--r--drivers/xen/Makefile1
-rw-r--r--drivers/xen/events/events_base.c2
-rw-r--r--drivers/xen/gntdev.c13
-rw-r--r--drivers/xen/grant-table.c89
-rw-r--r--drivers/xen/xencomm.c219
5 files changed, 20 insertions, 304 deletions
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index d75c811bfa56..45e00afa7f2d 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -16,7 +16,6 @@ xen-pad-$(CONFIG_X86) += xen-acpi-pad.o
16dom0-$(CONFIG_X86) += pcpu.o 16dom0-$(CONFIG_X86) += pcpu.o
17obj-$(CONFIG_XEN_DOM0) += $(dom0-y) 17obj-$(CONFIG_XEN_DOM0) += $(dom0-y)
18obj-$(CONFIG_BLOCK) += biomerge.o 18obj-$(CONFIG_BLOCK) += biomerge.o
19obj-$(CONFIG_XEN_XENCOMM) += xencomm.o
20obj-$(CONFIG_XEN_BALLOON) += xen-balloon.o 19obj-$(CONFIG_XEN_BALLOON) += xen-balloon.o
21obj-$(CONFIG_XEN_SELFBALLOONING) += xen-selfballoon.o 20obj-$(CONFIG_XEN_SELFBALLOONING) += xen-selfballoon.o
22obj-$(CONFIG_XEN_DEV_EVTCHN) += xen-evtchn.o 21obj-$(CONFIG_XEN_DEV_EVTCHN) += xen-evtchn.o
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 4672e003c0ad..f4a9e3311297 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -862,6 +862,8 @@ int bind_evtchn_to_irq(unsigned int evtchn)
862 irq = ret; 862 irq = ret;
863 goto out; 863 goto out;
864 } 864 }
865 /* New interdomain events are bound to VCPU 0. */
866 bind_evtchn_to_cpu(evtchn, 0);
865 } else { 867 } else {
866 struct irq_info *info = info_for_irq(irq); 868 struct irq_info *info = info_for_irq(irq);
867 WARN_ON(info == NULL || info->type != IRQT_EVTCHN); 869 WARN_ON(info == NULL || info->type != IRQT_EVTCHN);
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index 34a2704fbc88..073b4a19a8b0 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -284,10 +284,8 @@ static int map_grant_pages(struct grant_map *map)
284 } 284 }
285 285
286 pr_debug("map %d+%d\n", map->index, map->count); 286 pr_debug("map %d+%d\n", map->index, map->count);
287 err = gnttab_map_refs_userspace(map->map_ops, 287 err = gnttab_map_refs(map->map_ops, use_ptemod ? map->kmap_ops : NULL,
288 use_ptemod ? map->kmap_ops : NULL, 288 map->pages, map->count);
289 map->pages,
290 map->count);
291 if (err) 289 if (err)
292 return err; 290 return err;
293 291
@@ -317,10 +315,9 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
317 } 315 }
318 } 316 }
319 317
320 err = gnttab_unmap_refs_userspace(map->unmap_ops + offset, 318 err = gnttab_unmap_refs(map->unmap_ops + offset,
321 use_ptemod ? map->kmap_ops + offset : NULL, 319 use_ptemod ? map->kmap_ops + offset : NULL, map->pages + offset,
322 map->pages + offset, 320 pages);
323 pages);
324 if (err) 321 if (err)
325 return err; 322 return err;
326 323
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 8ee13e2e45e2..b84e3ab839aa 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -928,17 +928,15 @@ void gnttab_batch_copy(struct gnttab_copy *batch, unsigned count)
928} 928}
929EXPORT_SYMBOL_GPL(gnttab_batch_copy); 929EXPORT_SYMBOL_GPL(gnttab_batch_copy);
930 930
931int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, 931int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
932 struct gnttab_map_grant_ref *kmap_ops, 932 struct gnttab_map_grant_ref *kmap_ops,
933 struct page **pages, unsigned int count, 933 struct page **pages, unsigned int count)
934 bool m2p_override)
935{ 934{
936 int i, ret; 935 int i, ret;
937 bool lazy = false; 936 bool lazy = false;
938 pte_t *pte; 937 pte_t *pte;
939 unsigned long mfn, pfn; 938 unsigned long mfn;
940 939
941 BUG_ON(kmap_ops && !m2p_override);
942 ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map_ops, count); 940 ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map_ops, count);
943 if (ret) 941 if (ret)
944 return ret; 942 return ret;
@@ -957,12 +955,10 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
957 set_phys_to_machine(map_ops[i].host_addr >> PAGE_SHIFT, 955 set_phys_to_machine(map_ops[i].host_addr >> PAGE_SHIFT,
958 map_ops[i].dev_bus_addr >> PAGE_SHIFT); 956 map_ops[i].dev_bus_addr >> PAGE_SHIFT);
959 } 957 }
960 return 0; 958 return ret;
961 } 959 }
962 960
963 if (m2p_override && 961 if (!in_interrupt() && paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
964 !in_interrupt() &&
965 paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
966 arch_enter_lazy_mmu_mode(); 962 arch_enter_lazy_mmu_mode();
967 lazy = true; 963 lazy = true;
968 } 964 }
@@ -979,20 +975,8 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
979 } else { 975 } else {
980 mfn = PFN_DOWN(map_ops[i].dev_bus_addr); 976 mfn = PFN_DOWN(map_ops[i].dev_bus_addr);
981 } 977 }
982 pfn = page_to_pfn(pages[i]); 978 ret = m2p_add_override(mfn, pages[i], kmap_ops ?
983 979 &kmap_ops[i] : NULL);
984 WARN_ON(PagePrivate(pages[i]));
985 SetPagePrivate(pages[i]);
986 set_page_private(pages[i], mfn);
987
988 pages[i]->index = pfn_to_mfn(pfn);
989 if (unlikely(!set_phys_to_machine(pfn, FOREIGN_FRAME(mfn)))) {
990 ret = -ENOMEM;
991 goto out;
992 }
993 if (m2p_override)
994 ret = m2p_add_override(mfn, pages[i], kmap_ops ?
995 &kmap_ops[i] : NULL);
996 if (ret) 980 if (ret)
997 goto out; 981 goto out;
998 } 982 }
@@ -1003,32 +987,15 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
1003 987
1004 return ret; 988 return ret;
1005} 989}
1006
1007int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
1008 struct page **pages, unsigned int count)
1009{
1010 return __gnttab_map_refs(map_ops, NULL, pages, count, false);
1011}
1012EXPORT_SYMBOL_GPL(gnttab_map_refs); 990EXPORT_SYMBOL_GPL(gnttab_map_refs);
1013 991
1014int gnttab_map_refs_userspace(struct gnttab_map_grant_ref *map_ops, 992int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1015 struct gnttab_map_grant_ref *kmap_ops,
1016 struct page **pages, unsigned int count)
1017{
1018 return __gnttab_map_refs(map_ops, kmap_ops, pages, count, true);
1019}
1020EXPORT_SYMBOL_GPL(gnttab_map_refs_userspace);
1021
1022int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1023 struct gnttab_map_grant_ref *kmap_ops, 993 struct gnttab_map_grant_ref *kmap_ops,
1024 struct page **pages, unsigned int count, 994 struct page **pages, unsigned int count)
1025 bool m2p_override)
1026{ 995{
1027 int i, ret; 996 int i, ret;
1028 bool lazy = false; 997 bool lazy = false;
1029 unsigned long pfn, mfn;
1030 998
1031 BUG_ON(kmap_ops && !m2p_override);
1032 ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count); 999 ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count);
1033 if (ret) 1000 if (ret)
1034 return ret; 1001 return ret;
@@ -1039,33 +1006,17 @@ int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1039 set_phys_to_machine(unmap_ops[i].host_addr >> PAGE_SHIFT, 1006 set_phys_to_machine(unmap_ops[i].host_addr >> PAGE_SHIFT,
1040 INVALID_P2M_ENTRY); 1007 INVALID_P2M_ENTRY);
1041 } 1008 }
1042 return 0; 1009 return ret;
1043 } 1010 }
1044 1011
1045 if (m2p_override && 1012 if (!in_interrupt() && paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
1046 !in_interrupt() &&
1047 paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
1048 arch_enter_lazy_mmu_mode(); 1013 arch_enter_lazy_mmu_mode();
1049 lazy = true; 1014 lazy = true;
1050 } 1015 }
1051 1016
1052 for (i = 0; i < count; i++) { 1017 for (i = 0; i < count; i++) {
1053 pfn = page_to_pfn(pages[i]); 1018 ret = m2p_remove_override(pages[i], kmap_ops ?
1054 mfn = get_phys_to_machine(pfn); 1019 &kmap_ops[i] : NULL);
1055 if (mfn == INVALID_P2M_ENTRY || !(mfn & FOREIGN_FRAME_BIT)) {
1056 ret = -EINVAL;
1057 goto out;
1058 }
1059
1060 set_page_private(pages[i], INVALID_P2M_ENTRY);
1061 WARN_ON(!PagePrivate(pages[i]));
1062 ClearPagePrivate(pages[i]);
1063 set_phys_to_machine(pfn, pages[i]->index);
1064 if (m2p_override)
1065 ret = m2p_remove_override(pages[i],
1066 kmap_ops ?
1067 &kmap_ops[i] : NULL,
1068 mfn);
1069 if (ret) 1020 if (ret)
1070 goto out; 1021 goto out;
1071 } 1022 }
@@ -1076,22 +1027,8 @@ int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1076 1027
1077 return ret; 1028 return ret;
1078} 1029}
1079
1080int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *map_ops,
1081 struct page **pages, unsigned int count)
1082{
1083 return __gnttab_unmap_refs(map_ops, NULL, pages, count, false);
1084}
1085EXPORT_SYMBOL_GPL(gnttab_unmap_refs); 1030EXPORT_SYMBOL_GPL(gnttab_unmap_refs);
1086 1031
1087int gnttab_unmap_refs_userspace(struct gnttab_unmap_grant_ref *map_ops,
1088 struct gnttab_map_grant_ref *kmap_ops,
1089 struct page **pages, unsigned int count)
1090{
1091 return __gnttab_unmap_refs(map_ops, kmap_ops, pages, count, true);
1092}
1093EXPORT_SYMBOL_GPL(gnttab_unmap_refs_userspace);
1094
1095static unsigned nr_status_frames(unsigned nr_grant_frames) 1032static unsigned nr_status_frames(unsigned nr_grant_frames)
1096{ 1033{
1097 BUG_ON(grefs_per_grant_frame == 0); 1034 BUG_ON(grefs_per_grant_frame == 0);
diff --git a/drivers/xen/xencomm.c b/drivers/xen/xencomm.c
deleted file mode 100644
index 4793fc594549..000000000000
--- a/drivers/xen/xencomm.c
+++ /dev/null
@@ -1,219 +0,0 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Copyright (C) IBM Corp. 2006
17 *
18 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
19 */
20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
23#include <linux/mm.h>
24#include <linux/slab.h>
25#include <asm/page.h>
26#include <xen/xencomm.h>
27#include <xen/interface/xen.h>
28#include <asm/xen/xencomm.h> /* for xencomm_is_phys_contiguous() */
29
30static int xencomm_init(struct xencomm_desc *desc,
31 void *buffer, unsigned long bytes)
32{
33 unsigned long recorded = 0;
34 int i = 0;
35
36 while ((recorded < bytes) && (i < desc->nr_addrs)) {
37 unsigned long vaddr = (unsigned long)buffer + recorded;
38 unsigned long paddr;
39 int offset;
40 int chunksz;
41
42 offset = vaddr % PAGE_SIZE; /* handle partial pages */
43 chunksz = min(PAGE_SIZE - offset, bytes - recorded);
44
45 paddr = xencomm_vtop(vaddr);
46 if (paddr == ~0UL) {
47 printk(KERN_DEBUG "%s: couldn't translate vaddr %lx\n",
48 __func__, vaddr);
49 return -EINVAL;
50 }
51
52 desc->address[i++] = paddr;
53 recorded += chunksz;
54 }
55
56 if (recorded < bytes) {
57 printk(KERN_DEBUG
58 "%s: could only translate %ld of %ld bytes\n",
59 __func__, recorded, bytes);
60 return -ENOSPC;
61 }
62
63 /* mark remaining addresses invalid (just for safety) */
64 while (i < desc->nr_addrs)
65 desc->address[i++] = XENCOMM_INVALID;
66
67 desc->magic = XENCOMM_MAGIC;
68
69 return 0;
70}
71
72static struct xencomm_desc *xencomm_alloc(gfp_t gfp_mask,
73 void *buffer, unsigned long bytes)
74{
75 struct xencomm_desc *desc;
76 unsigned long buffer_ulong = (unsigned long)buffer;
77 unsigned long start = buffer_ulong & PAGE_MASK;
78 unsigned long end = (buffer_ulong + bytes) | ~PAGE_MASK;
79 unsigned long nr_addrs = (end - start + 1) >> PAGE_SHIFT;
80 unsigned long size = sizeof(*desc) +
81 sizeof(desc->address[0]) * nr_addrs;
82
83 /*
84 * slab allocator returns at least sizeof(void*) aligned pointer.
85 * When sizeof(*desc) > sizeof(void*), struct xencomm_desc might
86 * cross page boundary.
87 */
88 if (sizeof(*desc) > sizeof(void *)) {
89 unsigned long order = get_order(size);
90 desc = (struct xencomm_desc *)__get_free_pages(gfp_mask,
91 order);
92 if (desc == NULL)
93 return NULL;
94
95 desc->nr_addrs =
96 ((PAGE_SIZE << order) - sizeof(struct xencomm_desc)) /
97 sizeof(*desc->address);
98 } else {
99 desc = kmalloc(size, gfp_mask);
100 if (desc == NULL)
101 return NULL;
102
103 desc->nr_addrs = nr_addrs;
104 }
105 return desc;
106}
107
108void xencomm_free(struct xencomm_handle *desc)
109{
110 if (desc && !((ulong)desc & XENCOMM_INLINE_FLAG)) {
111 struct xencomm_desc *desc__ = (struct xencomm_desc *)desc;
112 if (sizeof(*desc__) > sizeof(void *)) {
113 unsigned long size = sizeof(*desc__) +
114 sizeof(desc__->address[0]) * desc__->nr_addrs;
115 unsigned long order = get_order(size);
116 free_pages((unsigned long)__va(desc), order);
117 } else
118 kfree(__va(desc));
119 }
120}
121
122static int xencomm_create(void *buffer, unsigned long bytes,
123 struct xencomm_desc **ret, gfp_t gfp_mask)
124{
125 struct xencomm_desc *desc;
126 int rc;
127
128 pr_debug("%s: %p[%ld]\n", __func__, buffer, bytes);
129
130 if (bytes == 0) {
131 /* don't create a descriptor; Xen recognizes NULL. */
132 BUG_ON(buffer != NULL);
133 *ret = NULL;
134 return 0;
135 }
136
137 BUG_ON(buffer == NULL); /* 'bytes' is non-zero */
138
139 desc = xencomm_alloc(gfp_mask, buffer, bytes);
140 if (!desc) {
141 printk(KERN_DEBUG "%s failure\n", "xencomm_alloc");
142 return -ENOMEM;
143 }
144
145 rc = xencomm_init(desc, buffer, bytes);
146 if (rc) {
147 printk(KERN_DEBUG "%s failure: %d\n", "xencomm_init", rc);
148 xencomm_free((struct xencomm_handle *)__pa(desc));
149 return rc;
150 }
151
152 *ret = desc;
153 return 0;
154}
155
156static struct xencomm_handle *xencomm_create_inline(void *ptr)
157{
158 unsigned long paddr;
159
160 BUG_ON(!xencomm_is_phys_contiguous((unsigned long)ptr));
161
162 paddr = (unsigned long)xencomm_pa(ptr);
163 BUG_ON(paddr & XENCOMM_INLINE_FLAG);
164 return (struct xencomm_handle *)(paddr | XENCOMM_INLINE_FLAG);
165}
166
167/* "mini" routine, for stack-based communications: */
168static int xencomm_create_mini(void *buffer,
169 unsigned long bytes, struct xencomm_mini *xc_desc,
170 struct xencomm_desc **ret)
171{
172 int rc = 0;
173 struct xencomm_desc *desc;
174 BUG_ON(((unsigned long)xc_desc) % sizeof(*xc_desc) != 0);
175
176 desc = (void *)xc_desc;
177
178 desc->nr_addrs = XENCOMM_MINI_ADDRS;
179
180 rc = xencomm_init(desc, buffer, bytes);
181 if (!rc)
182 *ret = desc;
183
184 return rc;
185}
186
187struct xencomm_handle *xencomm_map(void *ptr, unsigned long bytes)
188{
189 int rc;
190 struct xencomm_desc *desc;
191
192 if (xencomm_is_phys_contiguous((unsigned long)ptr))
193 return xencomm_create_inline(ptr);
194
195 rc = xencomm_create(ptr, bytes, &desc, GFP_KERNEL);
196
197 if (rc || desc == NULL)
198 return NULL;
199
200 return xencomm_pa(desc);
201}
202
203struct xencomm_handle *__xencomm_map_no_alloc(void *ptr, unsigned long bytes,
204 struct xencomm_mini *xc_desc)
205{
206 int rc;
207 struct xencomm_desc *desc = NULL;
208
209 if (xencomm_is_phys_contiguous((unsigned long)ptr))
210 return xencomm_create_inline(ptr);
211
212 rc = xencomm_create_mini(ptr, bytes, xc_desc,
213 &desc);
214
215 if (rc)
216 return NULL;
217
218 return xencomm_pa(desc);
219}