Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp869668rdb; Tue, 19 Sep 2023 12:36:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZs5HQeQs/EvdYN3NOnlGDpEhjh6B2iSQZ+HnR2eELvEryBnNJvqXzkMpIfj/0hLztvN+z X-Received: by 2002:a05:6a21:47ca:b0:147:d861:50e4 with SMTP id as10-20020a056a2147ca00b00147d86150e4mr412592pzc.33.1695152172048; Tue, 19 Sep 2023 12:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695152172; cv=none; d=google.com; s=arc-20160816; b=Oi/kyzgZs4xxg5jw2VG7JwoNRpV0vELN1a4MSEPM0ZlLCB0gjBAFBovlItRUjU/Opj fFS1tFPsXrEMhT+y5ZvB8JJ5BATkL5U43h7dVfGyINY2OQkRqkfnmcdZ1Eqi0nhb1bgk 7Bqi3w6w+1hj+Nxiv2bPR25b6KoEJbaQhNeW2RcQMaU/IUQqHIY2wae+D5OrIUhzH3Kl JBhlQv6LH/2vldQQN1FiFs6vDue+7kf9CEJ8gsgJ1vP1WgpL8GpOE8kWxd/sTIJ18h/1 RaDaVOWdcxoC1bOWr91qfxpZH3MhZWI/QrUk0a4TZhg1fuNwEnoOp7VYe5KqlD6lKKck NlSg== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature:dkim-signature; bh=5/Q5PWifz4L+U7lvQD7OTExB3tkW0piz1J3T5yg4+RA=; fh=n0VfwU14tfXTWFHpWQ7LQEOn1uDhMXSRNYv3HpqCLJ4=; b=dnJozs8iPAtpj3Eg6q/kGeptiejBMNcvvao8h81DMqsh++f2/tfCr/66tQR/pK8mEU I7nWPO0qK42LL3ra4lO5x9PHjJ+DZ9eFNdiH6QXE1GCyFoGVBts58l9hn0h6Vse+QI43 gl8aMeExPXjXbsitqoWyT08pDjLeqExclxy3N0zJj0C83JSpyl7LARgY7v+5sO2VNLDt EcUfFNfKPUIzgI6UFDTlm7nUYMWj4G29f+UXxtERV597RT+nZXrcNDWod41HvLRXHMOd oEVV+oPr0M2CHH3YrplVnFtaYF6uyylKeQbn5cwZ/3LA6W5/80Nzslvvy8/nx60H6bfJ 1Icw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=QzFjOF5b; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=7dIODHM8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id f20-20020a63f114000000b00578bb707e70si1291090pgi.799.2023.09.19.12.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 12:36:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=QzFjOF5b; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=7dIODHM8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id D4BB280D7F6E; Tue, 19 Sep 2023 07:05:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232569AbjISOE6 (ORCPT + 99 others); Tue, 19 Sep 2023 10:04:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232716AbjISOEy (ORCPT ); Tue, 19 Sep 2023 10:04:54 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6442F83; Tue, 19 Sep 2023 07:04:48 -0700 (PDT) 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 078F31FF1F; Tue, 19 Sep 2023 14:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1695132287; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5/Q5PWifz4L+U7lvQD7OTExB3tkW0piz1J3T5yg4+RA=; b=QzFjOF5bfCS9bvkLIuGN+jfUzvcoEc7qo+d4w+iz7BG0pKLlOtrqk5ZE2Be95idVDpXwou tIxm+AAGU7tODbc1QlBnaFBzCxFVc6DyLCtkFKZqn3SKKiT2Fs2xaBh6w988XUoHSiNR4k VKLcFmmTtTY0sHmwdZR+yNZRRgmig9g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1695132287; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5/Q5PWifz4L+U7lvQD7OTExB3tkW0piz1J3T5yg4+RA=; b=7dIODHM8tb0hLyKYkxtTcfp3yTg6/G2EwZtbL9LQviXX2QouzF83AgC68zuuq3pVoXU1w8 DnmMdX4ub9PBhgBw== 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 BCEB0134F3; Tue, 19 Sep 2023 14:04:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id PipJLX6qCWW8SQAAMHmgww (envelope-from ); Tue, 19 Sep 2023 14:04:46 +0000 Date: Tue, 19 Sep 2023 15:58:10 +0200 From: David Sterba To: Qu Wenruo Cc: dsterba@suse.cz, Johannes Thumshirn , Geert Uytterhoeven , Chris Mason , Josef Bacik , David Sterba , Qu Wenru , "linux-btrfs@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 1/4] btrfs: fix 64bit division in btrfs_insert_striped_mirrored_raid_extents Message-ID: <20230919135810.GT2747@twin.jikos.cz> Reply-To: dsterba@suse.cz References: <20230918-rst-updates-v1-0-17686dc06859@wdc.com> <20230918-rst-updates-v1-1-17686dc06859@wdc.com> <20230918162448.GI2747@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 19 Sep 2023 07:05:20 -0700 (PDT) On Tue, Sep 19, 2023 at 10:07:00AM +0930, Qu Wenruo wrote: > On 2023/9/19 01:54, David Sterba wrote: > > On Mon, Sep 18, 2023 at 03:03:10PM +0000, Johannes Thumshirn wrote: > >> On 18.09.23 16:19, Geert Uytterhoeven wrote: > >>> Hi Johannes, > >>> > >>> On Mon, Sep 18, 2023 at 4:14 PM Johannes Thumshirn > >>> wrote: > >>>> Fix modpost error due to 64bit division on 32bit systems in > >>>> btrfs_insert_striped_mirrored_raid_extents. > >>>> > >>>> Cc: Geert Uytterhoeven > >>>> Signed-off-by: Johannes Thumshirn > >>> > >>> Thanks for your patch! > >>> > >>>> --- a/fs/btrfs/raid-stripe-tree.c > >>>> +++ b/fs/btrfs/raid-stripe-tree.c > >>>> @@ -148,10 +148,10 @@ static int btrfs_insert_striped_mirrored_raid_extents( > >>>> { > >>>> struct btrfs_io_context *bioc; > >>>> struct btrfs_io_context *rbioc; > >>>> - const int nstripes = list_count_nodes(&ordered->bioc_list); > >>>> - const int index = btrfs_bg_flags_to_raid_index(map_type); > >>>> - const int substripes = btrfs_raid_array[index].sub_stripes; > >>>> - const int max_stripes = trans->fs_info->fs_devices->rw_devices / substripes; > >>>> + const size_t nstripes = list_count_nodes(&ordered->bioc_list); > >>>> + const enum btrfs_raid_types index = btrfs_bg_flags_to_raid_index(map_type); > >>>> + const u8 substripes = btrfs_raid_array[index].sub_stripes; > >>>> + const int max_stripes = div_u64(trans->fs_info->fs_devices->rw_devices, substripes); > >>> > >>> What if the quotient does not fit in a signed 32-bit value? > >> > >> Then you've bought a lot of HDDs ;-) > >> > >> Jokes aside, yes this is theoretically correct. Dave can you fix > >> max_stripes up to be u64 when applying? > > > > I think we can keep it int, or unsigned int if needed, we can't hit such > > huge values for rw_devices. The 'theoretically' would fit for a machine > > with infinite resources, otherwise the maximum number of devices I'd > > expect is a few thousand. > > In fact, we already have an check in btrfs_validate_super(), if the > num_devices is over 1<<31, we would reject the fs. No, it's just a warning in that case. > I think we should be safe to further reduce the threshold. > > U16_MAX sounds a valid and sane value to me. > If no rejection I can send out a patch for this. > > And later change internal rw_devices/num_devices to u16. U16 does not make sense here, it's not a native int type on many architectures and generates awkward assembly code. We use it in justified cases where it's saving space in structures that are allocated thousand times. The arbitrary limit 65536 is probably sane but not much different than 1<<31, practically not hit and was useful to note fuzzed superblocks.