From patchwork Wed Feb 24 22:47:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 62846 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp2685814lbl; Wed, 24 Feb 2016 15:10:51 -0800 (PST) X-Received: by 10.98.70.139 with SMTP id o11mr58636731pfi.123.1456355451109; Wed, 24 Feb 2016 15:10:51 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 82si7813991pfq.218.2016.02.24.15.10.50; Wed, 24 Feb 2016 15:10:51 -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; 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; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758521AbcBXXKt (ORCPT + 30 others); Wed, 24 Feb 2016 18:10:49 -0500 Received: from mail-pf0-f175.google.com ([209.85.192.175]:35481 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753747AbcBXXKr (ORCPT ); Wed, 24 Feb 2016 18:10:47 -0500 Received: by mail-pf0-f175.google.com with SMTP id c10so21805883pfc.2 for ; Wed, 24 Feb 2016 15:10:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=8BH5oyqwOk3rx7WlRbCImP2wF2O27ZF0WbHy3/YO2nA=; b=hIeRCjznG+isPqM+bmdyndUyJTCG8wEkJTcTKRSTgCSVfif7nrFh5Cf1+/SoCTW7An UUIe2LvS7Ncp7LmBbuHCK7cIL7TbpuBVN1OFoCcmHWw/3bPhqQFySwAq57bNdBwaNdNX xecKBiVJ5Wkuh+G8RYbipw3u5GoBU2WnqU+ms= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8BH5oyqwOk3rx7WlRbCImP2wF2O27ZF0WbHy3/YO2nA=; b=iaKlP7qr7gcIVywcHOgp0UIhSq0FfZmyck3i9MJydl1q6KdjvagJMl6JtZ7DCTClUH HQFmdSQxGT8wZahAP5W9pOQcQKMMGA1ck3bWPNSCE2HtI0sjmD0vekFi5io5PyLRNISL JzUSywscYrfWFfrjPv3Mv1ALDeH9YM+Z8QRRnqwPCTNkRy5fsFaq+uie2Hxxo98DJ79L HasOUEI4kerDcX7/sQ220mleE1HFmw0Hbiswq1XVtxYTJqsKugUsa+viEMLkfNeklUCS i4I47i15kjxa2Hc37+Rh9QDoSpnkf1to10lF8hCSYuMJJL0b0BspBBK1TEGODIjEgdVR objw== X-Gm-Message-State: AG10YORoX0Uy7/2dbu/0jrXa2j3eCPU/ZRB2PyfduzHC5ivrDKm2zu+haxwIryCTOpdqDViL X-Received: by 10.98.86.139 with SMTP id h11mr58457014pfj.105.1456355447155; Wed, 24 Feb 2016 15:10:47 -0800 (PST) Received: from yshi-Precision-T5600.corp.ad.wrs.com (unknown-216-82.windriver.com. [147.11.216.82]) by smtp.gmail.com with ESMTPSA id 144sm7334024pfa.83.2016.02.24.15.10.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Feb 2016 15:10:46 -0800 (PST) From: Yang Shi To: tj@kernel.org, jack@suse.cz, axboe@fb.com, fengguang.wu@intel.com, tglx@linutronix.de, rostedt@goodmis.org, bigeasy@linutronix.de, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rt-users@vger.kernel.org, linaro-kernel@lists.linaro.org, yang.shi@linaro.org Subject: [PATCH] writeback: call writeback tracepoints withoud holding list_lock in wb_writeback() Date: Wed, 24 Feb 2016 14:47:23 -0800 Message-Id: <1456354043-31420-1-git-send-email-yang.shi@linaro.org> X-Mailer: git-send-email 2.0.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 5634cc2aa9aebc77bc862992e7805469dcf83dac ("writeback: update writeback tracepoints to report cgroup") made writeback tracepoints report cgroup writeback, but it may trigger the below bug on -rt kernel due to the list_lock held for the for loop in wb_writeback(). BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:930 in_atomic(): 1, irqs_disabled(): 0, pid: 625, name: kworker/u16:3 INFO: lockdep is turned off. Preemption disabled at:[] wb_writeback+0xec/0x830 CPU: 7 PID: 625 Comm: kworker/u16:3 Not tainted 4.4.1-rt5 #20 Hardware name: Freescale Layerscape 2085a RDB Board (DT) Workqueue: writeback wb_workfn (flush-7:0) Call trace: [] dump_backtrace+0x0/0x200 [] show_stack+0x24/0x30 [] dump_stack+0x88/0xa8 [] ___might_sleep+0x2ec/0x300 [] rt_spin_lock+0x38/0xb8 [] kernfs_path_len+0x30/0x90 [] trace_event_raw_event_writeback_work_class+0xe8/0x2e8 [] wb_writeback+0x620/0x830 [] wb_workfn+0x61c/0x950 [] process_one_work+0x3ac/0xb30 [] worker_thread+0x9c/0x7a8 [] kthread+0x190/0x1b0 [] ret_from_fork+0x10/0x30 The list_lock was moved outside the for loop by commit e8dfc30582995ae12454cda517b17d6294175b07 ("writeback: elevate queue_io() into wb_writeback())", however, the commit log says "No behavior change", so it sounds safe to have the list_lock acquired inside the for loop as it did before. Just acquire list_lock at the necessary points and keep all writeback tracepoints outside the critical area protected by list_lock in wb_writeback(). Signed-off-by: Yang Shi --- fs/fs-writeback.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) -- 2.0.2 diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 1f76d89..9b7b5f6 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1623,7 +1623,6 @@ static long wb_writeback(struct bdi_writeback *wb, work->older_than_this = &oldest_jif; blk_start_plug(&plug); - spin_lock(&wb->list_lock); for (;;) { /* * Stop writeback when nr_pages has been consumed @@ -1661,15 +1660,19 @@ static long wb_writeback(struct bdi_writeback *wb, oldest_jif = jiffies; trace_writeback_start(wb, work); + + spin_lock(&wb->list_lock); if (list_empty(&wb->b_io)) queue_io(wb, work); if (work->sb) progress = writeback_sb_inodes(work->sb, wb, work); else progress = __writeback_inodes_wb(wb, work); - trace_writeback_written(wb, work); wb_update_bandwidth(wb, wb_start); + spin_unlock(&wb->list_lock); + + trace_writeback_written(wb, work); /* * Did we write something? Try for more @@ -1693,15 +1696,14 @@ static long wb_writeback(struct bdi_writeback *wb, */ if (!list_empty(&wb->b_more_io)) { trace_writeback_wait(wb, work); + spin_lock(&wb->list_lock); inode = wb_inode(wb->b_more_io.prev); - spin_lock(&inode->i_lock); spin_unlock(&wb->list_lock); + spin_lock(&inode->i_lock); /* This function drops i_lock... */ inode_sleep_on_writeback(inode); - spin_lock(&wb->list_lock); } } - spin_unlock(&wb->list_lock); blk_finish_plug(&plug); return nr_pages - work->nr_pages;