From patchwork Tue Jun 10 18:17:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 4329931 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 310289F1D6 for ; Tue, 10 Jun 2014 17:18:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 39141202E9 for ; Tue, 10 Jun 2014 17:18:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CBA3202E5 for ; Tue, 10 Jun 2014 17:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752194AbaFJRSW (ORCPT ); Tue, 10 Jun 2014 13:18:22 -0400 Received: from mail-we0-f170.google.com ([74.125.82.170]:57700 "EHLO mail-we0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751851AbaFJRSV (ORCPT ); Tue, 10 Jun 2014 13:18:21 -0400 Received: by mail-we0-f170.google.com with SMTP id w61so1038248wes.29 for ; Tue, 10 Jun 2014 10:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GYupPTl8lBgcb6VDokUhQ4s+oOu328WwhwBQ3FkNNQ8=; b=z5lUnrSsxFFaAA7jkK//C7lpkaXndqR1WzOMXffMtURYFBNiIPllechd8bWxzsQOqo 1DFi4HfzIY7EnDmvROqO1CFxy6rxXiqNbP1i7siWmvl4trUyfiNeeRGXC/3wi5mE8q7E VwIVDMZcWgQchPP32IBMfLjaMWRas+oKfLgmiJH/OwXVGL5nB3g4R/Pib4oEFb02wyRc 2oFBDZ7xgGYh4+W7+KKBWFMlBTTt38gwGDF/Ldk4PnpxZfMqhNbFdvWrn47qNE++jyHz cfwri3njqHderEbHLDORMp8hIJGQAOp3mEvTjwEK8sShiNvLzqWPXj2ZescNzUUp2nMT fSAw== X-Received: by 10.194.92.148 with SMTP id cm20mr41844323wjb.53.1402420699728; Tue, 10 Jun 2014 10:18:19 -0700 (PDT) Received: from debian-vm3.lan (bl10-142-30.dsl.telepac.pt. [85.243.142.30]) by mx.google.com with ESMTPSA id di10sm30475283wjb.1.2014.06.10.10.18.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Jun 2014 10:18:18 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH v2] Btrfs: fix RCU correctness warning when running sanity tests Date: Tue, 10 Jun 2014 19:17:16 +0100 Message-Id: <1402424236-13459-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1402423961-12169-1-git-send-email-fdmanana@gmail.com> References: <1402423961-12169-1-git-send-email-fdmanana@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When CONFIG_PROVE_RCU=y and CONFIG_PROVE_RCU_REPEATEDLY=y, the following was dumped in dmesg: [ 3197.218064] =============================== [ 3197.218064] [ INFO: suspicious RCU usage. ] [ 3197.218066] 3.15.0-rc8-fdm-btrfs-next-33+ #4 Not tainted [ 3197.218067] ------------------------------- [ 3197.218068] include/linux/radix-tree.h:196 suspicious rcu_dereference_check() usage! [ 3197.218068] [ 3197.218068] other info that might help us debug this: [ 3197.218068] [ 3197.218070] [ 3197.218070] rcu_scheduler_active = 1, debug_locks = 1 [ 3197.218071] 1 lock held by modprobe/12024: [ 3197.218072] #0: (&(&fs_info->buffer_lock)->rlock){+.+...}, at: [] btrfs_free_dummy_root+0x5a/0x1d0 [btrfs] [ 3197.218093] [ 3197.218093] stack backtrace: [ 3197.218095] CPU: 3 PID: 12024 Comm: modprobe Not tainted 3.15.0-rc8-fdm-btrfs-next-33+ #4 [ 3197.218096] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 [ 3197.218097] 0000000000000001 ffff8800af18fc18 ffffffff81685c5a 000000000000feb0 [ 3197.218099] ffff8800cf6ccb40 ffff8800af18fc48 ffffffff810a6316 ffff8801d955f640 [ 3197.218101] ffff8800d719e328 ffff8800d719e370 ffff8800d719c000 ffff8800af18fcb8 [ 3197.218102] Call Trace: [ 3197.218105] [] dump_stack+0x4e/0x68 [ 3197.218108] [] lockdep_rcu_suspicious+0xe6/0x130 [ 3197.218119] [] btrfs_free_dummy_root+0x188/0x1d0 [btrfs] [ 3197.218129] [] btrfs_test_qgroups+0xea/0x1bb [btrfs] [ 3197.218137] [] ? ftrace_define_fields_btrfs_space_reservation+0xfd/0xfd [btrfs] [ 3197.218144] [] ? ftrace_define_fields_btrfs_space_reservation+0xfd/0xfd [btrfs] [ 3197.218151] [] init_btrfs_fs+0xe5/0x184 [btrfs] [ 3197.218154] [] do_one_initcall+0x102/0x150 [ 3197.218157] [] ? set_memory_nx+0x43/0x50 [ 3197.218160] [] ? set_section_ro_nx+0x6d/0x74 [ 3197.218162] [] load_module+0x1cdc/0x2630 [ 3197.218164] [] ? show_initstate+0x60/0x60 [ 3197.218166] [] SyS_finit_module+0x8e/0x90 [ 3197.218168] [] system_call_fastpath+0x16/0x1b Signed-off-by: Filipe David Borba Manana --- V2: Added missing rcu read unlock if a retry is needed. fs/btrfs/tests/btrfs-tests.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c index a5dcacb..bdb1f05 100644 --- a/fs/btrfs/tests/btrfs-tests.c +++ b/fs/btrfs/tests/btrfs-tests.c @@ -130,8 +130,8 @@ static void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info) struct radix_tree_iter iter; void **slot; - spin_lock(&fs_info->buffer_lock); restart: + rcu_read_lock(); radix_tree_for_each_slot(slot, &fs_info->buffer_radix, &iter, 0) { struct extent_buffer *eb; @@ -140,15 +140,17 @@ restart: continue; /* Shouldn't happen but that kind of thinking creates CVE's */ if (radix_tree_exception(eb)) { - if (radix_tree_deref_retry(eb)) + if (radix_tree_deref_retry(eb)) { + rcu_read_unlock(); goto restart; + } continue; } - spin_unlock(&fs_info->buffer_lock); + rcu_read_unlock(); free_extent_buffer_stale(eb); - spin_lock(&fs_info->buffer_lock); + goto restart; } - spin_unlock(&fs_info->buffer_lock); + rcu_read_unlock(); btrfs_free_qgroup_config(fs_info); btrfs_free_fs_roots(fs_info);