Message ID | 20230403135304.19858-1-wuchi.zero@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2324267vqo; Mon, 3 Apr 2023 07:02:11 -0700 (PDT) X-Google-Smtp-Source: AKy350ZfvI+nNXSCW/eUUZUS6sip97PRRUd3JL03oGWojwVLITfdYJnhLBKL8drTVlS5GwTPxUZz X-Received: by 2002:a17:906:3703:b0:947:eafc:a738 with SMTP id d3-20020a170906370300b00947eafca738mr7352054ejc.60.1680530531062; Mon, 03 Apr 2023 07:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680530531; cv=none; d=google.com; s=arc-20160816; b=dNIDPsHDPh4anh5wqkLPaRLZem7/fsCBRvgkn+a16ubGLkAghfDL3XY9AZFgcqlEnc ES0I7fJ/JLEYbrmj9jS388n307ZNrOD+WI0vNtsHY8HuMgYN5f2JJFbGDFgssUMbQws0 EzMRQ0pnBOmVTqmIqvj6JQy1bwh7u1HCeOi8afOZmk2UVUUBjuVQyAtgzpM1a3W6wrdr qzkNEgdDMET3W/Xp1wRwgNkEkH9egKfWHlFxaiKOa0QIdqqrtvhxIy5wP0ilrh5UZoty WTt8w7gqIXhc0shcu5Mzn/aWiC7icrQ1iEer6D9lcDO+2M4t/qOQTsVJhwnGm8EbXrKs kTMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=SW9D8BEM++mU1mqMGl1AFvxnGWHPgMmcAakeggyzyYo=; b=HInJEeLl3iVtKcyzTqcUm6ru2i/hQEUxOVCeRnSP0/Xi+uTtL+KuCyfE5DN7fMZwV5 ZNF/e51IX/Y9ZASjLL4QyqEQp4h1ykJ4E85HRO54H03guDP7siqoxOGlFFJ+vdOd0Rel qQrgs27TZoj/qWPyF6ymZF4fBNi2uNL7350fjGfnZO3rZp0vKmUF5Bw7LkAYJlvDw2x2 FVPi5zutYkq/XKHtmMdW4qpbWbEuP1Ko7nKKhcw5Uq0qQavmVpoVp8aBvRVearaZ6iWq ZXLvYzS5ohurCO6RIBjEDn4C6pLvZt08Zk2Qs8T/9BsazmrOdHpUsuZHueJvmJsw//Qt GA6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oR5QkpTB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id my51-20020a1709065a7300b009351546e521si7271751ejc.706.2023.04.03.07.01.41; Mon, 03 Apr 2023 07:02:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oR5QkpTB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231624AbjDCNxQ (ORCPT <rfc822;zwp10758@gmail.com> + 99 others); Mon, 3 Apr 2023 09:53:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232276AbjDCNxP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 3 Apr 2023 09:53:15 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF31230E0; Mon, 3 Apr 2023 06:53:10 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id qe8-20020a17090b4f8800b0023f07253a2cso30586666pjb.3; Mon, 03 Apr 2023 06:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680529990; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SW9D8BEM++mU1mqMGl1AFvxnGWHPgMmcAakeggyzyYo=; b=oR5QkpTB3u45hn9geHeHFTG+NzVWvk2PBEEG/1KlzYUVg/1Tb66u8+aOui687oOyCn kC/DpBz7PzQEVWVp7XGzx9QWGtUvlkpbJ3vgSsjuGybxo/wA78fqZHnoBf5uYh6TSnfn 34LPanpDc9WgKViJiS4Eet7t3cWGwyNYZnxC5WKUscuXe5Zg2qqBHuyQmONdtyhgJ9Gw Gn11mgsp2XYusvdLdA1pYdpYavod9FNcDuUo1t6CtukgcE431D+ueHXyDSs+8JnsvhwN f2gQ1H+i7CX5ez4lE6xHp4vVl82AdAbexQuiVFPu3kR/wWeUobfDs4wf2SoWCsev9oSI KbVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680529990; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SW9D8BEM++mU1mqMGl1AFvxnGWHPgMmcAakeggyzyYo=; b=SwxrtxIDYVlGpaAe19kmg2f5pE98d3ZqtaPwGBM81nZPgtOrptLXSM5dDu9TUClE2L ExEQjFqsKvVhnl8dap+40lIEc7gK9I7HZPeLwciGJE04DHWDt+oCuF0FEEorXBDgN6kX atGxPZ5U0KjVxoFHU8bI430Wh2yrNkhqhP8s9I8US1F30ap2VK5SXGEllB84JKuvYhGu ev38sIwtIwl9hJOcUpwjAuosizw6KwPckWsWn1bqZZyORiFAIF9kQwMxFkxL8+d5c5FT bpQHH0VUb4zDXvxhawoaTfvdzzaSRRoQ0/FvNr1k3pl+jqoZWC4R+f/nXKbeBJTIhgpG eq+A== X-Gm-Message-State: AAQBX9c/E5yyAMV+SxxgIrlixRkBTQliUPcB+R/hpI5eu37eEmtUJmGs PDUy2AEpv7P7StZlyhyVstWahNtgE2oAsQ== X-Received: by 2002:a17:90b:3846:b0:236:6a28:f781 with SMTP id nl6-20020a17090b384600b002366a28f781mr41273891pjb.22.1680529990285; Mon, 03 Apr 2023 06:53:10 -0700 (PDT) Received: from C02FG34WMD6R.bytedance.net ([61.213.176.14]) by smtp.gmail.com with ESMTPSA id nv8-20020a17090b1b4800b00233cde36909sm9802883pjb.21.2023.04.03.06.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 06:53:09 -0700 (PDT) From: wuchi <wuchi.zero@gmail.com> To: tytso@mit.edu, adilger.kernel@dilger.ca, ojaswin@linux.ibm.com, ritesh.list@gmail.com Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ext4: simplify 32bit calculation of lblk Date: Mon, 3 Apr 2023 21:53:04 +0800 Message-Id: <20230403135304.19858-1-wuchi.zero@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762163982261793306?= X-GMAIL-MSGID: =?utf-8?q?1762163982261793306?= |
Series |
ext4: simplify 32bit calculation of lblk
|
|
Commit Message
wuchi
April 3, 2023, 1:53 p.m. UTC
commit <ad4fb9cafe100a> (ext4: fix 32bit overflow in ext4_ext_find_goal())
uses value compare to fix 32bit overflow. Try to simplify that.
Signed-off-by: wuchi <wuchi.zero@gmail.com>
---
fs/ext4/extents.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
Comments
On Mon, Apr 03, 2023 at 09:53:04PM +0800, wuchi wrote: > - if (block > ext_block) > - return ext_pblk + (block - ext_block); > - else > - return ext_pblk - (ext_block - block); > + return ext_pblk + ((signed long long)block - (signed long long)ext_block); And what exactly is the value add here, except for turning an easy to parse statement into a complex expression using casts?
Christoph Hellwig <hch@infradead.org> 于2023年4月5日周三 13:40写道: > > On Mon, Apr 03, 2023 at 09:53:04PM +0800, wuchi wrote: > > - if (block > ext_block) > > - return ext_pblk + (block - ext_block); > > - else > > - return ext_pblk - (ext_block - block); > > + return ext_pblk + ((signed long long)block - (signed long long)ext_block); > > And what exactly is the value add here, except for turning an easy > to parse statement into a complex expression using casts? > Yes,it will be more complex. the original intention is to reduce the conditional branch. =======
From: chi wu > Sent: 05 April 2023 09:48 > > Christoph Hellwig <hch@infradead.org> 于2023年4月5日周三 13:40写道: > > > > On Mon, Apr 03, 2023 at 09:53:04PM +0800, wuchi wrote: > > > - if (block > ext_block) > > > - return ext_pblk + (block - ext_block); > > > - else > > > - return ext_pblk - (ext_block - block); > > > + return ext_pblk + ((signed long long)block - (signed long long)ext_block); > > > > And what exactly is the value add here, except for turning an easy > > to parse statement into a complex expression using casts? > > > Yes,it will be more complex. the original intention is to reduce the > conditional branch. What is wrong with just: return ext_pblk + block - ext_block; (64bit + 32bit - 32bit) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
David Laight <David.Laight@aculab.com> 于2023年4月5日周三 19:43写道: > > From: chi wu > > Sent: 05 April 2023 09:48 > > > > Christoph Hellwig <hch@infradead.org> 于2023年4月5日周三 13:40写道: > > > > > > On Mon, Apr 03, 2023 at 09:53:04PM +0800, wuchi wrote: > > > > - if (block > ext_block) > > > > - return ext_pblk + (block - ext_block); > > > > - else > > > > - return ext_pblk - (ext_block - block); > > > > + return ext_pblk + ((signed long long)block - (signed long long)ext_block); > > > > > > And what exactly is the value add here, except for turning an easy > > > to parse statement into a complex expression using casts? > > > > > Yes,it will be more complex. the original intention is to reduce the > > conditional branch. > > What is wrong with just: > return ext_pblk + block - ext_block; > (64bit + 32bit - 32bit) > oh, It's my fault. I am trapped in that ext_pblk + block may overflow, but it is ok here. thanks. > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales)
From: chi wu > Sent: 05 April 2023 13:48 > > David Laight <David.Laight@aculab.com> 于2023年4月5日周三 19:43写道: > > > > From: chi wu > > > Sent: 05 April 2023 09:48 > > > > > > Christoph Hellwig <hch@infradead.org> 于2023年4月5日周三 13:40写道: > > > > > > > > On Mon, Apr 03, 2023 at 09:53:04PM +0800, wuchi wrote: > > > > > - if (block > ext_block) > > > > > - return ext_pblk + (block - ext_block); > > > > > - else > > > > > - return ext_pblk - (ext_block - block); > > > > > + return ext_pblk + ((signed long long)block - (signed long > long)ext_block); > > > > > > > > And what exactly is the value add here, except for turning an easy > > > > to parse statement into a complex expression using casts? > > > > > > > Yes,it will be more complex. the original intention is to reduce the > > > conditional branch. > > > > What is wrong with just: > > return ext_pblk + block - ext_block; > > (64bit + 32bit - 32bit) > > > oh, It's my fault. I am trapped in that ext_pblk + block may overflow, > but it is ok here. thanks. That doesn't matter, it will 'un-overflow' when ext_block is subtracted. You do need the '+' to happen before the '-', ok because +/- group left to right in C. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 3559ea6b0781..324b7d1386e0 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -237,10 +237,7 @@ static ext4_fsblk_t ext4_ext_find_goal(struct inode *inode, ext4_fsblk_t ext_pblk = ext4_ext_pblock(ex); ext4_lblk_t ext_block = le32_to_cpu(ex->ee_block); - if (block > ext_block) - return ext_pblk + (block - ext_block); - else - return ext_pblk - (ext_block - block); + return ext_pblk + ((signed long long)block - (signed long long)ext_block); } /* it looks like index is empty;