linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Bodo Stroesser <bstroesser@ts.fujitsu.com>
Cc: bfields@fieldses.org, linux-nfs@vger.kernel.org
Subject: Re: [PATCH] sunrpc.ko: RPC cache fix races
Date: Mon, 25 Feb 2013 09:52:41 +1100	[thread overview]
Message-ID: <20130225095241.7e2313af@notabene.brown> (raw)
In-Reply-To: <61eb00$3f9tb7@dgate20u.abg.fsc.net>

[-- Attachment #1: Type: text/plain, Size: 2389 bytes --]

On 21 Feb 2013 16:44:41 +0100 Bodo Stroesser <bstroesser@ts.fujitsu.com>
wrote:

> On 21 Feb 2013 00:55:00 +0100 neilb@suse.de wrote:
> 
> > On 20 Feb 2013 14:57:07 +0100 bstroesser@ts.fujitsu.com wrote:
> > 
> > > On 20 Feb 2013 04:09:00 +0100 neilb@suse.de wrote:
> 
> snip
> 
> > > > Maybe:
> > > > 
> > > >   switch(cache_make_upcall(detail, h)) {
> > > >   case -EINVAL:
> > > >         if (rv) {
> > > > 		set_bit(CACHE_NEGATIVE, &h->flags);
> > > > 		cache_fresh_locked(h, get_seconds() + CACHE_NEW_EXPIRY);
> > > > 		rv = -ENOENT;
> > > > 	}
> > > > 	/* FALLTHROUGH */
> > > >   case -EAGAIN:
> > > > 	cache_fresh_unlocked(h, detail);
> > > >   }
> > > 
> > > I agree, your patch is obviously better than the mine.
> > > But let me suggest one little change: I would like to substitute
> > > cache_fresh_unlocked() by clear_bit() and cache_revisit_request(),
> > > as the call to cache_dequeue() in cache_fresh_unlocked() seems to
> > > be obsolete here:
> > 
> > It is exactly this sort of thinking (on my part) that got us into this mess
> > in the first place.  I reasoned that the full locking/testing/whatever wasn't
> > necessary and took a short cut.  It wasn't a good idea.
> 
> Maybe I'm totally wrong, but AFAICS, calling cache_dequeue() here in extreme
> situations (two threads in parallel calling check_cache() while a first reader
> is going to open cache access) could again cause a race (?)

Can you explain the race you see?

> 
> BTW: if there is a reader for a cache, is there any protection against many
> upcalls being queued for the same cache entry?

The CACHE_PENDING flag should provide that protection.  We only queue an
upcall after "test_and_set", and always dequeue after "clear_bit".

NeilBrown


> 
> Bodo
> 
> > 
> > Given that this is obviously difficult code to get right, we should make it
> > as easy to review as possible.  Have "cache_fresh_unlocked" makes it more
> > obviously correct, and that is a good thing.
> > Maybe cache_dequeue isn't needed here, but it won't hurt so I'd much rather
> > have the clearer code.
> > In fact, I'd also like to change
> > 
> > 			if (test_and_clear_bit(CACHE_PENDING, &ch->flags))
> > 				cache_dequeue(current_detail, ch);
> > 			cache_revisit_request(ch);
> > 
> > near the end of cache_clean to call  cache_fresh_unlocked().
> > 


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

       reply	other threads:[~2013-02-24 23:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <61eb00$3f9tb7@dgate20u.abg.fsc.net>
2013-02-24 22:52 ` NeilBrown [this message]
     [not found] <d6437a$43j82m@dgate10u.abg.fsc.net>
2013-02-26  2:56 ` [PATCH] sunrpc.ko: RPC cache fix races NeilBrown
2013-02-25 19:55 Bodo Stroesser
  -- strict thread matches above, loose matches on Subject: below --
2013-02-21 15:44 Bodo Stroesser
     [not found] <d6437a$434ic3@dgate10u.abg.fsc.net>
2013-02-20 23:55 ` NeilBrown
2013-02-20 13:57 bstroesser
     [not found] <61eb00$3f3hds@dgate20u.abg.fsc.net>
2013-02-20  3:08 ` NeilBrown
     [not found] <61eb00$3f3hdt@dgate20u.abg.fsc.net>
2013-02-19 21:35 ` J. Bruce Fields
2013-02-19 17:08 bstroesser

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=20130225095241.7e2313af@notabene.brown \
    --to=neilb@suse.de \
    --cc=bfields@fieldses.org \
    --cc=bstroesser@ts.fujitsu.com \
    --cc=linux-nfs@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 NNTP newsgroup(s).