Skip to content

Commit 8db0ec7

Browse files
x-y-zakpm00
authored andcommitted
fs: use nth_page() in place of direct struct page manipulation
When dealing with hugetlb pages, struct page is not guaranteed to be contiguous on SPARSEMEM without VMEMMAP. Use nth_page() to handle it properly. Without the fix, a wrong subpage might be checked for HWPoison, causing wrong number of bytes of a page copied to user space. No bug is reported. The fix comes from code inspection. Link: https://lkml.kernel.org/r/[email protected] Fixes: 38c1ddb ("hugetlbfs: improve read HWPOISON hugepage") Signed-off-by: Zi Yan <[email protected]> Reviewed-by: Muchun Song <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Mike Rapoport (IBM) <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1640a0e commit 8db0ec7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/hugetlbfs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static size_t adjust_range_hwpoison(struct page *page, size_t offset, size_t byt
295295
size_t res = 0;
296296

297297
/* First subpage to start the loop. */
298-
page += offset / PAGE_SIZE;
298+
page = nth_page(page, offset / PAGE_SIZE);
299299
offset %= PAGE_SIZE;
300300
while (1) {
301301
if (is_raw_hwpoison_page_in_hugepage(page))
@@ -309,7 +309,7 @@ static size_t adjust_range_hwpoison(struct page *page, size_t offset, size_t byt
309309
break;
310310
offset += n;
311311
if (offset == PAGE_SIZE) {
312-
page++;
312+
page = nth_page(page, 1);
313313
offset = 0;
314314
}
315315
}

0 commit comments

Comments
 (0)