Module Name: src
Committed By: cherry
Date: Wed Aug 17 09:40:40 UTC 2011
Modified Files:
src/sys/arch/i386/include [cherry-xenmp]: cpu.h
src/sys/arch/x86/include [cherry-xenmp]: cpu.h
src/sys/arch/x86/x86 [cherry-xenmp]: pmap.c
src/sys/arch/xen/include [cherry-xenmp]: evtchn.h intr.h xenpmap.h
src/sys/arch/xen/x86 [cherry-xenmp]: cpu.c hypervisor_machdep.c intr.c
x86_xpmap.c xen_ipi.c
src/sys/arch/xen/xen [cherry-xenmp]: evtchn.c xentests.c
Log Message:
Pullup relevant changes from -current
To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.176.12.1 src/sys/arch/i386/include/cpu.h
cvs rdiff -u -r1.34.2.3 -r1.34.2.4 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.121.2.4 -r1.121.2.5 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.18.10.2 -r1.18.10.3 src/sys/arch/xen/include/evtchn.h
cvs rdiff -u -r1.31.10.3 -r1.31.10.4 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.27.2.2 -r1.27.2.3 src/sys/arch/xen/include/xenpmap.h
cvs rdiff -u -r1.56.2.5 -r1.56.2.6 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.14.2.2 -r1.14.2.3 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.27.6.1 -r1.27.6.2 src/sys/arch/xen/x86/intr.c
cvs rdiff -u -r1.26.2.5 -r1.26.2.6 src/sys/arch/xen/x86/x86_xpmap.c
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.47.6.3 -r1.47.6.4 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/arch/xen/xen/xentests.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/i386/include/cpu.h
diff -u src/sys/arch/i386/include/cpu.h:1.176 src/sys/arch/i386/include/cpu.h:1.176.12.1
--- src/sys/arch/i386/include/cpu.h:1.176 Mon Dec 29 19:59:09 2008
+++ src/sys/arch/i386/include/cpu.h Wed Aug 17 09:40:39 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.176 2008/12/29 19:59:09 pooka Exp $ */
+/* $NetBSD: cpu.h,v 1.176.12.1 2011/08/17 09:40:39 cherry Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -68,6 +68,7 @@
(*(struct cpu_info * const *)offsetof(struct cpu_info, ci_curlwp)));
return l;
}
+
__inline static void __unused
cpu_set_curpri(int pri)
{
Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.34.2.3 src/sys/arch/x86/include/cpu.h:1.34.2.4
--- src/sys/arch/x86/include/cpu.h:1.34.2.3 Sat Jul 16 10:59:45 2011
+++ src/sys/arch/x86/include/cpu.h Wed Aug 17 09:40:39 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.34.2.3 2011/07/16 10:59:45 cherry Exp $ */
+/* $NetBSD: cpu.h,v 1.34.2.4 2011/08/17 09:40:39 cherry Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -67,8 +67,6 @@
#include <sys/evcnt.h>
#include <sys/device_if.h> /* for device_t */
-#include <sys/device_if.h> /* for device_t */
-
#ifdef XEN
#include <xen/xen3-public/xen.h>
#include <xen/xen3-public/event_channel.h>
@@ -316,6 +314,8 @@
void cpu_init_idle_lwps(void);
void cpu_init_msrs(struct cpu_info *, bool);
void cpu_load_pmap(struct pmap *);
+void cpu_broadcast_halt(void);
+void cpu_kick(struct cpu_info *);
extern uint32_t cpus_attached;
Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.121.2.4 src/sys/arch/x86/x86/pmap.c:1.121.2.5
--- src/sys/arch/x86/x86/pmap.c:1.121.2.4 Sun Jul 31 20:49:11 2011
+++ src/sys/arch/x86/x86/pmap.c Wed Aug 17 09:40:39 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.121.2.4 2011/07/31 20:49:11 cherry Exp $ */
+/* $NetBSD: pmap.c,v 1.121.2.5 2011/08/17 09:40:39 cherry Exp $ */
/*-
* Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.121.2.4 2011/07/31 20:49:11 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.121.2.5 2011/08/17 09:40:39 cherry Exp $");
#include "opt_user_ldt.h"
#include "opt_lockdebug.h"
@@ -1619,10 +1619,6 @@
VM_PROT_READ | VM_PROT_WRITE, 0);
pmap_update(pmap_kernel());
-
- xpq_queue_lock();
- xpq_queue_pin_l3_table(xpmap_ptom_masked(ci->ci_pae_l3_pdirpa));
- xpq_queue_unlock();
#endif
#if defined(XEN) && defined (__x86_64)
KASSERT(ci != NULL);
Index: src/sys/arch/xen/include/evtchn.h
diff -u src/sys/arch/xen/include/evtchn.h:1.18.10.2 src/sys/arch/xen/include/evtchn.h:1.18.10.3
--- src/sys/arch/xen/include/evtchn.h:1.18.10.2 Thu Aug 4 09:07:46 2011
+++ src/sys/arch/xen/include/evtchn.h Wed Aug 17 09:40:39 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: evtchn.h,v 1.18.10.2 2011/08/04 09:07:46 cherry Exp $ */
+/* $NetBSD: evtchn.h,v 1.18.10.3 2011/08/17 09:40:39 cherry Exp $ */
/*
*
@@ -41,10 +41,9 @@
int event_set_handler(int, int (*func)(void *), void *, int, const char *);
int event_remove_handler(int, int (*func)(void *), void *);
+struct cpu_info;
struct intrhand;
-void event_set_iplhandler(struct cpu_info *ci,
- struct intrhand *,
- int);
+void event_set_iplhandler(struct cpu_info *, struct intrhand *, int);
extern int debug_port;
extern int xen_debug_handler(void *);
Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.31.10.3 src/sys/arch/xen/include/intr.h:1.31.10.4
--- src/sys/arch/xen/include/intr.h:1.31.10.3 Thu Aug 4 09:07:46 2011
+++ src/sys/arch/xen/include/intr.h Wed Aug 17 09:40:39 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.h,v 1.31.10.3 2011/08/04 09:07:46 cherry Exp $ */
+/* $NetBSD: intr.h,v 1.31.10.4 2011/08/17 09:40:39 cherry Exp $ */
/* NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp */
/*-
@@ -33,18 +33,15 @@
#ifndef _XEN_INTR_H_
#define _XEN_INTR_H_
-#ifndef _LOCORE
-#include <machine/cpu.h>
-#include <machine/pic.h>
#include <machine/intrdefs.h>
-#include <sys/evcnt.h>
-#include <sys/types.h>
-#include <sys/simplelock.h>
-
+#ifndef _LOCORE
#include <xen/xen.h>
#include <xen/hypervisor.h>
#include <xen/evtchn.h>
+#include <machine/cpu.h>
+#include <machine/pic.h>
+#include <sys/evcnt.h>
#include "opt_xen.h"
@@ -57,9 +54,8 @@
uint32_t ev_imask; /* interrupt mask */
struct intrhand *ev_handlers; /* handler chain */
struct evcnt ev_evcnt; /* interrupt counter */
+ struct cpu_info *ev_cpu; /* cpu on which this event is bound */
char ev_evname[32]; /* event counter name */
- struct cpu_info *ev_cpu; /* cpu on which this event is bound */
- struct simplelock ev_lock; /* protects this structure */
};
/*
@@ -166,7 +162,6 @@
void intr_default_setup(void);
int x86_nmi(void);
-void intr_calculatemasks(struct evtsource *);
void *intr_establish(int, struct pic *, int, int, int, int (*)(void *), void *, bool);
void intr_disestablish(struct intrhand *);
@@ -185,9 +180,9 @@
int xen_send_ipi(struct cpu_info *, uint32_t);
void xen_broadcast_ipi(uint32_t);
#else
-#define xen_ipi_init(_1) do {} while(0) /* nothing */
-#define xen_send_ipi(_i1, _i2) do {} while(0) /* nothing */
-#define xen_broadcast_ipi(_i1) do {} while(0) /* nothing */
+#define xen_ipi_init(_1) ((void) 0) /* nothing */
+#define xen_send_ipi(_i1, _i2) (0) /* nothing */
+#define xen_broadcast_ipi(_i1) ((void) 0) /* nothing */
#endif /* MULTIPROCESSOR */
#endif /* !_LOCORE */
Index: src/sys/arch/xen/include/xenpmap.h
diff -u src/sys/arch/xen/include/xenpmap.h:1.27.2.2 src/sys/arch/xen/include/xenpmap.h:1.27.2.3
--- src/sys/arch/xen/include/xenpmap.h:1.27.2.2 Thu Jun 23 14:19:49 2011
+++ src/sys/arch/xen/include/xenpmap.h Wed Aug 17 09:40:39 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xenpmap.h,v 1.27.2.2 2011/06/23 14:19:49 cherry Exp $ */
+/* $NetBSD: xenpmap.h,v 1.27.2.3 2011/08/17 09:40:39 cherry Exp $ */
/*
*
@@ -36,8 +36,16 @@
#define INVALID_P2M_ENTRY (~0UL)
+#ifdef MULTIPROCESSOR
void xpq_queue_lock(void);
void xpq_queue_unlock(void);
+bool xpq_queue_locked(void);
+#else /* MULTIPROCESSOR */
+#define xpq_queue_lock() do {} while(0) /* nothing */
+#define xpq_queue_unlock() do {} while(0) /* nothing */
+#define xpq_queue_locked() (true) /* Always true for UP */
+#endif /* MULTIPROCESSOR */
+
void xpq_queue_machphys_update(paddr_t, paddr_t);
void xpq_queue_invlpg(vaddr_t);
void xpq_queue_pte_update(paddr_t, pt_entry_t);
Index: src/sys/arch/xen/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.56.2.5 src/sys/arch/xen/x86/cpu.c:1.56.2.6
--- src/sys/arch/xen/x86/cpu.c:1.56.2.5 Sun Aug 7 19:48:08 2011
+++ src/sys/arch/xen/x86/cpu.c Wed Aug 17 09:40:39 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.56.2.5 2011/08/07 19:48:08 cherry Exp $ */
+/* $NetBSD: cpu.c,v 1.56.2.6 2011/08/17 09:40:39 cherry Exp $ */
/* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp */
/*-
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.56.2.5 2011/08/07 19:48:08 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.56.2.6 2011/08/17 09:40:39 cherry Exp $");
#include "opt_ddb.h"
#include "opt_multiprocessor.h"
@@ -1289,3 +1289,23 @@
#endif /* __x86_64__ */
}
+
+/*
+ * Notify all other cpus to halt.
+ */
+
+void
+cpu_broadcast_halt(void)
+{
+ xen_broadcast_ipi(XEN_IPI_HALT);
+}
+
+/*
+ * Send a dummy ipi to a cpu.
+ */
+
+void
+cpu_kick(struct cpu_info *ci)
+{
+ xen_send_ipi(ci, XEN_IPI_KICK);
+}
Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.2 src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.3
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.2 Thu Aug 4 09:07:47 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c Wed Aug 17 09:40:39 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor_machdep.c,v 1.14.2.2 2011/08/04 09:07:47 cherry Exp $ */
+/* $NetBSD: hypervisor_machdep.c,v 1.14.2.3 2011/08/17 09:40:39 cherry Exp $ */
/*
*
@@ -54,7 +54,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.14.2.2 2011/08/04 09:07:47 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.14.2.3 2011/08/17 09:40:39 cherry Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -86,33 +86,15 @@
// #define PORT_DEBUG 4
// #define EARLY_DEBUG_EVENT
-static inline unsigned int
-evt_bitstr_to_port(unsigned long l1, unsigned long l2)
-{
- unsigned int l1i, l2i, port;
-
- l1i = xen_ffs(l1) - 1;
- l2i = xen_ffs(l2) - 1;
-
- port = (l1i << LONG_SHIFT) + l2i;
- return port;
-}
-
/* callback function type */
-typedef void (*iterate_func_t)(struct cpu_info *,
- unsigned int,
- unsigned int,
- unsigned int,
- void *);
-
+typedef void (*iterate_func_t)(struct cpu_info *, unsigned int,
+ unsigned int, unsigned int, void *);
static inline void
-evt_iterate_pending(struct cpu_info *ci,
- volatile unsigned long *pendingl1,
- volatile unsigned long *pendingl2,
- volatile unsigned long *mask,
- iterate_func_t iterate_pending,
- void *iterate_args)
+evt_iterate_bits(struct cpu_info *ci, volatile unsigned long *pendingl1,
+ volatile unsigned long *pendingl2,
+ volatile unsigned long *mask,
+ iterate_func_t iterate_pending, void *iterate_args)
{
KASSERT(pendingl1 != NULL);
@@ -148,11 +130,8 @@
*/
static inline void
-evt_set_pending(struct cpu_info *ci,
- unsigned int port,
- unsigned int l1i,
- unsigned int l2i,
- void *args)
+evt_set_pending(struct cpu_info *ci, unsigned int port, unsigned int l1i,
+ unsigned int l2i, void *args)
{
KASSERT(args != NULL);
@@ -161,9 +140,8 @@
int *ret = args;
if (evtsource[port]) {
- hypervisor_set_ipending(ci,
- evtsource[port]->ev_imask,
- l1i, l2i);
+ hypervisor_set_ipending(ci, evtsource[port]->ev_imask,
+ l1i, l2i);
evtsource[port]->ev_evcnt.ev_count++;
if (*ret == 0 && ci->ci_ilevel <
evtsource[port]->ev_maxlevel)
@@ -214,12 +192,9 @@
vci->evtchn_upcall_pending = 0;
- evt_iterate_pending(ci,
- &vci->evtchn_pending_sel,
- s->evtchn_pending,
- s->evtchn_mask,
- evt_set_pending,
- &ret);
+ evt_iterate_bits(ci, &vci->evtchn_pending_sel,
+ s->evtchn_pending, s->evtchn_mask,
+ evt_set_pending, &ret);
sti();
}
@@ -238,11 +213,8 @@
/* Iterate through pending events and call the event handler */
static inline void
-evt_do_hypervisor_callback(struct cpu_info *ci,
- unsigned int port,
- unsigned int l1i,
- unsigned int l2i,
- void *args)
+evt_do_hypervisor_callback(struct cpu_info *ci, unsigned int port,
+ unsigned int l1i, unsigned int l2i, void *args)
{
KASSERT(args != NULL);
KASSERT(ci == curcpu());
@@ -295,12 +267,9 @@
while (vci->evtchn_upcall_pending) {
vci->evtchn_upcall_pending = 0;
- evt_iterate_pending(ci,
- &vci->evtchn_pending_sel,
- s->evtchn_pending,
- s->evtchn_mask,
- evt_do_hypervisor_callback,
- regs);
+ evt_iterate_bits(ci, &vci->evtchn_pending_sel,
+ s->evtchn_pending, s->evtchn_mask,
+ evt_do_hypervisor_callback, regs);
}
#ifdef DIAGNOSTIC
@@ -361,11 +330,8 @@
}
static inline void
-evt_enable_event(struct cpu_info *ci,
- unsigned int port,
- unsigned int l1i,
- unsigned int l2i,
- void *args)
+evt_enable_event(struct cpu_info *ci, unsigned int port,
+ unsigned int l1i, unsigned int l2i, void *args)
{
KASSERT(ci != NULL);
KASSERT(args == NULL);
@@ -383,19 +349,14 @@
* we know that all callback for this event have been processed.
*/
- evt_iterate_pending(ci,
- &ci->ci_isources[ipl]->ipl_evt_mask1,
- ci->ci_isources[ipl]->ipl_evt_mask2,
- NULL,
- evt_enable_event,
- NULL);
+ evt_iterate_bits(ci, &ci->ci_isources[ipl]->ipl_evt_mask1,
+ ci->ci_isources[ipl]->ipl_evt_mask2, NULL,
+ evt_enable_event, NULL);
}
void
-hypervisor_set_ipending(struct cpu_info *ci,
- uint32_t iplmask,
- int l1, int l2)
+hypervisor_set_ipending(struct cpu_info *ci, uint32_t iplmask, int l1, int l2)
{
int ipl;
Index: src/sys/arch/xen/x86/intr.c
diff -u src/sys/arch/xen/x86/intr.c:1.27.6.1 src/sys/arch/xen/x86/intr.c:1.27.6.2
--- src/sys/arch/xen/x86/intr.c:1.27.6.1 Fri Jun 3 13:27:41 2011
+++ src/sys/arch/xen/x86/intr.c Wed Aug 17 09:40:40 2011
@@ -103,7 +103,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.27.6.1 2011/06/03 13:27:41 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.27.6.2 2011/08/17 09:40:40 cherry Exp $");
#include "opt_multiprocessor.h"
#include "opt_xen.h"
@@ -119,7 +119,6 @@
#include <sys/proc.h>
#include <sys/errno.h>
#include <sys/cpu.h>
-#include <sys/simplelock.h>
#include <uvm/uvm_extern.h>
@@ -154,28 +153,6 @@
#endif
/*
- * Recalculate the interrupt from scratch for an event source.
- */
-void
-intr_calculatemasks(struct evtsource *evts)
-{
- struct intrhand *ih;
-
-#ifdef MULTIPROCESSOR /* on UP, #define simple_lock_held(alp) 1 */
- KASSERT(!simple_lock_held(&evts->ev_lock));
-#endif
- simple_lock(&evts->ev_lock);
- evts->ev_maxlevel = IPL_NONE;
- evts->ev_imask = 0;
- for (ih = evts->ev_handlers; ih != NULL; ih = ih->ih_evt_next) {
- if (ih->ih_level > evts->ev_maxlevel)
- evts->ev_maxlevel = ih->ih_level;
- evts->ev_imask |= (1 << ih->ih_level);
- }
- simple_unlock(&evts->ev_lock);
-}
-
-/*
* Fake interrupt handler structures for the benefit of symmetry with
* other interrupt sources.
*/
Index: src/sys/arch/xen/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.5 src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.6
--- src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.5 Sun Jul 31 20:49:11 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c Wed Aug 17 09:40:40 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: x86_xpmap.c,v 1.26.2.5 2011/07/31 20:49:11 cherry Exp $ */
+/* $NetBSD: x86_xpmap.c,v 1.26.2.6 2011/08/17 09:40:40 cherry Exp $ */
/*
* Copyright (c) 2006 Mathieu Ropert <[email protected]>
@@ -69,7 +69,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.26.2.5 2011/07/31 20:49:11 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.26.2.6 2011/08/17 09:40:40 cherry Exp $");
#include "opt_xen.h"
#include "opt_ddb.h"
@@ -77,6 +77,7 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/simplelock.h>
#include <uvm/uvm.h>
@@ -165,6 +166,8 @@
#define XPQUEUE_SIZE 2048
static mmu_update_t xpq_queue[XPQUEUE_SIZE];
static int xpq_idx = 0;
+
+#ifdef MULTIPROCESSOR
static struct simplelock xpq_lock = SIMPLELOCK_INITIALIZER;
void
@@ -179,13 +182,20 @@
simple_unlock(&xpq_lock);
}
+bool
+xpq_queue_locked(void)
+{
+ return simple_lock_held(&xpq_lock);
+}
+#endif /* MULTIPROCESSOR */
+
/* Must be called with xpq_lock held */
void
xpq_flush_queue(void)
{
int i, ok, ret;
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
XENPRINTK2(("flush queue %p entries %d\n", xpq_queue, xpq_idx));
for (i = 0; i < xpq_idx; i++)
XENPRINTK2(("%d: 0x%08" PRIx64 " 0x%08" PRIx64 "\n", i,
@@ -209,7 +219,7 @@
xpq_increment_idx(void)
{
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_idx++;
if (__predict_false(xpq_idx == XPQUEUE_SIZE))
xpq_flush_queue();
@@ -220,7 +230,7 @@
{
XENPRINTK2(("xpq_queue_machphys_update ma=0x%" PRIx64 " pa=0x%" PRIx64
"\n", (int64_t)ma, (int64_t)pa));
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_queue[xpq_idx].ptr = ma | MMU_MACHPHYS_UPDATE;
xpq_queue[xpq_idx].val = (pa - XPMAP_OFFSET) >> PAGE_SHIFT;
xpq_increment_idx();
@@ -234,7 +244,7 @@
{
KASSERT((ptr & 3) == 0);
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_queue[xpq_idx].ptr = (paddr_t)ptr | MMU_NORMAL_PT_UPDATE;
xpq_queue[xpq_idx].val = val;
xpq_increment_idx();
@@ -247,7 +257,7 @@
xpq_queue_pt_switch(paddr_t pa)
{
struct mmuext_op op;
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
XENPRINTK2(("xpq_queue_pt_switch: 0x%" PRIx64 " 0x%" PRIx64 "\n",
@@ -263,7 +273,7 @@
{
struct mmuext_op op;
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
XENPRINTK2(("xpq_queue_pin_l%d_table: %#" PRIxPADDR "\n",
@@ -281,7 +291,7 @@
{
struct mmuext_op op;
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
XENPRINTK2(("xpq_queue_unpin_table: %#" PRIxPADDR "\n", pa));
@@ -296,7 +306,7 @@
{
struct mmuext_op op;
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
XENPRINTK2(("xpq_queue_set_ldt\n"));
@@ -313,7 +323,7 @@
{
struct mmuext_op op;
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
XENPRINTK2(("xpq_queue_tlb_flush\n"));
@@ -344,7 +354,7 @@
xpq_queue_invlpg(vaddr_t va)
{
struct mmuext_op op;
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
XENPRINTK2(("xpq_queue_invlpg %#" PRIxVADDR "\n", va));
@@ -359,7 +369,7 @@
{
mmuext_op_t op;
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
/* Flush pending page updates */
xpq_flush_queue();
@@ -381,7 +391,7 @@
mmuext_op_t op;
/* Flush pending page updates */
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
op.cmd = MMUEXT_INVLPG_ALL;
@@ -401,7 +411,7 @@
mmuext_op_t op;
/* Flush pending page updates */
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
op.cmd = MMUEXT_TLB_FLUSH_MULTI;
@@ -421,7 +431,7 @@
mmuext_op_t op;
/* Flush pending page updates */
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
op.cmd = MMUEXT_TLB_FLUSH_ALL;
@@ -440,7 +450,7 @@
KASSERT(eva > sva);
/* Flush pending page updates */
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
/* Align to nearest page boundary */
@@ -461,7 +471,7 @@
KASSERT(eva > sva);
/* Flush pending page updates */
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
/* Align to nearest page boundary */
@@ -481,7 +491,7 @@
mmu_update_t op;
int ok;
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
op.ptr = ptr;
@@ -1066,7 +1076,7 @@
struct mmuext_op op;
int s = splvm();
- KASSERT(simple_lock_held(&xpq_lock));
+ KASSERT(xpq_queue_locked());
xpq_flush_queue();
op.cmd = MMUEXT_NEW_USER_BASEPTR;
op.arg1.mfn = xpmap_phys_to_machine_mapping[page >> PAGE_SHIFT];
Index: src/sys/arch/xen/x86/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.1.2.2 src/sys/arch/xen/x86/xen_ipi.c:1.1.2.3
--- src/sys/arch/xen/x86/xen_ipi.c:1.1.2.2 Sun Jul 31 20:49:12 2011
+++ src/sys/arch/xen/x86/xen_ipi.c Wed Aug 17 09:40:40 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.1.2.2 2011/07/31 20:49:12 cherry Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.1.2.3 2011/08/17 09:40:40 cherry Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,10 +33,10 @@
/*
* Based on: x86/ipi.c
- * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.2 2011/07/31 20:49:12 cherry Exp $");
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.3 2011/08/17 09:40:40 cherry Exp $");
*/
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.2 2011/07/31 20:49:12 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.3 2011/08/17 09:40:40 cherry Exp $");
#include <sys/types.h>
@@ -96,14 +96,11 @@
ci->ci_ipi_events[bit].ev_count++;
if (ipifunc[bit] != NULL) {
(*ipifunc[bit])(ci, regs);
- }
- else {
+ } else {
panic("ipifunc[%d] unsupported!\n", bit);
/* NOTREACHED */
}
}
-
- return;
}
/* Must be called once for every cpu that expects to send/recv ipis */
@@ -119,7 +116,8 @@
vcpu = ci->ci_cpuid;
KASSERT(vcpu < MAX_VIRT_CPUS);
- evtchn = ci->ci_ipi_evtchn = bind_vcpu_to_evtch(vcpu);
+ evtchn = bind_vcpu_to_evtch(vcpu);
+ ci->ci_ipi_evtchn = evtchn;
KASSERT(evtchn != -1 && evtchn < NR_EVENT_CHANNELS);
@@ -130,7 +128,6 @@
}
hypervisor_enable_event(evtchn);
- return;
}
/* prefer this to global variable */
@@ -148,8 +145,7 @@
if (ipimask & ~masks) {
return false;
- }
- else {
+ } else {
return true;
}
@@ -162,15 +158,14 @@
KASSERT(ci != NULL || ci != curcpu());
- if (!(ci->ci_flags & CPUF_RUNNING)) {
+ if ((ci->ci_flags & CPUF_RUNNING) == 0) {
return ENOENT;
}
evtchn = ci->ci_ipi_evtchn;
- if (false == valid_ipimask(ipimask)) {
- panic("xen_send_ipi() called with invalid ipimask\n");
- /* NOTREACHED */
- }
+
+ KASSERTMSG(valid_ipimask(ipimask) == true,
+ ("xen_send_ipi() called with invalid ipimask\n"));
atomic_or_32(&ci->ci_ipis, ipimask);
hypervisor_notify_via_evtchn(evtchn);
@@ -184,10 +179,8 @@
struct cpu_info *ci, *self = curcpu();
CPU_INFO_ITERATOR cii;
- if (false == valid_ipimask(ipimask)) {
- panic("xen_broadcast_ipi() called with invalid ipimask\n");
- /* NOTREACHED */
- }
+ KASSERTMSG(valid_ipimask(ipimask) == true,
+ ("xen_broadcast_ipi() called with invalid ipimask\n"));
/*
* XXX-cherry: there's an implicit broadcast sending order
@@ -211,9 +204,6 @@
}
}
}
-
- return;
- /* NOTREACHED */
}
/* MD wrapper for the xcall(9) callback. */
@@ -228,7 +218,6 @@
panic("vcpu%" PRIuCPUID "shutdown failed.\n", ci->ci_cpuid);
}
- return;
}
static void
@@ -242,7 +231,6 @@
#else
npxsave_cpu(true);
#endif /* __x86_64__ */
- return;
}
static void
@@ -291,7 +279,6 @@
KASSERT(intrf != NULL);
xc_ipi_handler();
- return;
}
void
@@ -304,7 +291,7 @@
if (ci) {
if (0 != xen_send_ipi(ci, XEN_IPI_XCALL)) {
panic("xen_send_ipi(XEN_IPI_XCALL) failed\n");
- };
+ }
} else {
xen_broadcast_ipi(XEN_IPI_XCALL);
}
Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.47.6.3 src/sys/arch/xen/xen/evtchn.c:1.47.6.4
--- src/sys/arch/xen/xen/evtchn.c:1.47.6.3 Thu Aug 4 13:04:20 2011
+++ src/sys/arch/xen/xen/evtchn.c Wed Aug 17 09:40:40 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: evtchn.c,v 1.47.6.3 2011/08/04 13:04:20 cherry Exp $ */
+/* $NetBSD: evtchn.c,v 1.47.6.4 2011/08/17 09:40:40 cherry Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.47.6.3 2011/08/04 13:04:20 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.47.6.4 2011/08/17 09:40:40 cherry Exp $");
#include "opt_xen.h"
#include "isa.h"
@@ -68,7 +68,7 @@
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/reboot.h>
-#include <sys/simplelock.h>
+#include <sys/mutex.h>
#include <uvm/uvm.h>
@@ -83,11 +83,14 @@
* This lock protects updates to the following mapping and reference-count
* arrays. The lock does not need to be acquired to read the mapping tables.
*/
-static struct simplelock evtchn_lock = SIMPLELOCK_INITIALIZER;
+static kmutex_t evtchn_lock;
/* event handlers */
struct evtsource *evtsource[NR_EVENT_CHANNELS];
+/* channel locks */
+static kmutex_t evtlock[NR_EVENT_CHANNELS];
+
/* Reference counts for bindings to event channels XXX: redo for SMP */
static uint8_t evtch_bindcount[NR_EVENT_CHANNELS];
@@ -249,7 +252,7 @@
if (evtsource[evtch]->ev_cpu != ci) {
/* facilitate spllower() on remote cpu */
struct cpu_info *rci = evtsource[evtch]->ev_cpu;
- if (xen_send_ipi(rci, XEN_IPI_KICK)) {
+ if (xen_send_ipi(rci, XEN_IPI_KICK) != 0) {
panic("xen_send_ipi(%s, XEN_IPI_KICK) failed\n", cpu_name(rci));
}
}
@@ -260,7 +263,7 @@
ci->ci_ilevel = evtsource[evtch]->ev_maxlevel;
iplmask = evtsource[evtch]->ev_imask;
sti();
- simple_lock(&evtsource[evtch]->ev_lock);
+ mutex_spin_enter(&evtlock[evtch]);
ih = evtsource[evtch]->ev_handlers;
while (ih != NULL) {
if (ih->ih_level <= ilevel ||
@@ -273,7 +276,7 @@
hypervisor_set_ipending(ih->ih_cpu, iplmask,
evtch >> LONG_SHIFT, evtch & LONG_MASK);
/* leave masked */
- simple_unlock(&evtsource[evtch]->ev_lock);
+ mutex_spin_exit(&evtlock[evtch]);
goto splx;
}
iplmask &= ~IUNMASK(ci, ih->ih_level);
@@ -282,7 +285,7 @@
ih_fun(ih->ih_arg, regs);
ih = ih->ih_evt_next;
}
- simple_unlock(&evtsource[evtch]->ev_lock);
+ mutex_spin_exit(&evtlock[evtch]);
cli();
hypervisor_enable_event(evtch);
splx:
@@ -333,10 +336,8 @@
{
evtchn_op_t op;
evtchn_port_t evtchn;
- int s;
- s = splhigh();
- simple_lock(&evtchn_lock);
+ mutex_spin_enter(&evtchn_lock);
evtchn = vcpu_ipi_to_evtch[vcpu];
if (evtchn == -1) {
@@ -351,8 +352,7 @@
evtch_bindcount[evtchn]++;
- simple_unlock(&evtchn_lock);
- splx(s);
+ mutex_spin_exit(&evtchn_lock);
return evtchn;
}
@@ -361,10 +361,9 @@
bind_virq_to_evtch(int virq)
{
evtchn_op_t op;
- int evtchn, s;
+ int evtchn;
- s = splhigh();
- simple_lock(&evtchn_lock);
+ mutex_spin_enter(&evtchn_lock);
/*
* XXX: The only per-cpu VIRQ we currently use is VIRQ_TIMER.
@@ -376,6 +375,7 @@
struct cpu_info *ci = curcpu();
if (virq == VIRQ_DEBUG && ci != &cpu_info_primary) {
+ mutex_spin_exit(&evtchn_lock);
return -1;
}
@@ -398,8 +398,7 @@
evtch_bindcount[evtchn]++;
- simple_unlock(&evtchn_lock);
- splx(s);
+ mutex_spin_exit(&evtchn_lock);
return evtchn;
}
@@ -409,7 +408,6 @@
{
evtchn_op_t op;
int evtchn;
- int s;
struct cpu_info *ci = curcpu();
@@ -424,8 +422,7 @@
return -1;
}
- s = splhigh();
- simple_lock(&evtchn_lock);
+ mutex_spin_enter(&evtchn_lock);
evtch_bindcount[evtchn]--;
if (evtch_bindcount[evtchn] == 0) {
@@ -437,8 +434,7 @@
virq_to_evtch[virq] = -1;
}
- simple_unlock(&evtchn_lock);
- splx(s);
+ mutex_spin_exit(&evtchn_lock);
return evtchn;
}
@@ -448,14 +444,13 @@
bind_pirq_to_evtch(int pirq)
{
evtchn_op_t op;
- int evtchn, s;
+ int evtchn;
if (pirq >= NR_PIRQS) {
panic("pirq %d out of bound, increase NR_PIRQS", pirq);
}
- s = splhigh();
- simple_lock(&evtchn_lock);
+ mutex_spin_enter(&evtchn_lock);
evtchn = pirq_to_evtch[pirq];
if (evtchn == -1) {
@@ -474,8 +469,7 @@
evtch_bindcount[evtchn]++;
- simple_unlock(&evtchn_lock);
- splx(s);
+ mutex_spin_exit(&evtchn_lock);
return evtchn;
}
@@ -485,9 +479,8 @@
{
evtchn_op_t op;
int evtchn = pirq_to_evtch[pirq];
- int s = splhigh();
- simple_lock(&evtchn_lock);
+ mutex_spin_enter(&evtchn_lock);
evtch_bindcount[evtchn]--;
if (evtch_bindcount[evtchn] == 0) {
@@ -499,8 +492,7 @@
pirq_to_evtch[pirq] = -1;
}
- simple_unlock(&evtchn_lock);
- splx(s);
+ mutex_spin_exit(&evtchn_lock);
return evtchn;
}
@@ -558,6 +550,29 @@
#endif /* NPCI > 0 || NISA > 0 */
+
+/*
+ * Recalculate the interrupt from scratch for an event source.
+ */
+static void
+intr_calculatemasks(struct evtsource *evts, int evtch)
+{
+ struct intrhand *ih;
+
+#ifdef MULTIPROCESSOR
+ KASSERT(!mutex_owned(&evtlock[evtch]));
+#endif
+ mutex_spin_enter(&evtlock[evtch]);
+ evts->ev_maxlevel = IPL_NONE;
+ evts->ev_imask = 0;
+ for (ih = evts->ev_handlers; ih != NULL; ih = ih->ih_evt_next) {
+ if (ih->ih_level > evts->ev_maxlevel)
+ evts->ev_maxlevel = ih->ih_level;
+ evts->ev_imask |= (1 << ih->ih_level);
+ }
+ mutex_spin_exit(&evtlock[evtch]);
+}
+
int
event_set_handler(int evtch, int (*func)(void *), void *arg, int level,
const char *evname)
@@ -624,7 +639,7 @@
* is more explicitly implemented.
*/
evts->ev_cpu = ci;
- simple_lock_init(&evts->ev_lock);
+ mutex_init(&evtlock[evtch], MUTEX_DEFAULT, IPL_HIGH);
evtsource[evtch] = evts;
if (evname)
strncpy(evts->ev_evname, evname,
@@ -637,7 +652,7 @@
} else {
evts = evtsource[evtch];
/* sort by IPL order, higher first */
- simple_lock(&evts->ev_lock);
+ mutex_spin_enter(&evtlock[evtch]);
for (ihp = &evts->ev_handlers; ; ihp = &((*ihp)->ih_evt_next)) {
if ((*ihp)->ih_level < ih->ih_level) {
/* insert before *ihp */
@@ -650,10 +665,10 @@
break;
}
}
- simple_unlock(&evts->ev_lock);
+ mutex_spin_exit(&evtlock[evtch]);
}
- intr_calculatemasks(evts);
+ intr_calculatemasks(evts, evtch);
splx(s);
return 0;
@@ -696,7 +711,7 @@
if (evts == NULL)
return ENOENT;
- simple_lock(&evts->ev_lock);
+ mutex_spin_enter(&evtlock[evtch]);
for (ihp = &evts->ev_handlers, ih = evts->ev_handlers;
ih != NULL;
ihp = &ih->ih_evt_next, ih = ih->ih_evt_next) {
@@ -704,11 +719,11 @@
break;
}
if (ih == NULL) {
- simple_unlock(&evts->ev_lock);
+ mutex_spin_exit(&evtlock[evtch]);
return ENOENT;
}
*ihp = ih->ih_evt_next;
- simple_unlock(&evts->ev_lock);
+ mutex_spin_exit(&evtlock[evtch]);
ipls = ci->ci_isources[ih->ih_level];
for (ihp = &ipls->ipl_handlers, ih = ipls->ipl_handlers;
@@ -726,7 +741,7 @@
free(evts, M_DEVBUF);
evtsource[evtch] = NULL;
} else {
- intr_calculatemasks(evts);
+ intr_calculatemasks(evts, evtch);
}
return 0;
}
Index: src/sys/arch/xen/xen/xentests.c
diff -u src/sys/arch/xen/xen/xentests.c:1.1.2.2 src/sys/arch/xen/xen/xentests.c:1.1.2.3
--- src/sys/arch/xen/xen/xentests.c:1.1.2.2 Fri Aug 5 17:26:27 2011
+++ src/sys/arch/xen/xen/xentests.c Wed Aug 17 09:40:40 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xentests.c,v 1.1.2.2 2011/08/05 17:26:27 cherry Exp $ */
+/* $NetBSD: xentests.c,v 1.1.2.3 2011/08/17 09:40:40 cherry Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xentests.c,v 1.1.2.2 2011/08/05 17:26:27 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xentests.c,v 1.1.2.3 2011/08/17 09:40:40 cherry Exp $");
#include <sys/types.h>
@@ -43,6 +43,7 @@
#include <sys/kthread.h>
#include <sys/mutex.h>
#include <sys/sched.h>
+#include <sys/simplelock.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <sys/xcall.h>