Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp207588imj; Thu, 14 Feb 2019 18:42:41 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib3GdE2So47E8hR0mnaxow2qfC++Ij0J/Jcdspj/oFvXfbxDt4pCouzM8MxopHwT2gKUSjy X-Received: by 2002:a17:902:8a:: with SMTP id a10mr7830698pla.158.1550198561815; Thu, 14 Feb 2019 18:42:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550198561; cv=none; d=google.com; s=arc-20160816; b=uclgmUJTfq/Ti1INrd+mKgzr3Hi8s+E21qVDaTSJ2cuCew5fFovUSXvZt0nme3vhg6 xkW2TouFEEmM0fxDBKK8b2vmKVwKrbRa1mTmzG1AIB1D7YYonYrG+JZ5+/nzxJrkGxmf iXrb9gzaqYUyKqpiW1LtXPmSHwFF842p/pDzK2vsePXqwlIO8Ul9wX5XiPrAN9LPYPKw vn+KzFdm+DyjIerXC00zmUltsTnZgcmL+T8JrzcdLnCnElrxTl2ikctiqoPW9RCHA2qe ig2u9jtif0r0l9hETkos03BEK3dOcXgCR/eTYCKFesli4ZVUAvW3w68KTXCqoEJKGCgQ h6BQ== 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=LV8N6Z50VTbH1QnUO/JtN+pU6gKy2vRy4w09S1u+QAU=; b=DOlBGoaSB9C80D3KYHctsA2SrhTaoz48Ioe7fGfdEPHK3GK+ACYy+7mQ82U9VLe+Qe cjFHcrovhQ7TTgMYktC9kh9xuGMpx2ECTTq4AM3u0X8JsgQsXYDxpFqGD3eW3B8qegO0 uLikLcMZtVJg3hYfnKKwsNZ/drPDcMncatbXKkKzeWgWMAXB+ej67uvCxWv5kkpQacow ljr96aNE76NxGt9VLoepAtAFXMpw68gvcrRlx/l9sbl/TK/ZaSD7J9jeWNHCH3o0IsyJ KSsPgZt/7/K1FrrLqrmkkU+bohcIIV5A38HHPUVAi4nAa8eNvPG1SqL0Lj41+afmow+J ekuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a6cu2VNF; 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 i13si3900153pgj.199.2019.02.14.18.42.25; Thu, 14 Feb 2019 18:42:41 -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=a6cu2VNF; 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 S1730324AbfBOCkE (ORCPT + 99 others); Thu, 14 Feb 2019 21:40:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:50256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390042AbfBOCKG (ORCPT ); Thu, 14 Feb 2019 21:10:06 -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 C7CFE2229F; Fri, 15 Feb 2019 02:10:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196605; bh=Bfk3PlCgtB59uOtGgirBBHKOLz54OWJ4q1g8XVtc2D8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a6cu2VNFt+xb031I8WPPbZUMXiI+ctGwR8D4mPvJmglLe5Ta8yh7Bv5weiJL5xgQR xfoOA1L/fvuBpZ9qnc1Tv7kfex8iKrLcaMlr3WTK242jxY5tUPUt9qVRoT/APh8Nmp OTMwA4mgG57fPmm9gWh6Jg0Cj6ZiiZtePaVDQJ24= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xie Yongji , Zhang Yu , Peter Zijlstra , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH AUTOSEL 4.20 40/77] locking/rwsem: Fix (possible) missed wakeup Date: Thu, 14 Feb 2019 21:08:18 -0500 Message-Id: <20190215020855.176727-40-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: Xie Yongji [ Upstream commit e158488be27b157802753a59b336142dc0eb0380 ] Because wake_q_add() can imply an immediate wakeup (cmpxchg failure case), we must not rely on the wakeup being delayed. However, commit: e38513905eea ("locking/rwsem: Rework zeroing reader waiter->task") relies on exactly that behaviour in that the wakeup must not happen until after we clear waiter->task. [ peterz: Added changelog. ] Signed-off-by: Xie Yongji Signed-off-by: Zhang Yu Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Fixes: e38513905eea ("locking/rwsem: Rework zeroing reader waiter->task") Link: https://lkml.kernel.org/r/1543495830-2644-1-git-send-email-xieyongji@baidu.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/locking/rwsem-xadd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c index 09b180063ee1..50d9af615dc4 100644 --- a/kernel/locking/rwsem-xadd.c +++ b/kernel/locking/rwsem-xadd.c @@ -198,15 +198,22 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem, woken++; tsk = waiter->task; - wake_q_add(wake_q, tsk); + get_task_struct(tsk); list_del(&waiter->list); /* - * Ensure that the last operation is setting the reader + * Ensure calling get_task_struct() before setting the reader * waiter to nil such that rwsem_down_read_failed() cannot * race with do_exit() by always holding a reference count * to the task to wakeup. */ smp_store_release(&waiter->task, NULL); + /* + * Ensure issuing the wakeup (either by us or someone else) + * after setting the reader waiter to nil. + */ + wake_q_add(wake_q, tsk); + /* wake_q_add() already take the task ref */ + put_task_struct(tsk); } adjustment = woken * RWSEM_ACTIVE_READ_BIAS - adjustment; -- 2.19.1