Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2020956rwb; Fri, 11 Nov 2022 04:03:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf44DJ56oGWMwO7eqMDg3oyPcC8g+qljCdFxqgpvw72MQvhvhtIxmvHwjfwDjXV3ZxuXWHfV X-Received: by 2002:a05:6402:d77:b0:459:aa70:d4fd with SMTP id ec55-20020a0564020d7700b00459aa70d4fdmr1160489edb.162.1668168220222; Fri, 11 Nov 2022 04:03:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668168220; cv=none; d=google.com; s=arc-20160816; b=ly28Iltt/QmfEjv7XtirfwxjmiBTkzof8Z4IZr+VgxKV110Tm2aOgOVdtsHgBVV86h ir1JpvQY/lJDvkjdOErqsFkxquN0KB58CruLAOkHm6ANP/wWTZEHl5mDFcf2/6hIj3O4 gOLLWhiSy0Bvb+wZ+bQ+dd3ZAQ4Lo63u9sY5bAtSjQOY2SObnxLMKJdCYeWEMc4yLXX8 wPR3i9eQj21Q2gNchRkgp+HZ+PgiOtaE58hG1mdmi2kk2hc8XFeO3LBLjNm8/pqgaxn1 cnx5HOkViBvaqFcgq3Ldql/bWYofiqLaTC4hBGqY5mAHAJPyzFwr3BM7GalHumsYBHIZ uQqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=n0d2cMxIe4yXkl7ENjvZzfOdmNSV5L2CP6byJwDVNJE=; b=n8/gqYPGR0PAs4x22o0BDoQeO++No62lXe4HpESIfnRGyDScuHgjBiI0Qg+c1eDxtK /q+6q3wzwYLGKOXfpxwVCA/WM+guSIVZ8WSW89gXQTTtAoJQCI2ADIX/1BVVIFyYHffW JxAbRq/zAk+1GWEbFGFBHg6uvZdqM2a3/cfvs4qZDjVFbkM0dWhdXM0/5IHHEW5w8Dhp M5pRlb0GvUXQBuNQjXDpqLMOiy0u6si1XTue+6+Bn08qUUOLKYNuZsK6eU+eoarC/bUk qTbmiB1dJX9GZ4zjYW5Vv3R9FsDfbgfw1BcRRRpsaIQr8psSxGB3Zln2zQ2VPwpgSUco c9CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=pGGz3nZk; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz19-20020a1709077d9300b007882936242fsi1968846ejc.769.2022.11.11.04.03.15; Fri, 11 Nov 2022 04:03:40 -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; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=pGGz3nZk; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232574AbiKKLpU (ORCPT + 92 others); Fri, 11 Nov 2022 06:45:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233096AbiKKLpJ (ORCPT ); Fri, 11 Nov 2022 06:45:09 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A597613F4D; Fri, 11 Nov 2022 03:45:07 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 61A67201A6; Fri, 11 Nov 2022 11:45:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1668167106; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=n0d2cMxIe4yXkl7ENjvZzfOdmNSV5L2CP6byJwDVNJE=; b=pGGz3nZk3qad5q8UyU1x1a0n1py6GXptXiGHtYtZL9WttmUltzLa68impCg4+8YIiBp/oE h3xzuvX+cJ4xLflMRgQRZwvXeJvKSyzmTEEU81j9ypBCpK8qFZ4FB2j6KGhEjVwT24+J88 kfbwNaLgkIq6KYlnDT2BNCPjUyOEXWA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1668167106; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=n0d2cMxIe4yXkl7ENjvZzfOdmNSV5L2CP6byJwDVNJE=; b=ViYv4XXbYUUfg0liiIS07iNndOSaIG+jfWgolxo1KJZcFJKJ2NtBpZUrzzaY36IEO8eKMJ 6iDMmuXzXwlbHqCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 205D713273; Fri, 11 Nov 2022 11:45:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kT7zBsI1bmMxMAAAMHmgww (envelope-from ); Fri, 11 Nov 2022 11:45:06 +0000 Date: Fri, 11 Nov 2022 12:44:42 +0100 From: David Sterba To: Qu Wenruo Cc: dsterba@suse.cz, ChenXiaoSong , clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, zhangxiaoxu5@huawei.com Subject: Re: [PATCH] btrfs: qgroup: fix sleep from invalid context bug in update_qgroup_limit_item() Message-ID: <20221111114442.GK5824@twin.jikos.cz> Reply-To: dsterba@suse.cz References: <20221110141342.2129475-1-chenxiaosong2@huawei.com> <20221110205436.GJ5824@twin.jikos.cz> <48ac1a74-6349-ccf5-92ef-2189037122b8@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48ac1a74-6349-ccf5-92ef-2189037122b8@gmx.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 On Fri, Nov 11, 2022 at 07:31:22AM +0800, Qu Wenruo wrote: > > > On 2022/11/11 04:54, David Sterba wrote: > > On Thu, Nov 10, 2022 at 10:13:42PM +0800, ChenXiaoSong wrote: > >> 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 introducing __update_qgroup_limit_item() helper, allocate > >> memory outside of the spin lock. > >> > >> Signed-off-by: ChenXiaoSong > > > > Added to misc-next, thanks. > > Please remove it for now, the patch only addressed what MM layer > reports, it doesn't really solve the root cause, we're doing a tree > modification (btrfs_search_slot()), under a spinlock. Removed. As the potential sleeping under spinlock is hard to spot we should add might_sleep to some places.