From patchwork Wed Jul 28 15:02:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Bader X-Patchwork-Id: 1510896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=gWJn+tDq; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GZcN0110tz9sX5; Thu, 29 Jul 2021 01:02:40 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1m8l4u-00074b-Dj; Wed, 28 Jul 2021 15:02:36 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1m8l4p-00073Q-Qp for kernel-team@lists.ubuntu.com; Wed, 28 Jul 2021 15:02:31 +0000 Received: from canonical.com (1.general.smb.uk.vpn [10.172.193.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 59F5D402F4 for ; Wed, 28 Jul 2021 15:02:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1627484551; bh=Zn+zoRURSm/iCoxt4mgnPD2l5dwTvhP9QDJbtOLLf0w=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gWJn+tDqfunF+RHDPkFVbQ5Uc/cCeNGUO32yiV9cCAumTHhQhabB24XwG1LGlTBgx vhmQ4Hd8yyMuoSGB6KipiA4zp133+mTrYYCgVTkKLXLRH1lPA3RgsVqL9SQHQ6oISf mL/PzLRdf/0+avT8VpiOaQrvX5DGQPBbJLLP0hMovtuscHDlH7EgTwa6QnRyo/RRKG JmmB2oOC5uTCOlAPlZzVCqONjDMhiQP0SxNcn62ZthxZWTDH8iR9IvTg13M8rYcYwT 9LIdv5niK/gyyYmD/NjiHZalXpeu7ZGroXKCZOFJUcBBC/bsEAKBjfKjRtY7PZVcnY eLdVb2VYHNQuQ== From: Stefan Bader To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/2] Revert "locking/mutex: clear MUTEX_FLAGS if wait_list is empty due to signal" Date: Wed, 28 Jul 2021 17:02:29 +0200 Message-Id: <20210728150230.150985-2-stefan.bader@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210728150230.150985-1-stefan.bader@canonical.com> References: <20210728150230.150985-1-stefan.bader@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" This reverts commit 2e1eb7b6e1e0e4bd988b0bbcbd96e2fee205885b, it seems to depend on some additional changes to locking and we have reports of strange corruption happening in various cases. Not really something that can be pinpointed but a chance that something related to locking is causing this. Signed-off-by: Stefan Bader Acked-by: Krzysztof Kozlowski --- kernel/locking/mutex-debug.c | 4 ++-- kernel/locking/mutex-debug.h | 2 +- kernel/locking/mutex.c | 16 ++++------------ kernel/locking/mutex.h | 4 +++- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c index 839df4383799..9aa713629387 100644 --- a/kernel/locking/mutex-debug.c +++ b/kernel/locking/mutex-debug.c @@ -57,7 +57,7 @@ void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter, task->blocked_on = waiter; } -void debug_mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter, +void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter, struct task_struct *task) { DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list)); @@ -65,7 +65,7 @@ void debug_mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter, DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter); task->blocked_on = NULL; - INIT_LIST_HEAD(&waiter->list); + list_del_init(&waiter->list); waiter->task = NULL; } diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h index 53e631e1d76d..1edd3f45a4ec 100644 --- a/kernel/locking/mutex-debug.h +++ b/kernel/locking/mutex-debug.h @@ -22,7 +22,7 @@ extern void debug_mutex_free_waiter(struct mutex_waiter *waiter); extern void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter, struct task_struct *task); -extern void debug_mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter, +extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter, struct task_struct *task); extern void debug_mutex_unlock(struct mutex *lock); extern void debug_mutex_init(struct mutex *lock, const char *name, diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index a1be54f68207..858a07590e39 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -172,16 +172,6 @@ static inline bool __mutex_waiter_is_first(struct mutex *lock, struct mutex_wait return list_first_entry(&lock->wait_list, struct mutex_waiter, list) == waiter; } -static void -__mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter) -{ - list_del(&waiter->list); - if (likely(list_empty(&lock->wait_list))) - __mutex_clear_flag(lock, MUTEX_FLAGS); - - debug_mutex_remove_waiter(lock, waiter, current); -} - /* * Give up ownership to a specific task, when @task = NULL, this is equivalent * to a regular unlock. Sets PICKUP on a handoff, clears HANDOF, preserves @@ -868,7 +858,9 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, acquired: __set_current_state(TASK_RUNNING); - __mutex_remove_waiter(lock, &waiter); + mutex_remove_waiter(lock, &waiter, current); + if (likely(list_empty(&lock->wait_list))) + __mutex_clear_flag(lock, MUTEX_FLAGS); debug_mutex_free_waiter(&waiter); @@ -885,7 +877,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, err: __set_current_state(TASK_RUNNING); - __mutex_remove_waiter(lock, &waiter); + mutex_remove_waiter(lock, &waiter, current); err_early_backoff: spin_unlock(&lock->wait_lock); debug_mutex_free_waiter(&waiter); diff --git a/kernel/locking/mutex.h b/kernel/locking/mutex.h index f0c710b1d192..1c2287d3fa71 100644 --- a/kernel/locking/mutex.h +++ b/kernel/locking/mutex.h @@ -10,10 +10,12 @@ * !CONFIG_DEBUG_MUTEXES case. Most of them are NOPs: */ +#define mutex_remove_waiter(lock, waiter, task) \ + __list_del((waiter)->list.prev, (waiter)->list.next) + #define debug_mutex_wake_waiter(lock, waiter) do { } while (0) #define debug_mutex_free_waiter(waiter) do { } while (0) #define debug_mutex_add_waiter(lock, waiter, ti) do { } while (0) -#define debug_mutex_remove_waiter(lock, waiter, ti) do { } while (0) #define debug_mutex_unlock(lock) do { } while (0) #define debug_mutex_init(lock, name, key) do { } while (0)