Article View: linux.kernel.netdev
Article #27345Re: [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions
From: Andy Shevchenko
Date: Sat, 05 Dec 2026 11:19
Date: Sat, 05 Dec 2026 11:19
42 lines
10782 bytes
10782 bytes
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)? ... > - 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. -- With Best Regards, Andy Shevchenko
Technical Details
Message-ID:
<axPzNaExgBV3dIQl@ashevche-desk.local>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377947-linux-kernel-netdev=dewy.ruReferences:
<20261205073304.86227-1-163wangjack@gmail.com> <20261205073304.86227-2-163wangjack@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377947-linux-kernel-netdev=dewy.ru From: andriy.shevchenko@linux.intel.com (Andy Shevchenko) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions Date: Sat, 5 Dec 2026 13:19:17 +0200 Organization: Usenet Network Message-ID: <axPzNaExgBV3dIQl@ashevche-desk.local> References: <20261205073304.86227-1-163wangjack@gmail.com> <20261205073304.86227-2-163wangjack@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="3014340"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:rZ4que9MxjT58A+X6OTvb3w0zqU= sha256:hlMdlCqssMH2KoMLiKLSNT55cF7Si6LFJtU9jHTGcg4= sha1:BC16RwYMzboRcsNw8c7Nk7rALdc= sha256:xXgGQge7TFPgzPIovxXhQ6a3fw00E3kNFgeKmAD+pJ0= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 05014117DFA; Sat, 5 Dec 2026 14:19:56 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.338 X-Spam-Status: No, score=-3.338 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PAxdordAL3wo; Sat, 5 Dec 2026 14:19:53 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377947-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=linux.intel.com X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id BA2B6117DF5; Sat, 5 Dec 2026 14:19:43 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 9ABCD34A97; Sat, 5 Dec 2026 11:19:30 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796469570; b=1+kD0BU3FGZVK5kl5dkqDMDOM0qa/3tp4FKo2yjZFmp1wUkA40zhzQBOYZIlfyPhJRTC f6Zhma/7xKFTkLbWnMlPVbCmyt+WZtmwo6SEN4EbwdaYkWCTkNBG6T9zy/v3pfdc29wdp PCLD2kP7YXP8/XQtsArLOQZjZH6sWSKI+T49AsRTFWuR6j15cOoeeBuoM9ZvL0g7MCLc1 HJZUyuclaSLqQj1Wjm134wCyLy53/ei5XfT3uSysIBM5nzqxd/icvIDWAaGEB3Z99zowt pFCt/rTnDBnVjQQMut5brf4pVsLG6AstNG7x0wFrzvO+p3K8rqxkdp3K6PRQ5z+Q+2Q== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796469570; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature: X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-IronPort-AV:X-IronPort-AV: Received:X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV: Received:Date:From:To:Cc:Subject:Message-ID:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Type:Content-Disposition: In-Reply-To:Organization; bh=VTd0C2+TndOBq19/17IIXFLngdIWWV9W0799BwiZOOk=; b=W02LzdMdTjikYLlqkfeop/YbHdutE8wHdmriuGui8KqPdqUSi8EUdBZuSZTbxH/e/8Dy +vSrPG4zexgfTDQkDIROSoOg/OvJzuSSm+iIx/0Y+KAgSgGwnAXLFG1ZexJ99iQ4NVUaL wL5EMxQ/d98hvZSBHMqeG9jeaXW9u1gLPrYtv37nhJ0z/fODWffazBVEAAL9B+GJj709I zTgWNDaOZzDCGGxREr4eLO54XLyB22R62N2vUyGYsA+k53kEdeG/AJfwYJeUTlb7PSvy4 Vl/FFJHqmYQHrBXkiFiOKyO5llCURFf5NZ/Ur+jq5Pk8YAAGVee6uM9dQm/paS+OgQg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b="bA/dY3wt"; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 357BF606A334; Sat, 5 Dec 2026 11:19:30 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=bA/dY3wt X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.21 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796469564; b=CrJpZTRdDYTjaSr5SmmfLDhSz0khCTQIWDOebOFXU3EXasFtXwGairiJr/j7VtGjPIYp xI5uQ8yP5qZl2Hv2DJWzXrNEmC0kK8tSiXAT1OU0P8FxGoTEEKISBIz/pDgj0n7SN2Fh9 m3RcTbU2Buu8PTIAWna02/s6IekCel/RHRRCMWlQZa5VHZ5idWdpsjzx+ue1/OFHqdX8u LU9Bb3cmk0xuxep01BbqD945j0IVZlhlnckck49rG+Ztv64XVnTKTaWAwsJFyqDFBFkmZ jWbliivw/YzLop52kmVgtWlR48W2xlEEo+IXm/CtY5qHyIu5BKnLpJ41iMJvsbjhXPA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796469564; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:Organization; bh=VTd0C2+TndOBq19/17IIXFLngdIWWV9W0799BwiZOOk=; b=MCvYMr7v0ZlltXPWAi0aba0K7a5VLgQJuRsvnWpTbkJhpP1xTSCLGM3m99izp/twQMtJ w7kBF/3rzUyXTEon8AhpEfdZFTrSGYb5Cf1LRIyxF1LIOrpQhS95m3VqA/7Pg2Vv/NtDv y/ghdj3yMk43ftpIxpXFzcF/SzvBQrFURgqBeaIvm36FS7SgJxzscTUI4TmH5oLRcNF3b q7kBOUgdwAUmryTXHENlaHhyHixE7S9rBgZYAnUoS0rA9wTQwcnwzKsIzUhtWag0fVscE QWxA4TaQyASWqBofCM5jXA7cJS3oJYBe+1BLKfa26AMNkvuEdG0c5S299QNbMsgvs3Q== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b="bA/dY3wt"; arc=none smtp.remote-ip=198.175.65.21 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF8C5606A32F; Sat, 5 Dec 2026 11:19:23 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DF8C5606A32F X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796469564; x=1828005564; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=VTd0C2+TndOBq19/17IIXFLngdIWWV9W0799BwiZOOk=; b=bA/dY3wtgjx/ZXtVedNASIHYYZiQ3R8YP8ytf9okO6vVpPEQuN0d/bZa cKz23vfKXTgozr+APJfPVD7yveghLDjL/nVrYLvrrr1UxeWqA9mEh6F80 Yz+ZGrGGq9yG54SsIl3xWYiwC4yNE50uSwdB/1/hrXeYDTA8cObNy29Ps h1hhpegOXU2z2Md3b5PLv9/G153tIfF333vOa0mx2RqPusUIduBdQUZUG 6LxFjTBqtMMcELu0qpx/Fvctrvg3zbjHVdIfD3gg/t+VBJkgTFFbLV0me EF/MHjwmg9EbgSEFMrm245l6RWh4shkPTJ3ejZxYQ2m/47Bwa06U6wDnH A==; X-CSE-ConnectionGUID: jefOeXrKTeq53LLZYqn4tg== X-CSE-MsgGUID: AtVpymHAReK4OLoG4Xaf0g== X-IronPort-AV: E=McAfee;i="6800,10657,11987"; a="5542602" X-IronPort-AV: E=Sophos;i="6.29,80,1794902400"; d="scan'208";a="5542602" X-Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2026 03:19:24 -0800 X-CSE-ConnectionGUID: tsz1v5dqQYK9SMFPbH8efg== X-CSE-MsgGUID: DbeonFKrTZmpkg50WWFDRg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,80,1794902400"; d="scan'208";a="14445415" X-Received: from conormcd-mobl2.ger.corp.intel.com (HELO localhost) ([10.245.245.126]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2026 03:19:20 -0800 X-Cc: 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 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261205073304.86227-2-163wangjack@gmail.com> X-Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo