aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/xen-blkback/blkback.c15
-rw-r--r--drivers/xen/gntdev.c13
-rw-r--r--drivers/xen/grant-table.c89
3 files changed, 27 insertions, 90 deletions
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index da18046d0e07..4b97b86da926 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -285,7 +285,8 @@ 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, pages, segs_to_unmap); 288 ret = gnttab_unmap_refs(unmap, NULL, pages,
289 segs_to_unmap);
289 BUG_ON(ret); 290 BUG_ON(ret);
290 put_free_pages(blkif, pages, segs_to_unmap); 291 put_free_pages(blkif, pages, segs_to_unmap);
291 segs_to_unmap = 0; 292 segs_to_unmap = 0;
@@ -320,7 +321,8 @@ static void unmap_purged_grants(struct work_struct *work)
320 pages[segs_to_unmap] = persistent_gnt->page; 321 pages[segs_to_unmap] = persistent_gnt->page;
321 322
322 if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) { 323 if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
323 ret = gnttab_unmap_refs(unmap, pages, segs_to_unmap); 324 ret = gnttab_unmap_refs(unmap, NULL, pages,
325 segs_to_unmap);
324 BUG_ON(ret); 326 BUG_ON(ret);
325 put_free_pages(blkif, pages, segs_to_unmap); 327 put_free_pages(blkif, pages, segs_to_unmap);
326 segs_to_unmap = 0; 328 segs_to_unmap = 0;
@@ -328,7 +330,7 @@ static void unmap_purged_grants(struct work_struct *work)
328 kfree(persistent_gnt); 330 kfree(persistent_gnt);
329 } 331 }
330 if (segs_to_unmap > 0) { 332 if (segs_to_unmap > 0) {
331 ret = gnttab_unmap_refs(unmap, pages, segs_to_unmap); 333 ret = gnttab_unmap_refs(unmap, NULL, pages, segs_to_unmap);
332 BUG_ON(ret); 334 BUG_ON(ret);
333 put_free_pages(blkif, pages, segs_to_unmap); 335 put_free_pages(blkif, pages, segs_to_unmap);
334 } 336 }
@@ -668,14 +670,15 @@ static void xen_blkbk_unmap(struct xen_blkif *blkif,
668 GNTMAP_host_map, pages[i]->handle); 670 GNTMAP_host_map, pages[i]->handle);
669 pages[i]->handle = BLKBACK_INVALID_HANDLE; 671 pages[i]->handle = BLKBACK_INVALID_HANDLE;
670 if (++invcount == BLKIF_MAX_SEGMENTS_PER_REQUEST) { 672 if (++invcount == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
671 ret = gnttab_unmap_refs(unmap, unmap_pages, invcount); 673 ret = gnttab_unmap_refs(unmap, NULL, unmap_pages,
674 invcount);
672 BUG_ON(ret); 675 BUG_ON(ret);
673 put_free_pages(blkif, unmap_pages, invcount); 676 put_free_pages(blkif, unmap_pages, invcount);
674 invcount = 0; 677 invcount = 0;
675 } 678 }
676 } 679 }
677 if (invcount) { 680 if (invcount) {
678 ret = gnttab_unmap_refs(unmap, unmap_pages, invcount); 681 ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount);
679 BUG_ON(ret); 682 BUG_ON(ret);
680 put_free_pages(blkif, unmap_pages, invcount); 683 put_free_pages(blkif, unmap_pages, invcount);
681 } 684 }
@@ -737,7 +740,7 @@ again:
737 } 740 }
738 741
739 if (segs_to_map) { 742 if (segs_to_map) {
740 ret = gnttab_map_refs(map, pages_to_gnt, segs_to_map); 743 ret = gnttab_map_refs(map, NULL, pages_to_gnt, segs_to_map);
741 BUG_ON(ret); 744 BUG_ON(ret);
742 } 745 }
743 746
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index 34a2704fbc88..073b4a19a8b0 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -284,10 +284,8 @@ static int map_grant_pages(struct grant_map *map)
284 } 284 }
285 285
286 pr_debug("map %d+%d\n", map->index, map->count); 286 pr_debug("map %d+%d\n", map->index, map->count);
287 err = gnttab_map_refs_userspace(map->map_ops, 287 err = gnttab_map_refs(map->map_ops, use_ptemod ? map->kmap_ops : NULL,
288 use_ptemod ? map->kmap_ops : NULL, 288 map->pages, map->count);
289 map->pages,
290 map->count);
291 if (err) 289 if (err)
292 return err; 290 return err;
293 291
@@ -317,10 +315,9 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
317 } 315 }
318 } 316 }
319 317
320 err = gnttab_unmap_refs_userspace(map->unmap_ops + offset, 318 err = gnttab_unmap_refs(map->unmap_ops + offset,
321 use_ptemod ? map->kmap_ops + offset : NULL, 319 use_ptemod ? map->kmap_ops + offset : NULL, map->pages + offset,
322 map->pages + offset, 320 pages);
323 pages);
324 if (err) 321 if (err)
325 return err; 322 return err;
326 323
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 8ee13e2e45e2..b84e3ab839aa 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -928,17 +928,15 @@ void gnttab_batch_copy(struct gnttab_copy *batch, unsigned count)
928} 928}
929EXPORT_SYMBOL_GPL(gnttab_batch_copy); 929EXPORT_SYMBOL_GPL(gnttab_batch_copy);
930 930
931int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, 931int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
932 struct gnttab_map_grant_ref *kmap_ops, 932 struct gnttab_map_grant_ref *kmap_ops,
933 struct page **pages, unsigned int count, 933 struct page **pages, unsigned int count)
934 bool m2p_override)
935{ 934{
936 int i, ret; 935 int i, ret;
937 bool lazy = false; 936 bool lazy = false;
938 pte_t *pte; 937 pte_t *pte;
939 unsigned long mfn, pfn; 938 unsigned long mfn;
940 939
941 BUG_ON(kmap_ops && !m2p_override);
942 ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map_ops, count); 940 ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map_ops, count);
943 if (ret) 941 if (ret)
944 return ret; 942 return ret;
@@ -957,12 +955,10 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
957 set_phys_to_machine(map_ops[i].host_addr >> PAGE_SHIFT, 955 set_phys_to_machine(map_ops[i].host_addr >> PAGE_SHIFT,
958 map_ops[i].dev_bus_addr >> PAGE_SHIFT); 956 map_ops[i].dev_bus_addr >> PAGE_SHIFT);
959 } 957 }
960 return 0; 958 return ret;
961 } 959 }
962 960
963 if (m2p_override && 961 if (!in_interrupt() && paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
964 !in_interrupt() &&
965 paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
966 arch_enter_lazy_mmu_mode(); 962 arch_enter_lazy_mmu_mode();
967 lazy = true; 963 lazy = true;
968 } 964 }
@@ -979,20 +975,8 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
979 } else { 975 } else {
980 mfn = PFN_DOWN(map_ops[i].dev_bus_addr); 976 mfn = PFN_DOWN(map_ops[i].dev_bus_addr);
981 } 977 }
982 pfn = page_to_pfn(pages[i]); 978 ret = m2p_add_override(mfn, pages[i], kmap_ops ?
983 979 &kmap_ops[i] : NULL);
984 WARN_ON(PagePrivate(pages[i]));
985 SetPagePrivate(pages[i]);
986 set_page_private(pages[i], mfn);
987
988 pages[i]->index = pfn_to_mfn(pfn);
989 if (unlikely(!set_phys_to_machine(pfn, FOREIGN_FRAME(mfn)))) {
990 ret = -ENOMEM;
991 goto out;
992 }
993 if (m2p_override)
994 ret = m2p_add_override(mfn, pages[i], kmap_ops ?
995 &kmap_ops[i] : NULL);
996 if (ret) 980 if (ret)
997 goto out; 981 goto out;
998 } 982 }
@@ -1003,32 +987,15 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
1003 987
1004 return ret; 988 return ret;
1005} 989}
1006
1007int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
1008 struct page **pages, unsigned int count)
1009{
1010 return __gnttab_map_refs(map_ops, NULL, pages, count, false);
1011}
1012EXPORT_SYMBOL_GPL(gnttab_map_refs); 990EXPORT_SYMBOL_GPL(gnttab_map_refs);
1013 991
1014int gnttab_map_refs_userspace(struct gnttab_map_grant_ref *map_ops, 992int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1015 struct gnttab_map_grant_ref *kmap_ops,
1016 struct page **pages, unsigned int count)
1017{
1018 return __gnttab_map_refs(map_ops, kmap_ops, pages, count, true);
1019}
1020EXPORT_SYMBOL_GPL(gnttab_map_refs_userspace);
1021
1022int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1023 struct gnttab_map_grant_ref *kmap_ops, 993 struct gnttab_map_grant_ref *kmap_ops,
1024 struct page **pages, unsigned int count, 994 struct page **pages, unsigned int count)
1025 bool m2p_override)
1026{ 995{
1027 int i, ret; 996 int i, ret;
1028 bool lazy = false; 997 bool lazy = false;
1029 unsigned long pfn, mfn;
1030 998
1031 BUG_ON(kmap_ops && !m2p_override);
1032 ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count); 999 ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count);
1033 if (ret) 1000 if (ret)
1034 return ret; 1001 return ret;
@@ -1039,33 +1006,17 @@ int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1039 set_phys_to_machine(unmap_ops[i].host_addr >> PAGE_SHIFT, 1006 set_phys_to_machine(unmap_ops[i].host_addr >> PAGE_SHIFT,
1040 INVALID_P2M_ENTRY); 1007 INVALID_P2M_ENTRY);
1041 } 1008 }
1042 return 0; 1009 return ret;
1043 } 1010 }
1044 1011
1045 if (m2p_override && 1012 if (!in_interrupt() && paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
1046 !in_interrupt() &&
1047 paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
1048 arch_enter_lazy_mmu_mode(); 1013 arch_enter_lazy_mmu_mode();
1049 lazy = true; 1014 lazy = true;
1050 } 1015 }
1051 1016
1052 for (i = 0; i < count; i++) { 1017 for (i = 0; i < count; i++) {
1053 pfn = page_to_pfn(pages[i]); 1018 ret = m2p_remove_override(pages[i], kmap_ops ?
1054 mfn = get_phys_to_machine(pfn); 1019 &kmap_ops[i] : NULL);
1055 if (mfn == INVALID_P2M_ENTRY || !(mfn & FOREIGN_FRAME_BIT)) {
1056 ret = -EINVAL;
1057 goto out;
1058 }
1059
1060 set_page_private(pages[i], INVALID_P2M_ENTRY);
1061 WARN_ON(!PagePrivate(pages[i]));
1062 ClearPagePrivate(pages[i]);
1063 set_phys_to_machine(pfn, pages[i]->index);
1064 if (m2p_override)
1065 ret = m2p_remove_override(pages[i],
1066 kmap_ops ?
1067 &kmap_ops[i] : NULL,
1068 mfn);
1069 if (ret) 1020 if (ret)
1070 goto out; 1021 goto out;
1071 } 1022 }
@@ -1076,22 +1027,8 @@ int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1076 1027
1077 return ret; 1028 return ret;
1078} 1029}
1079
1080int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *map_ops,
1081 struct page **pages, unsigned int count)
1082{
1083 return __gnttab_unmap_refs(map_ops, NULL, pages, count, false);
1084}
1085EXPORT_SYMBOL_GPL(gnttab_unmap_refs); 1030EXPORT_SYMBOL_GPL(gnttab_unmap_refs);
1086 1031
1087int gnttab_unmap_refs_userspace(struct gnttab_unmap_grant_ref *map_ops,
1088 struct gnttab_map_grant_ref *kmap_ops,
1089 struct page **pages, unsigned int count)
1090{
1091 return __gnttab_unmap_refs(map_ops, kmap_ops, pages, count, true);
1092}
1093EXPORT_SYMBOL_GPL(gnttab_unmap_refs_userspace);
1094
1095static unsigned nr_status_frames(unsigned nr_grant_frames) 1032static unsigned nr_status_frames(unsigned nr_grant_frames)
1096{ 1033{
1097 BUG_ON(grefs_per_grant_frame == 0); 1034 BUG_ON(grefs_per_grant_frame == 0);