Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp524684rwb; Wed, 16 Nov 2022 04:20:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf5NlXgwb0slPospgvujtkxEp0ybL95nE/BsbHjp2ibFgNVliBLPGHY6/jVBJlCkow/qE9Mb X-Received: by 2002:a63:ef12:0:b0:458:f364:b00e with SMTP id u18-20020a63ef12000000b00458f364b00emr20552615pgh.577.1668601206946; Wed, 16 Nov 2022 04:20:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668601206; cv=none; d=google.com; s=arc-20160816; b=qqv75oJnkNv79FyykwF13bZFt4SuqXfF5cg+VX2kZ2q9IkKVkb+hLFKmYaV5gfv2MA tqRodZm8RMA66D7KCfGlkFl9o+UgPLsLli/EVSDCNVc7UbYoJNXNZ5PqkDKqQkBrirSP yYSF3P6NoJhKNDDSDuTtpV/54yaAYHqlmEZre41GNwWiqqCO+tgctnFtWKj5JZDeecbK f+L7ShyoGBPL/7rtMtHBZxUi+4EIB3SQrAGyJbCikdI0qTflV1orEb+d7m7XJpv5ZQ56 GXpiQljZapxCF7ejX5FwgbWtb30aXSnXmfaMf9ZU6zIF0Giv2POidjTg33fGSNiAZ23Q CdFA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020a654d0c000000b00463fc72dae9si15584868pgt.144.2022.11.16.04.19.46; Wed, 16 Nov 2022 04:20:06 -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 + 91 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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(-) -- 2.31.1