Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05FF0C433EF for ; Wed, 9 Mar 2022 14:51:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233648AbiCIOwe (ORCPT ); Wed, 9 Mar 2022 09:52:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230457AbiCIOwd (ORCPT ); Wed, 9 Mar 2022 09:52:33 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14E9F17E351 for ; Wed, 9 Mar 2022 06:51:35 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id BA5941F380; Wed, 9 Mar 2022 14:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1646837493; 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=vssTC5zSl78dvgjlAEn3UNJsdkSoqrMAMrRZbxj686c=; b=u70XvGBPfT4v6CaVtDBBPOa7kA+xrbiKBfwGymtC26xqJmblPDseSXIjnLFF9jiUC9u7eL aoyeSwYRejQx4XwhoTLdiUgHaKPssbV97k739rPExFeDklASLono6pcnWx6fUkKgK/OlRl /FkKqfpORl6zD3awqUMdCIp9qbVykoc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1646837493; 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=vssTC5zSl78dvgjlAEn3UNJsdkSoqrMAMrRZbxj686c=; b=gcHWaEzRgVDk6Zwc+bjkOqpRXSvUD4ZQ007kqPhrHVgEYfFJNAzwwnKsnMTEz2TODNFdB8 bMC8hXQHeSsAw9Bw== Received: from ds.suse.cz (ds.suse.cz [10.100.12.205]) by relay2.suse.de (Postfix) with ESMTP id 6F444A3B81; Wed, 9 Mar 2022 14:51:33 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id D9FE4DA7DE; Wed, 9 Mar 2022 15:47:37 +0100 (CET) Date: Wed, 9 Mar 2022 15:47:37 +0100 From: David Sterba To: Johannes Thumshirn Cc: Anand Jain , David Sterba , "linux-btrfs@vger.kernel.org" , Naohiro Aota Subject: Re: [PATCH v2 1/2] btrfs: zoned: use rcu list in btrfs_can_activate_zone Message-ID: <20220309144737.GW12643@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Johannes Thumshirn , Anand Jain , David Sterba , "linux-btrfs@vger.kernel.org" , Naohiro Aota References: <5990aa9e-9082-613c-4ef1-27568d36329b@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Wed, Mar 09, 2022 at 07:44:11AM +0000, Johannes Thumshirn wrote: > On 09/03/2022 08:37, Anand Jain wrote: > > On 07/03/2022 18:47, Johannes Thumshirn wrote: > >> btrfs_can_activate_zone() can be called with the device_list_mutex already > >> held, which will lead to a deadlock. > >> > >> As we're only traversing the list for reads we can switch from the > >> device_list_mutex to an rcu traversal of the list. > >> > >> Fixes: a85f05e59bc1 ("btrfs: zoned: avoid chunk allocation if active block group has enough space") > >> Cc: Naohiro Aota > >> Signed-off-by: Johannes Thumshirn > >> --- > >> fs/btrfs/zoned.c | 6 +++--- > >> 1 file changed, 3 insertions(+), 3 deletions(-) > >> > >> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c > >> index b7b5fac1c779..cf6341d45689 100644 > >> --- a/fs/btrfs/zoned.c > >> +++ b/fs/btrfs/zoned.c > >> @@ -1986,8 +1986,8 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags) > >> ASSERT((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0); > >> > >> /* Check if there is a device with active zones left */ > >> - mutex_lock(&fs_devices->device_list_mutex); > >> - list_for_each_entry(device, &fs_devices->devices, dev_list) { > >> + rcu_read_lock(); > >> + list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) { > > > > > > Sorry for the late comment. > > Why not use dev_alloc_list and, chunk_mutex here? > > > > That's a good question indeed. Let me try it :) The 5.18 is now frozen, so please send it as an incremental fix, thanks.