From patchwork Fri Jul 5 09:31:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13724670 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 95CF7C30658 for ; Fri, 5 Jul 2024 09:32:50 +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=vWkWp8E71zXz8xi7fHz5OhnMPAzms2h6O9dtEeWWdSQ=; b=tIsdD4Ud1OUKWWxnhk+cnOl4z0 AdiWy+d7t1DzO6IO4u4IJfK1aNh54BI1MIVdzi9w4F4syRofHn8yPlOy7/E5eDu7tW3VeeeeGwb6X lBQ2RBphXew9VKg8yqBW9Dcej76i+nXmL1ut2HbNzY8/rS/fn/s9p5utbGNuzY8xXdyfGiM6ZxZGO XT8vzzy/jWloGKN87t6Z7OwtCt2lOREGGkD6kvG+rjoOMO+UrFP5a4V0AYq+xgrQBUJqqb5it/igR 7q5JiIRqd/ADLHiVZoiddXoG/xUBJ1pSyvCYWTXeV/gtbhyg025RnaGwX/fsOWs7CFzmnbVjrCKHs qvBw03Nw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPfJ3-0000000FSFh-3qFv; Fri, 05 Jul 2024 09:32:41 +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 1sPfIR-0000000FRyh-0PJY for linux-arm-kernel@lists.infradead.org; Fri, 05 Jul 2024 09:32:04 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 858F4CE3D0A; Fri, 5 Jul 2024 09:32:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBEC1C116B1; Fri, 5 Jul 2024 09:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720171920; bh=Hzb9ioOe75iuE8nil3shI39R8UAVrKoKUtFNw7Yvnpk=; h=From:To:Cc:Subject:Date:From; b=TiLzy/CVDuVmncADPZ3ZXszOGVJQjYV+m7aARw3zOLsU5tL5y0i+R/j3rBqjVbI5V 0LTKwKs1XvO6tCHdtz1sysCdvIUhHXrrmvmyEoG5wUdTQ/9f21159ciVpJC8M3pXdi n8QPnQW0id1pUskOaiE/DcETpDpqJUzWv7lMw6BuQR3imGGCkjw4oBmDmyB7IiW6pi mLtqJSQ5jQnYqntl9Fyj5px3GrnA4Pmwxd9vwNjn89bxKEgvgKKWDMhKbOpxAcH3h7 wHMETqAwdEJsZoyUv7gtIKNRdOV3RK8JJBnmt9NZ3SyTWc2rrGOfGHa9bkcJWad297 LhNjkDLAEl+HQ== 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 1sPfIM-00A0NK-Gy; Fri, 05 Jul 2024 10:31:58 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Thomas Gleixner , Nianyao Tang Subject: [PATCH 0/3] irqchip/gic-v4: Fix VMAPP/VMOVP races Date: Fri, 5 Jul 2024 10:31:52 +0100 Message-Id: <20240705093155.871070-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: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, tangnianyao@huawei.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-20240705_023203_330466_E4CC33A3 X-CRM114-Status: GOOD ( 13.47 ) 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 In 20240701072305.4129823-1-tangnianyao@huawei.com, Nianyao reports a number of possible races that can trigger on GICv4 implementations using the ITSList feature. These races involve concurrent VMOVP and VMAPP, the former happening on vcpu load, while the latter is triggered on the first device being MAPTI'd on a given ITS for this particular guest. The main issue is that we want to establish the affinity at VMAPP time, while vcpu_load wants to set the affinity where the vcpu actually runs. Lock ordering constraints mean that we can't lock the VPE on VMAPP, so things are modified without any lock. What could possibly go wrong? THe fix is a bit involved, and relies on 3 things: - Making sure that the initial affinity of a VPE is fixed at activate time, which is done early in the life of the vcpup, before it can run. - Add a per-VM lock that can be taken instead of the global vmovp_lock, paving the way for a more manageable lock order. - Take the per-VPE lock whenever modifying the VPE affinity, as expected everywhere else in the code. With that, VMAPP and VMOVP can now run concurrently and still lead to sensible results. Marc Zyngier (3): irqchip/gic-v4: Always configure affinity on VPE activation irqchip/gic-v4: Substitute vmovp_lock for a per-VM lock irqchip/gic-v4: Make sure a VPE is locked when VMAPP is issued drivers/irqchip/irq-gic-v3-its.c | 48 ++++++++++++++---------------- include/linux/irqchip/arm-gic-v4.h | 8 +++++ 2 files changed, 30 insertions(+), 26 deletions(-) Tested-by: Nianyao Tang