Skip to content

Commit 853d028

Browse files
author
David Vrabel
committed
xen/grant-table: pre-populate kernel unmap ops for xen_gnttab_unmap_refs()
When unmapping grants, instead of converting the kernel map ops to unmap ops on the fly, pre-populate the set of unmap ops. This allows the grant unmap for the kernel mappings to be trivially batched in the future. Signed-off-by: David Vrabel <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]>
1 parent d8ac3dd commit 853d028

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
9292
struct page **pages, unsigned int count);
9393

9494
extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
95-
struct gnttab_map_grant_ref *kmap_ops,
95+
struct gnttab_unmap_grant_ref *kunmap_ops,
9696
struct page **pages, unsigned int count);
9797

9898
bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);

arch/arm/xen/p2m.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
102102
EXPORT_SYMBOL_GPL(set_foreign_p2m_mapping);
103103

104104
int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
105-
struct gnttab_map_grant_ref *kmap_ops,
105+
struct gnttab_unmap_grant_ref *kunmap_ops,
106106
struct page **pages, unsigned int count)
107107
{
108108
int i;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
5555
struct gnttab_map_grant_ref *kmap_ops,
5656
struct page **pages, unsigned int count);
5757
extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
58-
struct gnttab_map_grant_ref *kmap_ops,
58+
struct gnttab_unmap_grant_ref *kunmap_ops,
5959
struct page **pages, unsigned int count);
6060
extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
6161

arch/x86/xen/p2m.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ static struct page *m2p_find_override(unsigned long mfn)
816816
}
817817

