Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7189879rwb; Tue, 15 Nov 2022 08:46:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf417Rhx2XFwdlaLrwP6WMsT9zL6qPBKbNOBd3O0V9IB72131PfRprWUsN/VeNhLnuLQOPAr X-Received: by 2002:a63:f453:0:b0:470:27c:54b8 with SMTP id p19-20020a63f453000000b00470027c54b8mr17105325pgk.578.1668530795216; Tue, 15 Nov 2022 08:46:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668530795; cv=none; d=google.com; s=arc-20160816; b=jLrl4lGh+zEIJmWne8KGe4x/M5yWw017PqDD0aQ04fMT/YYuccY48YtXpjGQNBbgr9 5ssYewxRB4SEvgRLhScI0jbZyTjNMVhJE7cd30I+Olv49qGx5K+tLIikGQOoLUw6tfTH ZyWWDcS7Nhyy7zhv8+j7tFw9oFomCPpKd6sO8w7XthyPqvrpuxKVC6nnzXMYdzLwYTKE Iaz7OzVUC5R3ugeHQ3iSw5vFD2zBrnTcmCDWAPT2D8XrvvXapmP/8KO5ySeJWxml2yda EoydFkqhFAuwzpfF4Sx/B2EfP+zJhUQKbPTCuvFRynYzQV3xYKtzdykjMCIUxrbZOUl9 nuDg== 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=VuIT+GW0jN1A9WLEs5+0nc+Rgvtb7fjMIpF+pPH5JVg=; b=MLRPwrxcAxqYQlB75ulZ5tkr1SFGjvef8ZT+m6XBxjxttTjOEHfC7tVKguluLPbnFz me/3xPwWVPZM9XmEK9Bi6lee5c1J6sM84Pzz7tm4wQM4t6yfr7l3UFXI+4OEcMuUGt6l DDjgiZnbeijLYoR9OTalAZRWFoOJTPd2kbfRR5zkUAv89I38AkdatBv7yIhFpRpdSpS0 s50hDrDKFD8jgIepHKlyWAQStYiDhi8Puu/tXpc7+letNDYlITQYq/0Iq8JExKl3GbAt uuoqn3+2lKmj+OTjQdiCL7r7+feao8C/pj98o5sQ9KQ9F7rDHlCOJ4m5WSm2P5IirFtF WCdQ== 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 t5-20020a056a00138500b0052f60f7e0a1si13226613pfg.5.2022.11.15.08.46.15; Tue, 15 Nov 2022 08:46:35 -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 S231725AbiKOQMf (ORCPT + 91 others); Tue, 15 Nov 2022 11:12:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbiKOQMe (ORCPT ); Tue, 15 Nov 2022 11:12:34 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F72E1D65A; Tue, 15 Nov 2022 08:12:33 -0800 (PST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NBWQn1FW7zHvsk; Wed, 16 Nov 2022 00:12:01 +0800 (CST) Received: from kwepemm600015.china.huawei.com (7.193.23.52) by dggemv703-chm.china.huawei.com (10.3.19.46) 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 00:12:31 +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 00:12:30 +0800 From: ChenXiaoSong To: , , CC: , , , , , , Subject: [PATCH v4 0/3] btrfs: fix sleep from invalid context bug in update_qgroup_limit_item() Date: Wed, 16 Nov 2022 01:17:06 +0800 Message-ID: <20221115171709.3774614-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: dggems702-chm.china.huawei.com (10.3.19.179) 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 delaying the limit item updates until unlock the spin lock. By the way, add might_sleep() to some places. ChenXiaoSong (3): btrfs: add might_sleep() to some places in update_qgroup_limit_item() btrfs: qgroup: introduce btrfs_update_quoto_limit() helper btrfs: qgroup: fix sleep from invalid context bug in update_qgroup_limit_item() fs/btrfs/ctree.c | 2 ++ fs/btrfs/qgroup.c | 45 ++++++++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 19 deletions(-) -- 2.31.1