Hi,
This small series disables KSM (Kernel Samepage Merging) in the Morello defconfig, as it is currently unsafe in the presence of tags - see patch 1 for details. To guarantee correctness even if it is manually enabled, patch 2 forces memcmp_pages() to report a difference.
It is quite possible that KSM would still be worthwhile even with the extra cost of comparing tags. Issue #62 [1] covers that investigation.
Review branch:
https://git.morello-project.org/kbrodsky-arm/linux/-/commits/morello/disable...
Cheers, Kevin
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/62
Kevin Brodsky (2): arm64: morello: Disable KSM in defconfig arm64: morello: Make memcmp_pages() always report a difference
.../configs/morello_transitional_pcuabi_defconfig | 1 - arch/arm64/kernel/morello.c | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
KSM (Kernel Samepage Merging) considers that two pages can be merged if their contents are identical. Morello makes it harder to tell whether this is truly the case as tags need to be compared, in addition to data. Tag access is currently enabled for all private mappings, which means that the extra tag comparison would be required in most cases. Given that it is unclear whether KSM would still be worthwhile with such additional overhead, let's disable it for now.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- arch/arm64/configs/morello_transitional_pcuabi_defconfig | 1 - 1 file changed, 1 deletion(-)
diff --git a/arch/arm64/configs/morello_transitional_pcuabi_defconfig b/arch/arm64/configs/morello_transitional_pcuabi_defconfig index 0f692600a181..479371a69515 100644 --- a/arch/arm64/configs/morello_transitional_pcuabi_defconfig +++ b/arch/arm64/configs/morello_transitional_pcuabi_defconfig @@ -56,7 +56,6 @@ CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y # CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set # CONFIG_COMPAT_BRK is not set -CONFIG_KSM=y CONFIG_MEMORY_FAILURE=y CONFIG_TRANSPARENT_HUGEPAGE=y CONFIG_CMA=y
KSM has recently been disabled by default for Morello. To ensure correctness even if it is manually enabled, make sure that memcmp_pages() always reports a difference, instead of comparing the data without taking the tags into account.
Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com --- arch/arm64/kernel/morello.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/arch/arm64/kernel/morello.c b/arch/arm64/kernel/morello.c index d999506509be..e3f732f4c52d 100644 --- a/arch/arm64/kernel/morello.c +++ b/arch/arm64/kernel/morello.c @@ -284,6 +284,20 @@ void morello_flush_cap_regs_to_64_regs(struct task_struct *tsk) tsk->thread.uw.tp_value = (user_uintptr_t)active_ctpidr; }
+int memcmp_pages(struct page *page1, struct page *page2) +{ + /* + * Always report that the pages are different. This should not create + * correctness issues with the ways memcmp_pages() is currently used. + * + * A precise implementation for Morello should compare both data and + * tags, for those pages whose tags are actually accessible (currently + * most of them). It is unclear whether the extra overhead would + * justify a precise approach. + */ + return 1; +} +
static void __init check_root_cap(uintcap_t cap) {
On 01-09-2023 14:07, Kevin Brodsky wrote:
Hi,
This small series disables KSM (Kernel Samepage Merging) in the Morello defconfig, as it is currently unsafe in the presence of tags - see patch 1 for details. To guarantee correctness even if it is manually enabled, patch 2 forces memcmp_pages() to report a difference.
It is quite possible that KSM would still be worthwhile even with the extra cost of comparing tags. Issue #62 [1] covers that investigation.
Review branch:
https://git.morello-project.org/kbrodsky-arm/linux/-/commits/morello/disable...
Cheers, Kevin
It makes sense to me. Looks good.
Tudor
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/62
Kevin Brodsky (2): arm64: morello: Disable KSM in defconfig arm64: morello: Make memcmp_pages() always report a difference
.../configs/morello_transitional_pcuabi_defconfig | 1 - arch/arm64/kernel/morello.c | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
On 01/09/2023 14:07, Kevin Brodsky wrote:
Hi,
This small series disables KSM (Kernel Samepage Merging) in the Morello defconfig, as it is currently unsafe in the presence of tags - see patch 1 for details. To guarantee correctness even if it is manually enabled, patch 2 forces memcmp_pages() to report a difference.
It is quite possible that KSM would still be worthwhile even with the extra cost of comparing tags. Issue #62 [1] covers that investigation.
Review branch:
https://git.morello-project.org/kbrodsky-arm/linux/-/commits/morello/disable...
Cheers, Kevin
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/62
Kevin Brodsky (2): arm64: morello: Disable KSM in defconfig arm64: morello: Make memcmp_pages() always report a difference
+1
.../configs/morello_transitional_pcuabi_defconfig | 1 - arch/arm64/kernel/morello.c | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
linux-morello@op-lists.linaro.org