Re: [PATCH v9 6/6] x86/sgx: Enable automatic SVN updates for SGX enclaves

From: Huang, Kai
Date: Thu Jul 24 2025 - 06:19:07 EST



> /* Counter to count the active SGX users */
> static int __maybe_unused sgx_usage_count;

Seems you forgot to remove this __maybe_unused.

I think you can just introduce 'sgx_usage_count' in this patch.

>
> +/* 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 __maybe_unused 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,12 +986,17 @@ static int __maybe_unused sgx_update_svn(void)
>
> int sgx_inc_usage_count(void)
> {
> + guard(mutex)(&sgx_svn_lock);
> +
> + if (sgx_usage_count++ == 0)
> + return sgx_update_svn();
> +
> return 0;
> }
>
> void sgx_dec_usage_count(void)
> {
> - return;
> + sgx_usage_count--;
> }
>
> static int __init sgx_init(void)
> --
> 2.45.2