Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp207114imj; Thu, 14 Feb 2019 18:41:57 -0800 (PST) X-Google-Smtp-Source: AHgI3IZhD3ZsN37/RdI3d6QZDVlMHDrreYoAcIaugWjSNpHvjvHbuUSvd4f44qRk6ZCPALZlpHWC X-Received: by 2002:a62:5e41:: with SMTP id s62mr7391856pfb.232.1550198517038; Thu, 14 Feb 2019 18:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550198517; cv=none; d=google.com; s=arc-20160816; b=vl54sAgvkYuqe6h8HAkUFqz4hNTdJBYionsA0RWJ+c045zZwN1FgHlZiVeqqN2GXWX TylDqPU5XantAC4ocX/aby47ciP+bPVDR8CKIHOw+CaFnOx+N4sgT7tbK9UMLToa8I7J mGEgItLQfboiGui7cKhFaAWG3OEa/MxKhhKy+fTztH0w2KoIEUngJi105nKRJcwFHd1E IlFlB6qlQyNDGsiXubRwPGoK5/h8fMsaFL4I18u1iCHxtXiZiayCXTY5T6G9evFSLlCJ SZra8yRpSxjC+8O0aLVCbaTxsXFL74FDMDHjqWiLNN0DNEACm6gLxDsg8Ss/JPi01G08 lHkg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=M4YpeMkqoXtLumivL50/cz6OJxxJMBULZWkxQyay6FA=; b=nOnRmoN67hOBbU9Cq8RxZB6VKXHZuO1J7K1Ec0OVKYFV5blmDguM/bbINa3aQHDXkj EljlrxmOr/Ak14Tz+8IqbgNl7+LKyrzAnM4SdI8JX2OH1XKi02wza/zf07Kl4wyXXSu7 vr1P+36gn485+WD7ZJ5FICEozU8STrYS+s1DrcayN2qLLIFnHmyxxwRteOKCEheRBPOM xNBfcWco+WVnrdKPw7NNIAOXd655OLKwCCiHYFU4IC1wiHj+1v5QeB+X9j03UgVLmZ4H /uOuYbBSZVhpMZKSvBS8hIhAr2rKjDvIvxJjiCXvNH+BC4XIGbudUlBpZIlEOgVZXNGN SEmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1hXcgvnW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h9si4423614plb.180.2019.02.14.18.41.41; Thu, 14 Feb 2019 18:41:57 -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=1hXcgvnW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390078AbfBOCKH (ORCPT + 99 others); Thu, 14 Feb 2019 21:10:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:50246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389959AbfBOCKE (ORCPT ); Thu, 14 Feb 2019 21:10:04 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 89340222C9; Fri, 15 Feb 2019 02:10:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196604; bh=9Sh6dAlQb5uVkUZprZC23zzTcgJQr9jYvWnjPa51V8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1hXcgvnWm1v4soXLREI+b21mxAdF5euKW6pt4H5bAihMYTuBPt3EFcGKLVmZStdNu HBO4iPtbBy0l8i3R0iM/dQ07nHqdsPUkALzt6GEccqPjNPr9lK6o7O3CeS87rqUzSV 0hyPfFsv2rfHBWxkE5oXFQBrAp4zatntPAOL0Lak= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peter Zijlstra , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH AUTOSEL 4.20 39/77] futex: Fix (possible) missed wakeup Date: Thu, 14 Feb 2019 21:08:17 -0500 Message-Id: <20190215020855.176727-39-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215020855.176727-1-sashal@kernel.org> References: <20190215020855.176727-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra [ Upstream commit b061c38bef43406df8e73c5be06cbfacad5ee6ad ] We must not rely on wake_q_add() to delay the wakeup; in particular commit: 1d0dcb3ad9d3 ("futex: Implement lockless wakeups") moved wake_q_add() before smp_store_release(&q->lock_ptr, NULL), which could result in futex_wait() waking before observing ->lock_ptr == NULL and going back to sleep again. Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Fixes: 1d0dcb3ad9d3 ("futex: Implement lockless wakeups") Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/futex.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kernel/futex.c b/kernel/futex.c index 5cc8083a4c89..6189292244a3 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -1444,11 +1444,7 @@ static void mark_wake_futex(struct wake_q_head *wake_q, struct futex_q *q) if (WARN(q->pi_state || q->rt_waiter, "refusing to wake PI futex\n")) return; - /* - * Queue the task for later wakeup for after we've released - * the hb->lock. wake_q_add() grabs reference to p. - */ - wake_q_add(wake_q, p); + get_task_struct(p); __unqueue_futex(q); /* * The waiting task can free the futex_q as soon as q->lock_ptr = NULL @@ -1458,6 +1454,13 @@ static void mark_wake_futex(struct wake_q_head *wake_q, struct futex_q *q) * plist_del in __unqueue_futex(). */ smp_store_release(&q->lock_ptr, NULL); + + /* + * Queue the task for later wakeup for after we've released + * the hb->lock. wake_q_add() grabs reference to p. + */ + wake_q_add(wake_q, p); + put_task_struct(p); } /* -- 2.19.1