Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3427394imu; Sun, 11 Nov 2018 14:51:52 -0800 (PST) X-Google-Smtp-Source: AJdET5fEvW+hlbw3eE7WzYv+V+0zPtciK+0n9toyjnoYhBuBxKJPhE/2vZvb6IYF0pN0ymiZcXJC X-Received: by 2002:a17:902:887:: with SMTP id 7-v6mr9785941pll.283.1541976712707; Sun, 11 Nov 2018 14:51:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541976712; cv=none; d=google.com; s=arc-20160816; b=LMbGlxfuWsLRXKDkNrRb1ceWG55at5WuPHGj/wNqwQ95824pnCw0sVqzvT4QRvu4pS bzfi5faQLaM7QefdLDOfEnUvYqKmWUVHcw90e71CPhIZI+Ewm1fQtFUPTT8M7mqomeHd clDuQv0vS9p/ZvbMoZ+arak81oHOAe8IW/YoKKUvTB4RtgcwDclDO6ArIpp4tPNHV/9z /bx8dyI9soHYwFcvoMtf1KjvJPvMTgkD8d1cmx2aZG+RCAcva4qfVhjHDkOZcRLwHIE5 woghBUG+OlmYpkvhgqdDE/4C+iK9w/Js62s9HyqtdPPhu3isuhimZsv7NbQCkNTu5J+l qu2g== 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=gVHUcgf58C3gBydtxCyz5xPc93NVNJmu9P3fo0pTC84=; b=Hpqq2+tMsOp24kBDaACCu2vjnagG2RtLhavKygNXyfwbLMgBDe2NZLbVyhxvGOO0xu vVkBQm828dPeJj4L6DE/Wxv/r9vuGAv2LHQyevadNhf9LrHD/motENQP+7ix6zjNNsEU l4SbQw5G7gaPug3PdZVvmr3mfzMWu2mBmOnpUjLLVKeDbhd2tp2GUCZ9T5+xsA//UAMh hiOMi3OhiXPCbOvTfTlDkP5EsQzZIahrJMGsjSnSvd0rZZatNSF4zt/y3FJYNhJuhwi+ 0WAXCzrMlcAo/X35eLlBIS3iLWBQjm+Se+iv7TgFxsXFmA0hXehNvTWIU6bANJyFfPT1 hl/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YoVAyyb0; 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 w17si8390263pgl.6.2018.11.11.14.51.37; Sun, 11 Nov 2018 14:51: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=YoVAyyb0; 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 S2404179AbeKLIXH (ORCPT + 99 others); Mon, 12 Nov 2018 03:23:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:55530 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404153AbeKLIXF (ORCPT ); Mon, 12 Nov 2018 03:23:05 -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 8191E208A3; Sun, 11 Nov 2018 22:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975588; bh=F4rcGtzEOS5rsMXwrFUqao8PrR5cHR3Fc8u7/15AQRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YoVAyyb0UhlYp8vovEAWXs3ROo7tDWrqZxnw8vrZv4nN0t5D92kvOGP7tdy3VX8aq eRGkTLlurfC/A8S7dj5hingTYa6YJ53Dl4zhWesWqQlguBAhHuJSg/cCsMwYqsSFj5 0cNn217jYjIPdpOC3KYM3ZGjTSye1Jw20bhRagBs= 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.14 196/222] btrfs: qgroup: Avoid calling qgroup functions if qgroup is not enabled Date: Sun, 11 Nov 2018 14:24:53 -0800 Message-Id: <20181111221704.332583813@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -2972,6 +2972,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 @@ -232,6 +232,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); }