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.

mm/madvise: use is_memory_failure() from madvise_do_behavior()

Patch series "mm/madvise: cleanup requests validations and classifications".

Cleanup madvise entry level code for cleaner request validations and
classifications.


This patch (of 4):

To reduce redundant open-coded checks of CONFIG_MEMORY_FAILURE and
MADV_{HWPOISON,SOFT_OFFLINE} in madvise_[un]lock(), is_memory_failure() is
introduced. madvise_do_behavior() is still doing the same open-coded
check, though. Use is_memory_failure() instead.

To avoid build failure on !CONFIG_MEMORY_FAILURE case, implement an empty
madvise_inject_error() under the config. Also move the definition of
is_memory_failure() inside #ifdef CONFIG_MEMORY_FAILURE clause for
madvise_inject_error() definition, to reduce duplicated ifdef clauses.

Link: https://lkml.kernel.org/r/20250312164750.59215-1-sj@kernel.org
Link: https://lkml.kernel.org/r/20250312164750.59215-2-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: David Hildenbrand <david@redhat.com>
Cc: Liam R. Howlett <howlett@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
9ecd2f83 15766485

+27 -22
+27 -22
mm/madvise.c
··· 1392 1392 1393 1393 return 0; 1394 1394 } 1395 - #endif 1395 + 1396 + static bool is_memory_failure(int behavior) 1397 + { 1398 + switch (behavior) { 1399 + case MADV_HWPOISON: 1400 + case MADV_SOFT_OFFLINE: 1401 + return true; 1402 + default: 1403 + return false; 1404 + } 1405 + } 1406 + 1407 + #else 1408 + 1409 + static int madvise_inject_error(int behavior, 1410 + unsigned long start, unsigned long end) 1411 + { 1412 + return 0; 1413 + } 1414 + 1415 + static bool is_memory_failure(int behavior) 1416 + { 1417 + return false; 1418 + } 1419 + 1420 + #endif /* CONFIG_MEMORY_FAILURE */ 1396 1421 1397 1422 static bool 1398 1423 madvise_behavior_valid(int behavior) ··· 1594 1569 } 1595 1570 #endif /* CONFIG_ANON_VMA_NAME */ 1596 1571 1597 - #ifdef CONFIG_MEMORY_FAILURE 1598 - static bool is_memory_failure(int behavior) 1599 - { 1600 - switch (behavior) { 1601 - case MADV_HWPOISON: 1602 - case MADV_SOFT_OFFLINE: 1603 - return true; 1604 - default: 1605 - return false; 1606 - } 1607 - } 1608 - #else 1609 - static bool is_memory_failure(int behavior) 1610 - { 1611 - return false; 1612 - } 1613 - #endif 1614 - 1615 1572 static int madvise_lock(struct mm_struct *mm, int behavior) 1616 1573 { 1617 1574 if (is_memory_failure(behavior)) ··· 1647 1640 unsigned long end; 1648 1641 int error; 1649 1642 1650 - #ifdef CONFIG_MEMORY_FAILURE 1651 - if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE) 1643 + if (is_memory_failure(behavior)) 1652 1644 return madvise_inject_error(behavior, start, start + len_in); 1653 - #endif 1654 1645 start = untagged_addr_remote(mm, start); 1655 1646 end = start + len; 1656 1647