From patchwork Mon Jan 17 18:29:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corinna Vinschen X-Patchwork-Id: 12715658 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2590BC433F5 for ; Mon, 17 Jan 2022 18:29:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238305AbiAQS3Y (ORCPT ); Mon, 17 Jan 2022 13:29:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:20412 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238267AbiAQS3X (ORCPT ); Mon, 17 Jan 2022 13:29:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642444162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q/t1Dg35LoOVsZDej/t+QtbWBTndc5BPT8YHSfXCqTA=; b=XuAjd6R2dV6nTK19Knf80cCweprYcQTzqdkhhrzczGkUeeBf4M+9N7tgPe4Gy4sXULPhEn 5CQWgxVJYySaNn4vLeCoLsX75mShMOjP+/31RsBt33RoTG/a8S+FfpGrYMx/hqxjhiXSd+ HaV5MFO/43lGKDdB/xH2k2iUv4gmSdE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-611-dtQ8xC9PNzyqOr3uOInm_Q-1; Mon, 17 Jan 2022 13:29:19 -0500 X-MC-Unique: dtQ8xC9PNzyqOr3uOInm_Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67CCF87A842; Mon, 17 Jan 2022 18:29:18 +0000 (UTC) Received: from calimero.vinschen.de (ovpn-112-3.rdu2.redhat.com [10.10.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B67F57FCC1; Mon, 17 Jan 2022 18:29:17 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id 76810A807B2; Mon, 17 Jan 2022 19:29:15 +0100 (CET) From: Corinna Vinschen To: intel-wired-lan@osuosl.org, netdev@vger.kernel.org, Vinicius Costa Gomes Cc: Lennert Buytenhek , Alexander Lobakin Subject: [PATCH 1/3 net-next v5] igc: avoid kernel warning when changing RX ring parameters Date: Mon, 17 Jan 2022 19:29:13 +0100 Message-Id: <20220117182915.1283151-2-vinschen@redhat.com> In-Reply-To: <20220117182915.1283151-1-vinschen@redhat.com> References: <20220117182915.1283151-1-vinschen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Calling ethtool changing the RX ring parameters like this: $ ethtool -G eth0 rx 1024 on igc triggers kernel warnings like this: [ 225.198467] ------------[ cut here ]------------ [ 225.198473] Missing unregister, handled but fix driver [ 225.198485] WARNING: CPU: 7 PID: 959 at net/core/xdp.c:168 xdp_rxq_info_reg+0x79/0xd0 [...] [ 225.198601] Call Trace: [ 225.198604] [ 225.198609] igc_setup_rx_resources+0x3f/0xe0 [igc] [ 225.198617] igc_ethtool_set_ringparam+0x30e/0x450 [igc] [ 225.198626] ethnl_set_rings+0x18a/0x250 [ 225.198631] genl_family_rcv_msg_doit+0xca/0x110 [ 225.198637] genl_rcv_msg+0xce/0x1c0 [ 225.198640] ? rings_prepare_data+0x60/0x60 [ 225.198644] ? genl_get_cmd+0xd0/0xd0 [ 225.198647] netlink_rcv_skb+0x4e/0xf0 [ 225.198652] genl_rcv+0x24/0x40 [ 225.198655] netlink_unicast+0x20e/0x330 [ 225.198659] netlink_sendmsg+0x23f/0x480 [ 225.198663] sock_sendmsg+0x5b/0x60 [ 225.198667] __sys_sendto+0xf0/0x160 [ 225.198671] ? handle_mm_fault+0xb2/0x280 [ 225.198676] ? do_user_addr_fault+0x1eb/0x690 [ 225.198680] __x64_sys_sendto+0x20/0x30 [ 225.198683] do_syscall_64+0x38/0x90 [ 225.198687] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 225.198693] RIP: 0033:0x7f7ae38ac3aa igc_ethtool_set_ringparam() copies the igc_ring structure but neglects to reset the xdp_rxq_info member before calling igc_setup_rx_resources(). This in turn calls xdp_rxq_info_reg() with an already registered xdp_rxq_info. Make sure to unregister the xdp_rxq_info structure first in igc_setup_rx_resources. Move xdp_rxq_info handling down to be the last action, thus allowing to remove the xdp_rxq_info_unreg call in the error path. Fixes: 73f1071c1d29 ("igc: Add support for XDP_TX action") Reported-by: Lennert Buytenhek Signed-off-by: Corinna Vinschen --- drivers/net/ethernet/intel/igc/igc_main.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index 2f17f36e94fd..56ed0f1463e5 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -505,14 +505,6 @@ int igc_setup_rx_resources(struct igc_ring *rx_ring) u8 index = rx_ring->queue_index; int size, desc_len, res; - res = xdp_rxq_info_reg(&rx_ring->xdp_rxq, ndev, index, - rx_ring->q_vector->napi.napi_id); - if (res < 0) { - netdev_err(ndev, "Failed to register xdp_rxq index %u\n", - index); - return res; - } - size = sizeof(struct igc_rx_buffer) * rx_ring->count; rx_ring->rx_buffer_info = vzalloc(size); if (!rx_ring->rx_buffer_info) @@ -534,10 +526,20 @@ int igc_setup_rx_resources(struct igc_ring *rx_ring) rx_ring->next_to_clean = 0; rx_ring->next_to_use = 0; + /* XDP RX-queue info */ + if (xdp_rxq_info_is_reg(&rx_ring->xdp_rxq)) + xdp_rxq_info_unreg(&rx_ring->xdp_rxq); + res = xdp_rxq_info_reg(&rx_ring->xdp_rxq, ndev, index, + rx_ring->q_vector->napi.napi_id); + if (res < 0) { + netdev_err(ndev, "Failed to register xdp_rxq index %u\n", + index); + goto err; + } + return 0; err: - xdp_rxq_info_unreg(&rx_ring->xdp_rxq); vfree(rx_ring->rx_buffer_info); rx_ring->rx_buffer_info = NULL; netdev_err(ndev, "Unable to allocate memory for Rx descriptor ring\n"); From patchwork Mon Jan 17 18:29:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corinna Vinschen X-Patchwork-Id: 12715657 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76481C433EF for ; Mon, 17 Jan 2022 18:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238287AbiAQS3X (ORCPT ); Mon, 17 Jan 2022 13:29:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25483 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235551AbiAQS3X (ORCPT ); Mon, 17 Jan 2022 13:29:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642444162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cv6sltPUkJtlMZoFEjr9r3hY/JFy9Ol9gLxXn9Aa8qw=; b=BBrs73xCQyA9chidAVnaJnRLsyMSVcXVzaRG5WvaYeKyEzXbf3P5G6hdBMZ4mreN+Bg7iU XZrTwY9q+bA2x0QzgEhIbXfqSscoXBLhszUHwMB7jdIfaotzCXBeZBhIGoZGfDcZg4QM6z LTtWki1nl69Cg8ciPJKfQUG6EfSF8As= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-134-SMdYphERPw6QjwfOEjBM8w-1; Mon, 17 Jan 2022 13:29:19 -0500 X-MC-Unique: SMdYphERPw6QjwfOEjBM8w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 45FD387A83C; Mon, 17 Jan 2022 18:29:18 +0000 (UTC) Received: from calimero.vinschen.de (ovpn-112-3.rdu2.redhat.com [10.10.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0E9410A4B56; Mon, 17 Jan 2022 18:29:17 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id 7B718A80BAE; Mon, 17 Jan 2022 19:29:15 +0100 (CET) From: Corinna Vinschen To: intel-wired-lan@osuosl.org, netdev@vger.kernel.org, Vinicius Costa Gomes Cc: Lennert Buytenhek , Alexander Lobakin Subject: [PATCH 2/3 net-next v5] igb: refactor XDP registration Date: Mon, 17 Jan 2022 19:29:14 +0100 Message-Id: <20220117182915.1283151-3-vinschen@redhat.com> In-Reply-To: <20220117182915.1283151-1-vinschen@redhat.com> References: <20220117182915.1283151-1-vinschen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org On changing the RX ring parameters igb uses a hack to avoid a warning when calling xdp_rxq_info_reg via igb_setup_rx_resources. It just clears the struct xdp_rxq_info content. Change this to unregister if we're already registered instead. Align code to the igc code. Fixes: 9cbc948b5a20c ("igb: add XDP support") Signed-off-by: Corinna Vinschen --- drivers/net/ethernet/intel/igb/igb_ethtool.c | 4 ---- drivers/net/ethernet/intel/igb/igb_main.c | 12 +++++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c index 51a2dcaf553d..2a5782063f4c 100644 --- a/drivers/net/ethernet/intel/igb/igb_ethtool.c +++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c @@ -965,10 +965,6 @@ static int igb_set_ringparam(struct net_device *netdev, memcpy(&temp_ring[i], adapter->rx_ring[i], sizeof(struct igb_ring)); - /* Clear copied XDP RX-queue info */ - memset(&temp_ring[i].xdp_rxq, 0, - sizeof(temp_ring[i].xdp_rxq)); - temp_ring[i].count = new_rx_count; err = igb_setup_rx_resources(&temp_ring[i]); if (err) { diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index 38ba92022cd4..cea89d301bfd 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -4352,7 +4352,7 @@ int igb_setup_rx_resources(struct igb_ring *rx_ring) { struct igb_adapter *adapter = netdev_priv(rx_ring->netdev); struct device *dev = rx_ring->dev; - int size; + int size, res; size = sizeof(struct igb_rx_buffer) * rx_ring->count; @@ -4376,9 +4376,15 @@ int igb_setup_rx_resources(struct igb_ring *rx_ring) rx_ring->xdp_prog = adapter->xdp_prog; /* XDP RX-queue info */ - if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev, - rx_ring->queue_index, 0) < 0) + if (xdp_rxq_info_is_reg(&rx_ring->xdp_rxq)) + xdp_rxq_info_unreg(&rx_ring->xdp_rxq); + res = xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev, + rx_ring->queue_index, 0); + if (res < 0) { + dev_err(dev, "Failed to register xdp_rxq index %u\n", + rx_ring->queue_index); goto err; + } return 0; From patchwork Mon Jan 17 18:29:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corinna Vinschen X-Patchwork-Id: 12715660 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1FA2C433EF for ; Mon, 17 Jan 2022 18:29:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238312AbiAQS31 (ORCPT ); Mon, 17 Jan 2022 13:29:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:24495 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238275AbiAQS3Z (ORCPT ); Mon, 17 Jan 2022 13:29:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642444165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+1z91pm1i6bzhtBA9nj8cTKaML2rfHmjBytKfTOFMZ4=; b=fgzPo0i+d5uSZ055cPLnVqgsgLyYiXzX/NKzlHumSCN31ZwG4F8IHxTySfDzB290ifIfWY mc7l/P1Jq9qKNF0NTxCW6Mtd6FEb5Nhe7MDGNtgOqc2w60G+B4Gt52RT4RzMAVsuz/Q1hZ dTdNpJWZogMgVknmjxLRUBRI2/E+TN8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-zKk6zmE3MC-Q1RRFPMFZlA-1; Mon, 17 Jan 2022 13:29:19 -0500 X-MC-Unique: zKk6zmE3MC-Q1RRFPMFZlA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8FB651017985; Mon, 17 Jan 2022 18:29:18 +0000 (UTC) Received: from calimero.vinschen.de (ovpn-112-3.rdu2.redhat.com [10.10.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0634D7ED8E; Mon, 17 Jan 2022 18:29:17 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id 8063AA80D66; Mon, 17 Jan 2022 19:29:15 +0100 (CET) From: Corinna Vinschen To: intel-wired-lan@osuosl.org, netdev@vger.kernel.org, Vinicius Costa Gomes Cc: Lennert Buytenhek , Alexander Lobakin Subject: [PATCH 3/3 net-next v5] igb/igc: RX queues: fix DMA leak in error case Date: Mon, 17 Jan 2022 19:29:15 +0100 Message-Id: <20220117182915.1283151-4-vinschen@redhat.com> In-Reply-To: <20220117182915.1283151-1-vinschen@redhat.com> References: <20220117182915.1283151-1-vinschen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When setting up the rx queues, igb and igc neglect to free DMA memory in error case. Add matching dma_free_coherent calls. Signed-off-by: Corinna Vinschen --- drivers/net/ethernet/intel/igb/igb_main.c | 1 + drivers/net/ethernet/intel/igc/igc_main.c | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index cea89d301bfd..343568d4ff7f 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -4389,6 +4389,7 @@ int igb_setup_rx_resources(struct igb_ring *rx_ring) return 0; err: + dma_free_coherent(dev, rx_ring->size, rx_ring->desc, rx_ring->dma); vfree(rx_ring->rx_buffer_info); rx_ring->rx_buffer_info = NULL; dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n"); diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index 56ed0f1463e5..f323cec0b74f 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -540,6 +540,7 @@ int igc_setup_rx_resources(struct igc_ring *rx_ring) return 0; err: + dma_free_coherent(dev, rx_ring->size, rx_ring->desc, rx_ring->dma); vfree(rx_ring->rx_buffer_info); rx_ring->rx_buffer_info = NULL; netdev_err(ndev, "Unable to allocate memory for Rx descriptor ring\n");