Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11797285pjo; Thu, 2 Jan 2020 14:27:01 -0800 (PST) X-Google-Smtp-Source: APXvYqx1T/gOV8DTeFm5B5o8JmxNM2H1PGspmymIGWQX7eai4dvS0NV7bTjbnu0hFfv7EOeHPSlB X-Received: by 2002:a54:4e08:: with SMTP id a8mr3179636oiy.77.1578004021352; Thu, 02 Jan 2020 14:27:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578004021; cv=none; d=google.com; s=arc-20160816; b=LAxGJ0pj006wjd+sGEro8Odceo4L57qVqQdZDlKWKPjrjcQkgs2b1QtTTPBu2CgT+u 68Crv75FcFk+XsigPMAHgcK/4XJ0BoYBbEMD9tk7WL/9Zvnwbq5c9amsYsK9/HBGjxRi IPuqHlYrj2s6l5kzt+S28nS3ibms8+qORyO/kSDIOt8avIjjroBVx+KflZfHTBKnoRjm bhcUWDZnyg9zWO4876mKPFRwNJf5sFLPa6QHDo8YCH4L4IaMslKKSJhJHTtmJXNorgUO PqpdXrSEc71djZ4gnN6/kktwhN6YE1JoeCkchfO2to6MRTtMk3g9owiBTdzll/EuWf7T JM8g== 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=AYICuqPiDgpq3aKhfJ//dZqHt0TKA3pcsPrTnhJ8MI4=; b=SQi7m7CgGNw+nRnPItbPHZhqHtIdFXfzs4TaZNPAxBOtNr5mf0l7BOD17KQZ+XREbt +VIAAiSwWy+l4Rvq3qqnrepOKOaXUVGhHRsE8VtnOVT13AE3/ecaYEpde1bcEYou85tf A+5XnZY2ImUWFLz63ZTUCeTz1N0oJE1qP6LtkEyVYtO/2CH41RwuT9lQ5XYCvYLw0eFT +IG+LR3e6INlygAI8AfBVzsivBeecY9Mn2HhYG/+tqJBwU+c1WINEn6awVQfZB9llIMW dwd6hZ78Jh8e1r3Ngian2Jl4cqDYeKYmvQwrHwbW5hz/uoG3jl9lKedZub0M10JVO1zk KRNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BpEx7OZ1; 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 p186si28961550oih.172.2020.01.02.14.26.49; Thu, 02 Jan 2020 14:27:01 -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=BpEx7OZ1; 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 S1729619AbgABW0L (ORCPT + 99 others); Thu, 2 Jan 2020 17:26:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:52964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729617AbgABW0J (ORCPT ); Thu, 2 Jan 2020 17:26:09 -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 2EBB420863; Thu, 2 Jan 2020 22:26:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003968; bh=TTrH4AKxvepDzY/FRGVncaQTflBmRdZjrfprl3Qu84g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BpEx7OZ14dH0GAQxHNbA8WtNZH4t+Xu/wIXcSx4wmZ8FjxAGymwZpXAlep8nqWmHg Fzfhx7Q4qK8I4qaXsYnvODW4XK4/UGzntsqqdyGhDvmC17GNC4f6v4R/BqW2bqYr9m /T0hTpAdtLf+FLM0+2O8wwidrZIQVCVzWqU6e4Ys= 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 4.14 74/91] net: ena: fix napi handler misbehavior when the napi budget is zero Date: Thu, 2 Jan 2020 23:07:56 +0100 Message-Id: <20200102220447.623164175@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220356.856162165@linuxfoundation.org> References: <20200102220356.856162165@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 @@ -1196,8 +1196,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; @@ -1214,7 +1214,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