From mboxrd@z Thu Jan 1 00:00:00 1970 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 5909024337B for ; Mon, 16 Feb 2026 14:50:35 +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=1771253438; cv=none; b=ZKrDlQRRhVWq5Efc36k1pn6SjDPrVIy5ifb18INlOXy3dQlr2RFs2f2sKfeTEOwULcBDtq94eNVfTLqkE7cdD+PNiItY0W+E1R1jCypMfy5PqinI51g3sihr5p/SUqG5aNWPApqh8b+OKc+SVIBU3mOOjQ+QhuyqQxCcyFHFKLQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771253438; c=relaxed/simple; bh=XDS/TVM0jMEwrqdteBCv+QzDwSKxalu9xwOECnHeIfQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=MFyu1pBT80L3WxldiBqFzJp3XJ0vQTnSCv+iMGUTJN8/Q7khZMC5/bZ5Zl2lg39Vs3p76E40FpcFO3/MzKrS8JynNcoDZHYecKOgGqyeSxhhVKgJEPZJiNtZyVY3vQVlGRIyUGr6euTN/QxWXgG9LZ549r/UKJv2djioux3cXE0= 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=C6FIudtU; 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="C6FIudtU" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4837b9913c9so15732755e9.0 for ; Mon, 16 Feb 2026 06:50:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771253434; x=1771858234; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=PN5r/7tt47yJK8ejJibZMzrosjD0HGAjuC2k5NzaqOI=; b=C6FIudtUj86wq2UdStKIMOF0UaIMO6Xne4j3iRvpTUdI1dRWVjIN/fYNZOl6vQTykp 4uDgJ5ZJhgoLgbutBOcC3XfYSipS/IQCeps5NnqI/et7m0CjPY8WEczzZhWn9fblCUhT AKiU88XvX9WzglVxyQghFjFbkYT+6mBv149jsIyn03VTsXIFq7OPKy8Oi8cQwxMEqF0x lea6d8QPTKWrFU52js72QV6VfV6k41uvh+4OxLdtzYDyRL6OFmsNB8+orvvkRJVTCmHs sayl5jqMG3c5N2EyIXYazyecJMSZ6kp5ZUix+lgce2snvmgBh0FmcUQ2WvK5dsy0QJWe s4Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771253434; x=1771858234; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PN5r/7tt47yJK8ejJibZMzrosjD0HGAjuC2k5NzaqOI=; b=eYQjFURn6MBYj4VtNXsZol70MVfBSt5lEx0sY8BAtGTi6t61v19LSGE+/3KB5AYtFG HcF+VuuDhSxkuif0wVQ8ULxv0WsPoV2a+CEXLT00MQCdhCm0/9sVEj8ST6K7XHImQiQT 3OqsMW6br/ST16LHAl6+RKRTR93Gn2rZFy7LuOnVJ1vEJTDtY3R72FJpPSYN0x1EJxlF /TRyOjT8CchFOFVkpZ9HPpSjngHnn0PRHau9YGspfguu0gL//GdmqAYEm+74NOgX9W87 6DkwhJevqgjSJs/6XLVw4x7BsRSiQ0mJp1tVboFkKX6pa6PJjOemafbgWUa+vPAFPVSe BdIg== X-Forwarded-Encrypted: i=1; AJvYcCXZ5mYhgfs4f3HPWDb7CfUc/+XQzUfn+Ci9AAQu8pdcG9Jbp5InDcwsTeyYN73s/NJuES3xt5fIP4nIPlI=@vger.kernel.org X-Gm-Message-State: AOJu0YxcRIB64/Uens/dG5IsOo7QNyXSBQ+DN0qKeYJgVhrsSYkYK+9t 3Mv5UPporiV0HyIdiJfSe1SUJicsHOsVYZeqaQwyOzdCYhpOujMCrq+uRQ383QSpbfMCdNngFfu azA== X-Received: from wmaw19.prod.google.com ([2002:a05:600c:6d53:b0:47f:941a:613d]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1c12:b0:480:49ce:42cc with SMTP id 5b1f17b1804b1-48373a02cfbmr205524815e9.9.1771253433414; Mon, 16 Feb 2026 06:50:33 -0800 (PST) Date: Mon, 16 Feb 2026 15:16:21 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.335.g19a08e0c02-goog Message-ID: <20260216142436.2207937-2-elver@google.com> Subject: [PATCH v4 0/2] arm64: Fixes for __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, David Laight , Al Viro , Catalin Marinas , Nathan Chancellor , Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" While investigating a Clang Context Analysis [1] false positive [2], I started to dig deeper into arm64's __READ_ONCE() implementation with LTO. That rabbit hole led me to find one critical bug with the current implementation (fixed already in [3]), and subtle improvements that then enabled me to fix the original false positive. Patch 1 refactors the macro to use a different way of getting an unqualified type and eliminates the ternary conditional. Building on the refactor, patch 2 fixes the context analysis false positive, by helping its alias analysis "see through" the __READ_ONCE despite the inline asm. ## Note on Alternative for Patch 2 An alternative considered for the Context Analysis fix was introducing a helper function to redirect the pointer alias; specifically passing a pointer to const-pointer does not invalidate an alias either (casting away the const is a deliberate escape hatch, albeit somewhat unusual looking). This approach was slightly more verbose, so the simpler approach was chosen for now. It is preserved here for future reference in case we need it for something else: static __always_inline void __set_pointer_opaque(void *const *dst, const void *val) { *(void **)dst = (void *)val; } ... __set_pointer_opaque((void *const *)&__ret, &__u.__val); ... [1] https://docs.kernel.org/next/dev-tools/context-analysis.html [2] https://lore.kernel.org/all/202601221040.TeM0ihff-lkp@intel.com/ [3] https://git.kernel.org/torvalds/c/bb0c99e08ab9aa6d04b --- v4: * Use the return-value-of-function-drops-qualifiers hack. * Rebase (original patch 1 already merged). v3: https://lore.kernel.org/all/20260130132951.2714396-1-elver@google.com/ * Comments-smithing. * Use 'typeof(*__ret) __val' v2: * Add __rwonce_typeof_unqual() as fallback for old compilers. Marco Elver (2): arm64: Optimize __READ_ONCE() with CONFIG_LTO=y arm64, compiler-context-analysis: Permit alias analysis through __READ_ONCE() with CONFIG_LTO=y arch/arm64/include/asm/rwonce.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) -- 2.53.0.335.g19a08e0c02-goog