Skip to content

Commit e85fc98

Browse files
committed
Revert "xen/grant-table: Avoid m2p_override during mapping"
This reverts commit 08ece5b. As it breaks ARM builds and needs more attention on the ARM side. Acked-by: David Vrabel <[email protected]> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
1 parent f93576e commit e85fc98

File tree

6 files changed

+46
-101
lines changed

6 files changed

+46
-101
lines changed

arch/x86/include/asm/xen/page.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ extern unsigned long set_phys_range_identity(unsigned long pfn_s,
5252
extern int m2p_add_override(unsigned long mfn, struct page *page,
5353
struct gnttab_map_grant_ref *kmap_op);
5454
extern int m2p_remove_override(struct page *page,
55-
struct gnttab_map_grant_ref *kmap_op,
56-
unsigned long mfn);
55+
struct gnttab_map_grant_ref *kmap_op);
5756
extern struct page *m2p_find_override(unsigned long mfn);
5857
extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
5958

@@ -122,7 +121,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
122121
pfn = m2p_find_override_pfn(mfn, ~0);
123122
}
124123

125-
/*
124+
/*
126125
* pfn is ~0 if there are no entries in the m2p for mfn or if the
127126
* entry doesn't map back to the mfn and m2p_override doesn't have a
128127
* valid entry for it.

arch/x86/xen/p2m.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,13 @@ int m2p_add_override(unsigned long mfn, struct page *page,
899899
"m2p_add_override: pfn %lx not mapped", pfn))
900900
return -EINVAL;
901901
}
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;
902909

903910
if (kmap_op != NULL) {
904911
if (!PageHighMem(page)) {
@@ -937,16 +944,19 @@ int m2p_add_override(unsigned long mfn, struct page *page,
937944
}
938945
EXPORT_SYMBOL_GPL(m2p_add_override);
939946
int m2p_remove_override(struct page *page,
940-
struct gnttab_map_grant_ref *kmap_op,
941-
unsigned long mfn)
947+
struct gnttab_map_grant_ref *kmap_op)
942948
{
943949
unsigned long flags;
950+
unsigned long mfn;
944951
unsigned long pfn;
945952
unsigned long uninitialized_var(address);
946953
unsigned level;
947954
pte_t *ptep = NULL;
948955

949956
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;
950960

951961
if (!PageHighMem(page)) {
952962
address = (unsigned long)__va(pfn << PAGE_SHIFT);
@@ -960,7 +970,10 @@ int m2p_remove_override(struct page *page,
960970
spin_lock_irqsave(&m2p_override_lock, flags);
961971
list_del(&page->lru);
962972
spin_unlock_irqrestore(&m2p_override_lock, flags);
973+
WARN_ON(!PagePrivate(page));
974+
ClearPagePrivate(page);
963975

976+
set_phys_to_machine(pfn, page->index);
964977
if (kmap_op != NULL) {
965978
if (!PageHighMem(page)) {
966979
struct multicall_space mcs;

drivers/block/xen-blkback/blkback.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
285285

286286
if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST ||
287287
!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);
289290
BUG_ON(ret);
290291
put_free_pages(blkif, pages, segs_to_unmap);
291292
segs_to_unmap = 0;
@@ -320,15 +321,16 @@ static void unmap_purged_grants(struct work_struct *work)
320321
pages[segs_to_unmap] = persistent_gnt->page;
321322

322323
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);
324326
BUG_ON(ret);
325327
put_free_pages(blkif, pages, segs_to_unmap);
326328
segs_to_unmap = 0;
327329
}
328330
kfree(persistent_gnt);
329331
}
330332
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);
332334
BUG_ON(ret);
333335
put_free_pages(blkif, pages, segs_to_unmap);
334336
}
@@ -668,14 +670,15 @@ static void xen_blkbk_unmap(struct xen_blkif *blkif,
668670
GNTMAP_host_map, pages[i]->handle);
669671
pages[i]->handle = BLKBACK_INVALID_HANDLE;
670672
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);
672675
BUG_ON(ret);
673676
put_free_pages(blkif, unmap_pages, invcount);
674677
invcount = 0;
675678
}
676679
}
677680
if (invcount) {
678-
ret = gnttab_unmap_refs(unmap, unmap_pages, invcount);
681+
ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount);
679682
BUG_ON(ret);
680683
put_free_pages(blkif, unmap_pages, invcount);
681684
}
@@ -737,7 +740,7 @@ static int xen_blkbk_map(struct xen_blkif *blkif,
737740
}
738741

739742
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);
741744
BUG_ON(ret);
742745
}
743746

drivers/xen/gntdev.c

+5-8
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,8 @@ static int map_grant_pages(struct grant_map *map)
284284
}
285285

286286
pr_debug("map %d+%d\n", map->index, map->count);
287-
err = gnttab_map_refs_userspace(map->map_ops,
288-
use_ptemod ? map->kmap_ops : NULL,
289-
map->pages,
290-
map->count);
287+
err = gnttab_map_refs(map->map_ops, use_ptemod ? map->kmap_ops : NULL,
288+
map->pages, map->count);
291289
if (err)
292290
return err;
293291

@@ -317,10 +315,9 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
317315
}
318316
}
319317

320-
err = gnttab_unmap_refs_userspace(map->unmap_ops + offset,
321-
use_ptemod ? map->kmap_ops + offset : NULL,
322-
map->pages + offset,
323-
pages);
318+
err = gnttab_unmap_refs(map->unmap_ops + offset,
319+
use_ptemod ? map->kmap_ops + offset : NULL, map->pages + offset,
320+
pages);
324321
if (err)
325322
return err;
326323

drivers/xen/grant-table.c

+13-76
Original file line numberDiff line numberDiff line change
@@ -928,17 +928,15 @@ void gnttab_batch_copy(struct gnttab_copy *batch, unsigned count)
928928
}
929929
EXPORT_SYMBOL_GPL(gnttab_batch_copy);
930930

931-
int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
931+
int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
932932
struct gnttab_map_grant_ref *kmap_ops,
933-
struct page **pages, unsigned int count,
934-
bool m2p_override)
933+
struct page **pages, unsigned int count)
935934
{
936935
int i, ret;
937936
bool lazy = false;
938937
pte_t *pte;
939-
unsigned long mfn, pfn;
938+
unsigned long mfn;
940939

941-
BUG_ON(kmap_ops && !m2p_override);
942940
ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map_ops, count);
943941
if (ret)
944942
return ret;
@@ -957,12 +955,10 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
957955
set_phys_to_machine(map_ops[i].host_addr >> PAGE_SHIFT,
958956
map_ops[i].dev_bus_addr >> PAGE_SHIFT);
959957
}
960-
return 0;
958+
return ret;
961959
}
962960

963-
if (m2p_override &&
964-
!in_interrupt() &&
965-
paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
961+
if (!in_interrupt() && paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
966962
arch_enter_lazy_mmu_mode();
967963
lazy = true;
968964
}
@@ -979,20 +975,8 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
979975
} else {
980976
mfn = PFN_DOWN(map_ops[i].dev_bus_addr);
981977
}
982-
pfn = page_to_pfn(pages[i]);
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);
978+
ret = m2p_add_override(mfn, pages[i], kmap_ops ?
979+
&kmap_ops[i] : NULL);
996980
if (ret)
997981
goto out;
998982
}
@@ -1003,32 +987,15 @@ int __gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
1003987

1004988
return ret;
1005989
}
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-
}
1012990
EXPORT_SYMBOL_GPL(gnttab_map_refs);
1013991

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,
992+
int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
1023993
struct gnttab_map_grant_ref *kmap_ops,
1024-
struct page **pages, unsigned int count,
1025-
bool m2p_override)
994+
struct page **pages, unsigned int count)
1026995
{
1027996
int i, ret;
1028997
bool lazy = false;
1029-
unsigned long pfn, mfn;
1030998

1031-
BUG_ON(kmap_ops && !m2p_override);
1032999
ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count);
10331000
if (ret)
10341001
return ret;
@@ -1039,33 +1006,17 @@ int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
10391006
set_phys_to_machine(unmap_ops[i].host_addr >> PAGE_SHIFT,
10401007
INVALID_P2M_ENTRY);
10411008
}
1042-
return 0;
1009+
return ret;
10431010
}
10441011

1045-
if (m2p_override &&
1046-
!in_interrupt() &&
1047-
paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
1012+
if (!in_interrupt() && paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
10481013
arch_enter_lazy_mmu_mode();
10491014
lazy = true;
10501015
}
10511016

10521017
for (i = 0; i < count; i++) {
1053-
pfn = page_to_pfn(pages[i]);
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);
1018+
ret = m2p_remove_override(pages[i], kmap_ops ?
1019+
&kmap_ops[i] : NULL);
10691020
if (ret)
10701021
goto out;
10711022
}
@@ -1076,22 +1027,8 @@ int __gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
10761027

10771028
return ret;
10781029
}
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-
}
10851030
EXPORT_SYMBOL_GPL(gnttab_unmap_refs);
10861031

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-
10951032
static unsigned nr_status_frames(unsigned nr_grant_frames)
10961033
{
10971034
BUG_ON(grefs_per_grant_frame == 0);

include/xen/grant_table.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,11 @@ void gnttab_free_auto_xlat_frames(void);
191191
#define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr))
192192

193193
int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
194+
struct gnttab_map_grant_ref *kmap_ops,
194195
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);
198196
int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
197+
struct gnttab_map_grant_ref *kunmap_ops,
199198
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);
203199

204200
/* Perform a batch of grant map/copy operations. Retry every batch slot
205201
* for which the hypervisor returns GNTST_eagain. This is typically due

0 commit comments

Comments
 (0)