From: Jamal Hadi Salim <jhs@mojatatu.com>
To: Eric Dumazet <edumazet@google.com>
Cc: renmingshuai <renmingshuai@huawei.com>,
xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net,
vladbu@nvidia.com, netdev@vger.kernel.org, yanan@huawei.com,
liaichun@huawei.com, caowangbao@huawei.com,
Eric Dumazet <eric.dumazet@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Victor Nogueira <victor@mojatatu.com>,
Pedro Tammela <pctammela@mojatatu.com>,
Davide Caratti <dcaratti@redhat.com>
Subject: Re: [PATCH] net/sched: Forbid assigning mirred action to a filter attached to the egress
Date: Tue, 26 Mar 2024 19:18:54 -0400 [thread overview]
Message-ID: <CAM0EoMkQMgYF5isb9JOQDbUhoq3VeEt3a8L2qyD4xUfrtyyGYw@mail.gmail.com> (raw)
In-Reply-To: <CAM0EoM=28nsomF9PniYNtpjD4+=+hVi-dA2befgW0OCz+v0y3Q@mail.gmail.com>
On Sun, Mar 24, 2024 at 11:27 AM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
>
> On Wed, Mar 20, 2024 at 3:34 PM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> >
> > On Wed, Mar 20, 2024 at 2:26 PM Eric Dumazet <edumazet@google.com> wrote:
> > >
> > > On Wed, Mar 20, 2024 at 7:13 PM Eric Dumazet <edumazet@google.com> wrote:
> > > >
> > > > On Wed, Mar 20, 2024 at 6:50 PM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> > >
> > > > Nope, you just have to complete the patch, moving around
> > > > dev_xmit_recursion_inc() and dev_xmit_recursion_dec()
> > >
> > > Untested part would be:
> > >
> > > diff --git a/net/core/dev.c b/net/core/dev.c
> > > index 303a6ff46e4e16296e94ed6b726621abe093e567..dbeaf67282e8b6ec164d00d796c9fd8e4fd7c332
> > > 100644
> > > --- a/net/core/dev.c
> > > +++ b/net/core/dev.c
> > > @@ -4259,6 +4259,8 @@ int __dev_queue_xmit(struct sk_buff *skb, struct
> > > net_device *sb_dev)
> > > */
> > > rcu_read_lock_bh();
> > >
> > > + dev_xmit_recursion_inc();
> > > +
> > > skb_update_prio(skb);
> > >
> > > qdisc_pkt_len_init(skb);
> > > @@ -4331,9 +4333,7 @@ int __dev_queue_xmit(struct sk_buff *skb, struct
> > > net_device *sb_dev)
> > > HARD_TX_LOCK(dev, txq, cpu);
> > >
> > > if (!netif_xmit_stopped(txq)) {
> > > - dev_xmit_recursion_inc();
> > > skb = dev_hard_start_xmit(skb, dev, txq, &rc);
> > > - dev_xmit_recursion_dec();
> > > if (dev_xmit_complete(rc)) {
> > > HARD_TX_UNLOCK(dev, txq);
> > > goto out;
> > > @@ -4353,12 +4353,14 @@ int __dev_queue_xmit(struct sk_buff *skb,
> > > struct net_device *sb_dev)
> > > }
> > >
> > > rc = -ENETDOWN;
> > > + dev_xmit_recursion_dec();
> > > rcu_read_unlock_bh();
> > >
> > > dev_core_stats_tx_dropped_inc(dev);
> > > kfree_skb_list(skb);
> > > return rc;
> > > out:
> > > + dev_xmit_recursion_dec();
> > > rcu_read_unlock_bh();
> > > return rc;
> > > }
> >
> > This removed the deadlock but now every packet being redirected will
> > be dropped. I was wrong earlier on the tc block because that only
> > works on clsact and ingress which are fine not needing this lock.
> > Here's a variation of the earlier patch that may work but comes at the
> > cost of a new per-cpu increment on the qdisc.
> >
> > --- a/net/core/dev.c
> > +++ b/net/core/dev.c
> > @@ -3789,6 +3789,11 @@ static inline int __dev_xmit_skb(struct sk_buff
> > *skb, struct Qdisc *q,
> > if (unlikely(contended))
> > spin_lock(&q->busylock);
> >
> > + if (__this_cpu_read(q->recursion_xmit) > 0) {
> > + //drop
> > + }
> > +
> > + __this_cpu_inc(q->recursion_xmit);
> > spin_lock(root_lock);
> > if (unlikely(test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) {
> > __qdisc_drop(skb, &to_free);
> > @@ -3825,6 +3830,7 @@ static inline int __dev_xmit_skb(struct sk_buff
> > *skb, struct Qdisc *q,
> > }
> > }
> > spin_unlock(root_lock);
> > + __this_cpu_dec(q->recursion_xmit);
> > if (unlikely(to_free))
> > kfree_skb_list_reason(to_free,
> > tcf_get_drop_reason(to_free));
> >
>
> And here's a tested version(attached) that fixes both the A->A and A->B->A.
Sent a proper patch as RFC, Eric please take a look.
cheers,
jamal
> cheers,
> jamal
prev parent reply other threads:[~2024-03-26 23:19 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-14 11:17 [PATCH] net/sched: Forbid assigning mirred action to a filter attached to the egress renmingshuai
2024-03-14 11:43 ` Jiri Pirko
2024-03-14 14:04 ` renmingshuai
2024-03-14 14:47 ` Pedro Tammela
2024-03-14 17:14 ` Jamal Hadi Salim
2024-03-15 1:56 ` renmingshuai
2024-03-15 22:34 ` Jamal Hadi Salim
2024-03-17 16:10 ` Jamal Hadi Salim
2024-03-18 14:27 ` Jamal Hadi Salim
2024-03-18 15:46 ` Eric Dumazet
2024-03-18 17:36 ` Jamal Hadi Salim
2024-03-18 19:11 ` Eric Dumazet
2024-03-18 22:05 ` Jamal Hadi Salim
2024-03-19 9:38 ` Eric Dumazet
2024-03-19 20:54 ` Jamal Hadi Salim
2024-03-20 16:46 ` Jamal Hadi Salim
2024-03-20 16:57 ` Eric Dumazet
2024-03-20 17:31 ` Jamal Hadi Salim
2024-03-20 17:50 ` Jamal Hadi Salim
2024-03-20 18:13 ` Eric Dumazet
2024-03-20 18:25 ` Eric Dumazet
2024-03-20 19:34 ` Jamal Hadi Salim
2024-03-24 15:27 ` Jamal Hadi Salim
2024-03-26 23:18 ` Jamal Hadi Salim [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAM0EoMkQMgYF5isb9JOQDbUhoq3VeEt3a8L2qyD4xUfrtyyGYw@mail.gmail.com \
--to=jhs@mojatatu.com \
--cc=caowangbao@huawei.com \
--cc=davem@davemloft.net \
--cc=dcaratti@redhat.com \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=liaichun@huawei.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pctammela@mojatatu.com \
--cc=renmingshuai@huawei.com \
--cc=victor@mojatatu.com \
--cc=vladbu@nvidia.com \
--cc=xiyou.wangcong@gmail.com \
--cc=yanan@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).