From patchwork Wed Nov 16 13:07:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChenXiaoSong X-Patchwork-Id: 1749 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp104158wru; Wed, 16 Nov 2022 04:11:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf7belsZZwsqHyAPVslvWkI8s1xK5o0jfd+zsXsdJy/maC6EQ/ikFXTzBpb1pdu9w2AK0eXk X-Received: by 2002:a05:6402:4498:b0:461:b754:ac3c with SMTP id er24-20020a056402449800b00461b754ac3cmr18509119edb.241.1668600710069; Wed, 16 Nov 2022 04:11:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668600710; cv=none; d=google.com; s=arc-20160816; b=cZL/Fi4NWQOAY7fkiJFjiq9fCbR67jFDiotD+S3bvmAJEFSOQxxHs9G0VOdvetrawM Urk3FdiZ4okFpXrfr3rxPAMC39h6/ruxUKOELKOIZvK8TgLJWX4rgyfnD3juxdsWx64G Px5tjZCGk0aHp2v+HXNBOdxLHXS/+P8qeljWyqjxUaMauM9B7KzVXzOE/rNIB/Cib25X nYD4eQp0TJAF8yE41tpAyq514PPU6Ohqv1waU92fc/UXlcvV3jqIcQWoytIFGCiBPatc 9ITFZanznCcHfw6dO0kgYcXb9BfBW24/csSECe44cjbM6CDUVgm9IeqG16xfaGPCyFH+ 8Flw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=1rZmLxca2z4aCA5IFJMKVlwIPVZhjCGSKGCIR7ujgFA=; b=innGrPWZW6uQwaEogWSa+1nMjYtbGI5QG5s4rsrW7oMgMEKl9e2dXT1gKhph0y6sfU hDfSEmhvKfcqwpH7J4aji7fKEMUdX9G587DVbNCiakkkovuhxd8ZcT8FuxMWjryz3isj SfR4GR3APe/QiFsiOENg/8XhU+NrQIOUQ3xKJUtgz0LDa32FQCzIYZCjwrjweTzzvLY9 R3UxOt/gjlaSElMQB6PLTHS1y0HSGYjQjHjDn0iS6Uw1zezcCDIKRfo54X9U7ToUQVe4 ui0GwaRKya9mlcm+Ubw4leVRK+8FLbquWYVfxD08ZRXWcgvTdfMOl/ckchu+3xvHnDyi JyrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020a1709062c4500b007ae74740fa4si11245568ejh.275.2022.11.16.04.11.26; Wed, 16 Nov 2022 04:11:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238685AbiKPMJy (ORCPT + 99 others); Wed, 16 Nov 2022 07:09:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233110AbiKPMJA (ORCPT ); Wed, 16 Nov 2022 07:09:00 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94D2730F46; Wed, 16 Nov 2022 04:02:43 -0800 (PST) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NC1rD3GWXz15Mjl; Wed, 16 Nov 2022 20:02:20 +0800 (CST) Received: from kwepemm600015.china.huawei.com (7.193.23.52) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 16 Nov 2022 20:02:42 +0800 Received: from huawei.com (10.175.101.6) by kwepemm600015.china.huawei.com (7.193.23.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 16 Nov 2022 20:02:41 +0800 From: ChenXiaoSong To: , , CC: , , , , , , Subject: [PATCH v5 0/2] btrfs: fix sleep from invalid context bug in update_qgroup_limit_item() Date: Wed, 16 Nov 2022 21:07:14 +0800 Message-ID: <20221116130716.991901-1-chenxiaosong2@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600015.china.huawei.com (7.193.23.52) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749654657902497275?= X-GMAIL-MSGID: =?utf-8?q?1749654657902497275?= At least 3 places might sleep in update_qgroup_limit_item(), as shown below: update_qgroup_limit_item btrfs_alloc_path /* allocate memory non-atomically, might sleep */ kmem_cache_zalloc(btrfs_path_cachep, GFP_NOFS) btrfs_search_slot setup_nodes_for_search reada_for_balance btrfs_readahead_node_child btrfs_readahead_tree_block btrfs_find_create_tree_block alloc_extent_buffer kmem_cache_zalloc /* allocate memory non-atomically, might sleep */ kmem_cache_alloc(GFP_NOFS|__GFP_NOFAIL|__GFP_ZERO) read_extent_buffer_pages submit_extent_page /* disk IO, might sleep */ submit_one_bio Fix this by calling qgroup_dirty() on @dstqgroup, and update limit item in btrfs_run_qgroups() later. By the way, add might_sleep() to btrfs_search_slot(). ChenXiaoSong (2): btrfs: add might_sleep() to btrfs_search_slot() btrfs: qgroup: fix sleep from invalid context bug in update_qgroup_limit_item() fs/btrfs/ctree.c | 2 ++ fs/btrfs/qgroup.c | 29 ++++++++++++----------------- 2 files changed, 14 insertions(+), 17 deletions(-)