From patchwork Tue Apr 30 09:36:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "wushaohua@chinatelecom.cn" X-Patchwork-Id: 1929412 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::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (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 4VTFkb3Dqjz23jG for ; Tue, 30 Apr 2024 19:48:23 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id CD89A414B6; Tue, 30 Apr 2024 09:48:16 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id wL4rzOpy-Nrs; Tue, 30 Apr 2024 09:48:15 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 7E63A41492 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 7E63A41492; Tue, 30 Apr 2024 09:48:15 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 34E68C007C; Tue, 30 Apr 2024 09:48:15 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id AD42EC0037 for ; Tue, 30 Apr 2024 09:48:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 8EB346081E for ; Tue, 30 Apr 2024 09:48:13 +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 a5bPnkL2xkw3 for ; Tue, 30 Apr 2024 09:48:12 +0000 (UTC) X-Greylist: delayed 715 seconds by postgrey-1.37 at util1.osuosl.org; Tue, 30 Apr 2024 09:48:10 UTC DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 2792160A4A 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 2792160A4A Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=182.42.147.92; helo=chinatelecom.cn; envelope-from=wushaohua@chinatelecom.cn; receiver= Received: from chinatelecom.cn (smtpnm6-10.21cn.com [182.42.147.92]) by smtp3.osuosl.org (Postfix) with ESMTP id 2792160A4A for ; Tue, 30 Apr 2024 09:48:10 +0000 (UTC) HMM_SOURCE_IP: 192.168.138.117:65043.266958192 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 45342B01346A; Tue, 30 Apr 2024 17:36:09 +0800 (CST) X-189-SAVE-TO-SEND: +wushaohua@chinatelecom.cn Received: from ([101.43.140.16]) by gateway-ssl-dep-77bc75f6c8-5v5w7 with ESMTP id e04978d599a4431eb1344eb6c537bc21 for dev@openvswitch.org; Tue, 30 Apr 2024 17:36:11 CST X-Transaction-ID: e04978d599a4431eb1344eb6c537bc21 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: Tue, 30 Apr 2024 17:36:09 +0800 Message-Id: <20240430093609.1739186-1-wushaohua@chinatelecom.cn> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240427090024.1678879-1-wushaohua@chinatelecom.cn> References: <20240427090024.1678879-1-wushaohua@chinatelecom.cn> MIME-Version: 1.0 Cc: wushaohua@chinatelecom.cn Subject: [ovs-dev] [PATCH v2] ofproto-dpif-rid: Fix duplicate entries. 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 In scenarios with multiple PMDs, there may be simultaneous requests for recirc_id from multiple PMD threads.In recirc_alloc_id_ctx, we first check if there is a duplicate entry in the metadata_map for the same frozen_state field. If successful, we directly retrieve the recirc_id. If unsuccessful, we create a new recirc_node and insert it into id_map and metadata_map. There is no locking mechanism to prevent the possibility of two threads with the same state simultaneously inserting, meaning their IDs are different, but their frozen_states are the same. trace log: static struct recirc_id_node * recirc_alloc_id__(const struct frozen_state *state, uint32_t hash) { ovs_assert(state->action_set_len <= state->ofpacts_len); struct recirc_id_node *node = xzalloc(sizeof *node); node->hash = hash; ovs_refcount_init(&node->refcount); node->is_hotupgrade = false; frozen_state_clone(CONST_CAST(struct frozen_state *, &node->state), state); struct recirc_id_node *hash_recirc_node = recirc_find_equal(&node->state, state); if (hash_recirc_node) { VLOG_INFO("wsh:hash equal:hash_recirc_node %p id:%u, hash_recirc_node hash:%u,node %p hash:%u\n", hash_recirc_nodeļ¼Œ hash_recirc_node->id, hash_recirc_node->hash, node, node->hash); } ovs_mutex_lock(&mutex); ... } Log recording: 2024-04-27T12:28:47.973Z|00006|ofproto_dpif_rid(pmd-c08/id:13)|INFO|wsh:hash equal: hash_recirc_node 0x7fb29c0276a0 id:27,hash_recirc_node hash:3224122528,node 0x7fb2900194d0 hash:3224122528 2024-04-27T12:28:47.973Z|00009|ofproto_dpif_rid(pmd-c02/id:15)|INFO|wsh:hash equal: hash_recirc_node 0x7fb29c0276a0 id:27,hash_recirc_node hash:3224122528,node 0x7fb288025270 hash:3224122528 2024-04-27T12:28:47.973Z|00006|ofproto_dpif_rid(pmd-c03/id:14)|INFO|wsh:hash equal: hash_recirc_node 0x7fb29c0276a0 id:27,hash_recirc_node hash:3224122528,node 0x7fb29401d4e0 hash:3224122528 2024-04-27T12:28:47.973Z|00004|ofproto_dpif_rid(pmd-c09/id:12)|INFO|node->id:28,hash:4019648042,table_id:75 2024-04-27T12:28:47.973Z|00007|ofproto_dpif_rid(pmd-c08/id:13)|INFO|wsh:hash equal: hash_recirc_node 0x7fb29c028d40 id:28,hash_recirc_node hash:4019648042,node 0x7fb29001ac30 hash:4019648042 2024-04-27T12:28:48.065Z|00005|ofproto_dpif_rid(pmd-c09/id:12)|INFO|node->id:29,hash:3800776147,table_id:30 2024-04-27T12:28:48.101Z|00007|ofproto_dpif_rid(pmd-c03/id:14)|INFO|node->id:30,hash:1580334976,table_id:75 Signed-off-by: Shaohua Wu --- v1->v2:modify log recording , add trace code. --- ofproto/ofproto-dpif-rid.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ofproto/ofproto-dpif-rid.c b/ofproto/ofproto-dpif-rid.c index f01468025..651db6c53 100644 --- a/ofproto/ofproto-dpif-rid.c +++ b/ofproto/ofproto-dpif-rid.c @@ -234,6 +234,7 @@ recirc_alloc_id__(const struct frozen_state *state, uint32_t hash) { ovs_assert(state->action_set_len <= state->ofpacts_len); + struct recirc_id_node *hash_recirc_node = NULL; struct recirc_id_node *node = xzalloc(sizeof *node); node->hash = hash; @@ -241,6 +242,12 @@ recirc_alloc_id__(const struct frozen_state *state, uint32_t hash) frozen_state_clone(CONST_CAST(struct frozen_state *, &node->state), state); ovs_mutex_lock(&mutex); + hash_recirc_node = recirc_ref_equal(&node->state, node->hash); + if (hash_recirc_node) { + ovs_mutex_unlock(&mutex); + recirc_id_node_free(node); + return hash_recirc_node; + } for (;;) { /* Claim the next ID. The ID space should be sparse enough for the allocation to succeed at the first try. We do skip the first