Received: by 10.213.65.68 with SMTP id h4csp270051imn; Fri, 23 Mar 2018 04:23:18 -0700 (PDT) X-Google-Smtp-Source: AG47ELuarTgzNku41kBcdDu0TdSJE1pF8k2RW/IY3+HYK4unamixqmG6I+JG37GGW/pyXDKihwWE X-Received: by 10.99.106.68 with SMTP id f65mr20611729pgc.343.1521804197950; Fri, 23 Mar 2018 04:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521804197; cv=none; d=google.com; s=arc-20160816; b=XIWqtvZlhMZGaPsrBs8gqohcfzGhjGRtQOixw1PinLkbZrhWmhxxVLBw88/YrX5pOf Iay/se3fHPE6EKOTSATWB3mrLWEx7LbOeb4wB0PAmN+1cCWHy3K/IzVH8x4krShEqAk7 H9NYBzfIg978PpgmD8mvYKcU7UEsz2OJzMPCBqxaO7+0XE6hcRXVOdSF3xhlXG17iv05 U1nXP4pOK3mLFbG7xgDFrzp9FTSXGk2cdjF1WzlbThLxR+YwTjHwwvpVTD+dixbIpjYn Dw6yNPa4dSuDfcbsCcaMcM2PssZ0ydrHbQD22DjnlC+ATVV32Nwyk82Dd6fui4qsAQ8m qdaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Gamv6oFa9cn3jGIUfbw2wr5++C21x4UrsSs4hgd3KFw=; b=nQVl1zkeapaGPiw+XmWlpLcLEhamCpkKg9ItNzhyEGWMWFV4a9e1IkBuUsse8Dhe/Z CP9MjjnE/xqVhpOwkd9EkQSVkjorGqD7pr2/VF+13eYB4kv6VRYezO6sLsZiDn7gS7A6 qGY5TXlDsulwcsYAPSjkT5Vd5j2KbdPKJGXN78FRlEtZZAP46Yxpc+OjlPM8njUK8Mkw ZAS2EPi3xjX2TGoQkvv3glDZj3sL2qFFazDYDJLQsfJVPQu8rH1rFJoahtP4sxmaO/iG Y3CZpQX6Iu2xJE8lqok7jZpsJ7csGV8fCOZtlUzqtkhiRJOPBMzvQ39Vbp+cEQBCSuNW feNg== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 92-v6si8323048plc.713.2018.03.23.04.23.03; Fri, 23 Mar 2018 04:23:17 -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; 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 S1755498AbeCWKIN (ORCPT + 99 others); Fri, 23 Mar 2018 06:08:13 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:41552 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755128AbeCWKIH (ORCPT ); Fri, 23 Mar 2018 06:08:07 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 01051D8E; Fri, 23 Mar 2018 10:08:06 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , Sasha Levin Subject: [PATCH 4.9 076/177] Btrfs: fix incorrect space accounting after failure to insert inline extent Date: Fri, 23 Mar 2018 10:53:24 +0100 Message-Id: <20180323094208.668814409@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094205.090519271@linuxfoundation.org> References: <20180323094205.090519271@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana [ Upstream commit 1c81ba237bcecad9bc885a1ddcf02d725ea38482 ] When using compression, if we fail to insert an inline extent we incorrectly end up attempting to free the reserved data space twice, once through extent_clear_unlock_delalloc(), because we pass it the flag EXTENT_DO_ACCOUNTING, and once through a direct call to btrfs_free_reserved_data_space_noquota(). This results in a trace like the following: [ 834.576240] ------------[ cut here ]------------ [ 834.576825] WARNING: CPU: 2 PID: 486 at fs/btrfs/extent-tree.c:4316 btrfs_free_reserved_data_space_noquota+0x60/0x9f [btrfs] [ 834.579501] Modules linked in: btrfs crc32c_generic xor raid6_pq ppdev i2c_piix4 acpi_cpufreq psmouse tpm_tis parport_pc pcspkr serio_raw tpm_tis_core sg parport evdev i2c_core tpm button loop autofs4 ext4 crc16 jbd2 mbcache sr_mod cdrom sd_mod ata_generic virtio_scsi ata_piix virtio_pci libata virtio_ring virtio scsi_mod e1000 floppy [last unloaded: btrfs] [ 834.592116] CPU: 2 PID: 486 Comm: kworker/u32:4 Not tainted 4.10.0-rc8-btrfs-next-37+ #2 [ 834.593316] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.1-0-gb3ef39f-prebuilt.qemu-project.org 04/01/2014 [ 834.595273] Workqueue: btrfs-delalloc btrfs_delalloc_helper [btrfs] [ 834.596103] Call Trace: [ 834.596103] dump_stack+0x67/0x90 [ 834.596103] __warn+0xc2/0xdd [ 834.596103] warn_slowpath_null+0x1d/0x1f [ 834.596103] btrfs_free_reserved_data_space_noquota+0x60/0x9f [btrfs] [ 834.596103] compress_file_range.constprop.42+0x2fa/0x3fc [btrfs] [ 834.596103] ? submit_compressed_extents+0x3a7/0x3a7 [btrfs] [ 834.596103] async_cow_start+0x32/0x4d [btrfs] [ 834.596103] btrfs_scrubparity_helper+0x187/0x3e7 [btrfs] [ 834.596103] btrfs_delalloc_helper+0xe/0x10 [btrfs] [ 834.596103] process_one_work+0x273/0x4e4 [ 834.596103] worker_thread+0x1eb/0x2ca [ 834.596103] ? rescuer_thread+0x2b6/0x2b6 [ 834.596103] kthread+0x100/0x108 [ 834.596103] ? __list_del_entry+0x22/0x22 [ 834.596103] ret_from_fork+0x2e/0x40 [ 834.611656] ---[ end trace 719902fe6bdef08f ]--- So fix this by not calling directly btrfs_free_reserved_data_space_noquota() if an error happened. Signed-off-by: Filipe Manana Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -567,8 +567,10 @@ cont: PAGE_SET_WRITEBACK | page_error_op | PAGE_END_WRITEBACK); - btrfs_free_reserved_data_space_noquota(inode, start, - end - start + 1); + if (ret == 0) + btrfs_free_reserved_data_space_noquota(inode, + start, + end - start + 1); goto free_pages_out; } }