From nobody Sat Jun 20 01:02:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E520C433EF for ; Mon, 28 Mar 2022 14:58:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244154AbiC1PAH (ORCPT ); Mon, 28 Mar 2022 11:00:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244146AbiC1O76 (ORCPT ); Mon, 28 Mar 2022 10:59:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2307CB84 for ; Mon, 28 Mar 2022 07:58:16 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1648479494; 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=SOuuvst+UUNcj8L4Pzp1TF8twONkUaE7vZdYgdMuLVo=; b=HgHOi4bJEj3U+SyFteDlU1LoxRHx0XUwJUo5/Krx3azavcESGbVbGBAE/dBrN+TNhfoi1c hlVxi9KlPTd6r5UZLSIjAl9jy607KP1HeZ7ahddP+Vbr3a2Bj+C8wQJOF9ySxfMzDOav/k fzbLG/NF3wwy6OppYP8RKHR0kQu0A5tqF4AnmIbl80/94GaoHphXUhpZWxWKVqlanDGbmf ihhAfqCGMYO+FvBAblg0vABkV0XyfvcNCx32/qaWeO75kL1Bk+ZD0wsovvYLG6jWnAFZ5H AhL6VR9815NgZDhX1J3feMmJjqT6nshKdroiq/wSnYV6f9jzinJBNz2Up12x2Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1648479494; 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=SOuuvst+UUNcj8L4Pzp1TF8twONkUaE7vZdYgdMuLVo=; b=2aCABIvcnUJpmvSC8UGLXtseBPVnJlnqfN1q1go6xtgFvzsm+iRVJNNKc6wIkd3IrnvyoO f3f+oZc0RjR82VCQ== To: torvalds@linux-foundation.org Cc: akpm@linux-foundation.org, bigeasy@linutronix.de, boqun.feng@gmail.com, bp@alien8.de, linux-kernel@vger.kernel.org, longman@redhat.com, mingo@kernel.org, peterz@infradead.org, tglx@linutronix.de, will@kernel.org, Dennis Zhou , Tejun Heo , Christoph Lameter Subject: [PATCH v2 1/3] x86/percpu: Remove volatile from arch_raw_cpu_ptr(). Date: Mon, 28 Mar 2022 16:58:08 +0200 Message-Id: <20220328145810.86783-2-bigeasy@linutronix.de> In-Reply-To: <20220328145810.86783-1-bigeasy@linutronix.de> References: <20220328145810.86783-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The volatile attribute in the inline assembly of arch_raw_cpu_ptr() forces the compiler to always generate the code, even if the compiler can decide upfront that its result is not needed. For instance invoking __intel_pmu_disable_all(false) (like intel_pmu_snapshot_arch_branch_stack() does) leads to loading the address of &cpu_hw_events into the register while compiler knows that it has no need for it. This ends up with code like: | movq $cpu_hw_events, %rax #, tcp_ptr__ | add %gs:this_cpu_off(%rip), %rax # this_cpu_off, tcp_ptr__ | xorl %eax, %eax # tmp93 It also creates additional code within local_lock() with !RT && !LOCKDEP which is not desired. By removing the volatile attribute the compiler can place the function freely and avoid it if it is not needed in the end. By using the function twice the compiler properly caches only the variable offset and always loads the CPU-offset. this_cpu_ptr() also remains properly placed within a preempt_disable() sections because - arch_raw_cpu_ptr() assembly has a memory input ("m" (this_cpu_off)) - prempt_{dis,en}able() fundamentally has a 'barrier()' in it Therefore this_cpu_ptr() is already properly serialized and does not rely on the 'volatile' attribute. Remove volatile from arch_raw_cpu_ptr(). [ bigeasy: Added Linus' explanation why this_cpu_ptr() is not moved out of a preempt_disable() section without the 'volatile' attribute. ] Suggested-by: Linus Torvalds Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/include/asm/percpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index a3c33b79fb865..5d572a19a389c 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -38,7 +38,7 @@ #define arch_raw_cpu_ptr(ptr) \ ({ \ unsigned long tcp_ptr__; \ - asm volatile("add " __percpu_arg(1) ", %0" \ + asm ("add " __percpu_arg(1) ", %0" \ : "=3Dr" (tcp_ptr__) \ : "m" (this_cpu_off), "0" (ptr)); \ (typeof(*(ptr)) __kernel __force *)tcp_ptr__; \ --=20 2.35.1 From nobody Sat Jun 20 01:02:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B7F3C433F5 for ; Mon, 28 Mar 2022 14:58:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244196AbiC1PAM (ORCPT ); Mon, 28 Mar 2022 11:00:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244149AbiC1O76 (ORCPT ); Mon, 28 Mar 2022 10:59:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C66BFDA for ; Mon, 28 Mar 2022 07:58:16 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1648479494; 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=G2K1bd9HAywoNYrUHng0l9se10lIg8eInYuxNMOXcG4=; b=EjUDbP7aP+qljVDBR2MAkDM5xU7vd9b9xa/rPob4/Vxcjov1URp6frYUNDHEpFX4qdKCGn dKuumlIgipJ0kMAxTQBICYpdOPU0HOI41z4KbrB2rPvndGLigSO5Vz7Qu6kfGdBfvVMk3X O02BpueYAoy3y5LOO7GEbe+Xl0RJPBQ8xUzUOsyz8skHJy3RtvZJM6LtQQqIjKgRS0oePz bAGZO0VYqwtA0/OkByTkrgrFK3IbNAy91Gcne3AR5we9OpsFS5X1D7VR8cGlC34WilEkx9 jtbVKl7fP2Z4T8Lx5rsjB5FgZp3IRDkePP9e/gsBqi9D8mZIJ14xPiMRn3dIEg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1648479494; 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=G2K1bd9HAywoNYrUHng0l9se10lIg8eInYuxNMOXcG4=; b=AlG2M3cx5+lNV2y/UxoYM+/ULV7blsPiFDlKJqN+gLBnL9PpXqYyYZPN557Bqa+aVvqX03 li9Dt4cAnMHsBSDQ== To: torvalds@linux-foundation.org Cc: akpm@linux-foundation.org, bigeasy@linutronix.de, boqun.feng@gmail.com, bp@alien8.de, linux-kernel@vger.kernel.org, longman@redhat.com, mingo@kernel.org, peterz@infradead.org, tglx@linutronix.de, will@kernel.org, Dennis Zhou , Tejun Heo , Christoph Lameter Subject: [PATCH v2 2/3] Revert "locking/local_lock: Make the empty local_lock_*() function a macro." Date: Mon, 28 Mar 2022 16:58:09 +0200 Message-Id: <20220328145810.86783-3-bigeasy@linutronix.de> In-Reply-To: <20220328145810.86783-1-bigeasy@linutronix.de> References: <20220328145810.86783-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With volatile removed from arch_raw_cpu_ptr() the compiler no longer creates the per-CPU reference. The usage of the macro can be reverted now. Signed-off-by: Sebastian Andrzej Siewior --- include/linux/local_lock_internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock= _internal.h index 6d635e8306d64..975e33b793a77 100644 --- a/include/linux/local_lock_internal.h +++ b/include/linux/local_lock_internal.h @@ -44,9 +44,9 @@ static inline void local_lock_debug_init(local_lock_t *l) } #else /* CONFIG_DEBUG_LOCK_ALLOC */ # define LOCAL_LOCK_DEBUG_INIT(lockname) -# define local_lock_acquire(__ll) do { typecheck(local_lock_t *, __ll); }= while (0) -# define local_lock_release(__ll) do { typecheck(local_lock_t *, __ll); }= while (0) -# define local_lock_debug_init(__ll) do { typecheck(local_lock_t *, __ll)= ; } while (0) +static inline void local_lock_acquire(local_lock_t *l) { } +static inline void local_lock_release(local_lock_t *l) { } +static inline void local_lock_debug_init(local_lock_t *l) { } #endif /* !CONFIG_DEBUG_LOCK_ALLOC */ =20 #define INIT_LOCAL_LOCK(lockname) { LOCAL_LOCK_DEBUG_INIT(lockname) } --=20 2.35.1 From nobody Sat Jun 20 01:02:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED1B4C433EF for ; Mon, 28 Mar 2022 14:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244202AbiC1PAQ (ORCPT ); Mon, 28 Mar 2022 11:00:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244150AbiC1O76 (ORCPT ); Mon, 28 Mar 2022 10:59:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7B1FC22 for ; Mon, 28 Mar 2022 07:58:16 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1648479495; 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=Pv8dPye5wqKdpkd72Xtt1o/6g48q7qMfvkbKH0ypcdU=; b=yVW52wZDuAlUh2e5q5nj/MGD5g5xNYHDONO/qL5BPypPkzAweOQ0cUmy+agYZkaq8dKajR DbpDQRO6ECzhnCgcdK8s+KG/0vImpFXz9yVpzMAWWlo083Pp25F2OaSz+BLmu0IWIm2L4n 3HaF9LqZo8ZzuKWthXvLrkgXRFcoZRVSYMG844URBKew4SVpLUfUJHDKlH9Lw2RmPao/+W /QiHWgFncCUDFlzczJo+RCvxN/gFoDifNYf9i3420XoaBERrU+gxV96FYC0PRirYSaRqK/ FOSFpdH8l1lfr8BeGeTRviAQQeTI0Ca6mSY3VK3yvoR95206wEANcS94ZyhcwA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1648479495; 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=Pv8dPye5wqKdpkd72Xtt1o/6g48q7qMfvkbKH0ypcdU=; b=8jMiRFg7CoAsJEIe2nIseEoi7wD5R+VpjM7p87QuQMFqI0oDjFEYGjCQ/fVJMgdgJIefpB T1u+K41m8x8DVqAg== To: torvalds@linux-foundation.org Cc: akpm@linux-foundation.org, bigeasy@linutronix.de, boqun.feng@gmail.com, bp@alien8.de, linux-kernel@vger.kernel.org, longman@redhat.com, mingo@kernel.org, peterz@infradead.org, tglx@linutronix.de, will@kernel.org, Dennis Zhou , Tejun Heo , Christoph Lameter Subject: [PATCH v2 3/3] Revert "mm/page_alloc: mark pagesets as __maybe_unused" Date: Mon, 28 Mar 2022 16:58:10 +0200 Message-Id: <20220328145810.86783-4-bigeasy@linutronix.de> In-Reply-To: <20220328145810.86783-1-bigeasy@linutronix.de> References: <20220328145810.86783-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The local_lock() is now using a proper static inline function which is enough for llvm to accept that the variable is used. Signed-off-by: Sebastian Andrzej Siewior --- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index bdc8f60ae4622..634323b13cd2f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -128,7 +128,7 @@ static DEFINE_MUTEX(pcp_batch_high_lock); struct pagesets { local_lock_t lock; }; -static DEFINE_PER_CPU(struct pagesets, pagesets) __maybe_unused =3D { +static DEFINE_PER_CPU(struct pagesets, pagesets) =3D { .lock =3D INIT_LOCAL_LOCK(lock), }; =20 --=20 2.35.1