From 4cbaf3c13300b79d0386b567630f8e9c91ac5099 Mon Sep 17 00:00:00 2001 From: Roman Kagan Date: Fri, 21 Sep 2018 11:22:12 +0300 Subject: hyperv: add synic message delivery Add infrastructure to deliver SynIC messages to the SynIC message page. Note that KVM may also want to deliver (SynIC timer) messages to the same message slot. The problem is that the access to a SynIC message slot is controlled by the value of its .msg_type field which indicates if the slot is being owned by the hypervisor (zero) or by the guest (non-zero). This leaves no room for synchronizing multiple concurrent producers. The simplest way to deal with this for both KVM and QEMU is to only deliver messages in the vcpu thread. KVM already does this; this patch makes it for QEMU, too. Specifically, - add a function for posting messages, which only copies the message into the staging buffer if its free, and schedules a work on the corresponding vcpu to actually deliver it to the guest slot; - instead of a sint ack callback, set up the sint route with a message status callback. This function is called in a bh whenever there are updates to the message slot status: either the vcpu made definitive progress delivering the message from the staging buffer (succeeded or failed) or the guest issued EOM; the status is passed as an argument to the callback. Signed-off-by: Roman Kagan Message-Id: <20180921082217.29481-6-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- include/hw/hyperv/hyperv.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'include/hw/hyperv') diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h index 6fba4762c8..82d561fc88 100644 --- a/include/hw/hyperv/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -11,18 +11,30 @@ #define HW_HYPERV_HYPERV_H #include "cpu-qom.h" +#include "hw/hyperv/hyperv-proto.h" typedef struct HvSintRoute HvSintRoute; -typedef void (*HvSintAckClb)(void *data); + +/* + * Callback executed in a bottom-half when the status of posting the message + * becomes known, before unblocking the connection for further messages + */ +typedef void (*HvSintMsgCb)(void *data, int status); HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data); + HvSintMsgCb cb, void *cb_data); void hyperv_sint_route_ref(HvSintRoute *sint_route); void hyperv_sint_route_unref(HvSintRoute *sint_route); int hyperv_sint_route_set_sint(HvSintRoute *sint_route); +/* + * Submit a message to be posted in vcpu context. If the submission succeeds, + * the status of posting the message is reported via the callback associated + * with the @sint_route; until then no more messages are accepted. + */ +int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); + static inline uint32_t hyperv_vp_index(CPUState *cs) { return cs->cpu_index; -- cgit v1.2.3