Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4685597pxf; Tue, 23 Mar 2021 17:56:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKkf2Twnbj60ftYDHfeQyxaL8xTgyCz1cnj3k5D0wfw3gUSy97UPOtZaZxmTU9S5bgKhCA X-Received: by 2002:aa7:dd4d:: with SMTP id o13mr614629edw.53.1616547402453; Tue, 23 Mar 2021 17:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616547402; cv=none; d=google.com; s=arc-20160816; b=JVpiWuZnpfaib4qgHz0/26eWB8jeGBLvRMe+45nSWIeKGBvbbaIK8sExs2bMrayH+g bSAkYaMQA6rc5Rjr50p89c05+kKL63GXYwWFUPE/ChCdppXLk0TCJJv5wRg4OSVY+LVN Q7Mq3o2ZuiHY+nYitvjxlK8mkFd0FfYE0IzlejWO1nL75niBoq9Lsdbz8RN5Q+REGGqc UACsXl8c0t4Q56F8JLjXmkmWXN+e53exTbXNX+w+Ha7Rlqbw5ssQgbx0tcCQdFgKIydc DZEXH+ehWHTqAQwXbwtdW3QA94UnUOeaJE2CZDzaWv118+PG7InuMFl7CaVwj6qgGCTl bXVQ== 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-transfer-encoding :content-disposition:mime-version:references:mail-followup-to :reply-to:message-id:subject:cc:to:from:date; bh=ViScOGuJ9pWokoj62ImnNOeSHSMB/gM1uArJOworWso=; b=wPyzLSBy1okOd+gG7rJfDDs+FRfexUXf5bgvE+eKGCJa5OETh/AImKDa94t7c6uvT1 FwKuZiI0dKgPVmIzXNn8ljoZOaIeu+u9gU5/+8th8obCDYJtBDmLYhMWC0AbQIaWO64J Q53pgAJXHr6hFqG842FJepWuDEkpSgOr8ipncoZu0JtNYXODu5LQN3nZktaX3gY3ZWjH OxmJBZ7AhB/5PIivH2WNsSRZytkPE9QUg9dQ55sD8isDGSI2rJJaOTgPwM2bgHY/7+H0 Qnu+Bil7BoEfQQD6ihDPTFjU3sKA2EJs4TJJxYZLyJukfBLYtY9l7D3pe39nP3CXZ3St I0Wg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a19si476714ejt.403.2021.03.23.17.54.57; Tue, 23 Mar 2021 17:56:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231296AbhCWN0k (ORCPT + 99 others); Tue, 23 Mar 2021 09:26:40 -0400 Received: from mx2.suse.de ([195.135.220.15]:39668 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbhCWNZt (ORCPT ); Tue, 23 Mar 2021 09:25:49 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8444AACBF; Tue, 23 Mar 2021 13:25:48 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 43C7CDA7AE; Tue, 23 Mar 2021 14:23:43 +0100 (CET) Date: Tue, 23 Mar 2021 14:23:43 +0100 From: David Sterba To: Arnd Bergmann Cc: Chris Mason , Josef Bacik , David Sterba , Anand Jain , Naohiro Aota , Arnd Bergmann , Nikolay Borisov , Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] btrfs: zoned: fix uninitialized max_chunk_size Message-ID: <20210323132343.GF7604@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Arnd Bergmann , Chris Mason , Josef Bacik , David Sterba , Anand Jain , Naohiro Aota , Arnd Bergmann , Nikolay Borisov , Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210323124624.1494552-1-arnd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210323124624.1494552-1-arnd@kernel.org> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 23, 2021 at 01:46:19PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > The ctl->max_chunk_size member might be used uninitialized > when none of the three conditions for initializing it in > init_alloc_chunk_ctl_policy_zoned() are true: > > In function ‘init_alloc_chunk_ctl_policy_zoned’, > inlined from ‘init_alloc_chunk_ctl’ at fs/btrfs/volumes.c:5023:3, > inlined from ‘btrfs_alloc_chunk’ at fs/btrfs/volumes.c:5340:2: > include/linux/compiler-gcc.h:48:45: error: ‘ctl.max_chunk_size’ may be used uninitialized [-Werror=maybe-uninitialized] > 4998 | ctl->max_chunk_size = min(limit, ctl->max_chunk_size); > | ^~~ > fs/btrfs/volumes.c: In function ‘btrfs_alloc_chunk’: > fs/btrfs/volumes.c:5316:32: note: ‘ctl’ declared here > 5316 | struct alloc_chunk_ctl ctl; > | ^~~ > > Initialize it to UINT_MAX and rely on the min() expression to limit > it. > > Fixes: 1cd6121f2a38 ("btrfs: zoned: implement zoned chunk allocator") > Signed-off-by: Arnd Bergmann > --- > Note that the -Wmaybe-unintialized warning is globally disabled > by default. For some reason I got this warning anyway when building > this specific file with gcc-11. The warning catches a theoretical case but this would not happen in pracitce. There are three bits to check and that covers all valid options, but there should be a final else {} like is in init_alloc_chunk_ctl_policy_regular that does not let the function continue as that would mean there are worse problems. btrfs_alloc_chunk init_alloc_chunk_ctl init_alloc_chunk_ctl_policy_zoned and btrfs_alloc_chunk validates the ctl->flags against BTRFS_BLOCK_GROUP_TYPE_MASK, which is exactly the tree branches. > --- > fs/btrfs/volumes.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index bc3b33efddc5..b42b423b6a10 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -4980,6 +4980,7 @@ static void init_alloc_chunk_ctl_policy_zoned( > u64 type = ctl->type; > > ctl->max_stripe_size = zone_size; > + ctl->max_chunk_size = UINT_MAX; This would allow the min() work but otherwise is not an expected to happen at all. > if (type & BTRFS_BLOCK_GROUP_DATA) { > ctl->max_chunk_size = round_down(BTRFS_MAX_DATA_CHUNK_SIZE, > zone_size); > -- > 2.29.2