From: Kefeng Wang <hidden> Date: 2021-08-25 09:17:26
The patch 1~3 is to support KFENCE feature on ARM.
NOTE:
The context of patch2/3 changes in arch/arm/mm/fault.c is based on link[1],
which make some refactor and cleanup about page fault.
kfence_test is not useful when kfence is not enabled, skip kfence test
when kfence not enabled in patch4.
I tested the kfence_test on ARM QEMU with or without ARM_LPAE and all passed.
[1] https://lore.kernel.org/linux-arm-kernel/20210610123556.171328-1-wangkefeng.wang@huawei.com/
Kefeng Wang (4):
ARM: mm: Provide set_memory_valid()
ARM: mm: Provide is_write_fault()
ARM: Support KFENCE for ARM
mm: kfence: Only load kfence_test when kfence is enabled
arch/arm/Kconfig | 1 +
arch/arm/include/asm/kfence.h | 52 +++++++++++++++++++++++++++++++
arch/arm/include/asm/set_memory.h | 5 +++
arch/arm/mm/fault.c | 16 ++++++++--
arch/arm/mm/pageattr.c | 41 ++++++++++++++++++------
include/linux/kfence.h | 2 ++
mm/kfence/core.c | 8 +++++
mm/kfence/kfence_test.c | 2 ++
8 files changed, 114 insertions(+), 13 deletions(-)
create mode 100644 arch/arm/include/asm/kfence.h
--
2.26.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Kefeng Wang <hidden> Date: 2021-08-25 09:17:28
The function will check whether the fault is caused by a write access.
Signed-off-by: Kefeng Wang <redacted>
---
arch/arm/mm/fault.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
From: Alexander Potapenko <glider@google.com> Date: 2021-08-25 09:32:02
On Wed, Aug 25, 2021 at 11:17 AM Kefeng Wang [off-list ref] wrote:
Provide kfence_is_enabled() helper, only load kfence_test module
when kfence is enabled.
What's wrong with the current behavior?
I think we need at least some way to tell the developer that KFENCE
does not work, and a failing test seems to be the perfect one.
--
Alexander Potapenko
Software Engineer
Google Germany GmbH
Erika-Mann-Straße, 33
80636 München
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marco Elver <elver@google.com> Date: 2021-08-25 09:54:27
On Wed, 25 Aug 2021 at 11:31, Alexander Potapenko [off-list ref] wrote:
On Wed, Aug 25, 2021 at 11:17 AM Kefeng Wang [off-list ref] wrote:
quoted
Provide kfence_is_enabled() helper, only load kfence_test module
when kfence is enabled.
What's wrong with the current behavior?
I think we need at least some way to tell the developer that KFENCE
does not work, and a failing test seems to be the perfect one.
Like Alex said, this is working as intended. The KFENCE test verifies
that everything is working as expected, *including* that KFENCE was
enabled, and has already helped us identify issues where we expected
it to be enabled! Trying to run the test when KFENCE was intentionally
disabled is therefore not a useful usecase.
Please drop this patch.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Kefeng Wang <hidden> Date: 2021-08-25 09:55:14
On 2021/8/25 17:31, Alexander Potapenko wrote:
On Wed, Aug 25, 2021 at 11:17 AM Kefeng Wang [off-list ref] wrote:
quoted
Provide kfence_is_enabled() helper, only load kfence_test module
when kfence is enabled.
What's wrong with the current behavior?
I think we need at least some way to tell the developer that KFENCE
does not work, and a failing test seems to be the perfect one.
If the kfence is not enabled, eg kfence.sample_interval=0, kfence_test
spend too much time,
and all tests will fails. It is meaningless. so better to just skip it ;)
+ return 0;
/*
* Because we want to be able to build the test as a module, we need to
* iterate through all known tracepoints, since the static registration
--
2.26.2
--
You received this message because you are subscribed to the Google Groups "kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20210825092116.149975-5-wangkefeng.wang%40huawei.com.
From: Marco Elver <elver@google.com> Date: 2021-08-25 09:59:21
On Wed, 25 Aug 2021 at 11:55, Kefeng Wang [off-list ref] wrote:
On 2021/8/25 17:31, Alexander Potapenko wrote:
quoted
On Wed, Aug 25, 2021 at 11:17 AM Kefeng Wang [off-list ref] wrote:
quoted
Provide kfence_is_enabled() helper, only load kfence_test module
when kfence is enabled.
What's wrong with the current behavior?
I think we need at least some way to tell the developer that KFENCE
does not work, and a failing test seems to be the perfect one.
If the kfence is not enabled, eg kfence.sample_interval=0, kfence_test
spend too much time,
and all tests will fails. It is meaningless. so better to just skip it ;)
But what is your usecase?
I'd like to avoid the export of a new function that is pretty much unused.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Kefeng Wang <hidden> Date: 2021-08-25 09:17:36
Add architecture specific implementation details for KFENCE and enable
KFENCE on ARM. In particular, this implements the required interface in
<asm/kfence.h>.
KFENCE requires that attributes for pages from its memory pool can
individually be set. Therefore, force the kfence pool to be mapped
at page granularity.
Testing this patch using the testcases in kfence_test.c and all passed
with or without ARM_LPAE.
Signed-off-by: Kefeng Wang <redacted>
---
arch/arm/Kconfig | 1 +
arch/arm/include/asm/kfence.h | 52 +++++++++++++++++++++++++++++++++++
arch/arm/mm/fault.c | 9 ++++--
3 files changed, 60 insertions(+), 2 deletions(-)
create mode 100644 arch/arm/include/asm/kfence.h
Add architecture specific implementation details for KFENCE and enable
KFENCE on ARM. In particular, this implements the required interface in
<asm/kfence.h>.
KFENCE requires that attributes for pages from its memory pool can
individually be set. Therefore, force the kfence pool to be mapped
at page granularity.
Testing this patch using the testcases in kfence_test.c and all passed
with or without ARM_LPAE.
Signed-off-by: Kefeng Wang <redacted>
---
arch/arm/Kconfig | 1 +
arch/arm/include/asm/kfence.h | 52 +++++++++++++++++++++++++++++++++++
arch/arm/mm/fault.c | 9 ++++--
3 files changed, 60 insertions(+), 2 deletions(-)
create mode 100644 arch/arm/include/asm/kfence.h
From: Kefeng Wang <hidden> Date: 2021-08-25 14:31:50
On 2021/8/25 21:18, ownia wrote:
On 2021/8/25 17:21, Kefeng Wang wrote:
quoted
Add architecture specific implementation details for KFENCE and enable
KFENCE on ARM. In particular, this implements the required interface in
<asm/kfence.h>.
KFENCE requires that attributes for pages from its memory pool can
individually be set. Therefore, force the kfence pool to be mapped
at page granularity.
Testing this patch using the testcases in kfence_test.c and all passed
with or without ARM_LPAE.
Signed-off-by: Kefeng Wang <redacted>
@@ -11,11 +11,16 @@ int set_memory_ro(unsigned long addr, int numpages);intset_memory_rw(unsignedlongaddr,intnumpages);intset_memory_x(unsignedlongaddr,intnumpages);intset_memory_nx(unsignedlongaddr,intnumpages);+intset_memory_valid(unsignedlongaddr,intnumpages,intenable);#elsestaticinlineintset_memory_ro(unsignedlongaddr,intnumpages){return0;}staticinlineintset_memory_rw(unsignedlongaddr,intnumpages){return0;}staticinlineintset_memory_x(unsignedlongaddr,intnumpages){return0;}staticinlineintset_memory_nx(unsignedlongaddr,intnumpages){return0;}+staticinlineintset_memory_valid(unsignedlongaddr,intnumpages,intenable)+{+return0;+}#endif#endif
@@ -31,6 +31,24 @@ static bool in_range(unsigned long start, unsigned long size,returnstart>=range_start&&start<range_end&&size<=range_end-start;}+/*+*ThisfunctionassumesthattherangeismappedwithPAGE_SIZEpages.+*/+staticint__change_memory_common(unsignedlongstart,unsignedlongsize,+pgprot_tset_mask,pgprot_tclear_mask)+{+structpage_change_datadata;+intret;++data.set_mask=set_mask;+data.clear_mask=clear_mask;++ret=apply_to_page_range(&init_mm,start,size,change_page_range,+&data);++flush_tlb_kernel_range(start,start+size);+returnret;+}staticintchange_memory_common(unsignedlongaddr,intnumpages,pgprot_tset_mask,pgprot_tclear_mask)
@@ -38,8 +56,6 @@ static int change_memory_common(unsigned long addr, int numpages,unsignedlongstart=addr&PAGE_MASK;unsignedlongend=PAGE_ALIGN(addr)+numpages*PAGE_SIZE;unsignedlongsize=end-start;-intret;-structpage_change_datadata;WARN_ON_ONCE(start!=addr);
@@ -50,14 +66,7 @@ static int change_memory_common(unsigned long addr, int numpages,!in_range(start,size,VMALLOC_START,VMALLOC_END))return-EINVAL;-data.set_mask=set_mask;-data.clear_mask=clear_mask;--ret=apply_to_page_range(&init_mm,start,size,change_page_range,-&data);--flush_tlb_kernel_range(start,end);-returnret;+return__change_memory_common(start,size,set_mask,clear_mask);}intset_memory_ro(unsignedlongaddr,intnumpages)
@@ -87,3 +96,15 @@ int set_memory_x(unsigned long addr, int numpages)__pgprot(0),__pgprot(L_PTE_XN));}++intset_memory_valid(unsignedlongaddr,intnumpages,intenable)+{+if(enable)+return__change_memory_common(addr,PAGE_SIZE*numpages,+__pgprot(L_PTE_VALID),+__pgprot(0));+else+return__change_memory_common(addr,PAGE_SIZE*numpages,+__pgprot(0),+__pgprot(L_PTE_VALID));+}
--
2.26.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marco Elver <elver@google.com> Date: 2021-08-25 10:14:54
On Wed, 25 Aug 2021 at 11:17, Kefeng Wang [off-list ref] wrote:
The patch 1~3 is to support KFENCE feature on ARM.
NOTE:
The context of patch2/3 changes in arch/arm/mm/fault.c is based on link[1],
which make some refactor and cleanup about page fault.
kfence_test is not useful when kfence is not enabled, skip kfence test
when kfence not enabled in patch4.
I tested the kfence_test on ARM QEMU with or without ARM_LPAE and all passed.
Thank you for enabling KFENCE on ARM -- I'll leave arch-code review to
an ARM maintainer.
However, as said on the patch, please drop the change to the
kfence_test and associated changes. This is working as intended; while
you claim that it takes a long time to run when disabled, when running
manually you just should not run it when disabled. There are CI
systems that rely on the KUnit test output and the fact that the
various test cases say "not ok" etc. Changing that would mean such CI
systems would no longer fail if KFENCE was accidentally disabled (once
KFENCE is enabled on various CI, which we'd like to do at some point).
There are ways to fail the test faster, but they all complicate the
test for no good reason. (And the addition of a new exported function
that is essentially useless.)
Thanks,
-- Marco
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marco Elver <elver@google.com> Date: 2021-08-25 10:57:37
On Wed, Aug 25, 2021 at 12:14PM +0200, Marco Elver wrote:
On Wed, 25 Aug 2021 at 11:17, Kefeng Wang [off-list ref] wrote:
quoted
The patch 1~3 is to support KFENCE feature on ARM.
NOTE:
The context of patch2/3 changes in arch/arm/mm/fault.c is based on link[1],
which make some refactor and cleanup about page fault.
kfence_test is not useful when kfence is not enabled, skip kfence test
when kfence not enabled in patch4.
I tested the kfence_test on ARM QEMU with or without ARM_LPAE and all passed.
Thank you for enabling KFENCE on ARM -- I'll leave arch-code review to
an ARM maintainer.
However, as said on the patch, please drop the change to the
kfence_test and associated changes. This is working as intended; while
you claim that it takes a long time to run when disabled, when running
manually you just should not run it when disabled. There are CI
systems that rely on the KUnit test output and the fact that the
various test cases say "not ok" etc. Changing that would mean such CI
systems would no longer fail if KFENCE was accidentally disabled (once
KFENCE is enabled on various CI, which we'd like to do at some point).
There are ways to fail the test faster, but they all complicate the
test for no good reason. (And the addition of a new exported function
that is essentially useless.)
From: Kefeng Wang <hidden> Date: 2021-08-25 14:15:46
On 2021/8/25 18:57, Marco Elver wrote:
On Wed, Aug 25, 2021 at 12:14PM +0200, Marco Elver wrote:
quoted
On Wed, 25 Aug 2021 at 11:17, Kefeng Wang [off-list ref] wrote:
quoted
The patch 1~3 is to support KFENCE feature on ARM.
NOTE:
The context of patch2/3 changes in arch/arm/mm/fault.c is based on link[1],
which make some refactor and cleanup about page fault.
kfence_test is not useful when kfence is not enabled, skip kfence test
when kfence not enabled in patch4.
I tested the kfence_test on ARM QEMU with or without ARM_LPAE and all passed.
Thank you for enabling KFENCE on ARM -- I'll leave arch-code review to
an ARM maintainer.
However, as said on the patch, please drop the change to the
kfence_test and associated changes. This is working as intended; while
you claim that it takes a long time to run when disabled, when running
manually you just should not run it when disabled. There are CI
systems that rely on the KUnit test output and the fact that the
various test cases say "not ok" etc. Changing that would mean such CI
systems would no longer fail if KFENCE was accidentally disabled (once
KFENCE is enabled on various CI, which we'd like to do at some point).
There are ways to fail the test faster, but they all complicate the
test for no good reason. (And the addition of a new exported function
that is essentially useless.)
I haven't received the mail, don't know why.
Whatever, I tested it, this patch is good and it save a lot of times,
so feel free
to add my tested-by, thanks.
will do the trick. So please drop your patch 4/4 here.
Thanks,
-- Marco
.