From: "Jan Beulich" Subject: [PATCH RFC 1/3] VMX: VMX: fix interaction of APIC-V and Viridian emulation Date: Fri, 21 Jun 2013 11:36:40 +0100 Message-ID: <51C448D802000078000DF962@nat28.tlf.novell.com> References: <51C4479D02000078000DF94F@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part7949E1A8.1__=" Return-path: In-Reply-To: <51C4479D02000078000DF94F@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Yang Z Zhang , Keir Fraser , Eddie Dong , Jun Nakajima List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part7949E1A8.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Viridian using a synthetic MSR for issuing EOI notifications bypasses the normal in-processor handling, which would clear GUEST_INTR_STATUS.SVI. Hence we need to do this in software in order for future interrupts to get delivered. Based on analysis by Yang Z Zhang . Also get the other virtual interrupt delivery related actors in sync with the newly added one in clearing the respective pointers (thus avoiding the call from generic code) when the feature is unavailable instead of checking feature availability in the actors. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -386,6 +386,9 @@ void vlapic_EOI_set(struct vlapic *vlapi =20 vlapic_clear_vector(vector, &vlapic->regs->data[APIC_ISR]); =20 + if ( hvm_funcs.handle_eoi ) + hvm_funcs.handle_eoi(vector); + if ( vlapic_test_and_clear_vector(vector, &vlapic->regs->data[APIC_TMR= ]) ) vioapic_update_EOI(vlapic_domain(vlapic), vector); =20 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -1411,13 +1411,10 @@ static void vmx_set_info_guest(struct vc =20 static void vmx_update_eoi_exit_bitmap(struct vcpu *v, u8 vector, u8 = trig) { - if ( cpu_has_vmx_virtual_intr_delivery ) - { - if (trig) - vmx_set_eoi_exit_bitmap(v, vector); - else - vmx_clear_eoi_exit_bitmap(v, vector); - } + if ( trig ) + vmx_set_eoi_exit_bitmap(v, vector); + else + vmx_clear_eoi_exit_bitmap(v, vector); } =20 static int vmx_virtual_intr_delivery_enabled(void) @@ -1430,9 +1427,6 @@ static void vmx_process_isr(int isr, str unsigned long status; u8 old; =20 - if ( !cpu_has_vmx_virtual_intr_delivery ) - return; - if ( isr < 0 ) isr =3D 0; =20 @@ -1502,6 +1496,15 @@ static void vmx_sync_pir_to_irr(struct v vlapic_set_vector(i, &vlapic->regs->data[APIC_IRR]); } =20 +static void vmx_handle_eoi(u8 vector) +{ + unsigned long status =3D __vmread(GUEST_INTR_STATUS); + + /* We need to clear the SVI field. */ + status &=3D VMX_GUEST_INTR_STATUS_SUBFIELD_BITMASK; + __vmwrite(GUEST_INTR_STATUS, status); +} + static struct hvm_function_table __initdata vmx_function_table =3D { .name =3D "VMX", .cpu_up_prepare =3D vmx_cpu_up_prepare, @@ -1554,6 +1557,7 @@ static struct hvm_function_table __initd .process_isr =3D vmx_process_isr, .deliver_posted_intr =3D vmx_deliver_posted_intr, .sync_pir_to_irr =3D vmx_sync_pir_to_irr, + .handle_eoi =3D vmx_handle_eoi, .nhvm_hap_walk_L1_p2m =3D nvmx_hap_walk_L1_p2m, }; =20 @@ -1580,6 +1584,13 @@ const struct hvm_function_table * __init =20 setup_ept_dump(); } + + if ( !cpu_has_vmx_virtual_intr_delivery ) + { + vmx_function_table.update_eoi_exit_bitmap =3D NULL; + vmx_function_table.process_isr =3D NULL; + vmx_function_table.handle_eoi =3D NULL; + } =20 if ( cpu_has_vmx_posted_intr_processing ) alloc_direct_apic_vector(&posted_intr_vector, event_check_interrup= t); --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -186,6 +186,7 @@ struct hvm_function_table { void (*process_isr)(int isr, struct vcpu *v); void (*deliver_posted_intr)(struct vcpu *v, u8 vector); void (*sync_pir_to_irr)(struct vcpu *v); + void (*handle_eoi)(u8 vector); =20 /*Walk nested p2m */ int (*nhvm_hap_walk_L1_p2m)(struct vcpu *v, paddr_t L2_gpa, --=__Part7949E1A8.1__= Content-Type: text/plain; name="x86-VMX-Viridian-APICV.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-VMX-Viridian-APICV.patch" VMX: fix interaction of APIC-V and Viridian emulation=0A=0AViridian using = a synthetic MSR for issuing EOI notifications bypasses=0Athe normal = in-processor handling, which would clear=0AGUEST_INTR_STATUS.SVI. Hence we = need to do this in software in order=0Afor future interrupts to get = delivered.=0A=0ABased on analysis by Yang Z Zhang .= =0A=0AAlso get the other virtual interrupt delivery related actors in = sync=0Awith the newly added one in clearing the respective pointers = (thus=0Aavoiding the call from generic code) when the feature is unavailabl= e=0Ainstead of checking feature availability in the actors.=0A=0ASigned-off= -by: Jan Beulich =0A=0A--- a/xen/arch/x86/hvm/vlapic.c= =0A+++ b/xen/arch/x86/hvm/vlapic.c=0A@@ -386,6 +386,9 @@ void vlapic_EOI_se= t(struct vlapic *vlapi=0A =0A vlapic_clear_vector(vector, &vlapic->regs= ->data[APIC_ISR]);=0A =0A+ if ( hvm_funcs.handle_eoi )=0A+ = hvm_funcs.handle_eoi(vector);=0A+=0A if ( vlapic_test_and_clear_vector(= vector, &vlapic->regs->data[APIC_TMR]) )=0A vioapic_update_EOI(vlap= ic_domain(vlapic), vector);=0A =0A--- a/xen/arch/x86/hvm/vmx/vmx.c=0A+++ = b/xen/arch/x86/hvm/vmx/vmx.c=0A@@ -1411,13 +1411,10 @@ static void = vmx_set_info_guest(struct vc=0A =0A static void vmx_update_eoi_exit_bitmap(= struct vcpu *v, u8 vector, u8 trig)=0A {=0A- if ( cpu_has_vmx_virtual_in= tr_delivery )=0A- {=0A- if (trig)=0A- vmx_set_eoi_exit= _bitmap(v, vector);=0A- else=0A- vmx_clear_eoi_exit_bitma= p(v, vector);=0A- }=0A+ if ( trig )=0A+ vmx_set_eoi_exit_bitma= p(v, vector);=0A+ else=0A+ vmx_clear_eoi_exit_bitmap(v, = vector);=0A }=0A =0A static int vmx_virtual_intr_delivery_enabled(void)=0A@= @ -1430,9 +1427,6 @@ static void vmx_process_isr(int isr, str=0A = unsigned long status;=0A u8 old;=0A =0A- if ( !cpu_has_vmx_virtual_i= ntr_delivery )=0A- return;=0A-=0A if ( isr < 0 )=0A isr = =3D 0;=0A =0A@@ -1502,6 +1496,15 @@ static void vmx_sync_pir_to_irr(struct = v=0A vlapic_set_vector(i, &vlapic->regs->data[APIC_IRR]);=0A }=0A = =0A+static void vmx_handle_eoi(u8 vector)=0A+{=0A+ unsigned long status = =3D __vmread(GUEST_INTR_STATUS);=0A+=0A+ /* We need to clear the SVI = field. */=0A+ status &=3D VMX_GUEST_INTR_STATUS_SUBFIELD_BITMASK;=0A+ = __vmwrite(GUEST_INTR_STATUS, status);=0A+}=0A+=0A static struct hvm_functi= on_table __initdata vmx_function_table =3D {=0A .name = =3D "VMX",=0A .cpu_up_prepare =3D vmx_cpu_up_prepare,=0A@@ = -1554,6 +1557,7 @@ static struct hvm_function_table __initd=0A = .process_isr =3D vmx_process_isr,=0A .deliver_posted_intr = =3D vmx_deliver_posted_intr,=0A .sync_pir_to_irr =3D vmx_sync_pir_= to_irr,=0A+ .handle_eoi =3D vmx_handle_eoi,=0A .nhvm_hap_w= alk_L1_p2m =3D nvmx_hap_walk_L1_p2m,=0A };=0A =0A@@ -1580,6 +1584,13 @@ = const struct hvm_function_table * __init=0A =0A setup_ept_dump();= =0A }=0A+=0A+ if ( !cpu_has_vmx_virtual_intr_delivery )=0A+ = {=0A+ vmx_function_table.update_eoi_exit_bitmap =3D NULL;=0A+ = vmx_function_table.process_isr =3D NULL;=0A+ vmx_function_table.han= dle_eoi =3D NULL;=0A+ }=0A =0A if ( cpu_has_vmx_posted_intr_process= ing )=0A alloc_direct_apic_vector(&posted_intr_vector, event_check_= interrupt);=0A--- a/xen/include/asm-x86/hvm/hvm.h=0A+++ b/xen/include/asm-x= 86/hvm/hvm.h=0A@@ -186,6 +186,7 @@ struct hvm_function_table {=0A void = (*process_isr)(int isr, struct vcpu *v);=0A void (*deliver_posted_intr)= (struct vcpu *v, u8 vector);=0A void (*sync_pir_to_irr)(struct vcpu = *v);=0A+ void (*handle_eoi)(u8 vector);=0A =0A /*Walk nested p2m = */=0A int (*nhvm_hap_walk_L1_p2m)(struct vcpu *v, paddr_t L2_gpa,=0A --=__Part7949E1A8.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part7949E1A8.1__=--