Netdev List
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: "Maciej Żenczykowski" <zenczykowski@gmail.com>
Cc: Chenbo Feng <chenbofeng.kernel@gmail.com>,
	Linux NetDev <netdev@vger.kernel.org>,
	netfilter-devel@vger.kernel.org, kernel-team@android.com,
	Lorenzo Colitti <lorenzo@google.com>,
	Chenbo Feng <fengc@google.com>,
	Maciej Zenczykowski <maze@google.com>
Subject: Re: [PATCH net-next] netfilter: xt_quota: fix the behavior of xt_quota module
Date: Tue, 2 Oct 2018 12:11:19 +0200	[thread overview]
Message-ID: <20181002101119.tyljwzqpdj7qoe6f@salvia> (raw)
In-Reply-To: <CANP3RGeo71YYqPENVkEC_XzS+44ANQ9gLV2eX=aZbuc6TMuTAQ@mail.gmail.com>

Hi Maciej!

On Tue, Oct 02, 2018 at 01:24:29AM -0700, Maciej Żenczykowski wrote:
> > A few questions, see below.
> >
> > First one is, don't we need a new match revision for this new option?
> 
> We were very careful to do this in a way that doesn't need a new revision.
> 
> That's what basically dictates most of the design.
> 
> If we bump the revision then you don't get fixed semantics unless
> you update both kernel and userspace iptables versions...

Well, you will need a kernel + userspace update anyway, right?

> and additionally we basically end up with two copies of xt_quota in
> the kernel source since there's pretty much nothing that can be
> shared between the two.

OK. Well, there is still one downside though from user perspective: A
user with new iptables userspace that supports --remain and old kernel
will not get this to work, since this option will be silently accepted
by the kernel, but it will be simply ignored.

I agree having revision infrastructure is limited and results in more
duplicated code, but this is what we have in iptables.

> > So 1 means, don't keep updating, quota is depleted?
> 
> The counter is always 1 higher then the remaining quota.
> So 1 means 0.
> And 0 means uninitialized and is only present on input from userspace.

OK.

> > This current_count = 1 would be exposed to userspace too, right?
> >
> > Hm, this semantics are going to be a bit awkwards to users I think, I
> > would prefer to expose this in a different way.
> 
> New userspace iptables hides this from users by adding/decrementing by
> one as needed on ingress/egress from kernel.
> Old iptables never looks at this field.

I see, indeed.

> >> +             if (current_count <= skb->len) {
> >> +                     atomic64_set(&q->counter, 1);
> >> +                     return ret;
> >> +             }
> >> +             old_count = current_count;
> >> +             new_count = current_count - skb->len;
> >> +             current_count = atomic64_cmpxchg(&q->counter, old_count,
> >> +                                              new_count);
> >> +     } while (current_count != old_count);
> >
> > Probably we simplify this via atomic64_add_return()?
> 
> Unfortunately that doesn't work because it's racy if current value is
> 2 and two (or three) threads both add -1 you end up at zero (or even
> +lots).

Hm, not sure what you mean with adding -1. I mean replacing all this
code above with something like:

        ret = (atomic64_add_return(skb->len, &consumed) >= quota) ^ XT_QUOTA_INVERT;

But I might be missing anything from your response on why this is
racy.

> > I guess problem is userspace may get a current counter that is larger
> > than the quota, but we could handle this from userspace iptables to
> > print a value that equals the quota, ie. from userspace, before
> > printing:
> 
> I'm not sure what you mean.

I mean: Instead of using atomic64_set() to set the counter to 1 once
we went over quota,

Please, don't get this as some sort of push back / I'm saying no to
this as it is.

I just would like we are aware of possible downsides with this
approach. Having said this, I'll take it as is if you insist that this
is the right approach :-)

Thanks !

  parent reply	other threads:[~2018-10-02 16:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02  1:23 [PATCH net-next iptables] Rework the xt_quota module Chenbo Feng
2018-10-02  1:23 ` [PATCH iptables] extensions: libxt_quota: Allow setting the remaining quota Chenbo Feng
2018-10-08 23:16   ` Pablo Neira Ayuso
2018-10-02  1:23 ` [PATCH net-next] netfilter: xt_quota: fix the behavior of xt_quota module Chenbo Feng
2018-10-02  7:59   ` Pablo Neira Ayuso
2018-10-02  8:24     ` Maciej Żenczykowski
2018-10-02  8:25       ` Maciej Żenczykowski
2018-10-02 10:11       ` Pablo Neira Ayuso [this message]
2018-10-02 10:15         ` Pablo Neira Ayuso
2018-10-02 10:38           ` Maciej Żenczykowski
2018-10-02 10:51             ` Pablo Neira Ayuso
2018-10-02 10:52               ` Pablo Neira Ayuso
2018-10-02 17:45               ` Chenbo Feng
2018-10-02 18:15                 ` Pablo Neira Ayuso
2018-10-02 18:28                   ` Chenbo Feng
2018-10-02 18:43                     ` Pablo Neira Ayuso
2018-10-02 22:22                       ` Maciej Żenczykowski
2018-10-03  9:19   ` Pablo Neira Ayuso
2018-10-03  9:26     ` Maciej Żenczykowski
2018-10-03  9:28       ` Pablo Neira Ayuso
2018-10-03 15:37   ` Pablo Neira Ayuso

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=20181002101119.tyljwzqpdj7qoe6f@salvia \
    --to=pablo@netfilter.org \
    --cc=chenbofeng.kernel@gmail.com \
    --cc=fengc@google.com \
    --cc=kernel-team@android.com \
    --cc=lorenzo@google.com \
    --cc=maze@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=zenczykowski@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