Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fscrypt: pass a byte offset to fscrypt_set_bio_crypt_ctx

Logical offsets into an inode are usually expressed as bytes in the VFS.
Switch fscrypt_set_bio_crypt_ctx to that convention.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20260302141922.370070-9-hch@lst.de
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

authored by

Christoph Hellwig and committed by
Eric Biggers
3c7eaa77 22be86a2

+21 -26
+2 -5
fs/buffer.c
··· 2778 2778 gfp_t gfp_mask) 2779 2779 { 2780 2780 const struct address_space *mapping = folio_mapping(bh->b_folio); 2781 - const struct inode *inode; 2782 - u64 lblk; 2783 2781 2784 2782 /* 2785 2783 * The ext4 journal (jbd2) can submit a buffer_head it directly created ··· 2785 2787 */ 2786 2788 if (!mapping) 2787 2789 return; 2788 - inode = mapping->host; 2789 - lblk = (folio_pos(bh->b_folio) + bh_offset(bh)) >> inode->i_blkbits; 2790 - fscrypt_set_bio_crypt_ctx(bio, inode, lblk, gfp_mask); 2790 + fscrypt_set_bio_crypt_ctx(bio, mapping->host, 2791 + folio_pos(bh->b_folio) + bh_offset(bh), gfp_mask); 2791 2792 } 2792 2793 2793 2794 static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh,
+4 -4
fs/crypto/bio.c
··· 75 75 { 76 76 const unsigned int blockbits = inode->i_blkbits; 77 77 const unsigned int blocks_per_page = 1 << (PAGE_SHIFT - blockbits); 78 + loff_t pos = (loff_t)lblk << blockbits; 78 79 struct fscrypt_zero_done done = { 79 80 .pending = ATOMIC_INIT(1), 80 81 .done = COMPLETION_INITIALIZER_ONSTACK(done.done), ··· 90 89 bio->bi_iter.bi_sector = sector; 91 90 bio->bi_private = &done; 92 91 bio->bi_end_io = fscrypt_zeroout_range_end_io; 93 - fscrypt_set_bio_crypt_ctx(bio, inode, lblk, GFP_NOFS); 92 + fscrypt_set_bio_crypt_ctx(bio, inode, pos, GFP_NOFS); 94 93 95 94 for (n = 0; n < BIO_MAX_VECS; n++) { 96 95 unsigned int blocks_this_page = ··· 99 98 100 99 __bio_add_page(bio, ZERO_PAGE(0), bytes_this_page, 0); 101 100 len -= blocks_this_page; 102 - lblk += blocks_this_page; 101 + pos += bytes_this_page; 103 102 sector += (bytes_this_page >> SECTOR_SHIFT); 104 - if (!len || !fscrypt_mergeable_bio(bio, inode, 105 - (loff_t)lblk << blockbits)) 103 + if (!len || !fscrypt_mergeable_bio(bio, inode, pos)) 106 104 break; 107 105 } 108 106
+3 -3
fs/crypto/inline_crypt.c
··· 285 285 * fscrypt_set_bio_crypt_ctx() - prepare a file contents bio for inline crypto 286 286 * @bio: a bio which will eventually be submitted to the file 287 287 * @inode: the file's inode 288 - * @first_lblk: the first file logical block number in the I/O 288 + * @pos: the first file position (in bytes) in the I/O 289 289 * @gfp_mask: memory allocation flags - these must be a waiting mask so that 290 290 * bio_crypt_set_ctx can't fail. 291 291 * ··· 298 298 * The encryption context will be freed automatically when the bio is freed. 299 299 */ 300 300 void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode, 301 - u64 first_lblk, gfp_t gfp_mask) 301 + loff_t pos, gfp_t gfp_mask) 302 302 { 303 303 const struct fscrypt_inode_info *ci; 304 304 u64 dun[BLK_CRYPTO_DUN_ARRAY_SIZE]; ··· 307 307 return; 308 308 ci = fscrypt_get_inode_info_raw(inode); 309 309 310 - fscrypt_generate_dun(ci, first_lblk << inode->i_blkbits, dun); 310 + fscrypt_generate_dun(ci, pos, dun); 311 311 bio_crypt_set_ctx(bio, ci->ci_enc_key.blk_key, dun, gfp_mask); 312 312 } 313 313 EXPORT_SYMBOL_GPL(fscrypt_set_bio_crypt_ctx);
+2 -3
fs/ext4/page-io.c
··· 427 427 * __GFP_DIRECT_RECLAIM is set, see comments for bio_alloc_bioset(). 428 428 */ 429 429 bio = bio_alloc(bh->b_bdev, BIO_MAX_VECS, REQ_OP_WRITE, GFP_NOIO); 430 - fscrypt_set_bio_crypt_ctx(bio, inode, 431 - (folio_pos(folio) + bh_offset(bh)) >> inode->i_blkbits, 432 - GFP_NOIO); 430 + fscrypt_set_bio_crypt_ctx(bio, inode, folio_pos(folio) + bh_offset(bh), 431 + GFP_NOIO); 433 432 bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9); 434 433 bio->bi_end_io = ext4_end_bio; 435 434 bio->bi_private = ext4_get_io_end(io->io_end);
+2 -2
fs/ext4/readpage.c
··· 355 355 */ 356 356 bio = bio_alloc(bdev, bio_max_segs(nr_pages), 357 357 REQ_OP_READ, GFP_KERNEL); 358 - fscrypt_set_bio_crypt_ctx(bio, inode, next_block, 359 - GFP_KERNEL); 358 + fscrypt_set_bio_crypt_ctx(bio, inode, 359 + (loff_t)next_block << blkbits, GFP_KERNEL); 360 360 ext4_set_bio_post_read_ctx(bio, inode, vi); 361 361 bio->bi_iter.bi_sector = first_block << (blkbits - 9); 362 362 bio->bi_end_io = mpage_end_io;
+3 -1
fs/f2fs/data.c
··· 527 527 * read/write raw data without encryption. 528 528 */ 529 529 if (!fio || !fio->encrypted_page) 530 - fscrypt_set_bio_crypt_ctx(bio, inode, first_idx, gfp_mask); 530 + fscrypt_set_bio_crypt_ctx(bio, inode, 531 + (loff_t)first_idx << inode->i_blkbits, 532 + gfp_mask); 531 533 } 532 534 533 535 static bool f2fs_crypt_mergeable_bio(struct bio *bio, const struct inode *inode,
+2 -4
fs/iomap/direct-io.c
··· 311 311 312 312 bio = iomap_dio_alloc_bio(iter, dio, nr_vecs, 313 313 REQ_OP_WRITE | REQ_SYNC | REQ_IDLE); 314 - fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits, 315 - GFP_KERNEL); 314 + fscrypt_set_bio_crypt_ctx(bio, inode, pos, GFP_KERNEL); 316 315 bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos); 317 316 bio->bi_private = dio; 318 317 bio->bi_end_io = iomap_dio_bio_end_io; ··· 341 342 nr_vecs = bio_iov_vecs_to_alloc(dio->submit.iter, BIO_MAX_VECS); 342 343 343 344 bio = iomap_dio_alloc_bio(iter, dio, nr_vecs, op); 344 - fscrypt_set_bio_crypt_ctx(bio, iter->inode, 345 - pos >> iter->inode->i_blkbits, GFP_KERNEL); 345 + fscrypt_set_bio_crypt_ctx(bio, iter->inode, pos, GFP_KERNEL); 346 346 bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos); 347 347 bio->bi_write_hint = iter->inode->i_write_hint; 348 348 bio->bi_ioprio = dio->iocb->ki_ioprio;
+3 -4
include/linux/fscrypt.h
··· 865 865 866 866 bool __fscrypt_inode_uses_inline_crypto(const struct inode *inode); 867 867 868 - void fscrypt_set_bio_crypt_ctx(struct bio *bio, 869 - const struct inode *inode, u64 first_lblk, 870 - gfp_t gfp_mask); 868 + void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode, 869 + loff_t pos, gfp_t gfp_mask); 871 870 872 871 bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode, 873 872 loff_t pos); ··· 884 885 885 886 static inline void fscrypt_set_bio_crypt_ctx(struct bio *bio, 886 887 const struct inode *inode, 887 - u64 first_lblk, gfp_t gfp_mask) { } 888 + loff_t pos, gfp_t gfp_mask) { } 888 889 889 890 static inline bool fscrypt_mergeable_bio(struct bio *bio, 890 891 const struct inode *inode,