Skip to contentSkip to conversation

linux: simplify and perform checking of multicall status

PATCH In review Jan Beulich 2 participants 4 messages Mar 26, 2007 – Apr 5, 2007 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux: simplify and perform checking of multicall status

arch/i386/mm/hypervisor.c +4 -4
Index: head-2007-03-19/arch/i386/mm/hypervisor.c
===================================================================
@@ -303,7 +303,7 @@ int xen_create_contiguous_region(
 		set_phys_to_machine((__pa(vstart)>>PAGE_SHIFT)+i,
 			INVALID_P2M_ENTRY);
 	}
-	if (HYPERVISOR_multicall(cr_mcl, i))
+	if (HYPERVISOR_multicall_check(cr_mcl, i, NULL))
 		BUG();
 
 	/* 2. Get a new contiguous memory extent. */
@@ -342,7 +342,7 @@ int xen_create_contiguous_region(
 	cr_mcl[i - 1].args[MULTI_UVMFLAGS_INDEX] = order
 						   ? UVMF_TLB_FLUSH|UVMF_ALL
 						   : UVMF_INVLPG|UVMF_ALL;
-	if (HYPERVISOR_multicall(cr_mcl, i))
+	if (HYPERVISOR_multicall_check(cr_mcl, i, NULL))
 		BUG();
 
 	if (success)
@@ -400,7 +400,7 @@ void xen_destroy_contiguous_region(unsig
 			INVALID_P2M_ENTRY);
 		out_frames[i] = (__pa(vstart) >> PAGE_SHIFT) + i;
 	}
-	if (HYPERVISOR_multicall(cr_mcl, i))
+	if (HYPERVISOR_multicall_check(cr_mcl, i, NULL))
 		BUG();
 
 	/* 3. Do the exchange for non-contiguous MFNs. */
