From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.21 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== 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== 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 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) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DF8C5606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=bA/dY3wt 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" 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" 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 Date: Sat, 5 Dec 2026 13:19:17 +0200 From: Andy Shevchenko To: Jack Wang <163wangjack@gmail.com> 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 Subject: Re: [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions Message-ID: References: <20261205073304.86227-1-163wangjack@gmail.com> <20261205073304.86227-2-163wangjack@gmail.com> 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-Disposition: inline In-Reply-To: <20261205073304.86227-2-163wangjack@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo 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