Skip to content

Commit feec24a

Browse files
nhoriguchitorvalds
authored andcommitted
mm, soft-offline: convert parameter to pfn
Currently soft_offline_page() receives struct page, and its sibling memory_failure() receives pfn. This discrepancy looks weird and makes precheck on pfn validity tricky. So let's align them. Link: http://lkml.kernel.org/r/20191016234706.GA5493@www9186uo.sakura.ne.jp Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Acked-by: Andrew Morton <akpm@linux-foundation.org> Cc: David Hildenbrand <david@redhat.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Oscar Salvador <osalvador@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 996ff7a commit feec24a

4 files changed

Lines changed: 12 additions & 18 deletions

File tree

‎drivers/base/memory.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,7 @@ static ssize_t soft_offline_page_store(struct device *dev,
538538
if (kstrtoull(buf, 0, &pfn) < 0)
539539
return -EINVAL;
540540
pfn >>= PAGE_SHIFT;
541-
if (!pfn_valid(pfn))
542-
return -ENXIO;
543-
/* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */
544-
if (!pfn_to_online_page(pfn))
545-
return -EIO;
546-
ret = soft_offline_page(pfn_to_page(pfn), 0);
541+
ret = soft_offline_page(pfn, 0);
547542
return ret == 0 ? count : ret;
548543
}
549544

‎include/linux/mm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,7 @@ extern int sysctl_memory_failure_early_kill;
27732773
extern int sysctl_memory_failure_recovery;
27742774
extern void shake_page(struct page *p, int access);
27752775
extern atomic_long_t num_poisoned_pages __read_mostly;
2776-
extern int soft_offline_page(struct page *page, int flags);
2776+
extern int soft_offline_page(unsigned long pfn, int flags);
27772777

27782778

27792779
/*

‎mm/madvise.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ static int madvise_inject_error(int behavior,
895895
pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n",
896896
pfn, start);
897897

898-
ret = soft_offline_page(page, MF_COUNT_INCREASED);
898+
ret = soft_offline_page(pfn, MF_COUNT_INCREASED);
899899
if (ret)
900900
return ret;
901901
continue;

‎mm/memory-failure.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ static void memory_failure_work_func(struct work_struct *work)
14761476
if (!gotten)
14771477
break;
14781478
if (entry.flags & MF_SOFT_OFFLINE)
1479-
soft_offline_page(pfn_to_page(entry.pfn), entry.flags);
1479+
soft_offline_page(entry.pfn, entry.flags);
14801480
else
14811481
memory_failure(entry.pfn, entry.flags);
14821482
}
@@ -1857,7 +1857,7 @@ static int soft_offline_free_page(struct page *page)
18571857

18581858
/**
18591859
* soft_offline_page - Soft offline a page.
1860-
* @page: page to offline
1860+
* @pfn: pfn to soft-offline
18611861
* @flags: flags. Same as memory_failure().
18621862
*
18631863
* Returns 0 on success, otherwise negated errno.
@@ -1877,18 +1877,17 @@ static int soft_offline_free_page(struct page *page)
18771877
* This is not a 100% solution for all memory, but tries to be
18781878
* ``good enough'' for the majority of memory.
18791879
*/
1880-
int soft_offline_page(struct page *page, int flags)
1880+
int soft_offline_page(unsigned long pfn, int flags)
18811881
{
18821882
int ret;
1883-
unsigned long pfn = page_to_pfn(page);
1883+
struct page *page;
18841884

1885-
if (is_zone_device_page(page)) {
1886-
pr_debug_ratelimited("soft_offline: %#lx page is device page\n",
1887-
pfn);
1888-
if (flags & MF_COUNT_INCREASED)
1889-
put_page(page);
1885+
if (!pfn_valid(pfn))
1886+
return -ENXIO;
1887+
/* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */
1888+
page = pfn_to_online_page(pfn);
1889+
if (!page)
18901890
return -EIO;
1891-
}
18921891

18931892
if (PageHWPoison(page)) {
18941893
pr_info("soft offline: %#lx page already poisoned\n", pfn);

0 commit comments

Comments
 (0)