818818
static int m2p_remove_override(struct page *page,
819-
struct gnttab_map_grant_ref *kmap_op,
819+
struct gnttab_unmap_grant_ref *kunmap_op,
820820
unsigned long mfn)
821821
{
822822
unsigned long flags;
@@ -840,7 +840,7 @@ static int m2p_remove_override(struct page *page,
840840
list_del(&page->lru);
841841
spin_unlock_irqrestore(&m2p_override_lock, flags);
842842

843-
if (kmap_op != NULL) {
843+
if (kunmap_op != NULL) {
844844
if (!PageHighMem(page)) {
845845
struct multicall_space mcs;
846846
struct gnttab_unmap_and_replace *unmap_op;
@@ -855,13 +855,13 @@ static int m2p_remove_override(struct page *page,
855855
* issued. In this case handle is going to -1 because
856856
* it hasn't been modified yet.
857857
*/
858-
if (kmap_op->handle == -1)
858+
if (kunmap_op->handle == -1)
859859
xen_mc_flush();
860860
/*
861861
* Now if kmap_op->handle is negative it means that the
862862
* hypercall actually returned an error.
863863
*/
864-
if (kmap_op->handle == GNTST_general_error) {
864+
if (kunmap_op->handle == GNTST_general_error) {
865865
pr_warn("m2p_remove_override: pfn %lx mfn %lx, failed to modify kernel mappings",
866866
pfn, mfn);
867867
put_balloon_scratch_page();
@@ -873,9 +873,9 @@ static int m2p_remove_override(struct page *page,
873873
mcs = __xen_mc_entry(
874874
sizeof(struct gnttab_unmap_and_replace));
875875
unmap_op = mcs.args;
876-
unmap_op->host_addr = kmap_op->host_addr;
876+
unmap_op->host_addr = kunmap_op->host_addr;
877877
unmap_op->new_addr = scratch_page_address;
878-
unmap_op->handle = kmap_op->handle;
878+
unmap_op->handle = kunmap_op->handle;
879879

880880
MULTI_grant_table_op(mcs.mc,
881881
GNTTABOP_unmap_and_replace, unmap_op, 1);
@@ -887,7 +887,6 @@ static int m2p_remove_override(struct page *page,
887887

888888
xen_mc_issue(PARAVIRT_LAZY_MMU);
889889

890-
kmap_op->host_addr = 0;
891890
put_balloon_scratch_page();
892891
}
893892
}
@@ -912,7 +911,7 @@ static int m2p_remove_override(struct page *page,
912911
}
913912

914913
int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
915-
struct gnttab_map_grant_ref *kmap_ops,
914+
struct gnttab_unmap_grant_ref *kunmap_ops,
916915
struct page **pages, unsigned int count)
917916
{
918917
int i, ret = 0;
@@ -921,7 +920,7 @@ int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
921920
if (xen_feature(XENFEAT_auto_translated_physmap))
922921
return 0;
923922

924-
if (kmap_ops &&
923+
if (kunmap_ops &&
925924
!in_interrupt() &&
926925
paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) {
927926
arch_enter_lazy_mmu_mode();
@@ -942,8 +941,8 @@ int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
942941
ClearPagePrivate(pages[i]);
943942
set_phys_to_machine(pfn, pages[i]->index);
944943

945-
if (kmap_ops)
946-
ret = m2p_remove_override(pages[i], &kmap_ops[i], mfn);
944+
if (kunmap_ops)
945+
ret = m2p_remove_override(pages[i], &kunmap_ops[i], mfn);
947946
if (ret)
948947
goto out;
949948
}

drivers/xen/gntdev.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct grant_map {
9191
struct gnttab_map_grant_ref *map_ops;
9292
struct gnttab_unmap_grant_ref *unmap_ops;
9393
struct gnttab_map_grant_ref *kmap_ops;
94+
struct gnttab_unmap_grant_ref *kunmap_ops;
9495
struct page **pages;
9596
};
9697

@@ -124,6 +125,7 @@ static void gntdev_free_map(struct grant_map *map)
124125
kfree(map->map_ops);
125126
kfree(map->unmap_ops);
126127
kfree(map->kmap_ops);
128+
kfree(map->kunmap_ops);
127129
kfree(map);
128130
}
129131

@@ -140,11 +142,13 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
140142
add->map_ops = kcalloc(count, sizeof(add->map_ops[0]), GFP_KERNEL);
141143
add->unmap_ops = kcalloc(count, sizeof(add->unmap_ops[0]), GFP_KERNEL);
142144
add->kmap_ops = kcalloc(count, sizeof(add->kmap_ops[0]), GFP_KERNEL);
145+
add->kunmap_ops = kcalloc(count, sizeof(add->kunmap_ops[0]), GFP_KERNEL);
143146
add->pages = kcalloc(count, sizeof(add->pages[0]), GFP_KERNEL);
144147
if (NULL == add->grants ||
145148
NULL == add->map_ops ||
146149
NULL == add->unmap_ops ||
147150
NULL == add->kmap_ops ||
151+
NULL == add->kunmap_ops ||
148152
NULL == add->pages)
149153
goto err;
150154

@@ -155,6 +159,7 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
155159
add->map_ops[i].handle = -1;
156160
add->unmap_ops[i].handle = -1;
157161
add->kmap_ops[i].handle = -1;
162+
add->kunmap_ops[i].handle = -1;
158163
}
159164

160165
add->index = 0;
@@ -280,6 +285,8 @@ static int map_grant_pages(struct grant_map *map)
280285
map->flags | GNTMAP_host_map,
281286
map->grants[i].ref,
282287
map->grants[i].domid);
288+
gnttab_set_unmap_op(&map->kunmap_ops[i], address,
289+
map->flags | GNTMAP_host_map, -1);
283290
}
284291
}
285292

@@ -290,13 +297,14 @@ static int map_grant_pages(struct grant_map *map)
290297
return err;
291298

292299
for (i = 0; i < map->count; i++) {
293-
if (map->map_ops[i].status)
300+
if (map->map_ops[i].status) {
294301
err = -EINVAL;
295-
else {
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);
302+
continue;
299303
}
304+
305+
map->unmap_ops[i].handle = map->map_ops[i].handle;
306+
if (use_ptemod)
307+
map->kunmap_ops[i].handle = map->kmap_ops[i].handle;
300308
}
301309
return err;
302310
}
@@ -316,7 +324,7 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
316324
}
317325

318326
err = gnttab_unmap_refs(map->unmap_ops + offset,
319-
use_ptemod ? map->kmap_ops + offset : NULL, map->pages + offset,
327+
use_ptemod ? map->kunmap_ops + offset : NULL, map->pages + offset,
320328
pages);
321329
if (err)
322330
return err;

drivers/xen/grant-table.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
738738
EXPORT_SYMBOL_GPL(gnttab_map_refs);
739739

740740
int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
741-
struct gnttab_map_grant_ref *kmap_ops,
741+
struct gnttab_unmap_grant_ref *kunmap_ops,
742742
struct page **pages, unsigned int count)
743743
{
744744
int ret;
@@ -747,7 +747,7 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
747747
if (ret)
748748
return ret;
749749

750-
return clear_foreign_p2m_mapping(unmap_ops, kmap_ops, pages, count);
750+
return clear_foreign_p2m_mapping(unmap_ops, kunmap_ops, pages, count);
751751
}
752752
EXPORT_SYMBOL_GPL(gnttab_unmap_refs);
753753

include/xen/grant_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
167167
struct gnttab_map_grant_ref *kmap_ops,
168168
struct page **pages, unsigned int count);
169169
int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
170-
struct gnttab_map_grant_ref *kunmap_ops,
170+
struct gnttab_unmap_grant_ref *kunmap_ops,
171171
struct page **pages, unsigned int count);
172172

173173
/* Perform a batch of grant map/copy operations. Retry every batch slot

0 commit comments

Comments
 (0)