From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun.feng@gmail.com>,
linux-kernel@vger.kernel.org, Hillf Danton <hdanton@sina.com>
Subject: Re: [PATCH v2 2/3] locking/rwsem: Enable early rwsem writer lock handoff
Date: Thu, 23 Feb 2023 09:16:33 -0500 [thread overview]
Message-ID: <0e036ff5-c0f1-96a7-cb07-222c7552201f@redhat.com> (raw)
In-Reply-To: <Y/dc01A9+k6KuHTc@hirez.programming.kicks-ass.net>
On 2/23/23 07:32, Peter Zijlstra wrote:
> On Thu, Feb 16, 2023 at 04:09:32PM -0500, Waiman Long wrote:
>> @@ -432,19 +433,39 @@ static void rwsem_mark_wake(struct rw_semaphore *sem,
>> * Mark writer at the front of the queue for wakeup.
>> * Until the task is actually later awoken later by
>> * the caller, other writers are able to steal it.
>> + *
>> + * *Unless* HANDOFF is set, in which case only the
>> + * first waiter is allowed to take it.
>> + *
>> * Readers, on the other hand, will block as they
>> * will notice the queued writer.
>> */
>> wake_q_add(wake_q, waiter->task);
>> lockevent_inc(rwsem_wake_writer);
>> +
>> + if ((count & RWSEM_LOCK_MASK) || !(count & RWSEM_FLAG_HANDOFF))
>> + return;
>> +
>> + /*
>> + * If the rwsem is free and handoff flag is set with wait_lock
>> + * held, no other CPUs can take an active lock. We can do an
>> + * early handoff.
>> + */
>> + adjustment = RWSEM_WRITER_LOCKED - RWSEM_FLAG_HANDOFF;
>> + atomic_long_set(&sem->owner, (long)waiter->task);
>> + waiter->task = NULL;
>> + atomic_long_add(adjustment, &sem->count);
>> + rwsem_del_waiter(sem, waiter);
>> + lockevent_inc(rwsem_wlock_ehandoff);
>> }
> *sigh*... you can't even properly copy/paste from the reader side :/
> This is broken, the moment you do waiter->task = NULL, waiter can
> dissapear from under you and that rwsem_del_waiter() is a UaF.
>
> Nor did you unify the reader and writer side and still have a giant
> trainwreck on your hands..
>
> Surely all that isn't too hard... let me post it.
>
Right, I should keep the clearing after deleting the waiter. Thanks for
spotting that. I will review your patches soon.
Cheers,
Longman
next prev parent reply other threads:[~2023-02-23 14:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 21:09 [PATCH-tip v2 0/3] locking/rwsem: Miscellaneous rwsem enhancements Waiman Long
2023-02-16 21:09 ` [PATCH v2 1/3] locking/rwsem: Minor code refactoring in rwsem_mark_wake() Waiman Long
2023-02-16 21:09 ` [PATCH v2 2/3] locking/rwsem: Enable early rwsem writer lock handoff Waiman Long
2023-02-17 5:24 ` Boqun Feng
2023-02-17 14:25 ` Waiman Long
2023-02-23 12:32 ` Peter Zijlstra
2023-02-23 14:16 ` Waiman Long [this message]
2023-02-16 21:09 ` [PATCH v2 3/3] locking/rwsem: Wake up all readers for wait queue waker Waiman Long
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=0e036ff5-c0f1-96a7-cb07-222c7552201f@redhat.com \
--to=longman@redhat.com \
--cc=boqun.feng@gmail.com \
--cc=hdanton@sina.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@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).