From patchwork Tue Mar 1 12:21:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 12764681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19A60C433FE for ; Tue, 1 Mar 2022 12:21:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D9D158D0003; Tue, 1 Mar 2022 07:21:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4DE68D0001; Tue, 1 Mar 2022 07:21:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B82A48D0005; Tue, 1 Mar 2022 07:21:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 981FF8D0001 for ; Tue, 1 Mar 2022 07:21:52 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 600E420808 for ; Tue, 1 Mar 2022 12:21:52 +0000 (UTC) X-FDA: 79195728864.08.2FBDB94 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf26.hostedemail.com (Postfix) with ESMTP id B1233140003 for ; Tue, 1 Mar 2022 12:21:51 +0000 (UTC) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1646137309; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rUBk7M1p4qT8w0880DAS1B5RVZj8zKAyQHnUzb2B04o=; b=yqfU0FGa/FFsP/tXBmGXAmkcVFEW6qwWKW7rdEDhMt9JcB/cBEMGMLiovt9W5I7aNSDgo6 aHhXKGRVU6B7fcrzRh6JuA3hK8ZdDp2C2Q4xFaPOjBkinEgVDXKE1As8ps8773KO1PbXfN Kzgj4TVPIIMhzoc/GvGPbycuq2aLtQ5JD6tru1i7RhqOJeaZ8G5x33JXjPzu6RHiSIjSt9 HYigFQ78i1/a2IMXWEd3mZjovq21sgcdqn7UWiuFZefv7OxWD2KWL4XqQmiyCuLoz0mvb0 ezv1Y7rZPgfRKgAuw2xx/y98a64UzTMlfQ1uRWCliqr5go45v0RyNJAGoI+cWg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1646137309; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rUBk7M1p4qT8w0880DAS1B5RVZj8zKAyQHnUzb2B04o=; b=vEnEhqWH8/NN/WnJEWUI6fe60nLv7e3Whi+F6PRtEjJaHl38C8AqTyeu0NIwNYrWGajBZh UZ6Iw0A0X4fBfZBg== To: cgroups@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner , Tejun Heo , Zefan Li , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 1/2] cgroup: Use irqsave in cgroup_rstat_flush_locked(). Date: Tue, 1 Mar 2022 13:21:42 +0100 Message-Id: <20220301122143.1521823-2-bigeasy@linutronix.de> In-Reply-To: <20220301122143.1521823-1-bigeasy@linutronix.de> References: <[PATCH 0/2] Correct locking assumption on PREEMPT_RT> <20220301122143.1521823-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B1233140003 X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=yqfU0FGa; dkim=pass header.d=linutronix.de header.s=2020e header.b=vEnEhqWH; spf=pass (imf26.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de X-Stat-Signature: nehey6in39fc65kbm8a9qe3qr5swwiyk X-HE-Tag: 1646137311-811159 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: All callers of cgroup_rstat_flush_locked() acquire cgroup_rstat_lock either with spin_lock_irq() or spin_lock_irqsave(). cgroup_rstat_flush_locked() itself acquires cgroup_rstat_cpu_lock which is a raw_spin_lock. This lock is also acquired in cgroup_rstat_updated() in IRQ context and therefore requires _irqsave() locking suffix in cgroup_rstat_flush_locked(). Since there is no difference between spin_lock_t and raw_spin_lock_t on !RT lockdep does not complain here. On RT lockdep complains because the interrupts were not disabled here and a deadlock is possible. Acquire the raw_spin_lock_t with disabled interrupts. Signed-off-by: Sebastian Andrzej Siewior --- kernel/cgroup/rstat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 9d331ba44870a..53b771c20ee50 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -153,8 +153,9 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp, bool may_sleep) raw_spinlock_t *cpu_lock = per_cpu_ptr(&cgroup_rstat_cpu_lock, cpu); struct cgroup *pos = NULL; + unsigned long flags; - raw_spin_lock(cpu_lock); + raw_spin_lock_irqsave(cpu_lock, flags); while ((pos = cgroup_rstat_cpu_pop_updated(pos, cgrp, cpu))) { struct cgroup_subsys_state *css; @@ -166,7 +167,7 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp, bool may_sleep) css->ss->css_rstat_flush(css, cpu); rcu_read_unlock(); } - raw_spin_unlock(cpu_lock); + raw_spin_unlock_irqrestore(cpu_lock, flags); /* if @may_sleep, play nice and yield if necessary */ if (may_sleep && (need_resched() || From patchwork Tue Mar 1 12:21:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 12764682 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5740CC433F5 for ; Tue, 1 Mar 2022 12:21:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86F438D0005; Tue, 1 Mar 2022 07:21:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D0568D0001; Tue, 1 Mar 2022 07:21:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 620AF8D0005; Tue, 1 Mar 2022 07:21:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 447EB8D0001 for ; Tue, 1 Mar 2022 07:21:53 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 129D081BF8 for ; Tue, 1 Mar 2022 12:21:53 +0000 (UTC) X-FDA: 79195728906.06.E6DFB5C Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf01.hostedemail.com (Postfix) with ESMTP id 7FA0C40004 for ; Tue, 1 Mar 2022 12:21:52 +0000 (UTC) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1646137310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MkBV1p2duSsoNMrj3lAoV1bq8psnWoqvtGtulisyZvo=; b=mcYC9YHHcxfeuyhzzO2lCCjI97B1nOA6o7f+Uwyv65FMymcttSPv19lKK0WRBL7AZbZGDw aW6/JPK8NCu8HtmmwWYRHP7fqixuYxLvWTUq1f9rpVn7iVBmYicO4A90TRaPIOcr6twDKL qSemOLDdQeOQnRgxo1DJdQ8gE/LdYCryxzWTKwbgsKSUjABLA58HvsiEjk9lbGKdwGGeeP qIFinPAcZ3zfNrAra3yrn95dgOgUfg5Kwmb9JhPcV1PsLb2NVUrEien6uU7lJKi/UeouhT pdD99SBzhNcSGsGFQBCYv9fJBW8cUq6TYYfYBDQIQF5l/5fRlEEk4MEuY32p+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1646137310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MkBV1p2duSsoNMrj3lAoV1bq8psnWoqvtGtulisyZvo=; b=zAGbPeMcmFPlhqSZK14/x/lmF/lv2bSohWisuiGxy/cWxSlRLJ0WGfH7uPLUaLnAH1b26F iSG1Vg00XVK6LhCg== To: cgroups@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner , Tejun Heo , Zefan Li , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 2/2] mm: workingset: Replace IRQ-off check with a lockdep assert. Date: Tue, 1 Mar 2022 13:21:43 +0100 Message-Id: <20220301122143.1521823-3-bigeasy@linutronix.de> In-Reply-To: <20220301122143.1521823-1-bigeasy@linutronix.de> References: <[PATCH 0/2] Correct locking assumption on PREEMPT_RT> <20220301122143.1521823-1-bigeasy@linutronix.de> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7FA0C40004 X-Stat-Signature: gnddfw11a7pjnambtqnajc1c8it6b5h1 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=mcYC9YHH; dkim=pass header.d=linutronix.de header.s=2020e header.b=zAGbPeMc; spf=pass (imf01.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de X-Rspam-User: X-HE-Tag: 1646137312-413916 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Commit 68d48e6a2df57 ("mm: workingset: add vmstat counter for shadow nodes") introduced an IRQ-off check to ensure that a lock is held which also disabled interrupts. This does not work the same way on PREEMPT_RT because none of the locks, that are held, disable interrupts. Replace this check with a lockdep assert which ensures that the lock is held. Signed-off-by: Sebastian Andrzej Siewior --- mm/workingset.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/workingset.c b/mm/workingset.c index 2e4fd7c3296fe..8a3828acc0bfd 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -434,6 +434,8 @@ struct list_lru shadow_nodes; void workingset_update_node(struct xa_node *node) { + struct address_space *mapping; + /* * Track non-empty nodes that contain only shadow entries; * unlink those that contain pages or are being freed. @@ -442,7 +444,8 @@ void workingset_update_node(struct xa_node *node) * already where they should be. The list_empty() test is safe * as node->private_list is protected by the i_pages lock. */ - VM_WARN_ON_ONCE(!irqs_disabled()); /* For __inc_lruvec_page_state */ + mapping = container_of(node->array, struct address_space, i_pages); + lockdep_assert_held(&mapping->i_pages.xa_lock); if (node->count && node->count == node->nr_values) { if (list_empty(&node->private_list)) {