diff options
-rw-r--r-- | arch/x86/include/asm/xen/hypercall.h | 17 | ||||
-rw-r--r-- | arch/x86/include/asm/xen/page.h | 12 | ||||
-rw-r--r-- | arch/x86/xen/Kconfig | 11 | ||||
-rw-r--r-- | arch/x86/xen/enlighten.c | 16 | ||||
-rw-r--r-- | arch/x86/xen/mmu.c | 501 | ||||
-rw-r--r-- | arch/x86/xen/mmu.h | 1 | ||||
-rw-r--r-- | arch/x86/xen/setup.c | 112 | ||||
-rw-r--r-- | arch/x86/xen/xen-ops.h | 3 | ||||
-rw-r--r-- | drivers/char/hvc_xen.c | 3 | ||||
-rw-r--r-- | drivers/xen/events.c | 101 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_probe.c | 4 | ||||
-rw-r--r-- | drivers/xen/xenfs/Makefile | 3 | ||||
-rw-r--r-- | drivers/xen/xenfs/privcmd.c | 404 | ||||
-rw-r--r-- | drivers/xen/xenfs/super.c | 95 | ||||
-rw-r--r-- | drivers/xen/xenfs/xenfs.h | 3 | ||||
-rw-r--r-- | drivers/xen/xenfs/xenstored.c | 68 | ||||
-rw-r--r-- | include/xen/Kbuild | 1 | ||||
-rw-r--r-- | include/xen/interface/memory.h | 29 | ||||
-rw-r--r-- | include/xen/privcmd.h | 80 | ||||
-rw-r--r-- | include/xen/xen-ops.h | 5 |
20 files changed, 1332 insertions, 137 deletions
diff --git a/arch/x86/include/asm/xen/hypercall.h b/arch/x86/include/asm/xen/hypercall.h index 7fda040a76cd..a3c28ae4025b 100644 --- a/arch/x86/include/asm/xen/hypercall.h +++ b/arch/x86/include/asm/xen/hypercall.h | |||
@@ -200,6 +200,23 @@ extern struct { char _entry[32]; } hypercall_page[]; | |||
200 | (type)__res; \ | 200 | (type)__res; \ |
201 | }) | 201 | }) |
202 | 202 | ||
203 | static inline long | ||
204 | privcmd_call(unsigned call, | ||
205 | unsigned long a1, unsigned long a2, | ||
206 | unsigned long a3, unsigned long a4, | ||
207 | unsigned long a5) | ||
208 | { | ||
209 | __HYPERCALL_DECLS; | ||
210 | __HYPERCALL_5ARG(a1, a2, a3, a4, a5); | ||
211 | |||
212 | asm volatile("call *%[call]" | ||
213 | : __HYPERCALL_5PARAM | ||
214 | : [call] "a" (&hypercall_page[call]) | ||
215 | : __HYPERCALL_CLOBBER5); | ||
216 | |||
217 | return (long)__res; | ||
218 | } | ||
219 | |||
203 | static inline int | 220 | static inline int |
204 | HYPERVISOR_set_trap_table(struct trap_info *table) | 221 | HYPERVISOR_set_trap_table(struct trap_info *table) |
205 | { | 222 | { |
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h index bf5f7d32bd08..dd8c1414b3d5 100644 --- a/arch/x86/include/asm/xen/page.h +++ b/arch/x86/include/asm/xen/page.h | |||
@@ -37,14 +37,21 @@ typedef struct xpaddr { | |||
37 | 37 | ||
38 | 38 | ||
39 | extern unsigned long get_phys_to_machine(unsigned long pfn); | 39 | extern unsigned long get_phys_to_machine(unsigned long pfn); |
40 | extern void set_phys_to_machine(unsigned long pfn, unsigned long mfn); | 40 | extern bool set_phys_to_machine(unsigned long pfn, unsigned long mfn); |
41 | 41 | ||
42 | static inline unsigned long pfn_to_mfn(unsigned long pfn) | 42 | static inline unsigned long pfn_to_mfn(unsigned long pfn) |
43 | { | 43 | { |
44 | unsigned long mfn; | ||
45 | |||
44 | if (xen_feature(XENFEAT_auto_translated_physmap)) | 46 | if (xen_feature(XENFEAT_auto_translated_physmap)) |
45 | return pfn; | 47 | return pfn; |
46 | 48 | ||
47 | return get_phys_to_machine(pfn) & ~FOREIGN_FRAME_BIT; | 49 | mfn = get_phys_to_machine(pfn); |
50 | |||
51 | if (mfn != INVALID_P2M_ENTRY) | ||
52 | mfn &= ~FOREIGN_FRAME_BIT; | ||
53 | |||
54 | return mfn; | ||
48 | } | 55 | } |
49 | 56 | ||
50 | static inline int phys_to_machine_mapping_valid(unsigned long pfn) | 57 | static inline int phys_to_machine_mapping_valid(unsigned long pfn) |
@@ -159,6 +166,7 @@ static inline pte_t __pte_ma(pteval_t x) | |||
159 | 166 | ||
160 | #define pgd_val_ma(x) ((x).pgd) | 167 | #define pgd_val_ma(x) ((x).pgd) |
161 | 168 | ||
169 | void xen_set_domain_pte(pte_t *ptep, pte_t pteval, unsigned domid); | ||
162 | 170 | ||
163 | xmaddr_t arbitrary_virt_to_machine(void *address); | 171 | xmaddr_t arbitrary_virt_to_machine(void *address); |
164 | unsigned long arbitrary_virt_to_mfn(void *vaddr); | 172 | unsigned long arbitrary_virt_to_mfn(void *vaddr); |
diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig index 68128a1b401a..90a7f5ad6916 100644 --- a/arch/x86/xen/Kconfig +++ b/arch/x86/xen/Kconfig | |||
@@ -19,15 +19,12 @@ config XEN_PVHVM | |||
19 | depends on X86_LOCAL_APIC | 19 | depends on X86_LOCAL_APIC |
20 | 20 | ||
21 | config XEN_MAX_DOMAIN_MEMORY | 21 | config XEN_MAX_DOMAIN_MEMORY |
22 | int "Maximum allowed size of a domain in gigabytes" | 22 | int |
23 | default 8 if X86_32 | 23 | default 128 |
24 | default 32 if X86_64 | ||
25 | depends on XEN | 24 | depends on XEN |
26 | help | 25 | help |
27 | The pseudo-physical to machine address array is sized | 26 | This only affects the sizing of some bss arrays, the unused |
28 | according to the maximum possible memory size of a Xen | 27 | portions of which are freed. |
29 | domain. This array uses 1 page per gigabyte, so there's no | ||
30 | need to be too stingy here. | ||
31 | 28 | ||
32 | config XEN_SAVE_RESTORE | 29 | config XEN_SAVE_RESTORE |
33 | bool | 30 | bool |
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index 63b83ceebd1a..44ab12dc2a12 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c | |||
@@ -136,9 +136,6 @@ static void xen_vcpu_setup(int cpu) | |||
136 | info.mfn = arbitrary_virt_to_mfn(vcpup); | 136 | info.mfn = arbitrary_virt_to_mfn(vcpup); |
137 | info.offset = offset_in_page(vcpup); | 137 | info.offset = offset_in_page(vcpup); |
138 | 138 | ||
139 | printk(KERN_DEBUG "trying to map vcpu_info %d at %p, mfn %llx, offset %d\n", | ||
140 | cpu, vcpup, info.mfn, info.offset); | ||
141 | |||
142 | /* Check to see if the hypervisor will put the vcpu_info | 139 | /* Check to see if the hypervisor will put the vcpu_info |
143 | structure where we want it, which allows direct access via | 140 | structure where we want it, which allows direct access via |
144 | a percpu-variable. */ | 141 | a percpu-variable. */ |
@@ -152,9 +149,6 @@ static void xen_vcpu_setup(int cpu) | |||
152 | /* This cpu is using the registered vcpu info, even if | 149 | /* This cpu is using the registered vcpu info, even if |
153 | later ones fail to. */ | 150 | later ones fail to. */ |
154 | per_cpu(xen_vcpu, cpu) = vcpup; | 151 | per_cpu(xen_vcpu, cpu) = vcpup; |
155 | |||
156 | printk(KERN_DEBUG "cpu %d using vcpu_info at %p\n", | ||
157 | cpu, vcpup); | ||
158 | } | 152 | } |
159 | } | 153 | } |
160 | 154 | ||
@@ -836,6 +830,11 @@ static int xen_write_msr_safe(unsigned int msr, unsigned low, unsigned high) | |||
836 | Xen console noise. */ | 830 | Xen console noise. */ |
837 | break; | 831 | break; |
838 | 832 | ||
833 | case MSR_IA32_CR_PAT: | ||
834 | if (smp_processor_id() == 0) | ||
835 | xen_set_pat(((u64)high << 32) | low); | ||
836 | break; | ||
837 | |||
839 | default: | 838 | default: |
840 | ret = native_write_msr_safe(msr, low, high); | 839 | ret = native_write_msr_safe(msr, low, high); |
841 | } | 840 | } |
@@ -874,8 +873,6 @@ void xen_setup_vcpu_info_placement(void) | |||
874 | /* xen_vcpu_setup managed to place the vcpu_info within the | 873 | /* xen_vcpu_setup managed to place the vcpu_info within the |
875 | percpu area for all cpus, so make use of it */ | 874 | percpu area for all cpus, so make use of it */ |
876 | if (have_vcpu_info_placement) { | 875 | if (have_vcpu_info_placement) { |
877 | printk(KERN_INFO "Xen: using vcpu_info placement\n"); | ||
878 | |||
879 | pv_irq_ops.save_fl = __PV_IS_CALLEE_SAVE(xen_save_fl_direct); | 876 | pv_irq_ops.save_fl = __PV_IS_CALLEE_SAVE(xen_save_fl_direct); |
880 | pv_irq_ops.restore_fl = __PV_IS_CALLEE_SAVE(xen_restore_fl_direct); | 877 | pv_irq_ops.restore_fl = __PV_IS_CALLEE_SAVE(xen_restore_fl_direct); |
881 | pv_irq_ops.irq_disable = __PV_IS_CALLEE_SAVE(xen_irq_disable_direct); | 878 | pv_irq_ops.irq_disable = __PV_IS_CALLEE_SAVE(xen_irq_disable_direct); |
@@ -1189,6 +1186,9 @@ asmlinkage void __init xen_start_kernel(void) | |||
1189 | xen_raw_console_write("mapping kernel into physical memory\n"); | 1186 | xen_raw_console_write("mapping kernel into physical memory\n"); |
1190 | pgd = xen_setup_kernel_pagetable(pgd, xen_start_info->nr_pages); | 1187 | pgd = xen_setup_kernel_pagetable(pgd, xen_start_info->nr_pages); |
1191 | 1188 | ||
1189 | /* Allocate and initialize top and mid mfn levels for p2m structure */ | ||
1190 | xen_build_mfn_list_list(); | ||
1191 | |||
1192 | init_mm.pgd = pgd; | 1192 | init_mm.pgd = pgd; |
1193 | 1193 | ||
1194 | /* keep using Xen gdt for now; no urgent need to change it */ | 1194 | /* keep using Xen gdt for now; no urgent need to change it */ |
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c index f72d18c69221..9631c90907eb 100644 --- a/arch/x86/xen/mmu.c +++ b/arch/x86/xen/mmu.c | |||
@@ -57,6 +57,7 @@ | |||
57 | #include <asm/linkage.h> | 57 | #include <asm/linkage.h> |
58 | #include <asm/page.h> | 58 | #include <asm/page.h> |
59 | #include <asm/init.h> | 59 | #include <asm/init.h> |
60 | #include <asm/pat.h> | ||
60 | 61 | ||
61 | #include <asm/xen/hypercall.h> | 62 | #include <asm/xen/hypercall.h> |
62 | #include <asm/xen/hypervisor.h> | 63 | #include <asm/xen/hypervisor.h> |
@@ -140,7 +141,8 @@ static inline void check_zero(void) | |||
140 | * large enough to allocate page table pages to allocate the rest. | 141 | * large enough to allocate page table pages to allocate the rest. |
141 | * Each page can map 2MB. | 142 | * Each page can map 2MB. |
142 | */ | 143 | */ |
143 | static pte_t level1_ident_pgt[PTRS_PER_PTE * 4] __page_aligned_bss; | 144 | #define LEVEL1_IDENT_ENTRIES (PTRS_PER_PTE * 4) |
145 | static RESERVE_BRK_ARRAY(pte_t, level1_ident_pgt, LEVEL1_IDENT_ENTRIES); | ||
144 | 146 | ||
145 | #ifdef CONFIG_X86_64 | 147 | #ifdef CONFIG_X86_64 |
146 | /* l3 pud for userspace vsyscall mapping */ | 148 | /* l3 pud for userspace vsyscall mapping */ |
@@ -171,49 +173,182 @@ DEFINE_PER_CPU(unsigned long, xen_current_cr3); /* actual vcpu cr3 */ | |||
171 | */ | 173 | */ |
172 | #define USER_LIMIT ((STACK_TOP_MAX + PGDIR_SIZE - 1) & PGDIR_MASK) | 174 | #define USER_LIMIT ((STACK_TOP_MAX + PGDIR_SIZE - 1) & PGDIR_MASK) |
173 | 175 | ||
176 | /* | ||
177 | * Xen leaves the responsibility for maintaining p2m mappings to the | ||
178 | * guests themselves, but it must also access and update the p2m array | ||
179 | * during suspend/resume when all the pages are reallocated. | ||
180 | * | ||
181 | * The p2m table is logically a flat array, but we implement it as a | ||
182 | * three-level tree to allow the address space to be sparse. | ||
183 | * | ||
184 | * Xen | ||
185 | * | | ||
186 | * p2m_top p2m_top_mfn | ||
187 | * / \ / \ | ||
188 | * p2m_mid p2m_mid p2m_mid_mfn p2m_mid_mfn | ||
189 | * / \ / \ / / | ||
190 | * p2m p2m p2m p2m p2m p2m p2m ... | ||
191 | * | ||
192 | * The p2m_mid_mfn pages are mapped by p2m_top_mfn_p. | ||
193 | * | ||
194 | * The p2m_top and p2m_top_mfn levels are limited to 1 page, so the | ||
195 | * maximum representable pseudo-physical address space is: | ||
196 | * P2M_TOP_PER_PAGE * P2M_MID_PER_PAGE * P2M_PER_PAGE pages | ||
197 | * | ||
198 | * P2M_PER_PAGE depends on the architecture, as a mfn is always | ||
199 | * unsigned long (8 bytes on 64-bit, 4 bytes on 32), leading to | ||
200 | * 512 and 1024 entries respectively. | ||
201 | */ | ||
202 | |||
203 | unsigned long xen_max_p2m_pfn __read_mostly; | ||
174 | 204 | ||
175 | #define P2M_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(unsigned long)) | 205 | #define P2M_PER_PAGE (PAGE_SIZE / sizeof(unsigned long)) |
176 | #define TOP_ENTRIES (MAX_DOMAIN_PAGES / P2M_ENTRIES_PER_PAGE) | 206 | #define P2M_MID_PER_PAGE (PAGE_SIZE / sizeof(unsigned long *)) |
207 | #define P2M_TOP_PER_PAGE (PAGE_SIZE / sizeof(unsigned long **)) | ||
177 | 208 | ||
178 | /* Placeholder for holes in the address space */ | 209 | #define MAX_P2M_PFN (P2M_TOP_PER_PAGE * P2M_MID_PER_PAGE * P2M_PER_PAGE) |
179 | static unsigned long p2m_missing[P2M_ENTRIES_PER_PAGE] __page_aligned_data = | ||
180 | { [ 0 ... P2M_ENTRIES_PER_PAGE-1 ] = ~0UL }; | ||
181 | 210 | ||
182 | /* Array of pointers to pages containing p2m entries */ | 211 | /* Placeholders for holes in the address space */ |
183 | static unsigned long *p2m_top[TOP_ENTRIES] __page_aligned_data = | 212 | static RESERVE_BRK_ARRAY(unsigned long, p2m_missing, P2M_PER_PAGE); |
184 | { [ 0 ... TOP_ENTRIES - 1] = &p2m_missing[0] }; | 213 | static RESERVE_BRK_ARRAY(unsigned long *, p2m_mid_missing, P2M_MID_PER_PAGE); |
214 | static RESERVE_BRK_ARRAY(unsigned long, p2m_mid_missing_mfn, P2M_MID_PER_PAGE); | ||
185 | 215 | ||
186 | /* Arrays of p2m arrays expressed in mfns used for save/restore */ | 216 | static RESERVE_BRK_ARRAY(unsigned long **, p2m_top, P2M_TOP_PER_PAGE); |
187 | static unsigned long p2m_top_mfn[TOP_ENTRIES] __page_aligned_bss; | 217 | static RESERVE_BRK_ARRAY(unsigned long, p2m_top_mfn, P2M_TOP_PER_PAGE); |
218 | static RESERVE_BRK_ARRAY(unsigned long *, p2m_top_mfn_p, P2M_TOP_PER_PAGE); | ||
188 | 219 | ||
189 | static unsigned long p2m_top_mfn_list[TOP_ENTRIES / P2M_ENTRIES_PER_PAGE] | 220 | RESERVE_BRK(p2m_mid, PAGE_SIZE * (MAX_DOMAIN_PAGES / (P2M_PER_PAGE * P2M_MID_PER_PAGE))); |
190 | __page_aligned_bss; | 221 | RESERVE_BRK(p2m_mid_mfn, PAGE_SIZE * (MAX_DOMAIN_PAGES / (P2M_PER_PAGE * P2M_MID_PER_PAGE))); |
191 | 222 | ||
192 | static inline unsigned p2m_top_index(unsigned long pfn) | 223 | static inline unsigned p2m_top_index(unsigned long pfn) |
193 | { | 224 | { |
194 | BUG_ON(pfn >= MAX_DOMAIN_PAGES); | 225 | BUG_ON(pfn >= MAX_P2M_PFN); |
195 | return pfn / P2M_ENTRIES_PER_PAGE; | 226 | return pfn / (P2M_MID_PER_PAGE * P2M_PER_PAGE); |
227 | } | ||
228 | |||
229 | static inline unsigned p2m_mid_index(unsigned long pfn) | ||
230 | { | ||
231 | return (pfn / P2M_PER_PAGE) % P2M_MID_PER_PAGE; | ||
196 | } | 232 | } |
197 | 233 | ||
198 | static inline unsigned p2m_index(unsigned long pfn) | 234 | static inline unsigned p2m_index(unsigned long pfn) |
199 | { | 235 | { |
200 | return pfn % P2M_ENTRIES_PER_PAGE; | 236 | return pfn % P2M_PER_PAGE; |
237 | } | ||
238 | |||
239 | static void p2m_top_init(unsigned long ***top) | ||
240 | { | ||
241 | unsigned i; | ||
242 | |||
243 | for (i = 0; i < P2M_TOP_PER_PAGE; i++) | ||
244 | top[i] = p2m_mid_missing; | ||
245 | } | ||
246 | |||
247 | static void p2m_top_mfn_init(unsigned long *top) | ||
248 | { | ||
249 | unsigned i; | ||
250 | |||
251 | for (i = 0; i < P2M_TOP_PER_PAGE; i++) | ||
252 | top[i] = virt_to_mfn(p2m_mid_missing_mfn); | ||
253 | } | ||
254 | |||
255 | static void p2m_top_mfn_p_init(unsigned long **top) | ||
256 | { | ||
257 | unsigned i; | ||
258 | |||
259 | for (i = 0; i < P2M_TOP_PER_PAGE; i++) | ||
260 | top[i] = p2m_mid_missing_mfn; | ||
261 | } | ||
262 | |||
263 | static void p2m_mid_init(unsigned long **mid) | ||
264 | { | ||
265 | unsigned i; | ||
266 | |||
267 | for (i = 0; i < P2M_MID_PER_PAGE; i++) | ||
268 | mid[i] = p2m_missing; | ||
269 | } | ||
270 | |||
271 | static void p2m_mid_mfn_init(unsigned long *mid) | ||
272 | { | ||
273 | unsigned i; | ||
274 | |||
275 | for (i = 0; i < P2M_MID_PER_PAGE; i++) | ||
276 | mid[i] = virt_to_mfn(p2m_missing); | ||
201 | } | 277 | } |
202 | 278 | ||
203 | /* Build the parallel p2m_top_mfn structures */ | 279 | static void p2m_init(unsigned long *p2m) |
280 | { | ||
281 | unsigned i; | ||
282 | |||
283 | for (i = 0; i < P2M_MID_PER_PAGE; i++) | ||
284 | p2m[i] = INVALID_P2M_ENTRY; | ||
285 | } | ||
286 | |||
287 | /* | ||
288 | * Build the parallel p2m_top_mfn and p2m_mid_mfn structures | ||
289 | * | ||
290 | * This is called both at boot time, and after resuming from suspend: | ||
291 | * - At boot time we're called very early, and must use extend_brk() | ||
292 | * to allocate memory. | ||
293 | * | ||
294 | * - After resume we're called from within stop_machine, but the mfn | ||
295 | * tree should alreay be completely allocated. | ||
296 | */ | ||
204 | void xen_build_mfn_list_list(void) | 297 | void xen_build_mfn_list_list(void) |
205 | { | 298 | { |
206 | unsigned pfn, idx; | 299 | unsigned long pfn; |
207 | 300 | ||
208 | for (pfn = 0; pfn < MAX_DOMAIN_PAGES; pfn += P2M_ENTRIES_PER_PAGE) { | 301 | /* Pre-initialize p2m_top_mfn to be completely missing */ |
209 | unsigned topidx = p2m_top_index(pfn); | 302 | if (p2m_top_mfn == NULL) { |
303 | p2m_mid_missing_mfn = extend_brk(PAGE_SIZE, PAGE_SIZE); | ||
304 | p2m_mid_mfn_init(p2m_mid_missing_mfn); | ||
305 | |||
306 | p2m_top_mfn_p = extend_brk(PAGE_SIZE, PAGE_SIZE); | ||
307 | p2m_top_mfn_p_init(p2m_top_mfn_p); | ||
210 | 308 | ||
211 | p2m_top_mfn[topidx] = virt_to_mfn(p2m_top[topidx]); | 309 | p2m_top_mfn = extend_brk(PAGE_SIZE, PAGE_SIZE); |
310 | p2m_top_mfn_init(p2m_top_mfn); | ||
311 | } else { | ||
312 | /* Reinitialise, mfn's all change after migration */ | ||
313 | p2m_mid_mfn_init(p2m_mid_missing_mfn); | ||
212 | } | 314 | } |
213 | 315 | ||
214 | for (idx = 0; idx < ARRAY_SIZE(p2m_top_mfn_list); idx++) { | 316 | for (pfn = 0; pfn < xen_max_p2m_pfn; pfn += P2M_PER_PAGE) { |
215 | unsigned topidx = idx * P2M_ENTRIES_PER_PAGE; | 317 | unsigned topidx = p2m_top_index(pfn); |
216 | p2m_top_mfn_list[idx] = virt_to_mfn(&p2m_top_mfn[topidx]); | 318 | unsigned mididx = p2m_mid_index(pfn); |
319 | unsigned long **mid; | ||
320 | unsigned long *mid_mfn_p; | ||
321 | |||
322 | mid = p2m_top[topidx]; | ||
323 | mid_mfn_p = p2m_top_mfn_p[topidx]; | ||
324 | |||
325 | /* Don't bother allocating any mfn mid levels if | ||
326 | * they're just missing, just update the stored mfn, | ||
327 | * since all could have changed over a migrate. | ||
328 | */ | ||
329 | if (mid == p2m_mid_missing) { | ||
330 | BUG_ON(mididx); | ||
331 | BUG_ON(mid_mfn_p != p2m_mid_missing_mfn); | ||
332 | p2m_top_mfn[topidx] = virt_to_mfn(p2m_mid_missing_mfn); | ||
333 | pfn += (P2M_MID_PER_PAGE - 1) * P2M_PER_PAGE; | ||
334 | continue; | ||
335 | } | ||
336 | |||
337 | if (mid_mfn_p == p2m_mid_missing_mfn) { | ||
338 | /* | ||
339 | * XXX boot-time only! We should never find | ||
340 | * missing parts of the mfn tree after | ||
341 | * runtime. extend_brk() will BUG if we call | ||
342 | * it too late. | ||
343 | */ | ||
344 | mid_mfn_p = extend_brk(PAGE_SIZE, PAGE_SIZE); | ||
345 | p2m_mid_mfn_init(mid_mfn_p); | ||
346 | |||
347 | p2m_top_mfn_p[topidx] = mid_mfn_p; | ||
348 | } | ||
349 | |||
350 | p2m_top_mfn[topidx] = virt_to_mfn(mid_mfn_p); | ||
351 | mid_mfn_p[mididx] = virt_to_mfn(mid[mididx]); | ||
217 | } | 352 | } |
218 | } | 353 | } |
219 | 354 | ||
@@ -222,8 +357,8 @@ void xen_setup_mfn_list_list(void) | |||
222 | BUG_ON(HYPERVISOR_shared_info == &xen_dummy_shared_info); | 357 | BUG_ON(HYPERVISOR_shared_info == &xen_dummy_shared_info); |
223 | 358 | ||
224 | HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = | 359 | HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = |
225 | virt_to_mfn(p2m_top_mfn_list); | 360 | virt_to_mfn(p2m_top_mfn); |
226 | HYPERVISOR_shared_info->arch.max_pfn = xen_start_info->nr_pages; | 361 | HYPERVISOR_shared_info->arch.max_pfn = xen_max_p2m_pfn; |
227 | } | 362 | } |
228 | 363 | ||
229 | /* Set up p2m_top to point to the domain-builder provided p2m pages */ | 364 | /* Set up p2m_top to point to the domain-builder provided p2m pages */ |
@@ -231,98 +366,176 @@ void __init xen_build_dynamic_phys_to_machine(void) | |||
231 | { | 366 | { |
232 | unsigned long *mfn_list = (unsigned long *)xen_start_info->mfn_list; | 367 | unsigned long *mfn_list = (unsigned long *)xen_start_info->mfn_list; |
233 | unsigned long max_pfn = min(MAX_DOMAIN_PAGES, xen_start_info->nr_pages); | 368 | unsigned long max_pfn = min(MAX_DOMAIN_PAGES, xen_start_info->nr_pages); |
234 | unsigned pfn; | 369 | unsigned long pfn; |
370 | |||
371 | xen_max_p2m_pfn = max_pfn; | ||
235 | 372 | ||
236 | for (pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES_PER_PAGE) { | 373 | p2m_missing = extend_brk(PAGE_SIZE, PAGE_SIZE); |
374 | p2m_init(p2m_missing); | ||
375 | |||
376 | p2m_mid_missing = extend_brk(PAGE_SIZE, PAGE_SIZE); | ||
377 | p2m_mid_init(p2m_mid_missing); | ||
378 | |||
379 | p2m_top = extend_brk(PAGE_SIZE, PAGE_SIZE); | ||
380 | p2m_top_init(p2m_top); | ||
381 | |||
382 | /* | ||
383 | * The domain builder gives us a pre-constructed p2m array in | ||
384 | * mfn_list for all the pages initially given to us, so we just | ||
385 | * need to graft that into our tree structure. | ||
386 | */ | ||
387 | for (pfn = 0; pfn < max_pfn; pfn += P2M_PER_PAGE) { | ||
237 | unsigned topidx = p2m_top_index(pfn); | 388 | unsigned topidx = p2m_top_index(pfn); |
389 | unsigned mididx = p2m_mid_index(pfn); | ||
238 | 390 | ||
239 | p2m_top[topidx] = &mfn_list[pfn]; | 391 | if (p2m_top[topidx] == p2m_mid_missing) { |
240 | } | 392 | unsigned long **mid = extend_brk(PAGE_SIZE, PAGE_SIZE); |
393 | p2m_mid_init(mid); | ||
394 | |||
395 | p2m_top[topidx] = mid; | ||
396 | } | ||
241 | 397 | ||
242 | xen_build_mfn_list_list(); | 398 | p2m_top[topidx][mididx] = &mfn_list[pfn]; |
399 | } | ||
243 | } | 400 | } |
244 | 401 | ||
245 | unsigned long get_phys_to_machine(unsigned long pfn) | 402 | unsigned long get_phys_to_machine(unsigned long pfn) |
246 | { | 403 | { |
247 | unsigned topidx, idx; | 404 | unsigned topidx, mididx, idx; |
248 | 405 | ||
249 | if (unlikely(pfn >= MAX_DOMAIN_PAGES)) | 406 | if (unlikely(pfn >= MAX_P2M_PFN)) |
250 | return INVALID_P2M_ENTRY; | 407 | return INVALID_P2M_ENTRY; |
251 | 408 | ||
252 | topidx = p2m_top_index(pfn); | 409 | topidx = p2m_top_index(pfn); |
410 | mididx = p2m_mid_index(pfn); | ||
253 | idx = p2m_index(pfn); | 411 | idx = p2m_index(pfn); |
254 | return p2m_top[topidx][idx]; | 412 | |
413 | return p2m_top[topidx][mididx][idx]; | ||
255 | } | 414 | } |
256 | EXPORT_SYMBOL_GPL(get_phys_to_machine); | 415 | EXPORT_SYMBOL_GPL(get_phys_to_machine); |
257 | 416 | ||
258 | /* install a new p2m_top page */ | 417 | static void *alloc_p2m_page(void) |
259 | bool install_p2mtop_page(unsigned long pfn, unsigned long *p) | ||
260 | { | 418 | { |
261 | unsigned topidx = p2m_top_index(pfn); | 419 | return (void *)__get_free_page(GFP_KERNEL | __GFP_REPEAT); |
262 | unsigned long **pfnp, *mfnp; | 420 | } |
263 | unsigned i; | ||
264 | 421 | ||
265 | pfnp = &p2m_top[topidx]; | 422 | static void free_p2m_page(void *p) |
266 | mfnp = &p2m_top_mfn[topidx]; | 423 | { |
424 | free_page((unsigned long)p); | ||
425 | } | ||
267 | 426 | ||
268 | for (i = 0; i < P2M_ENTRIES_PER_PAGE; i++) | 427 | /* |
269 | p[i] = INVALID_P2M_ENTRY; | 428 | * Fully allocate the p2m structure for a given pfn. We need to check |
429 | * that both the top and mid levels are allocated, and make sure the | ||
430 | * parallel mfn tree is kept in sync. We may race with other cpus, so | ||
431 | * the new pages are installed with cmpxchg; if we lose the race then | ||
432 | * simply free the page we allocated and use the one that's there. | ||
433 | */ | ||
434 | static bool alloc_p2m(unsigned long pfn) | ||
435 | { | ||
436 | unsigned topidx, mididx; | ||
437 | unsigned long ***top_p, **mid; | ||
438 | unsigned long *top_mfn_p, *mid_mfn; | ||
270 | 439 | ||
271 | if (cmpxchg(pfnp, p2m_missing, p) == p2m_missing) { | 440 | topidx = p2m_top_index(pfn); |
272 | *mfnp = virt_to_mfn(p); | 441 | mididx = p2m_mid_index(pfn); |
273 | return true; | 442 | |
443 | top_p = &p2m_top[topidx]; | ||
444 | mid = *top_p; | ||
445 | |||
446 | if (mid == p2m_mid_missing) { | ||
447 | /* Mid level is missing, allocate a new one */ | ||
448 | mid = alloc_p2m_page(); | ||
449 | if (!mid) | ||
450 | return false; | ||
451 | |||
452 | p2m_mid_init(mid); | ||
453 | |||
454 | if (cmpxchg(top_p, p2m_mid_missing, mid) != p2m_mid_missing) | ||
455 | free_p2m_page(mid); | ||
274 | } | 456 | } |
275 | 457 | ||
276 | return false; | 458 | top_mfn_p = &p2m_top_mfn[topidx]; |
277 | } | 459 | mid_mfn = p2m_top_mfn_p[topidx]; |
278 | 460 | ||
279 | static void alloc_p2m(unsigned long pfn) | 461 | BUG_ON(virt_to_mfn(mid_mfn) != *top_mfn_p); |
280 | { | 462 | |
281 | unsigned long *p; | 463 | if (mid_mfn == p2m_mid_missing_mfn) { |
464 | /* Separately check the mid mfn level */ | ||
465 | unsigned long missing_mfn; | ||
466 | unsigned long mid_mfn_mfn; | ||
467 | |||
468 | mid_mfn = alloc_p2m_page(); | ||
469 | if (!mid_mfn) | ||
470 | return false; | ||
471 | |||
472 | p2m_mid_mfn_init(mid_mfn); | ||
473 | |||
474 | missing_mfn = virt_to_mfn(p2m_mid_missing_mfn); | ||
475 | mid_mfn_mfn = virt_to_mfn(mid_mfn); | ||
476 | if (cmpxchg(top_mfn_p, missing_mfn, mid_mfn_mfn) != missing_mfn) | ||
477 | free_p2m_page(mid_mfn); | ||
478 | else | ||
479 | p2m_top_mfn_p[topidx] = mid_mfn; | ||
480 | } | ||
481 | |||
482 | if (p2m_top[topidx][mididx] == p2m_missing) { | ||
483 | /* p2m leaf page is missing */ | ||
484 | unsigned long *p2m; | ||
485 | |||
486 | p2m = alloc_p2m_page(); | ||
487 | if (!p2m) | ||
488 | return false; | ||
282 | 489 | ||
283 | p = (void *)__get_free_page(GFP_KERNEL | __GFP_NOFAIL); | 490 | p2m_init(p2m); |
284 | BUG_ON(p == NULL); | 491 | |
492 | if (cmpxchg(&mid[mididx], p2m_missing, p2m) != p2m_missing) | ||
493 | free_p2m_page(p2m); | ||
494 | else | ||
495 | mid_mfn[mididx] = virt_to_mfn(p2m); | ||
496 | } | ||
285 | 497 | ||
286 | if (!install_p2mtop_page(pfn, p)) | 498 | return true; |
287 | free_page((unsigned long)p); | ||
288 | } | 499 | } |
289 | 500 | ||
290 | /* Try to install p2m mapping; fail if intermediate bits missing */ | 501 | /* Try to install p2m mapping; fail if intermediate bits missing */ |
291 | bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn) | 502 | bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn) |
292 | { | 503 | { |
293 | unsigned topidx, idx; | 504 | unsigned topidx, mididx, idx; |
294 | 505 | ||
295 | if (unlikely(pfn >= MAX_DOMAIN_PAGES)) { | 506 | if (unlikely(pfn >= MAX_P2M_PFN)) { |
296 | BUG_ON(mfn != INVALID_P2M_ENTRY); | 507 | BUG_ON(mfn != INVALID_P2M_ENTRY); |
297 | return true; | 508 | return true; |
298 | } | 509 | } |
299 | 510 | ||
300 | topidx = p2m_top_index(pfn); | 511 | topidx = p2m_top_index(pfn); |
301 | if (p2m_top[topidx] == p2m_missing) { | 512 | mididx = p2m_mid_index(pfn); |
302 | if (mfn == INVALID_P2M_ENTRY) | ||
303 | return true; | ||
304 | return false; | ||
305 | } | ||
306 | |||
307 | idx = p2m_index(pfn); | 513 | idx = p2m_index(pfn); |
308 | p2m_top[topidx][idx] = mfn; | 514 | |
515 | if (p2m_top[topidx][mididx] == p2m_missing) | ||
516 | return mfn == INVALID_P2M_ENTRY; | ||
517 | |||
518 | p2m_top[topidx][mididx][idx] = mfn; | ||
309 | 519 | ||
310 | return true; | 520 | return true; |
311 | } | 521 | } |
312 | 522 | ||
313 | void set_phys_to_machine(unsigned long pfn, unsigned long mfn) | 523 | bool set_phys_to_machine(unsigned long pfn, unsigned long mfn) |
314 | { | 524 | { |
315 | if (unlikely(xen_feature(XENFEAT_auto_translated_physmap))) { | 525 | if (unlikely(xen_feature(XENFEAT_auto_translated_physmap))) { |
316 | BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY); | 526 | BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY); |
317 | return; | 527 | return true; |
318 | } | 528 | } |
319 | 529 | ||
320 | if (unlikely(!__set_phys_to_machine(pfn, mfn))) { | 530 | if (unlikely(!__set_phys_to_machine(pfn, mfn))) { |
321 | alloc_p2m(pfn); | 531 | if (!alloc_p2m(pfn)) |
532 | return false; | ||
322 | 533 | ||
323 | if (!__set_phys_to_machine(pfn, mfn)) | 534 | if (!__set_phys_to_machine(pfn, mfn)) |
324 | BUG(); | 535 | return false; |
325 | } | 536 | } |
537 | |||
538 | return true; | ||
326 | } | 539 | } |
327 | 540 | ||
328 | unsigned long arbitrary_virt_to_mfn(void *vaddr) | 541 | unsigned long arbitrary_virt_to_mfn(void *vaddr) |
@@ -399,7 +612,7 @@ static bool xen_iomap_pte(pte_t pte) | |||
399 | return pte_flags(pte) & _PAGE_IOMAP; | 612 | return pte_flags(pte) & _PAGE_IOMAP; |
400 | } | 613 | } |
401 | 614 | ||
402 | static void xen_set_iomap_pte(pte_t *ptep, pte_t pteval) | 615 | void xen_set_domain_pte(pte_t *ptep, pte_t pteval, unsigned domid) |
403 | { | 616 | { |
404 | struct multicall_space mcs; | 617 | struct multicall_space mcs; |
405 | struct mmu_update *u; | 618 | struct mmu_update *u; |
@@ -411,10 +624,16 @@ static void xen_set_iomap_pte(pte_t *ptep, pte_t pteval) | |||
411 | u->ptr = arbitrary_virt_to_machine(ptep).maddr; | 624 | u->ptr = arbitrary_virt_to_machine(ptep).maddr; |
412 | u->val = pte_val_ma(pteval); | 625 | u->val = pte_val_ma(pteval); |
413 | 626 | ||
414 | MULTI_mmu_update(mcs.mc, mcs.args, 1, NULL, DOMID_IO); | 627 | MULTI_mmu_update(mcs.mc, mcs.args, 1, NULL, domid); |
415 | 628 | ||
416 | xen_mc_issue(PARAVIRT_LAZY_MMU); | 629 | xen_mc_issue(PARAVIRT_LAZY_MMU); |
417 | } | 630 | } |
631 | EXPORT_SYMBOL_GPL(xen_set_domain_pte); | ||
632 | |||
633 | static void xen_set_iomap_pte(pte_t *ptep, pte_t pteval) | ||
634 | { | ||
635 | xen_set_domain_pte(ptep, pteval, DOMID_IO); | ||
636 | } | ||
418 | 637 | ||
419 | static void xen_extend_mmu_update(const struct mmu_update *update) | 638 | static void xen_extend_mmu_update(const struct mmu_update *update) |
420 | { | 639 | { |
@@ -561,7 +780,20 @@ static pteval_t pte_pfn_to_mfn(pteval_t val) | |||
561 | if (val & _PAGE_PRESENT) { | 780 | if (val & _PAGE_PRESENT) { |
562 | unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT; | 781 | unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT; |
563 | pteval_t flags = val & PTE_FLAGS_MASK; | 782 | pteval_t flags = val & PTE_FLAGS_MASK; |
564 | val = ((pteval_t)pfn_to_mfn(pfn) << PAGE_SHIFT) | flags; | 783 | unsigned long mfn = pfn_to_mfn(pfn); |
784 | |||
785 | /* | ||
786 | * If there's no mfn for the pfn, then just create an | ||
787 | * empty non-present pte. Unfortunately this loses | ||
788 | * information about the original pfn, so | ||
789 | * pte_mfn_to_pfn is asymmetric. | ||
790 | */ | ||
791 | if (unlikely(mfn == INVALID_P2M_ENTRY)) { | ||
792 | mfn = 0; | ||
793 | flags = 0; | ||
794 | } | ||
795 | |||
796 | val = ((pteval_t)mfn << PAGE_SHIFT) | flags; | ||
565 | } | 797 | } |
566 | 798 | ||
567 | return val; | 799 | return val; |
@@ -583,10 +815,18 @@ static pteval_t iomap_pte(pteval_t val) | |||
583 | 815 | ||
584 | pteval_t xen_pte_val(pte_t pte) | 816 | pteval_t xen_pte_val(pte_t pte) |
585 | { | 817 | { |
586 | if (xen_initial_domain() && (pte.pte & _PAGE_IOMAP)) | 818 | pteval_t pteval = pte.pte; |
587 | return pte.pte; | 819 | |
820 | /* If this is a WC pte, convert back from Xen WC to Linux WC */ | ||
821 | if ((pteval & (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT)) == _PAGE_PAT) { | ||
822 | WARN_ON(!pat_enabled); | ||
823 | pteval = (pteval & ~_PAGE_PAT) | _PAGE_PWT; | ||
824 | } | ||
588 | 825 | ||
589 | return pte_mfn_to_pfn(pte.pte); | 826 | if (xen_initial_domain() && (pteval & _PAGE_IOMAP)) |
827 | return pteval; | ||
828 | |||
829 | return pte_mfn_to_pfn(pteval); | ||
590 | } | 830 | } |
591 | PV_CALLEE_SAVE_REGS_THUNK(xen_pte_val); | 831 | PV_CALLEE_SAVE_REGS_THUNK(xen_pte_val); |
592 | 832 | ||
@@ -596,10 +836,48 @@ pgdval_t xen_pgd_val(pgd_t pgd) | |||
596 | } | 836 | } |
597 | PV_CALLEE_SAVE_REGS_THUNK(xen_pgd_val); | 837 | PV_CALLEE_SAVE_REGS_THUNK(xen_pgd_val); |
598 | 838 | ||
839 | /* | ||
840 | * Xen's PAT setup is part of its ABI, though I assume entries 6 & 7 | ||
841 | * are reserved for now, to correspond to the Intel-reserved PAT | ||
842 | * types. | ||
843 | * | ||
844 | * We expect Linux's PAT set as follows: | ||
845 | * | ||
846 | * Idx PTE flags Linux Xen Default | ||
847 | * 0 WB WB WB | ||
848 | * 1 PWT WC WT WT | ||
849 | * 2 PCD UC- UC- UC- | ||
850 | * 3 PCD PWT UC UC UC | ||
851 | * 4 PAT WB WC WB | ||
852 | * 5 PAT PWT WC WP WT | ||
853 | * 6 PAT PCD UC- UC UC- | ||
854 | * 7 PAT PCD PWT UC UC UC | ||
855 | */ | ||
856 | |||
857 | void xen_set_pat(u64 pat) | ||
858 | { | ||
859 | /* We expect Linux to use a PAT setting of | ||
860 | * UC UC- WC WB (ignoring the PAT flag) */ | ||
861 | WARN_ON(pat != 0x0007010600070106ull); | ||
862 | } | ||
863 | |||
599 | pte_t xen_make_pte(pteval_t pte) | 864 | pte_t xen_make_pte(pteval_t pte) |
600 | { | 865 | { |
601 | phys_addr_t addr = (pte & PTE_PFN_MASK); | 866 | phys_addr_t addr = (pte & PTE_PFN_MASK); |
602 | 867 | ||
868 | /* If Linux is trying to set a WC pte, then map to the Xen WC. | ||
869 | * If _PAGE_PAT is set, then it probably means it is really | ||
870 | * _PAGE_PSE, so avoid fiddling with the PAT mapping and hope | ||
871 | * things work out OK... | ||
872 | * | ||
873 | * (We should never see kernel mappings with _PAGE_PSE set, | ||
874 | * but we could see hugetlbfs mappings, I think.). | ||
875 | */ | ||
876 | if (pat_enabled && !WARN_ON(pte & _PAGE_PAT)) { | ||
877 | if ((pte & (_PAGE_PCD | _PAGE_PWT)) == _PAGE_PWT) | ||
878 | pte = (pte & ~(_PAGE_PCD | _PAGE_PWT)) | _PAGE_PAT; | ||
879 | } | ||
880 | |||
603 | /* | 881 | /* |
604 | * Unprivileged domains are allowed to do IOMAPpings for | 882 | * Unprivileged domains are allowed to do IOMAPpings for |
605 | * PCI passthrough, but not map ISA space. The ISA | 883 | * PCI passthrough, but not map ISA space. The ISA |
@@ -1712,6 +1990,9 @@ static __init void xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn) | |||
1712 | unsigned ident_pte; | 1990 | unsigned ident_pte; |
1713 | unsigned long pfn; | 1991 | unsigned long pfn; |
1714 | 1992 | ||
1993 | level1_ident_pgt = extend_brk(sizeof(pte_t) * LEVEL1_IDENT_ENTRIES, | ||
1994 | PAGE_SIZE); | ||
1995 | |||
1715 | ident_pte = 0; | 1996 | ident_pte = 0; |
1716 | pfn = 0; | 1997 | pfn = 0; |
1717 | for (pmdidx = 0; pmdidx < PTRS_PER_PMD && pfn < max_pfn; pmdidx++) { | 1998 | for (pmdidx = 0; pmdidx < PTRS_PER_PMD && pfn < max_pfn; pmdidx++) { |
@@ -1722,7 +2003,7 @@ static __init void xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn) | |||
1722 | pte_page = m2v(pmd[pmdidx].pmd); | 2003 | pte_page = m2v(pmd[pmdidx].pmd); |
1723 | else { | 2004 | else { |
1724 | /* Check for free pte pages */ | 2005 | /* Check for free pte pages */ |
1725 | if (ident_pte == ARRAY_SIZE(level1_ident_pgt)) | 2006 | if (ident_pte == LEVEL1_IDENT_ENTRIES) |
1726 | break; | 2007 | break; |
1727 | 2008 | ||
1728 | pte_page = &level1_ident_pgt[ident_pte]; | 2009 | pte_page = &level1_ident_pgt[ident_pte]; |
@@ -1837,13 +2118,15 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd, | |||
1837 | return pgd; | 2118 | return pgd; |
1838 | } | 2119 | } |
1839 | #else /* !CONFIG_X86_64 */ | 2120 | #else /* !CONFIG_X86_64 */ |
1840 | static pmd_t level2_kernel_pgt[PTRS_PER_PMD] __page_aligned_bss; | 2121 | static RESERVE_BRK_ARRAY(pmd_t, level2_kernel_pgt, PTRS_PER_PMD); |
1841 | 2122 | ||
1842 | __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd, | 2123 | __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd, |
1843 | unsigned long max_pfn) | 2124 | unsigned long max_pfn) |
1844 | { | 2125 | { |
1845 | pmd_t *kernel_pmd; | 2126 | pmd_t *kernel_pmd; |
1846 | 2127 | ||
2128 | level2_kernel_pgt = extend_brk(sizeof(pmd_t *) * PTRS_PER_PMD, PAGE_SIZE); | ||
2129 | |||
1847 | max_pfn_mapped = PFN_DOWN(__pa(xen_start_info->pt_base) + | 2130 | max_pfn_mapped = PFN_DOWN(__pa(xen_start_info->pt_base) + |
1848 | xen_start_info->nr_pt_frames * PAGE_SIZE + | 2131 | xen_start_info->nr_pt_frames * PAGE_SIZE + |
1849 | 512*1024); | 2132 | 512*1024); |
@@ -2269,6 +2552,72 @@ void __init xen_hvm_init_mmu_ops(void) | |||
2269 | } | 2552 | } |
2270 | #endif | 2553 | #endif |
2271 | 2554 | ||
2555 | #define REMAP_BATCH_SIZE 16 | ||
2556 | |||
2557 | struct remap_data { | ||
2558 | unsigned long mfn; | ||
2559 | pgprot_t prot; | ||
2560 | struct mmu_update *mmu_update; | ||
2561 | }; | ||
2562 | |||
2563 | static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token, | ||
2564 | unsigned long addr, void *data) | ||
2565 | { | ||
2566 | struct remap_data *rmd = data; | ||
2567 | pte_t pte = pte_mkspecial(pfn_pte(rmd->mfn++, rmd->prot)); | ||
2568 | |||
2569 | rmd->mmu_update->ptr = arbitrary_virt_to_machine(ptep).maddr; | ||
2570 | rmd->mmu_update->val = pte_val_ma(pte); | ||
2571 | rmd->mmu_update++; | ||
2572 | |||
2573 | return 0; | ||
2574 | } | ||
2575 | |||
2576 | int xen_remap_domain_mfn_range(struct vm_area_struct *vma, | ||
2577 | unsigned long addr, | ||
2578 | unsigned long mfn, int nr, | ||
2579 | pgprot_t prot, unsigned domid) | ||
2580 | { | ||
2581 | struct remap_data rmd; | ||
2582 | struct mmu_update mmu_update[REMAP_BATCH_SIZE]; | ||
2583 | int batch; | ||
2584 | unsigned long range; | ||
2585 | int err = 0; | ||
2586 | |||
2587 | prot = __pgprot(pgprot_val(prot) | _PAGE_IOMAP); | ||
2588 | |||
2589 | vma->vm_flags |= VM_IO | VM_RESERVED | VM_PFNMAP; | ||
2590 | |||
2591 | rmd.mfn = mfn; | ||
2592 | rmd.prot = prot; | ||
2593 | |||
2594 | while (nr) { | ||
2595 | batch = min(REMAP_BATCH_SIZE, nr); | ||
2596 | range = (unsigned long)batch << PAGE_SHIFT; | ||
2597 | |||
2598 | rmd.mmu_update = mmu_update; | ||
2599 | err = apply_to_page_range(vma->vm_mm, addr, range, | ||
2600 | remap_area_mfn_pte_fn, &rmd); | ||
2601 | if (err) | ||
2602 | goto out; | ||
2603 | |||
2604 | err = -EFAULT; | ||
2605 | if (HYPERVISOR_mmu_update(mmu_update, batch, NULL, domid) < 0) | ||
2606 | goto out; | ||
2607 | |||
2608 | nr -= batch; | ||
2609 | addr += range; | ||
2610 | } | ||
2611 | |||
2612 | err = 0; | ||
2613 | out: | ||
2614 | |||
2615 | flush_tlb_all(); | ||
2616 | |||
2617 | return err; | ||
2618 | } | ||
2619 | EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range); | ||
2620 | |||
2272 | #ifdef CONFIG_XEN_DEBUG_FS | 2621 | #ifdef CONFIG_XEN_DEBUG_FS |
2273 | 2622 | ||
2274 | static struct dentry *d_mmu_debug; | 2623 | static struct dentry *d_mmu_debug; |
diff --git a/arch/x86/xen/mmu.h b/arch/x86/xen/mmu.h index fa938c4aa2f7..537bb9aab777 100644 --- a/arch/x86/xen/mmu.h +++ b/arch/x86/xen/mmu.h | |||
@@ -12,7 +12,6 @@ enum pt_level { | |||
12 | 12 | ||
13 | 13 | ||
14 | bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn); | 14 | bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn); |
15 | bool install_p2mtop_page(unsigned long pfn, unsigned long *p); | ||
16 | 15 | ||
17 | void set_pte_mfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags); | 16 | void set_pte_mfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags); |
18 | 17 | ||
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index 9729c903404b..105db2501050 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c | |||
@@ -18,8 +18,10 @@ | |||
18 | #include <asm/xen/hypervisor.h> | 18 | #include <asm/xen/hypervisor.h> |
19 | #include <asm/xen/hypercall.h> | 19 | #include <asm/xen/hypercall.h> |
20 | 20 | ||
21 | #include <xen/xen.h> | ||
21 | #include <xen/page.h> | 22 | #include <xen/page.h> |
22 | #include <xen/interface/callback.h> | 23 | #include <xen/interface/callback.h> |
24 | #include <xen/interface/memory.h> | ||
23 | #include <xen/interface/physdev.h> | 25 | #include <xen/interface/physdev.h> |
24 | #include <xen/interface/memory.h> | 26 | #include <xen/interface/memory.h> |
25 | #include <xen/features.h> | 27 | #include <xen/features.h> |
@@ -34,6 +36,39 @@ extern void xen_sysenter_target(void); | |||
34 | extern void xen_syscall_target(void); | 36 | extern void xen_syscall_target(void); |
35 | extern void xen_syscall32_target(void); | 37 | extern void xen_syscall32_target(void); |
36 | 38 | ||
39 | /* Amount of extra memory space we add to the e820 ranges */ | ||
40 | phys_addr_t xen_extra_mem_start, xen_extra_mem_size; | ||
41 | |||
42 | /* | ||
43 | * The maximum amount of extra memory compared to the base size. The | ||
44 | * main scaling factor is the size of struct page. At extreme ratios | ||
45 | * of base:extra, all the base memory can be filled with page | ||
46 | * structures for the extra memory, leaving no space for anything | ||
47 | * else. | ||
48 | * | ||
49 | * 10x seems like a reasonable balance between scaling flexibility and | ||
50 | * leaving a practically usable system. | ||
51 | */ | ||
52 | #define EXTRA_MEM_RATIO (10) | ||
53 | |||
54 | static __init void xen_add_extra_mem(unsigned long pages) | ||
55 | { | ||
56 | u64 size = (u64)pages * PAGE_SIZE; | ||
57 | u64 extra_start = xen_extra_mem_start + xen_extra_mem_size; | ||
58 | |||
59 | if (!pages) | ||
60 | return; | ||
61 | |||
62 | e820_add_region(extra_start, size, E820_RAM); | ||
63 | sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); | ||
64 | |||
65 | memblock_x86_reserve_range(extra_start, extra_start + size, "XEN EXTRA"); | ||
66 | |||
67 | xen_extra_mem_size += size; | ||
68 | |||
69 | xen_max_p2m_pfn = PFN_DOWN(extra_start + size); | ||
70 | } | ||
71 | |||
37 | static unsigned long __init xen_release_chunk(phys_addr_t start_addr, | 72 | static unsigned long __init xen_release_chunk(phys_addr_t start_addr, |
38 | phys_addr_t end_addr) | 73 | phys_addr_t end_addr) |
39 | { | 74 | { |
@@ -105,16 +140,65 @@ static unsigned long __init xen_return_unused_memory(unsigned long max_pfn, | |||
105 | /** | 140 | /** |
106 | * machine_specific_memory_setup - Hook for machine specific memory setup. | 141 | * machine_specific_memory_setup - Hook for machine specific memory setup. |
107 | **/ | 142 | **/ |
108 | |||
109 | char * __init xen_memory_setup(void) | 143 | char * __init xen_memory_setup(void) |
110 | { | 144 | { |
145 | static struct e820entry map[E820MAX] __initdata; | ||
146 | |||
111 | unsigned long max_pfn = xen_start_info->nr_pages; | 147 | unsigned long max_pfn = xen_start_info->nr_pages; |
148 | unsigned long long mem_end; | ||
149 | int rc; | ||
150 | struct xen_memory_map memmap; | ||
151 | unsigned long extra_pages = 0; | ||
152 | unsigned long extra_limit; | ||
153 | int i; | ||
154 | int op; | ||
112 | 155 | ||
113 | max_pfn = min(MAX_DOMAIN_PAGES, max_pfn); | 156 | max_pfn = min(MAX_DOMAIN_PAGES, max_pfn); |
157 | mem_end = PFN_PHYS(max_pfn); | ||
158 | |||
159 | memmap.nr_entries = E820MAX; | ||
160 | set_xen_guest_handle(memmap.buffer, map); | ||
161 | |||
162 | op = xen_initial_domain() ? | ||
163 | XENMEM_machine_memory_map : | ||
164 | XENMEM_memory_map; | ||
165 | rc = HYPERVISOR_memory_op(op, &memmap); | ||
166 | if (rc == -ENOSYS) { | ||
167 | memmap.nr_entries = 1; | ||
168 | map[0].addr = 0ULL; | ||
169 | map[0].size = mem_end; | ||
170 | /* 8MB slack (to balance backend allocations). */ | ||
171 | map[0].size += 8ULL << 20; | ||
172 | map[0].type = E820_RAM; | ||
173 | rc = 0; | ||
174 | } | ||
175 | BUG_ON(rc); | ||
114 | 176 | ||
115 | e820.nr_map = 0; | 177 | e820.nr_map = 0; |
178 | xen_extra_mem_start = mem_end; | ||
179 | for (i = 0; i < memmap.nr_entries; i++) { | ||
180 | unsigned long long end = map[i].addr + map[i].size; | ||
181 | |||
182 | if (map[i].type == E820_RAM) { | ||
183 | if (map[i].addr < mem_end && end > mem_end) { | ||
184 | /* Truncate region to max_mem. */ | ||
185 | u64 delta = end - mem_end; | ||
186 | |||
187 | map[i].size -= delta; | ||
188 | extra_pages += PFN_DOWN(delta); | ||
189 | |||
190 | end = mem_end; | ||
191 | } | ||
192 | } | ||
116 | 193 | ||
117 | e820_add_region(0, PFN_PHYS((u64)max_pfn), E820_RAM); | 194 | if (end > xen_extra_mem_start) |
195 | xen_extra_mem_start = end; | ||
196 | |||
197 | /* If region is non-RAM or below mem_end, add what remains */ | ||
198 | if ((map[i].type != E820_RAM || map[i].addr < mem_end) && | ||
199 | map[i].size > 0) | ||
200 | e820_add_region(map[i].addr, map[i].size, map[i].type); | ||
201 | } | ||
118 | 202 | ||
119 | /* | 203 | /* |
120 | * Even though this is normal, usable memory under Xen, reserve | 204 | * Even though this is normal, usable memory under Xen, reserve |
@@ -136,7 +220,29 @@ char * __init xen_memory_setup(void) | |||
136 | 220 | ||
137 | sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); | 221 | sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); |
138 | 222 | ||
139 | xen_return_unused_memory(xen_start_info->nr_pages, &e820); | 223 | extra_pages += xen_return_unused_memory(xen_start_info->nr_pages, &e820); |
224 | |||
225 | /* | ||
226 | * Clamp the amount of extra memory to a EXTRA_MEM_RATIO | ||
227 | * factor the base size. On non-highmem systems, the base | ||
228 | * size is the full initial memory allocation; on highmem it | ||
229 | * is limited to the max size of lowmem, so that it doesn't | ||
230 | * get completely filled. | ||
231 | * | ||
232 | * In principle there could be a problem in lowmem systems if | ||
233 | * the initial memory is also very large with respect to | ||
234 | * lowmem, but we won't try to deal with that here. | ||
235 | */ | ||
236 | extra_limit = min(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)), | ||
237 | max_pfn + extra_pages); | ||
238 | |||
239 | if (extra_limit >= max_pfn) | ||
240 | extra_pages = extra_limit - max_pfn; | ||
241 | else | ||
242 | extra_pages = 0; | ||
243 | |||
244 | if (!xen_initial_domain()) | ||
245 | xen_add_extra_mem(extra_pages); | ||
140 | 246 | ||
141 | return "Xen"; | 247 | return "Xen"; |
142 | } | 248 | } |
diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 7c8ab86163e9..64044747348e 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h | |||
@@ -30,6 +30,9 @@ void xen_setup_machphys_mapping(void); | |||
30 | pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn); | 30 | pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn); |
31 | void xen_ident_map_ISA(void); | 31 | void xen_ident_map_ISA(void); |
32 | void xen_reserve_top(void); | 32 | void xen_reserve_top(void); |
33 | extern unsigned long xen_max_p2m_pfn; | ||
34 | |||
35 | void xen_set_pat(u64); | ||
33 | 36 | ||
34 | char * __init xen_memory_setup(void); | 37 | char * __init xen_memory_setup(void); |
35 | void __init xen_arch_setup(void); | 38 | void __init xen_arch_setup(void); |
diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c index 60446f82a3fc..6b8e6d18a8e6 100644 --- a/drivers/char/hvc_xen.c +++ b/drivers/char/hvc_xen.c | |||
@@ -74,7 +74,8 @@ static int __write_console(const char *data, int len) | |||
74 | wmb(); /* write ring before updating pointer */ | 74 | wmb(); /* write ring before updating pointer */ |
75 | intf->out_prod = prod; | 75 | intf->out_prod = prod; |
76 | 76 | ||
77 | notify_daemon(); | 77 | if (sent) |
78 | notify_daemon(); | ||
78 | return sent; | 79 | return sent; |
79 | } | 80 | } |
80 | 81 | ||
diff --git a/drivers/xen/events.c b/drivers/xen/events.c index 7d24b0d94ed4..347f17edad77 100644 --- a/drivers/xen/events.c +++ b/drivers/xen/events.c | |||
@@ -261,7 +261,7 @@ static void init_evtchn_cpu_bindings(void) | |||
261 | } | 261 | } |
262 | #endif | 262 | #endif |
263 | 263 | ||
264 | memset(cpu_evtchn_mask(0), ~0, sizeof(cpu_evtchn_mask(0))); | 264 | memset(cpu_evtchn_mask(0), ~0, sizeof(struct cpu_evtchn_s)); |
265 | } | 265 | } |
266 | 266 | ||
267 | static inline void clear_evtchn(int port) | 267 | static inline void clear_evtchn(int port) |
@@ -377,7 +377,7 @@ int bind_evtchn_to_irq(unsigned int evtchn) | |||
377 | irq = find_unbound_irq(); | 377 | irq = find_unbound_irq(); |
378 | 378 | ||
379 | set_irq_chip_and_handler_name(irq, &xen_dynamic_chip, | 379 | set_irq_chip_and_handler_name(irq, &xen_dynamic_chip, |
380 | handle_edge_irq, "event"); | 380 | handle_fasteoi_irq, "event"); |
381 | 381 | ||
382 | evtchn_to_irq[evtchn] = irq; | 382 | evtchn_to_irq[evtchn] = irq; |
383 | irq_info[irq] = mk_evtchn_info(evtchn); | 383 | irq_info[irq] = mk_evtchn_info(evtchn); |
@@ -435,6 +435,11 @@ static int bind_virq_to_irq(unsigned int virq, unsigned int cpu) | |||
435 | irq = per_cpu(virq_to_irq, cpu)[virq]; | 435 | irq = per_cpu(virq_to_irq, cpu)[virq]; |
436 | 436 | ||
437 | if (irq == -1) { | 437 | if (irq == -1) { |
438 | irq = find_unbound_irq(); | ||
439 | |||
440 | set_irq_chip_and_handler_name(irq, &xen_percpu_chip, | ||
441 | handle_percpu_irq, "virq"); | ||
442 | |||
438 | bind_virq.virq = virq; | 443 | bind_virq.virq = virq; |
439 | bind_virq.vcpu = cpu; | 444 | bind_virq.vcpu = cpu; |
440 | if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, | 445 | if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, |
@@ -442,11 +447,6 @@ static int bind_virq_to_irq(unsigned int virq, unsigned int cpu) | |||
442 | BUG(); | 447 | BUG(); |
443 | evtchn = bind_virq.port; | 448 | evtchn = bind_virq.port; |
444 | 449 | ||
445 | irq = find_unbound_irq(); | ||
446 | |||
447 | set_irq_chip_and_handler_name(irq, &xen_percpu_chip, | ||
448 | handle_percpu_irq, "virq"); | ||
449 | |||
450 | evtchn_to_irq[evtchn] = irq; | 450 | evtchn_to_irq[evtchn] = irq; |
451 | irq_info[irq] = mk_virq_info(evtchn, virq); | 451 | irq_info[irq] = mk_virq_info(evtchn, virq); |
452 | 452 | ||
@@ -578,41 +578,75 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id) | |||
578 | { | 578 | { |
579 | struct shared_info *sh = HYPERVISOR_shared_info; | 579 | struct shared_info *sh = HYPERVISOR_shared_info; |
580 | int cpu = smp_processor_id(); | 580 | int cpu = smp_processor_id(); |
581 | unsigned long *cpu_evtchn = cpu_evtchn_mask(cpu); | ||
581 | int i; | 582 | int i; |
582 | unsigned long flags; | 583 | unsigned long flags; |
583 | static DEFINE_SPINLOCK(debug_lock); | 584 | static DEFINE_SPINLOCK(debug_lock); |
585 | struct vcpu_info *v; | ||
584 | 586 | ||
585 | spin_lock_irqsave(&debug_lock, flags); | 587 | spin_lock_irqsave(&debug_lock, flags); |
586 | 588 | ||
587 | printk("vcpu %d\n ", cpu); | 589 | printk("\nvcpu %d\n ", cpu); |
588 | 590 | ||
589 | for_each_online_cpu(i) { | 591 | for_each_online_cpu(i) { |
590 | struct vcpu_info *v = per_cpu(xen_vcpu, i); | 592 | int pending; |
591 | printk("%d: masked=%d pending=%d event_sel %08lx\n ", i, | 593 | v = per_cpu(xen_vcpu, i); |
592 | (get_irq_regs() && i == cpu) ? xen_irqs_disabled(get_irq_regs()) : v->evtchn_upcall_mask, | 594 | pending = (get_irq_regs() && i == cpu) |
593 | v->evtchn_upcall_pending, | 595 | ? xen_irqs_disabled(get_irq_regs()) |
594 | v->evtchn_pending_sel); | 596 | : v->evtchn_upcall_mask; |
597 | printk("%d: masked=%d pending=%d event_sel %0*lx\n ", i, | ||
598 | pending, v->evtchn_upcall_pending, | ||
599 | (int)(sizeof(v->evtchn_pending_sel)*2), | ||
600 | v->evtchn_pending_sel); | ||
601 | } | ||
602 | v = per_cpu(xen_vcpu, cpu); | ||
603 | |||
604 | printk("\npending:\n "); | ||
605 | for (i = ARRAY_SIZE(sh->evtchn_pending)-1; i >= 0; i--) | ||
606 | printk("%0*lx%s", (int)sizeof(sh->evtchn_pending[0])*2, | ||
607 | sh->evtchn_pending[i], | ||
608 | i % 8 == 0 ? "\n " : " "); | ||
609 | printk("\nglobal mask:\n "); | ||
610 | for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) | ||
611 | printk("%0*lx%s", | ||
612 | (int)(sizeof(sh->evtchn_mask[0])*2), | ||
613 | sh->evtchn_mask[i], | ||
614 | i % 8 == 0 ? "\n " : " "); | ||
615 | |||
616 | printk("\nglobally unmasked:\n "); | ||
617 | for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) | ||
618 | printk("%0*lx%s", (int)(sizeof(sh->evtchn_mask[0])*2), | ||
619 | sh->evtchn_pending[i] & ~sh->evtchn_mask[i], | ||
620 | i % 8 == 0 ? "\n " : " "); | ||
621 | |||
622 | printk("\nlocal cpu%d mask:\n ", cpu); | ||
623 | for (i = (NR_EVENT_CHANNELS/BITS_PER_LONG)-1; i >= 0; i--) | ||
624 | printk("%0*lx%s", (int)(sizeof(cpu_evtchn[0])*2), | ||
625 | cpu_evtchn[i], | ||
626 | i % 8 == 0 ? "\n " : " "); | ||
627 | |||
628 | printk("\nlocally unmasked:\n "); | ||
629 | for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) { | ||
630 | unsigned long pending = sh->evtchn_pending[i] | ||
631 | & ~sh->evtchn_mask[i] | ||
632 | & cpu_evtchn[i]; | ||
633 | printk("%0*lx%s", (int)(sizeof(sh->evtchn_mask[0])*2), | ||
634 | pending, i % 8 == 0 ? "\n " : " "); | ||
595 | } | 635 | } |
596 | printk("pending:\n "); | ||
597 | for(i = ARRAY_SIZE(sh->evtchn_pending)-1; i >= 0; i--) | ||
598 | printk("%08lx%s", sh->evtchn_pending[i], | ||
599 | i % 8 == 0 ? "\n " : " "); | ||
600 | printk("\nmasks:\n "); | ||
601 | for(i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) | ||
602 | printk("%08lx%s", sh->evtchn_mask[i], | ||
603 | i % 8 == 0 ? "\n " : " "); | ||
604 | |||
605 | printk("\nunmasked:\n "); | ||
606 | for(i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) | ||
607 | printk("%08lx%s", sh->evtchn_pending[i] & ~sh->evtchn_mask[i], | ||
608 | i % 8 == 0 ? "\n " : " "); | ||
609 | 636 | ||
610 | printk("\npending list:\n"); | 637 | printk("\npending list:\n"); |
611 | for(i = 0; i < NR_EVENT_CHANNELS; i++) { | 638 | for (i = 0; i < NR_EVENT_CHANNELS; i++) { |
612 | if (sync_test_bit(i, sh->evtchn_pending)) { | 639 | if (sync_test_bit(i, sh->evtchn_pending)) { |
613 | printk(" %d: event %d -> irq %d\n", | 640 | int word_idx = i / BITS_PER_LONG; |
641 | printk(" %d: event %d -> irq %d%s%s%s\n", | ||
614 | cpu_from_evtchn(i), i, | 642 | cpu_from_evtchn(i), i, |
615 | evtchn_to_irq[i]); | 643 | evtchn_to_irq[i], |
644 | sync_test_bit(word_idx, &v->evtchn_pending_sel) | ||
645 | ? "" : " l2-clear", | ||
646 | !sync_test_bit(i, sh->evtchn_mask) | ||
647 | ? "" : " globally-masked", | ||
648 | sync_test_bit(i, cpu_evtchn) | ||
649 | ? "" : " locally-masked"); | ||
616 | } | 650 | } |
617 | } | 651 | } |
618 | 652 | ||
@@ -663,6 +697,9 @@ static void __xen_evtchn_do_upcall(void) | |||
663 | int irq = evtchn_to_irq[port]; | 697 | int irq = evtchn_to_irq[port]; |
664 | struct irq_desc *desc; | 698 | struct irq_desc *desc; |
665 | 699 | ||
700 | mask_evtchn(port); | ||
701 | clear_evtchn(port); | ||
702 | |||
666 | if (irq != -1) { | 703 | if (irq != -1) { |
667 | desc = irq_to_desc(irq); | 704 | desc = irq_to_desc(irq); |
668 | if (desc) | 705 | if (desc) |
@@ -800,10 +837,10 @@ static void ack_dynirq(unsigned int irq) | |||
800 | { | 837 | { |
801 | int evtchn = evtchn_from_irq(irq); | 838 | int evtchn = evtchn_from_irq(irq); |
802 | 839 | ||
803 | move_native_irq(irq); | 840 | move_masked_irq(irq); |
804 | 841 | ||
805 | if (VALID_EVTCHN(evtchn)) | 842 | if (VALID_EVTCHN(evtchn)) |
806 | clear_evtchn(evtchn); | 843 | unmask_evtchn(evtchn); |
807 | } | 844 | } |
808 | 845 | ||
809 | static int retrigger_dynirq(unsigned int irq) | 846 | static int retrigger_dynirq(unsigned int irq) |
@@ -959,7 +996,7 @@ static struct irq_chip xen_dynamic_chip __read_mostly = { | |||
959 | .mask = disable_dynirq, | 996 | .mask = disable_dynirq, |
960 | .unmask = enable_dynirq, | 997 | .unmask = enable_dynirq, |
961 | 998 | ||
962 | .ack = ack_dynirq, | 999 | .eoi = ack_dynirq, |
963 | .set_affinity = set_affinity_irq, | 1000 | .set_affinity = set_affinity_irq, |
964 | .retrigger = retrigger_dynirq, | 1001 | .retrigger = retrigger_dynirq, |
965 | }; | 1002 | }; |
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c index d409495876f1..132939f36020 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c | |||
@@ -64,9 +64,11 @@ | |||
64 | 64 | ||
65 | 65 | ||
66 | int xen_store_evtchn; | 66 | int xen_store_evtchn; |
67 | EXPORT_SYMBOL(xen_store_evtchn); | 67 | EXPORT_SYMBOL_GPL(xen_store_evtchn); |
68 | 68 | ||
69 | struct xenstore_domain_interface *xen_store_interface; | 69 | struct xenstore_domain_interface *xen_store_interface; |
70 | EXPORT_SYMBOL_GPL(xen_store_interface); | ||
71 | |||
70 | static unsigned long xen_store_mfn; | 72 | static unsigned long xen_store_mfn; |
71 | 73 | ||
72 | static BLOCKING_NOTIFIER_HEAD(xenstore_chain); | 74 | static BLOCKING_NOTIFIER_HEAD(xenstore_chain); |
diff --git a/drivers/xen/xenfs/Makefile b/drivers/xen/xenfs/Makefile index 25275c3bbdff..4fde9440fe1f 100644 --- a/drivers/xen/xenfs/Makefile +++ b/drivers/xen/xenfs/Makefile | |||
@@ -1,3 +1,4 @@ | |||
1 | obj-$(CONFIG_XENFS) += xenfs.o | 1 | obj-$(CONFIG_XENFS) += xenfs.o |
2 | 2 | ||
3 | xenfs-objs = super.o xenbus.o \ No newline at end of file | 3 | xenfs-y = super.o xenbus.o privcmd.o |
4 | xenfs-$(CONFIG_XEN_DOM0) += xenstored.o | ||
diff --git a/drivers/xen/xenfs/privcmd.c b/drivers/xen/xenfs/privcmd.c new file mode 100644 index 000000000000..f80be7f6eb95 --- /dev/null +++ b/drivers/xen/xenfs/privcmd.c | |||
@@ -0,0 +1,404 @@ | |||
1 | /****************************************************************************** | ||
2 | * privcmd.c | ||
3 | * | ||
4 | * Interface to privileged domain-0 commands. | ||
5 | * | ||
6 | * Copyright (c) 2002-2004, K A Fraser, B Dragovic | ||
7 | */ | ||
8 | |||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/sched.h> | ||
11 | #include <linux/slab.h> | ||
12 | #include <linux/string.h> | ||
13 | #include <linux/errno.h> | ||
14 | #include <linux/mm.h> | ||
15 | #include <linux/mman.h> | ||
16 | #include <linux/uaccess.h> | ||
17 | #include <linux/swap.h> | ||
18 | #include <linux/smp_lock.h> | ||
19 | #include <linux/highmem.h> | ||
20 | #include <linux/pagemap.h> | ||
21 | #include <linux/seq_file.h> | ||
22 | |||
23 | #include <asm/pgalloc.h> | ||
24 | #include <asm/pgtable.h> | ||
25 | #include <asm/tlb.h> | ||
26 | #include <asm/xen/hypervisor.h> | ||
27 | #include <asm/xen/hypercall.h> | ||
28 | |||
29 | #include <xen/xen.h> | ||
30 | #include <xen/privcmd.h> | ||
31 | #include <xen/interface/xen.h> | ||
32 | #include <xen/features.h> | ||
33 | #include <xen/page.h> | ||
34 | #include <xen/xen-ops.h> | ||
35 | |||
36 | #ifndef HAVE_ARCH_PRIVCMD_MMAP | ||
37 | static int privcmd_enforce_singleshot_mapping(struct vm_area_struct *vma); | ||
38 | #endif | ||
39 | |||
40 | static long privcmd_ioctl_hypercall(void __user *udata) | ||
41 | { | ||
42 | struct privcmd_hypercall hypercall; | ||
43 | long ret; | ||
44 | |||
45 | if (copy_from_user(&hypercall, udata, sizeof(hypercall))) | ||
46 | return -EFAULT; | ||
47 | |||
48 | ret = privcmd_call(hypercall.op, | ||
49 | hypercall.arg[0], hypercall.arg[1], | ||
50 | hypercall.arg[2], hypercall.arg[3], | ||
51 | hypercall.arg[4]); | ||
52 | |||
53 | return ret; | ||
54 | } | ||
55 | |||
56 | static void free_page_list(struct list_head *pages) | ||
57 | { | ||
58 | struct page *p, *n; | ||
59 | |||
60 | list_for_each_entry_safe(p, n, pages, lru) | ||
61 | __free_page(p); | ||
62 | |||
63 | INIT_LIST_HEAD(pages); | ||
64 | } | ||
65 | |||
66 | /* | ||
67 | * Given an array of items in userspace, return a list of pages | ||
68 | * containing the data. If copying fails, either because of memory | ||
69 | * allocation failure or a problem reading user memory, return an | ||
70 | * error code; its up to the caller to dispose of any partial list. | ||
71 | */ | ||
72 | static int gather_array(struct list_head *pagelist, | ||
73 | unsigned nelem, size_t size, | ||
74 | void __user *data) | ||
75 | { | ||
76 | unsigned pageidx; | ||
77 | void *pagedata; | ||
78 | int ret; | ||
79 | |||
80 | if (size > PAGE_SIZE) | ||
81 | return 0; | ||
82 | |||
83 | pageidx = PAGE_SIZE; | ||
84 | pagedata = NULL; /* quiet, gcc */ | ||
85 | while (nelem--) { | ||
86 | if (pageidx > PAGE_SIZE-size) { | ||
87 | struct page *page = alloc_page(GFP_KERNEL); | ||
88 | |||
89 | ret = -ENOMEM; | ||
90 | if (page == NULL) | ||
91 | goto fail; | ||
92 | |||
93 | pagedata = page_address(page); | ||
94 | |||
95 | list_add_tail(&page->lru, pagelist); | ||
96 | pageidx = 0; | ||
97 | } | ||
98 | |||
99 | ret = -EFAULT; | ||
100 | if (copy_from_user(pagedata + pageidx, data, size)) | ||
101 | goto fail; | ||
102 | |||
103 | data += size; | ||
104 | pageidx += size; | ||
105 | } | ||
106 | |||
107 | ret = 0; | ||
108 | |||
109 | fail: | ||
110 | return ret; | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * Call function "fn" on each element of the array fragmented | ||
115 | * over a list of pages. | ||
116 | */ | ||
117 | static int traverse_pages(unsigned nelem, size_t size, | ||
118 | struct list_head *pos, | ||
119 | int (*fn)(void *data, void *state), | ||
120 | void *state) | ||
121 | { | ||
122 | void *pagedata; | ||
123 | unsigned pageidx; | ||
124 | int ret = 0; | ||
125 | |||
126 | BUG_ON(size > PAGE_SIZE); | ||
127 | |||
128 | pageidx = PAGE_SIZE; | ||
129 | pagedata = NULL; /* hush, gcc */ | ||
130 | |||
131 | while (nelem--) { | ||
132 | if (pageidx > PAGE_SIZE-size) { | ||
133 | struct page *page; | ||
134 | pos = pos->next; | ||
135 | page = list_entry(pos, struct page, lru); | ||
136 | pagedata = page_address(page); | ||
137 | pageidx = 0; | ||
138 | } | ||
139 | |||
140 | ret = (*fn)(pagedata + pageidx, state); | ||
141 | if (ret) | ||
142 | break; | ||
143 | pageidx += size; | ||
144 | } | ||
145 | |||
146 | return ret; | ||
147 | } | ||
148 | |||
149 | struct mmap_mfn_state { | ||
150 | unsigned long va; | ||
151 | struct vm_area_struct *vma; | ||
152 | domid_t domain; | ||
153 | }; | ||
154 | |||
155 | static int mmap_mfn_range(void *data, void *state) | ||
156 | { | ||
157 | struct privcmd_mmap_entry *msg = data; | ||
158 | struct mmap_mfn_state *st = state; | ||
159 | struct vm_area_struct *vma = st->vma; | ||
160 | int rc; | ||
161 | |||
162 | /* Do not allow range to wrap the address space. */ | ||
163 | if ((msg->npages > (LONG_MAX >> PAGE_SHIFT)) || | ||
164 | ((unsigned long)(msg->npages << PAGE_SHIFT) >= -st->va)) | ||
165 | return -EINVAL; | ||
166 | |||
167 | /* Range chunks must be contiguous in va space. */ | ||
168 | if ((msg->va != st->va) || | ||
169 | ((msg->va+(msg->npages<<PAGE_SHIFT)) > vma->vm_end)) | ||
170 | return -EINVAL; | ||
171 | |||
172 | rc = xen_remap_domain_mfn_range(vma, | ||
173 | msg->va & PAGE_MASK, | ||
174 | msg->mfn, msg->npages, | ||
175 | vma->vm_page_prot, | ||
176 | st->domain); | ||
177 | if (rc < 0) | ||
178 | return rc; | ||
179 | |||
180 | st->va += msg->npages << PAGE_SHIFT; | ||
181 | |||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | static long privcmd_ioctl_mmap(void __user *udata) | ||
186 | { | ||
187 | struct privcmd_mmap mmapcmd; | ||
188 | struct mm_struct *mm = current->mm; | ||
189 | struct vm_area_struct *vma; | ||
190 | int rc; | ||
191 | LIST_HEAD(pagelist); | ||
192 | struct mmap_mfn_state state; | ||
193 | |||
194 | if (!xen_initial_domain()) | ||
195 | return -EPERM; | ||
196 | |||
197 | if (copy_from_user(&mmapcmd, udata, sizeof(mmapcmd))) | ||
198 | return -EFAULT; | ||
199 | |||
200 | rc = gather_array(&pagelist, | ||
201 | mmapcmd.num, sizeof(struct privcmd_mmap_entry), | ||
202 | mmapcmd.entry); | ||
203 | |||
204 | if (rc || list_empty(&pagelist)) | ||
205 | goto out; | ||
206 | |||
207 | down_write(&mm->mmap_sem); | ||
208 | |||
209 | { | ||
210 | struct page *page = list_first_entry(&pagelist, | ||
211 | struct page, lru); | ||
212 | struct privcmd_mmap_entry *msg = page_address(page); | ||
213 | |||
214 | vma = find_vma(mm, msg->va); | ||
215 | rc = -EINVAL; | ||
216 | |||
217 | if (!vma || (msg->va != vma->vm_start) || | ||
218 | !privcmd_enforce_singleshot_mapping(vma)) | ||
219 | goto out_up; | ||
220 | } | ||
221 | |||
222 | state.va = vma->vm_start; | ||
223 | state.vma = vma; | ||
224 | state.domain = mmapcmd.dom; | ||
225 | |||
226 | rc = traverse_pages(mmapcmd.num, sizeof(struct privcmd_mmap_entry), | ||
227 | &pagelist, | ||
228 | mmap_mfn_range, &state); | ||
229 | |||
230 | |||
231 | out_up: | ||
232 | up_write(&mm->mmap_sem); | ||
233 | |||
234 | out: | ||
235 | free_page_list(&pagelist); | ||
236 | |||
237 | return rc; | ||
238 | } | ||
239 | |||
240 | struct mmap_batch_state { | ||
241 | domid_t domain; | ||
242 | unsigned long va; | ||
243 | struct vm_area_struct *vma; | ||
244 | int err; | ||
245 | |||
246 | xen_pfn_t __user *user; | ||
247 | }; | ||
248 | |||
249 | static int mmap_batch_fn(void *data, void *state) | ||
250 | { | ||
251 | xen_pfn_t *mfnp = data; | ||
252 | struct mmap_batch_state *st = state; | ||
253 | |||
254 | if (xen_remap_domain_mfn_range(st->vma, st->va & PAGE_MASK, *mfnp, 1, | ||
255 | st->vma->vm_page_prot, st->domain) < 0) { | ||
256 | *mfnp |= 0xf0000000U; | ||
257 | st->err++; | ||
258 | } | ||
259 | st->va += PAGE_SIZE; | ||
260 | |||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | static int mmap_return_errors(void *data, void *state) | ||
265 | { | ||
266 | xen_pfn_t *mfnp = data; | ||
267 | struct mmap_batch_state *st = state; | ||
268 | |||
269 | put_user(*mfnp, st->user++); | ||
270 | |||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | static struct vm_operations_struct privcmd_vm_ops; | ||
275 | |||
276 | static long privcmd_ioctl_mmap_batch(void __user *udata) | ||
277 | { | ||
278 | int ret; | ||
279 | struct privcmd_mmapbatch m; | ||
280 | struct mm_struct *mm = current->mm; | ||
281 | struct vm_area_struct *vma; | ||
282 | unsigned long nr_pages; | ||
283 | LIST_HEAD(pagelist); | ||
284 | struct mmap_batch_state state; | ||
285 | |||
286 | if (!xen_initial_domain()) | ||
287 | return -EPERM; | ||
288 | |||
289 | if (copy_from_user(&m, udata, sizeof(m))) | ||
290 | return -EFAULT; | ||
291 | |||
292 | nr_pages = m.num; | ||
293 | if ((m.num <= 0) || (nr_pages > (LONG_MAX >> PAGE_SHIFT))) | ||
294 | return -EINVAL; | ||
295 | |||
296 | ret = gather_array(&pagelist, m.num, sizeof(xen_pfn_t), | ||
297 | m.arr); | ||
298 | |||
299 | if (ret || list_empty(&pagelist)) | ||
300 | goto out; | ||
301 | |||
302 | down_write(&mm->mmap_sem); | ||
303 | |||
304 | vma = find_vma(mm, m.addr); | ||
305 | ret = -EINVAL; | ||
306 | if (!vma || | ||
307 | vma->vm_ops != &privcmd_vm_ops || | ||
308 | (m.addr != vma->vm_start) || | ||
309 | ((m.addr + (nr_pages << PAGE_SHIFT)) != vma->vm_end) || | ||
310 | !privcmd_enforce_singleshot_mapping(vma)) { | ||
311 | up_write(&mm->mmap_sem); | ||
312 | goto out; | ||
313 | } | ||
314 | |||
315 | state.domain = m.dom; | ||
316 | state.vma = vma; | ||
317 | state.va = m.addr; | ||
318 | state.err = 0; | ||
319 | |||
320 | ret = traverse_pages(m.num, sizeof(xen_pfn_t), | ||
321 | &pagelist, mmap_batch_fn, &state); | ||
322 | |||
323 | up_write(&mm->mmap_sem); | ||
324 | |||
325 | if (state.err > 0) { | ||
326 | ret = 0; | ||
327 | |||
328 | state.user = m.arr; | ||
329 | traverse_pages(m.num, sizeof(xen_pfn_t), | ||
330 | &pagelist, | ||
331 | mmap_return_errors, &state); | ||
332 | } | ||
333 | |||
334 | out: | ||
335 | free_page_list(&pagelist); | ||
336 | |||
337 | return ret; | ||
338 | } | ||
339 | |||
340 | static long privcmd_ioctl(struct file *file, | ||
341 | unsigned int cmd, unsigned long data) | ||
342 | { | ||
343 | int ret = -ENOSYS; | ||
344 | void __user *udata = (void __user *) data; | ||
345 | |||
346 | switch (cmd) { | ||
347 | case IOCTL_PRIVCMD_HYPERCALL: | ||
348 | ret = privcmd_ioctl_hypercall(udata); | ||
349 | break; | ||
350 | |||
351 | case IOCTL_PRIVCMD_MMAP: | ||
352 | ret = privcmd_ioctl_mmap(udata); | ||
353 | break; | ||
354 | |||
355 | case IOCTL_PRIVCMD_MMAPBATCH: | ||
356 | ret = privcmd_ioctl_mmap_batch(udata); | ||
357 | break; | ||
358 | |||
359 | default: | ||
360 | ret = -EINVAL; | ||
361 | break; | ||
362 | } | ||
363 | |||
364 | return ret; | ||
365 | } | ||
366 | |||
367 | #ifndef HAVE_ARCH_PRIVCMD_MMAP | ||
368 | static int privcmd_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | ||
369 | { | ||
370 | printk(KERN_DEBUG "privcmd_fault: vma=%p %lx-%lx, pgoff=%lx, uv=%p\n", | ||
371 | vma, vma->vm_start, vma->vm_end, | ||
372 | vmf->pgoff, vmf->virtual_address); | ||
373 | |||
374 | return VM_FAULT_SIGBUS; | ||
375 | } | ||
376 | |||
377 | static struct vm_operations_struct privcmd_vm_ops = { | ||
378 | .fault = privcmd_fault | ||
379 | }; | ||
380 | |||
381 | static int privcmd_mmap(struct file *file, struct vm_area_struct *vma) | ||
382 | { | ||
383 | /* Unsupported for auto-translate guests. */ | ||
384 | if (xen_feature(XENFEAT_auto_translated_physmap)) | ||
385 | return -ENOSYS; | ||
386 | |||
387 | /* DONTCOPY is essential for Xen as copy_page_range is broken. */ | ||
388 | vma->vm_flags |= VM_RESERVED | VM_IO | VM_DONTCOPY; | ||
389 | vma->vm_ops = &privcmd_vm_ops; | ||
390 | vma->vm_private_data = NULL; | ||
391 | |||
392 | return 0; | ||
393 | } | ||
394 | |||
395 | static int privcmd_enforce_singleshot_mapping(struct vm_area_struct *vma) | ||
396 | { | ||
397 | return (xchg(&vma->vm_private_data, (void *)1) == NULL); | ||
398 | } | ||
399 | #endif | ||
400 | |||
401 | const struct file_operations privcmd_file_ops = { | ||
402 | .unlocked_ioctl = privcmd_ioctl, | ||
403 | .mmap = privcmd_mmap, | ||
404 | }; | ||
diff --git a/drivers/xen/xenfs/super.c b/drivers/xen/xenfs/super.c index bd96340063c1..d6662b789b6b 100644 --- a/drivers/xen/xenfs/super.c +++ b/drivers/xen/xenfs/super.c | |||
@@ -12,6 +12,8 @@ | |||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/fs.h> | 13 | #include <linux/fs.h> |
14 | #include <linux/magic.h> | 14 | #include <linux/magic.h> |
15 | #include <linux/mm.h> | ||
16 | #include <linux/backing-dev.h> | ||
15 | 17 | ||
16 | #include <xen/xen.h> | 18 | #include <xen/xen.h> |
17 | 19 | ||
@@ -22,6 +24,62 @@ | |||
22 | MODULE_DESCRIPTION("Xen filesystem"); | 24 | MODULE_DESCRIPTION("Xen filesystem"); |
23 | MODULE_LICENSE("GPL"); | 25 | MODULE_LICENSE("GPL"); |
24 | 26 | ||
27 | static int xenfs_set_page_dirty(struct page *page) | ||
28 | { | ||
29 | return !TestSetPageDirty(page); | ||
30 | } | ||
31 | |||
32 | static const struct address_space_operations xenfs_aops = { | ||
33 | .set_page_dirty = xenfs_set_page_dirty, | ||
34 | }; | ||
35 | |||
36 | static struct backing_dev_info xenfs_backing_dev_info = { | ||
37 | .ra_pages = 0, /* No readahead */ | ||
38 | .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK, | ||
39 | }; | ||
40 | |||
41 | static struct inode *xenfs_make_inode(struct super_block *sb, int mode) | ||
42 | { | ||
43 | struct inode *ret = new_inode(sb); | ||
44 | |||
45 | if (ret) { | ||
46 | ret->i_mode = mode; | ||
47 | ret->i_mapping->a_ops = &xenfs_aops; | ||
48 | ret->i_mapping->backing_dev_info = &xenfs_backing_dev_info; | ||
49 | ret->i_uid = ret->i_gid = 0; | ||
50 | ret->i_blocks = 0; | ||
51 | ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME; | ||
52 | } | ||
53 | return ret; | ||
54 | } | ||
55 | |||
56 | static struct dentry *xenfs_create_file(struct super_block *sb, | ||
57 | struct dentry *parent, | ||
58 | const char *name, | ||
59 | const struct file_operations *fops, | ||
60 | void *data, | ||
61 | int mode) | ||
62 | { | ||
63 | struct dentry *dentry; | ||
64 | struct inode *inode; | ||
65 | |||
66 | dentry = d_alloc_name(parent, name); | ||
67 | if (!dentry) | ||
68 | return NULL; | ||
69 | |||
70 | inode = xenfs_make_inode(sb, S_IFREG | mode); | ||
71 | if (!inode) { | ||
72 | dput(dentry); | ||
73 | return NULL; | ||
74 | } | ||
75 | |||
76 | inode->i_fop = fops; | ||
77 | inode->i_private = data; | ||
78 | |||
79 | d_add(dentry, inode); | ||
80 | return dentry; | ||
81 | } | ||
82 | |||
25 | static ssize_t capabilities_read(struct file *file, char __user *buf, | 83 | static ssize_t capabilities_read(struct file *file, char __user *buf, |
26 | size_t size, loff_t *off) | 84 | size_t size, loff_t *off) |
27 | { | 85 | { |
@@ -44,10 +102,23 @@ static int xenfs_fill_super(struct super_block *sb, void *data, int silent) | |||
44 | [1] = {}, | 102 | [1] = {}, |
45 | { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR }, | 103 | { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR }, |
46 | { "capabilities", &capabilities_file_ops, S_IRUGO }, | 104 | { "capabilities", &capabilities_file_ops, S_IRUGO }, |
105 | { "privcmd", &privcmd_file_ops, S_IRUSR|S_IWUSR }, | ||
47 | {""}, | 106 | {""}, |
48 | }; | 107 | }; |
108 | int rc; | ||
49 | 109 | ||
50 | return simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files); | 110 | rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files); |
111 | if (rc < 0) | ||
112 | return rc; | ||
113 | |||
114 | if (xen_initial_domain()) { | ||
115 | xenfs_create_file(sb, sb->s_root, "xsd_kva", | ||
116 | &xsd_kva_file_ops, NULL, S_IRUSR|S_IWUSR); | ||
117 | xenfs_create_file(sb, sb->s_root, "xsd_port", | ||
118 | &xsd_port_file_ops, NULL, S_IRUSR|S_IWUSR); | ||
119 | } | ||
120 | |||
121 | return rc; | ||
51 | } | 122 | } |
52 | 123 | ||
53 | static int xenfs_get_sb(struct file_system_type *fs_type, | 124 | static int xenfs_get_sb(struct file_system_type *fs_type, |
@@ -66,11 +137,25 @@ static struct file_system_type xenfs_type = { | |||
66 | 137 | ||
67 | static int __init xenfs_init(void) | 138 | static int __init xenfs_init(void) |
68 | { | 139 | { |
69 | if (xen_domain()) | 140 | int err; |
70 | return register_filesystem(&xenfs_type); | 141 | if (!xen_domain()) { |
142 | printk(KERN_INFO "xenfs: not registering filesystem on non-xen platform\n"); | ||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | err = register_filesystem(&xenfs_type); | ||
147 | if (err) { | ||
148 | printk(KERN_ERR "xenfs: Unable to register filesystem!\n"); | ||
149 | goto out; | ||
150 | } | ||
151 | |||
152 | err = bdi_init(&xenfs_backing_dev_info); | ||
153 | if (err) | ||
154 | unregister_filesystem(&xenfs_type); | ||
155 | |||
156 | out: | ||
71 | 157 | ||
72 | printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n"); | 158 | return err; |
73 | return 0; | ||
74 | } | 159 | } |
75 | 160 | ||
76 | static void __exit xenfs_exit(void) | 161 | static void __exit xenfs_exit(void) |
diff --git a/drivers/xen/xenfs/xenfs.h b/drivers/xen/xenfs/xenfs.h index 51f08b2d0bf1..b68aa6200003 100644 --- a/drivers/xen/xenfs/xenfs.h +++ b/drivers/xen/xenfs/xenfs.h | |||
@@ -2,5 +2,8 @@ | |||
2 | #define _XENFS_XENBUS_H | 2 | #define _XENFS_XENBUS_H |
3 | 3 | ||
4 | extern const struct file_operations xenbus_file_ops; | 4 | extern const struct file_operations xenbus_file_ops; |
5 | extern const struct file_operations privcmd_file_ops; | ||
6 | extern const struct file_operations xsd_kva_file_ops; | ||
7 | extern const struct file_operations xsd_port_file_ops; | ||
5 | 8 | ||
6 | #endif /* _XENFS_XENBUS_H */ | 9 | #endif /* _XENFS_XENBUS_H */ |
diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c new file mode 100644 index 000000000000..fef20dbc6a5c --- /dev/null +++ b/drivers/xen/xenfs/xenstored.c | |||
@@ -0,0 +1,68 @@ | |||
1 | #include <linux/slab.h> | ||
2 | #include <linux/types.h> | ||
3 | #include <linux/mm.h> | ||
4 | #include <linux/fs.h> | ||
5 | |||
6 | #include <xen/page.h> | ||
7 | |||
8 | #include "xenfs.h" | ||
9 | #include "../xenbus/xenbus_comms.h" | ||
10 | |||
11 | static ssize_t xsd_read(struct file *file, char __user *buf, | ||
12 | size_t size, loff_t *off) | ||
13 | { | ||
14 | const char *str = (const char *)file->private_data; | ||
15 | return simple_read_from_buffer(buf, size, off, str, strlen(str)); | ||
16 | } | ||
17 | |||
18 | static int xsd_release(struct inode *inode, struct file *file) | ||
19 | { | ||
20 | kfree(file->private_data); | ||
21 | return 0; | ||
22 | } | ||
23 | |||
24 | static int xsd_kva_open(struct inode *inode, struct file *file) | ||
25 | { | ||
26 | file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p", | ||
27 | xen_store_interface); | ||
28 | if (!file->private_data) | ||
29 | return -ENOMEM; | ||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma) | ||
34 | { | ||
35 | size_t size = vma->vm_end - vma->vm_start; | ||
36 | |||
37 | if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0)) | ||
38 | return -EINVAL; | ||
39 | |||
40 | if (remap_pfn_range(vma, vma->vm_start, | ||
41 | virt_to_pfn(xen_store_interface), | ||
42 | size, vma->vm_page_prot)) | ||
43 | return -EAGAIN; | ||
44 | |||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | const struct file_operations xsd_kva_file_ops = { | ||
49 | .open = xsd_kva_open, | ||
50 | .mmap = xsd_kva_mmap, | ||
51 | .read = xsd_read, | ||
52 | .release = xsd_release, | ||
53 | }; | ||
54 | |||
55 | static int xsd_port_open(struct inode *inode, struct file *file) | ||
56 | { | ||
57 | file->private_data = (void *)kasprintf(GFP_KERNEL, "%d", | ||
58 | xen_store_evtchn); | ||
59 | if (!file->private_data) | ||
60 | return -ENOMEM; | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | const struct file_operations xsd_port_file_ops = { | ||
65 | .open = xsd_port_open, | ||
66 | .read = xsd_read, | ||
67 | .release = xsd_release, | ||
68 | }; | ||
diff --git a/include/xen/Kbuild b/include/xen/Kbuild index 4e65c16a445b..84ad8f02fee5 100644 --- a/include/xen/Kbuild +++ b/include/xen/Kbuild | |||
@@ -1 +1,2 @@ | |||
1 | header-y += evtchn.h | 1 | header-y += evtchn.h |
2 | header-y += privcmd.h | ||
diff --git a/include/xen/interface/memory.h b/include/xen/interface/memory.h index d3938d3e71f8..d7a6c13bde69 100644 --- a/include/xen/interface/memory.h +++ b/include/xen/interface/memory.h | |||
@@ -186,6 +186,35 @@ struct xen_translate_gpfn_list { | |||
186 | }; | 186 | }; |
187 | DEFINE_GUEST_HANDLE_STRUCT(xen_translate_gpfn_list); | 187 | DEFINE_GUEST_HANDLE_STRUCT(xen_translate_gpfn_list); |
188 | 188 | ||
189 | /* | ||
190 | * Returns the pseudo-physical memory map as it was when the domain | ||
191 | * was started (specified by XENMEM_set_memory_map). | ||
192 | * arg == addr of struct xen_memory_map. | ||
193 | */ | ||
194 | #define XENMEM_memory_map 9 | ||
195 | struct xen_memory_map { | ||
196 | /* | ||
197 | * On call the number of entries which can be stored in buffer. On | ||
198 | * return the number of entries which have been stored in | ||
199 | * buffer. | ||
200 | */ | ||
201 | unsigned int nr_entries; | ||
202 | |||
203 | /* | ||
204 | * Entries in the buffer are in the same format as returned by the | ||
205 | * BIOS INT 0x15 EAX=0xE820 call. | ||
206 | */ | ||
207 | GUEST_HANDLE(void) buffer; | ||
208 | }; | ||
209 | DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map); | ||
210 | |||
211 | /* | ||
212 | * Returns the real physical memory map. Passes the same structure as | ||
213 | * XENMEM_memory_map. | ||
214 | * arg == addr of struct xen_memory_map. | ||
215 | */ | ||
216 | #define XENMEM_machine_memory_map 10 | ||
217 | |||
189 | 218 | ||
190 | /* | 219 | /* |
191 | * Prevent the balloon driver from changing the memory reservation | 220 | * Prevent the balloon driver from changing the memory reservation |
diff --git a/include/xen/privcmd.h b/include/xen/privcmd.h new file mode 100644 index 000000000000..b42cdfd92fee --- /dev/null +++ b/include/xen/privcmd.h | |||
@@ -0,0 +1,80 @@ | |||
1 | /****************************************************************************** | ||
2 | * privcmd.h | ||
3 | * | ||
4 | * Interface to /proc/xen/privcmd. | ||
5 | * | ||
6 | * Copyright (c) 2003-2005, K A Fraser | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License version 2 | ||
10 | * as published by the Free Software Foundation; or, when distributed | ||
11 | * separately from the Linux kernel or incorporated into other | ||
12 | * software packages, subject to the following license: | ||
13 | * | ||
14 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
15 | * of this source file (the "Software"), to deal in the Software without | ||
16 | * restriction, including without limitation the rights to use, copy, modify, | ||
17 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
18 | * and to permit persons to whom the Software is furnished to do so, subject to | ||
19 | * the following conditions: | ||
20 | * | ||
21 | * The above copyright notice and this permission notice shall be included in | ||
22 | * all copies or substantial portions of the Software. | ||
23 | * | ||
24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
29 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
30 | * IN THE SOFTWARE. | ||
31 | */ | ||
32 | |||
33 | #ifndef __LINUX_PUBLIC_PRIVCMD_H__ | ||
34 | #define __LINUX_PUBLIC_PRIVCMD_H__ | ||
35 | |||
36 | #include <linux/types.h> | ||
37 | |||
38 | typedef unsigned long xen_pfn_t; | ||
39 | |||
40 | #ifndef __user | ||
41 | #define __user | ||
42 | #endif | ||
43 | |||
44 | struct privcmd_hypercall { | ||
45 | __u64 op; | ||
46 | __u64 arg[5]; | ||
47 | }; | ||
48 | |||
49 | struct privcmd_mmap_entry { | ||
50 | __u64 va; | ||
51 | __u64 mfn; | ||
52 | __u64 npages; | ||
53 | }; | ||
54 | |||
55 | struct privcmd_mmap { | ||
56 | int num; | ||
57 | domid_t dom; /* target domain */ | ||
58 | struct privcmd_mmap_entry __user *entry; | ||
59 | }; | ||
60 | |||
61 | struct privcmd_mmapbatch { | ||
62 | int num; /* number of pages to populate */ | ||
63 | domid_t dom; /* target domain */ | ||
64 | __u64 addr; /* virtual address */ | ||
65 | xen_pfn_t __user *arr; /* array of mfns - top nibble set on err */ | ||
66 | }; | ||
67 | |||
68 | /* | ||
69 | * @cmd: IOCTL_PRIVCMD_HYPERCALL | ||
70 | * @arg: &privcmd_hypercall_t | ||
71 | * Return: Value returned from execution of the specified hypercall. | ||
72 | */ | ||
73 | #define IOCTL_PRIVCMD_HYPERCALL \ | ||
74 | _IOC(_IOC_NONE, 'P', 0, sizeof(struct privcmd_hypercall)) | ||
75 | #define IOCTL_PRIVCMD_MMAP \ | ||
76 | _IOC(_IOC_NONE, 'P', 2, sizeof(struct privcmd_mmap)) | ||
77 | #define IOCTL_PRIVCMD_MMAPBATCH \ | ||
78 | _IOC(_IOC_NONE, 'P', 3, sizeof(struct privcmd_mmapbatch)) | ||
79 | |||
80 | #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */ | ||
diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index 351f4051f6d8..98b92154a264 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h | |||
@@ -23,4 +23,9 @@ int xen_create_contiguous_region(unsigned long vstart, unsigned int order, | |||
23 | 23 | ||
24 | void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order); | 24 | void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order); |
25 | 25 | ||
26 | int xen_remap_domain_mfn_range(struct vm_area_struct *vma, | ||
27 | unsigned long addr, | ||
28 | unsigned long mfn, int nr, | ||
29 | pgprot_t prot, unsigned domid); | ||
30 | |||
26 | #endif /* INCLUDE_XEN_OPS_H */ | 31 | #endif /* INCLUDE_XEN_OPS_H */ |