From patchwork Sun Jul 5 13:07:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hepeng X-Patchwork-Id: 1323025 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.136; helo=silver.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=a05A8IdX; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B08BH2Jdgz9sRf for ; Sun, 5 Jul 2020 23:07:35 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 0B0FB2044A; Sun, 5 Jul 2020 13:07:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FRbthemDMxhg; Sun, 5 Jul 2020 13:07:30 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id D22FB203BB; Sun, 5 Jul 2020 13:07:30 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id AE6BFC0893; Sun, 5 Jul 2020 13:07:30 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id ED400C016F for ; Sun, 5 Jul 2020 13:07:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id DCC0687EBC for ; Sun, 5 Jul 2020 13:07:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0ry6kE5eXirO for ; Sun, 5 Jul 2020 13:07:27 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by whitealder.osuosl.org (Postfix) with ESMTPS id B428887CEC for ; Sun, 5 Jul 2020 13:07:27 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id s14so14298959plq.6 for ; Sun, 05 Jul 2020 06:07:27 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=YgkrFCrkpfBNNfa/ono1Xd+FJNoKcXwuD9gGGNAUzu4=; b=a05A8IdXbtrhWYgXSzmb7KhzTyCQbKA1m+2b1sU2XJOs1G0ilCg/eB5+NhtdWfe3Kk uJwmK8hCddYGTv8uloWakIkQL+3IS5EHTOPO2/hB4m/dPYi86lABvK/3S7jGhUy0qTjl xDe4JpjxsDGf0KLhmZ0EPxvHDwNCpx1a5MODPCGh0Dn7IrwRspktBwhMeP01zbdyUwAW wqe0wDf+CiRx3EuFLqASf8BwPZULJe6H5b0qqzC8z9v/1KlUrukDsc3qTTha2gK4+K3I 7nPdxqXdhcpzYgT6K8/UNtG/GQkV0JloY538ERptOGkxsy+K+TNrn0f2wSQ1EsWpUpMk Q+kw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=YgkrFCrkpfBNNfa/ono1Xd+FJNoKcXwuD9gGGNAUzu4=; b=fDw8XrIjDMNQPODGGN/Jh59/ibv+P1Xm/lyn7tOR5sP1grFhubW7J4ZSmnrs6riF/9 7G7+iQGKvDP+xXn+rv+rxzW0oqsFwctzi17xkA0+/u5+i9K6wmC7y8/X1XX7iz9Z5LAh 5g9xWPcA00hcuGU7ROdc4RmO9K3zyhwQONTaJ+3C1sMHzgCZqF99Z8I/ASKgXEpn42JN mLD5y6nNf40bDtpjxJvMobCJzVoJsCTwxRHrrL4WAMWSUqU2ZHrvY9P3WQDiXA72wtc0 OtbDMvZI5N3J5xVoV8QfquJWMX79kBe31TZmg2PhZYkLjFFtguTdyqieufSTiAbZZ9A1 29WA== X-Gm-Message-State: AOAM532ZQa0oyNet1RGA+6sN4AGLsWbWnoii+j0rMRGwpxJDd94q7FBQ 3+yXWFaxxR62n7ABV+Lazy3o3qBHMBw= X-Google-Smtp-Source: ABdhPJy+cMQnjQVeFCar+1mZBvrsw/zdOiAkqIPdT/9pUH0lRITINpKWc4K6caEXII/0IlaV6GvydA== X-Received: by 2002:a17:90a:bf09:: with SMTP id c9mr44599571pjs.221.1593954446817; Sun, 05 Jul 2020 06:07:26 -0700 (PDT) Received: from localhost ([103.136.220.67]) by smtp.gmail.com with ESMTPSA id o1sm15985014pjf.17.2020.07.05.06.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 06:07:26 -0700 (PDT) From: "hepeng.0320" To: dev@openvswitch.org Date: Sun, 5 Jul 2020 21:07:23 +0800 Message-Id: <20200705130723.78858-1-hepeng.0320@bytedance.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: 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: Peng He --- 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);