Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3467476imu; Sun, 11 Nov 2018 15:46:52 -0800 (PST) X-Google-Smtp-Source: AJdET5fvBsUpJ3vHMOCPwJyWxNAp9Z7TEIE5EKCBjH5yQ47UkumxYHKfAC2DePqgNpdpzchkzuQq X-Received: by 2002:a17:902:5e4:: with SMTP id f91-v6mr4679765plf.75.1541980012682; Sun, 11 Nov 2018 15:46:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980012; cv=none; d=google.com; s=arc-20160816; b=SLWDQRGqS3nn+HuJ+798Gfgp17dZ1hAKYmtSTkxJYmT3ZbqJ5IP5fGW1Dh7BgEhfh7 cE4XzdtzNNnu++CDkcjE5DwN3/CRt8prG2+QiVbHjsgsO8zV8/rOAwojYacwk+zwnn5P Hb3I0JQYrxiVGpNgkTzKNsbmcbsDcz8T+hthogJS9Fv5Z9mP8k9Cq5vGitVFiIqeS0fo vIXSGMdB34QwcZADRwEB6/sbf0oA6G+Yi9b4IPBwqR+7vPZMGLpVmAx4BBMVgTzi2l6Z 7f00LaoSPdIaBHjewu3RcKF8Wbm/KO0mrWcrKVxkvBqZGLSjXrTAkDxvnl3lGt7rhss9 p6Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CAeonN8bZbu/fU1jQZBx6+gMAckwkNB/bYhb4cDGPy0=; b=HLGXQlNCzRNPQoUqr9rqmPktlM5U5COO/VhqoKDvvEOc896ja/xk9Qud1HWfFK/hEa GrxVbHusO7smnQIib9mc/xGK8loGGEj6pNbanTCGa0Vq+1DBIL6t1VMfGD+Gq1LoJOcL U4CeKou4wL9xddd3UmHtThBC5satkbHu+LAuvIiJz00Mtj5x78eN4vRkwDRZuyThwPgP sq16lQUrhvZFYgedGsqWXapOvxItkHbkrR2CXBKExfbkBu/g5OGQ19y+VnrMYzJEBwYX QWHsfkgCtLooj6NDRCKYJ9lTDSbOoBtwc8OQ9bknPBJ9OCw6p6ppkKfy1G3qUHKBNWRa UDZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mljtCqk1; 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 r23si15908811pgu.359.2018.11.11.15.46.37; Sun, 11 Nov 2018 15:46:52 -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; dkim=pass header.i=@kernel.org header.s=default header.b=mljtCqk1; 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 S1733282AbeKLITC (ORCPT + 99 others); Mon, 12 Nov 2018 03:19:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:39714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730141AbeKLITB (ORCPT ); Mon, 12 Nov 2018 03:19:01 -0500 Received: from localhost (unknown [206.108.79.134]) (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 9DD7A2154B; Sun, 11 Nov 2018 22:29:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975345; bh=3D1IRyOCPxtZGsc0nApRg02T/VdBPi4Kl/GTiB+gcv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mljtCqk1dBJbh5iYzNnSzAobABpt0OOKtOwN/G75HulUSNcgliMLjsHqL/KV1TRFt uCEDxoxxoEgCVoq6BfRnhrwhhhW8fM5qC+dGTE3P0GjvCjvmtxjVh20htW77MkAQ5t nwvRntI/kvejT7PcAfy5xpop/RvxtG7p+LGFM8Z0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Murphy , Qu Wenruo , David Sterba Subject: [PATCH 4.19 326/361] btrfs: qgroup: Avoid calling qgroup functions if qgroup is not enabled Date: Sun, 11 Nov 2018 14:21:13 -0800 Message-Id: <20181111221659.471431123@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qu Wenruo commit 3628b4ca64f24a4ec55055597d0cb1c814729f8b upstream. Some qgroup trace events like btrfs_qgroup_release_data() and btrfs_qgroup_free_delayed_ref() can still be triggered even if qgroup is not enabled. This is caused by the lack of qgroup status check before calling some qgroup functions. Thankfully the functions can handle quota disabled case well and just do nothing for qgroup disabled case. This patch will do earlier check before triggering related trace events. And for enabled <-> disabled race case: 1) For enabled->disabled case Disable will wipe out all qgroups data including reservation and excl/rfer. Even if we leak some reservation or numbers, it will still be cleared, so nothing will go wrong. 2) For disabled -> enabled case Current btrfs_qgroup_release_data() will use extent_io tree to ensure we won't underflow reservation. And for delayed_ref we use head->qgroup_reserved to record the reserved space, so in that case head->qgroup_reserved should be 0 and we won't underflow. CC: stable@vger.kernel.org # 4.14+ Reported-by: Chris Murphy Link: https://lore.kernel.org/linux-btrfs/CAJCQCtQau7DtuUUeycCkZ36qjbKuxNzsgqJ7+sJ6W0dK_NLE3w@mail.gmail.com/ Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/qgroup.c | 4 ++++ fs/btrfs/qgroup.h | 2 ++ 2 files changed, 6 insertions(+) --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -3106,6 +3106,10 @@ static int __btrfs_qgroup_release_data(s int trace_op = QGROUP_RELEASE; int ret; + if (!test_bit(BTRFS_FS_QUOTA_ENABLED, + &BTRFS_I(inode)->root->fs_info->flags)) + return 0; + /* In release case, we shouldn't have @reserved */ WARN_ON(!free && reserved); if (free && reserved) --- a/fs/btrfs/qgroup.h +++ b/fs/btrfs/qgroup.h @@ -249,6 +249,8 @@ void btrfs_qgroup_free_refroot(struct bt static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info, u64 ref_root, u64 num_bytes) { + if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) + return; trace_btrfs_qgroup_free_delayed_ref(fs_info, ref_root, num_bytes); btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes, BTRFS_QGROUP_RSV_DATA);