* [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()
2025-07-15 12:40 [PATCH v8 0/5] Enable automatic SVN updates for SGX enclaves Elena Reshetova
@ 2025-07-15 12:40 ` Elena Reshetova
2025-07-19 11:15 ` Jarkko Sakkinen
2025-07-21 16:47 ` Dave Hansen
2025-07-15 12:40 ` [PATCH v8 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag Elena Reshetova
` (4 subsequent siblings)
5 siblings, 2 replies; 15+ messages in thread
From: Elena Reshetova @ 2025-07-15 12:40 UTC (permalink / raw)
To: dave.hansen
Cc: jarkko, seanjc, kai.huang, mingo, linux-sgx, linux-kernel, x86,
asit.k.mallick, vincent.r.scarlata, chongc, erdemaktas,
vannapurve, bondarn, scott.raynor, Elena Reshetova
Currently SGX does not have a global counter to count the
active users from userspace or hypervisor. Implement such a counter,
sgx_usage_count. It will be used by the driver when attempting
to call EUPDATESVN SGX instruction.
Note: the sgx_inc_usage_count prototype is defined to return
int for the cleanliness of the follow-up patches. When the
EUPDATESVN SGX instruction will be enabled in the follow-up patch,
the sgx_inc_usage_count will start to return int.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
arch/x86/kernel/cpu/sgx/driver.c | 22 ++++++++++++++++------
arch/x86/kernel/cpu/sgx/encl.c | 1 +
arch/x86/kernel/cpu/sgx/main.c | 14 ++++++++++++++
arch/x86/kernel/cpu/sgx/sgx.h | 3 +++
arch/x86/kernel/cpu/sgx/virt.c | 16 ++++++++++++++--
5 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kernel/cpu/sgx/driver.c b/arch/x86/kernel/cpu/sgx/driver.c
index 7f8d1e11dbee..a2994a74bdff 100644
--- a/arch/x86/kernel/cpu/sgx/driver.c
+++ b/arch/x86/kernel/cpu/sgx/driver.c
@@ -19,9 +19,15 @@ static int sgx_open(struct inode *inode, struct file *file)
struct sgx_encl *encl;
int ret;
+ ret = sgx_inc_usage_count();
+ if (ret)
+ return ret;
+
encl = kzalloc(sizeof(*encl), GFP_KERNEL);
- if (!encl)
- return -ENOMEM;
+ if (!encl) {
+ ret = -ENOMEM;
+ goto err_usage_count;
+ }
kref_init(&encl->refcount);
xa_init(&encl->page_array);
@@ -31,14 +37,18 @@ static int sgx_open(struct inode *inode, struct file *file)
spin_lock_init(&encl->mm_lock);
ret = init_srcu_struct(&encl->srcu);
- if (ret) {
- kfree(encl);
- return ret;
- }
+ if (ret)
+ goto err_encl;
file->private_data = encl;
return 0;
+
+err_encl:
+ kfree(encl);
+err_usage_count:
+ sgx_dec_usage_count();
+ return ret;
}
static int sgx_release(struct inode *inode, struct file *file)
diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index 279148e72459..3b54889ae4a4 100644
--- a/arch/x86/kernel/cpu/sgx/encl.c
+++ b/arch/x86/kernel/cpu/sgx/encl.c
@@ -765,6 +765,7 @@ void sgx_encl_release(struct kref *ref)
WARN_ON_ONCE(encl->secs.epc_page);
kfree(encl);
+ sgx_dec_usage_count();
}
/*
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 2de01b379aa3..0e75090f93c9 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -917,6 +917,20 @@ int sgx_set_attribute(unsigned long *allowed_attributes,
}
EXPORT_SYMBOL_GPL(sgx_set_attribute);
+/* Counter to count the active SGX users */
+static int sgx_usage_count;
+
+int sgx_inc_usage_count(void)
+{
+ sgx_usage_count++;
+ return 0;
+}
+
+void sgx_dec_usage_count(void)
+{
+ sgx_usage_count--;
+}
+
static int __init sgx_init(void)
{
int ret;
diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h
index d2dad21259a8..f5940393d9bd 100644
--- a/arch/x86/kernel/cpu/sgx/sgx.h
+++ b/arch/x86/kernel/cpu/sgx/sgx.h
@@ -102,6 +102,9 @@ static inline int __init sgx_vepc_init(void)
}
#endif
+int sgx_inc_usage_count(void);
+void sgx_dec_usage_count(void);
+
void sgx_update_lepubkeyhash(u64 *lepubkeyhash);
#endif /* _X86_SGX_H */
diff --git a/arch/x86/kernel/cpu/sgx/virt.c b/arch/x86/kernel/cpu/sgx/virt.c
index 7aaa3652e31d..6ce908ed51c9 100644
--- a/arch/x86/kernel/cpu/sgx/virt.c
+++ b/arch/x86/kernel/cpu/sgx/virt.c
@@ -255,22 +255,34 @@ static int sgx_vepc_release(struct inode *inode, struct file *file)
xa_destroy(&vepc->page_array);
kfree(vepc);
+ sgx_dec_usage_count();
return 0;
}
static int sgx_vepc_open(struct inode *inode, struct file *file)
{
struct sgx_vepc *vepc;
+ int ret;
+
+ ret = sgx_inc_usage_count();
+ if (ret)
+ return ret;
vepc = kzalloc(sizeof(struct sgx_vepc), GFP_KERNEL);
- if (!vepc)
- return -ENOMEM;
+ if (!vepc) {
+ ret = -ENOMEM;
+ goto err_usage_count;
+ }
mutex_init(&vepc->lock);
xa_init(&vepc->page_array);
file->private_data = vepc;
return 0;
+
+err_usage_count:
+ sgx_dec_usage_count();
+ return ret;
}
static long sgx_vepc_ioctl(struct file *file,
--
2.45.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()
2025-07-15 12:40 ` [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open() Elena Reshetova
@ 2025-07-19 11:15 ` Jarkko Sakkinen
2025-07-19 11:28 ` Jarkko Sakkinen
2025-07-21 16:47 ` Dave Hansen
1 sibling, 1 reply; 15+ messages in thread
From: Jarkko Sakkinen @ 2025-07-19 11:15 UTC (permalink / raw)
To: Elena Reshetova
Cc: dave.hansen, seanjc, kai.huang, mingo, linux-sgx, linux-kernel,
x86, asit.k.mallick, vincent.r.scarlata, chongc, erdemaktas,
vannapurve, bondarn, scott.raynor
On Tue, Jul 15, 2025 at 03:40:18PM +0300, Elena Reshetova wrote:
> Currently SGX does not have a global counter to count the
> active users from userspace or hypervisor. Implement such a counter,
> sgx_usage_count. It will be used by the driver when attempting
> to call EUPDATESVN SGX instruction.
>
> Note: the sgx_inc_usage_count prototype is defined to return
> int for the cleanliness of the follow-up patches. When the
> EUPDATESVN SGX instruction will be enabled in the follow-up patch,
> the sgx_inc_usage_count will start to return int.
>
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
> ---
> arch/x86/kernel/cpu/sgx/driver.c | 22 ++++++++++++++++------
> arch/x86/kernel/cpu/sgx/encl.c | 1 +
> arch/x86/kernel/cpu/sgx/main.c | 14 ++++++++++++++
> arch/x86/kernel/cpu/sgx/sgx.h | 3 +++
> arch/x86/kernel/cpu/sgx/virt.c | 16 ++++++++++++++--
> 5 files changed, 48 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/sgx/driver.c b/arch/x86/kernel/cpu/sgx/driver.c
> index 7f8d1e11dbee..a2994a74bdff 100644
> --- a/arch/x86/kernel/cpu/sgx/driver.c
> +++ b/arch/x86/kernel/cpu/sgx/driver.c
> @@ -19,9 +19,15 @@ static int sgx_open(struct inode *inode, struct file *file)
> struct sgx_encl *encl;
> int ret;
>
> + ret = sgx_inc_usage_count();
> + if (ret)
> + return ret;
> +
> encl = kzalloc(sizeof(*encl), GFP_KERNEL);
> - if (!encl)
> - return -ENOMEM;
> + if (!encl) {
> + ret = -ENOMEM;
> + goto err_usage_count;
> + }
>
> kref_init(&encl->refcount);
> xa_init(&encl->page_array);
> @@ -31,14 +37,18 @@ static int sgx_open(struct inode *inode, struct file *file)
> spin_lock_init(&encl->mm_lock);
>
> ret = init_srcu_struct(&encl->srcu);
> - if (ret) {
> - kfree(encl);
> - return ret;
> - }
> + if (ret)
> + goto err_encl;
>
> file->private_data = encl;
>
> return 0;
> +
> +err_encl:
> + kfree(encl);
> +err_usage_count:
> + sgx_dec_usage_count();
> + return ret;
> }
>
> static int sgx_release(struct inode *inode, struct file *file)
> diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> index 279148e72459..3b54889ae4a4 100644
> --- a/arch/x86/kernel/cpu/sgx/encl.c
> +++ b/arch/x86/kernel/cpu/sgx/encl.c
> @@ -765,6 +765,7 @@ void sgx_encl_release(struct kref *ref)
> WARN_ON_ONCE(encl->secs.epc_page);
>
> kfree(encl);
> + sgx_dec_usage_count();
> }
>
> /*
> diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
> index 2de01b379aa3..0e75090f93c9 100644
> --- a/arch/x86/kernel/cpu/sgx/main.c
> +++ b/arch/x86/kernel/cpu/sgx/main.c
> @@ -917,6 +917,20 @@ int sgx_set_attribute(unsigned long *allowed_attributes,
> }
> EXPORT_SYMBOL_GPL(sgx_set_attribute);
>
> +/* Counter to count the active SGX users */
> +static int sgx_usage_count;
> +
> +int sgx_inc_usage_count(void)
> +{
> + sgx_usage_count++;
> + return 0;
> +}
> +
> +void sgx_dec_usage_count(void)
> +{
> + sgx_usage_count--;
> +}
> +
> static int __init sgx_init(void)
> {
> int ret;
> diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h
> index d2dad21259a8..f5940393d9bd 100644
> --- a/arch/x86/kernel/cpu/sgx/sgx.h
> +++ b/arch/x86/kernel/cpu/sgx/sgx.h
> @@ -102,6 +102,9 @@ static inline int __init sgx_vepc_init(void)
> }
> #endif
>
> +int sgx_inc_usage_count(void);
> +void sgx_dec_usage_count(void);
> +
> void sgx_update_lepubkeyhash(u64 *lepubkeyhash);
>
> #endif /* _X86_SGX_H */
> diff --git a/arch/x86/kernel/cpu/sgx/virt.c b/arch/x86/kernel/cpu/sgx/virt.c
> index 7aaa3652e31d..6ce908ed51c9 100644
> --- a/arch/x86/kernel/cpu/sgx/virt.c
> +++ b/arch/x86/kernel/cpu/sgx/virt.c
> @@ -255,22 +255,34 @@ static int sgx_vepc_release(struct inode *inode, struct file *file)
> xa_destroy(&vepc->page_array);
> kfree(vepc);
>
> + sgx_dec_usage_count();
> return 0;
> }
>
> static int sgx_vepc_open(struct inode *inode, struct file *file)
> {
> struct sgx_vepc *vepc;
> + int ret;
> +
> + ret = sgx_inc_usage_count();
> + if (ret)
> + return ret;
>
> vepc = kzalloc(sizeof(struct sgx_vepc), GFP_KERNEL);
> - if (!vepc)
> - return -ENOMEM;
> + if (!vepc) {
> + ret = -ENOMEM;
> + goto err_usage_count;
> + }
> mutex_init(&vepc->lock);
> xa_init(&vepc->page_array);
>
> file->private_data = vepc;
>
> return 0;
> +
> +err_usage_count:
> + sgx_dec_usage_count();
> + return ret;
> }
This is essentially a wrapper over pre-existing function. I vote for
renaming the pre-existing function as __sgx_vepc_open() and add then a
new function calling it:
static int sgx_vepc_open(struct inode *inode, struct file *file)
{
int ret;
ret = sgx_inc_usage_count();
if (ret)
return ret;
ret = __sgx_vepc_open(inode, file);
if (ret) {
sgx_dec_usage_count();
return ret;
}
return 0;
}
I think this a factor better standing point also when having to dig
into this later on (easier to see the big picture) as it has clear
split of responsibilities:
1. top layer manages to usage count
2. lower layer allocates vepc structures (which has nothing to do
with the logic of the usage count).
This comment applies also to sgx_open().
>
> static long sgx_vepc_ioctl(struct file *file,
> --
> 2.45.2
>
BR, Jarkko
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()
2025-07-19 11:15 ` Jarkko Sakkinen
@ 2025-07-19 11:28 ` Jarkko Sakkinen
2025-07-22 6:45 ` Reshetova, Elena
0 siblings, 1 reply; 15+ messages in thread
From: Jarkko Sakkinen @ 2025-07-19 11:28 UTC (permalink / raw)
To: Elena Reshetova
Cc: dave.hansen, seanjc, kai.huang, mingo, linux-sgx, linux-kernel,
x86, asit.k.mallick, vincent.r.scarlata, chongc, erdemaktas,
vannapurve, bondarn, scott.raynor
On Sat, Jul 19, 2025 at 02:15:16PM +0300, Jarkko Sakkinen wrote:
> On Tue, Jul 15, 2025 at 03:40:18PM +0300, Elena Reshetova wrote:
> > Currently SGX does not have a global counter to count the
> > active users from userspace or hypervisor. Implement such a counter,
> > sgx_usage_count. It will be used by the driver when attempting
> > to call EUPDATESVN SGX instruction.
> >
> > Note: the sgx_inc_usage_count prototype is defined to return
> > int for the cleanliness of the follow-up patches. When the
> > EUPDATESVN SGX instruction will be enabled in the follow-up patch,
> > the sgx_inc_usage_count will start to return int.
> >
> > Suggested-by: Sean Christopherson <seanjc@google.com>
> > Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
> > ---
> > arch/x86/kernel/cpu/sgx/driver.c | 22 ++++++++++++++++------
> > arch/x86/kernel/cpu/sgx/encl.c | 1 +
> > arch/x86/kernel/cpu/sgx/main.c | 14 ++++++++++++++
> > arch/x86/kernel/cpu/sgx/sgx.h | 3 +++
> > arch/x86/kernel/cpu/sgx/virt.c | 16 ++++++++++++++--
> > 5 files changed, 48 insertions(+), 8 deletions(-)
> >
> > diff --git a/arch/x86/kernel/cpu/sgx/driver.c b/arch/x86/kernel/cpu/sgx/driver.c
> > index 7f8d1e11dbee..a2994a74bdff 100644
> > --- a/arch/x86/kernel/cpu/sgx/driver.c
> > +++ b/arch/x86/kernel/cpu/sgx/driver.c
> > @@ -19,9 +19,15 @@ static int sgx_open(struct inode *inode, struct file *file)
> > struct sgx_encl *encl;
> > int ret;
> >
> > + ret = sgx_inc_usage_count();
> > + if (ret)
> > + return ret;
> > +
> > encl = kzalloc(sizeof(*encl), GFP_KERNEL);
> > - if (!encl)
> > - return -ENOMEM;
> > + if (!encl) {
> > + ret = -ENOMEM;
> > + goto err_usage_count;
> > + }
> >
> > kref_init(&encl->refcount);
> > xa_init(&encl->page_array);
> > @@ -31,14 +37,18 @@ static int sgx_open(struct inode *inode, struct file *file)
> > spin_lock_init(&encl->mm_lock);
> >
> > ret = init_srcu_struct(&encl->srcu);
> > - if (ret) {
> > - kfree(encl);
> > - return ret;
> > - }
> > + if (ret)
> > + goto err_encl;
> >
> > file->private_data = encl;
> >
> > return 0;
> > +
> > +err_encl:
> > + kfree(encl);
> > +err_usage_count:
> > + sgx_dec_usage_count();
> > + return ret;
> > }
> >
> > static int sgx_release(struct inode *inode, struct file *file)
> > diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> > index 279148e72459..3b54889ae4a4 100644
> > --- a/arch/x86/kernel/cpu/sgx/encl.c
> > +++ b/arch/x86/kernel/cpu/sgx/encl.c
> > @@ -765,6 +765,7 @@ void sgx_encl_release(struct kref *ref)
> > WARN_ON_ONCE(encl->secs.epc_page);
> >
> > kfree(encl);
> > + sgx_dec_usage_count();
> > }
> >
> > /*
> > diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
> > index 2de01b379aa3..0e75090f93c9 100644
> > --- a/arch/x86/kernel/cpu/sgx/main.c
> > +++ b/arch/x86/kernel/cpu/sgx/main.c
> > @@ -917,6 +917,20 @@ int sgx_set_attribute(unsigned long *allowed_attributes,
> > }
> > EXPORT_SYMBOL_GPL(sgx_set_attribute);
> >
> > +/* Counter to count the active SGX users */
> > +static int sgx_usage_count;
> > +
> > +int sgx_inc_usage_count(void)
> > +{
> > + sgx_usage_count++;
> > + return 0;
> > +}
> > +
> > +void sgx_dec_usage_count(void)
> > +{
> > + sgx_usage_count--;
> > +}
> > +
> > static int __init sgx_init(void)
> > {
> > int ret;
> > diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h
> > index d2dad21259a8..f5940393d9bd 100644
> > --- a/arch/x86/kernel/cpu/sgx/sgx.h
> > +++ b/arch/x86/kernel/cpu/sgx/sgx.h
> > @@ -102,6 +102,9 @@ static inline int __init sgx_vepc_init(void)
> > }
> > #endif
> >
> > +int sgx_inc_usage_count(void);
> > +void sgx_dec_usage_count(void);
> > +
> > void sgx_update_lepubkeyhash(u64 *lepubkeyhash);
> >
> > #endif /* _X86_SGX_H */
> > diff --git a/arch/x86/kernel/cpu/sgx/virt.c b/arch/x86/kernel/cpu/sgx/virt.c
> > index 7aaa3652e31d..6ce908ed51c9 100644
> > --- a/arch/x86/kernel/cpu/sgx/virt.c
> > +++ b/arch/x86/kernel/cpu/sgx/virt.c
> > @@ -255,22 +255,34 @@ static int sgx_vepc_release(struct inode *inode, struct file *file)
> > xa_destroy(&vepc->page_array);
> > kfree(vepc);
> >
> > + sgx_dec_usage_count();
> > return 0;
> > }
> >
> > static int sgx_vepc_open(struct inode *inode, struct file *file)
> > {
> > struct sgx_vepc *vepc;
> > + int ret;
> > +
> > + ret = sgx_inc_usage_count();
> > + if (ret)
> > + return ret;
> >
> > vepc = kzalloc(sizeof(struct sgx_vepc), GFP_KERNEL);
> > - if (!vepc)
> > - return -ENOMEM;
> > + if (!vepc) {
> > + ret = -ENOMEM;
> > + goto err_usage_count;
> > + }
> > mutex_init(&vepc->lock);
> > xa_init(&vepc->page_array);
> >
> > file->private_data = vepc;
> >
> > return 0;
> > +
> > +err_usage_count:
> > + sgx_dec_usage_count();
> > + return ret;
> > }
>
> This is essentially a wrapper over pre-existing function. I vote for
> renaming the pre-existing function as __sgx_vepc_open() and add then a
> new function calling it:
>
> static int sgx_vepc_open(struct inode *inode, struct file *file)
> {
> int ret;
>
> ret = sgx_inc_usage_count();
> if (ret)
> return ret;
>
> ret = __sgx_vepc_open(inode, file);
> if (ret) {
> sgx_dec_usage_count();
> return ret;
> }
>
> return 0;
> }
>
> I think this a factor better standing point also when having to dig
> into this later on (easier to see the big picture) as it has clear
> split of responsibilities:
>
> 1. top layer manages to usage count
> 2. lower layer allocates vepc structures (which has nothing to do
> with the logic of the usage count).
>
> This comment applies also to sgx_open().
I'd also split this into two patches (those are not suggestions for
short summaries just saying):
Patch #1: Rename {sgx_open(),sgx_vepc_open()} as {__sgx_open,__sgx_vepc_open}
Patch #2: Add a new function called {sgx_open(),sgx_vepc_open()} and fixup the call sites.
This is not similar scenario as the one I was complaining with 4/5
and 5/5 because second patch adds new functions, which just have
names that were used for different purpose in the past (just
saying because thought this suggestion might soudn otherwise
somehow contradictory).
BR, Jarkko
^ permalink raw reply [flat|nested] 15+ messages in thread* RE: [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()
2025-07-19 11:28 ` Jarkko Sakkinen
@ 2025-07-22 6:45 ` Reshetova, Elena
0 siblings, 0 replies; 15+ messages in thread
From: Reshetova, Elena @ 2025-07-22 6:45 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: Hansen, Dave, seanjc@google.com, Huang, Kai, mingo@kernel.org,
linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org,
x86@kernel.org, Mallick, Asit K, Scarlata, Vincent R, Cai, Chong,
Aktas, Erdem, Annapurve, Vishal, Bondarevska, Nataliia,
Raynor, Scott
>
> On Sat, Jul 19, 2025 at 02:15:16PM +0300, Jarkko Sakkinen wrote:
> > On Tue, Jul 15, 2025 at 03:40:18PM +0300, Elena Reshetova wrote:
> > > Currently SGX does not have a global counter to count the
> > > active users from userspace or hypervisor. Implement such a counter,
> > > sgx_usage_count. It will be used by the driver when attempting
> > > to call EUPDATESVN SGX instruction.
> >
...
> > This is essentially a wrapper over pre-existing function. I vote for
> > renaming the pre-existing function as __sgx_vepc_open() and add then a
> > new function calling it:
> >
> > static int sgx_vepc_open(struct inode *inode, struct file *file)
> > {
> > int ret;
> >
> > ret = sgx_inc_usage_count();
> > if (ret)
> > return ret;
> >
> > ret = __sgx_vepc_open(inode, file);
> > if (ret) {
> > sgx_dec_usage_count();
> > return ret;
> > }
> >
> > return 0;
> > }
> >
> > I think this a factor better standing point also when having to dig
> > into this later on (easier to see the big picture) as it has clear
> > split of responsibilities:
> >
> > 1. top layer manages to usage count
> > 2. lower layer allocates vepc structures (which has nothing to do
> > with the logic of the usage count).
> >
> > This comment applies also to sgx_open().
>
> I'd also split this into two patches (those are not suggestions for
> short summaries just saying):
>
> Patch #1: Rename {sgx_open(),sgx_vepc_open()} as
> {__sgx_open,__sgx_vepc_open}
> Patch #2: Add a new function called {sgx_open(),sgx_vepc_open()} and fixup
> the call sites.
Sure, I will test and submit the v9 next with these changes.
>
> This is not similar scenario as the one I was complaining with 4/5
> and 5/5 because second patch adds new functions, which just have
> names that were used for different purpose in the past (just
> saying because thought this suggestion might soudn otherwise
> somehow contradictory).
Thank you for elaborating, yes, I understand it is different but
Dave has a different opinion there, so I am not sure which way to
take. Will wait until your discussion with Dave completes on this one.
Best Regards,
Elena
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()
2025-07-15 12:40 ` [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open() Elena Reshetova
2025-07-19 11:15 ` Jarkko Sakkinen
@ 2025-07-21 16:47 ` Dave Hansen
2025-07-22 6:46 ` Reshetova, Elena
1 sibling, 1 reply; 15+ messages in thread
From: Dave Hansen @ 2025-07-21 16:47 UTC (permalink / raw)
To: Elena Reshetova
Cc: jarkko, seanjc, kai.huang, mingo, linux-sgx, linux-kernel, x86,
asit.k.mallick, vincent.r.scarlata, chongc, erdemaktas,
vannapurve, bondarn, scott.raynor
On 7/15/25 05:40, Elena Reshetova wrote:
> +int sgx_inc_usage_count(void)
> +{
> + sgx_usage_count++;
> + return 0;
> +}
> +
> +void sgx_dec_usage_count(void)
> +{
> + sgx_usage_count--;
> +}
Gah.
I know this gets fixed up later in the series with the mutex, but this
code is broken and racy until that point.
I'd rather this do _nothing_:
int sgx_inc_usage_count(void)
{
return 0;
}
than a foo++ which just plain doesn't work.
^ permalink raw reply [flat|nested] 15+ messages in thread* RE: [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()
2025-07-21 16:47 ` Dave Hansen
@ 2025-07-22 6:46 ` Reshetova, Elena
0 siblings, 0 replies; 15+ messages in thread
From: Reshetova, Elena @ 2025-07-22 6:46 UTC (permalink / raw)
To: Hansen, Dave
Cc: jarkko@kernel.org, seanjc@google.com, Huang, Kai,
mingo@kernel.org, linux-sgx@vger.kernel.org,
linux-kernel@vger.kernel.org, x86@kernel.org, Mallick, Asit K,
Scarlata, Vincent R, Cai, Chong, Aktas, Erdem, Annapurve, Vishal,
Bondarevska, Nataliia, Raynor, Scott
> -----Original Message-----
> From: Hansen, Dave <dave.hansen@intel.com>
> Sent: Monday, July 21, 2025 7:48 PM
> To: Reshetova, Elena <elena.reshetova@intel.com>
> Cc: jarkko@kernel.org; seanjc@google.com; Huang, Kai
> <kai.huang@intel.com>; mingo@kernel.org; linux-sgx@vger.kernel.org; linux-
> kernel@vger.kernel.org; x86@kernel.org; Mallick, Asit K
> <asit.k.mallick@intel.com>; Scarlata, Vincent R <vincent.r.scarlata@intel.com>;
> Cai, Chong <chongc@google.com>; Aktas, Erdem <erdemaktas@google.com>;
> Annapurve, Vishal <vannapurve@google.com>; Bondarevska, Nataliia
> <bondarn@google.com>; Raynor, Scott <scott.raynor@intel.com>
> Subject: Re: [PATCH v8 1/5] x86/sgx: Introduce a counter to count the
> sgx_(vepc_)open()
>
> On 7/15/25 05:40, Elena Reshetova wrote:
> > +int sgx_inc_usage_count(void)
> > +{
> > + sgx_usage_count++;
> > + return 0;
> > +}
> > +
> > +void sgx_dec_usage_count(void)
> > +{
> > + sgx_usage_count--;
> > +}
>
> Gah.
>
> I know this gets fixed up later in the series with the mutex, but this
> code is broken and racy until that point.
>
> I'd rather this do _nothing_:
>
> int sgx_inc_usage_count(void)
> {
> return 0;
> }
>
> than a foo++ which just plain doesn't work.
Sure, I can fix it also in v9.
Best Regards,
Elena.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v8 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag
2025-07-15 12:40 [PATCH v8 0/5] Enable automatic SVN updates for SGX enclaves Elena Reshetova
2025-07-15 12:40 ` [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open() Elena Reshetova
@ 2025-07-15 12:40 ` Elena Reshetova
2025-07-15 12:40 ` [PATCH v8 3/5] x86/sgx: Define error codes for use by ENCLS[EUPDATESVN] Elena Reshetova
` (3 subsequent siblings)
5 siblings, 0 replies; 15+ messages in thread
From: Elena Reshetova @ 2025-07-15 12:40 UTC (permalink / raw)
To: dave.hansen
Cc: jarkko, seanjc, kai.huang, mingo, linux-sgx, linux-kernel, x86,
asit.k.mallick, vincent.r.scarlata, chongc, erdemaktas,
vannapurve, bondarn, scott.raynor, Elena Reshetova
Add a flag indicating whenever ENCLS[EUPDATESVN] SGX instruction
is supported. This will be used by SGX driver to perform CPU
SVN updates.
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
arch/x86/include/asm/cpufeatures.h | 1 +
arch/x86/kernel/cpu/cpuid-deps.c | 1 +
arch/x86/kernel/cpu/scattered.c | 1 +
tools/arch/x86/include/asm/cpufeatures.h | 1 +
4 files changed, 4 insertions(+)
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 602957dd2609..830d24ff1ada 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -494,6 +494,7 @@
#define X86_FEATURE_TSA_SQ_NO (21*32+11) /* AMD CPU not vulnerable to TSA-SQ */
#define X86_FEATURE_TSA_L1_NO (21*32+12) /* AMD CPU not vulnerable to TSA-L1 */
#define X86_FEATURE_CLEAR_CPU_BUF_VM (21*32+13) /* Clear CPU buffers using VERW before VMRUN */
+#define X86_FEATURE_SGX_EUPDATESVN (21*32+14) /* Support for ENCLS[EUPDATESVN] instruction */
/*
* BUG word(s)
diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
index 46efcbd6afa4..3d9f49ad0efd 100644
--- a/arch/x86/kernel/cpu/cpuid-deps.c
+++ b/arch/x86/kernel/cpu/cpuid-deps.c
@@ -79,6 +79,7 @@ static const struct cpuid_dep cpuid_deps[] = {
{ X86_FEATURE_SGX_LC, X86_FEATURE_SGX },
{ X86_FEATURE_SGX1, X86_FEATURE_SGX },
{ X86_FEATURE_SGX2, X86_FEATURE_SGX1 },
+ { X86_FEATURE_SGX_EUPDATESVN, X86_FEATURE_SGX1 },
{ X86_FEATURE_SGX_EDECCSSA, X86_FEATURE_SGX1 },
{ X86_FEATURE_XFD, X86_FEATURE_XSAVES },
{ X86_FEATURE_XFD, X86_FEATURE_XGETBV1 },
diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c
index b4a1f6732a3a..d13444d11ba0 100644
--- a/arch/x86/kernel/cpu/scattered.c
+++ b/arch/x86/kernel/cpu/scattered.c
@@ -42,6 +42,7 @@ static const struct cpuid_bit cpuid_bits[] = {
{ X86_FEATURE_PER_THREAD_MBA, CPUID_ECX, 0, 0x00000010, 3 },
{ X86_FEATURE_SGX1, CPUID_EAX, 0, 0x00000012, 0 },
{ X86_FEATURE_SGX2, CPUID_EAX, 1, 0x00000012, 0 },
+ { X86_FEATURE_SGX_EUPDATESVN, CPUID_EAX, 10, 0x00000012, 0 },
{ X86_FEATURE_SGX_EDECCSSA, CPUID_EAX, 11, 0x00000012, 0 },
{ X86_FEATURE_HW_PSTATE, CPUID_EDX, 7, 0x80000007, 0 },
{ X86_FEATURE_CPB, CPUID_EDX, 9, 0x80000007, 0 },
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index ee176236c2be..78c3894c17c1 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -487,6 +487,7 @@
#define X86_FEATURE_PREFER_YMM (21*32+ 8) /* Avoid ZMM registers due to downclocking */
#define X86_FEATURE_APX (21*32+ 9) /* Advanced Performance Extensions */
#define X86_FEATURE_INDIRECT_THUNK_ITS (21*32+10) /* Use thunk for indirect branches in lower half of cacheline */
+#define X86_FEATURE_SGX_EUPDATESVN (21*32+14) /* Support for ENCLS[EUPDATESVN] instruction */
/*
* BUG word(s)
--
2.45.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v8 3/5] x86/sgx: Define error codes for use by ENCLS[EUPDATESVN]
2025-07-15 12:40 [PATCH v8 0/5] Enable automatic SVN updates for SGX enclaves Elena Reshetova
2025-07-15 12:40 ` [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open() Elena Reshetova
2025-07-15 12:40 ` [PATCH v8 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag Elena Reshetova
@ 2025-07-15 12:40 ` Elena Reshetova
2025-07-15 12:40 ` [PATCH v8 4/5] x86/sgx: Implement ENCLS[EUPDATESVN] Elena Reshetova
` (2 subsequent siblings)
5 siblings, 0 replies; 15+ messages in thread
From: Elena Reshetova @ 2025-07-15 12:40 UTC (permalink / raw)
To: dave.hansen
Cc: jarkko, seanjc, kai.huang, mingo, linux-sgx, linux-kernel, x86,
asit.k.mallick, vincent.r.scarlata, chongc, erdemaktas,
vannapurve, bondarn, scott.raynor, Elena Reshetova
Add error codes for ENCLS[EUPDATESVN], then SGX CPUSVN update
process can know the execution state of EUPDATESVN and notify
userspace.
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
arch/x86/include/asm/sgx.h | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h
index 6a0069761508..1abf1461fab6 100644
--- a/arch/x86/include/asm/sgx.h
+++ b/arch/x86/include/asm/sgx.h
@@ -28,21 +28,22 @@
#define SGX_CPUID_EPC_MASK GENMASK(3, 0)
enum sgx_encls_function {
- ECREATE = 0x00,
- EADD = 0x01,
- EINIT = 0x02,
- EREMOVE = 0x03,
- EDGBRD = 0x04,
- EDGBWR = 0x05,
- EEXTEND = 0x06,
- ELDU = 0x08,
- EBLOCK = 0x09,
- EPA = 0x0A,
- EWB = 0x0B,
- ETRACK = 0x0C,
- EAUG = 0x0D,
- EMODPR = 0x0E,
- EMODT = 0x0F,
+ ECREATE = 0x00,
+ EADD = 0x01,
+ EINIT = 0x02,
+ EREMOVE = 0x03,
+ EDGBRD = 0x04,
+ EDGBWR = 0x05,
+ EEXTEND = 0x06,
+ ELDU = 0x08,
+ EBLOCK = 0x09,
+ EPA = 0x0A,
+ EWB = 0x0B,
+ ETRACK = 0x0C,
+ EAUG = 0x0D,
+ EMODPR = 0x0E,
+ EMODT = 0x0F,
+ EUPDATESVN = 0x18,
};
/**
@@ -73,6 +74,10 @@ enum sgx_encls_function {
* public key does not match IA32_SGXLEPUBKEYHASH.
* %SGX_PAGE_NOT_MODIFIABLE: The EPC page cannot be modified because it
* is in the PENDING or MODIFIED state.
+ * %SGX_INSUFFICIENT_ENTROPY: Insufficient entropy in RNG.
+ * %SGX_NO_UPDATE: EUPDATESVN was successful, but CPUSVN was not
+ * updated because current SVN was not newer than
+ * CPUSVN.
* %SGX_UNMASKED_EVENT: An unmasked event, e.g. INTR, was received
*/
enum sgx_return_code {
@@ -81,6 +86,8 @@ enum sgx_return_code {
SGX_CHILD_PRESENT = 13,
SGX_INVALID_EINITTOKEN = 16,
SGX_PAGE_NOT_MODIFIABLE = 20,
+ SGX_INSUFFICIENT_ENTROPY = 29,
+ SGX_NO_UPDATE = 31,
SGX_UNMASKED_EVENT = 128,
};
--
2.45.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v8 4/5] x86/sgx: Implement ENCLS[EUPDATESVN]
2025-07-15 12:40 [PATCH v8 0/5] Enable automatic SVN updates for SGX enclaves Elena Reshetova
` (2 preceding siblings ...)
2025-07-15 12:40 ` [PATCH v8 3/5] x86/sgx: Define error codes for use by ENCLS[EUPDATESVN] Elena Reshetova
@ 2025-07-15 12:40 ` Elena Reshetova
2025-07-15 12:40 ` [PATCH v8 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves Elena Reshetova
2025-07-18 4:50 ` [PATCH v8 0/5] " Huang, Kai
5 siblings, 0 replies; 15+ messages in thread
From: Elena Reshetova @ 2025-07-15 12:40 UTC (permalink / raw)
To: dave.hansen
Cc: jarkko, seanjc, kai.huang, mingo, linux-sgx, linux-kernel, x86,
asit.k.mallick, vincent.r.scarlata, chongc, erdemaktas,
vannapurve, bondarn, scott.raynor, Elena Reshetova
All running enclaves and cryptographic assets (such as internal SGX
encryption keys) are assumed to be compromised whenever an SGX-related
microcode update occurs. To mitigate this assumed compromise the new
supervisor SGX instruction ENCLS[EUPDATESVN] can generate fresh
cryptographic assets.
Before executing EUPDATESVN, all SGX memory must be marked as unused.
This requirement ensures that no potentially compromised enclave
survives the update and allows the system to safely regenerate
cryptographic assets.
Add the method to perform ENCLS[EUPDATESVN].
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
arch/x86/kernel/cpu/sgx/encls.h | 5 +++
arch/x86/kernel/cpu/sgx/main.c | 61 +++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+)
diff --git a/arch/x86/kernel/cpu/sgx/encls.h b/arch/x86/kernel/cpu/sgx/encls.h
index 99004b02e2ed..d9160c89a93d 100644
--- a/arch/x86/kernel/cpu/sgx/encls.h
+++ b/arch/x86/kernel/cpu/sgx/encls.h
@@ -233,4 +233,9 @@ static inline int __eaug(struct sgx_pageinfo *pginfo, void *addr)
return __encls_2(EAUG, pginfo, addr);
}
+/* Attempt to update CPUSVN at runtime. */
+static inline int __eupdatesvn(void)
+{
+ return __encls_ret_1(EUPDATESVN, "");
+}
#endif /* _X86_ENCLS_H */
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 0e75090f93c9..c97bba16e4fd 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -16,6 +16,7 @@
#include <linux/vmalloc.h>
#include <asm/msr.h>
#include <asm/sgx.h>
+#include <asm/archrandom.h>
#include "driver.h"
#include "encl.h"
#include "encls.h"
@@ -920,6 +921,66 @@ EXPORT_SYMBOL_GPL(sgx_set_attribute);
/* Counter to count the active SGX users */
static int sgx_usage_count;
+/**
+ * sgx_update_svn() - Attempt to call ENCLS[EUPDATESVN].
+ * This instruction attempts to update CPUSVN to the
+ * currently loaded microcode update SVN and generate new
+ * cryptographic assets. Must be called when EPC is empty.
+ * Most of the time, there will be no update and that's OK.
+ * If the failure is due to SGX_INSUFFICIENT_ENTROPY, the
+ * operation can be safely retried. In other failure cases,
+ * the retry should not be attempted.
+ *
+ * Return:
+ * 0: Success or not supported
+ * -EAGAIN: Can be safely retried, failure is due to lack of
+ * entropy in RNG.
+ * -EIO: Unexpected error, retries are not advisable.
+ */
+static int __maybe_unused sgx_update_svn(void)
+{
+ int ret;
+
+ /*
+ * If EUPDATESVN is not available, it is ok to
+ * silently skip it to comply with legacy behavior.
+ */
+ if (!cpu_feature_enabled(X86_FEATURE_SGX_EUPDATESVN))
+ return 0;
+
+ for (int i = 0; i < RDRAND_RETRY_LOOPS; i++) {
+ ret = __eupdatesvn();
+
+ /* Stop on success or unexpected errors: */
+ if (ret != SGX_INSUFFICIENT_ENTROPY)
+ break;
+ }
+
+ /*
+ * SVN successfully updated.
+ * Let users know when the update was successful.
+ */
+ if (!ret)
+ pr_info("SVN updated successfully\n");
+
+ if (!ret || ret == SGX_NO_UPDATE)
+ return 0;
+
+ /*
+ * SVN update failed due to lack of entropy in DRNG.
+ * Indicate to userspace that it should retry.
+ */
+ if (ret == SGX_INSUFFICIENT_ENTROPY)
+ return -EAGAIN;
+
+ /*
+ * EUPDATESVN was called when EPC is empty, all other error
+ * codes are unexpected.
+ */
+ ENCLS_WARN(ret, "EUPDATESVN");
+ return -EIO;
+}
+
int sgx_inc_usage_count(void)
{
sgx_usage_count++;
--
2.45.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v8 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves
2025-07-15 12:40 [PATCH v8 0/5] Enable automatic SVN updates for SGX enclaves Elena Reshetova
` (3 preceding siblings ...)
2025-07-15 12:40 ` [PATCH v8 4/5] x86/sgx: Implement ENCLS[EUPDATESVN] Elena Reshetova
@ 2025-07-15 12:40 ` Elena Reshetova
2025-07-19 11:22 ` Jarkko Sakkinen
2025-07-18 4:50 ` [PATCH v8 0/5] " Huang, Kai
5 siblings, 1 reply; 15+ messages in thread
From: Elena Reshetova @ 2025-07-15 12:40 UTC (permalink / raw)
To: dave.hansen
Cc: jarkko, seanjc, kai.huang, mingo, linux-sgx, linux-kernel, x86,
asit.k.mallick, vincent.r.scarlata, chongc, erdemaktas,
vannapurve, bondarn, scott.raynor, Elena Reshetova
== Background ==
ENCLS[EUPDATESVN] is a new SGX instruction [1] which allows enclave
attestation to include information about updated microcode SVN without a
reboot. Before an EUPDATESVN operation can be successful, all SGX memory
(aka. EPC) must be marked as “unused” in the SGX hardware metadata
(aka.EPCM). This requirement ensures that no compromised enclave can
survive the EUPDATESVN procedure and provides an opportunity to generate
new cryptographic assets.
== Patch Contents ==
Attempt to execute ENCLS[EUPDATESVN] every time the first file descriptor
is obtained via sgx_(vepc_)open(). In the most common case the microcode
SVN is already up-to-date, and the operation succeeds without updating SVN.
If it fails with any other error code than SGX_INSUFFICIENT_ENTROPY, this
is considered unexpected and the *open() returns an error. This should not
happen in practice.
On contrary, SGX_INSUFFICIENT_ENTROPY might happen due
to a pressure on the system's DRNG (RDSEED) and therefore the *open() can
be safely retried to allow normal enclave operation.
[1] Runtime Microcode Updates with Intel Software Guard Extensions,
https://cdrdv2.intel.com/v1/dl/getContent/648682
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
arch/x86/kernel/cpu/sgx/main.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index c97bba16e4fd..58cc342bfdbd 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -921,6 +921,9 @@ EXPORT_SYMBOL_GPL(sgx_set_attribute);
/* Counter to count the active SGX users */
static int sgx_usage_count;
+/* Mutex to ensure no concurrent EPC accesses during EUPDATESVN */
+static DEFINE_MUTEX(sgx_svn_lock);
+
/**
* sgx_update_svn() - Attempt to call ENCLS[EUPDATESVN].
* This instruction attempts to update CPUSVN to the
@@ -937,7 +940,7 @@ static int sgx_usage_count;
* entropy in RNG.
* -EIO: Unexpected error, retries are not advisable.
*/
-static int __maybe_unused sgx_update_svn(void)
+static int sgx_update_svn(void)
{
int ret;
@@ -983,7 +986,11 @@ static int __maybe_unused sgx_update_svn(void)
int sgx_inc_usage_count(void)
{
- sgx_usage_count++;
+ guard(mutex)(&sgx_svn_lock);
+
+ if (sgx_usage_count++ == 0)
+ return sgx_update_svn();
+
return 0;
}
--
2.45.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v8 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves
2025-07-15 12:40 ` [PATCH v8 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves Elena Reshetova
@ 2025-07-19 11:22 ` Jarkko Sakkinen
2025-07-21 16:45 ` Dave Hansen
0 siblings, 1 reply; 15+ messages in thread
From: Jarkko Sakkinen @ 2025-07-19 11:22 UTC (permalink / raw)
To: Elena Reshetova
Cc: dave.hansen, seanjc, kai.huang, mingo, linux-sgx, linux-kernel,
x86, asit.k.mallick, vincent.r.scarlata, chongc, erdemaktas,
vannapurve, bondarn, scott.raynor
On Tue, Jul 15, 2025 at 03:40:22PM +0300, Elena Reshetova wrote:
> -static int __maybe_unused sgx_update_svn(void)
> +static int sgx_update_svn(void)
I'd combine 4/5 and 5/5 because of this. Makes them so much easier to
backtrack changes later on if this type of stuff is avoided when
possible.
BR, Jarkko
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v8 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves
2025-07-19 11:22 ` Jarkko Sakkinen
@ 2025-07-21 16:45 ` Dave Hansen
0 siblings, 0 replies; 15+ messages in thread
From: Dave Hansen @ 2025-07-21 16:45 UTC (permalink / raw)
To: Jarkko Sakkinen, Elena Reshetova
Cc: seanjc, kai.huang, mingo, linux-sgx, linux-kernel, x86,
asit.k.mallick, vincent.r.scarlata, chongc, erdemaktas,
vannapurve, bondarn, scott.raynor
On 7/19/25 04:22, Jarkko Sakkinen wrote:
> On Tue, Jul 15, 2025 at 03:40:22PM +0300, Elena Reshetova wrote:
>> -static int __maybe_unused sgx_update_svn(void)
>> +static int sgx_update_svn(void)
> I'd combine 4/5 and 5/5 because of this. Makes them so much easier to
> backtrack changes later on if this type of stuff is avoided when
> possible.
I'm not really sure what "backtracking changes" is, but I disagree on
this one.
Breaking up patches is about reducing the mental load to review things.
Generally, the smaller the patch, the smaller the mental load. That
breaks down when, for instance, a helper has a complicated argument
handling or return codes.
But, in this case, we have a function that takes no arguments and
returns standard -ERROR codes. It's fine to break it out like this. No
reason to do more patch gymnastics at this point to squash it.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v8 0/5] Enable automatic SVN updates for SGX enclaves
2025-07-15 12:40 [PATCH v8 0/5] Enable automatic SVN updates for SGX enclaves Elena Reshetova
` (4 preceding siblings ...)
2025-07-15 12:40 ` [PATCH v8 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves Elena Reshetova
@ 2025-07-18 4:50 ` Huang, Kai
2025-07-18 12:02 ` Reshetova, Elena
5 siblings, 1 reply; 15+ messages in thread
From: Huang, Kai @ 2025-07-18 4:50 UTC (permalink / raw)
To: Reshetova, Elena, Hansen, Dave
Cc: seanjc@google.com, mingo@kernel.org, Scarlata, Vincent R,
x86@kernel.org, jarkko@kernel.org, Annapurve, Vishal,
linux-kernel@vger.kernel.org, Mallick, Asit K, Aktas, Erdem,
Cai, Chong, Bondarevska, Nataliia, linux-sgx@vger.kernel.org,
Raynor, Scott
On Tue, 2025-07-15 at 15:40 +0300, Elena Reshetova wrote:
> Changes since v7 following reviews by Dave:
>
> - change sgx_usage_count to be a normal int type
> and greatly simplify the sgx_inc_usage_count func.
> This results in requiring a mutex for each sgx_(vepc_)open
> but given that the mutex is held a short amount of
> time it should be ok perf-wise.
>
>
For this series:
Acked-by: Kai Huang <kai.huang@intel.com>
^ permalink raw reply [flat|nested] 15+ messages in thread* RE: [PATCH v8 0/5] Enable automatic SVN updates for SGX enclaves
2025-07-18 4:50 ` [PATCH v8 0/5] " Huang, Kai
@ 2025-07-18 12:02 ` Reshetova, Elena
0 siblings, 0 replies; 15+ messages in thread
From: Reshetova, Elena @ 2025-07-18 12:02 UTC (permalink / raw)
To: Huang, Kai, Hansen, Dave
Cc: seanjc@google.com, mingo@kernel.org, Scarlata, Vincent R,
x86@kernel.org, jarkko@kernel.org, Annapurve, Vishal,
linux-kernel@vger.kernel.org, Mallick, Asit K, Aktas, Erdem,
Cai, Chong, Bondarevska, Nataliia, linux-sgx@vger.kernel.org,
Raynor, Scott
> On Tue, 2025-07-15 at 15:40 +0300, Elena Reshetova wrote:
> > Changes since v7 following reviews by Dave:
> >
> > - change sgx_usage_count to be a normal int type
> > and greatly simplify the sgx_inc_usage_count func.
> > This results in requiring a mutex for each sgx_(vepc_)open
> > but given that the mutex is held a short amount of
> > time it should be ok perf-wise.
> >
> >
>
> For this series:
>
> Acked-by: Kai Huang <kai.huang@intel.com>
Thank you very much Kai for your reviews!
^ permalink raw reply [flat|nested] 15+ messages in thread