From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796563691; b=bivEnvsilpcOo30gcH7cjOuuv0veh7pcwF3Xna6rXMEIMqk3Gaf3zFrKyfWAqivzpJCe lX8FkMgSXr+aANQZE8fLw5EOO7w2QBRBgCr45M6u8TT3iMviqEGMqt+s0x/3HWoDPR9VQ P4zgkIn+9Ch4HzkcN9oPYGC0YzNgSbf2KzrSvAoakpZvpDPjQo9e830Zx/PZukLUHf8Bx VQS/aWx2QlZWHwWInJil+XIfGtqPG1DKkk/Sq0FIYvCBM48aeNslXS3u3IUFKXDSfAG74 E43lKcRQwk2m/Bz2dpyw338gsYTuIfIPYl5OG1I2/5d3mXnylEyUMbtAIZq82xFRstA== 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=g3cEKBc4hViSQ036XAJd8Ts9BiBtZHorh+fR8smnny109805E2CZZaAwYiLwDkcdIL+T ZzGsDjqRpeHWOE/0G4KQwOFEYZl5sSdY7x63u171K6rarmo+ssfw9Fsvm3z6W70t83MpB q0qbNXCYJZ4EVovjXt5lz41cxg8Q9Iqvr6k/OmIRUd3AHtlyyYsOEKKBTT9IFFH0edIQI td4aiav3MjJeEs1NVXhBIXr6WHuPjxEUHF/OClpEYPRSqD27404q2tDJhCt+ohCTRGPN2 n9Ev+VycWT7iet/j/x9XaCX9aTwg2WzTFUEufPcnbdg2hNRHWttNG2JDRzyQHYDarcg== 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.43 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 13CC6606A322 for ; Sun, 6 Dec 2026 13:28:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 13CC6606A322 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-f43.google.com with SMTP id 5b1f17b1804b1-4bba5e17cbeso21800885e9.1 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=vn/PR048VL4S6B8jaz6ovyyrgYeeRSiG0P+md/hATqo3xSX8k9CapJECf1IJ59RX4M HqWW9ObcOv2c4W0CFMHVWyyMKDq2OSqO1y07rKJyQFHltPX7c+2KUYBm1VoYLG/hh/a2 NmndXBhHcPY85iGpuZxRmFAz0123JlcRUKLh732vxQY+cED0r58tOm4xtpPyoy+IjXHx E1XaZDbz/BrWRv00+Zd0Dlm5hmqlkGXiG5qJsqS5FGceUOXDZ5XAe/LOuBxE1IxmMeOR SL+wAIibh1iXO5h6fOL1s86bkjDvvN8BmOuTgU9Yp6KB4TCY+IFtE+xznThSmYiMGQIv qNWA== X-Forwarded-Encrypted: i=1; AL+hErHyOnh/4M4ze+Pl5FwLmT279NIHKiupBwqGo0j/XWK9nTUpp5xBx39nBzXvNQPTo2WcgNU//XIPt0YcBaI=@vger.kernel.org X-Gm-Message-State: APuU4Z9lF33AqN4yQkK38csXnNguj8czE0A+22EZ2zeJOQFGJKoKk7gF ePMmiOMtYHHlwnOxNBORbQpM98kxp0FaEHWULTAT65zKY+Zbd1eIQ8rm X-Gm-Gg: AZFdTZdIFutL+hnpJtJBA+zE9j0jVJJT6mrWXs2dLinE7LTzKuGhWJztURicAw32x7p v19KsgJY55B/XySOVFpHexJRandBywr6MclpaN7r91eJd0+XYheR1PDvgr8RQmMuDraXK7U9PBu O4pjstoJ224u0YT+gurS/zZn4kOQ/rQ6El8N9ixy91q5nK1y7wsra/5rc1ULL/r2ri48n7N9keg /sjl9phl06kXYXHdCKp8LRNevnpOekjAyYa82HV3z+GUWaVeLopr/DicBbFmL2A9x9/PjrPWCBu bkkcZtKuZX1dFryEBipZwksx72gNZngeVs7W1zJWAFGj30RbTska2bTuMkZ1otmaa2r3Gu9dXRE GXUA+pvJOkIqC/q1eB7SlU0dvECkVxqczbqIXA51915XlxMWrZTi+7S64PhHwI3uakGBU+7/og4 M4Z0O+oTrkizWcraXeOzM+IITH3S1rVxSkxGcm3GO5e64FyUy0DFBy3bN6i6I1trs7iKpo3Xh8d T/nbkIw+tbBaSPQHxg4pBawkH26VKpc2fNYiKZKYmopoA3LP/roQiFqD84M3U+BRtmje+eKuwVj fWIPQapnGPxtVHV4Ew/32a/K84kU/nj0p5cR++2KHiAMNUaKabAp9Uk0m3iXv6+r 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: linux-kernel@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. >