Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1371231pxj; Fri, 18 Jun 2021 05:53:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztrfYlvPQ969mbxVSmW0Hx/HFAP5aTHO8HiyI7TmWzHjBrRPwRfN+IlzlVmP7xEtMWm+tp X-Received: by 2002:a17:906:f6c8:: with SMTP id jo8mr6680344ejb.177.1624020786562; Fri, 18 Jun 2021 05:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624020786; cv=none; d=google.com; s=arc-20160816; b=V4Zc9pp9PO6CsNPBgyMJ/QERM4sUcws3kC5P0xEsOz91slQBr0FsFnIoqNvStW71ci +xn2PyZDy+GOx2aHyyGT/mX/7bEFLWb7JgML1Wh/7y3RIyZk0Tck5Wryq1r+5P1oZ2oT 1dZZ8D7BN555olciv/PQCo9cbEjaPMZhNACwWEjPqyp5342G2r/V0wbAiTOL/XxRTk8r VCGmJsyRBToL0+Wlc4FlMyVAs2aHv0OR5o91DKt08kepqhglQmHLEAmcVs68sFa6vw1K nfASLgJC+WxjvcTSCuS1IYFweLaaEFrLx+Q4yejvgpTj6bKgRPJVBNY+U9dBLOORawh3 JUkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=nx2d4a6lq6b5t4oNwYu749XEfJFMbFcRsZP9tytHmcw=; b=vEPoGXghjVBbL7AUM5Kjl+RlGxosWIMtIg3x58s6qA4c/mNzlokWHRQNMktADReHg3 9TgYOyB/ZPyTTVRA8FNx8UFoF6CV4Lr1WM1qvr5r07p+8TkgtehtT47bmbx/zrr31h/J U7SiwWzt5yID3xBjp2hXKoNijRGKzMlLbLeBiVQrbELGjI/lmp8EgpEO3Nl9uZSwWkd1 +DbkyXUzBIj5fLkoZ3A4lrxwWzvgkaSpfE4Vm+4ARgKCSEPRkt53F7vU5vzhaVV7TkcU DN8LiJVtfMSIOiHuJUUXiB3xVw1fMZo+wQPyJQzJlZGjKy34NTmMj7x5iDsA6MM3+IIL qnBQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y18si8416241edv.141.2021.06.18.05.52.34; Fri, 18 Jun 2021 05:53:06 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231969AbhFRMPL (ORCPT + 99 others); Fri, 18 Jun 2021 08:15:11 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:7489 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231250AbhFRMPL (ORCPT ); Fri, 18 Jun 2021 08:15:11 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4G5yRG4hrzzZjjq; Fri, 18 Jun 2021 20:10:02 +0800 (CST) Received: from dggemi759-chm.china.huawei.com (10.1.198.145) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Fri, 18 Jun 2021 20:12:58 +0800 Received: from localhost.localdomain (10.67.165.24) by dggemi759-chm.china.huawei.com (10.1.198.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 18 Jun 2021 20:12:58 +0800 From: Guangbin Huang To: , CC: , , , , Subject: [PATCH net-next] net: hns3: fix reuse conflict of the rx page Date: Fri, 18 Jun 2021 20:09:45 +0800 Message-ID: <1624018185-38469-1-git-send-email-huangguangbin2@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggemi759-chm.china.huawei.com (10.1.198.145) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yunsheng Lin In the current rx page reuse handling process, the rx page buffer may have conflict between driver and stack in high-pressure scenario. To fix this problem, we need to check whether the page is only owned by driver at the begin and at the end of a page to make sure there is no reuse conflict between driver and stack when desc_cb->page_offset is rollbacked to zero or increased. Fixes: fa7711b888f2 ("net: hns3: optimize the rx page reuse handling process") Signed-off-by: Yunsheng Lin Signed-off-by: Guangbin Huang --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 51bbf5f760c5..cdb5f14fb6bc 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -3537,21 +3537,33 @@ static void hns3_nic_reuse_page(struct sk_buff *skb, int i, int size = le16_to_cpu(desc->rx.size); u32 truesize = hns3_buf_size(ring); u32 frag_size = size - pull_len; + bool reused; /* Avoid re-using remote or pfmem page */ if (unlikely(!dev_page_is_reusable(desc_cb->priv))) goto out; - /* Stack is not using and current page_offset is non-zero, we can - * reuse from the zero offset. + reused = hns3_can_reuse_page(desc_cb); + + /* Rx page can be reused when: + * 1. Rx page is only owned by the driver when page_offset + * is zero, which means 0 @ truesize will be used by + * stack after skb_add_rx_frag() is called, and the rest + * of rx page can be reused by driver. + * Or + * 2. Rx page is only owned by the driver when page_offset + * is non-zero, which means page_offset @ truesize will + * be used by stack after skb_add_rx_frag() is called, + * and 0 @ truesize can be reused by driver. */ - if (desc_cb->page_offset && hns3_can_reuse_page(desc_cb)) { - desc_cb->page_offset = 0; - desc_cb->reuse_flag = 1; - } else if (desc_cb->page_offset + truesize * 2 <= - hns3_page_size(ring)) { + if ((!desc_cb->page_offset && reused) || + ((desc_cb->page_offset + truesize + truesize) <= + hns3_page_size(ring) && desc_cb->page_offset)) { desc_cb->page_offset += truesize; desc_cb->reuse_flag = 1; + } else if (desc_cb->page_offset && reused) { + desc_cb->page_offset = 0; + desc_cb->reuse_flag = 1; } else if (frag_size <= ring->rx_copybreak) { void *frag = napi_alloc_frag(frag_size); -- 2.8.1