Make PAT handling less brittle
v3 cover Make PAT handling less brittle
While working on Qubes OS Marek found out that there were some PAT hacks in the Linux i195 driver. I decided to make Xen use Linux’s PAT to see if it solved the graphics glitches that were observed; it did. This required a substantial amount of preliminary work that is useful even without using Linux’s PAT.
Patches 1 through 11 are the preliminary work and I would like them to be accepted into upstream Xen. Patch 11 does break ABI by rejecting the unused PAT entries, but this will only impact buggy PV guests and can be disabled with a Xen command-line option. Patch 14 actually switches to Linux’s PAT and is NOT intended to be merged (at least for now) as it would at a minimum break migration of PV guests from hosts that do not have the patch.
Demi Marie Obenour (12):
x86/mm: Avoid hard-coding PAT in get_page_from_l1e()
p2m-pt: Avoid hard-coding Xen's PAT
efi: Avoid hard-coding the various PAT constants
x86: Add memory type constants
x86: Replace PAT_* with X86_MT_*
x86: Replace MTRR_* constants with X86_MT_* constants
x86: Replace EPT_EMT_* constants with X86_MT_*
x86: Remove MEMORY_NUM_TYPES and NO_HARDCODE_MEM_TYPE
x86: Derive XEN_MSR_PAT from its individual entries x86/mm: make code robust to future PAT changes x86/mm: Reject invalid cacheability in PV guests by default
x86: Use Linux's PAT
xen/arch/x86/cpu/mtrr/generic.c | 10 +-- xen/arch/x86/cpu/mtrr/main.c | 26 +++--- xen/arch/x86/e820.c | 4 +- xen/arch/x86/hvm/hvm.c | 12 +-- xen/arch/x86/hvm/mtrr.c | 100 ++++++++++++------------ xen/arch/x86/hvm/vmx/vmcs.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 18 ++--- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 2 +- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 9 --- xen/arch/x86/include/asm/mtrr.h | 22 +----- xen/arch/x86/include/asm/page.h | 4 +- xen/arch/x86/include/asm/processor.h | 15 ++-- xen/arch/x86/include/asm/x86-defns.h | 11 +++ xen/arch/x86/mm.c | 80 +++++++++++++++++-- xen/arch/x86/mm/hap/nested_ept.c | 4 +- xen/arch/x86/mm/p2m-ept.c | 51 ++++++------ xen/arch/x86/mm/p2m-pt.c | 6 +- xen/arch/x86/mm/shadow/multi.c | 8 +- xen/common/efi/boot.c | 12 +-- 19 files changed, 226 insertions(+), 170 deletions(-)
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 2/12 p2m-pt: Avoid hard-coding Xen's PAT
This makes the code much easier to understand. No functional change intended. As per Andrew Cooper, the existing logic is questionable, but this does not make it any worse.
--- xen/arch/x86/mm/p2m-pt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/mm/p2m-pt.c +3 -3
@@ -99,13 +99,13 @@ static unsigned long p2m_type_to_flags(const struct p2m_domain *p2m,return flags |P2M_BASE_FLAGS | _PAGE_RW | _PAGE_NX_BIT;case p2m_mmio_direct:if ( !rangeset_contains_singleton (mmio_ro_ranges,mfn_x (mfn)) ) - flags |= _PAGE_RW; + flags |= _PAGE_RW | _PAGE_UCM;else { - flags |= _PAGE_PWT; + flags |= _PAGE_UC;ASSERT (!level); } -return flags |P2M_BASE_FLAGS | _PAGE_PCD; +return flags |P2M_BASE_FLAGS ; } }
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 1/12 x86/mm: Avoid hard-coding PAT in get_page_from_l1e()
In reply to Demi Marie Obenourget_page_from_l1e() relied on Xen's choice of PAT, which is brittle in the face of future PAT changes. Use the proper _PAGE_* constants instead. Also, treat the two unused cases as if they are cacheable, as future changes may make them cacheable.
--- xen/arch/x86/mm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
xen/arch/x86/mm.c +10 -5
@@ -959,14 +959,19 @@ get_page_from_l1e( flip = _PAGE_RW; } +/* Force cacheable memtypes to UC */ switch ( l1f &PAGE_CACHE_ATTRS ) { -case 0 :/* WB */ - flip |= _PAGE_PWT | _PAGE_PCD; +case _PAGE_UC: +case _PAGE_UCM: +case _PAGE_WC: +/* not cached */ break ; -case _PAGE_PWT:/* WT */ -case _PAGE_PWT | _PAGE_PAT:/* WP */ - flip |= _PAGE_PCD | (l1f & _PAGE_PAT); +case _PAGE_WB: +case _PAGE_WT: +case _PAGE_WP: +default : + flip |= (l1f &PAGE_CACHE_ATTRS ) ^ _PAGE_UC;break ; }
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 3/12 efi: Avoid hard-coding the various PAT constants
In reply to Demi Marie ObenourThis makes the code much easier to understand, and avoids problems if Xen's PAT ever changes in the future.
--- xen/common/efi/boot.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
xen/common/efi/boot.c +6 -6
@@ -1748,23 +1748,23 @@ void __init efi_init_memory(void) emfn =PFN_UP (desc->PhysicalStart + len);if ( desc->Attribute &EFI_MEMORY_WB ) -/* nothing */ ; + prot |= _PAGE_WB;else if ( desc->Attribute &EFI_MEMORY_WT ) - prot |= _PAGE_PWT |MAP_SMALL_PAGES ; + prot |= _PAGE_WT |MAP_SMALL_PAGES ;else if ( desc->Attribute &EFI_MEMORY_WC ) - prot |= _PAGE_PAT |MAP_SMALL_PAGES ; + prot |= _PAGE_WC |MAP_SMALL_PAGES ;else if ( desc->Attribute & (EFI_MEMORY_UC |EFI_MEMORY_UCE ) ) - prot |= _PAGE_PWT | _PAGE_PCD |MAP_SMALL_PAGES ; + prot |= _PAGE_UC |MAP_SMALL_PAGES ;else if ( efi_bs_revision >=EFI_REVISION (2 ,5 ) && (desc->Attribute &EFI_MEMORY_WP ) ) - prot |= _PAGE_PAT | _PAGE_PWT |MAP_SMALL_PAGES ; + prot |= _PAGE_WP |MAP_SMALL_PAGES ;else {printk (XENLOG_ERR "Unknown cachability for MFNs %#lx-%#lx%s\n" , smfn, emfn -1 , efi_map_uc ?", assuming UC" :"" );if ( !efi_map_uc )continue ; - prot |= _PAGE_PWT | _PAGE_PCD |MAP_SMALL_PAGES ; + prot |= _PAGE_UC |MAP_SMALL_PAGES ; } if ( desc->Attribute & (efi_bs_revision < EFI_REVISION(2, 5)
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 4/12 x86: Add memory type constants
In reply to Demi Marie ObenourThese are not currently used, so there is no functional change. Future patches will use these constants.
---
Changes since v2:
- Avoid using _AC where not required.
- Define reserved memory types inline
--- xen/arch/x86/include/asm/x86-defns.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
xen/arch/x86/include/asm/x86-defns.h +11 -0
@@ -153,4 +153,15 @@ (1u << X86_EXC_AC) | (1u << X86_EXC_CP) | \ (1u << X86_EXC_VC) | (1u << X86_EXC_SX)) +/* Memory types */ +#define X86_MT_UC 0x00/* uncachable */ +#define X86_MT_WC 0x01/* write-combined */ +#define X86_MT_RESERVED_1 0x02/* reserved */ +#define X86_MT_RESERVED_2 0x03/* reserved */ +#define X86_MT_WT 0x04/* write-through */ +#define X86_MT_WP 0x05/* write-protect */ +#define X86_MT_WB 0x06/* write-back */ +#define X86_MT_UCM 0x07/* UC- */ +#define X86_NUM_MT 0x08 +#endif /* __XEN_X86_DEFNS_H__ */
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 5/12 x86: Replace PAT_* with X86_MT_*
In reply to Demi Marie ObenourThis allows eliminating the former.
---
Changes since v2: Style adjustments
--- xen/arch/x86/hvm/hvm.c | 12 ++++---- xen/arch/x86/hvm/mtrr.c | 52 ++++++++++++++++----------------- xen/arch/x86/hvm/vmx/vmx.c | 16 +++++----- xen/arch/x86/include/asm/mtrr.h | 12 +------- xen/arch/x86/mm/p2m-ept.c | 4 +-- xen/arch/x86/mm/shadow/multi.c | 4 +-- 6 files changed, 45 insertions(+), 55 deletions(-)
xen/arch/x86/hvm/hvm.c +6 -6
@@ -307,12 +307,12 @@ int hvm_set_guest_pat(struct vcpu *v, uint64_t guest_pat)for ( i =0 , tmp = guest_pat; i <8 ; i++, tmp >>=8 )switch ( tmp &0xff ) { -case PAT_TYPE_UC_MINUS : -case PAT_TYPE_UNCACHABLE : -case PAT_TYPE_WRBACK : -case PAT_TYPE_WRCOMB : -case PAT_TYPE_WRPROT : -case PAT_TYPE_WRTHROUGH : +case X86_MT_UCM : +case X86_MT_UC : +case X86_MT_WB : +case X86_MT_WC : +case X86_MT_WP : +case X86_MT_WT :break ;default :return 0 ;
xen/arch/x86/hvm/mtrr.c +26 -26
124 lines not on this page · raw message
xen/arch/x86/hvm/vmx/vmx.c +8 -8
@@ -1231,14 +1231,14 @@ static void cf_check vmx_handle_cd(struct vcpu *v, unsigned long value)* memory type are all UC. */ u64 uc_pat = - ((uint64_t )PAT_TYPE_UNCACHABLE ) |/* PAT0 */ - ((uint64_t )PAT_TYPE_UNCACHABLE <<8 ) |/* PAT1 */ - ((uint64_t )PAT_TYPE_UNCACHABLE <<16 ) |/* PAT2 */ - ((uint64_t )PAT_TYPE_UNCACHABLE <<24 ) |/* PAT3 */ - ((uint64_t )PAT_TYPE_UNCACHABLE <<32 ) |/* PAT4 */ - ((uint64_t )PAT_TYPE_UNCACHABLE <<40 ) |/* PAT5 */ - ((uint64_t )PAT_TYPE_UNCACHABLE <<48 ) |/* PAT6 */ - ((uint64_t )PAT_TYPE_UNCACHABLE <<56 );/* PAT7 */ + ((uint64_t )X86_MT_UC ) |/* PAT0 */ + ((uint64_t )X86_MT_UC <<8 ) |/* PAT1 */ + ((uint64_t )X86_MT_UC <<16 ) |/* PAT2 */ + ((uint64_t )X86_MT_UC <<24 ) |/* PAT3 */ + ((uint64_t )X86_MT_UC <<32 ) |/* PAT4 */ + ((uint64_t )X86_MT_UC <<40 ) |/* PAT5 */ + ((uint64_t )X86_MT_UC <<48 ) |/* PAT6 */ + ((uint64_t )X86_MT_UC <<56 );/* PAT7 */ vmx_get_guest_pat (v, pat);vmx_set_guest_pat (v, uc_pat);
xen/arch/x86/include/asm/mtrr.h +1 -11
@@ -16,17 +16,7 @@#define NORMAL_CACHE_MODE 0#define NO_FILL_CACHE_MODE 2 -enum { -PAT_TYPE_UNCACHABLE =0 , -PAT_TYPE_WRCOMB =1 , -PAT_TYPE_WRTHROUGH =4 , -PAT_TYPE_WRPROT =5 , -PAT_TYPE_WRBACK =6 , -PAT_TYPE_UC_MINUS =7 , -PAT_TYPE_NUMS -}; - -#define INVALID_MEM_TYPE PAT_TYPE_NUMS +#define INVALID_MEM_TYPE X86_NUM_MT/* In the Intel processor's MTRR interface, the MTRR type is always held in an 8 bit field: */
xen/arch/x86/mm/p2m-ept.c +2 -2
@@ -573,8 +573,8 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn,if ( gmtrr_mtype >=0 ) { *ipat = true; -return gmtrr_mtype !=PAT_TYPE_UC_MINUS ? gmtrr_mtype - :MTRR_TYPE_UNCACHABLE ; +return gmtrr_mtype !=X86_MT_UCM ? gmtrr_mtype + :MTRR_TYPE_UNCACHABLE ; }if ( gmtrr_mtype == -EADDRNOTAVAIL )return -1 ;
xen/arch/x86/mm/shadow/multi.c +2 -2
@@ -561,7 +561,7 @@ _sh_propagate(struct vcpu *v, (type = hvm_get_mem_pinned_cacheattr(d, target_gfn, 0)) >= 0 ) sflags |=pat_type_2_pte_flags (type); else if ( d->arch.hvm.is_in_uc_mode ) - sflags |= pat_type_2_pte_flags(PAT_TYPE_UNCACHABLE); + sflags |= pat_type_2_pte_flags(X86_MT_UC); else if ( iomem_access_permitted(d, mfn_x(target_mfn), mfn_x(target_mfn)) ) {
@@ -572,7 +572,7 @@ _sh_propagate(struct vcpu *v,mfn_to_maddr (target_mfn), MTRR_TYPE_UNCACHABLE); else if ( iommu_snoop ) - sflags |= pat_type_2_pte_flags(PAT_TYPE_WRBACK); + sflags |= pat_type_2_pte_flags(X86_MT_WB); else sflags |= get_pat_flags(v, gflags,
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 6/12 x86: Replace MTRR_* constants with X86_MT_* constants
In reply to Demi Marie ObenourThis allows eliminating of the former, with the exception of MTRR_NUM_TYPES. MTRR_NUM_TYPES is kept, as due to a quirk of the x86 architecture X86_MT_UCM (7) is not valid in an MTRR.
---
Changes since v2:
- Improve commit message
- Do not replace MTRR_NUM_TYPES with X86_MT_UCM
- State explicitly that MTRR_NUM_TYPES is kept
--- xen/arch/x86/cpu/mtrr/generic.c | 10 ++--- xen/arch/x86/cpu/mtrr/main.c | 26 ++++++------- xen/arch/x86/e820.c | 4 +- xen/arch/x86/hvm/mtrr.c | 30 +++++++-------- xen/arch/x86/hvm/vmx/vmcs.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 2 +- xen/arch/x86/include/asm/mtrr.h | 10 +---- xen/arch/x86/mm/p2m-ept.c | 51 ++++++++++++------------- xen/arch/x86/mm/shadow/multi.c | 2 +- 10 files changed, 66 insertions(+), 73 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +5 -5
@@ -127,11 +127,11 @@ static const char *__init mtrr_attrib_to_str(mtrr_type x) {static const char __initconst strings[MTRR_NUM_TYPES ][16 ] = { - [MTRR_TYPE_UNCACHABLE ] ="uncachable" , - [MTRR_TYPE_WRCOMB ] ="write-combining" , - [MTRR_TYPE_WRTHROUGH ] ="write-through" , - [MTRR_TYPE_WRPROT ] ="write-protect" , - [MTRR_TYPE_WRBACK ] ="write-back" , + [X86_MT_UC ] ="uncachable" , + [X86_MT_WC ] ="write-combining" , + [X86_MT_WT ] ="write-through" , + [X86_MT_WP ] ="write-protect" , + [X86_MT_WB ] ="write-back" , };return (x <ARRAY_SIZE (strings) && strings[x][0 ]) ? strings[x] :"?" ;
xen/arch/x86/cpu/mtrr/main.c +13 -13
@@ -163,10 +163,10 @@ static void cf_check ipi_handler(void *info) }static inline int types_compatible (mtrr_type type1,mtrr_type type2) { -return type1 ==MTRR_TYPE_UNCACHABLE || - type2 ==MTRR_TYPE_UNCACHABLE || - (type1 ==MTRR_TYPE_WRTHROUGH && type2 ==MTRR_TYPE_WRBACK ) || - (type1 ==MTRR_TYPE_WRBACK && type2 ==MTRR_TYPE_WRTHROUGH ); +return type1 ==X86_MT_UC || + type2 ==X86_MT_UC || + (type1 ==X86_MT_WT && type2 ==X86_MT_WB ) || + (type1 ==X86_MT_WB && type2 ==X86_MT_WT ); }/**
@@ -297,13 +297,13 @@ static void set_mtrr(unsigned int reg, unsigned long base,* * The available types are * -* %MTRR_TYPE_UNCACHABLE - No caching +* %X86_MT_UC - No caching * -* %MTRR_TYPE_WRBACK - Write data back in bursts whenever +* %X86_MT_WB - Write data back in bursts whenever * -* %MTRR_TYPE_WRCOMB - Write data back soon but allow bursts +* %X86_MT_WC - Write data back soon but allow bursts * -* %MTRR_TYPE_WRTHROUGH - Cache reads but not writes +* %X86_MT_WT - Cache reads but not writes * * BUGS: Needs a quiet flag for the cases where drivers do not mind * failures and do not wish system log messages to be sent.
@@ -328,7 +328,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, }/* If the type is WC, check that this processor supports it */ -if ((type ==MTRR_TYPE_WRCOMB ) && !have_wrcomb ()) { +if ((type ==X86_MT_WC ) && !have_wrcomb ()) {printk (KERN_WARNING "mtrr: your processor doesn't support write-combining\n" );return -EOPNOTSUPP ;
@@ -442,13 +442,13 @@ static int mtrr_check(unsigned long base, unsigned long size)* * The available types are * -* %MTRR_TYPE_UNCACHABLE - No caching +* %X86_MT_UC - No caching * -* %MTRR_TYPE_WRBACK - Write data back in bursts whenever +* %X86_MT_WB - Write data back in bursts whenever * -* %MTRR_TYPE_WRCOMB - Write data back soon but allow bursts +* %X86_MT_WC - Write data back soon but allow bursts * -* %MTRR_TYPE_WRTHROUGH - Cache reads but not writes +* %X86_MT_WT - Cache reads but not writes * * BUGS: Needs a quiet flag for the cases where drivers do not mind * failures and do not wish system log messages to be sent.
xen/arch/x86/e820.c +2 -2
@@ -459,7 +459,7 @@ static uint64_t __init mtrr_top_of_ram(void)printk (" MTRR cap: %" PRIx64" type: %" PRIx64"\n" , mtrr_cap, mtrr_def);/* MTRRs enabled, and default memory type is not writeback? */ -if ( !test_bit (11 , &mtrr_def) || ((uint8_t )mtrr_def ==MTRR_TYPE_WRBACK ) ) +if ( !test_bit (11 , &mtrr_def) || ((uint8_t )mtrr_def ==X86_MT_WB ) )return 0 ;/*
@@ -476,7 +476,7 @@ static uint64_t __init mtrr_top_of_ram(void)printk (" MTRR[%d]: base %" PRIx64" mask %" PRIx64"\n" , i, base, mask); -if ( !test_bit (11 , &mask) || ((uint8_t )base !=MTRR_TYPE_WRBACK ) ) +if ( !test_bit (11 , &mask) || ((uint8_t )base !=X86_MT_WB ) )continue ; base &= addr_mask; mask &= addr_mask;
xen/arch/x86/hvm/mtrr.c +15 -15
@@ -39,11 +39,11 @@ static const uint8_t pat_entry_2_pte_flags[8] = {/* Effective mm type lookup table, according to MTRR and PAT. */ static const uint8_t mm_type_tbl[MTRR_NUM_TYPES ][X86_NUM_MT ] = { #define RS MEMORY_NUM_TYPES -#define UC MTRR_TYPE_UNCACHABLE -#define WB MTRR_TYPE_WRBACK -#define WC MTRR_TYPE_WRCOMB -#define WP MTRR_TYPE_WRPROT -#define WT MTRR_TYPE_WRTHROUGH +#define UC X86_MT_UC +#define WB X86_MT_WB +#define WC X86_MT_WC +#define WP X86_MT_WP +#define WT X86_MT_WT/* PAT(UC, WC, RS, RS, WT, WP, WB, UC-) */ /* MTRR(UC) */ {UC ,WC ,RS ,RS ,UC ,UC ,UC ,UC },
@@ -202,7 +202,7 @@ int mtrr_get_type(const struct mtrr_state *m, paddr_t pa, unsigned int order)unsigned int seg, num_var_ranges =MASK_EXTR (m->mtrr_cap, MTRRcap_VCNT);if (unlikely (!m->enabled) ) -return MTRR_TYPE_UNCACHABLE ; +return X86_MT_UC ; pa &= mask;if ( (pa <0x100000 ) && m->fixed_enabled )
@@ -277,13 +277,13 @@ int mtrr_get_type(const struct mtrr_state *m, paddr_t pa, unsigned int order)return -1 ;/* Two or more matches, one being UC? */ -if ( overlap_mtrr & (1 <<MTRR_TYPE_UNCACHABLE ) ) -return MTRR_TYPE_UNCACHABLE ; +if ( overlap_mtrr & (1 <<X86_MT_UC ) ) +return X86_MT_UC ;/* Two or more matches, all of them WT and WB? */ if ( overlap_mtrr == - ((1 <<MTRR_TYPE_WRTHROUGH ) | (1 <<MTRR_TYPE_WRBACK )) ) -return MTRR_TYPE_WRTHROUGH ; + ((1 <<X86_MT_WT ) | (1 <<X86_MT_WB )) ) +return X86_MT_WT ;/* Behaviour is undefined, but return the last overlapped type. */ return overlap_mtrr_pos;
@@ -381,11 +381,11 @@ static inline bool_t valid_mtrr_type(uint8_t type) {switch ( type ) { -case MTRR_TYPE_UNCACHABLE : -case MTRR_TYPE_WRBACK : -case MTRR_TYPE_WRCOMB : -case MTRR_TYPE_WRPROT : -case MTRR_TYPE_WRTHROUGH : +case X86_MT_UC : +case X86_MT_WB : +case X86_MT_WC : +case X86_MT_WP : +case X86_MT_WT :return 1 ; }return 0 ;
xen/arch/x86/hvm/vmx/vmcs.c +1 -1
@@ -555,7 +555,7 @@ static int vmx_init_vmcs_config(bool bsp)/* Require Write-Back (WB) memory type for VMCS accesses. */ opt = (vmx_basic_msr_high & (VMX_BASIC_MEMORY_TYPE_MASK >>32 )) / ((VMX_BASIC_MEMORY_TYPE_MASK & -VMX_BASIC_MEMORY_TYPE_MASK ) >>32 ); -if ( opt !=MTRR_TYPE_WRBACK ) +if ( opt !=X86_MT_WB ) {printk ("VMX: CPU%d has unexpected VMCS access type %u\n" ,smp_processor_id (), opt);
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -434,7 +434,7 @@ static void cf_check domain_creation_finished(struct domain *d)return ;ASSERT (epte_get_entry_emt (d, gfn, apic_access_mfn,0 , &ipat, - p2m_mmio_direct) ==MTRR_TYPE_WRBACK ); + p2m_mmio_direct) ==X86_MT_WB );ASSERT (ipat);if (set_mmio_p2m_entry (d, gfn, apic_access_mfn,PAGE_ORDER_4K ) )
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +1 -1
@@ -38,7 +38,7 @@ struct vmx_msr_entry {u64 data; }; -#define EPT_DEFAULT_MT MTRR_TYPE_WRBACK +#define EPT_DEFAULT_MT X86_MT_WB struct ept_data { union {
xen/arch/x86/include/asm/mtrr.h +2 -8
@@ -3,15 +3,9 @@#include <xen/mm.h> -/* These are the region types. They match the architectural specification. */ -#define MTRR_TYPE_UNCACHABLE 0 -#define MTRR_TYPE_WRCOMB 1 -#define MTRR_TYPE_WRTHROUGH 4 -#define MTRR_TYPE_WRPROT 5 -#define MTRR_TYPE_WRBACK 6 -#define MTRR_NUM_TYPES 7 +#define MTRR_NUM_TYPES X86_MT_UCM#define MEMORY_NUM_TYPES MTRR_NUM_TYPES -#define NO_HARDCODE_MEM_TYPE MTRR_NUM_TYPES +#define NO_HARDCODE_MEM_TYPE MTRR_NUM_TYPES#define NORMAL_CACHE_MODE 0#define NO_FILL_CACHE_MODE 2
xen/arch/x86/mm/p2m-ept.c +25 -26
120 lines not on this page · raw message
xen/arch/x86/mm/shadow/multi.c +1 -1
@@ -570,7 +570,7 @@ _sh_propagate(struct vcpu *v, gflags,gfn_to_paddr (target_gfn),mfn_to_maddr (target_mfn), - MTRR_TYPE_UNCACHABLE); + X86_MT_UC); else if ( iommu_snoop ) sflags |= pat_type_2_pte_flags(X86_MT_WB); else
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 7/12 x86: Replace EPT_EMT_* constants with X86_MT_*
In reply to Demi Marie ObenourThis allows eliminating the former. No functional change intended.
--- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 9 --------- xen/arch/x86/mm/hap/nested_ept.c | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-)
xen/arch/x86/include/asm/hvm/vmx/vmx.h +0 -9
@@ -80,15 +80,6 @@ typedef enum {#define EPTE_RWX_MASK 0x7#define EPTE_FLAG_MASK 0x7f -#define EPT_EMT_UC 0 -#define EPT_EMT_WC 1 -#define EPT_EMT_RSV0 2 -#define EPT_EMT_RSV1 3 -#define EPT_EMT_WT 4 -#define EPT_EMT_WP 5 -#define EPT_EMT_WB 6 -#define EPT_EMT_RSV2 7 -#define PI_xAPIC_NDST_MASK 0xFF00void vmx_asm_vmexit_handler (struct cpu_user_regs );
xen/arch/x86/mm/hap/nested_ept.c +2 -2
@@ -84,8 +84,8 @@ static bool_t nept_emt_bits_check(ept_entry_t e, uint32_t level) {if ( e.sp || level ==1 ) { -if ( e.emt ==EPT_EMT_RSV0 || e.emt ==EPT_EMT_RSV1 || - e.emt ==EPT_EMT_RSV2 ) +if ( e.emt ==X86_MT_RESERVED_1 || e.emt ==X86_MT_RESERVED_2 || + e.emt ==X86_MT_UCM )return 1 ; }return 0 ;
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 11/12 x86/mm: Reject invalid cacheability in PV guests by default
In reply to Demi Marie ObenourSetting cacheability flags that are not ones specified by Xen is a bug in the guest. By default, inject #GP into any guest that does this. allow_invalid_cacheability can be used on the Xen command line to disable this check.
--- xen/arch/x86/mm.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
xen/arch/x86/mm.c +24 -1
@@ -145,6 +145,8 @@#ifdef CONFIG_PV #include "pv/mm.h" +bool allow_invalid_cacheability; +boolean_param ("allow_invalid_cacheability" , allow_invalid_cacheability);#endif /* Override macros from asm/page.h to make them work with mfn_t */
@@ -1346,7 +1348,28 @@ static int promote_l1_table(struct page_info *page) }else { -switch ( ret =get_page_from_l1e (pl1e[i], d, d) ) +l1_pgentry_t l1e = pl1e[i]; + +BUILD_BUG_ON (PAGE_CACHE_ATTRS >0xffff ); +if ( !allow_invalid_cacheability ) + { +switch ( l1e.l1 &PAGE_CACHE_ATTRS ) + { +case _PAGE_WB: +case _PAGE_UC: +case _PAGE_UCM: +case _PAGE_WC: +case _PAGE_WT: +case _PAGE_WP: +break ; +default : +pv_inject_hw_exception (TRAP_gp_fault,0 ); + ret = -EINVAL ; + goto fail; + } + } + +switch ( ret =get_page_from_l1e (l1e, d, d) ) {default : goto fail;
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 10/12 x86/mm: make code robust to future PAT changes
In reply to Demi Marie ObenourIt may be desirable to change Xen's PAT for various reasons. This requires changes to several _PAGE_* macros as well. Add static assertions to check that XEN_MSR_PAT is consistent with the _PAGE_* macros, and that _PAGE_WB is 0 as required by Linux.
--- xen/arch/x86/mm.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
xen/arch/x86/mm.c +36 -0
@@ -6357,8 +6357,44 @@ unsigned long get_upper_mfn_bound(void)static void __init __maybe_unused build_assertions (void ) { +/* A bunch of static assertions to check that the XEN_MSR_PAT is valid +* and consistent with the _PAGE_* macros */ BUILD_BUG_ON (XEN_MSR_PAT !=0x050100070406ULL &&"wrong XEN_MSR_PAT breaks PV guests" ); +BUILD_BUG_ON (_PAGE_WB &&"Linux requires _PAGE_WB to be 0" ); +#define PAT_VALUE (v) (0xFF & (XEN_MSR_PAT >> (8 * (v)))) +#define BAD_VALUE (v) ((v) < 0 || (v) > 7 || \ + (v) == X86_MT_RESERVED_1 || (v) == X86_MT_RESERVED_2) +#define BAD_PAT_VALUE (v) BUILD_BUG_ON(BAD_VALUE(PAT_VALUE(v))) +BAD_PAT_VALUE (0 ); +BAD_PAT_VALUE (1 ); +BAD_PAT_VALUE (2 ); +BAD_PAT_VALUE (3 ); +BAD_PAT_VALUE (4 ); +BAD_PAT_VALUE (5 ); +BAD_PAT_VALUE (6 ); +BAD_PAT_VALUE (7 ); +#undef BAD_PAT_VALUE +#undef BAD_VALUE +#define PAT_SHIFT (page_value) (((page_value) & _PAGE_PAT) >> 5 | \ + ((page_value) & (_PAGE_PCD | _PAGE_PWT)) >> 3) +#define CHECK_PAGE_VALUE (page_value) do { \ +/* Check that the _PAGE_* macros only use bits from PAGE_CACHE_ATTRS */ \ + BUILD_BUG_ON(((_PAGE_##page_value) & PAGE_CACHE_ATTRS) != \ + (_PAGE_##page_value)); \ +/* Check that the _PAGE_* are consistent with XEN_MSR_PAT */ \ + BUILD_BUG_ON(PAT_VALUE(PAT_SHIFT(_PAGE_##page_value)) != \ + (X86_MT_##page_value)); \ +} while (0) +CHECK_PAGE_VALUE (WT ); +CHECK_PAGE_VALUE (WB ); +CHECK_PAGE_VALUE (WC ); +CHECK_PAGE_VALUE (UC ); +CHECK_PAGE_VALUE (UCM ); +CHECK_PAGE_VALUE (WP ); +#undef CHECK_PAGE_VALUE +#undef PAT_SHIFT +#undef PAT_VALUE }/*
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 12/12 x86: Use Linux's PAT
In reply to Demi Marie ObenourThis is purely for testing, to see if it works around a bug in i915. It is not intended to be merged.
NOT-signed-off-by: DO NOT MERGE
--- xen/arch/x86/include/asm/page.h | 4 ++-- xen/arch/x86/include/asm/processor.h | 13 +++++-------- xen/arch/x86/mm.c | 2 -- 3 files changed, 7 insertions(+), 12 deletions(-)
xen/arch/x86/include/asm/page.h +2 -2
@@ -333,11 +333,11 @@ void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t);/* Memory types, encoded under Xen's choice of MSR_PAT. */ #define _PAGE_WB ( 0) -#define _PAGE_WT ( _PAGE_PWT) +#define _PAGE_WC ( _PAGE_PWT)#define _PAGE_UCM ( _PAGE_PCD )#define _PAGE_UC ( _PAGE_PCD | _PAGE_PWT) -#define _PAGE_WC (_PAGE_PAT )#define _PAGE_WP (_PAGE_PAT | _PAGE_PWT) +#define _PAGE_WT (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT)/* * Debug option: Ensure that granted mappings are not implicitly unmapped.
xen/arch/x86/include/asm/processor.h +5 -8
@@ -92,18 +92,15 @@ X86_EFLAGS_NT|X86_EFLAGS_DF|X86_EFLAGS_IF| \ X86_EFLAGS_TF) -/* -* Host IA32_CR_PAT value to cover all memory types. This is not the default -* MSR_PAT value, and is an ABI with PV guests. -*/ +/* Linux PAT, required by i915 driver */ #define XEN_MSR_PAT (X86_MT_WB << 0x00 | \ - X86_MT_WT << 0x08 | \ + X86_MT_WC << 0x08 | \ X86_MT_UCM << 0x10 | \ X86_MT_UC << 0x18 | \ - X86_MT_WC << 0x20 | \ + X86_MT_WB << 0x20 | \ X86_MT_WP << 0x28 | \ - X86_MT_UC << 0x30 | \ - X86_MT_UC << 0x38 | \ + X86_MT_UCM << 0x30 | \ + X86_MT_WT << 0x38 | \ 0)#ifndef __ASSEMBLY__
xen/arch/x86/mm.c +0 -2
@@ -6382,8 +6382,6 @@ static void __init __maybe_unused build_assertions(void) {/* A bunch of static assertions to check that the XEN_MSR_PAT is valid * and consistent with the _PAGE_* macros */ -BUILD_BUG_ON (XEN_MSR_PAT !=0x050100070406ULL && -"wrong XEN_MSR_PAT breaks PV guests" );BUILD_BUG_ON (_PAGE_WB &&"Linux requires _PAGE_WB to be 0" );#define PAT_VALUE (v) (0xFF & (XEN_MSR_PAT >> (8 * (v))))#define BAD_VALUE (v) ((v) < 0 || (v) > 7 || \
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 8/12 x86: Remove MEMORY_NUM_TYPES and NO_HARDCODE_MEM_TYPE
In reply to Demi Marie ObenourNo functional change intended.
---
Changes since v2:
- Keep MTRR_NUM_TYPES and adjust commit message accordingly
--- xen/arch/x86/hvm/mtrr.c | 18 +++++++++--------- xen/arch/x86/include/asm/mtrr.h | 2 -- xen/arch/x86/mm/shadow/multi.c | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/mtrr.c +9 -9
@@ -38,7 +38,7 @@ static const uint8_t pat_entry_2_pte_flags[8] = {/* Effective mm type lookup table, according to MTRR and PAT. */ static const uint8_t mm_type_tbl[MTRR_NUM_TYPES ][X86_NUM_MT ] = { -#define RS MEMORY_NUM_TYPES +#define RS MTRR_NUM_TYPES #define UC X86_MT_UC #define WB X86_MT_WB #define WC X86_MT_WC
@@ -66,9 +66,9 @@ static const uint8_t mm_type_tbl[MTRR_NUM_TYPES][X86_NUM_MT] = {* Reverse lookup table, to find a pat type according to MTRR and effective * memory type. This table is dynamically generated. */ -static uint8_t __read_mostly mtrr_epat_tbl[MTRR_NUM_TYPES ][MEMORY_NUM_TYPES ] = - { [0 ...MTRR_NUM_TYPES -1 ] = - { [0 ...MEMORY_NUM_TYPES -1 ] =INVALID_MEM_TYPE } +static uint8_t __read_mostly mtrr_epat_tbl[MTRR_NUM_TYPES ][MTRR_NUM_TYPES ] = + { [0 ...MTRR_NUM_TYPES -1 ] = + { [0 ...MTRR_NUM_TYPES -1 ] =INVALID_MEM_TYPE } };/* Lookup table for PAT entry of a given PAT value in host PAT. */
@@ -85,7 +85,7 @@ static int __init cf_check hvm_mtrr_pat_init(void) {unsigned int tmp = mm_type_tbl[i][j]; -if ( tmp <MEMORY_NUM_TYPES ) +if ( tmp <MTRR_NUM_TYPES ) mtrr_epat_tbl[i][tmp] = j; } }
@@ -317,11 +317,11 @@ static uint8_t effective_mm_type(struct mtrr_state *m, uint8_t gmtrr_mtype) {uint8_t mtrr_mtype, pat_value; - +/* if get_pat_flags() gives a dedicated MTRR type, * just use it -*/ -if ( gmtrr_mtype ==NO_HARDCODE_MEM_TYPE ) +*/ +if ( gmtrr_mtype ==MTRR_NUM_TYPES ) mtrr_mtype =mtrr_get_type (m, gpa,0 );else mtrr_mtype = gmtrr_mtype;
@@ -346,7 +346,7 @@ uint32_t get_pat_flags(struct vcpu *v,/* 1. Get the effective memory type of guest physical address, * with the pair of guest MTRR and PAT */ - guest_eff_mm_type =effective_mm_type (g, pat, gpaddr, + guest_eff_mm_type =effective_mm_type (g, pat, gpaddr, gl1e_flags, gmtrr_mtype);/* 2. Get the memory type of host physical address, with MTRR */ shadow_mtrr_type =mtrr_get_type (&mtrr_state, spaddr,0 );
xen/arch/x86/include/asm/mtrr.h +0 -2
@@ -4,8 +4,6 @@#include <xen/mm.h> #define MTRR_NUM_TYPES X86_MT_UCM -#define MEMORY_NUM_TYPES MTRR_NUM_TYPES -#define NO_HARDCODE_MEM_TYPE MTRR_NUM_TYPES#define NORMAL_CACHE_MODE 0#define NO_FILL_CACHE_MODE 2
xen/arch/x86/mm/shadow/multi.c +1 -1
@@ -578,7 +578,7 @@ _sh_propagate(struct vcpu *v, gflags,gfn_to_paddr (target_gfn),mfn_to_maddr (target_mfn), - NO_HARDCODE_MEM_TYPE); + MTRR_NUM_TYPES); } }
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
PATCH v3 9/12 x86: Derive XEN_MSR_PAT from its individual entries
In reply to Demi Marie ObenourThis avoids it being a magic constant that is difficult for humans to decode. Use BUILD_BUG_ON to check that the old and new values are identical.
--- xen/arch/x86/include/asm/processor.h | 10 +++++++++- xen/arch/x86/mm.c | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/processor.h +9 -1
@@ -96,7 +96,15 @@* Host IA32_CR_PAT value to cover all memory types. This is not the default * MSR_PAT value, and is an ABI with PV guests. */ -#define XEN_MSR_PAT _AC(0x050100070406, ULL) +#define XEN_MSR_PAT (X86_MT_WB << 0x00 | \ + X86_MT_WT << 0x08 | \ + X86_MT_UCM << 0x10 | \ + X86_MT_UC << 0x18 | \ + X86_MT_WC << 0x20 | \ + X86_MT_WP << 0x28 | \ + X86_MT_UC << 0x30 | \ + X86_MT_UC << 0x38 | \ + 0)#ifndef __ASSEMBLY__
xen/arch/x86/mm.c +6 -0
@@ -6355,6 +6355,12 @@ unsigned long get_upper_mfn_bound(void)return min (max_mfn,1UL << (paddr_bits -PAGE_SHIFT )) -1 ; } +static void __init __maybe_unused build_assertions (void ) +{ +BUILD_BUG_ON (XEN_MSR_PAT !=0x050100070406ULL && +"wrong XEN_MSR_PAT breaks PV guests" ); +} +/* * Local variables: * mode: C
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
Re: [PATCH v3 01/12] x86/mm: Avoid hard-coding PAT in get_page_from_l1e()
In reply to Demi Marie ObenourQuoted 4 lines · Demi Marie Obenour
get_page_from_l1e()relied on Xen's choice of PAT, which is brittle in the face of future PAT changes. Use the proper _PAGE_* constants instead. Also, treat the two unused cases as if they are cacheable, as future changes may make them cacheable.
This still does not cover ...
Quoted 15 lines
xen/arch/x86/mm.c +5
-2@@ -959,14 +959,19 @@ get_page_from_l1e( flip = _PAGE_RW; } +/* Force cacheable memtypes to UC */ switch ( l1f &PAGE_CACHE_ATTRS ) { -case 0 :/* WB */ - flip |= _PAGE_PWT | _PAGE_PCD; +case _PAGE_UC: +case _PAGE_UCM: +case _PAGE_WC: +/* not cached */
xen/arch/x86/mm.c get_page_from_l1e( · line 975
Quoted 10 lines
xen/arch/x86/mm.c +5
-3break ; -case _PAGE_PWT:/* WT */ -case _PAGE_PWT | _PAGE_PAT:/* WP */ - flip |= _PAGE_PCD | (l1f & _PAGE_PAT); +case _PAGE_WB: +case _PAGE_WT: +case _PAGE_WP: +default : + flip |= (l1f &PAGE_CACHE_ATTRS ) ^ _PAGE_UC;break ;
... the three cases here assuming certain properties wrt the flipping of _PAGE_UC. As said before - going from one kind of assumption to another _may_ be a good thing to do, but needs justifying as actually being an improvement. Alternatively such assumptions could be checked by suitable BUILD_BUG_ON(), which then at the same serve as documentation thereof.
Jan
Re: [PATCH v3 04/12] x86: Add memory type constants
In reply to Demi Marie Obenourxen/arch/x86/include/asm/x86-defns.h line 160
Quoted 11 lines · Demi Marie Obenour
xen/arch/x86/include/asm/x86-defns.h +5
-0@@ -153,4 +153,15 @@ (1u << X86_EXC_AC) | (1u << X86_EXC_CP) | \ (1u << X86_EXC_VC) | (1u << X86_EXC_SX)) +/* Memory types */ +#define X86_MT_UC 0x00/* uncachable */ +#define X86_MT_WC 0x01/* write-combined */ +#define X86_MT_RESERVED_1 0x02/* reserved */ +#define X86_MT_RESERVED_2 0x03/* reserved */
As said, unless there's a good reason to use 1 and 2 (and not e.g. 0 and 1), I'd prefer these to be numbered 2 and 3 to match the values they expand to (and the numbering then not being as arbitrary).
Jan
Re: [PATCH v3 01/12] x86/mm: Avoid hard-coding PAT in get_page_from_l1e()
In reply to Jan BeulichQuoted 40 lines · Jan Beulich
Quoted 4 lines · Demi Marie Obenour
get_page_from_l1e()relied on Xen's choice of PAT, which is brittle in the face of future PAT changes. Use the proper _PAGE_* constants instead. Also, treat the two unused cases as if they are cacheable, as future changes may make them cacheable.This still does not cover ...
Quoted 15 lines
xen/arch/x86/mm.c +5
-2@@ -959,14 +959,19 @@ get_page_from_l1e( flip = _PAGE_RW; } +/* Force cacheable memtypes to UC */ switch ( l1f &PAGE_CACHE_ATTRS ) { -case 0 :/* WB */ - flip |= _PAGE_PWT | _PAGE_PCD; +case _PAGE_UC: +case _PAGE_UCM: +case _PAGE_WC: +/* not cached */ xen/arch/x86/mm.c get_page_from_l1e( · line 975
Quoted 10 lines
xen/arch/x86/mm.c +5
-3break ; -case _PAGE_PWT:/* WT */ -case _PAGE_PWT | _PAGE_PAT:/* WP */ - flip |= _PAGE_PCD | (l1f & _PAGE_PAT); +case _PAGE_WB: +case _PAGE_WT: +case _PAGE_WP: +default : + flip |= (l1f &PAGE_CACHE_ATTRS ) ^ _PAGE_UC;break ;... the three cases here assuming certain properties wrt the flipping of
_PAGE_UC. As said before - going from one kind of assumption to another _may_ be a good thing to do, but needs justifying as actually being an improvement. Alternatively such assumptions could be checked by suitableBUILD_BUG_ON(), which then at the same serve as documentation thereof.
Quoted 1 line
Jan
I think I understand your point now: this still assumes that the two unused types are not UCM or WC, but this is not documented anywhere. I will move this to after the patch that introduces the X86_MT_* flags, which will allow me to switch on (XEN_MSR_PAT >> pte_flags_to_cacheattr(l1f)) instead without having to change the code again in a subsequent patch.
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
Re: [PATCH v3 06/12] x86: Replace MTRR_* constants with X86_MT_* constants
In reply to Demi Marie ObenourQuoted 6 lines · Demi Marie Obenour
This allows eliminating of the former, with the exception of
MTRR_NUM_TYPES.MTRR_NUM_TYPESis kept, as due to a quirk of the x86 architectureX86_MT_UCM(7) is not valid in an MTRR.Suggested-by Andrew Cooper <[email protected]>Signed-off-by Demi Marie Obenour <[email protected]>
Re: [PATCH v3 08/12] x86: Remove MEMORY_NUM_TYPES and NO_HARDCODE_MEM_TYPE
In reply to Demi Marie ObenourQuoted 3 lines · Demi Marie Obenour
No functional change intended.
Signed-off-by Demi Marie Obenour <[email protected]>
I'm not convinced removing this (visual) distinction is a good idea. I'd like to wait for other maontainers' views here.
Jan
Re: [PATCH v3 09/12] x86: Derive XEN_MSR_PAT from its individual entries
In reply to Demi Marie ObenourQuoted 5 lines · Demi Marie Obenour
xen/arch/x86/include/asm/processor.h +0
-0@@ -96,7 +96,15 @@* Host IA32_CR_PAT value to cover all memory types. This is not the default * MSR_PAT value, and is an ABI with PV guests.
xen/arch/x86/include/asm/processor.h line 106
Quoted 10 lines
xen/arch/x86/include/asm/processor.h +8
-1*/ -#define XEN_MSR_PAT _AC(0x050100070406, ULL) +#define XEN_MSR_PAT (X86_MT_WB << 0x00 | \ + X86_MT_WT << 0x08 | \ + X86_MT_UCM << 0x10 | \ + X86_MT_UC << 0x18 | \ + X86_MT_WC << 0x20 | \ + X86_MT_WP << 0x28 | \ + X86_MT_UC << 0x30 | \ + X86_MT_UC << 0x38 | \
This wants properly parenthesizing (the shifts against the ors), and at least the last four constants also look to need casting to uint64_t; in fact I'm surprised that ...
xen/arch/x86/include/asm/processor.h line 107
Quoted 1 line
xen/arch/x86/include/asm/processor.h +1
-0+ 0)
(interposed: I don't think this really does any good.)
xen/arch/x86/mm.c unsigned long get_upper_mfn_bound(void) · line 6361
Quoted 10 lines
xen/arch/x86/mm.c +4
-0@@ -6355,6 +6355,12 @@ unsigned long get_upper_mfn_bound(void)return min (max_mfn,1UL << (paddr_bits -PAGE_SHIFT )) -1 ; } +static void __init __maybe_unused build_assertions (void ) +{ +BUILD_BUG_ON (XEN_MSR_PAT !=0x050100070406ULL && +"wrong XEN_MSR_PAT breaks PV guests" );
... this didn't trigger for you. (We also don't normally add such constructs with a string literal to BUILD_BUG_ON() expressions, not the least because compilers may take issue with such. I'd like to suggest to convert this to a comment instead.)
Jan
Re: [PATCH v3 04/12] x86: Add memory type constants
In reply to Jan BeulichQuoted 7 lines · Jan Beulich
Quoted 6 lines · Demi Marie Obenour
xen/arch/x86/include/asm/x86-defns.h +0
-0@@ -153,4 +153,15 @@ (1u <<X86_EXC_AC ) | (1u <<X86_EXC_CP ) | \ (1u << X86_EXC_VC) | (1u << X86_EXC_SX))
Quoted 8 lines
xen/arch/x86/include/asm/x86-defns.h line 160
Quoted 5 lines
xen/arch/x86/include/asm/x86-defns.h +5
-0+/* Memory types */ +#define X86_MT_UC 0x00/* uncachable */ +#define X86_MT_WC 0x01/* write-combined */ +#define X86_MT_RESERVED_1 0x02/* reserved */ +#define X86_MT_RESERVED_2 0x03/* reserved */ As said, unless there's a good reason to use 1 and 2 (and not e.g. 0 and 1), I'd prefer these to be numbered 2 and 3 to match the values they expand to (and the numbering then not being as arbitrary).
TBH, I'd prefer not having them in the first place (I'll see if there's a way to simplify the build assertions which are the only users I can spot), but if we are going to have them then do use 2 and 3, and its fine to abbreviate to RSVD.
~Andrew
Re: [PATCH v3 04/12] x86: Add memory type constants
Quoted 17 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Demi Marie Obenour
xen/arch/x86/include/asm/x86-defns.h +0
-0@@ -153,4 +153,15 @@ (1u <<X86_EXC_AC ) | (1u <<X86_EXC_CP ) | \ (1u << X86_EXC_VC) | (1u << X86_EXC_SX))Quoted 8 lines
xen/arch/x86/include/asm/x86-defns.h line 160
Quoted 5 lines
xen/arch/x86/include/asm/x86-defns.h +5
-0+/* Memory types */ +#define X86_MT_UC 0x00/* uncachable */ +#define X86_MT_WC 0x01/* write-combined */ +#define X86_MT_RESERVED_1 0x02/* reserved */ +#define X86_MT_RESERVED_2 0x03/* reserved */ As said, unless there's a good reason to use 1 and 2 (and not e.g. 0 and 1), I'd prefer these to be numbered 2 and 3 to match the values they expand to (and the numbering then not being as arbitrary).
Quoted 4 lines
TBH, I'd prefer not having them in the first place (I'll see if there's a way to simplify the build assertions which are the only users I can spot), but if we are going to have them then do use 2 and 3, and its fine to abbreviate to RSVD.
They will be needed when the NPT code starts to use these constants, as EPT_EMT_RSV0 and EPT_EMT_RSV1 are used.
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab