RE: [PATCH] kcov: convert kcov.refcount to refcount_t

From: Reshetova, Elena
Date: Fri Jan 25 2019 - 04:02:49 EST


> > I suppose we can add smp_acquire__after_ctrl_dep() on the true branch.
> > Then it reall does become rel_acq.
> >
> > A wee something like so (I couldn't find an arm64 refcount, even though
> > I have distinct memories of talk about it).
>
> In the end, arm and arm64 chose to use REFCOUNT_FULL unconditionally,
> so there's no arch-specific implementation.
>
> > This isn't compiled, and obviously needs comment/documentation updates
> > to go along with it.
>
> Elena, can you do the doc updates?

Well, doc updates should go with below patch + and additional testing...

Peter, should I create a full version from below with doc/comments
updates, run the whole thing via zero day and send to you if it all looks ok?

Best Regards,
Elena.

> >
> > ---
> > arch/x86/include/asm/refcount.h | 9 ++++++++-
> > lib/refcount.c | 7 ++++++-
> > 2 files changed, 14 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/refcount.h b/arch/x86/include/asm/refcount.h
> > index dbaed55c1c24..6f7a1eb345b4 100644
> > --- a/arch/x86/include/asm/refcount.h
> > +++ b/arch/x86/include/asm/refcount.h
> > @@ -74,9 +74,16 @@ bool refcount_sub_and_test(unsigned int i, refcount_t *r)
> >
> > static __always_inline __must_check bool refcount_dec_and_test(refcount_t *r)
> > {
> > - return GEN_UNARY_SUFFIXED_RMWcc(LOCK_PREFIX "decl",
> > + bool ret = GEN_UNARY_SUFFIXED_RMWcc(LOCK_PREFIX "decl",
> > REFCOUNT_CHECK_LT_ZERO,
> > r->refs.counter, e, "cx");
> > +
> > + if (ret) {
> > + smp_acquire__after_ctrl_dep();
> > + return true;
> > + }
> > +
> > + return false;
> > }
> >
> > static __always_inline __must_check
> > diff --git a/lib/refcount.c b/lib/refcount.c
> > index ebcf8cd49e05..8276ad349d48 100644
> > --- a/lib/refcount.c
> > +++ b/lib/refcount.c
> > @@ -190,7 +190,12 @@ bool refcount_sub_and_test_checked(unsigned int i,
> refcount_t *r)
> >
> > } while (!atomic_try_cmpxchg_release(&r->refs, &val, new));
> >
> > - return !new;
> > + if (!new) {
> > + smp_acquire__after_ctrl_dep();
> > + return true;
> > + }
> > +
> > + return false;
> > }
> > EXPORT_SYMBOL(refcount_sub_and_test_checked);
> >
>
> Thanks for this!
>
> --
> Kees Cook