Message ID | 20230918-rst-updates-v1-1-17686dc06859@wdc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2760613vqi; Mon, 18 Sep 2023 08:53:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfRhQKPbTvQqxho9S4ys21yNYDAgyWq2g/nwP4kPun2tsrkgLvN5NehXXWDluNbOG+Fvs2 X-Received: by 2002:a05:6a00:b4a:b0:68f:f0bb:7de1 with SMTP id p10-20020a056a000b4a00b0068ff0bb7de1mr8558598pfo.11.1695052413576; Mon, 18 Sep 2023 08:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695052413; cv=none; d=google.com; s=arc-20160816; b=cTjTpCwUec5GLmBzqdJeVlYEYMLZ9ZVeI+rr9vO9AwlJvwNPWuO9BlLcifN0glaDxC Cp6hZsAlZ3XvQaqQyyeA/ru7QHgI+blwE/uj1p2FA2s28O1FiagUH4pXCvKu9Wc1/2q3 YKfoLgF69T31kgrnzQrU0HJZZpHUWp+u1aOns70a3j35lePoD50wrV8K18F1uCeuYadP kagU2S5W8sgJkVEVGZiMYAtvgpGhVViplaBuo98YyagMcsVrzCikXf5NtsbO4BXv/i7j 9dL9kTG2NUGQrmcQy2vV5zoPFOEv/qBxTRsxrl96OhFl4V5/gjEhwv80Xkf8DeaBAw+P HH5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :wdcironportexception:ironport-sdr:ironport-sdr:dkim-signature; bh=mDvesXG1eLDencH9a7UnLzJsfG+QdHX+nSGDmB7OQmk=; fh=J9Pn6g7IEAJF/tG+9dB20Bqd3t5UpF3izTf4NFk9Dtk=; b=eYH5lclxzvwG5gA1QWSBtrZcv5HL1egVTp/IV+oJqcNP/X4AaN/JXOcCJuCunDrlsa cce25xQuapS06bM8fyinKhjmwqwGoaMpz7Gb5ykn96ssIpGTPG9AFw3/+E4iOV+0VxqQ rXw/FZO9BdnB3+Etzum30wlrxAEXc2nGBcoBYEHG8IYSC1MEARrTT9H96DaX0bx4j3sp CTYHzCZkR/8YOHBGmTnBdjjMk3P8c5UeWnSVQfVkwIUb9vRrvb7UOSL8QbC5Ni3i/i1G lsc/gz3iB0bAwAJlhVm0ZgpvN/1dhqULXF/PT7MHFCGinjILWZx27+3vRkxbIVX8lWj/ kRjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=JtIho2RR; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id ef6-20020a056a002c8600b0069029c49b66si8155919pfb.60.2023.09.18.08.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 08:53:33 -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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=JtIho2RR; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id B6AA28050022; Mon, 18 Sep 2023 08:43:28 -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 S229631AbjIRPnG (ORCPT <rfc822;kernel.ruili@gmail.com> + 25 others); Mon, 18 Sep 2023 11:43:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbjIRPnE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 18 Sep 2023 11:43:04 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 673D510A; Mon, 18 Sep 2023 08:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1695051696; x=1726587696; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=U9qbeiDSJYQbLhJrQS7p5rADrDE7muaLT4aPGuFW2ps=; b=JtIho2RRfnFTsGpz1t8rHXoNXpOqd/8heWiRzww9WkGigtNT2yNhHlIw FjXnYB+A7NlPR50AQv2cRso7dubE5qa/A3sZsk5TUJSr3mO49z82w7A/7 DptpNT67rI1mOuG7HbN1twsplDzBV/DDNrOy3cGiUCIqeGxp9R1fdWOt4 V75iujvXdPtKjyeX8c4pnTFhVNFQOtXhnqe/rFo2z3iNW4Eay2pGGdlux VLrjMtrPfHn6/2ZFBiPLyLnQqUNPrdkljiEeZCiydAeh07qAWW3x+xLYq yxWWkCLl2HAWzd+rnjQO9HLVHgRYXVLOWSF+vTbK4Xg1VfdLACOWRcSMx w==; X-CSE-ConnectionGUID: HIKYJ9nFR1aDXHcwxUjuXg== X-CSE-MsgGUID: 5BPDJXQPR7izjc/wzRXV6A== X-IronPort-AV: E=Sophos;i="6.02,156,1688400000"; d="scan'208";a="242446870" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 18 Sep 2023 22:14:38 +0800 IronPort-SDR: eW/FyVE0qniifqTZNYNMQa9ZTwKmi6ouo1gsHuAsYRY+2kq+uixvYHDx+JIkd5vsvJu89AChvc EuQKhmvYtH/e9Qiqqi8x1bBu+QgdMANDKQgkH5vuB0Nq/N9UZHmuIsh4lLfDqep6rnnjZW9+yY /+2nJeTWQMNkMvjGXyJF6cZCMwHirZnDBtqZWuoMi7ZpAYiWFg7umc+669PmoAd1I2RSaUf8H5 VW5TRyLlh+7AWHdmHfaRiDyLuwM1m8LC1x+D/GNm89/Q44fQ+3fgmjIf21U1ZJQeZqNLMWHHNA Rng= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Sep 2023 06:21:35 -0700 IronPort-SDR: caD0NdUxqZHEWJI1EhPtt8NPYt9h7MBvKWfW6BhS621lYssSFF96kBAYbPslYMXkKXW2N/E1PT AUUd79mfF1fYFeDXtQ6ocmIk1y5a2Z2mTMFGtWJXwvW/rzGdg7tP09ZkZQ4gpHVq2q7385MNel FORX9RNYPLFPeQv+RHvNJCycQ14vabNkDZCmdaeFh95HeyWqSavf1A9ThNmImabk9bpzawxlhx BVZsvDdV5C+NM0Tb5zpvt+05wNGp3o2zCuV6lqcMCQ91z9qmkXjD1RNH3GOymbpv5M3ZxArXnV Iv0= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 18 Sep 2023 07:14:37 -0700 From: Johannes Thumshirn <johannes.thumshirn@wdc.com> Date: Mon, 18 Sep 2023 07:14:30 -0700 Subject: [PATCH 1/4] btrfs: fix 64bit division in btrfs_insert_striped_mirrored_raid_extents MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230918-rst-updates-v1-1-17686dc06859@wdc.com> References: <20230918-rst-updates-v1-0-17686dc06859@wdc.com> In-Reply-To: <20230918-rst-updates-v1-0-17686dc06859@wdc.com> To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>, David Sterba <dsterba@suse.com> Cc: Qu Wenru <wqu@suse.com>, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven <geert@linux-m68k.org>, Johannes Thumshirn <johannes.thumshirn@wdc.com> X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1695046476; l=1280; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=U9qbeiDSJYQbLhJrQS7p5rADrDE7muaLT4aPGuFW2ps=; b=Ozf+ipDi8Mm7lWMbgnIb2J2c0Xah43hULZG86xBGVs9N4P1rloFXxWIWyhD3PxUWO5iq7boMl ZY4qteZM3HjCMd92H3qvA3wJDcSoSKQGvpEjKtOi7+d/G3Rh4NpBxC+ X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, 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: <linux-kernel.vger.kernel.org> 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]); Mon, 18 Sep 2023 08:43:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777389598295786098 X-GMAIL-MSGID: 1777391279971927159 |
Series |
btrfs: RAID stripe tree updates
|
|
Commit Message
Johannes Thumshirn
Sept. 18, 2023, 2:14 p.m. UTC
Fix modpost error due to 64bit division on 32bit systems in
btrfs_insert_striped_mirrored_raid_extents.
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
fs/btrfs/raid-stripe-tree.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
Comments
On 18.09.23 16:19, Geert Uytterhoeven wrote: > Hi Johannes, > > On Mon, Sep 18, 2023 at 4:14 PM Johannes Thumshirn > <johannes.thumshirn@wdc.com> wrote: >> Fix modpost error due to 64bit division on 32bit systems in >> btrfs_insert_striped_mirrored_raid_extents. >> >> Cc: Geert Uytterhoeven <geert@linux-m68k.org> >> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> > > 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?
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 > > <johannes.thumshirn@wdc.com> wrote: > >> Fix modpost error due to 64bit division on 32bit systems in > >> btrfs_insert_striped_mirrored_raid_extents. > >> > >> Cc: Geert Uytterhoeven <geert@linux-m68k.org> > >> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> > > > > 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.
Hi David, On Mon, Sep 18, 2023 at 6:31 PM David Sterba <dsterba@suse.cz> 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 > > > <johannes.thumshirn@wdc.com> wrote: > > >> Fix modpost error due to 64bit division on 32bit systems in > > >> btrfs_insert_striped_mirrored_raid_extents. > > >> > > >> Cc: Geert Uytterhoeven <geert@linux-m68k.org> > > >> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> > > > > > > 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. rw_devices and various other *_devices are u64. Is there a good reason they are that big? With the fs fuzzing threads in mind, is any validation done on their values? Gr{oetje,eeting}s, Geert
On Mon, Sep 18, 2023 at 08:31:19PM +0200, Geert Uytterhoeven wrote: > Hi David, > > On Mon, Sep 18, 2023 at 6:31 PM David Sterba <dsterba@suse.cz> 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 > > > > <johannes.thumshirn@wdc.com> wrote: > > > >> Fix modpost error due to 64bit division on 32bit systems in > > > >> btrfs_insert_striped_mirrored_raid_extents. > > > >> > > > >> Cc: Geert Uytterhoeven <geert@linux-m68k.org> > > > >> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> > > > > > > > > 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. > > rw_devices and various other *_devices are u64. > Is there a good reason they are that big? Many members' types of the on-disk structures are generous and u64 was the default choice, in many cases practically meaning "you don't have to care about it for the whole fileystem lifetime" or when u32 would be close to some potentially reachable value (like 4GiB chunks). You could find examples where u64 is too much but it's not a big deal for data stored once and over time I don't remember that we'd have to regret that some struct member is not big enough. > With the fs fuzzing threads in mind, is any validation done on their values? I think the superblock is the most fuzzed structure of btrfs and we do a lot of direct validation, https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git/tree/fs/btrfs/disk-io.c#n2299 regarding the number of devices there's a warning when the value is larger than "1<<31" https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git/tree/fs/btrfs/disk-io.c#n2433 The rw_devices are counting how many devices are actually found (i.e. represented by a block device) and compared against the value stored in the super block. The u64 is also convenient for calculations where a e.g. a type counting zones was u32 because it's a sane type but then we need to convert it to bytes the shift overflows, we had such bugs. Fortunatelly the sector_t is u64 for a long time but it was also source of subtle errors when converting to bytes.
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 >>> <johannes.thumshirn@wdc.com> wrote: >>>> Fix modpost error due to 64bit division on 32bit systems in >>>> btrfs_insert_striped_mirrored_raid_extents. >>>> >>>> Cc: Geert Uytterhoeven <geert@linux-m68k.org> >>>> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> >>> >>> 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. 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. Thanks, Qu
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 > >>> <johannes.thumshirn@wdc.com> wrote: > >>>> Fix modpost error due to 64bit division on 32bit systems in > >>>> btrfs_insert_striped_mirrored_raid_extents. > >>>> > >>>> Cc: Geert Uytterhoeven <geert@linux-m68k.org> > >>>> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> > >>> > >>> 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.
On 2023/9/19 23:28, David Sterba wrote: > 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 >>>>> <johannes.thumshirn@wdc.com> wrote: >>>>>> Fix modpost error due to 64bit division on 32bit systems in >>>>>> btrfs_insert_striped_mirrored_raid_extents. >>>>>> >>>>>> Cc: Geert Uytterhoeven <geert@linux-m68k.org> >>>>>> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> >>>>> >>>>> 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. We can make it a proper reject. > >> 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. OK, we can make it unsigned int (mostly u32) for fs_info::*_devices, but still do extra limits on things like device add to limit it to U16_MAX. Would this be a better solution? At least it would still half the width while keep it native to most (if not all) archs. Thanks, Qu
On Wed, Sep 20, 2023 at 07:20:49AM +0930, Qu Wenruo wrote: > >>>>> 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. > > We can make it a proper reject. > > > > >> 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. > > OK, we can make it unsigned int (mostly u32) for fs_info::*_devices, but > still do extra limits on things like device add to limit it to U16_MAX. > > Would this be a better solution? > At least it would still half the width while keep it native to most (if > not all) archs. I don't see much point changing it from u64, it copies the on-disk type, we validate the value on input, then use it as an int type. There are not even theoretical problems stemming from the type width. With the validations in place we don't need to add any artificial limits to the number of devices, like we don't add such limitations elsewhere if not necessary.
diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 85e8e389990f..0c0e620ed8b9 100644 --- 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); int left = nstripes; int i; int ret = 0;