fscrypt: stop using PG_error to track error status
As a step towards freeing the PG_error flag for other uses, change ext4 and f2fs to stop using PG_error to track decryption errors. Instead, if a decryption error occurs, just mark the whole bio as failed. The coarser granularity isn't really a problem since it isn't any worse than what the block layer provides, and errors from a multi-page readahead aren't reported to applications unless a single-page read fails too. Signed-off-by: Eric Biggers <ebiggers@google.com> Reviewed-by: Chao Yu <chao@kernel.org> # for f2fs part Link: https://lore.kernel.org/r/20220815235052.86545-2-ebiggers@kernel.org
This commit is contained in:
parent
272ac15003
commit
14db0b3c7b
4 changed files with 29 additions and 20 deletions
|
@ -25,21 +25,25 @@
|
||||||
* then this function isn't applicable. This function may sleep, so it must be
|
* then this function isn't applicable. This function may sleep, so it must be
|
||||||
* called from a workqueue rather than from the bio's bi_end_io callback.
|
* called from a workqueue rather than from the bio's bi_end_io callback.
|
||||||
*
|
*
|
||||||
* This function sets PG_error on any pages that contain any blocks that failed
|
* Return: %true on success; %false on failure. On failure, bio->bi_status is
|
||||||
* to be decrypted. The filesystem must not mark such pages uptodate.
|
* also set to an error status.
|
||||||
*/
|
*/
|
||||||
void fscrypt_decrypt_bio(struct bio *bio)
|
bool fscrypt_decrypt_bio(struct bio *bio)
|
||||||
{
|
{
|
||||||
struct bio_vec *bv;
|
struct bio_vec *bv;
|
||||||
struct bvec_iter_all iter_all;
|
struct bvec_iter_all iter_all;
|
||||||
|
|
||||||
bio_for_each_segment_all(bv, bio, iter_all) {
|
bio_for_each_segment_all(bv, bio, iter_all) {
|
||||||
struct page *page = bv->bv_page;
|
struct page *page = bv->bv_page;
|
||||||
int ret = fscrypt_decrypt_pagecache_blocks(page, bv->bv_len,
|
int err = fscrypt_decrypt_pagecache_blocks(page, bv->bv_len,
|
||||||
bv->bv_offset);
|
bv->bv_offset);
|
||||||
if (ret)
|
|
||||||
SetPageError(page);
|
if (err) {
|
||||||
|
bio->bi_status = errno_to_blk_status(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(fscrypt_decrypt_bio);
|
EXPORT_SYMBOL(fscrypt_decrypt_bio);
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ static void __read_end_io(struct bio *bio)
|
||||||
bio_for_each_segment_all(bv, bio, iter_all) {
|
bio_for_each_segment_all(bv, bio, iter_all) {
|
||||||
page = bv->bv_page;
|
page = bv->bv_page;
|
||||||
|
|
||||||
/* PG_error was set if any post_read step failed */
|
/* PG_error was set if verity failed. */
|
||||||
if (bio->bi_status || PageError(page)) {
|
if (bio->bi_status || PageError(page)) {
|
||||||
ClearPageUptodate(page);
|
ClearPageUptodate(page);
|
||||||
/* will re-read again later */
|
/* will re-read again later */
|
||||||
|
@ -96,10 +96,12 @@ static void decrypt_work(struct work_struct *work)
|
||||||
{
|
{
|
||||||
struct bio_post_read_ctx *ctx =
|
struct bio_post_read_ctx *ctx =
|
||||||
container_of(work, struct bio_post_read_ctx, work);
|
container_of(work, struct bio_post_read_ctx, work);
|
||||||
|
struct bio *bio = ctx->bio;
|
||||||
|
|
||||||
fscrypt_decrypt_bio(ctx->bio);
|
if (fscrypt_decrypt_bio(bio))
|
||||||
|
bio_post_read_processing(ctx);
|
||||||
bio_post_read_processing(ctx);
|
else
|
||||||
|
__read_end_io(bio);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void verity_work(struct work_struct *work)
|
static void verity_work(struct work_struct *work)
|
||||||
|
|
|
@ -139,7 +139,7 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PG_error was set if decryption or verity failed. */
|
/* PG_error was set if verity failed. */
|
||||||
if (bio->bi_status || PageError(page)) {
|
if (bio->bi_status || PageError(page)) {
|
||||||
ClearPageUptodate(page);
|
ClearPageUptodate(page);
|
||||||
/* will re-read again later */
|
/* will re-read again later */
|
||||||
|
@ -185,7 +185,7 @@ static void f2fs_verify_bio(struct work_struct *work)
|
||||||
struct page *page = bv->bv_page;
|
struct page *page = bv->bv_page;
|
||||||
|
|
||||||
if (!f2fs_is_compressed_page(page) &&
|
if (!f2fs_is_compressed_page(page) &&
|
||||||
!PageError(page) && !fsverity_verify_page(page))
|
!fsverity_verify_page(page))
|
||||||
SetPageError(page);
|
SetPageError(page);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -236,10 +236,9 @@ static void f2fs_handle_step_decompress(struct bio_post_read_ctx *ctx,
|
||||||
bio_for_each_segment_all(bv, ctx->bio, iter_all) {
|
bio_for_each_segment_all(bv, ctx->bio, iter_all) {
|
||||||
struct page *page = bv->bv_page;
|
struct page *page = bv->bv_page;
|
||||||
|
|
||||||
/* PG_error was set if decryption failed. */
|
|
||||||
if (f2fs_is_compressed_page(page))
|
if (f2fs_is_compressed_page(page))
|
||||||
f2fs_end_read_compressed_page(page, PageError(page),
|
f2fs_end_read_compressed_page(page, false, blkaddr,
|
||||||
blkaddr, in_task);
|
in_task);
|
||||||
else
|
else
|
||||||
all_compressed = false;
|
all_compressed = false;
|
||||||
|
|
||||||
|
@ -259,14 +258,17 @@ static void f2fs_post_read_work(struct work_struct *work)
|
||||||
{
|
{
|
||||||
struct bio_post_read_ctx *ctx =
|
struct bio_post_read_ctx *ctx =
|
||||||
container_of(work, struct bio_post_read_ctx, work);
|
container_of(work, struct bio_post_read_ctx, work);
|
||||||
|
struct bio *bio = ctx->bio;
|
||||||
|
|
||||||
if (ctx->enabled_steps & STEP_DECRYPT)
|
if ((ctx->enabled_steps & STEP_DECRYPT) && !fscrypt_decrypt_bio(bio)) {
|
||||||
fscrypt_decrypt_bio(ctx->bio);
|
f2fs_finish_read_bio(bio, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ctx->enabled_steps & STEP_DECOMPRESS)
|
if (ctx->enabled_steps & STEP_DECOMPRESS)
|
||||||
f2fs_handle_step_decompress(ctx, true);
|
f2fs_handle_step_decompress(ctx, true);
|
||||||
|
|
||||||
f2fs_verify_and_finish_bio(ctx->bio, true);
|
f2fs_verify_and_finish_bio(bio, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void f2fs_read_end_io(struct bio *bio)
|
static void f2fs_read_end_io(struct bio *bio)
|
||||||
|
|
|
@ -351,7 +351,7 @@ u64 fscrypt_fname_siphash(const struct inode *dir, const struct qstr *name);
|
||||||
int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags);
|
int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags);
|
||||||
|
|
||||||
/* bio.c */
|
/* bio.c */
|
||||||
void fscrypt_decrypt_bio(struct bio *bio);
|
bool fscrypt_decrypt_bio(struct bio *bio);
|
||||||
int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
|
int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
|
||||||
sector_t pblk, unsigned int len);
|
sector_t pblk, unsigned int len);
|
||||||
|
|
||||||
|
@ -644,8 +644,9 @@ static inline int fscrypt_d_revalidate(struct dentry *dentry,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bio.c */
|
/* bio.c */
|
||||||
static inline void fscrypt_decrypt_bio(struct bio *bio)
|
static inline bool fscrypt_decrypt_bio(struct bio *bio)
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
|
static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
|
||||||
|
|
Loading…
Add table
Reference in a new issue