From nobody Mon Feb 9 05:52:07 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 E200516DC28 for ; Mon, 26 Jan 2026 00:33:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769387593; cv=none; b=iXTXuF0a/BWJVCtGJhLndrxDbfJgfAOeRWe49qTsSIHW+bmEzsmRwHKvdW904Y7s6ac5mLBFGjcGgdZSC1igp8aoIITdJh5YNNgzG2ouwd7FNNzIwK2A1ZYCK+n9DeRUeT4wjeqFS2fd4gU4CPevucwyZwftdRUcOAKB1Fwys6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769387593; c=relaxed/simple; bh=CL1Mshu87ynwu8kNu8sWz+pKSZGzdgDZHPjtAF+6ga4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WwSUkb5TAJGSDLyjV014dLIJ2QioaCdGr4Viv4D1GqJxOzldNlGygiBMnHSWsq6XTOiYsAAwce4sHbzp7XrWh9Iy6Ogi7ekNK/dy2j5mM8MDnbCwbHGfoHgV2hftKnFGsqSbBy1+hEebagLFDEQ683dLsOIjiRcU05JRnWKb37k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elver.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GqRIk4jT; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--elver.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GqRIk4jT" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4801e3aab32so18875185e9.3 for ; Sun, 25 Jan 2026 16:33:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769387590; x=1769992390; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=26BDCJEdJLp7RpCdQh1+Gie1UpBf3nEsfBaL4sC4xLw=; b=GqRIk4jT2MLcyJGzOVE/7z5R1lqLoYyiF6EU/rIF0x64icb606KxUft0TnGFg7G6VL 6wzvasvc/Xm10vPfy/ui5K34HqORdfTQbjETb5489qY7wGrZB75Kp+GDpX9W+Cexppry n5wrj0Gc4pT6VXZ/5sQ35vLpKnavh9Lf0FxlOyMVZHjtY7HOf89p0iG4WM18UCL9pSkw vGftsU+X7e7gUoik5agmJ8YVUe1q+ZkWMhu27luaqTNv8dA9r53CpcdqVD8RYRLljmZu HoE24khaMYwsImPdm7pR0/T2ppRRK8FkB9NbZcStKR8Yj9+Y6pzunM4D1glTUb0q/uGb PuRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769387590; x=1769992390; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=26BDCJEdJLp7RpCdQh1+Gie1UpBf3nEsfBaL4sC4xLw=; b=c0IKKIpp4O1epMOlOReI0OV0BhJ+HFmbkv0QRqHYq1CN1OwBKl5EuJF6Fit71Rg09l pweo+Qh6mgQipz4qllTlOz1GIDEJJSQrHUXU1tRJhCtWEA8htwlwiraVeXNGrDhvSqOM hW5TvLo7QNkIYtJNnN9ntWPscI5DBpqjZjbDNUEtlNDoBeZNMoLg7G5zhZhByhGp8t7L HeQT4nA48AHo7OmOm+ur6nAE39EMa0KDokp8bwemT88Wf9DMhAlw4IX7K1e0C3d2j/Kf 726V5D6ahs05QeYfpFVNKInlrXB0JnEo21x5Jw3D8wVOY1qpaw6+ZpFH862YloFWfOg4 3NEQ== X-Forwarded-Encrypted: i=1; AJvYcCWjaytmKwKquG7ItqmNvSBz00hNRp5CCCL1YtV9o2tG752AiU6MDb9ZNu9GjXKIcEaU9M97meVo/hOK87k=@vger.kernel.org X-Gm-Message-State: AOJu0YwCx9aTxH1tGJ7l0YJSVxgTkbiYuxJL5Pg4wrYq6D9eO3rd15H+ tITGab6HT+FDa7D0upeKAu4/4EgA3bLUJxUsHUmoiqcJS3Nz+JfWYQdBh6zXbV9FSwsFGUDoTby cAQ== X-Received: from wmbjw5.prod.google.com ([2002:a05:600c:5745:b0:47e:e4f5:36ca]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:190c:b0:477:9dc1:b706 with SMTP id 5b1f17b1804b1-4805ce67eb4mr48399755e9.19.1769387590378; Sun, 25 Jan 2026 16:33:10 -0800 (PST) Date: Mon, 26 Jan 2026 01:25:11 +0100 In-Reply-To: <20260126002936.2676435-1-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260126002936.2676435-1-elver@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260126002936.2676435-3-elver@google.com> Subject: [PATCH 2/3] arm64: Optimize __READ_ONCE() with CONFIG_LTO=y From: Marco Elver To: elver@google.com, Peter Zijlstra , Will Deacon Cc: Ingo Molnar , Thomas Gleixner , Boqun Feng , Waiman Long , Bart Van Assche , llvm@lists.linux.dev, Catalin Marinas , Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rework arm64 LTO __READ_ONCE() to improve code generation as follows: 1. Replace the _Generic-based __unqual_scalar_typeof() with the builtin typeof_unqual(). This strips qualifiers from all types, not just integer types, which is required to be able to assign (must be non-const) to __u.__val in the non-atomic case (required for #2). One subtle point here is that non-integer types of __val could be const or volatile within the union with the old __unqual_scalar_typeof(), if the passed variable is const or volatile. This would then result in a forced load from the stack if __u.__val is volatile; in the case of const, it does look odd if the underlying storage changes, but the compiler is told said member is "const" -- it smells like UB. 2. Eliminate the atomic flag and ternary conditional expression. Move the fallback volatile load into the default case of the switch, ensuring __u is unconditionally initialized across all paths. The statement expression now unconditionally returns __u.__val. This refactoring appears to help the compiler improve (or fix) code generation. With a defconfig + LTO + debug options builds, we observe different codegen for the following functions: btrfs_reclaim_sweep (708 -> 1032 bytes) btrfs_sinfo_bg_reclaim_threshold_store (200 -> 204 bytes) check_mem_access (3652 -> 3692 bytes) [inlined bpf_map_is_rdonly] console_flush_all (1268 -> 1264 bytes) console_lock_spinning_disable_and_check (180 -> 176 bytes) igb_add_filter (640 -> 636 bytes) igb_config_tx_modes (2404 -> 2400 bytes) kvm_vcpu_on_spin (480 -> 476 bytes) map_freeze (376 -> 380 bytes) netlink_bind (1664 -> 1656 bytes) nmi_cpu_backtrace (404 -> 400 bytes) set_rps_cpu (516 -> 520 bytes) swap_cluster_readahead (944 -> 932 bytes) tcp_accecn_third_ack (328 -> 336 bytes) tcp_create_openreq_child (1764 -> 1772 bytes) tcp_data_queue (5784 -> 5892 bytes) tcp_ecn_rcv_synack (620 -> 628 bytes) xen_manage_runstate_time (944 -> 896 bytes) xen_steal_clock (340 -> 296 bytes) Increase of some functions are due to more aggressive inlining due to better codegen (in this build, e.g. bpf_map_is_rdonly is no longer present due to being inlined completely). Signed-off-by: Marco Elver --- arch/arm64/include/asm/rwonce.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/rwonce.h b/arch/arm64/include/asm/rwonc= e.h index fc0fb42b0b64..9963948f4b44 100644 --- a/arch/arm64/include/asm/rwonce.h +++ b/arch/arm64/include/asm/rwonce.h @@ -32,8 +32,7 @@ #define __READ_ONCE(x) \ ({ \ typeof(&(x)) __x =3D &(x); \ - int atomic =3D 1; \ - union { __unqual_scalar_typeof(*__x) __val; char __c[1]; } __u; \ + union { TYPEOF_UNQUAL(*__x) __val; char __c[1]; } __u; \ switch (sizeof(x)) { \ case 1: \ asm volatile(__LOAD_RCPC(b, %w0, %1) \ @@ -56,9 +55,9 @@ : "Q" (*__x) : "memory"); \ break; \ default: \ - atomic =3D 0; \ + __u.__val =3D *(volatile typeof(*__x) *)__x; \ } \ - atomic ? (typeof(*__x))__u.__val : (*(volatile typeof(*__x) *)__x);\ + __u.__val; \ }) =20 #endif /* !BUILD_VDSO */ --=20 2.52.0.457.g6b5491de43-goog