From: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
To: "Eugeniy.Paltsev@synopsys.com" <Eugeniy.Paltsev@synopsys.com>,
"Vineet Gupta" <Vineet.Gupta1@synopsys.com>,
"linux-snps-arc@lists.infradead.org"
<linux-snps-arc@lists.infradead.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"peterz@infradead.org" <peterz@infradead.org>,
Alexey Brodkin <Alexey.Brodkin@synopsys.com>,
"will.deacon@arm.com" <will.deacon@arm.com>,
"boqun.feng@gmail.com" <boqun.feng@gmail.com>
Subject: Re: [PATCH] ARC: atomic64: fix atomic64_add_unless function
Date: Tue, 14 Aug 2018 14:35:02 +0000 [thread overview]
Message-ID: <1534257301.3962.79.camel@synopsys.com> (raw)
In-Reply-To: <C2D7FE5348E1B147BCA15975FBA23075012B08CB78@us01wembx1.internal.synopsys.com>
On Tue, 2018-08-14 at 13:42 +0000, Vineet Gupta wrote:
> On 08/11/2018 09:09 AM, Eugeniy Paltsev wrote:
> > Current implementation of 'atomic64_add_unless' function
> > (and hence 'atomic64_inc_not_zero') return incorrect value
> > if lover 32 bits of compared 64-bit number are equal and
> > higher 32 bits aren't.
> >
> > For in following example atomic64_add_unless must return '1'
> > but it actually returns '0':
> > --------->8---------
> > atomic64_t val = ATOMIC64_INIT(0x4444000000000000LL);
> > int ret = atomic64_add_unless(&val, 1LL, 0LL)
> > --------->8---------
> >
> > This happens because we write '0' to returned variable regardless
> > of higher 32 bits comparison result.
> >
> > So fix it.
> >
> > NOTE:
> > this change was tested with atomic64_test.
> >
> > Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
>
> LGTM. Curious, was this from code review or did u actually run into this ?
I've accidentally run into this when I played with atomic64_* functions
trying to implement hack to automatically align LL64/SC64 data for atomic 64-bit
operations on ARC to avoid problems like:
https://www.mail-archive.com/linux-snps-arc@lists.infradead.org/msg03791.html
> Thx,
> -Vineet
>
> > ---
> > arch/arc/include/asm/atomic.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/arc/include/asm/atomic.h b/arch/arc/include/asm/atomic.h
> > index 11859287c52a..e840cb1763b2 100644
> > --- a/arch/arc/include/asm/atomic.h
> > +++ b/arch/arc/include/asm/atomic.h
> > @@ -578,11 +578,11 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
> >
> > __asm__ __volatile__(
> > "1: llockd %0, [%2] \n"
> > - " mov %1, 1 \n"
> > " brne %L0, %L4, 2f # continue to add since v != u \n"
> > " breq.d %H0, %H4, 3f # return since v == u \n"
> > " mov %1, 0 \n"
> > "2: \n"
> > + " mov %1, 1 \n"
> > " add.f %L0, %L0, %L3 \n"
> > " adc %H0, %H0, %H3 \n"
> > " scondd %0, [%2] \n"
>
>
--
Eugeniy Paltsev
prev parent reply other threads:[~2018-08-14 14:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-11 16:08 [PATCH] ARC: atomic64: fix atomic64_add_unless function Eugeniy Paltsev
2018-08-14 13:42 ` Vineet Gupta
2018-08-14 14:35 ` Eugeniy Paltsev [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=1534257301.3962.79.camel@synopsys.com \
--to=eugeniy.paltsev@synopsys.com \
--cc=Alexey.Brodkin@synopsys.com \
--cc=Vineet.Gupta1@synopsys.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-snps-arc@lists.infradead.org \
--cc=peterz@infradead.org \
--cc=will.deacon@arm.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