Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6114990imu; Mon, 21 Jan 2019 03:31:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN7U5mSRRtBgJ9hZrO8BgGaRny9OwHX7SR59BU6QjnGuUTsuGhXpgYXWeXE4/Wz6UTH3xoXI X-Received: by 2002:a63:8441:: with SMTP id k62mr27697582pgd.392.1548070260117; Mon, 21 Jan 2019 03:31:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548070260; cv=none; d=google.com; s=arc-20160816; b=OGlKJwR7JYouyKfS7bbEtSrAUKKZhjTCqiVq3G34+Xg0huCKM+vDmn5f0hAUCu3hlm xPOymQ+MGFu7bigFrQ0FGIN9mJBdn/jv+4UEHagwZxmqQUcBc3L411LIyQxEKlDn2KUn tK7F/WPnd6Ca76isnZ0+ZsKU8RK+/UXujCix5aJgbdb3Yq6NmJfNw68EHOJqkhUQio3A bpg5ZWjL9I0l6bGcYvKVIoH/gPLXeKPmA9+HYhrQcDiotvoxFFeCH1RRyh5F7aP+K8yO VLwkqqFvNh3uM5KaSJSDK9i1o2Untd/fe+VtWvneiHay3WSwAUh3HbwNgAX+iz/RFk3T FxfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=CbZF09Ng9bBGYv3egiF3AQlQ5PENTpGzF5QLaRk+VR0=; b=EzOcy5v4Mo3i9cLsfxP5nRUU/0UYxXZ+LGbwaroApNJueUWZiq4z4FFUcVd5Gd7Znm HLE/LFtywNSU987WdB2zc2E38iM4x0WsVpfqv/bpaGvrQEVWdGsADVCdVcBG/GG5xcRf YBJzf98vwENHucNF9LVJ5IGmR004P2Qa/vfEpwRptAtR3MWn9H3zSUvSsou4KJzNa24O 3xELMYkXm+rOpqSZJWlVF02ONd5SMx4aFNDRXBZGyQOBTrJ6dmjn2grR8SoxSWCyRVdW ty6aPWmS6vHbC5K8ivDaARsntKBaYGMge1OCCN5HoxJnPc/rTBdL5xAUyknSEVwPUvJT hK/g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si11917748pgd.428.2019.01.21.03.30.45; Mon, 21 Jan 2019 03:31:00 -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; 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 S1727993AbfAUL2Z (ORCPT + 99 others); Mon, 21 Jan 2019 06:28:25 -0500 Received: from terminus.zytor.com ([198.137.202.136]:49975 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727665AbfAUL2Z (ORCPT ); Mon, 21 Jan 2019 06:28:25 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x0LBSFo52496127 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 21 Jan 2019 03:28:15 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x0LBSFwv2496124; Mon, 21 Jan 2019 03:28:15 -0800 Date: Mon, 21 Jan 2019 03:28:15 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Xie Yongji Message-ID: Cc: hpa@zytor.com, torvalds@linux-foundation.org, mingo@kernel.org, peterz@infradead.org, linux-kernel@vger.kernel.org, zhangyu31@baidu.com, tglx@linutronix.de, xieyongji@baidu.com Reply-To: mingo@kernel.org, torvalds@linux-foundation.org, hpa@zytor.com, peterz@infradead.org, zhangyu31@baidu.com, linux-kernel@vger.kernel.org, xieyongji@baidu.com, tglx@linutronix.de In-Reply-To: <1543495830-2644-1-git-send-email-xieyongji@baidu.com> References: <1543495830-2644-1-git-send-email-xieyongji@baidu.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/rwsem: Fix (possible) missed wakeup Git-Commit-ID: e158488be27b157802753a59b336142dc0eb0380 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: e158488be27b157802753a59b336142dc0eb0380 Gitweb: https://git.kernel.org/tip/e158488be27b157802753a59b336142dc0eb0380 Author: Xie Yongji AuthorDate: Thu, 29 Nov 2018 20:50:30 +0800 Committer: Ingo Molnar CommitDate: Mon, 21 Jan 2019 11:15:39 +0100 locking/rwsem: Fix (possible) missed wakeup 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 --- 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;