Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp799213imm; Mon, 21 May 2018 14:42:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqKOMYRPt0PPEJNQtMRHr98moQI2xujsE2dqk5CxlpiilNraHjN6EsYyn59I1G74TG1p9pr X-Received: by 2002:a17:902:6b47:: with SMTP id g7-v6mr22056710plt.251.1526938921088; Mon, 21 May 2018 14:42:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526938921; cv=none; d=google.com; s=arc-20160816; b=sjARHiblWECpYSuX6HO1X5okSFW0ZSGI+ISb1zW+tamy3pY8rDc1pK0RUBhZFIt7/5 753I8nNpDN62Anr0PBFFyERXxDR9bVGDz5ItD0EpMHlZ74lqXGehdJpH2mc2amfGmLmK HnHbD08guVfVOi2fN6jKf68Dee9M1Vo2SIOQ4qCtaaSo2vFJdlZbRK+10niFBD1YvZo+ FvxMAlY4BqWtXNCLWbwV6wAYdQNyhqGHclwuZIXTApSuQt0jo6o0IDbVMloBPQ42INfK cxEPeHhqJUJlW/eX3h2PZUyftgvWko1GzqKoP5QRX96DPK0bWG07XPHii+36e2WWjwmi JTkQ== 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:dkim-signature :arc-authentication-results; bh=5Ro5Gx4+v9TTNOg+s4HK23QgmT+ZnUEFhnuqlQUU+lg=; b=AAcBUzsBdvPq7v2+CIDkxPtjgCj/U/KT52CtBVMyDc6SZroURxMemakpXVdI3Y5ATw syLq+8xGwcwEgV7rfkU9VpIW53CAhG/p+fuGfrFJZV6Vxu6L84v9XZZRj4ZqeesKLsBU FIkqBuFzqvcKsWcPFhPkAYo+VJfZY/vaeKCZ3IVGqvGb4yqB/kqNFSerpKKC6p2Mjv2D deFalCnjwvtT90QEIGLXatJCkIhae64VZPHb+YJCZYq+wjtpVieGgjSAMuv6ZSvl4q/O xYH/iLGnO6tlVSoyWf6mA0y59I5TeX/kaPZM+b9ZMR0JhY1FKEohxNHdwPefLxnP/tXE IyVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QLHzAcTx; 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 bj6-v6si14812360plb.405.2018.05.21.14.41.46; Mon, 21 May 2018 14:42:01 -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=QLHzAcTx; 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 S1754538AbeEUVlh (ORCPT + 99 others); Mon, 21 May 2018 17:41:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:39554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932306AbeEUVYk (ORCPT ); Mon, 21 May 2018 17:24:40 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 64B4420853; Mon, 21 May 2018 21:24:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526937879; bh=CjAIyxkI0GJs+jfeJP4+roTPtEy57GoF1AQEq7VY21w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QLHzAcTxDts6KKvaLiDARZ0cQ6o6cvZjBJchK4a3Uwd7ZBEgz0XlXQaa5dSPcOnF5 3zC7A9SfArxhJJzE69EWt+gwVEmyX9ODkQYqoREYmx7oIgR7p+e3/2boc7rcxrRUEO Hjna1pfj6zNnBHe7Ged4U0UUGOnPT4KDHGbYkmRA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anand Jain , David Sterba Subject: [PATCH 4.16 058/110] btrfs: fix crash when trying to resume balance without the resume flag Date: Mon, 21 May 2018 23:11:55 +0200 Message-Id: <20180521210511.031885735@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521210503.823249477@linuxfoundation.org> References: <20180521210503.823249477@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.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Anand Jain commit 02ee654d3a04563c67bfe658a05384548b9bb105 upstream. We set the BTRFS_BALANCE_RESUME flag in the btrfs_recover_balance() only, which isn't called during the remount. So when resuming from the paused balance we hit the bug: kernel: kernel BUG at fs/btrfs/volumes.c:3890! :: kernel: balance_kthread+0x51/0x60 [btrfs] kernel: kthread+0x111/0x130 :: kernel: RIP: btrfs_balance+0x12e1/0x1570 [btrfs] RSP: ffffba7d0090bde8 Reproducer: On a mounted filesystem: btrfs balance start --full-balance /btrfs btrfs balance pause /btrfs mount -o remount,ro /dev/sdb /btrfs mount -o remount,rw /dev/sdb /btrfs To fix this set the BTRFS_BALANCE_RESUME flag in btrfs_resume_balance_async(). CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Anand Jain Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/volumes.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4046,6 +4046,15 @@ int btrfs_resume_balance_async(struct bt return 0; } + /* + * A ro->rw remount sequence should continue with the paused balance + * regardless of who pauses it, system or the user as of now, so set + * the resume flag. + */ + spin_lock(&fs_info->balance_lock); + fs_info->balance_ctl->flags |= BTRFS_BALANCE_RESUME; + spin_unlock(&fs_info->balance_lock); + tsk = kthread_run(balance_kthread, fs_info, "btrfs-balance"); return PTR_ERR_OR_ZERO(tsk); }