Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5368665ybi; Tue, 30 Jul 2019 19:34:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQpBHZM3zrLcSTtE6dP4BdPBq9IS51DUhHr1rSd/sK6c+yHsi75aSO6SN0SzsvlBhYxlUP X-Received: by 2002:aa7:9118:: with SMTP id 24mr43215284pfh.56.1564540457862; Tue, 30 Jul 2019 19:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564540457; cv=none; d=google.com; s=arc-20160816; b=gJo869xXdoJ+lZE+7RVVTZKl7FuLWFWLHr+363Ho7jTe4rtZ2VDjtfnXE9lyyJGCqo 5Xn71ibgU87QdwknHPf7LadRAE69oylify5VdVqAnzE/QTV/dNAEWhInZYGoMA+uzFOt L2SAC6mzkt3N1uyeuUTt2EyK8YRfrfhSbZXaITnA6h7wuFQi2Rj911sLqd1Epf8h76Ob VudMmfLVFlB5mRLRJbUX21r5GmpU9XdOKZ2X5qqiCB7e0cyER9q2SwfHv87r8KeiKh9q x/UqKqO31WCposTsOrBirB4om2ef50OTwJWRirZtuD892CSngPKgBbG7i9paT7Ts9TEf EJxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=eBNS+CI4i3CO6WZhApAL2cbahMsKjGqx0aAV+81FXYk=; b=HW5vYWnSsCPDKFa3JW+rCPmuD6PXfxRNMrACP8ivFqhWbbMpbgQYRa1HPTT73rQJ3y H9gTI3CowsoDy4FFGs9gexSVEiSMllFC/zJyveJvca4yHFrjlq1nGTGSAWM0Gvr9SpL/ pdoSu4DKacaIPGMfl6N6KKBpbvf6bfheNK73uc7ETkEwCsQCLWlA0R5IoQLH+HYWX76Q v/LZr7//Iw0mdDO9pDxtSWU9aPVe0wYsqpceZJCcT5vjK/sN3b4YgRfAGHECzB8cPzKG KFsJPMuYlUCp04a+V/LR+5LFr/ddcdaQAExTe7m9GwbVHpM9eNAAttBy4ZVGKMJTxR00 b0sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f32si257847pjg.42.2019.07.30.19.34.02; Tue, 30 Jul 2019 19:34:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387984AbfG3WGt (ORCPT + 99 others); Tue, 30 Jul 2019 18:06:49 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:44498 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387733AbfG3WGt (ORCPT ); Tue, 30 Jul 2019 18:06:49 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 9633028B646 From: Gabriel Krisman Bertazi To: tglx@linutronix.de Cc: mingo@redhat.com, peterz@infradead.org, dvhart@infradead.org, linux-kernel@vger.kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH RFC 1/2] futex: Split key setup from key queue locking and read Date: Tue, 30 Jul 2019 18:06:01 -0400 Message-Id: <20190730220602.28781-1-krisman@collabora.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org split the futex key setup from the queue locking and key reading. This is useful to support the setup of multiple keys at the same time, like what is done in futex_requeue() and what will be done for the FUTEX_WAIT_MULTIPLE command. Signed-off-by: Gabriel Krisman Bertazi --- kernel/futex.c | 71 +++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/kernel/futex.c b/kernel/futex.c index 6d50728ef2e7..91f3db335c57 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -2631,6 +2631,39 @@ static void futex_wait_queue_me(struct futex_hash_bucket *hb, struct futex_q *q, __set_current_state(TASK_RUNNING); } +static int __futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags, + struct futex_q *q, struct futex_hash_bucket **hb) +{ + + u32 uval; + int ret; + +retry_private: + *hb = queue_lock(q); + + ret = get_futex_value_locked(&uval, uaddr); + + if (ret) { + queue_unlock(*hb); + + ret = get_user(uval, uaddr); + if (ret) + return ret; + + if (!(flags & FLAGS_SHARED)) + goto retry_private; + + return 1; + } + + if (uval != val) { + queue_unlock(*hb); + ret = -EWOULDBLOCK; + } + + return ret; +} + /** * futex_wait_setup() - Prepare to wait on a futex * @uaddr: the futex userspace address @@ -2651,7 +2684,6 @@ static void futex_wait_queue_me(struct futex_hash_bucket *hb, struct futex_q *q, static int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags, struct futex_q *q, struct futex_hash_bucket **hb) { - u32 uval; int ret; /* @@ -2672,38 +2704,19 @@ static int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags, * absorb a wakeup if *uaddr does not match the desired values * while the syscall executes. */ -retry: - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q->key, FUTEX_READ); - if (unlikely(ret != 0)) - return ret; - -retry_private: - *hb = queue_lock(q); + do { + ret = get_futex_key(uaddr, flags & FLAGS_SHARED, + &q->key, FUTEX_READ); + if (unlikely(ret != 0)) + return ret; - ret = get_futex_value_locked(&uval, uaddr); + ret = __futex_wait_setup(uaddr, val, flags, q, hb); - if (ret) { - queue_unlock(*hb); - - ret = get_user(uval, uaddr); + /* Drop key reference if retry or error. */ if (ret) - goto out; + put_futex_key(&q->key); + } while (ret > 0); - if (!(flags & FLAGS_SHARED)) - goto retry_private; - - put_futex_key(&q->key); - goto retry; - } - - if (uval != val) { - queue_unlock(*hb); - ret = -EWOULDBLOCK; - } - -out: - if (ret) - put_futex_key(&q->key); return ret; } -- 2.20.1