x86/viridian: use hv_timer_message_payload struct
PATCH 1/1 x86/viridian: use hv_timer_message_payload struct
Instead of open-coding the struct type in viridian_synic_deliver_timer_msg(). Additionally expand the union field in hv_message struct to contain the timer payload, this way the memcpy in viridian_synic_deliver_timer_msg() can be replaced with a struct assign.
No functional change intended.
--- xen/arch/x86/hvm/viridian/synic.c | 17 ++++++---------- xen/arch/x86/include/asm/guest/hyperv-tlfs.h | 21 ++++++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-)
xen/arch/x86/hvm/viridian/synic.c +6 -11
@@ -327,15 +327,10 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx,struct viridian_vcpu *vv = v->arch.hvm.viridian;const union hv_synic_sint *vs = &vv->sint[sintx];struct hv_message *msg = vv->simp.ptr; -struct { -uint32_t TimerIndex; -uint32_t Reserved; -uint64_t ExpirationTime; -uint64_t DeliveryTime; - } payload = { - .TimerIndex = index, - .ExpirationTime = expiration, - .DeliveryTime = delivery, +const struct hv_timer_message_payload payload = { + .timer_index = index, + .expiration_time = expiration, + .delivery_time = delivery, };/* Don't assume SIM page to be mapped. */
@@ -359,8 +354,8 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, msg->header.message_flags.msg_pending =0 ; msg->header.payload_size =sizeof (payload); -BUILD_BUG_ON (sizeof (payload) >sizeof (msg->u.payload)); -memcpy (msg->u.payload, &payload,sizeof (payload)); +BUILD_BUG_ON (sizeof (msg->payload.timer) >sizeof (msg->payload.raw)); + msg->payload.timer = payload;if ( !vs->masked &&vlapic_enabled (vcpu_vlapic (v)) )vlapic_set_irq (vcpu_vlapic (v), vs->vector,0 );
xen/arch/x86/include/asm/guest/hyperv-tlfs.h +11 -10
@@ -527,12 +527,21 @@ struct hv_message_header { }; }; +/* Define timer message payload structure. */ +struct hv_timer_message_payload { +uint32_t timer_index; +uint32_t reserved; +uint64_t expiration_time;/* When the timer expired */ +uint64_t delivery_time;/* When the message was delivered */ +}; +/* Define synthetic interrupt controller message format. */ struct hv_message {struct hv_message_header header;union { -uint64_t payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT ]; - } u; +struct hv_timer_message_payload timer; +uint64_t raw[HV_MESSAGE_PAYLOAD_QWORD_COUNT ]; + } payload; };/* Define the synthetic interrupt message page layout. */
@@ -540,14 +549,6 @@ struct hv_message_page {struct hv_message sint_message[HV_SYNIC_SINT_COUNT ]; }; -/* Define timer message payload structure. */ -struct hv_timer_message_payload { -uint32_t timer_index; -uint32_t reserved; -uint64_t expiration_time;/* When the timer expired */ -uint64_t delivery_time;/* When the message was delivered */ -}; -struct hv_nested_enlightenments_control {struct {uint32_t directhypercall:1 ;
Signature · 1 line
2.51.0
Quoted 11 lines · Roger Pau Monne
xen/arch/x86/hvm/viridian/synic.c +0
-3@@ -327,15 +327,10 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx,struct viridian_vcpu *vv = v->arch.hvm.viridian;const union hv_synic_sint *vs = &vv->sint[sintx];struct hv_message *msg = vv->simp.ptr; -struct { -uint32_t TimerIndex; -uint32_t Reserved;
xen/arch/x86/hvm/viridian/synic.c bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, · line 333
Quoted 10 lines
xen/arch/x86/hvm/viridian/synic.c +4
-6-uint64_t ExpirationTime; -uint64_t DeliveryTime; - } payload = { - .TimerIndex = index, - .ExpirationTime = expiration, - .DeliveryTime = delivery, +const struct hv_timer_message_payload payload = { + .timer_index = index, + .expiration_time = expiration, + .delivery_time = delivery,
Align these = for readability?
xen/arch/x86/hvm/viridian/synic.c bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, · line 357
Quoted 10 lines
xen/arch/x86/hvm/viridian/synic.c +1
-2};/* Don't assume SIM page to be mapped. */ @@ -359,8 +354,8 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, msg->header.message_flags.msg_pending =0 ; msg->header.payload_size =sizeof (payload); -BUILD_BUG_ON (sizeof (payload) >sizeof (msg->u.payload)); -memcpy (msg->u.payload, &payload,sizeof (payload)); +BUILD_BUG_ON (sizeof (msg->payload.timer) >sizeof (msg->payload.raw));
This BUILD_BUG_ON() was only needed because of the memcpy() between different types. With structure assignment, the compiler will tell you if the type mismatches.
Therefore, it's safe to drop.
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Roger Pau Monne
xen/arch/x86/hvm/viridian/synic.c +0
-7@@ -327,15 +327,10 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx,struct viridian_vcpu *vv = v->arch.hvm.viridian;const union hv_synic_sint *vs = &vv->sint[sintx];struct hv_message *msg = vv->simp.ptr; -struct { -uint32_t TimerIndex; -uint32_t Reserved; -uint64_t ExpirationTime; -uint64_t DeliveryTime; - } payload = { - .TimerIndex = index,
Quoted 8 lines
xen/arch/x86/hvm/viridian/synic.c bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, · line 333
Quoted 6 lines
xen/arch/x86/hvm/viridian/synic.c +4
-2- .ExpirationTime = expiration, - .DeliveryTime = delivery, +const struct hv_timer_message_payload payload = { + .timer_index = index, + .expiration_time = expiration, + .delivery_time = delivery,Align these = for readability?
Sure, can do.
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/hvm/viridian/synic.c +0
-0};/* Don't assume SIM page to be mapped. */ @@ -359,8 +354,8 @@ bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, msg->header.message_flags.msg_pending =0 ; msg->header.payload_size =sizeof (payload);
Quoted 7 lines
xen/arch/x86/hvm/viridian/synic.c bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx, · line 357
Quoted 3 lines
xen/arch/x86/hvm/viridian/synic.c +1
-2-BUILD_BUG_ON (sizeof (payload) >sizeof (msg->u.payload)); -memcpy (msg->u.payload, &payload,sizeof (payload)); +BUILD_BUG_ON (sizeof (msg->payload.timer) >sizeof (msg->payload.raw));This
BUILD_BUG_ON()was only needed because of thememcpy()between different types. With structure assignment, the compiler will tell you if the type mismatches.
I've keep it to ensure the size of the hv_timer_message_payload doesn't exceed the maximum payload size (240 bytes), as msg->payload.raw is the maximum payload size defined by the standard.
Quoted 3 lines
Therefore, it's safe to drop.
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
Let me know if you are fine with keeping the BUILD_BUG_ON() given the justification above, as that would be my preference.
Thanks, Roger.