From patchwork Mon Oct 3 04:02:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng He X-Patchwork-Id: 1685538 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=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=kJilqyj1; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mh0ns311tz1ypH for ; Mon, 3 Oct 2022 23:41:35 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 39BA582EF1; Mon, 3 Oct 2022 12:41:33 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 39BA582EF1 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=kJilqyj1 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PTZu7PN1OBZj; Mon, 3 Oct 2022 12:41:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 6BE0682D75; Mon, 3 Oct 2022 12:41:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 6BE0682D75 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 339ADC0032; Mon, 3 Oct 2022 12:41:31 +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 7ED63C002D for ; Mon, 3 Oct 2022 12:41:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 6747D60BEA for ; Mon, 3 Oct 2022 12:41:30 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 6747D60BEA Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=kJilqyj1 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HeDv_5SyTYQ7 for ; Mon, 3 Oct 2022 12:41:29 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org CFD3D60709 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by smtp3.osuosl.org (Postfix) with ESMTPS id CFD3D60709 for ; Mon, 3 Oct 2022 12:41:29 +0000 (UTC) Received: by mail-pf1-x42d.google.com with SMTP id v186so10092531pfv.11 for ; Mon, 03 Oct 2022 05:41:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=dtCIrLdYkH6bEZiPYI0tMY2HzBNostw1wDFhJP/lkzo=; b=kJilqyj1x5bzwBlzxL7DIkVchZFqJBv62QnmU9jtVED6GbAsdCnL9ljl5MJBYoQSdC QJPt14chSgBnmb62YYTSgvcJ5dBnJ77StDsACjk+HDLd7vNA7mHO8+GYw8CjAVQaZHUd rz/8iOEmUKk49wWdTi7i5kgaYRoPOydaviuozorSE61JzibFXBdb/trq9lnEU73nNTlf WyAAExmt43VVC/dYqFv5THmK1c6wW044b2QXe4HKAhQ59tLK6kk76MYzE22i0RdpuDI4 y0n3OJibugnbY2i759PHSFtGWhzc4fh2uLO2rBHkDNmaCdFiShjBJaLowybNcs59cAYz Ac1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=dtCIrLdYkH6bEZiPYI0tMY2HzBNostw1wDFhJP/lkzo=; b=63FGCN1KZxXuKxVkUKF+mC13xh/aKPEijlW2/I8znVwcDDweNqPW26L7TxOJa4Gy4e ywPxvF+q8kghxDuYIuo83VY6vfDYolOBjnGGRY9QBHgf7US7ymjed8UsnAfBjGubSbf9 52yD8kMVTXI7mUBcRaQzAa1SviNVignhOpF19frZ2fulptIth9BWcy1vWKhIDB/E0oP8 nMkXS3aD2kyHncWC3+JtheEPC3l6cIj2OA+vpzedz0VyQZwBdkUhpjASENO7l3w/GM9r LM2VZz5/6MfjHixMzVy5K8h9yykhF12x9i4NAf4qEQ6mEBTEyq5s5ExOJY8vNvwWdQA/ bNmA== X-Gm-Message-State: ACrzQf1+rz/tp5lP66Uh7ETx5p2FVtiShn4n4f5YjhQhZfLqI9a4pFEM oiqEQJvLFOHBTQQArxfDejekHvlPUFCNVQ== X-Google-Smtp-Source: AMsMyM7Il60E+Uf+8Ova26oOu71F5ZajZM5xyhvb8+/1UZ7F3UI6W3TkIsdHQqJe7liJMMZ+0gMEdA== X-Received: by 2002:a63:8b49:0:b0:44b:ba5:ebd4 with SMTP id j70-20020a638b49000000b0044b0ba5ebd4mr7564757pge.385.1664800889095; Mon, 03 Oct 2022 05:41:29 -0700 (PDT) Received: from localhost ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id c11-20020aa7952b000000b0056183958089sm1492824pfp.167.2022.10.03.05.41.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 05:41:28 -0700 (PDT) From: Peng He X-Google-Original-From: Peng He To: dev@openvswitch.org Date: Mon, 3 Oct 2022 04:02:17 +0000 Message-Id: <20221003040220.1153222-1-hepeng.0320@bytedance.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [ovs-dev] [PATCH] dpif-netdev: fix the race comments 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" The following comments (brought in at 0de8783a9): /* XXX: There's a race window where a flow covering this packet * could have already been installed since we last did the flow * lookup before upcall. This could be solved by moving the * mutex lock outside the loop, but that's an awful long time * to be locking revalidators out of making flow modifications. */ is out-dated. Back at commit 0de8783a9, the classifier is per-datapath, multiple PMDs share a same classifier. Since now we have changed into per-PMD classifier, the lookup code only prevents from the race introduced by manually calling dpctl/add-flow, there are no other threads which would insert datapath flows. Signed-off-by: Peng He --- lib/dpif-netdev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index b316e59ef..680321600 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -8297,12 +8297,10 @@ handle_packet_upcall(struct dp_netdev_pmd_thread *pmd, if (OVS_LIKELY(error != ENOSPC)) { struct dp_netdev_flow *netdev_flow; - /* XXX: There's a race window where a flow covering this packet - * could have already been installed since we last did the flow - * lookup before upcall. This could be solved by moving the - * mutex lock outside the loop, but that's an awful long time - * to be locking revalidators out of making flow modifications. */ ovs_mutex_lock(&pmd->flow_mutex); + /* We need to lookup the flow in case someone uses dpctl/add-flow + * to add a datapath flow and this flow also cover this packet. + */ netdev_flow = dp_netdev_pmd_lookup_flow(pmd, key, NULL); if (OVS_UNLIKELY(netdev_flow)) { struct dp_netdev_actions *old_act = From patchwork Mon Oct 3 04:02:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng He X-Patchwork-Id: 1685540 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::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=IW2RfGLc; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mh0p03lGnz1ypH for ; Mon, 3 Oct 2022 23:41:44 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 74BFE60C00; Mon, 3 Oct 2022 12:41:42 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 74BFE60C00 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=IW2RfGLc X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2sINdClzKy8u; Mon, 3 Oct 2022 12:41:41 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 9F56C60C03; Mon, 3 Oct 2022 12:41:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 9F56C60C03 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 72572C0032; Mon, 3 Oct 2022 12:41:40 +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 0F181C002D for ; Mon, 3 Oct 2022 12:41:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id CA2DC60BF3 for ; Mon, 3 Oct 2022 12:41:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org CA2DC60BF3 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1GijR0qh1ylO for ; Mon, 3 Oct 2022 12:41:37 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 1F00B60C09 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by smtp3.osuosl.org (Postfix) with ESMTPS id 1F00B60C09 for ; Mon, 3 Oct 2022 12:41:37 +0000 (UTC) Received: by mail-pl1-x62e.google.com with SMTP id n7so9581767plp.1 for ; Mon, 03 Oct 2022 05:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=/qOetp/Cec70BesFd2xOVPkKkvoS3NQEvHBXHs3oMN8=; b=IW2RfGLcmlakbydYFn2HkT11KHUL2Kl0NGIIMYLV+fvVy3exQT6CB12rgAejRHCKjT B9PXkanGcHGa7/tZh79N7DCI2InkLCNR8Uo7apeJDEPsLMND6oadmZjlP7nSK7weUkVr yeOWHD139CTwN40X9Ml5mFDzpHc6ACudbB3r+LCrm+61qcLpJhX/5/iQqlHAtS6NemtP oQ0/QpMNUHWhfRQRL2PWFbQlLmwHBbfGUYF+0stjQQiAaIGv3h5AklYkQFzbc9NcjFQv LnhKCSXx8bwe7tvfjC2727YFea/uEWDt2J2Ywk7zXa0ErLOPJbsynfmeHrp3ND4hGfvW kRdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=/qOetp/Cec70BesFd2xOVPkKkvoS3NQEvHBXHs3oMN8=; b=OUntVFL0wZt24Rgbivv9RkFXpBpv54Ng7AQR9RJ4EB6SKKAm2tRznw8kXaiLupLlJ6 aWN1DVhAYzKVadfGNC0hylaZ/4mj5WQgDe8XVvjAVZesO7T48pDm4Gr5ihvI8yPxUtJQ I1QXm9ymzLO40woiLi1qBQNAgHaVOKujKuihJRz9LJBmAhxeEz1Y8/Hb6v4PWpZuSp10 hOkKW4Qz/CLjMb/7JvV2roXEaehoMSddqAwcoKJXjBfWGEZRNX5VtrxW6BdNqNKww6B5 SY6csOxUC3BDmi2juyqg8ypv7bRsRInsiQlo1v4Hr1b2CTvdohpFq9F/mbMsqUB1ymGl tEaw== X-Gm-Message-State: ACrzQf1P/oRhgUkJn5gokfXY89i7EkcTuTH3nJIxHtRo60KMI71UWUpv 4wzF+gJiixlK6Ra1A4/+rOuOJhl3eTEmzg== X-Google-Smtp-Source: AMsMyM72owRZ7NDQvHyyZE5G5PhAi7rD3f1m+TJeD3v20T5wEYJQM0EY0C9ide4rH/BHDyUn/fpGGA== X-Received: by 2002:a17:90b:1e07:b0:202:bb50:1963 with SMTP id pg7-20020a17090b1e0700b00202bb501963mr12045518pjb.82.1664800896374; Mon, 03 Oct 2022 05:41:36 -0700 (PDT) Received: from localhost ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id r27-20020aa79edb000000b00561ac9b1376sm382935pfq.133.2022.10.03.05.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 05:41:35 -0700 (PDT) From: Peng He X-Google-Original-From: Peng He To: dev@openvswitch.org Date: Mon, 3 Oct 2022 04:02:19 +0000 Message-Id: <20221003040220.1153222-3-hepeng.0320@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221003040220.1153222-1-hepeng.0320@bytedance.com> References: <20221003040220.1153222-1-hepeng.0320@bytedance.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v4 2/3] ofproto-dpif-upcall: new ukey needs to take the old ukey's dump seq 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" The userspace datapath mananges all the magaflows by a cmap. The cmap data structrue will grow/shrink during the datapath processing and it will re-position megaflows. This might result in two revalidator threads might process a same megaflow during one dump stage. Consider a situation that, revalidator 1 processes a megaflow A, and decides to delete it from the datapath, at the mean time, this megaflow A is also queued in the process batch of revalidator 2. Normally it's ok for revalidators to process the same megaflow multiple times, as the dump_seq shows it's already dumped and the stats will not be contributed twice. Assume that right after A is deleted, a PMD thread generates again a new megaflow B which has the same match and action of A. The ukey of megaflow B will replace the one of megaflow A. Now the ukey B is new to the revalidator system and its dump seq is 0. Now since the dump seq of ukey B is 0, when processing megaflow A, the revalidator 2 will not identify this megaflow A has already been dumped by revalidator 1 and will contribute the old megaflow A's stats again, this results in an inconsistent stats between ukeys and megaflows. To fix this, the newly generated the ukey B should take the dump_seq of the replaced ukey A to avoid a same megaflow being revalidated twice in one dump stage. We observe in the production environment, the OpenFlow rules' stats sometimes are amplified compared to the actual value. Signed-off-by: Peng He Acked-by: Eelco Chaudron --- ofproto/ofproto-dpif-upcall.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index dd1abfdee..e1af4d633 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -1877,6 +1877,7 @@ try_ukey_replace(struct umap *umap, struct udpif_key *old_ukey, ovs_mutex_lock(&new_ukey->mutex); cmap_replace(&umap->cmap, &old_ukey->cmap_node, &new_ukey->cmap_node, new_ukey->hash); + new_ukey->dump_seq = old_ukey->dump_seq; ovsrcu_postpone(ukey_delete__, old_ukey); transition_ukey(old_ukey, UKEY_DELETED); transition_ukey(new_ukey, UKEY_VISIBLE); From patchwork Mon Oct 3 04:02:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng He X-Patchwork-Id: 1685541 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=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ZUSfSuTy; dkim-atps=neutral Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mh0p71Xzzz1ypH for ; Mon, 3 Oct 2022 23:41:51 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 4F18C415DC; Mon, 3 Oct 2022 12:41:49 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 4F18C415DC Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ZUSfSuTy X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cXvLLICnK5qx; Mon, 3 Oct 2022 12:41:48 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id C32FA415E9; Mon, 3 Oct 2022 12:41:46 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org C32FA415E9 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2DA5FC0032; Mon, 3 Oct 2022 12:41:46 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 28289C0035 for ; Mon, 3 Oct 2022 12:41:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 38849415CB for ; Mon, 3 Oct 2022 12:41:41 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 38849415CB X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3I4jFDuYUAJU for ; Mon, 3 Oct 2022 12:41:40 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 13747415AE Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by smtp4.osuosl.org (Postfix) with ESMTPS id 13747415AE for ; Mon, 3 Oct 2022 12:41:39 +0000 (UTC) Received: by mail-pf1-x42a.google.com with SMTP id a26so1091348pfg.7 for ; Mon, 03 Oct 2022 05:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=9qzSWnywehD6turLpoex3ifk+j4rOro8W6h3KpAFec4=; b=ZUSfSuTyTGYb+d7HlxcxMpjWKNytXouzlZeWrpsNtF/x+oG+O9FZB3t5Bh65oduOrw 6hbmWbR8dSMw8dQ9T2PWb9QyrqAoG7KLdpDZW0b3tV3fRKLoYo3LUcEcI7No5u80DQDE otffRBX/5ZsMqtf2UkwcBFkjMkvX4GGg0oOqjHZgeEdY5BTxaH4NXQve1V9hRAz9W4oA m/aqd5+E0KZkd3OZgZ5xH4unF/fCtlgKgLrXyrjhJVK8DP1qBCuRFc0kOuGXyeERCPrS G0G6blXWydAbq1LATIPV0a4VPW6lMMBr7IHSoknbAQ4J+FWlcHEPChjSFewQH78jdIOa ugSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=9qzSWnywehD6turLpoex3ifk+j4rOro8W6h3KpAFec4=; b=7xfi447aKRdL2crmf8b/LdVAy3DoZONIyTrmNC68RLGpREGQn8fMFLcX6hfkSkTpT2 TRFUEvjwwGTrZSdkiXoxTI5WGXAxuLiSSqVF9XnDeJLDE5/QtmUNbdXrXpti7RyHRySN u/eIDcgCJ7JWj5KhjGThnvZHPjDY9VWbBTcm/WZiFjuBtdvvNtcG7vb8Nj3eFvCIq9yt 472B6IuGyGLCyBP7DzULsAR+9Lh++8CGnZOAz9jk4w1Q0gn6yms0uEB08xwN6QaCItem Wbkzgim3H90CH4M8ne4U6jKpN0lP2r0Ym1fN7jYg+5+/Qor5nC5X2SstXg4f7sdkEVXu 66SA== X-Gm-Message-State: ACrzQf0hsBV1uR5lwvFO1LmeYD4f0dDBSd0p+d7wFPw7W9hKUGe5KAnV bJePnwxMQ8/rQWK+21KNdw4nPcWtJj9pMA== X-Google-Smtp-Source: AMsMyM7ihK4gOByfF3YySz14sHuaR6L1e0GeDAOa9/YUmxnppJriBA6uZ78qrWOz1yjlqJelB5+mbw== X-Received: by 2002:a05:6a00:1892:b0:540:acee:29e8 with SMTP id x18-20020a056a00189200b00540acee29e8mr22543024pfh.1.1664800899264; Mon, 03 Oct 2022 05:41:39 -0700 (PDT) Received: from localhost ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id p3-20020a170902e74300b00176b0dec886sm7201650plf.58.2022.10.03.05.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 05:41:39 -0700 (PDT) From: Peng He X-Google-Original-From: Peng He To: dev@openvswitch.org Date: Mon, 3 Oct 2022 04:02:20 +0000 Message-Id: <20221003040220.1153222-4-hepeng.0320@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221003040220.1153222-1-hepeng.0320@bytedance.com> References: <20221003040220.1153222-1-hepeng.0320@bytedance.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v4 3/3] dpif-netdev: fix inconsistent processing between ukey and megaflow 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" When PMDs perform upcalls, the newly generated ukey will replace the old, however, the newly generated mageflow will be discard to reuse the old one without checking if the actions of new and old are equal. This code prevents in case someone runs dpctl/add-flow to add a dp flow with inconsistent actions with the actions of ukey, and causes more confusion. Signed-off-by: Peng He --- lib/dpif-netdev.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index a45b46014..b316e59ef 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -8304,7 +8304,22 @@ handle_packet_upcall(struct dp_netdev_pmd_thread *pmd, * to be locking revalidators out of making flow modifications. */ ovs_mutex_lock(&pmd->flow_mutex); netdev_flow = dp_netdev_pmd_lookup_flow(pmd, key, NULL); - if (OVS_LIKELY(!netdev_flow)) { + if (OVS_UNLIKELY(netdev_flow)) { + struct dp_netdev_actions *old_act = + dp_netdev_flow_get_actions(netdev_flow); + + if ((add_actions->size != old_act->size) || + memcmp(old_act->actions, add_actions->data, + add_actions->size)) { + + struct dp_netdev_actions *new_act = + dp_netdev_actions_create(add_actions->data, + add_actions->size); + + ovsrcu_set(&netdev_flow->actions, new_act); + ovsrcu_postpone(dp_netdev_actions_free, old_act); + } + } else { netdev_flow = dp_netdev_flow_add(pmd, &match, &ufid, add_actions->data, add_actions->size, orig_in_port);