* [PATCH qemu v8 0/1] Honor guest PAT on x86, absent Bochs display @ 2025-10-14 16:32 ~myrslint 2025-10-14 16:23 ` [PATCH qemu v8 1/1] " ~myrslint 0 siblings, 1 reply; 5+ messages in thread From: ~myrslint @ 2025-10-14 16:32 UTC (permalink / raw) To: qemu-devel; +Cc: Dmitry Osipenko, Paolo Bonzini, Gerd Hoffmann This revision rectifies the mistake I had made in preparing v7. Comment formatting was also corrected. As with the previous versions of the patch it is intended to address the following issue: https://gitlab.com/qemu-project/qemu/-/issues/2943 myrslint (1): Honor guest PAT on x86, absent Bochs display accel/kvm/kvm-all.c | 1 + accel/stubs/kvm-stub.c | 1 + hw/display/bochs-display.c | 17 +++++++++++++++ include/system/kvm.h | 9 ++++++++ target/i386/kvm/kvm.c | 42 +++++++++++++++++++++++++++++++------- 5 files changed, 63 insertions(+), 7 deletions(-) -- 2.49.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH qemu v8 1/1] Honor guest PAT on x86, absent Bochs display 2025-10-14 16:32 [PATCH qemu v8 0/1] Honor guest PAT on x86, absent Bochs display ~myrslint @ 2025-10-14 16:23 ` ~myrslint 2025-10-14 20:01 ` Dmitry Osipenko 0 siblings, 1 reply; 5+ messages in thread From: ~myrslint @ 2025-10-14 16:23 UTC (permalink / raw) To: qemu-devel; +Cc: Dmitry Osipenko, Paolo Bonzini, Gerd Hoffmann From: myrslint <qemu.haziness801@passinbox.com> On x86_64, where most CPUs support self-snoop, it is preferrable to always honor guest PAT. Not doing so is a quirk. There is a default enabled KVM quirk flag which enforces not doing so due to a former bug in Bochs display driver. The bug has been fixed but not enough has yet passed since so we only disable said quirk flag if a Bochs display is not configured for the virtual machine. This commit also moves around a bit of code that would be called when the initialization of a VM is done. Signed-off-by: myrslint <qemu.haziness801@passinbox.com> --- accel/kvm/kvm-all.c | 1 + accel/stubs/kvm-stub.c | 1 + hw/display/bochs-display.c | 17 +++++++++++++++ include/system/kvm.h | 9 ++++++++ target/i386/kvm/kvm.c | 42 +++++++++++++++++++++++++++++++------- 5 files changed, 63 insertions(+), 7 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 58802f7c3c..b1ae36d6a1 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -103,6 +103,7 @@ bool kvm_readonly_mem_allowed; bool kvm_vm_attributes_allowed; bool kvm_msi_use_devid; bool kvm_pre_fault_memory_supported; +bool kvm_bochs_drm_quirk; static bool kvm_has_guest_debug; static int kvm_sstep_flags; static bool kvm_immediate_exit; diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index 68cd33ba97..a69c89e1ad 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -24,6 +24,7 @@ bool kvm_gsi_direct_mapping; bool kvm_allowed; bool kvm_readonly_mem_allowed; bool kvm_msi_use_devid; +bool kvm_bochs_drm_quirk; void kvm_flush_coalesced_mmio_buffer(void) { diff --git a/hw/display/bochs-display.c b/hw/display/bochs-display.c index ad2821c974..e8def68b41 100644 --- a/hw/display/bochs-display.c +++ b/hw/display/bochs-display.c @@ -20,6 +20,8 @@ #include "ui/qemu-pixman.h" #include "qom/object.h" +#include "system/kvm.h" + typedef struct BochsDisplayMode { pixman_format_code_t format; uint32_t bytepp; @@ -309,6 +311,21 @@ static void bochs_display_realize(PCIDevice *dev, Error **errp) } memory_region_set_log(&s->vram, true, DIRTY_MEMORY_VGA); + + /* + * On x86_64, where most CPUs support self-snoop, it is preferrable to + * always honor guest PAT. Not doing so is a quirk. There is a default + * enabled KVM quirk flag which enforces not doing so due to a former bug + * in Bochs display driver. + * + * The bug has been fixed but not enough has yet passed since so we only + * disable said quirk flag if a Bochs display is not configured for the + * virtual machine. + * + * The following flag tells KVM initialization code not to disable that + * quirk flag. + */ + kvm_bochs_drm_quirk = true; } static bool bochs_display_get_big_endian_fb(Object *obj, Error **errp) diff --git a/include/system/kvm.h b/include/system/kvm.h index 4fc09e3891..45ddb2e0ee 100644 --- a/include/system/kvm.h +++ b/include/system/kvm.h @@ -43,6 +43,7 @@ extern bool kvm_gsi_direct_mapping; extern bool kvm_readonly_mem_allowed; extern bool kvm_msi_use_devid; extern bool kvm_pre_fault_memory_supported; +extern bool kvm_bochs_drm_quirk; #define kvm_enabled() (kvm_allowed) /** @@ -144,6 +145,13 @@ extern bool kvm_pre_fault_memory_supported; */ #define kvm_msi_devid_required() (kvm_msi_use_devid) +/** + * kvm_has_bochs_drm: + * Returns: true if KVM is possible and a Bochs DRM driver is + * in use for display. + */ +#define kvm_has_bochs_drm() (kvm_bochs_drm_quirk) + #else #define kvm_enabled() (0) @@ -158,6 +166,7 @@ extern bool kvm_pre_fault_memory_supported; #define kvm_gsi_direct_mapping() (false) #define kvm_readonly_mem_enabled() (false) #define kvm_msi_devid_required() (false) +#define kvm_has_bochs_drm() (false) #endif /* CONFIG_KVM_IS_POSSIBLE */ diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index db40caa341..4d2a01ca0e 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2692,13 +2692,13 @@ static bool kvm_rdmsr_pkg_energy_status(X86CPU *cpu, return true; } -static Notifier smram_machine_done; +static Notifier kvm_machine_done; static KVMMemoryListener smram_listener; static AddressSpace smram_address_space; static MemoryRegion smram_as_root; static MemoryRegion smram_as_mem; -static void register_smram_listener(Notifier *n, void *unused) +static void register_smram_listener(void) { CPUState *cpu; MemoryRegion *smram = @@ -2731,6 +2731,37 @@ static void register_smram_listener(Notifier *n, void *unused) } } +static bool kvm_x86_smm_enabled(void) +{ + return object_dynamic_cast(OBJECT(current_machine), TYPE_X86_MACHINE) && + x86_machine_is_smm_enabled(X86_MACHINE(current_machine)); +} + +static int kvm_x86_disable_quirsk2_mask(void) +{ + return kvm_check_extension(kvm_state, KVM_CAP_DISABLE_QUIRKS2); +} + +static int kvm_disable_ignore_guest_pat(void) +{ + return kvm_vm_enable_cap(kvm_state, KVM_CAP_DISABLE_QUIRKS2, 0, \ + KVM_X86_QUIRK_IGNORE_GUEST_PAT); +} + +static void handle_machine_done(Notifier *n, void *unused) +{ + if (kvm_x86_smm_enabled()) { + register_smram_listener(); + } + if (!kvm_has_bochs_drm() && \ + (kvm_x86_disable_quirsk2_mask() & KVM_X86_QUIRK_IGNORE_GUEST_PAT)) { + if (kvm_disable_ignore_guest_pat()) { + error_report("KVM_X86_QUIRK_IGNORE_GUEST_PAT available and " + "modifiable but we failed to disable it"); + } + } +} + static void *kvm_msr_energy_thread(void *data) { KVMState *s = data; @@ -3311,11 +3342,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) return ret; } - if (object_dynamic_cast(OBJECT(ms), TYPE_X86_MACHINE) && - x86_machine_is_smm_enabled(X86_MACHINE(ms))) { - smram_machine_done.notify = register_smram_listener; - qemu_add_machine_init_done_notifier(&smram_machine_done); - } + kvm_machine_done.notify = handle_machine_done; + qemu_add_machine_init_done_notifier(&kvm_machine_done); if (enable_cpu_pm) { ret = kvm_vm_enable_disable_exits(s); -- 2.49.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH qemu v8 1/1] Honor guest PAT on x86, absent Bochs display 2025-10-14 16:23 ` [PATCH qemu v8 1/1] " ~myrslint @ 2025-10-14 20:01 ` Dmitry Osipenko 2025-10-14 20:07 ` Dmitry Osipenko 0 siblings, 1 reply; 5+ messages in thread From: Dmitry Osipenko @ 2025-10-14 20:01 UTC (permalink / raw) To: ~myrslint, qemu-devel, Paolo Bonzini; +Cc: Gerd Hoffmann On 10/14/25 19:23, ~myrslint wrote: > From: myrslint <qemu.haziness801@passinbox.com> > > On x86_64, where most CPUs support self-snoop, it is preferrable to > always honor guest PAT. Not doing so is a quirk. There is a default > enabled KVM quirk flag which enforces not doing so due to a former bug > in Bochs display driver. > > The bug has been fixed but not enough has yet passed since so we only > disable said quirk flag if a Bochs display is not configured for the > virtual machine. > > This commit also moves around a bit of code that would be called when > the initialization of a VM is done. > > Signed-off-by: myrslint <qemu.haziness801@passinbox.com> > --- > accel/kvm/kvm-all.c | 1 + > accel/stubs/kvm-stub.c | 1 + > hw/display/bochs-display.c | 17 +++++++++++++++ > include/system/kvm.h | 9 ++++++++ > target/i386/kvm/kvm.c | 42 +++++++++++++++++++++++++++++++------- > 5 files changed, 63 insertions(+), 7 deletions(-) Looks perfect. Now up to Paolo to review further and apply the patch. Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> -- Best regards, Dmitry ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH qemu v8 1/1] Honor guest PAT on x86, absent Bochs display 2025-10-14 20:01 ` Dmitry Osipenko @ 2025-10-14 20:07 ` Dmitry Osipenko 2025-11-05 21:45 ` Dmitry Osipenko 0 siblings, 1 reply; 5+ messages in thread From: Dmitry Osipenko @ 2025-10-14 20:07 UTC (permalink / raw) To: ~myrslint, qemu-devel, Paolo Bonzini; +Cc: Gerd Hoffmann On 10/14/25 23:01, Dmitry Osipenko wrote: > On 10/14/25 19:23, ~myrslint wrote: >> From: myrslint <qemu.haziness801@passinbox.com> >> >> On x86_64, where most CPUs support self-snoop, it is preferrable to >> always honor guest PAT. Not doing so is a quirk. There is a default >> enabled KVM quirk flag which enforces not doing so due to a former bug >> in Bochs display driver. >> >> The bug has been fixed but not enough has yet passed since so we only >> disable said quirk flag if a Bochs display is not configured for the >> virtual machine. >> >> This commit also moves around a bit of code that would be called when >> the initialization of a VM is done. >> >> Signed-off-by: myrslint <qemu.haziness801@passinbox.com> >> --- >> accel/kvm/kvm-all.c | 1 + >> accel/stubs/kvm-stub.c | 1 + >> hw/display/bochs-display.c | 17 +++++++++++++++ >> include/system/kvm.h | 9 ++++++++ >> target/i386/kvm/kvm.c | 42 +++++++++++++++++++++++++++++++------- >> 5 files changed, 63 insertions(+), 7 deletions(-) > > Looks perfect. Now up to Paolo to review further and apply the patch. > > Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Ah, the commit title still isn't ideal. It should be prefixed with "i386/kvm:" like other kvm commits are in QEMU. Likely Paolo could correct it while applying if v9 won't be needed. -- Best regards, Dmitry ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH qemu v8 1/1] Honor guest PAT on x86, absent Bochs display 2025-10-14 20:07 ` Dmitry Osipenko @ 2025-11-05 21:45 ` Dmitry Osipenko 0 siblings, 0 replies; 5+ messages in thread From: Dmitry Osipenko @ 2025-11-05 21:45 UTC (permalink / raw) To: ~myrslint, qemu-devel, Paolo Bonzini; +Cc: Gerd Hoffmann On 10/14/25 23:07, Dmitry Osipenko wrote: > On 10/14/25 23:01, Dmitry Osipenko wrote: >> On 10/14/25 19:23, ~myrslint wrote: >>> From: myrslint <qemu.haziness801@passinbox.com> >>> >>> On x86_64, where most CPUs support self-snoop, it is preferrable to >>> always honor guest PAT. Not doing so is a quirk. There is a default >>> enabled KVM quirk flag which enforces not doing so due to a former bug >>> in Bochs display driver. >>> >>> The bug has been fixed but not enough has yet passed since so we only >>> disable said quirk flag if a Bochs display is not configured for the >>> virtual machine. >>> >>> This commit also moves around a bit of code that would be called when >>> the initialization of a VM is done. >>> >>> Signed-off-by: myrslint <qemu.haziness801@passinbox.com> >>> --- >>> accel/kvm/kvm-all.c | 1 + >>> accel/stubs/kvm-stub.c | 1 + >>> hw/display/bochs-display.c | 17 +++++++++++++++ >>> include/system/kvm.h | 9 ++++++++ >>> target/i386/kvm/kvm.c | 42 +++++++++++++++++++++++++++++++------- >>> 5 files changed, 63 insertions(+), 7 deletions(-) >> >> Looks perfect. Now up to Paolo to review further and apply the patch. >> >> Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > > Ah, the commit title still isn't ideal. It should be prefixed with > "i386/kvm:" like other kvm commits are in QEMU. Likely Paolo could > correct it while applying if v9 won't be needed. Tested on older Intel IVB machine where virtio-gpu hostmem doesn't work without this patch. Please add my r-b and t-b, specify your full name "Myrsky Lintu" in the Signed-off-by of the commit msg, correct the patch title prefix and send the v9. Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> # intel-ivb -- Best regards, Dmitry ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-05 21:46 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-10-14 16:32 [PATCH qemu v8 0/1] Honor guest PAT on x86, absent Bochs display ~myrslint 2025-10-14 16:23 ` [PATCH qemu v8 1/1] " ~myrslint 2025-10-14 20:01 ` Dmitry Osipenko 2025-10-14 20:07 ` Dmitry Osipenko 2025-11-05 21:45 ` Dmitry Osipenko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).