From patchwork Sun Aug 18 17:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13767512 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E9488C5320E for ; Sun, 18 Aug 2024 17:17:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=V16CggRbNiASGWVHFO/pz0G3LFjWy93UU+W8bDK09YY=; b=e43TMu4e3BA8sfXBL3gAEPZT07 yGAl3IcCwJpi74dRQpr1OndM7+AtzVshLaCIx2b8z1A1TM+imi+y9Bmzc5ZMcNm5rSrG4clvsHvPL KREE5zOMHYgqBJzP5Csv0yj6bjU88MjsEgCg4j6PFuRvLPSxh4tNPKuzkzLB9Qb9gNItWajZmxIAU I+3stEeeFigIS8WTk0gDC06M3V/exJX6Ky4B34a2PO4hRt+41ooJcsA0+EgnbjO+B3bqAj2q+nk2m I9dd8Xg91hZ+Tmt/gLC5MJst627G9b5uqIdsl2EA4/O/AVcQsDdSrxEn7rbO72Vl6MGmCblit6EZv rRZ276wA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfjX1-0000000GreV-41jY; Sun, 18 Aug 2024 17:17:31 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfjWL-0000000Grb5-3hoj for linux-arm-kernel@lists.infradead.org; Sun, 18 Aug 2024 17:16:51 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id B201FCE03F7; Sun, 18 Aug 2024 17:16:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA27EC32786; Sun, 18 Aug 2024 17:16:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724001404; bh=IH5l4LKZ28y9FltSfBkh7Hp2MJxrD0m1qcEB7e+oW/g=; h=From:To:Cc:Subject:Date:From; b=ohNw+xVNrV07olTSSScinCGnKaW2NQBJxyYrVLfIj2Vt+4ISHEkzmE5VfLIA4aqNA 5sZEwUKhTwFVzu8GjpxZGLY0aTPSrEkQbDtiN594DhCpbtic+OGWfIypl5WMq5xbt6 6F2pXek01DymPYZnYh4nbfDrUymyFy2rPAuxPe8Ez2NxTI+iPuZGy0XvNHrNx/Hh0Y hHIvDmH99ENI6dlpZoiNHP5x5YYqzFC0htS3sUeNfHBP4xSKX8ecUrQC0oXEm2nc70 tNSukMzQs/qME7lN1K++wd614mA/FNImwSyCNDpg10hEMHnMiPu0vMajd7sehduOD6 2WeYDkpnqwoUQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sfjWE-004hiP-I7; Sun, 18 Aug 2024 18:16:42 +0100 From: Marc Zyngier To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Zhou Wang , Thomas Gleixner Subject: [PATCH v2] irqchip/gic-v4: Fix ordering between vmapp and vpe locks Date: Sun, 18 Aug 2024 18:16:25 +0100 Message-Id: <20240818171625.3030584-1-maz@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, wangzhou1@hisilicon.com, tglx@linutronix.de 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-20240818_101650_292811_3C304836 X-CRM114-Status: GOOD ( 18.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The (recently established) lock ordering mandates that the per-VM vmapp_lock is acquired before we take the per-VPE lock. As it turns out, its_vpe_set_affinity() takes the VPE lock, and then calls into its_send_vmovp(), which itself takes the vmapp lock. Obviously, this isn't what we want. As its_send_vmovp() is only called from its_vpe_set_affinity(), hoist the vmapp locking from the former into the latter, restoring the expected order. Fixes: f0eb154c39471 ("irqchip/gic-v4: Substitute vmovp_lock for a per-VM lock") Reported-by: Zhou Wang Signed-off-by: Marc Zyngier Cc: Thomas Gleixner --- Notes: v2: - Dropped flags and rely on the irq_data being locked with interrupts disabled - Add extra documentation to explain why taking the vmapp_lock is dependent on the HW requiring the use of the ITS list v1: https://lore.kernel.org/r/20240723175203.3193882-1-maz@kernel.org drivers/irqchip/irq-gic-v3-its.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 9b34596b3542..fdec478ba5e7 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1329,12 +1329,6 @@ static void its_send_vmovp(struct its_vpe *vpe) return; } - /* - * Protect against concurrent updates of the mapping state on - * individual VMs. - */ - guard(raw_spinlock_irqsave)(&vpe->its_vm->vmapp_lock); - /* * Yet another marvel of the architecture. If using the * its_list "feature", we need to make sure that all ITSs @@ -3824,7 +3818,14 @@ static int its_vpe_set_affinity(struct irq_data *d, * protect us, and that we must ensure nobody samples vpe->col_idx * during the update, hence the lock below which must also be * taken on any vLPI handling path that evaluates vpe->col_idx. + * + * Finally, we must protect ourselves against concurrent updates of + * the mapping state on this VM should the ITS list be in use (see + * the shortcut in its_send_vmovp() otherewise). */ + if (its_list_map) + raw_spin_lock(&vpe->its_vm->vmapp_lock); + from = vpe_to_cpuid_lock(vpe, &flags); table_mask = gic_data_rdist_cpu(from)->vpe_table_mask; @@ -3854,6 +3855,9 @@ static int its_vpe_set_affinity(struct irq_data *d, irq_data_update_effective_affinity(d, cpumask_of(cpu)); vpe_to_cpuid_unlock(vpe, flags); + if (its_list_map) + raw_spin_unlock(&vpe->its_vm->vmapp_lock); + return IRQ_SET_MASK_OK_DONE; }