Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp996126yba; Thu, 4 Apr 2019 02:02:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyG7a+e12zSwZuX5qfTl46uiXDb8O/w1uFZ9ohxG1iWPI9X2ZdJmz/KeU0Zd5z+Q1XDSj+C X-Received: by 2002:a17:902:a81:: with SMTP id 1mr5045792plp.308.1554368546196; Thu, 04 Apr 2019 02:02:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368546; cv=none; d=google.com; s=arc-20160816; b=QmUqZnccp8e0pKKR3QQI4b3v98X1EI0IG2WiAipTwTG0z59w6OLUe+4h8qtuG5Z6iI Yzc0UmmgTChXGDRuG3oiywTxakqtm0M0NAZkSBbT25H0HtAxlCkxl+fDfS59hO12davS Q/wmZRRk3P8yHcDNIQ8j8moZzvtIimLrPhQc4baQPeHVmQuafXimrUltKAP1jSuCNOOX Poo1vNJy/k8UA0OFwbzlpN7YKn7q+5NYtKKWAH+2my5pVSVVoOQxUtg5ucbrgm1XUltV zk5sHXbzPIl+JcfDm4Yhauz+G7ltt4PQgqoDHyTZcC31fMQBJZp6qFTy7Re0WOo5DJbv C3cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+L6nzqNlW+vLoWKuOPBSTz/hn1DbwPNE8P8bZG+sEoE=; b=LGProWwggBaJ33aI5hMWRYFwitJM13iNfNcFk+vtv8HR4fQ87J98fzJEuw21I2DMHn CKPtoLFPWipXGYcIA+ppRQqv4bwQmUnI/n/naHfYIJVy7joK3SHcnjFeAnSONVqpL8im +MpVnVYvRpx7xAeSFBnCnACLjfmvIHUUE/Amad0MvYpFU6+UBT1gAILKafjClHKxc9Uz QZM9M/emHAaDX02xiAZ092mHn1/WCsIdU3Qxf4Io9mhDvO1oSA10hLBPN81p56UWeJFH wh5xd5c46CS1xV38hRP7xWuYQ1GhvC1lYTudP7BvkFjBnScdCAUFnyDlKMXpYEPFBC9h uriQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ri43+yjy; 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 z73si15986298pgd.345.2019.04.04.02.02.11; Thu, 04 Apr 2019 02:02:26 -0700 (PDT) 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=ri43+yjy; 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 S1730646AbfDDJAY (ORCPT + 99 others); Thu, 4 Apr 2019 05:00:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:37042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731237AbfDDJAW (ORCPT ); Thu, 4 Apr 2019 05:00:22 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7C43121741; Thu, 4 Apr 2019 09:00:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368421; bh=HRnhZo12Ruls5t5FZrceU4JZRheRi+ZIRlSrcB6yABE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ri43+yjyTGq9FZT4vD40svY/C27fZQWqk+NJG1xjfNAaymTcA30ih/WtacqC3pUgN Z7VH+Lgh8lrxJA3q8vo4WDQUdUVK9PwtLy/Tw9ZG9LGvkXSYEx0+9XuUiFnZWtivFa OuP+jowhfJcHZW+SD43b0MbNOa2WFOXhGGjqXg3E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sahitya Tummala , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 4.19 033/187] f2fs: do not use mutex lock in atomic context Date: Thu, 4 Apr 2019 10:46:10 +0200 Message-Id: <20190404084604.618119092@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 9083977dabf3833298ddcd40dee28687f1e6b483 ] Fix below warning coming because of using mutex lock in atomic context. BUG: sleeping function called from invalid context at kernel/locking/mutex.c:98 in_atomic(): 1, irqs_disabled(): 0, pid: 585, name: sh Preemption disabled at: __radix_tree_preload+0x28/0x130 Call trace: dump_backtrace+0x0/0x2b4 show_stack+0x20/0x28 dump_stack+0xa8/0xe0 ___might_sleep+0x144/0x194 __might_sleep+0x58/0x8c mutex_lock+0x2c/0x48 f2fs_trace_pid+0x88/0x14c f2fs_set_node_page_dirty+0xd0/0x184 Do not use f2fs_radix_tree_insert() to avoid doing cond_resched() with spin_lock() acquired. Signed-off-by: Sahitya Tummala Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/trace.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/trace.c b/fs/f2fs/trace.c index a1fcd00bbb2b..8ac1851a21c0 100644 --- a/fs/f2fs/trace.c +++ b/fs/f2fs/trace.c @@ -17,7 +17,7 @@ #include "trace.h" static RADIX_TREE(pids, GFP_ATOMIC); -static struct mutex pids_lock; +static spinlock_t pids_lock; static struct last_io_info last_io; static inline void __print_last_io(void) @@ -61,23 +61,29 @@ void f2fs_trace_pid(struct page *page) set_page_private(page, (unsigned long)pid); +retry: if (radix_tree_preload(GFP_NOFS)) return; - mutex_lock(&pids_lock); + spin_lock(&pids_lock); p = radix_tree_lookup(&pids, pid); if (p == current) goto out; if (p) radix_tree_delete(&pids, pid); - f2fs_radix_tree_insert(&pids, pid, current); + if (radix_tree_insert(&pids, pid, current)) { + spin_unlock(&pids_lock); + radix_tree_preload_end(); + cond_resched(); + goto retry; + } trace_printk("%3x:%3x %4x %-16s\n", MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev), pid, current->comm); out: - mutex_unlock(&pids_lock); + spin_unlock(&pids_lock); radix_tree_preload_end(); } @@ -122,7 +128,7 @@ void f2fs_trace_ios(struct f2fs_io_info *fio, int flush) void f2fs_build_trace_ios(void) { - mutex_init(&pids_lock); + spin_lock_init(&pids_lock); } #define PIDVEC_SIZE 128 @@ -150,7 +156,7 @@ void f2fs_destroy_trace_ios(void) pid_t next_pid = 0; unsigned int found; - mutex_lock(&pids_lock); + spin_lock(&pids_lock); while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) { unsigned idx; @@ -158,5 +164,5 @@ void f2fs_destroy_trace_ios(void) for (idx = 0; idx < found; idx++) radix_tree_delete(&pids, pid[idx]); } - mutex_unlock(&pids_lock); + spin_unlock(&pids_lock); } -- 2.19.1