From patchwork Tue Jul 23 17:52:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13740243 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 1598FC3DA49 for ; Tue, 23 Jul 2024 17:52:54 +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=TJh/gJR14hhCgLelkdHaLqrV0t2y8hldXQFtXdrCrOg=; b=qVAPgtNsDkakt6z/e/BvWNPw0f u+oLr3NlsOh17KTzFX9NVa2HX+IZJBrdtW/d8ZlqOXCwFypq6OQrX2xPgppw+3NaFLjRimErvuVHz UnCXVQXrROfHlLjU5f5K2xTSY4+Fux5iYg++GoLPaMpLOYs1QM3NUXAJsynZSHfDqkkPuzmuTAfxj kpwvZlTPR+bi1W7khTyOkjjRylrD+Q3t2TfFGftnEdTPRkw0KD4JPkZM/7z/gBl3GO7ADsm2vqyUd KPlVq+VuJRD/e5BlgclK0B92R6yKK89gaP7vNEdHp1rJVG+yHtXfdhBs4sxThLDeW9ZazZgtiNiZR zYveyLGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWJgk-0000000DA7A-04KB; Tue, 23 Jul 2024 17:52:38 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWJgM-0000000DA35-17jl for linux-arm-kernel@lists.infradead.org; Tue, 23 Jul 2024 17:52:15 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 87DE9CE0B9B; Tue, 23 Jul 2024 17:52:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0D78C4AF0A; Tue, 23 Jul 2024 17:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721757131; bh=5Vid5ceHiFFWZuNy4oItL9vBhbm1P/wz2ZcWpglh3NI=; h=From:To:Cc:Subject:Date:From; b=Slsn31Z3HS1rCiq7noZ/fe9lMibmtTs8AxDQ1S7O5AzClrE9Ik9qvUZDwsuHi4Ddu Q2VzE098efUYrUDs+aLZ+DM/fft7PnWCFkSzNmnfN5rz54fN+hk5/Fl+nF25oFDe+6 f9dTPLDEebgoZvJCgJSWZU6ZQUqsj9VFg29OrPSbCaXeN/5e973374K/MeX9+VCX0X xNCPcvY4F5UxjMdBWDb+fT8d9v9q5C2y7EdVpt+CYHO00hL78JfQgAGZ1Z021krgMn ThYGz7NabeIdGlGIi29HwY2DD71Cu1GY+xqMDMzjrt4rb9jySCaay4U0ZKQXgNOhii iK+DT+7X3XW4A== 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 1sWJgH-00EnZ4-Ue; Tue, 23 Jul 2024 18:52:10 +0100 From: Marc Zyngier To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Thomas Gleixner , Zhou Wang Subject: [PATCH] irqchip/gic-v4: Fix ordering between vmapp and vpe locks Date: Tue, 23 Jul 2024 18:52:03 +0100 Message-Id: <20240723175203.3193882-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, tglx@linutronix.de, wangzhou1@hisilicon.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-20240723_105214_675738_346F8E93 X-CRM114-Status: GOOD ( 18.39 ) 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 Tested-by: Zhou Wang --- drivers/irqchip/irq-gic-v3-its.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 951ec140bcea2..b88c6011c8771 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1328,12 +1328,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 @@ -3808,7 +3802,7 @@ static int its_vpe_set_affinity(struct irq_data *d, struct its_vpe *vpe = irq_data_get_irq_chip_data(d); unsigned int from, cpu = nr_cpu_ids; struct cpumask *table_mask; - unsigned long flags; + unsigned long flags, vmapp_flags; /* * Changing affinity is mega expensive, so let's be as lazy as @@ -3822,7 +3816,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. */ + if (its_list_map) + raw_spin_lock_irqsave(&vpe->its_vm->vmapp_lock, vmapp_flags); + from = vpe_to_cpuid_lock(vpe, &flags); table_mask = gic_data_rdist_cpu(from)->vpe_table_mask; @@ -3852,6 +3853,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_irqrestore(&vpe->its_vm->vmapp_lock, vmapp_flags); + return IRQ_SET_MASK_OK_DONE; }