Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp118496iob; Tue, 17 May 2022 20:50:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOoHkDND97/i2R6oNpoNRpCz/1rt/xXNzhQrnNtH3CR8HjJZBVxnbGGBxFyWJdEmUBoaau X-Received: by 2002:a17:902:7444:b0:161:5a62:cf8b with SMTP id e4-20020a170902744400b001615a62cf8bmr17507636plt.77.1652845833163; Tue, 17 May 2022 20:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652845833; cv=none; d=google.com; s=arc-20160816; b=vq70nAPUpVKXq5vtbs6UQbYtovLSdiNKywflJ+02fls0fC6fZ9YvPbVWfAuBqr/adq iiGfd2fz6DII4odA+uOS9nWQ1xrr8T/9Zf9+EjjalZT2S0g4oJB/Giwr8DKsdD436bsi TA0/adVgzHhkHsYGjv/muo243Kn9JYYILlgnNvPN1VLgb2Kt2+/83jCtFyGAihWoaa0c Gyfk3xlB36m/ZFvSu8ygMWdrcamaqWYkBdQOf+7RGf7QE+7KwUVloloF9ueFQrBg4z+y VfKoNJx/uXh/QNv3a9sOX9xvLrQTDEgmEtoJDa3GQ7m70ZqnkJscTchBdVWaaWJJq0yA eU0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=i8M8Z58/S4T70xu3ij6nwxp0vCG1VpWVG/K86RO/OHQ=; b=S57ORmlG4zVWZgypQ8poMb8mpzAneY1kYxLztwN+12VTzHe/8Vvy4wT46adLvK5FMd Kn/St38Z52apT4Icu+/5IY9UHv8BljZKPi2uaKfFi1sjj3EcVGSRE5r4JXd1yHN0dlN5 zmzXp31VxHJrI8SI7WZ9yPM0nWo8PBTVXpQIomCZE/Q02MaTyPmAuVl5eMADyIXc+UDj sHPI2MO9CHwJKgO25wwNB97ncxUsPvHVCVq3ThoqiXQg3SLR7J3EJ1OG/Zlz0KS3KR6s I5c61H1hNFL3UpPo8OAbsEeqEpuqNlDlUaW3KoQIy5YkG0WPMpYYSlU3gMuGCL4EDX8X 1pjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oRpBaAQf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bh8-20020a056a02020800b003c1dc83e6b6si1080044pgb.317.2022.05.17.20.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:50:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oRpBaAQf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C977D8A338; Tue, 17 May 2022 20:33:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234218AbiERCTF (ORCPT + 99 others); Tue, 17 May 2022 22:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233364AbiERCTC (ORCPT ); Tue, 17 May 2022 22:19:02 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE861B96; Tue, 17 May 2022 19:19:01 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id i24so811145pfa.7; Tue, 17 May 2022 19:19:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=i8M8Z58/S4T70xu3ij6nwxp0vCG1VpWVG/K86RO/OHQ=; b=oRpBaAQfMPXFHgxB0PgucXXcDl6TY/CTTaxyyDRbv/VsfyDOXQ0393OJvGm1s9zgWx dkErw99zOrw/OB55QKRSS5dE8PzpUt2MldLrJ28y9rQspOVY6PLbRn8T0jBY25H45w7w RKJN4y6YhIjjN0kQ2kbRWQ/a+IZdUZG1H4orncHmutwALOUhxcUOUD3o9xNVjyWbnMHH Wlc1Ar3CGCax1ZhIBeN+n83ncZNjY8M8veNTaIkGoI0L4YGvs1b1zDZdqDSoCjtXyrLf LoibZ0Uq96wDWhGLkhnBcX2fmhRnAIsS8EN51ohKL6KUYuB4qsWWKlM7nQdeHUwG5vNb qJ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=i8M8Z58/S4T70xu3ij6nwxp0vCG1VpWVG/K86RO/OHQ=; b=t8prXJNHgB9rzD8duYaNkluDGibS8zMsy3Kv0tPyUGTQmb37WZxD6XLT4j6YqW0ftc Si+avbfEwXp8gQL2ubg3ESYYeY9Bki+gW+OYrNaREl9jU7FdOp/zqzqGcylrVbEGbQbX ou/CA4qLM60RpG9xfP5fhD2EltN7J1pLQjMgGxOithZ4Hlx/k3uOYkO2j3VCGaM5DGdh rmo472R33njqIzBXoyWlIqfoD1RoD/yiHLqh8mfMZu1FBDWwd5pPU0mWZaCl0pIcFFvc Ya2uj2nmOWvX8J7y9mbmfQWeDhfecPI0DvDCl/ztLW5DCPtfNicbiVwKcOadaD5OeLuF y/EA== X-Gm-Message-State: AOAM5337p2WBUV451exC7YmGtk4AslKBU7492P/L0u+Ud8Xd9/mW6XhK Y6Cf9sy7F9u0ZE7AxedsCiE= X-Received: by 2002:a63:574d:0:b0:3db:4d75:70f3 with SMTP id h13-20020a63574d000000b003db4d7570f3mr21614428pgm.10.1652840341200; Tue, 17 May 2022 19:19:01 -0700 (PDT) Received: from Laptop-X1 ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id f23-20020a170902ab9700b0015e8d4eb26dsm283271plr.183.2022.05.17.19.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 19:19:00 -0700 (PDT) Date: Wed, 18 May 2022 10:18:53 +0800 From: Hangbin Liu To: Jonathan Toppins Cc: andy@greyhouse.net, davem@davemloft.net, dsahern@gmail.com, eric.dumazet@gmail.com, j.vosburgh@gmail.com, kuba@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, syzbot+92beb3d46aab498710fa@syzkaller.appspotmail.com, vfalico@gmail.com, vladimir.oltean@nxp.com, Eric Dumazet , linux-kernel@vger.kernel.org Subject: Re: [PATCHv2 net] bonding: fix missed rcu protection Message-ID: References: <20220517082312.805824-1-liuhangbin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 17, 2022 at 01:32:58PM -0400, Jonathan Toppins wrote: > Signed-off-by: Jonathan Toppins > --- > RESEND, list still didn't receive my last version > > The diffstat is slightly larger but IMO a slightly more readable version. > When I was reading v2 I found myself jumping around. Hi Jon, Thanks for the commit. But.. > diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c > index 38e152548126..f9d27b63c454 100644 > --- a/drivers/net/bonding/bond_main.c > +++ b/drivers/net/bonding/bond_main.c > @@ -5591,23 +5591,32 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev, > const struct ethtool_ops *ops; > struct net_device *real_dev; > struct phy_device *phydev; > + int ret = 0; > > + rcu_read_lock(); > real_dev = bond_option_active_slave_get_rcu(bond); > - if (real_dev) { > - ops = real_dev->ethtool_ops; > - phydev = real_dev->phydev; > - > - if (phy_has_tsinfo(phydev)) { > - return phy_ts_info(phydev, info); > - } else if (ops->get_ts_info) { > - return ops->get_ts_info(real_dev, info); > - } > - } > + if (real_dev) > + dev_hold(real_dev); > + rcu_read_unlock(); > + > + if (!real_dev) > + goto software; > > + ops = real_dev->ethtool_ops; > + phydev = real_dev->phydev; > + > + if (phy_has_tsinfo(phydev)) > + ret = phy_ts_info(phydev, info); > + else if (ops->get_ts_info) > + ret = ops->get_ts_info(real_dev, info); else { dev_put(real_dev); goto software; } Here we need another check and goto software if !phy_has_tsinfo() and no ops->get_ts_info. With this change we also have 2 goto and dev_put(). > + > + dev_put(real_dev); > + return ret; > + > +software: > info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE | > SOF_TIMESTAMPING_SOFTWARE; > info->phc_index = -1; > - > return 0; > } As Jakub remind, dev_hold() and dev_put() can take NULL now. So how about this new patch: diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 38e152548126..b5c5196e03ee 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -5591,16 +5591,23 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev, const struct ethtool_ops *ops; struct net_device *real_dev; struct phy_device *phydev; + int ret = 0; + rcu_read_lock(); real_dev = bond_option_active_slave_get_rcu(bond); + dev_hold(real_dev); + rcu_read_unlock(); + if (real_dev) { ops = real_dev->ethtool_ops; phydev = real_dev->phydev; if (phy_has_tsinfo(phydev)) { - return phy_ts_info(phydev, info); + ret = phy_ts_info(phydev, info); + goto out; } else if (ops->get_ts_info) { - return ops->get_ts_info(real_dev, info); + ret = ops->get_ts_info(real_dev, info); + goto out; } } @@ -5608,7 +5615,9 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev, SOF_TIMESTAMPING_SOFTWARE; info->phc_index = -1; - return 0; +out: + dev_put(real_dev); + return ret; } Thanks Hangbin