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() ||