[PATCH OLK-5.10 0/2] support apei_page_offline_policy
Automated configuration with enable_soft_offline as global master switch (default=1): enable_soft_offline = 0: Page isolation completely disabled enable_soft_offline = 1: Page isolation enabled, policy controlled by new interface New interface: sysctl_apei_page_offline_policy provides fine-grained control (default=2, isolating base pages only): bit 0: Notify BMC about soft_offline_page scanning bit 1: Control base page isolation bit 2: Control hugetlb page isolation Qi Xi (2): Revert "mm/memory-failure: support disabling soft offline for HugeTLB pages" apei/ghes: Add sysctl interface to control soft-offline page isolation .../ABI/testing/sysfs-memory-page-offline | 3 - drivers/acpi/apei/Makefile | 1 + drivers/acpi/apei/apei-internal.h | 8 ++ drivers/acpi/apei/ghes-policy.c | 102 ++++++++++++++++++ drivers/acpi/apei/ghes.c | 3 + include/linux/acpi.h | 14 +++ kernel/sysctl.c | 2 +- mm/memory-failure.c | 15 +-- 8 files changed, 131 insertions(+), 17 deletions(-) create mode 100644 drivers/acpi/apei/ghes-policy.c -- 2.33.0
hulk inclusion category: feature bugzilla: https://atomgit.com/openeuler/kernel/issues/8489 -------------------------------- This reverts commit e14f9d96acb78e7810ccd2e11d70c9915752e5b8. Commit e14f9d96acb7 ("mm/memory-failure: support disabling soft offline for HugeTLB pages") introduced a new bit of sysctl_enable_soft_offline to support disabling soft offline for HugeTLB pages only. It is no longer needed. Let's revert it. Signed-off-by: Qi Xi <xiqi2@huawei.com> --- .../ABI/testing/sysfs-memory-page-offline | 3 --- kernel/sysctl.c | 2 +- mm/memory-failure.c | 15 ++------------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-memory-page-offline b/Documentation/ABI/testing/sysfs-memory-page-offline index 93285bbadc9e..e14703f12fdf 100644 --- a/Documentation/ABI/testing/sysfs-memory-page-offline +++ b/Documentation/ABI/testing/sysfs-memory-page-offline @@ -20,9 +20,6 @@ Description: number, or a error when the offlining failed. Reading the file is not allowed. - Soft-offline can be controlled via sysctl, see: - Documentation/admin-guide/sysctl/vm.rst - What: /sys/devices/system/memory/hard_offline_page Date: Sep 2009 KernelVersion: 2.6.33 diff --git a/kernel/sysctl.c b/kernel/sysctl.c index daeeddb60c2e..d85c1eb43875 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -3334,7 +3334,7 @@ static struct ctl_table vm_table[] = { .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, - .extra2 = &three, + .extra2 = SYSCTL_ONE, }, #endif { diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 78c13e50f94b..46f55797b102 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -60,14 +60,11 @@ #include "internal.h" #include "ras/ras_event.h" -#define SOFT_OFFLINE_ENABLED BIT(0) -#define SOFT_OFFLINE_SKIP_HUGETLB BIT(1) - int sysctl_memory_failure_early_kill __read_mostly = 0; int sysctl_memory_failure_recovery __read_mostly = 1; -int sysctl_enable_soft_offline __read_mostly = SOFT_OFFLINE_ENABLED; +int sysctl_enable_soft_offline __read_mostly = 1; atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0); @@ -2164,20 +2161,12 @@ int soft_offline_page(unsigned long pfn, int flags) return -EIO; } - if (!(sysctl_enable_soft_offline & SOFT_OFFLINE_ENABLED)) { + if (!sysctl_enable_soft_offline) { pr_info_once("disabled by /proc/sys/vm/enable_soft_offline\n"); put_ref_page(ref_page); return -EOPNOTSUPP; } - if (sysctl_enable_soft_offline & SOFT_OFFLINE_SKIP_HUGETLB) { - if (PageHuge(page)) { - pr_info_once("disabled for HugeTLB pages by /proc/sys/vm/enable_soft_offline\n"); - put_ref_page(ref_page); - return -EOPNOTSUPP; - } - } - if (PageHWPoison(page)) { pr_info("soft offline: %#lx page already poisoned\n", pfn); put_ref_page(ref_page); -- 2.33.0
hulk inclusion category: feature bugzilla: https://atomgit.com/openeuler/kernel/issues/8489 -------------------------------- Add sysctl interface to control GHES triggered soft-offline page handling: - BIT0: Enable/disable driver notification (for BMC reporting, default 0) - BIT1: Enable/disable soft-offline for base pages (default 1) - BIT2: Enable/disable soft-offline for HugeTLB pages (default 0) Only BIT0 changes trigger notifier chain for driver notification. BIT1-2 control whether to perform soft-offline without notifications. Default policy (0x2) performs soft-offline on base pages only. Signed-off-by: Qi Xi <xiqi2@huawei.com> --- drivers/acpi/apei/Makefile | 1 + drivers/acpi/apei/apei-internal.h | 8 +++ drivers/acpi/apei/ghes-policy.c | 102 ++++++++++++++++++++++++++++++ drivers/acpi/apei/ghes.c | 3 + include/linux/acpi.h | 14 ++++ 5 files changed, 128 insertions(+) create mode 100644 drivers/acpi/apei/ghes-policy.c diff --git a/drivers/acpi/apei/Makefile b/drivers/acpi/apei/Makefile index 4dfac2128737..a2f54a554abd 100644 --- a/drivers/acpi/apei/Makefile +++ b/drivers/acpi/apei/Makefile @@ -3,5 +3,6 @@ obj-$(CONFIG_ACPI_APEI) += apei.o obj-$(CONFIG_ACPI_APEI_GHES) += ghes.o obj-$(CONFIG_ACPI_APEI_EINJ) += einj.o obj-$(CONFIG_ACPI_APEI_ERST_DEBUG) += erst-dbg.o +obj-$(CONFIG_ACPI_APEI_MEMORY_FAILURE) += ghes-policy.o apei-y := apei-base.o hest.o erst.o bert.o diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h index 1d6ef9654725..a8fea8aae2a0 100644 --- a/drivers/acpi/apei/apei-internal.h +++ b/drivers/acpi/apei/apei-internal.h @@ -136,4 +136,12 @@ int cper_estatus_check_header(const struct acpi_hest_generic_status *estatus); int cper_estatus_check(const struct acpi_hest_generic_status *estatus); int apei_osc_setup(void); +#ifdef CONFIG_ACPI_APEI_MEMORY_FAILURE +bool apei_page_should_offline(unsigned long pfn); +#else +static inline bool apei_page_should_offline(unsigned long pfn) +{ + return true; +} +#endif #endif diff --git a/drivers/acpi/apei/ghes-policy.c b/drivers/acpi/apei/ghes-policy.c new file mode 100644 index 000000000000..87c611f2cbaa --- /dev/null +++ b/drivers/acpi/apei/ghes-policy.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2026 HUAWEI, Inc. + * https://www.huawei.com/ + */ + +#include <linux/mm.h> +#include <linux/sysctl.h> +#include <linux/notifier.h> + +#define APEI_PAGE_OFFLINE_NOTIFY BIT(0) +#define APEI_PAGE_OFFLINE_ALLOW_BASE_PAGE BIT(1) +#define APEI_PAGE_OFFLINE_ALLOW_HUGETLB BIT(2) + +const int apei_page_offline_policy_max = 7; +int sysctl_apei_page_offline_policy __read_mostly = + APEI_PAGE_OFFLINE_ALLOW_BASE_PAGE; +EXPORT_SYMBOL(sysctl_apei_page_offline_policy); + +static ATOMIC_NOTIFIER_HEAD(apei_page_offline_notifier_chain); + +int register_apei_page_offline_notifier(struct notifier_block *nb) +{ + return atomic_notifier_chain_register( + &apei_page_offline_notifier_chain, nb); +} +EXPORT_SYMBOL(register_apei_page_offline_notifier); + +int unregister_apei_page_offline_notifier(struct notifier_block *nb) +{ + return atomic_notifier_chain_unregister( + &apei_page_offline_notifier_chain, nb); +} +EXPORT_SYMBOL(unregister_apei_page_offline_notifier); + +static int apei_page_offline_policy_handler(struct ctl_table *table, + int write, void __user *buffer, + size_t *lenp, loff_t *ppos) +{ + int old_val, new_val; + int ret; + + old_val = sysctl_apei_page_offline_policy; + ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); + + if (write && ret == 0) { + new_val = sysctl_apei_page_offline_policy; + pr_debug("APEI policy: 0x%x -> 0x%x\n", old_val, new_val); + + if ((old_val ^ new_val) & APEI_PAGE_OFFLINE_NOTIFY) + atomic_notifier_call_chain( + &apei_page_offline_notifier_chain, 0, + &new_val); + } + + return ret; +} + +bool apei_page_should_offline(unsigned long pfn) +{ + struct page *page; + + page = pfn_to_online_page(pfn); + if (!page) + return false; + + if (!(sysctl_apei_page_offline_policy & APEI_PAGE_OFFLINE_ALLOW_BASE_PAGE)) { + if (!PageHuge(page)) { + pr_info_once("disabled for normal pages by /proc/sys/vm/apei_page_offline_policy\n"); + return false; + } + } + + if (!(sysctl_apei_page_offline_policy & APEI_PAGE_OFFLINE_ALLOW_HUGETLB)) { + if (PageHuge(page)) { + pr_info_once("disabled for HugeTLB pages by /proc/sys/vm/apei_page_offline_policy\n"); + return false; + } + } + + return true; +} + +static struct ctl_table apei_table[] = { + { + .procname = "apei_page_offline_policy", + .data = &sysctl_apei_page_offline_policy, + .maxlen = sizeof(sysctl_apei_page_offline_policy), + .mode = 0644, + .proc_handler = apei_page_offline_policy_handler, + .extra1 = SYSCTL_ZERO, + .extra2 = (void *)&apei_page_offline_policy_max, + }, + {} +}; + +static int __init apei_policy_sysctl_init(void) +{ + register_sysctl_init("vm", apei_table); + return 0; +} +late_initcall(apei_policy_sysctl_init); diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 5b585e43a4cc..976c68fc0dd8 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -500,6 +500,9 @@ static bool ghes_do_memory_failure(u64 physical_addr, int flags) return true; } + if (flags == MF_SOFT_OFFLINE && !apei_page_should_offline(pfn)) + return false; + memory_failure_queue(pfn, flags); return true; } diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 4de2b4980f90..7b809dec502b 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1436,4 +1436,18 @@ acpi_pptt_find_cache_backwards(struct acpi_table_header *table_hdr, struct acpi_pptt_cache *cache); acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src); +#ifdef CONFIG_ACPI_APEI_MEMORY_FAILURE +int register_apei_page_offline_notifier(struct notifier_block *nb); +int unregister_apei_page_offline_notifier(struct notifier_block *nb); +#else +static inline int register_apei_page_offline_notifier(struct notifier_block *nb) +{ + return 0; +} + +static inline int unregister_apei_page_offline_notifier(struct notifier_block *nb) +{ + return 0; +} +#endif #endif /*_LINUX_ACPI_H*/ -- 2.33.0
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://atomgit.com/openeuler/kernel/merge_requests/20976 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/NLH... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://atomgit.com/openeuler/kernel/merge_requests/20976 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/NLH...
participants (2)
-
patchwork bot -
Qi Xi