x86 / viridian: remove the viridian_vcpu msg_pending bit mask
PATCH 1/1 x86 / viridian: remove the viridian_vcpu msg_pending bit mask
From: Paul Durrant <[email protected]>
The mask does not actually serve a useful purpose as we only use the SynIC for timer messages. Dropping the mask means that the EOM MSR handler essentially becomes a no-op. This means we can avoid setting 'message_pending' for timer messages and hence avoid a VMEXIT for the EOM.
---
Cc: Wei Liu <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
This should hopefully simplify Roger's "x86/vlapic: implement EOI callbacks" series a little.
--- xen/arch/x86/hvm/viridian/synic.c | 24 +----------------------- xen/arch/x86/hvm/vlapic.c | 2 -- xen/include/asm-x86/hvm/viridian.h | 2 -- 3 files changed, 1 insertion(+), 27 deletions(-)
xen/arch/x86/hvm/viridian/synic.c +1 -23
@@ -137,7 +137,6 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)if ( !(viridian_feature_mask (d) & HVMPV_synic) )return X86EMUL_EXCEPTION ; - vv->msg_pending =0 ;break ; case HV_X64_MSR_SINT0 ... HV_X64_MSR_SINT15:
@@ -168,9 +167,6 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)printk (XENLOG_G_INFO "%pv: VIRIDIAN SINT%u: vector: %x\n" , v, sintx, vector); -if ( new.polling ) -__clear_bit (sintx, &vv->msg_pending); - *vs = new;break ; }
@@ -334,9 +330,6 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, .DeliveryTime = delivery, }; -if (test_bit (sintx, &vv->msg_pending) ) -return false; -/* * To avoid using an atomic test-and-set, and barrier before calling * vlapic_set_irq(), this function must be called in context of the
@@ -346,12 +339,9 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, msg += sintx; +/* There is no need to set message_pending as we do not require an EOM */ if ( msg->header.message_type !=HVMSG_NONE ) - { - msg->header.message_flags.msg_pending =1 ; -__set_bit (sintx, &vv->msg_pending);return false; - } msg->header.message_type =HVMSG_TIMER_EXPIRED ; msg->header.message_flags.msg_pending =0 ;
@@ -380,18 +370,6 @@ bool viridian_synic_is_auto_eoi_sint(const struct vcpu *v,return vs->auto_eoi; } -void viridian_synic_ack_sint (const struct vcpu *v,unsigned int vector) -{ -struct viridian_vcpu *vv = v->arch.hvm.viridian; -unsigned int sintx = vv->vector_to_sintx[vector]; - -ASSERT (v == current); - -if ( sintx <ARRAY_SIZE (vv->sint) ) -__clear_bit (array_index_nospec (sintx,ARRAY_SIZE (vv->sint)), - &vv->msg_pending); -} -void viridian_synic_save_vcpu_ctxt (const struct vcpu *v,struct hvm_viridian_vcpu_context *ctxt) {
xen/arch/x86/hvm/vlapic.c +0 -2
@@ -466,8 +466,6 @@ void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector)if (vlapic_test_vector (vector, &vlapic->regs->data[APIC_TMR ]) )vioapic_update_EOI (d, vector); -else if (has_viridian_synic (d) ) -viridian_synic_ack_sint (v, vector);hvm_dpci_msi_eoi (d, vector); }
xen/include/asm-x86/hvm/viridian.h +0 -2
@@ -31,7 +31,6 @@ struct viridian_vcpustruct viridian_page vp_assist;bool apic_assist_pending;bool polled; -unsigned int msg_pending;uint64_t scontrol;uint64_t siefp;struct viridian_page simp;
@@ -89,7 +88,6 @@ void viridian_apic_assist_clear(const struct vcpu *v);void viridian_synic_poll (struct vcpu *v);bool viridian_synic_is_auto_eoi_sint (const struct vcpu *v,unsigned int vector); -void viridian_synic_ack_sint (const struct vcpu *v,unsigned int vector);#endif /* __ASM_X86_HVM_VIRIDIAN_H__ */
Signature · 1 line
2.20.1
Quoted 4 lines · Paul Durrant
From: Paul Durrant <[email protected]>
The mask does not actually serve a useful purpose as we only use the SynIC for timer messages.
Oh, I see. I assume it doesn't make sense because there can only be a single message pending (a timer one), and hence there isn't much value in doing this SynIC pending tracking?
Quoted 5 lines
Dropping the mask means that the EOM MSR handler
essentially becomes a no-op. This means we can avoid setting 'message_pending' for timer messages and hence avoid a VMEXIT for the EOM.Signed-off-by Paul Durrant <[email protected]>
I've got some question below and one nit.
Quoted 47 lines
---
Cc: Wei Liu <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>This should hopefully simplify Roger's "x86/vlapic: implement EOI callbacks" series a little.
--- xen/arch/x86/hvm/viridian/synic.c | 24 +----------------------- xen/arch/x86/hvm/vlapic.c | 2 -- xen/include/asm-x86/hvm/viridian.h | 2 -- 3 files changed, 1 insertion(+), 27 deletions(-)xen/arch/x86/hvm/viridian/synic.c +0
-7@@ -137,7 +137,6 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)if ( !(viridian_feature_mask (d) & HVMPV_synic) )return X86EMUL_EXCEPTION ; - vv->msg_pending =0 ;break ; case HV_X64_MSR_SINT0 ... HV_X64_MSR_SINT15:@@ -168,9 +167,6 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)printk (XENLOG_G_INFO "%pv: VIRIDIAN SINT%u: vector: %x\n" , v, sintx, vector); -if ( new.polling ) -__clear_bit (sintx, &vv->msg_pending); - *vs = new;break ; }@@ -334,9 +330,6 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, .DeliveryTime = delivery, }; -if (test_bit (sintx, &vv->msg_pending) ) -return false; -/* * To avoid using an atomic test-and-set, and barrier before calling * vlapic_set_irq(), this function must be called in context of the
xen/arch/x86/hvm/viridian/synic.c bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, · line 343
Quoted 5 lines
xen/arch/x86/hvm/viridian/synic.c +1
-0@@ -346,12 +339,9 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, msg += sintx; +/* There is no need to set message_pending as we do not require an EOM */ if ( msg->header.message_type !=HVMSG_NONE )
I think it's fine to use HVMSG_NONE ATM because Xen only knows about timer messages, but long term wouldn't it be better to use HVMSG_TIMER_EXPIRED?
Quoted 32 lines
xen/arch/x86/hvm/viridian/synic.c +0
-16- { - msg->header.message_flags.msg_pending =1 ; -__set_bit (sintx, &vv->msg_pending);return false; - } msg->header.message_type =HVMSG_TIMER_EXPIRED ; msg->header.message_flags.msg_pending =0 ;@@ -380,18 +370,6 @@ bool viridian_synic_is_auto_eoi_sint(const struct vcpu *v,return vs->auto_eoi; } -void viridian_synic_ack_sint (const struct vcpu *v,unsigned int vector) -{ -struct viridian_vcpu *vv = v->arch.hvm.viridian; -unsigned int sintx = vv->vector_to_sintx[vector]; - -ASSERT (v == current); - -if ( sintx <ARRAY_SIZE (vv->sint) ) -__clear_bit (array_index_nospec (sintx,ARRAY_SIZE (vv->sint)), - &vv->msg_pending); -} -void viridian_synic_save_vcpu_ctxt (const struct vcpu *v,struct hvm_viridian_vcpu_context *ctxt) {xen/arch/x86/hvm/vlapic.c +0
-0
xen/arch/x86/hvm/vlapic.c void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector) · line 470
Quoted 5 lines
xen/arch/x86/hvm/vlapic.c +0
-2@@ -466,8 +466,6 @@ void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector)if (vlapic_test_vector (vector, &vlapic->regs->data[APIC_TMR ]) )vioapic_update_EOI (d, vector); -else if (has_viridian_synic (d) ) -viridian_synic_ack_sint (v, vector);
Please also clean the comment above about SynIC SINTx being edge triggered.
Thanks, Roger.
Quoted 14 lines
-----Original Message-----
From: Roger Pau Monné <[email protected]>
Sent: 13 August 2020 11:16
To: Paul Durrant <[email protected]>
Cc: [email protected]; Durrant, Paul <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>
Subject: RE: [EXTERNAL] [PATCH] x86 / viridian: remove theviridian_vcpumsg_pendingbit maskCAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
On Thu, Aug 13, 2020 at 10:57:23AM +0100, Paul Durrant wrote:
Quoted 8 lines
Quoted 4 lines
From: Paul Durrant <[email protected]>
The mask does not actually serve a useful purpose as we only use the SynIC for timer messages.
Oh, I see. I assume it doesn't make sense because there can only be a single message pending (a timer one), and hence there isn't much value in doing this SynIC pending tracking?
Yes, exactly. We'd potentially need to add code back in if we use the synic for other message types (e.g. implementing HvPostMessage, perhaps on top of the argo framework).
Quoted 9 lines
Quoted 6 lines
Dropping the mask means that the EOM MSR handler
essentially becomes a no-op. This means we can avoid setting 'message_pending' for timer messages and hence avoid a VMEXIT for the EOM.Signed-off-by Paul Durrant <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>
Thanks.
Quoted 50 lines
I've got some question below and one nit.
Quoted 48 lines
---
Cc: Wei Liu <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>This should hopefully simplify Roger's "x86/vlapic: implement EOI callbacks" series a little.
--- xen/arch/x86/hvm/viridian/synic.c | 24 +----------------------- xen/arch/x86/hvm/vlapic.c | 2 -- xen/include/asm-x86/hvm/viridian.h | 2 -- 3 files changed, 1 insertion(+), 27 deletions(-)xen/arch/x86/hvm/viridian/synic.c +0
-7@@ -137,7 +137,6 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)if ( !(viridian_feature_mask (d) & HVMPV_synic) )return X86EMUL_EXCEPTION ; - vv->msg_pending =0 ;break ; case HV_X64_MSR_SINT0 ... HV_X64_MSR_SINT15:@@ -168,9 +167,6 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)printk (XENLOG_G_INFO "%pv: VIRIDIAN SINT%u: vector: %x\n" , v, sintx, vector); -if ( new.polling ) -__clear_bit (sintx, &vv->msg_pending); - *vs = new;break ; }@@ -334,9 +330,6 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, .DeliveryTime = delivery, }; -if (test_bit (sintx, &vv->msg_pending) ) -return false; -/* * To avoid using an atomic test-and-set, and barrier before calling * vlapic_set_irq(), this function must be called in context of the @@ -346,12 +339,9 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx,
Quoted 9 lines
xen/arch/x86/hvm/viridian/synic.c bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, · line 343
Quoted 4 lines
xen/arch/x86/hvm/viridian/synic.c +1
-0msg += sintx; +/* There is no need to set message_pending as we do not require an EOM */ if ( msg->header.message_type !=HVMSG_NONE )I think it's fine to use
HVMSG_NONEATM because Xen only knows about timer messages, but long term wouldn't it be better to useHVMSG_TIMER_EXPIRED?
I don't think so. The test is supposed to be 'is the slot occupied'. In future we could introduce support for new message types and hence a check of != HVMSG_NONE seems like the right thing to do.
Quoted 33 lines
Quoted 33 lines
xen/arch/x86/hvm/viridian/synic.c +0
-16- { - msg->header.message_flags.msg_pending =1 ; -__set_bit (sintx, &vv->msg_pending);return false; - } msg->header.message_type =HVMSG_TIMER_EXPIRED ; msg->header.message_flags.msg_pending =0 ;@@ -380,18 +370,6 @@ bool viridian_synic_is_auto_eoi_sint(const struct vcpu *v,return vs->auto_eoi; } -void viridian_synic_ack_sint (const struct vcpu *v,unsigned int vector) -{ -struct viridian_vcpu *vv = v->arch.hvm.viridian; -unsigned int sintx = vv->vector_to_sintx[vector]; - -ASSERT (v == current); - -if ( sintx <ARRAY_SIZE (vv->sint) ) -__clear_bit (array_index_nospec (sintx,ARRAY_SIZE (vv->sint)), - &vv->msg_pending); -} -void viridian_synic_save_vcpu_ctxt (const struct vcpu *v,struct hvm_viridian_vcpu_context *ctxt) {xen/arch/x86/hvm/vlapic.c +0
-0@@ -466,8 +466,6 @@ void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector)
Quoted 8 lines
xen/arch/x86/hvm/vlapic.c void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector) · line 470
Quoted 4 lines
xen/arch/x86/hvm/vlapic.c +0
-2if (vlapic_test_vector (vector, &vlapic->regs->data[APIC_TMR ]) )vioapic_update_EOI (d, vector); -else if (has_viridian_synic (d) ) -viridian_synic_ack_sint (v, vector);Please also clean the comment above about SynIC SINTx being edge triggered.
Oh yes, I'll send a v2.
Paul
Quoted 1 line
Thanks, Roger.