Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1051461rwl; Fri, 7 Apr 2023 09:11:14 -0700 (PDT) X-Google-Smtp-Source: AKy350b++Bul89wMpjpZSSPKvagqCVnSywQhXFvoi8c/yFBWWSoH7pCyKL4QV3gRdeGgELabhs96 X-Received: by 2002:a17:906:3e4f:b0:932:615c:33d4 with SMTP id t15-20020a1709063e4f00b00932615c33d4mr1968094eji.34.1680883874620; Fri, 07 Apr 2023 09:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680883874; cv=none; d=google.com; s=arc-20160816; b=dUIdjx6wMrwB+R9V/XCiEcAP3KEvnN6ZPh+ovjOP+No/IqVGfO5dWyUT0qeJ2D9/lW mLU+2Lv3NCw+gFEhdf496MovFnrhsGpyuZ81pKETq0DztXSwZzt6diEuKjG5oATBbsQj QO9ZUg2yX50HboX8FZf1Rzhafg0Jamn58BS9+ZgGasW5CEo7zdN876uTHOv8BPsa1JEE U7+3PotWabXl8gxO4Q3iBFUu320sa7BzsLxJVpZxPZehruPuxRpvwO9Fvn5w1HSBA4G+ Amt37btDTgU9iRH+7mp3VkNTaaRyITWREqE16xwkrsDDNakkSiN0c1hGoFbY7PUea6uT Lw8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=pG4bkww4TTKH5g62+sthOLOmqZqedZWZduXMaCftkq4=; b=X2jTI5QAD9ap0Nyzm31yE37lSar+pqzylIr90prV+r0H4gEb5wq3zLlzGMFAzooEWL xXQxFrEV7qIKv4vZJpvf4IcFO33mo7lLMdaqeOhtXOO4V23+pifx2/2uHXVYFSO2LLvW +ODdu1prl0OKW1uxbUQhLn2myQ8neYuIuFbnuyYydOm2B/5BxDfqpbSBbAjkxxGjVFy/ 8xbYw/9c8WN1wl24gJYjC1gMXO/JeNpr8cvqbGFpRs8kksFh6cnnzeiql6w84rfDV+G8 /R/psXnyAejgCmbf2k3T5FIlh5FwoI/4CUDuh6nmfz8zAog09fE2F+qQ/bbqU9Uu8M3b jEPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mojatatu-com.20210112.gappssmtp.com header.s=20210112 header.b="wO/b6t0T"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb42-20020a1709077eaa00b00933574cbb3esi4293055ejc.229.2023.04.07.09.10.39; Fri, 07 Apr 2023 09:11:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mojatatu-com.20210112.gappssmtp.com header.s=20210112 header.b="wO/b6t0T"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231715AbjDGQJq (ORCPT + 99 others); Fri, 7 Apr 2023 12:09:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230245AbjDGQJn (ORCPT ); Fri, 7 Apr 2023 12:09:43 -0400 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80CAFBB92 for ; Fri, 7 Apr 2023 09:09:19 -0700 (PDT) Received: by mail-yb1-xb36.google.com with SMTP id f188so30968462ybb.3 for ; Fri, 07 Apr 2023 09:09:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1680883758; x=1683475758; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pG4bkww4TTKH5g62+sthOLOmqZqedZWZduXMaCftkq4=; b=wO/b6t0TAhKJ7bG5BAH8ilaCdIekWtZdXo5wLOJrG1RO6kku1Vr/OAiB5x05nSbiI8 SkPgZpgZ4/6tGs8Hthod/dDkKpFZFHb8joim2BmuiCYWF3hd61faFClVR65J3+xUgvHc QMbssiyAzV/1FDNc8tpgAgYWN+Rv+4vlQp2g3YFzJJhnw37gziOreeGwHxNTJw21n2Wr 0ikt8o8jq84Za+/DrAJj/OHHBqwbNS1pWwaGK5KaQYQC3WAWSBPl7ZERAOWjv0H0o/L1 rH7U5HtwbZ2jwD2CBRhOzk0vq8Ow2ShAtcsIgPn57RKCu6W+el9HMkgXz4TYhkK2I3qR VRcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680883758; x=1683475758; h=content-transfer-encoding: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=pG4bkww4TTKH5g62+sthOLOmqZqedZWZduXMaCftkq4=; b=EY76NL3jywpkECLYSZBRoUnuWZGvxw3i48zz9CX3FmWJWhFDlSMHYbuAdXGIEwlVLU 77XfV5wrutHBpNXnpIGoNpWUWmRLvC0nag02ifyStXHvjKMfgrVDmnv0Xcya1BtY6Z2P WmWbQxt07MMXZZI902kkFN7NuZq/DsqLXLENuQkVn5NvRxpvOefy1uDvfYdONcjhO9Aj zyIlXyjiCOJijs3Hkm8+EgHnU5Vlj2+QWlTBJf+YS9RDZI8ZgT7h3Qzc8B6c2ufV48bk XWv3PhKeovBNM1hk486r8ZUiv3G7oWGgoXVCplAX0ViL76AwSXm5K+jOh/8nrurxB3KP t4Pw== X-Gm-Message-State: AAQBX9d69uG9+jaN859pazQs7skhwd9ucVWWqu82WQUaYtGkG0ZZcVIe ene3wqbM+W755ibDNuhG+JHLYbiX9SjAc0DyzJyPlA== X-Received: by 2002:a25:7490:0:b0:b78:45fd:5f01 with SMTP id p138-20020a257490000000b00b7845fd5f01mr2072667ybc.7.1680883758618; Fri, 07 Apr 2023 09:09:18 -0700 (PDT) MIME-Version: 1.0 References: <20230403103440.2895683-1-vladimir.oltean@nxp.com> <20230403103440.2895683-6-vladimir.oltean@nxp.com> In-Reply-To: <20230403103440.2895683-6-vladimir.oltean@nxp.com> From: Jamal Hadi Salim Date: Fri, 7 Apr 2023 12:09:07 -0400 Message-ID: Subject: Re: [PATCH v4 net-next 5/9] net/sched: pass netlink extack to mqprio and taprio offload To: Vladimir Oltean Cc: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Cong Wang , Jiri Pirko , Vinicius Costa Gomes , Kurt Kanzenbach , Gerhard Engleder , Amritha Nambiar , Ferenc Fejes , Xiaoliang Yang , Roger Quadros , Pranavi Somisetty , Harini Katakam , Giuseppe Cavallaro , Alexandre Torgue , Michael Sit Wei Hong , Mohammad Athari Bin Ismail , Oleksij Rempel , Jacob Keller , linux-kernel@vger.kernel.org, Simon Horman Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Mon, Apr 3, 2023 at 6:35=E2=80=AFAM Vladimir Oltean wrote: > > With the multiplexed ndo_setup_tc() model which lacks a first-class > struct netlink_ext_ack * argument, the only way to pass the netlink > extended ACK message down to the device driver is to embed it within the > offload structure. > > Do this for struct tc_mqprio_qopt_offload and struct tc_taprio_qopt_offlo= ad. > > Since struct tc_taprio_qopt_offload also contains a tc_mqprio_qopt_offloa= d > structure, and since device drivers might effectively reuse their mqprio > implementation for the mqprio portion of taprio, we make taprio set the > extack in both offload structures to point at the same netlink extack > message. > > In fact, the taprio handling is a bit more tricky, for 2 reasons. > > First is because the offload structure has a longer lifetime than the > extack structure. The driver is supposed to populate the extack > synchronously from ndo_setup_tc() and leave it alone afterwards. > To not have any use-after-free surprises, we zero out the extack pointer > when we leave taprio_enable_offload(). > > The second reason is because taprio does overwrite the extack message on > ndo_setup_tc() error. We need to switch to the weak form of setting an > extack message, which preserves a potential message set by the driver. > > Signed-off-by: Vladimir Oltean > Reviewed-by: Simon Horman Acked-by: Jamal Hadi Salim cheers, jamal > --- > v3->v4: none > v2->v3: patch is new > > include/net/pkt_sched.h | 2 ++ > net/sched/sch_mqprio.c | 5 ++++- > net/sched/sch_taprio.c | 12 ++++++++++-- > 3 files changed, 16 insertions(+), 3 deletions(-) > > diff --git a/include/net/pkt_sched.h b/include/net/pkt_sched.h > index bb0bd69fb655..b43ed4733455 100644 > --- a/include/net/pkt_sched.h > +++ b/include/net/pkt_sched.h > @@ -166,6 +166,7 @@ struct tc_mqprio_caps { > struct tc_mqprio_qopt_offload { > /* struct tc_mqprio_qopt must always be the first element */ > struct tc_mqprio_qopt qopt; > + struct netlink_ext_ack *extack; > u16 mode; > u16 shaper; > u32 flags; > @@ -193,6 +194,7 @@ struct tc_taprio_sched_entry { > > struct tc_taprio_qopt_offload { > struct tc_mqprio_qopt_offload mqprio; > + struct netlink_ext_ack *extack; > u8 enable; > ktime_t base_time; > u64 cycle_time; > diff --git a/net/sched/sch_mqprio.c b/net/sched/sch_mqprio.c > index 9ee5a9a9b9e9..5287ff60b3f9 100644 > --- a/net/sched/sch_mqprio.c > +++ b/net/sched/sch_mqprio.c > @@ -33,9 +33,12 @@ static int mqprio_enable_offload(struct Qdisc *sch, > const struct tc_mqprio_qopt *qopt, > struct netlink_ext_ack *extack) > { > - struct tc_mqprio_qopt_offload mqprio =3D {.qopt =3D *qopt}; > struct mqprio_sched *priv =3D qdisc_priv(sch); > struct net_device *dev =3D qdisc_dev(sch); > + struct tc_mqprio_qopt_offload mqprio =3D { > + .qopt =3D *qopt, > + .extack =3D extack, > + }; > int err, i; > > switch (priv->mode) { > diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c > index 1f469861eae3..cbad43019172 100644 > --- a/net/sched/sch_taprio.c > +++ b/net/sched/sch_taprio.c > @@ -1520,7 +1520,9 @@ static int taprio_enable_offload(struct net_device = *dev, > return -ENOMEM; > } > offload->enable =3D 1; > + offload->extack =3D extack; > mqprio_qopt_reconstruct(dev, &offload->mqprio.qopt); > + offload->mqprio.extack =3D extack; > taprio_sched_to_offload(dev, sched, offload, &caps); > > for (tc =3D 0; tc < TC_MAX_QUEUE; tc++) > @@ -1528,14 +1530,20 @@ static int taprio_enable_offload(struct net_devic= e *dev, > > err =3D ops->ndo_setup_tc(dev, TC_SETUP_QDISC_TAPRIO, offload); > if (err < 0) { > - NL_SET_ERR_MSG(extack, > - "Device failed to setup taprio offload"); > + NL_SET_ERR_MSG_WEAK(extack, > + "Device failed to setup taprio offloa= d"); > goto done; > } > > q->offloaded =3D true; > > done: > + /* The offload structure may linger around via a reference taken = by the > + * device driver, so clear up the netlink extack pointer so that = the > + * driver isn't tempted to dereference data which stopped being v= alid > + */ > + offload->extack =3D NULL; > + offload->mqprio.extack =3D NULL; > taprio_offload_free(offload); > > return err; > -- > 2.34.1 >