[{"id":3676758,"web_url":"http://patchwork.ozlabs.org/comment/3676758/","msgid":"<20260413133938.GO469338@kernel.org>","list_archive_url":null,"date":"2026-04-13T13:39:38","subject":"Re: [Intel-wired-lan] [PATCH iwl-net v2 5/6] ixgbe: fix ITR value\n overflow in adaptive interrupt throttling","submitter":{"id":82748,"url":"http://patchwork.ozlabs.org/api/people/82748/","name":"Simon Horman","email":"horms@kernel.org"},"content":"On Wed, Apr 08, 2026 at 03:11:53PM +0200, Aleksandr Loktionov wrote:\n> ixgbe_update_itr() packs a mode flag (IXGBE_ITR_ADAPTIVE_LATENCY,\n> bit 7) and a usecs delay (bits [6:0]) into an unsigned int, then\n> stores the combined value in ring_container->itr which is declared as\n> u8.  Values above 0xFF wrap on truncation, corrupting both the delay\n> and the mode flag on the next readback.\n> \n> Separate the mode bits from the usecs sub-field; clamp only the usecs\n> portion to [0, IXGBE_ITR_ADAPTIVE_LATENCY - 1] (= 0x7F) using min_t()\n> so overflow cannot bleed into bit 7.\n> \n> Fixes: b4ded8327fea (\"ixgbe: Update adaptive ITR algorithm\")\n> Cc: stable@vger.kernel.org\n> Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>\n> ---\n> v1 -> v2:\n>  - Add proper [N/M] numbering so patchwork tracks it as part of the set;\n>    no code change.\n> \n>  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 5 +++--\n>  1 file changed, 3 insertions(+), 2 deletions(-)\n> \n> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c\n> index 210c7b9..9f3ae21 100644\n> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c\n> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c\n> @@ -2889,8 +2889,9 @@ static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,\n>  \t}\n>  \n>  clear_counts:\n> -\t/* write back value */\n> -\tring_container->itr = itr;\n> +\tring_container->itr = (itr & IXGBE_ITR_ADAPTIVE_LATENCY) |\n> +\t\tmin_t(unsigned int, itr & ~IXGBE_ITR_ADAPTIVE_LATENCY,\n> +\t\t      IXGBE_ITR_ADAPTIVE_LATENCY - 1);\n\n* It is not clear to me that the mode flag bit (IXGBE_ITR_ADAPTIVE_LATENCY)\n  is always set in itr when reaching this code. But with this patch that\n  bit will always be set in ring_container->itr.\n\n* Perhaps no such case exists, but it's not clear to me how this handles a\n  case where the usec delay has overflowed into the mode flag bit.\n\n  As a hypothetical example, consider the case where the delay overflows to\n  exactly 0x80.  The resulting delay is 0 (both with and without this\n  patch).\n\n  I would suggest an approach of keeping the delay and mode bits separate\n  during calculation - in separate local variables - and only combining\n  them when ring_container->itr is set.\n\n  This may turn out to be more verbose. But I expect it is easier to reason\n  with.\n\n* Looking over the code, it looks like the maximum allowed udelay is\n  IXGBE_ITR_ADAPTIVE_MAX_USECS (126) rather than\n  IXGBE_ITR_ADAPTIVE_LATENCY - 1 (127).\n\n* The calculation does not guard against delay values less\n  than IXGBE_ITR_ADAPTIVE_MIN_USECS. Which looking over the code seems\n  to be something that matters. (And which occurred in the hypothetical\n  example above).\n\n* As itr is an unsigned int, and IXGBE_ITR_ADAPTIVE_LATENCY - 1 is a\n  compile time constant, I expect that min() is sufficient.\n  IOW, I don't think min_t is needed here.\n\n* It looks like using FIELD_PREP is appropriate to construct\n  ring_container->itr. But that may be overkill if you end up with\n  something like:\n\n\tring_container->itr = mode | clamp(delay, IXGBE_ITR_ADAPTIVE_MAX_USECS,\n\t\t\t\t\t   IXGBE_ITR_ADAPTIVE_MIN_USECS);\n\n>  \n>  \t/* next update should occur within next jiffy */\n>  \tring_container->next_update = next_update + 1;\n> -- \n> 2.52.0","headers":{"Return-Path":"<intel-wired-lan-bounces@osuosl.org>","X-Original-To":["incoming@patchwork.ozlabs.org","intel-wired-lan@lists.osuosl.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","intel-wired-lan@lists.osuosl.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256\n header.s=default header.b=nSMna1mn;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org\n (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org;\n envelope-from=intel-wired-lan-bounces@osuosl.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fvT6Y1d9Rz1yDF\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 23:39:48 +1000 (AEST)","from localhost (localhost [127.0.0.1])\n\tby smtp1.osuosl.org (Postfix) with ESMTP id C99848476F;\n\tMon, 13 Apr 2026 13:39:46 +0000 (UTC)","from smtp1.osuosl.org ([127.0.0.1])\n by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP\n id ePgxjgx0MhyV; Mon, 13 Apr 2026 13:39:46 +0000 (UTC)","from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142])\n\tby smtp1.osuosl.org (Postfix) with ESMTP id 093E884756;\n\tMon, 13 Apr 2026 13:39:46 +0000 (UTC)","from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133])\n by lists1.osuosl.org (Postfix) with ESMTP id 9FEDD237\n for <intel-wired-lan@lists.osuosl.org>; Mon, 13 Apr 2026 13:39:44 +0000 (UTC)","from localhost (localhost [127.0.0.1])\n by smtp2.osuosl.org (Postfix) with ESMTP id 88A534039D\n for <intel-wired-lan@lists.osuosl.org>; Mon, 13 Apr 2026 13:39:44 +0000 (UTC)","from smtp2.osuosl.org ([127.0.0.1])\n by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP\n id 4s6QbVmhpB-s for <intel-wired-lan@lists.osuosl.org>;\n Mon, 13 Apr 2026 13:39:44 +0000 (UTC)","from tor.source.kernel.org (tor.source.kernel.org\n [IPv6:2600:3c04:e001:324:0:1991:8:25])\n by smtp2.osuosl.org (Postfix) with ESMTPS id C7077400C2\n for <intel-wired-lan@lists.osuosl.org>; Mon, 13 Apr 2026 13:39:43 +0000 (UTC)","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n by tor.source.kernel.org (Postfix) with ESMTP id 55AF260172;\n Mon, 13 Apr 2026 13:39:42 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 15330C2BCAF;\n Mon, 13 Apr 2026 13:39:40 +0000 (UTC)"],"X-Virus-Scanned":["amavis at osuosl.org","amavis at osuosl.org"],"X-Comment":"SPF check N/A for local connections - client-ip=140.211.166.142;\n helo=lists1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org;\n receiver=<UNKNOWN> ","DKIM-Filter":["OpenDKIM Filter v2.11.0 smtp1.osuosl.org 093E884756","OpenDKIM Filter v2.11.0 smtp2.osuosl.org C7077400C2"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org;\n\ts=default; t=1776087586;\n\tbh=caQLH2eQA+cVj6L+jPl6I978k2jvHU4IalKwYY1AlgU=;\n\th=Date:From:To:Cc:References:In-Reply-To:Subject:List-Id:\n\t List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:\n\t From;\n\tb=nSMna1mnFD2vlJsNjHZ0xj0SBlrSCoGxN0/I0Yh2H9kJ/iM3Z37Sg3GzWVkAEpOzq\n\t uuyhkLQGGD3RMZFhQvZurOKlrurswdoEWcpQ4jeybH95W9KgS1rKGzzFMfbPzXTBMY\n\t KlQuNUpUcvHdIotcYx16yCncE+Ryme+FwgZHrNw9Zi6pnR4bwnuAtVTxrgS9hXMl+u\n\t IwQGfevy1o/vEUop6EIh+donWzdpxllzmrkIFrXUH5RkWdCrpGAbrty2Caxo8OC1ux\n\t 0JeKLrS7ysA0iFi+vaZbqB8F+rYnZBR7II/VHQ1urVGCBnrhi/JRqDgZXEb2aX2LKi\n\t dgmI+er3lMq8Q==","Received-SPF":"Pass (mailfrom) identity=mailfrom;\n client-ip=2600:3c04:e001:324:0:1991:8:25; helo=tor.source.kernel.org;\n envelope-from=horms@kernel.org; receiver=<UNKNOWN>","DMARC-Filter":"OpenDMARC Filter v1.4.2 smtp2.osuosl.org C7077400C2","Date":"Mon, 13 Apr 2026 14:39:38 +0100","From":"Simon Horman <horms@kernel.org>","To":"Aleksandr Loktionov <aleksandr.loktionov@intel.com>","Cc":"intel-wired-lan@lists.osuosl.org, anthony.l.nguyen@intel.com,\n netdev@vger.kernel.org","Message-ID":"<20260413133938.GO469338@kernel.org>","References":"<20260408131154.2661818-1-aleksandr.loktionov@intel.com>\n <20260408131154.2661818-6-aleksandr.loktionov@intel.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20260408131154.2661818-6-aleksandr.loktionov@intel.com>","X-Mailman-Original-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n d=kernel.org; s=k20201202; t=1776087582;\n bh=0X3mZWOmxnCPoruGCJnthAxCGMk/6xAlSVH+ODrnXMU=;\n h=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n b=PSCwuu5v+KZUBwaW+KFZWQ8FGHtXNfvmLmhpOWwIbY4daYzEdpafJN/VzbSqZcCoL\n E76fubZyK5z/NGghsczaofX5rDQ0F3a/w5vMD92sJDRva95AqHrHG4PhMwMx8Xg/kg\n fYq51iYvhFGj2b8HxWDTyadgD7eO3aerOPMBmu/GawBCZ4TZzLLihHnnVbwIOo3Aa0\n dEG44rBsRx8KWLx8pzFiOQ2gH9jUZb5taiTZatbS7R8XZp6foHwfEEQQKGtKqmi5R9\n koC05GjLDhALLEbF769DkfwRo2wA03Gv6FmhHL/FeCcaQQjpglMdhJQvvoSK8MNFSr\n zVFWhKWBFWIlg==","X-Mailman-Original-Authentication-Results":["smtp2.osuosl.org;\n dmarc=pass (p=quarantine dis=none)\n header.from=kernel.org","smtp2.osuosl.org;\n dkim=pass (2048-bit key,\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=PSCwuu5v"],"Subject":"Re: [Intel-wired-lan] [PATCH iwl-net v2 5/6] ixgbe: fix ITR value\n overflow in adaptive interrupt throttling","X-BeenThere":"intel-wired-lan@osuosl.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Intel Wired Ethernet Linux Kernel Driver Development\n <intel-wired-lan.osuosl.org>","List-Unsubscribe":"<https://lists.osuosl.org/mailman/options/intel-wired-lan>,\n <mailto:intel-wired-lan-request@osuosl.org?subject=unsubscribe>","List-Archive":"<http://lists.osuosl.org/pipermail/intel-wired-lan/>","List-Post":"<mailto:intel-wired-lan@osuosl.org>","List-Help":"<mailto:intel-wired-lan-request@osuosl.org?subject=help>","List-Subscribe":"<https://lists.osuosl.org/mailman/listinfo/intel-wired-lan>,\n <mailto:intel-wired-lan-request@osuosl.org?subject=subscribe>","Errors-To":"intel-wired-lan-bounces@osuosl.org","Sender":"\"Intel-wired-lan\" <intel-wired-lan-bounces@osuosl.org>"}}]