From mboxrd@z Thu Jan 1 00:00:00 1970 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 D8AC0CD4F4C for ; Sun, 8 Sep 2024 09:39:19 +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-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fm9uXpyvEpp3SXmw7kL1i16OslrEPU/H8+JsYPFG4QM=; b=QjJCX3DyHhmwl6lNnZVG+me3u/ SU7E1jzsFmgl5ceE3V2+LTXHp2GFgnCMFxZodzHqauQKzWBx+wh1uukOAgTK0t438EgszV787h958 mN6QKCc49ULRixsyyD2DdLz/SM4kBntFdgMuesHpKo6KhikCdJlyrfsnIO+08xwsJ+BJw3ZVbgOpJ LzXNV2larR2Gw5lgZ+HDiRcPs5vkPKWHz38MIdyqYA3QsnaVYHbwob6RM36HrV+9Z+KRFQyBRhykY cuwozBJB+ODXdIbXq9NR+NOpYiX/VB9ZZStVJiCWo+lR735wmpr32daP8EmRbmEpDhjlJ70KbwtSX 2PyJuV5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1snENt-0000000GVUb-2UOe; Sun, 08 Sep 2024 09:39:05 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1snEMt-0000000GVO7-3R84 for linux-arm-kernel@lists.infradead.org; Sun, 08 Sep 2024 09:38:05 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 3F32AA4153F; Sun, 8 Sep 2024 09:37:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9B76C4CEC3; Sun, 8 Sep 2024 09:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725788280; bh=siJn425AxZ5+7HkM3BgAENCGYl7MdXTqBPGST4nKFcY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lPLeRvTGFAWE1X2IoSaZ9WkgMsVRhhTxDBU+ZjXIiQEw6hgN9Cwly5XSQSoUTMoTA Sl9HGCWYZaamEKPCuzJ+4h8zFZvh/oqS2FuugJeA/C3nCb2WSYjU5nGOtH/w6Btebd 4yJZuewcfwF2kOiXfA9e4tIC0ATJ5PqCCdwQG+ygYG11hWir1DQEV30AwaXD5SE45z R/CW5V364aAXx1Nvc37ea1OUrgFVEAWAABu0WOoLsSZC5BBGoMr4aUwM40AHX73mEI YWd8Kw5eebZWZKQpRXY/Z1xxKvYOUh+BZDvFCsTSE+ccG1XgLT/3v60fVsv/Hsh2sC uL24p8s/3JWtA== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1snEMo-00Aczu-ST; Sun, 08 Sep 2024 10:37:59 +0100 Date: Sun, 08 Sep 2024 10:37:53 +0100 Message-ID: <87wmjmv632.wl-maz@kernel.org> From: Marc Zyngier To: Sergey Shtylyov Cc: Thomas Gleixner , , Subject: Re: [PATCH] irqchip/gic: prevent buffer overflow in gic_ipi_send_mask() In-Reply-To: References: <048ff3bb-09d1-2e60-4f3b-611e2bfde7aa@omp.ru> <87cyli5zj7.ffs@tglx> <86o752v8xs.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: s.shtylyov@omp.ru, tglx@linutronix.de, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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-20240908_023804_010988_DDE0045B X-CRM114-Status: GOOD ( 24.14 ) 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 On Fri, 06 Sep 2024 21:29:47 +0100, Sergey Shtylyov wrote: > > On 9/5/24 10:47 AM, Marc Zyngier wrote: > [...] > > >>> ARM GIC arch v2 spec claims support for just 8 CPU interfaces. However, > >>> looking at the GIC driver's irq_set_affinity() method, it seems that the > >>> passed CPU mask may contain the logical CPU #s beyond 8, and that method > >>> filters them out before reading gic_cpu_map[], bailing out with > >>> -EINVAL. > >> > >> The reasoning is correct in theory, but in reality it's a non problem. > >> > >> Simply because processors which use this GIC version cannot have more > >> than 8 cores. > >> > >> That means num_possible_cpus() <= 8 so the cpumask handed in cannot have > >> bits >= 8 set. Ergo for_each_cpu() can't return a bit which is >= 8. > > > > That. > > That? :-) What Thomas explained. > > > The irq_set_affinity() check exists because the affinity can be > > provided by userspace, and used to be be *anything*. Since > > In this case you mean gic_set_affinity(), right? Yes. > > > 33de0aa4bae98, the affinity that the driver gets is narrowed to what > > is actually *online*. > > What I haven't quite understood from my (cursory) looking at the GICv2 > spec (and the GIC driver) is why only one CPU (with a lowest #) is selected > from *mask_val before writing to GICD_GIC_DIST_TARGET, while the spec holds > that an IRQ can be forwarded to any set of 8 CPU interfaces... Because on all the existing implementations, having more than a single target in GICD_ITARGETSRn results in all the targeted CPUs to be interrupted, with the guarantee that only one will see the actual interrupt (the read from GICC_IAR returns a value that is not 0x3ff), and everyone else will only see a spurious interrupt (0x3ff). This is because the distributor does not track which CPU is actually in a position to handle the interrupt. While this can be, under limited circumstances, beneficial from an interrupt servicing latency, it is always bad from a global throughput perspective. You end-up thrashing CPU caches, generating odd latencies in unsuspecting code, and in general with disappointing performance. Thankfully, GIC (v1/v2) is a dead horse, and v3 doesn't have this particular problem (it replaced it with a bigger one in the form of 1:n distribution). M. -- Without deviation from the norm, progress is not possible.