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=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 8B3FCC43381 for ; Wed, 20 Feb 2019 22:33:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B5F520836 for ; Wed, 20 Feb 2019 22:33:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k+aCs+83" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726346AbfBTWd3 (ORCPT ); Wed, 20 Feb 2019 17:33:29 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45412 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725826AbfBTWd2 (ORCPT ); Wed, 20 Feb 2019 17:33:28 -0500 Received: by mail-pg1-f196.google.com with SMTP id y4so12646003pgc.12 for ; Wed, 20 Feb 2019 14:33:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rZhNeG51aOq63QH5hartD/m3iOk8Jsxnt7pmN/qlzB8=; b=k+aCs+83AelmMoAVB+88znwkCVX/PrsYv8DsyhRZOmTFGiOJseiLdYr6bPnL/xdPL9 /tCZ73bQRL57wRrrNnomarOrgHARVw5u2AOSiwzWHCPX1EABO8hHw2kHCCLpPSvZ31Mi BFWlDUTL28FnJlue2a7diCCGyFHvm4RfuwS4llIoBbMrPfthhlKcohKlZPGLU8QgjmIn BSqUGWD8blTksrXXqnEmrpAWThQDinCeF8JzoDa01moBxCZ4vnIwK9Lxx8sOdhosEjpD o7YAqv82rOvn7xFmkH9McsCu/j0ZS9euD9a7+sm4Ef9isSXRhT5dWev1+LdeQVBtRK38 0hkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rZhNeG51aOq63QH5hartD/m3iOk8Jsxnt7pmN/qlzB8=; b=pdFKP0vAgCCKGiLa0B9XRohWqDM2PpbS4vYJEcaezzKm7M4oQEara8DWn9adZssm1d tQwmObMgpup44Kpabqsd/hYHOwHIeGN169hZzvXF8X6lKtzjfeEHmI8CmFKDKdpjpaRR THSAL6dY43/0h4U/1gsWtVI8y5JzWylCIllSavrTiigG8kRpPNTSNcJQEezun0WKVr6y /wWBuOiVXRVZvr4r2zGuQEKRjV4BoSZX89JnnAIvu2yK7X9LrY/IFCooCqIfe1L1J6eI FUZeQs/47Zf1vOQPz7OcmkmwW20B4QhAiqv44p/SDl2xXQzBOWmlnaXg7hL2TPYKbQL9 wIaw== X-Gm-Message-State: AHQUAubwYS/lkOSeB1aMyq/c19KDWyQL9DfwFlbdqFtpNCtF0t9D9xyq oGEjWlwMjTIDg6hHpbKVpLI2/mPtDD9/ZYHTpWap9abp X-Google-Smtp-Source: AHgI3IbtCKKLmzwFeJdParz6XO2wClnuIp3/FC/uoDJgft5PB7XPe0waQzeYTi8Y6C0fjp5XMf9DKHBKhhf24xsivx0= X-Received: by 2002:a62:62c5:: with SMTP id w188mr37377758pfb.160.1550702007456; Wed, 20 Feb 2019 14:33:27 -0800 (PST) MIME-Version: 1.0 References: <20190214074712.17846-1-vladbu@mellanox.com> <20190214074712.17846-2-vladbu@mellanox.com> In-Reply-To: From: Cong Wang Date: Wed, 20 Feb 2019 14:33:15 -0800 Message-ID: Subject: Re: [PATCH net-next 01/12] net: sched: flower: don't check for rtnl on head dereference To: Vlad Buslov Cc: Linux Kernel Network Developers , Jamal Hadi Salim , Jiri Pirko , David Miller Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Feb 19, 2019 at 1:46 AM Vlad Buslov wrote: > > > On Mon 18 Feb 2019 at 19:08, Cong Wang wrote: > > On Wed, Feb 13, 2019 at 11:47 PM Vlad Buslov wrote: > >> > >> Flower classifier only changes root pointer during init and destroy. Cls > >> API implements reference counting for tcf_proto, so there is no danger of > >> concurrent access to tp when it is being destroyed, even without protection > >> provided by rtnl lock. > > > > How about atomicity? Refcnt doesn't guarantee atomicity, how do > > you make sure two concurrent modifications are atomic? > > In order to guarantee atomicity I lock shared flower classifier data > structures with tp->lock in following patches. Sure, I meant the atomicity of the _whole_ change, as you know the TC filters are stored in hierarchical structures: a block, a chain, a tp struct, some type-specific data structure like a hash table. Locking tp only solves a partial of the atomicity here. Are you going to restart the whole change from top down to the bottom? > > > > > > >> > >> Implement new function fl_head_dereference() to dereference tp->root > >> without checking for rtnl lock. Use it in all flower function that obtain > >> head pointer instead of rtnl_dereference(). > >> > > > > So what lock protects RCU writers after this patch? > > I explained it in comment for fl_head_dereference(), but should have > copied this information to changelog as well: > Flower classifier only changes root pointer during init and destroy. > Cls API implements reference counting for tcf_proto, so there is no > danger of concurrent access to tp when it is being destroyed, even > without protection provided by rtnl lock. So you are saying an RCU pointer is okay to deference without any lock eve without RCU read lock, right? > > In initial version of this change I used tp->lock to protect tp->root > access and verified it with lockdep, but during internal review Jiri > noted that this is not needed in current flower implementation. Let's see what you have on top of your own branch unlocked_flower_cong_1: 1458 static int fl_change(struct net *net, struct sk_buff *in_skb, 1459 struct tcf_proto *tp, unsigned long base, 1460 u32 handle, struct nlattr **tca, 1461 void **arg, bool ovr, bool rtnl_held, 1462 struct netlink_ext_ack *extack) 1463 { 1464 struct cls_fl_head *head = fl_head_dereference(tp); At the point of line 1464, there is no lock taken, tp->lock is taken after it, block->lock or chain lock is already unlocked before ->change(). So, what protects this RCU structure? According to RCU, it must be either RCU read lock or some writer lock. I see none here. :( What am I missing?