From patchwork Sat Nov 18 20:37:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13460293 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b="0HpD/vsw" Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E034DC5 for ; Sat, 18 Nov 2023 12:38:23 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6b20577ef7bso2783060b3a.3 for ; Sat, 18 Nov 2023 12:38:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1700339903; x=1700944703; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/DRBRsuYSe8GiQqSl23qJvxzf8oMDFUuuf3/1QCpP2I=; b=0HpD/vsw+ttjmdiMYXGk0fC5um+c+tw7r/rCxtVJD8Z7hlI9/hM/7cRq+MyOFOI4/G RWp5YKrbi1FqcJksymnFzgzOTdzDS+yxSq9nwtpjHVFYM/lEqP+15XyOMuZXxWI2G5Jq UP69nFR4wmfn34PnONXJqw3fBPKrdqTQSe03lG/hwAKv4MdDPJvvyp2b+yLeNDiYhGy1 W903OXnIix4UGvm+mdkp8rcdWRHLalfscglsI35yYH1QDNuM9U62I8pHgQ1Wla/yc/7m aFp93cGeQ1INrfJrNykQ3I5j1TyYvlGH+XliZSzGsSrzbVkz/PzahuV2P9cWlcF+iKVz 0f1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700339903; x=1700944703; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/DRBRsuYSe8GiQqSl23qJvxzf8oMDFUuuf3/1QCpP2I=; b=w9Uj+iiVkd4UtT3zbqUuCygTdkGcJ4jFmh4eTyF45nZDE/StvgxiR6JOoX1q/p2E01 PtCI7hGecEQWsubKQgPijQbIyr4FJtdQO3Ap3w7JAuZmmVhYwPxlkmOOGBPeewZWNePF Wjezq/VWqkMeBDiiMu4gAynoPRWY4ygftYYn2Y5kp6QybWA9WxxURe+CoXbJXE84s2Cn yvXgqPwbTYeD5UZYClMCc4O3UTWpG5nbnmOsuEjHrX4792/mHgTbDKhl2wUWtDsliDJw ceGMODZwu02szCa/zLKjQMgDARgVi7LhnX3P1ccFtU0rDpyJKalQJEzss23/CRCo8Dqr P4WQ== X-Gm-Message-State: AOJu0YzmGOZEiiozWZ/TegLHVbq2M6Ad973QmE0/EzJA9KR533cg4qKf wWM/tlHe5gcWKoUPzgziOD9LEQ== X-Google-Smtp-Source: AGHT+IE0GF5ywV1LKlzG46IErkUZ3O3YwC319W1H3vRFuLMxSVTZ4nHn8ztB5OEu4eWZXgyuJDrDrQ== X-Received: by 2002:a05:6a00:84a:b0:6bd:f760:6ab1 with SMTP id q10-20020a056a00084a00b006bdf7606ab1mr3122765pfk.14.1700339903327; Sat, 18 Nov 2023 12:38:23 -0800 (PST) Received: from localhost.localdomain ([2804:7f1:e2c3:b02d:77:2195:4deb:3614]) by smtp.gmail.com with ESMTPSA id g31-20020a63565f000000b005891f3af36asm3403875pgm.87.2023.11.18.12.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 12:38:23 -0800 (PST) From: Victor Nogueira To: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, daniel@iogearbox.net Cc: netdev@vger.kernel.org, kernel@mojatatu.com Subject: [PATCH RFC net-next 1/3] net: sched: Move drop_reason to struct tc_skb_cb Date: Sat, 18 Nov 2023 17:37:52 -0300 Message-ID: <20231118203754.2270159-2-victor@mojatatu.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231118203754.2270159-1-victor@mojatatu.com> References: <20231118203754.2270159-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Move drop_reason from struct tcf_result to skb cb - more specifically to struct tc_skb_cb. With that, we'll be able to also set the drop reason for the remaining qdiscs (aside from clsact) that do not have access to tcf_result when time comes to set the skb drop reason. Signed-off-by: Victor Nogueira --- include/net/pkt_cls.h | 14 ++++++++++++-- include/net/pkt_sched.h | 1 + include/net/sch_generic.h | 1 - net/core/dev.c | 4 ++-- net/sched/act_api.c | 2 +- net/sched/cls_api.c | 20 ++++++++++---------- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index a76c9171db0e..7bd7ea511100 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -154,10 +154,20 @@ __cls_set_class(unsigned long *clp, unsigned long cl) return xchg(clp, cl); } -static inline void tcf_set_drop_reason(struct tcf_result *res, +struct tc_skb_cb; + +static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb); + +static inline enum skb_drop_reason +tc_skb_cb_drop_reason(const struct sk_buff *skb) +{ + return tc_skb_cb(skb)->drop_reason; +} + +static inline void tcf_set_drop_reason(const struct sk_buff *skb, enum skb_drop_reason reason) { - res->drop_reason = reason; + tc_skb_cb(skb)->drop_reason = reason; } static inline void diff --git a/include/net/pkt_sched.h b/include/net/pkt_sched.h index 9fa1d0794dfa..f09bfa1efed0 100644 --- a/include/net/pkt_sched.h +++ b/include/net/pkt_sched.h @@ -277,6 +277,7 @@ static inline void skb_txtime_consumed(struct sk_buff *skb) struct tc_skb_cb { struct qdisc_skb_cb qdisc_cb; + u32 drop_reason; u16 mru; u8 post_ct:1; diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index dcb9160e6467..c499b56bb215 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -332,7 +332,6 @@ struct tcf_result { }; const struct tcf_proto *goto_tp; }; - enum skb_drop_reason drop_reason; }; struct tcf_chain; diff --git a/net/core/dev.c b/net/core/dev.c index 05ce00632892..eb39e9f80428 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3924,14 +3924,14 @@ static int tc_run(struct tcx_entry *entry, struct sk_buff *skb, tc_skb_cb(skb)->mru = 0; tc_skb_cb(skb)->post_ct = false; - res.drop_reason = *drop_reason; + tcf_set_drop_reason(skb, *drop_reason); mini_qdisc_bstats_cpu_update(miniq, skb); ret = tcf_classify(skb, miniq->block, miniq->filter_list, &res, false); /* Only tcf related quirks below. */ switch (ret) { case TC_ACT_SHOT: - *drop_reason = res.drop_reason; + *drop_reason = tc_skb_cb_drop_reason(skb); mini_qdisc_qstats_cpu_drop(miniq); break; case TC_ACT_OK: diff --git a/net/sched/act_api.c b/net/sched/act_api.c index c39252d61ebb..12ac05857045 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1098,7 +1098,7 @@ int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions, } } else if (TC_ACT_EXT_CMP(ret, TC_ACT_GOTO_CHAIN)) { if (unlikely(!rcu_access_pointer(a->goto_chain))) { - tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); return TC_ACT_SHOT; } tcf_action_goto_chain_exec(a, res); diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 1976bd163986..13a04463e18e 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -1658,7 +1658,7 @@ static inline int __tcf_classify(struct sk_buff *skb, int act_index, u32 *last_executed_chain) { - u32 orig_reason = res->drop_reason; + u32 orig_reason = tc_skb_cb_drop_reason(skb); #ifdef CONFIG_NET_CLS_ACT const int max_reclassify_loop = 16; const struct tcf_proto *first_tp; @@ -1683,13 +1683,13 @@ static inline int __tcf_classify(struct sk_buff *skb, */ if (unlikely(n->tp != tp || n->tp->chain != n->chain || !tp->ops->get_exts)) { - tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); return TC_ACT_SHOT; } exts = tp->ops->get_exts(tp, n->handle); if (unlikely(!exts || n->exts != exts)) { - tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); return TC_ACT_SHOT; } @@ -1717,14 +1717,14 @@ static inline int __tcf_classify(struct sk_buff *skb, /* Policy drop or drop reason is over-written by * classifiers with a bogus value(0) */ if (err == TC_ACT_SHOT && - res->drop_reason == SKB_NOT_DROPPED_YET) - tcf_set_drop_reason(res, orig_reason); + tc_skb_cb_drop_reason(skb) == SKB_NOT_DROPPED_YET) + tcf_set_drop_reason(skb, orig_reason); return err; } } if (unlikely(n)) { - tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); return TC_ACT_SHOT; } @@ -1736,7 +1736,7 @@ static inline int __tcf_classify(struct sk_buff *skb, tp->chain->block->index, tp->prio & 0xffff, ntohs(tp->protocol)); - tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); return TC_ACT_SHOT; } @@ -1774,7 +1774,7 @@ int tcf_classify(struct sk_buff *skb, n = tcf_exts_miss_cookie_lookup(ext->act_miss_cookie, &act_index); if (!n) { - tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); return TC_ACT_SHOT; } @@ -1785,7 +1785,7 @@ int tcf_classify(struct sk_buff *skb, fchain = tcf_chain_lookup_rcu(block, chain); if (!fchain) { - tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); return TC_ACT_SHOT; } @@ -1807,7 +1807,7 @@ int tcf_classify(struct sk_buff *skb, ext = tc_skb_ext_alloc(skb); if (WARN_ON_ONCE(!ext)) { - tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); return TC_ACT_SHOT; } From patchwork Sat Nov 18 20:37:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13460294 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b="WRrFqO8d" Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D656BC5 for ; Sat, 18 Nov 2023 12:38:26 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1ce618b7919so10701075ad.0 for ; Sat, 18 Nov 2023 12:38:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1700339906; x=1700944706; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z6MNyhW0nhTU4iWeHDPoxoiHHuLw7r3Gkh93O/dqOtk=; b=WRrFqO8dqEmZcKeLSRWUYwtu5+KlybG7mF8OQ2VDS6e8bLe3ruc5UDM1tNGpPVbjGd T9lwH7IfgbvlKNTlDsr1vr4jvSPbbis5VDmB59KR/4lWuNOlhO4UThuOcR3YiJdSaPwA WF+1rsha0uQ4LrGH3C6oFsJuHRA/T6zv4WVxnaWVCmFMWr+CSq5i+c/W4jmag/Ju1nwL AOw+6iAiG2zziFPnlFH02wJUMA8BDpG3b1bZnnMSxLJ9rvu/uGxU2pPqCTbjSlG2SRPr trrzGnqc6QYaWYSD7IfxhYEMHKGM0ewXZO1QxFAX6oS+mwRTdNAu8sINuts3p5NQX4r2 FPiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700339906; x=1700944706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z6MNyhW0nhTU4iWeHDPoxoiHHuLw7r3Gkh93O/dqOtk=; b=wGOFytRWMRrDbMFVsSuLWmhyWnf9mjriML6y8JZPE6/erp2ROuk4YqofUq4geFebYD VrMNsGdvJRImr75RIYK4lo1PHazkv2V9FSUxK4CdHMwiKoRCP4ue5kpX4g0Zwq0Up6Y1 ZrIJYMynILsho72EdIoGe6Mq5fiUssrpqIpFSKDj3aM+esRxan9GnGKB4tLdILq7n7Ui KUGQ1KkAOn9sNZXLFUKYfrqYyhTDEzk7E0G2GWNagVlNPkRaw0kBubTUClmgcBb3j38N b/N7dyGhRHuOAB+SMeKhc7s05qkL8Idil5J4sh1OVyKPdCuFpYoXpNYCi65sKkTSVM1c AaTg== X-Gm-Message-State: AOJu0YzaHr6RN6eyRC30bdraKbhUTrWr0VUTL9nO7ZbJpdHP4DUeoIYb yh0krcIoSXNhjiBGVrjA/N1QphbBEc4hYeJZj50qcw== X-Google-Smtp-Source: AGHT+IGLQ+ZUBRbil6TQux1M1kA/L9LGDnFKOQjGMnZhEorh+7g+PwJaZtE3wm/W3XuDvISPAnLIUg== X-Received: by 2002:a17:903:4d:b0:1ce:5fa5:9056 with SMTP id l13-20020a170903004d00b001ce5fa59056mr6122347pla.3.1700339906243; Sat, 18 Nov 2023 12:38:26 -0800 (PST) Received: from localhost.localdomain ([2804:7f1:e2c3:b02d:77:2195:4deb:3614]) by smtp.gmail.com with ESMTPSA id g31-20020a63565f000000b005891f3af36asm3403875pgm.87.2023.11.18.12.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 12:38:25 -0800 (PST) From: Victor Nogueira To: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, daniel@iogearbox.net Cc: netdev@vger.kernel.org, kernel@mojatatu.com Subject: [PATCH RFC net-next 2/3] net: sched: Make tc-related drop reason more flexible for remaining qdiscs Date: Sat, 18 Nov 2023 17:37:53 -0300 Message-ID: <20231118203754.2270159-3-victor@mojatatu.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231118203754.2270159-1-victor@mojatatu.com> References: <20231118203754.2270159-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Incrementing on Daniel's patch[1], make tc-related drop reason more flexible for remaining qdiscs - that is, all qdiscs aside from clsact. In essence, the drop reason will be set by cls_api and act_api in case any error occurred in the data path. With that, we can give the user more detailed information so that they can distinguish between a policy drop or an error drop. [1] https://lore.kernel.org/all/20231009092655.22025-1-daniel@iogearbox.net Signed-off-by: Victor Nogueira --- include/net/pkt_cls.h | 16 -------------- include/net/pkt_sched.h | 19 ----------------- include/net/sch_generic.h | 45 +++++++++++++++++++++++++++++++++++++++ net/core/dev.c | 7 ++++-- 4 files changed, 50 insertions(+), 37 deletions(-) diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index 7bd7ea511100..f308e8268651 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -154,22 +154,6 @@ __cls_set_class(unsigned long *clp, unsigned long cl) return xchg(clp, cl); } -struct tc_skb_cb; - -static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb); - -static inline enum skb_drop_reason -tc_skb_cb_drop_reason(const struct sk_buff *skb) -{ - return tc_skb_cb(skb)->drop_reason; -} - -static inline void tcf_set_drop_reason(const struct sk_buff *skb, - enum skb_drop_reason reason) -{ - tc_skb_cb(skb)->drop_reason = reason; -} - static inline void __tcf_bind_filter(struct Qdisc *q, struct tcf_result *r, unsigned long base) { diff --git a/include/net/pkt_sched.h b/include/net/pkt_sched.h index f09bfa1efed0..1e200d9a066d 100644 --- a/include/net/pkt_sched.h +++ b/include/net/pkt_sched.h @@ -275,25 +275,6 @@ static inline void skb_txtime_consumed(struct sk_buff *skb) skb->tstamp = ktime_set(0, 0); } -struct tc_skb_cb { - struct qdisc_skb_cb qdisc_cb; - u32 drop_reason; - - u16 mru; - u8 post_ct:1; - u8 post_ct_snat:1; - u8 post_ct_dnat:1; - u16 zone; /* Only valid if post_ct = true */ -}; - -static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb) -{ - struct tc_skb_cb *cb = (struct tc_skb_cb *)skb->cb; - - BUILD_BUG_ON(sizeof(*cb) > sizeof_field(struct sk_buff, cb)); - return cb; -} - static inline bool tc_qdisc_stats_dump(struct Qdisc *sch, unsigned long cl, struct qdisc_walker *arg) diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index c499b56bb215..00251a526bf4 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -1036,11 +1036,54 @@ static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch) return skb; } +struct tc_skb_cb { + struct qdisc_skb_cb qdisc_cb; + u32 drop_reason; + + u16 mru; + u8 post_ct:1; + u8 post_ct_snat:1; + u8 post_ct_dnat:1; + u16 zone; /* Only valid if post_ct = true */ +}; + +static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb) +{ + struct tc_skb_cb *cb = (struct tc_skb_cb *)skb->cb; + + BUILD_BUG_ON(sizeof(*cb) > sizeof_field(struct sk_buff, cb)); + return cb; +} + +static inline enum skb_drop_reason +tc_skb_cb_drop_reason(const struct sk_buff *skb) +{ + return tc_skb_cb(skb)->drop_reason; +} + +static inline void tcf_set_drop_reason(const struct sk_buff *skb, + enum skb_drop_reason reason) +{ + tc_skb_cb(skb)->drop_reason = reason; +} + +static inline void tcf_init_drop_reason(const struct sk_buff *skb, + const enum skb_drop_reason reason) +{ + const u32 orig_drop_reason = tc_skb_cb_drop_reason(skb); + + /* If not set previously, initialise with reason */ + if (likely(orig_drop_reason == SKB_NOT_DROPPED_YET)) + tcf_set_drop_reason(skb, reason); +} + /* Instead of calling kfree_skb() while root qdisc lock is held, * queue the skb for future freeing at end of __dev_xmit_skb() */ static inline void __qdisc_drop(struct sk_buff *skb, struct sk_buff **to_free) { + tcf_init_drop_reason(skb, SKB_DROP_REASON_QDISC_DROP); + skb->next = *to_free; *to_free = skb; } @@ -1048,6 +1091,8 @@ static inline void __qdisc_drop(struct sk_buff *skb, struct sk_buff **to_free) static inline void __qdisc_drop_all(struct sk_buff *skb, struct sk_buff **to_free) { + tcf_init_drop_reason(skb, SKB_DROP_REASON_QDISC_DROP); + if (skb->prev) skb->prev->next = *to_free; else diff --git a/net/core/dev.c b/net/core/dev.c index eb39e9f80428..c47959754ab0 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3754,6 +3754,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, qdisc_calculate_pkt_len(skb, q); + tcf_set_drop_reason(skb, SKB_DROP_REASON_QDISC_DROP); + if (q->flags & TCQ_F_NOLOCK) { if (q->flags & TCQ_F_CAN_BYPASS && nolock_qdisc_is_empty(q) && qdisc_run_begin(q)) { @@ -3783,7 +3785,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, no_lock_out: if (unlikely(to_free)) kfree_skb_list_reason(to_free, - SKB_DROP_REASON_QDISC_DROP); + tc_skb_cb_drop_reason(to_free)); return rc; } @@ -3838,7 +3840,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, } spin_unlock(root_lock); if (unlikely(to_free)) - kfree_skb_list_reason(to_free, SKB_DROP_REASON_QDISC_DROP); + kfree_skb_list_reason(to_free, + tc_skb_cb_drop_reason(to_free)); if (unlikely(contended)) spin_unlock(&q->busylock); return rc; From patchwork Sat Nov 18 20:37:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13460295 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b="lSmIYeYO" Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D01B7D5 for ; Sat, 18 Nov 2023 12:38:29 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6bf03b98b9bso3074616b3a.1 for ; Sat, 18 Nov 2023 12:38:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1700339909; x=1700944709; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6BH0h9BqIXM1scIo6s3enWyiip53HzVmoI7QyAejJRg=; b=lSmIYeYOlPNBnvj6on2dXKoeZVM7lIlEtW+O4+v3PNAJPjjkYrTylKrulhXYhe76o8 WMXhiGF2EFsRtTqjdaOJ/Y6LI9nrSlzo9w3adtVCFPKOTbMnIJ03faHGm+pqWMN8ssMM vj1zK1+xhDNO697Xxv5maqNIc611mUumZTkVpKqsKSqksfq7q0p/pKgyTVQ4b9Ay9k5O ahnniJ53CLJz2EpcpZnxDoiUZSUR3jlIqL6T9h8FJdJ1df8Oj7qyRaJmrXsqKkYBwyg0 6tAciqqMIOu7KfQXQTCIc6oONSn+7xMTdwgJUH6c1PL/LS1Fss0QpMHfKzc9pnQbjHLq jHjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700339909; x=1700944709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6BH0h9BqIXM1scIo6s3enWyiip53HzVmoI7QyAejJRg=; b=to7lIGkNL6o/vVXIUIoMPxk9L3ItJJod4YnFeu3Q7GX58AQqtITM/6vLXhwvCfPgV2 nFgguG6xVYvxkdGxLsD2erA63n85sregTgF42PVmxHjY+N66SZwqkNIM+cew9IcvlZSe bePxxA1yASS7Z8BHwbyLHuBjYmwt6cY1Fsfik0E/XjxOSpobNEp4zZTYA0/Q6q4ALg4O nCE3OJKuU4jRCgCfXA/+YAgVcOMDdmmYZR4s62/v8pav68729Osr6E4hVOJfeC6T18Mc HE7vz+5vqN6dDDfT/wHDJyA4gHuMbEvXhJ6fhqzbqo05Y1vR0t32UpNz0Oau0soy9+Y+ 020w== X-Gm-Message-State: AOJu0YxRi3L8d6GHa5y2m/3CWXKDcQhq8zcIG3W2C4u6ONma6l5vh9jf AWKRom0PKAsPS7nznw17ghdqX8bAXLzXbRkefMfDtQ== X-Google-Smtp-Source: AGHT+IEjFQ/I42gX5A14AWA4iM0H28hjDDGGfkXo3yPtTlEYS6EoreIEMHiZKMc7LaenwcLmUJSXxg== X-Received: by 2002:a05:6a21:19a:b0:17a:e981:7fe4 with SMTP id le26-20020a056a21019a00b0017ae9817fe4mr14387727pzb.16.1700339909201; Sat, 18 Nov 2023 12:38:29 -0800 (PST) Received: from localhost.localdomain ([2804:7f1:e2c3:b02d:77:2195:4deb:3614]) by smtp.gmail.com with ESMTPSA id g31-20020a63565f000000b005891f3af36asm3403875pgm.87.2023.11.18.12.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 12:38:28 -0800 (PST) From: Victor Nogueira To: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, daniel@iogearbox.net Cc: netdev@vger.kernel.org, kernel@mojatatu.com Subject: [PATCH RFC net-next 3/3] net: sched: Add initial TC error skb drop reasons Date: Sat, 18 Nov 2023 17:37:54 -0300 Message-ID: <20231118203754.2270159-4-victor@mojatatu.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231118203754.2270159-1-victor@mojatatu.com> References: <20231118203754.2270159-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Continue expanding Daniel's patch by adding new skb drop reasons that are idiosyncratic to TC. More specifically: - SKB_DROP_REASON_TC_EXT_COOKIE_NOTFOUND: tc cookie was looked up using ext, but was not found. - SKB_DROP_REASON_TC_COOKIE_EXT_MISMATCH: tc ext was looked up using cookie and either was not found or different from expected. - SKB_DROP_REASON_TC_CHAIN_NOTFOUND: tc chain lookup failed. - SKB_DROP_REASON_TC_RECLASSIFY_LOOP: tc exceeded max reclassify loop iterations Signed-off-by: Victor Nogueira --- include/net/dropreason-core.h | 30 +++++++++++++++++++++++++++--- net/sched/act_api.c | 3 ++- net/sched/cls_api.c | 22 ++++++++++++++-------- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h index 3c70ad53a49c..fa6ace8f1611 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -85,7 +85,11 @@ FN(IPV6_NDISC_BAD_OPTIONS) \ FN(IPV6_NDISC_NS_OTHERHOST) \ FN(QUEUE_PURGE) \ - FN(TC_ERROR) \ + FN(TC_EXT_COOKIE_NOTFOUND) \ + FN(TC_COOKIE_EXT_MISMATCH) \ + FN(TC_COOKIE_MISMATCH) \ + FN(TC_CHAIN_NOTFOUND) \ + FN(TC_RECLASSIFY_LOOP) \ FNe(MAX) /** @@ -376,8 +380,28 @@ enum skb_drop_reason { SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST, /** @SKB_DROP_REASON_QUEUE_PURGE: bulk free. */ SKB_DROP_REASON_QUEUE_PURGE, - /** @SKB_DROP_REASON_TC_ERROR: generic internal tc error. */ - SKB_DROP_REASON_TC_ERROR, + /** + * @SKB_DROP_REASON_TC_EXT_COOKIE_NOTFOUND: tc cookie was looked up + * using ext, but was not found. + */ + SKB_DROP_REASON_TC_EXT_COOKIE_NOTFOUND, + /** + * @SKB_DROP_REASON_TC_COOKIE_EXT_MISMATCH: tc ext was lookup using + * cookie and either was not found or different from expected. + */ + SKB_DROP_REASON_TC_COOKIE_EXT_MISMATCH, + /** + * @SKB_DROP_REASON_TC_COOKIE_MISMATCH: tc cookie available but was + * unable to match to filter. + */ + SKB_DROP_REASON_TC_COOKIE_MISMATCH, + /** @SKB_DROP_REASON_TC_CHAIN_NOTFOUND: tc chain lookup failed. */ + SKB_DROP_REASON_TC_CHAIN_NOTFOUND, + /** + * @SKB_DROP_REASON_TC_RECLASSIFY_LOOP: tc exceeded max reclassify loop + * iterations. + */ + SKB_DROP_REASON_TC_RECLASSIFY_LOOP, /** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 12ac05857045..429cb232e17b 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1098,7 +1098,8 @@ int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions, } } else if (TC_ACT_EXT_CMP(ret, TC_ACT_GOTO_CHAIN)) { if (unlikely(!rcu_access_pointer(a->goto_chain))) { - tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, + SKB_DROP_REASON_TC_CHAIN_NOTFOUND); return TC_ACT_SHOT; } tcf_action_goto_chain_exec(a, res); diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 13a04463e18e..2dddabba3e9f 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -1683,13 +1683,15 @@ static inline int __tcf_classify(struct sk_buff *skb, */ if (unlikely(n->tp != tp || n->tp->chain != n->chain || !tp->ops->get_exts)) { - tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, + SKB_DROP_REASON_TC_COOKIE_MISMATCH); return TC_ACT_SHOT; } exts = tp->ops->get_exts(tp, n->handle); if (unlikely(!exts || n->exts != exts)) { - tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, + SKB_DROP_REASON_TC_COOKIE_EXT_MISMATCH); return TC_ACT_SHOT; } @@ -1724,7 +1726,8 @@ static inline int __tcf_classify(struct sk_buff *skb, } if (unlikely(n)) { - tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, + SKB_DROP_REASON_TC_COOKIE_MISMATCH); return TC_ACT_SHOT; } @@ -1736,7 +1739,8 @@ static inline int __tcf_classify(struct sk_buff *skb, tp->chain->block->index, tp->prio & 0xffff, ntohs(tp->protocol)); - tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, + SKB_DROP_REASON_TC_RECLASSIFY_LOOP); return TC_ACT_SHOT; } @@ -1774,7 +1778,8 @@ int tcf_classify(struct sk_buff *skb, n = tcf_exts_miss_cookie_lookup(ext->act_miss_cookie, &act_index); if (!n) { - tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, + SKB_DROP_REASON_TC_EXT_COOKIE_NOTFOUND); return TC_ACT_SHOT; } @@ -1785,7 +1790,9 @@ int tcf_classify(struct sk_buff *skb, fchain = tcf_chain_lookup_rcu(block, chain); if (!fchain) { - tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, + SKB_DROP_REASON_TC_CHAIN_NOTFOUND); + return TC_ACT_SHOT; } @@ -1807,10 +1814,9 @@ int tcf_classify(struct sk_buff *skb, ext = tc_skb_ext_alloc(skb); if (WARN_ON_ONCE(!ext)) { - tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR); + tcf_set_drop_reason(skb, SKB_DROP_REASON_NOMEM); return TC_ACT_SHOT; } - ext->chain = last_executed_chain; ext->mru = cb->mru; ext->post_ct = cb->post_ct;