From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.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 10E6B72628 for ; Mon, 24 Nov 2025 18:19:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764008345; cv=none; b=pin6DAGFmBs3FQ/s/lsCaF+p6sxtQg308efuxvuZRiMBYdo5AAEQeaWEIKbg+wEor2Djt1vIWLsGx9mzDukD6pxpdj1ph5pXbyVzCi8Z3z2HVDz8hwjKBLpeleqt0e76WLIT8maUqV+D2HHwBHmCnm+cb4c2g8Wsez6uRLhffC0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764008345; c=relaxed/simple; bh=jfjVdRjsEr8OD9ZQvMjDwrhdEOQWbYV7snhP+1jnVdw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ENkOutu7+DyAKomAEuawIFZODZ99rI6p6sOFmPYH0Naj/lFH5GSaC1q4XAvGAYiJsZRL2t5i7f6gFzhrU1RzQy26IL8Qk4ncZVTLG6K1xH3Pv5qtCGqWr7K+0mVG6DFI2tW0R90XaLxpQcthBKg+i34x4GSVhpFdVolOdlw3LIo= 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=JN1lsWf0; arc=none smtp.client-ip=209.85.128.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="JN1lsWf0" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-47778b23f64so24705715e9.0 for ; Mon, 24 Nov 2025 10:19:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764008342; x=1764613142; 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=kxXQGwqm7ImpxdTmhXRgI6IaBwUjXZd7g+J3mVCB1BY=; b=JN1lsWf0fXg4ViTEK0KyDttL+Ok/pbwOoAr0unZFBAAkeop5KBQq4R0EX2TH38oYHJ 275lt4EagKB0DMrwrMZGFDOO6DKWidXHnYgw4Rs+C/Y3DJ+7lmk1tWnCcB9cG8sIRw91 toGlHy3GXkwO1SlXNvx2sRlszejJAmEUq5MaIA8TlCm8qiIxzWF5ngpLNsaPYFBo1cgH jf73mv1zp2PGc9RXvu16tqi3L0GIU8Fea3nwKRHrUoQ3JgV7VkyRgfsFoVH4GmvGUgiy lMOtx5DXP7kiyQFEQYrXBy3KQNAKAaHqPBhePL/ultzjtFUkTmla6Vz6Mm3uPP5yvbzL upxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764008342; x=1764613142; 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=kxXQGwqm7ImpxdTmhXRgI6IaBwUjXZd7g+J3mVCB1BY=; b=voEvwW5wwkUxwFkKN/0xTKJ31VmX2v9G54yDCLNClHoCJLeRFx1SrJOOkh1VeiXpRJ fte6CEjOLH99K4rY749CAJlMGrDxzsEVKdT7c85DYFi6RkI8ByEDNxmBbS+brnVXDH81 r3fggEUz6WvqGPyU74tCOzp56USfBWRUwt67oIU8igT3uwLbhPnrTpvucpR3Trz2t+pf haZw8tIvVaZ4iHsid86ma9boMrstQmzE7jHbXWmuvADW2dsjS2p/n5FSxrrwWl+ldncI cU2+u/tiHm2biv9n6j53ZyXhmXueKZXM8ZesC8QYxlZy9/FCF1LxJulCeFwzoOVK8me7 2N3g== X-Gm-Message-State: AOJu0YyAvfsZJVpexoO/dFOLcQoWgZIQyaALP6vzu6tV9shOYgiBs5/u X+7uE0ujdwr66SbnjFzvEZRuT0IL+u5JN1vARWLE0TgVAM1ZZtb+HnRQ X-Gm-Gg: ASbGncs6ZZnqh8W4Hx55dPghgKaRzpM2yjMFoosxy0LLXbF7yG/MkMjhnLyk9rdluF2 hoKYIrtC+S4TuEsqXdnh9KjWyd9WoNMS9JeiPy0wgDjuMZNlnac7y9Hl+I18tm7FJ5a+7uIlMRY ntir2ocOFS9Og20eMlh94+Gx+HpD5xNzmrvr3dkFhHrpXG3Gvlqs52Q7BEDxzhHlE8vJEW6MnIs MOPTq9pGpFsN+IRh9ImOX7auQ5FamkHi7a2odBPbRNB5W3gd0q8uoP2RoAf3UBeQ5BFAGVZ8IHr iQwuSWmMwl1NTzOi0qHZLXNrx1hn5kUYIubNKawz/8W1Se8T7zODzLLpurMAp3xsdqNMqynJ9a0 Iie8EzHUkB5nIoes0X2iKs9yWXpubYnh+UPTLA0bFshDbVqZYjbyG1viLNSTioyKqcmDvanmlsR s0Y+JretaMWW0yjv5dcXYHh4MRhuLg3GaCImzRSryJnqUQZsn4njnm X-Google-Smtp-Source: AGHT+IGuve3AqXNauOhkPeDD4nH8V1iEcOiK4prYPLPOX1ytyJubTpj0KDLs3AlkQh+2SBR1FdRGbg== X-Received: by 2002:a05:600c:4ece:b0:477:7af8:c8ad with SMTP id 5b1f17b1804b1-477c115db0cmr142646845e9.31.1764008342068; Mon, 24 Nov 2025 10:19:02 -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 5b1f17b1804b1-47903e5fae6sm592365e9.0.2025.11.24.10.19.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Nov 2025 10:19:01 -0800 (PST) Date: Mon, 24 Nov 2025 18:18:59 +0000 From: David Laight To: Yury Norov Cc: linux-kernel@vger.kernel.org, Borislav Petkov , Dave Hansen , Ingo Molnar , Thomas Gleixner , x86@kernel.org Subject: Re: [PATCH 01/44] x86/asm/bitops: Change the return type of variable__ffs() to unsigned int Message-ID: <20251124181859.5ead20fc@pumpkin> In-Reply-To: References: <20251119224140.8616-1-david.laight.linux@gmail.com> <20251119224140.8616-2-david.laight.linux@gmail.com> <20251120182909.522d58cc@pumpkin> <20251120211810.60f53cb7@pumpkin> 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 Mon, 24 Nov 2025 09:58:51 -0500 Yury Norov wrote: > On Thu, Nov 20, 2025 at 09:18:10PM +0000, David Laight wrote: > > On Thu, 20 Nov 2025 13:33:11 -0500 > > Yury Norov wrote: > > > > > On Thu, Nov 20, 2025 at 06:29:09PM +0000, David Laight wrote: > > > > On Thu, 20 Nov 2025 10:54:01 -0500 > > > > Yury Norov wrote: > > > > > > > > > On Wed, Nov 19, 2025 at 10:40:57PM +0000, david.laight.linux@gmail.com wrote: > > > > > > From: David Laight > > > > > > > > > > > > The return type of variable__ffs() is currently 'unsigned long'. > > > > > > This makes the x86 __ffs() be 'unsigned long' whereas the generic > > > > > > version is 'unsigned int'. > > > > > > > > > > > > Similarly change variable_ffz() and ffz(). > > > > > > > > > > > > This may save some REX prefix on 64bit. > > > > > > > > > > > > Detected by some extra checks added to min_t() to detect possible > > > > > > truncation of large values. > > > > > > > > > > > > Signed-off-by: David Laight > > > > > > --- > > > > > > arch/x86/include/asm/bitops.h | 18 +++++++----------- > > > > > > 1 file changed, 7 insertions(+), 11 deletions(-) > > > > > > > > > > > > diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h > > > > > > index c2ce213f2b9b..2e8a954d2e2d 100644 > > > > > > --- a/arch/x86/include/asm/bitops.h > > > > > > +++ b/arch/x86/include/asm/bitops.h > > > > > > @@ -240,7 +240,7 @@ arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr) > > > > > > variable_test_bit(nr, addr); > > > > > > } > > > > > > > > > > > > -static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned long word) > > > > > > +static __always_inline __attribute_const__ unsigned int variable__ffs(unsigned long word) > > > > > > > > > > There's a mismatch with the generic ffs() in asm-generic/bitops/ffs.h. > > > > > > > > > > The generic_ffs() returns int. There is another variable__ffs() defined > > > > > in arch/risk, also returning int. > > > > > > > > > > So I believe, the correct fix would be to switch x86 to int as well. > > > > > And anyways, I believe this deserves a separate series. > > > > > > > > It is a single patch, do you want me to resend the patch on its own? > > > > (With a different commit message) > > > > > > The patch looks wrong to me. All the flavors of ffs(), ffz() and > > > others should have the same signature. > > > > I only changed 'long' to 'int', all the generic (and builtin) ones are 'int'. > > So I'm not sure which difference you are talking about. > > IIRC the __attribute_const__ just lets the compiler do CSE. > > All the versions of ffs(), ffz() and others should in the better world > have the same signatures. This is unfortunately not what we have now. > > for __ffs() we've got signatures: > > RISCV: > static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned long word) > > x86: > static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned long word) > > Generic: > static __always_inline __attribute_const__ unsigned int generic___ffs(unsigned long word) > > You're changing x86 implementation to match the generic one, but don't > change RISCV, and this is wrong. More like 'incomplete'. It looks like chunks of the RISCV file are a straight C&P of the x86 one. > Can you make them all matching, and check the same for ffz() please? > This would require a small separate series, I guess. I can do a patch for RISCV - but I'm not setup to compile it. But it should be just changing the function return types. > > Moving forward, it would be nice to make all that helpers looking more > unified across different arches and flavors. Although, out of scope of > your series. I tripped up this one as part of my min_t() checks. Basically if you do any maths with the result of the x86 'ffs' functions the other operand (which is likely to be 32bits due to the domain of the value) has to be promoted to 64bits. This is likely to happen more often than the opposite. David > > Thanks, > Yury