Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85115C636D4 for ; Fri, 10 Feb 2023 15:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232491AbjBJPH7 (ORCPT ); Fri, 10 Feb 2023 10:07:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232110AbjBJPH5 (ORCPT ); Fri, 10 Feb 2023 10:07:57 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B0CB1C598 for ; Fri, 10 Feb 2023 07:07:55 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id y1so5378271wru.2 for ; Fri, 10 Feb 2023 07:07:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=qlNC/kKbUsPlOCKxymEIios8n2ASOqnWF3/GBA5cjF8=; b=lUiODl6bVd/fiZW4XlYgkYvOyJLav2vvyyiWeUXwQEPV09CChytAMwjjvRT0y6b2gx 3tGbsprUTD5PgTf821cAG8WnuE71fRwT7VI07pUdubcRoTjoscHc6fOnt8jUeo6blWaf 3C3aY8Wxj5ut8lRP6XRG918amBW2lPMn2hZgDTcJ/Fu8u01vC8CoMWe5LsO5qvG4XOku p0X1zCcFem9m7EENqaeQQUm9aRx7DMErky8UyerVpVYP5JFH9npBkyA/AYrPGwelLvAh 2tYbYNRlWECWCWVqp6BvTzPlJYqx6gFOva9Yr6HDm7sdM+Xz5myPKiWX5kRb74BBwCbm vMDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qlNC/kKbUsPlOCKxymEIios8n2ASOqnWF3/GBA5cjF8=; b=D70HNd3XhV8lgzn4u5rRzOuS3UhWkKhs67tOE5Q/g+4JTJG99grsiOAIrkEsinU1Bq rRAYmjon0FGgCPrBA9KC57Tzw8lLRB3XM7H/a3SCio3C2nO8IZRVMMBfyq15q87ln11w 9h+tR0rIhV6QD4wW2WIPkHHpgtbbp6ha6Hf5kg1kgAoAQZQpVhrtZ+Ww+HVt3/COvDSm 4NqLBMR+/77DR525noQALqaC9PS9m31GwbT5RMt5nk5Z+Ga4NCT95DW9Y3bmdSfH1tX6 3zTRfWXfNw7HJNoOBLFQjwQrH8YU0rqvQnkRFOK3CiABUazLFnejFB+dDWiNUEw4qv49 Y7GQ== X-Gm-Message-State: AO0yUKUi26Me0tHonsoFjArvCLYFAtGJU/Ryz/02nBQ+UK/TFCOIieEt k2DiMiGJow8uwhsmZ3f/ASkfIyz9LUSzTFWrH0FR4w== X-Google-Smtp-Source: AK7set9TQ9KQwoqhGEVIEcXvcv/U/mBHAlTVV6SnxMr8fK8HsjlFlHF/wol0CSMUXWf24slV/I76/nqHc2iMbAXrygg= X-Received: by 2002:a5d:6583:0:b0:2c4:936:f423 with SMTP id q3-20020a5d6583000000b002c40936f423mr475464wru.113.1676041673935; Fri, 10 Feb 2023 07:07:53 -0800 (PST) MIME-Version: 1.0 References: <20230207135440.1482856-1-vladimir.oltean@nxp.com> <20230207135440.1482856-11-vladimir.oltean@nxp.com> In-Reply-To: <20230207135440.1482856-11-vladimir.oltean@nxp.com> From: Eric Dumazet Date: Fri, 10 Feb 2023 16:07:42 +0100 Message-ID: Subject: Re: [PATCH v2 net-next 10/15] net/sched: make stab available before ops->init() call To: Vladimir Oltean Cc: netdev@vger.kernel.org, "David S. Miller" , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Vinicius Costa Gomes , Kurt Kanzenbach , Jacob Keller , Gerhard Engleder , Jesse Brandeburg , Tony Nguyen , intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 7, 2023 at 2:55 PM Vladimir Oltean wrote: > > Some qdiscs like taprio turn out to be actually pretty reliant on a well > configured stab, to not underestimate the skb transmission time (by > properly accounting for L1 overhead). > > In a future change, taprio will need the stab, if configured by the > user, to be available at ops->init() time. It will become even more > important in upcoming work, when the overhead will be used for the > queueMaxSDU calculation that is passed to an offloading driver. > > However, rcu_assign_pointer(sch->stab, stab) is called right after > ops->init(), making it unavailable, and I don't really see a good reason > for that. > > Move it earlier, which nicely seems to simplify the error handling path > as well. Well... if you say so :) > > Signed-off-by: Vladimir Oltean > Reviewed-by: Kurt Kanzenbach > If TCA_STAB attribute is malformed, we end up calling ->destroy() on a not yet initialized qdisc :/ I am going to send the following fix, unless someone disagrees. (Moving qdisc_put_stab() _after_ ops->destroy(sch) is not strictly needed for a fix, but undo should be done in reverse steps for clarity. diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index e9780631b5b58202068e20c42ccf1197eac2194c..aba789c30a2eb50d339b8a888495b794825e1775 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -1286,7 +1286,7 @@ static struct Qdisc *qdisc_create(struct net_device *dev, stab = qdisc_get_stab(tca[TCA_STAB], extack); if (IS_ERR(stab)) { err = PTR_ERR(stab); - goto err_out4; + goto err_out3; } rcu_assign_pointer(sch->stab, stab); } @@ -1294,14 +1294,14 @@ static struct Qdisc *qdisc_create(struct net_device *dev, if (ops->init) { err = ops->init(sch, tca[TCA_OPTIONS], extack); if (err != 0) - goto err_out5; + goto err_out4; } if (tca[TCA_RATE]) { err = -EOPNOTSUPP; if (sch->flags & TCQ_F_MQROOT) { NL_SET_ERR_MSG(extack, "Cannot attach rate estimator to a multi-queue root qdisc"); - goto err_out5; + goto err_out4; } err = gen_new_estimator(&sch->bstats, @@ -1312,7 +1312,7 @@ static struct Qdisc *qdisc_create(struct net_device *dev, tca[TCA_RATE]); if (err) { NL_SET_ERR_MSG(extack, "Failed to generate new estimator"); - goto err_out5; + goto err_out4; } } @@ -1321,12 +1321,13 @@ static struct Qdisc *qdisc_create(struct net_device *dev, return sch; -err_out5: - qdisc_put_stab(rtnl_dereference(sch->stab)); err_out4: - /* ops->init() failed, we call ->destroy() like qdisc_create_dflt() */ + /* Even if ops->init() failed, we call ops->destroy() + * like qdisc_create_dflt(). + */ if (ops->destroy) ops->destroy(sch); + qdisc_put_stab(rtnl_dereference(sch->stab)); err_out3: netdev_put(dev, &sch->dev_tracker); qdisc_free(sch);