Skip to content

Commit fa59895

Browse files
Hugh Dickinsakpm00
authored andcommitted
shmem: minor fixes to splice-read implementation
HWPoison: my reading of folio_test_hwpoison() is that it only tests the head page of a large folio, whereas splice_folio_into_pipe() will splice as much of the folio as it can: so for safety we should also check the has_hwpoisoned flag, set if any of the folio's pages are hwpoisoned. (Perhaps that ugliness can be improved at the mm end later.) The call to splice_zeropage_into_pipe() risked overrunning past EOF: ask it for "part" not "len". Link: https://lkml.kernel.org/r/[email protected] Fixes: bd194b1 ("shmem: Implement splice-read") Signed-off-by: Hugh Dickins <[email protected]> Reviewed-by: David Howells <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Jens Axboe <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 253e5df commit fa59895

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mm/shmem.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,7 +2796,8 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
27962796
if (*ppos >= i_size_read(inode))
27972797
break;
27982798

2799-
error = shmem_get_folio(inode, *ppos / PAGE_SIZE, &folio, SGP_READ);
2799+
error = shmem_get_folio(inode, *ppos / PAGE_SIZE, &folio,
2800+
SGP_READ);
28002801
if (error) {
28012802
if (error == -EINVAL)
28022803
error = 0;
@@ -2805,7 +2806,9 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
28052806
if (folio) {
28062807
folio_unlock(folio);
28072808

2808-
if (folio_test_hwpoison(folio)) {
2809+
if (folio_test_hwpoison(folio) ||
2810+
(folio_test_large(folio) &&
2811+
folio_test_has_hwpoisoned(folio))) {
28092812
error = -EIO;
28102813
break;
28112814
}
@@ -2841,7 +2844,7 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,
28412844
folio_put(folio);
28422845
folio = NULL;
28432846
} else {
2844-
n = splice_zeropage_into_pipe(pipe, *ppos, len);
2847+
n = splice_zeropage_into_pipe(pipe, *ppos, part);
28452848
}
28462849

28472850
if (!n)

0 commit comments

Comments
 (0)