Testing 5.17 bugfix material
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or so, mostly around RAS and fixing the backing storage issues. Could folks please give this branch a good thrashing?
I'm planning to send this bunch up to Linus after 5.17-rc1 comes out.
Kristen, I really dug into the changelogs of your two patches to make it more clear that they are bugfix and stable@ material. I'd appreciate some additional eyeballs there.
Hi Dave,
Quoted 6 lines · Dave Hansen
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or so, mostly around RAS and fixing the backing storage issues. Could folks please give this branch a good thrashing?
Quoted 7 lines
I'm planning to send this bunch up to Linus after 5.17-rc1 comes out.
Kristen, I really dug into the changelogs of your two patches to make it more clear that they are bugfix and stable@ material. I'd appreciate some additional eyeballs there.
When testing this with a large enclave loaded by Intel runtime, we saw it hang on EADD ioctl and the ioctl never returns.
Also noticed the selftest fails on oversub but the return errno is EINTR not ENOMEM as expected.
When user space register signal handler with SA_RESTART flag, EINTR would be an auto restart of ioctl. So that might be what's going on with Intel runtime test. And I suspect following code may cause infinite restart of the ioctl:
struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim)
{
struct sgx_epc_page *page;
for ( ; ; ) {
page = __sgx_alloc_epc_page();
if (!IS_ERR(page)) {
page->owner = owner;
break;
}
if (list_empty(&sgx_active_page_list))<-- should also check
sgx_nr_available_backing_pages?
return ERR_PTR(-ENOMEM);
if (!reclaim) {
page = ERR_PTR(-EBUSY);
break;
}
if (signal_pending(current)) {
page = ERR_PTR(-ERESTARTSYS);<---- this is the only exit of
the for loop when backing store limit reaches.
break;
}
sgx_reclaim_pages(); <---- no checking for backing store fail due
to limit here.
cond_resched();
}Thanks
Haitao
Jarkko Sakkinen
maintainerQuoted 62 lines · Haitao Huang
Hi Dave,
Quoted 6 lines · Dave Hansen
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or so, mostly around RAS and fixing the backing storage issues. Could folks please give this branch a good thrashing?
Quoted 7 lines
I'm planning to send this bunch up to Linus after 5.17-rc1 comes out.
Kristen, I really dug into the changelogs of your two patches to make it more clear that they are bugfix and stable@ material. I'd appreciate some additional eyeballs there.
When testing this with a large enclave loaded by Intel runtime, we saw it hang
on EADD ioctl and the ioctl never returns.Also noticed the selftest fails on oversub but the return errno is EINTR not ENOMEM as expected.
When user space register signal handler with
SA_RESTARTflag, EINTR would be an auto restart of ioctl. So that might be what's going on with Intel runtime test. And I suspect following code may cause infinite restart of the ioctl:struct
sgx_epc_page*sgx_alloc_epc_page(void *owner, bool reclaim){ struct sgx_epc_page *page; for ( ; ; ) { page = __sgx_alloc_epc_page(); if (!IS_ERR(page)) { page->owner = owner; break; } if (list_empty(&sgx_active_page_list))<-- should also check sgx_nr_available_backing_pages? return ERR_PTR(-ENOMEM); if (!reclaim) { page = ERR_PTR(-EBUSY); break; } if (signal_pending(current)) { page = ERR_PTR(-ERESTARTSYS);<---- this is the only exit of the for loop when backing store limit reaches. break; } sgx_reclaim_pages(); <---- no checking for backing store fail due to limit here. cond_resched(); }
Quoted 2 lines
Thanks
Haitao
Haitao, this does not match what I see in tip/x86/sgx:
struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim)
{
struct sgx_epc_page *page;
for ( ; ; ) {
page = __sgx_alloc_epc_page();
if (!IS_ERR(page)) {
page->owner = owner;
break;
}
if (list_empty(&sgx_active_page_list))
return ERR_PTR(-ENOMEM);
if (!reclaim) {
page = ERR_PTR(-EBUSY);
break;
}
if (signal_pending(current)) {
page = ERR_PTR(-ERESTARTSYS);
break;
}
sgx_reclaim_pages();
cond_resched();
}
if (sgx_should_reclaim(SGX_NR_LOW_PAGES))
wake_up(&ksgxd_waitq);
return page;
}Just in case I also checked tip/master, and the result is the same.
/Jarkko
Jarkko Sakkinen
maintainerQuoted 43 lines · Jarkko Sakkinen
Quoted 42 lines · Haitao Huang
Hi Dave,
Quoted 6 lines · Dave Hansen
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or so, mostly around RAS and fixing the backing storage issues. Could folks please give this branch a good thrashing?
Quoted 7 lines
I'm planning to send this bunch up to Linus after 5.17-rc1 comes out.
Kristen, I really dug into the changelogs of your two patches to make it more clear that they are bugfix and stable@ material. I'd appreciate some additional eyeballs there.
When testing this with a large enclave loaded by Intel runtime, we saw it hang
on EADD ioctl and the ioctl never returns.Also noticed the selftest fails on oversub but the return errno is EINTR not ENOMEM as expected.
When user space register signal handler with
SA_RESTARTflag, EINTR would be an auto restart of ioctl. So that might be what's going on with Intel runtime test. And I suspect following code may cause infinite restart of the ioctl:struct
sgx_epc_page*sgx_alloc_epc_page(void *owner, bool reclaim){ struct sgx_epc_page *page; for ( ; ; ) { page = __sgx_alloc_epc_page(); if (!IS_ERR(page)) { page->owner = owner; break; }
Quoted 3 lines
Quoted 3 lines
if (list_empty(&sgx_active_page_list))<-- should also check
sgx_nr_available_backing_pages?return ERR_PTR(-ENOMEM);
I don't think so but why do you think it should?
Quoted 6 lines
Quoted 6 lines
if (!reclaim) { page = ERR_PTR(-EBUSY); break; }
Quoted 8 lines
Quoted 8 lines
if (
signal_pending(current)) {
page = ERR_PTR(-ERESTARTSYS);<---- this is the only exit of
the for loop when backing store limit reaches.break; } sgx_reclaim_pages(); <---- no checking for backing store fail dueto limit here.
Initially I'd think you're making here the right conclusion. Given the limit sgx_reclaim_pages() should return e.g. boolean or int to tell that we are out of backing storage.
Kristen?
Quoted 5 lines
Quoted 5 lines
cond_resched(); }Thanks
Haitao
The reason was that it was not x86/sgx branch of tip but this:
https://git.kernel.org/pub/scm/linux/kernel/git/daveh/devel.git/log/?h=x86/sgx
Sorry for initial reject.
BR, Jarkko
Quoted 56 lines · Jarkko Sakkinen
Quoted 55 lines · Jarkko Sakkinen
Quoted 3 lines · Haitao Huang
Hi Dave,
On Fri, 21 Jan 2022 13:57:50 -0600, Dave Hansen
Quoted 5 lines
Quoted 3 lines · wrote:
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or
so,
Quoted 1 line
Quoted 1 line
mostly around RAS and fixing the backing storage issues. Could
folks
Quoted 3 lines
Quoted 3 lines
please give this branch a good thrashing?
Quoted 1 line
https://git.kernel.org/pub/scm/linux/kernel/git/daveh/devel.git/log/?h=x86/sgx
Quoted 2 lines
Quoted 2 lines
I'm planning to send this bunch up to Linus after 5.17-rc1 comes
out.
Quoted 2 lines
Quoted 2 lines
Kristen, I really dug into the changelogs of your two patches to
make it
Quoted 1 line
Quoted 1 line
more clear that they are bugfix and stable@ material. I'd
appreciate
Quoted 3 lines
Quoted 1 line
some additional eyeballs there.
When testing this with a large enclave loaded by Intel runtime, we
saw it
Quoted 4 lines
hang
on EADD ioctl and the ioctl never returns.Also noticed the selftest fails on oversub but the return errno is
EINTR not
Quoted 3 lines
ENOMEM as expected.
When user space register signal handler with
SA_RESTARTflag, EINTRwould
Quoted 1 line
be an auto restart of ioctl. So that might be what's going on with
Intel
Quoted 1 line
runtime test. And I suspect following code may cause infinite restart
of the
Quoted 13 lines
ioctl:
struct
sgx_epc_page*sgx_alloc_epc_page(void *owner, bool reclaim){ struct sgx_epc_page *page; for ( ; ; ) { page = __sgx_alloc_epc_page(); if (!IS_ERR(page)) { page->owner = owner; break; }
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
if (list_empty(&sgx_active_page_list))<-- should also check
sgx_nr_available_backing_pages?return ERR_PTR(-ENOMEM);I don't think so but why do you think it should?
I was thinking no point to continue if
(atomic_long_read(&sgx_nr_available_backing_pages)==0).
We just failed on finding available EPC above in __sgx_alloc_epc_page. So if we can't swap, then nothing we can do, right?
BR
Haitao
Quoted 4 lines · Dave Hansen
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or so, mostly around RAS and fixing the backing storage issues. Could folks
~~~
Remote ATtestation?
Quoted 9 lines
please give this branch a good thrashing?
I'm planning to send this bunch up to Linus after 5.17-rc1 comes out.
Kristen, I really dug into the changelogs of your two patches to make it more clear that they are bugfix and stable@ material. I'd appreciate some additional eyeballs there.
Thanks for the heads up, this actually fits perfectly my next weeks other goals.
I'm implementing ECDSA attestation for Enarx next week (i.e. using AESMD). I was planning to use this branch in any case.
I can combine that with enclaves that trigger backing storage (it can host arbitarily sized WebAssembly programs). For those changes I'll do testing both my own hardware (i5-9600KF) and also Icelake Server (Platinum 8352Y).
If anything comes up, I'll post a fix directly, or if I get stuck I'll rise up the issues here.
BR, Jarkko
Quoted 6 lines · Dave Hansen
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or so, mostly around RAS and fixing the backing storage issues. Could folks please give this branch a good thrashing?
Quoted 8 lines
I'm planning to send this bunch up to Linus after 5.17-rc1 comes out.
Kristen, I really dug into the changelogs of your two patches to make it
more clear that they are bugfix and stable@ material. I'd appreciate some additional eyeballs there.
There's a bug in the calculation for the available backing bytes, pointed out by Haitao and team. Here's a fix applied to your tree.
From 2ebcf0e70b1235224410e08c983e357d5ac3c435 Mon Sep 17 00:00:00 2001
From: Kristen Carlson Accardi <[email protected]>
Date: Mon, 24 Jan 2022 09:28:56 -0800
Subject: [PATCH] x86/sgx: fixup for available backing pages calculation
Remove improper parentheses from calculation for available backing bytes. Without this fix, the result will be incorrect due to rounding.
--- arch/x86/kernel/cpu/sgx/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/main.c +1 -1
@@ -922,7 +922,7 @@ static bool __init sgx_page_cache_init(void)return false; } - available_backing_bytes = total_epc_bytes * (sgx_overcommit_percent /100 ); + available_backing_bytes = total_epc_bytes * sgx_overcommit_percent /100 ;atomic_long_set (&sgx_nr_available_backing_pages, available_backing_bytes >>PAGE_SHIFT );return true;
Signature · 1 line
2.20.1
Jarkko Sakkinen
Acked-byQuoted 49 lines · Kristen C
Quoted 6 lines · Dave Hansen
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or so, mostly around RAS and fixing the backing storage issues. Could folks please give this branch a good thrashing?
Quoted 8 lines
I'm planning to send this bunch up to Linus after 5.17-rc1 comes out.
Kristen, I really dug into the changelogs of your two patches to make it
more clear that they are bugfix and stable@ material. I'd appreciate some additional eyeballs there.There's a bug in the calculation for the available backing bytes, pointed out by Haitao and team. Here's a fix applied to your tree.
From
2ebcf0e70b1235224410e08c983e357d5ac3c435Mon Sep 17 00:00:00 2001
From: Kristen Carlson Accardi <[email protected]>
Date: Mon, 24 Jan 2022 09:28:56 -0800
Subject: [PATCH] x86/sgx: fixup for available backing pages calculationRemove improper parentheses from calculation for available backing bytes. Without this fix, the result will be incorrect due to rounding.
Signed-off-by Kristen Carlson Accardi <[email protected]>--- arch/x86/kernel/cpu/sgx/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/cpu/sgx/main.c +1
-1@@ -922,7 +922,7 @@ static bool __init sgx_page_cache_init(void)return false; } - available_backing_bytes = total_epc_bytes * (sgx_overcommit_percent /100 ); + available_backing_bytes = total_epc_bytes * sgx_overcommit_percent /100 ;atomic_long_set (&sgx_nr_available_backing_pages, available_backing_bytes >>PAGE_SHIFT );return true;Signature · 1 line
2.20.1
So what about sgx_reclaim_pages() having no return value that Haitao pointed out?
/Jarkko
Quoted 57 lines · Jarkko Sakkinen
Quoted 56 lines · Kristen C
Quoted 13 lines · Dave Hansen
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or so,
mostly around RAS and fixing the backing storage issues. Could folks
please give this branch a good thrashing?I'm planning to send this bunch up to Linus after 5.17-rc1 comes out.
Quoted 6 lines
Kristen, I really dug into the changelogs of your two patches to make
it
more clear that they are bugfix and stable@ material. I'd appreciate
some additional eyeballs there.There's a bug in the calculation for the available backing bytes, pointed out by Haitao and team. Here's a fix applied to your tree.
From
2ebcf0e70b1235224410e08c983e357d5ac3c435Mon Sep 17 00:00:00 2001
From: Kristen Carlson Accardi <[email protected]>
Date: Mon, 24 Jan 2022 09:28:56 -0800
Subject: [PATCH] x86/sgx: fixup for available backing pages calculationRemove improper parentheses from calculation for available backing bytes. Without this fix, the result will be incorrect due to rounding.
Signed-off-by Kristen Carlson Accardi <[email protected]>--- arch/x86/kernel/cpu/sgx/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/cpu/sgx/main.c +1
-1@@ -922,7 +922,7 @@ static bool __init sgx_page_cache_init(void)return false; } - available_backing_bytes = total_epc_bytes * (sgx_overcommit_percent /100 ); + available_backing_bytes = total_epc_bytes * sgx_overcommit_percent /100 ; atomic_long_set(&sgx_nr_available_backing_pages,
available_backing_bytes>>PAGE_SHIFT);
Quoted 7 lines
Quoted 4 lines
return true;
Signature · 1 line
2.20.1So what about
sgx_reclaim_pages()having no return value that Haitao pointed out?
I'm taking a look at that, and testing, and will send a separate fix.
Jarkko Sakkinen
maintainerQuoted 66 lines · Kristen C
Quoted 57 lines · Jarkko Sakkinen
Quoted 56 lines · Kristen C
Quoted 13 lines · Dave Hansen
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or so,
mostly around RAS and fixing the backing storage issues. Could folks
please give this branch a good thrashing?I'm planning to send this bunch up to Linus after 5.17-rc1 comes out.
Quoted 6 lines
Kristen, I really dug into the changelogs of your two patches to make
it
more clear that they are bugfix and stable@ material. I'd appreciate
some additional eyeballs there.There's a bug in the calculation for the available backing bytes, pointed out by Haitao and team. Here's a fix applied to your tree.
From
2ebcf0e70b1235224410e08c983e357d5ac3c435Mon Sep 17 00:00:00 2001
From: Kristen Carlson Accardi <[email protected]>
Date: Mon, 24 Jan 2022 09:28:56 -0800
Subject: [PATCH] x86/sgx: fixup for available backing pages calculationRemove improper parentheses from calculation for available backing bytes. Without this fix, the result will be incorrect due to rounding.
Signed-off-by Kristen Carlson Accardi <[email protected]>--- arch/x86/kernel/cpu/sgx/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/cpu/sgx/main.c +1
-1@@ -922,7 +922,7 @@ static bool __init sgx_page_cache_init(void)return false; } - available_backing_bytes = total_epc_bytes * (sgx_overcommit_percent /100 ); + available_backing_bytes = total_epc_bytes * sgx_overcommit_percent /100 ; atomic_long_set(&sgx_nr_available_backing_pages,
available_backing_bytes>>PAGE_SHIFT);Quoted 7 lines
Quoted 4 lines
return true;
Signature · 1 line
2.20.1So what about
sgx_reclaim_pages()having no return value that Haitao pointed out?
Quoted 1 line
I'm taking a look at that, and testing, and will send a separate fix.
NP, take your time, just remarked that it looks legit :-)
/Jarkko
Jarkko Sakkinen
maintainerQuoted 6 lines · Dave Hansen
Hi Everyone,
There are a few SGX fixes that have showed up in the last week or so, mostly around RAS and fixing the backing storage issues. Could folks please give this branch a good thrashing?
Quoted 7 lines
I'm planning to send this bunch up to Linus after 5.17-rc1 comes out.
Kristen, I really dug into the changelogs of your two patches to make it more clear that they are bugfix and stable@ material. I'd appreciate some additional eyeballs there.
Please drop my shmem patches as it crashes kselftest. I'll send two replacements soonish (it was easier to debug that way and makes sense for future bijections etc.).
/Jarkko