x86/hvm/viridian: APIC assist
cover x86/hvm/viridian: APIC assist
This patch series enables use of the APIC assist enlightenment in Xen.
Patch #1 modifies the viridian code to keep the guest APIC assist pages mapped for the lifetime of the domain (and incorporates a straightforward data-structure change).
Patch #2 adds a new viridian code and a configuration option to the toolstack that, when enabled, allows the local APIC emulation to make use the APIC assist pages.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 1/2 x86/hvm/viridian: keep APIC assist page mapped...
... for the lifetime of the domain.
If Xen is to make use of the APIC assist enlightenment then a persistent mapping needs to be kept, rather than the temporary one which is currently used only to initialize the page content.
--- xen/arch/x86/hvm/viridian.c | 54 +++++++++++++++++++++++++++----------- xen/include/asm-x86/hvm/viridian.h | 6 ++++- 2 files changed, 43 insertions(+), 17 deletions(-)
xen/arch/x86/hvm/viridian.c +38 -16
@@ -163,7 +163,7 @@ static void dump_apic_assist(const struct vcpu *v) {const union viridian_apic_assist *aa; - aa = &v->arch.hvm_vcpu.viridian.apic_assist; + aa = &v->arch.hvm_vcpu.viridian.apic_assist.msr;printk (XENLOG_G_INFO "%pv: VIRIDIAN APIC_ASSIST: enabled: %x pfn: %lx\n" , v, aa->fields.enabled, (unsigned long )aa->fields.pfn);
@@ -217,9 +217,9 @@ static void enable_hypercall_page(struct domain *d)static void initialize_apic_assist (struct vcpu *v) {struct domain *d = v->domain; -unsigned long gmfn = v->arch.hvm_vcpu.viridian.apic_assist.fields.pfn; +unsigned long gmfn = v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.pfn;struct page_info *page =get_page_from_gfn (d, gmfn,NULL ,P2M_ALLOC ); -uint8_t *p; +void *va;/* * We don't yet make use of the APIC assist page but by setting
@@ -231,21 +231,40 @@ static void initialize_apic_assist(struct vcpu *v)* details of how Windows uses the page. */ -if ( !page || !get_page_type (page, PGT_writable_page) ) +if ( !page ) +return ; + +if ( !get_page_type (page, PGT_writable_page) ) { -if ( page ) -put_page (page); -gdprintk (XENLOG_WARNING ,"Bad GMFN %lx (MFN %lx)\n" , gmfn, - page ?page_to_mfn (page) :INVALID_MFN ); +put_page (page);return ; } - p =__map_domain_page (page); + va =__map_domain_page_global (page); +if ( !va ) + { +put_page_and_type (page); +return ; + } - *(u32 *)p =0 ; + *(uint32_t *)va =0 ; -unmap_domain_page (p); + v->arch.hvm_vcpu.viridian.apic_assist.page = page; + v->arch.hvm_vcpu.viridian.apic_assist.va = va; +} + +static void teardown_apic_assist (struct vcpu *v) +{ +struct page_info *page = v->arch.hvm_vcpu.viridian.apic_assist.page; +void *va = v->arch.hvm_vcpu.viridian.apic_assist.va; + +if ( !va ) +return ; + + v->arch.hvm_vcpu.viridian.apic_assist.va =NULL ; + v->arch.hvm_vcpu.viridian.apic_assist.page =NULL ; +unmap_domain_page_global (va);put_page_and_type (page); }
@@ -374,9 +393,9 @@ int wrmsr_viridian_regs(uint32_t idx, uint64_t val)case VIRIDIAN_MSR_APIC_ASSIST :perfc_incr (mshv_wrmsr_apic_msr); - v->arch.hvm_vcpu.viridian.apic_assist.raw = val; + v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = val;dump_apic_assist (v); -if (v->arch.hvm_vcpu.viridian.apic_assist.fields.enabled) +if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled )initialize_apic_assist (v);break ;
@@ -485,7 +504,7 @@ int rdmsr_viridian_regs(uint32_t idx, uint64_t *val)case VIRIDIAN_MSR_APIC_ASSIST :perfc_incr (mshv_rdmsr_apic_msr); - *val = v->arch.hvm_vcpu.viridian.apic_assist.raw; + *val = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw;break ;case VIRIDIAN_MSR_REFERENCE_TSC :
@@ -530,6 +549,7 @@ int viridian_vcpu_init(struct vcpu *v)void viridian_vcpu_deinit (struct vcpu *v) {free_cpumask_var (v->arch.hvm_vcpu.viridian.flush_cpumask); +teardown_apic_assist (v); }int viridian_hypercall (struct cpu_user_regs *regs)
@@ -728,7 +748,7 @@ static int viridian_save_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)for_each_vcpu ( d, v ) {struct hvm_viridian_vcpu_context ctxt; - ctxt.apic_assist = v->arch.hvm_vcpu.viridian.apic_assist.raw; + ctxt.apic_assist = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw;if (hvm_save_entry (VIRIDIAN_VCPU , v->vcpu_id, h, &ctxt) !=0 )return 1 ;
@@ -754,7 +774,9 @@ static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)if (hvm_load_entry (VIRIDIAN_VCPU , h, &ctxt) !=0 )return -EINVAL ; - v->arch.hvm_vcpu.viridian.apic_assist.raw = ctxt.apic_assist; + v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = ctxt.apic_assist; +if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled ) +initialize_apic_assist (v);return 0 ; }
xen/include/asm-x86/hvm/viridian.h +5 -1
@@ -21,7 +21,11 @@ union viridian_apic_assiststruct viridian_vcpu { -union viridian_apic_assist apic_assist; +struct { +union viridian_apic_assist msr; +struct page_info *page; +void *va; + } apic_assist;cpumask_var_t flush_cpumask; };
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 1/2] x86/hvm/viridian: keep APIC assist page mapped...
Quoted 45 lines · Paul Durrant
... for the lifetime of the domain.
If Xen is to make use of the APIC assist enlightenment then a persistent mapping needs to be kept, rather than the temporary one which is currently used only to initialize the page content.
Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Andrew Cooper <[email protected]>--- xen/arch/x86/hvm/viridian.c | 54 +++++++++++++++++++++++++++----------- xen/include/asm-x86/hvm/viridian.h | 6 ++++- 2 files changed, 43 insertions(+), 17 deletions(-)xen/arch/x86/hvm/viridian.c +3
-4@@ -163,7 +163,7 @@ static void dump_apic_assist(const struct vcpu *v) {const union viridian_apic_assist *aa; - aa = &v->arch.hvm_vcpu.viridian.apic_assist; + aa = &v->arch.hvm_vcpu.viridian.apic_assist.msr;printk (XENLOG_G_INFO "%pv: VIRIDIAN APIC_ASSIST: enabled: %x pfn: %lx\n" , v, aa->fields.enabled, (unsigned long )aa->fields.pfn);@@ -217,9 +217,9 @@ static void enable_hypercall_page(struct domain *d)static void initialize_apic_assist (struct vcpu *v) {struct domain *d = v->domain; -unsigned long gmfn = v->arch.hvm_vcpu.viridian.apic_assist.fields.pfn; +unsigned long gmfn = v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.pfn;struct page_info *page =get_page_from_gfn (d, gmfn,NULL ,P2M_ALLOC ); -uint8_t *p; +void *va;/* * We don't yet make use of the APIC assist page but by setting @@ -231,21 +231,40 @@ static void initialize_apic_assist(struct vcpu *v)* details of how Windows uses the page. */ -if ( !page || !get_page_type (page, PGT_writable_page) )
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 239
Quoted 10 lines
xen/arch/x86/hvm/viridian.c +5
-4+if ( !page ) +return ; + +if ( !get_page_type (page, PGT_writable_page) ) { -if ( page ) -put_page (page); -gdprintk (XENLOG_WARNING ,"Bad GMFN %lx (MFN %lx)\n" , gmfn, - page ?page_to_mfn (page) :INVALID_MFN ); +put_page (page);
You don't want to report errors in case this goes south?
Quoted 108 lines
xen/arch/x86/hvm/viridian.c +30
-8return ; } - p =__map_domain_page (page); + va =__map_domain_page_global (page); +if ( !va ) + { +put_page_and_type (page); +return ; + } - *(u32 *)p =0 ; + *(uint32_t *)va =0 ; -unmap_domain_page (p); + v->arch.hvm_vcpu.viridian.apic_assist.page = page; + v->arch.hvm_vcpu.viridian.apic_assist.va = va; +} + +static void teardown_apic_assist (struct vcpu *v) +{ +struct page_info *page = v->arch.hvm_vcpu.viridian.apic_assist.page; +void *va = v->arch.hvm_vcpu.viridian.apic_assist.va; + +if ( !va ) +return ; + + v->arch.hvm_vcpu.viridian.apic_assist.va =NULL ; + v->arch.hvm_vcpu.viridian.apic_assist.page =NULL ; +unmap_domain_page_global (va);put_page_and_type (page); }@@ -374,9 +393,9 @@ int wrmsr_viridian_regs(uint32_t idx, uint64_t val)case VIRIDIAN_MSR_APIC_ASSIST :perfc_incr (mshv_wrmsr_apic_msr); - v->arch.hvm_vcpu.viridian.apic_assist.raw = val; + v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = val;dump_apic_assist (v); -if (v->arch.hvm_vcpu.viridian.apic_assist.fields.enabled) +if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled )initialize_apic_assist (v);break ;@@ -485,7 +504,7 @@ int rdmsr_viridian_regs(uint32_t idx, uint64_t *val)case VIRIDIAN_MSR_APIC_ASSIST :perfc_incr (mshv_rdmsr_apic_msr); - *val = v->arch.hvm_vcpu.viridian.apic_assist.raw; + *val = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw;break ;case VIRIDIAN_MSR_REFERENCE_TSC :@@ -530,6 +549,7 @@ int viridian_vcpu_init(struct vcpu *v)void viridian_vcpu_deinit (struct vcpu *v) {free_cpumask_var (v->arch.hvm_vcpu.viridian.flush_cpumask); +teardown_apic_assist (v); }int viridian_hypercall (struct cpu_user_regs *regs)@@ -728,7 +748,7 @@ static int viridian_save_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)for_each_vcpu ( d, v ) {struct hvm_viridian_vcpu_context ctxt; - ctxt.apic_assist = v->arch.hvm_vcpu.viridian.apic_assist.raw; + ctxt.apic_assist = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw;if (hvm_save_entry (VIRIDIAN_VCPU , v->vcpu_id, h, &ctxt) !=0 )return 1 ;@@ -754,7 +774,9 @@ static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)if (hvm_load_entry (VIRIDIAN_VCPU , h, &ctxt) !=0 )return -EINVAL ; - v->arch.hvm_vcpu.viridian.apic_assist.raw = ctxt.apic_assist; + v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = ctxt.apic_assist; +if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled ) +initialize_apic_assist (v);return 0 ; }xen/include/asm-x86/hvm/viridian.h +5
-1@@ -21,7 +21,11 @@ union viridian_apic_assiststruct viridian_vcpu { -union viridian_apic_assist apic_assist; +struct { +union viridian_apic_assist msr; +struct page_info *page; +void *va; + } apic_assist;cpumask_var_t flush_cpumask; };Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/2] x86/hvm/viridian: keep APIC assist page mapped...
Quoted 60 lines
-----Original Message-----
From: Konrad Rzeszutek Wilk [mailto:[email protected]]
Sent: 15 March 2016 23:20
To: Paul Durrant
Cc: [email protected]; Andrew Cooper; Keir (Xen.org); Jan Beulich
Subject: Re: [Xen-devel] [PATCH 1/2] x86/hvm/viridian: keep APIC assist page mapped...Quoted 4 lines · Paul Durrant
... for the lifetime of the domain.
If Xen is to make use of the APIC assist enlightenment then a persistent mapping needs to be kept, rather than the temporary one which is
currently
Quoted 8 lines
used only to initialize the page content.
Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Andrew Cooper <[email protected]>--- xen/arch/x86/hvm/viridian.c | 54 +++++++++++++++++++++++++++-----------
Quoted 8 lines
xen/include/asm-x86/hvm/viridian.h | 6 ++++- 2 files changed, 43 insertions(+), 17 deletions(-)xen/arch/x86/hvm/viridian.c +0
-0xen/arch/x86/hvm/viridian.c static void dump_apic_assist(const struct vcpu *v) · line 168
Quoted 7 lines
xen/arch/x86/hvm/viridian.c +1
-1@@ -163,7 +163,7 @@ static void dump_apic_assist(const struct vcpu *v) { const union viridian_apic_assist *aa; - aa = &v->arch.hvm_vcpu.viridian.apic_assist; + aa = &v->arch.hvm_vcpu.viridian.apic_assist.msr; printk(XENLOG_G_INFO "%pv: VIRIDIAN APIC_ASSIST: enabled: %x pfn:%lx\n",
xen/arch/x86/hvm/viridian.c static void enable_hypercall_page(struct domain
Quoted 2 lines
xen/arch/x86/hvm/viridian.c +0
-0v, aa->fields.enabled, (unsigned long)aa->fields.pfn);@@ -217,9 +217,9 @@ static void enable_hypercall_page(struct domain*d)
xen/arch/x86/hvm/viridian.c static void enable_hypercall_page(struct domain *d)
Quoted 7 lines
xen/arch/x86/hvm/viridian.c +1
-1static void initialize_apic_assist (struct vcpu *v) {struct domain *d = v->domain; -unsigned long gmfn = v->arch.hvm_vcpu.viridian.apic_assist.fields.pfn; +unsigned long gmfn = v- arch.hvm_vcpu.viridian.apic_assist.msr.fields.pfn; struct page_info *page = get_page_from_gfn(d, gmfn, NULL,
P2M_ALLOC);Quoted 9 lines
xen/arch/x86/hvm/viridian.c +1
-1-uint8_t *p; +void *va;/* * We don't yet make use of the APIC assist page but by setting
xen/arch/x86/hvm/viridian.c +0
-0@@ -231,21 +231,40 @@ static void initialize_apic_assist(struct vcpu *v)* details of how Windows uses the page. */
Quoted 14 lines
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 239
Quoted 11 lines
xen/arch/x86/hvm/viridian.c +5
-5-if ( !page || !get_page_type (page, PGT_writable_page) ) +if ( !page ) +return ; + +if ( !get_page_type (page, PGT_writable_page) ) { -if ( page ) -put_page (page); -gdprintk (XENLOG_WARNING ,"Bad GMFN %lx (MFN %lx)\n" , gmfn, - page ?page_to_mfn (page) :INVALID_MFN ); +put_page (page);You don't want to report errors in case this goes south?
Well, the guest should keep on running but without the enlightenment. You're right that I should probably keep the warning though.
Paul
Quoted 103 lines
xen/arch/x86/hvm/viridian.c static int viridian_save_vcpu_ctxt(struct domain *d,
Quoted 64 lines
xen/arch/x86/hvm/viridian.c +26
-6return ; } - p =__map_domain_page (page); + va =__map_domain_page_global (page); +if ( !va ) + { +put_page_and_type (page); +return ; + } - *(u32 *)p =0 ; + *(uint32_t *)va =0 ; -unmap_domain_page (p); + v->arch.hvm_vcpu.viridian.apic_assist.page = page; + v->arch.hvm_vcpu.viridian.apic_assist.va = va; +} + +static void teardown_apic_assist (struct vcpu *v) +{ +struct page_info *page = v->arch.hvm_vcpu.viridian.apic_assist.page; +void *va = v->arch.hvm_vcpu.viridian.apic_assist.va; + +if ( !va ) +return ; + + v->arch.hvm_vcpu.viridian.apic_assist.va =NULL ; + v->arch.hvm_vcpu.viridian.apic_assist.page =NULL ; +unmap_domain_page_global (va);put_page_and_type (page); }@@ -374,9 +393,9 @@ int wrmsr_viridian_regs(uint32_t idx, uint64_t val)case VIRIDIAN_MSR_APIC_ASSIST :perfc_incr (mshv_wrmsr_apic_msr); - v->arch.hvm_vcpu.viridian.apic_assist.raw = val; + v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = val;dump_apic_assist (v); -if (v->arch.hvm_vcpu.viridian.apic_assist.fields.enabled) +if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled )initialize_apic_assist (v);break ;@@ -485,7 +504,7 @@ int rdmsr_viridian_regs(uint32_t idx, uint64_t *val)case VIRIDIAN_MSR_APIC_ASSIST :perfc_incr (mshv_rdmsr_apic_msr); - *val = v->arch.hvm_vcpu.viridian.apic_assist.raw; + *val = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw;break ;case VIRIDIAN_MSR_REFERENCE_TSC :@@ -530,6 +549,7 @@ int viridian_vcpu_init(struct vcpu *v)void viridian_vcpu_deinit (struct vcpu *v) {free_cpumask_var (v->arch.hvm_vcpu.viridian.flush_cpumask); +teardown_apic_assist (v); }int viridian_hypercall (struct cpu_user_regs *regs)@@ -728,7 +748,7 @@ static int viridian_save_vcpu_ctxt(struct domain *d,
hvm_domain_context_t*h)xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain *d,
Quoted 9 lines
xen/arch/x86/hvm/viridian.c +1
-1for_each_vcpu ( d, v ) {struct hvm_viridian_vcpu_context ctxt; - ctxt.apic_assist = v->arch.hvm_vcpu.viridian.apic_assist.raw; + ctxt.apic_assist = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw;if (hvm_save_entry (VIRIDIAN_VCPU , v->vcpu_id, h, &ctxt) !=0 )return 1 ;@@ -754,7 +774,9 @@ static int viridian_load_vcpu_ctxt(struct domain *d,
hvm_domain_context_t*h)xen/include/asm-
Quoted 11 lines
xen/arch/x86/hvm/viridian.c +3
-1if (hvm_load_entry (VIRIDIAN_VCPU , h, &ctxt) !=0 )return -EINVAL ; - v->arch.hvm_vcpu.viridian.apic_assist.raw = ctxt.apic_assist; + v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = ctxt.apic_assist; +if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled ) +initialize_apic_assist (v);return 0 ; }xen/include/asm- renamed from xen/include/asm-x86/hvm/viridian.h +0
-0
x86/hvm/viridian.hQuoted 16 lines
index 2eec85e..c60c113 100644
xen/include/asm-x86/hvm/viridian.h +5
-1@@ -21,7 +21,11 @@ union viridian_apic_assiststruct viridian_vcpu { -union viridian_apic_assist apic_assist; +struct { +union viridian_apic_assist msr; +struct page_info *page; +void *va; + } apic_assist;cpumask_var_t flush_cpumask; };
Quoted 8 lines
Quoted 8 lines
--
2.1.4_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 2/2 x86/hvm/viridian: Enable APIC assist enlightenment
In reply to Paul DurrantThis patch adds code to enable the APIC assist enlightenment which, under certain conditions, means that the guest can avoid an EOI of the local APIC and thereby avoid a VMEXIT.
Use of the enlightenment by the hypervisor is under control of the toolstack.
--- docs/man/xl.cfg.pod.5 | 8 ++++++ tools/libxl/libxl_dom.c | 3 ++ tools/libxl/libxl_types.idl | 1 + xen/arch/x86/hvm/viridian.c | 59 +++++++++++++++++++++++++++++++------- xen/arch/x86/hvm/vlapic.c | 58 +++++++++++++++++++++++++++++++++---- xen/include/asm-x86/hvm/viridian.h | 5 ++++ xen/include/public/hvm/params.h | 7 ++++- 7 files changed, 124 insertions(+), 17 deletions(-)
docs/man/xl.cfg.pod.5 +8 -0
@@ -1484,6 +1484,14 @@ This set incorporates use of hypercalls for remote TLB flushing. This enlightenment may improve performance of Windows guests running on hosts with higher levels of (physical) CPU contention. +=item B<apic_assist> + +This set incorporates use of the APIC assist page to avoid EOI of +the local APIC. +This enlightenment may improve performance of Windows guests, +particularly those running PV drivers that make use of per-vcpu +event channel upcall vectors. + =item B<defaults> This is a special value that enables the default set of groups, which
tools/libxl/libxl_dom.c +3 -0
@@ -253,6 +253,9 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,if (libxl_bitmap_test (&enlightenments,LIBXL_VIRIDIAN_ENLIGHTENMENT_HCALL_REMOTE_TLB_FLUSH )) mask |= HVMPV_hcall_remote_tlb_flush; +if (libxl_bitmap_test (&enlightenments,LIBXL_VIRIDIAN_ENLIGHTENMENT_APIC_ASSIST )) + mask |= HVMPV_apic_assist; +if (mask !=0 && xc_hvm_param_set(CTX->xch, domid,
tools/libxl/libxl_types.idl +1 -0
@@ -221,6 +221,7 @@ libxl_viridian_enlightenment = Enumeration("viridian_enlightenment", [ (2, "time_ref_count"), (3, "reference_tsc"), (4, "hcall_remote_tlb_flush"), + (5, "apic_assist"), ]) libxl_hdtype = Enumeration("hdtype", [
xen/arch/x86/hvm/viridian.c +49 -10
71 lines not on this page · raw message
xen/arch/x86/hvm/vlapic.c +52 -6
94 lines not on this page · raw message
xen/include/asm-x86/hvm/viridian.h +5 -0
@@ -25,6 +25,7 @@ struct viridian_vcpuunion viridian_apic_assist msr;struct page_info *page;void *va; +int vector; } apic_assist;cpumask_var_t flush_cpumask; };
@@ -125,6 +126,10 @@ void viridian_time_ref_count_thaw(struct domain *d);int viridian_vcpu_init (struct vcpu *v);void viridian_vcpu_deinit (struct vcpu *v); +void viridian_start_apic_assist (struct vcpu *v,int vector); +bool_t viridian_complete_apic_assist (struct vcpu *v,int *vector); +void viridian_abort_apic_assist (struct vcpu *v); +#endif /* __ASM_X86_HVM_VIRIDIAN_H__ */ /*
xen/include/public/hvm/params.h +6 -1
@@ -115,12 +115,17 @@#define _HVMPV_hcall_remote_tlb_flush 4#define HVMPV_hcall_remote_tlb_flush (1 << _HVMPV_hcall_remote_tlb_flush) +/* Use APIC assist */ +#define _HVMPV_apic_assist 5 +#define HVMPV_apic_assist (1 << _HVMPV_apic_assist) +#define HVMPV_feature_mask \ (HVMPV_base_freq | \ HVMPV_no_freq | \ HVMPV_time_ref_count | \ HVMPV_reference_tsc | \ - HVMPV_hcall_remote_tlb_flush) + HVMPV_hcall_remote_tlb_flush | \ + HVMPV_apic_assist)#endif
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 2/2] x86/hvm/viridian: Enable APIC assist enlightenment
Quoted 3 lines · Paul Durrant
This patch adds code to enable the APIC assist enlightenment which, under certain conditions, means that the guest can avoid an EOI of the local APIC and thereby avoid a VMEXIT.
I noticed you deleted the comment having the spec.
Would it be better if:
1) It was in the git commit description.
2) As part of the docs directory?
Oh and the link is broken. An the link it points to is broken too.
So no spec for this, eh?
Quoted 26 lines
Use of the enlightenment by the hypervisor is under control of the toolstack.
Signed-off-by Paul Durrant <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Wei Liu <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Andrew Cooper <[email protected]>--- docs/man/xl.cfg.pod.5 | 8 ++++++ tools/libxl/libxl_dom.c | 3 ++ tools/libxl/libxl_types.idl | 1 + xen/arch/x86/hvm/viridian.c | 59 +++++++++++++++++++++++++++++++------- xen/arch/x86/hvm/vlapic.c | 58 +++++++++++++++++++++++++++++++++---- xen/include/asm-x86/hvm/viridian.h | 5 ++++ xen/include/public/hvm/params.h | 7 ++++- 7 files changed, 124 insertions(+), 17 deletions(-)docs/man/xl.cfg.pod.5 +0
-0
docs/man/xl.cfg.pod.5 This set incorporates use of hypercalls for remote TLB flushing. · line 1489
Quoted 6 lines
docs/man/xl.cfg.pod.5 +3
-0@@ -1484,6 +1484,14 @@ This set incorporates use of hypercalls for remote TLB flushing. This enlightenment may improve performance of Windows guests running on hosts with higher levels of (physical) CPU contention. +=item B<apic_assist> + +This set incorporates use of the APIC assist page to avoid EOI of
What set? Option?
docs/man/xl.cfg.pod.5 This set incorporates use of hypercalls for remote TLB flushing. · line 1491
Quoted 2 lines
docs/man/xl.cfg.pod.5 +2
-0+the local APIC. +This enlightenment may improve performance of Windows guests,
may? How does this square with Intel vAPIC?
Could you mention that here? Or in the commit description?
And can non-Windows guests use it too?
Or is this particular for Windows guests? IF so which ones?
docs/man/xl.cfg.pod.5 This set incorporates use of hypercalls for remote TLB flushing. · line 1493
Quoted 2 lines
docs/man/xl.cfg.pod.5 +2
-0+particularly those running PV drivers that make use of per-vcpu +event channel upcall vectors.
What kind of PV drivers? Anybody?
Quoted 62 lines
docs/man/xl.cfg.pod.5 +1
-0+ =item B<defaults> This is a special value that enables the default set of groups, whichtools/libxl/libxl_dom.c +3
-0@@ -253,6 +253,9 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,if (libxl_bitmap_test (&enlightenments,LIBXL_VIRIDIAN_ENLIGHTENMENT_HCALL_REMOTE_TLB_FLUSH )) mask |= HVMPV_hcall_remote_tlb_flush; +if (libxl_bitmap_test (&enlightenments,LIBXL_VIRIDIAN_ENLIGHTENMENT_APIC_ASSIST )) + mask |= HVMPV_apic_assist; +if (mask !=0 && xc_hvm_param_set(CTX->xch, domid,tools/libxl/libxl_types.idl +1
-0@@ -221,6 +221,7 @@ libxl_viridian_enlightenment = Enumeration("viridian_enlightenment", [ (2, "time_ref_count"), (3, "reference_tsc"), (4, "hcall_remote_tlb_flush"), + (5, "apic_assist"), ]) libxl_hdtype = Enumeration("hdtype", [xen/arch/x86/hvm/viridian.c +7
-10@@ -221,16 +221,6 @@ static void initialize_apic_assist(struct vcpu *v)struct page_info *page =get_page_from_gfn (d, gmfn,NULL ,P2M_ALLOC );void *va; -/* -* We don't yet make use of the APIC assist page but by setting -* the CPUID3A_MSR_APIC_ACCESS bit in CPUID leaf 40000003 we are duty -* bound to support the MSR. We therefore do just enough to keep windows -* happy. -* -* See http://msdn.microsoft.com/en-us/library/ff538657%28VS.85%29.aspx for -* details of how Windows uses the page. -*/ -if ( !page )return ;@@ -251,6 +241,55 @@ static void initialize_apic_assist(struct vcpu *v) v->arch.hvm_vcpu.viridian.apic_assist.page = page; v->arch.hvm_vcpu.viridian.apic_assist.va = va; + v->arch.hvm_vcpu.viridian.apic_assist.vector =-1 ; +} + +void viridian_start_apic_assist (struct vcpu *v,int vector) +{ +void *va = v->arch.hvm_vcpu.viridian.apic_assist.va; +
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 260
Quoted 10 lines
xen/arch/x86/hvm/viridian.c +10
-0+if ( !(viridian_feature_mask (v->domain) & HVMPV_apic_assist) || + !va ) +return ; + +/* +* If there is already an assist pending then something has gone +* wrong and the VM will most likely hang so force a crash now +* to make the problem clear. +*/ +if (v->arch.hvm_vcpu.viridian.apic_assist.vector >=0 )
I think you need spaces sprinkled here.
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 264
Quoted 4 lines
xen/arch/x86/hvm/viridian.c +4
-0+domain_crash (v->domain); + + v->arch.hvm_vcpu.viridian.apic_assist.vector = vector; + *(uint32_t *)va |=1u ;
Oh my. What does that do? Why not 0xBADF00D
Is that prescriped in the spec?
That looks quite unhealthy to do.
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 275
Quoted 11 lines
xen/arch/x86/hvm/viridian.c +11
-0+} + +bool_t viridian_complete_apic_assist (struct vcpu *v,int *vector) +{ +void *va = v->arch.hvm_vcpu.viridian.apic_assist.va; + +if ( !(viridian_feature_mask (v->domain) & HVMPV_apic_assist) || + !va ) +return 0 ; + +if ( *(uint32_t *)va &1 )
Is that really part of the spec?
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 279
Quoted 4 lines
xen/arch/x86/hvm/viridian.c +4
-0+return 0 ;/* Interrupt not yet processed by the guest */ + + *vector = v->arch.hvm_vcpu.viridian.apic_assist.vector; + v->arch.hvm_vcpu.viridian.apic_assist.vector =-1 ;
Could you explain that bit please? Why the reset of the vector? Maybe it becomes clear later on.
/me grumbles about not spec.
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 289
Quoted 10 lines
xen/arch/x86/hvm/viridian.c +10
-0+return 1 ; +} + +void viridian_abort_apic_assist (struct vcpu *v) +{ +void *va = v->arch.hvm_vcpu.viridian.apic_assist.va; + +if ( !(viridian_feature_mask (v->domain) & HVMPV_apic_assist) || + !va ) +return ;
This is the third time I see that. Perhaps you can make a function out of it.
Quoted 19 lines
xen/arch/x86/hvm/viridian.c +3
-0+ + *(uint32_t *)va &= ~1u ; + v->arch.hvm_vcpu.viridian.apic_assist.vector =-1 ; }static void teardown_apic_assist (struct vcpu *v)xen/arch/x86/hvm/vlapic.c +1
-0@@ -38,6 +38,7 @@#include <asm/hvm/support.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/nestedhvm.h> +#include <asm/hvm/viridian.h> #include <public/hvm/ioreq.h> #include <public/hvm/params.h>
xen/arch/x86/hvm/vlapic.c static int vlapic_find_highest_vector(const void *bitmap) · line 104
Quoted 9 lines
xen/arch/x86/hvm/vlapic.c +6
-0@@ -95,6 +96,18 @@ static int vlapic_find_highest_vector(const void *bitmap)return (fls (word[word_offset*4 ]) -1 ) + (word_offset *32 ); } +static int vlapic_find_lowest_vector (const void *bitmap) +{ +const uint32_t *word = bitmap; +unsigned int word_offset; + +/* Work forwards through the bitmap (first 32-bit word in every four). */
Would it be easier said:
Operate on chunks of 4 bytes?
Quoted 10 lines
xen/arch/x86/hvm/vlapic.c +6
-0+for ( word_offset =0 ; word_offset <NR_VECTORS /32 ; word_offset++) +if ( word[word_offset *4 ] ) +return (ffs (word[word_offset *4 ]) -1 ) + (word_offset *32 ); + +return -1 ; +}/* * IRR-specific bitmap update & search routines.
xen/arch/x86/hvm/vlapic.c int vlapic_virtual_intr_delivery_enabled(void) · line 1173
Quoted 5 lines
xen/arch/x86/hvm/vlapic.c +1
-1@@ -1157,7 +1170,7 @@ int vlapic_virtual_intr_delivery_enabled(void)int vlapic_has_pending_irq (struct vcpu *v) {struct vlapic *vlapic =vcpu_vlapic (v); -int irr, isr; +int irr, vector, isr;
vector = -1?
Quoted 120 lines
xen/arch/x86/hvm/vlapic.c +38
-5if ( !vlapic_enabled (vlapic) )return -1 ;@@ -1170,10 +1183,27 @@ int vlapic_has_pending_irq(struct vcpu *v) !nestedhvm_vcpu_in_guestmode(v) )return irr; +/* +* If APIC assist was used then there may have been no EOI so +* we need to clear the requisite bit from the ISR here, before +* comparing with the IRR. +*/ +if (viridian_complete_apic_assist (v, &vector) && + vector !=-1 ) +vlapic_clear_vector (vector, &vlapic->regs->data[APIC_ISR ]); + isr =vlapic_find_highest_isr (vlapic); isr = (isr !=-1 ) ? isr :0 ;if ( (isr &0xf0 ) >= (irr &0xf0 ) ) + { +/* +* There's already a higher priority vector pending so +* we need to abort any previous APIC assist to ensure there +* is an EOI. +*/ +viridian_abort_apic_assist (v);return -1 ; + }return irr; }@@ -1181,13 +1211,29 @@ int vlapic_has_pending_irq(struct vcpu *v)int vlapic_ack_pending_irq (struct vcpu *v,int vector,bool_t force_ack) {struct vlapic *vlapic =vcpu_vlapic (v); +int isr; -if ( force_ack || !vlapic_virtual_intr_delivery_enabled () ) - { -vlapic_set_vector (vector, &vlapic->regs->data[APIC_ISR ]); -vlapic_clear_irr (vector, vlapic); - } +if ( !force_ack && +vlapic_virtual_intr_delivery_enabled () ) +return 1 ; + +if (vlapic_test_vector (vector, &vlapic->regs->data[APIC_TMR ]) ) + goto done; + + isr =vlapic_find_lowest_vector (&vlapic->regs->data[APIC_ISR ]); +if ( isr >=0 && isr < vector ) + goto done; + +/* +* This vector is edge triggered and there are no lower priority +* vectors pending, so we can use APIC assist to avoid exiting +* for EOI. +*/ +viridian_start_apic_assist (v, vector); +done: +vlapic_set_vector (vector, &vlapic->regs->data[APIC_ISR ]); +vlapic_clear_irr (vector, vlapic);return 1 ; }xen/include/asm-x86/hvm/viridian.h +5
-0@@ -25,6 +25,7 @@ struct viridian_vcpuunion viridian_apic_assist msr;struct page_info *page;void *va; +int vector; } apic_assist;cpumask_var_t flush_cpumask; };@@ -125,6 +126,10 @@ void viridian_time_ref_count_thaw(struct domain *d);int viridian_vcpu_init (struct vcpu *v);void viridian_vcpu_deinit (struct vcpu *v); +void viridian_start_apic_assist (struct vcpu *v,int vector); +bool_t viridian_complete_apic_assist (struct vcpu *v,int *vector); +void viridian_abort_apic_assist (struct vcpu *v); +#endif /* __ASM_X86_HVM_VIRIDIAN_H__ */ /* xen/include/public/hvm/params.h +6
-1@@ -115,12 +115,17 @@#define _HVMPV_hcall_remote_tlb_flush 4#define HVMPV_hcall_remote_tlb_flush (1 << _HVMPV_hcall_remote_tlb_flush) +/* Use APIC assist */ +#define _HVMPV_apic_assist 5 +#define HVMPV_apic_assist (1 << _HVMPV_apic_assist) +#define HVMPV_feature_mask \ (HVMPV_base_freq | \ HVMPV_no_freq | \ HVMPV_time_ref_count | \ HVMPV_reference_tsc | \ - HVMPV_hcall_remote_tlb_flush) + HVMPV_hcall_remote_tlb_flush | \ + HVMPV_apic_assist)#endif Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/2] x86/hvm/viridian: Enable APIC assist enlightenment
Quoted 9 lines
-----Original Message-----
From: Konrad Rzeszutek Wilk [mailto:[email protected]]
Sent: 15 March 2016 23:18
To: Paul Durrant
Cc: [email protected]; Wei Liu; Stefano Stabellini; Andrew Cooper; Ian Jackson; Jan Beulich; Keir (Xen.org)
Subject: Re: [Xen-devel] [PATCH 2/2] x86/hvm/viridian: Enable APIC assist enlightenment
Quoted 7 lines
Quoted 3 lines · Paul Durrant
This patch adds code to enable the APIC assist enlightenment which, under certain conditions, means that the guest can avoid an EOI of the local APIC and thereby avoid a VMEXIT.
I noticed you deleted the comment having the spec.
That's because Microsoft killed the link and I couldn't find the spec online any more. But, thankfully, I've now found it again although it has actually taken me weeks to do so.
Quoted 10 lines
Would it be better if:
1) It was in the git commit description.
2) As part of the docs directory?Oh and the link is broken. An the link it points to is broken too.
So no spec for this, eh?
Now I've found it again I'll reference it.
Quoted 31 lines
Quoted 13 lines
Use of the enlightenment by the hypervisor is under control of the toolstack.
Signed-off-by Paul Durrant <[email protected]>Cc Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Wei Liu <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Andrew Cooper <[email protected]>Quoted 5 lines
--- docs/man/xl.cfg.pod.5 | 8 ++++++ tools/libxl/libxl_dom.c | 3 ++ tools/libxl/libxl_types.idl | 1 + xen/arch/x86/hvm/viridian.c | 59+++++++++++++++++++++++++++++++-------
Quoted 1 line
xen/arch/x86/hvm/vlapic.c | 58+++++++++++++++++++++++++++++++++----
docs/man/xl.cfg.pod.5 This set incorporates use of hypercalls for
Quoted 9 lines
xen/include/asm-x86/hvm/viridian.h | 5 ++++ xen/include/public/hvm/params.h | 7 ++++- 7 files changed, 124 insertions(+), 17 deletions(-)docs/man/xl.cfg.pod.5 +0
-0@@ -1484,6 +1484,14 @@ This set incorporates use of hypercalls forremote TLB flushing.
Quoted 9 lines
docs/man/xl.cfg.pod.5 This set incorporates use of hypercalls for remote TLB flushing. · line 1489
Quoted 6 lines
docs/man/xl.cfg.pod.5 +3
-0This enlightenment may improve performance of Windows guests running on hosts with higher levels of (physical) CPU contention. +=item B<apic_assist> + +This set incorporates use of the APIC assist page to avoid EOI ofWhat set? Option?
Set of viridian enlightenments. Read the pre-amble to the section.
Quoted 6 lines
docs/man/xl.cfg.pod.5 This set incorporates use of hypercalls for remote TLB flushing. · line 1491
Quoted 2 lines
docs/man/xl.cfg.pod.5 +2
-0+the local APIC. +This enlightenment may improve performance of Windows guests,may? How does this square with Intel vAPIC?
Could you mention that here? Or in the commit description?
Yes, I'll mention that it's clearly somewhat pointless if posted interrupts are in operation and that it has no effect in that case.
Quoted 1 line
And can non-Windows guests use it too?
If they adhere to the viridian spec., yes.
Quoted 7 lines
Or is this particular for Windows guests? IF so which ones?
docs/man/xl.cfg.pod.5 This set incorporates use of hypercalls for remote TLB flushing. · line 1493
Quoted 2 lines
docs/man/xl.cfg.pod.5 +2
-0+particularly those running PV drivers that make use of per-vcpu +event channel upcall vectors.What kind of PV drivers? Anybody?
Anybody's drivers that care to make use of FIFO event channels and that HVM op.
Quoted 74 lines
tools/libxl/libxl_dom.c static int hvm_set_viridian_features(libxl__gc *gc,
Quoted 9 lines
docs/man/xl.cfg.pod.5 +1
-0+ =item B<defaults> This is a special value that enables the default set of groups, whichtools/libxl/libxl_dom.c +0
-0@@ -253,6 +253,9 @@ static int hvm_set_viridian_features(libxl__gc *gc,
uint32_tdomid,tools/libxl/libxl_dom.c static int hvm_set_viridian_features(libxl__gc *gc, · line 253
Quoted 1 line
tools/libxl/libxl_dom.c +0
-0if (libxl_bitmap_test(&enlightenments,
LIBXL_VIRIDIAN_ENLIGHTENMENT_HCALL_REMOTE_TLB_FLUSH))tools/libxl/libxl_dom.c static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
Quoted 3 lines
tools/libxl/libxl_dom.c +1
-0mask |= HVMPV_hcall_remote_tlb_flush; + if (libxl_bitmap_test(&enlightenments,
LIBXL_VIRIDIAN_ENLIGHTENMENT_APIC_ASSIST))tools/libxl/libxl_types.idl libxl_viridian_enlightenment =
Quoted 10 lines
tools/libxl/libxl_dom.c +2
-0+ mask |= HVMPV_apic_assist; +if (mask !=0 && xc_hvm_param_set(CTX->xch, domid,tools/libxl/libxl_types.idl +0
-0@@ -221,6 +221,7 @@ libxl_viridian_enlightenment =Enumeration("viridian_enlightenment", [
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 221
Quoted 13 lines
tools/libxl/libxl_types.idl +1
-0(2, "time_ref_count"), (3, "reference_tsc"), (4, "hcall_remote_tlb_flush"), + (5, "apic_assist"), ]) libxl_hdtype = Enumeration("hdtype", [xen/arch/x86/hvm/viridian.c +0
-0@@ -221,16 +221,6 @@ static void initialize_apic_assist(struct vcpu *v) struct page_info *page = get_page_from_gfn(d, gmfn, NULL,
P2M_ALLOC);xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v)
Quoted 5 lines
xen/arch/x86/hvm/viridian.c +0
-3void *va; -/* -* We don't yet make use of the APIC assist page but by setting -* the CPUID3A_MSR_APIC_ACCESS bit in CPUID leaf 40000003 we are duty
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 227
Quoted 1 line
xen/arch/x86/hvm/viridian.c +0
-1-* bound to support the MSR. We therefore do just enough to keep windows
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v)
Quoted 3 lines
xen/arch/x86/hvm/viridian.c +0
-3-* happy. -* -* See http://msdn.microsoft.com/en- us/library/ff538657%28VS.85%29.aspx for
Quoted 21 lines
xen/arch/x86/hvm/viridian.c +11
-3-* details of how Windows uses the page. -*/ -if ( !page )return ;@@ -251,6 +241,55 @@ static void initialize_apic_assist(struct vcpu *v) v->arch.hvm_vcpu.viridian.apic_assist.page = page; v->arch.hvm_vcpu.viridian.apic_assist.va = va; + v->arch.hvm_vcpu.viridian.apic_assist.vector =-1 ; +} + +void viridian_start_apic_assist (struct vcpu *v,int vector) +{ +void *va = v->arch.hvm_vcpu.viridian.apic_assist.va; + +if ( !(viridian_feature_mask (v->domain) & HVMPV_apic_assist) || + !va ) +return ; +
Quoted 9 lines
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 260
Quoted 6 lines
xen/arch/x86/hvm/viridian.c +6
-0+/* +* If there is already an assist pending then something has gone +* wrong and the VM will most likely hang so force a crash now +* to make the problem clear. +*/ +if (v->arch.hvm_vcpu.viridian.apic_assist.vector >=0 )I think you need spaces sprinkled here.
I do indeed.
Quoted 7 lines
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 264
Quoted 4 lines
xen/arch/x86/hvm/viridian.c +4
-0+domain_crash (v->domain); + + v->arch.hvm_vcpu.viridian.apic_assist.vector = vector; + *(uint32_t *)va |=1u ;Oh my. What does that do? Why not
0xBADF00D
Is that prescriped in the spec?
The LSB is the only bit that has defined functionality. The next 31 bits are reserved and the rest of the page is undefined.
Quoted 3 lines
That looks quite unhealthy to do.
Reading the spec. again I do see that the reserved bits are defined to be zero, so it looks like I can use = rather than |=.
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/viridian.c +5
-0+} + +bool_t viridian_complete_apic_assist (struct vcpu *v,int *vector) +{ +void *va = v->arch.hvm_vcpu.viridian.apic_assist.va;
Quoted 9 lines
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 275
Quoted 6 lines
xen/arch/x86/hvm/viridian.c +6
-0+ +if ( !(viridian_feature_mask (v->domain) & HVMPV_apic_assist) || + !va ) +return 0 ; + +if ( *(uint32_t *)va &1 )Is that really part of the spec?
Yes.
Quoted 10 lines
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 279
Quoted 4 lines
xen/arch/x86/hvm/viridian.c +4
-0+return 0 ;/* Interrupt not yet processed by the guest */ + + *vector = v->arch.hvm_vcpu.viridian.apic_assist.vector; + v->arch.hvm_vcpu.viridian.apic_assist.vector =-1 ;Could you explain that bit please? Why the reset of the vector? Maybe it becomes clear later on.
/me grumbles about not spec.
Quoted 14 lines
xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 289
Quoted 10 lines
xen/arch/x86/hvm/viridian.c +10
-0+return 1 ; +} + +void viridian_abort_apic_assist (struct vcpu *v) +{ +void *va = v->arch.hvm_vcpu.viridian.apic_assist.va; + +if ( !(viridian_feature_mask (v->domain) & HVMPV_apic_assist) || + !va ) +return ;This is the third time I see that. Perhaps you can make a function out of it.
Yes, or maybe a macro.
Quoted 31 lines
xen/arch/x86/hvm/vlapic.c static int vlapic_find_highest_vector(const void
Quoted 19 lines
xen/arch/x86/hvm/viridian.c +3
-0+ + *(uint32_t *)va &= ~1u ; + v->arch.hvm_vcpu.viridian.apic_assist.vector =-1 ; }static void teardown_apic_assist (struct vcpu *v)xen/arch/x86/hvm/vlapic.c +1
-0@@ -38,6 +38,7 @@#include <asm/hvm/support.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/nestedhvm.h> +#include <asm/hvm/viridian.h> #include <public/hvm/ioreq.h> #include <public/hvm/params.h> @@ -95,6 +96,18 @@ static int vlapic_find_highest_vector(const void*bitmap)
xen/arch/x86/hvm/vlapic.c static int vlapic_find_highest_vector(const void *bitmap)
Quoted 9 lines
xen/arch/x86/hvm/vlapic.c +6
-0return (fls (word[word_offset*4 ]) -1 ) + (word_offset *32 ); } +static int vlapic_find_lowest_vector (const void *bitmap) +{ +const uint32_t *word = bitmap; +unsigned int word_offset; + +/* Work forwards through the bitmap (first 32-bit word in every four). */
Quoted 4 lines
Would it be easier said:
Operate on chunks of 4 bytes?
I was aping the comment in the 'find highest' function. I'll keep it as it is for consistency.
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/hvm/vlapic.c +6
-0+for ( word_offset =0 ; word_offset <NR_VECTORS /32 ; word_offset++) +if ( word[word_offset *4 ] ) +return (ffs (word[word_offset *4 ]) -1 ) + (word_offset *32 ); + +return -1 ; +}
Quoted 11 lines
xen/arch/x86/hvm/vlapic.c int vlapic_virtual_intr_delivery_enabled(void) · line 1173
Quoted 8 lines
xen/arch/x86/hvm/vlapic.c +1
-1/* * IRR-specific bitmap update & search routines. @@ -1157,7 +1170,7 @@ int vlapic_virtual_intr_delivery_enabled(void)int vlapic_has_pending_irq (struct vcpu *v) {struct vlapic *vlapic =vcpu_vlapic (v); -int irr, isr; +int irr, vector, isr;vector = -1?
No need. vector is not checked unless viridian_complete_apic_assist() returns 1, in which case it is guaranteed to be set.
Paul
Quoted 116 lines
xen/include/asm-
Quoted 67 lines
xen/arch/x86/hvm/vlapic.c +38
-5if ( !vlapic_enabled (vlapic) )return -1 ;@@ -1170,10 +1183,27 @@ int vlapic_has_pending_irq(struct vcpu *v) !nestedhvm_vcpu_in_guestmode(v) )return irr; +/* +* If APIC assist was used then there may have been no EOI so +* we need to clear the requisite bit from the ISR here, before +* comparing with the IRR. +*/ +if (viridian_complete_apic_assist (v, &vector) && + vector !=-1 ) +vlapic_clear_vector (vector, &vlapic->regs->data[APIC_ISR ]); + isr =vlapic_find_highest_isr (vlapic); isr = (isr !=-1 ) ? isr :0 ;if ( (isr &0xf0 ) >= (irr &0xf0 ) ) + { +/* +* There's already a higher priority vector pending so +* we need to abort any previous APIC assist to ensure there +* is an EOI. +*/ +viridian_abort_apic_assist (v);return -1 ; + }return irr; }@@ -1181,13 +1211,29 @@ int vlapic_has_pending_irq(struct vcpu *v)int vlapic_ack_pending_irq (struct vcpu *v,int vector,bool_t force_ack) {struct vlapic *vlapic =vcpu_vlapic (v); +int isr; -if ( force_ack || !vlapic_virtual_intr_delivery_enabled () ) - { -vlapic_set_vector (vector, &vlapic->regs->data[APIC_ISR ]); -vlapic_clear_irr (vector, vlapic); - } +if ( !force_ack && +vlapic_virtual_intr_delivery_enabled () ) +return 1 ; + +if (vlapic_test_vector (vector, &vlapic->regs->data[APIC_TMR ]) ) + goto done; + + isr =vlapic_find_lowest_vector (&vlapic->regs->data[APIC_ISR ]); +if ( isr >=0 && isr < vector ) + goto done; + +/* +* This vector is edge triggered and there are no lower priority +* vectors pending, so we can use APIC assist to avoid exiting +* for EOI. +*/ +viridian_start_apic_assist (v, vector); +done: +vlapic_set_vector (vector, &vlapic->regs->data[APIC_ISR ]); +vlapic_clear_irr (vector, vlapic);return 1 ; }xen/include/asm- renamed from xen/include/asm-x86/hvm/viridian.h +0
-0
x86/hvm/viridian.hxen/include/asm-x86/hvm/viridian.h void viridian_time_ref_count_thaw(struct domain
Quoted 12 lines
index c60c113..658d46a 100644
xen/include/asm-x86/hvm/viridian.h +1
-0@@ -25,6 +25,7 @@ struct viridian_vcpuunion viridian_apic_assist msr;struct page_info *page;void *va; +int vector; } apic_assist;cpumask_var_t flush_cpumask; };@@ -125,6 +126,10 @@ void viridian_time_ref_count_thaw(struct domain*d);
Review
Quoted 11 lines
xen/include/asm-x86/hvm/viridian.h +4
-0int viridian_vcpu_init (struct vcpu *v);void viridian_vcpu_deinit (struct vcpu *v); +void viridian_start_apic_assist (struct vcpu *v,int vector); +bool_t viridian_complete_apic_assist (struct vcpu *v,int *vector); +void viridian_abort_apic_assist (struct vcpu *v); +#endif /* __ASM_X86_HVM_VIRIDIAN_H__ */ /* (quoted diff) +0
-0
b/xen/include/public/hvm/params.hxen/include/public/hvm/params.h line 116
Quoted 6 lines
index 73d4718..e69c72c 100644
xen/include/public/hvm/params.h +0
-0@@ -115,12 +115,17 @@#define _HVMPV_hcall_remote_tlb_flush 4#define HVMPV_hcall_remote_tlb_flush (1 <<
_HVMPV_hcall_remote_tlb_flush)Quoted 16 lines
xen/include/public/hvm/params.h +6
-1+/* Use APIC assist */ +#define _HVMPV_apic_assist 5 +#define HVMPV_apic_assist (1 << _HVMPV_apic_assist) +#define HVMPV_feature_mask \ (HVMPV_base_freq | \ HVMPV_no_freq | \ HVMPV_time_ref_count | \ HVMPV_reference_tsc | \ - HVMPV_hcall_remote_tlb_flush) + HVMPV_hcall_remote_tlb_flush | \ + HVMPV_apic_assist)#endif
Quoted 8 lines
Quoted 8 lines
xen/include/public/hvm/params.h +0
-1--2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/2] x86/hvm/viridian: Enable APIC assist enlightenment
Quoted 16 lines
Quoted 11 lines
Quoted 1 line · On 16.03.16 at 16:02, <[email protected]> wrote:
From: Konrad Rzeszutek Wilk [mailto:[email protected]]
Sent: 15 March 2016 23:18xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 264
Quoted 4 lines · Paul Durrant
xen/arch/x86/hvm/viridian.c +4
-0+domain_crash (v->domain); + + v->arch.hvm_vcpu.viridian.apic_assist.vector = vector; + *(uint32_t *)va |=1u ;Oh my. What does that do? Why not
0xBADF00D
Is that prescriped in the spec?The LSB is the only bit that has defined functionality. The next 31 bits are reserved and the rest of the page is undefined.
Quoted 1 line
Quoted 5 lines
Quoted 2 lines
That looks quite unhealthy to do.
Reading the spec. again I do see that the reserved bits are defined to be zero, so it looks like I can use = rather than |=.
Wouldn't that put at risk forward compatibility?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/2] x86/hvm/viridian: Enable APIC assist enlightenment
Quoted 25 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 16 March 2016 16:28
To: Paul Durrant
Cc: Andrew Cooper; Ian Jackson; Stefano Stabellini; Wei Liu; xen- [email protected]; Konrad Rzeszutek Wilk; Keir (Xen.org)
Subject: RE: [Xen-devel] [PATCH 2/2] x86/hvm/viridian: Enable APIC assist enlightenmentQuoted 16 lines
Quoted 11 lines
Quoted 1 line · On 16.03.16 at 16:02, <[email protected]> wrote:
From: Konrad Rzeszutek Wilk [mailto:[email protected]]
Sent: 15 March 2016 23:18xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 264
Quoted 4 lines · Paul Durrant
xen/arch/x86/hvm/viridian.c +4
-0+domain_crash (v->domain); + + v->arch.hvm_vcpu.viridian.apic_assist.vector = vector; + *(uint32_t *)va |=1u ;Oh my. What does that do? Why not
0xBADF00D
Is that prescriped in the spec?The LSB is the only bit that has defined functionality. The next 31 bits are reserved and the rest of the page is undefined.
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
That looks quite unhealthy to do.
Reading the spec. again I do see that the reserved bits are defined to be zero, so it looks like I can use = rather than |=.
Wouldn't that put at risk forward compatibility?
The spec just says "Reserved to Zero" so it's hard to know what the right thing to do is until further bits are defined.
Paul
Quoted 1 line
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/2] x86/hvm/viridian: Enable APIC assist enlightenment
Quoted 22 lines
Quoted 22 lines
Quoted 1 line · On 16.03.16 at 18:23, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 16 March 2016 16:28Quoted 19 lines
Quoted 11 lines
Quoted 1 line · On 16.03.16 at 16:02, <[email protected]> wrote:
From: Konrad Rzeszutek Wilk [mailto:[email protected]]
Sent: 15 March 2016 23:18xen/arch/x86/hvm/viridian.c static void initialize_apic_assist(struct vcpu *v) · line 264
Quoted 4 lines · Paul Durrant
xen/arch/x86/hvm/viridian.c +4
-0+domain_crash (v->domain); + + v->arch.hvm_vcpu.viridian.apic_assist.vector = vector; + *(uint32_t *)va |=1u ;Oh my. What does that do? Why not
0xBADF00D
Is that prescriped in the spec?The LSB is the only bit that has defined functionality. The next 31 bits are reserved and the rest of the page is undefined.
Quoted 3 lines
That looks quite unhealthy to do.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Reading the spec. again I do see that the reserved bits are defined to be zero, so it looks like I can use = rather than |=.
Wouldn't that put at risk forward compatibility?
The spec just says "Reserved to Zero" so it's hard to know what the right thing to do is until further bits are defined.
The same as with any other reserved bits, I would say: Leave them alone.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel