From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (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 19A2036D4EB for ; Fri, 30 Jan 2026 12:05:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=74.125.82.53 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769774733; cv=pass; b=uJP2e8jdK/pd7oH1dpOQ+/04xk9vLvKO5owkZ3hgjo9EyImPVs27ABtqgM8ODrgQ/jlDCpNBHZJ56wGCiVEEVGS5S+9AA91XTheXTVdD8hahqRz70H34Tm8Pma9HgVERgHsgD9LAteGsxYfNox2qbwUdpTKq+PPtmUAQE1qJYr0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769774733; c=relaxed/simple; bh=QbV5ZM+xXUpBx7Dyu2SFGPdnLdCzZf39HnqRtAhIgcI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DxZ5iDT/AeTIgFIkPT2LTkoxj44pgNOUraV8gPIHFXBk1HBM4gO/awt/j56m8G6eq6nFSVFW4HWf/PMPf5HQx0eXql9v8HxSqL2YaxtTjd+gAcNHJPaEYh9bxTYf5ADxKGSrpzgcNkckf572jAmI2CySoRIf+rTricZdjD0EPE0= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WuefGSGJ; arc=pass smtp.client-ip=74.125.82.53 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WuefGSGJ" Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-1233b953bebso2318930c88.1 for ; Fri, 30 Jan 2026 04:05:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769774731; cv=none; d=google.com; s=arc-20240605; b=OAkV+PoCtYpO89lpxgAZ38/F6+T3QaGfSKcuve0OsFrQNgPMB8dO73NKrunHLf/WA5 6Ij8A+cnLsnEvix4nNNSjWEpLHSSZXIyyuqfSJQb4nzQBctBSxtX9NVyJt0Oiv23WIhc xoe/02fxrvCg4JOBzNmHj6ZVqrE92G+7nOJMMHzHk/wBVyuFxa1F1E4T1Uf2x0UwPf8L TMTIf0V8CCpqoZRIwKxsVnoaTJ1IQwUFpOGF5386pAFbcCQviOms5Wch7AODIHAp0OcG cS3FNJW801Uo4y8V8oEKN+bqrIfKe2tmZMQicyP3L9Exl2tzzH3I8Rx3NWawj3pmZvKR q4wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=XQjNjAE5Q1B5SU0KSLnPGrt3o0FUeKh5OiAeQmMY6aE=; fh=6IRIB13+Kg+hn8R3ggHLFT/QUBe/y1Cv7PbEU6JUAa8=; b=JXHSIz3WuZoZ+x0kacpsClT64nPqFaCjsRTwoMQndpqDLGoR4oJJxl4VFl+F3G4UV9 ZXb7l/we4ryoN1pXGyI5SftbjBEBHQWgyST+YVwxJbMyfx2CadkJS1J86AvzkCgsFG1m CdepHfPsh5hAFyuykIbBze7riGZWdqIorYzBWeS9wbjvSxtjqvrZ7pIzbIdT5oLCHtO4 9jMyTkZdUed+2pvDSGZfpkgZjLXhH6XGzkGLYiLOw6F/alWci54aYS+pC9D0qD9ctVsp s0nbLUK+UDMxC6wAtfseFhkxqFUv3ncF/Qi0ZRjP1Zza5ngEpi+YCeQPOHoQwBt810TM ZR0w==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769774731; x=1770379531; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=XQjNjAE5Q1B5SU0KSLnPGrt3o0FUeKh5OiAeQmMY6aE=; b=WuefGSGJPmOBfqzGR/pA3dVu7bH+dfE+f1OJ3qeRCJ5EbBV+t2Bf4W7dbwd1GF2E9A rj1oCiqo2TwkFXbc7C71McRtKSODeLuWR67RuUUdEyc6ALZZPvVucXxzBxsYZ1yLM+PE MUqhnTmQkn7ak27HHxgnHmHs3JvQ+ZxgAB77kuHxbuT7oQV7BJKcOw7ankpo3uzRoJbn uC5VzkwpANQ9EjaxnKIsmBmL3ydGId8y+1AUmHIp1uNmCP10JerqRE+/Zc/yXOfAmMyU AoUDUwa7ZjjnSIGtW2H3u+g7hEBAu5D5XKscLj8tTP9Pd+OLf1WLhMHX8K9V/zMeIIb9 e4Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769774731; x=1770379531; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XQjNjAE5Q1B5SU0KSLnPGrt3o0FUeKh5OiAeQmMY6aE=; b=iiTX4/0Ax3ng63yh3j7Ue4SWXHA62dsS8XIxFUX065JMf5yctdUzwn3jvklfAGuWei 4g0oeIpL0OqAlB8/6FC8NCCFbMlff0ZrHXeqJ84zTIXm8vCKn6QX7p2q6WaIlM9qYAIk z55KiH5bcy6CryzqJHjFHXNQU+XBWV1sdCcuk1VJa4+mM1EsHM2eqc9/GauOWHABJ1zP AuSkpaP3/K1qwsfFtp0YZ99QJ13wV6D9irHJQRNrPoq7IfpfGH6U2O0eMoZDKBhxMVJF iZNFFrOXAgdyt2enjMKIURAmVfHskHoFnCr0OKWTNSQWosJ0NE99rZSRPj6IRByQSvBR Kqcw== X-Forwarded-Encrypted: i=1; AJvYcCVkY8ktoJTWafb47UdSOIt6gZAtOVXfJVqO/HBCvIa5rZHXHYGmjIDKuvzTpGGrGpG3z03PJSPbN5QbdKY=@vger.kernel.org X-Gm-Message-State: AOJu0YyFSu1rY9pXxtnYRV1pDMEmapmUILsY6/8Ypz0WAdJaZYpINL1G 98w/9IvTZ21yt58y9XBofsY+fomg2EeNvBj0NAU3gvnXWDa2eaElDrX+3ho8dng5XfDI66EO5MO 9Gm9Z21ZcvmyZbmsZhbmJUEZJQStDBPie8ax/75uY X-Gm-Gg: AZuq6aLG8jO/KzFheK6ZjzHRVv+OvtcuivksYs2ckktuJgmzNKvpIz1mcrY9K5DBvDH nqySm9ES0UTsemhBj4Xof3IAPPif8StUmxRpT0oPK8yRXv4pzMCNKCj3Wa4zU541PSkA/d5+OwN ZB+TLTL1uFxWHt+CMJ58ZJRBGWRKcSCfsXll4mGuIg79qQ3dupQgNn3q/10wWpOfDOlmeK98D68 fV0bHIFXGWYygV+MaArevuJkKbw9U3RHWWBrfEzTwWV3d7N1vachTAR6g4HDHLkENnpK60H/QYl VECjGgsDYdyU8Ef4lYCD2fWgcOM= X-Received: by 2002:a05:7022:660a:b0:122:153:d161 with SMTP id a92af1059eb24-125c0fa713cmr1267052c88.17.1769774730831; Fri, 30 Jan 2026 04:05:30 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260129005645.747680-1-elver@google.com> <20260129005645.747680-4-elver@google.com> <20260129095219.6a3b8dc8@pumpkin> In-Reply-To: <20260129095219.6a3b8dc8@pumpkin> From: Marco Elver Date: Fri, 30 Jan 2026 13:04:54 +0100 X-Gm-Features: AZwV_QgCEUOQyaM6FamGIBtoY0m3tlb8ivndN86S9L9oQ2RkXeS3PyM7AKCtSe8 Message-ID: Subject: Re: [PATCH v2 3/3] arm64, compiler-context-analysis: Permit alias analysis through __READ_ONCE() with CONFIG_LTO=y To: David Laight Cc: Peter Zijlstra , Will Deacon , 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, kernel test robot Content-Type: text/plain; charset="UTF-8" On Thu, 29 Jan 2026 at 12:31, David Laight wrote: > > On Thu, 29 Jan 2026 01:52:34 +0100 > Marco Elver wrote: > > > When enabling Clang's Context Analysis (aka. Thread Safety Analysis) on > > kernel/futex/core.o (see Peter's changes at [1]), in arm64 LTO builds we > > could see: > > > > | kernel/futex/core.c:982:1: warning: spinlock 'atomic ? __u.__val : q->lock_ptr' is still held at the end of function [-Wthread-safety-analysis] > > | 982 | } > > | | ^ > > | kernel/futex/core.c:976:2: note: spinlock acquired here > > | 976 | spin_lock(lock_ptr); > > | | ^ > > | kernel/futex/core.c:982:1: warning: expecting spinlock 'q->lock_ptr' to be held at the end of function [-Wthread-safety-analysis] > > | 982 | } > > | | ^ > > | kernel/futex/core.c:966:6: note: spinlock acquired here > > | 966 | void futex_q_lockptr_lock(struct futex_q *q) > > | | ^ > > | 2 warnings generated. > > > > Where we have: > > > > extern void futex_q_lockptr_lock(struct futex_q *q) __acquires(q->lock_ptr); > > .. > > void futex_q_lockptr_lock(struct futex_q *q) > > { > > spinlock_t *lock_ptr; > > > > /* > > * See futex_unqueue() why lock_ptr can change. > > */ > > guard(rcu)(); > > retry: > > >> lock_ptr = READ_ONCE(q->lock_ptr); > > spin_lock(lock_ptr); > > ... > > } > > > > The READ_ONCE() above is expanded to arm64's LTO __READ_ONCE(). Here, > > Clang Thread Safety Analysis's alias analysis resolves 'lock_ptr' to > > 'atomic ? __u.__val : q->lock_ptr', > > Doesn't the previous patch remove that conditional? > This description should really refer to the code before this patch. Will word-smith this a bit. But this refers to the state of where the original issue was found that spawned all this. > > and considers this the identity of > > the context lock given it can't see through the inline assembly; > > however, we simply want 'q->lock_ptr' as the canonical context lock. > > While for code generation the compiler simplified to __u.__val for > > pointers (8 byte case -> atomic), TSA's analysis (a) happens much > > earlier on the AST, and (b) would be the wrong deduction. > > > > Now that we've gotten rid of the 'atomic' ternary comparison, we can > > return '__u.__val' through a pointer that we initialize with '&x', but > > then change with a pointer-to-pointer. When READ_ONCE()'ing a context > > lock pointer, TSA's alias analysis does not invalidate the initial alias > > when updated through the pointer-to-pointer, and we make it effectively > > "see through" the __READ_ONCE(). > > Some of that need to be a comment in the code. > I also suspect you've just found a bug in the TSA logic. Adding a comment. From a soundness POV, yes it's a bug, but I think reassigning a pointer via a pointer-to-pointer in the same scope is just pointless, so I'm willing to keep this as a deliberate escape hatch (might need to add a test to Clang to capture this and discuss if someone wants to change).