From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (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 07594242D60 for ; Thu, 29 Jan 2026 00:56:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769648222; cv=none; b=A0oSRGQBwKOIjPtU5/V3qyWh2TbQMXYmMQE3sjyDW5DtCyDbBctzUDkvSnnbYqT92J4NZ8wsxYGL0a80i0Ks8LoQacxSFhsmAGAb0r7bzrrXFu3OkRxfSWlYMmdgL6nKKGTqyESNZdtROrJ0gvLXyKOF7HISEPff2KJoFzgbHYg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769648222; c=relaxed/simple; bh=3jTwrrwI2J6lukKx9GQ9B648virwtCl6c+cXw1i3stk=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=O1I1W7c22L/sAGpQyBhMGx2keBR9MNxrU+jUmVog/RktCg+RBRq7kHTvIXQIWGAF6b52rz2M1h8EiXpFvVF+X90W1RD/9pMTVPWz9TBBfO07IfizCse16LDw6YSJXbKd3LFoHCcfG17wdrzGeYqPUuAg/xaT1JqsTI27qLg7aEc= 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=DRPH13TE; arc=none smtp.client-ip=209.85.218.74 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="DRPH13TE" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-b884bfed5a7so76616966b.0 for ; Wed, 28 Jan 2026 16:56:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769648218; x=1770253018; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=ZukGKueGp87OrsWwJYFUiCCf9dq8hTvBab+Jn9rxA6I=; b=DRPH13TEh89KF3oHgPm1DyRf+YaI+gCiZht49l0NHyp3zDYRqUw4OIfA+uW6ArCjB1 gVrVPxZC5ncq2wMDAW2ogF2/xs9TlYmBZIr9ie1LzRjawZvkZVpgila5H0ArnM9QavTk qt9k2YMefddl3Jcc3eiATEGvhuma4hkgnE58gJY3SgmAzrusjHYm37+umdHTOXeZIApz oaW+RTH+/27P0QreQGoxgqZ1C4w/Jn6yCTNznlk917LSF52teVLHSHdM/SB4Lnh5fRuX e+2R+M5A2qi9F4TlYhIzEYG8thEZxXD/shhmudgsQ50p26oBaWnygwiJhnshYdn9Rzxe OJ1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769648218; x=1770253018; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ZukGKueGp87OrsWwJYFUiCCf9dq8hTvBab+Jn9rxA6I=; b=l4LxtMLh+gudNlcPCJbOAHcqe9TUiaTcmecpH/5YxnjjmJ99xxzIylyln/Uq/R9FkY fh7i3f/EK+6rFDlEreEB6TotGT/+BfhmvOaa6/rD2gyxGutyQyysS1HfVkbeyp57XkUD CsL7vCVspCi9MF4cahv2SFTcEj2k4JnoUIoU2waCZiPHf1/r88oHvxDpEpTjL4mV45DF bc68e4S3yvfpEzy9zUO79fSgDYPaIgC/1ATWtPJWz0Vt/9i+cPF3M90voU/Lx9jryzIU DT9gpDWiJj1RpFuy0Kd9h6X6d5QRemQvqMGlN8Xjhm/tydYiTtULOjiHCPuu2afsnwfF MetQ== X-Forwarded-Encrypted: i=1; AJvYcCWcJ3x6VFjEdVVrquxGJwvt2NPxLDPBp7zZddVKXaIf2gshXsFnnrJTj+4So4L9w4ca0/tBGnNKDR6Jxxg=@vger.kernel.org X-Gm-Message-State: AOJu0YxXTF8/PQHA2JxN/IjslSvQImGwTdxc8fsWCgnMlzzQTi7+xZAv HBCEHsa1xyUwUE352KvTPpMiMVFJtQyyhOhofEO0oV0fWNVu9mPqEjfgzqHKErNq6W6QSY+NKIW 0TQ== X-Received: from ejbbw17.prod.google.com ([2002:a17:906:c1d1:b0:b88:2156:436c]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:3f8e:b0:b73:758c:c96f with SMTP id a640c23a62f3a-b8dab3a41e3mr495095966b.52.1769648218454; Wed, 28 Jan 2026 16:56:58 -0800 (PST) Date: Thu, 29 Jan 2026 01:52:31 +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.rc1.217.geba53bf80e-goog Message-ID: <20260129005645.747680-1-elver@google.com> Subject: [PATCH v2 0/3] 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, Catalin Marinas , 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 (patch 1), and subtle improvements that then enabled me to fix the original false positive. Patch 1 fixes a bug where READ_ONCE() on types larger than 8 bytes (non-atomic fallback) incorrectly qualified the pointer rather than the pointee as volatile. This resulted in a lack of "once" semantics for large struct loads. Patch 2 refactors the macro to use TYPEOF_UNQUAL and eliminates the ternary conditional. Building on the refactor, patch 3 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 3 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/ --- v2: * Add __rwonce_typeof_unqual() as fallback for old compilers. v1: https://lore.kernel.org/all/20260126002936.2676435-1-elver@google.com/ Marco Elver (3): arm64: Fix non-atomic __READ_ONCE() with CONFIG_LTO=y 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 | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) -- 2.53.0.rc1.217.geba53bf80e-goog