@@ -432,7 +432,7 @@ void xen_destroy_contiguous_region(unsig
 	cr_mcl[i - 1].args[MULTI_UVMFLAGS_INDEX] = order
 						   ? UVMF_TLB_FLUSH|UVMF_ALL
 						   : UVMF_INVLPG|UVMF_ALL;
-	if (HYPERVISOR_multicall(cr_mcl, i))
+	if (HYPERVISOR_multicall_check(cr_mcl, i, NULL))
 		BUG();
 
 	balloon_unlock(flags);
drivers/xen/core/machine_kexec.c +0 -1
Index: head-2007-03-19/drivers/xen/core/machine_kexec.c
===================================================================
@@ -7,7 +7,6 @@
 #include <xen/interface/kexec.h>
 #include <linux/mm.h>
 #include <linux/bootmem.h>
-#include <asm/hypercall.h>
 
 extern void machine_kexec_setup_load_arg(xen_kexec_image_t *xki, 
 					 struct kimage *image);
drivers/xen/netback/netback.c +3 -2
Index: head-2007-03-19/drivers/xen/netback/netback.c
===================================================================
@@ -615,8 +615,9 @@ static void net_rx_action(unsigned long 
 	BUG_ON(npo.mcl_prod > NET_RX_RING_SIZE+3);
 	BUG_ON(npo.meta_prod > NET_RX_RING_SIZE);
 
-	ret = HYPERVISOR_multicall(npo.mcl, npo.mcl_prod);
-	BUG_ON(ret != 0);
+	ret = HYPERVISOR_multicall_check(npo.mcl, npo.mcl_prod, NULL);
+	BUG_ON(ret < 0);
+	WARN_ON(ret > 0);
 
 	while ((skb = __skb_dequeue(&rxq)) != NULL) {
 		nr_frags = *(int *)skb->cb;
drivers/xen/netfront/netfront.c +2 -1
Index: head-2007-03-19/drivers/xen/netfront/netfront.c
===================================================================
@@ -1579,7 +1579,8 @@ static void netif_release_rx_bufs(struct
 			mcl->args[2] = 0;
 			mcl->args[3] = DOMID_SELF;
 			mcl++;
-			HYPERVISOR_multicall(np->rx_mcl, mcl - np->rx_mcl);
+			if (HYPERVISOR_multicall_check(np->rx_mcl, mcl - np->rx_mcl, NULL))
+				BUG();
 		}
 	}
 
include/asm-i386/mach-xen/asm/hypercall.h +1 -1
Index: head-2007-03-19/include/asm-i386/mach-xen/asm/hypercall.h
===================================================================
@@ -238,7 +238,7 @@ HYPERVISOR_memory_op(
 
 static inline int
 HYPERVISOR_multicall(
-	void *call_list, int nr_calls)
+	multicall_entry_t *call_list, int nr_calls)
 {
 	return _hypercall2(int, multicall, call_list, nr_calls);
 }
include/asm-i386/mach-xen/asm/hypervisor.h +1 -1
Index: head-2007-03-19/include/asm-i386/mach-xen/asm/hypervisor.h
===================================================================
@@ -122,7 +122,7 @@ void xen_destroy_contiguous_region(
 /* Turn jiffies into Xen system time. */
 u64 jiffies_to_st(unsigned long jiffies);
 
-#include <asm/hypercall.h>
+#include <xen/hypercall.h>
 
 #if defined(CONFIG_X86_64)
 #define MULTI_UVMFLAGS_INDEX 2
include/asm-ia64/hypervisor.h +1 -1
Index: head-2007-03-19/include/asm-ia64/hypervisor.h
===================================================================
@@ -55,7 +55,7 @@ void xen_destroy_contiguous_region(
 #include <xen/interface/event_channel.h>
 #include <xen/interface/physdev.h>
 #include <xen/interface/sched.h>
-#include <asm/hypercall.h>
+#include <xen/hypercall.h>
 #include <asm/ptrace.h>
 #include <asm/page.h>
 
include/asm-x86_64/mach-xen/asm/hypercall.h +1 -1
Index: head-2007-03-19/include/asm-x86_64/mach-xen/asm/hypercall.h
===================================================================
@@ -241,7 +241,7 @@ HYPERVISOR_memory_op(
 
 static inline int
 HYPERVISOR_multicall(
-	void *call_list, int nr_calls)
+	multicall_entry_t *call_list, int nr_calls)
 {
 	return _hypercall2(int, multicall, call_list, nr_calls);
 }
include/xen/hvm.h +0 -1
Index: head-2007-03-19/include/xen/hvm.h
===================================================================
@@ -3,7 +3,6 @@
 #define XEN_HVM_H__
 
 #include <xen/interface/hvm/params.h>
-#include <asm/hypercall.h>
 
 static inline unsigned long hvm_get_parameter(int idx)
 {
include/xen/hypercall.h new file +23 -0
Index: head-2007-03-19/include/xen/hypercall.h
===================================================================
@@ -0,0 +1,23 @@
+#ifndef __XEN_HYPERCALL_H__
+#define __XEN_HYPERCALL_H__
+
+#include <asm/hypercall.h>
+
+static inline int
+HYPERVISOR_multicall_check(
+	multicall_entry_t *call_list, int nr_calls,
+	const unsigned long *rc_list)
+{
+	int rc = HYPERVISOR_multicall(call_list, nr_calls);
+
+	if (unlikely(rc == 0))
+		return rc;
+
+	for ( ; nr_calls > 0; --nr_calls, ++call_list)
+		if (unlikely(call_list->result != (rc_list ? *rc_list++ : 0)))
+			return nr_calls;
+
+	return 0;
+}
+
+#endif /* __XEN_HYPERCALL_H__ */
#1 lore raw

include/xen/hypercall.h line 14

Quoted 9 lines · Jan Beulich
include/xen/hypercall.h new file +9 -0
+static inline int
+HYPERVISOR_multicall_check(
+ multicall_entry_t *call_list, int nr_calls,
+ const unsigned long *rc_list)
+{
+ int rc = HYPERVISOR_multicall(call_list, nr_calls);
+
+ if (unlikely(rc == 0))
+  return rc;

ITYM unlikely(rc != 0)?

-- Keir

#2 lore raw
Quoted 14 lines
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 05.04.07 10:29 >>>

include/xen/hypercall.h line 14

Quoted 9 lines · Jan Beulich
include/xen/hypercall.h new file +9 -0
+static inline int
+HYPERVISOR_multicall_check(
+ multicall_entry_t *call_list, int nr_calls,
+ const unsigned long *rc_list)
+{
+ int rc = HYPERVISOR_multicall(call_list, nr_calls);
+
+ if (unlikely(rc == 0))
+  return rc;

ITYM unlikely(rc != 0)?

Huh, indeed. And perhaps it should (give the rest of the function) even be

	if (unlikely(rc < 0))
		return rc;
	BUG_ON(rc);

(i.e. so that positive return values indicate the failed slot, negative ones indicate a failure of the multicall itself).

Jan

#3 lore raw
Quoted 9 lines · Jan Beulich

Huh, indeed. And perhaps it should (give the rest of the function) even be

if (unlikely(rc < 0))
return rc;
BUG_ON(rc);

(i.e. so that positive return values indicate the failed slot, negative ones indicate a failure of the multicall itself).

Makes sense. I'll merge that in.

-- Keir