From patchwork Thu May 23 07:50:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "wushaohua@chinatelecom.cn" X-Patchwork-Id: 1938211 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlL2f2Yzkz1ynR for ; Thu, 23 May 2024 17:51:06 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id D5D2D4073C; Thu, 23 May 2024 07:51:01 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id OrmGb2fcuHgy; Thu, 23 May 2024 07:51:00 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 6158D40723 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 6158D40723; Thu, 23 May 2024 07:51:00 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 30DD1C0077; Thu, 23 May 2024 07:51:00 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9A74DC0037 for ; Thu, 23 May 2024 07:50:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 8996260784 for ; Thu, 23 May 2024 07:50:58 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id YU4YjqPQuElc for ; Thu, 23 May 2024 07:50:58 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=182.42.152.55; helo=chinatelecom.cn; envelope-from=wushaohua@chinatelecom.cn; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org A296660774 Authentication-Results: smtp3.osuosl.org; dmarc=none (p=none dis=none) header.from=chinatelecom.cn DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org A296660774 Received: from chinatelecom.cn (smtpnm6-09.21cn.com [182.42.152.55]) by smtp3.osuosl.org (Postfix) with ESMTP id A296660774 for ; Thu, 23 May 2024 07:50:55 +0000 (UTC) HMM_SOURCE_IP: 192.168.138.117:24797.970045166 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-101.43.140.16 (unknown [192.168.138.117]) by chinatelecom.cn (HERMES) with SMTP id 08C9011000169; Thu, 23 May 2024 15:50:50 +0800 (CST) X-189-SAVE-TO-SEND: +wushaohua@chinatelecom.cn Received: from ([101.43.140.16]) by gateway-ssl-dep-84c6c6b769-jsnsj with ESMTP id a1c01d8ab6e949d8b8912424fcaf59f6 for dev@openvswitch.org; Thu, 23 May 2024 15:50:52 CST X-Transaction-ID: a1c01d8ab6e949d8b8912424fcaf59f6 X-Real-From: wushaohua@chinatelecom.cn X-Receive-IP: 101.43.140.16 X-MEDUSA-Status: 0 From: wushaohua@chinatelecom.cn To: dev@openvswitch.org Date: Thu, 23 May 2024 15:50:49 +0800 Message-Id: <20240523075049.1936263-1-wushaohua@chinatelecom.cn> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Cc: wushaohua@chinatelecom.cn Subject: [ovs-dev] [PATCH] dpif-netdev: Resolved flow table reference issue. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Shaohua Wu description: The statistics for the cached DP flow table are updated in packet_batch_per_flow_execute. There might be a timing gap where the dp flow in the batch reaches its aging time and is prematurely aged. If actions on the dp flows are executed at this time,and the memory for the DP flow has been released, it can lead to a crash. 0 raise () from /lib64/libc.so.6 1 abort () from /lib64/libc.so.6 2 odp_execute_actions at lib/odp-execute.c:1166 3 dp_netdev_execute_actions at lib/dpif-netdev.c:11339 4 packet_batch_per_flow_execute at lib/dpif-netdev.c:8537 5 dp_netdev_input__ at lib/dpif-netdev.c:10722 6 dp_netdev_input at lib/dpif-netdev.c:10731 7 dp_netdev_process_rxq_port at lib/dpif-netdev.c:6332 8 dpif_netdev_run at lib/dpif-netdev.c:7343 9 dpif_run at lib/dpif.c:479 10 type_run at ofproto/ofproto-dpif.c:370 11 ofproto_type_run at ofproto/ofproto.c:1789 12 bridge_run__ at vswitchd/bridge.c:3245 13 bridge_run at vswitchd/bridge.c:3310 14 main at vswitchd/ovs-vswitchd.c:127 (gdb) f 4 (gdb) p flow->ref_cnt $4 = {count = 0} (gdb) p flow->dead $5 = true Signed-off-by: Shaohua Wu --- lib/dpif-netdev.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index c7f9e1490..8f96efde0 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -8255,12 +8255,13 @@ static inline void packet_batch_per_flow_init(struct packet_batch_per_flow *batch, struct dp_netdev_flow *flow) { - flow->batch = batch; - - batch->flow = flow; - dp_packet_batch_init(&batch->array); - batch->byte_count = 0; - batch->tcp_flags = 0; + if (dp_netdev_flow_ref(flow)) { + flow->batch = batch; + batch->flow = flow; + dp_packet_batch_init(&batch->array); + batch->byte_count = 0; + batch->tcp_flags = 0; + } } static inline void @@ -8322,9 +8323,11 @@ packet_enqueue_to_flow_map(struct dp_packet *packet, size_t index) { struct dp_packet_flow_map *map = &flow_map[index]; - map->flow = flow; - map->packet = packet; - map->tcp_flags = tcp_flags; + if (dp_netdev_flow_ref(flow)) { + map->flow = flow; + map->packet = packet; + map->tcp_flags = tcp_flags; + } } /* SMC lookup function for a batch of packets. @@ -8888,6 +8891,7 @@ dp_netdev_input__(struct dp_netdev_pmd_thread *pmd, } dp_netdev_queue_batches(map->packet, map->flow, map->tcp_flags, batches, &n_batches); + dp_netdev_flow_unref(map->flow); } /* All the flow batches need to be reset before any call to @@ -8905,6 +8909,7 @@ dp_netdev_input__(struct dp_netdev_pmd_thread *pmd, for (i = 0; i < n_batches; i++) { packet_batch_per_flow_execute(&batches[i], pmd); + dp_netdev_flow_unref(batches[i].flow); } }