From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.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 B00532EFD91 for ; Fri, 30 Jan 2026 13:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769779808; cv=none; b=kolKWrawBa3ialwOc8IR58FPL0DheyZ8GZzv6HZHbwI2Gla/44N3sIhVaA7uIfG1VLMzyXKLtMPp6QCiECtiXLb0NxBticaXuKqmShr2rZCbnLjP9E/gcVZvx+R45k8c688Yku57EM5GGUJ4x+et9XV+paxANaSD3rSfL53uHJE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769779808; c=relaxed/simple; bh=4XzaSftGKMp+7lfBWzbmLBe6n2finsa7kSDMRym3YHk=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=VsX1dlWK7LHRutGmhfo97byYuiqrwMZPgGkb1z33EN9Tn/ww4n7zt7WWVo5xHmIACjJhlafBIoUuwIqNuWwAgUSQWwCji+Iwfl5RGTDzPpgACFnhJgaN0PxeY9CIpDKmGPmtVlWFnCa6hNYy5DiqgFQVoWLtEDABS3FfuEDNXgc= 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=XPF1But7; arc=none smtp.client-ip=209.85.208.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="XPF1But7" Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-658b9bfaa1cso2306441a12.1 for ; Fri, 30 Jan 2026 05:30:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769779805; x=1770384605; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=5gV3Xp+lTWPd5vADH178EfrhS9HF61GnJcWvrSFIRbk=; b=XPF1But7/LgeDRenOKBqqxOjU93t8/7qrK1+w+w8w8JOVOkT0J1CIqFoMR7MVi/Qrn l07p9O+t38O37OGGKuHEJaZI/Grjnh59vAEfLqnazs/XkMZQpAF7lLBrq5krfxQXK7iO YXaKWpdCrXNYHWazd4wvrS/bjlbhlO6xMV0y81Q7YGeZ9gr7j8PVfmFZ7AmirFY7LUDq b3CzcOnFUG/Ah2TOPKM/Ag+8jhYkcrDHdhEPD5pCvNIiYEAFvkGlc5mJwK1P9XpmxFAe /igzoQdH+dopB4ozxM7ORHh7acEXdr0PgVndZyTRcX1v8pH0aEtqw1ulvov9RaYNqJOB kvvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769779805; x=1770384605; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5gV3Xp+lTWPd5vADH178EfrhS9HF61GnJcWvrSFIRbk=; b=bMNqqLbOygVaxtD3vudrEGLBIyY72StTPg7M3EM1adRhqJiO3dEKYmugweP0+AWs5h HVhi3w29nymI3QrVwWaEF9VhchS5VUKfruWqvhIk9t6U4aNi3gJpohkN2k5K+xPUNjJm f+yAi1KiQHeWTKuT+d0sbnIQLOsbRjg5Vj4TnsgZeDB5Qv8FeWpdzDmrUqOrblPsLz5D dCtsMspN7ZlCzWlpLwWmmJBVSj7vDjRvIHiBQENhtl1Gmgy4JZWVOohLc/NWzpR451qH YJw5LQ67rwEJtZ7PDpNxRHEXnLX76Cj44C+tAyRYR8cUDpMFF4z+MrSt6n7H7JP35xsD 7zJw== X-Forwarded-Encrypted: i=1; AJvYcCW2ya0emnOrn1+QtXyQurT8YLF2T82kYOFXmVqcTfsqZvTGyG0AdQN/Py9MnMkLfcpoX9wlmnUfSZ4wdO8=@vger.kernel.org X-Gm-Message-State: AOJu0Yx84Ujfqa6Ed4htwCUq2wJKKxfSPbYIDu9BM6JyrjZNrXVteObI bRApEVt+0hPhhnybCcQ4XbZ4ahBqyOjG5s71Up/JaHH2UoG2uRKcUoaRDLhqMfnaC+N/jM+3Y7Y ayw== X-Received: from edtc22.prod.google.com ([2002:aa7:c996:0:b0:650:bcc2:4d7a]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:280b:b0:658:eca:1fa5 with SMTP id 4fb4d7f45d1cf-658de58a598mr1929989a12.20.1769779804975; Fri, 30 Jan 2026 05:30:04 -0800 (PST) Date: Fri, 30 Jan 2026 14:28:23 +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.225.gd81095ad13-goog Message-ID: <20260130132951.2714396-1-elver@google.com> Subject: [PATCH v3 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, David Laight , 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 __rwonce_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/ --- v3: * Comments-smithing. * Use 'typeof(*__ret) __val' v2: * Add __rwonce_typeof_unqual() as fallback for old compilers. 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 | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) -- 2.53.0.rc1.225.gd81095ad13-goog