qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: ~myrslint <myrslint@git.sr.ht>
Cc: qemu-devel@nongnu.org,  ~myrslint <myrskylintu@proton.me>,
	 Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH qemu 1/1] Default disable ignore guest PAT quirk
Date: Wed, 13 Aug 2025 14:00:56 +0100	[thread overview]
Message-ID: <877bz75qbb.fsf@draig.linaro.org> (raw)
In-Reply-To: <175506686028.15648.7602021948044277748-1@git.sr.ht> (myrslint@git.sr.ht's message of "Wed, 13 Aug 2025 06:23:24 +0000")

~myrslint <myrslint@git.sr.ht> writes:

> From: myrslint <qemu.haziness801@passinbox.com>
>
> Addresses this issue:
> https://gitlab.com/qemu-project/qemu/-/issues/2943

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2943

> Most Intel CPUs in current use have self-snoop. The few added lines of
> code also check for availability of the quirk disablement option so if
> some CPU does not have this feature no change of behavior will occur.
> ---
>  accel/kvm/kvm-all.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
>
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 890d5ea9f8..c3d06ae2f8 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -2682,6 +2682,32 @@ static int kvm_init(AccelState *as, MachineState *ms)
>  
>      s->vmfd = ret;
>  
> +/* if target platform has no notion of this or kernel version does
> + * not have it there is no use for compiling this in */
> +#ifdef KVM_X86_QUIRK_IGNORE_GUEST_PAT

architecture specific changes should be in kvm_arch_init (in this case
in target/i386/kvm/kvm.c)

> +    /* first check for modifiable quirks bitmask */
> +    ret = kvm_check_extension(s, KVM_CAP_DISABLE_QUIRKS2);
> +    /* next make sure disabling it is allowed */
> +    if (ret & KVM_X86_QUIRK_IGNORE_GUEST_PAT) {
> +        struct kvm_enable_cap *cap;
> +        cap = calloc(1, sizeof(struct kvm_enable_cap));

I few things, style says:

  Use of the ``malloc/free/realloc/calloc/valloc/memalign/posix_memalign``
  APIs is not allowed in the QEMU codebase. Instead of these routines,
  use the GLib memory allocation routines
  ``g_malloc/g_malloc0/g_new/g_new0/g_realloc/g_free``
  or QEMU's ``qemu_memalign/qemu_blockalign/qemu_vfree`` APIs.

And to avoid manual free you would do:

  g_autofree kvm_enable_cap *cap = g_new0(kvm_enable_cap, 1);

However why not just have a structure on the stack, e.g:

  struct kvm_enable_cap cap = { .cap = KVM_CAP_DISABLE_QUIRKS2,
                                .args = { KVM_X86_QUIRK_IGNORE_GUEST_PAT };

In fact looking at kvm_vcpu_enable_cap() you should probably just use that.

> +        if (cap) {
> +            cap->cap = KVM_CAP_DISABLE_QUIRKS2;
> +            cap->args[0] = KVM_X86_QUIRK_IGNORE_GUEST_PAT;
> +            /* if intel cpu does not support self-snoop this is a nop */
> +            ret = kvm_vm_ioctl(s, KVM_ENABLE_CAP, cap);
> +            if (ret < 0) {
> +                error_printf("KVM_X86_QUIRK_IGNORE_GUEST_PAT available and "
> +                             "modifiable but we failed to disable
> it\n");

I think this should be error_report

> +            }
> +            free(cap);
> +        } else {

You don't need the else leg if you are dynamically allocating as g_new
and friends will abort().

> +            error_printf("KVM_X86_QUIRK_IGNORE_GUEST_PAT: could not "
> +                         "allocate memory\n");
> +        }
> +    }
> +#endif
> +
>      s->nr_as = kvm_vm_check_extension(s, KVM_CAP_MULTI_ADDRESS_SPACE);
>      if (s->nr_as <= 1) {
>          s->nr_as = 1;

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


      reply	other threads:[~2025-08-13 13:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-13  6:34 [PATCH qemu 0/1] A small patch to address Issue #2943 ~myrslint
2025-08-13  6:23 ` [PATCH qemu 1/1] Default disable ignore guest PAT quirk ~myrslint
2025-08-13 13:00   ` Alex Bennée [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877bz75qbb.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=myrskylintu@proton.me \
    --cc=myrslint@git.sr.ht \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).