Message ID | YI4AwgZaFSGsTDR9@zeniv-ca.linux.org.uk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [git,pull] work.misc | expand |
On Sat, May 1, 2021 at 6:30 PM Al Viro <viro@zeniv.linux.org.uk> wrote: > > Mikulas Patocka (1): > buffer: a small optimization in grow_buffers Side note: if that optimization actually matters (which I doubt), we could just make getblk and friends take s_blocksize_bits instead of the block size. And avoid the whole "find first bit" thing. As it is, we end up doing odd and broken things if anybody were to ever use a non-power-of-2 blocksize (we check that it's a multiple of the hw blocksize, we check that it's between 512 and PAGE_SIZE, but we don't seem to check that it's a power-of-2). This is mostly a legacy interface, I don't think anybody cares, but I thought I'd mention it anyway.. Linus
On Sun, May 02, 2021 at 09:26:26AM -0700, Linus Torvalds wrote: > On Sat, May 1, 2021 at 6:30 PM Al Viro <viro@zeniv.linux.org.uk> wrote: > > > > Mikulas Patocka (1): > > buffer: a small optimization in grow_buffers > > Side note: if that optimization actually matters (which I doubt), we > could just make getblk and friends take s_blocksize_bits instead of > the block size. And avoid the whole "find first bit" thing. > > As it is, we end up doing odd and broken things if anybody were to > ever use a non-power-of-2 blocksize (we check that it's a multiple of > the hw blocksize, we check that it's between 512 and PAGE_SIZE, but we > don't seem to check that it's a power-of-2). I think we have checks that the hw blocksize is a power-of-two (maybe just in SCSI? see sd_read_capacity()) I don't see much demand in the storage industry for non-power-of-two sizes; I was once asked about a 12kB sector size at Intel, but when I said "no", they didn't seem surprised. I see interest in going smaller (cacheline sized) for pmem and I see interest in going larger (16kB sector sizes) for NAND.
On Sun, May 2, 2021 at 11:00 AM Matthew Wilcox <willy@infradead.org> wrote: > > I think we have checks that the hw blocksize is a power-of-two (maybe > just in SCSI? see sd_read_capacity()) Not the hardware block size: our own fs/buffer.c block size. I could imagine some fs corruption that causes a filesystem to ask for something like a 1536-byte block size, and I don't see __bread() for example checking that 'size' is actually a power of 2. And if it isn't a power of two, then I see __find_get_block() and __getblk_slow() doing insane things and possibly even overflowing the allocated page. Some filesystems actually start from the blocksize on disk (xfs looks to do that), and do things like sb->s_blocksize = mp->m_sb.sb_blocksize; sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1; and just imagine what happens if the blocksize on disk is 1536... Now, xfs has a check in the SB validation routine: sbp->sb_blocksize != (1 << sbp->sb_blocklog) and if that fails, it will return -EFSCORRUPTED. But what about other random filesystems? Hopefully everybody checks it. But my point is, that passing in "size" instead of "bits" not only caused this ffs() optimization, it's also a potential source of subtle problems.. (But it goes back to the dark ages, I'm not blaming anybody but myself). Linus
The pull request you sent on Sun, 2 May 2021 01:30:42 +0000:
> git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git work.misc
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/27787ba3fa4904422b3928b898d1bd3d74d98bea
Thank you!