qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, Bernhard Beschow <shentey@gmail.com>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Markus Armbruster <armbru@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	Jason Wang <jasowang@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Eduardo Habkost <eduardo@habkost.net>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v2 2/5] hw/i386/apic: Defer error check from apic_get_class to kvm_apic_realize
Date: Tue, 3 Oct 2023 16:49:35 -0400	[thread overview]
Message-ID: <ZRx+X8C8+34K4d+q@x1n> (raw)
In-Reply-To: <20231003082728.83496-3-philmd@linaro.org>

On Tue, Oct 03, 2023 at 10:27:25AM +0200, Philippe Mathieu-Daudé wrote:
> apic_get_class() isn't supposed to fail. kvm_apic_realize() is
> DeviceRealize() handler, which can fail. Defer the error check
> to the latter.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/i386/kvm/apic.c       | 5 +++++
>  target/i386/cpu-sysemu.c | 8 --------
>  2 files changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c
> index 1e89ca0899..4883308247 100644
> --- a/hw/i386/kvm/apic.c
> +++ b/hw/i386/kvm/apic.c
> @@ -228,6 +228,11 @@ static void kvm_apic_realize(DeviceState *dev, Error **errp)
>  {
>      APICCommonState *s = APIC_COMMON(dev);
>  
> +    if (!kvm_irqchip_in_kernel()) {
> +        error_setg(errp, "KVM does not support userspace APIC");
> +        return;
> +    }

IMO the code reads a bit weird, that we are already trying to create
kvm-apic even if !kvm_irqchip_in_kernel()..

Would it be better to check this in i386's kvm_arch_irqchip_create()?

> +
>      memory_region_init_io(&s->io_memory, OBJECT(s), &kvm_apic_io_ops, s,
>                            "kvm-apic-msi", APIC_SPACE_SIZE);
>  
> diff --git a/target/i386/cpu-sysemu.c b/target/i386/cpu-sysemu.c
> index 2375e48178..6a228c9178 100644
> --- a/target/i386/cpu-sysemu.c
> +++ b/target/i386/cpu-sysemu.c
> @@ -253,10 +253,6 @@ APICCommonClass *apic_get_class(Error **errp)
>  
>      /* TODO: in-kernel irqchip for hvf */
>      if (kvm_enabled()) {
> -        if (!kvm_irqchip_in_kernel()) {
> -            error_setg(errp, "KVM does not support userspace APIC");
> -            return NULL;
> -        }
>          apic_type = "kvm-apic";
>      } else if (xen_enabled()) {
>          apic_type = "xen-apic";
> @@ -272,10 +268,6 @@ void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
>      APICCommonState *apic;
>      APICCommonClass *apic_class = apic_get_class(errp);
>  
> -    if (!apic_class) {
> -        return;
> -    }
> -
>      cpu->apic_state = DEVICE(object_new_with_class(OBJECT_CLASS(apic_class)));
>      object_property_add_child(OBJECT(cpu), "lapic",
>                                OBJECT(cpu->apic_state));
> -- 
> 2.41.0
> 

-- 
Peter Xu



  reply	other threads:[~2023-10-03 20:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03  8:27 [PATCH v2 0/5] hw/intc/apic: QOM cleanup Philippe Mathieu-Daudé
2023-10-03  8:27 ` [PATCH v2 1/5] hw/intc/apic: Use ERRP_GUARD() in apic_common_realize() Philippe Mathieu-Daudé
2023-10-03 20:50   ` Peter Xu
2023-10-03  8:27 ` [PATCH v2 2/5] hw/i386/apic: Defer error check from apic_get_class to kvm_apic_realize Philippe Mathieu-Daudé
2023-10-03 20:49   ` Peter Xu [this message]
2023-10-03 23:21   ` Bernhard Beschow
2023-10-05  7:06     ` Philippe Mathieu-Daudé
2023-10-05  7:40       ` Bernhard Beschow
2023-10-03  8:27 ` [PATCH v2 3/5] hw/i386/apic: Simplify apic_get_class() Philippe Mathieu-Daudé
2023-10-03 20:51   ` Peter Xu
2023-10-03 23:41   ` Bernhard Beschow
2023-10-03  8:27 ` [PATCH v2 4/5] hw/intc/apic: Rename x86_cpu_apic_create() -> x86_cpu_apic_new() Philippe Mathieu-Daudé
2023-10-03 20:51   ` Peter Xu
2023-10-05 23:00   ` Paolo Bonzini
2023-10-03  8:27 ` [PATCH v2 5/5] hw/intc/apic: Pass CPU using QOM link property Philippe Mathieu-Daudé
2023-10-05 23:04   ` Paolo Bonzini
2023-10-16 14:38     ` Philippe Mathieu-Daudé

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=ZRx+X8C8+34K4d+q@x1n \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=jasowang@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=shentey@gmail.com \
    /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).