Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs: hugetlbfs: cleanup folio in adjust_range_hwpoison()

Let's cleanup and simplify the function a bit.

Link: https://lkml.kernel.org/r/20250901150359.867252-17-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand and committed by
Andrew Morton
a638ee7f 06d42cf4

+11 -23
+11 -23
fs/hugetlbfs/inode.c
··· 192 192 * Someone wants to read @bytes from a HWPOISON hugetlb @folio from @offset. 193 193 * Returns the maximum number of bytes one can read without touching the 1st raw 194 194 * HWPOISON page. 195 - * 196 - * The implementation borrows the iteration logic from copy_page_to_iter*. 197 195 */ 198 196 static size_t adjust_range_hwpoison(struct folio *folio, size_t offset, 199 197 size_t bytes) 200 198 { 201 - struct page *page; 202 - size_t n = 0; 203 - size_t res = 0; 199 + struct page *page = folio_page(folio, offset / PAGE_SIZE); 200 + size_t safe_bytes; 204 201 205 - /* First page to start the loop. */ 206 - page = folio_page(folio, offset / PAGE_SIZE); 207 - offset %= PAGE_SIZE; 208 - while (1) { 202 + if (is_raw_hwpoison_page_in_hugepage(page)) 203 + return 0; 204 + /* Safe to read the remaining bytes in this page. */ 205 + safe_bytes = PAGE_SIZE - (offset % PAGE_SIZE); 206 + page++; 207 + 208 + /* Check each remaining page as long as we are not done yet. */ 209 + for (; safe_bytes < bytes; safe_bytes += PAGE_SIZE, page++) 209 210 if (is_raw_hwpoison_page_in_hugepage(page)) 210 211 break; 211 212 212 - /* Safe to read n bytes without touching HWPOISON subpage. */ 213 - n = min(bytes, (size_t)PAGE_SIZE - offset); 214 - res += n; 215 - bytes -= n; 216 - if (!bytes || !n) 217 - break; 218 - offset += n; 219 - if (offset == PAGE_SIZE) { 220 - page++; 221 - offset = 0; 222 - } 223 - } 224 - 225 - return res; 213 + return min(safe_bytes, bytes); 226 214 } 227 215 228 216 /*