Skip to contentSkip to conversation

xen/p2m: Don't call get_balloon_scratch_page() twice, keep interrupts disabled for multicalls

PATCH In review Boris Ostrovsky 3 participants 5 messages Sep 6, 2013

Subsystems (2)
lore
Share & tools
lore

Boris Ostrovsky

author reviewer
#0 lore raw

PATCH 1/1 xen/p2m: Don't call get_balloon_scratch_page() twice, keep interrupts disabled for multicalls

m2p_remove_override() calls get_balloon_scratch_page() in MULTI_update_va_mapping() even though it already has pointer to this page from the earlier call (in scratch_page). This second call doesn't have a matching put_balloon_scratch_page() thus not restoring preempt count back. (Also, there is no put_balloon_scratch_page() in the error path.)

In addition, the second multicall uses __xen_mc_entry() which does not disable interrupts. Rearrange xen_mc_* calls to keep interrupts off while performing multicalls.

---
 arch/x86/xen/p2m.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/xen/p2m.c +6 -4
index 0d4ec35..8b901e8 100644
@@ -990,10 +990,13 @@ int m2p_remove_override(struct page *page,
 				printk(KERN_WARNING "m2p_remove_override: "
 						"pfn %lx mfn %lx, failed to modify kernel mappings",
 						pfn, mfn);
+				put_balloon_scratch_page();
 				return -1;
 			}
 
