diff options
author | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2013-07-23 13:23:54 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2013-08-20 10:25:35 -0400 |
commit | ee0726407feaf504dff304fb603652fb2d778b42 (patch) | |
tree | 408473642b805ba2e56b94766f877fcb8518f24b | |
parent | 072b2064b88f709c53a83c6ec1f1cb17bf7c0abf (diff) |
xen/m2p: use GNTTABOP_unmap_and_replace to reinstate the original mapping
GNTTABOP_unmap_grant_ref unmaps a grant and replaces it with a 0
mapping instead of reinstating the original mapping.
Doing so separately would be racy.
To unmap a grant and reinstate the original mapping atomically we use
GNTTABOP_unmap_and_replace.
GNTTABOP_unmap_and_replace doesn't work with GNTMAP_contains_pte, so
don't use it for kmaps. GNTTABOP_unmap_and_replace zeroes the mapping
passed in new_addr so we have to reinstate it, however that is a
per-cpu mapping only used for balloon scratch pages, so we can be sure that
it's not going to be accessed while the mapping is not valid.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
CC: alex@alex.org.uk
CC: dcrisan@flexiant.com
[v1: Konrad fixed up the conflicts]
Conflicts:
arch/x86/xen/p2m.c
-rw-r--r-- | arch/x86/xen/p2m.c | 21 | ||||
-rw-r--r-- | drivers/xen/gntdev.c | 11 |
2 files changed, 17 insertions, 15 deletions
diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index 74672eeac881..0d4ec35895d4 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c | |||
@@ -161,6 +161,7 @@ | |||
161 | #include <asm/xen/page.h> | 161 | #include <asm/xen/page.h> |
162 | #include <asm/xen/hypercall.h> | 162 | #include <asm/xen/hypercall.h> |
163 | #include <asm/xen/hypervisor.h> | 163 | #include <asm/xen/hypervisor.h> |
164 | #include <xen/balloon.h> | ||
164 | #include <xen/grant_table.h> | 165 | #include <xen/grant_table.h> |
165 | 166 | ||
166 | #include "multicalls.h" | 167 | #include "multicalls.h" |
@@ -967,7 +968,10 @@ int m2p_remove_override(struct page *page, | |||
967 | if (kmap_op != NULL) { | 968 | if (kmap_op != NULL) { |
968 | if (!PageHighMem(page)) { | 969 | if (!PageHighMem(page)) { |
969 | struct multicall_space mcs; | 970 | struct multicall_space mcs; |
970 | struct gnttab_unmap_grant_ref *unmap_op; | 971 | struct gnttab_unmap_and_replace *unmap_op; |
972 | struct page *scratch_page = get_balloon_scratch_page(); | ||
973 | unsigned long scratch_page_address = (unsigned long) | ||
974 | __va(page_to_pfn(scratch_page) << PAGE_SHIFT); | ||
971 | 975 | ||
972 | /* | 976 | /* |
973 | * It might be that we queued all the m2p grant table | 977 | * It might be that we queued all the m2p grant table |
@@ -990,20 +994,25 @@ int m2p_remove_override(struct page *page, | |||
990 | } | 994 | } |
991 | 995 | ||
992 | mcs = xen_mc_entry( | 996 | mcs = xen_mc_entry( |
993 | sizeof(struct gnttab_unmap_grant_ref)); | 997 | sizeof(struct gnttab_unmap_and_replace)); |
994 | unmap_op = mcs.args; | 998 | unmap_op = mcs.args; |
995 | unmap_op->host_addr = kmap_op->host_addr; | 999 | unmap_op->host_addr = kmap_op->host_addr; |
1000 | unmap_op->new_addr = scratch_page_address; | ||
996 | unmap_op->handle = kmap_op->handle; | 1001 | unmap_op->handle = kmap_op->handle; |
997 | unmap_op->dev_bus_addr = 0; | ||
998 | 1002 | ||
999 | MULTI_grant_table_op(mcs.mc, | 1003 | MULTI_grant_table_op(mcs.mc, |
1000 | GNTTABOP_unmap_grant_ref, unmap_op, 1); | 1004 | GNTTABOP_unmap_and_replace, unmap_op, 1); |
1001 | 1005 | ||
1002 | xen_mc_issue(PARAVIRT_LAZY_MMU); | 1006 | xen_mc_issue(PARAVIRT_LAZY_MMU); |
1003 | 1007 | ||
1004 | set_pte_at(&init_mm, address, ptep, | 1008 | mcs = __xen_mc_entry(0); |
1005 | pfn_pte(pfn, PAGE_KERNEL)); | 1009 | MULTI_update_va_mapping(mcs.mc, scratch_page_address, |
1010 | pfn_pte(page_to_pfn(get_balloon_scratch_page()), | ||
1011 | PAGE_KERNEL_RO), 0); | ||
1012 | xen_mc_issue(PARAVIRT_LAZY_MMU); | ||
1013 | |||
1006 | kmap_op->host_addr = 0; | 1014 | kmap_op->host_addr = 0; |
1015 | put_balloon_scratch_page(); | ||
1007 | } | 1016 | } |
1008 | } | 1017 | } |
1009 | 1018 | ||
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index eab5427c75f5..e41c79c986ea 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c | |||
@@ -272,19 +272,12 @@ static int map_grant_pages(struct grant_map *map) | |||
272 | * with find_grant_ptes. | 272 | * with find_grant_ptes. |
273 | */ | 273 | */ |
274 | for (i = 0; i < map->count; i++) { | 274 | for (i = 0; i < map->count; i++) { |
275 | unsigned level; | ||
276 | unsigned long address = (unsigned long) | 275 | unsigned long address = (unsigned long) |
277 | pfn_to_kaddr(page_to_pfn(map->pages[i])); | 276 | pfn_to_kaddr(page_to_pfn(map->pages[i])); |
278 | pte_t *ptep; | ||
279 | u64 pte_maddr = 0; | ||
280 | BUG_ON(PageHighMem(map->pages[i])); | 277 | BUG_ON(PageHighMem(map->pages[i])); |
281 | 278 | ||
282 | ptep = lookup_address(address, &level); | 279 | gnttab_set_map_op(&map->kmap_ops[i], address, |
283 | pte_maddr = arbitrary_virt_to_machine(ptep).maddr; | 280 | map->flags | GNTMAP_host_map, |
284 | gnttab_set_map_op(&map->kmap_ops[i], pte_maddr, | ||
285 | map->flags | | ||
286 | GNTMAP_host_map | | ||
287 | GNTMAP_contains_pte, | ||
288 | map->grants[i].ref, | 281 | map->grants[i].ref, |
289 | map->grants[i].domid); | 282 | map->grants[i].domid); |
290 | } | 283 | } |