From patchwork Wed Nov 16 13:07:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChenXiaoSong X-Patchwork-Id: 21006 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp104185wru; Wed, 16 Nov 2022 04:11:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf4KJo8iiJui8u/j6XlnM6WBuBb66nafz2hiMp56EUzSmjV4mko0qBXT++2/of/oEiPs5iNc X-Received: by 2002:aa7:ccd5:0:b0:458:211d:cbe4 with SMTP id y21-20020aa7ccd5000000b00458211dcbe4mr19195953edt.11.1668600712432; Wed, 16 Nov 2022 04:11:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668600712; cv=none; d=google.com; s=arc-20160816; b=IdevfzpQl6GBPnJ4eAFtOEmLj0ASct2ixhXTXWGif8c93WVYxx1lzvsmZyIve4D7Iq COcKG4kgpm4yVRBp+A3DGkK6H5HMOV2oMG0X6xRkd/xOxDlNqoqJHwVgjyE1LOIhk+gG J2SpDK1KWlTRtQldXzi9Ziw8Y3TK3BR2n+EA4QzFRKaIGd8uBs8EPGo4Z8gITFvFZxMM Oata8zVLC3UtxLqq/NvNYfE1wE83gxD9/2o+MI/GADnXq469vL669iDiuX960G23bj7Z OUxfMo5NW1DDhPpqVFQwTrB5YwYWadE1jQ6S+TMPLAsev1RQ8nxwhh/Wv0gQNhGxuic5 aUnQ== 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=gDMFa+r5Sga12zgiOcSh/NDoeCEUkIAOuL9mUaOuyW8=; b=iRoeFJ/U8rTQ+cs6DeXrBD2X80eyuD7xI0o5JEfoeoZgjvS/hOZh861iGRsxG4+44X 9SNU81XU4m1IwLSbOdirlXgtZc/ZsteoxuNvu026fKYUFc/HYp78QDJpwdHjX5VTkpZ0 XFSxGCpCW4lJ4S0ogtliClGBM252/hFrpmwKBlcaA7Y29OOH8UzqU2rmt8CR3+0vJ2ec cCwLMjiFvEvlUvyelqLQ35PBxm+ZXwciPC5FPOb/sV9pWFvPrdYuK07rh8RPDIT5M8Cz V13Nhiw04V+wFxqo5eF8DVvaG4YGjgGj0Fu4/CKxMcpt4Gskog1gLuNdzAr+Uhe1mvfb gitA== 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 c11-20020a05640227cb00b0046151310d6dsi8028750ede.498.2022.11.16.04.11.28; Wed, 16 Nov 2022 04:11:52 -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 S232298AbiKPMKA (ORCPT + 99 others); Wed, 16 Nov 2022 07:10:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238495AbiKPMJB (ORCPT ); Wed, 16 Nov 2022 07:09:01 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D18A930F70; Wed, 16 Nov 2022 04:02:44 -0800 (PST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NC1n20nNKzJnnc; Wed, 16 Nov 2022 19:59:34 +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 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 1/2] btrfs: add might_sleep() to btrfs_search_slot() Date: Wed, 16 Nov 2022 21:07:15 +0800 Message-ID: <20221116130716.991901-2-chenxiaosong2@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221116130716.991901-1-chenxiaosong2@huawei.com> References: <20221116130716.991901-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?1749654660712287099?= X-GMAIL-MSGID: =?utf-8?q?1749654660712287099?= At least 2 places might sleep in btrfs_search_slot(), as shown below: 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_search_slot(). Signed-off-by: ChenXiaoSong --- fs/btrfs/ctree.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index a9543f01184c..809053e9cfde 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1934,6 +1934,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);