From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 DBD732192E3; Wed, 27 Aug 2025 03:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756266068; cv=none; b=ifvzEQll63baNEsh0WiaLnic2Y8QYMZkNxOzlf0mLJxVC+PsdfEWrLW20zagz7KaQd4jQjP/04ASNuSRnx/xaLvxv2Nf1CWgS2WoI2erMz2uf87PqYzqTuCOj07GiH8A8Yu9VuoWm/MbADjG48viSZrongqkoxSFKxtN3bJaRQE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756266068; c=relaxed/simple; bh=mYhR4hDG9DbVR34fVtQQOt59e7gIITeGVvG1SoehGpA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MpSfB0BbmH1FxNiK8qngEZl35Pae8uWHNTB0DTtXdIu/trLTjb0qHzdeIDzCOVF3QMtGpcULg8VAu8TxVdFy6lmtcyc+UoG+bMFzW8y8HRECUmL8EIb5nFQkDsEo9JFeBAOGTDAfRXyfyVZlqB1B2fJCx2CoZTrPSQU78XxmP98= 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=mxvPw6HJ; arc=none smtp.client-ip=209.85.215.171 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="mxvPw6HJ" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-b4717543ed9so4293286a12.3; Tue, 26 Aug 2025 20:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756266066; x=1756870866; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=i7hQgakYGN92JM43ym9Xl9fivI9QPXuqHNitq7m6h9Q=; b=mxvPw6HJnB7lsO5WHcD9mXvYRwpUO+eb4KdltJB5O7lLjXS9MZty2MOlzZ40feHQbi GXvcgIZgQqiF/oxtbIOlkwUfb55Z2UTvOwNIrTudkmbAKzldGClRH/ygRebYRIbkcHig l1orhwck69iS85czg3ZknJ6Y6ly9DlB7zZm7nfPv9mi9VmKIP5Jn9ysHt6d7+Hxa4DJl tXpZjA1IKn6ZX98ChlUjMUx+63fI/gFD1/veS53qFh0PoXwxYrWJtU23VNObj2BOnyuh FH0RPpeFBoCoDa3JpaHgAq5zjvPnxovbAP8ixuidhHdNR1w1WjBFSMOoICaSq4RlL03Q Jp/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756266066; x=1756870866; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=i7hQgakYGN92JM43ym9Xl9fivI9QPXuqHNitq7m6h9Q=; b=nLP70g/QQPmeDyNfkKGrZzkTVCWcU7/urbGzCHgfLne7HyPWuq3qFsdUGWsuPmXxOS iwphFSd45B8GaPnXBKCI1GfzYd03+EAtMDapi7Gy+gb+YtFX3AfBe2x36lPTKprviOHT yqX8TO7/LgDXqgCbGtwTCLheqCAWdFV2AvBc1qM/FtIPW3Hb8Hmu/YozeTuIuxQmGBKF dIbwb4P3cJBikXMIvZCfSOvZjgCzibSOK82X3rYjbxd/FaJrrk3EGYfahmsGUmPLu8YQ oS+fOiVGGdvu15wTtoLldm//k/YjB5UR8eeplniiZJ6JV7mj7cOxiiAXVW61g2PGTg+Y tASg== X-Forwarded-Encrypted: i=1; AJvYcCU2aS3xdn13s9QRnLsq6bz6pLu8XIpZKnSTLxymQaLXQqro37o52TcmIxMB/+jDfQN6S2NMUNEfumnSEBzP@vger.kernel.org, AJvYcCWrBVVMrJ1W1uWTvTDOuiJiRbLoeuBg2Wz/nsLIx/afZ6tqccMb1LMmHqeAjSxBjWQQfV1CpBR5vR/cEViWT1Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxONdMKqdHA19SBBGtVyyDf3U3Ss5TQLWZCrq0Ilbx0BGqQ5BAj xWRYAftZVwlB7Cpby7rOW1PMiYQ9orJQ8jrRNZNhDLg4XaVEz3sB/3ZM X-Gm-Gg: ASbGncvjPZRTJBlCTosNxyOFPozWbIfGHIUisqApWnwe+OZzUEzTboZg9xsmQYEf6MC 2a+UoUctWCDIjTmoI3JNUtelktA9X8TUjSYgcOlZKSrsOMzSa3cZNYo6O6gm89vOK+oihjUXGz/ p4s9hiXakbPeRjVR93+6419DHeTlxH5k3yMH4Z2iqsZW6YP/YvkfSIfT9vu2DgDSmnER6eVxu2Z ssnHCSDtn0mm5ihh1+Fn92/xbtt4IMhcnqBLpZa+CkIADH0VoG77AwH7Tetv9Es6yHhFLnfO+fw 1SqbbK6Ng6eB2L7/hpF9UI/Du9aFeAEt1xZ7we+m03pfNreLu9NPcsS/zFLXlwpDn8ijyvdxKnk LSmVWI6q6ly+MEeuuuB6Gvhm2UvagnG55 X-Google-Smtp-Source: AGHT+IEJfoCSb3DI07rprjVPxQ5PK2rDzT96h9Gj0pmdTGWBTR1HDwbCJwoFIgVFU4rX5YFZ1j8hKQ== X-Received: by 2002:a05:6a20:2590:b0:243:78a:8278 with SMTP id adf61e73a8af0-24340d72bc8mr28593728637.48.1756266065948; Tue, 26 Aug 2025 20:41:05 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-770401af16bsm11876114b3a.54.2025.08.26.20.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Aug 2025 20:41:05 -0700 (PDT) Date: Tue, 26 Aug 2025 23:41:03 -0400 From: Yury Norov To: Kees Cook Cc: Rasmus Villemoes , kernel test robot , Vineet Gupta , linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] arc: Fix __fls() const-foldability via __builtin_clzl() Message-ID: References: <20250826034354.work.684-kees@kernel.org> <87ldn644d0.fsf@prevas.dk> <202508260955.2DE50A3FB@keescook> <202508261911.ECB628656@keescook> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202508261911.ECB628656@keescook> On Tue, Aug 26, 2025 at 07:13:03PM -0700, Kees Cook wrote: > On Tue, Aug 26, 2025 at 09:24:04PM -0400, Yury Norov wrote: > > On Tue, Aug 26, 2025 at 09:56:06AM -0700, Kees Cook wrote: > > > On Tue, Aug 26, 2025 at 03:08:59PM +0200, Rasmus Villemoes wrote: > > > > If __builtin_arc_fls() simply doesn't qualify for attr_const for > > > > $reason, I think it would be good to have that documented in the commit > > > > msg. If it does, I think a gcc ticket and link to that would be in order. > > > > > > I already sent the patch to fix it. :) > > > > > > https://gcc.gnu.org/pipermail/gcc-patches/2025-August/693273.html > > > > I'm OK taking the patch if it fixes real problem for you, but it looks > > more like a GCC problem, right? Is Clang also affected? > > Without it, KUnit testing of ffs/fls fails on arc. Clang is not That's a solid point. Can you please notice it in changelog too? > affected. Even with the GCC fix landed, all older GCCs with still fail, > and since it provides a improved code generation for arc, it seems worth > it (compile-time-calculable values will be emitted instead of always > running the arc instructions). Yep. This is what I meant. Once the fix is landed, we will not need this code. When the minimal supported GCC version will become greater than one that has the fix applied, it will be much easier to spot this hack and drop it, if we mention that explicitly. Something like that: #if IS_ENABLED(CONFIG_CC_IS_GCC) && CONFIG_GCC_VERSION < XXX if ( __builtin_constant_p(x)) return x ? BITS_PER_LONG - 1 - __builtin_clzl(x) : 0; #endif > > If, say, Clang is not affected, and you expect that newer GCC versions > > will not be affected too, let's protect the new code with a proper > > ifdefery, so that it will be easier to drop the workaround later? > > I think the codegen benefit is worth it as I have it. That's I'm surely agree. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4AD98CA0EFF for ; Wed, 27 Aug 2025 03:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BXmqc9WeL/3zVf2KqrM/cx67AQFxUiZxFpHf6pxYwI8=; b=vqHdn/UsO6NfJY puSzwRxG54FgGtM5nMXoTUiBkEkqn88PRe66eNKBCz693k9ozT8Nj+JL7+Hh36LZUI5aN9+v7VLPg N3c99X6Vs5Oyvqe3ynuo89PkDz/iCQKWVddQ91BsfE9ROh6G7Z7ynRMMQjiGODLHrJd26Z/yQo0P1 pgRiwz12eHqP4ySVb21eJWdu59UK3JFKIs0l/KQqWAnXxQfq92oN+cpigKYN/Oqx23Ng1hJ/qc7/u IgkFo2u8Y9JCCB0JpZuRF6WLlq0dKzC8KOEG/CeVoEJPyc8SvgSPUCvNjRRQ4po2gxNAcLQMq3g/T BnccEkmsx4tL17PaQmvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1ur727-0000000Drb4-3Ogz; Wed, 27 Aug 2025 03:41:11 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1ur722-0000000DraG-3ydP for linux-snps-arc@lists.infradead.org; Wed, 27 Aug 2025 03:41:10 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-771e15ce64eso2273749b3a.0 for ; Tue, 26 Aug 2025 20:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756266066; x=1756870866; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=i7hQgakYGN92JM43ym9Xl9fivI9QPXuqHNitq7m6h9Q=; b=ji9LyBwzrOb7w+Xvrs0kFQa0HQyRwNw6ZaP5KP5sbGvN8RIwbOp7BEr/oUP6IkC6Bf 1dmPjfbtRcGvlOSfs6SaZOvIU205O4+oivnH3Kfw2demjMrHqXP5FCxX+3YfhKqOEiou FqwDxFxZk7HGdavfgOgFyEaUKr+a1PlntqMJ89Y5KOTIpcjiU7yXVw2vlVKUQ8ZNyTxd jxQO+iyizOHw7NEb8KTpNtbD0EB41mx4MH7ZTSes+C+NmrHQakcbzaxkZhAKIyNi2ceU ALkfrxf4hqjEPiTJCICV3Yq+U5K0DoI4AR8YjJengvWS8xN0BA5I8Nwkn/yQwM7xpRGT VQIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756266066; x=1756870866; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=i7hQgakYGN92JM43ym9Xl9fivI9QPXuqHNitq7m6h9Q=; b=ikRLNO4QQQpvHgjEHv2ioNDYuldZbAPGHxe5TDTnqtiOl+FooWn4Bzj7fH1gDGeq7q uiiQE3dhpNCt4AwLemMndt5MBlaCw6RxH4vOBKulw+oPXqiMFac24mPJ6MnavwR44ALa Mxx/uFalJ+N/IINAUNl/DUr/nG2aNDD08CSNBthBWGDMItVULYfQHoBpHHS3yUBomMLE MDJO0y5+yIb1xV6+mvK41C2d4QpaC7k3I8bQDp3Ea56vE/0FQI8WLX4iYLrxcw1IZt4v sYKaeyJZZE7JfHgRuAVaNecB9QpaFiw/vzfykUn228ZqN23UnAV/nmLYz10dgeMf9IAy DLkQ== X-Forwarded-Encrypted: i=1; AJvYcCUWl3xmcdt06OOgFRqcaWEBOQUcOLu0saach7rMUkCzH8W/H23EK+TdPYPJCzY4AV7HgH1rR2NvZ2c24NlewQ==@lists.infradead.org X-Gm-Message-State: AOJu0Yx19SI/ppvYVbxeZCAgmlNZKV58Tngc5usE1pBnMGiFU5QUjU9P okA+sk8VblmHPRprgQN/yFXIo9tXMTA550x26RV6gFJ+l41oluAhRbKD X-Gm-Gg: ASbGncuiGVYWrIgKqmxVPDN0Y1W6S6bTmS/YtJflqmu+5iJMjmK0NVwAMxJwWcRXcV+ AlP8bLZwrj61sEyoh5rbPRMIgZGLFazx/b4sMM+NAJXnbhV+WIczmuoIG5gSxthGLmXsQtXjfeZ as/Q/9Q7X92rWgM9/8uKjWqAfHOrFqNNA2SQ5a86Y5d8mLxY7TXhQWM7wuoqK4Xo3hRKlIAznvy qM47EBuSVECEuPrsIQAgrJHHKcOXEWfeBpEdQJhb6pCurNbMFmm5nNZOokFgQ2ZacvmImEA3jmA Lwxo2MCnmKHLGCjfhkZOeqCKcW0J8fOTcsnb5G99K9z+5MS0mJMjralsR6wZnWvwU4vzYuToyT5 NJl1OtIv7k5Jy2dExTKMsV+qYAUKBnt6R X-Google-Smtp-Source: AGHT+IEJfoCSb3DI07rprjVPxQ5PK2rDzT96h9Gj0pmdTGWBTR1HDwbCJwoFIgVFU4rX5YFZ1j8hKQ== X-Received: by 2002:a05:6a20:2590:b0:243:78a:8278 with SMTP id adf61e73a8af0-24340d72bc8mr28593728637.48.1756266065948; Tue, 26 Aug 2025 20:41:05 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-770401af16bsm11876114b3a.54.2025.08.26.20.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Aug 2025 20:41:05 -0700 (PDT) Date: Tue, 26 Aug 2025 23:41:03 -0400 From: Yury Norov To: Kees Cook Cc: Rasmus Villemoes , kernel test robot , Vineet Gupta , linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] arc: Fix __fls() const-foldability via __builtin_clzl() Message-ID: References: <20250826034354.work.684-kees@kernel.org> <87ldn644d0.fsf@prevas.dk> <202508260955.2DE50A3FB@keescook> <202508261911.ECB628656@keescook> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <202508261911.ECB628656@keescook> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250826_204106_988937_7FB50CB7 X-CRM114-Status: GOOD ( 25.66 ) X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+linux-snps-arc=archiver.kernel.org@lists.infradead.org On Tue, Aug 26, 2025 at 07:13:03PM -0700, Kees Cook wrote: > On Tue, Aug 26, 2025 at 09:24:04PM -0400, Yury Norov wrote: > > On Tue, Aug 26, 2025 at 09:56:06AM -0700, Kees Cook wrote: > > > On Tue, Aug 26, 2025 at 03:08:59PM +0200, Rasmus Villemoes wrote: > > > > If __builtin_arc_fls() simply doesn't qualify for attr_const for > > > > $reason, I think it would be good to have that documented in the commit > > > > msg. If it does, I think a gcc ticket and link to that would be in order. > > > > > > I already sent the patch to fix it. :) > > > > > > https://gcc.gnu.org/pipermail/gcc-patches/2025-August/693273.html > > > > I'm OK taking the patch if it fixes real problem for you, but it looks > > more like a GCC problem, right? Is Clang also affected? > > Without it, KUnit testing of ffs/fls fails on arc. Clang is not That's a solid point. Can you please notice it in changelog too? > affected. Even with the GCC fix landed, all older GCCs with still fail, > and since it provides a improved code generation for arc, it seems worth > it (compile-time-calculable values will be emitted instead of always > running the arc instructions). Yep. This is what I meant. Once the fix is landed, we will not need this code. When the minimal supported GCC version will become greater than one that has the fix applied, it will be much easier to spot this hack and drop it, if we mention that explicitly. Something like that: #if IS_ENABLED(CONFIG_CC_IS_GCC) && CONFIG_GCC_VERSION < XXX if ( __builtin_constant_p(x)) return x ? BITS_PER_LONG - 1 - __builtin_clzl(x) : 0; #endif > > If, say, Clang is not affected, and you expect that newer GCC versions > > will not be affected too, let's protect the new code with a proper > > ifdefery, so that it will be easier to drop the workaround later? > > I think the codegen benefit is worth it as I have it. That's I'm surely agree. _______________________________________________ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc