Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp2305532rdb; Wed, 6 Sep 2023 00:00:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEw6PRqkAHpZ6FZ3mxQbdxiHKUf8BV7mpPi+yN11JDjAP/ZFAXAmmsz393QrlBualzbHX/y X-Received: by 2002:a17:907:7617:b0:9a1:af6f:e37d with SMTP id jx23-20020a170907761700b009a1af6fe37dmr1395535ejc.5.1693983602870; Wed, 06 Sep 2023 00:00:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693983602; cv=none; d=google.com; s=arc-20160816; b=x7k0kJgeM2hMdUV1rG+HpCrkmT6AKRzy0pOurriy0pf/zRYZBe4aPGEenQJQl10UaC jIXHH5gMZ+NEx90hyR6RHmZV8XYAAI7pkhx3jz3nEVUaHcfx0A6cskINWaBmem5fv4Th HGQQLAVospFAaTV2OWb4zOPh1exbS3vazw708ybFH2v5Xo+iuf9eLEX8aiH2GBBhjGP8 P8myS/A/qVzp+kMLqZJFzl8jQmjppOjCRbwcLHgx9oKyTEylAkJqWsbOMWzLqtxuq0g0 ehr2FOO/tsTF5dZo+0i+2hZCShyEEn0m1cpoiNQaYVgObhd7PIaROqm4K0IBmt73vMI6 6Spg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=o+r0G0bylHSS+CjoWPPOo1ILpFjUDWxyCQfsdUVi8wE=; fh=0Dj0l57wncHA7h93wCvaAUcgPwY7AkIydBzyjwT2UFY=; b=WXSeNn9+ghbGFFFgUQC2QmFWbXZp0IoEnBzbRIV/tolO4R3Dk1L9qaL74R7ALmmTMX bZt3Ver7iyFxx8yElqSYAAR5gL3qvolMFjEGIPoUnVFX/bmaXytqwCtHIFELauI3B5nR RbyyJRuBpHEmrVhJclbopnyJ2md6JkIGe3AmjujSjedr0F10Gfmbgh8kjRG0ivQ0lR03 ZtfyfjylTeFMoLG2Ofr3sMkVDv2MPSTgfV1o4Lp6QuKeC3DlDm5HIT4l4N54ATRqKQhD DWbGPW9VsF0W+fAl8gYqu2QdbSDKVpVC+KZk0EqCnzcQvKOos2B166N7pcpfNa60pcXO 8Caw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cS1rto+K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ci12-20020a170906c34c00b0099cd74ad42fsi9069833ejb.106.2023.09.05.23.59.35; Wed, 06 Sep 2023 00:00:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cS1rto+K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239603AbjIEWWe (ORCPT + 99 others); Tue, 5 Sep 2023 18:22:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232868AbjIEWWc (ORCPT ); Tue, 5 Sep 2023 18:22:32 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FAE0191; Tue, 5 Sep 2023 15:22:29 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA676C433C8; Tue, 5 Sep 2023 22:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693952549; bh=8YMYHkyZiAhmJ6syQzQUheL3bNZAGl1TBDnFPJ0oIRA=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=cS1rto+KUZQR80agwkIXGYjTxBddvUTSRVNsRnBz6OCUhBYAxWcqojyjfBd6DJ+ib YGbS6HtA0WjFrtKMhJffxUnUSWGDixfW4gtRTd6CER96HTTqL/xHBabV6DD68/U60v jnZQEjdhl0Zj1Cs6prs4vt4VmzdKL3mfuKzWR2Uo2yeqCIAR1CWUzKKAdJdHeqF27u Y0smuBneec+FNqKkaVYljHYaQ3IPukBs4Qn1HJjrIKkguUllc2HRU2ERNOXcr2l/o0 8X/qCc7jiMXiaNXGzKtmpesdvNtEfJSC2+IiIXHXgspCmlhAZ46I2YhzuFZq1s71db A1i1NwS9QBb2w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 9A692CE0FF4; Tue, 5 Sep 2023 15:22:28 -0700 (PDT) Date: Tue, 5 Sep 2023 15:22:28 -0700 From: "Paul E. McKenney" To: Joel Fernandes Cc: Mathieu Desnoyers , David Laight , Denis Arefev , Lai Jiangshan , Josh Triplett , Steven Rostedt , "rcu@vger.kernel.org" , "lvc-project@linuxtesting.org" , "linux-kernel@vger.kernel.org" , "trufanov@swemel.ru" , "vfh@swemel.ru" , ldufour@linux.ibm.com Subject: Re: [PATCH v2] The value may overflow Message-ID: <285f9ee6-2f45-4b5a-8cd8-92b6f3b017a7@paulmck-laptop> Reply-To: paulmck@kernel.org References: <83422425-0534-4b12-a6e4-8068b7164a17@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 05, 2023 at 04:56:12PM -0400, Joel Fernandes wrote: > On Tue, Sep 5, 2023 at 4:52 PM Paul E. McKenney wrote: > > > > On Tue, Sep 05, 2023 at 04:40:46PM -0400, Joel Fernandes wrote: > [...] > > > > > > > So this bug appears to have no effect for default RCU setups, even on very > > > > > > > large 64-bit systems, which is consistent with field experience. Even if > > > > > > > this is the case, it still should be fixed, to avoid confusion if nothing > > > > > > > else. Or just in case someone decides to set CONFIG_RCU_FANOUT_LEAF=32. > > > > > > > Which actually happened the other day due to someone trusting ChatGPT's > > > > > > > opinion about RCU Kconfig options... > > > > > > > > > > > > And I therefore queued Denis's v3 patch with an edited commit log. > > > > > > Of course, if anyone sees some other way that the bug could manifest > > > > > > other than in a 64-bit kernel built with CONFIG_RCU_FANOUT_LEAF greater > > > > > > than 30 on a system with at least 31 CPUs, please let me know so that > > > > > > I can adjust. > > > > > > > > > > > > Thanx, Paul > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > > > > > commit ed083b0e22f1396dee3599896249a3f218845298 > > > > > > Author: Denis Arefev > > > > > > Date: Mon Sep 4 15:21:14 2023 +0300 > > > > > > > > > > > > Fix srcu_struct node grpmask overflow on 64-bit systems > > > > > > The value of an arithmetic expression 1 << (cpu - sdp->mynode->grplo) > > > > > > > > > > AFAIU, the overflow resides in the "bitwise expression" and not > > > > > the arithmetic expression. > > > > > > > > Rather than quibble about exactly what constitutes arithmetic, I > > > > updated the first paragraph and added your Reviewed-by as shown > > > > below. ;-) > > > > > > > > > Other than this, please add my > > > > > > > > > > Reviewed-by: Mathieu Desnoyers > > > > > > > > Thank you all!!! > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > commit 50477ff756ab99402b1523b7c6be8b5d790d05e7 > > > > Author: Denis Arefev > > > > Date: Mon Sep 4 15:21:14 2023 +0300 > > > > > > > > Fix srcu_struct node grpmask overflow on 64-bit systems > > > > > > > > The value of a bitwise expression 1 << (cpu - sdp->mynode->grplo) > > > > is subject to overflow due to a failure to cast operands to a larger > > > > data type before performing the bitwise operation. > > > > > > > > The maximum result of this subtraction is defined by the RCU_FANOUT_LEAF > > > > Kconfig option, which on 64-bit systems defaults to 16 (resulting in a > > > > maximum shift of 15), but which can be set up as high as 64 (resulting > > > > in a maximum shift of 63). A value of 31 can result in sign extension, > > > > resulting in 0xffffffff80000000 instead of the desired 0x80000000. > > > > A value of 31 or greater triggers undefined behavior per the C standard. > > > > > > Do you mean here "A value of 32 or greater"? > > > > > > Only N >= 32 throws warning for: > > > unsigned long foo = (1 << N); > > > > > > N=31 does undesirable sign extension but no warning. > > > > Good catch, thank you, and I will update this on my next rebase. > > Thanks, and with that the patch looks good to me: > Reviewed-by: Joel Fernandes (Google) Thank you very much, and I will apply this on the next rebase. Thanx, Paul