From: "Othman, Ossama" <ossama.othman@intel.com>
To: "Henri Häkkinen" <henrih81@gmail.com>,
"Alan Cox" <alan@lxorguk.ukuu.org.uk>
Cc: "gregkh@suse.de" <gregkh@suse.de>,
Matti Lammi <mattij.lammi@gmail.com>,
"randy.dunlap@oracle.com" <randy.dunlap@oracle.com>,
"devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] Staging: memrar: Moved memrar_allocator struct into memrar_allocator.c
Date: Thu, 24 Jun 2010 10:46:41 -0700 [thread overview]
Message-ID: <A5FE05C4C76E4C4CAB15D9962B96FC950CEA181645@orsmsx510.amr.corp.intel.com> (raw)
In-Reply-To: <1C8E6A7A-45FE-4862-A6AD-397548588F96@gmail.com>
Hi,
> >> size_t memrar_allocator_largest_free_area(struct memrar_allocator
> *allocator)
> >> {
> >> - if (allocator == NULL)
> >> - return 0;
> >> - return allocator->largest_free_area;
> >> + size_t tmp = 0;
> >> +
> >> + if (allocator != NULL) {
> >> + mutex_lock(&allocator->lock);
> >> + tmp = allocator->largest_free_area;
> >> + mutex_unlock(&allocator->lock);
> >
> > This doesn't seem to make any sense (in either version). The moment
> you
> > drop the lock the value in "tmp" becomes stale as the allocator could
> > change it. ?
> >
>
> The idea was proposed by Ossama Othman in his earlier reply.
:-)
[OO] > > Certainly the allocator->largest_free_area value could be updated
> after the lock is released and by the time it is returned to the user
> (for statistical purposes), but at least the internal allocator state
> would remain consistent in the presences of multiple threads.
My suggestion focused solely on hiding the allocator lock from the caller. The TOCTOU race I alluded to above exists in the current version of the code, and was not introduced with the change I proposed to your patch.
HTH,
-Ossama
next prev parent reply other threads:[~2010-06-24 17:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-14 12:40 [PATCH] Staging: memrar: Moved memrar_allocator struct into memrar_allocator.c Henri Häkkinen
2010-06-23 17:51 ` Othman, Ossama
2010-06-24 9:35 ` Fwd: " Henri Häkkinen
2010-06-24 17:46 ` Othman, Ossama [this message]
2010-06-23 22:17 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2010-06-14 11:54 Henri Häkkinen
2010-06-22 22:00 ` Greg KH
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=A5FE05C4C76E4C4CAB15D9962B96FC950CEA181645@orsmsx510.amr.corp.intel.com \
--to=ossama.othman@intel.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@suse.de \
--cc=henrih81@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mattij.lammi@gmail.com \
--cc=randy.dunlap@oracle.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;
as well as URLs for NNTP newsgroup(s).