Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1218895pxj; Sat, 12 Jun 2021 01:56:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKEa8nfx7bRHBCWafEPtp6aWiCPqk6PaEoSxs/h8/9mbjcxKRFIJqySlIJwDVfAOyWN7rh X-Received: by 2002:a17:906:488f:: with SMTP id v15mr6970881ejq.428.1623488170666; Sat, 12 Jun 2021 01:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623488170; cv=none; d=google.com; s=arc-20160816; b=pGCsmmm/yIuENJpfnbsUbqvC8hVbu3lKjIL5cptnSnhIUtzPEe1XT1hjajrdfnNGVb QPMs1tUZw9Zhdx+jtG1PaSPhts3yk1J2WeE5tpU2jmWwgBsc6ROihv0DYbp5G63XLwxH h5OyWm5+28xOlghU+5dHT/+6v1YFnWQKqEctyYU0ZlYPR/Z0ecKOjH21TWEXgjZooXA1 ToncW0VComnYx0IdViZNskbjeNQ+elHG6wLqYlukxsIgUDVG6gmNjf9LnL9lhUutCnct CYdI/rW6r3ll7EVmmq7tbtWT30wVu7cuV5hsDekbFD5xAe3lrhUicUeyj8loiFKpkRYP NxBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=GD2Olda9AmSNWAvIUnqMGuloWkjPAxn/zDHn8rCyeik=; b=WBU2vUfOe24WOBLpHgyIlHbF92QV6FzJXJL7Rn3eB2bz7EgB0GqoQqZcxaQOq+WCRO e8JWK+tBu96Nz2/JVBdFiqnKUJR2MaG/UkmFyjj6MDWj0IdQlF4zNOt2B442TNF62lo5 fe4pFtSN3qxXh0mib+FWILPOuRfaLX2lkO20Y1sbkP9/oEVY5gveSPO5kwmZEna0ncrY mwpcIYlcsBDZuCuONK5Wc52Bknxhhho7avLPLyazs6F2wS9P9fcRJJQi0mOVythYUigv fgkTNOI+BeUG7cpNjx1Ve13Uaq//9RwQL1SFTg07Ud+M7VmZSjWR2U0okIexBja3EUgN 22nQ== 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 i14si6705193ejo.611.2021.06.12.01.55.45; Sat, 12 Jun 2021 01:56:10 -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 S230115AbhFLI4t (ORCPT + 99 others); Sat, 12 Jun 2021 04:56:49 -0400 Received: from mail-vs1-f43.google.com ([209.85.217.43]:41774 "EHLO mail-vs1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbhFLI4t (ORCPT ); Sat, 12 Jun 2021 04:56:49 -0400 Received: by mail-vs1-f43.google.com with SMTP id c1so5119990vsh.8; Sat, 12 Jun 2021 01:54:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GD2Olda9AmSNWAvIUnqMGuloWkjPAxn/zDHn8rCyeik=; b=WMZIqcJpKrCtTBxTrQuhxSryloSzbak5D0o0I862v8EGdRs791HlhJKBqo6dsJhDl8 O66sEJS3CG9kxXYHskZlKX8K4sSu9+P4CeHtUu1OF0qRoAeIBA5km9bHwNX8ji52SjTp OMlaVZFmft7jz3XIROSwM0j53Lp08GL0eUfCurIeGlFK5rx3qmwG2jSQ8GrQwcpteTV9 AEYfLpc3Jka4eHdIT6qVvNYmKSLc6Sv3/lCGyoHY8bg3qFMRPiyBZ5qG46pPXgayBi6J Cjr/lvhKa57mJTOWqhxIx18StzTPN4iEkq1REZ4GJY+K8OPL3RQUSEZpsiaLse/wgqx/ EJZA== X-Gm-Message-State: AOAM532TRuMEaTDZ12b7pz2oHz6lnmZ4q35iOHQe3k056qHNqhFpqY5a 31eT2wqwB+D8a8cQBH+z4hiJqbb1hsMrYxBVVAU= X-Received: by 2002:a67:efd6:: with SMTP id s22mr13429864vsp.3.1623488074285; Sat, 12 Jun 2021 01:54:34 -0700 (PDT) MIME-Version: 1.0 References: <20210610110001.2805317-1-geert@linux-m68k.org> <20210610220155.GQ664593@dread.disaster.area> <20210611224638.GT664593@dread.disaster.area> In-Reply-To: <20210611224638.GT664593@dread.disaster.area> From: Geert Uytterhoeven Date: Sat, 12 Jun 2021 10:54:23 +0200 Message-ID: Subject: Re: [PATCH] xfs: Fix 64-bit division on 32-bit in xlog_state_switch_iclogs() To: Dave Chinner Cc: Dave Chinner , Chandan Babu R , "Darrick J . Wong" , Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org, Linux-Next , Linux Kernel Mailing List , noreply@ellerman.id.au Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dave, On Sat, Jun 12, 2021 at 12:46 AM Dave Chinner wrote: > On Fri, Jun 11, 2021 at 08:55:24AM +0200, Geert Uytterhoeven wrote: > > On Fri, Jun 11, 2021 at 12:02 AM Dave Chinner wrote: > > > On Thu, Jun 10, 2021 at 01:00:01PM +0200, Geert Uytterhoeven wrote: > > > > On 32-bit (e.g. m68k): > > > > > > > > ERROR: modpost: "__udivdi3" [fs/xfs/xfs.ko] undefined! > > > > > > > > Fix this by using a uint32_t intermediate, like before. > > > > > > > > Reported-by: noreply@ellerman.id.au > > > > Fixes: 7660a5b48fbef958 ("xfs: log stripe roundoff is a property of the log") > > > > Signed-off-by: Geert Uytterhoeven > > > > --- > > > > Compile-tested only. > > > > --- > > > > fs/xfs/xfs_log.c | 4 ++-- > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > > > > > 64 bit division on 32 bit platforms is still a problem in this day > > > and age? > > > > They're not a problem. But you should use the right operations from > > , iff you really need these expensive operations. > > See, that's the whole problem. This *isn't* obviously a 64 bit > division - BBTOB is shifting the variable down by 9 (bytes to blocks) > and then using that as the divisor. BTOBB, not BBTOB ;-) > The problem is that BBTOB has an internal cast to a 64 bit size, > and roundup() just blindly takes it and hence we get non-obvious > compile errors only on 32 bit platforms. Indeed. Perhaps the macros should be fixed? #define BBSHIFT 9 #define BBSIZE (1<> BBSHIFT) #define BTOBBT(bytes) ((__u64)(bytes) >> BBSHIFT) Why are these two casting bytes to u64? The result will be smaller due to the shift. if the type holding bytes was too small, you're screwed anyway. #define BBTOB(bbs) ((bbs) << BBSHIFT) Why does this one lack the cast? If the passed bbs is ever 32-bit, it may overflow due to the shift. > We have type checking macros for all sorts of generic functionality > - why haven't these generic macros that do division also have type > checking to catch this? i.e. so that when people build kernels on > 64 bit machines find out that they've unwittingly broken 32 bit > builds the moment they use roundup() and/or friends incorrectly? > > That would save a lot of extra work having fix crap like this up > after the fact... While adding checks would work for e.g. roundup(), it wouldn't work for plain divisions not involving rounding, as we don't have a way to catch this for "a / b", except for the link error on 32-bit platforms. Perhaps the build bots are not monitoring linux-xfs? Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds