mailestone-2
[linux-based-stubdoms.git] / linux.patch
blobd136116af2cfe6f7d6cff00b31ab8966bcaf5c3b
1 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
2 index 0493093..97f848d 100644
3 --- a/arch/x86/xen/enlighten.c
4 +++ b/arch/x86/xen/enlighten.c
5 @@ -779,7 +779,7 @@ static __init void set_xen_basic_apic_ops(void)
6 apic->icr_write = xen_apic_icr_write;
7 apic->wait_icr_idle = xen_apic_wait_icr_idle;
8 apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
9 - apic->probe = xen_safe_probe;
10 +// apic->probe = xen_safe_probe;
11 apic->acpi_madt_oem_check = xen_safe_flat_acpi_madt_oem_check;
12 /* Copy over the full contents of the newly modified apic into
13 * our apic_xen, which is to be called first by apic_probe[]. */
14 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
15 index 204e3ba..8637eb8 100644
16 --- a/arch/x86/xen/mmu.c
17 +++ b/arch/x86/xen/mmu.c
18 @@ -1666,6 +1666,7 @@ static void xen_flush_tlb_single(unsigned long addr)
19 static void xen_flush_tlb_others(const struct cpumask *cpus,
20 struct mm_struct *mm, unsigned long va)
22 + extern unsigned int num_processors;
23 struct {
24 struct mmuext_op op;
25 DECLARE_BITMAP(mask, num_processors);
26 @@ -2639,12 +2640,21 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,
27 unsigned long addr, void *data)
29 struct remap_data *rmd = data;
30 - pte_t pte = pte_mkspecial(pfn_pte(rmd->mfn++, rmd->prot));
32 + /* Use the native_make_pte function because we are sure we don't
33 + * have to do any pfn->mfn translations but at the same time we
34 + * could in a stubdom so xen_initial_domain() would return false. */
35 + pte_t pte = pte_mkspecial(native_make_pte(((phys_addr_t)(rmd->mfn++)
36 + << PAGE_SHIFT) | massage_pgprot(rmd->prot)));
37 + pteval_t val = pte_val_ma(pte);
39 + if (pat_enabled && !WARN_ON(val & _PAGE_PAT)) {
40 + if ((val & (_PAGE_PCD | _PAGE_PWT)) == _PAGE_PWT)
41 + val = (val & ~(_PAGE_PCD | _PAGE_PWT)) | _PAGE_PAT;
42 + }
43 rmd->mmu_update->ptr = arbitrary_virt_to_machine(ptep).maddr;
44 - rmd->mmu_update->val = pte_val_ma(pte);
45 + rmd->mmu_update->val = pte_val_ma(pte);
46 rmd->mmu_update++;
48 return 0;
50 @@ -2693,6 +2703,58 @@ out:
52 EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
54 +int xen_remap_foreign_gpfn_range(unsigned long addr,unsigned long mfn,
55 + int nr, unsigned domid)
57 + struct remap_data rmd;
58 + struct mmu_update mmu_update[REMAP_BATCH_SIZE];
59 + int level,i,batch,nr_page = nr;
60 + unsigned long range;
61 + int err = 0;
62 + unsigned long vaddr,offset, set_mfn,base_addr = addr;
63 + pte_t pte,*ptep;
65 + rmd.mfn = mfn;
66 + rmd.prot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_IOMAP);
68 + while(nr_page) {
69 + batch = min(REMAP_BATCH_SIZE, nr);
70 + range = (unsigned long)batch << PAGE_SHIFT;
72 + rmd.mmu_update = mmu_update;
74 + for(i=0; i < batch; i++){
75 + pte = pte_mkspecial(pfn_pte(rmd.mfn++, rmd.prot));
76 + vaddr = base_addr + i*PAGE_SIZE;
77 + ptep = lookup_address(vaddr, &level);
78 + BUG_ON(!ptep || (level != PG_LEVEL_4K));
80 + rmd.mmu_update->ptr = XMADDR((phys_addr_t)pte_mfn(*ptep) << PAGE_SHIFT).maddr;
81 + rmd.mmu_update->val = pte_val_ma(pte);
82 + rmd.mmu_update++;
83 + }
85 + err = -EFAULT;
86 + if(HYPERVISOR_mmu_update(mmu_update, batch, NULL, domid) < 0)
87 + goto out;
89 + nr_page -= batch;
90 + base_addr += range;
91 + }
93 + err = 0;
94 +out:
95 + flush_tlb_all();
96 + return err;
98 +EXPORT_SYMBOL_GPL(xen_remap_foreign_gpfn_range);
100 +unsigned long mapped_vaddr_to_mfn(void *address)
102 + return arbitrary_virt_to_mfn(address);
104 +EXPORT_SYMBOL_GPL(mapped_vaddr_to_mfn);
106 #ifdef CONFIG_XEN_PVHVM
107 static void xen_hvm_exit_mmap(struct mm_struct *mm)
109 diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c
110 index dc72563..0cea4a3 100644
111 --- a/drivers/video/xen-fbfront.c
112 +++ b/drivers/video/xen-fbfront.c
113 @@ -25,8 +25,12 @@
114 #include <linux/module.h>
115 #include <linux/vmalloc.h>
116 #include <linux/mm.h>
117 +#include <linux/sched.h>
118 +#include <asm/pgtable.h>
119 +#include <asm/page.h>
121 #include <asm/xen/hypervisor.h>
122 +#include <asm/xen/page.h>
124 #include <xen/xen.h>
125 #include <xen/events.h>
126 @@ -34,6 +38,7 @@
127 #include <xen/interface/io/fbif.h>
128 #include <xen/interface/io/protocols.h>
129 #include <xen/xenbus.h>
130 +#include <xen/xen-ops.h>
132 struct xenfb_info {
133 unsigned char *fb;
134 @@ -62,6 +67,12 @@ module_param_array(video, int, NULL, 0);
135 MODULE_PARM_DESC(video,
136 "Video memory size in MB, width, height in pixels (default 2,800,600)");
138 +static unsigned long foreign_gpfn = 0;
139 +module_param(foreign_gpfn, ulong, S_IRUGO);
141 +static unsigned long foreign_domid = 0;
142 +module_param(foreign_domid, ulong, S_IRUGO);
144 static void xenfb_make_preferred_console(void);
145 static int xenfb_remove(struct xenbus_device *);
146 static void xenfb_init_shared_page(struct xenfb_info *, struct fb_info *);
147 @@ -374,7 +385,6 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
149 /* Limit kernel param videoram amount to what is in xenstore */
150 if (xenbus_scanf(XBT_NIL, dev->otherend, "videoram", "%d", &val) == 1) {
151 - if (val < video[KPARAM_MEM])
152 video[KPARAM_MEM] = val;
155 @@ -397,7 +407,16 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
156 info->fb = vmalloc(fb_size);
157 if (info->fb == NULL)
158 goto error_nomem;
159 - memset(info->fb, 0, fb_size);
161 + if((foreign_gpfn != 0) && (foreign_domid != 0)){
162 + ret = xen_remap_foreign_gpfn_range((unsigned long)(info->fb),
163 + foreign_gpfn >> PAGE_SHIFT,
164 + fb_size >> PAGE_SHIFT, foreign_domid);
165 + if(ret < 0){
166 + printk("Can not remap vram of hvm guest. rc(%d)\n",ret);
167 + goto error;
171 info->nr_pages = (fb_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
172 diff --git a/drivers/xen/xenfs/privcmd.c b/drivers/xen/xenfs/privcmd.c
173 index f80be7f..4d25031 100644
174 --- a/drivers/xen/xenfs/privcmd.c
175 +++ b/drivers/xen/xenfs/privcmd.c
176 @@ -191,8 +191,10 @@ static long privcmd_ioctl_mmap(void __user *udata)
177 LIST_HEAD(pagelist);
178 struct mmap_mfn_state state;
180 +#if 0
181 if (!xen_initial_domain())
182 return -EPERM;
183 +#endif
185 if (copy_from_user(&mmapcmd, udata, sizeof(mmapcmd)))
186 return -EFAULT;
187 @@ -282,9 +284,10 @@ static long privcmd_ioctl_mmap_batch(void __user *udata)
188 unsigned long nr_pages;
189 LIST_HEAD(pagelist);
190 struct mmap_batch_state state;
192 +#if 0
193 if (!xen_initial_domain())
194 return -EPERM;
195 +#endif
197 if (copy_from_user(&m, udata, sizeof(m)))
198 return -EFAULT;
199 diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
200 index 4349e89..b9593b0 100644
201 --- a/include/xen/xen-ops.h
202 +++ b/include/xen/xen-ops.h
203 @@ -20,6 +20,10 @@ int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
204 unsigned long mfn, int nr,
205 pgprot_t prot, unsigned domid);
207 +int xen_remap_foreign_gpfn_range(unsigned long addr,unsigned long mfn,
208 + int nr, unsigned domid);
209 +unsigned long mapped_vaddr_to_mfn(void *address);
211 extern unsigned long *xen_contiguous_bitmap;
212 int xen_create_contiguous_region(unsigned long vstart, unsigned int order,
213 unsigned int address_bits);