From patchwork Fri Feb 1 12:37:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 10792663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3517B746 for ; Fri, 1 Feb 2019 12:37:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 255D92F29B for ; Fri, 1 Feb 2019 12:37:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19BE83201A; Fri, 1 Feb 2019 12:37:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8DC52F29B for ; Fri, 1 Feb 2019 12:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729884AbfBAMh1 (ORCPT ); Fri, 1 Feb 2019 07:37:27 -0500 Received: from foss.arm.com ([217.140.101.70]:59266 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729877AbfBAMh0 (ORCPT ); Fri, 1 Feb 2019 07:37:26 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 16F1E80D; Fri, 1 Feb 2019 04:37:26 -0800 (PST) Received: from donnerap.arm.com (donnerap.cambridge.arm.com [10.1.197.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2B2D73F59C; Fri, 1 Feb 2019 04:37:25 -0800 (PST) From: Andre Przywara To: Will Deacon Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Subject: [PATCH v2 4/4] arm: Auto-detect guest GIC type Date: Fri, 1 Feb 2019 12:37:16 +0000 Message-Id: <20190201123716.92901-5-andre.przywara@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190201123716.92901-1-andre.przywara@arm.com> References: <20190201123716.92901-1-andre.przywara@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; + + kvm->cfg.arch.irqchip = try; + return 0; case IRQCHIP_GICV2M: gic_msi_size = KVM_VGIC_V2M_SIZE; gic_msi_base = ARM_GIC_CPUI_BASE - gic_msi_size; diff --git a/arm/include/arm-common/gic.h b/arm/include/arm-common/gic.h index 1125d601..ec9cf31a 100644 --- a/arm/include/arm-common/gic.h +++ b/arm/include/arm-common/gic.h @@ -24,6 +24,7 @@ #define KVM_VGIC_V2M_SIZE 0x1000 enum irqchip_type { + IRQCHIP_AUTO, IRQCHIP_GICV2, IRQCHIP_GICV2M, IRQCHIP_GICV3,