From patchwork Wed Nov 16 14:23:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChenXiaoSong X-Patchwork-Id: 21061 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp139598wru; Wed, 16 Nov 2022 05:30:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf77QQXKcy7WRDJrNs2r3n4xp07c8D7Sn1cEg8zhHFuthqHup+tw/a0wNnGDsaP0VbDFx+jN X-Received: by 2002:a17:906:95da:b0:7ae:bfdb:7706 with SMTP id n26-20020a17090695da00b007aebfdb7706mr18893197ejy.207.1668605436950; Wed, 16 Nov 2022 05:30:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668605436; cv=none; d=google.com; s=arc-20160816; b=L2pwX0j5lSDlW/EuPG5VJuygiC7FDaF5W6808PQ4EgtQyiIhRcgulAQ4qcuqPZ7IXH jseS/OKS1Mt3mO2PGzCWUU1ooXu1hRFqUJ6b6HVtZbhOSwqdHBapWAxqhIlMpig8DCRA EKPaVfXXT9Y9hDtgGMuHPpENMDbIR8D8fNtlEpxGtZA/g8DXpDHEB1P2ifPrgA7/PiEG fXR+4knX5L3jgX6tEO8CAmCMdfoaOSDAMUyq/SjYGnBu68/i+Zvq2oSiiDgrJp8WK4Q2 0xGd6KVk1gCVmEhqBF7YgqQvGApcjujjtDRF5vaWt3XcmhsuTIB2bhfSogHW4oE9AYQg Q1Fw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=KLNabC4w3fXYd5E1I/F0yLh6SIliM2sU2E7VFjo+xrQ=; b=s5LuTn0hUdhDBSjZLQLTXta3/G3JJ/4FvWinzeCaSfQP550Hl5tee0FPlFbzlySuYy UNf3wC9DoOn1c91Pc3eN7s3pl91r3+OvlOdVHccuSJ5BuV1T90DeXcGq+uKb3iqQX6LZ 4pTJAQFTBJWyZhJ63CxIaWi7bN0qYu9pDoE9A2B7vf8FGB3UkUE0+vWQ+/qXv0VD+wD8 k9JAzCgVIg5IJcejvG7VDx7LROjGlY9vuxI882kje6CX2E0g3954M0dw4zMKtH5Mkq4H vS4HTv5tWoV74lgUOYapfWyBw16c7wHesGsY0SSdhywsSNLnuplMx22F1l4VEqRC/XWR MmJQ== 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 cb13-20020a0564020b6d00b00460ff7dc801si12761847edb.445.2022.11.16.05.30.13; Wed, 16 Nov 2022 05:30:36 -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 S236982AbiKPNTm (ORCPT + 99 others); Wed, 16 Nov 2022 08:19:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232801AbiKPNTg (ORCPT ); Wed, 16 Nov 2022 08:19:36 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AC172126B; Wed, 16 Nov 2022 05:19:35 -0800 (PST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NC3Xv1Dpfz15MjQ; Wed, 16 Nov 2022 21:19:11 +0800 (CST) Received: from kwepemm600015.china.huawei.com (7.193.23.52) by dggemv711-chm.china.huawei.com (10.1.198.66) 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 21:19:32 +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 21:19:31 +0800 From: ChenXiaoSong To: , , CC: , , , , , , Subject: [PATCH v6 1/2] btrfs: add might_sleep() to some places in update_qgroup_limit_item() Date: Wed, 16 Nov 2022 22:23:53 +0800 Message-ID: <20221116142354.1228954-2-chenxiaosong2@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221116142354.1228954-1-chenxiaosong2@huawei.com> References: <20221116142354.1228954-1-chenxiaosong2@huawei.com> 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?1749659615119458092?= X-GMAIL-MSGID: =?utf-8?q?1749659615119458092?= 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 As the potential sleeping under spin lock is hard to spot, we should add might_sleep() to btrfs_alloc_path() and btrfs_search_slot(). Signed-off-by: ChenXiaoSong --- fs/btrfs/ctree.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index a9543f01184c..1cd0d00ef328 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -78,6 +78,8 @@ size_t __attribute_const__ btrfs_get_num_csums(void) struct btrfs_path *btrfs_alloc_path(void) { + might_sleep(); + return kmem_cache_zalloc(btrfs_path_cachep, GFP_NOFS); } @@ -1934,6 +1936,8 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, int min_write_lock_level; int prev_cmp; + might_sleep(); + lowest_level = p->lowest_level; WARN_ON(lowest_level && ins_len > 0); WARN_ON(p->nodes[0] != NULL);