From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796238217; b=g4EOORpjhXwwYJyOYJe8N3ZdVzZ0QX3pe7OBhIaJjtNBFBf4Nh3zr7S92roT4TwCP5Ow e53m8kVFhZlpl6kEsDbDxkvSbYDhS3MWdETFaTjGM+tNtCftg6JroyuV2LMgVFDsk64oO FrgYNrjif9/jP7cuvfOTGoyr+eyG2t4VIhRmYj3MQBUajs1ah1MP2Q1o/Qh1eECvzLnnc pL8WG8MzDkqqOJMMoaLoxssImD/TDSynEW0gzDTHQK4pKS37TJn7mgFUpq9XVbolN2xFp AWc6Z4TiA3SEfTZ7SF+mtFpvenyzbSUCWtzNTAy6KDQ5URi5gmt+GMpji1V2DkTxwKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796238217; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-Id: In-Reply-To:References:X-Mailer:Mime-Version:Content-Type: Content-Transfer-Encoding; bh=ZFTXBHPx6QaLXx+0N3+DB7ZLV0gU2x3zeXbqaOfHhQs=; b=llUA5IUk8wb3z7Eyoq+h/dHFAxye0qVdF9aeQv6nEr+zC/s088zEOs9D59tmTdKpKUzQ ePqmp2cc5TTFdXYYL5iScDOH/0x6ySluxVcbzWfrqXh/UALS7St750fQJ8El2HrSnecFe n1IPle78vhstSm3lPaRjkAKqYd9Rqiau4v4rWvT/aqcOP1uSVKYCfH/PNtQq1kI5S0ma1 x+HAeMvfQ10fKOfFONe36Ccl3EsXngdQmyDfrR6bk7cfcI6FWOS4hu1+y5r845xb0WYM2 mhd4MAyhVVMpet42uOWo1oKshHGSPKHxR1KxIvKjm9szY5v92mbhPRHgnMkWti9CZtw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=YFYoeWuK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9BC6606A336; Wed, 2 Dec 2026 19:03:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=YFYoeWuK Received: by smtp.kernel.org (Postfix) with ESMTPSA id C66F91F00897; Wed, 2 Dec 2026 19:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796238217; bh=ZFTXBHPx6QaLXx+0N3+DB7ZLV0gU2x3zeXbqaOfHhQs=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=YFYoeWuKG8SrAw/Z0iJhG5ZROjodT9J1Yhi8Hs2nWH38jmKP+BVRhYD5TWUl08lnT RnCSypoOeHVpdTU6Js4RyIGKt4rwAAXmezUeSbbSrn0p2UwwG/7/TMDQGmpyvBQDwO kUaRoDDKSFKQjxT8tySLPteRJrbsrZ4d/ZxXIDcw= Date: Wed, 2 Dec 2026 11:03:36 -0800 From: Andrew Morton To: Vineet Gupta Cc: dennis@kernel.org, tj@kernel.org, cl@gentwo.org, chris@chrisdown.name, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, acme@kernel.org, yonghong.song@linux.dev, eddyz87@gmail.com, martin.lau@linux.dev, nathan@kernel.org, ndesaulniers@google.com, morbo@google.com, justinstitt@google.com, llvm@lists.linux.dev Subject: Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations Message-Id: <20261202110336.89af512bf2a336c18e11556c@linux-foundation.org> In-Reply-To: <20261117220824.609017-1-vineet.gupta@linux.dev> References: <20261117220824.609017-1-vineet.gupta@linux.dev> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 17 Nov 2026 14:08:24 -0800 Vineet Gupta wrote: > __percpu carries BTF_TYPE_TAG(percpu), which records that a pointer > points to per-cpu memory. __PCPU_ATTRS() applies __percpu to the per-cpu > variable itself, so DECLARE_PER_CPU() and DEFINE_PER_CPU() put the tag in > declaration specifier position on the variable's own type. > > arch/x86/include/asm/processor.h has > > DECLARE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info); > > which an x86 defconfig preprocesses to > > extern __seg_gs __attribute__((btf_type_tag("percpu"))) > __attribute__((section(".data..percpu" "..read_mostly"))) > __typeof__(struct cpuinfo_x86) cpu_info; > > and GCC warns: > > processor.h:232:36: warning: ignoring attributes applied to > 'struct cpuinfo_x86' after definition [-Wattributes] > > which -Werror turns into a build failure. > > The compiler is right to object to a type tag on the aggregate, and the > issue is fundamental: every variant of an aggregate shares one DIE, so > there is nowhere to put it. clang drops it silently and GCC warns. > > The tag is meant to record that a pointer points to per-cpu memory, and > cpu_info is not a pointer. > > And this gets worse: for a pointer-typed per-cpu variable GCC attaches > the tag to the pointee, so > > static DEFINE_PER_CPU(struct bpf_hrtimer *, hrtimer_running); > > comes out as PTR -> TYPE_TAG 'percpu' -> struct bpf_hrtimer. The truth > is the other way round: hrtimer_running lives in per-cpu memory and > points at ordinary memory, while that record says it is an ordinary > pointer to per-cpu memory. clang emits no tag there at all. > > Add __percpu_var, which skips the btf tag (__percpu under sparse) and > use it in __PCPU_ATTRS(). > > ... > Sorry, I've been hiding from this patch because I don't understand the BTF stuff at all :( Would it be more appropriate for a BPF person to handle this? The patch does address some real problems so I can queue this for some -next exposure, would prefer not to be the one to upstream it! otoh, Chris had a good look at the previous version so that and a few weeks of -next exposure is enough.