lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJUuVQ6fj_tRk_sLifSEBvyH5Va=LjTLmabnDmC4b020+-4thg@mail.gmail.com>
Date:	Thu, 9 Apr 2015 22:43:49 -0400
From:	Andev <debiandev@...il.com>
To:	Jason Low <jason.low2@...com>
Cc:	Linus Torvalds <torvalds@...ux-foundation.org>,
	Paul McKenney <paulmck@...ux.vnet.ibm.com>,
	Ingo Molnar <mingo@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Davidlohr Bueso <dave@...olabs.net>,
	Tim Chen <tim.c.chen@...ux.intel.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	Aswin Chandramouleeswaran <aswin@...com>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/2] locking/rwsem: Use a return variable in rwsem_spin_on_owner()

On Thu, Apr 9, 2015 at 4:36 PM, Jason Low <jason.low2@...com> wrote:
> On Thu, 2015-04-09 at 11:16 -0700, Linus Torvalds wrote:
>> On Thu, Apr 9, 2015 at 11:08 AM, Linus Torvalds
>> <torvalds@...ux-foundation.org> wrote:
>> >
>> > The pointer is a known-safe kernel pointer - it's just that it was
>> > "known safe" a few instructions ago, and might be rcu-free'd at any
>> > time.
>>
>> Actually, we could even do something like this:
>>
>>  static inline int sem_owner_on_cpu(struct semaphore *sem, struct
>> task_struct *owner)
>>  {
>>         int on_cpu;
>>
>>     #ifdef CONFIG_DEBUG_PAGEALLOC
>>         rcu_read_lock();
>>     #endif
>>         on_cpu = sem->owner == owner && owner->on_cpu;
>>     #ifdef CONFIG_DEBUG_PAGEALLOC
>>         rcu_read_unlock();
>>     #endif
>>         return on_cpu;
>>     }
>>
>> because we really don't need to hold the RCU lock over the whole loop,
>> we just need to validate that the semaphore owner still matches, and
>> if so, check that it's on_cpu.
>>
>> And if CONFIG_DEBUG_PAGEALLOC is set, we don't care about performance
>> *at*all*. We will have worse performance problems than doing some RCU
>> read-locking inside the loop.
>>
>> And if CONFIG_DEBUG_PAGEALLOC isn't set, we don't really care about
>> locking, since at worst we just access stale memory for one iteration.
>>
>> Hmm. It's not pretty, but neither is the current "let's just take a
>> rcu lock that we don't really need over a loop that doesn't have very
>> strict bounding".
>
> So then something like the following (for rwsem)?
>
> We can also run some tests to see how the worst case "access
> stale memory for one iteration" to the heuristic can have an affect on
> performance, though that probably wouldn't be much of an issue in
> practice.
>
> ---
>  kernel/locking/rwsem-xadd.c |   43 ++++++++++++++++++++++++++++---------------
>  1 files changed, 28 insertions(+), 15 deletions(-)
>
> diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
> index 3417d01..870c574 100644
> --- a/kernel/locking/rwsem-xadd.c
> +++ b/kernel/locking/rwsem-xadd.c
> @@ -295,6 +295,31 @@ static inline bool rwsem_try_write_lock_unqueued(struct rw_semaphore *sem)
>         }
>  }
>
> +static inline bool owner_running(struct rw_semaphore *sem, struct task_struct *owner)
> +{
> +       bool ret;
> +
> +#ifdef CONFIG_DEBUG_PAGEALLOC
> +       rcu_read_lock();
> +#endif

Please use 'if (IS_ENABLED(CONFIG_DEBUG_PAGEALLOC)) {}' here. Makes
code much readable IMHO.

-- 
Andev
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