Few fixes for Xen:
- cpu_load_pmap: use atomic kcpuset(9) operations; fixes rare crashes. - Add kcpuset_copybits(9) and replace xen_kcpuset2bits(). Avoids incorrect ncpu problem in early boot. Also, micro-optimises xen_mcast_invlpg() and xen_mcast_tlbflush() routines. Tested by chs@.
This commit is contained in:
parent
c1004a7836
commit
e75fa0930a
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cpu.c,v 1.91 2012/04/20 22:23:25 rmind Exp $ */
|
||||
/* $NetBSD: cpu.c,v 1.92 2012/06/06 22:22:41 rmind 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.91 2012/04/20 22:23:25 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.92 2012/06/06 22:22:41 rmind Exp $");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
#include "opt_multiprocessor.h"
|
||||
@ -1110,10 +1110,11 @@ cpu_load_pmap(struct pmap *pmap, struct pmap *oldpmap)
|
||||
|
||||
#if defined(__x86_64__) || defined(PAE)
|
||||
struct cpu_info *ci = curcpu();
|
||||
cpuid_t cid = cpu_index(ci);
|
||||
|
||||
mutex_enter(&ci->ci_kpm_mtx);
|
||||
/* make new pmap visible to pmap_kpm_sync_xcall() */
|
||||
kcpuset_set(pmap->pm_xen_ptp_cpus, cpu_index(ci));
|
||||
kcpuset_atomic_set(pmap->pm_xen_ptp_cpus, cid);
|
||||
#endif
|
||||
#ifdef i386
|
||||
#ifdef PAE
|
||||
@ -1166,9 +1167,9 @@ cpu_load_pmap(struct pmap *pmap, struct pmap *oldpmap)
|
||||
#endif /* __x86_64__ */
|
||||
#if defined(__x86_64__) || defined(PAE)
|
||||
/* old pmap no longer visible to pmap_kpm_sync_xcall() */
|
||||
if (oldpmap != pmap_kernel())
|
||||
kcpuset_clear(oldpmap->pm_xen_ptp_cpus, cpu_index(ci));
|
||||
|
||||
if (oldpmap != pmap_kernel()) {
|
||||
kcpuset_atomic_clear(oldpmap->pm_xen_ptp_cpus, cid);
|
||||
}
|
||||
mutex_exit(&ci->ci_kpm_mtx);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: x86_xpmap.c,v 1.43 2012/04/20 22:23:25 rmind Exp $ */
|
||||
/* $NetBSD: x86_xpmap.c,v 1.44 2012/06/06 22:22:41 rmind Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Mathieu Ropert <mro@adviseo.fr>
|
||||
@ -69,7 +69,7 @@
|
||||
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.43 2012/04/20 22:23:25 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.44 2012/06/06 22:22:41 rmind Exp $");
|
||||
|
||||
#include "opt_xen.h"
|
||||
#include "opt_ddb.h"
|
||||
@ -361,32 +361,14 @@ xpq_queue_invlpg(vaddr_t va)
|
||||
panic("xpq_queue_invlpg");
|
||||
}
|
||||
|
||||
#if defined(_LP64) && MAXCPUS > 64
|
||||
#error "XEN/amd64 uses 64 bit masks"
|
||||
#elsif !defined(_LP64) && MAXCPUS > 32
|
||||
#error "XEN/i386 uses 32 bit masks"
|
||||
#else
|
||||
/* XXX: Inefficient. */
|
||||
static u_long
|
||||
xen_kcpuset2bits(kcpuset_t *kc)
|
||||
{
|
||||
u_long bits = 0;
|
||||
|
||||
for (cpuid_t i = 0; i < ncpu; i++) {
|
||||
if (kcpuset_isset(kc, i)) {
|
||||
bits |= 1 << i;
|
||||
}
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
xen_mcast_invlpg(vaddr_t va, kcpuset_t *kc)
|
||||
{
|
||||
u_long xcpumask = xen_kcpuset2bits(kc);
|
||||
u_long xcpumask = 0;
|
||||
mmuext_op_t op;
|
||||
|
||||
kcpuset_copybits(kc, &xcpumask, sizeof(xcpumask));
|
||||
|
||||
/* Flush pending page updates */
|
||||
xpq_flush_queue();
|
||||
|
||||
@ -423,9 +405,11 @@ xen_bcast_invlpg(vaddr_t va)
|
||||
void
|
||||
xen_mcast_tlbflush(kcpuset_t *kc)
|
||||
{
|
||||
u_long xcpumask = xen_kcpuset2bits(kc);
|
||||
u_long xcpumask = 0;
|
||||
mmuext_op_t op;
|
||||
|
||||
kcpuset_copybits(kc, &xcpumask, sizeof(xcpumask));
|
||||
|
||||
/* Flush pending page updates */
|
||||
xpq_flush_queue();
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: subr_kcpuset.c,v 1.5 2012/04/20 22:23:25 rmind Exp $ */
|
||||
/* $NetBSD: subr_kcpuset.c,v 1.6 2012/06/06 22:22:41 rmind Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 The NetBSD Foundation, Inc.
|
||||
@ -41,7 +41,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_kcpuset.c,v 1.5 2012/04/20 22:23:25 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_kcpuset.c,v 1.6 2012/06/06 22:22:41 rmind Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
@ -301,6 +301,15 @@ kcpuset_copyout(kcpuset_t *kcp, cpuset_t *ucp, size_t len)
|
||||
return copyout(kcp, ucp, len);
|
||||
}
|
||||
|
||||
void
|
||||
kcpuset_copybits(const kcpuset_t *kcp, void *bitfield, size_t len)
|
||||
{
|
||||
size_t rlen = MIN(kc_bitsize, len);
|
||||
|
||||
KASSERT(kcp != NULL);
|
||||
memcpy(bitfield, kcp->bits, rlen);
|
||||
}
|
||||
|
||||
/*
|
||||
* Routines to change bit field - zero, fill, copy, set, unset, etc.
|
||||
*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: kcpuset.h,v 1.5 2012/04/20 22:23:25 rmind Exp $ */
|
||||
/* $NetBSD: kcpuset.h,v 1.6 2012/06/06 22:22:41 rmind Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008, 2011 The NetBSD Foundation, Inc.
|
||||
@ -50,6 +50,7 @@ void kcpuset_unuse(kcpuset_t *, kcpuset_t **);
|
||||
|
||||
int kcpuset_copyin(const cpuset_t *, kcpuset_t *, size_t);
|
||||
int kcpuset_copyout(kcpuset_t *, cpuset_t *, size_t);
|
||||
void kcpuset_copybits(const kcpuset_t *, void *, size_t);
|
||||
|
||||
void kcpuset_zero(kcpuset_t *);
|
||||
void kcpuset_fill(kcpuset_t *);
|
||||
|
Loading…
Reference in New Issue
Block a user