-			mcs = xen_mc_entry(
+			xen_mc_batch();
+
+			mcs = __xen_mc_entry(
 					sizeof(struct gnttab_unmap_and_replace));
 			unmap_op = mcs.args;
 			unmap_op->host_addr = kmap_op->host_addr;
@@ -1003,12 +1006,11 @@ int m2p_remove_override(struct page *page,
 			MULTI_grant_table_op(mcs.mc,
 					GNTTABOP_unmap_and_replace, unmap_op, 1);
 
-			xen_mc_issue(PARAVIRT_LAZY_MMU);
-
 			mcs = __xen_mc_entry(0);
 			MULTI_update_va_mapping(mcs.mc, scratch_page_address,
-					pfn_pte(page_to_pfn(get_balloon_scratch_page()),
+					pfn_pte(page_to_pfn(scratch_page),
 					PAGE_KERNEL_RO), 0);
+
 			xen_mc_issue(PARAVIRT_LAZY_MMU);
 
 			kmap_op->host_addr = 0;
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Boris Ostrovsky

m2p_remove_override() calls get_balloon_scratch_page() in MULTI_update_va_mapping() even though it already has pointer to this page from the earlier call (in scratch_page). This second call doesn't have a matching put_balloon_scratch_page() thus not restoring preempt count back. (Also, there is no put_balloon_scratch_page() in the error path.)

In addition, the second multicall uses __xen_mc_entry() which does not disable interrupts. Rearrange xen_mc_* calls to keep interrupts off while performing multicalls.

Quoted 40 lines
 arch/x86/xen/p2m.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/xen/p2m.c +6 -4
index 0d4ec35..8b901e8 100644
@@ -990,10 +990,13 @@ int m2p_remove_override(struct page *page,
 				printk(KERN_WARNING "m2p_remove_override: "
 						"pfn %lx mfn %lx, failed to modify kernel mappings",
 						pfn, mfn);
+				put_balloon_scratch_page();
 				return -1;
 			}
 
-			mcs = xen_mc_entry(
+			xen_mc_batch();
+
+			mcs = __xen_mc_entry(
 					sizeof(struct gnttab_unmap_and_replace));
 			unmap_op = mcs.args;
 			unmap_op->host_addr = kmap_op->host_addr;
@@ -1003,12 +1006,11 @@ int m2p_remove_override(struct page *page,
 			MULTI_grant_table_op(mcs.mc,
 					GNTTABOP_unmap_and_replace, unmap_op, 1);
 
-			xen_mc_issue(PARAVIRT_LAZY_MMU);
-
 			mcs = __xen_mc_entry(0);
 			MULTI_update_va_mapping(mcs.mc, scratch_page_address,
-					pfn_pte(page_to_pfn(get_balloon_scratch_page()),
+					pfn_pte(page_to_pfn(scratch_page),
 					PAGE_KERNEL_RO), 0);
+
 			xen_mc_issue(PARAVIRT_LAZY_MMU);
 
 			kmap_op->host_addr = 0;
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Boris Ostrovsky

m2p_remove_override() calls get_balloon_scratch_page() in MULTI_update_va_mapping() even though it already has pointer to this page from the earlier call (in scratch_page). This second call doesn't have a matching put_balloon_scratch_page() thus not restoring preempt count back. (Also, there is no put_balloon_scratch_page() in the error path.)

Quoted 5 lines
Quoted 5 lines

In addition, the second multicall uses __xen_mc_entry() which does not disable interrupts. Rearrange xen_mc_* calls to keep interrupts off while performing multicalls.

You also might want to mention that this fixes the regression introduced by .. commit id <"title"

Quoted 43 lines
Quoted 40 lines
  arch/x86/xen/p2m.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/xen/p2m.c +6 -4
index 0d4ec35..8b901e8 100644
@@ -990,10 +990,13 @@ int m2p_remove_override(struct page *page,
  				printk(KERN_WARNING "m2p_remove_override: "
  						"pfn %lx mfn %lx, failed to modify kernel mappings",
  						pfn, mfn);
+				put_balloon_scratch_page();
  				return -1;
  			}
 
-			mcs = xen_mc_entry(
+			xen_mc_batch();
+
+			mcs = __xen_mc_entry(
  					sizeof(struct gnttab_unmap_and_replace));
  			unmap_op = mcs.args;
  			unmap_op->host_addr = kmap_op->host_addr;
@@ -1003,12 +1006,11 @@ int m2p_remove_override(struct page *page,
  			MULTI_grant_table_op(mcs.mc,
  					GNTTABOP_unmap_and_replace, unmap_op, 1);
 
-			xen_mc_issue(PARAVIRT_LAZY_MMU);
-
  			mcs = __xen_mc_entry(0);
  			MULTI_update_va_mapping(mcs.mc, scratch_page_address,
-					pfn_pte(page_to_pfn(get_balloon_scratch_page()),
+					pfn_pte(page_to_pfn(scratch_page),
  					PAGE_KERNEL_RO), 0);
+
  			xen_mc_issue(PARAVIRT_LAZY_MMU);
 
  			kmap_op->host_addr = 0;
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Stefano Stabellini
Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Boris Ostrovsky

m2p_remove_override() calls get_balloon_scratch_page() in MULTI_update_va_mapping() even though it already has pointer to this page from the earlier call (in scratch_page). This second call doesn't have a matching put_balloon_scratch_page() thus not restoring preempt count back. (Also, there is no put_balloon_scratch_page() in the error path.)

Quoted 5 lines
Quoted 5 lines

In addition, the second multicall uses __xen_mc_entry() which does not disable interrupts. Rearrange xen_mc_* calls to keep interrupts off while performing multicalls.

You also might want to mention that this fixes the regression introduced by .. commit id <"title"

Quoted 43 lines
Quoted 40 lines
  arch/x86/xen/p2m.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/xen/p2m.c +6 -4
index 0d4ec35..8b901e8 100644
@@ -990,10 +990,13 @@ int m2p_remove_override(struct page *page,
  				printk(KERN_WARNING "m2p_remove_override: "
  						"pfn %lx mfn %lx, failed to modify kernel mappings",
  						pfn, mfn);
+				put_balloon_scratch_page();
  				return -1;
  			}
 
-			mcs = xen_mc_entry(
+			xen_mc_batch();
+
+			mcs = __xen_mc_entry(
  					sizeof(struct gnttab_unmap_and_replace));
  			unmap_op = mcs.args;
  			unmap_op->host_addr = kmap_op->host_addr;
@@ -1003,12 +1006,11 @@ int m2p_remove_override(struct page *page,
  			MULTI_grant_table_op(mcs.mc,
  					GNTTABOP_unmap_and_replace, unmap_op, 1);
 
-			xen_mc_issue(PARAVIRT_LAZY_MMU);
-
  			mcs = __xen_mc_entry(0);
  			MULTI_update_va_mapping(mcs.mc, scratch_page_address,
-					pfn_pte(page_to_pfn(get_balloon_scratch_page()),
+					pfn_pte(page_to_pfn(scratch_page),
  					PAGE_KERNEL_RO), 0);
+
  			xen_mc_issue(PARAVIRT_LAZY_MMU);
 
  			kmap_op->host_addr = 0;
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#4 lore raw
In reply to Boris Ostrovsky
Quoted 11 lines · Boris Ostrovsky

m2p_remove_override() calls get_balloon_scratch_page() in MULTI_update_va_mapping() even though it already has pointer to this page from the earlier call (in scratch_page). This second call doesn't have a matching put_balloon_scratch_page() thus not restoring preempt count back. (Also, there is no put_balloon_scratch_page() in the error path.)

In addition, the second multicall uses __xen_mc_entry() which does not disable interrupts. Rearrange xen_mc_* calls to keep interrupts off while performing multicalls.

Quoted 40 lines
 arch/x86/xen/p2m.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/xen/p2m.c +6 -4
index 0d4ec35..8b901e8 100644
@@ -990,10 +990,13 @@ int m2p_remove_override(struct page *page,
 				printk(KERN_WARNING "m2p_remove_override: "
 						"pfn %lx mfn %lx, failed to modify kernel mappings",
 						pfn, mfn);
+				put_balloon_scratch_page();
 				return -1;
 			}
 
-			mcs = xen_mc_entry(
+			xen_mc_batch();
+
+			mcs = __xen_mc_entry(
 					sizeof(struct gnttab_unmap_and_replace));
 			unmap_op = mcs.args;
 			unmap_op->host_addr = kmap_op->host_addr;
@@ -1003,12 +1006,11 @@ int m2p_remove_override(struct page *page,
 			MULTI_grant_table_op(mcs.mc,
 					GNTTABOP_unmap_and_replace, unmap_op, 1);
 
-			xen_mc_issue(PARAVIRT_LAZY_MMU);
-
 			mcs = __xen_mc_entry(0);
 			MULTI_update_va_mapping(mcs.mc, scratch_page_address,
-					pfn_pte(page_to_pfn(get_balloon_scratch_page()),
+					pfn_pte(page_to_pfn(scratch_page),
 					PAGE_KERNEL_RO), 0);
+
 			xen_mc_issue(PARAVIRT_LAZY_MMU);
 
 			kmap_op->host_addr = 0;
Signature · 1 line
1.8.3.1