Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1652490

Re: [PATCH 0/3] ipc subsystem refcounter conversions

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [PATCH 0/3] ipc subsystem refcounter conversions
Date 2017-05-29 14:30 +0200
Message-ID <tMrY6-8e7-15@gated-at.bofh.it> (permalink)
References (4 earlier) <tMp0g-6bg-69@gated-at.bofh.it> <tMq5X-6Uy-15@gated-at.bofh.it> <tMqz0-77t-9@gated-at.bofh.it> <tMrbI-7Eh-5@gated-at.bofh.it> <tMrln-7Ii-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, May 29, 2017 at 06:39:44AM -0500, Eric W. Biederman wrote:
> I failed to see that there is a refcount_inc.  Too much noise in
> the header file I suppose.
> 
> But implementing refcount_inc in terms of refcount_inc_not_zero is
> totally broken.  The two operations are not the same and the go to
> different assumptions the code is making.
> 
> That explains why you think refcount_inc_not_zero should lie because
> you are implementing refcount_inc with it.  They are semantically very
> different operations.  Please separate them.

There has been much debate about this. And the best I'll do is add a
comment and/or retain these exact semantics.

What is done is:

	refcount_inc() := WARN_ON(!refcount_inc_not_zero())

Because incrementing a zero reference count is a use-after-free and
something we should not do ever.

This is where the whole usage count vs reference count pain comes from.

Once there are no more _references_ to an object, a reference count
frees the object. Therefore a zero reference count means a dead object
and incrementing from that is fail.

The usage count model otoh counts how many (active) users there are of
an object, and no active users is a good and expected situation. But it
is very explicitly not a reference count. Because even in the no users
case do we have a reference to the object (we've not leaked it after
all, we just don't track all references).


Similarly, refcount_dec() is implemented using dec_and_test() and will
WARN when it hits 0, because this is a leak and we don't want those
either.

A usage count variant otoh would be fine with hitting 0.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH 0/3] ipc subsystem refcounter conversions Kees Cook <keescook@chromium.org> - 2017-05-27 22:00 +0200
  Re: [PATCH 0/3] ipc subsystem refcounter conversions Christoph Hellwig <hch@infradead.org> - 2017-05-29 10:40 +0200
    Re: [PATCH 0/3] ipc subsystem refcounter conversions ebiederm@xmission.com (Eric W. Biederman) - 2017-05-29 11:20 +0200
      Re: [PATCH 0/3] ipc subsystem refcounter conversions Peter Zijlstra <peterz@infradead.org> - 2017-05-29 12:30 +0200
        Re: [PATCH 0/3] ipc subsystem refcounter conversions ebiederm@xmission.com (Eric W. Biederman) - 2017-05-29 13:00 +0200
          Re: [PATCH 0/3] ipc subsystem refcounter conversions ebiederm@xmission.com (Eric W. Biederman) - 2017-05-29 13:40 +0200
            Re: [PATCH 0/3] ipc subsystem refcounter conversions ebiederm@xmission.com (Eric W. Biederman) - 2017-05-29 13:50 +0200
              Re: [PATCH 0/3] ipc subsystem refcounter conversions Peter Zijlstra <peterz@infradead.org> - 2017-05-29 14:30 +0200
                Re: [PATCH 0/3] ipc subsystem refcounter conversions Peter Zijlstra <peterz@infradead.org> - 2017-05-29 17:50 +0200
          Re: [PATCH 0/3] ipc subsystem refcounter conversions Peter Zijlstra <peterz@infradead.org> - 2017-05-29 14:20 +0200

csiph-web