Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp596592lqb; Wed, 29 May 2024 05:30:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXtaAxOQXTwH04EBEx7ltUDAne192zLM8p1IOuqlwhWU8YlIMTLbt5NB7lx1nGRpPk4uyWAvqk4Elu5g4D7OxsaUrEItP8kTY6vO2Jr6g== X-Google-Smtp-Source: AGHT+IFSKxRjI7rnCuhJ1+P/RdF8YAeOVJk8AuyRema3KlKiLuCOeNbnwjIMkKVsUvD5rdQP9wIM X-Received: by 2002:a17:902:ea0a:b0:1f2:fd9a:dbf3 with SMTP id d9443c01a7336-1f4486d1fa4mr176563435ad.11.1716985809533; Wed, 29 May 2024 05:30:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716985809; cv=pass; d=google.com; s=arc-20160816; b=XBPCU8O9H7IcEyQUrCqBmQriUAj7WPf1oIGkAtx/3b8oQWTOmV0hQpfxV97j0StTQe PYpFGnFVUTKvvcFMoZ/K3A2IsCSnkEqzZwkJD4Bxc6moHlTMJX1yN0Kl25u7MKNTitjp p0ghAOlI2/hhamf+VDYCGcKqR8vCIXy2U3erK1J2P7l2CRJLTduNsVgAgAdxCE+Ls4Cy VjnhR8awhYi2zekHL+JZVlnvM4V75CjUsQTQHUfJjvvHKwPvztPQNWzctzDZNLc2TmqB /GDujcggI9vx/bK4fr2PvKsc4gK0goR9MEvTE4pzV2M8gSfXg7RCaNpFe7sMtcNAxWcL TESQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:cc:to:from:date:references:in-reply-to:message-id :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:feedback-id:dkim-signature:dkim-signature; bh=sYEH2A6/FkKh/OJLUXEHX6R9YKo5fgdDk4asAVIZiks=; fh=oJOJdwaWnasYfveGFhAG+clPvI8ctiiGkOIxDGNJN70=; b=lNxyNPCr8+UtU42TgO2QVmo4zWUBRuSQDU+CjJwHGHjOaJrQQVGFTSnLLW8amLd//v kDfm7OaWNRmJ735yPdphYoel9QY4llt7gnnsPpm8i18cOUzvrJv8EukesL2PYqYbJZiW tDZxlcp4T8KpPoBG0R8AWVzEcuypGjDGEBgMZK959Wh58sA0G3aehxnrjkgulkYsS4Os QeMA+t6CKTNFsHqG6nMZ4CrXYgmQ2WiE9bvspvbD2Fczp7yjRtl2q2uTJFTmWdTykmVM +R74Ed6pqs3coShnErsUEjIHE4Fy0hu2TBu87hY2J15+i7ugo8W1+MdbF/qHrWZ5v5a7 endA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm3 header.b=IuJVe1Zf; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ViFZqJ4b; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-194088-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194088-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c9708a1si99126785ad.240.2024.05.29.05.30.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 05:30:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194088-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@arndb.de header.s=fm3 header.b=IuJVe1Zf; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ViFZqJ4b; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-194088-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194088-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 299682891EF for ; Wed, 29 May 2024 12:30:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FDD718131A; Wed, 29 May 2024 12:30:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b="IuJVe1Zf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ViFZqJ4b" Received: from wfout3-smtp.messagingengine.com (wfout3-smtp.messagingengine.com [64.147.123.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36B962869A for ; Wed, 29 May 2024 12:30:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.146 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716985802; cv=none; b=Sx5s30OYF56cQs/NU58jhX/Tp0HKbzzATtGv63eMBbuCQWN3O3Y541y8eMJXUBWKVBf0cxBT/hy98fsVNb9SHCxM2H/1osfjV+b46LRedYfO4PskLazs0ncLqFuicxacd1ZWsgQLx7q7rbLv2/7Gdxk0h5J0qtU2+nls1i62oB0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716985802; c=relaxed/simple; bh=ZTtRPXu1uNDYT6LgLq48Uj+HG2fXM4HZEfAeRbVg/S8=; h=MIME-Version:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:Content-Type; b=geNje5zKKycp3yH/ABH0kxY3TVOrzFh54E2MizeUaKG8kliSl1Fh4F1d/g5FG8ec3/QVZiByIUIXbHcheEFmZO6qgc3/XdbVo6Xqj5R7lm+ApK+DyrE7bIw2GJ9JS7H7EZIdscTIPRNVHzyVodD6+lBjcSK0gDV0KomPTIKtzjw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de; spf=pass smtp.mailfrom=arndb.de; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b=IuJVe1Zf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ViFZqJ4b; arc=none smtp.client-ip=64.147.123.146 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arndb.de Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id C24351C00099; Wed, 29 May 2024 08:29:58 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute5.internal (MEProxy); Wed, 29 May 2024 08:29:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1716985798; x=1717072198; bh=sYEH2A6/Fk Kh/OJLUXEHX6R9YKo5fgdDk4asAVIZiks=; b=IuJVe1Zf7fCjzap6H2auKd2dqY 7k73pHCYJbWDAJUanYcM9AGs/HNJR/yNPxYc1WkqJH+hkSc3oIMp5Bp0XUCV4uM/ tnZhfD4Wg7FfqcJLS1iywUERe0Eu8/pgg+5d+B1eZ9vnS2ac41elIsXCb/DgryvT 8J/vbIJyNoYKbv4ixoLAjJYgW3QRNzE9IF/h9RUNuEXU3VrlbOrDhUt/6XMpVeJQ 4NQeUjHrdAVVCBPHjZ/5yl2uaJrptDlqG2iFRT+C2djZMhInOphs75V79UsKagT/ RuuaGVIbM2mh0eOQxqAU+5kxzz7/aVSJhhA4VXM1RJud+FkiohYIdKHFFe6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1716985798; x=1717072198; bh=sYEH2A6/FkKh/OJLUXEHX6R9YKo5 fgdDk4asAVIZiks=; b=ViFZqJ4bqYqRAZUaLYl8b9eN/AoyJoD27teUzLcTqKgH rbnX0OKFWV08aKLDLKzVYW6R4ocyiTaQ9bEyK/5Lfd53iD8YsmU5BjpUlshDFew/ 8/O/IHGGcuZGO2Q3ayOcx8dxXAuRDZl9tRFZzhoBSJjmghVVEOr/svuKnRNNmUOW wf1OqISEQ0ODkVZDSAS5deitJjNylvgMfMqOPEJv62fNK9qkPE3DNFbC0XXzwr6g fCszrE9M36QjG6tRzjV4Iy+opNdE+Boy9qP3m2M800bK5R+nDuBbYlW013ZebWxB n+uRZnmm0zjh240JrjnmkzRTMCsZw+5/YURHArKU3Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddghedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedftehr nhguuceuvghrghhmrghnnhdfuceorghrnhgusegrrhhnuggsrdguvgeqnecuggftrfgrth htvghrnhepffehueegteeihfegtefhjefgtdeugfegjeelheejueethfefgeeghfektdek teffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hrnhgusegrrhhnuggsrdguvg X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id E0E08B6008D; Wed, 29 May 2024 08:29:57 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-491-g033e30d24-fm-20240520.001-g033e30d2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <8ff9bc52-bf2f-4856-9335-14bf659e7e4c@app.fastmail.com> In-Reply-To: References: <20240528120844.3523915-1-arnd@kernel.org> Date: Wed, 29 May 2024 14:29:37 +0200 From: "Arnd Bergmann" To: "Mark Rutland" , "Arnd Bergmann" Cc: "Catalin Marinas" , "Will Deacon" , "Jason Gunthorpe" , "Valentin Schneider" , "Baoquan He" , "Peter Zijlstra" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64/io: add constant-argument check Content-Type: text/plain On Wed, May 29, 2024, at 13:14, Mark Rutland wrote: >> { >> - if (count == 8 || count == 4 || count == 2 || count == 1) { >> + if (__builtin_constant_p(count) && >> + (count == 8 || count == 4 || count == 2 || count == 1)) { >> __const_memcpy_toio_aligned32(to, from, count); >> dgh(); >> } else { > > I don't think this is the right fix. > > The idea was that this was checked in __iowrite32_copy(), which does: > > #define __iowrite32_copy(to, from, count) \ > (__builtin_constant_p(count) ? \ > __const_iowrite32_copy(to, from, count) : \ > __iowrite32_copy_full(to, from, count)) > > ... and so __const_iowrite32_copy() should really be marked as __always_inline, > and the same for __const_memcpy_toio_aligned32(), to guarantee that both get > inlined and such that __const_memcpy_toio_aligned32() sees a constant. > > The same reasoning applies to __const_iowrite64_copy() and > __const_memcpy_toio_aligned64(). > > Checking for a constant in __const_iowrite32_copy() doesn't guarantee > that __const_memcpy_toio_aligned32() is inlined and will actually see a > constant. > > Does diff the below you for you? Yes, your version addresses both failures I ran into, and I think all other theoretical cases. I would prefer to combine both though, using __always_inline to force the compiler to pick the inline version over __iowrite32_copy_full() even when it is optimizing for size and it decides the inline version is larger, but removing the extra complexity from the macro. According to Jason, he used a macro here to be sure that the compiler can detect an inline function argument as constant when the value is known but it is not a constant value according to the C standard. This was indeed a problem in older versions of clang that missed a lot of optimizations in the kernel, but clang-8 and higher were changed to have the same behavior as gcc here, so it is no longer necessary now that the older versions are unable to build kernels. Arnd