From patchwork Thu Sep 3 15:25:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 11754129 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6055109B for ; Thu, 3 Sep 2020 15:27:13 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B36D2072A for ; Thu, 3 Sep 2020 15:27:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="oOpLrdTA"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="uoFb6Cdy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B36D2072A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wqJoKmPvpUwvQm+5Jby/wf3fnfpWjlYGYN/6vdAY1qg=; b=oOpLrdTAIxYvv4WgyT8j1Avcg oMtHkmiRPmv/skkZGc8ogpoGXQKr0u2pB+qOLUfiwN3Fx7p52B3VZoUZtXb5PGHUS4mFM6aJcCvdC uWpXnnL3B77PMHod85HC5Ix8FIqGfWQUUMrnEFzEW1MdM/xJmsWlAfhM5iJG/WK3aNlQY1JiXqTuL r/Rc7ZvnSJVnzO0SVYERboASuwD3KYXKOHtjTnC+GQZbnyw1LMZ34R96PfPR2YjqTn+wC4OoVBRfI NMLIukb105zATLx65vBVtDgDh3b6f2OPEqoorpw7Vi9inJkvhY07ZYe4y8IKGv09f84KxpBfwNCnr 1HiFTlSDA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDr8e-00055G-Rc; Thu, 03 Sep 2020 15:27:00 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDr88-0004sj-Q2 for linux-arm-kernel@lists.infradead.org; Thu, 03 Sep 2020 15:26:31 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 011C720C09; Thu, 3 Sep 2020 15:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599146788; bh=HBjR8yqpG73ePWO3TJecMmjtceWadFNU+gdwbXpG+SI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uoFb6CdyZLtnPLWXFpdfmJZw1Tg/GSjEE+49gDnsyYj1dDONEVOOO9gWFO/X4RBdu L2nKnp4CiwzTNztHbRWuPqDjlDT7nCooNHLAAOts236MPkuqCBfVurtLJVZQwJpgMm AR7y41dXI4Dv20HN7jPrNyYF29q0uEuBi72gAeS4= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDr86-008vT9-DY; Thu, 03 Sep 2020 16:26:26 +0100 From: Marc Zyngier To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 09/23] KVM: arm64: Move kvm_vgic_vcpu_init() to irqchip_flow Date: Thu, 3 Sep 2020 16:25:56 +0100 Message-Id: <20200903152610.1078827-10-maz@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903152610.1078827-1-maz@kernel.org> References: <20200903152610.1078827-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, Christoffer.Dall@arm.com, lorenzo.pieralisi@arm.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200903_112629_019518_3181B4CE X-CRM114-Status: GOOD ( 25.00 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , Suzuki K Poulose , Christoffer Dall , James Morse , kernel-team@android.com, Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Abstract kvm_vgic_vcpu_init() by moving it to the irqchip_flow structure. This results in a minor change of the way we initialize vcpus: VCPUs created prior to the creation of the vgic device don't have their local view of the vgic initialized. This means that on vgic instantiation, we must "catch up" and initialise the CPU interfaces for these vcpus. VCPUs created after the vgic device will follow the unusual flow. Special care must be taken to accomodate the different locking contexts though. The function can then be made static and the irqchip_in_kernel() test dropped, as we only get here if a vgic has been created. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_irq.h | 4 ++++ arch/arm64/kvm/arm.c | 2 +- arch/arm64/kvm/vgic/vgic-init.c | 37 +++++++++++++++++++++++++------- include/kvm/arm_vgic.h | 1 - 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/kvm_irq.h b/arch/arm64/include/asm/kvm_irq.h index f83594257bc4..09df1f46d4de 100644 --- a/arch/arm64/include/asm/kvm_irq.h +++ b/arch/arm64/include/asm/kvm_irq.h @@ -19,6 +19,7 @@ enum kvm_irqchip_type { struct kvm_irqchip_flow { void (*irqchip_destroy)(struct kvm *); + int (*irqchip_vcpu_init)(struct kvm_vcpu *); }; /* @@ -50,4 +51,7 @@ struct kvm_irqchip_flow { #define kvm_irqchip_destroy(k) \ __kvm_irqchip_action((k), destroy, (k)) +#define kvm_irqchip_vcpu_init(v) \ + __vcpu_irqchip_action_ret((v), vcpu_init, (v)) + #endif diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 09b4bcb2c805..d82d348a36c3 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -265,7 +265,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) vcpu->arch.hw_mmu = &vcpu->kvm->arch.mmu; - err = kvm_vgic_vcpu_init(vcpu); + err = kvm_irqchip_vcpu_init(vcpu); if (err) return err; diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c index 4e2c23a7dab1..d845699c6966 100644 --- a/arch/arm64/kvm/vgic/vgic-init.c +++ b/arch/arm64/kvm/vgic/vgic-init.c @@ -12,10 +12,12 @@ #include #include "vgic.h" +static int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu); static void kvm_vgic_destroy(struct kvm *kvm); static struct kvm_irqchip_flow vgic_irqchip_flow = { .irqchip_destroy = kvm_vgic_destroy, + .irqchip_vcpu_init = kvm_vgic_vcpu_init, }; /* @@ -45,6 +47,8 @@ static struct kvm_irqchip_flow vgic_irqchip_flow = { * allocation is allowed there. */ +static int __kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu); + /* CREATION */ /** @@ -110,6 +114,17 @@ int kvm_vgic_create(struct kvm *kvm, u32 type) INIT_LIST_HEAD(&dist->lpi_translation_cache); raw_spin_lock_init(&dist->lpi_list_lock); + /* + * vcpus may have been created before the GIC. Initialize + * them. Careful that kvm->lock is held already on the + * KVM_CREATE_DEVICE path, so use the non-locking version. + */ + kvm_for_each_vcpu(i, vcpu, kvm) { + ret = __kvm_vgic_vcpu_init(vcpu); + if (ret) + break; + } + out_unlock: unlock_all_vcpus(kvm); return ret; @@ -176,7 +191,7 @@ static int kvm_vgic_dist_init(struct kvm *kvm, unsigned int nr_spis) * Only do initialization, but do not actually enable the * VGIC CPU interface */ -int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu) +static int __kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu) { struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; int ret = 0; @@ -211,18 +226,24 @@ int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu) } } - if (!irqchip_in_kernel(vcpu->kvm)) - return 0; - /* * If we are creating a VCPU with a GICv3 we must also register the * KVM io device for the redistributor that belongs to this VCPU. */ - if (irqchip_is_gic_v3(vcpu->kvm)) { - mutex_lock(&vcpu->kvm->lock); + if (irqchip_is_gic_v3(vcpu->kvm)) ret = vgic_register_redist_iodev(vcpu); - mutex_unlock(&vcpu->kvm->lock); - } + + return ret; +} + +static int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu) +{ + int ret; + + mutex_lock(&vcpu->kvm->lock); + ret = __kvm_vgic_vcpu_init(vcpu); + mutex_unlock(&vcpu->kvm->lock); + return ret; } diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index e8bdc304ec9b..b2fd0e39af11 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -335,7 +335,6 @@ extern struct static_key_false vgic_v2_cpuif_trap; extern struct static_key_false vgic_v3_cpuif_trap; int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write); -int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu); int kvm_vgic_create(struct kvm *kvm, u32 type); int kvm_vgic_map_resources(struct kvm *kvm); int kvm_vgic_hyp_init(void);