linux-fscrypt.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>,
	Yongpeng Yang <yangyongpeng.storage@gmail.com>,
	Jaegeuk Kim <jaegeuk@kernel.org>, Theodore Ts'o <tytso@mit.edu>,
	linux-fscrypt@vger.kernel.org,
	Yongpeng Yang <yangyongpeng@xiaomi.com>,
	linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org,
	Luis Chamberlain <mcgrof@kernel.org>
Subject: Re: [PATCH v2] fscrypt: fix left shift underflow when inode->i_blkbits > PAGE_SHIFT
Date: Wed, 5 Nov 2025 05:40:23 -0800	[thread overview]
Message-ID: <aQtTxx8ufd00_sJf@infradead.org> (raw)
In-Reply-To: <20251104181006.GC1780@sol>

On Tue, Nov 04, 2025 at 10:10:06AM -0800, Eric Biggers wrote:
> On Tue, Nov 04, 2025 at 03:12:53AM -0800, Christoph Hellwig wrote:
> > On Mon, Nov 03, 2025 at 08:48:29AM -0800, Eric Biggers wrote:
> > > >  	*inode_ret = inode;
> > > > -	*lblk_num_ret = ((u64)folio->index << (PAGE_SHIFT - inode->i_blkbits)) +
> > > > +	*lblk_num_ret = (((u64)folio->index << PAGE_SHIFT) >> inode->i_blkbits) +
> > 
> > This should be using folio_pos() instead of open coding the arithmetics.
> 
> Well, folio_pos() doesn't work with sizes greater than S64_MAX, and it
> uses multiplication rather than a shift.

What do you mean with "sizes greater than S64_MAX"?  folio_pos works
on a folio and is the MM designated helper to get the file offset
from a folio, where a file offset is a loff_t, aka s64.

And as answered to the previous mail, the compiler turns that
multiplication into a shift.

> Anyway, the trivial version avoids having to consider any of this...

I see it the other way around - folio_pos is the defined way to get
the index into the inode (block device inode here) in the abstract
way.


      reply	other threads:[~2025-11-05 13:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-30  7:29 [PATCH v2] fscrypt: fix left shift underflow when inode->i_blkbits > PAGE_SHIFT Yongpeng Yang
2025-11-03 16:48 ` Eric Biggers
2025-11-04 11:12   ` Christoph Hellwig
2025-11-04 15:05     ` Yongpeng Yang
2025-11-05 13:38       ` Christoph Hellwig
2025-11-04 18:10     ` Eric Biggers
2025-11-05 13:40       ` Christoph Hellwig [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aQtTxx8ufd00_sJf@infradead.org \
    --to=hch@infradead.org \
    --cc=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=tytso@mit.edu \
    --cc=yangyongpeng.storage@gmail.com \
    --cc=yangyongpeng@xiaomi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).