From patchwork Fri Jan 19 10:22:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyunjian X-Patchwork-Id: 13523549 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 311DF3CF4F; Fri, 19 Jan 2024 10:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705659766; cv=none; b=fPL9+vuqODGSr0Vo5/WhIiqT0Jbg3KmsPMSvqjcqfLSMg6xgyPwdfiV3vE+mPu/3reFWZb9Q6nwo9pbyj7b0/Nz8BpZ07AoEJv4syeNPCYwH0918jS4BpTDXKm0E39GRcu2BZFuuMKW159TqQDO0xxZG0iqfpVfkkjg8oVPs/v0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705659766; c=relaxed/simple; bh=s18ppnGo5XugcpIC11YfHzdsPrSQi1CfkjQOubpKxYs=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Z3vkSWq8I03DC7jIxU8EJJzZzSqOAk7GU4l2DxYckZ3nTx7I5Zzv65QRzuchqQ/nm54H6w95ao3/eS1InaY5jw+YTaQcW/ssHyV3D+VJ5d3YMyDhfmHxGopQ2a0RfQN3NhiM7qNCEjxyoGgUPzBQGU1SnSnn2uIPqBOPKwbkZW4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TGbHK3nRMz29kL2; Fri, 19 Jan 2024 18:21:01 +0800 (CST) Received: from dggpemm500008.china.huawei.com (unknown [7.185.36.136]) by mail.maildlp.com (Postfix) with ESMTPS id 6A45618002F; Fri, 19 Jan 2024 18:22:41 +0800 (CST) Received: from localhost (10.174.242.157) by dggpemm500008.china.huawei.com (7.185.36.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 19 Jan 2024 18:22:41 +0800 From: Yunjian Wang To: , , , CC: , , , Yunjian Wang Subject: [PATCH net 1/2] tun: fix missing dropped counter in tun_xdp_act Date: Fri, 19 Jan 2024 18:22:35 +0800 Message-ID: <1705659755-39828-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500008.china.huawei.com (7.185.36.136) X-Patchwork-Delegate: kuba@kernel.org The commit 8ae1aff0b331 ("tuntap: split out XDP logic") includes dropped counter for XDP_DROP, XDP_ABORTED, and invalid XDP actions. Unfortunately, that commit missed the dropped counter when error occurs during XDP_TX and XDP_REDIRECT actions. This patch fixes this issue. Fixes: 8ae1aff0b331 ("tuntap: split out XDP logic") Signed-off-by: Yunjian Wang Reviewed-by: Willem de Bruijn Acked-by: Jason Wang --- drivers/net/tun.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index afa5497f7c35..237fef557ba5 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1630,13 +1630,17 @@ static int tun_xdp_act(struct tun_struct *tun, struct bpf_prog *xdp_prog, switch (act) { case XDP_REDIRECT: err = xdp_do_redirect(tun->dev, xdp, xdp_prog); - if (err) + if (err) { + dev_core_stats_rx_dropped_inc(tun->dev); return err; + } break; case XDP_TX: err = tun_xdp_tx(tun->dev, xdp); - if (err < 0) + if (err < 0) { + dev_core_stats_rx_dropped_inc(tun->dev); return err; + } break; case XDP_PASS: break; From patchwork Fri Jan 19 10:22:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyunjian X-Patchwork-Id: 13523556 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 988123CF40; Fri, 19 Jan 2024 10:23:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705659786; cv=none; b=o2ytE4xZgCWMed1d5B/KUKEZL1QfSDD7BHx9RJO4fbLTNe8Jadyn9dgvRUYwE6FSHg4AJFNOjsPeCIuji7d/AiUJi3xRA+ibPq5aXx376/Xs42VpY3uPj4yWXz0M/s8T8HTcaATWiHlHylsy/Nso6UTFzpzwEryPnnZqjXdRnBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705659786; c=relaxed/simple; bh=H+L7PUjG/moR9/SE/ZV68ckNWu2AYzqZAphFxrn/bCw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=UrqF/5xUbsOP1+fKAqAkdPdwPEP5LI0NdbmUAMY9Zw9b3go5bWP9rWxoW1rm07reno90ZlVAmvrYJpcKx4R125pXi11aLBNo5yvwi5OE6rXBO0YNRCnfkYeVFAlGi5cAvmQdrZ6o/qp7ADcGunlBA5ygALIaCf3EEJ7XtUqPucI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4TGbJP4ZpSzXgTX; Fri, 19 Jan 2024 18:21:57 +0800 (CST) Received: from dggpemm500008.china.huawei.com (unknown [7.185.36.136]) by mail.maildlp.com (Postfix) with ESMTPS id 695F4140153; Fri, 19 Jan 2024 18:23:02 +0800 (CST) Received: from localhost (10.174.242.157) by dggpemm500008.china.huawei.com (7.185.36.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 19 Jan 2024 18:23:02 +0800 From: Yunjian Wang To: , , , CC: , , , Yunjian Wang Subject: [PATCH net 2/2] tun: add missing rx stats accounting in tun_xdp_act Date: Fri, 19 Jan 2024 18:22:56 +0800 Message-ID: <1705659776-21108-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500008.china.huawei.com (7.185.36.136) X-Patchwork-Delegate: kuba@kernel.org The TUN can be used as vhost-net backend, and it is necessary to count the packets transmitted from TUN to vhost-net/virtio-net. However, there are some places in the receive path that were not taken into account when using XDP. It would be beneficial to also include new accounting for successfully received bytes using dev_sw_netstats_rx_add. Fixes: 761876c857cb ("tap: XDP support") Signed-off-by: Yunjian Wang Reviewed-by: Willem de Bruijn Acked-by: Jason Wang --- drivers/net/tun.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 237fef557ba5..4a4f8c8e79fa 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1634,6 +1634,7 @@ static int tun_xdp_act(struct tun_struct *tun, struct bpf_prog *xdp_prog, dev_core_stats_rx_dropped_inc(tun->dev); return err; } + dev_sw_netstats_rx_add(tun->dev, xdp->data_end - xdp->data); break; case XDP_TX: err = tun_xdp_tx(tun->dev, xdp); @@ -1641,6 +1642,7 @@ static int tun_xdp_act(struct tun_struct *tun, struct bpf_prog *xdp_prog, dev_core_stats_rx_dropped_inc(tun->dev); return err; } + dev_sw_netstats_rx_add(tun->dev, xdp->data_end - xdp->data); break; case XDP_PASS: break;