From patchwork Thu Oct 27 21:26:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bodong Wang X-Patchwork-Id: 1695685 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=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=U85+84Qy; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MyzKd6S6Hz20S2 for ; Fri, 28 Oct 2022 08:27:32 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ooAPK-0004dp-1I; Thu, 27 Oct 2022 21:27:22 +0000 Received: from mail-co1nam11on2040.outbound.protection.outlook.com ([40.107.220.40] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ooAPH-0004cr-B6 for kernel-team@lists.ubuntu.com; Thu, 27 Oct 2022 21:27:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fqqxf+SsUg0RvaZfi6zUx8Jly2cvkorU2jLS5Bh8vTyGA6+eFOVquoVJI0NHb73FQ3gj64hAuw9VxpPkm1TZ1w/78x3pZywAL4rQ6aGHPddXgOyk79zWFGXirWSNUd2+mMzFbtnsP2QsD2hR2dF7BLRZGPUezu8iejTK0lcqBviBaO3dIL0M9bFQs9kl8evx8EAgk2ctmkupq3aWIvzM6QISYjh76qKk4Isvnk5PHyxoQ8lOQrC2EXcrUjfVgk7wzUgRC8kBY4dUblsmMkhCMQW3tIlr0gmClUcCgzcfXMoIDc84udhnJpxuKGiMArt0t1A9Y8kE31DrVTXVX3f1Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Qtfx6mmv8t3gEiwfAkoyWX46YKm3XDhjoplqzT5d78o=; b=U2A3bay5nObbwKcECoFOXb6WbgoYIktGHCaLFC7Xamj3vwIT2LVtgnP2XQhpT8pR1saaWF75/zZpWwzHtVVZiwFPpb0RLVdNXO6qQ/zEJgACL+EnHtdh+EMB7Rto8Dhtvmh22Q9DuI+N/rqJFoG1Z/IcNNViOa9re7mIaw09aq07NGFTLQY1m3E19gLMtjXkvwtpQ/lLyRmy4/ltiwNCgIN39Pz+KsiGCwj7dQq0W8nlAnqzo6O5Zpdr1q3UwnRr1B/XN9nj3lYWIrNGX2/VXbnc1x33yg79D+X3ck13hmeqW2vOJf0Fr3c5xWSx9q/WNawv2fR19gXdIQmch3Qytw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Qtfx6mmv8t3gEiwfAkoyWX46YKm3XDhjoplqzT5d78o=; b=U85+84QyCydWV6u3XV9lpiHUVdVbywF75JcRsXfl2MhcBN1Gu6Ocgv5zFGD6yC1Wi9wK1UPOnZEn2ffi4WoYgTETwDao3w4Bj02OcgGalhnDFIJebPNkteZlA6vlZrye6yh2hN8Z4B0RVavR1TBpN/CN8fkAnmw/wfi5KuHhSglWsgQhGmKVqsbu9tRh9JPXrK8mzAsEThUpZr8eddpm6LsYDSZiWibOV2+XQrvytWE5Kuk4l7bHhGiKDe3UOH+teiCUlWalh0xs45gM3XgNXEAhAerBYK7wo5EqU1vyTgdw6LNsL4yGOFhKKr4V/8qmzKcnyWtI+m5tu3O1HM0XHw== Received: from MW4PR04CA0253.namprd04.prod.outlook.com (2603:10b6:303:88::18) by SN7PR12MB7452.namprd12.prod.outlook.com (2603:10b6:806:299::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.21; Thu, 27 Oct 2022 21:27:15 +0000 Received: from CO1NAM11FT090.eop-nam11.prod.protection.outlook.com (2603:10b6:303:88:cafe::a0) by MW4PR04CA0253.outlook.office365.com (2603:10b6:303:88::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.28 via Frontend Transport; Thu, 27 Oct 2022 21:27:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by CO1NAM11FT090.mail.protection.outlook.com (10.13.175.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.14 via Frontend Transport; Thu, 27 Oct 2022 21:27:15 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Thu, 27 Oct 2022 14:27:07 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Thu, 27 Oct 2022 14:27:07 -0700 Received: from mtl123.mtl.labs.mlnx (10.127.8.10) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29 via Frontend Transport; Thu, 27 Oct 2022 14:27:06 -0700 Received: from sw-mtx-hparm-006.mtx.labs.mlnx. (sw-mtx-hparm-006.mtx.labs.mlnx [10.9.151.93]) by mtl123.mtl.labs.mlnx (8.14.4/8.14.4) with ESMTP id 29RLR02C032221; Fri, 28 Oct 2022 00:27:04 +0300 From: Bodong Wang To: Subject: [SRU][F:linux-bluefield][PATCH 03/10] netfilter: conntrack: remove unneeded nf_ct_put Date: Thu, 27 Oct 2022 16:26:41 -0500 Message-ID: <1666906019-80328-4-git-send-email-bodong@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666906019-80328-1-git-send-email-bodong@nvidia.com> References: <1666906019-80328-1-git-send-email-bodong@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT090:EE_|SN7PR12MB7452:EE_ X-MS-Office365-Filtering-Correlation-Id: f3b14e71-1c68-4a6d-fe72-08dab86204ba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EgJg/Qw9njCqUTfW4auCGX+euJfJWBm+sZVe3K740t5Yj3lsW4S8B7ZjMquhdqMjtlXWaTRUFPuYvTjatTAKWy3/liZzqwBmtwk5ng/B4XJKxock/q0vveB27KUTlO7/Bp/4AMCzqdWvqtRANmFP+VHYGwRDMaDYBr/HYIl7NxkZHyT9xJLcNcAI1sf1mIx5EvrYUa7XrDWOPeqB/zb4+Qub6Qa6ffXHq9ekQXZShS+z6T8g9bH9CnXvyGrcSdIZWiGahBUrTVBGVlrDxo/u2FZQv9zAg9j6bJC4IaVzfQGBkjCseoR8iwp3sfpVFnIhaikmu+s+AR9rrKOwTfgWtUmFmP4xf8hvIi91o0BZUBfy5pKJnZBW9H6Z50RnzCIE7i4gfSF13YQ0372ZtyIO63EvrL+pNBcG3DmtwYpyCfcib7jiqMIR0Rvwaof2D8JNKqieBOdS6dYraTE7nuJy+G7aOCOz1WOdGBMNy0UnnO5WKCPlEWAf23HhMDliJN0qiL1GxM5oQpskI7I6IYuUFWmjxm7cBcGbMPUxFVY3Nn60UFku7uLW78ghyANQ2EWP58vpHE/PRRoBt0yfo8/rxXUxuCQlZB2qg94vMxPGbMNEXQsln6BNDNKjNUR/ZTWeNFjDTf49Dd2u+m6G5utJeL3O2wEWOWczkhSZ9H+WpPOOne1K0MSdPgiGOKgihbm2DWneuQBJzR7SlYsrsM4MLvoYJrEp2sEkaM6HfYRTRjA7rrzoE7bd1vad8ZdJnkTLGP87o42QiNx7vod1z7CSvrXB0aH3+EFfevrQXqqcPWPOz04ngvNwiJGsJPBDnqs6dtxmBDiGRhxSXOkLgtwrJFxkN4ZlG071TD8ZisoGxZw= X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230022)(4636009)(376002)(136003)(346002)(396003)(39860400002)(451199015)(40470700004)(36840700001)(46966006)(70206006)(4326008)(8676002)(40480700001)(7636003)(83380400001)(2906002)(2616005)(336012)(36756003)(356005)(47076005)(41300700001)(82310400005)(26005)(5660300002)(186003)(8936002)(70586007)(478600001)(86362001)(316002)(966005)(6666004)(54906003)(82740400003)(40460700003)(107886003)(6916009)(36860700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2022 21:27:15.1078 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3b14e71-1c68-4a6d-fe72-08dab86204ba X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT090.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7452 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Florian Westphal BugLink: https://bugs.launchpad.net/bugs/1995004 We can delay refcount increment until we reassign the existing entry to the current skb. A 0 refcount can't happen while the nf_conn object is still in the hash table and parallel mutations are impossible because we hold the bucket lock. Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso (Cherry-picked from upstream ff73e7479b8eea594a985ca29f4b45d604dbcb2c) Signed-off-by: Bodong Wang --- net/netfilter/nf_conntrack_core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 6909c50..f8213dc 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -909,6 +909,7 @@ static void __nf_conntrack_insert_prepare(struct nf_conn *ct) tstamp->start = ktime_get_real_ns(); } +/* caller must hold locks to prevent concurrent changes */ static int __nf_ct_resolve_clash(struct sk_buff *skb, struct nf_conntrack_tuple_hash *h) { @@ -922,13 +923,12 @@ static int __nf_ct_resolve_clash(struct sk_buff *skb, if (nf_ct_is_dying(ct)) return NF_DROP; - if (!atomic_inc_not_zero(&ct->ct_general.use)) - return NF_DROP; - if (((ct->status & IPS_NAT_DONE_MASK) == 0) || nf_ct_match(ct, loser_ct)) { struct net *net = nf_ct_net(ct); + nf_conntrack_get(&ct->ct_general); + nf_ct_acct_merge(ct, ctinfo, loser_ct); nf_ct_add_to_dying_list(loser_ct); nf_conntrack_put(&loser_ct->ct_general); @@ -938,7 +938,6 @@ static int __nf_ct_resolve_clash(struct sk_buff *skb, return NF_ACCEPT; } - nf_ct_put(ct); return NF_DROP; }