Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp164813lql; Fri, 12 Apr 2024 07:00:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWy30SJSQddoS1bF4+vTZCOPJcBbQLtGRiISgkcnyfP+glOiQacCzJgj2owQnIpiyroUN/9CI2s/sDYa4LD9Fnz1D+pfSrhLc3VqAXgrA== X-Google-Smtp-Source: AGHT+IHHeDz/KRmuJqCQ02QPmLrSKxm52oSc2cZzVYeCJtMCZbtNSj0MaEg34sGow5SvphRRzmzt X-Received: by 2002:a05:6358:228c:b0:17e:6a5b:4d3a with SMTP id t12-20020a056358228c00b0017e6a5b4d3amr2107476rwb.8.1712930411857; Fri, 12 Apr 2024 07:00:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712930411; cv=pass; d=google.com; s=arc-20160816; b=gGwu0l8pETDixIKSF4lGlTpsNnQdHtrrXZ5yn2y6oqJl+whyXQ7PDXpNNcWjNrLr2I TCOX66/rndMtT74Rycev2g8UU5YjzxKIvwZ4nyMd9WNKMtorobJLZCA7Pvy6Uss9UfI2 6DqU2x0bA800O0BgY7V7yLLL6ejFSqYmLxFLPRgqgmc3XibsEct86vmkVQgMF56u1wZX u77gR+9KjXi8pZ1adGLh3TXSJGhU41sid4F1fgdsQRK/akiwvSg11IvpMTVRfMBrq8tX EFBaEXEyGqK69oD7jxm75InEYBWEQD0SBz4dX+QI5eTonRuwzyXRHFJ9XnXo0VtBqcUG IclA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=y4z7dPWo0s5r7vmjB1y36fPb8YPdW9/A7YVf13iHWK8=; fh=vXnF8lgSsnhm0fjkTnFz+ynHLvwBJ7p7IEt3IHjJUl8=; b=INlkj98wpgZClHijSUuvgUb0AZnqhVzxIcs+4iE/ORkSnkyA5SJCVumVP7Lx4bvJ64 RRmULgMzKbqDavzrvKbUCdEeQsqY7EbShQZp71aNKuRkvx7JjsbbjL8loVqgmLBSRxAM VC23bTyJqKkhbsnyE2tCjFzu2hXxBw7UMByMAKrDU6OcyRbAQVdOZPKcgH4wgMUcXOg8 4AQjNI8Fj1FakkV+zO2WlXU4TPKCD4JrJFd34yekN2UVDmgb2yCt9Bnc15dOT7eLdUS7 PHy71TH4CVZhbhV+5W8jdQpiicp7Kl6PvOb+eRjPJxD/Dv/ucuoEcFDXjdAw7EduqIyQ i2mQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W9a7fOds; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-142771-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142771-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id bq21-20020a056a02045500b005ceef3c53a1si3508146pgb.635.2024.04.12.07.00.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 07:00:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142771-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W9a7fOds; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-142771-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142771-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 25CC0B2176C for ; Fri, 12 Apr 2024 13:53:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47D8E8624F; Fri, 12 Apr 2024 13:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W9a7fOds" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E6C785287 for ; Fri, 12 Apr 2024 13:53:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712930015; cv=none; b=qFabAFOOkaSJ4K7T1m2e+SqtHiqoJCGTXcrk0shv3JAi3wRSKF3uFjw+SlfKNQJSjOFEbmhSraVJ9Not65M3n6uXML27VffMWidOkHdSK+7I+ZuBODiH8Cgr7ImUvPG0gQLDLYMXvDdb4rhLIisv1PqRXmrdCBwjCZpsXDh1WWA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712930015; c=relaxed/simple; bh=5GhNa5rV7rEKpJFGc4DkQalPEvkcxeBWtDg5sglJ6Wg=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=XKe2sRhZqHfLkHTpEMw1UHrBuQNIYTqrSo0dYug3tuONxip2FEX9wCkxXQDSZVVzEkRxsa6WWeGGGYvJBjFn3RYVuXzg2Y5yTNXC03LIJ+7axAOR2AmPPyi6fow2zwE09cY6HAduWiix4580rUbKEgGeGttZw+18EIlHKjGNmiw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W9a7fOds; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9A5DC113CC; Fri, 12 Apr 2024 13:53:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712930014; bh=5GhNa5rV7rEKpJFGc4DkQalPEvkcxeBWtDg5sglJ6Wg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=W9a7fOdsyAsT9KPJSmC4jmJx/R5x73DoZAAq3r4MbDekw9YffvuNlg/3TB3/YDWOg jG9iWLUttC9672FJoCSS66UZMY12TBa0X2xi58WVSqGx1wyh3mpXUsrZkqF6KhIs4B hG9Lbjw2EftNLn+9N9R4wTqdFUP6WhwSOBWryoOeUmRW1pqh7pF6voYiAZOYiCujsc hhr+nvhPNgPGWYJ0A6pj5emN/hAZm36uR0vzzzcHLbfAAkxlfV+4RfVDAuDCvMSzUd iUpXIwCNdIFtCd0wH6YxaEq5xAEnPVHJlS5EpIFlRUSrRZjpcV/HmIUjvozk7zsJef uAcuYUdbH5nWQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.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 1rvHLQ-003uFv-GW; Fri, 12 Apr 2024 14:53:32 +0100 Date: Fri, 12 Apr 2024 14:53:32 +0100 Message-ID: <86il0msn4z.wl-maz@kernel.org> From: Marc Zyngier To: Dawei Li Cc: tglx@linutronix.de, yury.norov@gmail.com, akpm@linux-foundation.org, florian.fainelli@broadcom.com, chenhuacai@kernel.org, jiaxun.yang@flygoat.com, anup@brainfault.org, palmer@dabbelt.com, samuel.holland@sifive.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/6] irqchip/gic-v3-its: Avoid explicit cpumask allocation on stack In-Reply-To: <20240412105839.2896281-4-dawei.li@shingroup.cn> References: <20240412105839.2896281-1-dawei.li@shingroup.cn> <20240412105839.2896281-4-dawei.li@shingroup.cn> 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.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: dawei.li@shingroup.cn, tglx@linutronix.de, yury.norov@gmail.com, akpm@linux-foundation.org, florian.fainelli@broadcom.com, chenhuacai@kernel.org, jiaxun.yang@flygoat.com, anup@brainfault.org, palmer@dabbelt.com, samuel.holland@sifive.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Fri, 12 Apr 2024 11:58:36 +0100, Dawei Li wrote: > > In general it's preferable to avoid placing cpumasks on the stack, as > for large values of NR_CPUS these can consume significant amounts of > stack space and make stack overflows more likely. > > Remove cpumask var on stack and use proper cpumask API to address it. Define proper. Or better, define what is "improper" about the current usage. > > Signed-off-by: Dawei Li > --- > drivers/irqchip/irq-gic-v3-its.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c > index fca888b36680..a821396c4261 100644 > --- a/drivers/irqchip/irq-gic-v3-its.c > +++ b/drivers/irqchip/irq-gic-v3-its.c > @@ -3826,7 +3826,7 @@ static int its_vpe_set_affinity(struct irq_data *d, > bool force) > { > struct its_vpe *vpe = irq_data_get_irq_chip_data(d); > - struct cpumask common, *table_mask; > + struct cpumask *table_mask; > unsigned long flags; > int from, cpu; > > @@ -3850,8 +3850,11 @@ static int its_vpe_set_affinity(struct irq_data *d, > * If we are offered another CPU in the same GICv4.1 ITS > * affinity, pick this one. Otherwise, any CPU will do. > */ > - if (table_mask && cpumask_and(&common, mask_val, table_mask)) > - cpu = cpumask_test_cpu(from, &common) ? from : cpumask_first(&common); > + if (table_mask && cpumask_intersects(mask_val, table_mask)) { > + cpu = cpumask_test_cpu(from, mask_val) && > + cpumask_test_cpu(from, table_mask) ? > + from : cpumask_first_and(mask_val, table_mask); So we may end-up computing the AND of the two bitmaps twice (once for cpumask_intersects(), once for cpumask_first_and()), instead of only doing it once. I don't expect that to be horrible, but I also note that you don't even talk about the trade-offs you are choosing to make. > + } > else > cpu = cpumask_first(mask_val); Please fix the coding style (if () { ... } else { ... }). M. -- Without deviation from the norm, progress is not possible.