diff options
-rw-r--r-- | arch/arm/Kconfig | 1 | ||||
-rw-r--r-- | arch/arm/xen/enlighten.c | 77 | ||||
-rw-r--r-- | arch/x86/include/asm/xen/page.h | 5 | ||||
-rw-r--r-- | arch/x86/xen/grant-table.c | 3 | ||||
-rw-r--r-- | arch/x86/xen/p2m.c | 17 | ||||
-rw-r--r-- | drivers/block/xen-blkback/blkback.c | 15 | ||||
-rw-r--r-- | drivers/xen/gntdev.c | 13 | ||||
-rw-r--r-- | drivers/xen/grant-table.c | 95 | ||||
-rw-r--r-- | drivers/xen/swiotlb-xen.c | 22 | ||||
-rw-r--r-- | drivers/xen/xen-selfballoon.c | 22 | ||||
-rw-r--r-- | include/xen/grant_table.h | 10 |
11 files changed, 197 insertions, 83 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index dc6ef9a2c649..e25419817791 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig | |||
@@ -1905,6 +1905,7 @@ config XEN | |||
1905 | depends on !GENERIC_ATOMIC64 | 1905 | depends on !GENERIC_ATOMIC64 |
1906 | select ARM_PSCI | 1906 | select ARM_PSCI |
1907 | select SWIOTLB_XEN | 1907 | select SWIOTLB_XEN |
1908 | select ARCH_DMA_ADDR_T_64BIT | ||
1908 | help | 1909 | help |
1909 | Say Y if you want to run Linux in a Virtual Machine on Xen on ARM. | 1910 | Say Y if you want to run Linux in a Virtual Machine on Xen on ARM. |
1910 | 1911 | ||
diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c index 2162172c0ddc..b96723e258a0 100644 --- a/arch/arm/xen/enlighten.c +++ b/arch/arm/xen/enlighten.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/of_address.h> | 23 | #include <linux/of_address.h> |
24 | #include <linux/cpuidle.h> | 24 | #include <linux/cpuidle.h> |
25 | #include <linux/cpufreq.h> | 25 | #include <linux/cpufreq.h> |
26 | #include <linux/cpu.h> | ||
26 | 27 | ||
27 | #include <linux/mm.h> | 28 | #include <linux/mm.h> |
28 | 29 | ||
@@ -154,7 +155,7 @@ int xen_unmap_domain_mfn_range(struct vm_area_struct *vma, | |||
154 | } | 155 | } |
155 | EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range); | 156 | EXPORT_SYMBOL_GPL(xen_unmap_domain_mfn_range); |
156 | 157 | ||
157 | static void __init xen_percpu_init(void *unused) | 158 | static void xen_percpu_init(void) |
158 | { | 159 | { |
159 | struct vcpu_register_vcpu_info info; | 160 | struct vcpu_register_vcpu_info info; |
160 | struct vcpu_info *vcpup; | 161 | struct vcpu_info *vcpup; |
@@ -193,6 +194,31 @@ static void xen_power_off(void) | |||
193 | BUG(); | 194 | BUG(); |
194 | } | 195 | } |
195 | 196 | ||
197 | static int xen_cpu_notification(struct notifier_block *self, | ||
198 | unsigned long action, | ||
199 | void *hcpu) | ||
200 | { | ||
201 | switch (action) { | ||
202 | case CPU_STARTING: | ||
203 | xen_percpu_init(); | ||
204 | break; | ||
205 | default: | ||
206 | break; | ||
207 | } | ||
208 | |||
209 | return NOTIFY_OK; | ||
210 | } | ||
211 | |||
212 | static struct notifier_block xen_cpu_notifier = { | ||
213 | .notifier_call = xen_cpu_notification, | ||
214 | }; | ||
215 | |||
216 | static irqreturn_t xen_arm_callback(int irq, void *arg) | ||
217 | { | ||
218 | xen_hvm_evtchn_do_upcall(); | ||
219 | return IRQ_HANDLED; | ||
220 | } | ||
221 | |||
196 | /* | 222 | /* |
197 | * see Documentation/devicetree/bindings/arm/xen.txt for the | 223 | * see Documentation/devicetree/bindings/arm/xen.txt for the |
198 | * documentation of the Xen Device Tree format. | 224 | * documentation of the Xen Device Tree format. |
@@ -208,7 +234,7 @@ static int __init xen_guest_init(void) | |||
208 | const char *version = NULL; | 234 | const char *version = NULL; |
209 | const char *xen_prefix = "xen,xen-"; | 235 | const char *xen_prefix = "xen,xen-"; |
210 | struct resource res; | 236 | struct resource res; |
211 | unsigned long grant_frames; | 237 | phys_addr_t grant_frames; |
212 | 238 | ||
213 | node = of_find_compatible_node(NULL, NULL, "xen,xen"); | 239 | node = of_find_compatible_node(NULL, NULL, "xen,xen"); |
214 | if (!node) { | 240 | if (!node) { |
@@ -227,8 +253,12 @@ static int __init xen_guest_init(void) | |||
227 | return 0; | 253 | return 0; |
228 | grant_frames = res.start; | 254 | grant_frames = res.start; |
229 | xen_events_irq = irq_of_parse_and_map(node, 0); | 255 | xen_events_irq = irq_of_parse_and_map(node, 0); |
230 | pr_info("Xen %s support found, events_irq=%d gnttab_frame_pfn=%lx\n", | 256 | pr_info("Xen %s support found, events_irq=%d gnttab_frame=%pa\n", |
231 | version, xen_events_irq, (grant_frames >> PAGE_SHIFT)); | 257 | version, xen_events_irq, &grant_frames); |
258 | |||
259 | if (xen_events_irq < 0) | ||
260 | return -ENODEV; | ||
261 | |||
232 | xen_domain_type = XEN_HVM_DOMAIN; | 262 | xen_domain_type = XEN_HVM_DOMAIN; |
233 | 263 | ||
234 | xen_setup_features(); | 264 | xen_setup_features(); |
@@ -281,9 +311,21 @@ static int __init xen_guest_init(void) | |||
281 | disable_cpuidle(); | 311 | disable_cpuidle(); |
282 | disable_cpufreq(); | 312 | disable_cpufreq(); |
283 | 313 | ||
314 | xen_init_IRQ(); | ||
315 | |||
316 | if (request_percpu_irq(xen_events_irq, xen_arm_callback, | ||
317 | "events", &xen_vcpu)) { | ||
318 | pr_err("Error request IRQ %d\n", xen_events_irq); | ||
319 | return -EINVAL; | ||
320 | } | ||
321 | |||
322 | xen_percpu_init(); | ||
323 | |||
324 | register_cpu_notifier(&xen_cpu_notifier); | ||
325 | |||
284 | return 0; | 326 | return 0; |
285 | } | 327 | } |
286 | core_initcall(xen_guest_init); | 328 | early_initcall(xen_guest_init); |
287 | 329 | ||
288 | static int __init xen_pm_init(void) | 330 | static int __init xen_pm_init(void) |
289 | { | 331 | { |
@@ -297,31 +339,6 @@ static int __init xen_pm_init(void) | |||
297 | } | 339 | } |
298 | late_initcall(xen_pm_init); | 340 | late_initcall(xen_pm_init); |
299 | 341 | ||
300 | static irqreturn_t xen_arm_callback(int irq, void *arg) | ||
301 | { | ||
302 | xen_hvm_evtchn_do_upcall(); | ||
303 | return IRQ_HANDLED; | ||
304 | } | ||
305 | |||
306 | static int __init xen_init_events(void) | ||
307 | { | ||
308 | if (!xen_domain() || xen_events_irq < 0) | ||
309 | return -ENODEV; | ||
310 | |||
311 | xen_init_IRQ(); | ||
312 | |||
313 | if (request_percpu_irq(xen_events_irq, xen_arm_callback, | ||
314 | "events", &xen_vcpu)) { | ||
315 | pr_err("Error requesting IRQ %d\n", xen_events_irq); | ||
316 | return -EINVAL; | ||
317 | } | ||
318 | |||
319 | on_each_cpu(xen_percpu_init, NULL, 0); | ||
320 | |||
321 | return 0; | ||
322 | } | ||
323 | postcore_initcall(xen_init_events); | ||
324 | |||
325 | /* In the hypervisor.S file. */ | 342 | /* In the hypervisor.S file. */ |
326 | EXPORT_SYMBOL_GPL(HYPERVISOR_event_channel_op); | 343 | EXPORT_SYMBOL_GPL(HYPERVISOR_event_channel_op); |
327 | EXPORT_SYMBOL_GPL(HYPERVISOR_grant_table_op); | 344 | EXPORT_SYMBOL_GPL(HYPERVISOR_grant_table_op); |
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h index 3e276eb23d1b..787e1bb5aafc 100644 --- a/arch/x86/include/asm/xen/page.h +++ b/arch/x86/include/asm/xen/page.h | |||
@@ -52,7 +52,8 @@ extern unsigned long set_phys_range_identity(unsigned long pfn_s, | |||
52 | extern int m2p_add_override(unsigned long mfn, struct page *page, | 52 | extern int m2p_add_override(unsigned long mfn, struct page *page, |
53 | struct gnttab_map_grant_ref *kmap_op); | 53 | struct gnttab_map_grant_ref *kmap_op); |
54 | extern int m2p_remove_override(struct page *page, | 54 | extern int m2p_remove_override(struct page *page, |
55 | struct gnttab_map_grant_ref *kmap_op); | 55 | struct gnttab_map_grant_ref *kmap_op, |
56 | unsigned long mfn); | ||
56 | extern struct page *m2p_find_override(unsigned long mfn); | 57 | extern struct page *m2p_find_override(unsigned long mfn); |
57 | extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn); | 58 | extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn); |
58 | 59 | ||
@@ -121,7 +122,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn) | |||
121 | pfn = m2p_find_override_pfn(mfn, ~0); | 122 | pfn = m2p_find_override_pfn(mfn, ~0); |
122 | } | 123 | } |
123 | 124 | ||
124 | /* | 125 | /* |
125 | * pfn is ~0 if there are no entries in the m2p for mfn or if the | 126 | * pfn is ~0 if there are no entries in the m2p for mfn or if the |
126 | * entry doesn't map back to the mfn and m2p_override doesn't have a | 127 | * entry doesn't map back to the mfn and m2p_override doesn't have a |
127 | * valid entry for it. | 128 | * valid entry for it. |
diff --git a/arch/x86/xen/grant-table.c b/arch/x86/xen/grant-table.c index 103c93f874b2..c98583588580 100644 --- a/arch/x86/xen/grant-table.c +++ b/arch/x86/xen/grant-table.c | |||
@@ -162,14 +162,15 @@ static int __init xlated_setup_gnttab_pages(void) | |||
162 | rc = arch_gnttab_map_shared(pfns, nr_grant_frames, nr_grant_frames, | 162 | rc = arch_gnttab_map_shared(pfns, nr_grant_frames, nr_grant_frames, |
163 | &xen_auto_xlat_grant_frames.vaddr); | 163 | &xen_auto_xlat_grant_frames.vaddr); |
164 | 164 | ||
165 | kfree(pages); | ||
166 | if (rc) { | 165 | if (rc) { |
167 | pr_warn("%s Couldn't map %ld pfns rc:%d\n", __func__, | 166 | pr_warn("%s Couldn't map %ld pfns rc:%d\n", __func__, |
168 | nr_grant_frames, rc); | 167 | nr_grant_frames, rc); |
169 | free_xenballooned_pages(nr_grant_frames, pages); | 168 | free_xenballooned_pages(nr_grant_frames, pages); |
169 | kfree(pages); | ||
170 | kfree(pfns); | 170 | kfree(pfns); |
171 | return rc; | 171 | return rc; |
172 | } | 172 | } |
173 | kfree(pages); | ||
173 | 174 | ||
174 | xen_auto_xlat_grant_frames.pfn = pfns; | 175 | xen_auto_xlat_grant_frames.pfn = pfns; |
175 | xen_auto_xlat_grant_frames.count = nr_grant_frames; | 176 | xen_auto_xlat_grant_frames.count = nr_grant_frames; |
diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index 696c694986d0..8009acbe41e4 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c | |||
@@ -899,13 +899,6 @@ int m2p_add_override(unsigned long mfn, struct page *page, | |||
899 | "m2p_add_override: pfn %lx not mapped", pfn)) | 899 | "m2p_add_override: pfn %lx not mapped", pfn)) |
900 | return -EINVAL; | 900 | return -EINVAL; |
901 | } | 901 | } |
902 | WARN_ON(PagePrivate(page)); | ||
903 | SetPagePrivate(page); | ||
904 | set_page_private(page, mfn); | ||
905 | page->index = pfn_to_mfn(pfn); | ||
906 | |||
907 | if (unlikely(!set_phys_to_machine(pfn, FOREIGN_FRAME(mfn)))) | ||
908 | return -ENOMEM; | ||
909 | 902 | ||
910 | if (kmap_op != NULL) { | 903 | if (kmap_op != NULL) { |
911 | if (!PageHighMem(page)) { | 904 | if (!PageHighMem(page)) { |
@@ -944,19 +937,16 @@ int m2p_add_override(unsigned long mfn, struct page *page, | |||
944 | } | 937 | } |
945 | EXPORT_SYMBOL_GPL(m2p_add_override); | 938 | EXPORT_SYMBOL_GPL(m2p_add_override); |
946 | int m2p_remove_override(struct page *page, | 939 | int m2p_remove_override(struct page *page, |
947 | struct gnttab_map_grant_ref *kmap_op) | 940 | struct gnttab_map_grant_ref *kmap_op, |
941 | unsigned long mfn) | ||
948 | { | 942 | { |
949 | unsigned long flags; | 943 | unsigned long flags; |
950 | unsigned long mfn; | ||
951 | unsigned long pfn; | 944 | unsigned long pfn; |
952 | unsigned long uninitialized_var(address); | 945 | unsigned long uninitialized_var(address); |
953 | unsigned level; | 946 | unsigned level; |
954 | pte_t *ptep = NULL; | 947 | pte_t *ptep = NULL; |
955 | 948 | ||
956 | pfn = page_to_pfn(page); | 949 | pfn = page_to_pfn(page); |
957 | mfn = get_phys_to_machine(pfn); | ||
958 | if (mfn == INVALID_P2M_ENTRY || !(mfn & FOREIGN_FRAME_BIT)) | ||
959 | return -EINVAL; | ||
960 | 950 | ||
961 | if (!PageHighMem(page)) { | 951 | if (!PageHighMem(page)) { |
962 | address = (unsigned long)__va(pfn << PAGE_SHIFT); | 952 | address = (unsigned long)__va(pfn << PAGE_SHIFT); |
@@ -970,10 +960,7 @@ int m2p_remove_override(struct page *page, | |||
970 | spin_lock_irqsave(&m2p_override_lock, flags); | 960 | spin_lock_irqsave(&m2p_override_lock, flags); |
971 | list_del(&page->lru); | 961 | list_del(&page->lru); |
972 | spin_unlock_irqrestore(&m2p_override_lock, flags); | 962 | spin_unlock_irqrestore(&m2p_override_lock, flags); |
973 | WARN_ON(!PagePrivate(page)); | ||
974 | ClearPagePrivate(page); | ||
975 | 963 | ||
976 | set_phys_to_machine(pfn, page->index); | ||
977 | if (kmap_op != NULL) { | 964 | if (kmap_op != NULL) { |
978 | if (!PageHighMem(page)) { | 965 | if (!PageHighMem(page)) { |
979 | struct multicall_space mcs; | 966 | struct multicall_space mcs; |
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index 4b97b86da926..da18046d0e07 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c | |||
@@ -285,8 +285,7 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root, | |||
285 | 285 | ||
286 | if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST || | 286 | if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST || |
287 | !rb_next(&persistent_gnt->node)) { | 287 | !rb_next(&persistent_gnt->node)) { |
288 | ret = gnttab_unmap_refs(unmap, NULL, pages, | 288 | ret = gnttab_unmap_refs(unmap, pages, segs_to_unmap); |
289 | segs_to_unmap); | ||
290 | BUG_ON(ret); | 289 | BUG_ON(ret); |
291 | put_free_pages(blkif, pages, segs_to_unmap); | 290 | put_free_pages(blkif, pages, segs_to_unmap); |
292 | segs_to_unmap = 0; | 291 | segs_to_unmap = 0; |
@@ -321,8 +320,7 @@ static void unmap_purged_grants(struct work_struct *work) | |||
321 | pages[segs_to_unmap] = persistent_gnt->page; | 320 | pages[segs_to_unmap] = persistent_gnt->page; |
322 | 321 | ||
323 | if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) { | 322 | if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) { |
324 | ret = gnttab_unmap_refs(unmap, NULL, pages, | 323 | ret = gnttab_unmap_refs(unmap, pages, segs_to_unmap); |
325 | segs_to_unmap); | ||
326 | BUG_ON(ret); | 324 | BUG_ON(ret); |
327 | put_free_pages(blkif, pages, segs_to_unmap); | 325 | put_free_pages(blkif, pages, segs_to_unmap); |
328 | segs_to_unmap = 0; | 326 | segs_to_unmap = 0; |
@@ -330,7 +328,7 @@ static void unmap_purged_grants(struct work_struct *work) | |||
330 | kfree(persistent_gnt); | 328 | kfree(persistent_gnt); |
331 | } | 329 | } |
332 | if (segs_to_unmap > 0) { | 330 | if (segs_to_unmap > 0) { |
333 | ret = gnttab_unmap_refs(unmap, NULL, pages, segs_to_unmap); | 331 | ret = gnttab_unmap_refs(unmap, pages, segs_to_unmap); |
334 | BUG_ON(ret); | 332 | BUG_ON(ret); |
335 | put_free_pages(blkif, pages, segs_to_unmap); | 333 | put_free_pages(blkif, pages, segs_to_unmap); |
336 | } | 334 | } |
@@ -670,15 +668,14 @@ static void xen_blkbk_unmap(struct xen_blkif *blkif, | |||
670 | GNTMAP_host_map, pages[i]->handle); | 668 | GNTMAP_host_map, pages[i]->handle); |
671 | pages[i]->handle = BLKBACK_INVALID_HANDLE; | 669 | pages[i]->handle = BLKBACK_INVALID_HANDLE; |
672 | if (++invcount == BLKIF_MAX_SEGMENTS_PER_REQUEST) { | 670 | if (++invcount == BLKIF_MAX_SEGMENTS_PER_REQUEST) { |
673 | ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, | 671 | ret = gnttab_unmap_refs(unmap, unmap_pages, invcount); |
674 | invcount); | ||
675 | BUG_ON(ret); | 672 | BUG_ON(ret); |
676 | put_free_pages(blkif, unmap_pages, invcount); | 673 | put_free_pages(blkif, unmap_pages, invcount); |
677 | invcount = 0; | 674 | invcount = 0; |
678 | } | 675 | } |
679 | } | 676 | } |
680 | if (invcount) { | 677 | if (invcount) { |
681 | ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount); | 678 | ret = gnttab_unmap_refs(unmap, unmap_pages, invcount); |
682 | BUG_ON(ret); | 679 | BUG_ON(ret); |
683 | put_free_pages(blkif, unmap_pages, invcount); | 680 | put_free_pages(blkif, unmap_pages, invcount); |
684 | } | 681 | } |
@@ -740,7 +737,7 @@ again: | |||
740 | } | 737 | } |
741 | 738 | ||
742 | if (segs_to_map) { | 739 | if (segs_to_map) { |
743 | ret = gnttab_map_refs(map, NULL, pages_to_gnt, segs_to_map); | 740 | ret = gnttab_map_refs(map, pages_to_gnt, segs_to_map); |
744 | BUG_ON(ret); | 741 | BUG_ON(ret); |
745 | } | 742 | } |
746 | 743 | ||
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 073b4a19a8b0..34a2704fbc88 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c | |||
@@ -284,8 +284,10 @@ 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(map->map_ops, use_ptemod ? map->kmap_ops : NULL, | 287 | err = gnttab_map_refs_userspace(map->map_ops, |
288 | map->pages, map->count); | 288 | use_ptemod ? map->kmap_ops : NULL, |
289 | map->pages, | ||
290 | map->count); | ||
289 | if (err) | 291 | if (err) |
290 | return err; | 292 | return err; |
291 | 293 | ||
@@ -315,9 +317,10 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages) | |||
315 | } | 317 | } |
316 | } | 318 | } |
317 | 319 | ||
318 | err = gnttab_unmap_refs(map->unmap_ops + offset, | 320 | err = gnttab_unmap_refs_userspace(map->unmap_ops + offset, |
319 | use_ptemod ? map->kmap_ops + offset : NULL, map->pages + offset, | 321 | use_ptemod ? map->kmap_ops + offset : NULL, |
320 | pages); | 322 | map->pages + offset, |
323 | pages); | ||
321 | if (err) | 324 | if (err) |
322 | return err; | 325 | return err; |
323 | 326 | ||
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 1ce1c40331f3..8ee13e2e45e2 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c | |||
@@ -837,7 +837,7 @@ unsigned int gnttab_max_grant_frames(void) | |||
837 | } | 837 | } |
838 | EXPORT_SYMBOL_GPL(gnttab_max_grant_frames); | 838 | EXPORT_SYMBOL_GPL(gnttab_max_grant_frames); |
839 | 839 | ||
840 | int gnttab_setup_auto_xlat_frames(unsigned long addr) | 840 | int gnttab_setup_auto_xlat_frames(phys_addr_t addr) |
841 | { | 841 | { |
842 | xen_pfn_t *pfn; | 842 | xen_pfn_t *pfn; |
843 | unsigned int max_nr_gframes = __max_nr_grant_frames(); | 843 | unsigned int max_nr_gframes = __max_nr_grant_frames(); |
@@ -849,8 +849,8 @@ int gnttab_setup_auto_xlat_frames(unsigned long addr) | |||
849 | 849 | ||
850 | vaddr = xen_remap(addr, PAGE_SIZE * max_nr_gframes); | 850 | vaddr = xen_remap(addr, PAGE_SIZE * max_nr_gframes); |
851 | if (vaddr == NULL) { | 851 | if (vaddr == NULL) { |
852 | pr_warn("Failed to ioremap gnttab share frames (addr=0x%08lx)!\n", | 852 | pr_warn("Failed to ioremap gnttab share frames (addr=%pa)!\n", |
853 | addr); | 853 | &addr); |
854 | return -ENOMEM; | 854 | return -ENOMEM; |
855 | } | 855 | } |
856 | pfn = kcalloc(max_nr_gframes, sizeof(pfn[0]), GFP_KERNEL); | 856 | pfn = kcalloc(max_nr_gframes, sizeof(pfn[0]), GFP_KERNEL); |
@@ -928,15 +928,17 @@ void gnttab_batch_copy(struct gnttab_copy *batch, unsigned count) | |||
928 | } | 928 | } |
929 | EXPORT_SYMBOL_GPL(gnttab_batch_copy); | 929 | EXPORT_SYMBOL_GPL(gnttab_batch_copy); |
930 | 930 | ||
931 | int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, | 931 | int __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) | ||
934 | { | 935 | { |
935 | int i, ret; | 936 | int i, ret; |
936 | bool lazy = false; | 937 | bool lazy = false; |
937 | pte_t *pte; | 938 | pte_t *pte; |
938 | unsigned long mfn; | 939 | unsigned long mfn, pfn; |
939 | 940 | ||
941 | BUG_ON(kmap_ops && !m2p_override); | ||
940 | ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map_ops, count); | 942 | ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map_ops, count); |
941 | if (ret) | 943 | if (ret) |
942 | return ret; | 944 | return ret; |
@@ -955,10 +957,12 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, | |||
955 | set_phys_to_machine(map_ops[i].host_addr >> PAGE_SHIFT, | 957 | set_phys_to_machine(map_ops[i].host_addr >> PAGE_SHIFT, |
956 | map_ops[i].dev_bus_addr >> PAGE_SHIFT); | 958 | map_ops[i].dev_bus_addr >> PAGE_SHIFT); |
957 | } | 959 | } |
958 | return ret; | 960 | return 0; |
959 | } | 961 | } |
960 | 962 | ||
961 | if (!in_interrupt() && paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) { | 963 | if (m2p_override && |
964 | !in_interrupt() && | ||
965 | paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) { | ||
962 | arch_enter_lazy_mmu_mode(); | 966 | arch_enter_lazy_mmu_mode(); |
963 | lazy = true; | 967 | lazy = true; |
964 | } | 968 | } |
@@ -975,8 +979,20 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, | |||
975 | } else { | 979 | } else { |
976 | mfn = PFN_DOWN(map_ops[i].dev_bus_addr); | 980 | mfn = PFN_DOWN(map_ops[i].dev_bus_addr); |
977 | } | 981 | } |
978 | ret = m2p_add_override(mfn, pages[i], kmap_ops ? | 982 | pfn = page_to_pfn(pages[i]); |
979 | &kmap_ops[i] : NULL); | 983 | |
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); | ||
980 | if (ret) | 996 | if (ret) |
981 | goto out; | 997 | goto out; |
982 | } | 998 | } |
@@ -987,15 +1003,32 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, | |||
987 | 1003 | ||
988 | return ret; | 1004 | return ret; |
989 | } | 1005 | } |
1006 | |||
1007 | int 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 | } | ||
990 | EXPORT_SYMBOL_GPL(gnttab_map_refs); | 1012 | EXPORT_SYMBOL_GPL(gnttab_map_refs); |
991 | 1013 | ||
992 | int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, | 1014 | int gnttab_map_refs_userspace(struct gnttab_map_grant_ref *map_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 | } | ||
1020 | EXPORT_SYMBOL_GPL(gnttab_map_refs_userspace); | ||
1021 | |||
1022 | int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, | ||
993 | struct gnttab_map_grant_ref *kmap_ops, | 1023 | struct gnttab_map_grant_ref *kmap_ops, |
994 | struct page **pages, unsigned int count) | 1024 | struct page **pages, unsigned int count, |
1025 | bool m2p_override) | ||
995 | { | 1026 | { |
996 | int i, ret; | 1027 | int i, ret; |
997 | bool lazy = false; | 1028 | bool lazy = false; |
1029 | unsigned long pfn, mfn; | ||
998 | 1030 | ||
1031 | BUG_ON(kmap_ops && !m2p_override); | ||
999 | ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count); | 1032 | ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count); |
1000 | if (ret) | 1033 | if (ret) |
1001 | return ret; | 1034 | return ret; |
@@ -1006,17 +1039,33 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, | |||
1006 | set_phys_to_machine(unmap_ops[i].host_addr >> PAGE_SHIFT, | 1039 | set_phys_to_machine(unmap_ops[i].host_addr >> PAGE_SHIFT, |
1007 | INVALID_P2M_ENTRY); | 1040 | INVALID_P2M_ENTRY); |
1008 | } | 1041 | } |
1009 | return ret; | 1042 | return 0; |
1010 | } | 1043 | } |
1011 | 1044 | ||
1012 | if (!in_interrupt() && paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) { | 1045 | if (m2p_override && |
1046 | !in_interrupt() && | ||
1047 | paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) { | ||
1013 | arch_enter_lazy_mmu_mode(); | 1048 | arch_enter_lazy_mmu_mode(); |
1014 | lazy = true; | 1049 | lazy = true; |
1015 | } | 1050 | } |
1016 | 1051 | ||
1017 | for (i = 0; i < count; i++) { | 1052 | for (i = 0; i < count; i++) { |
1018 | ret = m2p_remove_override(pages[i], kmap_ops ? | 1053 | pfn = page_to_pfn(pages[i]); |
1019 | &kmap_ops[i] : NULL); | 1054 | mfn = get_phys_to_machine(pfn); |
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); | ||
1020 | if (ret) | 1069 | if (ret) |
1021 | goto out; | 1070 | goto out; |
1022 | } | 1071 | } |
@@ -1027,8 +1076,22 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, | |||
1027 | 1076 | ||
1028 | return ret; | 1077 | return ret; |
1029 | } | 1078 | } |
1079 | |||
1080 | int 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 | } | ||
1030 | EXPORT_SYMBOL_GPL(gnttab_unmap_refs); | 1085 | EXPORT_SYMBOL_GPL(gnttab_unmap_refs); |
1031 | 1086 | ||
1087 | int 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 | } | ||
1093 | EXPORT_SYMBOL_GPL(gnttab_unmap_refs_userspace); | ||
1094 | |||
1032 | static unsigned nr_status_frames(unsigned nr_grant_frames) | 1095 | static unsigned nr_status_frames(unsigned nr_grant_frames) |
1033 | { | 1096 | { |
1034 | BUG_ON(grefs_per_grant_frame == 0); | 1097 | BUG_ON(grefs_per_grant_frame == 0); |
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 1eac0731c349..ebd8f218a788 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c | |||
@@ -75,14 +75,32 @@ static unsigned long xen_io_tlb_nslabs; | |||
75 | 75 | ||
76 | static u64 start_dma_addr; | 76 | static u64 start_dma_addr; |
77 | 77 | ||
78 | /* | ||
79 | * Both of these functions should avoid PFN_PHYS because phys_addr_t | ||
80 | * can be 32bit when dma_addr_t is 64bit leading to a loss in | ||
81 | * information if the shift is done before casting to 64bit. | ||
82 | */ | ||
78 | static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr) | 83 | static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr) |
79 | { | 84 | { |
80 | return phys_to_machine(XPADDR(paddr)).maddr; | 85 | unsigned long mfn = pfn_to_mfn(PFN_DOWN(paddr)); |
86 | dma_addr_t dma = (dma_addr_t)mfn << PAGE_SHIFT; | ||
87 | |||
88 | dma |= paddr & ~PAGE_MASK; | ||
89 | |||
90 | return dma; | ||
81 | } | 91 | } |
82 | 92 | ||
83 | static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr) | 93 | static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr) |
84 | { | 94 | { |
85 | return machine_to_phys(XMADDR(baddr)).paddr; | 95 | unsigned long pfn = mfn_to_pfn(PFN_DOWN(baddr)); |
96 | dma_addr_t dma = (dma_addr_t)pfn << PAGE_SHIFT; | ||
97 | phys_addr_t paddr = dma; | ||
98 | |||
99 | BUG_ON(paddr != dma); /* truncation has occurred, should never happen */ | ||
100 | |||
101 | paddr |= baddr & ~PAGE_MASK; | ||
102 | |||
103 | return paddr; | ||
86 | } | 104 | } |
87 | 105 | ||
88 | static inline dma_addr_t xen_virt_to_bus(void *address) | 106 | static inline dma_addr_t xen_virt_to_bus(void *address) |
diff --git a/drivers/xen/xen-selfballoon.c b/drivers/xen/xen-selfballoon.c index 21e18c18c7a1..745ad79c1d8e 100644 --- a/drivers/xen/xen-selfballoon.c +++ b/drivers/xen/xen-selfballoon.c | |||
@@ -175,6 +175,7 @@ static void frontswap_selfshrink(void) | |||
175 | #endif /* CONFIG_FRONTSWAP */ | 175 | #endif /* CONFIG_FRONTSWAP */ |
176 | 176 | ||
177 | #define MB2PAGES(mb) ((mb) << (20 - PAGE_SHIFT)) | 177 | #define MB2PAGES(mb) ((mb) << (20 - PAGE_SHIFT)) |
178 | #define PAGES2MB(pages) ((pages) >> (20 - PAGE_SHIFT)) | ||
178 | 179 | ||
179 | /* | 180 | /* |
180 | * Use current balloon size, the goal (vm_committed_as), and hysteresis | 181 | * Use current balloon size, the goal (vm_committed_as), and hysteresis |
@@ -525,6 +526,7 @@ EXPORT_SYMBOL(register_xen_selfballooning); | |||
525 | int xen_selfballoon_init(bool use_selfballooning, bool use_frontswap_selfshrink) | 526 | int xen_selfballoon_init(bool use_selfballooning, bool use_frontswap_selfshrink) |
526 | { | 527 | { |
527 | bool enable = false; | 528 | bool enable = false; |
529 | unsigned long reserve_pages; | ||
528 | 530 | ||
529 | if (!xen_domain()) | 531 | if (!xen_domain()) |
530 | return -ENODEV; | 532 | return -ENODEV; |
@@ -549,6 +551,26 @@ int xen_selfballoon_init(bool use_selfballooning, bool use_frontswap_selfshrink) | |||
549 | if (!enable) | 551 | if (!enable) |
550 | return -ENODEV; | 552 | return -ENODEV; |
551 | 553 | ||
554 | /* | ||
555 | * Give selfballoon_reserved_mb a default value(10% of total ram pages) | ||
556 | * to make selfballoon not so aggressive. | ||
557 | * | ||
558 | * There are mainly two reasons: | ||
559 | * 1) The original goal_page didn't consider some pages used by kernel | ||
560 | * space, like slab pages and memory used by device drivers. | ||
561 | * | ||
562 | * 2) The balloon driver may not give back memory to guest OS fast | ||
563 | * enough when the workload suddenly aquries a lot of physical memory. | ||
564 | * | ||
565 | * In both cases, the guest OS will suffer from memory pressure and | ||
566 | * OOM killer may be triggered. | ||
567 | * By reserving extra 10% of total ram pages, we can keep the system | ||
568 | * much more reliably and response faster in some cases. | ||
569 | */ | ||
570 | if (!selfballoon_reserved_mb) { | ||
571 | reserve_pages = totalram_pages / 10; | ||
572 | selfballoon_reserved_mb = PAGES2MB(reserve_pages); | ||
573 | } | ||
552 | schedule_delayed_work(&selfballoon_worker, selfballoon_interval * HZ); | 574 | schedule_delayed_work(&selfballoon_worker, selfballoon_interval * HZ); |
553 | 575 | ||
554 | return 0; | 576 | return 0; |
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h index 5acb1e4ac0d3..7ad033dbc845 100644 --- a/include/xen/grant_table.h +++ b/include/xen/grant_table.h | |||
@@ -185,17 +185,21 @@ struct grant_frames { | |||
185 | }; | 185 | }; |
186 | extern struct grant_frames xen_auto_xlat_grant_frames; | 186 | extern struct grant_frames xen_auto_xlat_grant_frames; |
187 | unsigned int gnttab_max_grant_frames(void); | 187 | unsigned int gnttab_max_grant_frames(void); |
188 | int gnttab_setup_auto_xlat_frames(unsigned long addr); | 188 | int gnttab_setup_auto_xlat_frames(phys_addr_t addr); |
189 | void gnttab_free_auto_xlat_frames(void); | 189 | void gnttab_free_auto_xlat_frames(void); |
190 | 190 | ||
191 | #define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr)) | 191 | #define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr)) |
192 | 192 | ||
193 | int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, | 193 | int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, |
194 | struct gnttab_map_grant_ref *kmap_ops, | ||
195 | struct page **pages, unsigned int count); | 194 | struct page **pages, unsigned int count); |
195 | int gnttab_map_refs_userspace(struct gnttab_map_grant_ref *map_ops, | ||
196 | struct gnttab_map_grant_ref *kmap_ops, | ||
197 | struct page **pages, unsigned int count); | ||
196 | int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, | 198 | int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, |
197 | struct gnttab_map_grant_ref *kunmap_ops, | ||
198 | struct page **pages, unsigned int count); | 199 | struct page **pages, unsigned int count); |
200 | int gnttab_unmap_refs_userspace(struct gnttab_unmap_grant_ref *unmap_ops, | ||
201 | struct gnttab_map_grant_ref *kunmap_ops, | ||
202 | struct page **pages, unsigned int count); | ||
199 | 203 | ||
200 | /* Perform a batch of grant map/copy operations. Retry every batch slot | 204 | /* Perform a batch of grant map/copy operations. Retry every batch slot |
201 | * for which the hypervisor returns GNTST_eagain. This is typically due | 205 | * for which the hypervisor returns GNTST_eagain. This is typically due |