htable.h revision a6a74e0e62d62ff750cd4b790be5eacc99c3bb8c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2014 by Delphix. All rights reserved.
*/
#ifndef _VM_HTABLE_H
#define _VM_HTABLE_H
#ifdef __cplusplus
extern "C" {
#endif
#endif
/*
* Each hardware page table has an htable_t describing it.
*
* We use a reference counter mechanism to detect when we can free an htable.
* In the implmentation the reference count is split into 2 separate counters:
*
* ht_busy is a traditional reference count of uses of the htable pointer
*
* entries in the pagetable
*
* ht_busy is only incremented by htable_lookup() or htable_create()
* while holding the appropriate hash_table mutex. While installing a new
* valid PTE or PTP, in order to increment ht_valid_cnt a thread must have
* done an htable_lookup() or htable_create() but not the htable_release yet.
*
* htable_release(), while holding the mutex, can know that if
* busy == 1 and valid_cnt == 0, the htable can be free'd.
*
* The fields have been ordered to make htable_lookup() fast. Hence,
* ht_hat, ht_vaddr, ht_level and ht_next need to be clustered together.
*/
struct htable {
/* never used for kernel hat */
};
/*
* Flags values for htable ht_flags field:
*
* HTABLE_VLP - this is the top level htable of a VLP HAT.
*
* HTABLE_SHARED_PFN - this htable had its PFN assigned from sharing another
* htable. Used by hat_share() for ISM.
*/
#define HTABLE_VLP (0x01)
#define HTABLE_SHARED_PFN (0x02)
/*
* The htable hash table hashing function. The 28 is so that high
* order bits are include in the hash index to skew the wrap
* around of addresses. Even though the hash buckets are stored per
* hat we include the value of hat pointer in the hash function so
* that the secondary hash for the htable mutex winds up begin different in
* every address space.
*/
/*
* Each CPU gets a unique hat_cpu_info structure in cpu_hat_info.
*/
struct hat_cpu_info {
#if defined(__amd64)
#endif /* __amd64 */
};
/*
* Compute the last page aligned VA mapped by an htable.
*
* Given a va and a level, compute the virtual address of the start of the
* next page at that level.
*
* XX64 - The check for the VA hole needs to be better generalized.
*/
#if defined(__amd64)
#define HTABLE_LAST_PAGE(ht) \
#define NEXT_ENTRY_VA(va, l) \
#define HTABLE_NUM_PTES(ht) \
#endif
#if defined(_KERNEL)
/*
* initialization function called from hat_init()
*/
extern void htable_init(void);
/*
* Functions to lookup, or "lookup and create", the htable corresponding
* to the virtual address "vaddr" in the "hat" at the given "level" of
* page tables. htable_lookup() may return NULL if no such entry exists.
*
* On return the given htable is marked busy (a shared lock) - this prevents
* the htable from being stolen or freed) until htable_release() is called.
*
* If kalloc_flag is set on an htable_create() we can't call kmem allocation
* routines for this htable, since it's for the kernel hat itself.
*
* htable_acquire() is used when an htable pointer has been extracted from
* an hment and we need to get a reference to the htable.
*/
extern void htable_acquire(htable_t *);
/*
* Code to free all remaining htables for a hat. Called after the hat is no
* longer in use by any thread.
*/
/*
* Find the htable, page table entry index, and PTE of the given virtual
* address. If not found returns NULL. When found, returns the htable_t *,
* sets entry, and has a hold on the htable.
*/
level_t);
/*
* Similar to hat_getpte(), except that this only succeeds if a valid
* page mapping is present.
*/
/*
* Called to allocate initial/additional htables for reserve.
*/
extern void htable_initial_reserve(uint_t);
extern void htable_reserve(uint_t);
/*
* Used to readjust the htable reserve after the reserve list has been used.
* Also called after boot to release left over boot reserves.
*/
extern void htable_adjust_reserve(void);
/*
* return number of bytes mapped by all the htables in a given hat
*/
/*
* Attach initial pagetables as htables
*/
pfn_t);
/*
* Routine to find the next populated htable at or above a given virtual
* address. Can specify an upper limit, or HTABLE_WALK_TO_END to indicate
* that it should search the entire address space. Similar to
* hat_getpte(), but used for walking through address ranges. It can be
* used like this:
*
* va = ...
* ht = NULL;
* while (va < end_va) {
* pte = htable_walk(hat, &ht, &va, end_va);
* if (!pte)
* break;
*
* ... code to operate on page at va ...
*
* va += LEVEL_SIZE(ht->ht_level);
* }
* if (ht)
* htable_release(ht);
*
*/
/*
* Utilities convert between virtual addresses and page table entry indeces.
*/
/*
* Interfaces that provide access to page table entries via the htable.
*
* Note that all accesses except x86pte_copy() and x86pte_zero() are atomic.
*/
extern void x86pte_cpu_init(cpu_t *);
extern void x86pte_cpu_fini(cpu_t *);
/*
* x86pte_set returns LPAGE_ERROR if it's asked to overwrite a page table
* link with a large page mapping.
*/
/*
* access to a pagetable knowing only the pfn
*/
extern void x86pte_mapout(void);
/*
* these are actually inlines for "lock; incw", "lock; decw", etc. instructions.
*/
#ifdef __xpv
extern void xen_flush_tlb(void);
extern void xen_gflush_tlb(cpuset_t);
/*
* The hypervisor maps all page tables into our address space read-only.
* Under normal circumstances, the hypervisor then handles all updates to
* the page tables underneath the covers for us. However, when we are
* trying to dump core after a hypervisor panic, the hypervisor is no
* longer available to do these updates. To work around the protection
* problem, we simply disable write-protect checking for the duration of a
* pagetable update operation.
*/
#define XPV_ALLOW_PAGETABLE_UPDATES() \
{ \
if (IN_XPV_PANIC()) \
}
#define XPV_DISALLOW_PAGETABLE_UPDATES() \
{ \
if (IN_XPV_PANIC() > 0) \
}
#else /* __xpv */
#define XPV_ALLOW_PAGETABLE_UPDATES()
#define XPV_DISALLOW_PAGETABLE_UPDATES()
#endif
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _VM_HTABLE_H */