Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1191692ybf; Thu, 27 Feb 2020 06:35:07 -0800 (PST) X-Google-Smtp-Source: APXvYqzEGuWmjFwzlr19WWCjPrUcVXpvbTnxcj9b88fTw0NytRuALp4OYrLyd5wkQlPcT6mID0Ng X-Received: by 2002:aca:4ad8:: with SMTP id x207mr3380270oia.55.1582814107116; Thu, 27 Feb 2020 06:35:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582814107; cv=none; d=google.com; s=arc-20160816; b=riu5+6Ww4v/wWj8YOJDOPebaG9NWM/KYzqHfwX/Cp4l4BCOhIWdzyz3ZsafrrTq++R i80w465AaqoYtzAAHgF1wOv9Ny3hzSlpreMTt+/s0EVhvP5qDePcWkg1VQSOsSdBRWUN sJmj+1u+Q2rDMHklNzvzQceEz2jVZIgNd5pfk1hWnVsrcPL//3J1/vVepKddmUQo0Puj Del5reB0lDqZbQskV8SQoHXF0VtqxuTYtt/HV2lkjMTK7WxsayLpTogjiB0iWgj9YvAt aY/DFvzN7axW14FmR2P2Kw+JtqXYYQe4paQBMinFCgX0Q5OwMCzZN3YUKILxyJUl/Jud mofg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:to:from:dkim-signature; bh=g4u2tCq6VrB3NNmd1OEBCpeKPVMZ2u1R5Alackp4Okc=; b=eZuIjBcNSNk8IfvGHo0lBOmJq48DaEelEps+RVUUg8Liusf8pHpS2KBFe+qcjHEFbL 0wzLjtKAc1Ge2Tzk9V/mYcXCuKXkHv898jWcq/c/rjsCpGW3ls1X7uO9CmP2r/u96dLK 5hH833U3L9ZZH+k8OzqcDV07X8z7yQgkLSVCJpc+t96gbnvrLLFewX5aS1yzhxmn+6gC xx8q/4XNjwvVp/7AIWhQoGYZ7IQDxvUEGoa+uX9l5SBy8AP3Cvr9irDCuAzPENjjXvw7 IlbJb7hsWu7ed7scElpZvu4jAQBC7IwhnWE/T+n0abqAsJoQ0w55Om0e+lRnGnAcMuhS jaiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YSxCHkxr; 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 t24si1647666oth.319.2020.02.27.06.34.54; Thu, 27 Feb 2020 06:35:07 -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=YSxCHkxr; 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 S1732888AbgB0OeR (ORCPT + 99 others); Thu, 27 Feb 2020 09:34:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:45144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387712AbgB0OeH (ORCPT ); Thu, 27 Feb 2020 09:34:07 -0500 Received: from localhost.localdomain (c-98-220-238-81.hsd1.il.comcast.net [98.220.238.81]) (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 F27F5246B2; Thu, 27 Feb 2020 14:34:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582814046; bh=6AMIoZ2bBZlvfbk81sl3FlnzSFeiOBjvPHt5xpK0suk=; h=From:To:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=YSxCHkxrwqDT2xtNFnJgdz0QUoX9dHAy1DzCern7GCLW+6zplRmaXCIoyz19+fA3Z sYLDpAdE7HJW0mv34QKAs2L8Ys8fHh7J/tL9Mg+ThBG6lUonby3/PSpN6kTqqZSQ5Z QPtW9Uy7eD43VVoPjmqZAX6VN6FVQ4JzEOOP6CcQ= From: zanussi@kernel.org To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Daniel Wagner , Tom Zanussi Subject: [PATCH RT 11/23] locking/rtmutex: Clean ->pi_blocked_on in the error case Date: Thu, 27 Feb 2020 08:33:22 -0600 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra v4.14.170-rt75-rc2 stable review patch. If anyone has any objections, please let me know. ----------- [ Upstream commit 0be4ea6e3ce693101be0fbd55a0cc7ce238ab2eb ] The function rt_mutex_wait_proxy_lock() cleans ->pi_blocked_on in case of failure (timeout, signal). The same cleanup is required in __rt_mutex_start_proxy_lock(). In both the cases the tasks was interrupted by a signal or timeout while acquiring the lock and after the interruption it longer blocks on the lock. Fixes: 1a1fb985f2e2b ("futex: Handle early deadlock return correctly") Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Tom Zanussi --- kernel/locking/rtmutex.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 1177f2815040..4bc01a2a9a88 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -2328,6 +2328,26 @@ void rt_mutex_proxy_unlock(struct rt_mutex *lock, rt_mutex_set_owner(lock, NULL); } +static void fixup_rt_mutex_blocked(struct rt_mutex *lock) +{ + struct task_struct *tsk = current; + /* + * RT has a problem here when the wait got interrupted by a timeout + * or a signal. task->pi_blocked_on is still set. The task must + * acquire the hash bucket lock when returning from this function. + * + * If the hash bucket lock is contended then the + * BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on)) in + * task_blocks_on_rt_mutex() will trigger. This can be avoided by + * clearing task->pi_blocked_on which removes the task from the + * boosting chain of the rtmutex. That's correct because the task + * is not longer blocked on it. + */ + raw_spin_lock(&tsk->pi_lock); + tsk->pi_blocked_on = NULL; + raw_spin_unlock(&tsk->pi_lock); +} + /** * __rt_mutex_start_proxy_lock() - Start lock acquisition for another task * @lock: the rt_mutex to take @@ -2400,6 +2420,9 @@ int __rt_mutex_start_proxy_lock(struct rt_mutex *lock, ret = 0; } + if (ret) + fixup_rt_mutex_blocked(lock); + debug_rt_mutex_print_deadlock(waiter); return ret; @@ -2480,7 +2503,6 @@ int rt_mutex_wait_proxy_lock(struct rt_mutex *lock, struct hrtimer_sleeper *to, struct rt_mutex_waiter *waiter) { - struct task_struct *tsk = current; int ret; raw_spin_lock_irq(&lock->wait_lock); @@ -2492,23 +2514,8 @@ int rt_mutex_wait_proxy_lock(struct rt_mutex *lock, * have to fix that up. */ fixup_rt_mutex_waiters(lock); - /* - * RT has a problem here when the wait got interrupted by a timeout - * or a signal. task->pi_blocked_on is still set. The task must - * acquire the hash bucket lock when returning from this function. - * - * If the hash bucket lock is contended then the - * BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on)) in - * task_blocks_on_rt_mutex() will trigger. This can be avoided by - * clearing task->pi_blocked_on which removes the task from the - * boosting chain of the rtmutex. That's correct because the task - * is not longer blocked on it. - */ - if (ret) { - raw_spin_lock(&tsk->pi_lock); - tsk->pi_blocked_on = NULL; - raw_spin_unlock(&tsk->pi_lock); - } + if (ret) + fixup_rt_mutex_blocked(lock); raw_spin_unlock_irq(&lock->wait_lock); -- 2.14.1