Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp821746ybl; Wed, 4 Dec 2019 11:26:21 -0800 (PST) X-Google-Smtp-Source: APXvYqwRcQeIqYLMiq1eB8gfWSw/aus8Oi0vnWQMWfgYJzI16IsI8JoJ7fbj9ZFbD1zU6f5jm7rR X-Received: by 2002:a05:6830:87:: with SMTP id a7mr3638449oto.314.1575487581169; Wed, 04 Dec 2019 11:26:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575487581; cv=none; d=google.com; s=arc-20160816; b=VKx9tynWdQDyiwLenTqH/Z65MEYOlv0GFFt0sD/CAf7/Iy3DtfhjqceveDoL4ANEsC H8xPosg6995devyCCnQLKUC1/sTo1gm/IYH2DWs2olp5q+SZ9+/yd9AM5BfChD4ntzCT ivSMXQHvAndPjyzReIVTwWchD4bI5DG6RcBLTaCfA70VGZ1CC8SEH2+AVCQGCleWNTrt n/mQIzeoQyMyL/OOYKOhBj4sKgsOxj497ZoLyC7gxy3Bvs3nLuv0lKSOpSNyj2lj3Fh1 J3VXqkA8fBVI6ysBy0sbpedhPX3+j+a9AC6w3jl8MYIahyozIjDEXURhq6tiojKmelew +r3g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/UoaluZ2iCq3tRxXPioknbrBlcIG1W6RkSC6BBdpPd4=; b=JnWZjnKAFCuETRLMM/jXM7yRFY90xahmNSA0CvPqdfDYD4mLDCQxpObFEUmlzHO05+ bARE61N9Q1ZUcbAYRz7WnnC+58q6sCMl2CdmsoEBqcI9LdMUZQZ+3Sb3a7wOuTSOpYui v7bExI2gDtEeFxDytUKFLRFSY9LFyh7Qxv01+kARYOe9JWoqLdQ+dbEqd8ufgkZ7m0jt gvueG4f0JirRgQvGJZw2KGbs5OP+Am0DGy9kXdonDOzf2YM3nUjFADCaCo1GwrfK2m// 8yZEbDKd7XrZY0xOvQWjV4q1dt/xkXiHoPR1EXP9muHrryAI+k7Fuy8fsKyi2P6d3TH8 VmFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Fc4O9KjF; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1si3277658otg.273.2019.12.04.11.26.08; Wed, 04 Dec 2019 11:26:21 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=Fc4O9KjF; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731419AbfLDST6 (ORCPT + 99 others); Wed, 4 Dec 2019 13:19:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:33844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730492AbfLDSI6 (ORCPT ); Wed, 4 Dec 2019 13:08:58 -0500 Received: from localhost (unknown [217.68.49.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 612D9206DF; Wed, 4 Dec 2019 18:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575482937; bh=uKXpVmh/ikjybWUv3q4M6l44VxMqVZPCOOxvCGn/hNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fc4O9KjFdvSfwHaXAPfLY5GRa6TE73cnot8JhkXOMQzyV9aizjQAo4HrZ4ChBVxDF R6QENAeeuClt5KYL6yOyGZ5n0gNDQYeHBbjGyG+RFsc7r/7TOwhmWFMVLNysusAsQa YANzj438BFydLv22l1sRMlk0kWtJ31KoLz6jmJRc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "Peter Zijlstra (Intel)" Subject: [PATCH 4.14 196/209] futex: Provide distinct return value when owner is exiting Date: Wed, 4 Dec 2019 18:56:48 +0100 Message-Id: <20191204175336.977670539@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204175321.609072813@linuxfoundation.org> References: <20191204175321.609072813@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner commit ac31c7ff8624409ba3c4901df9237a616c187a5d upstream. attach_to_pi_owner() returns -EAGAIN for various cases: - Owner task is exiting - Futex value has changed The caller drops the held locks (hash bucket, mmap_sem) and retries the operation. In case of the owner task exiting this can result in a live lock. As a preparatory step for seperating those cases, provide a distinct return value (EBUSY) for the owner exiting case. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Ingo Molnar Acked-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20191106224556.935606117@linutronix.de Signed-off-by: Greg Kroah-Hartman --- kernel/futex.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) --- a/kernel/futex.c +++ b/kernel/futex.c @@ -1182,11 +1182,11 @@ static int handle_exit_race(u32 __user * u32 uval2; /* - * If the futex exit state is not yet FUTEX_STATE_DEAD, wait - * for it to finish. + * If the futex exit state is not yet FUTEX_STATE_DEAD, tell the + * caller that the alleged owner is busy. */ if (tsk && tsk->futex_state != FUTEX_STATE_DEAD) - return -EAGAIN; + return -EBUSY; /* * Reread the user space value to handle the following situation: @@ -2093,12 +2093,13 @@ retry_private: if (!ret) goto retry; goto out; + case -EBUSY: case -EAGAIN: /* * Two reasons for this: - * - Owner is exiting and we just wait for the + * - EBUSY: Owner is exiting and we just wait for the * exit to complete. - * - The user space value changed. + * - EAGAIN: The user space value changed. */ double_unlock_hb(hb1, hb2); hb_waiters_dec(hb2); @@ -2859,12 +2860,13 @@ retry_private: goto out_unlock_put_key; case -EFAULT: goto uaddr_faulted; + case -EBUSY: case -EAGAIN: /* * Two reasons for this: - * - Task is exiting and we just wait for the + * - EBUSY: Task is exiting and we just wait for the * exit to complete. - * - The user space value changed. + * - EAGAIN: The user space value changed. */ queue_unlock(hb); put_futex_key(&q.key);