Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp927110lqt; Fri, 19 Apr 2024 15:14:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVwN4hu2zy+sPytw+BNlHjHvjPMlZ/FdyK2i1YyZAwn2zOGcqBzPh63ux/afzfhZwvHt9V/wh2T6qQtJG7/YH+0r9QUC05UnaKwTSzoqg== X-Google-Smtp-Source: AGHT+IEuaXZmQrrxTGoZrC1KmXxSRKL8+MSaHX7xRbcTY4Kf4aA3diZUDX92kLJVe3DFwHPLfs+p X-Received: by 2002:a05:6a00:2d1e:b0:6ed:1012:9572 with SMTP id fa30-20020a056a002d1e00b006ed10129572mr4768505pfb.29.1713564843626; Fri, 19 Apr 2024 15:14:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713564843; cv=pass; d=google.com; s=arc-20160816; b=rIRahZ/lZOGolWi8k4wyYiaxEeWy1re70G4hFriV+Qiqq4gQcTMGI+fm2nkmuUcIbi lR14MLVruw/unTxTAWgkKBrPn7cItLIptmxHLsgX8le/V5bRVwhWwbH52xfvUbmOGw2K nHrL64H8/evFPd1j7C8hPPZjKt/Kph1K3lUsaf3an5igHwlrq7Q5wJXqLzd5C8J5cEGA kjJa5EKTsU5EpdALNSZBwauZ6XkAdqOIukdBgqVXzOGXVauIVgszRTSG98AftIC4VCOG BdsNvDIHC0MQPMpy9GJtmrptb5AFLX5ZIQUE/9EPxRu5Rjnl0MFd8JubHbqM0VPpO7dF YzkA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=XLemlwrfOOHHIdLYfovzq1+tB6FxSufcqxpxI2QR6C4=; fh=WJ2vCc3DWsuSX/DUCQRjHxxZ6qjzNttA2aHbQIJNwGE=; b=inopqHdqH4VAOWLtN3GU3L1EIzvvvKolG8+zitjh4E2MAciEoi3DwDapL3nnK/cC8k w+J5MdZO7givQwXoUL58mWQUCwlU6oIIscjf5JuT0OL+dcImbiBTUMGYuVCBBCN+mmza ZNBbX3EQpuPsNB89KbQtSOIR6YjW8nyWBR5qCiiwh6c7BsI6Mc2JoYSD1r67HzJoCkKV VitT0qaYEa1+CNUNzsNXpY3PMbKfhPsI/rYzt8FM/byAj13sOjCEk77GKF9aAFtvtEJT vUeeqoWydgnrq56nydgpw3Kpho5elbvSPcVT/Fr/0BQ8W83RAegE1xwlSmnao0ASR5ci 2agg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eBUVhb7G; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-151993-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151993-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id i2-20020a636d02000000b005f7ddef45bfsi2348138pgc.789.2024.04.19.15.14.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 15:14:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151993-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=@gmail.com header.s=20230601 header.b=eBUVhb7G; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-151993-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151993-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 2BDC1B21598 for ; Fri, 19 Apr 2024 22:14:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B72113D288; Fri, 19 Apr 2024 22:13:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eBUVhb7G" Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC08712DD97; Fri, 19 Apr 2024 22:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713564834; cv=none; b=UzpuKnjhrLR8Z0zuO+ZhUYA3JrOETcmT4qnSEoU+S6GPWKRB4hb8VwqPRbTwsXV7VBH4obaCISlnj398tHtpDYjgJ7qCqpCs8CeRNJprK3WH1Q1dtEuDmsD1lUqNmgwJOS6gh7uX9F/myocdDr/Cp7/8SjhSkk1zp5/iOkvZKk0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713564834; c=relaxed/simple; bh=4RCTcwheMb+Q4EVU5iBIoEbIEMFY5NKFObbcFjjXIbI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NdV/qW8SGG8F5CfJrGQnzMnHcCtekLwjBsCiUtU/L8+IaYtDmbWyoje/hWBH0mckXdGUkNT7zbvJmnT/oV7yjosH/w9eqMfMcrQvEA59rEgbF5dfxMp0nBqyz7Uw9dGU0M6ISZKqyTLToN8K0dW5XNBQyQ0knSY8LGNMnBueOIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eBUVhb7G; arc=none smtp.client-ip=209.85.128.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-61b2218ab6fso19151057b3.1; Fri, 19 Apr 2024 15:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713564831; x=1714169631; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=XLemlwrfOOHHIdLYfovzq1+tB6FxSufcqxpxI2QR6C4=; b=eBUVhb7GtmQP5q1TjYAWoU40THJtXmg/ihX9CGCsKx2/VC4CZ3mLPV8Y1G75gok1YM JuFG5I5hyw6mYtBteTa1ZESMPp35EVaVBE3fd7jpsV+8+G2t/vkhDrxkznBLcL0e1isp f/fhdADRmBaBxRMXjWp8oZVK52aR1lEHPc6T+niyXJ1KTDsg1nyMsV2enhfFOyovkV6r VLVZXhSZfWsZ/Hwn3DOjSOxAFCIK4oNsBfApJW3GjWAjoXAVbI/cj5sFpVLhr9jOtXw5 XmJQ93jmovdAcDLfCra4rz2DUCruXl0W8DsaTloaPyFjiOB4hizsHMfv6hwUXnM4AV66 KZ5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713564831; x=1714169631; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XLemlwrfOOHHIdLYfovzq1+tB6FxSufcqxpxI2QR6C4=; b=mmy7QT7h5duNhgkENtiNUaNCTFhdNlxWYdYLKEJZFsts7Wt/pdxczrgDO5r/4QBwOn i5mzXzbqbpdNx38tL5CSLjOQOJja1UjM6yk03NmFwVBnndQNiy+gShhgkMBZQ52xRWF6 gYJmKaFu59WgW/vhtq5li4ymRZtp8Lr0XBJ09aP87Q1v9z66p2jdrD8ofcVOmhsq9l5Q POzsbt29EqcsEtcwoPgCMBLqLuGI90G1XGHNxwolfgIi2/VWRiiU/zQs1+0B9FE0z1QU 4UG2vDejwFErgm8MvE8ka77ODL+0g9SKxZ2LggtPZPNGRuqPBBJFG4ZmgrkM+ozi+dB/ ziYw== X-Forwarded-Encrypted: i=1; AJvYcCU40pt8BzujvgtmJYSpB6BJZG6G+z0MwHhLapZSIq4NiWxDiCjklRgUePXZwSISGWCXBCWmc9q5JzG0T6h/QJwBXKyf7zUL+5QL/X9RdQfRiNbD5mDS3M4Wd8fWCx3Ow80JYmOmQ/dOUg== X-Gm-Message-State: AOJu0YxUpKHNGyJYBV/DroyTfTS0wku6/5mibdPsfv8Zzzz02f5Mzprr SS72X3r3J6kAexk9pkcxt4NqZ/J/B4vSGEXyQpXXWJNnuedHSnYlteJkFw== X-Received: by 2002:a05:690c:301:b0:618:2972:ee3b with SMTP id bg1-20020a05690c030100b006182972ee3bmr3438512ywb.39.1713564831483; Fri, 19 Apr 2024 15:13:51 -0700 (PDT) Received: from localhost ([2601:344:8301:57f0:7f85:3703:8b1a:b551]) by smtp.gmail.com with ESMTPSA id m190-20020a0dfcc7000000b006187ad29fe8sm957045ywf.61.2024.04.19.15.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 15:13:50 -0700 (PDT) Date: Fri, 19 Apr 2024 15:13:49 -0700 From: Yury Norov To: Dawei Li Cc: Sam Ravnborg , davem@davemloft.net, andreas@gaisler.com, sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/5] Remove onstack cpumask var usage Message-ID: References: <20240418104949.3606645-1-dawei.li@shingroup.cn> <20240419051350.GA558245@ravnborg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Apr 19, 2024 at 05:26:34PM +0800, Dawei Li wrote: > Hi Sam, > > Thanks for the review. > > On Fri, Apr 19, 2024 at 07:13:50AM +0200, Sam Ravnborg wrote: > > Hi Dawei, > > > > On Thu, Apr 18, 2024 at 06:49:44PM +0800, Dawei Li wrote: > > > Hi, > > > > > > This series aims at removing on-stack cpumask var usage for sparc arch. > > > > > > Generally 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. > > > > Took a quick look at the patches, looks good except the one the bot > > already complained about. > > I will fix this building warning in respinning. > > > A quick grep shows a few more cases where we have an on-stack cpumask > > in sparc code. > > > > kernel/ds.c: cpumask_t mask; > > About this case, it's kinda tricky for: > - dr_cpu_data() returns void, so alloc_cpumask_var() is no go. > > - No idea of the calling context of dr_cpu_data(). IIUC, > dr_cpu_data() > ->dr_cpu_configure() > ->kzalloc(resp_len, GFP_KERNEL) > So I guess it's in process context? > If consumption above is OK, a simple but _ugly_ solution could be: > > diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c > index ffdc15588ac2..c9e4ebdccf49 100644 > --- a/arch/sparc/kernel/ds.c > +++ b/arch/sparc/kernel/ds.c > @@ -634,7 +634,8 @@ static void dr_cpu_data(struct ds_info *dp, struct ds_cap_state *cp, void *buf, > struct dr_cpu_tag *tag = (struct dr_cpu_tag *) (data + 1); > u32 *cpu_list = (u32 *) (tag + 1); > u64 req_num = tag->req_num; > - cpumask_t mask; > + static DEFINE_MUTEX(mask_lock); > + static cpumask_t mask; > unsigned int i; > int err; > > @@ -651,6 +652,8 @@ static void dr_cpu_data(struct ds_info *dp, struct ds_cap_state *cp, void *buf, > > purge_dups(cpu_list, tag->num_records); > > + mutex_lock(&mask_lock); > + > cpumask_clear(&mask); > for (i = 0; i < tag->num_records; i++) { > if (cpu_list[i] == CPU_SENTINEL) > @@ -665,6 +668,8 @@ static void dr_cpu_data(struct ds_info *dp, struct ds_cap_state *cp, void *buf, > else > err = dr_cpu_unconfigure(dp, cp, req_num, &mask); > > + mutex_unlock(&mask_lock); > + > if (err) > dr_cpu_send_error(dp, cp, data); > } > > How does it sound to you? > > > kernel/leon_kernel.c: cpumask_t mask; > > It's in irqchip::irq_set_affinity(), which is in atomic context(raw spinlock(s) held), > so dynamic allocation is not a good idea. > > My proposal(*untested*) is somewhat complicated for it introduces a new helper. > > diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c > index 4c61da491fee..6eced7acb8bc 100644 > --- a/arch/sparc/kernel/leon_kernel.c > +++ b/arch/sparc/kernel/leon_kernel.c > @@ -104,15 +104,25 @@ unsigned long leon_get_irqmask(unsigned int irq) > } > > #ifdef CONFIG_SMP > + > +static bool cpumask_include(const struct cpumask *srcp1, const struct cpumask *srcp2) Don't steal the other's subsystems prefixes. > +{ > + unsigned int cpu; > + > + for_each_cpu(cpu, srcp2) { > + if (!cpumask_test_cpu(cpu, srcp1)) > + return false; > + } > + > + return true; > +} We've got cpumask_subset() for this. > static int irq_choose_cpu(const struct cpumask *affinity) > { > - cpumask_t mask; > + unsigned int cpu = cpumask_first_and(affinity, cpu_online_mask); > > - cpumask_and(&mask, cpu_online_mask, affinity); > - if (cpumask_equal(&mask, cpu_online_mask) || cpumask_empty(&mask)) > - return boot_cpu_id; > - else > - return cpumask_first(&mask); > + return cpumask_include(affinity, cpu_online_mask) || cpu >= nr_cpu_ids ? > + boot_cpu_id : cpu; > } > #else > #define irq_choose_cpu(affinity) boot_cpu_id > > Is it OK? > > [cc Yury for bitmap API] > > > kernel/leon_smp.c:static void leon_cross_call(void *func, cpumask_t mask, unsigned long arg1, > > kernel/sun4d_smp.c:static void sun4d_cross_call(void *func, cpumask_t mask, unsigned long arg1, > > Actually I am awared of existence of (at least some of) them, but so far I > have not found a _proper_ way of dealing with them(especially for case of > ds.c). > > Please lemme dig into it. > > Thanks, > > Dawei > > > > > Do you plan to look at the other on-stack users too? > > It would be nice to see them all gone in one patch-set. > > > > Sam > >