perfbook.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: Akira Yokosawa <akiyks@gmail.com>
Cc: Alan Huang <mmpgouride@gmail.com>, perfbook@vger.kernel.org
Subject: Re: [PATCH v2] CodeSamples/defer: Fix hazard torture
Date: Mon, 24 Apr 2023 08:44:28 -0700	[thread overview]
Message-ID: <382e0a57-28c9-4da1-9474-abcdbe84d46d@paulmck-laptop> (raw)
In-Reply-To: <c5b09b36-1b3f-6d03-2dda-ad2514c71de9@gmail.com>

On Sat, Apr 22, 2023 at 08:56:17PM +0900, Akira Yokosawa wrote:
> On Sat, 22 Apr 2023 10:34:21 +0000, Alan Huang wrote:
> > Because hp_try_record() must check for concurrent modifications,
> > we should not dereference the pointer. The arg of hazptr_read_stress_test
> > is always NULL, which is designated at time when create the thread,
> > therefore, all threads will store their hazard pointer in the same slot.
> > Also, hazptr_thread_exit will clear their own hazard pointer from
> > smp_thread_id() * K.
> > 
> > Signed-off-by: Alan Huang <mmpgouride@gmail.com>
> 
> Now I see all your points.  Thank you for your thorough review
> of the code!
> 
> As I mentioned earlier, the deref of p was introduced by commit
> a082aba85ce0 ("defer/hazptr: Checkpoint for text/code update"),
> while the uses of arg in hazptr_read_stress_test() and
> hazptr_read_perf_test() were there since the addition of this code
> by commit c672535d475a ("Convert Tom Hart's hazard-pointer
> implementation to perfbook"), that is, if I'm reading the code
> correctly.
> 
> So,
> 
> Reviewed-by: Akira Yokosawa <akiyks@gmail.com>
> Fixes: c672535d475a ("Convert Tom Hart's hazard-pointer implementation to perfbook")
> Fixes: a082aba85ce0 ("defer/hazptr: Checkpoint for text/code update")

Now -that- is what I call an embarrassing bug!

Thank you both for tracking it down and for the fix!!!

Queued and pushed.

							Thanx, Paul

>         Thanks, Akira
> 
> > ---
> >  CodeSamples/defer/hazptr.h        | 2 +-
> >  CodeSamples/defer/hazptrtorture.h | 5 ++---
> >  2 files changed, 3 insertions(+), 4 deletions(-)
> > 
> > diff --git a/CodeSamples/defer/hazptr.h b/CodeSamples/defer/hazptr.h
> > index 759ab53d..e061303d 100644
> > --- a/CodeSamples/defer/hazptr.h
> > +++ b/CodeSamples/defer/hazptr.h
> > @@ -87,7 +87,7 @@ static inline void *hp_record(void **p,			//\lnlbl{hr:b}
> >  	void *tmp;
> >  
> >  	do {
> > -		tmp = hp_try_record(*p, hp);
> > +		tmp = hp_try_record(p, hp);
> >  	} while (tmp == (void *)HAZPTR_POISON);
> >  	return tmp;
> >  }							//\lnlbl{hr:e}
> > diff --git a/CodeSamples/defer/hazptrtorture.h b/CodeSamples/defer/hazptrtorture.h
> > index 53efa259..acdd532b 100644
> > --- a/CodeSamples/defer/hazptrtorture.h
> > +++ b/CodeSamples/defer/hazptrtorture.h
> > @@ -99,7 +99,7 @@ void *hazptr_read_perf_test(void *arg)
> >  {
> >  	int i;
> >  	int me = (long)arg;
> > -	int base = me * K;
> > +	int base = smp_thread_id() * K;
> >  	long long n_reads_local = 0;
> >  	hazptr_head_t hh;
> >  	hazptr_head_t *hhp = &hh;
> > @@ -241,8 +241,7 @@ DEFINE_PER_THREAD(long long [HAZPTR_STRESS_PIPE_LEN + 1], hazptr_stress_count);
> >  
> >  void *hazptr_read_stress_test(void *arg)
> >  {
> > -	int me = (int)(long)arg;
> > -	int base = me * K;
> > +	int base = smp_thread_id() * K;
> >  	struct hazptr_stress *p;
> >  	int pc;
> >  

      reply	other threads:[~2023-04-24 15:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-22 10:34 [PATCH v2] CodeSamples/defer: Fix hazard torture Alan Huang
2023-04-22 10:39 ` Alan Huang
2023-04-22 11:56 ` Akira Yokosawa
2023-04-24 15:44   ` Paul E. McKenney [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=382e0a57-28c9-4da1-9474-abcdbe84d46d@paulmck-laptop \
    --to=paulmck@kernel.org \
    --cc=akiyks@gmail.com \
    --cc=mmpgouride@gmail.com \
    --cc=perfbook@vger.kernel.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).