aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen/grant-table.c
diff options
context:
space:
mode:
authorZoltan Kiss <zoltan.kiss@citrix.com>2014-01-23 16:23:44 -0500
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2014-01-31 09:48:32 -0500
commit08ece5bb2312b4510b161a6ef6682f37f4eac8a1 (patch)
treed331f6b82ca8f0346afdf54bc793fb10c4bdaec8 /drivers/xen/grant-table.c
parent47c542050d306e50f09512eb6339dbf2fc02fddd (diff)
xen/grant-table: Avoid m2p_override during mapping
The grant mapping API does m2p_override unnecessarily: only gntdev needs it, for blkback and future netback patches it just cause a lock contention, as those pages never go to userspace. Therefore this series does the following: - the original functions were renamed to __gnttab_[un]map_refs, with a new parameter m2p_override - based on m2p_override either they follow the original behaviour, or just set the private flag and call set_phys_to_machine - gnttab_[un]map_refs are now a wrapper to call __gnttab_[un]map_refs with m2p_override false - a new function gnttab_[un]map_refs_userspace provides the old behaviour It also removes a stray space from page.h and change ret to 0 if XENFEAT_auto_translated_physmap, as that is the only possible return value there. v2: - move the storing of the old mfn in page->index to gnttab_map_refs - move the function header update to a separate patch v3: - a new approach to retain old behaviour where it needed - squash the patches into one v4: - move out the common bits from m2p* functions, and pass pfn/mfn as parameter - clear page->private before doing anything with the page, so m2p_find_override won't race with this v5: - change return value handling in __gnttab_[un]map_refs - remove a stray space in page.h - add detail why ret = 0 now at some places v6: - don't pass pfn to m2p* functions, just get it locally Signed-off-by: Zoltan Kiss <zoltan.kiss@citrix.com> Suggested-by: David Vrabel <david.vrabel@citrix.com> Acked-by: David Vrabel <david.vrabel@citrix.com> Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/xen/grant-table.c')
-rw-r--r--drivers/xen/grant-table.c89
1 files changed, 76 insertions, 13 deletions
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index b84e3ab839aa..8ee13e2e45e2 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -928,15 +928,17 @@ 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)
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
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}
990EXPORT_SYMBOL_GPL(gnttab_map_refs); 1012EXPORT_SYMBOL_GPL(gnttab_map_refs);
991 1013
992int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, 1014int 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}
1020EXPORT_SYMBOL_GPL(gnttab_map_refs_userspace);
1021
1022int __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
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}
1030EXPORT_SYMBOL_GPL(gnttab_unmap_refs); 1085EXPORT_SYMBOL_GPL(gnttab_unmap_refs);
1031 1086
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
1032static unsigned nr_status_frames(unsigned nr_grant_frames) 1095static 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);