From ab63fe1a921f0d8c9f1ce95d30560c8681f1adb6 Mon Sep 17 00:00:00 2001 From: Wu Zhou Date: Wed, 2 Aug 2023 02:03:43 -0700 Subject: [PATCH] hv: vm_event: send RTC change event in hv vRTC This patch adds support for HV vrtc vm_event. RTC change event is sent upon each date/time reg write. Those events will be handled in DM. DM will try to emit an RTC change event(to Libvirt) based on its strategy. Only support post-launched VMs. The DM event handler has already implemented the rtc chanage event. Those events will be processed the same way as vrtc events from DM vrtc. Tracked-On: #8547 Signed-off-by: Wu Zhou Reviewed-by: Junjie Mao --- hypervisor/dm/vrtc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hypervisor/dm/vrtc.c b/hypervisor/dm/vrtc.c index 01f7c4295..23ea7ae73 100644 --- a/hypervisor/dm/vrtc.c +++ b/hypervisor/dm/vrtc.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "mc146818rtc.h" @@ -549,6 +550,8 @@ static bool vrtc_write(struct acrn_vcpu *vcpu, uint16_t addr, size_t width, struct acrn_vrtc *vrtc = &vcpu->vm->vrtc; struct acrn_vrtc temp_vrtc; uint8_t mask = 0xFFU; + struct vm_event rtc_chg_event; + struct rtc_change_event_data *edata = (struct rtc_change_event_data *)rtc_chg_event.event_data; if ((width == 1U) && (addr == CMOS_ADDR_PORT)) { vrtc->addr = (uint8_t)(value & 0x7FU); @@ -595,6 +598,12 @@ static bool vrtc_write(struct acrn_vcpu *vcpu, uint16_t addr, size_t width, vrtc->offset_rtctime += after - current; vrtc->last_rtctime = VRTC_BROKEN_TIME; spinlock_release(&vrtc_rebase_lock); + if (is_postlaunched_vm(vcpu->vm) && vrtc_is_time_register(vrtc->addr)) { + rtc_chg_event.type = VM_EVENT_RTC_CHG; + edata->delta_time = after - current; + edata->last_time = current; + send_vm_event(vcpu->vm, &rtc_chg_event); + } break; } }