Make cross-cpu pte access MP safe.

XXX: review cases of use of pmap_set_pte() vs direct use of xpq_queue_pte_update()
This commit is contained in:
cherry 2012-01-09 13:04:13 +00:00
parent 0e1fd236aa
commit 66e35f7978
3 changed files with 42 additions and 29 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pmap.h,v 1.28 2011/11/06 15:18:18 cherry Exp $ */
/* $NetBSD: pmap.h,v 1.29 2012/01/09 13:04:13 cherry Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@ -263,6 +263,8 @@
atomic_and_ulong((volatile unsigned long *)p, ~(b))
#define pmap_pte_flush() /* nothing */
#else
extern kmutex_t pte_lock;
static __inline pt_entry_t
pmap_pa2pte(paddr_t pa)
{
@ -277,54 +279,57 @@ pmap_pte2pa(pt_entry_t pte)
static __inline void
pmap_pte_set(pt_entry_t *pte, pt_entry_t npte)
{
int s = splvm();
mutex_enter(&pte_lock);
xpq_queue_pte_update(xpmap_ptetomach(pte), npte);
splx(s);
mutex_exit(&pte_lock);
}
static __inline pt_entry_t
pmap_pte_cas(volatile pt_entry_t *ptep, pt_entry_t o, pt_entry_t n)
{
int s = splvm();
pt_entry_t opte = *ptep;
pt_entry_t opte;
mutex_enter(&pte_lock);
opte = *ptep;
if (opte == o) {
xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(ptep)), n);
xpq_flush_queue();
}
splx(s);
mutex_exit(&pte_lock);
return opte;
}
static __inline pt_entry_t
pmap_pte_testset(volatile pt_entry_t *pte, pt_entry_t npte)
{
int s = splvm();
pt_entry_t opte = *pte;
pt_entry_t opte;
mutex_enter(&pte_lock);
opte = *pte;
xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), npte);
xpq_flush_queue();
splx(s);
mutex_exit(&pte_lock);
return opte;
}
static __inline void
pmap_pte_setbits(volatile pt_entry_t *pte, pt_entry_t bits)
{
int s = splvm();
mutex_enter(&pte_lock);
xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), (*pte) | bits);
xpq_flush_queue();
splx(s);
mutex_exit(&pte_lock);
}
static __inline void
pmap_pte_clearbits(volatile pt_entry_t *pte, pt_entry_t bits)
{
int s = splvm();
mutex_enter(&pte_lock);
xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)),
(*pte) & ~bits);
xpq_flush_queue();
splx(s);
mutex_exit(&pte_lock);
}
static __inline void

View File

@ -1,4 +1,4 @@
/* $NetBSD: pmap.h,v 1.112 2011/11/06 15:18:18 cherry Exp $ */
/* $NetBSD: pmap.h,v 1.113 2012/01/09 13:04:13 cherry Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@ -354,6 +354,8 @@
#endif /* PAE */
#else /* XEN */
extern kmutex_t pte_lock;
static __inline pt_entry_t
pmap_pa2pte(paddr_t pa)
{
@ -368,54 +370,57 @@ pmap_pte2pa(pt_entry_t pte)
static __inline void
pmap_pte_set(pt_entry_t *pte, pt_entry_t npte)
{
int s = splvm();
mutex_enter(&pte_lock);
xpq_queue_pte_update(xpmap_ptetomach(pte), npte);
splx(s);
mutex_exit(&pte_lock);
}
static __inline pt_entry_t
pmap_pte_cas(volatile pt_entry_t *ptep, pt_entry_t o, pt_entry_t n)
{
int s = splvm();
pt_entry_t opte = *ptep;
pt_entry_t opte;
mutex_enter(&pte_lock);
opte = *ptep;
if (opte == o) {
xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(ptep)), n);
xpq_flush_queue();
}
splx(s);
mutex_exit(&pte_lock);
return opte;
}
static __inline pt_entry_t
pmap_pte_testset(volatile pt_entry_t *pte, pt_entry_t npte)
{
int s = splvm();
pt_entry_t opte = *pte;
pt_entry_t opte;
mutex_enter(&pte_lock);
opte = *pte;
xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)),
npte);
xpq_flush_queue();
splx(s);
mutex_exit(&pte_lock);
return opte;
}
static __inline void
pmap_pte_setbits(volatile pt_entry_t *pte, pt_entry_t bits)
{
int s = splvm();
mutex_enter(&pte_lock);
xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), (*pte) | bits);
xpq_flush_queue();
splx(s);
mutex_exit(&pte_lock);
}
static __inline void
pmap_pte_clearbits(volatile pt_entry_t *pte, pt_entry_t bits)
{
int s = splvm();
mutex_enter(&pte_lock);
xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)),
(*pte) & ~bits);
xpq_flush_queue();
splx(s);
mutex_exit(&pte_lock);
}
static __inline void

View File

@ -1,4 +1,4 @@
/* $NetBSD: x86_xpmap.c,v 1.36 2011/11/06 15:18:19 cherry Exp $ */
/* $NetBSD: x86_xpmap.c,v 1.37 2012/01/09 13:04:13 cherry 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.36 2011/11/06 15:18:19 cherry Exp $");
__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.37 2012/01/09 13:04:13 cherry Exp $");
#include "opt_xen.h"
#include "opt_ddb.h"
@ -117,6 +117,7 @@ volatile shared_info_t *HYPERVISOR_shared_info;
/* Xen requires the start_info struct to be page aligned */
union start_info_union start_info_union __aligned(PAGE_SIZE);
unsigned long *xpmap_phys_to_machine_mapping;
kmutex_t pte_lock;
void xen_failsafe_handler(void);
@ -652,6 +653,8 @@ bootstrap_again:
/* Finally, flush TLB. */
xpq_queue_tlb_flush();
mutex_init(&pte_lock, MUTEX_DEFAULT, IPL_VM);
return (init_tables + ((count + l2_4_count) * PAGE_SIZE));
}