From patchwork Wed Feb 3 13:45:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 375408 Delivered-To: patch@linaro.org Received: by 2002:a17:906:48d2:0:0:0:0 with SMTP id d18csp417306ejt; Wed, 3 Feb 2021 05:47:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYe28hjJpKJ3HpVgAvKbMLxMLCAhogvicoBfnoukTQfXcozt7/aaxaB0878RjCHE8AaIph X-Received: by 2002:a17:906:15c7:: with SMTP id l7mr3338706ejd.226.1612360067042; Wed, 03 Feb 2021 05:47:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612360067; cv=none; d=google.com; s=arc-20160816; b=FLxRjAgAYFW33FjOxmWAaCan2Juy8/fh/kLRXnZnhvytqVvNtGhpO7M9GpN0aWjMmg RabVIJxfhwEqhstyR5bwxMoO+EIQPfOVd3LyUHE+lweW5kwA++XgrY3Viw2R1lFLcx9H G/YDjAfVCG6j+3v5uMhPlhgIow9FNODueQBkcHcx5HMXRmCRp/fAhdUJ3nIbJx3c7VVS vCqg85MvTFda4gXHwZfyr+VkIUIBDT1pmtPVf0Jl1u79nQkOhYZBQxtXWiBCEr4E4VTm Nqp9XXmm22s0dORoFpESfYaBcUAlq6MV1o9FYzDOAjCZADAwvh7D8t0i4R9fNuAbWvK+ Cl0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SH5Nj25x7+v0gQvzlOdJud0ErPOJ5XP3gEjc5bfgYKY=; b=j0IzwJF7eE+LdHI1t46ibOAo8gKtNpofdBZRfPuRowjEFT/mISwvoRAoAF1ZUoKJRU TjWQ2iS2FI9V3951I1sZTDz4TE+3tSFS7u8IzGkjTz6otRi1J90IeGqKDuBZb3MyOjJv S51etotdvzf5XKii3S8HXFGFMlvsqg3TsVZMLb31k5eZ/qlty/g5I7XNeGsHxjiC4kh4 kGnexM7c08F0aDiwxTs/ibDhMLbI+7iEWiR6UPuDNu1ZwTzwzHVSRivYfpn5hg/7yLii n/s6qFbGNBQ2VmxzMgdiilfPKOqw0aUvWuJO8Qo0DMWDEL/9SQ3T1HJNH6bLyu2nkmWn srsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XfT445G4; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jz24si1404088ejc.430.2021.02.03.05.47.46; Wed, 03 Feb 2021 05:47:47 -0800 (PST) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XfT445G4; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232222AbhBCNrc (ORCPT + 13 others); Wed, 3 Feb 2021 08:47:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232195AbhBCNrV (ORCPT ); Wed, 3 Feb 2021 08:47:21 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD490C061797 for ; Wed, 3 Feb 2021 05:45:58 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id l12so4506554wmq.2 for ; Wed, 03 Feb 2021 05:45:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SH5Nj25x7+v0gQvzlOdJud0ErPOJ5XP3gEjc5bfgYKY=; b=XfT445G4wZ4PKUnsgeT4VrLtHzCml1M0Oj6q+Hn/HN1tEDGfkWHIIPD0WvgsvcVOfp +pBW47XxIPkCRm/di75xUdPTOj/yGLjKCrcqLhYTBSaxqgTkpSOkNkctl/zE2gWhsHIH 80j9GQXlDSkOLtPt+Hl6uFrtnCDgsvjFBMDWLgncFPnBv7ciIu7fBdO1CXeAHDKoQ3/g zT89cFJjdtZikZ8g8MiOsJF/mqSq/JwZBeWw5EXoz3OiTylhVIi/HS6xV/hg9H1IAIlC xqVXwoh3ngTPuFMqIl8Uhs/TCtuiiTazF6GhjqW7mA8XIQFoiLinLwmEmfn+1Hz9OLeb Di3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SH5Nj25x7+v0gQvzlOdJud0ErPOJ5XP3gEjc5bfgYKY=; b=LPDugSbxsEASrNrmav5GuHy9JcOH++AdkGqsV26JhJLYfZYsdnHgJ9mLtvGk+c6e3O gDNfaSK8/VqBMQsfvDV6cM95gJCKgUe4yEIapqyuZud0Fnt9nPWAWBLPcPTgMTdBBi2a Is9jN4bL0ZcE6LrXru6q7Vfxno3mB7cDOK61UWoYzSfUIGvFpe5ZNMpqlMzjVxm9e83A oHKcYIreeF94ruplTyQ6/SdZNOyPK2+niKdZCvSiQL90D2f2ZgDmdtayQRZSrcCnFhq3 l+O7ymqv5crMNozUk4ZDWvDP5rQmycyC24YG3BUIU48GzwEaqndJL4JhUPVm9kuUyzvi LYNw== X-Gm-Message-State: AOAM530bikAtwDhL9HOSeS3UuEs9slA5IBxMw+GGmFk4+9/but6RILRf WjO32g1ZiQJBvEMM5lR+WrERsj5A81JKHA== X-Received: by 2002:a1c:21c6:: with SMTP id h189mr2774643wmh.173.1612359957109; Wed, 03 Feb 2021 05:45:57 -0800 (PST) Received: from dell.default ([91.110.221.188]) by smtp.gmail.com with ESMTPSA id r124sm2867900wmr.16.2021.02.03.05.45.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 05:45:56 -0800 (PST) From: Lee Jones To: stable@vger.kernel.org Cc: Thomas Gleixner , Peter Zijlstra , Lee Jones Subject: [PATCH 09/10] futex: Simplify fixup_pi_state_owner() Date: Wed, 3 Feb 2021 13:45:38 +0000 Message-Id: <20210203134539.2583943-10-lee.jones@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210203134539.2583943-1-lee.jones@linaro.org> References: <20210203134539.2583943-1-lee.jones@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Thomas Gleixner [ Upstream commit f2dac39d93987f7de1e20b3988c8685523247ae2 ] Too many gotos already and an upcoming fix would make it even more unreadable. Signed-off-by: Thomas Gleixner Acked-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- kernel/futex.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) -- 2.25.1 diff --git a/kernel/futex.c b/kernel/futex.c index be5e3e927bffa..c163f5d6efab3 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -2272,18 +2272,16 @@ static void unqueue_me_pi(struct futex_q *q) spin_unlock(q->lock_ptr); } -static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, - struct task_struct *argowner) +static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, + struct task_struct *argowner) { struct futex_pi_state *pi_state = q->pi_state; - u32 uval, uninitialized_var(curval), newval; struct task_struct *oldowner, *newowner; - u32 newtid; - int ret; - - lockdep_assert_held(q->lock_ptr); + u32 uval, curval, newval, newtid; + int err = 0; oldowner = pi_state->owner; + /* Owner died? */ if (!pi_state->owner) newtid |= FUTEX_OWNER_DIED; @@ -2324,7 +2322,7 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, if (__rt_mutex_futex_trylock(&pi_state->pi_mutex)) { /* We got the lock after all, nothing to fix. */ - return 0; + return 1; } /* @@ -2339,7 +2337,7 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, * We raced against a concurrent self; things are * already fixed up. Nothing to do. */ - return 0; + return 1; } newowner = argowner; } @@ -2380,7 +2378,7 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, handle_fault: spin_unlock(q->lock_ptr); - ret = fault_in_user_writeable(uaddr); + err = fault_in_user_writeable(uaddr); spin_lock(q->lock_ptr); @@ -2388,12 +2386,27 @@ 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) - return 0; + return argowner == current; - if (ret) - return ret; + /* Retry if err was -EAGAIN or the fault in succeeded */ + if (!err) + goto retry; - goto retry; + return err; +} + +static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, + struct task_struct *argowner) +{ + struct futex_pi_state *pi_state = q->pi_state; + int ret; + + lockdep_assert_held(q->lock_ptr); + + raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock); + ret = __fixup_pi_state_owner(uaddr, q, argowner); + raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); + return ret; } static long futex_wait_restart(struct restart_block *restart);