From patchwork Thu Jun 12 01:47:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 4338991 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 9CA1B9F333 for ; Thu, 12 Jun 2014 00:48:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A77872028D for ; Thu, 12 Jun 2014 00:48:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A596020340 for ; Thu, 12 Jun 2014 00:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755224AbaFLAsD (ORCPT ); Wed, 11 Jun 2014 20:48:03 -0400 Received: from mail-wg0-f52.google.com ([74.125.82.52]:46212 "EHLO mail-wg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754340AbaFLAsB (ORCPT ); Wed, 11 Jun 2014 20:48:01 -0400 Received: by mail-wg0-f52.google.com with SMTP id b13so473559wgh.23 for ; Wed, 11 Jun 2014 17:47:59 -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=ZUHTpoU8Qj6fiMTIYFbdRudKqaBaXftccZk/VuIFDjU=; b=VbDlvWtfRx38Le8JpqDUejzcQrlp9vkt/BWbO74+BhYt7vmj9qi7snUKRS9vh2dAYE ay+YuRJOufa4oKg/ag40tC23D8DFyCPw7MozmInFBpnUZ/uZv8Dw8AYqM+NFM5E6OmRD 7jNa+M9lUBdA2qip0RG2beNR8s0RiPKlPK1XnjBQ0j07COFmra2aVZhAEq4PvMH7b9CU 7z85+GoUkJR5vW8tgLxN9chF0K9p47uG8BIfOL7AUELIp4RYW8xSUYEAJqa1AgCOogLi wOOsVn59/XCu8abRTsYVSaKCV1wF28/lSmC++BU/qrHpqp/5UNTuZcAoLohuX7opriWK idwQ== X-Received: by 10.194.23.135 with SMTP id m7mr56454638wjf.2.1402534079618; Wed, 11 Jun 2014 17:47:59 -0700 (PDT) Received: from debian-vm3.lan (bl10-142-30.dsl.telepac.pt. [85.243.142.30]) by mx.google.com with ESMTPSA id bp2sm233498wib.9.2014.06.11.17.47.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jun 2014 17:47:58 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH v2] Btrfs: fix qgroups sanity test crash or hang Date: Thu, 12 Jun 2014 02:47:37 +0100 Message-Id: <1402537657-3172-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1402531956-27668-1-git-send-email-fdmanana@gmail.com> References: <1402531956-27668-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 Often when running the qgroups sanity test, a crash or a hang happened. This is because the extent buffer the test uses for the root node doesn't have an header level explicitly set, making it have a random level value. This is a problem when it's not zero for the btrfs_search_slot() calls the test ends up doing, resulting in crashes or hangs such as the following: [ 6454.127192] Btrfs loaded, debug=on, assert=on, integrity-checker=on (...) [ 6454.127760] BTRFS: selftest: Running qgroup tests [ 6454.127964] BTRFS: selftest: Running test_test_no_shared_qgroup [ 6454.127966] BTRFS: selftest: Qgroup basic add [ 6480.152005] BUG: soft lockup - CPU#0 stuck for 23s! [modprobe:5383] [ 6480.152005] Modules linked in: btrfs(+) xor raid6_pq binfmt_misc nfsd auth_rpcgss oid_registry nfs_acl nfs lockd fscache sunrpc i2c_piix4 i2c_core pcspkr evbug psmouse serio_raw e1000 [last unloaded: btrfs] [ 6480.152005] irq event stamp: 188448 [ 6480.152005] hardirqs last enabled at (188447): [] restore_args+0x0/0x30 [ 6480.152005] hardirqs last disabled at (188448): [] apic_timer_interrupt+0x6a/0x80 [ 6480.152005] softirqs last enabled at (188446): [] __do_softirq+0x1cf/0x450 [ 6480.152005] softirqs last disabled at (188441): [] irq_exit+0xb5/0xc0 [ 6480.152005] CPU: 0 PID: 5383 Comm: modprobe Not tainted 3.15.0-rc8-fdm-btrfs-next-33+ #4 [ 6480.152005] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 [ 6480.152005] task: ffff8802146125a0 ti: ffff8800d0d00000 task.ti: ffff8800d0d00000 [ 6480.152005] RIP: 0010:[] [] __write_lock_failed+0x13/0x20 [ 6480.152005] RSP: 0018:ffff8800d0d038e8 EFLAGS: 00000287 [ 6480.152005] RAX: 0000000000000000 RBX: ffffffff8168ef5c RCX: 000005deb8525852 [ 6480.152005] RDX: 0000000000000000 RSI: 0000000000001d45 RDI: ffff8802105000b8 [ 6480.152005] RBP: ffff8800d0d038e8 R08: fffffe12710f63db R09: ffffffffa03196fb [ 6480.152005] R10: ffff8802146125a0 R11: ffff880214612e28 R12: ffff8800d0d03858 [ 6480.152005] R13: 0000000000000000 R14: ffff8800d0d00000 R15: ffff8802146125a0 [ 6480.152005] FS: 00007f14ff804700(0000) GS:ffff880215e00000(0000) knlGS:0000000000000000 [ 6480.152005] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b [ 6480.152005] CR2: 00007fff4df0dac8 CR3: 00000000d1796000 CR4: 00000000000006f0 [ 6480.152005] Stack: [ 6480.152005] ffff8800d0d03908 ffffffff810ae967 0000000000000001 ffff8802105000b8 [ 6480.152005] ffff8800d0d03938 ffffffff8168e57e ffffffffa0319c16 0000000000000007 [ 6480.152005] ffff880210500000 ffff880210500100 ffff8800d0d039b8 ffffffffa0319c16 [ 6480.152005] Call Trace: [ 6480.152005] [] do_raw_write_lock+0x47/0xa0 [ 6480.152005] [] _raw_write_lock+0x5e/0x80 [ 6480.152005] [] ? btrfs_tree_lock+0x116/0x270 [btrfs] [ 6480.152005] [] btrfs_tree_lock+0x116/0x270 [btrfs] [ 6480.152005] [] btrfs_lock_root_node+0x3b/0x50 [btrfs] [ 6480.152005] [] btrfs_search_slot+0x916/0xa20 [btrfs] [ 6480.152005] [] ? create_object+0x23f/0x300 [ 6480.152005] [] btrfs_insert_empty_items+0x78/0xd0 [btrfs] [ 6480.152005] [] insert_normal_tree_ref.constprop.4+0xa2/0x19a [btrfs] [ 6480.152005] [] test_no_shared_qgroup+0xb1/0x1ca [btrfs] [ 6480.152005] [] ? local_clock+0x16/0x30 [ 6480.152005] [] btrfs_test_qgroups+0x1ae/0x1d7 [btrfs] [ 6480.152005] [] ? ftrace_define_fields_btrfs_space_reservation+0xfd/0xfd [btrfs] [ 6480.152005] [] init_btrfs_fs+0xb4/0x153 [btrfs] [ 6480.152005] [] do_one_initcall+0x102/0x150 [ 6480.152005] [] ? set_memory_nx+0x43/0x50 [ 6480.152005] [] ? set_section_ro_nx+0x6d/0x74 [ 6480.152005] [] load_module+0x1cdc/0x2630 (...) Therefore initialize the extent buffer as an empty leaf (level 0). Issue easy to reproduce when btrfs is built as a module via: $ for ((i = 1; i <= 1000000; i++)); do rmmod btrfs; modprobe btrfs; done Signed-off-by: Filipe David Borba Manana --- V2: Fixed silly mistake. Set root->node's header level and nritems after checking if root->node is not null. fs/btrfs/tests/qgroup-tests.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/tests/qgroup-tests.c b/fs/btrfs/tests/qgroup-tests.c index fa691b7..ec3dcb2 100644 --- a/fs/btrfs/tests/qgroup-tests.c +++ b/fs/btrfs/tests/qgroup-tests.c @@ -415,6 +415,8 @@ int btrfs_test_qgroups(void) ret = -ENOMEM; goto out; } + btrfs_set_header_level(root->node, 0); + btrfs_set_header_nritems(root->node, 0); root->alloc_bytenr += 8192; tmp_root = btrfs_alloc_dummy_root();