diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-10 16:56:56 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-10 16:56:56 -0500 |
commit | bdccc4edeb03ad68c55053b0260bdaaac547bbd9 (patch) | |
tree | c9fdce7c6bb13632f5a64925a1fb3fa306b7cfe1 /drivers | |
parent | 98368ab436538103a557fc1f15f54afd8aab6712 (diff) | |
parent | 72978b2fe2f2cdf9f319c6c6dcdbe92b38de2be2 (diff) |
Merge tag 'stable/for-linus-3.20-rc0-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull xen features and fixes from David Vrabel:
- Reworked handling for foreign (grant mapped) pages to simplify the
code, enable a number of additional use cases and fix a number of
long-standing bugs.
- Prefer the TSC over the Xen PV clock when dom0 (and the TSC is
stable).
- Assorted other cleanup and minor bug fixes.
* tag 'stable/for-linus-3.20-rc0-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: (25 commits)
xen/manage: Fix USB interaction issues when resuming
xenbus: Add proper handling of XS_ERROR from Xenbus for transactions.
xen/gntdev: provide find_special_page VMA operation
xen/gntdev: mark userspace PTEs as special on x86 PV guests
xen-blkback: safely unmap grants in case they are still in use
xen/gntdev: safely unmap grants in case they are still in use
xen/gntdev: convert priv->lock to a mutex
xen/grant-table: add a mechanism to safely unmap pages that are in use
xen-netback: use foreign page information from the pages themselves
xen: mark grant mapped pages as foreign
xen/grant-table: add helpers for allocating pages
x86/xen: require ballooned pages for grant maps
xen: remove scratch frames for ballooned pages and m2p override
xen/grant-table: pre-populate kernel unmap ops for xen_gnttab_unmap_refs()
mm: add 'foreign' alias for the 'pinned' page flag
mm: provide a find_special_page vma operation
x86/xen: cleanup arch/x86/xen/mmu.c
x86/xen: add some __init annotations in arch/x86/xen/mmu.c
x86/xen: add some __init and static annotations in arch/x86/xen/setup.c
x86/xen: use correct types for addresses in arch/x86/xen/setup.c
...
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/xen-blkback/blkback.c | 177 | ||||
-rw-r--r-- | drivers/block/xen-blkback/common.h | 3 | ||||
-rw-r--r-- | drivers/net/xen-netback/interface.c | 7 | ||||
-rw-r--r-- | drivers/net/xen-netback/netback.c | 106 | ||||
-rw-r--r-- | drivers/xen/balloon.c | 86 | ||||
-rw-r--r-- | drivers/xen/gntdev.c | 143 | ||||
-rw-r--r-- | drivers/xen/grant-table.c | 120 | ||||
-rw-r--r-- | drivers/xen/manage.c | 8 | ||||
-rw-r--r-- | drivers/xen/tmem.c | 2 | ||||
-rw-r--r-- | drivers/xen/xen-scsiback.c | 6 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_dev_frontend.c | 11 |
11 files changed, 385 insertions, 284 deletions
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index 63fc7f06a014..2a04d341e598 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <asm/xen/hypervisor.h> | 47 | #include <asm/xen/hypervisor.h> |
48 | #include <asm/xen/hypercall.h> | 48 | #include <asm/xen/hypercall.h> |
49 | #include <xen/balloon.h> | 49 | #include <xen/balloon.h> |
50 | #include <xen/grant_table.h> | ||
50 | #include "common.h" | 51 | #include "common.h" |
51 | 52 | ||
52 | /* | 53 | /* |
@@ -100,7 +101,7 @@ module_param(log_stats, int, 0644); | |||
100 | 101 | ||
101 | #define BLKBACK_INVALID_HANDLE (~0) | 102 | #define BLKBACK_INVALID_HANDLE (~0) |
102 | 103 | ||
103 | /* Number of free pages to remove on each call to free_xenballooned_pages */ | 104 | /* Number of free pages to remove on each call to gnttab_free_pages */ |
104 | #define NUM_BATCH_FREE_PAGES 10 | 105 | #define NUM_BATCH_FREE_PAGES 10 |
105 | 106 | ||
106 | static inline int get_free_page(struct xen_blkif *blkif, struct page **page) | 107 | static inline int get_free_page(struct xen_blkif *blkif, struct page **page) |
@@ -111,7 +112,7 @@ static inline int get_free_page(struct xen_blkif *blkif, struct page **page) | |||
111 | if (list_empty(&blkif->free_pages)) { | 112 | if (list_empty(&blkif->free_pages)) { |
112 | BUG_ON(blkif->free_pages_num != 0); | 113 | BUG_ON(blkif->free_pages_num != 0); |
113 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); | 114 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); |
114 | return alloc_xenballooned_pages(1, page, false); | 115 | return gnttab_alloc_pages(1, page); |
115 | } | 116 | } |
116 | BUG_ON(blkif->free_pages_num == 0); | 117 | BUG_ON(blkif->free_pages_num == 0); |
117 | page[0] = list_first_entry(&blkif->free_pages, struct page, lru); | 118 | page[0] = list_first_entry(&blkif->free_pages, struct page, lru); |
@@ -151,14 +152,14 @@ static inline void shrink_free_pagepool(struct xen_blkif *blkif, int num) | |||
151 | blkif->free_pages_num--; | 152 | blkif->free_pages_num--; |
152 | if (++num_pages == NUM_BATCH_FREE_PAGES) { | 153 | if (++num_pages == NUM_BATCH_FREE_PAGES) { |
153 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); | 154 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); |
154 | free_xenballooned_pages(num_pages, page); | 155 | gnttab_free_pages(num_pages, page); |
155 | spin_lock_irqsave(&blkif->free_pages_lock, flags); | 156 | spin_lock_irqsave(&blkif->free_pages_lock, flags); |
156 | num_pages = 0; | 157 | num_pages = 0; |
157 | } | 158 | } |
158 | } | 159 | } |
159 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); | 160 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); |
160 | if (num_pages != 0) | 161 | if (num_pages != 0) |
161 | free_xenballooned_pages(num_pages, page); | 162 | gnttab_free_pages(num_pages, page); |
162 | } | 163 | } |
163 | 164 | ||
164 | #define vaddr(page) ((unsigned long)pfn_to_kaddr(page_to_pfn(page))) | 165 | #define vaddr(page) ((unsigned long)pfn_to_kaddr(page_to_pfn(page))) |
@@ -262,6 +263,17 @@ static void put_persistent_gnt(struct xen_blkif *blkif, | |||
262 | atomic_dec(&blkif->persistent_gnt_in_use); | 263 | atomic_dec(&blkif->persistent_gnt_in_use); |
263 | } | 264 | } |
264 | 265 | ||
266 | static void free_persistent_gnts_unmap_callback(int result, | ||
267 | struct gntab_unmap_queue_data *data) | ||
268 | { | ||
269 | struct completion *c = data->data; | ||
270 | |||
271 | /* BUG_ON used to reproduce existing behaviour, | ||
272 | but is this the best way to deal with this? */ | ||
273 | BUG_ON(result); | ||
274 | complete(c); | ||
275 | } | ||
276 | |||
265 | static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root, | 277 | static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root, |
266 | unsigned int num) | 278 | unsigned int num) |
267 | { | 279 | { |
@@ -269,8 +281,17 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root, | |||
269 | struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | 281 | struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
270 | struct persistent_gnt *persistent_gnt; | 282 | struct persistent_gnt *persistent_gnt; |
271 | struct rb_node *n; | 283 | struct rb_node *n; |
272 | int ret = 0; | ||
273 | int segs_to_unmap = 0; | 284 | int segs_to_unmap = 0; |
285 | struct gntab_unmap_queue_data unmap_data; | ||
286 | struct completion unmap_completion; | ||
287 | |||
288 | init_completion(&unmap_completion); | ||
289 | |||
290 | unmap_data.data = &unmap_completion; | ||
291 | unmap_data.done = &free_persistent_gnts_unmap_callback; | ||
292 | unmap_data.pages = pages; | ||
293 | unmap_data.unmap_ops = unmap; | ||
294 | unmap_data.kunmap_ops = NULL; | ||
274 | 295 | ||
275 | foreach_grant_safe(persistent_gnt, n, root, node) { | 296 | foreach_grant_safe(persistent_gnt, n, root, node) { |
276 | BUG_ON(persistent_gnt->handle == | 297 | BUG_ON(persistent_gnt->handle == |
@@ -285,9 +306,11 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root, | |||
285 | 306 | ||
286 | if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST || | 307 | if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST || |
287 | !rb_next(&persistent_gnt->node)) { | 308 | !rb_next(&persistent_gnt->node)) { |
288 | ret = gnttab_unmap_refs(unmap, NULL, pages, | 309 | |
289 | segs_to_unmap); | 310 | unmap_data.count = segs_to_unmap; |
290 | BUG_ON(ret); | 311 | gnttab_unmap_refs_async(&unmap_data); |
312 | wait_for_completion(&unmap_completion); | ||
313 | |||
291 | put_free_pages(blkif, pages, segs_to_unmap); | 314 | put_free_pages(blkif, pages, segs_to_unmap); |
292 | segs_to_unmap = 0; | 315 | segs_to_unmap = 0; |
293 | } | 316 | } |
@@ -653,18 +676,14 @@ void xen_blkbk_free_caches(struct xen_blkif *blkif) | |||
653 | shrink_free_pagepool(blkif, 0 /* All */); | 676 | shrink_free_pagepool(blkif, 0 /* All */); |
654 | } | 677 | } |
655 | 678 | ||
656 | /* | 679 | static unsigned int xen_blkbk_unmap_prepare( |
657 | * Unmap the grant references, and also remove the M2P over-rides | 680 | struct xen_blkif *blkif, |
658 | * used in the 'pending_req'. | 681 | struct grant_page **pages, |
659 | */ | 682 | unsigned int num, |
660 | static void xen_blkbk_unmap(struct xen_blkif *blkif, | 683 | struct gnttab_unmap_grant_ref *unmap_ops, |
661 | struct grant_page *pages[], | 684 | struct page **unmap_pages) |
662 | int num) | ||
663 | { | 685 | { |
664 | struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | ||
665 | struct page *unmap_pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | ||
666 | unsigned int i, invcount = 0; | 686 | unsigned int i, invcount = 0; |
667 | int ret; | ||
668 | 687 | ||
669 | for (i = 0; i < num; i++) { | 688 | for (i = 0; i < num; i++) { |
670 | if (pages[i]->persistent_gnt != NULL) { | 689 | if (pages[i]->persistent_gnt != NULL) { |
@@ -674,21 +693,95 @@ static void xen_blkbk_unmap(struct xen_blkif *blkif, | |||
674 | if (pages[i]->handle == BLKBACK_INVALID_HANDLE) | 693 | if (pages[i]->handle == BLKBACK_INVALID_HANDLE) |
675 | continue; | 694 | continue; |
676 | unmap_pages[invcount] = pages[i]->page; | 695 | unmap_pages[invcount] = pages[i]->page; |
677 | gnttab_set_unmap_op(&unmap[invcount], vaddr(pages[i]->page), | 696 | gnttab_set_unmap_op(&unmap_ops[invcount], vaddr(pages[i]->page), |
678 | GNTMAP_host_map, pages[i]->handle); | 697 | GNTMAP_host_map, pages[i]->handle); |
679 | pages[i]->handle = BLKBACK_INVALID_HANDLE; | 698 | pages[i]->handle = BLKBACK_INVALID_HANDLE; |
680 | if (++invcount == BLKIF_MAX_SEGMENTS_PER_REQUEST) { | 699 | invcount++; |
681 | ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, | 700 | } |
682 | invcount); | 701 | |
702 | return invcount; | ||
703 | } | ||
704 | |||
705 | static void xen_blkbk_unmap_and_respond_callback(int result, struct gntab_unmap_queue_data *data) | ||
706 | { | ||
707 | struct pending_req* pending_req = (struct pending_req*) (data->data); | ||
708 | struct xen_blkif *blkif = pending_req->blkif; | ||
709 | |||
710 | /* BUG_ON used to reproduce existing behaviour, | ||
711 | but is this the best way to deal with this? */ | ||
712 | BUG_ON(result); | ||
713 | |||
714 | put_free_pages(blkif, data->pages, data->count); | ||
715 | make_response(blkif, pending_req->id, | ||
716 | pending_req->operation, pending_req->status); | ||
717 | free_req(blkif, pending_req); | ||
718 | /* | ||
719 | * Make sure the request is freed before releasing blkif, | ||
720 | * or there could be a race between free_req and the | ||
721 | * cleanup done in xen_blkif_free during shutdown. | ||
722 | * | ||
723 | * NB: The fact that we might try to wake up pending_free_wq | ||
724 | * before drain_complete (in case there's a drain going on) | ||
725 | * it's not a problem with our current implementation | ||
726 | * because we can assure there's no thread waiting on | ||
727 | * pending_free_wq if there's a drain going on, but it has | ||
728 | * to be taken into account if the current model is changed. | ||
729 | */ | ||
730 | if (atomic_dec_and_test(&blkif->inflight) && atomic_read(&blkif->drain)) { | ||
731 | complete(&blkif->drain_complete); | ||
732 | } | ||
733 | xen_blkif_put(blkif); | ||
734 | } | ||
735 | |||
736 | static void xen_blkbk_unmap_and_respond(struct pending_req *req) | ||
737 | { | ||
738 | struct gntab_unmap_queue_data* work = &req->gnttab_unmap_data; | ||
739 | struct xen_blkif *blkif = req->blkif; | ||
740 | struct grant_page **pages = req->segments; | ||
741 | unsigned int invcount; | ||
742 | |||
743 | invcount = xen_blkbk_unmap_prepare(blkif, pages, req->nr_pages, | ||
744 | req->unmap, req->unmap_pages); | ||
745 | |||
746 | work->data = req; | ||
747 | work->done = xen_blkbk_unmap_and_respond_callback; | ||
748 | work->unmap_ops = req->unmap; | ||
749 | work->kunmap_ops = NULL; | ||
750 | work->pages = req->unmap_pages; | ||
751 | work->count = invcount; | ||
752 | |||
753 | gnttab_unmap_refs_async(&req->gnttab_unmap_data); | ||
754 | } | ||
755 | |||
756 | |||
757 | /* | ||
758 | * Unmap the grant references. | ||
759 | * | ||
760 | * This could accumulate ops up to the batch size to reduce the number | ||
761 | * of hypercalls, but since this is only used in error paths there's | ||
762 | * no real need. | ||
763 | */ | ||
764 | static void xen_blkbk_unmap(struct xen_blkif *blkif, | ||
765 | struct grant_page *pages[], | ||
766 | int num) | ||
767 | { | ||
768 | struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | ||
769 | struct page *unmap_pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | ||
770 | unsigned int invcount = 0; | ||
771 | int ret; | ||
772 | |||
773 | while (num) { | ||
774 | unsigned int batch = min(num, BLKIF_MAX_SEGMENTS_PER_REQUEST); | ||
775 | |||
776 | invcount = xen_blkbk_unmap_prepare(blkif, pages, batch, | ||
777 | unmap, unmap_pages); | ||
778 | if (invcount) { | ||
779 | ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount); | ||
683 | BUG_ON(ret); | 780 | BUG_ON(ret); |
684 | put_free_pages(blkif, unmap_pages, invcount); | 781 | put_free_pages(blkif, unmap_pages, invcount); |
685 | invcount = 0; | ||
686 | } | 782 | } |
687 | } | 783 | pages += batch; |
688 | if (invcount) { | 784 | num -= batch; |
689 | ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount); | ||
690 | BUG_ON(ret); | ||
691 | put_free_pages(blkif, unmap_pages, invcount); | ||
692 | } | 785 | } |
693 | } | 786 | } |
694 | 787 | ||
@@ -982,32 +1075,8 @@ static void __end_block_io_op(struct pending_req *pending_req, int error) | |||
982 | * the grant references associated with 'request' and provide | 1075 | * the grant references associated with 'request' and provide |
983 | * the proper response on the ring. | 1076 | * the proper response on the ring. |
984 | */ | 1077 | */ |
985 | if (atomic_dec_and_test(&pending_req->pendcnt)) { | 1078 | if (atomic_dec_and_test(&pending_req->pendcnt)) |
986 | struct xen_blkif *blkif = pending_req->blkif; | 1079 | xen_blkbk_unmap_and_respond(pending_req); |
987 | |||
988 | xen_blkbk_unmap(blkif, | ||
989 | pending_req->segments, | ||
990 | pending_req->nr_pages); | ||
991 | make_response(blkif, pending_req->id, | ||
992 | pending_req->operation, pending_req->status); | ||
993 | free_req(blkif, pending_req); | ||
994 | /* | ||
995 | * Make sure the request is freed before releasing blkif, | ||
996 | * or there could be a race between free_req and the | ||
997 | * cleanup done in xen_blkif_free during shutdown. | ||
998 | * | ||
999 | * NB: The fact that we might try to wake up pending_free_wq | ||
1000 | * before drain_complete (in case there's a drain going on) | ||
1001 | * it's not a problem with our current implementation | ||
1002 | * because we can assure there's no thread waiting on | ||
1003 | * pending_free_wq if there's a drain going on, but it has | ||
1004 | * to be taken into account if the current model is changed. | ||
1005 | */ | ||
1006 | if (atomic_dec_and_test(&blkif->inflight) && atomic_read(&blkif->drain)) { | ||
1007 | complete(&blkif->drain_complete); | ||
1008 | } | ||
1009 | xen_blkif_put(blkif); | ||
1010 | } | ||
1011 | } | 1080 | } |
1012 | 1081 | ||
1013 | /* | 1082 | /* |
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h index f65b807e3236..cc90a840e616 100644 --- a/drivers/block/xen-blkback/common.h +++ b/drivers/block/xen-blkback/common.h | |||
@@ -350,6 +350,9 @@ struct pending_req { | |||
350 | struct grant_page *indirect_pages[MAX_INDIRECT_PAGES]; | 350 | struct grant_page *indirect_pages[MAX_INDIRECT_PAGES]; |
351 | struct seg_buf seg[MAX_INDIRECT_SEGMENTS]; | 351 | struct seg_buf seg[MAX_INDIRECT_SEGMENTS]; |
352 | struct bio *biolist[MAX_INDIRECT_SEGMENTS]; | 352 | struct bio *biolist[MAX_INDIRECT_SEGMENTS]; |
353 | struct gnttab_unmap_grant_ref unmap[MAX_INDIRECT_SEGMENTS]; | ||
354 | struct page *unmap_pages[MAX_INDIRECT_SEGMENTS]; | ||
355 | struct gntab_unmap_queue_data gnttab_unmap_data; | ||
353 | }; | 356 | }; |
354 | 357 | ||
355 | 358 | ||
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c index 037f74f0fcf6..12f9e2708afb 100644 --- a/drivers/net/xen-netback/interface.c +++ b/drivers/net/xen-netback/interface.c | |||
@@ -483,9 +483,8 @@ int xenvif_init_queue(struct xenvif_queue *queue) | |||
483 | * better enable it. The long term solution would be to use just a | 483 | * better enable it. The long term solution would be to use just a |
484 | * bunch of valid page descriptors, without dependency on ballooning | 484 | * bunch of valid page descriptors, without dependency on ballooning |
485 | */ | 485 | */ |
486 | err = alloc_xenballooned_pages(MAX_PENDING_REQS, | 486 | err = gnttab_alloc_pages(MAX_PENDING_REQS, |
487 | queue->mmap_pages, | 487 | queue->mmap_pages); |
488 | false); | ||
489 | if (err) { | 488 | if (err) { |
490 | netdev_err(queue->vif->dev, "Could not reserve mmap_pages\n"); | 489 | netdev_err(queue->vif->dev, "Could not reserve mmap_pages\n"); |
491 | return -ENOMEM; | 490 | return -ENOMEM; |
@@ -664,7 +663,7 @@ void xenvif_disconnect(struct xenvif *vif) | |||
664 | */ | 663 | */ |
665 | void xenvif_deinit_queue(struct xenvif_queue *queue) | 664 | void xenvif_deinit_queue(struct xenvif_queue *queue) |
666 | { | 665 | { |
667 | free_xenballooned_pages(MAX_PENDING_REQS, queue->mmap_pages); | 666 | gnttab_free_pages(MAX_PENDING_REQS, queue->mmap_pages); |
668 | } | 667 | } |
669 | 668 | ||
670 | void xenvif_free(struct xenvif *vif) | 669 | void xenvif_free(struct xenvif *vif) |
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c index c8ce701a7efb..7dc2d64db3cb 100644 --- a/drivers/net/xen-netback/netback.c +++ b/drivers/net/xen-netback/netback.c | |||
@@ -314,9 +314,7 @@ static struct xenvif_rx_meta *get_next_rx_buffer(struct xenvif_queue *queue, | |||
314 | static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb, | 314 | static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb, |
315 | struct netrx_pending_operations *npo, | 315 | struct netrx_pending_operations *npo, |
316 | struct page *page, unsigned long size, | 316 | struct page *page, unsigned long size, |
317 | unsigned long offset, int *head, | 317 | unsigned long offset, int *head) |
318 | struct xenvif_queue *foreign_queue, | ||
319 | grant_ref_t foreign_gref) | ||
320 | { | 318 | { |
321 | struct gnttab_copy *copy_gop; | 319 | struct gnttab_copy *copy_gop; |
322 | struct xenvif_rx_meta *meta; | 320 | struct xenvif_rx_meta *meta; |
@@ -333,6 +331,8 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb | |||
333 | offset &= ~PAGE_MASK; | 331 | offset &= ~PAGE_MASK; |
334 | 332 | ||
335 | while (size > 0) { | 333 | while (size > 0) { |
334 | struct xen_page_foreign *foreign; | ||
335 | |||
336 | BUG_ON(offset >= PAGE_SIZE); | 336 | BUG_ON(offset >= PAGE_SIZE); |
337 | BUG_ON(npo->copy_off > MAX_BUFFER_OFFSET); | 337 | BUG_ON(npo->copy_off > MAX_BUFFER_OFFSET); |
338 | 338 | ||
@@ -361,9 +361,10 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb | |||
361 | copy_gop->flags = GNTCOPY_dest_gref; | 361 | copy_gop->flags = GNTCOPY_dest_gref; |
362 | copy_gop->len = bytes; | 362 | copy_gop->len = bytes; |
363 | 363 | ||
364 | if (foreign_queue) { | 364 | foreign = xen_page_foreign(page); |
365 | copy_gop->source.domid = foreign_queue->vif->domid; | 365 | if (foreign) { |
366 | copy_gop->source.u.ref = foreign_gref; | 366 | copy_gop->source.domid = foreign->domid; |
367 | copy_gop->source.u.ref = foreign->gref; | ||
367 | copy_gop->flags |= GNTCOPY_source_gref; | 368 | copy_gop->flags |= GNTCOPY_source_gref; |
368 | } else { | 369 | } else { |
369 | copy_gop->source.domid = DOMID_SELF; | 370 | copy_gop->source.domid = DOMID_SELF; |
@@ -406,35 +407,6 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb | |||
406 | } | 407 | } |
407 | 408 | ||
408 | /* | 409 | /* |
409 | * Find the grant ref for a given frag in a chain of struct ubuf_info's | ||
410 | * skb: the skb itself | ||
411 | * i: the frag's number | ||
412 | * ubuf: a pointer to an element in the chain. It should not be NULL | ||
413 | * | ||
414 | * Returns a pointer to the element in the chain where the page were found. If | ||
415 | * not found, returns NULL. | ||
416 | * See the definition of callback_struct in common.h for more details about | ||
417 | * the chain. | ||
418 | */ | ||
419 | static const struct ubuf_info *xenvif_find_gref(const struct sk_buff *const skb, | ||
420 | const int i, | ||
421 | const struct ubuf_info *ubuf) | ||
422 | { | ||
423 | struct xenvif_queue *foreign_queue = ubuf_to_queue(ubuf); | ||
424 | |||
425 | do { | ||
426 | u16 pending_idx = ubuf->desc; | ||
427 | |||
428 | if (skb_shinfo(skb)->frags[i].page.p == | ||
429 | foreign_queue->mmap_pages[pending_idx]) | ||
430 | break; | ||
431 | ubuf = (struct ubuf_info *) ubuf->ctx; | ||
432 | } while (ubuf); | ||
433 | |||
434 | return ubuf; | ||
435 | } | ||
436 | |||
437 | /* | ||
438 | * Prepare an SKB to be transmitted to the frontend. | 410 | * Prepare an SKB to be transmitted to the frontend. |
439 | * | 411 | * |
440 | * This function is responsible for allocating grant operations, meta | 412 | * This function is responsible for allocating grant operations, meta |
@@ -459,8 +431,6 @@ static int xenvif_gop_skb(struct sk_buff *skb, | |||
459 | int head = 1; | 431 | int head = 1; |
460 | int old_meta_prod; | 432 | int old_meta_prod; |
461 | int gso_type; | 433 | int gso_type; |
462 | const struct ubuf_info *ubuf = skb_shinfo(skb)->destructor_arg; | ||
463 | const struct ubuf_info *const head_ubuf = ubuf; | ||
464 | 434 | ||
465 | old_meta_prod = npo->meta_prod; | 435 | old_meta_prod = npo->meta_prod; |
466 | 436 | ||
@@ -507,68 +477,16 @@ static int xenvif_gop_skb(struct sk_buff *skb, | |||
507 | len = skb_tail_pointer(skb) - data; | 477 | len = skb_tail_pointer(skb) - data; |
508 | 478 | ||
509 | xenvif_gop_frag_copy(queue, skb, npo, | 479 | xenvif_gop_frag_copy(queue, skb, npo, |
510 | virt_to_page(data), len, offset, &head, | 480 | virt_to_page(data), len, offset, &head); |
511 | NULL, | ||
512 | 0); | ||
513 | data += len; | 481 | data += len; |
514 | } | 482 | } |
515 | 483 | ||
516 | for (i = 0; i < nr_frags; i++) { | 484 | for (i = 0; i < nr_frags; i++) { |
517 | /* This variable also signals whether foreign_gref has a real | ||
518 | * value or not. | ||
519 | */ | ||
520 | struct xenvif_queue *foreign_queue = NULL; | ||
521 | grant_ref_t foreign_gref; | ||
522 | |||
523 | if ((skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) && | ||
524 | (ubuf->callback == &xenvif_zerocopy_callback)) { | ||
525 | const struct ubuf_info *const startpoint = ubuf; | ||
526 | |||
527 | /* Ideally ubuf points to the chain element which | ||
528 | * belongs to this frag. Or if frags were removed from | ||
529 | * the beginning, then shortly before it. | ||
530 | */ | ||
531 | ubuf = xenvif_find_gref(skb, i, ubuf); | ||
532 | |||
533 | /* Try again from the beginning of the list, if we | ||
534 | * haven't tried from there. This only makes sense in | ||
535 | * the unlikely event of reordering the original frags. | ||
536 | * For injected local pages it's an unnecessary second | ||
537 | * run. | ||
538 | */ | ||
539 | if (unlikely(!ubuf) && startpoint != head_ubuf) | ||
540 | ubuf = xenvif_find_gref(skb, i, head_ubuf); | ||
541 | |||
542 | if (likely(ubuf)) { | ||
543 | u16 pending_idx = ubuf->desc; | ||
544 | |||
545 | foreign_queue = ubuf_to_queue(ubuf); | ||
546 | foreign_gref = | ||
547 | foreign_queue->pending_tx_info[pending_idx].req.gref; | ||
548 | /* Just a safety measure. If this was the last | ||
549 | * element on the list, the for loop will | ||
550 | * iterate again if a local page were added to | ||
551 | * the end. Using head_ubuf here prevents the | ||
552 | * second search on the chain. Or the original | ||
553 | * frags changed order, but that's less likely. | ||
554 | * In any way, ubuf shouldn't be NULL. | ||
555 | */ | ||
556 | ubuf = ubuf->ctx ? | ||
557 | (struct ubuf_info *) ubuf->ctx : | ||
558 | head_ubuf; | ||
559 | } else | ||
560 | /* This frag was a local page, added to the | ||
561 | * array after the skb left netback. | ||
562 | */ | ||
563 | ubuf = head_ubuf; | ||
564 | } | ||
565 | xenvif_gop_frag_copy(queue, skb, npo, | 485 | xenvif_gop_frag_copy(queue, skb, npo, |
566 | skb_frag_page(&skb_shinfo(skb)->frags[i]), | 486 | skb_frag_page(&skb_shinfo(skb)->frags[i]), |
567 | skb_frag_size(&skb_shinfo(skb)->frags[i]), | 487 | skb_frag_size(&skb_shinfo(skb)->frags[i]), |
568 | skb_shinfo(skb)->frags[i].page_offset, | 488 | skb_shinfo(skb)->frags[i].page_offset, |
569 | &head, | 489 | &head); |
570 | foreign_queue, | ||
571 | foreign_queue ? foreign_gref : UINT_MAX); | ||
572 | } | 490 | } |
573 | 491 | ||
574 | return npo->meta_prod - old_meta_prod; | 492 | return npo->meta_prod - old_meta_prod; |
@@ -1241,12 +1159,6 @@ static void xenvif_fill_frags(struct xenvif_queue *queue, struct sk_buff *skb) | |||
1241 | /* Take an extra reference to offset network stack's put_page */ | 1159 | /* Take an extra reference to offset network stack's put_page */ |
1242 | get_page(queue->mmap_pages[pending_idx]); | 1160 | get_page(queue->mmap_pages[pending_idx]); |
1243 | } | 1161 | } |
1244 | /* FIXME: __skb_fill_page_desc set this to true because page->pfmemalloc | ||
1245 | * overlaps with "index", and "mapping" is not set. I think mapping | ||
1246 | * should be set. If delivered to local stack, it would drop this | ||
1247 | * skb in sk_filter unless the socket has the right to use it. | ||
1248 | */ | ||
1249 | skb->pfmemalloc = false; | ||
1250 | } | 1162 | } |
1251 | 1163 | ||
1252 | static int xenvif_get_extras(struct xenvif_queue *queue, | 1164 | static int xenvif_get_extras(struct xenvif_queue *queue, |
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 3860d02729dc..0b52d92cb2e5 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c | |||
@@ -92,7 +92,6 @@ EXPORT_SYMBOL_GPL(balloon_stats); | |||
92 | 92 | ||
93 | /* We increase/decrease in batches which fit in a page */ | 93 | /* We increase/decrease in batches which fit in a page */ |
94 | static xen_pfn_t frame_list[PAGE_SIZE / sizeof(unsigned long)]; | 94 | static xen_pfn_t frame_list[PAGE_SIZE / sizeof(unsigned long)]; |
95 | static DEFINE_PER_CPU(struct page *, balloon_scratch_page); | ||
96 | 95 | ||
97 | 96 | ||
98 | /* List of ballooned pages, threaded through the mem_map array. */ | 97 | /* List of ballooned pages, threaded through the mem_map array. */ |
@@ -423,22 +422,12 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) | |||
423 | page = pfn_to_page(pfn); | 422 | page = pfn_to_page(pfn); |
424 | 423 | ||
425 | #ifdef CONFIG_XEN_HAVE_PVMMU | 424 | #ifdef CONFIG_XEN_HAVE_PVMMU |
426 | /* | ||
427 | * Ballooned out frames are effectively replaced with | ||
428 | * a scratch frame. Ensure direct mappings and the | ||
429 | * p2m are consistent. | ||
430 | */ | ||
431 | if (!xen_feature(XENFEAT_auto_translated_physmap)) { | 425 | if (!xen_feature(XENFEAT_auto_translated_physmap)) { |
432 | if (!PageHighMem(page)) { | 426 | if (!PageHighMem(page)) { |
433 | struct page *scratch_page = get_balloon_scratch_page(); | ||
434 | |||
435 | ret = HYPERVISOR_update_va_mapping( | 427 | ret = HYPERVISOR_update_va_mapping( |
436 | (unsigned long)__va(pfn << PAGE_SHIFT), | 428 | (unsigned long)__va(pfn << PAGE_SHIFT), |
437 | pfn_pte(page_to_pfn(scratch_page), | 429 | __pte_ma(0), 0); |
438 | PAGE_KERNEL_RO), 0); | ||
439 | BUG_ON(ret); | 430 | BUG_ON(ret); |
440 | |||
441 | put_balloon_scratch_page(); | ||
442 | } | 431 | } |
443 | __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); | 432 | __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); |
444 | } | 433 | } |
@@ -500,18 +489,6 @@ static void balloon_process(struct work_struct *work) | |||
500 | mutex_unlock(&balloon_mutex); | 489 | mutex_unlock(&balloon_mutex); |
501 | } | 490 | } |
502 | 491 | ||
503 | struct page *get_balloon_scratch_page(void) | ||
504 | { | ||
505 | struct page *ret = get_cpu_var(balloon_scratch_page); | ||
506 | BUG_ON(ret == NULL); | ||
507 | return ret; | ||
508 | } | ||
509 | |||
510 | void put_balloon_scratch_page(void) | ||
511 | { | ||
512 | put_cpu_var(balloon_scratch_page); | ||
513 | } | ||
514 | |||
515 | /* Resets the Xen limit, sets new target, and kicks off processing. */ | 492 | /* Resets the Xen limit, sets new target, and kicks off processing. */ |
516 | void balloon_set_new_target(unsigned long target) | 493 | void balloon_set_new_target(unsigned long target) |
517 | { | 494 | { |
@@ -605,61 +582,13 @@ static void __init balloon_add_region(unsigned long start_pfn, | |||
605 | } | 582 | } |
606 | } | 583 | } |
607 | 584 | ||
608 | static int alloc_balloon_scratch_page(int cpu) | ||
609 | { | ||
610 | if (per_cpu(balloon_scratch_page, cpu) != NULL) | ||
611 | return 0; | ||
612 | |||
613 | per_cpu(balloon_scratch_page, cpu) = alloc_page(GFP_KERNEL); | ||
614 | if (per_cpu(balloon_scratch_page, cpu) == NULL) { | ||
615 | pr_warn("Failed to allocate balloon_scratch_page for cpu %d\n", cpu); | ||
616 | return -ENOMEM; | ||
617 | } | ||
618 | |||
619 | return 0; | ||
620 | } | ||
621 | |||
622 | |||
623 | static int balloon_cpu_notify(struct notifier_block *self, | ||
624 | unsigned long action, void *hcpu) | ||
625 | { | ||
626 | int cpu = (long)hcpu; | ||
627 | switch (action) { | ||
628 | case CPU_UP_PREPARE: | ||
629 | if (alloc_balloon_scratch_page(cpu)) | ||
630 | return NOTIFY_BAD; | ||
631 | break; | ||
632 | default: | ||
633 | break; | ||
634 | } | ||
635 | return NOTIFY_OK; | ||
636 | } | ||
637 | |||
638 | static struct notifier_block balloon_cpu_notifier = { | ||
639 | .notifier_call = balloon_cpu_notify, | ||
640 | }; | ||
641 | |||
642 | static int __init balloon_init(void) | 585 | static int __init balloon_init(void) |
643 | { | 586 | { |
644 | int i, cpu; | 587 | int i; |
645 | 588 | ||
646 | if (!xen_domain()) | 589 | if (!xen_domain()) |
647 | return -ENODEV; | 590 | return -ENODEV; |
648 | 591 | ||
649 | if (!xen_feature(XENFEAT_auto_translated_physmap)) { | ||
650 | register_cpu_notifier(&balloon_cpu_notifier); | ||
651 | |||
652 | get_online_cpus(); | ||
653 | for_each_online_cpu(cpu) { | ||
654 | if (alloc_balloon_scratch_page(cpu)) { | ||
655 | put_online_cpus(); | ||
656 | unregister_cpu_notifier(&balloon_cpu_notifier); | ||
657 | return -ENOMEM; | ||
658 | } | ||
659 | } | ||
660 | put_online_cpus(); | ||
661 | } | ||
662 | |||
663 | pr_info("Initialising balloon driver\n"); | 592 | pr_info("Initialising balloon driver\n"); |
664 | 593 | ||
665 | balloon_stats.current_pages = xen_pv_domain() | 594 | balloon_stats.current_pages = xen_pv_domain() |
@@ -696,15 +625,4 @@ static int __init balloon_init(void) | |||
696 | 625 | ||
697 | subsys_initcall(balloon_init); | 626 | subsys_initcall(balloon_init); |
698 | 627 | ||
699 | static int __init balloon_clear(void) | ||
700 | { | ||
701 | int cpu; | ||
702 | |||
703 | for_each_possible_cpu(cpu) | ||
704 | per_cpu(balloon_scratch_page, cpu) = NULL; | ||
705 | |||
706 | return 0; | ||
707 | } | ||
708 | early_initcall(balloon_clear); | ||
709 | |||
710 | MODULE_LICENSE("GPL"); | 628 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 073b4a19a8b0..d5bb1a33d0a3 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c | |||
@@ -67,7 +67,7 @@ struct gntdev_priv { | |||
67 | * Only populated if populate_freeable_maps == 1 */ | 67 | * Only populated if populate_freeable_maps == 1 */ |
68 | struct list_head freeable_maps; | 68 | struct list_head freeable_maps; |
69 | /* lock protects maps and freeable_maps */ | 69 | /* lock protects maps and freeable_maps */ |
70 | spinlock_t lock; | 70 | struct mutex lock; |
71 | struct mm_struct *mm; | 71 | struct mm_struct *mm; |
72 | struct mmu_notifier mn; | 72 | struct mmu_notifier mn; |
73 | }; | 73 | }; |
@@ -91,7 +91,9 @@ struct grant_map { | |||
91 | struct gnttab_map_grant_ref *map_ops; | 91 | struct gnttab_map_grant_ref *map_ops; |
92 | struct gnttab_unmap_grant_ref *unmap_ops; | 92 | struct gnttab_unmap_grant_ref *unmap_ops; |
93 | struct gnttab_map_grant_ref *kmap_ops; | 93 | struct gnttab_map_grant_ref *kmap_ops; |
94 | struct gnttab_unmap_grant_ref *kunmap_ops; | ||
94 | struct page **pages; | 95 | struct page **pages; |
96 | unsigned long pages_vm_start; | ||
95 | }; | 97 | }; |
96 | 98 | ||
97 | static int unmap_grant_pages(struct grant_map *map, int offset, int pages); | 99 | static int unmap_grant_pages(struct grant_map *map, int offset, int pages); |
@@ -118,12 +120,13 @@ static void gntdev_free_map(struct grant_map *map) | |||
118 | return; | 120 | return; |
119 | 121 | ||
120 | if (map->pages) | 122 | if (map->pages) |
121 | free_xenballooned_pages(map->count, map->pages); | 123 | gnttab_free_pages(map->count, map->pages); |
122 | kfree(map->pages); | 124 | kfree(map->pages); |
123 | kfree(map->grants); | 125 | kfree(map->grants); |
124 | kfree(map->map_ops); | 126 | kfree(map->map_ops); |
125 | kfree(map->unmap_ops); | 127 | kfree(map->unmap_ops); |
126 | kfree(map->kmap_ops); | 128 | kfree(map->kmap_ops); |
129 | kfree(map->kunmap_ops); | ||
127 | kfree(map); | 130 | kfree(map); |
128 | } | 131 | } |
129 | 132 | ||
@@ -140,21 +143,24 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count) | |||
140 | add->map_ops = kcalloc(count, sizeof(add->map_ops[0]), GFP_KERNEL); | 143 | add->map_ops = kcalloc(count, sizeof(add->map_ops[0]), GFP_KERNEL); |
141 | add->unmap_ops = kcalloc(count, sizeof(add->unmap_ops[0]), GFP_KERNEL); | 144 | add->unmap_ops = kcalloc(count, sizeof(add->unmap_ops[0]), GFP_KERNEL); |
142 | add->kmap_ops = kcalloc(count, sizeof(add->kmap_ops[0]), GFP_KERNEL); | 145 | add->kmap_ops = kcalloc(count, sizeof(add->kmap_ops[0]), GFP_KERNEL); |
146 | add->kunmap_ops = kcalloc(count, sizeof(add->kunmap_ops[0]), GFP_KERNEL); | ||
143 | add->pages = kcalloc(count, sizeof(add->pages[0]), GFP_KERNEL); | 147 | add->pages = kcalloc(count, sizeof(add->pages[0]), GFP_KERNEL); |
144 | if (NULL == add->grants || | 148 | if (NULL == add->grants || |
145 | NULL == add->map_ops || | 149 | NULL == add->map_ops || |
146 | NULL == add->unmap_ops || | 150 | NULL == add->unmap_ops || |
147 | NULL == add->kmap_ops || | 151 | NULL == add->kmap_ops || |
152 | NULL == add->kunmap_ops || | ||
148 | NULL == add->pages) | 153 | NULL == add->pages) |
149 | goto err; | 154 | goto err; |
150 | 155 | ||
151 | if (alloc_xenballooned_pages(count, add->pages, false /* lowmem */)) | 156 | if (gnttab_alloc_pages(count, add->pages)) |
152 | goto err; | 157 | goto err; |
153 | 158 | ||
154 | for (i = 0; i < count; i++) { | 159 | for (i = 0; i < count; i++) { |
155 | add->map_ops[i].handle = -1; | 160 | add->map_ops[i].handle = -1; |
156 | add->unmap_ops[i].handle = -1; | 161 | add->unmap_ops[i].handle = -1; |
157 | add->kmap_ops[i].handle = -1; | 162 | add->kmap_ops[i].handle = -1; |
163 | add->kunmap_ops[i].handle = -1; | ||
158 | } | 164 | } |
159 | 165 | ||
160 | add->index = 0; | 166 | add->index = 0; |
@@ -216,9 +222,9 @@ static void gntdev_put_map(struct gntdev_priv *priv, struct grant_map *map) | |||
216 | } | 222 | } |
217 | 223 | ||
218 | if (populate_freeable_maps && priv) { | 224 | if (populate_freeable_maps && priv) { |
219 | spin_lock(&priv->lock); | 225 | mutex_lock(&priv->lock); |
220 | list_del(&map->next); | 226 | list_del(&map->next); |
221 | spin_unlock(&priv->lock); | 227 | mutex_unlock(&priv->lock); |
222 | } | 228 | } |
223 | 229 | ||
224 | if (map->pages && !use_ptemod) | 230 | if (map->pages && !use_ptemod) |
@@ -239,6 +245,14 @@ static int find_grant_ptes(pte_t *pte, pgtable_t token, | |||
239 | BUG_ON(pgnr >= map->count); | 245 | BUG_ON(pgnr >= map->count); |
240 | pte_maddr = arbitrary_virt_to_machine(pte).maddr; | 246 | pte_maddr = arbitrary_virt_to_machine(pte).maddr; |
241 | 247 | ||
248 | /* | ||
249 | * Set the PTE as special to force get_user_pages_fast() fall | ||
250 | * back to the slow path. If this is not supported as part of | ||
251 | * the grant map, it will be done afterwards. | ||
252 | */ | ||
253 | if (xen_feature(XENFEAT_gnttab_map_avail_bits)) | ||
254 | flags |= (1 << _GNTMAP_guest_avail0); | ||
255 | |||
242 | gnttab_set_map_op(&map->map_ops[pgnr], pte_maddr, flags, | 256 | gnttab_set_map_op(&map->map_ops[pgnr], pte_maddr, flags, |
243 | map->grants[pgnr].ref, | 257 | map->grants[pgnr].ref, |
244 | map->grants[pgnr].domid); | 258 | map->grants[pgnr].domid); |
@@ -247,6 +261,15 @@ static int find_grant_ptes(pte_t *pte, pgtable_t token, | |||
247 | return 0; | 261 | return 0; |
248 | } | 262 | } |
249 | 263 | ||
264 | #ifdef CONFIG_X86 | ||
265 | static int set_grant_ptes_as_special(pte_t *pte, pgtable_t token, | ||
266 | unsigned long addr, void *data) | ||
267 | { | ||
268 | set_pte_at(current->mm, addr, pte, pte_mkspecial(*pte)); | ||
269 | return 0; | ||
270 | } | ||
271 | #endif | ||
272 | |||
250 | static int map_grant_pages(struct grant_map *map) | 273 | static int map_grant_pages(struct grant_map *map) |
251 | { | 274 | { |
252 | int i, err = 0; | 275 | int i, err = 0; |
@@ -280,6 +303,8 @@ static int map_grant_pages(struct grant_map *map) | |||
280 | map->flags | GNTMAP_host_map, | 303 | map->flags | GNTMAP_host_map, |
281 | map->grants[i].ref, | 304 | map->grants[i].ref, |
282 | map->grants[i].domid); | 305 | map->grants[i].domid); |
306 | gnttab_set_unmap_op(&map->kunmap_ops[i], address, | ||
307 | map->flags | GNTMAP_host_map, -1); | ||
283 | } | 308 | } |
284 | } | 309 | } |
285 | 310 | ||
@@ -290,20 +315,42 @@ static int map_grant_pages(struct grant_map *map) | |||
290 | return err; | 315 | return err; |
291 | 316 | ||
292 | for (i = 0; i < map->count; i++) { | 317 | for (i = 0; i < map->count; i++) { |
293 | if (map->map_ops[i].status) | 318 | if (map->map_ops[i].status) { |
294 | err = -EINVAL; | 319 | err = -EINVAL; |
295 | else { | 320 | continue; |
296 | BUG_ON(map->map_ops[i].handle == -1); | ||
297 | map->unmap_ops[i].handle = map->map_ops[i].handle; | ||
298 | pr_debug("map handle=%d\n", map->map_ops[i].handle); | ||
299 | } | 321 | } |
322 | |||
323 | map->unmap_ops[i].handle = map->map_ops[i].handle; | ||
324 | if (use_ptemod) | ||
325 | map->kunmap_ops[i].handle = map->kmap_ops[i].handle; | ||
300 | } | 326 | } |
301 | return err; | 327 | return err; |
302 | } | 328 | } |
303 | 329 | ||
330 | struct unmap_grant_pages_callback_data | ||
331 | { | ||
332 | struct completion completion; | ||
333 | int result; | ||
334 | }; | ||
335 | |||
336 | static void unmap_grant_callback(int result, | ||
337 | struct gntab_unmap_queue_data *data) | ||
338 | { | ||
339 | struct unmap_grant_pages_callback_data* d = data->data; | ||
340 | |||
341 | d->result = result; | ||
342 | complete(&d->completion); | ||
343 | } | ||
344 | |||
304 | static int __unmap_grant_pages(struct grant_map *map, int offset, int pages) | 345 | static int __unmap_grant_pages(struct grant_map *map, int offset, int pages) |
305 | { | 346 | { |
306 | int i, err = 0; | 347 | int i, err = 0; |
348 | struct gntab_unmap_queue_data unmap_data; | ||
349 | struct unmap_grant_pages_callback_data data; | ||
350 | |||
351 | init_completion(&data.completion); | ||
352 | unmap_data.data = &data; | ||
353 | unmap_data.done= &unmap_grant_callback; | ||
307 | 354 | ||
308 | if (map->notify.flags & UNMAP_NOTIFY_CLEAR_BYTE) { | 355 | if (map->notify.flags & UNMAP_NOTIFY_CLEAR_BYTE) { |
309 | int pgno = (map->notify.addr >> PAGE_SHIFT); | 356 | int pgno = (map->notify.addr >> PAGE_SHIFT); |
@@ -315,11 +362,16 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages) | |||
315 | } | 362 | } |
316 | } | 363 | } |
317 | 364 | ||
318 | err = gnttab_unmap_refs(map->unmap_ops + offset, | 365 | unmap_data.unmap_ops = map->unmap_ops + offset; |
319 | use_ptemod ? map->kmap_ops + offset : NULL, map->pages + offset, | 366 | unmap_data.kunmap_ops = use_ptemod ? map->kunmap_ops + offset : NULL; |
320 | pages); | 367 | unmap_data.pages = map->pages + offset; |
321 | if (err) | 368 | unmap_data.count = pages; |
322 | return err; | 369 | |
370 | gnttab_unmap_refs_async(&unmap_data); | ||
371 | |||
372 | wait_for_completion(&data.completion); | ||
373 | if (data.result) | ||
374 | return data.result; | ||
323 | 375 | ||
324 | for (i = 0; i < pages; i++) { | 376 | for (i = 0; i < pages; i++) { |
325 | if (map->unmap_ops[offset+i].status) | 377 | if (map->unmap_ops[offset+i].status) |
@@ -387,17 +439,26 @@ static void gntdev_vma_close(struct vm_area_struct *vma) | |||
387 | * not do any unmapping, since that has been done prior to | 439 | * not do any unmapping, since that has been done prior to |
388 | * closing the vma, but it may still iterate the unmap_ops list. | 440 | * closing the vma, but it may still iterate the unmap_ops list. |
389 | */ | 441 | */ |
390 | spin_lock(&priv->lock); | 442 | mutex_lock(&priv->lock); |
391 | map->vma = NULL; | 443 | map->vma = NULL; |
392 | spin_unlock(&priv->lock); | 444 | mutex_unlock(&priv->lock); |
393 | } | 445 | } |
394 | vma->vm_private_data = NULL; | 446 | vma->vm_private_data = NULL; |
395 | gntdev_put_map(priv, map); | 447 | gntdev_put_map(priv, map); |
396 | } | 448 | } |
397 | 449 | ||
450 | static struct page *gntdev_vma_find_special_page(struct vm_area_struct *vma, | ||
451 | unsigned long addr) | ||
452 | { | ||
453 | struct grant_map *map = vma->vm_private_data; | ||
454 | |||
455 | return map->pages[(addr - map->pages_vm_start) >> PAGE_SHIFT]; | ||
456 | } | ||
457 | |||
398 | static struct vm_operations_struct gntdev_vmops = { | 458 | static struct vm_operations_struct gntdev_vmops = { |
399 | .open = gntdev_vma_open, | 459 | .open = gntdev_vma_open, |
400 | .close = gntdev_vma_close, | 460 | .close = gntdev_vma_close, |
461 | .find_special_page = gntdev_vma_find_special_page, | ||
401 | }; | 462 | }; |
402 | 463 | ||
403 | /* ------------------------------------------------------------------ */ | 464 | /* ------------------------------------------------------------------ */ |
@@ -433,14 +494,14 @@ static void mn_invl_range_start(struct mmu_notifier *mn, | |||
433 | struct gntdev_priv *priv = container_of(mn, struct gntdev_priv, mn); | 494 | struct gntdev_priv *priv = container_of(mn, struct gntdev_priv, mn); |
434 | struct grant_map *map; | 495 | struct grant_map *map; |
435 | 496 | ||
436 | spin_lock(&priv->lock); | 497 | mutex_lock(&priv->lock); |
437 | list_for_each_entry(map, &priv->maps, next) { | 498 | list_for_each_entry(map, &priv->maps, next) { |
438 | unmap_if_in_range(map, start, end); | 499 | unmap_if_in_range(map, start, end); |
439 | } | 500 | } |
440 | list_for_each_entry(map, &priv->freeable_maps, next) { | 501 | list_for_each_entry(map, &priv->freeable_maps, next) { |
441 | unmap_if_in_range(map, start, end); | 502 | unmap_if_in_range(map, start, end); |
442 | } | 503 | } |
443 | spin_unlock(&priv->lock); | 504 | mutex_unlock(&priv->lock); |
444 | } | 505 | } |
445 | 506 | ||
446 | static void mn_invl_page(struct mmu_notifier *mn, | 507 | static void mn_invl_page(struct mmu_notifier *mn, |
@@ -457,7 +518,7 @@ static void mn_release(struct mmu_notifier *mn, | |||
457 | struct grant_map *map; | 518 | struct grant_map *map; |
458 | int err; | 519 | int err; |
459 | 520 | ||
460 | spin_lock(&priv->lock); | 521 | mutex_lock(&priv->lock); |
461 | list_for_each_entry(map, &priv->maps, next) { | 522 | list_for_each_entry(map, &priv->maps, next) { |
462 | if (!map->vma) | 523 | if (!map->vma) |
463 | continue; | 524 | continue; |
@@ -476,7 +537,7 @@ static void mn_release(struct mmu_notifier *mn, | |||
476 | err = unmap_grant_pages(map, /* offset */ 0, map->count); | 537 | err = unmap_grant_pages(map, /* offset */ 0, map->count); |
477 | WARN_ON(err); | 538 | WARN_ON(err); |
478 | } | 539 | } |
479 | spin_unlock(&priv->lock); | 540 | mutex_unlock(&priv->lock); |
480 | } | 541 | } |
481 | 542 | ||
482 | static struct mmu_notifier_ops gntdev_mmu_ops = { | 543 | static struct mmu_notifier_ops gntdev_mmu_ops = { |
@@ -498,7 +559,7 @@ static int gntdev_open(struct inode *inode, struct file *flip) | |||
498 | 559 | ||
499 | INIT_LIST_HEAD(&priv->maps); | 560 | INIT_LIST_HEAD(&priv->maps); |
500 | INIT_LIST_HEAD(&priv->freeable_maps); | 561 | INIT_LIST_HEAD(&priv->freeable_maps); |
501 | spin_lock_init(&priv->lock); | 562 | mutex_init(&priv->lock); |
502 | 563 | ||
503 | if (use_ptemod) { | 564 | if (use_ptemod) { |
504 | priv->mm = get_task_mm(current); | 565 | priv->mm = get_task_mm(current); |
@@ -572,10 +633,10 @@ static long gntdev_ioctl_map_grant_ref(struct gntdev_priv *priv, | |||
572 | return -EFAULT; | 633 | return -EFAULT; |
573 | } | 634 | } |
574 | 635 | ||
575 | spin_lock(&priv->lock); | 636 | mutex_lock(&priv->lock); |
576 | gntdev_add_map(priv, map); | 637 | gntdev_add_map(priv, map); |
577 | op.index = map->index << PAGE_SHIFT; | 638 | op.index = map->index << PAGE_SHIFT; |
578 | spin_unlock(&priv->lock); | 639 | mutex_unlock(&priv->lock); |
579 | 640 | ||
580 | if (copy_to_user(u, &op, sizeof(op)) != 0) | 641 | if (copy_to_user(u, &op, sizeof(op)) != 0) |
581 | return -EFAULT; | 642 | return -EFAULT; |
@@ -594,7 +655,7 @@ static long gntdev_ioctl_unmap_grant_ref(struct gntdev_priv *priv, | |||
594 | return -EFAULT; | 655 | return -EFAULT; |
595 | pr_debug("priv %p, del %d+%d\n", priv, (int)op.index, (int)op.count); | 656 | pr_debug("priv %p, del %d+%d\n", priv, (int)op.index, (int)op.count); |
596 | 657 | ||
597 | spin_lock(&priv->lock); | 658 | mutex_lock(&priv->lock); |
598 | map = gntdev_find_map_index(priv, op.index >> PAGE_SHIFT, op.count); | 659 | map = gntdev_find_map_index(priv, op.index >> PAGE_SHIFT, op.count); |
599 | if (map) { | 660 | if (map) { |
600 | list_del(&map->next); | 661 | list_del(&map->next); |
@@ -602,7 +663,7 @@ static long gntdev_ioctl_unmap_grant_ref(struct gntdev_priv *priv, | |||
602 | list_add_tail(&map->next, &priv->freeable_maps); | 663 | list_add_tail(&map->next, &priv->freeable_maps); |
603 | err = 0; | 664 | err = 0; |
604 | } | 665 | } |
605 | spin_unlock(&priv->lock); | 666 | mutex_unlock(&priv->lock); |
606 | if (map) | 667 | if (map) |
607 | gntdev_put_map(priv, map); | 668 | gntdev_put_map(priv, map); |
608 | return err; | 669 | return err; |
@@ -670,7 +731,7 @@ static long gntdev_ioctl_notify(struct gntdev_priv *priv, void __user *u) | |||
670 | out_flags = op.action; | 731 | out_flags = op.action; |
671 | out_event = op.event_channel_port; | 732 | out_event = op.event_channel_port; |
672 | 733 | ||
673 | spin_lock(&priv->lock); | 734 | mutex_lock(&priv->lock); |
674 | 735 | ||
675 | list_for_each_entry(map, &priv->maps, next) { | 736 | list_for_each_entry(map, &priv->maps, next) { |
676 | uint64_t begin = map->index << PAGE_SHIFT; | 737 | uint64_t begin = map->index << PAGE_SHIFT; |
@@ -698,7 +759,7 @@ static long gntdev_ioctl_notify(struct gntdev_priv *priv, void __user *u) | |||
698 | rc = 0; | 759 | rc = 0; |
699 | 760 | ||
700 | unlock_out: | 761 | unlock_out: |
701 | spin_unlock(&priv->lock); | 762 | mutex_unlock(&priv->lock); |
702 | 763 | ||
703 | /* Drop the reference to the event channel we did not save in the map */ | 764 | /* Drop the reference to the event channel we did not save in the map */ |
704 | if (out_flags & UNMAP_NOTIFY_SEND_EVENT) | 765 | if (out_flags & UNMAP_NOTIFY_SEND_EVENT) |
@@ -748,7 +809,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) | |||
748 | pr_debug("map %d+%d at %lx (pgoff %lx)\n", | 809 | pr_debug("map %d+%d at %lx (pgoff %lx)\n", |
749 | index, count, vma->vm_start, vma->vm_pgoff); | 810 | index, count, vma->vm_start, vma->vm_pgoff); |
750 | 811 | ||
751 | spin_lock(&priv->lock); | 812 | mutex_lock(&priv->lock); |
752 | map = gntdev_find_map_index(priv, index, count); | 813 | map = gntdev_find_map_index(priv, index, count); |
753 | if (!map) | 814 | if (!map) |
754 | goto unlock_out; | 815 | goto unlock_out; |
@@ -783,7 +844,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) | |||
783 | map->flags |= GNTMAP_readonly; | 844 | map->flags |= GNTMAP_readonly; |
784 | } | 845 | } |
785 | 846 | ||
786 | spin_unlock(&priv->lock); | 847 | mutex_unlock(&priv->lock); |
787 | 848 | ||
788 | if (use_ptemod) { | 849 | if (use_ptemod) { |
789 | err = apply_to_page_range(vma->vm_mm, vma->vm_start, | 850 | err = apply_to_page_range(vma->vm_mm, vma->vm_start, |
@@ -806,16 +867,34 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) | |||
806 | if (err) | 867 | if (err) |
807 | goto out_put_map; | 868 | goto out_put_map; |
808 | } | 869 | } |
870 | } else { | ||
871 | #ifdef CONFIG_X86 | ||
872 | /* | ||
873 | * If the PTEs were not made special by the grant map | ||
874 | * hypercall, do so here. | ||
875 | * | ||
876 | * This is racy since the mapping is already visible | ||
877 | * to userspace but userspace should be well-behaved | ||
878 | * enough to not touch it until the mmap() call | ||
879 | * returns. | ||
880 | */ | ||
881 | if (!xen_feature(XENFEAT_gnttab_map_avail_bits)) { | ||
882 | apply_to_page_range(vma->vm_mm, vma->vm_start, | ||
883 | vma->vm_end - vma->vm_start, | ||
884 | set_grant_ptes_as_special, NULL); | ||
885 | } | ||
886 | #endif | ||
887 | map->pages_vm_start = vma->vm_start; | ||
809 | } | 888 | } |
810 | 889 | ||
811 | return 0; | 890 | return 0; |
812 | 891 | ||
813 | unlock_out: | 892 | unlock_out: |
814 | spin_unlock(&priv->lock); | 893 | mutex_unlock(&priv->lock); |
815 | return err; | 894 | return err; |
816 | 895 | ||
817 | out_unlock_put: | 896 | out_unlock_put: |
818 | spin_unlock(&priv->lock); | 897 | mutex_unlock(&priv->lock); |
819 | out_put_map: | 898 | out_put_map: |
820 | if (use_ptemod) | 899 | if (use_ptemod) |
821 | map->vma = NULL; | 900 | map->vma = NULL; |
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 7786291ba229..17972fbacddc 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include <linux/io.h> | 42 | #include <linux/io.h> |
43 | #include <linux/delay.h> | 43 | #include <linux/delay.h> |
44 | #include <linux/hardirq.h> | 44 | #include <linux/hardirq.h> |
45 | #include <linux/workqueue.h> | ||
45 | 46 | ||
46 | #include <xen/xen.h> | 47 | #include <xen/xen.h> |
47 | #include <xen/interface/xen.h> | 48 | #include <xen/interface/xen.h> |
@@ -50,6 +51,7 @@ | |||
50 | #include <xen/interface/memory.h> | 51 | #include <xen/interface/memory.h> |
51 | #include <xen/hvc-console.h> | 52 | #include <xen/hvc-console.h> |
52 | #include <xen/swiotlb-xen.h> | 53 | #include <xen/swiotlb-xen.h> |
54 | #include <xen/balloon.h> | ||
53 | #include <asm/xen/hypercall.h> | 55 | #include <asm/xen/hypercall.h> |
54 | #include <asm/xen/interface.h> | 56 | #include <asm/xen/interface.h> |
55 | 57 | ||
@@ -671,6 +673,59 @@ void gnttab_free_auto_xlat_frames(void) | |||
671 | } | 673 | } |
672 | EXPORT_SYMBOL_GPL(gnttab_free_auto_xlat_frames); | 674 | EXPORT_SYMBOL_GPL(gnttab_free_auto_xlat_frames); |
673 | 675 | ||
676 | /** | ||
677 | * gnttab_alloc_pages - alloc pages suitable for grant mapping into | ||
678 | * @nr_pages: number of pages to alloc | ||
679 | * @pages: returns the pages | ||
680 | */ | ||
681 | int gnttab_alloc_pages(int nr_pages, struct page **pages) | ||
682 | { | ||
683 | int i; | ||
684 | int ret; | ||
685 | |||
686 | ret = alloc_xenballooned_pages(nr_pages, pages, false); | ||
687 | if (ret < 0) | ||
688 | return ret; | ||
689 | |||
690 | for (i = 0; i < nr_pages; i++) { | ||
691 | #if BITS_PER_LONG < 64 | ||
692 | struct xen_page_foreign *foreign; | ||
693 | |||
694 | foreign = kzalloc(sizeof(*foreign), GFP_KERNEL); | ||
695 | if (!foreign) { | ||
696 | gnttab_free_pages(nr_pages, pages); | ||
697 | return -ENOMEM; | ||
698 | } | ||
699 | set_page_private(pages[i], (unsigned long)foreign); | ||
700 | #endif | ||
701 | SetPagePrivate(pages[i]); | ||
702 | } | ||
703 | |||
704 | return 0; | ||
705 | } | ||
706 | EXPORT_SYMBOL(gnttab_alloc_pages); | ||
707 | |||
708 | /** | ||
709 | * gnttab_free_pages - free pages allocated by gnttab_alloc_pages() | ||
710 | * @nr_pages; number of pages to free | ||
711 | * @pages: the pages | ||
712 | */ | ||
713 | void gnttab_free_pages(int nr_pages, struct page **pages) | ||
714 | { | ||
715 | int i; | ||
716 | |||
717 | for (i = 0; i < nr_pages; i++) { | ||
718 | if (PagePrivate(pages[i])) { | ||
719 | #if BITS_PER_LONG < 64 | ||
720 | kfree((void *)page_private(pages[i])); | ||
721 | #endif | ||
722 | ClearPagePrivate(pages[i]); | ||
723 | } | ||
724 | } | ||
725 | free_xenballooned_pages(nr_pages, pages); | ||
726 | } | ||
727 | EXPORT_SYMBOL(gnttab_free_pages); | ||
728 | |||
674 | /* Handling of paged out grant targets (GNTST_eagain) */ | 729 | /* Handling of paged out grant targets (GNTST_eagain) */ |
675 | #define MAX_DELAY 256 | 730 | #define MAX_DELAY 256 |
676 | static inline void | 731 | static inline void |
@@ -727,30 +782,87 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, | |||
727 | if (ret) | 782 | if (ret) |
728 | return ret; | 783 | return ret; |
729 | 784 | ||
730 | /* Retry eagain maps */ | 785 | for (i = 0; i < count; i++) { |
731 | for (i = 0; i < count; i++) | 786 | /* Retry eagain maps */ |
732 | if (map_ops[i].status == GNTST_eagain) | 787 | if (map_ops[i].status == GNTST_eagain) |
733 | gnttab_retry_eagain_gop(GNTTABOP_map_grant_ref, map_ops + i, | 788 | gnttab_retry_eagain_gop(GNTTABOP_map_grant_ref, map_ops + i, |
734 | &map_ops[i].status, __func__); | 789 | &map_ops[i].status, __func__); |
735 | 790 | ||
791 | if (map_ops[i].status == GNTST_okay) { | ||
792 | struct xen_page_foreign *foreign; | ||
793 | |||
794 | SetPageForeign(pages[i]); | ||
795 | foreign = xen_page_foreign(pages[i]); | ||
796 | foreign->domid = map_ops[i].dom; | ||
797 | foreign->gref = map_ops[i].ref; | ||
798 | } | ||
799 | } | ||
800 | |||
736 | return set_foreign_p2m_mapping(map_ops, kmap_ops, pages, count); | 801 | return set_foreign_p2m_mapping(map_ops, kmap_ops, pages, count); |
737 | } | 802 | } |
738 | EXPORT_SYMBOL_GPL(gnttab_map_refs); | 803 | EXPORT_SYMBOL_GPL(gnttab_map_refs); |
739 | 804 | ||
740 | int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, | 805 | int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, |
741 | struct gnttab_map_grant_ref *kmap_ops, | 806 | struct gnttab_unmap_grant_ref *kunmap_ops, |
742 | struct page **pages, unsigned int count) | 807 | struct page **pages, unsigned int count) |
743 | { | 808 | { |
809 | unsigned int i; | ||
744 | int ret; | 810 | int ret; |
745 | 811 | ||
746 | ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count); | 812 | ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count); |
747 | if (ret) | 813 | if (ret) |
748 | return ret; | 814 | return ret; |
749 | 815 | ||
750 | return clear_foreign_p2m_mapping(unmap_ops, kmap_ops, pages, count); | 816 | for (i = 0; i < count; i++) |
817 | ClearPageForeign(pages[i]); | ||
818 | |||
819 | return clear_foreign_p2m_mapping(unmap_ops, kunmap_ops, pages, count); | ||
751 | } | 820 | } |
752 | EXPORT_SYMBOL_GPL(gnttab_unmap_refs); | 821 | EXPORT_SYMBOL_GPL(gnttab_unmap_refs); |
753 | 822 | ||
823 | #define GNTTAB_UNMAP_REFS_DELAY 5 | ||
824 | |||
825 | static void __gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item); | ||
826 | |||
827 | static void gnttab_unmap_work(struct work_struct *work) | ||
828 | { | ||
829 | struct gntab_unmap_queue_data | ||
830 | *unmap_data = container_of(work, | ||
831 | struct gntab_unmap_queue_data, | ||
832 | gnttab_work.work); | ||
833 | if (unmap_data->age != UINT_MAX) | ||
834 | unmap_data->age++; | ||
835 | __gnttab_unmap_refs_async(unmap_data); | ||
836 | } | ||
837 | |||
838 | static void __gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item) | ||
839 | { | ||
840 | int ret; | ||
841 | int pc; | ||
842 | |||
843 | for (pc = 0; pc < item->count; pc++) { | ||
844 | if (page_count(item->pages[pc]) > 1) { | ||
845 | unsigned long delay = GNTTAB_UNMAP_REFS_DELAY * (item->age + 1); | ||
846 | schedule_delayed_work(&item->gnttab_work, | ||
847 | msecs_to_jiffies(delay)); | ||
848 | return; | ||
849 | } | ||
850 | } | ||
851 | |||
852 | ret = gnttab_unmap_refs(item->unmap_ops, item->kunmap_ops, | ||
853 | item->pages, item->count); | ||
854 | item->done(ret, item); | ||
855 | } | ||
856 | |||
857 | void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item) | ||
858 | { | ||
859 | INIT_DELAYED_WORK(&item->gnttab_work, gnttab_unmap_work); | ||
860 | item->age = 0; | ||
861 | |||
862 | __gnttab_unmap_refs_async(item); | ||
863 | } | ||
864 | EXPORT_SYMBOL_GPL(gnttab_unmap_refs_async); | ||
865 | |||
754 | static int gnttab_map_frames_v1(xen_pfn_t *frames, unsigned int nr_gframes) | 866 | static int gnttab_map_frames_v1(xen_pfn_t *frames, unsigned int nr_gframes) |
755 | { | 867 | { |
756 | int rc; | 868 | int rc; |
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index f8bb36f9d9ce..bf1940706422 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c | |||
@@ -105,10 +105,16 @@ static void do_suspend(void) | |||
105 | 105 | ||
106 | err = freeze_processes(); | 106 | err = freeze_processes(); |
107 | if (err) { | 107 | if (err) { |
108 | pr_err("%s: freeze failed %d\n", __func__, err); | 108 | pr_err("%s: freeze processes failed %d\n", __func__, err); |
109 | goto out; | 109 | goto out; |
110 | } | 110 | } |
111 | 111 | ||
112 | err = freeze_kernel_threads(); | ||
113 | if (err) { | ||
114 | pr_err("%s: freeze kernel threads failed %d\n", __func__, err); | ||
115 | goto out_thaw; | ||
116 | } | ||
117 | |||
112 | err = dpm_suspend_start(PMSG_FREEZE); | 118 | err = dpm_suspend_start(PMSG_FREEZE); |
113 | if (err) { | 119 | if (err) { |
114 | pr_err("%s: dpm_suspend_start %d\n", __func__, err); | 120 | pr_err("%s: dpm_suspend_start %d\n", __func__, err); |
diff --git a/drivers/xen/tmem.c b/drivers/xen/tmem.c index 83b5c53bec6b..8a65423bc696 100644 --- a/drivers/xen/tmem.c +++ b/drivers/xen/tmem.c | |||
@@ -374,7 +374,7 @@ static struct frontswap_ops tmem_frontswap_ops = { | |||
374 | }; | 374 | }; |
375 | #endif | 375 | #endif |
376 | 376 | ||
377 | static int xen_tmem_init(void) | 377 | static int __init xen_tmem_init(void) |
378 | { | 378 | { |
379 | if (!xen_domain()) | 379 | if (!xen_domain()) |
380 | return 0; | 380 | return 0; |
diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index e999496eda3e..ecd540a7a562 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c | |||
@@ -227,7 +227,7 @@ static void put_free_pages(struct page **page, int num) | |||
227 | return; | 227 | return; |
228 | if (i > scsiback_max_buffer_pages) { | 228 | if (i > scsiback_max_buffer_pages) { |
229 | n = min(num, i - scsiback_max_buffer_pages); | 229 | n = min(num, i - scsiback_max_buffer_pages); |
230 | free_xenballooned_pages(n, page + num - n); | 230 | gnttab_free_pages(n, page + num - n); |
231 | n = num - n; | 231 | n = num - n; |
232 | } | 232 | } |
233 | spin_lock_irqsave(&free_pages_lock, flags); | 233 | spin_lock_irqsave(&free_pages_lock, flags); |
@@ -244,7 +244,7 @@ static int get_free_page(struct page **page) | |||
244 | spin_lock_irqsave(&free_pages_lock, flags); | 244 | spin_lock_irqsave(&free_pages_lock, flags); |
245 | if (list_empty(&scsiback_free_pages)) { | 245 | if (list_empty(&scsiback_free_pages)) { |
246 | spin_unlock_irqrestore(&free_pages_lock, flags); | 246 | spin_unlock_irqrestore(&free_pages_lock, flags); |
247 | return alloc_xenballooned_pages(1, page, false); | 247 | return gnttab_alloc_pages(1, page); |
248 | } | 248 | } |
249 | page[0] = list_first_entry(&scsiback_free_pages, struct page, lru); | 249 | page[0] = list_first_entry(&scsiback_free_pages, struct page, lru); |
250 | list_del(&page[0]->lru); | 250 | list_del(&page[0]->lru); |
@@ -2106,7 +2106,7 @@ static void __exit scsiback_exit(void) | |||
2106 | while (free_pages_num) { | 2106 | while (free_pages_num) { |
2107 | if (get_free_page(&page)) | 2107 | if (get_free_page(&page)) |
2108 | BUG(); | 2108 | BUG(); |
2109 | free_xenballooned_pages(1, &page); | 2109 | gnttab_free_pages(1, &page); |
2110 | } | 2110 | } |
2111 | scsiback_deregister_configfs(); | 2111 | scsiback_deregister_configfs(); |
2112 | xenbus_unregister_driver(&scsiback_driver); | 2112 | xenbus_unregister_driver(&scsiback_driver); |
diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c index 85534ea63555..9433e46518c8 100644 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c | |||
@@ -326,10 +326,13 @@ static int xenbus_write_transaction(unsigned msg_type, | |||
326 | } | 326 | } |
327 | 327 | ||
328 | if (msg_type == XS_TRANSACTION_START) { | 328 | if (msg_type == XS_TRANSACTION_START) { |
329 | trans->handle.id = simple_strtoul(reply, NULL, 0); | 329 | if (u->u.msg.type == XS_ERROR) |
330 | 330 | kfree(trans); | |
331 | list_add(&trans->list, &u->transactions); | 331 | else { |
332 | } else if (msg_type == XS_TRANSACTION_END) { | 332 | trans->handle.id = simple_strtoul(reply, NULL, 0); |
333 | list_add(&trans->list, &u->transactions); | ||
334 | } | ||
335 | } else if (u->u.msg.type == XS_TRANSACTION_END) { | ||
333 | list_for_each_entry(trans, &u->transactions, list) | 336 | list_for_each_entry(trans, &u->transactions, list) |
334 | if (trans->handle.id == u->u.msg.tx_id) | 337 | if (trans->handle.id == u->u.msg.tx_id) |
335 | break; | 338 | break; |