direct-io.hg

view xen/include/asm-x86/mm.h @ 11395:63e3321fb16a

[XEN] Remove unused IS_INVALID_M2P_ENTRY macro.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Aug 31 22:29:23 2006 +0100 (2006-08-31)
parents 9956c3a3bd84
children 965df40965e5
line source
2 #ifndef __ASM_X86_MM_H__
3 #define __ASM_X86_MM_H__
5 #include <xen/config.h>
6 #include <xen/cpumask.h>
7 #include <xen/list.h>
8 #include <asm/io.h>
9 #include <asm/uaccess.h>
11 /*
12 * Per-page-frame information.
13 *
14 * Every architecture must ensure the following:
15 * 1. 'struct page_info' contains a 'struct list_head list'.
16 * 2. Provide a PFN_ORDER() macro for accessing the order of a free page.
17 */
18 #define PFN_ORDER(_pfn) ((_pfn)->u.free.order)
20 struct page_info
21 {
22 /* Each frame can be threaded onto a doubly-linked list. */
23 union {
24 struct list_head list;
25 /* Shadow uses this field as an up-pointer in lower-level shadows */
26 paddr_t up;
27 };
29 /* Reference count and various PGC_xxx flags and fields. */
30 u32 count_info;
32 /* Context-dependent fields follow... */
33 union {
35 /* Page is in use: ((count_info & PGC_count_mask) != 0). */
36 struct {
37 /* Owner of this page (NULL if page is anonymous). */
38 u32 _domain; /* pickled format */
39 /* Type reference count and various PGT_xxx flags and fields. */
40 unsigned long type_info;
41 } __attribute__ ((packed)) inuse;
43 /* Page is on a free list: ((count_info & PGC_count_mask) == 0). */
44 struct {
45 /* Order-size of the free chunk this page is the head of. */
46 u32 order;
47 /* Mask of possibly-tainted TLBs. */
48 cpumask_t cpumask;
49 } __attribute__ ((packed)) free;
51 } u;
53 union {
54 /* Timestamp from 'TLB clock', used to reduce need for safety
55 * flushes. Only valid on a) free pages, and b) guest pages with a
56 * zero type count. */
57 u32 tlbflush_timestamp;
59 /* Only used on guest pages with a shadow.
60 * Guest pages with a shadow must have a non-zero type count, so this
61 * does not conflict with the tlbflush timestamp. */
62 u32 shadow_flags;
64 // XXX -- we expect to add another field here, to be used for min/max
65 // purposes, which is only used for shadow pages.
66 };
67 };
69 /* The following page types are MUTUALLY EXCLUSIVE. */
70 #define PGT_none (0U<<29) /* no special uses of this page */
71 #define PGT_l1_page_table (1U<<29) /* using this page as an L1 page table? */
72 #define PGT_l2_page_table (2U<<29) /* using this page as an L2 page table? */
73 #define PGT_l3_page_table (3U<<29) /* using this page as an L3 page table? */
74 #define PGT_l4_page_table (4U<<29) /* using this page as an L4 page table? */
75 #define PGT_gdt_page (5U<<29) /* using this page in a GDT? */
76 #define PGT_ldt_page (6U<<29) /* using this page in an LDT? */
77 #define PGT_writable_page (7U<<29) /* has writable mappings of this page? */
79 #ifndef SHADOW
80 #define PGT_l1_shadow PGT_l1_page_table
81 #define PGT_l2_shadow PGT_l2_page_table
82 #define PGT_l3_shadow PGT_l3_page_table
83 #define PGT_l4_shadow PGT_l4_page_table
84 #define PGT_hl2_shadow (5U<<29)
85 #define PGT_snapshot (6U<<29)
86 #define PGT_writable_pred (7U<<29) /* predicted gpfn with writable ref */
88 #define PGT_fl1_shadow (5U<<29)
89 #endif
91 #define PGT_type_mask (7U<<29) /* Bits 29-31. */
93 /* Owning guest has pinned this page to its current type? */
94 #define _PGT_pinned 28
95 #define PGT_pinned (1U<<_PGT_pinned)
96 /* Has this page been validated for use as its current type? */
97 #define _PGT_validated 27
98 #define PGT_validated (1U<<_PGT_validated)
99 #if defined(__i386__)
100 /* The 11 most significant bits of virt address if this is a page table. */
101 #define PGT_va_shift 16
102 #define PGT_va_mask (((1U<<11)-1)<<PGT_va_shift)
103 /* Is the back pointer still mutable (i.e. not fixed yet)? */
104 #define PGT_va_mutable (((1U<<11)-1)<<PGT_va_shift)
105 /* Is the back pointer unknown (e.g., p.t. is mapped at multiple VAs)? */
106 #define PGT_va_unknown (((1U<<11)-2)<<PGT_va_shift)
107 #elif defined(__x86_64__)
108 /* The 27 most significant bits of virt address if this is a page table. */
109 #define PGT_va_shift 32
110 #define PGT_va_mask ((unsigned long)((1U<<28)-1)<<PGT_va_shift)
111 /* Is the back pointer still mutable (i.e. not fixed yet)? */
112 #define PGT_va_mutable ((unsigned long)((1U<<28)-1)<<PGT_va_shift)
113 /* Is the back pointer unknown (e.g., p.t. is mapped at multiple VAs)? */
114 #define PGT_va_unknown ((unsigned long)((1U<<28)-2)<<PGT_va_shift)
115 #endif
117 /* 16-bit count of uses of this frame as its current type. */
118 #define PGT_count_mask ((1U<<16)-1)
120 #ifndef SHADOW
121 #ifdef __x86_64__
122 #define PGT_high_mfn_shift 52
123 #define PGT_high_mfn_mask (0xfffUL << PGT_high_mfn_shift)
124 #define PGT_mfn_mask (((1U<<27)-1) | PGT_high_mfn_mask)
125 #define PGT_high_mfn_nx (0x800UL << PGT_high_mfn_shift)
126 #else
127 /* 23-bit mfn mask for shadow types: good for up to 32GB RAM. */
128 #define PGT_mfn_mask ((1U<<23)-1)
129 /* NX for PAE xen is not supported yet */
130 #define PGT_high_mfn_nx (1ULL << 63)
132 #define PGT_score_shift 23
133 #define PGT_score_mask (((1U<<4)-1)<<PGT_score_shift)
134 #endif
135 #endif /* SHADOW */
137 /* Cleared when the owning guest 'frees' this page. */
138 #define _PGC_allocated 31
139 #define PGC_allocated (1U<<_PGC_allocated)
140 /* Set on a *guest* page to mark it out-of-sync with its shadow */
141 #define _PGC_out_of_sync 30
142 #define PGC_out_of_sync (1U<<_PGC_out_of_sync)
143 /* Set when is using a page as a page table */
144 #define _PGC_page_table 29
145 #define PGC_page_table (1U<<_PGC_page_table)
146 /* 29-bit count of references to this frame. */
147 #define PGC_count_mask ((1U<<29)-1)
149 /* shadow uses the count_info on shadow pages somewhat differently */
150 /* NB: please coordinate any changes here with the SHF's in shadow.h */
151 #define PGC_SH_none (0U<<28) /* on the shadow free list */
152 #define PGC_SH_min_shadow (1U<<28)
153 #define PGC_SH_l1_32_shadow (1U<<28) /* shadowing a 32-bit L1 guest page */
154 #define PGC_SH_fl1_32_shadow (2U<<28) /* L1 shadow for a 32b 4M superpage */
155 #define PGC_SH_l2_32_shadow (3U<<28) /* shadowing a 32-bit L2 guest page */
156 #define PGC_SH_l1_pae_shadow (4U<<28) /* shadowing a pae L1 page */
157 #define PGC_SH_fl1_pae_shadow (5U<<28) /* L1 shadow for pae 2M superpg */
158 #define PGC_SH_l2_pae_shadow (6U<<28) /* shadowing a pae L2-low page */
159 #define PGC_SH_l2h_pae_shadow (7U<<28) /* shadowing a pae L2-high page */
160 #define PGC_SH_l3_pae_shadow (8U<<28) /* shadowing a pae L3 page */
161 #define PGC_SH_l1_64_shadow (9U<<28) /* shadowing a 64-bit L1 page */
162 #define PGC_SH_fl1_64_shadow (10U<<28) /* L1 shadow for 64-bit 2M superpg */
163 #define PGC_SH_l2_64_shadow (11U<<28) /* shadowing a 64-bit L2 page */
164 #define PGC_SH_l3_64_shadow (12U<<28) /* shadowing a 64-bit L3 page */
165 #define PGC_SH_l4_64_shadow (13U<<28) /* shadowing a 64-bit L4 page */
166 #define PGC_SH_max_shadow (13U<<28)
167 #define PGC_SH_p2m_table (14U<<28) /* in use as the p2m table */
168 #define PGC_SH_monitor_table (15U<<28) /* in use as a monitor table */
169 #define PGC_SH_unused (15U<<28)
171 #define PGC_SH_type_mask (15U<<28)
172 #define PGC_SH_type_shift 28
174 #define PGC_SH_pinned (1U<<27)
176 #define _PGC_SH_log_dirty 26
177 #define PGC_SH_log_dirty (1U<<26)
179 /* 26 bit ref count for shadow pages */
180 #define PGC_SH_count_mask ((1U<<26) - 1)
182 /* We trust the slab allocator in slab.c, and our use of it. */
183 #define PageSlab(page) (1)
184 #define PageSetSlab(page) ((void)0)
185 #define PageClearSlab(page) ((void)0)
187 #define IS_XEN_HEAP_FRAME(_pfn) (page_to_maddr(_pfn) < xenheap_phys_end)
189 #if defined(__i386__)
190 #define pickle_domptr(_d) ((u32)(unsigned long)(_d))
191 static inline struct domain *unpickle_domptr(u32 _domain)
192 { return (_domain & 1) ? NULL : (void *)_domain; }
193 #define PRtype_info "08lx" /* should only be used for printk's */
194 #elif defined(__x86_64__)
195 static inline struct domain *unpickle_domptr(u32 _domain)
196 { return ((_domain == 0) || (_domain & 1)) ? NULL : __va(_domain); }
197 static inline u32 pickle_domptr(struct domain *domain)
198 { return (domain == NULL) ? 0 : (u32)__pa(domain); }
199 #define PRtype_info "016lx"/* should only be used for printk's */
200 #endif
202 /* The order of the largest allocation unit we use for shadow pages */
203 #if CONFIG_PAGING_LEVELS == 2
204 #define SHADOW_MAX_ORDER 0 /* Only ever need 4k allocations */
205 #else
206 #define SHADOW_MAX_ORDER 2 /* Need up to 16k allocs for 32-bit on PAE/64 */
207 #endif
209 #define page_get_owner(_p) (unpickle_domptr((_p)->u.inuse._domain))
210 #define page_set_owner(_p,_d) ((_p)->u.inuse._domain = pickle_domptr(_d))
212 #define XENSHARE_writable 0
213 #define XENSHARE_readonly 1
214 extern void share_xen_page_with_guest(
215 struct page_info *page, struct domain *d, int readonly);
216 extern void share_xen_page_with_privileged_guests(
217 struct page_info *page, int readonly);
219 extern struct page_info *frame_table;
220 extern unsigned long max_page;
221 extern unsigned long total_pages;
222 void init_frametable(void);
224 int alloc_page_type(struct page_info *page, unsigned long type);
225 void free_page_type(struct page_info *page, unsigned long type);
226 extern void invalidate_shadow_ldt(struct vcpu *d);
227 extern int shadow_remove_all_write_access(
228 struct domain *d, unsigned long gmfn, unsigned long mfn);
229 extern u32 shadow_remove_all_access( struct domain *d, unsigned long gmfn);
230 extern int _shadow_mode_refcounts(struct domain *d);
232 static inline void put_page(struct page_info *page)
233 {
234 u32 nx, x, y = page->count_info;
236 do {
237 x = y;
238 nx = x - 1;
239 }
240 while ( unlikely((y = cmpxchg(&page->count_info, x, nx)) != x) );
242 if ( unlikely((nx & PGC_count_mask) == 0) )
243 free_domheap_page(page);
244 }
247 static inline int get_page(struct page_info *page,
248 struct domain *domain)
249 {
250 u32 x, nx, y = page->count_info;
251 u32 d, nd = page->u.inuse._domain;
252 u32 _domain = pickle_domptr(domain);
254 do {
255 x = y;
256 nx = x + 1;
257 d = nd;
258 if ( unlikely((x & PGC_count_mask) == 0) || /* Not allocated? */
259 unlikely((nx & PGC_count_mask) == 0) || /* Count overflow? */
260 unlikely(d != _domain) ) /* Wrong owner? */
261 {
262 if ( !_shadow_mode_refcounts(domain) )
263 DPRINTK("Error pfn %lx: rd=%p, od=%p, caf=%08x, taf=%"
264 PRtype_info "\n",
265 page_to_mfn(page), domain, unpickle_domptr(d),
266 x, page->u.inuse.type_info);
267 return 0;
268 }
269 __asm__ __volatile__(
270 LOCK_PREFIX "cmpxchg8b %3"
271 : "=d" (nd), "=a" (y), "=c" (d),
272 "=m" (*(volatile u64 *)(&page->count_info))
273 : "0" (d), "1" (x), "c" (d), "b" (nx) );
274 }
275 while ( unlikely(nd != d) || unlikely(y != x) );
277 return 1;
278 }
280 void put_page_type(struct page_info *page);
281 int get_page_type(struct page_info *page, unsigned long type);
282 int get_page_from_l1e(l1_pgentry_t l1e, struct domain *d);
283 void put_page_from_l1e(l1_pgentry_t l1e, struct domain *d);
285 static inline void put_page_and_type(struct page_info *page)
286 {
287 put_page_type(page);
288 put_page(page);
289 }
292 static inline int get_page_and_type(struct page_info *page,
293 struct domain *domain,
294 unsigned long type)
295 {
296 int rc = get_page(page, domain);
298 if ( likely(rc) && unlikely(!get_page_type(page, type)) )
299 {
300 put_page(page);
301 rc = 0;
302 }
304 return rc;
305 }
307 static inline int page_is_removable(struct page_info *page)
308 {
309 return ((page->count_info & PGC_count_mask) == 1);
310 }
312 #define ASSERT_PAGE_IS_TYPE(_p, _t) \
313 ASSERT(((_p)->u.inuse.type_info & PGT_type_mask) == (_t)); \
314 ASSERT(((_p)->u.inuse.type_info & PGT_count_mask) != 0)
315 #define ASSERT_PAGE_IS_DOMAIN(_p, _d) \
316 ASSERT(((_p)->count_info & PGC_count_mask) != 0); \
317 ASSERT(page_get_owner(_p) == (_d))
319 // Quick test for whether a given page can be represented directly in CR3.
320 //
321 #if CONFIG_PAGING_LEVELS == 3
322 #define MFN_FITS_IN_CR3(_MFN) !(mfn_x(_MFN) >> 20)
324 /* returns a lowmem machine address of the copied L3 root table */
325 unsigned long
326 pae_copy_root(struct vcpu *v, l3_pgentry_t *l3tab);
327 #endif /* CONFIG_PAGING_LEVELS == 3 */
329 int check_descriptor(struct desc_struct *d);
331 /*
332 * The MPT (machine->physical mapping table) is an array of word-sized
333 * values, indexed on machine frame number. It is expected that guest OSes
334 * will use it to store a "physical" frame number to give the appearance of
335 * contiguous (or near contiguous) physical memory.
336 */
337 #undef machine_to_phys_mapping
338 #define machine_to_phys_mapping ((unsigned long *)RDWR_MPT_VIRT_START)
339 #define INVALID_M2P_ENTRY (~0UL)
340 #define VALID_M2P(_e) (!((_e) & (1UL<<(BITS_PER_LONG-1))))
342 #define set_gpfn_from_mfn(mfn, pfn) (machine_to_phys_mapping[(mfn)] = (pfn))
343 #define get_gpfn_from_mfn(mfn) (machine_to_phys_mapping[(mfn)])
346 #define mfn_to_gmfn(_d, mfn) \
347 ( (shadow_mode_translate(_d)) \
348 ? get_gpfn_from_mfn(mfn) \
349 : (mfn) )
351 #define gmfn_to_mfn(_d, gpfn) mfn_x(sh_gfn_to_mfn(_d, gpfn))
354 /*
355 * The phys_to_machine_mapping is the reversed mapping of MPT for full
356 * virtualization. It is only used by shadow_mode_translate()==true
357 * guests, so we steal the address space that would have normally
358 * been used by the read-only MPT map.
359 */
360 #define phys_to_machine_mapping ((l1_pgentry_t *)RO_MPT_VIRT_START)
361 #define INVALID_MFN (~0UL)
362 #define VALID_MFN(_mfn) (!((_mfn) & (1U<<31)))
364 static inline unsigned long get_mfn_from_gpfn(unsigned long pfn)
365 {
366 l1_pgentry_t l1e = l1e_empty();
367 int ret;
369 #if CONFIG_PAGING_LEVELS > 2
370 if ( pfn >= (RO_MPT_VIRT_END - RO_MPT_VIRT_START) / sizeof(l1_pgentry_t) )
371 /* This pfn is higher than the p2m map can hold */
372 return INVALID_MFN;
373 #endif
375 ret = __copy_from_user(&l1e,
376 &phys_to_machine_mapping[pfn],
377 sizeof(l1e));
379 if ( (ret == 0) && (l1e_get_flags(l1e) & _PAGE_PRESENT) )
380 return l1e_get_pfn(l1e);
382 return INVALID_MFN;
383 }
385 #ifdef MEMORY_GUARD
386 void memguard_init(void);
387 void memguard_guard_range(void *p, unsigned long l);
388 void memguard_unguard_range(void *p, unsigned long l);
389 #else
390 #define memguard_init() ((void)0)
391 #define memguard_guard_range(_p,_l) ((void)0)
392 #define memguard_unguard_range(_p,_l) ((void)0)
393 #endif
395 void memguard_guard_stack(void *p);
397 int ptwr_do_page_fault(struct domain *, unsigned long,
398 struct cpu_user_regs *);
400 int audit_adjust_pgtables(struct domain *d, int dir, int noisy);
402 #ifndef NDEBUG
404 #define AUDIT_SHADOW_ALREADY_LOCKED ( 1u << 0 )
405 #define AUDIT_ERRORS_OK ( 1u << 1 )
406 #define AUDIT_QUIET ( 1u << 2 )
408 void _audit_domain(struct domain *d, int flags);
409 #define audit_domain(_d) _audit_domain((_d), AUDIT_ERRORS_OK)
410 void audit_domains(void);
412 #else
414 #define _audit_domain(_d, _f) ((void)0)
415 #define audit_domain(_d) ((void)0)
416 #define audit_domains() ((void)0)
418 #endif
420 int new_guest_cr3(unsigned long pfn);
421 void make_cr3(struct vcpu *v, unsigned long mfn);
423 void propagate_page_fault(unsigned long addr, u16 error_code);
425 int __sync_lazy_execstate(void);
427 /* Arch-specific portion of memory_op hypercall. */
428 long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg);
429 long subarch_memory_op(int op, XEN_GUEST_HANDLE(void) arg);
431 int steal_page(
432 struct domain *d, struct page_info *page, unsigned int memflags);
434 #endif /* __ASM_X86_MM_H__ */