From patchwork Fri Jul 5 09:31:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13724668 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 7F5EAC30658 for ; Fri, 5 Jul 2024 09:32:28 +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:References:In-Reply-To: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:List-Owner; bh=4cG80Tu/R6ba96dbyZQmaA30Cjd0d/7IQnLNMOP8lhw=; b=na39ggicaNegSn548UKA0fzHRr t0Qa6bIMEL79tCuqxQXzmqzBlEIcMoa9imX09cQ8pTFe35XBmgT5+M+/z4ZdWIHw6He8QOgeKcd4E VjaK8DxtfAHDRzvE/g4tUbMgkL+0FF28m6fiBpVkA+UGBvk7ETen0HtjYS9wb8N8vd+pPEgTKSR3L ApOJiHCYgGTGg7ysx8iayNZmLTFlT1k8BQSNSY0AHiqyttYgh/9mBRz6I45JiHfMHvQIFU/8bOIgb S3YePKRmeMM2mYW3YTDWSNXOzXQakeoRaZe2bN7NnjpE+hQ92dLsTSv30NCVO2z7xdzPnxbz86fwF Y6CUOyjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPfIe-0000000FS3t-2n4i; Fri, 05 Jul 2024 09:32:16 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPfIQ-0000000FRyg-1hwq for linux-arm-kernel@lists.infradead.org; Fri, 05 Jul 2024 09:32:03 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5546562AE4; Fri, 5 Jul 2024 09:32:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A5DCC32781; Fri, 5 Jul 2024 09:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720171921; bh=nzaJSHHvHLH4tw2NS88X2blB90LpkIyqdRotWeSvNdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l1x7D6TbGvzN0orBc1T5rVFA9zBXP6ySBl1DRMs7OBq2jTKIh0HogJS+qy1CWoK3v xTF52gz5KHoVCuVE8tdni+gUbp8I5nmK86yaUe4dDDPtTfkDHSdidv0iy8xRw4sKPO /LCG/9aQb8iD623oAja57AtHxuKPhi6PUZbda6WNo+GmQyTo8MFu1pUs3tHNLvTZM4 CAkrqJRTnbYPl9oQv3EVtM36SyhFvz7SbNAjr/J5SEfnTCqwZZF7G76j/MFwk7PSvf GDilttOWS7Dft3HUfLPLjxh6LyyGiY5CiP6+ek/xv75zUtVnYfNLmXZoRQ3rbtbxz7 BeCz/wkr9ojBA== 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-PY; 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 1/3] irqchip/gic-v4: Always configure affinity on VPE activation Date: Fri, 5 Jul 2024 10:31:53 +0100 Message-Id: <20240705093155.871070-2-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240705093155.871070-1-maz@kernel.org> References: <20240705093155.871070-1-maz@kernel.org> 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_023202_551376_2F05FD85 X-CRM114-Status: GOOD ( 18.21 ) 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 We currently have two paths to set the initial affinity of a VPE: - at activation time on GICv4 without the stupid VMOVP list, and on GICv4.1 - at map time for GICv4 with VMOVP list The latter location may end-up modifying the affinity of VPE that is currently running, making the results unpredictible. Instead, unify the two paths, making sure we only set the initial affinity at activation time. Reported-by: Nianyao Tang Signed-off-by: Marc Zyngier --- drivers/irqchip/irq-gic-v3-its.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 3c755d5dad6e6..a00c5e8c4ea65 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1809,13 +1809,9 @@ static void its_map_vm(struct its_node *its, struct its_vm *vm) for (i = 0; i < vm->nr_vpes; i++) { struct its_vpe *vpe = vm->vpes[i]; - struct irq_data *d = irq_get_irq_data(vpe->irq); - /* Map the VPE to the first possible CPU */ - vpe->col_idx = cpumask_first(cpu_online_mask); its_send_vmapp(its, vpe, true); its_send_vinvall(its, vpe); - irq_data_update_effective_affinity(d, cpumask_of(vpe->col_idx)); } } @@ -4562,6 +4558,10 @@ static int its_vpe_irq_domain_activate(struct irq_domain *domain, struct its_vpe *vpe = irq_data_get_irq_chip_data(d); struct its_node *its; + /* Map the VPE to the first possible CPU */ + vpe->col_idx = cpumask_first(cpu_online_mask); + irq_data_update_effective_affinity(d, cpumask_of(vpe->col_idx)); + /* * If we use the list map, we issue VMAPP on demand... Unless * we're on a GICv4.1 and we eagerly map the VPE on all ITSs @@ -4570,9 +4570,6 @@ static int its_vpe_irq_domain_activate(struct irq_domain *domain, if (!gic_requires_eager_mapping()) return 0; - /* Map the VPE to the first possible CPU */ - vpe->col_idx = cpumask_first(cpu_online_mask); - list_for_each_entry(its, &its_nodes, entry) { if (!is_v4(its)) continue; @@ -4581,8 +4578,6 @@ static int its_vpe_irq_domain_activate(struct irq_domain *domain, its_send_vinvall(its, vpe); } - irq_data_update_effective_affinity(d, cpumask_of(vpe->col_idx)); - return 0; } From patchwork Fri Jul 5 09:31:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13724671 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 C04A9C30658 for ; Fri, 5 Jul 2024 09:33:06 +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:References:In-Reply-To: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:List-Owner; bh=WmuTAHupBqvMGuQvp0b1EdG1dwXdOY+b2K1SsSXhKT8=; b=09NDY+PdLjYj/QrG8qO13yNzlJ eOqxIkNObthBajlpQBjG38IeaBr/kLRAY9A5bi3NFgct9Q0kKF8yWF4ql591cAvDs4qK3kefGuG5c GPMekamBqgFzbxh9CmFK6E0zt1be/nDUJUqVbdheFvzCb2FlWAij4MjO+YAwoCP523POQiQldD2xO jVsGCiI6vLZYMHpwYE4GCuBNtdTFyyDAq5lConvtUKKHKqja8cTYt9pQOBNzkRNzbQ0U4cXkJA5ZA Ny8u82TcmtGwVbZptGpIiZhBFTMSuLAJH0FiBJZ9Vj2m7MCPdMgS1K/y/Ggu8K7pSXd9osDAxH9kt o4dlHaqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPfJG-0000000FSKh-02xX; Fri, 05 Jul 2024 09:32:54 +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-0000000FRym-2GVe for linux-arm-kernel@lists.infradead.org; Fri, 05 Jul 2024 09:32:05 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id F13F5CE3CF6; Fri, 5 Jul 2024 09:32:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43CF6C4AF0B; Fri, 5 Jul 2024 09:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720171921; bh=GJ1I7tTBeFCHTX2tR7t3dckUliPv66ihFKX42pTzlaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2jpyzUXLIecjzta5xVfmWJaZzluULhfveAbqrErKtR46N0Y8mBppf1EjHNHxov7Q cq6t+A5UH1Z2sTt497M6zQHca1S68fiTtTMiDyhZeGjUoa5ScZFuo+JV3nUqPYzU7+ lpn50ALL4r5VA7uRZXlkhrsi+lkEhEsbHpLL4RpsaQyfb4ZUvexU9EpRix70XlnLiP v+VDf2XhxedlQh57BMTj1E1/pLN/F9LzcAFrNCd7uikxwxlx+c8lYzK0ROcD3BzBea EcRzV+mZ/SXvGt/xx9xPZzBUWLKfiAUrf1I3h1Yxi+YVBQZnuI1y2qoRQdrHNYN+TL VZ3QDPAzuYw5w== 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 1sPfIN-00A0NK-1O; Fri, 05 Jul 2024 10:31:59 +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 2/3] irqchip/gic-v4: Substitute vmovp_lock for a per-VM lock Date: Fri, 5 Jul 2024 10:31:54 +0100 Message-Id: <20240705093155.871070-3-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240705093155.871070-1-maz@kernel.org> References: <20240705093155.871070-1-maz@kernel.org> 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_023204_004126_F93EB2A0 X-CRM114-Status: GOOD ( 20.07 ) 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 vmovp_lock is abused in a number of cases to serialise updates to vlpi_count[] and deal with map/unmap of a VM to ITSs. Instead, provide a per-VM lock and revisit the use of vlpi_count[] so that it is always wrapped in this per-VM vmapp_lock. This reduces the potential contention on a concurrent VMOVP command, and paves the way for subsequent VPE locking that holding vmovp_lock actively prevents due to the lock ordering. Signed-off-by: Marc Zyngier --- drivers/irqchip/irq-gic-v3-its.c | 27 ++++++++++++--------------- include/linux/irqchip/arm-gic-v4.h | 8 ++++++++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index a00c5e8c4ea65..b52d60097cad5 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1317,7 +1317,6 @@ static void its_send_vmovp(struct its_vpe *vpe) { struct its_cmd_desc desc = {}; struct its_node *its; - unsigned long flags; int col_id = vpe->col_idx; desc.its_vmovp_cmd.vpe = vpe; @@ -1329,6 +1328,12 @@ 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 @@ -1337,8 +1342,7 @@ static void its_send_vmovp(struct its_vpe *vpe) * * Wall <-- Head. */ - raw_spin_lock_irqsave(&vmovp_lock, flags); - + guard(raw_spinlock)(&vmovp_lock); desc.its_vmovp_cmd.seq_num = vmovp_seq_num++; desc.its_vmovp_cmd.its_list = get_its_list(vpe->its_vm); @@ -1353,8 +1357,6 @@ static void its_send_vmovp(struct its_vpe *vpe) desc.its_vmovp_cmd.col = &its->collections[col_id]; its_send_single_vcommand(its, its_build_vmovp_cmd, &desc); } - - raw_spin_unlock_irqrestore(&vmovp_lock, flags); } static void its_send_vinvall(struct its_node *its, struct its_vpe *vpe) @@ -1791,12 +1793,10 @@ static bool gic_requires_eager_mapping(void) static void its_map_vm(struct its_node *its, struct its_vm *vm) { - unsigned long flags; - if (gic_requires_eager_mapping()) return; - raw_spin_lock_irqsave(&vmovp_lock, flags); + guard(raw_spinlock_irqsave)(&vm->vmapp_lock); /* * If the VM wasn't mapped yet, iterate over the vpes and get @@ -1814,19 +1814,15 @@ static void its_map_vm(struct its_node *its, struct its_vm *vm) its_send_vinvall(its, vpe); } } - - raw_spin_unlock_irqrestore(&vmovp_lock, flags); } static void its_unmap_vm(struct its_node *its, struct its_vm *vm) { - unsigned long flags; - /* Not using the ITS list? Everything is always mapped. */ if (gic_requires_eager_mapping()) return; - raw_spin_lock_irqsave(&vmovp_lock, flags); + guard(raw_spinlock_irqsave)(&vm->vmapp_lock); if (!--vm->vlpi_count[its->list_nr]) { int i; @@ -1834,8 +1830,6 @@ static void its_unmap_vm(struct its_node *its, struct its_vm *vm) for (i = 0; i < vm->nr_vpes; i++) its_send_vmapp(its, vm->vpes[i], false); } - - raw_spin_unlock_irqrestore(&vmovp_lock, flags); } static int its_vlpi_map(struct irq_data *d, struct its_cmd_info *info) @@ -3922,6 +3916,8 @@ static void its_vpe_invall(struct its_vpe *vpe) { struct its_node *its; + guard(raw_spinlock_irqsave)(&vpe->its_vm->vmapp_lock); + list_for_each_entry(its, &its_nodes, entry) { if (!is_v4(its)) continue; @@ -4527,6 +4523,7 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq vm->db_lpi_base = base; vm->nr_db_lpis = nr_ids; vm->vprop_page = vprop_page; + raw_spin_lock_init(&vm->vmapp_lock); if (gic_rdists->has_rvpeid) irqchip = &its_vpe_4_1_irq_chip; diff --git a/include/linux/irqchip/arm-gic-v4.h b/include/linux/irqchip/arm-gic-v4.h index 2c63375bbd43f..ecabed6d33075 100644 --- a/include/linux/irqchip/arm-gic-v4.h +++ b/include/linux/irqchip/arm-gic-v4.h @@ -25,6 +25,14 @@ struct its_vm { irq_hw_number_t db_lpi_base; unsigned long *db_bitmap; int nr_db_lpis; + /* + * Ensures mutual exclusion between updates to vlpi_count[] + * and map/unmap when using the ITSList mechanism. + * + * The lock order for any sequence involving the ITSList is + * vmapp_lock -> vpe_lock ->vmovp_lock. + */ + raw_spinlock_t vmapp_lock; u32 vlpi_count[GICv4_ITS_LIST_MAX]; }; From patchwork Fri Jul 5 09:31:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13724669 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 AA367C3271F for ; Fri, 5 Jul 2024 09:32:36 +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:References:In-Reply-To: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:List-Owner; bh=dNs8eXrENafqxSUSf9l1KBiDa4flAxHDpQDxH1ZDeMI=; b=d11Zx4bD1q/rDpPEHVqhDJR4ar 0VDtlTPxnxb9FYSlQxYkJlPqizo2Ega1G3Ac/afcJFOZVZajVLNuPuzVAKpGxO1mFEHU2ONuPWRCK 32N+emJ4fNgwux5LxrylDk7wjU7dl3YLpHhWhEeUxCFj19Us8n/G6oaaqovab3W4t1oHxaHmN0mD3 b3lJn4q3ZnzUha/A6GVFSmU1skc3vHt8h8ruwS2KTZ8bQGb4DsO12Zbdqp8TC5IbjIG8KtxshqW3F LMcgGgc00A6rR/ZCbFNeMgfFbTTsMs787miagbGEkZmxlhvn18rVJ5eWQP66MjYkQc4uTCTECCvQ8 cSzA3hWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPfIp-0000000FS7R-2pPA; Fri, 05 Jul 2024 09:32:27 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPfIQ-0000000FRyk-3phb 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 dfw.source.kernel.org (Postfix) with ESMTP id 0DBC762B9A; Fri, 5 Jul 2024 09:32:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7940C4AF0E; Fri, 5 Jul 2024 09:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720171921; bh=vXaZypimdtDEFoahBdSVdRJ7Rc7jfwOUM1aU//Iu5Fg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BgscsyC1n1k00NijCvI/9W6kFbsc2kpaZLIbXxkYsn6HxWp/YHhaDo54s+hzxCenF howYQHnUDCsn+kKB3Vg/+fcB7IqQpud2nBDy9zo069ZAzviZ4iDO8LtyfO87tStXuT OLnla40I0m1hscgu8LeHGTEReWxkaMlvmIQxFlwOOJQeMvEJJt1hC3/iPGYqSaAOX7 OmcZhLHw0Z2/FKNJ6qPIvwkNl8+uR3tt8cL49Zof5wm3+fAKdTMiqGEEwR5ffAoP8Z vpFyS0dhtYjYkbr47FJ1B0VIa8UyBzwHFSyZOW3AOwFhkHhQn11VVyjjotEqkcJuip CujJXmwVB8AIQ== 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 1sPfIN-00A0NK-8e; Fri, 05 Jul 2024 10:31:59 +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 3/3] irqchip/gic-v4: Make sure a VPE is locked when VMAPP is issued Date: Fri, 5 Jul 2024 10:31:55 +0100 Message-Id: <20240705093155.871070-4-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240705093155.871070-1-maz@kernel.org> References: <20240705093155.871070-1-maz@kernel.org> 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_038076_48AB03BB X-CRM114-Status: GOOD ( 14.98 ) 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 order to make sure that vpe->col_idx is correctly sampled when a VMAPP command is issued, we must hold the lock for the VPE. This is now possible since the introduction of the per-VM vmapp_lock, which can be taken before vpe_lock in the locking order. Signed-off-by: Marc Zyngier --- drivers/irqchip/irq-gic-v3-its.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index b52d60097cad5..951ec140bcea2 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1810,7 +1810,9 @@ static void its_map_vm(struct its_node *its, struct its_vm *vm) for (i = 0; i < vm->nr_vpes; i++) { struct its_vpe *vpe = vm->vpes[i]; - its_send_vmapp(its, vpe, true); + scoped_guard(raw_spinlock, &vpe->vpe_lock) + its_send_vmapp(its, vpe, true); + its_send_vinvall(its, vpe); } } @@ -1827,8 +1829,10 @@ static void its_unmap_vm(struct its_node *its, struct its_vm *vm) if (!--vm->vlpi_count[its->list_nr]) { int i; - for (i = 0; i < vm->nr_vpes; i++) + for (i = 0; i < vm->nr_vpes; i++) { + guard(raw_spinlock)(&vm->vpes[i]->vpe_lock); its_send_vmapp(its, vm->vpes[i], false); + } } }