Basic recovery for machine checks inside SGX
Subsystems (9)
Tony Luck
reviewerPATCH v11 6/7 x86/sgx: Add hook to error injection address validation
In reply to Tony LuckSGX reserved memory does not appear in the standard address maps.
Add hook to call into the SGX code to check if an address is located in SGX memory.
There are other challenges in injecting errors into SGX. Update the documentation with a sequence of operations to inject.
--- .../firmware-guide/acpi/apei/einj.rst | 19 +++++++++++++++++++ drivers/acpi/apei/einj.c | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-)
Documentation/firmware-guide/acpi/apei/einj.rst +19 -0
@@ -181,5 +181,24 @@ You should see something like this in dmesg:: [22715.834759] EDAC sbridge MC3: PROCESSOR 0:306e7 TIME 1422553404 SOCKET 0 APIC 0 [22716.616173] EDAC MC3: 1 CE memory read error on CPU_SrcID#0_Channel#0_DIMM#0 (channel:0 slot:0 page:0x12345 offset:0x0 grain:32 syndrome:0x0 - area:DRAM err_code:0001:0090 socket:0 channel_mask:1 rank:0) +Special notes for injection into SGX enclaves: + +There may be a separate BIOS setup option to enable SGX injection. + +The injection process consists of setting some special memory controller +trigger that will inject the error on the next write to the target +address. But the h/w prevents any software outside of an SGX enclave +from accessing enclave pages (even BIOS SMM mode). + +The following sequence can be used: + 1) Determine physical address of enclave page + 2) Use "notrigger=1" mode to inject (this will setup + the injection address, but will not actually inject) + 3) Enter the enclave + 4) Store data to the virtual address matching physical address from step 1 + 5) Execute CLFLUSH for that virtual address + 6) Spin delay for 250ms + 7) Read from the virtual address. This will trigger the error + For more information about EINJ, please refer to ACPI specification version 4.0, section 17.5 and ACPI 5.0, section 18.6.
drivers/acpi/apei/einj.c +2 -1
@@ -544,7 +544,8 @@ static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, ((region_intersects (base_addr, size,IORESOURCE_SYSTEM_RAM ,IORES_DESC_NONE ) !=REGION_INTERSECTS ) && (region_intersects (base_addr, size,IORESOURCE_MEM ,IORES_DESC_PERSISTENT_MEMORY ) - != REGION_INTERSECTS))) + !=REGION_INTERSECTS ) && + !arch_is_platform_page(base_addr))) return -EINVAL; inject:
Signature · 1 line
2.31.1
[tip: x86/sgx] x86/sgx: Add hook to error injection address validation
The following commit has been merged into the x86/sgx branch of tip:
The following commit has been merged into the x86/sgx branch of tip:
Commit-ID: c6acb1e7bf4656b9434335c72b8245cc84575fde Gitweb: https://git.kernel.org/tip/c6acb1e7bf4656b9434335c72b8245cc84575fde Author: Tony Luck <[email protected]> AuthorDate: Tue, 26 Oct 2021 15:00:49 -07:00 Committer: Dave Hansen <[email protected]> CommitterDate: Mon, 15 Nov 2021 11:13:16 -08:00
x86/sgx: Add hook to error injection address validation
SGX reserved memory does not appear in the standard address maps.
Add hook to call into the SGX code to check if an address is located in SGX memory.
There are other challenges in injecting errors into SGX. Update the documentation with a sequence of operations to inject.
--- Documentation/firmware-guide/acpi/apei/einj.rst | 19 ++++++++++++++++- drivers/acpi/apei/einj.c | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-)
Documentation/firmware-guide/acpi/apei/einj.rst +19 -0
@@ -181,5 +181,24 @@ You should see something like this in dmesg:: [22715.834759] EDAC sbridge MC3: PROCESSOR 0:306e7 TIME 1422553404 SOCKET 0 APIC 0 [22716.616173] EDAC MC3: 1 CE memory read error on CPU_SrcID#0_Channel#0_DIMM#0 (channel:0 slot:0 page:0x12345 offset:0x0 grain:32 syndrome:0x0 - area:DRAM err_code:0001:0090 socket:0 channel_mask:1 rank:0) +Special notes for injection into SGX enclaves: + +There may be a separate BIOS setup option to enable SGX injection. + +The injection process consists of setting some special memory controller +trigger that will inject the error on the next write to the target +address. But the h/w prevents any software outside of an SGX enclave +from accessing enclave pages (even BIOS SMM mode). + +The following sequence can be used: + 1) Determine physical address of enclave page + 2) Use "notrigger=1" mode to inject (this will setup + the injection address, but will not actually inject) + 3) Enter the enclave + 4) Store data to the virtual address matching physical address from step 1 + 5) Execute CLFLUSH for that virtual address + 6) Spin delay for 250ms + 7) Read from the virtual address. This will trigger the error + For more information about EINJ, please refer to ACPI specification version 4.0, section 17.5 and ACPI 5.0, section 18.6.
drivers/acpi/apei/einj.c +2 -1
@@ -545,7 +545,8 @@ static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, ((region_intersects (base_addr, size,IORESOURCE_SYSTEM_RAM ,IORES_DESC_NONE ) !=REGION_INTERSECTS ) && (region_intersects (base_addr, size,IORESOURCE_MEM ,IORES_DESC_PERSISTENT_MEMORY ) - != REGION_INTERSECTS))) + !=REGION_INTERSECTS ) && + !arch_is_platform_page(base_addr))) return -EINVAL; inject:
Tony Luck
reviewerPATCH v11 7/7 x86/sgx: Add check for SGX pages to ghes_do_memory_failure()
In reply to Tony LuckSGX EPC pages do not have a "struct page" associated with them so the pfn_valid() sanity check fails and results in a warning message to the console.
Add an additional check to skip the warning if the address of the error is in an SGX EPC page.
--- drivers/acpi/apei/ghes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/ghes.c +1 -1
@@ -449,7 +449,7 @@ static bool ghes_do_memory_failure(u64 physical_addr, int flags)return false; pfn =PHYS_PFN (physical_addr); -if (!pfn_valid (pfn)) { +if (!pfn_valid (pfn) && !arch_is_platform_page (physical_addr)) { pr_warn_ratelimited(FW_WARN GHES_PFX"Invalid address in generic error data: %#llx\n" , physical_addr);
Signature · 1 line
2.31.1
Re: [PATCH v11 7/7] x86/sgx: Add check for SGX pages to ghes_do_memory_failure()
Quoted 11 lines · Tony Luck
SGX EPC pages do not have a "struct page" associated with them so the
pfn_valid()sanity check fails and results in a warning message to the console.Add an additional check to skip the warning if the address of the error is in an SGX EPC page.
Reviewed-by Jarkko Sakkinen <[email protected]>Tested-by Reinette Chatre <[email protected]>Signed-off-by Tony Luck <[email protected]>
Quoted 20 lines
--- drivers/acpi/apei/ghes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/acpi/apei/ghes.c +1
-2@@ -449,7 +449,7 @@ static bool ghes_do_memory_failure(u64 physical_addr, int flags)return false; pfn =PHYS_PFN (physical_addr); -if (!pfn_valid (pfn)) { +if (!pfn_valid (pfn) && !arch_is_platform_page (physical_addr)) { pr_warn_ratelimited(FW_WARN GHES_PFX"Invalid address in generic error data: %#llx\n" , physical_addr); --2.31.1
[tip: x86/sgx] x86/sgx: Add check for SGX pages to ghes_do_memory_failure()
In reply to Tony LuckThe following commit has been merged into the x86/sgx branch of tip:
The following commit has been merged into the x86/sgx branch of tip:
Commit-ID: 3ad6fd77a2d62e8f4465b429b65805eaf88e1b9e Gitweb: https://git.kernel.org/tip/3ad6fd77a2d62e8f4465b429b65805eaf88e1b9e Author: Tony Luck <[email protected]> AuthorDate: Tue, 26 Oct 2021 15:00:50 -07:00 Committer: Dave Hansen <[email protected]> CommitterDate: Mon, 15 Nov 2021 11:13:16 -08:00
x86/sgx: Add check for SGX pages to ghes_do_memory_failure()
SGX EPC pages do not have a "struct page" associated with them so the pfn_valid() sanity check fails and results in a warning message to the console.
Add an additional check to skip the warning if the address of the error is in an SGX EPC page.
--- drivers/acpi/apei/ghes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/ghes.c +1 -1
@@ -449,7 +449,7 @@ static bool ghes_do_memory_failure(u64 physical_addr, int flags)return false; pfn =PHYS_PFN (physical_addr); -if (!pfn_valid (pfn)) { +if (!pfn_valid (pfn) && !arch_is_platform_page (physical_addr)) { pr_warn_ratelimited(FW_WARN GHES_PFX"Invalid address in generic error data: %#llx\n" , physical_addr);