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); From patchwork Wed Nov 16 14:23:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChenXiaoSong X-Patchwork-Id: 21064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp139887wru; Wed, 16 Nov 2022 05:31:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf6UacF9KFhhtOBbfR8VPIQz6xcIGtfuishyanNQUe8T2AJEd+u8He6SrWwZcq/v+0+UBw3x X-Received: by 2002:a17:903:26c1:b0:186:9852:b9e4 with SMTP id jg1-20020a17090326c100b001869852b9e4mr9236043plb.52.1668605470318; Wed, 16 Nov 2022 05:31:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668605470; cv=none; d=google.com; s=arc-20160816; b=CPEsMbK49XdQzTzHl1Yxrzn+YULZRnsgc1R2y4cTKHSeJR9PuV904eE1pL2ouVfAWE fKCyHi0gTHFEFO+kasmQqNpU+p80gPHQ6hWZOOnmWZQiWNGGSNQv7jguxA2Lb/H78uzM wI7cVHK74crwWezVpRL2Wb1NVkd8Y0TdMADqquFGYslC21sqtgjrFxyqA+XqblIlPrEK 1dwbZ0+6cJAZVa9XZc3WLqLS1+WJFh2hGrVj/o9kayMFywynRNRMSVJ6L2WdBv5Go4CQ yLd2JJYF5PWGC4PEV3zqMhSntB0p+6p/9OBjY6XeIgMr49XbMiEH+7Ij4F3h31m32mJn 32NQ== 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=NG2zCvmrXdUxEt+Oqj5MJN9L1C+XD6fPgNt3J3KypZY=; b=Cu78gyCvVO0lDTXMcRxNQycuBpvpJSVNOKZ2XedF+YARgsNPgSGyBIG5AN9jjHmCnU j0++RYIF92PYZo4JtCZRlXnYdRsrbGJQbPoaDQ4Y3i2ohRPB1KV4OTIUxFSlwfAXD01n AslaJAd+kzBpjiUFXVVGlA4AYkTK5X2dgD9z1sxsWMtdq2kpTLoKK99tjbMJzymGXjRs w1rEydUnkjhmbz1gaoG7BiLkbQ/UxsAWTadAfT7CBPHNOmvkRe59R/brK/jbPbXUo23d u0NFpMr2dUuRg4Ci08GOMVqt8kNCoqsQY2l/GobokGTED/KmUMerEr0CXo2OZzai8yw/ GthA== 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 z17-20020a634c11000000b00460c07c5542si16277027pga.407.2022.11.16.05.30.54; Wed, 16 Nov 2022 05:31:10 -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 S233966AbiKPNTj (ORCPT + 99 others); Wed, 16 Nov 2022 08:19:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232762AbiKPNTg (ORCPT ); Wed, 16 Nov 2022 08:19:36 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74CB220F73; Wed, 16 Nov 2022 05:19:35 -0800 (PST) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NC3Xk660QzHvpW; Wed, 16 Nov 2022 21:19:02 +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 21:19:33 +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:32 +0800 From: ChenXiaoSong To: , , CC: , , , , , , Subject: [PATCH v6 2/2] btrfs: qgroup: fix sleep from invalid context bug in update_qgroup_limit_item() Date: Wed, 16 Nov 2022 22:23:54 +0800 Message-ID: <20221116142354.1228954-3-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?1749659649703458491?= X-GMAIL-MSGID: =?utf-8?q?1749659649703458491?= Syzkaller reported BUG as follows: BUG: sleeping function called from invalid context at include/linux/sched/mm.h:274 Call Trace: dump_stack_lvl+0xcd/0x134 __might_resched.cold+0x222/0x26b kmem_cache_alloc+0x2e7/0x3c0 update_qgroup_limit_item+0xe1/0x390 btrfs_qgroup_inherit+0x147b/0x1ee0 create_subvol+0x4eb/0x1710 btrfs_mksubvol+0xfe5/0x13f0 __btrfs_ioctl_snap_create+0x2b0/0x430 btrfs_ioctl_snap_create_v2+0x25a/0x520 btrfs_ioctl+0x2a1c/0x5ce0 __x64_sys_ioctl+0x193/0x200 do_syscall_64+0x35/0x80 Fix this by calling qgroup_dirty() on @dstqgroup, and update limit item in btrfs_run_qgroups() later. Signed-off-by: ChenXiaoSong Reviewed-by: Qu Wenruo --- fs/btrfs/qgroup.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 9334c3157c22..b74105a10f16 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2951,14 +2951,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid, dstgroup->rsv_rfer = inherit->lim.rsv_rfer; dstgroup->rsv_excl = inherit->lim.rsv_excl; - ret = update_qgroup_limit_item(trans, dstgroup); - if (ret) { - qgroup_mark_inconsistent(fs_info); - btrfs_info(fs_info, - "unable to update quota limit for %llu", - dstgroup->qgroupid); - goto unlock; - } + qgroup_dirty(fs_info, dstgroup); } if (srcid) {