diff mbox series

[2/3] fs: use nth_page() in place of direct struct page manipulation.

Message ID 20230830182753.55367-3-zi.yan@sent.com (mailing list archive)
State Superseded
Headers show
Series Use nth_page() in place of direct struct page manipulation | expand

Commit Message

Zi Yan Aug. 30, 2023, 6:27 p.m. UTC
From: Zi Yan <ziy@nvidia.com>

When dealing with hugetlb pages, struct page is not guaranteed to be
contiguous on SPARSEMEM without VMEMMAP. Use nth_page() to handle it
properly.

Signed-off-by: Zi Yan <ziy@nvidia.com>
---
 fs/hugetlbfs/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Muchun Song Aug. 31, 2023, 7:17 a.m. UTC | #1
> On Aug 31, 2023, at 02:27, Zi Yan <zi.yan@sent.com> wrote:
> 
> From: Zi Yan <ziy@nvidia.com>
> 
> When dealing with hugetlb pages, struct page is not guaranteed to be
> contiguous on SPARSEMEM without VMEMMAP. Use nth_page() to handle it
> properly.
> 
> Signed-off-by: Zi Yan <ziy@nvidia.com <mailto:ziy@nvidia.com>>

Reviewed-by: Muchun Song <songmuchun@bytedance.com>

It's better to add a Fixes tag to the commit 38c1ddbde6.

Thanks.
Zi Yan Aug. 31, 2023, 3:37 p.m. UTC | #2
On 31 Aug 2023, at 3:17, Muchun Song wrote:

>> On Aug 31, 2023, at 02:27, Zi Yan <zi.yan@sent.com> wrote:
>>
>> From: Zi Yan <ziy@nvidia.com>
>>
>> When dealing with hugetlb pages, struct page is not guaranteed to be
>> contiguous on SPARSEMEM without VMEMMAP. Use nth_page() to handle it
>> properly.
>>
>> Signed-off-by: Zi Yan <ziy@nvidia.com <mailto:ziy@nvidia.com>>
>
> Reviewed-by: Muchun Song <songmuchun@bytedance.com>
>
> It's better to add a Fixes tag to the commit 38c1ddbde6.

Thanks. Will add it in the next version.

--
Best Regards,
Yan, Zi
diff mbox series

Patch

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 316c4cebd3f3..60fce26ff937 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -295,7 +295,7 @@  static size_t adjust_range_hwpoison(struct page *page, size_t offset, size_t byt
 	size_t res = 0;
 
 	/* First subpage to start the loop. */
-	page += offset / PAGE_SIZE;
+	page = nth_page(page, offset / PAGE_SIZE);
 	offset %= PAGE_SIZE;
 	while (1) {
 		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
 			break;
 		offset += n;
 		if (offset == PAGE_SIZE) {
-			page++;
+			page = nth_page(page, 1);
 			offset = 0;
 		}
 	}