Skip to content

Commit

Permalink
mm,hwpoison: refactor madvise_inject_error
Browse files Browse the repository at this point in the history
Make a proper if-else condition for {hard,soft}-offline.

Signed-off-by: Oscar Salvador <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Acked-by: Naoya Horiguchi <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Qian Cai <[email protected]>
Cc: Tony Luck <[email protected]>
Cc: "Aneesh Kumar K.V" <[email protected]>
Cc: Aneesh Kumar K.V <[email protected]>
Cc: Aristeu Rozanski <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Dmitry Yakunin <[email protected]>
Cc: Mike Kravetz <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
osalvadorvilardaga authored and torvalds committed Oct 16, 2020
1 parent 7e27f22 commit dc7560b
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions mm/madvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ static long madvise_remove(struct vm_area_struct *vma,
static int madvise_inject_error(int behavior,
unsigned long start, unsigned long end)
{
struct page *page;
struct zone *zone;
unsigned long size;

Expand All @@ -882,6 +881,7 @@ static int madvise_inject_error(int behavior,

for (; start < end; start += size) {
unsigned long pfn;
struct page *page;
int ret;

ret = get_user_pages_fast(start, 1, 0, &page);
Expand All @@ -903,25 +903,21 @@ static int madvise_inject_error(int behavior,

if (behavior == MADV_SOFT_OFFLINE) {
pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n",
pfn, start);

pfn, start);
ret = soft_offline_page(pfn, MF_COUNT_INCREASED);
if (ret)
return ret;
continue;
} else {
pr_info("Injecting memory failure for pfn %#lx at process virtual address %#lx\n",
pfn, start);
/*
* Drop the page reference taken by get_user_pages_fast(). In
* the absence of MF_COUNT_INCREASED the memory_failure()
* routine is responsible for pinning the page to prevent it
* from being released back to the page allocator.
*/
put_page(page);
ret = memory_failure(pfn, 0);
}

pr_info("Injecting memory failure for pfn %#lx at process virtual address %#lx\n",
pfn, start);

/*
* Drop the page reference taken by get_user_pages_fast(). In
* the absence of MF_COUNT_INCREASED the memory_failure()
* routine is responsible for pinning the page to prevent it
* from being released back to the page allocator.
*/
put_page(page);
ret = memory_failure(pfn, 0);
if (ret)
return ret;
}
Expand Down

0 comments on commit dc7560b

Please sign in to comment.