xref: /illumos-gate/usr/src/uts/i86pc/vm/htable.h (revision 74ecdb51)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ae115bc7Smrj  * Common Development and Distribution License (the "License").
6ae115bc7Smrj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
25a6a74e0eSMatthew Ahrens /*
26a6a74e0eSMatthew Ahrens  * Copyright (c) 2014 by Delphix. All rights reserved.
27*74ecdb51SJohn Levon  * Copyright 2018 Joyent, Inc.
28a6a74e0eSMatthew Ahrens  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef	_VM_HTABLE_H
317c478bd9Sstevel@tonic-gate #define	_VM_HTABLE_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #if defined(__GNUC__) && defined(_ASM_INLINES) && defined(_KERNEL)
387c478bd9Sstevel@tonic-gate #include <asm/htable.h>
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate extern void atomic_andb(uint8_t *addr, uint8_t value);
427c478bd9Sstevel@tonic-gate extern void atomic_orb(uint8_t *addr, uint8_t value);
437c478bd9Sstevel@tonic-gate extern void atomic_inc16(uint16_t *addr);
447c478bd9Sstevel@tonic-gate extern void atomic_dec16(uint16_t *addr);
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * Each hardware page table has an htable_t describing it.
487c478bd9Sstevel@tonic-gate  *
497c478bd9Sstevel@tonic-gate  * We use a reference counter mechanism to detect when we can free an htable.
507c478bd9Sstevel@tonic-gate  * In the implmentation the reference count is split into 2 separate counters:
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  *	ht_busy is a traditional reference count of uses of the htable pointer
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  *	ht_valid_cnt is a count of how references are implied by valid PTE/PTP
557c478bd9Sstevel@tonic-gate  *	         entries in the pagetable
567c478bd9Sstevel@tonic-gate  *
577c478bd9Sstevel@tonic-gate  * ht_busy is only incremented by htable_lookup() or htable_create()
587c478bd9Sstevel@tonic-gate  * while holding the appropriate hash_table mutex. While installing a new
597c478bd9Sstevel@tonic-gate  * valid PTE or PTP, in order to increment ht_valid_cnt a thread must have
607c478bd9Sstevel@tonic-gate  * done an htable_lookup() or htable_create() but not the htable_release yet.
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  * htable_release(), while holding the mutex, can know that if
637c478bd9Sstevel@tonic-gate  * busy == 1 and valid_cnt == 0, the htable can be free'd.
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  * The fields have been ordered to make htable_lookup() fast. Hence,
667c478bd9Sstevel@tonic-gate  * ht_hat, ht_vaddr, ht_level and ht_next need to be clustered together.
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate struct htable {
697c478bd9Sstevel@tonic-gate 	struct htable	*ht_next;	/* forward link for hash table */
707c478bd9Sstevel@tonic-gate 	struct hat	*ht_hat;	/* hat this mapping comes from */
717c478bd9Sstevel@tonic-gate 	uintptr_t	ht_vaddr;	/* virt addr at start of this table */
72ae115bc7Smrj 	int8_t		ht_level;	/* page table level: 0=4K, 1=2M, ... */
73ae115bc7Smrj 	uint8_t		ht_flags;	/* see below */
747c478bd9Sstevel@tonic-gate 	int16_t		ht_busy;	/* implements locking protocol */
757c478bd9Sstevel@tonic-gate 	int16_t		ht_valid_cnt;	/* # of valid entries in this table */
767c478bd9Sstevel@tonic-gate 	uint32_t	ht_lock_cnt;	/* # of locked entries in this table */
777c478bd9Sstevel@tonic-gate 					/* never used for kernel hat */
787c478bd9Sstevel@tonic-gate 	pfn_t		ht_pfn;		/* pfn of page of the pagetable */
797c478bd9Sstevel@tonic-gate 	struct htable	*ht_prev;	/* backward link for hash table */
807c478bd9Sstevel@tonic-gate 	struct htable	*ht_parent;	/* htable that points to this htable */
817c478bd9Sstevel@tonic-gate 	struct htable	*ht_shares;	/* for HTABLE_SHARED_PFN only */
827c478bd9Sstevel@tonic-gate };
837c478bd9Sstevel@tonic-gate typedef struct htable htable_t;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * Flags values for htable ht_flags field:
877c478bd9Sstevel@tonic-gate  *
88*74ecdb51SJohn Levon  * HTABLE_COPIED - This is the top level htable of a HAT being used with per-CPU
89*74ecdb51SJohn Levon  * 	pagetables.
907c478bd9Sstevel@tonic-gate  *
91ae115bc7Smrj  * HTABLE_SHARED_PFN - this htable had its PFN assigned from sharing another
927c478bd9Sstevel@tonic-gate  * 	htable. Used by hat_share() for ISM.
937c478bd9Sstevel@tonic-gate  */
94*74ecdb51SJohn Levon #define	HTABLE_COPIED		(0x01)
95ae115bc7Smrj #define	HTABLE_SHARED_PFN	(0x02)
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * The htable hash table hashing function.  The 28 is so that high
997c478bd9Sstevel@tonic-gate  * order bits are include in the hash index to skew the wrap
1007c8868c1Sjosephb  * around of addresses. Even though the hash buckets are stored per
1017c8868c1Sjosephb  * hat we include the value of hat pointer in the hash function so
1027c8868c1Sjosephb  * that the secondary hash for the htable mutex winds up begin different in
1037c8868c1Sjosephb  * every address space.
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate #define	HTABLE_HASH(hat, va, lvl)					\
1067c8868c1Sjosephb 	((((va) >> LEVEL_SHIFT(1)) + ((va) >> 28) + (lvl) +		\
1077c8868c1Sjosephb 	((uintptr_t)(hat) >> 4)) & ((hat)->hat_num_hash - 1))
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
110*74ecdb51SJohn Levon  * Each CPU gets a unique hat_cpu_info structure in cpu_hat_info. For more
111*74ecdb51SJohn Levon  * information on its use and members, see uts/i86pc/vm/hat_i86.c.
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate struct hat_cpu_info {
1147c478bd9Sstevel@tonic-gate 	kmutex_t hci_mutex;		/* mutex to ensure sequential usage */
1157c478bd9Sstevel@tonic-gate #if defined(__amd64)
116*74ecdb51SJohn Levon 	pfn_t	hci_pcp_l3pfn;		/* pfn of hci_pcp_l3ptes */
117*74ecdb51SJohn Levon 	pfn_t	hci_pcp_l2pfn;		/* pfn of hci_pcp_l2ptes */
118*74ecdb51SJohn Levon 	x86pte_t *hci_pcp_l3ptes;	/* PCP Level==3 pagetable (top) */
119*74ecdb51SJohn Levon 	x86pte_t *hci_pcp_l2ptes;	/* PCP Level==2 pagetable */
120*74ecdb51SJohn Levon 	struct hat *hci_user_hat;	/* CPU specific HAT */
121*74ecdb51SJohn Levon 	pfn_t	hci_user_l3pfn;		/* pfn of hci_user_l3ptes */
122*74ecdb51SJohn Levon 	x86pte_t *hci_user_l3ptes;	/* PCP User L3 pagetable */
1237c478bd9Sstevel@tonic-gate #endif	/* __amd64 */
1247c478bd9Sstevel@tonic-gate };
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * Compute the last page aligned VA mapped by an htable.
1297c478bd9Sstevel@tonic-gate  *
1307c478bd9Sstevel@tonic-gate  * Given a va and a level, compute the virtual address of the start of the
1317c478bd9Sstevel@tonic-gate  * next page at that level.
1327c478bd9Sstevel@tonic-gate  *
1337c478bd9Sstevel@tonic-gate  * XX64 - The check for the VA hole needs to be better generalized.
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate #if defined(__amd64)
136*74ecdb51SJohn Levon #define	HTABLE_NUM_PTES(ht)	(((ht)->ht_flags & HTABLE_COPIED) ? \
137*74ecdb51SJohn Levon 	(((ht)->ht_level == mmu.max_level) ? 512 : 4) : 512)
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #define	HTABLE_LAST_PAGE(ht)						\
1407c478bd9Sstevel@tonic-gate 	((ht)->ht_level == mmu.max_level ? ((uintptr_t)0UL - MMU_PAGESIZE) :\
1417c478bd9Sstevel@tonic-gate 	((ht)->ht_vaddr - MMU_PAGESIZE +				\
142ae115bc7Smrj 	((uintptr_t)HTABLE_NUM_PTES(ht) << LEVEL_SHIFT((ht)->ht_level))))
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #define	NEXT_ENTRY_VA(va, l)	\
1457c478bd9Sstevel@tonic-gate 	((va & LEVEL_MASK(l)) + LEVEL_SIZE(l) == mmu.hole_start ?	\
1467c478bd9Sstevel@tonic-gate 	mmu.hole_end : (va & LEVEL_MASK(l)) + LEVEL_SIZE(l))
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #elif defined(__i386)
1497c478bd9Sstevel@tonic-gate 
150843e1988Sjohnlev #define	HTABLE_NUM_PTES(ht)	\
151843e1988Sjohnlev 	(!mmu.pae_hat ? 1024 : ((ht)->ht_level == 2 ? 4 : 512))
152ae115bc7Smrj 
1537c478bd9Sstevel@tonic-gate #define	HTABLE_LAST_PAGE(ht)	((ht)->ht_vaddr - MMU_PAGESIZE + \
154ae115bc7Smrj 	((uintptr_t)HTABLE_NUM_PTES(ht) << LEVEL_SHIFT((ht)->ht_level)))
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #define	NEXT_ENTRY_VA(va, l) ((va & LEVEL_MASK(l)) + LEVEL_SIZE(l))
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #endif
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * initialization function called from hat_init()
1647c478bd9Sstevel@tonic-gate  */
1657c478bd9Sstevel@tonic-gate extern void htable_init(void);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate  * Functions to lookup, or "lookup and create", the htable corresponding
1697c478bd9Sstevel@tonic-gate  * to the virtual address "vaddr"  in the "hat" at the given "level" of
1707c478bd9Sstevel@tonic-gate  * page tables. htable_lookup() may return NULL if no such entry exists.
1717c478bd9Sstevel@tonic-gate  *
1727c478bd9Sstevel@tonic-gate  * On return the given htable is marked busy (a shared lock) - this prevents
1737c478bd9Sstevel@tonic-gate  * the htable from being stolen or freed) until htable_release() is called.
1747c478bd9Sstevel@tonic-gate  *
1757c478bd9Sstevel@tonic-gate  * If kalloc_flag is set on an htable_create() we can't call kmem allocation
1767c478bd9Sstevel@tonic-gate  * routines for this htable, since it's for the kernel hat itself.
1777c478bd9Sstevel@tonic-gate  *
1787c478bd9Sstevel@tonic-gate  * htable_acquire() is used when an htable pointer has been extracted from
1797c478bd9Sstevel@tonic-gate  * an hment and we need to get a reference to the htable.
1807c478bd9Sstevel@tonic-gate  */
1817c478bd9Sstevel@tonic-gate extern htable_t *htable_lookup(struct hat *hat, uintptr_t vaddr, level_t level);
1827c478bd9Sstevel@tonic-gate extern htable_t *htable_create(struct hat *hat, uintptr_t vaddr, level_t level,
1837c478bd9Sstevel@tonic-gate 	htable_t *shared);
1847c478bd9Sstevel@tonic-gate extern void htable_acquire(htable_t *);
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate extern void htable_release(htable_t *ht);
187ae115bc7Smrj extern void htable_destroy(htable_t *ht);
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate /*
1907c478bd9Sstevel@tonic-gate  * Code to free all remaining htables for a hat. Called after the hat is no
1917c478bd9Sstevel@tonic-gate  * longer in use by any thread.
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate extern void htable_purge_hat(struct hat *hat);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * Find the htable, page table entry index, and PTE of the given virtual
1977c478bd9Sstevel@tonic-gate  * address.  If not found returns NULL. When found, returns the htable_t *,
1987c478bd9Sstevel@tonic-gate  * sets entry, and has a hold on the htable.
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate extern htable_t *htable_getpte(struct hat *, uintptr_t, uint_t *, x86pte_t *,
2017c478bd9Sstevel@tonic-gate 	level_t);
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate  * Similar to hat_getpte(), except that this only succeeds if a valid
2057c478bd9Sstevel@tonic-gate  * page mapping is present.
2067c478bd9Sstevel@tonic-gate  */
2077c478bd9Sstevel@tonic-gate extern htable_t *htable_getpage(struct hat *hat, uintptr_t va, uint_t *entry);
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate /*
2107c478bd9Sstevel@tonic-gate  * Called to allocate initial/additional htables for reserve.
2117c478bd9Sstevel@tonic-gate  */
2127c478bd9Sstevel@tonic-gate extern void htable_initial_reserve(uint_t);
2137c478bd9Sstevel@tonic-gate extern void htable_reserve(uint_t);
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate /*
2167c478bd9Sstevel@tonic-gate  * Used to readjust the htable reserve after the reserve list has been used.
2177c478bd9Sstevel@tonic-gate  * Also called after boot to release left over boot reserves.
2187c478bd9Sstevel@tonic-gate  */
2197c478bd9Sstevel@tonic-gate extern void htable_adjust_reserve(void);
2207c478bd9Sstevel@tonic-gate 
221ae115bc7Smrj /*
222843e1988Sjohnlev  * return number of bytes mapped by all the htables in a given hat
223ae115bc7Smrj  */
224843e1988Sjohnlev extern size_t htable_mapped(struct hat *);
225843e1988Sjohnlev 
226ae115bc7Smrj 
227ae115bc7Smrj /*
228843e1988Sjohnlev  * Attach initial pagetables as htables
229ae115bc7Smrj  */
230843e1988Sjohnlev extern void htable_attach(struct hat *, uintptr_t, level_t, struct htable *,
231843e1988Sjohnlev     pfn_t);
232ae115bc7Smrj 
2337c478bd9Sstevel@tonic-gate /*
2347c478bd9Sstevel@tonic-gate  * Routine to find the next populated htable at or above a given virtual
2357c478bd9Sstevel@tonic-gate  * address. Can specify an upper limit, or HTABLE_WALK_TO_END to indicate
2367c478bd9Sstevel@tonic-gate  * that it should search the entire address space.  Similar to
2377c478bd9Sstevel@tonic-gate  * hat_getpte(), but used for walking through address ranges. It can be
2387c478bd9Sstevel@tonic-gate  * used like this:
2397c478bd9Sstevel@tonic-gate  *
2407c478bd9Sstevel@tonic-gate  *	va = ...
2417c478bd9Sstevel@tonic-gate  *	ht = NULL;
2427c478bd9Sstevel@tonic-gate  *	while (va < end_va) {
2437c478bd9Sstevel@tonic-gate  *		pte = htable_walk(hat, &ht, &va, end_va);
2447c478bd9Sstevel@tonic-gate  *		if (!pte)
2457c478bd9Sstevel@tonic-gate  *			break;
2467c478bd9Sstevel@tonic-gate  *
2477c478bd9Sstevel@tonic-gate  *		... code to operate on page at va ...
2487c478bd9Sstevel@tonic-gate  *
2497c478bd9Sstevel@tonic-gate  *		va += LEVEL_SIZE(ht->ht_level);
2507c478bd9Sstevel@tonic-gate  *	}
2517c478bd9Sstevel@tonic-gate  *	if (ht)
2527c478bd9Sstevel@tonic-gate  *		htable_release(ht);
2537c478bd9Sstevel@tonic-gate  *
2547c478bd9Sstevel@tonic-gate  */
2557c478bd9Sstevel@tonic-gate extern x86pte_t htable_walk(struct hat *hat, htable_t **ht, uintptr_t *va,
2567c478bd9Sstevel@tonic-gate 	uintptr_t eaddr);
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate #define	HTABLE_WALK_TO_END ((uintptr_t)-1)
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate /*
2617c478bd9Sstevel@tonic-gate  * Utilities convert between virtual addresses and page table entry indeces.
2627c478bd9Sstevel@tonic-gate  */
2637c478bd9Sstevel@tonic-gate extern uint_t htable_va2entry(uintptr_t va, htable_t *ht);
2647c478bd9Sstevel@tonic-gate extern uintptr_t htable_e2va(htable_t *ht, uint_t entry);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate  * Interfaces that provide access to page table entries via the htable.
2687c478bd9Sstevel@tonic-gate  *
2697c478bd9Sstevel@tonic-gate  * Note that all accesses except x86pte_copy() and x86pte_zero() are atomic.
2707c478bd9Sstevel@tonic-gate  */
271ae115bc7Smrj extern void	x86pte_cpu_init(cpu_t *);
272ae115bc7Smrj extern void	x86pte_cpu_fini(cpu_t *);
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate extern x86pte_t	x86pte_get(htable_t *, uint_t entry);
2757c478bd9Sstevel@tonic-gate 
276ae115bc7Smrj /*
277ae115bc7Smrj  * x86pte_set returns LPAGE_ERROR if it's asked to overwrite a page table
278ae115bc7Smrj  * link with a large page mapping.
279ae115bc7Smrj  */
280ae115bc7Smrj #define	LPAGE_ERROR (-(x86pte_t)1)
2817c478bd9Sstevel@tonic-gate extern x86pte_t	x86pte_set(htable_t *, uint_t entry, x86pte_t new, void *);
2827c478bd9Sstevel@tonic-gate 
283ae115bc7Smrj extern x86pte_t x86pte_inval(htable_t *ht, uint_t entry,
284a6a74e0eSMatthew Ahrens 	x86pte_t old, x86pte_t *ptr, boolean_t tlb);
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate extern x86pte_t x86pte_update(htable_t *ht, uint_t entry,
2877c478bd9Sstevel@tonic-gate 	x86pte_t old, x86pte_t new);
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate extern void	x86pte_copy(htable_t *src, htable_t *dest, uint_t entry,
2907c478bd9Sstevel@tonic-gate 	uint_t cnt);
2917c478bd9Sstevel@tonic-gate 
292ae115bc7Smrj /*
293ae115bc7Smrj  * access to a pagetable knowing only the pfn
294ae115bc7Smrj  */
295ae115bc7Smrj extern x86pte_t *x86pte_mapin(pfn_t, uint_t, htable_t *);
296ae115bc7Smrj extern void x86pte_mapout(void);
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate /*
2997c478bd9Sstevel@tonic-gate  * these are actually inlines for "lock; incw", "lock; decw", etc. instructions.
3007c478bd9Sstevel@tonic-gate  */
3017c478bd9Sstevel@tonic-gate #define	HTABLE_INC(x)	atomic_inc16((uint16_t *)&x)
3027c478bd9Sstevel@tonic-gate #define	HTABLE_DEC(x)	atomic_dec16((uint16_t *)&x)
3031a5e258fSJosef 'Jeff' Sipek #define	HTABLE_LOCK_INC(ht)	atomic_inc_32(&(ht)->ht_lock_cnt)
3041a5e258fSJosef 'Jeff' Sipek #define	HTABLE_LOCK_DEC(ht)	atomic_dec_32(&(ht)->ht_lock_cnt)
3057c478bd9Sstevel@tonic-gate 
306843e1988Sjohnlev #ifdef __xpv
307843e1988Sjohnlev extern void xen_flush_va(caddr_t va);
308843e1988Sjohnlev extern void xen_gflush_va(caddr_t va, cpuset_t);
309843e1988Sjohnlev extern void xen_flush_tlb(void);
310843e1988Sjohnlev extern void xen_gflush_tlb(cpuset_t);
311843e1988Sjohnlev extern void xen_pin(pfn_t, level_t);
312843e1988Sjohnlev extern void xen_unpin(pfn_t);
313843e1988Sjohnlev extern int xen_kpm_page(pfn_t, uint_t);
314843e1988Sjohnlev 
315843e1988Sjohnlev /*
316843e1988Sjohnlev  * The hypervisor maps all page tables into our address space read-only.
317843e1988Sjohnlev  * Under normal circumstances, the hypervisor then handles all updates to
318843e1988Sjohnlev  * the page tables underneath the covers for us.  However, when we are
319843e1988Sjohnlev  * trying to dump core after a hypervisor panic, the hypervisor is no
320843e1988Sjohnlev  * longer available to do these updates.  To work around the protection
321843e1988Sjohnlev  * problem, we simply disable write-protect checking for the duration of a
322843e1988Sjohnlev  * pagetable update operation.
323843e1988Sjohnlev  */
324843e1988Sjohnlev #define	XPV_ALLOW_PAGETABLE_UPDATES()					\
325843e1988Sjohnlev 	{								\
326843e1988Sjohnlev 		if (IN_XPV_PANIC())					\
327843e1988Sjohnlev 			setcr0((getcr0() & ~CR0_WP) & 0xffffffff); 	\
328843e1988Sjohnlev 	}
329843e1988Sjohnlev #define	XPV_DISALLOW_PAGETABLE_UPDATES()				\
330843e1988Sjohnlev 	{								\
331843e1988Sjohnlev 		if (IN_XPV_PANIC() > 0)					\
332843e1988Sjohnlev 			setcr0((getcr0() | CR0_WP) & 0xffffffff);	\
333843e1988Sjohnlev 	}
334843e1988Sjohnlev 
335843e1988Sjohnlev #else /* __xpv */
336843e1988Sjohnlev 
337843e1988Sjohnlev #define	XPV_ALLOW_PAGETABLE_UPDATES()
338843e1988Sjohnlev #define	XPV_DISALLOW_PAGETABLE_UPDATES()
339843e1988Sjohnlev 
340843e1988Sjohnlev #endif
341843e1988Sjohnlev 
3427c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3467c478bd9Sstevel@tonic-gate }
3477c478bd9Sstevel@tonic-gate #endif
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate #endif	/* _VM_HTABLE_H */
350