Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp14223647pxu; Mon, 4 Jan 2021 16:57:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxb3XXRpQ6KQAD55NdzytkvSAe7fdvJil0o80lCs+wxPWsb1fsby30sEmA0B8aj2vYJnG3E X-Received: by 2002:a05:6402:487:: with SMTP id k7mr21441827edv.130.1609808244503; Mon, 04 Jan 2021 16:57:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609808244; cv=none; d=google.com; s=arc-20160816; b=xpkxz3HhTm2SEEZp0Q/of728B2EhgHR4FnMgFI0mCloqGD3z8v518SnaFX2I/cvs0K Tx1mKiXZg+E/u+c1xDrWxhDihjF3DhZORQb2mvv2nPSDG/cgBU8NxtE8JRfg6JSjsyEw le1Lgschw8CNqx5PKI5bL8CRQQb3Y3G6IPm5CDJ+twHACDA4ahAuaeAc6fgV6kBZM7II IRh0tHN0nVj4Ifi/A8dW0NhJvXG4eaAyPfDtGWdMXWtWc23tCZJiV7VMuFOigm9rJ6pu PXKAYEhWj1VYg60+lo1TS5rnLAJ3vl2xRSyxfndeu1CmI7aG0AORNbhNUDNGj9ysmoBT hIOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=n/CGDoYBE+dXOpGqRxCS2ivcb9jRqslobwDq2y3UTJw=; b=AFINIS5j/Wk9Q5Gy4VNQa1gRAzqPTxOyTl7G5Xb9BrF+D1kx7jlrkqJX48sgYtUGlM hNwxhM5K+DeCVNbbWhONdzch4eoPyt2aPuGLqi2t21WCOXFcP3CdHFAKwAzgKvnw4OZf Ux8l0Vobu32mHHkf0Q2zEKxWEtaJkENgvXlEB4JPXkRSDLQFE+5ARLXI6xW2KQ4YZg+B 4AzNAMHSsVy2FwnIQU+R11jE1g4/YGTh9winmZEyrc00gWMQvuew3DqNvcuFuhtOKkQV AOTLIyVZ2lp0LHYhksAh7+TN5knbBf7MWomC1CXBzi2ypDg9YBX0MrmRBmETrUZwX/GK TFCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca10si31055242edb.435.2021.01.04.16.57.01; Mon, 04 Jan 2021 16:57:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727384AbhAEAzu (ORCPT + 99 others); Mon, 4 Jan 2021 19:55:50 -0500 Received: from mail-il1-f173.google.com ([209.85.166.173]:39452 "EHLO mail-il1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727148AbhAEAzt (ORCPT ); Mon, 4 Jan 2021 19:55:49 -0500 Received: by mail-il1-f173.google.com with SMTP id q1so27118855ilt.6 for ; Mon, 04 Jan 2021 16:55:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=n/CGDoYBE+dXOpGqRxCS2ivcb9jRqslobwDq2y3UTJw=; b=PEjEOllhDppRVOa+vX1b/HY5G7oqhwA1hwQGTZOcU9WU/C/Wu249oTfK5ou9r2cif7 xNf1lvGQFsTalsZuM1eU3J9rEy+0zytUJtME37hgXpDjTDCrwZNty/tEsafNdgvoTLOE odO6kx8xsS7bYibiSv1tvcILE9Aw9CjDecs6p5sxt23RAEGprN3lf/Buog5QOmmE+RNd 4gHGEfz9HU3VCSSZrieueBVTeFAQ/MB7OBUR0rIUoz4p1lxgw7tCDzk5o7KRYkkaYpIR 33nCjWNiPjudGbRAsS8JURF2erBLt/1DlVPEIDlLLpHNnySP5x5CSPrVB6XjQV0pPZ9r BhiA== X-Gm-Message-State: AOAM532UIr2En7Vq4HHAIiUuOfw+jA/w3iiHp8DHz9pAGY0wUbbItpoC rXSrKhVKvIZ1ku03pt5PvWo= X-Received: by 2002:a92:6f12:: with SMTP id k18mr73850762ilc.66.1609808107998; Mon, 04 Jan 2021 16:55:07 -0800 (PST) Received: from google.com (110.41.72.34.bc.googleusercontent.com. [34.72.41.110]) by smtp.gmail.com with ESMTPSA id 15sm33356984ilx.84.2021.01.04.16.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 16:55:07 -0800 (PST) Date: Tue, 5 Jan 2021 00:55:06 +0000 From: Dennis Zhou To: Nathan Chancellor Cc: Tejun Heo , Christoph Lameter , linux-mm@kvack.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, kbuild-all@lists.01.org, kernel test robot Subject: Re: [PATCH] percpu: fix clang modpost warning in pcpu_build_alloc_info() Message-ID: References: <20201231212852.3175381-1-dennis@kernel.org> <20210104234651.GA3548546@ubuntu-m3-large-x86> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210104234651.GA3548546@ubuntu-m3-large-x86> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 04, 2021 at 04:46:51PM -0700, Nathan Chancellor wrote: > On Thu, Dec 31, 2020 at 09:28:52PM +0000, Dennis Zhou wrote: > > This is an unusual situation so I thought it best to explain it in a > > separate patch. > > > > "percpu: reduce the number of cpu distance comparisons" introduces a > > dependency on cpumask helper functions in __init code. This code > > references a struct cpumask annotated __initdata. When the function is > > inlined (gcc), everything is fine, but clang decides not to inline these > > function calls. This causes modpost to warn about an __initdata access > > by a function not annotated with __init [1]. > > > > Ways I thought about fixing it: > > 1. figure out why clang thinks this inlining is too costly. > > 2. create a wrapper function annotated __init (this). > > 3. annotate cpumask with __refdata. > > > > Ultimately it comes down to if it's worth saving the cpumask memory and > > allowing it to be freed. IIUC, __refdata won't be freed, so option 3 is > > just a little wasteful. 1 is out of my depth, leaving 2. I don't feel > > great about this behavior being dependent on inlining semantics, but > > cpumask helpers are small and probably should be inlined. > > > > modpost complaint: > > WARNING: modpost: vmlinux.o(.text+0x735425): Section mismatch in reference from the function cpumask_clear_cpu() to the variable .init.data:pcpu_build_alloc_info.mask > > The function cpumask_clear_cpu() references > > the variable __initdata pcpu_build_alloc_info.mask. > > This is often because cpumask_clear_cpu lacks a __initdata > > annotation or the annotation of pcpu_build_alloc_info.mask is wrong. > > > > clang output: > > mm/percpu.c:2724:5: remark: cpumask_clear_cpu not inlined into pcpu_build_alloc_info because too costly to inline (cost=725, threshold=325) [-Rpass-missed=inline] > > > > [1] https://lore.kernel.org/linux-mm/202012220454.9F6Bkz9q-lkp@intel.com/ > > > > Reported-by: kernel test robot > > Signed-off-by: Dennis Zhou > > --- > > This is on top of percpu#for-5.12. > > > > mm/percpu.c | 16 ++++++++++++++-- > > 1 file changed, 14 insertions(+), 2 deletions(-) > > > > diff --git a/mm/percpu.c b/mm/percpu.c > > index 80f8f885a990..357977c4cb00 100644 > > --- a/mm/percpu.c > > +++ b/mm/percpu.c > > @@ -2642,6 +2642,18 @@ early_param("percpu_alloc", percpu_alloc_setup); > > > > /* pcpu_build_alloc_info() is used by both embed and page first chunk */ > > #if defined(BUILD_EMBED_FIRST_CHUNK) || defined(BUILD_PAGE_FIRST_CHUNK) > > + > > +/* > > + * This wrapper is to avoid a warning where cpumask_clear_cpu() is not inlined > > + * when compiling with clang causing modpost to warn about accessing __initdata > > + * from a non __init function. By doing this, we allow the struct cpumask to be > > + * freed instead of it taking space by annotating with __refdata. > > + */ > > +static void __init pcpu_cpumask_clear_cpu(int cpu, struct cpumask *mask) > > +{ > > + cpumask_clear_cpu(cpu, mask); > > +} > > + > > /** > > * pcpu_build_alloc_info - build alloc_info considering distances between CPUs > > * @reserved_size: the size of reserved percpu area in bytes > > @@ -2713,7 +2725,7 @@ static struct pcpu_alloc_info * __init pcpu_build_alloc_info( > > cpu = cpumask_first(&mask); > > group_map[cpu] = group; > > group_cnt[group]++; > > - cpumask_clear_cpu(cpu, &mask); > > + pcpu_cpumask_clear_cpu(cpu, &mask); > > > > for_each_cpu(tcpu, &mask) { > > if (!cpu_distance_fn || > > @@ -2721,7 +2733,7 @@ static struct pcpu_alloc_info * __init pcpu_build_alloc_info( > > cpu_distance_fn(tcpu, cpu) == LOCAL_DISTANCE)) { > > group_map[tcpu] = group; > > group_cnt[group]++; > > - cpumask_clear_cpu(tcpu, &mask); > > + pcpu_cpumask_clear_cpu(tcpu, &mask); > > } > > } > > } > > -- > > 2.29.2.729.g45daf8777d-goog > > Hi Nathan, > > Hi Dennis, > > I did a bisect of the problematic config against defconfig and it points > out that CONFIG_GCOV_PROFILE_ALL is in the bad config but not the good > config, which makes some sense as that will mess with clang's inlining > heuristics. It does not appear to be the single config that makes a > difference but it gives some clarity. > Ah, thanks. To me it's kind of a corner case that I don't have a lot of insight into. __init code is pretty limited and this warning is really at the compilers whim. However, in this case only clang throws this warning. > I do not personally have any strong opinions around the patch but is it > really that much wasted memory to just annotate mask with __refdata? It's really not much memory, 1 bit per max # of cpus. The reported config is on the extreme side compiling with 8k NR_CPUS, so 1kb. I'm just not in love with the idea of adding a patch to improve readability and it cost idle memory to resolve a compile time warning. If no one else chimes in in the next few days, I'll probably just apply it and go from there. If another issue comes up I'll drop this and tag it as __refdata. Thanks, Dennis