From: Jan Beulich Date: Fri, 19 Jan 2018 10:16:10 +0000 (+0100) Subject: x86/shadow: widen reference count X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~734 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=97207ddd3b2bbbf6e723d8c5f2a93592a1cf5d81;p=xen.git x86/shadow: widen reference count Utilize as many of the bits available in the union as possible, without (just to be on the safe side) colliding with any of the bits outside of PGT_type_mask. Note that the first and last hunks of the xen/include/asm-x86/mm.h change are merely code motion. Signed-off-by: Jan Beulich Acked-by: Tim Deegan Acked-by: Andrew Cooper --- diff --git a/xen/arch/x86/mm/shadow/private.h b/xen/arch/x86/mm/shadow/private.h index 554905e87e..845541fe8a 100644 --- a/xen/arch/x86/mm/shadow/private.h +++ b/xen/arch/x86/mm/shadow/private.h @@ -520,7 +520,7 @@ void sh_destroy_shadow(struct domain *d, mfn_t smfn); * Returns 0 for failure, 1 for success. */ static inline int sh_get_ref(struct domain *d, mfn_t smfn, paddr_t entry_pa) { - u32 x, nx; + unsigned long x, nx; struct page_info *sp = mfn_to_page(smfn); ASSERT(mfn_valid(smfn)); @@ -529,7 +529,7 @@ static inline int sh_get_ref(struct domain *d, mfn_t smfn, paddr_t entry_pa) x = sp->u.sh.count; nx = x + 1; - if ( unlikely(nx >= (1U << PAGE_SH_REFCOUNT_WIDTH)) ) + if ( unlikely(nx >= (1UL << PAGE_SH_REFCOUNT_WIDTH)) ) { SHADOW_PRINTK("shadow ref overflow, gmfn=%lx smfn=%lx\n", __backpointer(sp), mfn_x(smfn)); @@ -553,7 +553,7 @@ static inline int sh_get_ref(struct domain *d, mfn_t smfn, paddr_t entry_pa) * physical address of the shadow entry that held this reference. */ static inline void sh_put_ref(struct domain *d, mfn_t smfn, paddr_t entry_pa) { - u32 x, nx; + unsigned long x, nx; struct page_info *sp = mfn_to_page(smfn); ASSERT(mfn_valid(smfn)); @@ -571,8 +571,8 @@ static inline void sh_put_ref(struct domain *d, mfn_t smfn, paddr_t entry_pa) if ( unlikely(x == 0) ) { - SHADOW_ERROR("shadow ref underflow, smfn=%lx oc=%08x t=%#x\n", - mfn_x(smfn), sp->u.sh.count, sp->u.sh.type); + SHADOW_ERROR("shadow ref underflow, smfn=%lx oc=%#lx t=%#x\n", + mfn_x(smfn), sp->u.sh.count + 0UL, sp->u.sh.type); BUG(); } diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 4af6b2341a..3013c266fe 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -18,6 +18,77 @@ */ #define PFN_ORDER(_pfn) ((_pfn)->v.free.order) +#define PG_shift(idx) (BITS_PER_LONG - (idx)) +#define PG_mask(x, idx) (x ## UL << PG_shift(idx)) + + /* The following page types are MUTUALLY EXCLUSIVE. */ +#define PGT_none PG_mask(0, 3) /* no special uses of this page */ +#define PGT_l1_page_table PG_mask(1, 3) /* using as an L1 page table? */ +#define PGT_l2_page_table PG_mask(2, 3) /* using as an L2 page table? */ +#define PGT_l3_page_table PG_mask(3, 3) /* using as an L3 page table? */ +#define PGT_l4_page_table PG_mask(4, 3) /* using as an L4 page table? */ +#define PGT_seg_desc_page PG_mask(5, 3) /* using this page in a GDT/LDT? */ +#define PGT_shared_page PG_mask(6, 3) /* CoW sharable page */ +#define PGT_writable_page PG_mask(7, 3) /* has writable mappings? */ +#define PGT_type_mask PG_mask(7, 3) /* Bits 61-63. */ + + /* Page is locked? */ +#define _PGT_locked PG_shift(4) +#define PGT_locked PG_mask(1, 4) + /* Owning guest has pinned this page to its current type? */ +#define _PGT_pinned PG_shift(5) +#define PGT_pinned PG_mask(1, 5) + /* Has this page been validated for use as its current type? */ +#define _PGT_validated PG_shift(6) +#define PGT_validated PG_mask(1, 6) + /* PAE only: is this an L2 page directory containing Xen-private mappings? */ +#define _PGT_pae_xen_l2 PG_shift(7) +#define PGT_pae_xen_l2 PG_mask(1, 7) +/* Has this page been *partially* validated for use as its current type? */ +#define _PGT_partial PG_shift(8) +#define PGT_partial PG_mask(1, 8) + + /* Count of uses of this frame as its current type. */ +#define PGT_count_width PG_shift(8) +#define PGT_count_mask ((1UL<count_info&PGC_state) == PGC_state_##st) + + /* Count of references to this frame. */ +#define PGC_count_width PG_shift(9) +#define PGC_count_mask ((1UL<count_info&PGC_state) == PGC_state_##st) - - /* Count of references to this frame. */ -#define PGC_count_width PG_shift(9) -#define PGC_count_mask ((1UL<count_info & PGC_xen_heap) #define is_xen_heap_mfn(mfn) \ (__mfn_valid(mfn) && is_xen_heap_page(__mfn_to_page(mfn)))