Re: [PATCH v8 06/10] iomap: fix iomap_dio_zero() for fs bs > system page size

From: Dave Chinner
Date: Sun Jun 30 2024 - 22:37:23 EST


On Tue, Jun 25, 2024 at 11:44:16AM +0000, Pankaj Raghav (Samsung) wrote:
> From: Pankaj Raghav <p.raghav@xxxxxxxxxxx>
>
> iomap_dio_zero() will pad a fs block with zeroes if the direct IO size
> < fs block size. iomap_dio_zero() has an implicit assumption that fs block
> size < page_size. This is true for most filesystems at the moment.
>
> If the block size > page size, this will send the contents of the page
> next to zero page(as len > PAGE_SIZE) to the underlying block device,
> causing FS corruption.
>
> iomap is a generic infrastructure and it should not make any assumptions
> about the fs block size and the page size of the system.
>
> Signed-off-by: Pankaj Raghav <p.raghav@xxxxxxxxxxx>
> Reviewed-by: Hannes Reinecke <hare@xxxxxxx>

Looks fine, so:

Reviewed-by: Dave Chinner <dchinner@xxxxxxxxxx>

but....

> +/*
> + * Used for sub block zeroing in iomap_dio_zero()
> + */
> +#define ZERO_PAGE_64K_SIZE (65536)
> +#define ZERO_PAGE_64K_ORDER (get_order(ZERO_PAGE_64K_SIZE))
> +static struct page *zero_page_64k;

.....

> @@ -753,3 +765,17 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
> return iomap_dio_complete(dio);
> }
> EXPORT_SYMBOL_GPL(iomap_dio_rw);
> +
> +static int __init iomap_dio_init(void)
> +{
> + zero_page_64k = alloc_pages(GFP_KERNEL | __GFP_ZERO,
> + ZERO_PAGE_64K_ORDER);
> +
> + if (!zero_page_64k)
> + return -ENOMEM;
> +
> + set_memory_ro((unsigned long)page_address(zero_page_64k),
> + 1U << ZERO_PAGE_64K_ORDER);
^^^^^^^^^^^^^^^^^^^^^^^^^
isn't that just ZERO_PAGE_64K_SIZE?

-Dave.
--
Dave Chinner
david@xxxxxxxxxxxxx