From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.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 9BB0D2AE77 for ; Mon, 26 Jan 2026 00:33:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769387584; cv=none; b=ljeQbWYyAHeb7RoW7hdUSTSVyPxP+MYtJkl93L1J+IGGmAGqnFbXNGw0LCmSqnNfYEe8f+D2+gtmN5TJbbKSM+ITOLBMBnjmFSlCeTRfWT68CAD9IKViKDWXN6M/mbfTK8Q9/Q1d7OoellJIHKRsEYno402ICdJNitxJ1XlKvhQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769387584; c=relaxed/simple; bh=mhB7SsK4rd/dcahtJD51o0o+LgrIzabQkW905TGIH4I=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=FkgOzahube+ykhe/7nxSyUd5arU5aRZKegURWnKC6LXoj6PWuf8Kto9L8rHUE4/uiPANMl8j9V5vyV1VIizEFZJAo5NeliaNV20HpcBmR0DFKD8/AhFiXUUQGGulH7bX5kPkWle+HjTB2ek9K9mjAcFquVvdoUtKmwPbJFyy0bc= 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=eQOrk+g+; arc=none smtp.client-ip=209.85.218.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="eQOrk+g+" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b8709d4ff20so251360366b.0 for ; Sun, 25 Jan 2026 16:33:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769387581; x=1769992381; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=SLUD9kqtzHxYW5dCA5OGESTleTXqSLmFV9783ZIDQu0=; b=eQOrk+g+DXnX774yW21ZBj5359Yctv9r8LqJzticuGTxUhlnwmKYvkvYIK0gQJs4FL dnMGUP2z+W+XYzoba0mlbS5kSgyBVeP0GTQp581wJhDAPTzuoJ+NB9M0AbZMWHKMOVME gTo3JWFB36IrkQHaYEX35tGdkvljAK2/U7A9lycBR/lCYulyDCN/tR+NC0jG/i+wVeVd PnzB+/PaUmnUw6yP3NS8amIfv1fwnXtjzi6Vs8BYloApA0UwviQCVDAbZmR97cVHU4JX XmwquKJCnTDv0I8l6dhtF+JBHo7f+Z47wj7jA5t1q2NyUWr84VtuQQ8pm90NQWyFPED/ hIfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769387581; x=1769992381; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SLUD9kqtzHxYW5dCA5OGESTleTXqSLmFV9783ZIDQu0=; b=dxloxyUtT9Sih01/xL9YYPBx1uCv2Fq6xRjXqUXNi52ptW2sMD3Y7gRAUsRRbSKD1I Ux/56Kojk9s46rBxp+dF9M8HLL07tMC3epDgFM6z5OIDuzZT9woz9qSLSH4Dnj8dDhTf gCknU+d8Gw7TdYLsGh1hhB+d3AVtXCLKBQI8vFZ7MpXdS9J2cgy9n/haBLmfGNM1gWu6 fKIapykI9LZRkY4fcgnfgCcJUPV7PeOoijuaB7SmxS83ru7ybVfpY7i1l8JKaqfH2Jo0 u3TZxDe+GOy4iVswsYU8v8hIpeBdDktEKiExPzScTtLFilPRMvaF6mwZrw3Jce2fF0qt aKkw== X-Forwarded-Encrypted: i=1; AJvYcCWT09EMtX7PbgEw4ryWFVIrz0XylOkg8cjDDeXFSlmClT1nHo2J2PL3zXMJrGySc7nwkRON2gPKexgARE4=@vger.kernel.org X-Gm-Message-State: AOJu0YzbVJvEzl0pkqEf8jN1zeduu8qBieLZgYH3nwkQnN7rIQQL2ho8 LPIU0GTz2TeoZmNA/DwAagn3EPNsVDb+vZxQkH6yhAbl5zCVr3eDGIOR1hQ+YL/Zmb5SkOSGoJj Egw== X-Received: from edon6.prod.google.com ([2002:aa7:d046:0:b0:658:38d0:b315]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:97d5:b0:b73:8639:cd96 with SMTP id a640c23a62f3a-b8d20dec1d3mr172240066b.24.1769387580903; Sun, 25 Jan 2026 16:33:00 -0800 (PST) Date: Mon, 26 Jan 2026 01:25:09 +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.52.0.457.g6b5491de43-goog Message-ID: <20260126002936.2676435-1-elver@google.com> Subject: [PATCH 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/ 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 2.52.0.457.g6b5491de43-goog