From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9F2AC43381 for ; Mon, 4 Mar 2019 14:14:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 64A6520823 for ; Mon, 4 Mar 2019 14:14:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=Mellanox.com header.i=@Mellanox.com header.b="gNFD1xA5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726640AbfCDOO0 (ORCPT ); Mon, 4 Mar 2019 09:14:26 -0500 Received: from mail-eopbgr00052.outbound.protection.outlook.com ([40.107.0.52]:26614 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726129AbfCDOOZ (ORCPT ); Mon, 4 Mar 2019 09:14:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uBcKhuVVuVUi0pglDnB1FJkQwMCBDjPaIltKZHmxR6U=; b=gNFD1xA5V7gF5+rpIKOduugeBwjRXKo0d2WpazGxpYPLqBoR+SB9D+rj0qvBETuVsAC38YAWYhfkMDG23CksIQXc6ni12SKj4sRfOvPgKuMxtKcxKiUn7S7VrRgfbFop59FAs+aUlwGw85CTFwgAI483nP4umCtQwIAItv0+180= Received: from HE1PR0502MB3641.eurprd05.prod.outlook.com (10.167.127.11) by HE1PR0502MB3868.eurprd05.prod.outlook.com (10.167.143.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1665.19; Mon, 4 Mar 2019 14:14:20 +0000 Received: from HE1PR0502MB3641.eurprd05.prod.outlook.com ([fe80::b03d:8cd4:d259:f749]) by HE1PR0502MB3641.eurprd05.prod.outlook.com ([fe80::b03d:8cd4:d259:f749%6]) with mapi id 15.20.1665.019; Mon, 4 Mar 2019 14:14:20 +0000 From: Vlad Buslov To: Cong Wang CC: Linux Kernel Network Developers , Jamal Hadi Salim , Jiri Pirko , David Miller Subject: Re: [PATCH net-next] net: sched: don't release block->lock when dumping chains Thread-Topic: [PATCH net-next] net: sched: don't release block->lock when dumping chains Thread-Index: AQHUzSE2Z57toeAqHUiQqsqlEQimbKXxNogAgAEKngCAAgXaAIABCNoAgAIt5YCABBEYAA== Date: Mon, 4 Mar 2019 14:14:20 +0000 Message-ID: References: <20190225154544.10453-1-vladbu@mellanox.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P123CA0001.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:a6::13) To HE1PR0502MB3641.eurprd05.prod.outlook.com (2603:10a6:7:85::11) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [37.142.13.130] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3a96e94a-2e66-4536-ca07-08d6a0abb185 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020);SRVR:HE1PR0502MB3868; x-ms-traffictypediagnostic: HE1PR0502MB3868: x-microsoft-exchange-diagnostics: =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eC/POOKwcpm8JuIHyxQpccyvhAdUqeLAwIAfWCo5?= =?iso-8859-1?Q?1+Vk3zIQa1UEgPFRfNALlyuNiMU0tKOj0JWfaQnyvv30dRFlq9gSXSe2RF?= =?iso-8859-1?Q?egWGD0Gmpe5DIgyCgTbJHWN24/3n93ausV3S7+L5JUzkGttqQp56nulj2g?= =?iso-8859-1?Q?KcvoYgyKzDWT5d92ZgUX72NLhZx/MD8tpu0wtTgEtS+1AlHlxa+SmZhmxm?= =?iso-8859-1?Q?qYkt5GlNiMx03Rbj6i37hThkDpK5KfZSOhdFOR5KpsqkzUVvXv2yfll5f4?= =?iso-8859-1?Q?EV66/4tNWdyzVikEXJTHBg+4Cq5xL9ajsF0rKRY96g9UYdyF6rsq0mAzlA?= =?iso-8859-1?Q?Ff4aCSbSByqPLob4CkX9KEu7Kx7zzZI2wYc7DZeJ9JZhyG/R/WmLkwoXWk?= =?iso-8859-1?Q?Okalx5oLw41Vwv5dJYEbaywmjFVPj2/0eKmvczEQCvXrk1bamxQiaPkZAZ?= =?iso-8859-1?Q?ae6W0KaAmgegwC7+0ZHv8kroXW7swxEMuxg5Fd4SBjnqFArAnr9yomFcpT?= =?iso-8859-1?Q?kpXWmdyieA=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 09669DB681 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(376002)(39860400002)(366004)(346002)(136003)(51914003)(199004)(189003)(52116002)(316002)(102836004)(53546011)(6506007)(386003)(76176011)(93886005)(186003)(66066001)(7736002)(2906002)(99286004)(3846002)(6116002)(36756003)(25786009)(54906003)(6346003)(26005)(81166006)(81156014)(8676002)(97736004)(6246003)(14454004)(4326008)(478600001)(105586002)(106356001)(8936002)(53936002)(71190400001)(71200400001)(256004)(14444005)(5660300002)(6486002)(486006)(229853002)(305945005)(2616005)(86362001)(446003)(11346002)(476003)(68736007)(6512007)(6916009)(6436002);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR0502MB3868;H:HE1PR0502MB3641.eurprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=vladbu@mellanox.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: MUz3jzy1xB8nEiilTAyEhjRW+Mim7LN5kRRDAgO3VprcBG2lFRDCtQS6ywOukBDg4myCX/aRrfnKWFLq4JSXNv9jhxywawc0MtOmC2FHJ1TSXHULJ663a6UH/xy6Gg80RsCD8jXm4lSCVlhjANiqvE+b0TKi3Sxas4seNqC0Uw27q5PRw+NeAof7y68MRkLlDvFwOmx0Ubxqy3OjE3FinMl8PSwqymiBJf9GTefbc/aKRJ6AWBn29FV436Y18bM9q4kKGQ546XyujdQPuPQ2ecmyYYYaglQ5+Mt31za33rZPdIEX1Ka2hO9J0o35w4qVm7eauaTS3NXms3q8ll76AgBr+Xc/Vf6SwgVCXWSmGZeUpJd3miTgK7WKRWJpkvT6arNIHytApr9r79eqqX4QI6eMGYtiKB/tkbUaJohP/JU= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a96e94a-2e66-4536-ca07-08d6a0abb185 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Mar 2019 14:14:20.0402 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0502MB3868 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Sat 02 Mar 2019 at 00:08, Cong Wang wrote: > On Thu, Feb 28, 2019 at 6:53 AM Vlad Buslov wrote: >> >> >> On Wed 27 Feb 2019 at 23:03, Cong Wang wrote: >> > On Tue, Feb 26, 2019 at 8:10 AM Vlad Buslov wrot= e: >> >> >> >> >> >> On Tue 26 Feb 2019 at 00:15, Cong Wang wro= te: >> >> > On Mon, Feb 25, 2019 at 7:45 AM Vlad Buslov w= rote: >> >> >> >> >> >> Function tc_dump_chain() obtains and releases block->lock on each = iteration >> >> >> of its inner loop that dumps all chains on block. Outputting chain= template >> >> >> info is fast operation so locking/unlocking mutex multiple times i= s an >> >> >> overhead when lock is highly contested. Modify tc_dump_chain() to = only >> >> >> obtain block->lock once and dump all chains without releasing it. >> >> >> >> >> >> Signed-off-by: Vlad Buslov >> >> >> Suggested-by: Cong Wang >> >> > >> >> > Thanks for the followup! >> >> > >> >> > Isn't it similar for __tcf_get_next_proto() in tcf_chain_dump()? >> >> > And for tc_dump_tfilter()? >> >> >> >> Not really. These two dump all tp filters and not just a template, wh= ich >> >> is O(n) on number of filters and can be slow because it calls hw offl= oad >> >> API for each of them. Our typical use-case involves periodic filter d= ump >> >> (to update stats) while multiple concurrent user-space threads are >> >> updating filters, so it is important for them to be able to execute i= n >> >> parallel. >> > >> > Hmm, but if these are read-only, you probably don't even need a >> > mutex, you can just use RCU read lock to protect list iteration >> > and you still can grab the refcnt in the same way. >> >> That is how it worked in my initial implementation. However, it doesn't >> work with hw offloads because driver callbacks can sleep. > > Hmm? You drop RCU read lock after grabbing the refcnt, > right? If so what's the problem with sleeping? Okay, I misunderstood your suggestion. In tc_dump_tfilter() we can't use RCU in __tcf_get_next_chain() because chain reference counters are not atomic and require protection of block->lock. __tcf_get_next_proto() requires chain->filter_chain_lock because it checks 'deleting' flag besides taking reference to tp.