public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: Andre Przywara <andre.przywara@arm.com>
Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Subject: Re: [PATCH v2 4/4] arm: Auto-detect guest GIC type
Date: Fri, 8 Feb 2019 16:10:13 +0000	[thread overview]
Message-ID: <20190208161012.GA11987@brain-police> (raw)
In-Reply-To: <20190201123716.92901-5-andre.przywara@arm.com>

On Fri, Feb 01, 2019 at 12:37:16PM +0000, Andre Przywara wrote:
> At the moment kvmtool always tries to instantiate a virtual GICv2 for
> the guest, and fails with some scary error message if that doesn't work.
> The user has then to manually specify "--irqchip=gicv3", which is not
> really obvious.
> With the advent of more GICv3-only machines, let's try to be more
> clever and implement some auto-detection of the GIC type needed:
> We try gicv3-its, gicv3, gicv2m and gicv2, in that order. That first one
> succeeding wins.
> For GICv2 machines the first two will always fail. For GICv2-backwards
> compatible GICv3 machines GICv3 is probably the better choice these days.
> 
> This algorithm is in effect is there is no explicit --irqchip parameter
> on the command line. We still allow the GIC type to be set explicitly.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
>  arm/gic.c                    | 25 +++++++++++++++++++++++++
>  arm/include/arm-common/gic.h |  1 +
>  2 files changed, 26 insertions(+)
> 
> diff --git a/arm/gic.c b/arm/gic.c
> index abcbcc09..a86da20e 100644
> --- a/arm/gic.c
> +++ b/arm/gic.c
> @@ -182,6 +182,8 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)
>  		gic_device.type = KVM_DEV_TYPE_ARM_VGIC_V3;
>  		dist_attr.attr  = KVM_VGIC_V3_ADDR_TYPE_DIST;
>  		break;
> +	case IRQCHIP_AUTO:
> +		return -ENODEV;
>  	}
>  
>  	err = ioctl(kvm->vm_fd, KVM_CREATE_DEVICE, &gic_device);
> @@ -199,6 +201,8 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type)
>  	case IRQCHIP_GICV3:
>  		err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &redist_attr);
>  		break;
> +	case IRQCHIP_AUTO:
> +		return -ENODEV;
>  	}
>  	if (err)
>  		goto out_err;
> @@ -249,9 +253,30 @@ static int gic__create_irqchip(struct kvm *kvm)
>  
>  int gic__create(struct kvm *kvm, enum irqchip_type type)
>  {
> +	enum irqchip_type try;
>  	int err;
>  
>  	switch (type) {
> +	case IRQCHIP_AUTO:
> +		try = IRQCHIP_GICV3_ITS;
> +		err = gic__create(kvm, try);
> +		if (err) {
> +			try = IRQCHIP_GICV3;
> +			err = gic__create(kvm, try);
> +		}
> +		if (err) {
> +			try = IRQCHIP_GICV2M;
> +			err = gic__create(kvm, try);
> +		}
> +		if (err) {
> +			try = IRQCHIP_GICV2;
> +			err = gic__create(kvm, try);
> +		}
> +		if (err)
> +			return err;

Easier to write this as a descending loop over the irqchip_type enum?

Will

  reply	other threads:[~2019-02-08 16:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-01 12:37 [PATCH v2 0/4] Various convenience fixes Andre Przywara
2019-02-01 12:37 ` [PATCH v2 1/4] arm: fdt: add stdout-path to /chosen node Andre Przywara
2019-02-01 12:37 ` [PATCH v2 2/4] Makefile: support -s switch Andre Przywara
2019-02-01 12:37 ` [PATCH v2 3/4] Makefile: Remove echoing of kvmtools version file Andre Przywara
2019-02-01 12:37 ` [PATCH v2 4/4] arm: Auto-detect guest GIC type Andre Przywara
2019-02-08 16:10   ` Will Deacon [this message]
2019-02-08 16:16 ` [PATCH v2 0/4] Various convenience fixes Will Deacon

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=20190208161012.GA11987@brain-police \
    --to=will.deacon@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    /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