Skip to content

Commit 2fc136e

Browse files
Stefano Stabellinikonradwilk
authored andcommitted
xen/m2p: do not reuse kmap_op->dev_bus_addr
If the caller passes a valid kmap_op to m2p_add_override, we use kmap_op->dev_bus_addr to store the original mfn, but dev_bus_addr is part of the interface with Xen and if we are batching the hypercalls it might not have been written by the hypervisor yet. That means that later on Xen will write to it and we'll think that the original mfn is actually what Xen has written to it. Rather than "stealing" struct members from kmap_op, keep using page->index to store the original mfn and add another parameter to m2p_remove_override to get the corresponding kmap_op instead. It is now responsibility of the caller to keep track of which kmap_op corresponds to a particular page in the m2p_override (gntdev, the only user of this interface that passes a valid kmap_op, is already doing that). CC: stable@kernel.org Reported-and-Tested-By: Sander Eikelenboom <linux@eikelenboom.it> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
1 parent 80ba77d commit 2fc136e

6 files changed

Lines changed: 23 additions & 23 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ extern unsigned long set_phys_range_identity(unsigned long pfn_s,
5151

5252
extern int m2p_add_override(unsigned long mfn, struct page *page,
5353
struct gnttab_map_grant_ref *kmap_op);
54-
extern int m2p_remove_override(struct page *page, bool clear_pte);
54+
extern int m2p_remove_override(struct page *page,
55+
struct gnttab_map_grant_ref *kmap_op);
5556
extern struct page *m2p_find_override(unsigned long mfn);
5657
extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
5758

‎arch/x86/xen/p2m.c‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,6 @@ int m2p_add_override(unsigned long mfn, struct page *page,
828828

829829
xen_mc_issue(PARAVIRT_LAZY_MMU);
830830
}
831-
/* let's use dev_bus_addr to record the old mfn instead */
832-
kmap_op->dev_bus_addr = page->index;
833-
page->index = (unsigned long) kmap_op;
834831
}
835832
spin_lock_irqsave(&m2p_override_lock, flags);
836833
list_add(&page->lru, &m2p_overrides[mfn_hash(mfn)]);
@@ -857,7 +854,8 @@ int m2p_add_override(unsigned long mfn, struct page *page,
857854
return 0;
858855
}
859856
EXPORT_SYMBOL_GPL(m2p_add_override);
860-
int m2p_remove_override(struct page *page, bool clear_pte)
857+
int m2p_remove_override(struct page *page,
858+
struct gnttab_map_grant_ref *kmap_op)
861859
{
862860
unsigned long flags;
863861
unsigned long mfn;
@@ -887,10 +885,8 @@ int m2p_remove_override(struct page *page, bool clear_pte)
887885
WARN_ON(!PagePrivate(page));
888886
ClearPagePrivate(page);
889887

890-
if (clear_pte) {
891-
struct gnttab_map_grant_ref *map_op =
892-
(struct gnttab_map_grant_ref *) page->index;
893-
set_phys_to_machine(pfn, map_op->dev_bus_addr);
888+
set_phys_to_machine(pfn, page->index);
889+
if (kmap_op != NULL) {
894890
if (!PageHighMem(page)) {
895891
struct multicall_space mcs;
896892
struct gnttab_unmap_grant_ref *unmap_op;
@@ -902,13 +898,13 @@ int m2p_remove_override(struct page *page, bool clear_pte)
902898
* issued. In this case handle is going to -1 because
903899
* it hasn't been modified yet.
904900
*/
905-
if (map_op->handle == -1)
901+
if (kmap_op->handle == -1)
906902
xen_mc_flush();
907903
/*
908-
* Now if map_op->handle is negative it means that the
904+
* Now if kmap_op->handle is negative it means that the
909905
* hypercall actually returned an error.
910906
*/
911-
if (map_op->handle == GNTST_general_error) {
907+
if (kmap_op->handle == GNTST_general_error) {
912908
printk(KERN_WARNING "m2p_remove_override: "
913909
"pfn %lx mfn %lx, failed to modify kernel mappings",
914910
pfn, mfn);
@@ -918,8 +914,8 @@ int m2p_remove_override(struct page *page, bool clear_pte)
918914
mcs = xen_mc_entry(
919915
sizeof(struct gnttab_unmap_grant_ref));
920916
unmap_op = mcs.args;
921-
unmap_op->host_addr = map_op->host_addr;
922-
unmap_op->handle = map_op->handle;
917+
unmap_op->host_addr = kmap_op->host_addr;
918+
unmap_op->handle = kmap_op->handle;
923919
unmap_op->dev_bus_addr = 0;
924920

925921
MULTI_grant_table_op(mcs.mc,
@@ -930,10 +926,9 @@ int m2p_remove_override(struct page *page, bool clear_pte)
930926
set_pte_at(&init_mm, address, ptep,
931927
pfn_pte(pfn, PAGE_KERNEL));
932928
__flush_tlb_single(address);
933-
map_op->host_addr = 0;
929+
kmap_op->host_addr = 0;
934930
}
935-
} else
936-
set_phys_to_machine(pfn, page->index);
931+
}
937932

938933
/* p2m(m2p(mfn)) == FOREIGN_FRAME(mfn): the mfn is already present
939934
* somewhere in this domain, even before being added to the

‎drivers/block/xen-blkback/blkback.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static void xen_blkbk_unmap(struct pending_req *req)
337337
invcount++;
338338
}
339339

340-
ret = gnttab_unmap_refs(unmap, pages, invcount, false);
340+
ret = gnttab_unmap_refs(unmap, NULL, pages, invcount);
341341
BUG_ON(ret);
342342
}
343343

‎drivers/xen/gntdev.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
314314
}
315315
}
316316

317-
err = gnttab_unmap_refs(map->unmap_ops + offset, map->pages + offset,
318-
pages, true);
317+
err = gnttab_unmap_refs(map->unmap_ops + offset,
318+
use_ptemod ? map->kmap_ops + offset : NULL, map->pages + offset,
319+
pages);
319320
if (err)
320321
return err;
321322

‎drivers/xen/grant-table.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,8 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
870870
EXPORT_SYMBOL_GPL(gnttab_map_refs);
871871

872872
int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
873-
struct page **pages, unsigned int count, bool clear_pte)
873+
struct gnttab_map_grant_ref *kmap_ops,
874+
struct page **pages, unsigned int count)
874875
{
875876
int i, ret;
876877
bool lazy = false;
@@ -888,7 +889,8 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
888889
}
889890

890891
for (i = 0; i < count; i++) {
891-
ret = m2p_remove_override(pages[i], clear_pte);
892+
ret = m2p_remove_override(pages[i], kmap_ops ?
893+
&kmap_ops[i] : NULL);
892894
if (ret)
893895
return ret;
894896
}

‎include/xen/grant_table.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
187187
struct gnttab_map_grant_ref *kmap_ops,
188188
struct page **pages, unsigned int count);
189189
int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
190-
struct page **pages, unsigned int count, bool clear_pte);
190+
struct gnttab_map_grant_ref *kunmap_ops,
191+
struct page **pages, unsigned int count);
191192

192193
#endif /* __ASM_GNTTAB_H__ */

0 commit comments

Comments
 (0)