udf: Fix handling of in-ICB files
Subsystems (2)
Jan Kara
reviewercover udf: Fix handling of in-ICB files
Hello,
conversion of UDF to use the same address_space operations for normal an inline (in-ICB) files had two bugs resulting in buffered reads / writes not really working properly for in-ICB files. Interestingly none of the xfstests discovered this (likely because files have to be small to fit within ICB and you have to evict the first file page from the page cache to notice). I've now verified with manual testing that read & writes to in-ICB files work again after these fixes. I plan to push these fixes to Linus through my tree soon.
Honza
Jan Kara
reviewerPATCH 1/3 udf: Fix lost writes in udf_adinicb_writepage()
The patch converting udf_adinicb_writepage() to avoid manually kmapping the page used memcpy_to_page() however that copies in the wrong direction (effectively overwriting file data with the old contents). What we should be using is memcpy_from_page() to copy data from the page into the inode and then mark inode dirty to store the data.
--- fs/udf/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/udf/inode.c +1 -1
@@ -193,7 +193,7 @@ static int udf_adinicb_writepage(struct folio *folio,struct udf_inode_info *iinfo =UDF_I (inode);BUG_ON (!PageLocked (page)); -memcpy_to_page (page,0 , iinfo->i_data + iinfo->i_lenEAttr, +memcpy_from_page (iinfo->i_data + iinfo->i_lenEAttr, page,0 ,i_size_read (inode));unlock_page (page);mark_inode_dirty (inode);
Signature · 1 line
2.35.3
Re: [PATCH 1/3] udf: Fix lost writes in udf_adinicb_writepage()
Quoted 8 lines · Jan Kara
The patch converting
udf_adinicb_writepage()to avoid manually kmapping the page usedmemcpy_to_page()however that copies in the wrong direction (effectively overwriting file data with the old contents). What we should be using ismemcpy_from_page()to copy data from the page into the inode and then mark inode dirty to store the data.Fixes 5cfc45321a6d ("udf: Convert udf_adinicb_writepage() to memcpy_to_page()")Signed-off-by Jan Kara <[email protected]>
Oops. Now you're copying in the right direction, we have a folio function for that, so we could just folio-ise the entire function? Maybe you'd rather keep the fix minimal and apply this later.
fs/udf/inode.c +5 -5
@@ -188,14 +188,14 @@ static void udf_write_failed(struct address_space *mapping, loff_t to)static int udf_adinicb_writepage (struct folio *folio,struct writeback_control *wbc,void *data) { -struct page *page = &folio->page; -struct inode *inode = page->mapping->host; +struct inode *inode = folio->mapping->host;struct udf_inode_info *iinfo =UDF_I (inode); -BUG_ON (!PageLocked (page)); -memcpy_to_page (page,0 , iinfo->i_data + iinfo->i_lenEAttr, +BUG_ON (!folio_test_locked (folio)); +BUG_ON (folio->index !=0 ); +memcpy_from_file_folio (iinfo->i_data + iinfo->i_lenEAttr, folio,0 ,i_size_read (inode)); -unlock_page (page); +folio_unlock (folio);mark_inode_dirty (inode);return 0 ;
Jan Kara
reviewerRe: [PATCH 1/3] udf: Fix lost writes in udf_adinicb_writepage()
Quoted 7 lines · Matthew Wilcox
Quoted 6 lines · Jan Kara
The patch converting
udf_adinicb_writepage()to avoid manually kmapping the page usedmemcpy_to_page()however that copies in the wrong direction (effectively overwriting file data with the old contents). What we should be using ismemcpy_from_page()to copy data from the page into the inode and then mark inode dirty to store the data.
Quoted 8 lines
Quoted 2 lines
Fixes 5cfc45321a6d ("udf: Convert udf_adinicb_writepage() to memcpy_to_page()")Signed-off-by Jan Kara <[email protected]>Oops. Now you're copying in the right direction, we have a folio function for that, so we could just folio-ise the entire function? Maybe you'd rather keep the fix minimal and apply this later.
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
Thanks! Yes, I had this in mind but wanted to fix the corruption first so that I can push it quickly to rc2... But I'll queue your patch for later.
Honza
Quoted 25 lines
fs/udf/inode.c +5
-5@@ -188,14 +188,14 @@ static void udf_write_failed(struct address_space *mapping, loff_t to)static int udf_adinicb_writepage (struct folio *folio,struct writeback_control *wbc,void *data) { -struct page *page = &folio->page; -struct inode *inode = page->mapping->host; +struct inode *inode = folio->mapping->host;struct udf_inode_info *iinfo =UDF_I (inode); -BUG_ON (!PageLocked (page)); -memcpy_to_page (page,0 , iinfo->i_data + iinfo->i_lenEAttr, +BUG_ON (!folio_test_locked (folio)); +BUG_ON (folio->index !=0 ); +memcpy_from_file_folio (iinfo->i_data + iinfo->i_lenEAttr, folio,0 ,i_size_read (inode)); -unlock_page (page); +folio_unlock (folio);mark_inode_dirty (inode);return 0 ;
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerPATCH 2/3 udf: Fix reading of in-ICB files
In reply to Jan KaraAfter merging address space operations of normal and in-ICB files, readahead could get called for in-ICB files which resulted in udf_get_block() being called for these files. udf_get_block() is not prepared to be called for in-ICB files and ends up returning garbage results as it interprets file data as extent list. Fix the problem by skipping readahead for in-ICB files.
--- fs/udf/inode.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/udf/inode.c +9 -0
@@ -241,6 +241,15 @@ static int udf_read_folio(struct file *file, struct folio *folio)static void udf_readahead (struct readahead_control *rac) { +struct udf_inode_info *iinfo =UDF_I (rac->mapping->host); + +/* +* No readahead needed for in-ICB files and udf_get_block() would get +* confused for such file anyway. +*/ +if (iinfo->i_alloc_type ==ICBTAG_FLAG_AD_IN_ICB ) +return ; +mpage_readahead (rac, udf_get_block); }
Signature · 1 line
2.35.3
Jan Kara
reviewerPATCH 3/3 udf: Warn if block mapping is done for in-ICB files
In reply to Jan KaraNow that address space operations are merge dfor in-ICB and normal files, it is more likely some code mistakenly tries to map blocks for in-ICB files. WARN and return error instead of silently returning garbage.
--- fs/udf/inode.c | 3 +++ 1 file changed, 3 insertions(+)
fs/udf/inode.c +3 -0
@@ -416,6 +416,9 @@ static int udf_map_block(struct inode *inode, struct udf_map_rq *map)int err;struct udf_inode_info *iinfo =UDF_I (inode); +if (WARN_ON_ONCE (iinfo->i_alloc_type ==ICBTAG_FLAG_AD_IN_ICB )) +return -EFSCORRUPTED ; + map->oflags =0 ;if (!(map->iflags &UDF_MAP_CREATE )) {struct kernel_lb_addr eloc;
Signature · 1 line
2.35.3