From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 CAB4F35BDDB for ; Tue, 27 Jan 2026 14:30:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524234; cv=none; b=CP7Zpp/t+9aIvaIFgzc/Ihifq8QQCvYL3xaXpN3aBeAA+49Jvcp8jsWL/4/wndbTPBaQmeUvRyhoHuNqJBzRjQuiPvPOGTeuKg53dSCGVjxthjB/skl2iIqtD2DqfXjlSL/UAkmIHq8kUlhzfZqw3S7YtbbsrbHBGEnpo+JjaF8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524234; c=relaxed/simple; bh=q2XFkv3k1e6ui7Ak1rh2fCMB9+jqFgzgbk8wV3/jOiQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OMyrD7U9KgT+u97+3hplg5Lw+u5+Zj63DcEeMb37BsTfXQEWvF/VsrWm+0lc3ty7WOJd1bDZ+RDhBKUNwzMShAujCS4mHt/VQq97xbO/YfToAyyHk0kUnjsgd4YarcbvRXrZggdxprjHDv0+CoVgKPc5yIDxPtprq1vCROkF5Zk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=I49O6Yfx; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I49O6Yfx" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-4359a316d89so4286069f8f.0 for ; Tue, 27 Jan 2026 06:30:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769524231; x=1770129031; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=vhshd5OZQ3rINSAnt7Pm+c6X8anVL8a4fk783Hki388=; b=I49O6YfxykuSnA3CaBl8B3knk5N60OI/Qqhv9JWYMU2Re8Cu5GHyk2cHJ6Md7sOoMk 6ok0Dv5DDHL/ivDBjmqA21r0QSDIgzknpMaK/zzHUhvo/SCJ3YH07QJlhYAHlelYK/9d PlhegrVXytFmo7B6/qWH6sNqcoQQLzD03C0GEVtCdV9dPXtTqOiXGxhKUDIouls7zCzr pPVC0T4QrGor5VCGgLqBS67gm/PM5ai4DgOeQpFtfOWFxdh63os8BN2wbYLSLLE+fyUO G/qsizDCBj6w8tgjVZ2+0eNcyqH17W0s9rCnuEeXfxHEnwBhif2vne8SpZCHybM/KW9q NWOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769524231; x=1770129031; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vhshd5OZQ3rINSAnt7Pm+c6X8anVL8a4fk783Hki388=; b=ntcXUoxwb0fllgH2sgUfb5e4Pb5yrTNmJUZ2WIuGDHLey4pKaja/YQeLNtAAVFBmrG 7/hTQJmYXT7ClgrM5eVbt8hzANwWugn9slVYF1glqJP9p7ULdn5fAmq3ATPOlL+8Cn8j P6pxoHSZg/xjioAUrSH91quwCvf+7hq6nOT06pQ3bGiDwuW3DDGx7bwNVrnw04BsNKYr hOVUZf3avojsLO4HM4FomutJ+ZnHKCVEoqM7/C4c7poRrdqQJ53wL8VB1gRQClvPEBao WO4XJIRuxN4tt1Zr2hzFNpllQaA+KIbP4ogTv5JBPjycXZTQWd5CruBQ+ohWaOaUnf0h FM9A== X-Forwarded-Encrypted: i=1; AJvYcCVnr+bTwWtLEGzhqNh7qm4pqfZFbP7q0e5VNbA/dX0O1RFaM68RMe1NVN3e2IuKBqr/jkUxekLa1Ql0K/A=@vger.kernel.org X-Gm-Message-State: AOJu0YxVCM0ZsNj71rW4VwKjGCZpWLn0aLYOMpWIhFLsEnQbx1rpSkW8 XqlITP75GCCHHKQ/+YKyp6DTTj5CF5rYr98iUHEgHBKNJmV2mWek2jsF X-Gm-Gg: AZuq6aL2KaTliFmUZ6fF2oSdqqOczeNJDaoTKj/78zXBs8y9nlusE+Z3JA/9MSbRX64 pybxRF+70vfFjjc9ZQO90WA1ECMYI5ex7cq1BAsi5rDpsvk+hfv7rErYQNzhPV+yYfQtm0dr7AE 149oxeWxY0S85m3CqfxIqWQf6NOAqju1R7kUdCfrw+fmdA6sWXUta99bl4TJqWJmvzHOeWktHDv DHwBloWduMWnDs9NlcPT4F6QmKiBKvytCsITdmOYIUP0+aA84OvSQv0GWVvyRuAZ4RCLR39Qdgl 4JMmdlPAiK89fW2ey4U0WLbaLfOHexZjjD2Eg81mLdOC4jE90ctMDf48xlcmujH8LVy2Kjwu3e/ R34eDBWD9KJvVtYV31hHLkA5XvReQCgI3E709s6iot9Cx6LUtdl2vg/Mq1cZg7U8HegdlRBe3UP 54OuwAbOcxMfXccAvAuQ2ileUCE63nXh8iK5cybKe63ylCn+Tl1INc X-Received: by 2002:a05:6000:3102:b0:435:97fc:6f1c with SMTP id ffacd0b85a97d-435dd08fbe9mr3025222f8f.25.1769524230765; Tue, 27 Jan 2026 06:30:30 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1c246ecsm39449626f8f.10.2026.01.27.06.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jan 2026 06:30:30 -0800 (PST) Date: Tue, 27 Jan 2026 14:30:26 +0000 From: David Laight To: Marco Elver Cc: Arnd Bergmann , Peter Zijlstra , Will Deacon , Ingo Molnar , Thomas Gleixner , Boqun Feng , Waiman Long , Bart Van Assche , llvm@lists.linux.dev, Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] arm64: Optimize __READ_ONCE() with CONFIG_LTO=y Message-ID: <20260127143026.32429f32@pumpkin> In-Reply-To: References: <20260126002936.2676435-1-elver@google.com> <20260126002936.2676435-3-elver@google.com> <7478d2cf-9636-45c8-8ffa-8e3a3ba9baf8@app.fastmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 27 Jan 2026 13:01:22 +0100 Marco Elver wrote: > On Mon, 26 Jan 2026 at 23:24, Arnd Bergmann wrote: > > > > On Mon, Jan 26, 2026, at 20:54, Marco Elver wrote: > > > On Mon, Jan 26, 2026 at 08:56AM +0100, Arnd Bergmann wrote: > > >> On Mon, Jan 26, 2026, at 01:25, Marco Elver wrote: > > >> > > >> How does this work with CC_HAS_TYPEOF_UNQUAL=false? > > >> > > >> As far as I can tell, TYPEOF_UNQUAL() falls back to __typeof__ > > >> on gcc-13, clang-18 and earlier, and not strip out qualifiers. > > > > > > I think we only need to worry about Clang for LTO builds. But yeah, our > > > minimum supported Clang is 15, so between 15-18 it'd be broken. > > > > Right, I missed the #ifdef CONFIG_LTO check, so indeed gcc is > > fine here. > > > > >> With fd69b2f7d5f4 ("compiler: Use __typeof_unqual__() for > > >> __unqual_scalar_typeof()"), I would expect __unqual_scalar_typeof() > > >> to do the right thing already. > > > > > > It'd still be broken for Clang 15-18, so it won't help much. We need > > > this to work for more than "scalar", so even though it'll work for Clang > > > 19+ given the redefinition to __typeof_unqual__, we should deprecate the > > > _Generic-based __unqual_scalar_typeof() sooner than later. > > > > > > I was able to make this work for older compilers: > > > > > ... > > > #define __READ_ONCE(x) \ > > > ({ \ > > > auto __x = &(x); \ > > > - auto __ret = (TYPEOF_UNQUAL(*__x) *)__x, *__retp = &__ret; \ > > > - union { TYPEOF_UNQUAL(*__x) __val; char __c[1]; } __u; \ > > > + auto __ret = (__read_once_typeof(*__x) *)__x, *__retp = &__ret; \ > > > + union { __read_once_typeof(*__x) __val; char __c[1]; } __u; \ > > > *__retp = &__u.__val; \ > > > > > > > > Thoughts? > > > > Looks better than __unqual_scalar_typeof() to me. Would it make > > sense to do the same __read_once_typeof() in the asm-generic > > version of __READ_ONCE()? I don't remember if we discussed it > > in the thread leading up to dee081bf8f82 ("READ_ONCE: Drop > > pointer qualifiers when reading from scalar types"). > > We probably didn't have __auto_type back then. > > I don't see the point for the asm-generic __READ_ONCE(): it's not > wrong to cast to 'const volatile volatile T*' nor 'const volatile > const T*' etc., which is dereferenced directly and not stored in any > temporary variable when used in READ_ONCE(). I actually don't know why > __unqual_scalar_typeof() is used in the asm-generic __READ_ONCE(), > which just adds 'const volatile' right back. That looks historic, once upon a time the code was: typeof(x) __x = __READ_ONCE(x); smp_read_barrier_depends(); __x; but const needed stripping and someone decided to cast the result back to the original type. Of course that is pointless since the qualifiers aren't relevant on an 'rvalue' so are then discarded. Then the barrier and temporary variable got removed. (The barrier was only needed for alpha - which has its own __READ_ONCE()). In the arm LTO version the ?: will also remove the qualifiers. > > And __READ_ONCE_SCALAR() appears to be gone, where the > qualifier-stripping resulted in better code-gen. The qualifier stripping was needed to read a 'const' variable. Looks to me like the 'better code gen' happened earlier. The 'earlier' version took the address of the on-stack volatile variable. So you may not need to remove the const/volatile qualifiers at all. David