Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17926004ybl; Thu, 2 Jan 2020 14:57:46 -0800 (PST) X-Google-Smtp-Source: APXvYqxqEVtM2tXKryQ6hMat41/f88ufML/q/r/dpPhzkDyRFIIrIGPBys+zKzi3MZLgn9dS5V0f X-Received: by 2002:a05:6830:1d6e:: with SMTP id l14mr94163661oti.32.1578005866420; Thu, 02 Jan 2020 14:57:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578005866; cv=none; d=google.com; s=arc-20160816; b=smUzL/6QELanJSfYnkFCQDzl5bArgSW7JGgjt8eR8D8iwgY1Nl8Mu+27CpV6NxRG7D HPB2dMjXIP6Pbblc0ZtWKwFu6VREHfcx/2ht601oQ6aQk4e8Zl+cdS9LrxkTkhO7cjA6 /exRsBY7qjOXtq8EYdKl63HB0mofw7qpR/I4pCm3N8+/sMfOuOExWZduqDZlqyOU3srq 60CHWkLsXg+v1BJEeCyb5PmXgUwq589frIEevXf7xZ/+iGVHYFuUqePqBHBAue5btSME SBsyrdwMd1NvqclepkUKWJjOxbNW70X2pXBIGyVMKHejgaixQB5/IPc3By1IWV3SLqWF FuYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5Y+OmvAnacAnywBDqHnS5QIFwoTB9TlcCPOwptfOJ4o=; b=OC/YoercPNQxPAM3DL7AYTWNJuKqJr4NlO1jDVY67b67keKEPLx9k6stL0lRrkGmQ/ SmjSBrGax/qPR7Bkib/OLwEhm7f9+0mpYTd3CrwD+iRea/1I2I3cJ/BplwJFYUenD1Tv klUX+YBR9fwIA4xeGyYPAvbQhC5zK9uVqggGKeXLyPItgupYoPVxxS6JTKQzBPSQ/XwM 5wKh7ixIquCC7e02AyJUJiRT3OwcAO03qWhc/AwfxKakxdrG/AS1zHYg0E3AVNmNC43D 7AY8blLL6n/i853L5Sb6qIL9knQtgigKJ1ncrZW/Qg7rqOj0O5DxCt3Ly8hu+vXR2fM3 Aw2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Fcfs9A5k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v21si35090523otf.87.2020.01.02.14.57.34; Thu, 02 Jan 2020 14:57:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Fcfs9A5k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728655AbgABW41 (ORCPT + 99 others); Thu, 2 Jan 2020 17:56:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:33582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728326AbgABWSX (ORCPT ); Thu, 2 Jan 2020 17:18:23 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3360721582; Thu, 2 Jan 2020 22:18:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003502; bh=IQQjTn2rQUrfNOk9A8Gln9nVWGLvN0dhB7+ltGEOMN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fcfs9A5kNqCkCnV5FUuBOgkS/0PEqUWLkoZw07M/HZfV9aNOraDhrf0rEf4rX14cM 8il1c80dnYYAeaQHAvm1oC0T7MpKLA4jxBmWbreEoTmGaZsd1T7GzT/0dVSqOzbvK5 FnCNY6a7QI4L4jW2PhMGKcwQreQHxspm+qdyUqy8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Netanel Belgazal , "David S. Miller" Subject: [PATCH 5.4 188/191] net: ena: fix napi handler misbehavior when the napi budget is zero Date: Thu, 2 Jan 2020 23:07:50 +0100 Message-Id: <20200102215849.750363784@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Netanel Belgazal [ Upstream commit 24dee0c7478d1a1e00abdf5625b7f921467325dc ] In netpoll the napi handler could be called with budget equal to zero. Current ENA napi handler doesn't take that into consideration. The napi handler handles Rx packets in a do-while loop. Currently, the budget check happens only after decrementing the budget, therefore the napi handler, in rare cases, could run over MAX_INT packets. In addition to that, this moves all budget related variables to int calculation and stop mixing u32 to avoid ambiguity Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)") Signed-off-by: Netanel Belgazal Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -1238,8 +1238,8 @@ static int ena_io_poll(struct napi_struc struct ena_napi *ena_napi = container_of(napi, struct ena_napi, napi); struct ena_ring *tx_ring, *rx_ring; - u32 tx_work_done; - u32 rx_work_done; + int tx_work_done; + int rx_work_done = 0; int tx_budget; int napi_comp_call = 0; int ret; @@ -1256,7 +1256,11 @@ static int ena_io_poll(struct napi_struc } tx_work_done = ena_clean_tx_irq(tx_ring, tx_budget); - rx_work_done = ena_clean_rx_irq(rx_ring, napi, budget); + /* On netpoll the budget is zero and the handler should only clean the + * tx completions. + */ + if (likely(budget)) + rx_work_done = ena_clean_rx_irq(rx_ring, napi, budget); /* If the device is about to reset or down, avoid unmask * the interrupt and return 0 so NAPI won't reschedule