From nobody Sat Feb 7 10:08:23 2026 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 7C1491779A4 for ; Mon, 12 Aug 2024 12:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723464002; cv=none; b=m5uonxafi6oIAN7e9brGodY/aznuO+dB/W0j698fW0mIcgXNqB8MVHqFYQu9pIEuFPLIRIgcSICLKqe0MqbGDoeXUpHVfx1Wsz7vVFI7VjK0MgymsQi6fZV/a/1whC5dpW4Huo4Jd+CtAogKNkX257F2A4bVLPtc17TlXTlTwG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723464002; c=relaxed/simple; bh=vmXxu2Bpkktda/zGB5IUkhfiITUIErTtQ92h56iIjHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QtME0UEpGeTSes5cKjUNeVO/PK+p+0OZJFYhgQdedR+7SYBfqmzfawlHUIHlFuFuG1Xz42qGoMN3w32ZO/PVWWNfZLpxZd154MOSmT2kJ7ntuAT1zyOk9ss9Nec19JJ1LGSDBFocyX8N5aSZBCsw7y0o3rvlST7k7OQpj48U35w= 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=ZmUl+6oA; arc=none smtp.client-ip=209.85.208.48 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZmUl+6oA" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5a10835487fso5736229a12.1 for ; Mon, 12 Aug 2024 05:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723463999; x=1724068799; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fruDKXqvLpvOHXHlfsYMBztoBLfQBCYZJcuGnYhVG7c=; b=ZmUl+6oAMaGLE2SYliqbyz1VAh22PH7JbiS5UbmS9obXt2/cCLAdVCeQB2lxSTdFCr hjoIENIObrPl4bvretAa6pFjY89WH7qIIOR6aIEMkdQtj6WMAvaQVG6MWg+SLRj7ZnQE i9rrvugObayrVAd0E3q8idxUX/v4ZQ9OQuWSUqFTeS9iA/9qxTM/bx7D1WEKutOxDjhz HDkx6wKSAvrqAnz8od5GYQtm7n9gPKJb4rQ0edseCdqaySRNMWLmsylOJJ1EqNbHjRU8 9vnNDYanc8oIRWzsY7ZrDl74oE0XIoAztw6iFqJcIE0eFeKqdYliIUSkj8L6tVstq+En nQKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723463999; x=1724068799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fruDKXqvLpvOHXHlfsYMBztoBLfQBCYZJcuGnYhVG7c=; b=k3d8x5Vy8vYnac0UtBLv2fBR3tzCOK9ddZs51qr1RC6GWd2vZYD6l1m05g+f+yHNhJ FRp6n0G3vt1fX4gEe1T8A9ZZxUkzq6++6BlsCAPmJykfr/wOv1BMza5kd6fOQhXC/R5x VR2SXY8DaXDxG6cT8T3OUwBei/4IEYqAp3liINDlBEbsDKtar87Id2SL+DQ93zdxxs// IHv4uZtsr2b31IOj2tmpBozMi1SyUvScQeUTiVybajymSNuYW4Y0dH873sS7AxF4UNKG u7oipFcmX2wuQqFWD11igo3iGb/z9v9lxQtBzdjvop5SBoahqn8wHpgKkyoow9t2Sxrf c6rg== X-Forwarded-Encrypted: i=1; AJvYcCWW6EfOaVgnD4ZA8ddSZ4gPxU13MMp+bWtPpqzePjQWhSRuYKC76TYkblfgh71n5bnuYFCeH/VTJQ6HkKofAFMfDQqiaekrAhwqsqQ5 X-Gm-Message-State: AOJu0YwGI2ZrhpRYI8jgqVquGn11yA6ICUqhhMgo9G1HFiBoSJPDXf3o ENHaAgsMfngIHksRqA3lbZoHT0W25y37D+h36YxVMAueztOjPDutoVYX4v63EKY= X-Google-Smtp-Source: AGHT+IHuOkc+I/HRzwKiheSTIvJj3Z6nmuPXhvaWwBFb6EcIiM2K0UMjtS7f0OP9qPL7ja6c4c3zXg== X-Received: by 2002:a05:6402:27d0:b0:57c:7471:a0dd with SMTP id 4fb4d7f45d1cf-5bd44c2fb29mr21508a12.12.1723463998274; Mon, 12 Aug 2024 04:59:58 -0700 (PDT) Received: from fedora.iskraemeco.si ([193.77.86.250]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd1a5e04aesm2055970a12.76.2024.08.12.04.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 04:59:57 -0700 (PDT) From: Uros Bizjak To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Dennis Zhou , Tejun Heo , Christoph Lameter , Andy Lutomirski , Ingo Molnar , Nadav Amit , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Borislav Petkov , Luc Van Oostenryck Subject: [RFC PATCH v2 1/4] percpu: Define pcpu_typeof() Date: Mon, 12 Aug 2024 13:57:35 +0200 Message-ID: <20240812115945.484051-2-ubizjak@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240812115945.484051-1-ubizjak@gmail.com> References: <20240812115945.484051-1-ubizjak@gmail.com> 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" Define pcpu_typeof() to use __typeof_unqual__() as typeof operator when available, to return unqualified type of the expression. If an arch defines __percpu variables in their own named address space, then pcpu_typeof() returns unqualified type of the expression without named address space quialifier when CONFIG_CC_HAS_TYPEOF_UNQUAL is defined. Signed-off-by: Uros Bizjak Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Nadav Amit Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Luc Van Oostenryck --- arch/x86/include/asm/percpu.h | 38 ++++++++++++++++++++++------------ include/asm-generic/percpu.h | 26 +++++++++++------------ include/linux/part_stat.h | 2 +- include/linux/percpu-defs.h | 39 ++++++++++++++++++++++++++++------- init/Kconfig | 3 +++ kernel/locking/percpu-rwsem.c | 2 +- 6 files changed, 75 insertions(+), 35 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index c55a79d5feae..4ab4ad60d767 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -73,10 +73,14 @@ unsigned long tcp_ptr__ =3D raw_cpu_read_long(this_cpu_off); \ \ tcp_ptr__ +=3D (__force unsigned long)(_ptr); \ - (typeof(*(_ptr)) __kernel __force *)tcp_ptr__; \ + (pcpu_typeof(*(_ptr)) __kernel __force *)tcp_ptr__; \ }) #else -#define arch_raw_cpu_ptr(_ptr) ({ BUILD_BUG(); (typeof(_ptr))0; }) +#define arch_raw_cpu_ptr(_ptr) \ +({ \ + BUILD_BUG(); \ + (pcpu_typeof(*(_ptr)) __kernel __force *)0; \ +}) #endif =20 #define PER_CPU_VAR(var) %__percpu_seg:(var)__percpu_rel @@ -172,7 +176,7 @@ do { \ : [val] __pcpu_reg_##size("=3D", pfo_val__) \ : [var] "m" (__my_cpu_var(_var))); \ \ - (typeof(_var))(unsigned long) pfo_val__; \ + (pcpu_typeof(_var))(unsigned long) pfo_val__; \ }) =20 #define __raw_cpu_write(size, qual, _var, _val) \ @@ -180,7 +184,7 @@ do { \ __pcpu_type_##size pto_val__ =3D __pcpu_cast_##size(_val); \ \ if (0) { \ - typeof(_var) pto_tmp__; \ + pcpu_typeof(_var) pto_tmp__; \ pto_tmp__ =3D (_val); \ (void)pto_tmp__; \ } \ @@ -193,7 +197,11 @@ do { \ * The generic per-CPU infrastrucutre is not suitable for * reading const-qualified variables. */ -#define __raw_cpu_read_const(pcp) ({ BUILD_BUG(); (typeof(pcp))0; }) +#define __raw_cpu_read_const(pcp) \ +({ \ + BUILD_BUG(); \ + (pcpu_typeof(pcp))0; \ +}) =20 #endif /* CONFIG_USE_X86_SEG_SUPPORT */ =20 @@ -205,7 +213,7 @@ do { \ : [val] __pcpu_reg_##size("=3D", pfo_val__) \ : [var] "i" (&(_var))); \ \ - (typeof(_var))(unsigned long) pfo_val__; \ + (pcpu_typeof(_var))(unsigned long) pfo_val__; \ }) =20 #define percpu_unary_op(size, qual, op, _var) \ @@ -219,7 +227,7 @@ do { \ __pcpu_type_##size pto_val__ =3D __pcpu_cast_##size(_val); \ \ if (0) { \ - typeof(_var) pto_tmp__; \ + pcpu_typeof(_var) pto_tmp__; \ pto_tmp__ =3D (_val); \ (void)pto_tmp__; \ } \ @@ -239,7 +247,7 @@ do { \ (int)(val) : 0; \ \ if (0) { \ - typeof(var) pao_tmp__; \ + pcpu_typeof(var) pao_tmp__; \ pao_tmp__ =3D (val); \ (void)pao_tmp__; \ } \ @@ -263,7 +271,7 @@ do { \ : [tmp] __pcpu_reg_##size("+", paro_tmp__), \ [var] "+m" (__my_cpu_var(_var)) \ : : "memory"); \ - (typeof(_var))(unsigned long) (paro_tmp__ + _val); \ + (pcpu_typeof(_var))(unsigned long) (paro_tmp__ + _val); \ }) =20 /* @@ -272,7 +280,7 @@ do { \ */ #define raw_percpu_xchg_op(_var, _nval) \ ({ \ - typeof(_var) pxo_old__ =3D raw_cpu_read(_var); \ + pcpu_typeof(_var) pxo_old__ =3D raw_cpu_read(_var); \ \ raw_cpu_write(_var, _nval); \ \ @@ -286,7 +294,7 @@ do { \ */ #define this_percpu_xchg_op(_var, _nval) \ ({ \ - typeof(_var) pxo_old__ =3D this_cpu_read(_var); \ + pcpu_typeof(_var) pxo_old__ =3D this_cpu_read(_var); \ \ do { } while (!this_cpu_try_cmpxchg(_var, &pxo_old__, _nval)); \ \ @@ -309,7 +317,7 @@ do { \ : [nval] __pcpu_reg_##size(, pco_new__) \ : "memory"); \ \ - (typeof(_var))(unsigned long) pco_old__; \ + (pcpu_typeof(_var))(unsigned long) pco_old__; \ }) =20 #define percpu_try_cmpxchg_op(size, qual, _var, _ovalp, _nval) \ @@ -568,7 +576,11 @@ do { \ #else /* !CONFIG_X86_64: */ =20 /* There is no generic 64-bit read stable operation for 32-bit targets. */ -#define this_cpu_read_stable_8(pcp) ({ BUILD_BUG(); (typeof(pcp))0; }) +#define this_cpu_read_stable_8(pcp) \ +({ \ + BUILD_BUG(); \ + (pcpu_typeof(pcp))0; \ +}) =20 #define raw_cpu_read_long(pcp) raw_cpu_read_4(pcp) =20 diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h index 94cbd50cc870..c091e09046c5 100644 --- a/include/asm-generic/percpu.h +++ b/include/asm-generic/percpu.h @@ -74,7 +74,7 @@ do { \ =20 #define raw_cpu_generic_add_return(pcp, val) \ ({ \ - typeof(pcp) *__p =3D raw_cpu_ptr(&(pcp)); \ + pcpu_typeof(pcp) *__p =3D raw_cpu_ptr(&(pcp)); \ \ *__p +=3D val; \ *__p; \ @@ -82,8 +82,8 @@ do { \ =20 #define raw_cpu_generic_xchg(pcp, nval) \ ({ \ - typeof(pcp) *__p =3D raw_cpu_ptr(&(pcp)); \ - typeof(pcp) __ret; \ + pcpu_typeof(pcp) *__p =3D raw_cpu_ptr(&(pcp)); \ + pcpu_typeof(pcp) __ret; \ __ret =3D *__p; \ *__p =3D nval; \ __ret; \ @@ -91,7 +91,7 @@ do { \ =20 #define __cpu_fallback_try_cmpxchg(pcp, ovalp, nval, _cmpxchg) \ ({ \ - typeof(pcp) __val, __old =3D *(ovalp); \ + pcpu_typeof(pcp) __val, __old =3D *(ovalp); \ __val =3D _cmpxchg(pcp, __old, nval); \ if (__val !=3D __old) \ *(ovalp) =3D __val; \ @@ -100,8 +100,8 @@ do { \ =20 #define raw_cpu_generic_try_cmpxchg(pcp, ovalp, nval) \ ({ \ - typeof(pcp) *__p =3D raw_cpu_ptr(&(pcp)); \ - typeof(pcp) __val =3D *__p, ___old =3D *(ovalp); \ + pcpu_typeof(pcp) *__p =3D raw_cpu_ptr(&(pcp)); \ + pcpu_typeof(pcp) __val =3D *__p, ___old =3D *(ovalp); \ bool __ret; \ if (__val =3D=3D ___old) { \ *__p =3D nval; \ @@ -115,14 +115,14 @@ do { \ =20 #define raw_cpu_generic_cmpxchg(pcp, oval, nval) \ ({ \ - typeof(pcp) __old =3D (oval); \ + pcpu_typeof(pcp) __old =3D (oval); \ raw_cpu_generic_try_cmpxchg(pcp, &__old, nval); \ __old; \ }) =20 #define __this_cpu_generic_read_nopreempt(pcp) \ ({ \ - typeof(pcp) ___ret; \ + pcpu_typeof(pcp) ___ret; \ preempt_disable_notrace(); \ ___ret =3D READ_ONCE(*raw_cpu_ptr(&(pcp))); \ preempt_enable_notrace(); \ @@ -131,7 +131,7 @@ do { \ =20 #define __this_cpu_generic_read_noirq(pcp) \ ({ \ - typeof(pcp) ___ret; \ + pcpu_typeof(pcp) ___ret; \ unsigned long ___flags; \ raw_local_irq_save(___flags); \ ___ret =3D raw_cpu_generic_read(pcp); \ @@ -141,7 +141,7 @@ do { \ =20 #define this_cpu_generic_read(pcp) \ ({ \ - typeof(pcp) __ret; \ + pcpu_typeof(pcp) __ret; \ if (__native_word(pcp)) \ __ret =3D __this_cpu_generic_read_nopreempt(pcp); \ else \ @@ -160,7 +160,7 @@ do { \ =20 #define this_cpu_generic_add_return(pcp, val) \ ({ \ - typeof(pcp) __ret; \ + pcpu_typeof(pcp) __ret; \ unsigned long __flags; \ raw_local_irq_save(__flags); \ __ret =3D raw_cpu_generic_add_return(pcp, val); \ @@ -170,7 +170,7 @@ do { \ =20 #define this_cpu_generic_xchg(pcp, nval) \ ({ \ - typeof(pcp) __ret; \ + pcpu_typeof(pcp) __ret; \ unsigned long __flags; \ raw_local_irq_save(__flags); \ __ret =3D raw_cpu_generic_xchg(pcp, nval); \ @@ -190,7 +190,7 @@ do { \ =20 #define this_cpu_generic_cmpxchg(pcp, oval, nval) \ ({ \ - typeof(pcp) __ret; \ + pcpu_typeof(pcp) __ret; \ unsigned long __flags; \ raw_local_irq_save(__flags); \ __ret =3D raw_cpu_generic_cmpxchg(pcp, oval, nval); \ diff --git a/include/linux/part_stat.h b/include/linux/part_stat.h index ac8c44dd8237..e228e1087f0c 100644 --- a/include/linux/part_stat.h +++ b/include/linux/part_stat.h @@ -33,7 +33,7 @@ struct disk_stats { =20 #define part_stat_read(part, field) \ ({ \ - typeof((part)->bd_stats->field) res =3D 0; \ + pcpu_typeof((part)->bd_stats->field) res =3D 0; \ unsigned int _cpu; \ for_each_possible_cpu(_cpu) \ res +=3D per_cpu_ptr((part)->bd_stats, _cpu)->field; \ diff --git a/include/linux/percpu-defs.h b/include/linux/percpu-defs.h index 8efce7414fad..aa824c6edb82 100644 --- a/include/linux/percpu-defs.h +++ b/include/linux/percpu-defs.h @@ -220,6 +220,21 @@ do { \ (void)__vpp_verify; \ } while (0) =20 +/* + * Define percpu_typeof() to use __typeof_unqual__() as typeof + * operator when available, to return unqualified type of the exp. + * + * If an arch defines __percpu variables in their own named address + * space, then pcpu_typeof() returns unqualified type of the + * expression without named address space qualifier when + * CONFIG_CC_HAS_TYPEOF_UNQUAL is defined. + */ +#ifdef CONFIG_CC_HAS_TYPEOF_UNQUAL +#define pcpu_typeof(exp) __typeof_unqual__(exp) +#else +#define pcpu_typeof(exp) __typeof__(exp) +#endif + #ifdef CONFIG_SMP =20 /* @@ -228,7 +243,10 @@ do { \ * pointer value. The weird cast keeps both GCC and sparse happy. */ #define SHIFT_PERCPU_PTR(__p, __offset) \ - RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset)) + uintptr_t ptr__ =3D (__force uintptr_t)(__p); \ + \ + RELOC_HIDE((pcpu_typeof(*(__p)) __kernel __force *)(ptr__), \ + (__offset)) =20 #define per_cpu_ptr(ptr, cpu) \ ({ \ @@ -254,13 +272,20 @@ do { \ =20 #else /* CONFIG_SMP */ =20 -#define VERIFY_PERCPU_PTR(__p) \ +#define PERCPU_PTR(__p) \ ({ \ - __verify_pcpu_ptr(__p); \ - (typeof(*(__p)) __kernel __force *)(__p); \ + uintptr_t ptr__ =3D (__force uintptr_t)(__p); \ + \ + (pcpu_typeof(*(__p)) __kernel __force *)(ptr__); \ +}) + +#define per_cpu_ptr(ptr, cpu) \ +({ \ + __verify_pcpu_ptr(ptr); \ + (void)(cpu); \ + PERCPU_PTR(ptr); \ }) =20 -#define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); VERIFY_PERCPU_PTR(ptr); }) #define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0) #define this_cpu_ptr(ptr) raw_cpu_ptr(ptr) =20 @@ -315,7 +340,7 @@ static __always_inline void __this_cpu_preempt_check(co= nst char *op) { } =20 #define __pcpu_size_call_return(stem, variable) \ ({ \ - typeof(variable) pscr_ret__; \ + pcpu_typeof(variable) pscr_ret__; \ __verify_pcpu_ptr(&(variable)); \ switch(sizeof(variable)) { \ case 1: pscr_ret__ =3D stem##1(variable); break; \ @@ -330,7 +355,7 @@ static __always_inline void __this_cpu_preempt_check(co= nst char *op) { } =20 #define __pcpu_size_call_return2(stem, variable, ...) \ ({ \ - typeof(variable) pscr2_ret__; \ + pcpu_typeof(variable) pscr2_ret__; \ __verify_pcpu_ptr(&(variable)); \ switch(sizeof(variable)) { \ case 1: pscr2_ret__ =3D stem##1(variable, __VA_ARGS__); break; \ diff --git a/init/Kconfig b/init/Kconfig index 37260d17267e..a9a04d0683b6 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -873,6 +873,9 @@ config ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH config CC_HAS_INT128 def_bool !$(cc-option,$(m64-flag) -D__SIZEOF_INT128__=3D0) && 64BIT =20 +config CC_HAS_TYPEOF_UNQUAL + def_bool $(success,echo 'int foo (int a) { __typeof_unqual__(a) b =3D a; = return b; }' | $(CC) -x c - -S -o /dev/null) + config CC_IMPLICIT_FALLTHROUGH string default "-Wimplicit-fallthrough=3D5" if CC_IS_GCC && $(cc-option,-Wimplic= it-fallthrough=3D5) diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c index 6083883c4fe0..8345238ba428 100644 --- a/kernel/locking/percpu-rwsem.c +++ b/kernel/locking/percpu-rwsem.c @@ -184,7 +184,7 @@ EXPORT_SYMBOL_GPL(__percpu_down_read); =20 #define per_cpu_sum(var) \ ({ \ - typeof(var) __sum =3D 0; \ + pcpu_typeof(var) __sum =3D 0; \ int cpu; \ compiletime_assert_atomic_type(__sum); \ for_each_possible_cpu(cpu) \ --=20 2.46.0 From nobody Sat Feb 7 10:08:23 2026 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 3DEA41779BB for ; Mon, 12 Aug 2024 12:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723464003; cv=none; b=nTEM6WZheVyHjfSV/F8oEfca38uhG7ZC2KtjgIjeULDLNa4x0XuVmNv8FeFtPcEtfGDrxg805cZEIpmfPEIWcFFM+T40OU3Th71btrVY26EI9yXPtmqSztJnnh/3uUsaaZ3pZkoGMvkHmHDaiOEOuD9Vp1FqzHxY/crDbYrYMYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723464003; c=relaxed/simple; bh=A23uUvQ7BdMbF5zWE+OLndw2Turmi86y1ZGhT+Okjbk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FJ20COOMSGYHA1ed29KagNvBPmdQN49IiNd7J/eFgiyr54g5hdtiLxb0z0JvydZXW529KoXvJD/HHJGkMagKnRED3i6Yyiw16Kg3Z3SDek89ZVkMBs5ffrBLUX69LnTqGSshbtl5oJwBRO9ls3ImSoZN6Bht1O6e78gm4nJB/As= 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=IoxvuOy8; arc=none smtp.client-ip=209.85.218.51 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IoxvuOy8" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a7ab63a388bso139963266b.1 for ; Mon, 12 Aug 2024 05:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723463999; x=1724068799; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=efqfVk4wKUu5y2Eyqs3KUsdZhsPQcKGa1y+niD5IcF0=; b=IoxvuOy8kF2cVguoCm/uSh6VbbikzIvbpW9avQPfnSR03J57klWKCl0OuheIqdc58M w9O9f1LGukXaI1c9c6URP/TV9ESkNMgp1v1LUu049slhoQSmFrY75dCxHdFDANWOcfpL H6nXvZxfeTtHvtUBAvqrRt9h9PIAjeSJzt295aqbY9Oj5wWQCdoZcefgRpK5fWxZxHR4 EmbbEYQK6n6ghbZfDbiQsdOhB1AXnRHBQDBiCNfJxkGZzkhaVTK/Oqjn2h/8S1usewck aX09ifZq8BUuhZpNsUGg3zWpO6z85QQuvz1y77/KAOo6gdGBgGYhPqtvTM7urI14xSGL Eldg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723463999; x=1724068799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=efqfVk4wKUu5y2Eyqs3KUsdZhsPQcKGa1y+niD5IcF0=; b=hJJNiURg6VxEDIq1r0UG/RTJXEecjCPr7gl5SmpBP5LoFj28xKqTMOBlMTgGYOeMew FgIvhzW4YdpZq9jG44JydUVJEtlFjQo1KopJB95yvuY737UesJ4LGAITJaOUsSnqJ7JC +BrWFK+OFjq7xS48r+qX2WBkzZRWfvy2aUunm2715TiHy8XlVma0gkwwIkbvrgBzFWQb FCxrQHOlVNKGIhqw0mPgHvigtNwL3eemiJxx5fDfLsl3X2hCIF2IG6QPq29AUo+q1coR HySebR0ig8QuCyACPDV20juAgzO6V8JM088GZ+zwep3TkfyEFA1OOruuQbkAaQRGrllI DaJA== X-Forwarded-Encrypted: i=1; AJvYcCWwdUxZbZh1R9JEgP2NMCkvN5oaG/G2gIGzLvZQPCVi3Ut14qUyiqD9XnlzaTnm6owT9fZtAQ7IKyq6m1xy8m2TBJlNhAd/DGUCPjaI X-Gm-Message-State: AOJu0YyGg/RXnf/keLJ65F91CWWHojdml5L/kwrcyloQuW/tD7AKIyvD xv9cJTTRrpXFBA0wh9/zSN03BJxI6je1RuQwqIYjq4o6OihhLxDVzuEFOYzUdP8= X-Google-Smtp-Source: AGHT+IGiz6BT46LDWsI4Kfhh8bbjUUZbNV/Nqu7ImfCdRuAQ78vk+RWaGtts3dHDU6gbsnhG/C8MMg== X-Received: by 2002:a05:6402:2347:b0:57d:669:caf2 with SMTP id 4fb4d7f45d1cf-5bd44c66b08mr14452a12.25.1723463999358; Mon, 12 Aug 2024 04:59:59 -0700 (PDT) Received: from fedora.iskraemeco.si ([193.77.86.250]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd1a5e04aesm2055970a12.76.2024.08.12.04.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 04:59:58 -0700 (PDT) From: Uros Bizjak To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Dennis Zhou , Tejun Heo , Christoph Lameter , Andy Lutomirski , Ingo Molnar , Nadav Amit , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Borislav Petkov , Luc Van Oostenryck Subject: [RFC PATCH v2 2/4] percpu: Assorted fixes found by strict percpu address space checks Date: Mon, 12 Aug 2024 13:57:36 +0200 Message-ID: <20240812115945.484051-3-ubizjak@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240812115945.484051-1-ubizjak@gmail.com> References: <20240812115945.484051-1-ubizjak@gmail.com> 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" Assorted fixes to prevent defconfig build failures when strict percpu address space checks will be enabled. These show effeciveness of strict percpu address space checks. Signed-off-by: Uros Bizjak Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Nadav Amit Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Luc Van Oostenryck --- arch/x86/kernel/head64.c | 3 ++- drivers/base/devres.c | 2 +- fs/aio.c | 2 +- include/linux/cleanup.h | 4 ++-- include/linux/prandom.h | 1 + kernel/events/hw_breakpoint.c | 4 ++-- kernel/workqueue.c | 2 +- lib/percpu_counter.c | 2 +- net/core/dev.c | 2 +- 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index a817ed0724d1..f5d6ad351cc4 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -560,9 +560,10 @@ void early_setup_idt(void) void __head startup_64_setup_gdt_idt(void) { void *handler =3D NULL; + struct desc_struct *gdt =3D (struct desc_struct *)(uintptr_t)init_per_cpu= _var(gdt_page.gdt); =20 struct desc_ptr startup_gdt_descr =3D { - .address =3D (unsigned long)&RIP_REL_REF(init_per_cpu_var(gdt_page.gdt)), + .address =3D (unsigned long)&RIP_REL_REF(*gdt), .size =3D GDT_SIZE - 1, }; =20 diff --git a/drivers/base/devres.c b/drivers/base/devres.c index a2ce0ead06a6..894f5a1e6d18 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -1231,6 +1231,6 @@ void devm_free_percpu(struct device *dev, void __perc= pu *pdata) * devm_free_pages() does. */ WARN_ON(devres_release(dev, devm_percpu_release, devm_percpu_match, - (__force void *)pdata)); + (__force void *)(uintptr_t)pdata)); } EXPORT_SYMBOL_GPL(devm_free_percpu); diff --git a/fs/aio.c b/fs/aio.c index 6066f64967b3..e8920178b50f 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -100,7 +100,7 @@ struct kioctx { =20 unsigned long user_id; =20 - struct __percpu kioctx_cpu *cpu; + struct kioctx_cpu __percpu *cpu; =20 /* * For percpu reqs_available, number of slots we move to/from global diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index d9e613803df1..f7e1158cbacf 100644 --- a/include/linux/cleanup.h +++ b/include/linux/cleanup.h @@ -154,7 +154,7 @@ static inline class_##_name##_t class_##_name##ext##_co= nstructor(_init_args) \ #define DEFINE_GUARD(_name, _type, _lock, _unlock) \ DEFINE_CLASS(_name, _type, if (_T) { _unlock; }, ({ _lock; _T; }), _type = _T); \ static inline void * class_##_name##_lock_ptr(class_##_name##_t *_T) \ - { return *_T; } + { return (void *)(uintptr_t)*_T; } =20 #define DEFINE_GUARD_COND(_name, _ext, _condlock) \ EXTEND_CLASS(_name, _ext, \ @@ -211,7 +211,7 @@ static inline void class_##_name##_destructor(class_##_= name##_t *_T) \ \ static inline void *class_##_name##_lock_ptr(class_##_name##_t *_T) \ { \ - return _T->lock; \ + return (void *)(uintptr_t)_T->lock; \ } =20 =20 diff --git a/include/linux/prandom.h b/include/linux/prandom.h index f7f1e5251c67..f2ed5b72b3d6 100644 --- a/include/linux/prandom.h +++ b/include/linux/prandom.h @@ -10,6 +10,7 @@ =20 #include #include +#include #include =20 struct rnd_state { diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c index 6c2cb4e4f48d..d82fe78f0658 100644 --- a/kernel/events/hw_breakpoint.c +++ b/kernel/events/hw_breakpoint.c @@ -849,7 +849,7 @@ register_wide_hw_breakpoint(struct perf_event_attr *att= r, =20 cpu_events =3D alloc_percpu(typeof(*cpu_events)); if (!cpu_events) - return (void __percpu __force *)ERR_PTR(-ENOMEM); + return (void __percpu __force *)(uintptr_t)ERR_PTR(-ENOMEM); =20 cpus_read_lock(); for_each_online_cpu(cpu) { @@ -868,7 +868,7 @@ register_wide_hw_breakpoint(struct perf_event_attr *att= r, return cpu_events; =20 unregister_wide_hw_breakpoint(cpu_events); - return (void __percpu __force *)ERR_PTR(err); + return (void __percpu __force *)(uintptr_t)ERR_PTR(err); } EXPORT_SYMBOL_GPL(register_wide_hw_breakpoint); =20 diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 1745ca788ede..32729a2e93af 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -377,7 +377,7 @@ struct workqueue_struct { =20 /* hot fields used during command issue, aligned to cacheline */ unsigned int flags ____cacheline_aligned; /* WQ: WQ_* flags */ - struct pool_workqueue __percpu __rcu **cpu_pwq; /* I: per-cpu pwqs */ + struct pool_workqueue __rcu * __percpu *cpu_pwq; /* I: per-cpu pwqs */ struct wq_node_nr_active *node_nr_active[]; /* I: per-node nr_active */ }; =20 diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c index 51bc5246986d..3d0613ac7e73 100644 --- a/lib/percpu_counter.c +++ b/lib/percpu_counter.c @@ -209,7 +209,7 @@ int __percpu_counter_init_many(struct percpu_counter *f= bc, s64 amount, INIT_LIST_HEAD(&fbc[i].list); #endif fbc[i].count =3D amount; - fbc[i].counters =3D (void *)counters + (i * counter_size); + fbc[i].counters =3D (void __percpu *)counters + (i * counter_size); =20 debug_percpu_counter_activate(&fbc[i]); } diff --git a/net/core/dev.c b/net/core/dev.c index 751d9b70e6ad..5cad88cf029c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10860,7 +10860,7 @@ noinline void netdev_core_stats_inc(struct net_devi= ce *dev, u32 offset) return; } =20 - field =3D (__force unsigned long __percpu *)((__force void *)p + offset); + field =3D (unsigned long __percpu *)(void __percpu *)(p + offset); this_cpu_inc(*field); } EXPORT_SYMBOL_GPL(netdev_core_stats_inc); --=20 2.46.0 From nobody Sat Feb 7 10:08:23 2026 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 CD9DD178387 for ; Mon, 12 Aug 2024 12:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723464004; cv=none; b=eRwlMXN54od+vaHm9iTym4uFEwy8YiNjV0XYp5vyceUXh/YZTDTQPGK3FnDhemQXfXh15O58n7Xi8RGuc9W6Lu3xYKvd+PKg6yN32QYU74r/eqK5NGytsM3CoR99hQ4LdNpP5c4Fvx5sQjx32J2KLxrPzAXNfJTESYcr9Bb67Zg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723464004; c=relaxed/simple; bh=y0S3xQjkruxUj/Chc3SsrTEw1JQcaPlDIEiQXmm0SEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c+5k7qdRvCMQz0DNReOAhqF7sF5R2l9LvTtA6pfBMMvAgw3oQ7rZRwFTqq1UVtHdW/bHEBY8iIhlPM3v4QUEIobjatuFPFLXQNf/nVoAB9nxI3i4ds2ysA1JWZuEzmcg0xtub8jMTxI5n3V5ZeG/FpzbVTkNh7Qbl8kxFnSGUg8= 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=jVCWQfrP; arc=none smtp.client-ip=209.85.208.48 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jVCWQfrP" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5a1c496335aso1940795a12.1 for ; Mon, 12 Aug 2024 05:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723464001; x=1724068801; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JJLe5IUAL1/xG0v/qE20AqL4y9xZWwRXykIQj0IeARs=; b=jVCWQfrPLl6RkiboAWlyDhAyFo/UAKhzrrI1ZdvBu4jNvQEs2ymwohsibyVnqWMCP1 v7/1QMFzJWNzj5BqnmnAgCN5A2IFfAZr4KEn3kIR+3IA2rzGazOAGNGYDtGTE/HGX7lQ gcRGMsGkGXYr8MXMhgVe2ihdWAb2w1L9evahLfehNAkVd+XX0Miz4UN9Em8HdEUnQYdH Q1DCbe0g1+iYE26Hyp8p7fvozw+5MAyZKkXqyqABSBYNXMxpudi9Qx5FC2ge7Uz7Fk+B qbukxJp4N8alutT6H94wrKD20HLcybSPP96Wgu0LpFa+xjvx9GwXOaHB4hfTUdPD3k+j 9AZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723464001; x=1724068801; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JJLe5IUAL1/xG0v/qE20AqL4y9xZWwRXykIQj0IeARs=; b=UtH5IDu4ir2PgDzxSWdYcatau6dWvGbLX6MNSKBRYh93tub4qwsPEewo/6YxzTNZ95 MqKdFHD1P7SRc4oSVmivRDyRl4urq0/xcTHNETY6cxk8GCG/PqewiWxD2zJQ7i20rTZu DPPOG2hpxRJ28Xd8F1G4jUUaPpJ3bIbr5xKGnuKV6OgLVcuMji1BWqr+edSTcgC82Ngy KguEtDDmVm2mnH95Ak55bnNh/KCiBMHp82csbdb1RjFUx0PezOIblIg9FBhBmO2E9QD9 j4enNJgyA3Wf/uAK80jSKoeKrgcS9taf6RpZeSfqcN9ps2/TAQcFukP1yJB3Ea5gd3kZ BqjQ== X-Forwarded-Encrypted: i=1; AJvYcCVTiIqvT+BWS6XrUn3o3JbtVTuXgLyjQLqiMHJMhQg2R7ON3vdCpDJONMMu8krzUqwsOdzV81qzK3UtM+EPBCn+3BG/J9Yn7XWNLQfd X-Gm-Message-State: AOJu0YyrbNipxEZ/X0VnKRpkp8WwSx74a1YFzWAK8oCKRXxk3Bnid1qo CH7w5/uT/7JNSXwIWKbHYR3Nqw45QQtL8pR+hUKznzXgpL+YDBmr X-Google-Smtp-Source: AGHT+IHLf0wX3sTf+xZ73mLemXQoM3mULwR0RMBbNFiKu9Xs4bJxq0l9b69j/UaSYylfIRYCAo7wzA== X-Received: by 2002:a05:6402:3552:b0:5bb:9ae0:4a49 with SMTP id 4fb4d7f45d1cf-5bd44c66a3amr11213a12.30.1723464000709; Mon, 12 Aug 2024 05:00:00 -0700 (PDT) Received: from fedora.iskraemeco.si ([193.77.86.250]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd1a5e04aesm2055970a12.76.2024.08.12.04.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 05:00:00 -0700 (PDT) From: Uros Bizjak To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Dennis Zhou , Tejun Heo , Christoph Lameter , Andy Lutomirski , Ingo Molnar , Nadav Amit , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Borislav Petkov , Luc Van Oostenryck Subject: [RFC PATCH v2 3/4] percpu: Repurpose __percpu tag as a named address space qualifier Date: Mon, 12 Aug 2024 13:57:37 +0200 Message-ID: <20240812115945.484051-4-ubizjak@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240812115945.484051-1-ubizjak@gmail.com> References: <20240812115945.484051-1-ubizjak@gmail.com> 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" The patch introduces per_cpu_qual define and repurposes __percpu tag as a named address space qualifier using the new define. Arches can now conditionally define __per_cpu_qual as their named address space qualifier for percpu variables. Signed-off-by: Uros Bizjak Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Nadav Amit Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Luc Van Oostenryck --- include/asm-generic/percpu.h | 15 +++++++++++++++ include/linux/compiler_types.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h index c091e09046c5..5f85d7ba8e2d 100644 --- a/include/asm-generic/percpu.h +++ b/include/asm-generic/percpu.h @@ -6,6 +6,21 @@ #include #include =20 +/* + * per_cpu_qual is the qualifier for the percpu named address space. + * + * Most arches use generic named address space for percpu variables but + * some arches define percpu variables in different named address space + * (on the x86 arch, percpu variables may be declared as being relative + * to the %fs or %gs segments using __seg_fs or __seg_gs named address + * space qualifiers). + */ +#ifdef __per_cpu_qual +#define per_cpu_qual __per_cpu_qual +#else +#define per_cpu_qual /* nothing */ +#endif + #ifdef CONFIG_SMP =20 /* diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index f14c275950b5..4c5917b97bc3 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -57,7 +57,7 @@ static inline void __chk_io_ptr(const volatile void __iom= em *ptr) { } # define __user BTF_TYPE_TAG(user) # endif # define __iomem -# define __percpu BTF_TYPE_TAG(percpu) +# define __percpu per_cpu_qual BTF_TYPE_TAG(percpu) # define __rcu BTF_TYPE_TAG(rcu) =20 # define __chk_user_ptr(x) (void)0 --=20 2.46.0 From nobody Sat Feb 7 10:08:23 2026 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 5D0D817A588 for ; Mon, 12 Aug 2024 12:00:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723464007; cv=none; b=VcmMJ4clfGvxY6mSsME7ANrUrDZDA+z0SGP0yWLS6XkFTYytyOReCshgn1jdNDHNNPH79ebQ17ae4Eht2Abjxeal/57RQFQsA421hnUCVfs6S6EUXMx+82mqW0WhUEHQAF/kn7XK6U1+NjXnrLr4Go4r1J34vMHMGZkI4OL9+lE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723464007; c=relaxed/simple; bh=tA4SiORwu8uHyYqQ7ye+y4E02/avmDo7X6E7ktKohLw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=av7sLEjtkDG7fShI+dPLz2PRJDQFzGaP3LeWL/BacmCVXkW2V2KZnFMHxM+zpQKt/JfR/+Yis9oUlDKkbbCycd0qpoM4rVCeA9xvPBTmS9cxx8qHUb1IiaGGINQh7ssDxUCGchY/anMcBCXkYB3DW4qN+o0TzSGJzotub4kHHwo= 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=nRfgxWuk; arc=none smtp.client-ip=209.85.208.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nRfgxWuk" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2f15790b472so53121211fa.0 for ; Mon, 12 Aug 2024 05:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723464003; x=1724068803; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x3uJRiNLLgOcZsmmzORMPDWc5fHy9y5CyFJXSzVXE+M=; b=nRfgxWukfDLNKufVHZI6iJodcBMcQErIl3eoV2XyxlbIYJuHlkUXpk1p7cXupZISXc A7vdX/jNOKDmXYf92+E2SWeyX4uOejhbeh3jq9Jipr4I5Xgo1yI6vs+m75rvuhg1mkNw p9NjXNgMROXyOGoSPw9JJirOEfGvi96s3I4PQiS4R3NYC7GqBAdOBbKXak8+ZTMPEEH/ 2essmTPuVn7+6n44NeZHPWmNSfW/ihYHaL/TtlZDryYYNrz8fQ7hknLkjCe0FmPgA/j5 320oAjoHYFdhWKjvD6Ngsp35EKTGkQUE8vrzGc2vTjJXXNDwJHBqCMkOHSxXrSB+MGvM D4sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723464003; x=1724068803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x3uJRiNLLgOcZsmmzORMPDWc5fHy9y5CyFJXSzVXE+M=; b=LLYF69Ya/E2KYuqMWHs5FOdpVef8Fd+Wj8JPECtCPPHGyTtaesnv7yZq+XhDz3UKd6 G31TxjbCoj5ZUgWBCdjP18wBwoum9ntQz48pxOvqI3dSeZf/7SCqAVOWOJQ7XsRyHob1 YlhTQciSUYLbdcss51SSbscM5L6vovcK2PN/8Wwn4OUNhLdX2au8Gwyo4HR3/Cb95+we ECHNfJQ2WTF7pZhn2c5UEYbH6aAvvuMz9eC23v7RSeLFshHCb78sa1hrOiwDx1R9WauB K629xzataxvw1xZIXkf0DkGsXAu1F5VDYTS0YPKBKy4RnDJeDqH1H3rZm5QOCYACBgQT ttOw== X-Forwarded-Encrypted: i=1; AJvYcCV+RUgPuCL5k+oCY5P7bHqgwbOeaIiJ4RIllm2+9V8ZAJ9Zjfi07Ltni3q81JwJyB6dBTGzC1ShzJQzM0Faoc+GSx7tBzsnp18zZ+ku X-Gm-Message-State: AOJu0Yx1fTUpThJ76O2WE4QckMb5wopzoK9EzgXmGpxEuj8jhrD1MswA nyhYrc6UzLwpSEEeTWlY0LNvAlWv7yCYDxxfsd+V0SYiZEtD7zJm X-Google-Smtp-Source: AGHT+IHKlXKj0B7JY5kmC2Q2zZaBnmA29zjjoQCSZ3jusm9LFJTTfxdKLemTAAxWJakoGZgPOzvHiQ== X-Received: by 2002:a05:651c:545:b0:2ef:c281:54f7 with SMTP id 38308e7fff4ca-2f1a6cf52a4mr60754621fa.37.1723464002929; Mon, 12 Aug 2024 05:00:02 -0700 (PDT) Received: from fedora.iskraemeco.si ([193.77.86.250]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd1a5e04aesm2055970a12.76.2024.08.12.05.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 05:00:01 -0700 (PDT) From: Uros Bizjak To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Dennis Zhou , Tejun Heo , Christoph Lameter , Andy Lutomirski , Ingo Molnar , Nadav Amit , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Borislav Petkov , Luc Van Oostenryck Subject: [RFC PATCH v2 4/4] percpu/x86: Enable strict percpu checks via named AS qualifiers Date: Mon, 12 Aug 2024 13:57:38 +0200 Message-ID: <20240812115945.484051-5-ubizjak@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240812115945.484051-1-ubizjak@gmail.com> References: <20240812115945.484051-1-ubizjak@gmail.com> 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" Declare percpu variables in __seg_gs/__seg_fs named AS and keep them named AS qualified until they are dereferenced with percpu accessor. This approach enables various compiler check for cross-namespace variable assignments. Signed-off-by: Uros Bizjak Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Nadav Amit Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Luc Van Oostenryck --- arch/x86/include/asm/percpu.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 4ab4ad60d767..b54119398c4b 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -95,9 +95,18 @@ =20 #endif /* CONFIG_SMP */ =20 -#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))) +#if defined(CONFIG_USE_X86_SEG_SUPPORT) && defined(CONFIG_CC_HAS_TYPEOF_UN= QUAL) +# define __my_cpu_type(var) typeof(var) +# define __my_cpu_ptr(ptr) (ptr) +# define __my_cpu_var(var) (var) + +# define __per_cpu_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))) +#endif + #define __percpu_arg(x) __percpu_prefix "%" #x #define __force_percpu_arg(x) __force_percpu_prefix "%" #x =20 --=20 2.46.0