Skip to contentSkip to conversation

blk-crypto: use BLK_STS_INVAL for alignment errors

PATCH Applied Carlos Llamas 4 participants 6 messages Oct 30, 2025 – Oct 31, 2025 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blk-crypto: use BLK_STS_INVAL for alignment errors

Make __blk_crypto_bio_prep() propagate BLK_STS_INVAL when IO segments fail the data unit alignment check.

This was flagged by an LTP test that expects EINVAL when performing an O_DIRECT read with a misaligned buffer [1].

---
 block/blk-crypto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-crypto.c +1 -1
index 4b1ad84d1b5a..3e7bf1974cbd 100644
@@ -292,7 +292,7 @@ bool __blk_crypto_bio_prep(struct bio **bio_ptr)
 	}
 
 	if (!bio_crypt_check_alignment(bio)) {
-		bio->bi_status = BLK_STS_IOERR;
+		bio->bi_status = BLK_STS_INVAL;
 		goto fail;
 	}
 
Signature · 1 line
2.51.1.851.g4ebd6896fd-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Carlos Llamas

Make __blk_crypto_bio_prep() propagate BLK_STS_INVAL when IO segments fail the data unit alignment check.

This was flagged by an LTP test that expects EINVAL when performing an O_DIRECT read with a misaligned buffer [1].

---
 block/blk-crypto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-crypto.c +0 -0
index 4b1ad84d1b5a..3e7bf1974cbd 100644

block/blk-crypto.c bool __blk_crypto_bio_prep(struct bio **bio_ptr) · line 296

Quoted 6 lines
block/blk-crypto.c +1 -1
@@ -292,7 +292,7 @@ bool __blk_crypto_bio_prep(struct bio **bio_ptr)
 	}
 
 	if (!bio_crypt_check_alignment(bio)) {
-		bio->bi_status = BLK_STS_IOERR;
+		bio->bi_status = BLK_STS_INVAL;
 		goto fail;

- Eric

#2 lore raw
In reply to Carlos Llamas
Quoted 19 lines · Carlos Llamas

Make __blk_crypto_bio_prep() propagate BLK_STS_INVAL when IO segments fail the data unit alignment check.

This was flagged by an LTP test that expects EINVAL when performing an O_DIRECT read with a misaligned buffer [1].

---
 block/blk-crypto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-crypto.c +0 -0
index 4b1ad84d1b5a..3e7bf1974cbd 100644

block/blk-crypto.c bool __blk_crypto_bio_prep(struct bio **bio_ptr) · line 296

Quoted 6 lines
block/blk-crypto.c +1 -1
@@ -292,7 +292,7 @@ bool __blk_crypto_bio_prep(struct bio **bio_ptr)
 	}
 
 	if (!bio_crypt_check_alignment(bio)) {
-		bio->bi_status = BLK_STS_IOERR;
+		bio->bi_status = BLK_STS_INVAL;
 		goto fail;

Note that the dio_mem_align reporting in ext4 and f2fs also need to be updated to account for this.

#3 lore raw
Quoted 22 lines · Christoph Hellwig
Quoted 21 lines · Carlos Llamas

Make __blk_crypto_bio_prep() propagate BLK_STS_INVAL when IO segments fail the data unit alignment check.

This was flagged by an LTP test that expects EINVAL when performing an O_DIRECT read with a misaligned buffer [1].

---
 block/blk-crypto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-crypto.c +0 -0
index 4b1ad84d1b5a..3e7bf1974cbd 100644
@@ -292,7 +292,7 @@ bool __blk_crypto_bio_prep(struct bio **bio_ptr)
 	}
 
Quoted 7 lines

block/blk-crypto.c bool __blk_crypto_bio_prep(struct bio **bio_ptr) · line 296

Quoted 4 lines
block/blk-crypto.c +1 -1
 	if (!bio_crypt_check_alignment(bio)) {
-		bio->bi_status = BLK_STS_IOERR;
+		bio->bi_status = BLK_STS_INVAL;
 		goto fail;

Note that the dio_mem_align reporting in ext4 and f2fs also need to be updated to account for this.

I'm not sure what you mean. They already take encryption into account and report dio_mem_align=filesystem_block_size on encrypted files.

- Eric

#4 lore raw
Quoted 2 lines · Eric Biggers

I'm not sure what you mean. They already take encryption into account and report dio_mem_align=filesystem_block_size on encrypted files.

Oh, right - it's just hidden a few layers deep.

maintainer Applied
#5 lore raw
In reply to Carlos Llamas
Quoted 8 lines · Carlos Llamas

Make __blk_crypto_bio_prep() propagate BLK_STS_INVAL when IO segments fail the data unit alignment check.

This was flagged by an LTP test that expects EINVAL when performing an O_DIRECT read with a misaligned buffer [1].

[...]

Applied, thanks!

[1/1] blk-crypto: use BLK_STS_INVAL for alignment errors

      commit: 0b39ca457241aeca07a613002512573e8804f93a

Best regards,

Signature · 1 line
Jens Axboe