Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2913906ybx; Fri, 8 Nov 2019 11:11:52 -0800 (PST) X-Google-Smtp-Source: APXvYqz0itTYr0ptXa3dny+00x1t3rAgX9GMB68ttXE+B7S6IIh83ezCiZkK71+OWk0XfJBujuS/ X-Received: by 2002:a50:958d:: with SMTP id w13mr12383426eda.243.1573240312113; Fri, 08 Nov 2019 11:11:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573240312; cv=none; d=google.com; s=arc-20160816; b=Ca63M/A+i42tUjHn2DYrmo/HGAiVsQAUmhRUZ7+Zb7mVaZeSDSACpqfBkoJ24afxIv pv3vT4Uru0wwBZb4BZ4GAStJrbsZQeTiraewWYa7HFtlRXwm1fiNqajz1DgHIRTK+unJ FPsfnICtJ1JUB/a0iFnzqJrgIDS4tJ6R1I+nESrfBlrF8CCLqwXfI+9LhiRrj649gOTP f9LTIh5JGSQmWPiAJWt8LMSToD4EyMtXsN9goWMUoR+uQ6zjDA2SuD5yYqhzGfdO6FE8 i2LNIugXlqzDVhCppu6lHRAhr0uZmRT2FG430P5UHvHithRdj3xc2kW/jN7bl5J8KDHZ SnMw== 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=XXiVmD1cAJeaBZMxALfZ+CVWojvc+W3FTwJJT7XMz1E=; b=jJdICfAasV22eLXNvRW2X4Ta2DWqiPDqHaApIoS4cMnPvTBinRy3xnAenQb1zrzIEU +zeO7es0RlO7WytjZIt5U0PdfBZR7boyzJh7IYLwumBehVtIyLBQbD/iMKq0K86zrRqL laneFOGXswkD4vQAuKaGVzoWmWFG6JYW4jBoo0xvp8KqKLqzf5surOB+9Limni/TDcm+ qoEtytgedUEZ4485pwOUC95WvmtZ9EzZRre7v5vvTW9EY6H9mf2yH09ySrxmQPISQc9y FtA/46vPFWsnvX0AFt/IogODOc34Pu+EpiFiokMkgcnsmLHx1hBwOCRvSL70ImbrDutV LTAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mIDWc8i0; 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 c23si4534883ejk.143.2019.11.08.11.11.29; Fri, 08 Nov 2019 11:11:52 -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=mIDWc8i0; 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 S2391958AbfKHTLA (ORCPT + 99 others); Fri, 8 Nov 2019 14:11:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:43330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391953AbfKHTK7 (ORCPT ); Fri, 8 Nov 2019 14:10:59 -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 4BB8320673; Fri, 8 Nov 2019 19:10:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573240258; bh=VEYYR7bD4FTmSODOnA+DpEKBm0gjVXVQvA7r9m/ayOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mIDWc8i0sjHnYYGo3Wc5uB2AXVw5RBrXR5iM9cN3mGBwIo+J/pdjMAokiElxaK69E C40Xwyx2u+ZUfmhE2zgtVXNKaBUsB+QWGKjuBf9L03oVvxYXzjao7Cf2KmQ527pDTO ae5hS5UgvsI6mZ2RhxBKBMYm4PzVyNPMk4XwTlxk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxim Mikityanskiy , Saeed Mahameed Subject: [PATCH 5.3 119/140] net/mlx5e: Fix handling of compressed CQEs in case of low NAPI budget Date: Fri, 8 Nov 2019 19:50:47 +0100 Message-Id: <20191108174912.273017519@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174900.189064908@linuxfoundation.org> References: <20191108174900.189064908@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: Maxim Mikityanskiy [ Upstream commit 9df86bdb6746d7fcfc2fda715f7a7c3d0ddb2654 ] When CQE compression is enabled, compressed CQEs use the following structure: a title is followed by one or many blocks, each containing 8 mini CQEs (except the last, which may contain fewer mini CQEs). Due to NAPI budget restriction, a complete structure is not always parsed in one NAPI run, and some blocks with mini CQEs may be deferred to the next NAPI poll call - we have the mlx5e_decompress_cqes_cont call in the beginning of mlx5e_poll_rx_cq. However, if the budget is extremely low, some blocks may be left even after that, but the code that follows the mlx5e_decompress_cqes_cont call doesn't check it and assumes that a new CQE begins, which may not be the case. In such cases, random memory corruptions occur. An extremely low NAPI budget of 8 is used when busy_poll or busy_read is active. This commit adds a check to make sure that the previous compressed CQE has been completely parsed after mlx5e_decompress_cqes_cont, otherwise it prevents a new CQE from being fetched in the middle of a compressed CQE. This commit fixes random crashes in __build_skb, __page_pool_put_page and other not-related-directly places, that used to happen when both CQE compression and busy_poll/busy_read were enabled. Fixes: 7219ab34f184 ("net/mlx5e: CQE compression") Signed-off-by: Maxim Mikityanskiy Signed-off-by: Saeed Mahameed Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -1367,8 +1367,11 @@ int mlx5e_poll_rx_cq(struct mlx5e_cq *cq if (unlikely(!test_bit(MLX5E_RQ_STATE_ENABLED, &rq->state))) return 0; - if (rq->cqd.left) + if (rq->cqd.left) { work_done += mlx5e_decompress_cqes_cont(rq, cqwq, 0, budget); + if (rq->cqd.left || work_done >= budget) + goto out; + } cqe = mlx5_cqwq_get_cqe(cqwq); if (!cqe) {