From: Denis V. Lunev <[email protected]> synic_update() records the SynIC control bit and page addresses and maps the message and event pages at those addresses in one go. Loading the SynIC wants the two apart: VMBus creates its SINT routes from the control bit in its own post_load, so the state must be restored with the CPU section, while the mapping can wait.
Add hyperv_synic_update_state() and hyperv_synic_update_mr(), with x86 wrappers. hyperv_synic_update() keeps doing both. The mapping now compares where the page is mapped with the recorded address, rather than the old recorded address with the new one, which is the same thing while both are updated together. No functional change. CC: Paolo Bonzini <[email protected]> CC: Marcelo Tosatti <[email protected]> CC: Maciej S. Szmigiero <[email protected]> CC: Peter Xu <[email protected]> CC: Fabiano Rosas <[email protected]> CC: Zhao Liu <[email protected]> Signed-off-by: Denis V. Lunev <[email protected]> --- hw/hyperv/hyperv.c | 70 ++++++++++++++++++++++++----------- include/hw/hyperv/hyperv.h | 3 ++ target/i386/kvm/hyperv-stub.c | 8 ++++ target/i386/kvm/hyperv.c | 16 +++++++- target/i386/kvm/hyperv.h | 2 + 5 files changed, 76 insertions(+), 23 deletions(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 900ff80213..307e7a40ad 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -65,33 +65,61 @@ bool hyperv_is_synic_present(CPUState *cs) return get_synic(cs); } +static void synic_map_page(MemoryRegion *mr, hwaddr addr) +{ + if (memory_region_is_mapped(mr)) { + if (mr->addr == addr) { + return; + } + memory_region_del_subregion(get_system_memory(), mr); + } + if (addr) { + memory_region_add_subregion(get_system_memory(), addr, mr); + } +} + +static void synic_update_mr(SynICState *synic) +{ + synic_map_page(&synic->msg_page_mr, synic->msg_page_addr); + synic_map_page(&synic->event_page_mr, synic->event_page_addr); +} + +static void synic_set_state(SynICState *synic, bool sctl_enable, + hwaddr msg_page_addr, hwaddr event_page_addr) +{ + synic->sctl_enabled = sctl_enable; + synic->msg_page_addr = msg_page_addr; + synic->event_page_addr = event_page_addr; +} + static void synic_update(SynICState *synic, bool sctl_enable, hwaddr msg_page_addr, hwaddr event_page_addr) { + synic_set_state(synic, sctl_enable, msg_page_addr, event_page_addr); + synic_update_mr(synic); +} - synic->sctl_enabled = sctl_enable; - if (synic->msg_page_addr != msg_page_addr) { - if (synic->msg_page_addr) { - memory_region_del_subregion(get_system_memory(), - &synic->msg_page_mr); - } - if (msg_page_addr) { - memory_region_add_subregion(get_system_memory(), msg_page_addr, - &synic->msg_page_mr); - } - synic->msg_page_addr = msg_page_addr; +void hyperv_synic_update_state(CPUState *cs, bool sctl_enable, + hwaddr msg_page_addr, hwaddr event_page_addr) +{ + SynICState *synic = get_synic(cs); + + if (!synic) { + return; } - if (synic->event_page_addr != event_page_addr) { - if (synic->event_page_addr) { - memory_region_del_subregion(get_system_memory(), - &synic->event_page_mr); - } - if (event_page_addr) { - memory_region_add_subregion(get_system_memory(), event_page_addr, - &synic->event_page_mr); - } - synic->event_page_addr = event_page_addr; + + synic_set_state(synic, sctl_enable, msg_page_addr, event_page_addr); +} + +void hyperv_synic_update_mr(CPUState *cs) +{ + SynICState *synic = get_synic(cs); + + if (!synic) { + return; } + + synic_update_mr(synic); } void hyperv_synic_update(CPUState *cs, bool sctl_enable, diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h index 23091301d0..fcad9efb5b 100644 --- a/include/hw/hyperv/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -80,6 +80,9 @@ void hyperv_synic_add(CPUState *cs); void hyperv_synic_reset(CPUState *cs); void hyperv_synic_update(CPUState *cs, bool enable, hwaddr msg_page_addr, hwaddr event_page_addr); +void hyperv_synic_update_state(CPUState *cs, bool enable, + hwaddr msg_page_addr, hwaddr event_page_addr); +void hyperv_synic_update_mr(CPUState *cs); bool hyperv_is_synic_enabled(void); bool hyperv_is_synic_present(CPUState *cs); diff --git a/target/i386/kvm/hyperv-stub.c b/target/i386/kvm/hyperv-stub.c index 767a4c7e1a..c4d18f2cf5 100644 --- a/target/i386/kvm/hyperv-stub.c +++ b/target/i386/kvm/hyperv-stub.c @@ -53,6 +53,14 @@ void hyperv_x86_synic_update(X86CPU *cpu) { } +void hyperv_x86_synic_update_state(X86CPU *cpu) +{ +} + +void hyperv_x86_synic_update_mr(X86CPU *cpu) +{ +} + void hyperv_x86_set_vmbus_recommended_features_enabled(void) { } diff --git a/target/i386/kvm/hyperv.c b/target/i386/kvm/hyperv.c index 420c76b5ff..08001b26c5 100644 --- a/target/i386/kvm/hyperv.c +++ b/target/i386/kvm/hyperv.c @@ -42,7 +42,7 @@ void hyperv_x86_synic_reset(X86CPU *cpu) hyperv_synic_reset(CPU(cpu)); } -void hyperv_x86_synic_update(X86CPU *cpu) +void hyperv_x86_synic_update_state(X86CPU *cpu) { CPUX86State *env = &cpu->env; bool enable = env->msr_hv_synic_control & HV_SYNIC_ENABLE; @@ -50,7 +50,19 @@ void hyperv_x86_synic_update(X86CPU *cpu) (env->msr_hv_synic_msg_page & TARGET_PAGE_MASK) : 0; hwaddr event_page_addr = (env->msr_hv_synic_evt_page & HV_SIEFP_ENABLE) ? (env->msr_hv_synic_evt_page & TARGET_PAGE_MASK) : 0; - hyperv_synic_update(CPU(cpu), enable, msg_page_addr, event_page_addr); + hyperv_synic_update_state(CPU(cpu), enable, msg_page_addr, + event_page_addr); +} + +void hyperv_x86_synic_update_mr(X86CPU *cpu) +{ + hyperv_synic_update_mr(CPU(cpu)); +} + +void hyperv_x86_synic_update(X86CPU *cpu) +{ + hyperv_x86_synic_update_state(cpu); + hyperv_x86_synic_update_mr(cpu); } static void async_synic_update(CPUState *cs, run_on_cpu_data data) diff --git a/target/i386/kvm/hyperv.h b/target/i386/kvm/hyperv.h index a393a5d428..a0aee0cff3 100644 --- a/target/i386/kvm/hyperv.h +++ b/target/i386/kvm/hyperv.h @@ -26,6 +26,8 @@ int hyperv_x86_synic_add(X86CPU *cpu); int hyperv_enable_synic(X86CPU *cpu); void hyperv_x86_synic_reset(X86CPU *cpu); void hyperv_x86_synic_update(X86CPU *cpu); +void hyperv_x86_synic_update_state(X86CPU *cpu); +void hyperv_x86_synic_update_mr(X86CPU *cpu); void hyperv_x86_set_vmbus_recommended_features_enabled(void); -- 2.53.0
