Netdev List
 help / color / mirror / Atom feed
From: Pedro Tammela <pctammela@mojatatu.com>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, jhs@mojatatu.com,
	jiri@resnulli.us
Subject: Re: [PATCH net-next 1/5] net/sched: wrap open coded Qdics class filter counter
Date: Mon, 24 Jul 2023 14:05:55 -0300	[thread overview]
Message-ID: <af86baa5-be74-9d62-7208-df8e12728572@mojatatu.com> (raw)
In-Reply-To: <ZL1tF6QB2jhy1cjw@pop-os.localdomain>

On 23/07/2023 15:10, Cong Wang wrote:
> On Fri, Jul 21, 2023 at 04:13:28PM -0300, Pedro Tammela wrote:
>> The 'filter_cnt' counter is used to control a Qdisc class lifetime.
>> Each filter referecing this class by its id will eventually
>> increment/decrement this counter in their respective
>> 'add/update/delete' routines.
>> As these operations are always serialized under rtnl lock, we don't
>> need an atomic type like 'refcount_t'.
>>
>> It also means that we lose the overflow/underflow checks already
>> present in refcount_t, which are valuable to hunt down bugs
>> where the unsigned counter wraps around as it aids automated tools
>> like syzkaller to scream in such situations.
>>
>> Wrap the open coded increment/decrement into helper functions and
>> add overflow checks to the operations.
> 
> So what's the concern of using refcount_t here? Since we have RTNL lock,
> I don't think performance is a concern.
> 
> I'd prefer to reuse the overflow/underflow with refcount_t than
> open-coding new ones.

I see.
There's a need for another minor adaption as well.
As the 'filter_cnt' starts from 0, it can do 0->1 transitions, which the 
refcount API warns.
So in a refcount_t 'filter_cnt' we would need to initialize it to 1.

I think it's confusing for a variable that represents a count of filters 
have 1 as a nil value.

> 
> 
>> diff --git a/include/net/tc_class.h b/include/net/tc_class.h
>> new file mode 100644
>> index 000000000000..2ab4aa2dba30
>> --- /dev/null
>> +++ b/include/net/tc_class.h
> 
> Why not put these helpers togethre with other qdisc class helpers in
> include/net/sch_generic.h?

OK

> 
> Thanks.


  reply	other threads:[~2023-07-24 17:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-21 19:13 [PATCH net-next 0/5] net/sched: improve class lifetime handling Pedro Tammela
2023-07-21 19:13 ` [PATCH net-next 1/5] net/sched: wrap open coded Qdics class filter counter Pedro Tammela
2023-07-23 18:10   ` Cong Wang
2023-07-24 17:05     ` Pedro Tammela [this message]
2023-07-21 19:13 ` [PATCH net-next 2/5] net/sched: sch_drr: warn about class in use while deleting Pedro Tammela
2023-07-21 19:13 ` [PATCH net-next 3/5] net/sched: sch_hfsc: " Pedro Tammela
2023-07-21 19:13 ` [PATCH net-next 4/5] net/sched: sch_htb: " Pedro Tammela
2023-07-21 19:13 ` [PATCH net-next 5/5] net/sched: sch_qfq: " Pedro Tammela
2023-07-22 12:41 ` [PATCH net-next 0/5] net/sched: improve class lifetime handling Jamal Hadi Salim

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=af86baa5-be74-9d62-7208-df8e12728572@mojatatu.com \
    --to=pctammela@mojatatu.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=xiyou.wangcong@gmail.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