x86/sgx: Add code to inject hwpoison into SGX memory
PATCH 1/1 x86/sgx: Add code to inject hwpoison into SGX memory
Inspired by commit c6acb1e7bf46 (x86/sgx: Add hook to error injection address validation), add a similar code in hwpoison_inject function to check if the address is located in SGX Memory. The error will then be handled by the arch_memory_failure function in the SGX driver.
--- Documentation/mm/hwpoison.rst | 44 +++++++++++++++++++++++++++++++++++ mm/hwpoison-inject.c | 3 +++ 2 files changed, 47 insertions(+)
Documentation/mm/hwpoison.rst +44 -0
@@ -162,6 +162,50 @@ Testing Some portable hwpoison test programs in mce-test, see below. +* Special notes for injection into SGX enclaves + + 1) Determine physical address of enclave page + + dmesg | grep "sgx: EPC" + + sgx: EPC section 0x8000c00000-0x807f7fffff + sgx: EPC section 0x10000c00000-0x1007fffffff + + 2) Convert the EPC address to page frame number. + + For 4K page size, the page frame number for 0x8000c00000 is + 0x8000c00000 / 0x1000 = 0x8000c00. + + 3) Trace memory_failure + + echo nop > /sys/kernel/tracing/current_tracer + echo *memory_failure > /sys/kernel/tracing/set_ftrace_filter + echo function > /sys/kernel/tracing/current_tracer + + 4) Inject a memory error + + modprobe hwpoison-inject + echo "0x8000c00" > /sys/kernel/debug/hwpoison/corrupt-pfn + + 5) Check the trace output + + cat /sys/kernel/tracing/trace + + # tracer: function + # + # entries-in-buffer/entries-written: 2/2 #P:128 + # + # _-----=> irqs-off + # / _----=> need-resched + # | / _---=> hardirq/softirq + # || / _--=> preempt-depth + # ||| / _-=> migrate-disable + # |||| / delay + # TASK-PID CPU# ||||| TIMESTAMP FUNCTION + # | | | ||||| | | + bash-12167 [002] ..... 113.136808: memory_failure<-simple_attr_write + bash-12167 [002] ..... 113.136810: arch_memory_failure<-memory_failure + References ==========
mm/hwpoison-inject.c +3 -0
@@ -21,6 +21,9 @@ static int hwpoison_inject(void *data, u64 val)if (!capable (CAP_SYS_ADMIN ))return -EPERM ; +if (arch_is_platform_page (pfn <<PAGE_SHIFT )) + goto inject; +if (!pfn_valid (pfn))return -ENXIO ;
Signature · 1 line
2.31.1
Quoted 4 lines
Inspired by commit
c6acb1e7bf46(x86/sgx: Add hook to error injection address validation), add a similar code inhwpoison_injectfunction to check if the address is located in SGX Memory. The error will then be handled by thearch_memory_failurefunction in the SGX driver.
Looks good to me.
[I wish that Linux hadn't called this "hwpoison_inject()" because there's nothing hardware related about this injection. But you are just an innocent consumer of that poor naming choice]
-Tony
Quoted 14 lines
-----Original Message-----
From: Luck, Tony <[email protected]>
Sent: September 27, 2022 4:35 PM
To: Thomas Tai <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Thomas Tai <[email protected]>
Subject: RE: [PATCH] x86/sgx: Add code to inject hwpoison into SGX memoryQuoted 4 lines
Inspired by commit
c6acb1e7bf46(x86/sgx: Add hook to error injection address validation), add a similar code inhwpoison_injectfunction to check if the address is located in SGX Memory. The error will then be handled by thearch_memory_failurefunction in the SGX driver.
Quoted 7 lines
Looks good to me.
[I wish that Linux hadn't called this "
hwpoison_inject()" because there's nothing hardware related about this injection. But you are just an innocent consumer of that poor naming choice]Reviewed-by Tony Luck <[email protected]>
Thanks, Tony, for your review.
Cheers,
Thomas
Quoted 2 lines
-Tony
Quoted 71 lines · Thomas Tai
Inspired by commit
c6acb1e7bf46(x86/sgx: Add hook to error injection address validation), add a similar code inhwpoison_injectfunction to check if the address is located in SGX Memory. The error will then be handled by thearch_memory_failurefunction in the SGX driver.Signed-off-by Thomas Tai <[email protected]>--- Documentation/mm/hwpoison.rst | 44 +++++++++++++++++++++++++++++++++++ mm/hwpoison-inject.c | 3 +++ 2 files changed, 47 insertions(+)Documentation/mm/hwpoison.rst +44
-0@@ -162,6 +162,50 @@ Testing Some portable hwpoison test programs in mce-test, see below. +* Special notes for injection into SGX enclaves + + 1) Determine physical address of enclave page + + dmesg | grep "sgx: EPC" + + sgx: EPC section 0x8000c00000-0x807f7fffff + sgx: EPC section 0x10000c00000-0x1007fffffff + + 2) Convert the EPC address to page frame number. + + For 4K page size, the page frame number for 0x8000c00000 is + 0x8000c00000 / 0x1000 = 0x8000c00. + + 3) Trace memory_failure + + echo nop > /sys/kernel/tracing/current_tracer + echo *memory_failure > /sys/kernel/tracing/set_ftrace_filter + echo function > /sys/kernel/tracing/current_tracer + + 4) Inject a memory error + + modprobe hwpoison-inject + echo "0x8000c00" > /sys/kernel/debug/hwpoison/corrupt-pfn + + 5) Check the trace output + + cat /sys/kernel/tracing/trace + + # tracer: function + # + # entries-in-buffer/entries-written: 2/2 #P:128 + # + # _-----=> irqs-off + # / _----=> need-resched + # | / _---=> hardirq/softirq + # || / _--=> preempt-depth + # ||| / _-=> migrate-disable + # |||| / delay + # TASK-PID CPU# ||||| TIMESTAMP FUNCTION + # | | | ||||| | | + bash-12167 [002] ..... 113.136808: memory_failure<-simple_attr_write + bash-12167 [002] ..... 113.136810: arch_memory_failure<-memory_failure + References ==========mm/hwpoison-inject.c +0
-0
mm/hwpoison-inject.c static int hwpoison_inject(void *data, u64 val) · line 24
Quoted 4 lines
mm/hwpoison-inject.c +1
-0@@ -21,6 +21,9 @@ static int hwpoison_inject(void *data, u64 val)if (!capable (CAP_SYS_ADMIN ))return -EPERM ; +if (arch_is_platform_page (pfn <<PAGE_SHIFT ))
Maybe it's better to add a comment above. Anyway, this patch looks good to me. Thanks.
Thanks,
Miaohe Lin
Quoted 88 lines
-----Original Message-----
From: Miaohe Lin <[email protected]>
Sent: September 28, 2022 4:00 AM
To: Thomas Tai <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; akpm@linux- foundation.org; [email protected]; [email protected]
Subject: Re: [PATCH] x86/sgx: Add code to inject hwpoison into SGX memoryQuoted 8 lines · Thomas Tai
Inspired by commit
c6acb1e7bf46(x86/sgx: Add hook to error injection address validation), add a similar code inhwpoison_injectfunction to check if the address is located in SGX Memory. The error will then be handled by thearch_memory_failurefunction in the SGX driver.Signed-off-by Thomas Tai <[email protected]>--- Documentation/mm/hwpoison.rst | 44+++++++++++++++++++++++++++++++++++
Review
Quoted 4 lines
mm/hwpoison-inject.c | 3 +++ 2 files changed, 47 insertions(+)(quoted diff) +0
-0
b/Documentation/mm/hwpoison.rstQuoted 39 lines
index
b9d5253c1305..8a542aca4744100644Documentation/mm/hwpoison.rst +32
-0@@ -162,6 +162,50 @@ Testing Some portable hwpoison test programs in mce-test, see below. +* Special notes for injection into SGX enclaves + + 1) Determine physical address of enclave page + + dmesg | grep "sgx: EPC" + + sgx: EPC section 0x8000c00000-0x807f7fffff + sgx: EPC section 0x10000c00000-0x1007fffffff + + 2) Convert the EPC address to page frame number. + + For 4K page size, the page frame number for 0x8000c00000 is + 0x8000c00000 / 0x1000 = 0x8000c00. + + 3) Trace memory_failure + + echo nop > /sys/kernel/tracing/current_tracer + echo *memory_failure > /sys/kernel/tracing/set_ftrace_filter + echo function > /sys/kernel/tracing/current_tracer + + 4) Inject a memory error + + modprobe hwpoison-inject + echo "0x8000c00" > /sys/kernel/debug/hwpoison/corrupt-pfn + + 5) Check the trace output + + cat /sys/kernel/tracing/trace + + # tracer: function + # + # entries-in-buffer/entries-written: 2/2 #P:128Documentation/mm/hwpoison.rst Testing · line 206
Quoted 10 lines
Documentation/mm/hwpoison.rst +10
-0+ # + # _-----=> irqs-off + # / _----=> need-resched + # | / _---=> hardirq/softirq + # || / _--=> preempt-depth + # ||| / _-=> migrate-disable + # |||| / delay + # TASK-PID CPU# ||||| TIMESTAMP FUNCTION + # | | | ||||| | | + bash-12167 [002] ..... 113.136808: memory_failure<-
simple_attr_writeDocumentation/mm/hwpoison.rst Testing · line 207
Quoted 1 line
Documentation/mm/hwpoison.rst +1
-0+ bash-12167 [002] ..... 113.136810: arch_memory_failure<-
memory_failureQuoted 12 lines
Documentation/mm/hwpoison.rst +1
-0+ References ==========mm/hwpoison-inject.c +0
-0@@ -21,6 +21,9 @@ static int hwpoison_inject(void *data, u64 val)if (!capable (CAP_SYS_ADMIN ))return -EPERM ;
Quoted 4 lines
mm/hwpoison-inject.c static int hwpoison_inject(void *data, u64 val) · line 24
Quoted 1 line
mm/hwpoison-inject.c +1
-0+if (arch_is_platform_page (pfn <<PAGE_SHIFT ))Maybe it's better to add a comment above. Anyway, this patch looks good to me. Thanks.
Thanks, Miaohe, for your suggestion. I will add a comment and resend the patch.
Thanks,
Thomas
Quoted 6 lines
Reviewed-by Miaohe Lin <[email protected]>Thanks,
Miaohe Lin
Quoted 83 lines · Thomas Tai
Inspired by commit
c6acb1e7bf46(x86/sgx: Add hook to error injection address validation), add a similar code inhwpoison_injectfunction to check if the address is located in SGX Memory. The error will then be handled by thearch_memory_failurefunction in the SGX driver.Signed-off-by Thomas Tai <[email protected]>--- Documentation/mm/hwpoison.rst | 44 +++++++++++++++++++++++++++++++++++ mm/hwpoison-inject.c | 3 +++ 2 files changed, 47 insertions(+)Documentation/mm/hwpoison.rst +44
-0@@ -162,6 +162,50 @@ Testing Some portable hwpoison test programs in mce-test, see below. +* Special notes for injection into SGX enclaves + + 1) Determine physical address of enclave page + + dmesg | grep "sgx: EPC" + + sgx: EPC section 0x8000c00000-0x807f7fffff + sgx: EPC section 0x10000c00000-0x1007fffffff + + 2) Convert the EPC address to page frame number. + + For 4K page size, the page frame number for 0x8000c00000 is + 0x8000c00000 / 0x1000 = 0x8000c00. + + 3) Trace memory_failure + + echo nop > /sys/kernel/tracing/current_tracer + echo *memory_failure > /sys/kernel/tracing/set_ftrace_filter + echo function > /sys/kernel/tracing/current_tracer + + 4) Inject a memory error + + modprobe hwpoison-inject + echo "0x8000c00" > /sys/kernel/debug/hwpoison/corrupt-pfn + + 5) Check the trace output + + cat /sys/kernel/tracing/trace + + # tracer: function + # + # entries-in-buffer/entries-written: 2/2 #P:128 + # + # _-----=> irqs-off + # / _----=> need-resched + # | / _---=> hardirq/softirq + # || / _--=> preempt-depth + # ||| / _-=> migrate-disable + # |||| / delay + # TASK-PID CPU# ||||| TIMESTAMP FUNCTION + # | | | ||||| | | + bash-12167 [002] ..... 113.136808: memory_failure<-simple_attr_write + bash-12167 [002] ..... 113.136810: arch_memory_failure<-memory_failure + References ==========mm/hwpoison-inject.c +3
-0@@ -21,6 +21,9 @@ static int hwpoison_inject(void *data, u64 val)if (!capable (CAP_SYS_ADMIN ))return -EPERM ; +if (arch_is_platform_page (pfn <<PAGE_SHIFT )) + goto inject; +if (!pfn_valid (pfn))return -ENXIO ;Signature · 1 line
2.31.1
Hey, this is really useful addition. Thanks for doing this.
BR, Jarkko
Quoted 96 lines
-----Original Message-----
From: Jarkko Sakkinen <[email protected]>
Sent: September 30, 2022 5:44 PM
To: Thomas Tai <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH] x86/sgx: Add code to inject hwpoison into SGX memoryQuoted 8 lines · Thomas Tai
Inspired by commit
c6acb1e7bf46(x86/sgx: Add hook to error injection address validation), add a similar code inhwpoison_injectfunction to check if the address is located in SGX Memory. The error will then be handled by thearch_memory_failurefunction in the SGX driver.Signed-off-by Thomas Tai <[email protected]>--- Documentation/mm/hwpoison.rst | 44+++++++++++++++++++++++++++++++++++
Review
Quoted 4 lines
mm/hwpoison-inject.c | 3 +++ 2 files changed, 47 insertions(+)(quoted diff) +0
-0
b/Documentation/mm/hwpoison.rstQuoted 39 lines
index
b9d5253c1305..8a542aca4744100644Documentation/mm/hwpoison.rst +32
-0@@ -162,6 +162,50 @@ Testing Some portable hwpoison test programs in mce-test, see below. +* Special notes for injection into SGX enclaves + + 1) Determine physical address of enclave page + + dmesg | grep "sgx: EPC" + + sgx: EPC section 0x8000c00000-0x807f7fffff + sgx: EPC section 0x10000c00000-0x1007fffffff + + 2) Convert the EPC address to page frame number. + + For 4K page size, the page frame number for 0x8000c00000 is + 0x8000c00000 / 0x1000 = 0x8000c00. + + 3) Trace memory_failure + + echo nop > /sys/kernel/tracing/current_tracer + echo *memory_failure > /sys/kernel/tracing/set_ftrace_filter + echo function > /sys/kernel/tracing/current_tracer + + 4) Inject a memory error + + modprobe hwpoison-inject + echo "0x8000c00" > /sys/kernel/debug/hwpoison/corrupt-pfn + + 5) Check the trace output + + cat /sys/kernel/tracing/trace + + # tracer: function + # + # entries-in-buffer/entries-written: 2/2 #P:128Documentation/mm/hwpoison.rst Testing · line 206
Quoted 10 lines
Documentation/mm/hwpoison.rst +10
-0+ # + # _-----=> irqs-off + # / _----=> need-resched + # | / _---=> hardirq/softirq + # || / _--=> preempt-depth + # ||| / _-=> migrate-disable + # |||| / delay + # TASK-PID CPU# ||||| TIMESTAMP FUNCTION + # | | | ||||| | | + bash-12167 [002] ..... 113.136808: memory_failure<-
simple_attr_writeDocumentation/mm/hwpoison.rst Testing · line 207
Quoted 1 line
Documentation/mm/hwpoison.rst +1
-0+ bash-12167 [002] ..... 113.136810: arch_memory_failure<-
memory_failureQuoted 18 lines
Documentation/mm/hwpoison.rst +1
-0+ References ==========mm/hwpoison-inject.c +3
-0@@ -21,6 +21,9 @@ static int hwpoison_inject(void *data, u64 val)if (!capable (CAP_SYS_ADMIN ))return -EPERM ; +if (arch_is_platform_page (pfn <<PAGE_SHIFT )) + goto inject; +if (!pfn_valid (pfn))return -ENXIO ;
Quoted 7 lines
Quoted 3 lines
--
2.31.1Hey, this is really useful addition. Thanks for doing this.
Reviewed-by Jarkko Sakkinen <[email protected]>
Thanks, Jarkko, for your review.
Thomas
Quoted 2 lines
BR, Jarkko