Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp613160rwb; Wed, 16 Nov 2022 05:31:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf5pz22s9JrQmE6rWcC+4j/6B4lDr5pBn7WYlbcZWjT5n4Q0dVeDS4g5g0xb7XDXd9cpMfXB X-Received: by 2002:a17:90b:916:b0:20d:d531:97cc with SMTP id bo22-20020a17090b091600b0020dd53197ccmr3809672pjb.164.1668605513078; Wed, 16 Nov 2022 05:31:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668605513; cv=none; d=google.com; s=arc-20160816; b=YvsXUBfjhDp7qW4lsUkkYAz7N65gf1E8ezQZh2S7zddZjOiiy1kUBJm1WMh5rWvw/c XdkhqVmEJaqBviKVJxtkx2GOBW4PGmTZs/Bt9IcZiVmzHoK1CB8kRMrl+Cfgnf9Ig4Nn D934iuTBjnjgMe9qHqR/gt42E3onJPX9I52/4p+HUHgPX47eoo8TzSyxDp/6hQQgffRr lDy8ZSjrUGr5Xgw4wE74pvA5QrHjMRhYmpuLKDxby3GmUUw7h/3TXiOB2p7xH/thom2E 7rVX1J6aE7sffkcZSXTD1OEdBCRC9+gOVwd2pXSZroNG3uiYXxuqTgT2zC5rIzrX8MpI ym1Q== 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 Return-Path: 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.31.38; Wed, 16 Nov 2022 05:31:53 -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 + 91 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 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 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 --- 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) { -- 2.31.1