xen/x86: various XPTI speedups
PATCH v3 1/7 x86/xpti: avoid copying L4 page table contents when possible
In reply to Juergen GrossFor mitigation of Meltdown the current L4 page table is copied to the cpu local root page table each time a 64 bit pv guest is entered.
Copying can be avoided in cases where the guest L4 page table hasn't been modified while running the hypervisor, e.g. when handling interrupts or any hypercall not modifying the L4 page table or %cr3.
So add a per-cpu flag whether the copying should be performed and set that flag only when loading a new %cr3 or modifying the L4 page table. This includes synchronization of the cpu local root page table with other cpus, so add a special synchronization flag for that case.
A simple performance check (compiling the hypervisor via "make -j 4") in dom0 with 4 vcpus shows a significant improvement:
- real time drops from 112 seconds to 103 seconds
- system time drops from 142 seconds to 131 seconds
---
V3:
- set flag locally only if affected L4 is active (Jan Beulich)
- add setting flag to flush_area_mask() (Jan Beulich)
- set flag in make_cr3() only if called for current active vcpu
To be applied on top of Jan's "Meltdown band-aid overhead reduction" series
--- xen/arch/x86/flushtlb.c | 3 +++ xen/arch/x86/mm.c | 42 +++++++++++++++++++++++++++------------ xen/arch/x86/smp.c | 2 +- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/arch/x86/x86_64/entry.S | 8 ++++++-- xen/include/asm-x86/current.h | 8 ++++++++ xen/include/asm-x86/flushtlb.h | 2 ++ 7 files changed, 50 insertions(+), 16 deletions(-)
xen/arch/x86/flushtlb.c +3 -0
@@ -158,6 +158,9 @@ unsigned int flush_area_local(const void *va, unsigned int flags) } } +if ( flags &FLUSH_ROOT_PGTBL ) +get_cpu_info ()->root_pgt_changed = true; +local_irq_restore (irqfl);return flags;
xen/arch/x86/mm.c +29 -13
64 lines not on this page · raw message
xen/arch/x86/smp.c +1 -1
@@ -208,7 +208,7 @@ void invalidate_interrupt(struct cpu_user_regs *regs)ack_APIC_irq ();perfc_incr (ipis);if ( (flags &FLUSH_VCPU_STATE ) &&__sync_local_execstate () ) - flags &= ~(FLUSH_TLB |FLUSH_TLB_GLOBAL ); + flags &= ~(FLUSH_TLB |FLUSH_TLB_GLOBAL |FLUSH_ROOT_PGTBL );if ( flags & ~(FLUSH_VCPU_STATE |FLUSH_ORDER_MASK ) )flush_area_local (flush_va, flags);cpumask_clear_cpu (smp_processor_id (), &flush_cpumask);
xen/arch/x86/x86_64/asm-offsets.c +1 -0
@@ -143,6 +143,7 @@ void __dummy__(void) OFFSET(CPUINFO_shadow_spec_ctrl, struct cpu_info, shadow_spec_ctrl); OFFSET(CPUINFO_use_shadow_spec_ctrl, struct cpu_info, use_shadow_spec_ctrl); OFFSET(CPUINFO_bti_ist_info, struct cpu_info, bti_ist_info); + OFFSET(CPUINFO_root_pgt_changed, struct cpu_info, root_pgt_changed);DEFINE (CPUINFO_sizeof,sizeof (struct cpu_info ));BLANK ();
xen/arch/x86/x86_64/entry.S +6 -2
@@ -129,10 +129,13 @@ restore_all_guest: .Lrag_cr3_start: mov VCPU_cr3(%rbx), %r9 GET_STACK_END(dx) - mov STACK_CPUINFO_FIELD(pv_cr3)(%rdx), %rdi + mov STACK_CPUINFO_FIELD(pv_cr3)(%rdx), %rax + cmpb $0, STACK_CPUINFO_FIELD(root_pgt_changed)(%rdx) + je .Lrag_copy_done + movb $0, STACK_CPUINFO_FIELD(root_pgt_changed)(%rdx) movabs $PADDR_MASK & PAGE_MASK, %rsi movabs $DIRECTMAP_VIRT_START, %rcx - mov %rdi, %rax + mov %rax, %rdi and %rsi, %rdi and %r9, %rsi add %rcx, %rdi
@@ -148,6 +151,7 @@ restore_all_guest: sub $(ROOT_PAGETABLE_FIRST_XEN_SLOT - \ ROOT_PAGETABLE_LAST_XEN_SLOT - 1) * 8, %rdi rep movsq +.Lrag_copy_done: mov STACK_CPUINFO_FIELD(cr4)(%rdx), %rdi mov %r9, STACK_CPUINFO_FIELD(xen_cr3)(%rdx) mov %rdi, %rsi
xen/include/asm-x86/current.h +8 -0
@@ -59,6 +59,14 @@ struct cpu_info {bool use_shadow_spec_ctrl;uint8_t bti_ist_info; +/* +* The following field controls copying of the L4 page table of 64-bit +* PV guests to the per-cpu root page table on entering the guest context. +* If set the L4 page table is being copied to the root page table and +* the field will be reset. +*/ +bool root_pgt_changed; +unsigned long __pad;/* get_stack_bottom() must be 16-byte aligned */ };
xen/include/asm-x86/flushtlb.h +2 -0
@@ -103,6 +103,8 @@ void write_cr3(unsigned long cr3);#define FLUSH_VA_VALID 0x800/* Flush CPU state */ #define FLUSH_VCPU_STATE 0x1000 +/* Flush the per-cpu root page table */ +#define FLUSH_ROOT_PGTBL 0x2000/* Flush local TLBs/caches. */ unsigned int flush_area_local (const void *va,unsigned int flags);
Signature · 7 lines
2.13.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 2/7 x86/xpti: don't flush TLB twice when switching to 64-bit pv context
In reply to Juergen GrossWhen switching to a 64-bit pv context the TLB is flushed twice today:
the first time when switching to the new address space in write_ptbase(), the second time when switching to guest mode in restore_to_guest.
Avoid the first TLB flush in that case.
---
V3:
- omit setting root_pgt_changed to false (Jan Beulich)
--- xen/arch/x86/mm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
xen/arch/x86/mm.c +8 -1
@@ -123,6 +123,7 @@#include <asm/io_apic.h> #include <asm/pci.h> #include <asm/guest.h> +#include <asm/processor.h> #include <asm/hvm/grant_table.h> #include <asm/pv/grant_table.h>
@@ -507,8 +508,14 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {if (this_cpu (root_pgt) &&is_pv_vcpu (v) && !is_pv_32bit_vcpu (v) ) + {get_cpu_info ()->root_pgt_changed = true; -write_cr3 (v->arch.cr3); + asmvolatile ("mov %0, %%cr3" : :"r" (v->arch.cr3) :"memory" ); + } +else + { +write_cr3 (v->arch.cr3); + } }/*
Signature · 7 lines
2.13.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 3/7 xen/x86: support per-domain flag for xpti
In reply to Juergen GrossInstead of switching XPTI globally on or off add a per-domain flag for that purpose. This allows to modify the xpti boot parameter to support running dom0 without Meltdown mitigations. Using "xpti=nodom0" as boot parameter will achieve that.
Move the xpti boot parameter handling to xen/arch/x86/pv/domain.c as it is pv-domain specific.
---
V3:
- latch get_cpu_info() return value in variable (Jan Beulich)
- call always xpti_domain_init() for pv dom0 (Jan Beulich)
- add __init annotations (Jan Beulich)
- drop per domain XPTI message (Jan Beulich)
- document xpti=default support (Jan Beulich)
- move domain xpti flag into a padding hole (Jan Beulich)
--- docs/misc/xen-command-line.markdown | 10 ++++- xen/arch/x86/domctl.c | 4 ++ xen/arch/x86/mm.c | 10 ++++- xen/arch/x86/pv/dom0_build.c | 3 ++ xen/arch/x86/pv/domain.c | 80 ++++++++++++++++++++++++++++++++++++- xen/arch/x86/setup.c | 20 +--------- xen/arch/x86/smpboot.c | 5 +-- xen/arch/x86/x86_64/entry.S | 2 + xen/include/asm-x86/current.h | 3 +- xen/include/asm-x86/domain.h | 3 ++ xen/include/asm-x86/pv/domain.h | 5 ++- 11 files changed, 118 insertions(+), 27 deletions(-)
docs/misc/xen-command-line.markdown +9 -1
@@ -1955,7 +1955,7 @@ clustered mode. The default, given no hint from the **FADT**, is cluster mode. ### xpti -> `= <boolean>` +> `= default | nodom0 | <boolean>` > Default: `false` on AMD hardware > Default: `true` everywhere else
@@ -1963,6 +1963,14 @@ mode. Override default selection of whether to isolate 64-bit PV guest page tables. +`true` activates page table isolation even on AMD hardware. + +`false` deactivates page table isolation on all systems. + +`default` sets the default behaviour. + +`nodom0` deactivates page table isolation for dom0. + ### xsave > `= <boolean>`
xen/arch/x86/domctl.c +4 -0
@@ -24,6 +24,7 @@#include <asm/hvm/hvm.h> #include <asm/hvm/support.h> #include <asm/processor.h> +#include <asm/pv/domain.h> #include <asm/acpi.h> /* for hvm_acpi_power_button */ #include <xen/hypercall.h> /* for arch_do_domctl */ #include <xsm/xsm.h>
@@ -610,6 +611,9 @@ long arch_do_domctl( ret =switch_compat (d); else ret = -EINVAL ; + +if ( ret ==0 ) +xpti_domain_init (d);break ;case XEN_DOMCTL_get_address_size:
xen/arch/x86/mm.c +8 -2
@@ -507,14 +507,20 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) { -if (this_cpu (root_pgt) &&is_pv_vcpu (v) && !is_pv_32bit_vcpu (v) ) +struct cpu_info *cpu_info =get_cpu_info (); + +if (is_pv_vcpu (v) && v->domain->arch.pv_domain.xpti ) { -get_cpu_info ()->root_pgt_changed = true; + cpu_info->root_pgt_changed = true; + cpu_info->pv_cr3 =__pa (this_cpu (root_pgt)); asmvolatile ("mov %0, %%cr3" : :"r" (v->arch.cr3) :"memory" ); }else { +/* Make sure to clear xen_cr3 before pv_cr3; write_cr3() serializes. */ + cpu_info->xen_cr3 =0 ;write_cr3 (v->arch.cr3); + cpu_info->pv_cr3 =0 ; } }
xen/arch/x86/pv/dom0_build.c +3 -0
@@ -19,6 +19,7 @@#include <asm/dom0_build.h> #include <asm/guest.h> #include <asm/page.h> +#include <asm/pv/domain.h> #include <asm/pv/mm.h> #include <asm/setup.h>
@@ -707,6 +708,8 @@ int __init dom0_construct_pv(struct domain *d, cpu = p->processor; } +xpti_domain_init (d); + d->arch.paging.mode =0 ;/* Set up CR3 value for write_ptbase */
xen/arch/x86/pv/domain.c +79 -1
98 lines not on this page · raw message
xen/arch/x86/setup.c +2 -18
@@ -53,6 +53,7 @@#include <asm/cpuid.h> #include <asm/spec_ctrl.h> #include <asm/guest.h> +#include <asm/pv/domain.h> /* opt_nosmp: If true, secondary processors are ignored. */ static bool __initdata opt_nosmp;
@@ -169,9 +170,6 @@ static int __init parse_smap_param(const char *s) }custom_param ("smap" , parse_smap_param); -static int8_t __initdata opt_xpti =-1 ; -boolean_param ("xpti" , opt_xpti); -bool __read_mostly acpi_disabled;bool __initdata acpi_force;static char __initdata acpi_param[10 ] ="" ;
@@ -1546,21 +1544,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) cr4_pv32_mask = mmu_cr4_features &XEN_CR4_PV32_BITS ; -if ( opt_xpti <0 ) - { -uint64_t caps =0 ; - -if ( boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) - caps =ARCH_CAPABILITIES_RDCL_NO ; -else if (boot_cpu_has (X86_FEATURE_ARCH_CAPS ) ) -rdmsrl (MSR_ARCH_CAPABILITIES , caps); - - opt_xpti = !(caps &ARCH_CAPABILITIES_RDCL_NO ); - } -if ( opt_xpti ) -setup_clear_cpu_cap (X86_FEATURE_NO_XPTI ); -else -setup_force_cpu_cap (X86_FEATURE_NO_XPTI ); +xpti_init ();if ( cpu_has_fsgsbase )set_in_cr4 (X86_CR4_FSGSBASE );
xen/arch/x86/smpboot.c +2 -3
@@ -331,7 +331,7 @@ void start_secondary(void *unused)spin_debug_disable ();get_cpu_info ()->xen_cr3 =0 ; -get_cpu_info ()->pv_cr3 =this_cpu (root_pgt) ?__pa (this_cpu (root_pgt)) :0 ; +get_cpu_info ()->pv_cr3 =0 ;load_system_tables ();
@@ -1050,8 +1050,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)panic ("Error %d setting up PV root page table\n" , rc);if (per_cpu (root_pgt,0 ) ) { -get_cpu_info ()->pv_cr3 =__pa (per_cpu (root_pgt,0 )); - +get_cpu_info ()->pv_cr3 =0 ;/* * All entry points which may need to switch page tables have to start * with interrupts off. Re-write what pv_trap_init() has put there.
xen/arch/x86/x86_64/entry.S +2 -0
@@ -130,6 +130,8 @@ restore_all_guest: mov VCPU_cr3(%rbx), %r9 GET_STACK_END(dx) mov STACK_CPUINFO_FIELD(pv_cr3)(%rdx), %rax + test %rax, %rax + jz .Lrag_cr3_end cmpb $0, STACK_CPUINFO_FIELD(root_pgt_changed)(%rdx) je .Lrag_copy_done movb $0, STACK_CPUINFO_FIELD(root_pgt_changed)(%rdx)
xen/include/asm-x86/current.h +2 -1
@@ -44,7 +44,8 @@ struct cpu_info {/* * Of the two following fields the latter is being set to the CR3 value * to be used on the given pCPU for loading whenever 64-bit PV guest -* context is being entered. The value never changes once set. +* context is being entered. A value of zero indicates no setting of CR3 +* is to be performed. * The former is the value to restore when re-entering Xen, if any. IOW * its value being zero means there's nothing to restore. However, its * value can also be negative, indicating to the exit-to-Xen code that
xen/include/asm-x86/domain.h +3 -0
@@ -253,6 +253,9 @@ struct pv_domainatomic_t nr_l4_pages; +/* XPTI active? */ +bool xpti; +/* map_domain_page() mapping cache. */ struct mapcache_domain mapcache;
xen/include/asm-x86/pv/domain.h +4 -1
@@ -27,6 +27,8 @@ void pv_vcpu_destroy(struct vcpu *v);int pv_vcpu_initialise (struct vcpu *v);void pv_domain_destroy (struct domain *d);int pv_domain_initialise (struct domain *d); +void xpti_init (void ); +void xpti_domain_init (struct domain *d);#else /* !CONFIG_PV */
@@ -36,7 +38,8 @@ static inline void pv_vcpu_destroy(struct vcpu *v) {}static inline int pv_vcpu_initialise (struct vcpu *v) {return -EOPNOTSUPP ; }static inline void pv_domain_destroy (struct domain *d) {}static inline int pv_domain_initialise (struct domain *d) {return -EOPNOTSUPP ; } - +static inline void xpti_init (void ) {} +static inline void xpti_domain_init (struct domain *d) {}#endif /* CONFIG_PV */ void paravirt_ctxt_switch_from (struct vcpu *v);
Signature · 7 lines
2.13.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 5/7 xen/x86: disable global pages for domains with XPTI active
In reply to Juergen GrossInstead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
In order to avoid states with cr3/cr4 having inconsistent values (e.g. global pages being activated while cr3 already specifies a XPTI address space) move loading of the new cr4 value to write_ptbase() (actually to write_cr3_cr4() called by write_ptbase()).
---
V3:
- move cr4 loading for all domains from *_ctxt_switch_to() to write_cr3_cr4() called by write_ptbase() (Jan Beulich)
- rebase
--- xen/arch/x86/domain.c | 5 ----- xen/arch/x86/flushtlb.c | 13 ++++++++----- xen/arch/x86/mm.c | 11 ++++++++--- xen/arch/x86/x86_64/entry.S | 10 ---------- xen/common/efi/runtime.c | 4 ++-- xen/include/asm-x86/domain.h | 3 ++- xen/include/asm-x86/flushtlb.h | 2 +- 7 files changed, 21 insertions(+), 27 deletions(-)
xen/arch/x86/domain.c +0 -5
@@ -1520,17 +1520,12 @@ void paravirt_ctxt_switch_from(struct vcpu *v)void paravirt_ctxt_switch_to (struct vcpu *v) {root_pgentry_t *root_pgt =this_cpu (root_pgt); -unsigned long cr4;if ( root_pgt ) root_pgt[root_table_offset (PERDOMAIN_VIRT_START )] =l4e_from_page (v->domain->arch.perdomain_l3_pg, __PAGE_HYPERVISOR_RW); - cr4 =pv_guest_cr4_to_real_cr4 (v); -if (unlikely (cr4 !=read_cr4 ()) ) -write_cr4 (cr4); -if (unlikely (v->arch.debugreg[7 ] &DR7_ACTIVE_MASK ) )activate_debugregs (v);
xen/arch/x86/flushtlb.c +8 -5
@@ -91,20 +91,23 @@ static void do_tlb_flush(void)post_flush (t); } -void write_cr3 (unsigned long cr3) +void write_cr3_cr4 (unsigned long cr3,unsigned long cr4) { -unsigned long flags, cr4; +unsigned long flags;u32 t;/* This non-reentrant function is sometimes called in interrupt context. */ local_irq_save (flags); t =pre_flush (); - cr4 =read_cr4 (); -write_cr4 (cr4 & ~X86_CR4_PGE ); +if (read_cr4 () &X86_CR4_PGE ) +write_cr4 (cr4 & ~X86_CR4_PGE ); + asmvolatile ("mov %0, %%cr3" : :"r" (cr3) :"memory" ); -write_cr4 (cr4); + +if (read_cr4 () != cr4 ) +write_cr4 (cr4);post_flush (t);
xen/arch/x86/mm.c +8 -3
@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;if (is_pv_vcpu (v) && v->domain->arch.pv_domain.xpti ) { cpu_info->root_pgt_changed = true; cpu_info->pv_cr3 =__pa (this_cpu (root_pgt)); - asmvolatile ("mov %0, %%cr3" : :"r" (v->arch.cr3) :"memory" ); +write_cr3_cr4 (v->arch.cr3, new_cr4); }else { -/* Make sure to clear xen_cr3 before pv_cr3; write_cr3() serializes. */ +/* Make sure to clear xen_cr3 before pv_cr3. */ cpu_info->xen_cr3 =0 ; -write_cr3 (v->arch.cr3); +/* write_cr3_cr4() serializes. */ +write_cr3_cr4 (v->arch.cr3, new_cr4); cpu_info->pv_cr3 =0 ; } }
xen/arch/x86/x86_64/entry.S +0 -10
@@ -154,13 +154,8 @@ restore_all_guest: ROOT_PAGETABLE_LAST_XEN_SLOT - 1) * 8, %rdi rep movsq .Lrag_copy_done: - mov STACK_CPUINFO_FIELD(cr4)(%rdx), %rdi mov %r9, STACK_CPUINFO_FIELD(xen_cr3)(%rdx) - mov %rdi, %rsi - and $~X86_CR4_PGE, %rdi - mov %rdi, %cr4 mov %rax, %cr3 - mov %rsi, %cr4 .Lrag_cr3_end: ALTERNATIVE_NOP .Lrag_cr3_start, .Lrag_cr3_end, X86_FEATURE_NO_XPTI
@@ -218,12 +213,7 @@ restore_all_xen: * so "g" will have to do. */ UNLIKELY_START(g, exit_cr3) - mov %cr4, %rdi - mov %rdi, %rsi - and $~X86_CR4_PGE, %rdi - mov %rdi, %cr4 mov %rax, %cr3 - mov %rsi, %cr4 UNLIKELY_END(exit_cr3) .Lrax_cr3_end: ALTERNATIVE_NOP .Lrax_cr3_start, .Lrax_cr3_end, X86_FEATURE_NO_XPTI
xen/common/efi/runtime.c +2 -2
@@ -111,7 +111,7 @@ struct efi_rs_state efi_rs_enter(void)lgdt (&gdt_desc); } -write_cr3 (virt_to_maddr (efi_l4_pgtable)); +write_cr3_cr4 (virt_to_maddr (efi_l4_pgtable),read_cr4 ());return state; }
@@ -120,7 +120,7 @@ void efi_rs_leave(struct efi_rs_state *state) {if ( !state->cr3 )return ; -write_cr3 (state->cr3); +write_cr3_cr4 (state->cr3,read_cr4 ());if (is_pv_vcpu (current) && !is_idle_vcpu (current) ) { struct desc_ptr gdt_desc = {
xen/include/asm-x86/domain.h +2 -1
@@ -621,7 +621,8 @@ unsigned long pv_guest_cr4_fixup(const struct vcpu *, unsigned long guest_cr4); X86_CR4_SMAP | X86_CR4_OSXSAVE | \ X86_CR4_FSGSBASE)) \ | ((v)->domain->arch.vtsc ? X86_CR4_TSD : 0)) \ - & ~X86_CR4_DE) + & ~(X86_CR4_DE | \ + ((v)->domain->arch.pv_domain.xpti ? X86_CR4_PGE : 0)))#define real_cr4_to_pv_guest_cr4 (c) \ ((c) & ~(X86_CR4_PGE | X86_CR4_PSE | X86_CR4_TSD | \ X86_CR4_OSXSAVE | X86_CR4_SMEP | \
xen/include/asm-x86/flushtlb.h +1 -1
@@ -84,7 +84,7 @@ static inline unsigned long read_cr3(void) }/* Write pagetable base and implicitly tick the tlbflush clock. */ -void write_cr3 (unsigned long cr3); +void write_cr3_cr4 (unsigned long cr3,unsigned long cr4);/* flush_* flag fields: */ /*
Signature · 7 lines
2.13.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 4/7 xen/x86: use invpcid for flushing the TLB
In reply to Juergen GrossIf possible use the INVPCID instruction for flushing the TLB instead of toggling cr4.pge for that purpose.
While at it remove the dependency on cr4.pge being required for mtrr loading, as this will be required later anyway.
Add a command line option "noinvpcid" for deactivating the use of INVPCID.
---
V3:
- new patch
--- docs/misc/xen-command-line.markdown | 8 ++++++++ xen/arch/x86/cpu/mtrr/generic.c | 37 ++++++++++++++++++++++++++----------- xen/arch/x86/flushtlb.c | 31 +++++++++++++++++++++---------- xen/arch/x86/setup.c | 7 +++++++ 4 files changed, 62 insertions(+), 21 deletions(-)
docs/misc/xen-command-line.markdown +8 -0
@@ -1380,6 +1380,14 @@ Because responsibility for APIC setup is shared between Xen and the domain 0 kernel this option is automatically propagated to the domain 0 command line. +### noinvpcid (x86) +> `= <boolean>` + +Disable using the INVPCID instruction for flushing TLB entries. +This should only be used in case of known issues on the current platform +with that instruction. Disabling INVPCID will normally result in a slightly +degraded performance. + ### noirqbalance > `= <boolean>`
xen/arch/x86/cpu/mtrr/generic.c +26 -11
@@ -5,6 +5,7 @@#include <xen/mm.h> #include <xen/stdbool.h> #include <asm/flushtlb.h> +#include <asm/invpcid.h> #include <asm/io.h> #include <asm/mtrr.h> #include <asm/msr.h>
@@ -400,8 +401,10 @@ static DEFINE_SPINLOCK(set_atomicity_lock);* has been called. */ -static void prepare_set (void ) +static bool prepare_set (void ) { +unsigned long cr4; +/* Note that this is not ideal, since the cache is only flushed/disabled for this CPU while the MTRRs are changed, but changing this requires more invasive changes to the way the kernel boots */
@@ -412,18 +415,24 @@ static void prepare_set(void)write_cr0 (read_cr0 () |X86_CR0_CD );wbinvd (); -/* TLB flushing here relies on Xen always using CR4.PGE. */ -BUILD_BUG_ON (!(XEN_MINIMAL_CR4 &X86_CR4_PGE )); -write_cr4 (read_cr4 () & ~X86_CR4_PGE ); + cr4 =read_cr4 (); +if (cr4 &X86_CR4_PGE ) +write_cr4 (cr4 & ~X86_CR4_PGE ); +else if (cpu_has_invpcid) +invpcid_flush_all (); +else + asmvolatile ("mov %0, %%cr3" : :"r" (read_cr3 ()) :"memory" );/* Save MTRR state */ rdmsrl (MSR_MTRRdefType, deftype);/* Disable MTRRs, and set the default type to uncached */ mtrr_wrmsr (MSR_MTRRdefType, deftype & ~0xcff ); + +return cr4 &X86_CR4_PGE ; } -static void post_set (void ) +static void post_set (bool pge) {/* Intel (P6) standard MTRRs */ mtrr_wrmsr (MSR_MTRRdefType, deftype);
@@ -432,7 +441,12 @@ static void post_set(void)write_cr0 (read_cr0 () & ~X86_CR0_CD );/* Reenable CR4.PGE (also flushes the TLB) */ -write_cr4 (read_cr4 () |X86_CR4_PGE ); +if (pge) +write_cr4 (read_cr4 () |X86_CR4_PGE ); +else if (cpu_has_invpcid) +invpcid_flush_all (); +else + asmvolatile ("mov %0, %%cr3" : :"r" (read_cr3 ()) :"memory" );spin_unlock (&set_atomicity_lock); }
@@ -441,14 +455,15 @@ static void generic_set_all(void) {unsigned long mask, count;unsigned long flags; +bool pge;local_irq_save (flags); -prepare_set (); + pge =prepare_set ();/* Actually set the state */ mask =set_mtrr_state (); -post_set (); +post_set (pge);local_irq_restore (flags);/* Use the atomic bitops to update the global mask */
@@ -457,7 +472,6 @@ static void generic_set_all(void)set_bit (count, &smp_changes_mask); mask >>=1 ; } - } static void generic_set_mtrr(unsigned int reg, unsigned long base,
@@ -474,11 +488,12 @@ static void generic_set_mtrr(unsigned int reg, unsigned long base, {unsigned long flags;struct mtrr_var_range *vr; +bool pge; vr = &mtrr_state.var_ranges[reg];local_irq_save (flags); -prepare_set (); + pge =prepare_set ();if (size ==0 ) {/* The invalid bit is kept in the mask, so we simply clear the
@@ -499,7 +514,7 @@ static void generic_set_mtrr(unsigned int reg, unsigned long base,mtrr_wrmsr (MSR_IA32_MTRR_PHYSMASK (reg), vr->mask); } -post_set (); +post_set (pge);local_irq_restore (flags); }
xen/arch/x86/flushtlb.c +21 -10
@@ -10,6 +10,7 @@#include <xen/sched.h> #include <xen/softirq.h> #include <asm/flushtlb.h> +#include <asm/invpcid.h> #include <asm/page.h> /* Debug builds: Wrap frequently to stress-test the wrap logic. */
@@ -71,6 +72,25 @@ static void post_flush(u32 t)this_cpu (tlbflush_time) = t; } +static void do_tlb_flush (void ) +{ +u32 t; + + t =pre_flush (); + +if ( cpu_has_invpcid ) +invpcid_flush_all (); +else + { +unsigned long cr4 =read_cr4 (); + +write_cr4 (cr4 ^X86_CR4_PGE ); +write_cr4 (cr4); + } + +post_flush (t); +} +void write_cr3 (unsigned long cr3) {unsigned long flags, cr4;
@@ -118,16 +138,7 @@ unsigned int flush_area_local(const void *va, unsigned int flags) : : "m" (*(const char *)(va)) : "memory" ); }else - { -u32 t =pre_flush (); -unsigned long cr4 =read_cr4 (); - -write_cr4 (cr4 & ~X86_CR4_PGE ); -barrier (); -write_cr4 (cr4); - -post_flush (t); - } +do_tlb_flush (); }if ( flags &FLUSH_CACHE )
xen/arch/x86/setup.c +7 -0
@@ -63,6 +63,10 @@ boolean_param("nosmp", opt_nosmp);static unsigned int __initdata max_cpus;integer_param ("maxcpus" , max_cpus); +/* opt_noinvpcid: If true, don't use INVPCID instruction even if available. */ +static bool __initdata opt_noinvpcid; +boolean_param ("noinvpcid" , opt_noinvpcid); +unsigned long __read_mostly cr4_pv32_mask;/* **** Linux config option: propagated to domain0. */
@@ -1549,6 +1553,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( cpu_has_fsgsbase )set_in_cr4 (X86_CR4_FSGSBASE ); +if ( opt_noinvpcid ) +setup_clear_cpu_cap (X86_FEATURE_INVPCID ); +init_speculation_mitigations ();init_idle_domain ();
Signature · 7 lines
2.13.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 7/7 xen/x86: use PCID feature
In reply to Juergen GrossAvoid flushing the complete TLB when switching %cr3 for mitigation of Meltdown by using the PCID feature if available.
We are using 4 PCID values for a 64 bit pv domain subject to XPTI and 2 values for the non-XPTI case:
- guest active and in kernel mode
- guest active and in user mode
- hypervisor active and guest in user mode (XPTI only)
- hypervisor active and guest in kernel mode (XPTI only)
We use PCID only if PCID _and_ INVPCID are supported. With PCID in use we disable global pages in cr4. A command line parameter controls in which cases PCID is being used.
As the non-XPTI case has shown not to perform better with PCID at least on some machines the default is to use PCID only for domains subject to XPTI.
---
V3:
- support PCID for non-XPTI case, too
- add command line parameter for controlling usage of PCID
- check PCID active by using cr4.pcide (Jan Beulich)
--- docs/misc/xen-command-line.markdown | 12 +++++++++ xen/arch/x86/debug.c | 3 ++- xen/arch/x86/domain_page.c | 2 +- xen/arch/x86/domctl.c | 4 +++ xen/arch/x86/flushtlb.c | 49 ++++++++++++++++++++++++++++------ xen/arch/x86/mm.c | 34 +++++++++++++++++++++--- xen/arch/x86/pv/dom0_build.c | 1 + xen/arch/x86/pv/domain.c | 52 +++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/domain.h | 14 +++++++--- xen/include/asm-x86/pv/domain.h | 2 ++ xen/include/asm-x86/x86-defns.h | 1 + 11 files changed, 158 insertions(+), 16 deletions(-)
docs/misc/xen-command-line.markdown +12 -0
@@ -1450,6 +1450,18 @@ All numbers specified must be hexadecimal ones. This option can be specified more than once (up to 8 times at present). +### pcid (x86) +> `= off | all | xpti | noxpti` + +> Default: `xpti` + +> Can be modified at runtime + +If available, control usage of the PCID feature of the processor for +64-bit pv-domains. PCID can be used either for no domain at all, for +all of them, only for those subject to XPTI or for those not subject +to XPTI. + ### ple\_gap > `= <integer>`
xen/arch/x86/debug.c +2 -1
@@ -97,7 +97,8 @@ dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val)l3_pgentry_t l3e, *l3t;l2_pgentry_t l2e, *l2t;l1_pgentry_t l1e, *l1t; -unsigned long cr3 = (pgd3val ? pgd3val : dp->vcpu[0 ]->arch.cr3); +unsigned long cr3 = (pgd3val ? pgd3val + : (dp->vcpu[0 ]->arch.cr3 & ~X86_CR3_NOFLUSH ));mfn_t mfn =maddr_to_mfn (cr3); DBGP2("vaddr:%lx domid:%d cr3:%lx pgd3:%lx\n", vaddr, dp->domain_id,
xen/arch/x86/domain_page.c +1 -1
@@ -51,7 +51,7 @@ static inline struct vcpu *mapcache_current_vcpu(void)if ( (v = idle_vcpu[smp_processor_id ()]) == current )sync_local_execstate ();/* We must now be running on the idle page table. */ -ASSERT (read_cr3 () ==__pa (idle_pg_table)); +ASSERT ((read_cr3 () & ~X86_CR3_PCIDMASK ) ==__pa (idle_pg_table)); }return v;
xen/arch/x86/domctl.c +4 -0
@@ -613,7 +613,11 @@ long arch_do_domctl( ret = -EINVAL ;if ( ret ==0 ) + {xpti_domain_init (d); +pcid_domain_init (d); + } +break ;case XEN_DOMCTL_get_address_size:
xen/arch/x86/flushtlb.c +41 -8
62 lines not on this page · raw message
xen/arch/x86/mm.c +31 -3
@@ -497,12 +497,38 @@ void free_shared_domheap_page(struct page_info *page)free_domheap_page (page); } +/* +* Return additional PCID specific cr3 bits. +* +* Note that X86_CR3_NOFLUSH will not be readable in cr3. Anyone consuming +* v->arch.cr3 should mask away X86_CR3_NOFLUSH and X86_CR3_PCIDMASK in case +* the value is used to address the root page table. +*/ +static unsigned long get_pcid_bits (struct vcpu *v,bool is_xen) +{ +return X86_CR3_NOFLUSH | (is_xen ?PCID_PV_XEN :0 ) | + ((v->arch.flags & TF_kernel_mode) ?PCID_PV_PRIV :PCID_PV_USER ); +} +void make_cr3 (struct vcpu *v,mfn_t mfn) { +struct domain *d = v->domain; + v->arch.cr3 =mfn_x (mfn) <<PAGE_SHIFT ; -if ( v == current &&this_cpu (root_pgt) &&is_pv_vcpu (v) && - !is_pv_32bit_vcpu (v) ) -get_cpu_info ()->root_pgt_changed = true; +if (is_pv_domain (d) ) + { +if ( d->arch.pv_domain.xpti && v == current ) + { +struct cpu_info *cpu_info =get_cpu_info (); + + cpu_info->root_pgt_changed = true; +if ( d->arch.pv_domain.pcid ) + cpu_info->pv_cr3 =__pa (this_cpu (root_pgt)) | +get_pcid_bits (v, false); + } +if ( d->arch.pv_domain.pcid ) + v->arch.cr3 |=get_pcid_bits (v, d->arch.pv_domain.xpti); + } }void write_ptbase (struct vcpu *v)
@@ -517,6 +543,8 @@ void write_ptbase(struct vcpu *v) { cpu_info->root_pgt_changed = true; cpu_info->pv_cr3 =__pa (this_cpu (root_pgt)); +if ( new_cr4 &X86_CR4_PCIDE ) + cpu_info->pv_cr3 |=get_pcid_bits (v, false);write_cr3_cr4 (v->arch.cr3, new_cr4); } else
xen/arch/x86/pv/dom0_build.c +1 -0
@@ -709,6 +709,7 @@ int __init dom0_construct_pv(struct domain *d, }xpti_domain_init (d); +pcid_domain_init (d); d->arch.paging.mode =0 ;
xen/arch/x86/pv/domain.c +52 -0
58 lines not on this page · raw message
xen/include/asm-x86/domain.h +11 -3
@@ -255,6 +255,8 @@ struct pv_domain/* XPTI active? */ bool xpti; +/* Use PCID feature? */ +bool pcid;/* map_domain_page() mapping cache. */ struct mapcache_domain mapcache;
@@ -262,6 +264,11 @@ struct pv_domainstruct cpuidmasks *cpuidmasks; }; +/* PCID values for the address spaces of 64-bit pv domains: */ +#define PCID_PV_PRIV 0x0000/* Used for other domains, too. */ +#define PCID_PV_USER 0x0001 +#define PCID_PV_XEN 0x0002/* To be ORed to above values. */ +struct monitor_write_data {struct {unsigned int msr :1 ;
@@ -619,14 +626,15 @@ unsigned long pv_guest_cr4_fixup(const struct vcpu *, unsigned long guest_cr4); | (mmu_cr4_features \ & (X86_CR4_PGE | X86_CR4_PSE | X86_CR4_SMEP | \ X86_CR4_SMAP | X86_CR4_OSXSAVE | \ - X86_CR4_FSGSBASE)) \ - | ((v)->domain->arch.vtsc ? X86_CR4_TSD : 0)) \ + X86_CR4_FSGSBASE | X86_CR4_PCIDE)) \ + | ((v)->domain->arch.vtsc ? X86_CR4_TSD : 0) \ + | ((v)->domain->arch.pv_domain.pcid ? X86_CR4_PCIDE : 0)) \ & ~(X86_CR4_DE | \ ((v)->domain->arch.pv_domain.xpti ? X86_CR4_PGE : 0)))#define real_cr4_to_pv_guest_cr4 (c) \ ((c) & ~(X86_CR4_PGE | X86_CR4_PSE | X86_CR4_TSD | \ X86_CR4_OSXSAVE | X86_CR4_SMEP | \ - X86_CR4_FSGSBASE | X86_CR4_SMAP)) + X86_CR4_FSGSBASE | X86_CR4_SMAP | X86_CR4_PCIDE))#define domain_max_vcpus (d) (is_hvm_domain(d) ? HVM_MAX_VCPUS : MAX_VIRT_CPUS)
xen/include/asm-x86/pv/domain.h +2 -0
@@ -29,6 +29,7 @@ void pv_domain_destroy(struct domain *d);int pv_domain_initialise (struct domain *d);void xpti_init (void );void xpti_domain_init (struct domain *d); +void pcid_domain_init (struct domain *d);#else /* !CONFIG_PV */
@@ -40,6 +41,7 @@ static inline void pv_domain_destroy(struct domain *d) {}static inline int pv_domain_initialise (struct domain *d) {return -EOPNOTSUPP ; }static inline void xpti_init (void ) {}static inline void xpti_domain_init (struct domain *d) {} +static inline void pcid_domain_init (struct domain *d) {}#endif /* CONFIG_PV */ void paravirt_ctxt_switch_from (struct vcpu *v);
xen/include/asm-x86/x86-defns.h +1 -0
@@ -46,6 +46,7 @@* Intel CPU flags in CR3 */ #define X86_CR3_NOFLUSH (_AC(1, ULL) << 63) +#define X86_CR3_PCIDMASK _AC(0x0fff, ULL)/* Mask for PCID */ /* * Intel CPU features in CR4
Signature · 7 lines
2.13.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 6/7 xen/x86: use flag byte for decision whether xen_cr3 is valid
In reply to Juergen GrossToday cpu_info->xen_cr3 is either 0 to indicate %cr3 doesn't need to be switched on entry to Xen, or negative for keeping the value while indicating not to restore %cr3, or positive in case %cr3 is to be restored.
Switch to use a flag byte instead of a negative xen_cr3 value in order to allow %cr3 values with the high bit set in case we want to keep TLB entries when using the PCID feature.
This reduces the number of branches in interrupt handling and results in better performance (e.g. parallel make of the Xen hypervisor on my system was using about 3% less system time).
---
V3:
- renamed use_xen_cr3 to better fitting use_pv_cr3
- corrected comment regarding semantics of use_pv_cr3 (Jan Beulich)
- prefer 32-bit operations over 8- or 16-bit ones (Jan Beulich)
--- xen/arch/x86/domain.c | 1 + xen/arch/x86/mm.c | 3 +- xen/arch/x86/smpboot.c | 2 ++ xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/arch/x86/x86_64/compat/entry.S | 5 ++- xen/arch/x86/x86_64/entry.S | 67 +++++++++++++++++--------------------- xen/include/asm-x86/current.h | 12 ++++--- 7 files changed, 45 insertions(+), 46 deletions(-)
xen/arch/x86/domain.c +1 -0
@@ -1693,6 +1693,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next)ASSERT (local_irq_is_enabled ()); +get_cpu_info ()->use_pv_cr3 = false;get_cpu_info ()->xen_cr3 =0 ;if (unlikely (dirty_cpu != cpu) && dirty_cpu !=VCPU_CPU_CLEAN )
xen/arch/x86/mm.c +2 -1
@@ -521,7 +521,8 @@ void write_ptbase(struct vcpu *v) }else { -/* Make sure to clear xen_cr3 before pv_cr3. */ +/* Make sure to clear use_pv_cr3 and xen_cr3 before pv_cr3. */ + cpu_info->use_pv_cr3 = false; cpu_info->xen_cr3 =0 ;/* write_cr3_cr4() serializes. */ write_cr3_cr4 (v->arch.cr3, new_cr4);
xen/arch/x86/smpboot.c +2 -0
@@ -330,6 +330,7 @@ void start_secondary(void *unused)*/ spin_debug_disable (); +get_cpu_info ()->use_pv_cr3 = false;get_cpu_info ()->xen_cr3 =0 ;get_cpu_info ()->pv_cr3 =0 ;
@@ -1128,6 +1129,7 @@ void __init smp_prepare_boot_cpu(void)per_cpu (scratch_cpumask, cpu) = &scratch_cpu0mask;#endif +get_cpu_info ()->use_pv_cr3 = false;get_cpu_info ()->xen_cr3 =0 ;get_cpu_info ()->pv_cr3 =0 ; }
xen/arch/x86/x86_64/asm-offsets.c +1 -0
@@ -144,6 +144,7 @@ void __dummy__(void) OFFSET(CPUINFO_use_shadow_spec_ctrl, struct cpu_info, use_shadow_spec_ctrl); OFFSET(CPUINFO_bti_ist_info, struct cpu_info, bti_ist_info); OFFSET(CPUINFO_root_pgt_changed, struct cpu_info, root_pgt_changed); + OFFSET(CPUINFO_use_pv_cr3, struct cpu_info, use_pv_cr3);DEFINE (CPUINFO_sizeof,sizeof (struct cpu_info ));BLANK ();
xen/arch/x86/x86_64/compat/entry.S +2 -3
@@ -211,10 +211,9 @@ ENTRY(cstar_enter) GET_STACK_END(bx) .Lcstar_cr3_start: mov STACK_CPUINFO_FIELD(xen_cr3)(%rbx), %rcx - neg %rcx + test %rcx, %rcx jz .Lcstar_cr3_okay - mov %rcx, STACK_CPUINFO_FIELD(xen_cr3)(%rbx) - neg %rcx + movb $0, STACK_CPUINFO_FIELD(use_pv_cr3)(%rbx) mov %rcx, %cr3 /* %r12 is still zero at this point. */ mov %r12, STACK_CPUINFO_FIELD(xen_cr3)(%rbx)
xen/arch/x86/x86_64/entry.S +29 -38
171 lines not on this page · raw message
xen/include/asm-x86/current.h +8 -4
@@ -47,10 +47,7 @@ struct cpu_info {* context is being entered. A value of zero indicates no setting of CR3 * is to be performed. * The former is the value to restore when re-entering Xen, if any. IOW -* its value being zero means there's nothing to restore. However, its -* value can also be negative, indicating to the exit-to-Xen code that -* restoring is not necessary, but allowing any nested entry code paths -* to still know the value to put back into CR3. +* its value being zero means there's nothing to restore. */ unsigned long xen_cr3;unsigned long pv_cr3;
@@ -68,6 +65,13 @@ struct cpu_info {*/ bool root_pgt_changed; +/* +* use_pv_cr3 is set in case the value of pv_cr3 is to be written into +* CR3 when returning from an interrupt. The main use is when returning +* from a NMI or MCE to hypervisor code where pv_cr3 was active. +*/ +bool use_pv_cr3; +unsigned long __pad;/* get_stack_bottom() must be 16-byte aligned */ };
Signature · 7 lines
2.13.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
v3 cover xen/x86: various XPTI speedups
This patch series aims at reducing the overhead of the XPTI Meltdown mitigation. It is based on Jan's XPTI speedup series.
Patch 1 had been posted before, the main changes in this patch are due to addressing Jan's comments on my first version. The main objective of that patch is to avoid copying the L4 page table each time the guest is being activated, as often the contents didn't change while the hypervisor was active.
Patch 2 tries to minimize flushing the TLB: there is no need to flush it in write_ptbase() and when activating the guest.
Patch 3 sets the stage for being able to activate XPTI per domain. As a first step it is now possible to switch XPTI off for dom0 via the xpti boot parameter.
Patch 4 adds support for using the INVPCID instruction for flushing the TLB.
Patch 5 reduces the costs of TLB flushes even further: as we don't make any use of global TLB entries with XPTI being active we can avoid removing all global TLB entries on TLB flushes by simply deactivating the global pages in CR4.
Patch 6 was originally only meant to prepare using PCIDs in patch 6. For that purpose it was necessary to allow CR3 values with bit 63 set in order to avoid flushing TLB entries when writing CR3. This requires a modification of Jan's rather clever state machine with positive and negative CR3 values for the hypervisor by using a dedicated flag byte instead. It turned out this modification saved one branch on interrupt entry speeding up the handling by a few percent.
Patch 7 is the main performance contributor: by making use of the PCID feature (if available) TLB entries can survive CR3 switches. The TLB needs to be flushed on context switches only and not when switching between guest and hypervisor or guest kernel and user mode.
On my machine (Intel i7-4600M) using the PCID feature in the non-XPTI case showed a slightly worse performance than using global pages instead (using PCID and global pages is a bad idea as invalidating global pages in this case would need a complete TLB flush). For this reason I've decided to use PCID for XPTI only as the default. That can easily be changed by using the command line parameter "pcid=all".
The complete series has been verified to still mitigate against Meltdown attacks. A simple performance test (make -j 4 in the Xen hypervisor directory) showed significant improvements compared to the state without this series (so with Jan's series applied), the percentage after the numbers is always related to XPTI off:
XPTI off Jan, XPTI on +this series, XPTI on real 1m21.169s 1m52.149s (+38%) 1m25.692s (+6%) user 2m47.652s 2m50.054s (+1%) 2m46.428s (-1%) sys 1m11.949s 2m21.767s (+97%) 1m23.053s (+15%)
A git branch of that series (+ Jan's patches) is available:
https://github.com/jgross1/xen.git xpti
Juergen Gross (7):
x86/xpti: avoid copying L4 page table contents when possible x86/xpti: don't flush TLB twice when switching to 64-bit pv context xen/x86: support per-domain flag for xpti
xen/x86: use invpcid for flushing the TLB
xen/x86: disable global pages for domains with XPTI active xen/x86: use flag byte for decision whether xen_cr3 is valid xen/x86: use PCID feature
docs/misc/xen-command-line.markdown | 30 +++++++- xen/arch/x86/cpu/mtrr/generic.c | 37 +++++++--- xen/arch/x86/debug.c | 3 +- xen/arch/x86/domain.c | 6 +- xen/arch/x86/domain_page.c | 2 +- xen/arch/x86/domctl.c | 8 +++ xen/arch/x86/flushtlb.c | 96 +++++++++++++++++++------- xen/arch/x86/mm.c | 91 +++++++++++++++++++++---- xen/arch/x86/pv/dom0_build.c | 4 ++ xen/arch/x86/pv/domain.c | 132 +++++++++++++++++++++++++++++++++++- xen/arch/x86/setup.c | 27 +++----- xen/arch/x86/smp.c | 2 +- xen/arch/x86/smpboot.c | 7 +- xen/arch/x86/x86_64/asm-offsets.c | 2 + xen/arch/x86/x86_64/compat/entry.S | 5 +- xen/arch/x86/x86_64/entry.S | 87 ++++++++++-------------- xen/common/efi/runtime.c | 4 +- xen/include/asm-x86/current.h | 23 +++++-- xen/include/asm-x86/domain.h | 20 ++++-- xen/include/asm-x86/flushtlb.h | 4 +- xen/include/asm-x86/pv/domain.h | 7 +- xen/include/asm-x86/x86-defns.h | 1 + 22 files changed, 453 insertions(+), 145 deletions(-)
Signature · 7 lines
2.13.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 1/7] x86/xpti: avoid copying L4 page table contents when possible
In reply to Juergen Grossxen/arch/x86/flushtlb.c unsigned int flush_area_local(const void *va, unsigned int flags) · line 166
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
xen/arch/x86/flushtlb.c +3
-0@@ -158,6 +158,9 @@ unsigned int flush_area_local(const void *va, unsigned int flags) } } +if ( flags &FLUSH_ROOT_PGTBL ) +get_cpu_info ()->root_pgt_changed = true; +local_irq_restore (irqfl);return flags;
Does this really need to sit inside the interrupts disabled section?
Thinking about it I even wonder whether the cache flush part needs to be. Even for the INVLPG portion of the TLB flush part I can't seem to see a need for IRQs to be off. I think it's really just the pre_flush() / post_flush() pair which needs to be inside such a section. I'll prepare a patch (for after 4.11). I think some of the changes later in your series will actually further ease this.
xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 505
Quoted 10 lines
xen/arch/x86/mm.c +3
-0@@ -499,10 +499,15 @@ void free_shared_domheap_page(struct page_info *page)void make_cr3 (struct vcpu *v,mfn_t mfn) { v->arch.cr3 =mfn_x (mfn) <<PAGE_SHIFT ; +if ( v == current &&this_cpu (root_pgt) &&is_pv_vcpu (v) && + !is_pv_32bit_vcpu (v) ) +get_cpu_info ()->root_pgt_changed = true; }
As this doesn't actually update CR3, setting the flag shouldn't generally be necessary if the caller then invokes write_ptbase(). Isn't setting the flag here needed solely in the case of _toggle_guest_pt() being up the call tree? In which case it would perhaps better be set there (and in turn some or even all of the conditional around it could be dropped)?
xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 511
Quoted 5 lines
xen/arch/x86/mm.c +2
-0void write_ptbase (struct vcpu *v) { +if (this_cpu (root_pgt) &&is_pv_vcpu (v) && !is_pv_32bit_vcpu (v) ) +get_cpu_info ()->root_pgt_changed = true;write_cr3 (v->arch.cr3);
When you come here from e.g. __sync_local_execstate(), you don't really need to set the flag. Of course you'll come here again before the next 64-bit PV vCPU will make it to restore_all_guest, so by the time we make it there the flag will be set anyway. However, if you already use such a subtlety, then there's also no point excluding 32-bit vCPU-s here (nor in make_cr3()), as those will never make it to restore_all_guest. Same then for excluding HVM vCPU-s. And I then wonder whether (here or more likely in a later patch) the root_pgt check couldn't go away as well.
Quoted 19 lines
xen/arch/x86/mm.c +3
-12@@ -3698,18 +3703,29 @@ long do_mmu_update(break ; rc =mod_l4_entry (va,l4e_from_intpte (req.val), mfn, cmd ==MMU_PT_UPDATE_PRESERVE_AD , v); -/* -* No need to sync if all uses of the page can be accounted -* to the page lock we hold, its pinned status, and uses on -* this (v)CPU. -*/ -if ( !rc && !cpu_has_no_xpti && - ((page->u.inuse.type_info & PGT_count_mask) > - (1 + !!(page->u.inuse.type_info & PGT_pinned) + - (pagetable_get_pfn (curr->arch.guest_table) == mfn) + - (pagetable_get_pfn (curr->arch.guest_table_user) == - mfn))) ) - sync_guest = true; +if ( !rc && !cpu_has_no_xpti ) + {
xen/arch/x86/mm.c long do_mmu_update( · line 3718
Quoted 10 lines
xen/arch/x86/mm.c +10
-0+bool local_in_use = false; + +if ( (pagetable_get_pfn (curr->arch.guest_table) == + mfn) || + (pagetable_get_pfn (curr->arch.guest_table_user) == + mfn) ) + { + local_in_use = true; +get_cpu_info ()->root_pgt_changed = true; + }
The conditional causes root_pgt_changed to get set even in cases where what CR3 points to doesn't actually change (if it's the user page tables that get modified). I think you want to check curr->arch.cr3 here, or only curr->arch.guest_table (as user mode can't invoke hypercalls).
xen/arch/x86/mm.c long do_mmu_update( · line 3726
Quoted 8 lines
xen/arch/x86/mm.c +8
-0+/* +* No need to sync if all uses of the page can be +* accounted to the page lock we hold, its pinned +* status, and uses on this (v)CPU. +*/ +if ( (page->u.inuse.type_info & PGT_count_mask) > + (1 + !!(page->u.inuse.type_info & PGT_pinned) + + local_in_use) )
The boolean local_in_use evaluates to 1 here, when previously the value could have been 1 or 2 (I agree that's highly theoretical, but anyway). Of course this will be addressed implicitly if you check (only) curr->arch.guest_table above and move the curr->arch.guest_table_user check here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 2/7] x86/xpti: don't flush TLB twice when switching to 64-bit pv context
In reply to Juergen GrossQuoted 31 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
When switching to a 64-bit pv context the TLB is flushed twice today:
the first time when switching to the new address space inwrite_ptbase(), the second time when switching to guest mode inrestore_to_guest.Avoid the first TLB flush in that case.
Signed-off-by Juergen Gross <[email protected]>---
V3:
- omit settingroot_pgt_changedto false (Jan Beulich)--- xen/arch/x86/mm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)xen/arch/x86/mm.c +1
-0@@ -123,6 +123,7 @@#include <asm/io_apic.h> #include <asm/pci.h> #include <asm/guest.h> +#include <asm/processor.h> #include <asm/hvm/grant_table.h> #include <asm/pv/grant_table.h> @@ -507,8 +508,14 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {
xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 518
Quoted 10 lines
xen/arch/x86/mm.c +7
-1if (this_cpu (root_pgt) &&is_pv_vcpu (v) && !is_pv_32bit_vcpu (v) ) + {get_cpu_info ()->root_pgt_changed = true; -write_cr3 (v->arch.cr3); + asmvolatile ("mov %0, %%cr3" : :"r" (v->arch.cr3) :"memory" ); + } +else + { +write_cr3 (v->arch.cr3); + }
Unnecessary braces. with that
(This could be taken care of while committing, but the patch depends on patch 1 anyway, which may see further transformation.)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 3/7] xen/x86: support per-domain flag for xpti
In reply to Juergen Grossxen/arch/x86/pv/domain.c line 78
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
xen/arch/x86/pv/domain.c +4
-0+void xpti_domain_init (struct domain *d) +{ +if ( !is_pv_domain (d) ||is_pv_32bit_domain (d) ) +return ;
As you rely on the zero-initialization of the field here, ...
xen/arch/x86/pv/domain.c line 83
Quoted 4 lines
xen/arch/x86/pv/domain.c +4
-0+switch ( opt_xpti ) + { +case XPTI_OFF : + d->arch.pv_domain.xpti = false;
... this could go away as well.
xen/arch/x86/smpboot.c void __init smp_prepare_cpus(unsigned int max_cpus) · line 1056
Quoted 10 lines
xen/arch/x86/smpboot.c +1
-2@@ -1050,8 +1050,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)panic ("Error %d setting up PV root page table\n" , rc);if (per_cpu (root_pgt,0 ) ) { -get_cpu_info ()->pv_cr3 =__pa (per_cpu (root_pgt,0 )); - +get_cpu_info ()->pv_cr3 =0 ;/* * All entry points which may need to switch page tables have to start * with interrupts off. Re-write what pv_trap_init() has put there.
Please don't drop the blank line.
xen/include/asm-x86/pv/domain.h static inline void pv_vcpu_destroy(struct vcpu *v) {} · line 43
Quoted 8 lines
xen/include/asm-x86/pv/domain.h +2
-1@@ -36,7 +38,8 @@ static inline void pv_vcpu_destroy(struct vcpu *v) {}static inline int pv_vcpu_initialise (struct vcpu *v) {return -EOPNOTSUPP ; }static inline void pv_domain_destroy (struct domain *d) {}static inline int pv_domain_initialise (struct domain *d) {return -EOPNOTSUPP ; } - +static inline void xpti_init (void ) {} +static inline void xpti_domain_init (struct domain *d) {}#endif /* CONFIG_PV */
Same here. With that
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 1/7] x86/xpti: avoid copying L4 page table contents when possible
In reply to a message not in the archiveQuoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
xen/arch/x86/flushtlb.c +0
-0@@ -158,6 +158,9 @@ unsigned int flush_area_local(const void *va, unsigned int flags) } }
Quoted 8 lines
xen/arch/x86/flushtlb.c unsigned int flush_area_local(const void *va, unsigned int flags) · line 166
Quoted 6 lines
xen/arch/x86/flushtlb.c +3
-0+if ( flags &FLUSH_ROOT_PGTBL ) +get_cpu_info ()->root_pgt_changed = true; +local_irq_restore (irqfl);return flags;Does this really need to sit inside the interrupts disabled section?
Hmm, no, I don't think so. I'll move it below local_irq_restore().
Quoted 16 lines
Thinking about it I even wonder whether the cache flush part needs to be. Even for the INVLPG portion of the TLB flush part I can't seem to see a need for IRQs to be off. I think it's really just the
pre_flush()/post_flush()pair which needs to be inside such a section. I'll prepare a patch (for after 4.11). I think some of the changes later in your series will actually further ease this.Quoted 9 lines
xen/arch/x86/mm.c +3
-0@@ -499,10 +499,15 @@ void free_shared_domheap_page(struct page_info *page)void make_cr3 (struct vcpu *v,mfn_t mfn) { v->arch.cr3 =mfn_x (mfn) <<PAGE_SHIFT ; +if ( v == current &&this_cpu (root_pgt) &&is_pv_vcpu (v) && + !is_pv_32bit_vcpu (v) ) +get_cpu_info ()->root_pgt_changed = true;
Quoted 8 lines
xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 505
Quoted 1 line
xen/arch/x86/mm.c +0
-0}As this doesn't actually update CR3, setting the flag shouldn't generally be necessary if the caller then invokes
write_ptbase(). Isn't setting the flag here needed solely in the case of_toggle_guest_pt()being up the call tree? In which case it would perhaps better be set there (and in turn some or even all of the conditional around it could be dropped)?
Yes, you are right.
Quoted 7 lines
xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 511
Quoted 6 lines
xen/arch/x86/mm.c +2
-0void write_ptbase (struct vcpu *v) { +if (this_cpu (root_pgt) &&is_pv_vcpu (v) && !is_pv_32bit_vcpu (v) ) +get_cpu_info ()->root_pgt_changed = true;write_cr3 (v->arch.cr3);
Quoted 10 lines
When you come here from e.g.
__sync_local_execstate(), you don't really need to set the flag. Of course you'll come here again before the next 64-bit PV vCPU will make it torestore_all_guest, so by the time we make it there the flag will be set anyway. However, if you already use such a subtlety, then there's also no point excluding 32-bit vCPU-s here (nor inmake_cr3()), as those will never make it torestore_all_guest. Same then for excluding HVM vCPU-s. And I then wonder whether (here or more likely in a later patch) theroot_pgtcheck couldn't go away as well.
I'm not sure this is worth it. Patch 3 will re-introduce a conditional here and it will look rather different (e.g. without the root_pgt check). So micro-optimizing this patch barely makes any sense.
Quoted 28 lines
Quoted 28 lines
xen/arch/x86/mm.c +11
-12@@ -3698,18 +3703,29 @@ long do_mmu_update(break ; rc =mod_l4_entry (va,l4e_from_intpte (req.val), mfn, cmd ==MMU_PT_UPDATE_PRESERVE_AD , v); -/* -* No need to sync if all uses of the page can be accounted -* to the page lock we hold, its pinned status, and uses on -* this (v)CPU. -*/ -if ( !rc && !cpu_has_no_xpti && - ((page->u.inuse.type_info & PGT_count_mask) > - (1 + !!(page->u.inuse.type_info & PGT_pinned) + - (pagetable_get_pfn (curr->arch.guest_table) == mfn) + - (pagetable_get_pfn (curr->arch.guest_table_user) == - mfn))) ) - sync_guest = true; +if ( !rc && !cpu_has_no_xpti ) + { +bool local_in_use = false; + +if ( (pagetable_get_pfn (curr->arch.guest_table) == + mfn) || + (pagetable_get_pfn (curr->arch.guest_table_user) == + mfn) ) + { + local_in_use = true;
Quoted 8 lines
xen/arch/x86/mm.c long do_mmu_update( · line 3718
Quoted 2 lines
xen/arch/x86/mm.c +2
-0+get_cpu_info ()->root_pgt_changed = true; + }The conditional causes
root_pgt_changedto get set even in cases where what CR3 points to doesn't actually change (if it's the user page tables that get modified). I think you want to checkcurr->arch.cr3here, or onlycurr->arch.guest_table(as user mode can't invoke hypercalls).
I'll go with curr->arch.guest_table.
Quoted 10 lines
xen/arch/x86/mm.c long do_mmu_update( · line 3726
Quoted 9 lines
xen/arch/x86/mm.c +8
-0+/* +* No need to sync if all uses of the page can be +* accounted to the page lock we hold, its pinned +* status, and uses on this (v)CPU. +*/ +if ( (page->u.inuse.type_info & PGT_count_mask) > + (1 + !!(page->u.inuse.type_info & PGT_pinned) + + local_in_use) )
Quoted 5 lines
The boolean
local_in_useevaluates to 1 here, when previously the value could have been 1 or 2 (I agree that's highly theoretical, but anyway). Of course this will be addressed implicitly if you check (only)curr->arch.guest_tableabove and move thecurr->arch.guest_table_usercheck here.
Yes.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 3/7] xen/x86: support per-domain flag for xpti
In reply to a message not in the archiveQuoted 8 lines · Jan Beulich
xen/arch/x86/pv/domain.c line 78
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
xen/arch/x86/pv/domain.c +4
-0+void xpti_domain_init (struct domain *d) +{ +if ( !is_pv_domain (d) ||is_pv_32bit_domain (d) ) +return ;As you rely on the zero-initialization of the field here, ...
Quoted 6 lines
xen/arch/x86/pv/domain.c line 83
Quoted 4 lines
xen/arch/x86/pv/domain.c +4
-0+switch ( opt_xpti ) + { +case XPTI_OFF : + d->arch.pv_domain.xpti = false;... this could go away as well.
I wanted to make the switch statement complete. No problem to drop setting of xpti here of you like that better.
Quoted 13 lines
xen/arch/x86/smpboot.c void __init smp_prepare_cpus(unsigned int max_cpus) · line 1056
Quoted 11 lines
xen/arch/x86/smpboot.c +1
-2@@ -1050,8 +1050,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)panic ("Error %d setting up PV root page table\n" , rc);if (per_cpu (root_pgt,0 ) ) { -get_cpu_info ()->pv_cr3 =__pa (per_cpu (root_pgt,0 )); - +get_cpu_info ()->pv_cr3 =0 ;/* * All entry points which may need to switch page tables have to start * with interrupts off. Re-write what pv_trap_init() has put there. Please don't drop the blank line.
Okay.
Quoted 11 lines
xen/include/asm-x86/pv/domain.h static inline void pv_vcpu_destroy(struct vcpu *v) {} · line 43
Quoted 9 lines
xen/include/asm-x86/pv/domain.h +2
-1@@ -36,7 +38,8 @@ static inline void pv_vcpu_destroy(struct vcpu *v) {}static inline int pv_vcpu_initialise (struct vcpu *v) {return -EOPNOTSUPP ; }static inline void pv_domain_destroy (struct domain *d) {}static inline int pv_domain_initialise (struct domain *d) {return -EOPNOTSUPP ; } - +static inline void xpti_init (void ) {} +static inline void xpti_domain_init (struct domain *d) {}#endif /* CONFIG_PV */ Same here. With that
Quoted 1 line
Reviewed-by Jan Beulich <[email protected]>
Thanks,
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 4/7] xen/x86: use invpcid for flushing the TLB
In reply to Juergen GrossQuoted 4 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
docs/misc/xen-command-line.markdown Because responsibility for APIC setup is shared between Xen and the · line 1389
Quoted 10 lines
docs/misc/xen-command-line.markdown +7
-0@@ -1380,6 +1380,14 @@ Because responsibility for APIC setup is shared between Xen and the domain 0 kernel this option is automatically propagated to the domain 0 command line. +### noinvpcid (x86) +> `= <boolean>` + +Disable using the INVPCID instruction for flushing TLB entries. +This should only be used in case of known issues on the current platform +with that instruction. Disabling INVPCID will normally result in a slightly +degraded performance.
At the first glance this looks as if it wants to be a cpuid= sub-option. However, that would disable use by both Xen and (HVM) guests. Andrew, what are your plans here as to distinguishing the "Xen uses a feature" from the "disable use of a feature altogether"?
If we stay with a separate option, then please make this a normal boolean one (i.e. drop the "no" prefix), as "no-noinvpcid" is rather ugly.
docs/misc/xen-command-line.markdown static void generic_set_all(void) · line 477
Quoted 8 lines
docs/misc/xen-command-line.markdown +0
-1@@ -457,7 +472,6 @@ static void generic_set_all(void) set_bit(count, &smp_changes_mask); mask >>= 1; } - } static void generic_set_mtrr(unsigned int reg, unsigned long base,
I don't mind this line being dropped, but in general please avoid stray changes which aren't assimilated into changes you do anyway.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 1/7] x86/xpti: avoid copying L4 page table contents when possible
In reply to Juergen GrossQuoted 20 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 16:26, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 511
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
void
write_ptbase(struct vcpu *v)
{xen/arch/x86/mm.c +2
-0+if (this_cpu (root_pgt) &&is_pv_vcpu (v) && !is_pv_32bit_vcpu (v) ) +get_cpu_info ()->root_pgt_changed = true;write_cr3 (v->arch.cr3);Quoted 10 lines
When you come here from e.g.
__sync_local_execstate(), you don't really need to set the flag. Of course you'll come here again before the next 64-bit PV vCPU will make it torestore_all_guest, so by the time we make it there the flag will be set anyway. However, if you already use such a subtlety, then there's also no point excluding 32-bit vCPU-s here (nor inmake_cr3()), as those will never make it torestore_all_guest. Same then for excluding HVM vCPU-s. And I then wonder whether (here or more likely in a later patch) theroot_pgtcheck couldn't go away as well.
Quoted 3 lines
I'm not sure this is worth it. Patch 3 will re-introduce a conditional here and it will look rather different (e.g. without the
root_pgtcheck). So micro-optimizing this patch barely makes any sense.
Yes, I've seen that once I made it there. Perhaps worth dropping the two is_*() checks here, but not worry about the root_pgt one.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 3/7] xen/x86: support per-domain flag for xpti
In reply to Juergen GrossQuoted 15 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 16:29, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
xen/arch/x86/pv/domain.c line 78
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
xen/arch/x86/pv/domain.c +4
-0+void xpti_domain_init (struct domain *d) +{ +if ( !is_pv_domain (d) ||is_pv_32bit_domain (d) ) +return ;As you rely on the zero-initialization of the field here, ...
Quoted 4 lines
xen/arch/x86/pv/domain.c +4
-0+switch ( opt_xpti ) + { +case XPTI_OFF : + d->arch.pv_domain.xpti = false;
Quoted 4 lines
Quoted 1 line
... this could go away as well.
I wanted to make the switch statement complete. No problem to drop setting of xpti here of you like that better.
FAOD I didn't mean dropping the entire case block.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to Juergen GrossQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g. lstar_enter through switch_to_kernel to restore_all_guest without ever switching to the full page Xen tables?
xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 10 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;
I'm not overly happy to see any new uses of mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otoh pv_guest_cr4_to_real_cr4() does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't be read_cr4() | X86_CR4_PGE, not the least because we've just got rid of the blanket reversion to mmu_cr4_features in VMX code.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 4/7] xen/x86: use invpcid for flushing the TLB
In reply to a message not in the archiveQuoted 21 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
docs/misc/xen-command-line.markdown Because responsibility for APIC setup is shared between Xen and the · line 1389
Quoted 10 lines
docs/misc/xen-command-line.markdown +7
-0@@ -1380,6 +1380,14 @@ Because responsibility for APIC setup is shared between Xen and the domain 0 kernel this option is automatically propagated to the domain 0 command line. +### noinvpcid (x86) +> `= <boolean>` + +Disable using the INVPCID instruction for flushing TLB entries. +This should only be used in case of known issues on the current platform +with that instruction. Disabling INVPCID will normally result in a slightly +degraded performance.At the first glance this looks as if it wants to be a cpuid= sub-option. However, that would disable use by both Xen and (HVM) guests. Andrew, what are your plans here as to distinguishing the "Xen uses a feature" from the "disable use of a feature altogether"?
Quoted 3 lines
If we stay with a separate option, then please make this a normal boolean one (i.e. drop the "no" prefix), as "no-noinvpcid" is rather ugly.
Okay.
Quoted 8 lines
Quoted 8 lines
docs/misc/xen-command-line.markdown +0
-1@@ -457,7 +472,6 @@ static void generic_set_all(void) set_bit(count, &smp_changes_mask); mask >>= 1; } - }
Quoted 4 lines
docs/misc/xen-command-line.markdown static void generic_set_all(void) · line 477
Quoted 1 line
docs/misc/xen-command-line.markdown +0
-0static void generic_set_mtrr(unsigned int reg, unsigned long base,I don't mind this line being dropped, but in general please avoid stray changes which aren't assimilated into changes you do anyway.
The main reason I did drop this line was the trailing tab. I just took the risk of someone complaining.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 3/7] xen/x86: support per-domain flag for xpti
In reply to a message not in the archiveQuoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 16:29, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
xen/arch/x86/pv/domain.c line 78
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
xen/arch/x86/pv/domain.c +4
-0+void xpti_domain_init (struct domain *d) +{ +if ( !is_pv_domain (d) ||is_pv_32bit_domain (d) ) +return ;As you rely on the zero-initialization of the field here, ...
Quoted 4 lines
xen/arch/x86/pv/domain.c +4
-0+switch ( opt_xpti ) + { +case XPTI_OFF : + d->arch.pv_domain.xpti = false;
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
... this could go away as well.
I wanted to make the switch statement complete. No problem to drop setting of xpti here of you like that better.
FAOD I didn't mean dropping the entire case block.
Of course not. This would just be wrong with the current default block.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to a message not in the archiveQuoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
Quoted 6 lines
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?
With patch 7 of this series in mind I'm not convinced the extra effort is really making sense. Today most processors do have PCID support so for that old hardware I don't think we need to make the handling even more complex.
Quoted 12 lines
xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 11 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;
Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.
I do understand that using mmu_cr4_features isn't the best way to set cr4. But I think it is a good idea to have a default value which should normally be used instead of only switching various bits on and off.
In case cr4 is loaded with a strange value in some corner case that value might be used from then on instead of being repaired by loading a dedicated value at certain points in time, e.g. when doing a context switch.
So maybe we should introduce cr4_default which is derived from mmu_cr4_features? mmu_cr4_features would contain all bits which are allowed on the current processor with the current command line options, while cr4_default would be a subset of mmu_cr4_features.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to a message not in the archiveQuoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 19:18, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?
Quoted 8 lines
Quoted 4 lines
With patch 7 of this series in mind I'm not convinced the extra effort is really making sense. Today most processors do have PCID support so for that old hardware I don't think we need to make the handling even more complex.
PCID yes, but INVPCID (and we're talking about Intel hardware here only anyway)? But yes, the extra complexity is what has kept me so far from investing time here.
As PCID seems to speed up XPTI only and XPTI is necessary for INTEL cpus only I don't see a problem here. :-)
Quoted 29 lines
Quoted 20 lines
Quoted 12 lines
xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 11 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.Quoted 8 lines
I do understand that using
mmu_cr4_featuresisn't the best way to set cr4. But I think it is a good idea to have a default value which should normally be used instead of only switching various bits on and off.In case cr4 is loaded with a strange value in some corner case that value might be used from then on instead of being repaired by loading a dedicated value at certain points in time, e.g. when doing a context switch.
Quoted 5 lines
But that would make it even more difficult to notice and debug a possible problem. The more we play with CR4 bits, the more important it is that we keep an accurate record of what is currently loaded into it, and that we have a clear understanding of what we mean to be loaded into the register at any given point in time.
What about adding an appropriate ASSERT() for that case?
So I would use read_cr4() | X86_CR4_PGE and ASSERT() that cr4 matches the default value.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to Juergen GrossQuoted 16 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 19:18, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
Quoted 6 lines
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?
Quoted 4 lines
With patch 7 of this series in mind I'm not convinced the extra effort is really making sense. Today most processors do have PCID support so for that old hardware I don't think we need to make the handling even more complex.
PCID yes, but INVPCID (and we're talking about Intel hardware here only anyway)? But yes, the extra complexity is what has kept me so far from investing time here.
Quoted 19 lines
Quoted 11 lines
xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 10 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.
Quoted 8 lines
I do understand that using
mmu_cr4_featuresisn't the best way to set cr4. But I think it is a good idea to have a default value which should normally be used instead of only switching various bits on and off.In case cr4 is loaded with a strange value in some corner case that value might be used from then on instead of being repaired by loading a dedicated value at certain points in time, e.g. when doing a context switch.
But that would make it even more difficult to notice and debug a possible problem. The more we play with CR4 bits, the more important it is that we keep an accurate record of what is currently loaded into it, and that we have a clear understanding of what we mean to be loaded into the register at any given point in time.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to a message not in the archiveQuoted 27 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 08:58, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 19:18, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
Quoted 6 lines
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?Quoted 4 lines
With patch 7 of this series in mind I'm not convinced the extra effort is really making sense. Today most processors do have PCID support so for that old hardware I don't think we need to make the handling even more complex.
PCID yes, but INVPCID (and we're talking about Intel hardware here only anyway)? But yes, the extra complexity is what has kept me so far from investing time here.
Quoted 7 lines
Quoted 2 lines
As PCID seems to speed up XPTI only and XPTI is necessary for INTEL cpus only I don't see a problem here. :-)
Well, yes as far as AMD is unaffected, but not entirely yes to the rest, as I intentionally pointed out the difference of availability of PCID (which even Westmere's have) and INVPCID (which only my Haswell has).
Haswells are out for nearly 5 years now.
I think in case we want to do something else here we should delay that to 4.12. Even without PCID this patch is speeding up XPTI handling significantly (parallel hypervisor compilation: elapsed time -6%, system time -12%), so I'm not making anything worse.
BTW: while Westmere is supporting PCID I remember having done some PCID testing with Westmere not showing any performance gains at all.
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 20 lines
Quoted 12 lines
xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 11 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.Quoted 8 lines
I do understand that using
mmu_cr4_featuresisn't the best way to set cr4. But I think it is a good idea to have a default value which should normally be used instead of only switching various bits on and off.In case cr4 is loaded with a strange value in some corner case that value might be used from then on instead of being repaired by loading a dedicated value at certain points in time, e.g. when doing a context switch.
But that would make it even more difficult to notice and debug a possible problem. The more we play with CR4 bits, the more important it is that we keep an accurate record of what is currently loaded into it, and that we have a clear understanding of what we mean to be loaded into the register at any given point in time.
Quoted 7 lines
Quoted 4 lines
What about adding an appropriate
ASSERT()for that case?So I would use
read_cr4()|X86_CR4_PGEandASSERT()that cr4 matches the default value.That's an option; later we may want to sprinkle around a few more such assertions.
Okay, I'll go that route then. Do you want me to use a new default_cr4 variable for doing the assertion (and as initial cr4 value for secondary cpus), or are you fine with using mmu_cr4_features for now?
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to Juergen GrossQuoted 23 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 08:58, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 19:18, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
Quoted 6 lines
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?With patch 7 of this series in mind I'm not convinced the extra effort is really making sense. Today most processors do have PCID support so for that old hardware I don't think we need to make the handling even more complex.
Quoted 6 lines
Quoted 3 lines
PCID yes, but INVPCID (and we're talking about Intel hardware here only anyway)? But yes, the extra complexity is what has kept me so far from investing time here.
As PCID seems to speed up XPTI only and XPTI is necessary for INTEL cpus only I don't see a problem here. :-)
Well, yes as far as AMD is unaffected, but not entirely yes to the rest, as I intentionally pointed out the difference of availability of PCID (which even Westmere's have) and INVPCID (which only my Haswell has).
Quoted 34 lines
Quoted 28 lines
Quoted 19 lines
Quoted 11 lines
xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 10 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.Quoted 8 lines
I do understand that using
mmu_cr4_featuresisn't the best way to set cr4. But I think it is a good idea to have a default value which should normally be used instead of only switching various bits on and off.In case cr4 is loaded with a strange value in some corner case that value might be used from then on instead of being repaired by loading a dedicated value at certain points in time, e.g. when doing a context switch.
Quoted 5 lines
But that would make it even more difficult to notice and debug a possible problem. The more we play with CR4 bits, the more important it is that we keep an accurate record of what is currently loaded into it, and that we have a clear understanding of what we mean to be loaded into the register at any given point in time.
Quoted 4 lines
What about adding an appropriate
ASSERT()for that case?So I would use
read_cr4()|X86_CR4_PGEandASSERT()that cr4 matches the default value.
That's an option; later we may want to sprinkle around a few more such assertions.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to Juergen GrossQuoted 46 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 09:29, <[email protected]> wrote:
Quoted 44 lines · Jan Beulich
Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 08:58, <[email protected]> wrote:
Quoted 31 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 19:18, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.Quoted 8 lines
I do understand that using
mmu_cr4_featuresisn't the best way to set cr4. But I think it is a good idea to have a default value which should normally be used instead of only switching various bits on and off.In case cr4 is loaded with a strange value in some corner case that value might be used from then on instead of being repaired by loading a dedicated value at certain points in time, e.g. when doing a context switch.
Quoted 5 lines
But that would make it even more difficult to notice and debug a possible problem. The more we play with CR4 bits, the more important it is that we keep an accurate record of what is currently loaded into it, and that we have a clear understanding of what we mean to be loaded into the register at any given point in time.
What about adding an appropriate
ASSERT()for that case?So I would use
read_cr4()|X86_CR4_PGEandASSERT()that cr4 matches the default value.
Quoted 6 lines
Quoted 2 lines
That's an option; later we may want to sprinkle around a few more such assertions.
Okay, I'll go that route then. Do you want me to use a new
default_cr4variable for doing the assertion (and as initial cr4 value for secondary cpus), or are you fine with usingmmu_cr4_featuresfor now?
I'd prefer if we could get away without yet another variable holding some variant of possible CR4 values. As a follow-up we'll then want to switch pv_guest_cr4_to_real_cr4() away from using mmu_cr4_features as well (except for a possible assertion to put there).
And btw, please consider re-organizing your change to pv_guest_cr4_to_real_cr4() to match what we do for X86_CR4_TSD, rather than first ORing in X86_CR4_PGE in order to then (conditionally) mask it back out.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 6/7] xen/x86: use flag byte for decision whether xen_cr3 is valid
In reply to Juergen GrossQuoted 10 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Today
cpu_info->xen_cr3is either 0 to indicate %cr3 doesn't need to be switched on entry to Xen, or negative for keeping the value while indicating not to restore %cr3, or positive in case %cr3 is to be restored.Switch to use a flag byte instead of a negative
xen_cr3value in order to allow %cr3 values with the high bit set in case we want to keep TLB entries when using the PCID feature.
Quoted 5 lines
This reduces the number of branches in interrupt handling and results in better performance (e.g. parallel make of the Xen hypervisor on my system was using about 3% less system time).
Signed-off-by Juergen Gross <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
In reply to Juergen GrossQuoted 11 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Avoid flushing the complete TLB when switching %cr3 for mitigation of Meltdown by using the PCID feature if available.
We are using 4 PCID values for a 64 bit pv domain subject to XPTI and 2 values for the non-XPTI case:
- guest active and in kernel mode
- guest active and in user mode
- hypervisor active and guest in user mode (XPTI only)
- hypervisor active and guest in kernel mode (XPTI only)
Before committing to this route, Jun, Kevin, can we please get confirmation that PCID isn't (and isn't going to be) subject to the same speculation issues in the pipeline that the U/S bit is (having caused Meltdown in the first place)? To me it seems a pretty likely thing to play all the same games.
Quoted 6 lines
--- docs/misc/xen-command-line.markdown | 12 +++++++++ xen/arch/x86/debug.c | 3 ++- xen/arch/x86/domain_page.c | 2 +- xen/arch/x86/domctl.c | 4 +++ xen/arch/x86/flushtlb.c | 49 ++++++++++++++++++++++++++++------
Quoted 8 lines
xen/arch/x86/mm.c | 34 +++++++++++++++++++++--- xen/arch/x86/pv/dom0_build.c | 1 + xen/arch/x86/pv/domain.c | 52 +++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/domain.h | 14 +++++++--- xen/include/asm-x86/pv/domain.h | 2 ++ xen/include/asm-x86/x86-defns.h | 1 + 11 files changed, 158 insertions(+), 16 deletions(-)
Having had the discussion previously, I'm missing a change to smp.c:new_tlbflush_clock_period() here.
xen/arch/x86/debug.c dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val) · line 101
Quoted 9 lines
xen/arch/x86/debug.c +2
-1@@ -97,7 +97,8 @@ dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val)l3_pgentry_t l3e, *l3t;l2_pgentry_t l2e, *l2t;l1_pgentry_t l1e, *l1t; -unsigned long cr3 = (pgd3val ? pgd3val : dp->vcpu[0 ]->arch.cr3); +unsigned long cr3 = (pgd3val ? pgd3val + : (dp->vcpu[0 ]->arch.cr3 & ~X86_CR3_NOFLUSH ));
What about the PCID portion? You want the address of the page here, so I think you should use a "white-listing" masking operation instead of a blacklisting one.
Also, as you touch this anyway, it would have been nice to drop the unnecessary middle argument at the same time.
Quoted 9 lines
xen/arch/x86/flushtlb.c +3
-0@@ -102,7 +102,19 @@ void write_cr3_cr4(unsigned long cr3, unsigned long cr4) t =pre_flush ();if (read_cr4 () &X86_CR4_PGE ) +/* +* X86_CR4_PGE set means PCID being inactive. +* We have to purge the TLB via flipping cr4.pge.
xen/arch/x86/flushtlb.c void write_cr3_cr4(unsigned long cr3, unsigned long cr4) · line 117
Quoted 10 lines
xen/arch/x86/flushtlb.c +9
-0+*/ write_cr4 (cr4 & ~X86_CR4_PGE ); + else if ( cpu_has_invpcid ) + /* + * If we are using PCID purge the TLB via INVPCID as loading cr3 + * will affect the current PCID only. + * If INVPCID is not supported we don't use PCIDs so loading cr3 + * will purge the TLB (we are in the "global pages off" branch). + */ + invpcid_flush_all();
Since with CR4.PGE correctness-wise clear it doesn't matter whether you use invpcid_flush_all() or invpcid_flush_all_nonglobals() here, does it also not matter performance-wise?
xen/arch/x86/flushtlb.c unsigned int flush_area_local(const void *va, unsigned int flags) · line 139
Quoted 10 lines
xen/arch/x86/flushtlb.c +0
-6@@ -131,14 +143,35 @@ unsigned int flush_area_local(const void *va, unsigned int flags) {if ( order ==0 ) { -/* -* We don't INVLPG multi-page regions because the 2M/4M/1G -* region may not have been mapped with a superpage. Also there -* are various errata surrounding INVLPG usage on superpages, and -* a full flush is in any case not *that* expensive. -*/
This comment really explains the order == 0 check above, so I don't think it should be moved.
xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 504
Quoted 11 lines
xen/arch/x86/mm.c +5
-0@@ -497,12 +497,38 @@ void free_shared_domheap_page(struct page_info *page)free_domheap_page (page); } +/* +* Return additional PCID specific cr3 bits. +* +* Note that X86_CR3_NOFLUSH will not be readable in cr3. Anyone consuming +* v->arch.cr3 should mask away X86_CR3_NOFLUSH and X86_CR3_PCIDMASK in case
I stand to my previous comment, which was left unanswered afaics:
"Is it a good idea to suppress the flush this way for every reader
of v->arch.cr3? For example, what about the use in dbg_pv_va2mfn()? I think it should be the consumers of the field to decide whether to OR in that flag (which isn't part of the register value anyway)."
To be more precise, I can see the pcid to be put here (which will require consumers to be aware anyway), but I don't think the non- register-value no-flush indicator belongs here. IOW I think after writing the value into %cr3, the value read back should match the stored value.
Quoted 16 lines
xen/arch/x86/mm.c +10
-3+* the value is used to address the root page table. +*/ +static unsigned long get_pcid_bits (struct vcpu *v,bool is_xen) +{ +return X86_CR3_NOFLUSH | (is_xen ?PCID_PV_XEN :0 ) | + ((v->arch.flags & TF_kernel_mode) ?PCID_PV_PRIV :PCID_PV_USER ); +} +void make_cr3 (struct vcpu *v,mfn_t mfn) { +struct domain *d = v->domain; + v->arch.cr3 =mfn_x (mfn) <<PAGE_SHIFT ; -if ( v == current &&this_cpu (root_pgt) &&is_pv_vcpu (v) && - !is_pv_32bit_vcpu (v) ) -get_cpu_info ()->root_pgt_changed = true;
xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 527
Quoted 10 lines
xen/arch/x86/mm.c +10
-0+if (is_pv_domain (d) ) + { +if ( d->arch.pv_domain.xpti && v == current ) + { +struct cpu_info *cpu_info =get_cpu_info (); + + cpu_info->root_pgt_changed = true; +if ( d->arch.pv_domain.pcid ) + cpu_info->pv_cr3 =__pa (this_cpu (root_pgt)) | +get_pcid_bits (v, false);
Just like we seem to have agreed (on an earlier patch) that setting root_pgt_changed elsewhere may be better, perhaps that extends to pv_cr3 as well? It would certainly be nice if this was written with the final intended value right away, yet the lack of an "else" here suggests there is at least one place where this doesn't happen, but pv_cr3 is also written with a non-zero value.
xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 530
Quoted 3 lines
xen/arch/x86/mm.c +3
-0+ } +if ( d->arch.pv_domain.pcid ) + v->arch.cr3 |=get_pcid_bits (v, d->arch.pv_domain.xpti);
It is certainly at least confusing that you pass "xpti" as argument for a parameter named "is_xen". The question is what mode you want us to be in when running with PCID but no XPTI: Should Xen use its own PCID then? That would seem reasonable to me, but would seem to require passing true here. Yet then this would require switching CR3 on the way out to guests and back in from guests even in that case (just without copying the root page table).
If in that mode Xen isn't meant to use its own PCID, the command line option "pcid=noxpti" would seem at least misleading to me then, as you wouldn't really use different PCIDs in that mode, but only disable global pages (which probably hurts performance) and use INVPCID for flushing (which probably helps performance).
Quoted 15 lines
xen/arch/x86/pv/domain.c +9
-0@@ -95,6 +95,58 @@ void xpti_domain_init(struct domain *d) } } +static __read_mostly enum { +PCID_OFF , +PCID_ALL , +PCID_XPTI , +PCID_NOXPTI +} opt_pcid =PCID_XPTI ; + +static __init int parse_pcid (const char *s) +{
xen/arch/x86/pv/domain.c void xpti_domain_init(struct domain *d) · line 116
Quoted 10 lines
xen/arch/x86/pv/domain.c +10
-0+int rc =0 ; + +if ( !strcmp (s,"off" ) ) + opt_pcid =PCID_OFF ; +else if ( !strcmp (s,"all" ) ) + opt_pcid =PCID_ALL ; +else if ( !strcmp (s,"xpti" ) ) + opt_pcid =PCID_XPTI ; +else if ( !strcmp (s,"noxpti" ) ) + opt_pcid =PCID_NOXPTI ;
I'd prefer if you used parse_bool() and parse_boolean() here, so that the syntax of this new option fits with all other boolean ones we have.
xen/arch/x86/pv/domain.c void xpti_domain_init(struct domain *d) · line 133
Quoted 10 lines
xen/arch/x86/pv/domain.c +10
-0+void pcid_domain_init (struct domain *d) +{ +if ( !is_pv_domain (d) ||is_pv_32bit_domain (d) || + !cpu_has_invpcid || !cpu_has_pcid ) +return ; + +switch ( opt_pcid ) + { +case PCID_OFF : + d->arch.pv_domain.pcid = false;
As for the earlier patch, with the return above implying the value to be zero this store ought to be unnecessary.
xen/arch/x86/pv/domain.c unsigned long pv_guest_cr4_fixup(const struct vcpu *, unsigned long guest_cr4); · line 629
Quoted 7 lines
xen/arch/x86/pv/domain.c +1
-2@@ -619,14 +626,15 @@ unsigned long pv_guest_cr4_fixup(const struct vcpu *, unsigned long guest_cr4); | (mmu_cr4_features \ & (X86_CR4_PGE |X86_CR4_PSE |X86_CR4_SMEP | \X86_CR4_SMAP |X86_CR4_OSXSAVE | \ -X86_CR4_FSGSBASE )) \ - | ((v)->domain->arch.vtsc ? X86_CR4_TSD : 0)) \ +X86_CR4_FSGSBASE |X86_CR4_PCIDE )) \
Why? Afaics you never set the bit in mmu_cr4_features.
xen/include/asm-x86/x86-defns.h line 49
Quoted 7 lines
xen/include/asm-x86/x86-defns.h +1
-0@@ -46,6 +46,7 @@* Intel CPU flags in CR3 */ #define X86_CR3_NOFLUSH (_AC(1, ULL) << 63) +#define X86_CR3_PCIDMASK _AC(0x0fff, ULL)/* Mask for PCID */
As per an earlier comment you also want X86_CR3_ADDR_MASK here (and as an implication from the suggested name I think it would be better if you also added another underscore in the one you already add).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
In reply to a message not in the archiveQuoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Avoid flushing the complete TLB when switching %cr3 for mitigation of Meltdown by using the PCID feature if available.
We are using 4 PCID values for a 64 bit pv domain subject to XPTI and 2 values for the non-XPTI case:
- guest active and in kernel mode
- guest active and in user mode
- hypervisor active and guest in user mode (XPTI only)
- hypervisor active and guest in kernel mode (XPTI only)
Quoted 5 lines
Before committing to this route, Jun, Kevin, can we please get confirmation that PCID isn't (and isn't going to be) subject to the same speculation issues in the pipeline that the U/S bit is (having caused Meltdown in the first place)? To me it seems a pretty likely thing to play all the same games.
Really? This would assume either the processor is capable to deal with multiple matching TLB entries when speculating or that there can be only one entry per virtual address present in the TLB at the same time in spite of different PCIDs.
And why aren't you asking for the same problem with VPIDs? This should be comparable to the PCID problem you are suspecting.
Quoted 16 lines
Quoted 15 lines
--- docs/misc/xen-command-line.markdown | 12 +++++++++ xen/arch/x86/debug.c | 3 ++- xen/arch/x86/domain_page.c | 2 +- xen/arch/x86/domctl.c | 4 +++ xen/arch/x86/flushtlb.c | 49 ++++++++++++++++++++++++++++------ xen/arch/x86/mm.c | 34 +++++++++++++++++++++--- xen/arch/x86/pv/dom0_build.c | 1 + xen/arch/x86/pv/domain.c | 52 +++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/domain.h | 14 +++++++--- xen/include/asm-x86/pv/domain.h | 2 ++ xen/include/asm-x86/x86-defns.h | 1 + 11 files changed, 158 insertions(+), 16 deletions(-)
Quoted 2 lines
Having had the discussion previously, I'm missing a change to smp.c:new_tlbflush_clock_period() here.
I can add that. I did not do this as I haven't treated FLUSH_TLB differently to FLUSH_TLB_GLOBAL (trying this even without any other change to staging led to degfaults in dom0). So such a change to new_tlbflush_clock_period() should be a separate patch I believe.
Quoted 14 lines
xen/arch/x86/debug.c dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val) · line 101
Quoted 10 lines
xen/arch/x86/debug.c +2
-1@@ -97,7 +97,8 @@ dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val)l3_pgentry_t l3e, *l3t;l2_pgentry_t l2e, *l2t;l1_pgentry_t l1e, *l1t; -unsigned long cr3 = (pgd3val ? pgd3val : dp->vcpu[0 ]->arch.cr3); +unsigned long cr3 = (pgd3val ? pgd3val + : (dp->vcpu[0 ]->arch.cr3 & ~X86_CR3_NOFLUSH ));What about the PCID portion? You want the address of the page here, so I think you should use a "white-listing" masking operation instead of a blacklisting one.
The PCID portion is no problem here as the value is converted into a mfn.
I can do the modification you are asking for, of course.
Quoted 3 lines
Also, as you touch this anyway, it would have been nice to drop the unnecessary middle argument at the same time.
Okay.
Quoted 16 lines
Quoted 16 lines
xen/arch/x86/flushtlb.c +8
-0@@ -102,7 +102,19 @@ void write_cr3_cr4(unsigned long cr3, unsigned long cr4) t =pre_flush ();if (read_cr4 () &X86_CR4_PGE ) +/* +* X86_CR4_PGE set means PCID being inactive. +* We have to purge the TLB via flipping cr4.pge. +*/ write_cr4 (cr4 & ~X86_CR4_PGE ); +else if ( cpu_has_invpcid ) +/* +* If we are using PCID purge the TLB via INVPCID as loading cr3 +* will affect the current PCID only.
Quoted 8 lines
xen/arch/x86/flushtlb.c void write_cr3_cr4(unsigned long cr3, unsigned long cr4) · line 117
Quoted 4 lines
xen/arch/x86/flushtlb.c +4
-0+* If INVPCID is not supported we don't use PCIDs so loading cr3 +* will purge the TLB (we are in the "global pages off" branch). +*/ +invpcid_flush_all ();Since with CR4.PGE correctness-wise clear it doesn't matter whether you use
invpcid_flush_all()orinvpcid_flush_all_nonglobals()here, does it also not matter performance-wise?
I didn't check that. I'll have a try.
Quoted 14 lines
xen/arch/x86/flushtlb.c unsigned int flush_area_local(const void *va, unsigned int flags) · line 139
Quoted 11 lines
xen/arch/x86/flushtlb.c +0
-6@@ -131,14 +143,35 @@ unsigned int flush_area_local(const void *va, unsigned int flags) {if ( order ==0 ) { -/* -* We don't INVLPG multi-page regions because the 2M/4M/1G -* region may not have been mapped with a superpage. Also there -* are various errata surrounding INVLPG usage on superpages, and -* a full flush is in any case not *that* expensive. -*/ This comment really explains the order == 0 check above, so I don't think it should be moved.
Okay.
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/mm.c +0
-0@@ -497,12 +497,38 @@ void free_shared_domheap_page(struct page_info *page)free_domheap_page (page); }
Quoted 7 lines
xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 504
Quoted 5 lines
xen/arch/x86/mm.c +5
-0+/* +* Return additional PCID specific cr3 bits. +* +* Note that X86_CR3_NOFLUSH will not be readable in cr3. Anyone consuming +* v->arch.cr3 should mask away X86_CR3_NOFLUSH and X86_CR3_PCIDMASK in case I stand to my previous comment, which was left unanswered afaics:
Uuh, sorry for that.
Quoted 10 lines
"Is it a good idea to suppress the flush this way for every reader
ofv->arch.cr3? For example, what about the use indbg_pv_va2mfn()? I think it should be the consumers of the field to decide whether to OR in that flag (which isn't part of the register value anyway)."
To be more precise, I can see the pcid to be put here (which will require consumers to be aware anyway), but I don't think the non- register-value no-flush indicator belongs here. IOW I think after writing the value into %cr3, the value read back should match the stored value.
This will make restore_all_guest more complicated. v->arch.cr3 is copied to cpu_info->xen_cr3 there and this value is then used for %cr3. I really don't want to add complex logic there to add the no-flush indicator in case PCIDs are active.
Quoted 27 lines
Quoted 16 lines
xen/arch/x86/mm.c +10
-3+* the value is used to address the root page table. +*/ +static unsigned long get_pcid_bits (struct vcpu *v,bool is_xen) +{ +return X86_CR3_NOFLUSH | (is_xen ?PCID_PV_XEN :0 ) | + ((v->arch.flags & TF_kernel_mode) ?PCID_PV_PRIV :PCID_PV_USER ); +} +void make_cr3 (struct vcpu *v,mfn_t mfn) { +struct domain *d = v->domain; + v->arch.cr3 =mfn_x (mfn) <<PAGE_SHIFT ; -if ( v == current &&this_cpu (root_pgt) &&is_pv_vcpu (v) && - !is_pv_32bit_vcpu (v) ) -get_cpu_info ()->root_pgt_changed = true;xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 527
Quoted 10 lines
xen/arch/x86/mm.c +10
-0+if (is_pv_domain (d) ) + { +if ( d->arch.pv_domain.xpti && v == current ) + { +struct cpu_info *cpu_info =get_cpu_info (); + + cpu_info->root_pgt_changed = true; +if ( d->arch.pv_domain.pcid ) + cpu_info->pv_cr3 =__pa (this_cpu (root_pgt)) | +get_pcid_bits (v, false);
Quoted 7 lines
Just like we seem to have agreed (on an earlier patch) that setting
root_pgt_changedelsewhere may be better, perhaps that extends topv_cr3as well? It would certainly be nice if this was written with the final intended value right away, yet the lack of an "else" here suggests there is at least one place where this doesn't happen, butpv_cr3is also written with a non-zero value.
Yes. I'll look into moving it to _toggle_guest_pt().
Quoted 13 lines
xen/arch/x86/mm.c void free_shared_domheap_page(struct page_info *page) · line 530
Quoted 4 lines
xen/arch/x86/mm.c +3
-0+ } +if ( d->arch.pv_domain.pcid ) + v->arch.cr3 |=get_pcid_bits (v, d->arch.pv_domain.xpti);It is certainly at least confusing that you pass "xpti" as argument for a parameter named "
is_xen". The question is what mode you want us to be in when running with PCID but no XPTI: Should Xen use its own PCID then? That would seem reasonable to me, but would seem to require passing true here. Yet then this would require switching CR3 on the way out to guests and back in from guests even in that case (just without copying the root page table).
Quoted 5 lines
If in that mode Xen isn't meant to use its own PCID, the command line option "pcid=noxpti" would seem at least misleading to me then, as you wouldn't really use different PCIDs in that mode, but only disable global pages (which probably hurts performance) and use INVPCID for flushing (which probably helps performance).
The idea is to use different PCID values for guest kernel and user mode. This removes the need for global guest user pages. I don't want to use global guest user pages together with PCID as flushing global pages from the TLB with PCID enabled requires flushing either the complete TLB or you'd have to use INVLPG in all possible address spaces (so you'd need to have multiple %cr3 switches).
I'll add some comments in this regard.
Quoted 22 lines
Quoted 22 lines
xen/arch/x86/pv/domain.c +15
-0@@ -95,6 +95,58 @@ void xpti_domain_init(struct domain *d) } } +static __read_mostly enum { +PCID_OFF , +PCID_ALL , +PCID_XPTI , +PCID_NOXPTI +} opt_pcid =PCID_XPTI ; + +static __init int parse_pcid (const char *s) +{ +int rc =0 ; + +if ( !strcmp (s,"off" ) ) + opt_pcid =PCID_OFF ; +else if ( !strcmp (s,"all" ) ) + opt_pcid =PCID_ALL ;
Quoted 8 lines
xen/arch/x86/pv/domain.c void xpti_domain_init(struct domain *d) · line 116
Quoted 4 lines
xen/arch/x86/pv/domain.c +4
-0+else if ( !strcmp (s,"xpti" ) ) + opt_pcid =PCID_XPTI ; +else if ( !strcmp (s,"noxpti" ) ) + opt_pcid =PCID_NOXPTI ;I'd prefer if you used
parse_bool()andparse_boolean()here, so that the syntax of this new option fits with all other boolean ones we have.
Okay.
Quoted 14 lines
xen/arch/x86/pv/domain.c void xpti_domain_init(struct domain *d) · line 133
Quoted 11 lines
xen/arch/x86/pv/domain.c +10
-0+void pcid_domain_init (struct domain *d) +{ +if ( !is_pv_domain (d) ||is_pv_32bit_domain (d) || + !cpu_has_invpcid || !cpu_has_pcid ) +return ; + +switch ( opt_pcid ) + { +case PCID_OFF : + d->arch.pv_domain.pcid = false;As for the earlier patch, with the return above implying the value to be zero this store ought to be unnecessary.
Okay.
Quoted 10 lines
xen/arch/x86/pv/domain.c unsigned long pv_guest_cr4_fixup(const struct vcpu *, unsigned long guest_cr4); · line 629
Quoted 8 lines
xen/arch/x86/pv/domain.c +1
-2@@ -619,14 +626,15 @@ unsigned long pv_guest_cr4_fixup(const struct vcpu *, unsigned long guest_cr4); | (mmu_cr4_features \ & (X86_CR4_PGE |X86_CR4_PSE |X86_CR4_SMEP | \X86_CR4_SMAP |X86_CR4_OSXSAVE | \ -X86_CR4_FSGSBASE )) \ - | ((v)->domain->arch.vtsc ? X86_CR4_TSD : 0)) \ +X86_CR4_FSGSBASE |X86_CR4_PCIDE )) \Why? Afaics you never set the bit in
mmu_cr4_features.
Oops, this is a leftover from v2.
Quoted 13 lines
xen/include/asm-x86/x86-defns.h line 49
Quoted 8 lines
xen/include/asm-x86/x86-defns.h +1
-0@@ -46,6 +46,7 @@* Intel CPU flags in CR3 */ #define X86_CR3_NOFLUSH (_AC(1, ULL) << 63) +#define X86_CR3_PCIDMASK _AC(0x0fff, ULL)/* Mask for PCID */ As per an earlier comment you also want
X86_CR3_ADDR_MASKhere (and as an implication from the suggested name I think it would be better if you also added another underscore in the one you already add).
Yes.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 2/7] x86/xpti: don't flush TLB twice when switching to 64-bit pv context
In reply to Jan BeulichQuoted 43 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
When switching to a 64-bit pv context the TLB is flushed twice today:
the first time when switching to the new address space inwrite_ptbase(), the second time when switching to guest mode inrestore_to_guest.Avoid the first TLB flush in that case.
Signed-off-by Juergen Gross <[email protected]>---
V3:
- omit settingroot_pgt_changedto false (Jan Beulich)--- xen/arch/x86/mm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)xen/arch/x86/mm.c +1
-0@@ -123,6 +123,7 @@#include <asm/io_apic.h> #include <asm/pci.h> #include <asm/guest.h> +#include <asm/processor.h> #include <asm/hvm/grant_table.h> #include <asm/pv/grant_table.h> @@ -507,8 +508,14 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 518
Quoted 10 lines
xen/arch/x86/mm.c +7
-1if (this_cpu (root_pgt) &&is_pv_vcpu (v) && !is_pv_32bit_vcpu (v) ) + {get_cpu_info ()->root_pgt_changed = true; -write_cr3 (v->arch.cr3); + asmvolatile ("mov %0, %%cr3" : :"r" (v->arch.cr3) :"memory" ); + } +else + { +write_cr3 (v->arch.cr3); + }Unnecessary braces. with that
Quoted 4 lines
Reviewed-by Jan Beulich <[email protected]>(This could be taken care of while committing, but the patch depends on patch 1 anyway, which may see further transformation.)
Just realized it now: I have to re-introduce the conditionals I removed on your behalf from patch 1, as otherwise I'd omit TLB flushing via write_cr3() for 32-bit pv-domains and HVM-domains.
Therefor I'm removing your R-b in case you don't like that (patch 3 changes the conditional again, so I don't think that is really bad).
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
In reply to Juergen GrossQuoted 20 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 12:29, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Avoid flushing the complete TLB when switching %cr3 for mitigation of Meltdown by using the PCID feature if available.
We are using 4 PCID values for a 64 bit pv domain subject to XPTI and 2 values for the non-XPTI case:
- guest active and in kernel mode
- guest active and in user mode
- hypervisor active and guest in user mode (XPTI only)
- hypervisor active and guest in kernel mode (XPTI only)Quoted 5 lines
Before committing to this route, Jun, Kevin, can we please get confirmation that PCID isn't (and isn't going to be) subject to the same speculation issues in the pipeline that the U/S bit is (having caused Meltdown in the first place)? To me it seems a pretty likely thing to play all the same games.
Quoted 4 lines
Really? This would assume either the processor is capable to deal with multiple matching TLB entries when speculating or that there can be only one entry per virtual address present in the TLB at the same time in spite of different PCIDs.
Hmm, yes, good point.
Quoted 2 lines
And why aren't you asking for the same problem with VPIDs? This should be comparable to the PCID problem you are suspecting.
Since Linux is using the approach, I'm not really suspecting a problem. I'd just like to be sure there is none / not going to be one. None of this is spelled out in the doc after all.
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
--- docs/misc/xen-command-line.markdown | 12 +++++++++ xen/arch/x86/debug.c | 3 ++- xen/arch/x86/domain_page.c | 2 +- xen/arch/x86/domctl.c | 4 +++ xen/arch/x86/flushtlb.c | 49 ++++++++++++++++++++++++++++------ xen/arch/x86/mm.c | 34 +++++++++++++++++++++--- xen/arch/x86/pv/dom0_build.c | 1 + xen/arch/x86/pv/domain.c | 52 +++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/domain.h | 14 +++++++--- xen/include/asm-x86/pv/domain.h | 2 ++ xen/include/asm-x86/x86-defns.h | 1 + 11 files changed, 158 insertions(+), 16 deletions(-)
Quoted 7 lines
Quoted 2 lines
Having had the discussion previously, I'm missing a change to smp.c:new_tlbflush_clock_period() here.
I can add that. I did not do this as I haven't treated
FLUSH_TLBdifferently toFLUSH_TLB_GLOBAL(trying this even without any other change to staging led to degfaults in dom0). So such a change tonew_tlbflush_clock_period()should be a separate patch I believe.
Ah yes, you don't have the "flushing too much" issue anymore in this version, or at least not in as obvious a way. Or wait - it's in patch 4. You still do an including-global flush there regardless of whether FLUSH_TLB_GLOBAL was actually requested. Anyway, we'll save this aspect for later.
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/debug.c +0
-0@@ -97,7 +97,8 @@ dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val)l3_pgentry_t l3e, *l3t;l2_pgentry_t l2e, *l2t;Quoted 8 lines
xen/arch/x86/debug.c dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val) · line 101
Quoted 4 lines
xen/arch/x86/debug.c +2
-1l1_pgentry_t l1e, *l1t; -unsigned long cr3 = (pgd3val ? pgd3val : dp->vcpu[0 ]->arch.cr3); +unsigned long cr3 = (pgd3val ? pgd3val + : (dp->vcpu[0 ]->arch.cr3 & ~X86_CR3_NOFLUSH ));What about the PCID portion? You want the address of the page here, so I think you should use a "white-listing" masking operation instead of a blacklisting one.
Quoted 4 lines
The PCID portion is no problem here as the value is converted into a mfn.
I can do the modification you are asking for, of course.
Well, even if the bits are shifter out in the end, the code could look more correct. Plus by masking to just the address, future new meaning assigned to currently unused bits would not be a problem for this piece of code anymore.
Quoted 21 lines
Quoted 7 lines
xen/arch/x86/debug.c dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val)
Quoted 5 lines
xen/arch/x86/debug.c +5
-0+/* +* Return additional PCID specific cr3 bits. +* +* Note that X86_CR3_NOFLUSH will not be readable in cr3. Anyone consuming +* v->arch.cr3 should mask away X86_CR3_NOFLUSH and X86_CR3_PCIDMASK in case I stand to my previous comment, which was left unanswered afaics:
Uuh, sorry for that.
Quoted 10 lines
"Is it a good idea to suppress the flush this way for every reader
ofv->arch.cr3? For example, what about the use indbg_pv_va2mfn()? I think it should be the consumers of the field to decide whether to OR in that flag (which isn't part of the register value anyway)."
To be more precise, I can see the pcid to be put here (which will require consumers to be aware anyway), but I don't think the non- register-value no-flush indicator belongs here. IOW I think after writing the value into %cr3, the value read back should match the stored value.
Quoted 4 lines
This will make
restore_all_guestmore complicated.v->arch.cr3is copied tocpu_info->xen_cr3there and this value is then used for %cr3. I really don't want to add complex logic there to add the no-flush indicator in case PCIDs are active.
Valid point. Looking at all present uses of ->arch.cr3, it's probably indeed better the way you have it. However, I'm now wondering about something else: make_cr3() leaves PCID as zero for HVM and idle domains, but runs Xen with PCIDs 2 and 3 for (some) PV domains. That looks like an undesirable setup though - it would seem better to run Xen (with full page tables) with PCID 0 at all times.
Then we'd have e.g.
PCID 0 Xen (full page tables)
PCID x PV guest priv
PCID y PV guest user
Global pages in PCID 0 could then still be permitted, and wouldn't ever need flushing except when FLUSH_TLB_GLOBAL is requested.
As to the use of two separate PCIDs for PV kernel and user modes
- while this helps isolation, it prevents recovering the non-XPTI property of user mode TLB entries surviving in-guest mode switches. I wonder whether this is part of the reason you see PCID have a negative effect in the non-XPTI case.
So in the end the question is: Why not use just two PCIDs, and allow global pages just like we do now, with the added benefit that we no longer need to flush Xen's global TLB entries just because we want to get rid of PV guest user ones.
Quoted 12 lines
Quoted 12 lines
xen/arch/x86/debug.c
Quoted 3 lines
xen/arch/x86/debug.c +3
-0+ } +if ( d->arch.pv_domain.pcid ) + v->arch.cr3 |=get_pcid_bits (v, d->arch.pv_domain.xpti);It is certainly at least confusing that you pass "xpti" as argument for a parameter named "
is_xen". The question is what mode you want us to be in when running with PCID but no XPTI: Should Xen use its own PCID then? That would seem reasonable to me, but would seem to require passing true here. Yet then this would require switching CR3 on the way out to guests and back in from guests even in that case (just without copying the root page table).
Quoted 8 lines
Quoted 5 lines
If in that mode Xen isn't meant to use its own PCID, the command line option "pcid=noxpti" would seem at least misleading to me then, as you wouldn't really use different PCIDs in that mode, but only disable global pages (which probably hurts performance) and use INVPCID for flushing (which probably helps performance).
The idea is to use different PCID values for guest kernel and user mode. This removes the need for global guest user pages.
Partly only. Global guest user pages serve two purposes: They survive a round trip user -> kernel -> user (as long as no Xen context switch occurs in the middle), and they also allow the kernel to utilize TLB entries user mode has just created e.g. for system call input. Your current use of PCIDs retains only the first property.
Quoted 5 lines
I don't
want to use global guest user pages together with PCID as flushing global pages from the TLB with PCID enabled requires flushing either the complete TLB or you'd have to use INVLPG in all possible address spaces (so you'd need to have multiple %cr3 switches).
Well, yes, flushing _individual_ pages is a problem in that case. As to multiple CR3 switches - are these all that bad really with the no-flush bit set? With the reduced number of PCIDs in actual use (as discussed above) "all possible address spaces" would mean just two. And I could imagine that in a number of cases just one INVLPG (with the right PCID active) might suffice.
One complicating factor is that we don't want to introduce Xen TLB entries for other than what we map in the minimal page tables into PV guest PCID space, which would happen if we simply switched PCID around an INVLPG.
What I don't understand in any event is why you need separate PCIDs for Xen depending on whether the active PV guest is in kernel or user mode.
As a side note, I've noticed only now that get_pcid_bits()'s first parameter wants to be constified.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines · Juergen Gross
On my machine (Intel i7-4600M) using the PCID feature in the non-XPTI case showed a slightly worse performance than using global pages instead (using PCID and global pages is a bad idea as invalidating global pages in this case would need a complete TLB flush). For this reason I've decided to use PCID for XPTI only as the default. That can easily be changed by using the command line parameter "pcid=all".
Quoted 9 lines
XPTI off Jan, XPTI on +this series, XPTI on real 1m21.169s 1m52.149s (+38%) 1m25.692s (+6%) user 2m47.652s 2m50.054s (+1%) 2m46.428s (-1%) sys 1m11.949s 2m21.767s (+97%) 1m23.053s (+15%)A git branch of that series (+ Jan's patches) is available:
As usual, I've run a few benchmarks. Long story short, this series mitigates the performance hit of XPTI, in pretty much all the cases. In a couple of cases, even significantly so (~10%).
The improvement is not as good as in the above numbers, even for similar workloads (compile ones), but I guess that depends on the hardware. But anyway, things do improve, and I think we should have the series in 4.11.
I can also confirm that using PCID with XPTI=no, does not bring much of an improvement, if any at all.
There's the weird case of STREAM, where using PCID makes things go significantly worse, not only than no-PCID and xpti=no, but also than PCID and xpri=true.
Basically, when using PCID, xpti boosts STREAM performance, which is a little weird. I'll try to manually re-run the benchmark in a couple of configurations, and let's see what I will find.
Here's the results. Basically:
- if you want to compare xpti=on, with and without this series, look at 'Jan, XPTI on' (without) and '+this series, XPTI on' (with);
- if you want to compare, with this series, xpti on and off, look at 'XPTI off' (off) and '+this series, XPTI on' (on);
- if you want to compare xpti=off, with and without PCID, look at 'XPTI off' (without) and '+this series, XPTI off, PCID all' (with).
https://openbenchmarking.org/result/1803232-DARI-180323589
Also available here:
AIO-Stress 0.21
Test: Random Write
MB/s > Higher Is Better
XPTI off .......................... 1783.11 |===================================================================================================================================================
+this series, XPTI on ............. 1967.75 |==================================================================================================================================================================
+this series, XPTI off, PCID all .. 1827.43 |======================================================================================================================================================
Jan, XPTI on ...................... 1866.80 |==========================================================================================================================================================Stream 2013-01-17
Type: Copy
MB/s > Higher Is Better
XPTI off .......................... 19442.54 |=================================================================================================================================================================
+this series, XPTI on ............. 18939.40 |=============================================================================================================================================================
+this series, XPTI off, PCID all .. 15478.48 |================================================================================================================================
Jan, XPTI on ...................... 15638.96 |==================================================================================================================================Stream 2013-01-17
Type: Scale
MB/s > Higher Is Better
XPTI off .......................... 12978.74 |=================================================================================================================================================================
+this series, XPTI on ............. 12851.56 |===============================================================================================================================================================
+this series, XPTI off, PCID all .. 10699.02 |=====================================================================================================================================
Jan, XPTI on ...................... 10778.84 |======================================================================================================================================Stream 2013-01-17
Type: Triad
MB/s > Higher Is Better
XPTI off .......................... 14280.68 |=================================================================================================================================================================
+this series, XPTI on ............. 14022.30 |==============================================================================================================================================================
+this series, XPTI off, PCID all .. 12149.18 |=========================================================================================================================================
Jan, XPTI on ...................... 12218.22 |==========================================================================================================================================Stream 2013-01-17
Type: Add
MB/s > Higher Is Better
XPTI off .......................... 16093.28 |=================================================================================================================================================================
+this series, XPTI on ............. 15815.04 |==============================================================================================================================================================
+this series, XPTI off, PCID all .. 12077.40 |=========================================================================================================================
Jan, XPTI on ...................... 12269.30 |===========================================================================================================================t-test1 2017-01-13
Threads: 1
Seconds < Lower Is Better
XPTI off .......................... 76.16 |===============================================================================================
+this series, XPTI on ............. 113.93 |=============================================================================================================================================
+this series, XPTI off, PCID all .. 74.68 |=============================================================================================
Jan, XPTI on ...................... 131.26 |===================================================================================================================================================================t-test1 2017-01-13
Threads: 2
Seconds < Lower Is Better
XPTI off .......................... 24.28 |====================================================================================================
+this series, XPTI on ............. 34.91 |================================================================================================================================================
+this series, XPTI off, PCID all .. 23.92 |===================================================================================================
Jan, XPTI on ...................... 39.73 |====================================================================================================================================================================Timed Linux Kernel Compilation 4.13
Time To Compile
Seconds < Lower Is Better
XPTI off .......................... 155.35 |==============================================================================================================================================
+this series, XPTI on ............. 170.36 |===========================================================================================================================================================
+this series, XPTI off, PCID all .. 155.81 |==============================================================================================================================================
Jan, XPTI on ...................... 178.89 |===================================================================================================================================================================Timed MPlayer Compilation 1.0-rc3
Time To Compile
Seconds < Lower Is Better
XPTI off .......................... 45.94 |=======================================================================================================================================================
+this series, XPTI on ............. 48.85 |================================================================================================================================================================
+this series, XPTI off, PCID all .. 45.95 |=======================================================================================================================================================
Jan, XPTI on ...................... 49.97 |====================================================================================================================================================================Timed PHP Compilation 7.1.9
Time To Compile
Seconds < Lower Is Better
XPTI off .......................... 119.18 |================================================================================================================================================
+this series, XPTI on ............. 129.24 |============================================================================================================================================================
+this series, XPTI off, PCID all .. 120.29 |=================================================================================================================================================
Jan, XPTI on ...................... 134.76 |===================================================================================================================================================================Parallel BZIP2 Compression 1.1.12
256MB File Compression
Seconds < Lower Is Better
XPTI off .......................... 8.97 |===========================================================================================================================================================
+this series, XPTI on ............. 8.43 |==================================================================================================================================================
+this series, XPTI off, PCID all .. 9.00 |===========================================================================================================================================================
Jan, XPTI on ...................... 9.55 |=====================================================================================================================================================================Hackbench
Count: 1 - Type: Process
Seconds < Lower Is Better
XPTI off .......................... 11.11 |=====================================================================================================
+this series, XPTI on ............. 16.62 |=======================================================================================================================================================
+this series, XPTI off, PCID all .. 11.05 |====================================================================================================
Jan, XPTI on ...................... 18.11 |====================================================================================================================================================================Hackbench
Count: 4 - Type: Process
Seconds < Lower Is Better
XPTI off .......................... 37.82 |===============================================================================================
+this series, XPTI on ............. 59.66 |=====================================================================================================================================================
+this series, XPTI off, PCID all .. 37.58 |==============================================================================================
Jan, XPTI on ...................... 65.47 |====================================================================================================================================================================Hackbench
Count: 16 - Type: Process
Seconds < Lower Is Better
XPTI off .......................... 142.24 |==========================================================================================
+this series, XPTI on ............. 232.55 |===================================================================================================================================================
+this series, XPTI off, PCID all .. 141.58 |==========================================================================================
Jan, XPTI on ...................... 257.20 |===================================================================================================================================================================Redis 4.0.8
Test: LPOP
Requests Per Second > Higher Is Better
XPTI off .......................... 402887.81 |================================================================================================================================================================
+this series, XPTI on ............. 146349.66 |==========================================================
+this series, XPTI off, PCID all .. 341182.95 |=======================================================================================================================================
Jan, XPTI on ...................... 128094.76 |===================================================Redis 4.0.8
Test: SADD
Requests Per Second > Higher Is Better
XPTI off .......................... 378952.25 |================================================================================================================================================================
+this series, XPTI on ............. 165097.91 |======================================================================
+this series, XPTI off, PCID all .. 371460.27 |=============================================================================================================================================================
Jan, XPTI on ...................... 141056.13 |============================================================Redis 4.0.8
Test: LPUSH
Requests Per Second > Higher Is Better
XPTI off .......................... 327837.31 |=============================================================================================================================================================
+this series, XPTI on ............. 146894.11 |=======================================================================
+this series, XPTI off, PCID all .. 333126.30 |================================================================================================================================================================
Jan, XPTI on ...................... 126966.19 |=============================================================Redis 4.0.8
Test: GET
Requests Per Second > Higher Is Better
XPTI off .......................... 397632.29 |================================================================================================================================================================
+this series, XPTI on ............. 169390.22 |====================================================================
+this series, XPTI off, PCID all .. 393664.83 |==============================================================================================================================================================
Jan, XPTI on ...................... 143045.55 |==========================================================Redis 4.0.8
Test: SET
Requests Per Second > Higher Is Better
XPTI off .......................... 352699.10 |================================================================================================================================================================
+this series, XPTI on ............. 153986.24 |======================================================================
+this series, XPTI off, PCID all .. 350564.06 |===============================================================================================================================================================
Jan, XPTI on ...................... 133726.65 |=============================================================Stress-NG 0.07.26
Test: Crypto
Bogo Ops/s > Higher Is Better
XPTI off .......................... 689.86 |===================================================================================================================================================================
+this series, XPTI on ............. 688.27 |===================================================================================================================================================================
+this series, XPTI off, PCID all .. 689.49 |===================================================================================================================================================================
Jan, XPTI on ...................... 688.75 |===================================================================================================================================================================Stress-NG 0.07.26
Test: Bsearch
Bogo Ops/s > Higher Is Better
XPTI off .......................... 3939.99 |==================================================================================================================================================================
+this series, XPTI on ............. 3936.73 |==================================================================================================================================================================
+this series, XPTI off, PCID all .. 3936.85 |==================================================================================================================================================================
Jan, XPTI on ...................... 3930.97 |==================================================================================================================================================================Stress-NG 0.07.26
Test: Forking
Bogo Ops/s > Higher Is Better
XPTI off .......................... 6056.42 |=================================================================================================================================================================
+this series, XPTI on ............. 5222.55 |===========================================================================================================================================
+this series, XPTI off, PCID all .. 6107.00 |==================================================================================================================================================================
Jan, XPTI on ...................... 4515.24 |========================================================================================================================Stress-NG 0.07.26
Test: Hsearch
Bogo Ops/s > Higher Is Better
XPTI off .......................... 26376.03 |=================================================================================================================================================================
+this series, XPTI on ............. 26278.84 |================================================================================================================================================================
+this series, XPTI off, PCID all .. 26391.88 |=================================================================================================================================================================
Jan, XPTI on ...................... 26258.08 |================================================================================================================================================================Stress-NG 0.07.26
Test: Lsearch
Bogo Ops/s > Higher Is Better
XPTI off .......................... 60.27 |====================================================================================================================================================================
+this series, XPTI on ............. 60.26 |====================================================================================================================================================================
+this series, XPTI off, PCID all .. 60.27 |====================================================================================================================================================================
Jan, XPTI on ...................... 60.27 |====================================================================================================================================================================Stress-NG 0.07.26
Test: Tsearch
Bogo Ops/s > Higher Is Better
XPTI off .......................... 124.15 |==================================================================================================================================================================
+this series, XPTI on ............. 124.12 |==================================================================================================================================================================
+this series, XPTI off, PCID all .. 125.04 |===================================================================================================================================================================
Jan, XPTI on ...................... 124.75 |===================================================================================================================================================================Stress-NG 0.07.26
Test: CPU Stress
Bogo Ops/s > Higher Is Better
XPTI off .......................... 1709.34 |============================================================================================================================================================
+this series, XPTI on ............. 1751.09 |================================================================================================================================================================
+this series, XPTI off, PCID all .. 1746.89 |================================================================================================================================================================
Jan, XPTI on ...................... 1772.44 |==================================================================================================================================================================Stress-NG 0.07.26
Test: Semaphores
Bogo Ops/s > Higher Is Better
XPTI off .......................... 2208236.65 |============================================================================================================================================================
+this series, XPTI on ............. 2044183.40 |================================================================================================================================================
+this series, XPTI off, PCID all .. 2252052.71 |===============================================================================================================================================================
Jan, XPTI on ...................... 2092475.64 |====================================================================================================================================================Stress-NG 0.07.26
Test: Matrix Math
Bogo Ops/s > Higher Is Better
XPTI off .......................... 20279.06 |=================================================================================================================================================================
+this series, XPTI on ............. 20261.14 |=================================================================================================================================================================
+this series, XPTI off, PCID all .. 20287.40 |=================================================================================================================================================================
Jan, XPTI on ...................... 20264.35 |=================================================================================================================================================================Stress-NG 0.07.26
Test: Vector Math
Bogo Ops/s > Higher Is Better
XPTI off .......................... 10506.60 |=================================================================================================================================================================
+this series, XPTI on ............. 10500.10 |=================================================================================================================================================================
+this series, XPTI off, PCID all .. 10509.78 |=================================================================================================================================================================
Jan, XPTI on ...................... 10493.20 |=================================================================================================================================================================Stress-NG 0.07.26
Test: Memory Copying
Bogo Ops/s > Higher Is Better
XPTI off .......................... 1051.84 |==================================================================================================================================================================
+this series, XPTI on ............. 1012.27 |============================================================================================================================================================
+this series, XPTI off, PCID all .. 983.86 |========================================================================================================================================================
Jan, XPTI on ...................... 992.60 |=========================================================================================================================================================Stress-NG 0.07.26
Test: Socket Activity
Bogo Ops/s > Higher Is Better
XPTI off .......................... 1587.44 |=================================================================================================================================================================
+this series, XPTI on ............. 1087.62 |==============================================================================================================
+this series, XPTI off, PCID all .. 1594.80 |==================================================================================================================================================================
Jan, XPTI on ...................... 922.89 |==============================================================================================Stress-NG 0.07.26
Test: Context Switching
Bogo Ops/s > Higher Is Better
XPTI off .......................... 696817.28 |================================================================================================================================================================
+this series, XPTI on ............. 343513.18 |===============================================================================
+this series, XPTI off, PCID all .. 657917.78 |=======================================================================================================================================================
Jan, XPTI on ...................... 280122.99 |================================================================Stress-NG 0.07.26
Test: Glibc C String Functions
Bogo Ops/s > Higher Is Better
XPTI off .......................... 268516.17 |=============================================================================================================================================================
+this series, XPTI on ............. 269261.27 |=============================================================================================================================================================
+this series, XPTI off, PCID all .. 273643.72 |================================================================================================================================================================
Jan, XPTI on ...................... 266052.71 |============================================================================================================================================================Stress-NG 0.07.26
Test: Glibc Qsort Data Sorting
Bogo Ops/s > Higher Is Better
XPTI off .......................... 57.80 |====================================================================================================================================================================
+this series, XPTI on ............. 56.66 |=================================================================================================================================================================
+this series, XPTI off, PCID all .. 57.77 |====================================================================================================================================================================
Jan, XPTI on ...................... 56.88 |=================================================================================================================================================================Stress-NG 0.07.26
Test: System V Message Passing
Bogo Ops/s > Higher Is Better
XPTI off .......................... 3645928.49 |===============================================================================================================================================================
+this series, XPTI on ............. 1743511.46 |============================================================================
+this series, XPTI off, PCID all .. 3573098.79 |============================================================================================================================================================
Jan, XPTI on ...................... 1596148.22 |======================================================================PyBench 2018-02-16
Total For Average Test Times
Milliseconds < Lower Is Better
XPTI off .......................... 3007 |=====================================================================================================================================================================
+this series, XPTI on ............. 3000 |=====================================================================================================================================================================
+this series, XPTI off, PCID all .. 2995 |====================================================================================================================================================================
Jan, XPTI on ...................... 3000 |=====================================================================================================================================================================NGINX Benchmark 1.9.9
Static Web Page Serving
Requests Per Second > Higher Is Better
XPTI off .......................... 15930.51 |=================================================================================================================================================================
+this series, XPTI on ............. 11537.88 |=====================================================================================================================
+this series, XPTI off, PCID all .. 15915.73 |=================================================================================================================================================================
Jan, XPTI on ...................... 10454.68 |==========================================================================================================PHPBench 0.8.1
PHP Benchmark Suite
Score > Higher Is Better
XPTI off .......................... 279331 |==================================================================================================================================================================
+this series, XPTI on ............. 253206 |===================================================================================================================================================
+this series, XPTI off, PCID all .. 280877 |===================================================================================================================================================================
Jan, XPTI on ...................... 247288 |================================================================================================================================================Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Software Engineer @ SUSE https://www.suse.com/
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
In reply to a message not in the archiveQuoted 121 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 12:29, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Avoid flushing the complete TLB when switching %cr3 for mitigation of Meltdown by using the PCID feature if available.
We are using 4 PCID values for a 64 bit pv domain subject to XPTI and 2 values for the non-XPTI case:
- guest active and in kernel mode
- guest active and in user mode
- hypervisor active and guest in user mode (XPTI only)
- hypervisor active and guest in kernel mode (XPTI only)Quoted 5 lines
Before committing to this route, Jun, Kevin, can we please get confirmation that PCID isn't (and isn't going to be) subject to the same speculation issues in the pipeline that the U/S bit is (having caused Meltdown in the first place)? To me it seems a pretty likely thing to play all the same games.
Quoted 4 lines
Really? This would assume either the processor is capable to deal with multiple matching TLB entries when speculating or that there can be only one entry per virtual address present in the TLB at the same time in spite of different PCIDs.
Hmm, yes, good point.
Quoted 2 lines
And why aren't you asking for the same problem with VPIDs? This should be comparable to the PCID problem you are suspecting.
Since Linux is using the approach, I'm not really suspecting a problem. I'd just like to be sure there is none / not going to be one. None of this is spelled out in the doc after all.
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
--- docs/misc/xen-command-line.markdown | 12 +++++++++ xen/arch/x86/debug.c | 3 ++- xen/arch/x86/domain_page.c | 2 +- xen/arch/x86/domctl.c | 4 +++ xen/arch/x86/flushtlb.c | 49 ++++++++++++++++++++++++++++------ xen/arch/x86/mm.c | 34 +++++++++++++++++++++--- xen/arch/x86/pv/dom0_build.c | 1 + xen/arch/x86/pv/domain.c | 52 +++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/domain.h | 14 +++++++--- xen/include/asm-x86/pv/domain.h | 2 ++ xen/include/asm-x86/x86-defns.h | 1 + 11 files changed, 158 insertions(+), 16 deletions(-)Quoted 7 lines
Quoted 2 lines
Having had the discussion previously, I'm missing a change to smp.c:new_tlbflush_clock_period() here.
I can add that. I did not do this as I haven't treated
FLUSH_TLBdifferently toFLUSH_TLB_GLOBAL(trying this even without any other change to staging led to degfaults in dom0). So such a change tonew_tlbflush_clock_period()should be a separate patch I believe.Ah yes, you don't have the "flushing too much" issue anymore in this version, or at least not in as obvious a way. Or wait - it's in patch 4. You still do an including-global flush there regardless of whether
FLUSH_TLB_GLOBALwas actually requested. Anyway, we'll save this aspect for later.Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/debug.c +0
-0@@ -97,7 +97,8 @@ dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val)l3_pgentry_t l3e, *l3t;l2_pgentry_t l2e, *l2t;Quoted 8 lines
xen/arch/x86/debug.c dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val) · line 101
Quoted 4 lines
xen/arch/x86/debug.c +2
-1l1_pgentry_t l1e, *l1t; -unsigned long cr3 = (pgd3val ? pgd3val : dp->vcpu[0 ]->arch.cr3); +unsigned long cr3 = (pgd3val ? pgd3val + : (dp->vcpu[0 ]->arch.cr3 & ~X86_CR3_NOFLUSH ));What about the PCID portion? You want the address of the page here, so I think you should use a "white-listing" masking operation instead of a blacklisting one.
Quoted 4 lines
The PCID portion is no problem here as the value is converted into a mfn.
I can do the modification you are asking for, of course.
Well, even if the bits are shifter out in the end, the code could look more correct. Plus by masking to just the address, future new meaning assigned to currently unused bits would not be a problem for this piece of code anymore.
Quoted 21 lines
Quoted 7 lines
xen/arch/x86/debug.c dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val)
Quoted 5 lines
xen/arch/x86/debug.c +5
-0+/* +* Return additional PCID specific cr3 bits. +* +* Note that X86_CR3_NOFLUSH will not be readable in cr3. Anyone consuming +* v->arch.cr3 should mask away X86_CR3_NOFLUSH and X86_CR3_PCIDMASK in case I stand to my previous comment, which was left unanswered afaics:
Uuh, sorry for that.
Quoted 10 lines
"Is it a good idea to suppress the flush this way for every reader
ofv->arch.cr3? For example, what about the use indbg_pv_va2mfn()? I think it should be the consumers of the field to decide whether to OR in that flag (which isn't part of the register value anyway)."
To be more precise, I can see the pcid to be put here (which will require consumers to be aware anyway), but I don't think the non- register-value no-flush indicator belongs here. IOW I think after writing the value into %cr3, the value read back should match the stored value.Quoted 4 lines
This will make
restore_all_guestmore complicated.v->arch.cr3is copied tocpu_info->xen_cr3there and this value is then used for %cr3. I really don't want to add complex logic there to add the no-flush indicator in case PCIDs are active.Valid point. Looking at all present uses of ->arch.cr3, it's probably indeed better the way you have it. However, I'm now wondering about something else:
make_cr3()leaves PCID as zero for HVM and idle domains, but runs Xen with PCIDs 2 and 3 for (some) PV domains. That looks like an undesirable setup though - it would seem better to run Xen (with full page tables) with PCID 0 at all times.
Quoted 4 lines
Then we'd have e.g.
PCID 0 Xen (full page tables)
PCID x PV guest priv
PCID y PV guest user
So this would need another way to switch between guest and xen %cr3. Or would you want to use different %cr3 values with the same PCID without flushing the TLB in between? This seems to be a way to ask for problems...
In case you'd use the same %cr3 (guest kernel one, I guess) for both
cases: are you really sure there is no problem in any hypervisor path accessing guest data which would result in using guest kernel access rights when coming from user mode (BTW: that was the security note I had in v2 of my series).
Quoted 6 lines
Global pages in PCID 0 could then still be permitted, and wouldn't ever need flushing except when
FLUSH_TLB_GLOBALis requested.As to the use of two separate PCIDs for PV kernel and user modes
- while this helps isolation, it prevents recovering the non-XPTI property of user mode TLB entries surviving in-guest mode switches.
I don't get that. With PCID the guest's kernel _and_ user entries will survive in-guest mode switches as there is no TLB flushing involved (the no-flush bit is set in v->arch.cr3 for both modes).
The only downside are guest kernel accesses to user pages: they will need additional TLB entries as the PCID is different.
Quoted 7 lines
I wonder whether this is part of the reason you see PCID have a negative effect in the non-XPTI case.
So in the end the question is: Why not use just two PCIDs, and allow global pages just like we do now, with the added benefit that we no longer need to flush Xen's global TLB entries just because we want to get rid of PV guest user ones.
I can't see how that would work without either needing some more TLB flushes in order to prevent stale TLB entries or loosing the Meltdown mitigation.
Which %cr3/PCID combination should be used in hypervisor, guest kernel and guest user mode? Which pages would be global?
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
xen/arch/x86/debug.c
Quoted 4 lines
xen/arch/x86/debug.c +3
-0+ } +if ( d->arch.pv_domain.pcid ) + v->arch.cr3 |=get_pcid_bits (v, d->arch.pv_domain.xpti);It is certainly at least confusing that you pass "xpti" as argument for a parameter named "
is_xen". The question is what mode you want us to be in when running with PCID but no XPTI: Should Xen use its own PCID then? That would seem reasonable to me, but would seem to require passing true here. Yet then this would require switching CR3 on the way out to guests and back in from guests even in that case (just without copying the root page table).Quoted 8 lines
Quoted 5 lines
If in that mode Xen isn't meant to use its own PCID, the command line option "pcid=noxpti" would seem at least misleading to me then, as you wouldn't really use different PCIDs in that mode, but only disable global pages (which probably hurts performance) and use INVPCID for flushing (which probably helps performance).
The idea is to use different PCID values for guest kernel and user mode. This removes the need for global guest user pages.
Quoted 6 lines
Partly only. Global guest user pages serve two purposes: They survive a round trip user -> kernel -> user (as long as no Xen context switch occurs in the middle), and they also allow the kernel to utilize TLB entries user mode has just created e.g. for system call input. Your current use of PCIDs retains only the first property.
Right.
Quoted 14 lines
Quoted 6 lines
I don't
want to use global guest user pages together with PCID as flushing global pages from the TLB with PCID enabled requires flushing either the complete TLB or you'd have to use INVLPG in all possible address spaces (so you'd need to have multiple %cr3 switches).Well, yes, flushing _individual_ pages is a problem in that case. As to multiple CR3 switches - are these all that bad really with the no-flush bit set? With the reduced number of PCIDs in actual use (as discussed above) "all possible address spaces" would mean just two. And I could imagine that in a number of cases just one INVLPG (with the right PCID active) might suffice.
Quoted 8 lines
One complicating factor is that we don't want to introduce Xen TLB entries for other than what we map in the minimal page tables into PV guest PCID space, which would happen if we simply switched PCID around an INVLPG.
What I don't understand in any event is why you need separate PCIDs for Xen depending on whether the active PV guest is in kernel or user mode.
Main reason are the different page tables anchored in %cr3.
Quoted 2 lines
As a side note, I've noticed only now that get_pcid_bits()'s first parameter wants to be constified.
Will change that.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 15:11, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Valid point. Looking at all present uses of ->arch.cr3, it's probably indeed better the way you have it. However, I'm now wondering about something else:
make_cr3()leaves PCID as zero for HVM and idle domains, but runs Xen with PCIDs 2 and 3 for (some) PV domains. That looks like an undesirable setup though - it would seem better to run Xen (with full page tables) with PCID 0 at all times.Quoted 4 lines
Then we'd have e.g.
PCID 0 Xen (full page tables)
PCID x PV guest priv
PCID y PV guest user
Quoted 4 lines
So this would need another way to switch between guest and xen %cr3. Or would you want to use different %cr3 values with the same PCID without flushing the TLB in between? This seems to be a way to ask for problems...
Well, a TLB flush is clearly needed in such a setup when going from kernel to user mode.
Quoted 5 lines
In case you'd use the same %cr3 (guest kernel one, I guess) for both
cases: are you really sure there is no problem in any hypervisor path accessing guest data which would result in using guest kernel access rights when coming from user mode (BTW: that was the security note I had in v2 of my series).
I'm afraid I don't understand: Same %cr3? There are separate kernel and user page tables, requiring different values anyway. I also don't understand what problems in hypervisor code paths you suspect, when everything looks to work fine right now without PCID.
Quoted 7 lines
Quoted 6 lines
Global pages in PCID 0 could then still be permitted, and wouldn't ever need flushing except when
FLUSH_TLB_GLOBALis requested.As to the use of two separate PCIDs for PV kernel and user modes
- while this helps isolation, it prevents recovering the non-XPTI property of user mode TLB entries surviving in-guest mode switches.
Quoted 6 lines
I don't get that. With PCID the guest's kernel _and_ user entries will survive in-guest mode switches as there is no TLB flushing involved (the no-flush bit is set in
v->arch.cr3for both modes).The only downside are guest kernel accesses to user pages: they will need additional TLB entries as the PCID is different.
That's the point I was trying to make. This was further explained in my previous reply a little further down.
Quoted 8 lines
Quoted 7 lines
I wonder whether this is part of the reason you see PCID have a negative effect in the non-XPTI case.
So in the end the question is: Why not use just two PCIDs, and allow global pages just like we do now, with the added benefit that we no longer need to flush Xen's global TLB entries just because we want to get rid of PV guest user ones.
Quoted 6 lines
I can't see how that would work without either needing some more TLB flushes in order to prevent stale TLB entries or loosing the Meltdown mitigation.
Which %cr3/PCID combination should be used in hypervisor, guest kernel and guest user mode?
Xen would run with PCID 0 (and full Xen mappings) at all times (except early entry and late exit code of course). The guest would run with PCID 1 (and minimal Xen mappings) at all times. The switch of PCID eliminates the need for flushes on the way out and back in.
Quoted 1 line
Which pages would be global?
Use of global pages would continue to be as today: Xen has some, and guest user mode has some. Of course it is quite possible that the use of global pages with a single guest PCID is still worse than no global pages with two guest PCIDs, but that's a separate step to take (and measure) imo.
Quoted 18 lines
Quoted 18 lines
Quoted 5 lines
I don't
want to use global guest user pages together with PCID as flushing global pages from the TLB with PCID enabled requires flushing either the complete TLB or you'd have to use INVLPG in all possible address spaces (so you'd need to have multiple %cr3 switches).Well, yes, flushing _individual_ pages is a problem in that case. As to multiple CR3 switches - are these all that bad really with the no-flush bit set? With the reduced number of PCIDs in actual use (as discussed above) "all possible address spaces" would mean just two. And I could imagine that in a number of cases just one INVLPG (with the right PCID active) might suffice.
One complicating factor is that we don't want to introduce Xen TLB entries for other than what we map in the minimal page tables into PV guest PCID space, which would happen if we simply switched PCID around an INVLPG.
Quoted 5 lines
Quoted 3 lines
What I don't understand in any event is why you need separate PCIDs for Xen depending on whether the active PV guest is in kernel or user mode.
Main reason are the different page tables anchored in %cr3.
Hmm, right, looks like we can't have the best of both worlds: We'd like the Xen part of the address space to be shared, but the guest part of it to be separate. Question then still is whether the reduced flushing outweighs the reduced sharing. IOW between what we have today (a single PCID and a lot of flushing) and what you introduce (four PCIDs and very little flushing) is a middle approach - two PCIDs plus some flushing.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
In reply to a message not in the archiveQuoted 29 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 15:11, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Valid point. Looking at all present uses of ->arch.cr3, it's probably indeed better the way you have it. However, I'm now wondering about something else:
make_cr3()leaves PCID as zero for HVM and idle domains, but runs Xen with PCIDs 2 and 3 for (some) PV domains. That looks like an undesirable setup though - it would seem better to run Xen (with full page tables) with PCID 0 at all times.Quoted 4 lines
Then we'd have e.g.
PCID 0 Xen (full page tables)
PCID x PV guest priv
PCID y PV guest userQuoted 4 lines
So this would need another way to switch between guest and xen %cr3. Or would you want to use different %cr3 values with the same PCID without flushing the TLB in between? This seems to be a way to ask for problems...
Well, a TLB flush is clearly needed in such a setup when going from kernel to user mode.
Quoted 5 lines
In case you'd use the same %cr3 (guest kernel one, I guess) for both
cases: are you really sure there is no problem in any hypervisor path accessing guest data which would result in using guest kernel access rights when coming from user mode (BTW: that was the security note I had in v2 of my series).
Quoted 5 lines
I'm afraid I don't understand: Same %cr3? There are separate kernel and user page tables, requiring different values anyway. I also don't understand what problems in hypervisor code paths you suspect, when everything looks to work fine right now without PCID.
With switching between different page tables you need to flush the TLB. That was my point.
Quoted 30 lines
Quoted 8 lines
Quoted 7 lines
Global pages in PCID 0 could then still be permitted, and wouldn't ever need flushing except when
FLUSH_TLB_GLOBALis requested.As to the use of two separate PCIDs for PV kernel and user modes
- while this helps isolation, it prevents recovering the non-XPTI property of user mode TLB entries surviving in-guest mode switches.Quoted 6 lines
I don't get that. With PCID the guest's kernel _and_ user entries will survive in-guest mode switches as there is no TLB flushing involved (the no-flush bit is set in
v->arch.cr3for both modes).The only downside are guest kernel accesses to user pages: they will need additional TLB entries as the PCID is different.
That's the point I was trying to make. This was further explained in my previous reply a little further down.
Quoted 12 lines
Quoted 7 lines
I wonder whether this is part of the reason you see PCID have a negative effect in the non-XPTI case.
So in the end the question is: Why not use just two PCIDs, and allow global pages just like we do now, with the added benefit that we no longer need to flush Xen's global TLB entries just because we want to get rid of PV guest user ones.
I can't see how that would work without either needing some more TLB flushes in order to prevent stale TLB entries or loosing the Meltdown mitigation.
Quoted 7 lines
Quoted 2 lines
Which %cr3/PCID combination should be used in hypervisor, guest kernel and guest user mode?
Xen would run with PCID 0 (and full Xen mappings) at all times (except early entry and late exit code of course). The guest would run with PCID 1 (and minimal Xen mappings) at all times. The switch of PCID eliminates the need for flushes on the way out and back in.
You still need the kernel page tables flushed when switching to user mode, right?
Quoted 8 lines
Quoted 2 lines
Which pages would be global?
Use of global pages would continue to be as today: Xen has some, and guest user mode has some. Of course it is quite possible that the use of global pages with a single guest PCID is still worse than no global pages with two guest PCIDs, but that's a separate step to take (and measure) imo.
But global pages of Xen would either make it vulnerable with regard to Meltdown or you need a TLB flush again when switching between Xen and guest making all the PCID stuff moot.
Quoted 25 lines
Quoted 19 lines
Quoted 19 lines
Quoted 6 lines
I don't
want to use global guest user pages together with PCID as flushing global pages from the TLB with PCID enabled requires flushing either the complete TLB or you'd have to use INVLPG in all possible address spaces (so you'd need to have multiple %cr3 switches).Well, yes, flushing _individual_ pages is a problem in that case. As to multiple CR3 switches - are these all that bad really with the no-flush bit set? With the reduced number of PCIDs in actual use (as discussed above) "all possible address spaces" would mean just two. And I could imagine that in a number of cases just one INVLPG (with the right PCID active) might suffice.
One complicating factor is that we don't want to introduce Xen TLB entries for other than what we map in the minimal page tables into PV guest PCID space, which would happen if we simply switched PCID around an INVLPG.
Quoted 5 lines
Quoted 3 lines
What I don't understand in any event is why you need separate PCIDs for Xen depending on whether the active PV guest is in kernel or user mode.
Main reason are the different page tables anchored in %cr3.
Quoted 7 lines
Hmm, right, looks like we can't have the best of both worlds: We'd like the Xen part of the address space to be shared, but the guest part of it to be separate. Question then still is whether the reduced flushing outweighs the reduced sharing. IOW between what we have today (a single PCID and a lot of flushing) and what you introduce (four PCIDs and very little flushing) is a middle approach - two PCIDs plus some flushing.
As I believe kernel is touching much less user pages than kernel pages I'm pretty sure my approach is better in most cases.
And TBH I'm still not sure the "some flushing" wouldn't be too expensive.
So lets compare the possibilities:
My approach:
- no global pages
- 4 different PCIDs
- no TLB flushes needed when switching between Xen and guest
- no TLB flushes needed when switching between guest user and kernel
- flushing of single pages (guest or Xen) rather simple (4 INVPCIDs)
- flushing of complete TLB via 1 INVPCID
2 PCIDs (Xen and guest), keeping guest user pages as global pages
- Xen can't use global pages - global bit must be handled dynamically for Xen pages (or do we want to drop global pages e.g. for AMD, too?
- 2 PCIDs
- no TLB flushes needed when switching between Xen and guest
- when switching from guest kernel to guest user the kernel pages must be flushed from TLB
- flushing of single guest user pages needs 2 changes of %cr3 and 2 INVLPGs, switch code must be mapped to guest page tables
- flushing of complete TLB via 1 INVPCID
So the advantage of the 2 PCID solution are the single TLB entries for guest user pages compared to 2 entries for guest user pages accessed by the guest kernel or Xen.
The disadvantage are the flushed guest kernel pages when executing user code, the more complicated single user page flushing and the dynamical Xen global bit handling.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 08:49, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 15:11, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
So in the end the question is: Why not use just two PCIDs, and allow global pages just like we do now, with the added benefit that we no longer need to flush Xen's global TLB entries just because we want to get rid of PV guest user ones.
I can't see how that would work without either needing some more TLB flushes in order to prevent stale TLB entries or loosing the Meltdown mitigation.
Which %cr3/PCID combination should be used in hypervisor, guest kernel and guest user mode?
Quoted 7 lines
Quoted 4 lines
Xen would run with PCID 0 (and full Xen mappings) at all times (except early entry and late exit code of course). The guest would run with PCID 1 (and minimal Xen mappings) at all times. The switch of PCID eliminates the need for flushes on the way out and back in.
You still need the kernel page tables flushed when switching to user mode, right?
Of course.
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
Which pages would be global?
Use of global pages would continue to be as today: Xen has some, and guest user mode has some. Of course it is quite possible that the use of global pages with a single guest PCID is still worse than no global pages with two guest PCIDs, but that's a separate step to take (and measure) imo.
But global pages of Xen would either make it vulnerable with regard to Meltdown or you need a TLB flush again when switching between Xen and guest making all the PCID stuff moot.
No - the guest would run with PCID 1 active, and global Xen TLB entries would exist for PCID 0 only.
Quoted 10 lines
So lets compare the possibilities:
My approach:
- no global pages
- 4 different PCIDs
- no TLB flushes needed when switching between Xen and guest
- no TLB flushes needed when switching between guest user and kernel
- flushing of single pages (guest or Xen) rather simple (4 INVPCIDs)
- flushing of complete TLB via 1 INVPCID
Quoted 3 lines
2 PCIDs (Xen and guest), keeping guest user pages as global pages
- Xen can't use global pages - global bit must be handled dynamically for Xen pages (or do we want to drop global pages e.g. for AMD, too?
As per above - I don't see why Xen couldn't use global pages. The option of using them is part of why I'm wondering whether this might be worth looking into.
Quoted 8 lines
- 2 PCIDs
- no TLB flushes needed when switching between Xen and guest
- when switching from guest kernel to guest user the kernel pages must be flushed from TLB
- flushing of single guest user pages needs 2 changes of %cr3 and 2 INVLPGs, switch code must be mapped to guest page tables
- flushing of complete TLB via 1 INVPCID
Quoted 7 lines
So the advantage of the 2 PCID solution are the single TLB entries for guest user pages compared to 2 entries for guest user pages accessed by the guest kernel or Xen.
The disadvantage are the flushed guest kernel pages when executing user code, the more complicated single user page flushing and the dynamical Xen global bit handling.
Right. In order to make forward progress here I think we should shelve the discussion on the 2-PCID alternative for now. What I'd like to ask for as a change to your current approach is to use PCID 0 for Xen rather than running Xen with PCIDs 2 or 3 when PCIDs are enabled, and (implicitly) with PCID 0 when they're disabled. Or alternatively don't use PCID 0 at all when PCIDs are enabled. I'm simply worried of us overlooking a case where PCID 0 TLB entries may be left in place (when switching between PCIDs enabled and PCIDs disabled) when they should have been flushed, opening back up a Meltdown-like attack window.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
In reply to a message not in the archiveQuoted 34 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 08:49, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 15:11, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
So in the end the question is: Why not use just two PCIDs, and allow global pages just like we do now, with the added benefit that we no longer need to flush Xen's global TLB entries just because we want to get rid of PV guest user ones.
I can't see how that would work without either needing some more TLB flushes in order to prevent stale TLB entries or loosing the Meltdown mitigation.
Which %cr3/PCID combination should be used in hypervisor, guest kernel and guest user mode?
Quoted 7 lines
Quoted 4 lines
Xen would run with PCID 0 (and full Xen mappings) at all times (except early entry and late exit code of course). The guest would run with PCID 1 (and minimal Xen mappings) at all times. The switch of PCID eliminates the need for flushes on the way out and back in.
You still need the kernel page tables flushed when switching to user mode, right?
Of course.
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Which pages would be global?
Use of global pages would continue to be as today: Xen has some, and guest user mode has some. Of course it is quite possible that the use of global pages with a single guest PCID is still worse than no global pages with two guest PCIDs, but that's a separate step to take (and measure) imo.
Quoted 6 lines
Quoted 3 lines
But global pages of Xen would either make it vulnerable with regard to Meltdown or you need a TLB flush again when switching between Xen and guest making all the PCID stuff moot.
No - the guest would run with PCID 1 active, and global Xen TLB entries would exist for PCID 0 only.
Uuh, global pages are accessible via all PCIDs. That's why they are called global...
Quoted 11 lines
Quoted 11 lines
So lets compare the possibilities:
My approach:
- no global pages
- 4 different PCIDs
- no TLB flushes needed when switching between Xen and guest
- no TLB flushes needed when switching between guest user and kernel
- flushing of single pages (guest or Xen) rather simple (4 INVPCIDs)
- flushing of complete TLB via 1 INVPCID
Quoted 7 lines
Quoted 3 lines
2 PCIDs (Xen and guest), keeping guest user pages as global pages
- Xen can't use global pages - global bit must be handled dynamically for Xen pages (or do we want to drop global pages e.g. for AMD, too?As per above - I don't see why Xen couldn't use global pages. The option of using them is part of why I'm wondering whether this might be worth looking into.
See chapter 4.10.2.4 SDM Vol. 3
Quoted 17 lines
Quoted 9 lines
- 2 PCIDs
- no TLB flushes needed when switching between Xen and guest
- when switching from guest kernel to guest user the kernel pages must be flushed from TLB
- flushing of single guest user pages needs 2 changes of %cr3 and 2 INVLPGs, switch code must be mapped to guest page tables
- flushing of complete TLB via 1 INVPCIDQuoted 7 lines
So the advantage of the 2 PCID solution are the single TLB entries for guest user pages compared to 2 entries for guest user pages accessed by the guest kernel or Xen.
The disadvantage are the flushed guest kernel pages when executing user code, the more complicated single user page flushing and the dynamical Xen global bit handling.
Quoted 10 lines
Right. In order to make forward progress here I think we should shelve the discussion on the 2-PCID alternative for now. What I'd like to ask for as a change to your current approach is to use PCID 0 for Xen rather than running Xen with PCIDs 2 or 3 when PCIDs are enabled, and (implicitly) with PCID 0 when they're disabled. Or alternatively don't use PCID 0 at all when PCIDs are enabled. I'm simply worried of us overlooking a case where PCID 0 TLB entries may be left in place (when switching between PCIDs enabled and PCIDs disabled) when they should have been flushed, opening back up a Meltdown-like attack window.
The reason I didn't use PCID 0 for running Xen was to use a few INVPCID calls as possible for single page invalidation and still covering the cases for PCID on while XPTI off and including PCID 0.
I can change the scheme to use different values for guest PCIDs with XPTI on, of course. Are you fine with:
- XPTI off: PCID 0 = kernel, PCID 1 = user
- XPTI on: PCID 0 = kernel/Xen, PCID 1 = user/Xen, PCID 2 = kernel/guest, PCID 3 = user/guest
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 10:55, <[email protected]> wrote:
Quoted 38 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 08:49, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 15:11, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
So in the end the question is: Why not use just two PCIDs, and allow global pages just like we do now, with the added benefit that we no longer need to flush Xen's global TLB entries just because we want to get rid of PV guest user ones.
I can't see how that would work without either needing some more TLB flushes in order to prevent stale TLB entries or loosing the Meltdown mitigation.
Which %cr3/PCID combination should be used in hypervisor, guest kernel and guest user mode?
Quoted 7 lines
Quoted 4 lines
Xen would run with PCID 0 (and full Xen mappings) at all times (except early entry and late exit code of course). The guest would run with PCID 1 (and minimal Xen mappings) at all times. The switch of PCID eliminates the need for flushes on the way out and back in.
You still need the kernel page tables flushed when switching to user mode, right?
Of course.
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
Which pages would be global?
Use of global pages would continue to be as today: Xen has some, and guest user mode has some. Of course it is quite possible that the use of global pages with a single guest PCID is still worse than no global pages with two guest PCIDs, but that's a separate step to take (and measure) imo.
But global pages of Xen would either make it vulnerable with regard to Meltdown or you need a TLB flush again when switching between Xen and guest making all the PCID stuff moot.
Quoted 5 lines
Quoted 2 lines
No - the guest would run with PCID 1 active, and global Xen TLB entries would exist for PCID 0 only.
Uuh, global pages are accessible via all PCIDs. That's why they are called global...
Okay, in that case all of what I've said in this regard was rubbish. (I don't, btw, think that this is the only sensible interpretation of "global" - it could as well mean protected from ordinary flushes within the given PCID realm.)
Quoted 26 lines
Quoted 16 lines
Quoted 8 lines
- 2 PCIDs
- no TLB flushes needed when switching between Xen and guest
- when switching from guest kernel to guest user the kernel pages must be flushed from TLB
- flushing of single guest user pages needs 2 changes of %cr3 and 2 INVLPGs, switch code must be mapped to guest page tables
- flushing of complete TLB via 1 INVPCIDQuoted 7 lines
So the advantage of the 2 PCID solution are the single TLB entries for guest user pages compared to 2 entries for guest user pages accessed by the guest kernel or Xen.
The disadvantage are the flushed guest kernel pages when executing user code, the more complicated single user page flushing and the dynamical Xen global bit handling.
Quoted 10 lines
Right. In order to make forward progress here I think we should shelve the discussion on the 2-PCID alternative for now. What I'd like to ask for as a change to your current approach is to use PCID 0 for Xen rather than running Xen with PCIDs 2 or 3 when PCIDs are enabled, and (implicitly) with PCID 0 when they're disabled. Or alternatively don't use PCID 0 at all when PCIDs are enabled. I'm simply worried of us overlooking a case where PCID 0 TLB entries may be left in place (when switching between PCIDs enabled and PCIDs disabled) when they should have been flushed, opening back up a Meltdown-like attack window.
Quoted 3 lines
The reason I didn't use PCID 0 for running Xen was to use a few INVPCID calls as possible for single page invalidation and still covering the cases for PCID on while XPTI off and including PCID 0.
How would the number of INVPCIDs needed differ depending on the actual PCID values used?
Quoted 6 lines
I can change the scheme to use different values for guest PCIDs with XPTI on, of course. Are you fine with:
- XPTI off: PCID 0 = kernel, PCID 1 = user
- XPTI on: PCID 0 = kernel/Xen, PCID 1 = user/Xen, PCID 2 = kernel/guest, PCID 3 = user/guest
Yes, that would fit the first variant I've described. I take it you prefer not to avoid PCID 0 altogether when PCIDs are enabled - is there a particular reason?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
In reply to a message not in the archiveQuoted 43 lines · Jan Beulich
Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 10:55, <[email protected]> wrote:
Quoted 40 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 08:49, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 15:11, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
So in the end the question is: Why not use just two PCIDs, and allow global pages just like we do now, with the added benefit that we no longer need to flush Xen's global TLB entries just because we want to get rid of PV guest user ones.
I can't see how that would work without either needing some more TLB flushes in order to prevent stale TLB entries or loosing the Meltdown mitigation.
Which %cr3/PCID combination should be used in hypervisor, guest kernel and guest user mode?
Quoted 7 lines
Quoted 4 lines
Xen would run with PCID 0 (and full Xen mappings) at all times (except early entry and late exit code of course). The guest would run with PCID 1 (and minimal Xen mappings) at all times. The switch of PCID eliminates the need for flushes on the way out and back in.
You still need the kernel page tables flushed when switching to user mode, right?
Of course.
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
Which pages would be global?
Use of global pages would continue to be as today: Xen has some, and guest user mode has some. Of course it is quite possible that the use of global pages with a single guest PCID is still worse than no global pages with two guest PCIDs, but that's a separate step to take (and measure) imo.
But global pages of Xen would either make it vulnerable with regard to Meltdown or you need a TLB flush again when switching between Xen and guest making all the PCID stuff moot.
No - the guest would run with PCID 1 active, and global Xen TLB entries would exist for PCID 0 only.
Quoted 7 lines
Quoted 2 lines
Uuh, global pages are accessible via all PCIDs. That's why they are called global...
Okay, in that case all of what I've said in this regard was rubbish. (I don't, btw, think that this is the only sensible interpretation of "global" - it could as well mean protected from ordinary flushes within the given PCID realm.)
That's the reason I gave the reference to the SDM. It clearly states that TLB entries with the global bit set don't have to match the current PCID for being regarded to match.
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 9 lines
- 2 PCIDs
- no TLB flushes needed when switching between Xen and guest
- when switching from guest kernel to guest user the kernel pages must be flushed from TLB
- flushing of single guest user pages needs 2 changes of %cr3 and 2 INVLPGs, switch code must be mapped to guest page tables
- flushing of complete TLB via 1 INVPCIDQuoted 7 lines
So the advantage of the 2 PCID solution are the single TLB entries for guest user pages compared to 2 entries for guest user pages accessed by the guest kernel or Xen.
The disadvantage are the flushed guest kernel pages when executing user code, the more complicated single user page flushing and the dynamical Xen global bit handling.
Right. In order to make forward progress here I think we should shelve the discussion on the 2-PCID alternative for now. What I'd like to ask for as a change to your current approach is to use PCID 0 for Xen rather than running Xen with PCIDs 2 or 3 when PCIDs are enabled, and (implicitly) with PCID 0 when they're disabled. Or alternatively don't use PCID 0 at all when PCIDs are enabled. I'm simply worried of us overlooking a case where PCID 0 TLB entries may be left in place (when switching between PCIDs enabled and PCIDs disabled) when they should have been flushed, opening back up a Meltdown-like attack window.
Quoted 6 lines
Quoted 3 lines
The reason I didn't use PCID 0 for running Xen was to use a few INVPCID calls as possible for single page invalidation and still covering the cases for PCID on while XPTI off and including PCID 0.
How would the number of INVPCIDs needed differ depending on the actual PCID values used?
See answer below.
Quoted 10 lines
Quoted 6 lines
I can change the scheme to use different values for guest PCIDs with XPTI on, of course. Are you fine with:
- XPTI off: PCID 0 = kernel, PCID 1 = user
- XPTI on: PCID 0 = kernel/Xen, PCID 1 = user/Xen, PCID 2 = kernel/guest, PCID 3 = user/guestYes, that would fit the first variant I've described. I take it you prefer not to avoid PCID 0 altogether when PCIDs are enabled - is there a particular reason?
Yes. As written in the comment in flush_area_local() I can't be sure whether the current address space is that of a domain with XPTI enabled (the idle domain could be "current"). So I need to always flush with PCID 0 and with the possible PCID values for a XPTI domain. When using PCID 0 for XPTI as well I'll need 4 INVPCIDs, while when avoiding it I'd need 5 (at least when current == idle).
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 12:29, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 10:55, <[email protected]> wrote:
I can change the scheme to use different values for guest PCIDs with XPTI on, of course. Are you fine with:
- XPTI off: PCID 0 = kernel, PCID 1 = user
- XPTI on: PCID 0 = kernel/Xen, PCID 1 = user/Xen, PCID 2 = kernel/guest, PCID 3 = user/guestYes, that would fit the first variant I've described. I take it you prefer not to avoid PCID 0 altogether when PCIDs are enabled - is there a particular reason?
Quoted 6 lines
Yes. As written in the comment in
flush_area_local()I can't be sure whether the current address space is that of a domain with XPTI enabled (the idle domain could be "current"). So I need to always flush with PCID 0 and with the possible PCID values for a XPTI domain. When using PCID 0 for XPTI as well I'll need 4 INVPCIDs, while when avoiding it I'd need 5 (at least when current == idle).
I see. Which makes me wonder whether a suitable combination of INVLPG (to get rid of global entries) and INVPCID couldn't be used instead. For example, you may be able to replace the INVPCID for the active PCID by INVLPG (without needing to know who "current" is).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
In reply to a message not in the archiveQuoted 21 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 12:29, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 10:55, <[email protected]> wrote:
I can change the scheme to use different values for guest PCIDs with XPTI on, of course. Are you fine with:
- XPTI off: PCID 0 = kernel, PCID 1 = user
- XPTI on: PCID 0 = kernel/Xen, PCID 1 = user/Xen, PCID 2 = kernel/guest, PCID 3 = user/guestYes, that would fit the first variant I've described. I take it you prefer not to avoid PCID 0 altogether when PCIDs are enabled - is there a particular reason?
Quoted 6 lines
Yes. As written in the comment in
flush_area_local()I can't be sure whether the current address space is that of a domain with XPTI enabled (the idle domain could be "current"). So I need to always flush with PCID 0 and with the possible PCID values for a XPTI domain. When using PCID 0 for XPTI as well I'll need 4 INVPCIDs, while when avoiding it I'd need 5 (at least when current == idle).
Quoted 5 lines
I see. Which makes me wonder whether a suitable combination of INVLPG (to get rid of global entries) and INVPCID couldn't be used instead. For example, you may be able to replace the INVPCID for the active PCID by INVLPG (without needing to know who "current" is).
INVLPG has the disadvantage to clear all paging-structure cache entries associated with the current PCID.
And I thought we were finally on the same page not to use global pages with PCID enabled?
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 14:04, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 12:29, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 10:55, <[email protected]> wrote:
I can change the scheme to use different values for guest PCIDs with XPTI on, of course. Are you fine with:
- XPTI off: PCID 0 = kernel, PCID 1 = user
- XPTI on: PCID 0 = kernel/Xen, PCID 1 = user/Xen, PCID 2 = kernel/guest, PCID 3 = user/guestYes, that would fit the first variant I've described. I take it you prefer not to avoid PCID 0 altogether when PCIDs are enabled - is there a particular reason?
Quoted 6 lines
Yes. As written in the comment in
flush_area_local()I can't be sure whether the current address space is that of a domain with XPTI enabled (the idle domain could be "current"). So I need to always flush with PCID 0 and with the possible PCID values for a XPTI domain. When using PCID 0 for XPTI as well I'll need 4 INVPCIDs, while when avoiding it I'd need 5 (at least when current == idle).Quoted 5 lines
I see. Which makes me wonder whether a suitable combination of INVLPG (to get rid of global entries) and INVPCID couldn't be used instead. For example, you may be able to replace the INVPCID for the active PCID by INVLPG (without needing to know who "current" is).
Quoted 5 lines
INVLPG has the disadvantage to clear all paging-structure cache entries associated with the current PCID.
And I thought we were finally on the same page not to use global pages with PCID enabled?
Yes, we are. If no global TLB entries can ever survive a CR4.PCIDE 0 -> 1 transition, all would be fine without INVLPG of course.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 7/7] xen/x86: use PCID feature
In reply to a message not in the archiveQuoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 14:04, <[email protected]> wrote:
Quoted 26 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 12:29, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 26.03.18 at 10:55, <[email protected]> wrote:
I can change the scheme to use different values for guest PCIDs with XPTI on, of course. Are you fine with:
- XPTI off: PCID 0 = kernel, PCID 1 = user
- XPTI on: PCID 0 = kernel/Xen, PCID 1 = user/Xen, PCID 2 = kernel/guest, PCID 3 = user/guestYes, that would fit the first variant I've described. I take it you prefer not to avoid PCID 0 altogether when PCIDs are enabled - is there a particular reason?
Quoted 6 lines
Yes. As written in the comment in
flush_area_local()I can't be sure whether the current address space is that of a domain with XPTI enabled (the idle domain could be "current"). So I need to always flush with PCID 0 and with the possible PCID values for a XPTI domain. When using PCID 0 for XPTI as well I'll need 4 INVPCIDs, while when avoiding it I'd need 5 (at least when current == idle).I see. Which makes me wonder whether a suitable combination of INVLPG (to get rid of global entries) and INVPCID couldn't be used instead. For example, you may be able to replace the INVPCID for the active PCID by INVLPG (without needing to know who "current" is).
Quoted 8 lines
Quoted 5 lines
INVLPG has the disadvantage to clear all paging-structure cache entries associated with the current PCID.
And I thought we were finally on the same page not to use global pages with PCID enabled?
Yes, we are. If no global TLB entries can ever survive a CR4.PCIDE 0 -> 1 transition, all would be fine without INVLPG of course.
Okay, I'll add an ASSERT() to make sure this is true:
ASSERT(!cr4.pge || !cr4.pcide)
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to a message not in the archiveQuoted 25 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 10 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;
Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.
I just realized that using read_cr4() | X86_CR4_PGE is wrong. We would keep bits switched on which a pv domain is allowed to modify (plus CR4_TSD eventually).
Do we really want that?
We could mask away certain bits, of course, but in the end we'd just have a default calculated cr4 value instead of having it just set somewhere initially.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 09:14, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 10 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.
Quoted 5 lines
I just realized that using
read_cr4()|X86_CR4_PGEis wrong. We would keep bits switched on which a pv domain is allowed to modify (plusCR4_TSDeventually).Do we really want that?
Does it matter what exact CR4 settings we run with when it's not a PV guest that's in context, and when we don't depend on the settings ourselves? I don't think it does, and HVM guests run with their own CR4 anyway. In fact there may end up being cases where we won't need to switch CR4 another time when we come here the next time with v being a PV vCPU.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to a message not in the archiveQuoted 39 lines · Jan Beulich
Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 09:14, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 10 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.I just realized that using
read_cr4()|X86_CR4_PGEis wrong. We would keep bits switched on which a pv domain is allowed to modify (plusCR4_TSDeventually).
Quoted 8 lines
Quoted 1 line
Do we really want that?
Does it matter what exact CR4 settings we run with when it's not a PV guest that's in context, and when we don't depend on the settings ourselves? I don't think it does, and HVM guests run with their own CR4 anyway. In fact there may end up being cases where we won't need to switch CR4 another time when we come here the next time with v being a PV vCPU.
I could imagine that there is some performance impact. cr4.tsd set might make rdtsc a little bit slower as an additional privilege level check is needed.
Suspending requires cr4.fsgsbase to be set, which might have been reset by a pv guest.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
Quoted 49 lines · Juergen Gross
Quoted 39 lines · Jan Beulich
Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 09:14, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 10 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.I just realized that using
read_cr4()|X86_CR4_PGEis wrong. We would keep bits switched on which a pv domain is allowed to modify (plusCR4_TSDeventually).Quoted 8 lines
Quoted 1 line
Do we really want that?
Does it matter what exact CR4 settings we run with when it's not a PV guest that's in context, and when we don't depend on the settings ourselves? I don't think it does, and HVM guests run with their own CR4 anyway. In fact there may end up being cases where we won't need to switch CR4 another time when we come here the next time with v being a PV vCPU.
Quoted 6 lines
I could imagine that there is some performance impact. cr4.tsd set might make rdtsc a little bit slower as an additional privilege level check is needed.
Suspending requires cr4.fsgsbase to be set, which might have been reset by a pv guest.
Which is wrong, of course, as pv_guest_cr4_to_real_cr4() will always return a 1 for cr4.fsgsbase if the processor supports that bit.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to Juergen GrossQuoted 50 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 09:37, <[email protected]> wrote:
Quoted 39 lines · Jan Beulich
Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 09:14, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 10 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.I just realized that using
read_cr4()|X86_CR4_PGEis wrong. We would keep bits switched on which a pv domain is allowed to modify (plusCR4_TSDeventually).Quoted 8 lines
Quoted 1 line
Do we really want that?
Does it matter what exact CR4 settings we run with when it's not a PV guest that's in context, and when we don't depend on the settings ourselves? I don't think it does, and HVM guests run with their own CR4 anyway. In fact there may end up being cases where we won't need to switch CR4 another time when we come here the next time with v being a PV vCPU.
Quoted 3 lines
I could imagine that there is some performance impact. cr4.tsd set might make rdtsc a little bit slower as an additional privilege level check is needed.
Quite possible, indeed. Another opinion on the route to take would be helpful here. Andrew?
Quoted 2 lines
Suspending requires cr4.fsgsbase to be set, which might have been reset by a pv guest.
pv_guest_cr4_to_real_cr4() consistently forces this bit to 1 (on capable hardware).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
In reply to a message not in the archiveQuoted 50 lines · Jan Beulich
Quoted 50 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 09:37, <[email protected]> wrote:
Quoted 47 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 09:14, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 13:51, <[email protected]> wrote:
Instead of flushing the TLB from global pages when switching address spaces with XPTI being active just disable global pages via %cr4 completely when a domain subject to XPTI is active. This avoids the need for extra TLB flushes as loading %cr3 will remove all TLB entries.
I continue to be not entirely convinced of this move. I had an alternative in mind: Since retaining global pages is particularly relevant for switches between guest user and guest kernel modes, what if we made a shortcut from e.g.
lstar_enterthroughswitch_to_kerneltorestore_all_guestwithout ever switching to the full page Xen tables?xen/arch/x86/mm.c void make_cr3(struct vcpu *v, mfn_t mfn) · line 514
Quoted 10 lines
xen/arch/x86/mm.c +4
-0@@ -508,18 +508,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)void write_ptbase (struct vcpu *v) {struct cpu_info *cpu_info =get_cpu_info (); +unsigned long new_cr4; + + new_cr4 = (is_pv_vcpu (v) && !is_idle_vcpu (v)) + ?pv_guest_cr4_to_real_cr4 (v) : mmu_cr4_features;Quoted 7 lines
I'm not overly happy to see any new uses of
mmu_cr4_features. This should really only be used for priming certain values imo, which isn't the case here (otohpv_guest_cr4_to_real_cr4()does so too, and perhaps better wouldn't). Hence I wonder whether this shouldn't beread_cr4()|X86_CR4_PGE, not the least because we've just got rid of the blanket reversion tommu_cr4_featuresin VMX code.Quoted 5 lines
I just realized that using
read_cr4()|X86_CR4_PGEis wrong. We would keep bits switched on which a pv domain is allowed to modify (plusCR4_TSDeventually).Do we really want that?
Does it matter what exact CR4 settings we run with when it's not a PV guest that's in context, and when we don't depend on the settings ourselves? I don't think it does, and HVM guests run with their own CR4 anyway. In fact there may end up being cases where we won't need to switch CR4 another time when we come here the next time with v being a PV vCPU.
Quoted 6 lines
Quoted 3 lines
I could imagine that there is some performance impact. cr4.tsd set might make rdtsc a little bit slower as an additional privilege level check is needed.
Quite possible, indeed. Another opinion on the route to take would be helpful here. Andrew?
I could mask away tsd, of course. I need to do so for pcide already, so that would be just another bit reset in the mask.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v3 5/7] xen/x86: disable global pages for domains with XPTI active
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 10:44, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 09:37, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 09:14, <[email protected]> wrote:
I just realized that using
read_cr4()|X86_CR4_PGEis wrong. We would keep bits switched on which a pv domain is allowed to modify (plusCR4_TSDeventually).Quoted 8 lines
Quoted 1 line
Do we really want that?
Does it matter what exact CR4 settings we run with when it's not a PV guest that's in context, and when we don't depend on the settings ourselves? I don't think it does, and HVM guests run with their own CR4 anyway. In fact there may end up being cases where we won't need to switch CR4 another time when we come here the next time with v being a PV vCPU.
I could imagine that there is some performance impact. cr4.tsd set might make rdtsc a little bit slower as an additional privilege level check is needed.
Quoted 5 lines
Quoted 2 lines
Quite possible, indeed. Another opinion on the route to take would be helpful here. Andrew?
I could mask away tsd, of course. I need to do so for pcide already, so that would be just another bit reset in the mask.
Fine with me.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel