From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796563691; b=TWSofNk+M7p1efDBjq3IBb+budZymCA1dMqz9rmhARnLlrqItDiuPzX/EGNudPbzv/s3 zKF0fe5grQL8HsJ2qAF2tqPx5ya0085UqcyWDNDh+C7t+xp0VBa30u/fwM9SKaD38sHk7 GJCRZjos3c2+qToaKyKuK+V1cGvqa3WYb8OlcybXepxvMnpuFWKzJnrPmT64Uv3rYe3cA NC4IBKTS8doOIJfOZNxXNq7FfbUiDUwwUPrwwglwq1x39NzCjf0Fdhrc6k5U91Xh3hzTr 1yBg2WAlJ4KynFeXbanHN60OQ7JoxFshc55pBRIDgC6w1RZd61Q3cpZAGhjoDULPwJg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796563691; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=W3Mca+wIcSDjz74ODKNng8GjtR7RsyoCcAlkem83+mQ=; b=zCIglshsOyUlu5Sqdaq6MT6KnAb1N+YQ+e+eOFVzp1ojz3ZoTTxeud50vWzy9/3mNlz9 XBouYZ4LNCF0XmS2DhTTANWThAGG/x41iDa2BXLUvYKiseePUQWLeWQt+CYqtqLI1y4lA IKAqMitIrmXqmg5FaBI3oyhMtBiElcinEDnpwg663qKWLxKjiR9gwJ56O6X70TKRlqQTX a3gbjxIlmM+KtAYzfy/ohh3QSo2kuYrVBH1LMwL4BLVcMQVJ/7flNnORZsOEqb3vU7a80 wnCX1l68n4FxWrDrvnqwvbBCi8kZuzylf+CIYrO6yA+2/THK7f4oLjIdL5+7yrblAvw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="Z/5IDouk"; arc=none smtp.remote-ip=209.85.128.49 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C078606A321 for ; Sun, 6 Dec 2026 13:28:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0C078606A321 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.a=rsa-sha256 header.s=20260707 header.b=Z/5IDouk Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4bb69f5b161so15253345e9.0 for ; Sun, 06 Dec 2026 05:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796563689; x=1797168489; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=W3Mca+wIcSDjz74ODKNng8GjtR7RsyoCcAlkem83+mQ=; b=Z/5IDouk/uDMILyTwWN3OoDrRVh5k0xx3vy8hFTjaEMo7hSY4or2tpRRcxuP8eFIBq JLP2JXRE/J41EYT7zqzT9ymY6SjXNJokJ9v4HtSSJq/Bq13wAP+dNqGS2BrhMoXuV1Br F1zc18JM1NHvElHmdrcCRXZeHzMXd1X30d874K0VDW+amebN1Pbfbb9O7ksaxtXdgGR5 M+oVgn9MLGqMSN0JqcKAzOJcc29/WUh0Pbj+AC/Z+Zmt4XXuh9FgFuTDUQFvEfX3Feky rN1ITb3CGLDQuqygcjcPiPta1QR6eSZPYY/U6it39L8FjDTUqADBmvHMId0yc/UEbkCg mTbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796563689; x=1797168489; h=content-transfer-encoding:content-type: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 :content-type; bh=W3Mca+wIcSDjz74ODKNng8GjtR7RsyoCcAlkem83+mQ=; b=MsnOGZ6rJjZrjD/C8muCRSm8wflcp/Mnc4Oh4KG4pSL+Fc2AwxFF2H5mG6ShYxE9uu z4Fc57DXSUXS48AyJh4hPPQxZzF/2kJTYA/DJvNm95YrlYGrjCa3HXUMFfuSoZn+3iRJ wFhlsXDj8q4MLyK30+wOfnI1+R2jH9mrKb0zkw0VJf+JKF98UqaaXS7J2JgQIbyhqWYe j7w6JdcpgnEFrJNIjFAVFlir7ZHSmM7AVawd+lBViv7zx9OCemz/3PnlYpAuKoPhS0wJ 1PTrpVC69I6RM1/L1ePKTIELwsJwqcrpQ2/4bdwZCzo4FKH1P3FC6ITaUrPtMltuqANe ywUg== X-Forwarded-Encrypted: i=1; AL+hErE92qOazhV/MKWlG0YK4kWxdU8iaFkIXWfNyP9TG/d3Aj9sbUKWi1ZisfAqy/aCuWtJwUV7CoE=@vger.kernel.org X-Gm-Message-State: APuU4Z+g6RtdrWiFLPNST8/Mxbt5U/ea5b4DiN7pWyE/VOoN3TYor4E5 bu4Xu30U/+YIkADeK/zON14vVe1xLBHEkLu5F2aX4/KAYvnA9sQpitzL X-Gm-Gg: AZFdTZeuSGvfJAjM2yqVh/7/rKtNojuPM7lNVGVw8LzsZhJ+qFTNVd67mZSEy0and51 JwQrBoyRT7zU2LDjyH2NJUUcVdtq5/xg2RShPQD91eRZybiAtun9ja0TjqRnWA4RreEncTjsLvl Fg0I8JrRgz8mYKcOhpGWIWJgmpLUt/rJcaN/hu9I2EgIPmaOcxdEaFPc5gB7wPI0HgDHhm8zuM0 0Ta6G/6a6HzU0bHKzer5JugW9AhQKPnEJe1jDEjp6OfJ3/FDOS9B6V6AhdxledusULh6nOubbAQ 3pwZduAfiYKckmV7RofwzgTjt/Edux4FismlP5fXqc1CawbJptXD9q2u1QEJW5eGXK/a17+Cssi zi4U6i/1t1FVBC8MCeyqmTUA+74g0e+rzjKtP5+374IJKvRFzbPCZ+qn0/JcZ1cw6wUMBvgYVRk OYd9u5ALM09Yo2R8l3cl88+XggFuBIgb0AMfR2PqWgA793Etp/pEoPd58Uyp4ub2JIeGz/BRZK0 qeC8181DjwN90dFa+1s13kJtaLr3ISj3rMfs3SuAabsK8Nnt1icR0pvQtQdXwYaHtN1rr8VJV7w eqTCh2N3+fHh/NKOqBNHGvrLjmBTOt5+WvZuca2i1g+U1dkzEgtxEpR1S95xnjjr X-Received: by 2002:a05:600c:4743:b0:4bb:5f95:c014 with SMTP id 5b1f17b1804b1-4bbeb8ac513mr139334695e9.19.1796563689251; Sun, 06 Dec 2026 05:28:09 -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-4bbea2d6aa8sm169799255e9.15.2026.12.06.05.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 05:28:09 -0800 (PST) Date: Sun, 6 Dec 2026 13:28:07 +0000 From: David Laight To: Andy Shevchenko Cc: Jack Wang <163wangjack@gmail.com>, vinicius.gomes@intel.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, victor@mojatatu.com, mhm.dawod@gmail.com, esalomatkina@ispras.ru, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions Message-ID: <20261206132807.550de376@pumpkin> In-Reply-To: References: <20261205073304.86227-1-163wangjack@gmail.com> <20261205073304.86227-2-163wangjack@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 5 Dec 2026 13:19:17 +0200 Andy Shevchenko wrote: > On Sat, Dec 05, 2026 at 03:33:03PM +0800, Jack Wang wrote: > > BYTES_PER_KBIT is unsigned long, so ILP32 uses 32-bit unsigned math. > > Since v6.8, negative sendslope turns positive, breaking software CBS > > and cbs_dump() while high idleslope/port_rate overflow. > > > > Cast BYTES_PER_KBIT and speed in cbs_set_port_rate() to s64 to ensure > > signed 64-bit arithmetic on all architectures. > > ... > > > skip: > > - port_rate = speed * 1000 * BYTES_PER_KBIT; > > + port_rate = (s64)speed * 1000 * (s64)BYTES_PER_KBIT; > > The second casting is redundant. Actually how do you expect port_rate be > negative? > > ... > > > - WRITE_ONCE(q->idleslope, qopt->idleslope * BYTES_PER_KBIT); > > - WRITE_ONCE(q->sendslope, qopt->sendslope * BYTES_PER_KBIT); > > + WRITE_ONCE(q->idleslope, qopt->idleslope * (s64)BYTES_PER_KBIT); > > + WRITE_ONCE(q->sendslope, qopt->sendslope * (s64)BYTES_PER_KBIT); > > Taking into account the above, why this casting near to the constant and not to > the variable(s)? Widening the constant might make it less likely that the compiler actually widens the variable before the multiply (instead of doing a 32x32 multiple that has a 64bit result). I hate these silly constants. If I want to know what the code it actually doing I need to look up whether BYTES_PER_KBIT is 1000/8 or 1024/8 (or even something else). In any case it ought to be KBITS_TO_BYTES(x). David > > ... > > > - opt.sendslope = div64_s64(READ_ONCE(q->sendslope), BYTES_PER_KBIT); > > - opt.idleslope = div64_s64(READ_ONCE(q->idleslope), BYTES_PER_KBIT); > > > + opt.sendslope = div64_s64(READ_ONCE(q->sendslope), (s64)BYTES_PER_KBIT); > > + opt.idleslope = div64_s64(READ_ONCE(q->idleslope), (s64)BYTES_PER_KBIT); > > Why? What makes the difference here? The parameter of the function is already > s64. >