Skip to contentSkip to conversation

ceph: fix end offset in truncate_inode_pages_range call

PATCH In review Luis Henriques 2 participants 4 messages Jul 1, 2019 – Jul 2, 2019 Ceph client

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: fix end offset in truncate_inode_pages_range call

Commit e450f4d1a5d6 ("ceph: pass inclusive lend parameter to filemap_write_and_wait_range()") fixed the end offset parameter used to call filemap_write_and_wait_range and invalidate_inode_pages2_range. Unfortunately it missed truncate_inode_pages_range, introducing a regression that is easily detected by xfstest generic/130.

The problem is that when doing direct IO it is possible that an extra page is truncated from the page cache when the end offset is page aligned. This can cause data loss if that page hasn't been sync'ed to the OSDs.

While there, change code to use PAGE_ALIGN macro instead.

Fixes e450f4d1a5d6 ("ceph: pass inclusive lend parameter to filemap_write_and_wait_range()")
---
 fs/ceph/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/file.c +1 -1
index 183c37c0a8fc..7a57db8e2fa9 100644
@@ -1007,7 +1007,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
 			 * may block.
 			 */
 			truncate_inode_pages_range(inode->i_mapping, pos,
-					(pos+len) | (PAGE_SIZE - 1));
+						   PAGE_ALIGN(pos + len) - 1);
 
 			req->r_mtime = mtime;
 		}
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Luis Henriques

Commit e450f4d1a5d6 ("ceph: pass inclusive lend parameter to filemap_write_and_wait_range()") fixed the end offset parameter used to call filemap_write_and_wait_range and invalidate_inode_pages2_range. Unfortunately it missed truncate_inode_pages_range, introducing a regression that is easily detected by xfstest generic/130.

The problem is that when doing direct IO it is possible that an extra page is truncated from the page cache when the end offset is page aligned. This can cause data loss if that page hasn't been sync'ed to the OSDs.

While there, change code to use PAGE_ALIGN macro instead.

Fixes e450f4d1a5d6 ("ceph: pass inclusive lend parameter to filemap_write_and_wait_range()")
---
 fs/ceph/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/file.c +0 -0
index 183c37c0a8fc..7a57db8e2fa9 100644

fs/ceph/file.c (struct kiocb *iocb, struct iov_iter *iter, · line 1013

Quoted 8 lines
fs/ceph/file.c +1 -1
@@ -1007,7 +1007,7 @@ 	(struct kiocb *iocb, struct iov_iter *iter,
 			 * may block.
 			 */
 			truncate_inode_pages_range(inode->i_mapping, pos,
-					(pos+len) | (PAGE_SIZE - 1));
+						   PAGE_ALIGN(pos + len) - 1);
 
 			req->r_mtime = mtime;
 		}
#2 lore raw
In reply to Luis Henriques
Quoted 23 lines · Luis Henriques

Commit e450f4d1a5d6 ("ceph: pass inclusive lend parameter to filemap_write_and_wait_range()") fixed the end offset parameter used to call filemap_write_and_wait_range and invalidate_inode_pages2_range. Unfortunately it missed truncate_inode_pages_range, introducing a regression that is easily detected by xfstest generic/130.

The problem is that when doing direct IO it is possible that an extra page is truncated from the page cache when the end offset is page aligned. This can cause data loss if that page hasn't been sync'ed to the OSDs.

While there, change code to use PAGE_ALIGN macro instead.

Fixes e450f4d1a5d6 ("ceph: pass inclusive lend parameter to filemap_write_and_wait_range()")
---
 fs/ceph/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/file.c +0 -0
index 183c37c0a8fc..7a57db8e2fa9 100644

fs/ceph/file.c ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter, · line 1013

Quoted 8 lines
fs/ceph/file.c +1 -1
@@ -1007,7 +1007,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
 			 * may block.
 			 */
 			truncate_inode_pages_range(inode->i_mapping, pos,
-					(pos+len) | (PAGE_SIZE - 1));
+						   PAGE_ALIGN(pos + len) - 1);
 
 			req->r_mtime = mtime;
 		}

Luis, should this be sent to stable? It seems like a data corruption problem...

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>
#3 lore raw
Quoted 30 lines · Jeff Layton
Quoted 29 lines · Luis Henriques

Commit e450f4d1a5d6 ("ceph: pass inclusive lend parameter to filemap_write_and_wait_range()") fixed the end offset parameter used to call filemap_write_and_wait_range and invalidate_inode_pages2_range. Unfortunately it missed truncate_inode_pages_range, introducing a regression that is easily detected by xfstest generic/130.

The problem is that when doing direct IO it is possible that an extra page is truncated from the page cache when the end offset is page aligned. This can cause data loss if that page hasn't been sync'ed to the OSDs.

While there, change code to use PAGE_ALIGN macro instead.

Fixes e450f4d1a5d6 ("ceph: pass inclusive lend parameter to filemap_write_and_wait_range()")
---
 fs/ceph/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/file.c +1 -1
index 183c37c0a8fc..7a57db8e2fa9 100644
@@ -1007,7 +1007,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
 			 * may block.
 			 */
 			truncate_inode_pages_range(inode->i_mapping, pos,
-					(pos+len) | (PAGE_SIZE - 1));
+						   PAGE_ALIGN(pos + len) - 1);
 
Quoted 5 lines

fs/ceph/file.c ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter, · line 1013

Quoted 2 lines
fs/ceph/file.c +0 -0
 			req->r_mtime = mtime;
 		}

Luis, should this be sent to stable? It seems like a data corruption problem...

Yes, I believe so. But I believe all the active stable kernels that include commit e450f4d1a5d6 (or a backport of it) will pick it anyway due to the 'Fixes:' tag. AFAIK only 5.1 and 5.2 are affected.

Cheers,

Signature · 1 line
Luis