From patchwork Sat Jul 4 04:43:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Lui0uum5jw==?= X-Patchwork-Id: 1322712 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=PwYfV0FM; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49zK3P6TgPz9sDX for ; Sat, 4 Jul 2020 14:43:43 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 60E6E8961A; Sat, 4 Jul 2020 04:43:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ys-avZWctTfJ; Sat, 4 Jul 2020 04:43:40 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 3786188C50; Sat, 4 Jul 2020 04:43:40 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 17BA5C0888; Sat, 4 Jul 2020 04:43:40 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id ACF99C0733 for ; Sat, 4 Jul 2020 04:43:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 9B21788C50 for ; Sat, 4 Jul 2020 04:43:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rYD9JWIr7eaF for ; Sat, 4 Jul 2020 04:43:37 +0000 (UTC) X-Greylist: delayed 00:45:49 by SQLgrey-1.7.6 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by hemlock.osuosl.org (Postfix) with ESMTPS id A337588C5B for ; Sat, 4 Jul 2020 04:43:37 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id s14so13299185plq.6 for ; Fri, 03 Jul 2020 21:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cPfD4U+EhRxEqLhMGCXIlYjVcPtPa32j9QD0mCQ8glk=; b=PwYfV0FMqr1VAnvJ83BRKcWJkRnniYZ0DDdClncUwTrqsE+FuZxdmRm7cZmaseYowW d/eId/CxvlElK1gmqi5UxR5KAq6Pk6cnCS01uyYOMCK/HW50ItwBfyucX6/n4fTHC9W+ GUa6pHR/NRNM6N3ublAJaeJ17y4yqydec0C04VCsWD2UJxLQ8aNHa890upuAoEsvBN9n llkQ6y8rvtGdxHGw41omuclhPyEQXro8KxL+Z53oN5BOH/iNcGIKxjkk0LDdQPBRgLZO LoZnOicShogctiRfwS9IPxR1siJOZDR33WrRBMIqqURD8uTaS6ckpWsU2/IV2qbN3sgR 4uQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cPfD4U+EhRxEqLhMGCXIlYjVcPtPa32j9QD0mCQ8glk=; b=srTU9awFCsFVEQnGecL8EEG1VF7JiXtoPKMOPprcKvnTMJkoSIz1gv6nkzk8/c4wpg 3LACs2ugkzX//50T01+W80zG3CmJBiKeEBeThX4w/SrkfzE+eRtoNWT+g6EhbCkDuj0J QCL9ZX1PoUhCtrL+adoOyZ+q2p7Zn7wrmn7F8cM70fD0rxVxtjIoT009TRfAe4CkFXYY iNmf+tXSXcfxBbPUaM5YfBd+m4dVU44z7a7T6e1JmtdT2H2OdbYNpxz2f5qamM+Xdt3H 7GQqZydQqLf1ujwks5GPFki1frizDi4C+zxbAlJ1T4GsCKrV8ib/xaKWDs3hgV5hN/k9 /f8Q== X-Gm-Message-State: AOAM5324D0GJt8TEH7aeT3flXgNrR4nYUgrAJH1KdTaINUBXCEA5ALVV HEnMwZel1UStWbdSSac/1yKaP0oVb8lwPA== X-Google-Smtp-Source: ABdhPJynFlfNgezOSYltFGDwXuWLrI4EvUQPn/B1duGx9M2BkkQd6fEwwtEUQg13DSmvNWEzaPE47g== X-Received: by 2002:a17:90b:11ca:: with SMTP id gv10mr43660938pjb.19.1593837816851; Fri, 03 Jul 2020 21:43:36 -0700 (PDT) Received: from localhost ([103.136.220.67]) by smtp.gmail.com with ESMTPSA id ci23sm2948348pjb.29.2020.07.03.21.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 21:43:36 -0700 (PDT) From: "hepeng.0320" To: dev@openvswitch.org Date: Sat, 4 Jul 2020 12:43:33 +0800 Message-Id: <20200704044333.74479-1-hepeng.0320@bytedance.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [ovs-dev] conntrack-tp: fix lock order in conn_update_expiration 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" *conn_update_expiration* violates the lock order of conn->lock and ct->lock. In the comments of conntrack, the conn->lock should be held after ct->lock when ct->lock needs to be taken. Signed-off-by: hepeng.0320 --- lib/conntrack-tp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/conntrack-tp.c b/lib/conntrack-tp.c index 3a7604c0d..a586d3a8d 100644 --- a/lib/conntrack-tp.c +++ b/lib/conntrack-tp.c @@ -260,15 +260,20 @@ conn_update_expiration(struct conntrack *ct, struct conn *conn, struct timeout_policy *tp; uint32_t val; + ovs_mutex_unlock(&conn->lock); + ovs_mutex_lock(&ct->ct_lock); + ovs_mutex_lock(&conn->lock); tp = timeout_policy_lookup(ct, conn->tp_id); if (tp) { val = tp->policy.attrs[tm_to_ct_dpif_tp(tm)]; } else { val = ct_dpif_netdev_tp_def[tm_to_ct_dpif_tp(tm)]; } + ovs_mutex_unlock(&conn->lock); ovs_mutex_unlock(&ct->ct_lock); + ovs_mutex_lock(&conn->lock); VLOG_DBG_RL(&rl, "Update timeout %s zone=%u with policy id=%d " "val=%u sec.", ct_timeout_str[tm], conn->key.zone, conn->tp_id, val);