From: Maarten Lankhorst <maarten.lankhorst@canonical.com>
To: Thomas Hellstrom <thellstrom@vmware.com>
Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
ccross@google.com, linux-media@vger.kernel.org
Subject: Re: [RFC PATCH 2/2 with seqcount v3] reservation: add suppport for read-only access using rcu
Date: Mon, 19 May 2014 16:13:20 +0200 [thread overview]
Message-ID: <537A1180.2010109@canonical.com> (raw)
In-Reply-To: <537A0A5D.6090909@vmware.com>
op 19-05-14 15:42, Thomas Hellstrom schreef:
> Hi, Maarten!
>
> Some nitpicks, and that krealloc within rcu lock still worries me.
> Otherwise looks good.
>
> /Thomas
>
>
>
> On 04/23/2014 12:15 PM, Maarten Lankhorst wrote:
>> @@ -55,8 +60,8 @@ int reservation_object_reserve_shared(struct
>> reservation_object *obj)
>> kfree(obj->staged);
>> obj->staged = NULL;
>> return 0;
>> - }
>> - max = old->shared_max * 2;
>> + } else
>> + max = old->shared_max * 2;
> Perhaps as a separate reformatting patch?
I'll fold it in to the patch that added reservation_object_reserve_shared.
>> +
>> +int reservation_object_get_fences_rcu(struct reservation_object *obj,
>> + struct fence **pfence_excl,
>> + unsigned *pshared_count,
>> + struct fence ***pshared)
>> +{
>> + unsigned shared_count = 0;
>> + unsigned retry = 1;
>> + struct fence **shared = NULL, *fence_excl = NULL;
>> + int ret = 0;
>> +
>> + while (retry) {
>> + struct reservation_object_list *fobj;
>> + unsigned seq;
>> +
>> + seq = read_seqcount_begin(&obj->seq);
>> +
>> + rcu_read_lock();
>> +
>> + fobj = rcu_dereference(obj->fence);
>> + if (fobj) {
>> + struct fence **nshared;
>> +
>> + shared_count = ACCESS_ONCE(fobj->shared_count);
> ACCESS_ONCE() shouldn't be needed inside the seqlock?
Yes it is, shared_count may be increased, leading to potential different sizes for krealloc and memcpy
if the ACCESS_ONCE is removed. I could use shared_max here instead, which stays the same,
but it would waste more memory.
>> + nshared = krealloc(shared, sizeof(*shared) *
>> shared_count, GFP_KERNEL);
> Again, krealloc should be a sleeping function, and not suitable within a
> RCU read lock? I still think this krealloc should be moved to the start
> of the retry loop, and we should start with a suitable guess of
> shared_count (perhaps 0?) It's not like we're going to waste a lot of
> memory....
But shared_count is only known when holding the rcu lock.
What about this change?
@@ -254,16 +254,27 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj,
fobj = rcu_dereference(obj->fence);
if (fobj) {
struct fence **nshared;
+ size_t sz;
shared_count = ACCESS_ONCE(fobj->shared_count);
- nshared = krealloc(shared, sizeof(*shared) * shared_count, GFP_KERNEL);
+ sz = sizeof(*shared) * shared_count;
+
+ nshared = krealloc(shared, sz,
+ GFP_NOWAIT | __GFP_NOWARN);
if (!nshared) {
+ rcu_read_unlock();
+ nshared = krealloc(shared, sz, GFP_KERNEL)
+ if (nshared) {
+ shared = nshared;
+ continue;
+ }
+
ret = -ENOMEM;
- shared_count = retry = 0;
- goto unlock;
+ shared_count = 0;
+ break;
}
shared = nshared;
- memcpy(shared, fobj->shared, sizeof(*shared) * shared_count);
+ memcpy(shared, fobj->shared, sz);
} else
shared_count = 0;
fence_excl = rcu_dereference(obj->fence_excl);
>> +
>> + /*
>> + * There could be a read_seqcount_retry here, but nothing cares
>> + * about whether it's the old or newer fence pointers that are
>> + * signale. That race could still have happened after checking
> Typo.
Oops.
next prev parent reply other threads:[~2014-05-19 14:13 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-09 14:48 [PATCH 0/2] Updates to fence api Maarten Lankhorst
2014-04-09 14:48 ` Maarten Lankhorst
2014-04-09 14:48 ` [PATCH 1/2] reservation: update api and add some helpers Maarten Lankhorst
2014-04-09 14:48 ` Maarten Lankhorst
2014-04-09 14:49 ` [PATCH 2/2] [RFC] reservation: add suppport for read-only access using rcu Maarten Lankhorst
2014-04-09 14:49 ` Maarten Lankhorst
2014-04-10 8:46 ` Thomas Hellstrom
2014-04-10 8:46 ` Thomas Hellstrom
2014-04-10 10:07 ` Maarten Lankhorst
2014-04-10 10:07 ` Maarten Lankhorst
2014-04-10 11:08 ` Thomas Hellstrom
2014-04-10 11:25 ` Thomas Hellstrom
2014-04-10 11:25 ` Thomas Hellstrom
2014-04-10 15:00 ` [PATCH 2/2] [RFC v2 with seqcount] " Maarten Lankhorst
2014-04-10 15:00 ` Maarten Lankhorst
2014-04-11 8:38 ` Thomas Hellstrom
2014-04-11 8:38 ` Thomas Hellstrom
2014-04-11 9:24 ` Maarten Lankhorst
2014-04-11 9:24 ` Maarten Lankhorst
2014-04-11 10:11 ` Thomas Hellstrom
2014-04-11 10:11 ` Thomas Hellstrom
2014-04-11 18:09 ` Maarten Lankhorst
2014-04-11 18:09 ` Maarten Lankhorst
2014-04-11 19:30 ` Thomas Hellstrom
2014-04-11 19:30 ` Thomas Hellstrom
2014-04-14 7:04 ` Maarten Lankhorst
2014-04-11 19:35 ` Thomas Hellstrom
2014-04-11 19:35 ` Thomas Hellstrom
2014-04-14 7:42 ` Maarten Lankhorst
2014-04-14 7:42 ` Maarten Lankhorst
2014-04-14 7:45 ` Thomas Hellstrom
2014-04-14 7:45 ` Thomas Hellstrom
2014-04-23 11:15 ` [RFC PATCH 2/2 with seqcount v3] " Maarten Lankhorst
2014-04-23 11:15 ` Maarten Lankhorst
2014-04-29 14:32 ` Maarten Lankhorst
2014-04-29 14:32 ` Maarten Lankhorst
2014-04-29 18:55 ` Thomas Hellstrom
2014-04-29 18:55 ` Thomas Hellstrom
2014-05-19 13:42 ` Thomas Hellstrom
2014-05-19 13:42 ` Thomas Hellstrom
2014-05-19 14:13 ` Maarten Lankhorst [this message]
2014-05-19 14:13 ` Maarten Lankhorst
2014-05-19 14:43 ` Thomas Hellstrom
2014-05-19 14:43 ` Thomas Hellstrom
2014-05-20 15:13 ` Thomas Hellstrom
2014-05-20 15:13 ` Thomas Hellstrom
2014-05-20 15:32 ` Maarten Lankhorst
2014-05-20 15:32 ` Maarten Lankhorst
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=537A1180.2010109@canonical.com \
--to=maarten.lankhorst@canonical.com \
--cc=ccross@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=thellstrom@vmware.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).