Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3934115pxj; Mon, 21 Jun 2021 09:41:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcMzWStFFMMpo4vLbz1z++aCi3Dwp+85U0o1SjjGlyWT4l6/LPN6/4az8Y1MJcZtCWmhFN X-Received: by 2002:a17:907:9607:: with SMTP id gb7mr26029379ejc.208.1624293678648; Mon, 21 Jun 2021 09:41:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293678; cv=none; d=google.com; s=arc-20160816; b=OJgGDYUc0g//n9ivStTZyQMdON+grsIFhzTFqCpKKgVWq0a+D8oz1y/LXrKhiczvrG 0eD7IqulOoiE2GWIsNCynIqeBgi8gkdYTO3fLzBZZq4KzmTGwD1LA+cphsnUW72zNyE0 A6svS3hodolE5fGPrcZdw1D/c1z+UMn3n9Km7P+ardcMiCuBjUjEmZlz0n+qv9DnPqWe Zf3PizKNmOjpR4JhBrqWxddEd28xCwi3nRgabJLDwppIOcpWWmQSSpeJ87y9syH9mGpw HOY/cJ5CkKuhMjOBwjs+D5Eb06OzAtnI02NQcU97oGyKOx491MiMm9l1kUUS6+6nNOLA zQ3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kOOlETjqhig6Fyj5XYRyI/mYM5cjwTbv8JJ6C6xX0H4=; b=Z/fd8VeLQ80FlcXog8dUAWpBsts7/MKKTfuFrCArlDdoL70IPwfGHLoTRyA79EtEV0 tnPVhmKLJoa6JKdO+Y33IGh0fzuTQo7lBadEBY69otVo/bDRuukYukznSWOTOiNsjnjQ L85Rpq4HoIcUGMtbrZ0IIpb85ruaNc0FNIxA6rs+Y2bfKWXmF4HX4ya1eZBpLOqqMRva jYlPIqB/bIerwN9DFxtzBNDIwyZlejs3Edv8+E50v6EBtBWaKfvjmaE5DSAyCRyObhZy 4wA1z+7/7px1BYWvzf+zZEwKAGwRE+uV7q6iUFxZ5385/sXsJzYfnY8zWfj+S9O8apou /puA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LOl+AkRF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si16948979edf.15.2021.06.21.09.40.56; Mon, 21 Jun 2021 09:41:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LOl+AkRF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233011AbhFUQlx (ORCPT + 99 others); Mon, 21 Jun 2021 12:41:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:33594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231937AbhFUQih (ORCPT ); Mon, 21 Jun 2021 12:38:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3EE9761245; Mon, 21 Jun 2021 16:29:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292970; bh=5W71BzudKsWzc92z921J1yzf/qG2GG5lDLQAv7LITOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LOl+AkRFTonmLWod/xKnR5aZ5ptmI4kQCqBVPCuXETxA60BxHaEuowUCc6y2DcE+f zIkqVFJQcqH7JtN8ip1vpRMI/z50ljWkgWKuJiAyVL41NE9bvT2kwmejNVdIm/k77w f5q1KBa8kNCE6LplSIReT+WyGD/0z+kR+I7IWy2s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shay Agroskin , "David S. Miller" , Sasha Levin Subject: [PATCH 5.12 023/178] net: ena: fix DMA mapping function issues in XDP Date: Mon, 21 Jun 2021 18:13:57 +0200 Message-Id: <20210621154922.575572256@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shay Agroskin [ Upstream commit 504fd6a5390c30b1b7670768e314dd5d473da06a ] This patch fixes several bugs found when (DMA/LLQ) mapping a packet for transmission. The mapping procedure makes the transmitted packet accessible by the device. When using LLQ, this requires copying the packet's header to push header (which would be passed to LLQ) and creating DMA mapping for the payload (if the packet doesn't fit the maximum push length). When not using LLQ, we map the whole packet with DMA. The following bugs are fixed in the code: 1. Add support for non-LLQ machines: The ena_xdp_tx_map_frame() function assumed that LLQ is supported, and never mapped the whole packet using DMA. On some instances, which don't support LLQ, this causes loss of traffic. 2. Wrong DMA buffer length passed to device: When using LLQ, the first 'tx_max_header_size' bytes of the packet would be copied to push header. The rest of the packet would be copied to a DMA'd buffer. 3. Freeing the XDP buffer twice in case of a mapping error: In case a buffer DMA mapping fails, the function uses xdp_return_frame_rx_napi() to free the RX buffer and returns from the function with an error. XDP frames that fail to xmit get freed by the kernel and so there is no need for this call. Fixes: 548c4940b9f1 ("net: ena: Implement XDP_TX action") Signed-off-by: Shay Agroskin Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 54 ++++++++++---------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 102f2c91fdb8..20f8012bbe04 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -236,36 +236,48 @@ static int ena_xdp_io_poll(struct napi_struct *napi, int budget) static int ena_xdp_tx_map_frame(struct ena_ring *xdp_ring, struct ena_tx_buffer *tx_info, struct xdp_frame *xdpf, - void **push_hdr, - u32 *push_len) + struct ena_com_tx_ctx *ena_tx_ctx) { struct ena_adapter *adapter = xdp_ring->adapter; struct ena_com_buf *ena_buf; - dma_addr_t dma = 0; + int push_len = 0; + dma_addr_t dma; + void *data; u32 size; tx_info->xdpf = xdpf; + data = tx_info->xdpf->data; size = tx_info->xdpf->len; - ena_buf = tx_info->bufs; - /* llq push buffer */ - *push_len = min_t(u32, size, xdp_ring->tx_max_header_size); - *push_hdr = tx_info->xdpf->data; + if (xdp_ring->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV) { + /* Designate part of the packet for LLQ */ + push_len = min_t(u32, size, xdp_ring->tx_max_header_size); + + ena_tx_ctx->push_header = data; + + size -= push_len; + data += push_len; + } + + ena_tx_ctx->header_len = push_len; - if (size - *push_len > 0) { + if (size > 0) { dma = dma_map_single(xdp_ring->dev, - *push_hdr + *push_len, - size - *push_len, + data, + size, DMA_TO_DEVICE); if (unlikely(dma_mapping_error(xdp_ring->dev, dma))) goto error_report_dma_error; - tx_info->map_linear_data = 1; - tx_info->num_of_bufs = 1; - } + tx_info->map_linear_data = 0; - ena_buf->paddr = dma; - ena_buf->len = size; + ena_buf = tx_info->bufs; + ena_buf->paddr = dma; + ena_buf->len = size; + + ena_tx_ctx->ena_bufs = ena_buf; + ena_tx_ctx->num_bufs = tx_info->num_of_bufs = 1; + } return 0; @@ -274,10 +286,6 @@ error_report_dma_error: &xdp_ring->syncp); netif_warn(adapter, tx_queued, adapter->netdev, "Failed to map xdp buff\n"); - xdp_return_frame_rx_napi(tx_info->xdpf); - tx_info->xdpf = NULL; - tx_info->num_of_bufs = 0; - return -EINVAL; } @@ -289,8 +297,6 @@ static int ena_xdp_xmit_frame(struct ena_ring *xdp_ring, struct ena_com_tx_ctx ena_tx_ctx = {}; struct ena_tx_buffer *tx_info; u16 next_to_use, req_id; - void *push_hdr; - u32 push_len; int rc; next_to_use = xdp_ring->next_to_use; @@ -298,15 +304,11 @@ static int ena_xdp_xmit_frame(struct ena_ring *xdp_ring, tx_info = &xdp_ring->tx_buffer_info[req_id]; tx_info->num_of_bufs = 0; - rc = ena_xdp_tx_map_frame(xdp_ring, tx_info, xdpf, &push_hdr, &push_len); + rc = ena_xdp_tx_map_frame(xdp_ring, tx_info, xdpf, &ena_tx_ctx); if (unlikely(rc)) goto error_drop_packet; - ena_tx_ctx.ena_bufs = tx_info->bufs; - ena_tx_ctx.push_header = push_hdr; - ena_tx_ctx.num_bufs = tx_info->num_of_bufs; ena_tx_ctx.req_id = req_id; - ena_tx_ctx.header_len = push_len; rc = ena_xmit_common(dev, xdp_ring, -- 2.30.2