All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: tglx@linutronix.de, mingo@redhat.com, dvhart@infradead.org,
	linux-kernel@vger.kernel.org, Davidlohr Bueso <dbueso@suse.de>
Subject: Re: [PATCH 2/2] futex: Leave the pi lock stealer in a consistent state upon successful fault
Date: Tue, 16 Mar 2021 12:20:02 +0100	[thread overview]
Message-ID: <YFCUYimuDkUonySp@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20210315050224.107056-3-dave@stgolabs.net>

On Sun, Mar 14, 2021 at 10:02:24PM -0700, Davidlohr Bueso wrote:
> Before 34b1a1ce145 (futex: Handle faults correctly for PI futexes) any
> concurrent pi_state->owner fixup would assume that the task that fixed
> things on our behalf also correctly updated the userspace value. This
> is not always the case anymore, and can result in scenarios where a lock
> stealer returns a successful FUTEX_PI_LOCK operation but raced during a fault
> with an enqueued top waiter in an immutable state so the uval TID was
> not updated for the stealer, breaking otherwise expected (and valid)
> semantics and confusing the stealer task:


> ---
>  kernel/futex.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/futex.c b/kernel/futex.c
> index ded7af2ba87f..95ce10c4e33d 100644
> --- a/kernel/futex.c
> +++ b/kernel/futex.c
> @@ -2460,7 +2460,6 @@ static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
>  
>  	case -EAGAIN:
>  		cond_resched();
> -		err = 0;
>  		break;
>  
>  	default:
> @@ -2474,11 +2473,22 @@ static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
>  	/*
>  	 * Check if someone else fixed it for us:
>  	 */
> -	if (pi_state->owner != oldowner)
> +	if (pi_state->owner != oldowner) {
> +		/*
> +		 * The change might have come from the rare immutable
> +		 * state below, which leaves the userspace value out of
> +		 * sync. But if we are the lock stealer and can update
> +		 * the uval, do so, instead of reporting a successful
> +		 * lock operation with an invalid user state.
> +		 */
> +		if (!err && argowner == current)
> +			goto retry;
> +
>  		return argowner == current;
> +	}
>  
>  	/* Retry if err was -EAGAIN or the fault in succeeded */
> -	if (!err)
> +	if (err == -EAGAIN || !err)
>  		goto retry;
>  

IIRC we made the explicit choice to never loop here. That saves having
to worry about getting stuck in in-kernel loops.

Userspace triggering the case where the futex goes corrupt is UB, after
that we have no obligation for anything to still work. It's on them,
they get to deal with the bits remaining.


  reply	other threads:[~2021-03-16 11:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15  5:02 [PATCH -tip 0/2] futex: Two pi fixes Davidlohr Bueso
2021-03-15  5:02 ` [PATCH 1/2] futex: Fix irq mismatch in exit_pi_state_list() Davidlohr Bueso
2021-03-15 13:12   ` Peter Zijlstra
2021-03-15 19:03     ` Davidlohr Bueso
2021-03-15  5:02 ` [PATCH 2/2] futex: Leave the pi lock stealer in a consistent state upon successful fault Davidlohr Bueso
2021-03-16 11:20   ` Peter Zijlstra [this message]
2021-03-16 18:03     ` Davidlohr Bueso
2021-03-16 19:48       ` Thomas Gleixner
2021-03-16 20:12       ` Peter Zijlstra

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=YFCUYimuDkUonySp@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=dave@stgolabs.net \
    --cc=dbueso@suse.de \
    --cc=dvhart@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.