From nobody Thu Apr 2 20:28:14 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 95A7938F22D for ; Fri, 27 Mar 2026 02:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774578139; cv=none; b=eQ4g+Nw6nDUhFIeLpEKLC3d4Xr5iv+bEZY6o4k9ycYD8rODhoqZNk3ib+ahvMIrIipBiTmwvJ3bI99ilIOfQxOcOwC1dRR+b8SZxQ+R2/6/nAFtsYFV3Xj52nVN+Y2JlLoujXZwhA9DP4SyqmvOr+NS6RWEZLYR2gLUTm/sz1JA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774578139; c=relaxed/simple; bh=UGzU1mq0mWTa3MC6NaQ1zDuSMBjlUw2dx1/E5mRiol8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q/17PRqVdycHh96TWe+e8/s8CvJ8vHQB8mOhpWWicmXF7DAndYFq0TwCyOVH2Ryr/1Yz5tGB+joEtBsgHmE96jOZfTgVeIGuF4kpHCFulM2pt/JR6410hoczgNx0keSQ556xs5UP9B8hyGFafwg+tAtR5HPKVQeNP3Fa5v1x6jA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=csX6smVV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=c+mj4E82; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="csX6smVV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="c+mj4E82" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1774578135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DXjrn8JaZj55Y3q5GBHuBALmB2iH7f42lYVO8MWGAqs=; b=csX6smVVqU8dVFeANDf4oVE/WqfJGsfwdxGccsu01oM3RwMI+Mhb9/frKKykSl8P3vuTYY MKiqPNwsF7ljjsXn/N/aX1D6IWasOKfZgYplyAfWDGDFkwfEOYQtnOwYQsWWy2X4JvtvwH H8YqrgOM9upbrNpdghzWtdsSQpYNkx6l/No4dX64EeGu1nlttzYjQFm+GG1DALhwEvnkJ5 ml9CgFGcYoOmCxm7iz2tB1Rp6RuzBfYt6HpVQVtSHiNXJIlJbQzypiMfmKLb7SeLAUE6Mr mE/T36xeYYzepYT79bwm0XVPQB0YunRaSXbZDfQhD8gcHaK3hxPgHYHa+SoQFA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1774578135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DXjrn8JaZj55Y3q5GBHuBALmB2iH7f42lYVO8MWGAqs=; b=c+mj4E82tg6Mi/6J6Xu2BgGQizDC3Vs5kyuQP7tNoyi2miIUsCCOpN1Dg+cMQN42f7wnnj 7F40lfI0uCaEGWAg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Sean Christopherson , David Woodhouse , Peter Zijlstra , Christian Ludloff , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v6 81/90] x86/percpu: Add offset argument to x86_this_cpu_test_bit() Date: Fri, 27 Mar 2026 03:16:35 +0100 Message-ID: <20260327021645.555257-82-darwi@linutronix.de> In-Reply-To: <20260327021645.555257-1-darwi@linutronix.de> References: <20260327021645.555257-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" x86_this_cpu_test_bit() assumes that the queried bitmap starts at the base address of the percpu object. For X86_FEATURE bitops, this matches the current cpuinfo_x86::x86_capability[] layout. Upcoming changes though will route all X86_FEATURE queries to the CPUID tables, where the bitmap resides at the per-CPU CPUID table plus an offset. Add an offset argument to x86_this_cpu_test_bit(). Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpufeature.h | 2 +- arch/x86/include/asm/percpu.h | 34 ++++++++++++++++++------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufe= ature.h index 520949560138..b12bde4986b5 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -56,7 +56,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; =20 #define this_cpu_has(bit) \ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \ - x86_this_cpu_test_bit(bit, cpu_info.x86_capability)) + x86_this_cpu_test_bit(bit, cpu_info.x86_capability, 0)) =20 /* * This is the default CPU features testing macro to use in code. diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 409981468cba..8a36f0bb979d 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -89,15 +89,17 @@ #endif /* CONFIG_SMP */ =20 #if defined(CONFIG_USE_X86_SEG_SUPPORT) && defined(USE_TYPEOF_UNQUAL) -# define __my_cpu_type(var) typeof(var) -# define __my_cpu_ptr(ptr) (ptr) -# define __my_cpu_var(var) (var) +# define __my_cpu_type(var) typeof(var) +# define __my_cpu_ptr(ptr) (ptr) +# define __my_cpu_ptr_off(ptr, off) (typeof(ptr))((uintptr_t)(ptr) + (off)) +# define __my_cpu_var(var) (var) =20 -# define __percpu_qual __percpu_seg_override +# define __percpu_qual __percpu_seg_override #else -# define __my_cpu_type(var) typeof(var) __percpu_seg_override -# define __my_cpu_ptr(ptr) (__my_cpu_type(*(ptr))*)(__force uintptr_t)(ptr) -# define __my_cpu_var(var) (*__my_cpu_ptr(&(var))) +# define __my_cpu_type(var) typeof(var) __percpu_seg_override +# define __my_cpu_ptr(ptr) (__my_cpu_type(*(ptr))*)(__force uintptr_t)(pt= r) +# define __my_cpu_ptr_off(ptr, off) (__my_cpu_type(*(ptr))*)((__force uint= ptr_t)(ptr) + (off)) +# define __my_cpu_var(var) (*__my_cpu_ptr(&(var))) #endif =20 #define __force_percpu_arg(x) __force_percpu_prefix "%" #x @@ -570,29 +572,33 @@ do { \ */ #define this_cpu_read_stable(pcp) __pcpu_size_call_return(this_cpu_read_= stable_, pcp) =20 -#define x86_this_cpu_constant_test_bit(_nr, _var) \ +#define x86_this_cpu_constant_test_bit(_nr, _var, _offset) \ ({ \ unsigned long __percpu *addr__ =3D \ - (unsigned long __percpu *)&(_var) + BIT_WORD(_nr); \ + (unsigned long __percpu *)((u8 __percpu *)&(_var) + (_offset)) +\ + BIT_WORD(_nr); \ + \ + /* Ensure bitops safety */ \ + BUILD_BUG_ON(!IS_ALIGNED((unsigned long)(_offset), sizeof(unsigned long))= );\ \ !!(BIT_MASK(_nr) & raw_cpu_read(*addr__)); \ }) =20 -#define x86_this_cpu_variable_test_bit(_nr, _var) \ +#define x86_this_cpu_variable_test_bit(_nr, _var, _offset) \ ({ \ bool oldbit; \ \ asm volatile("btl %[nr], " __percpu_arg([var]) \ : "=3D@ccc" (oldbit) \ - : [var] "m" (__my_cpu_var(_var)), \ + : [var] "m" (*__my_cpu_ptr_off(&(_var), _offset)), \ [nr] "rI" (_nr)); \ oldbit; \ }) =20 -#define x86_this_cpu_test_bit(_nr, _var) \ +#define x86_this_cpu_test_bit(_nr, _var, _offset) \ (__builtin_constant_p(_nr) \ - ? x86_this_cpu_constant_test_bit(_nr, _var) \ - : x86_this_cpu_variable_test_bit(_nr, _var)) + ? x86_this_cpu_constant_test_bit(_nr, _var, _offset) \ + : x86_this_cpu_variable_test_bit(_nr, _var, _offset)) =20 =20 #include --=20 2.53.0