mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Elena Reshetova <elena.reshetova@intel.com>
Cc: jarkko@kernel.org, seanjc@google.com, kai.huang@intel.com,
	mingo@kernel.org, linux-sgx@vger.kernel.org,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	asit.k.mallick@intel.com, vincent.r.scarlata@intel.com,
	chongc@google.com, erdemaktas@google.com, vannapurve@google.com,
	bondarn@google.com, scott.raynor@intel.com
Subject: Re: [PATCH v10 5/6] x86/sgx: Implement ENCLS[EUPDATESVN]
Date: Fri, 1 Aug 2025 10:12:58 -0700	[thread overview]
Message-ID: <96866c15-2eb1-4df4-9e63-dfd5e40ecb91@intel.com> (raw)
In-Reply-To: <20250801112619.1117549-6-elena.reshetova@intel.com>

The changelog is missing a tidbit about the fact that this is still dead
code until sgx_inc_usage_count() gets a real implementation.

On 8/1/25 04:25, Elena Reshetova wrote:
...
> +/**
> + * 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.

As a general rule, I'd much rather have the "Must be $FOO" rules written
in code than in a comment, or along with a comment:

	/* EPC is guaranteed to be empty when there are no users: */
	WARN(count, "Elevated usage count...");

> + * Most of the time, there will be no update and that's OK.

This should go with the check for SGX_NO_UPDATE, not here.

> + * 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.

Ditto. This is rewriting the code in comments.

> + * 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;

There are four cases to handle. Doesn't it make sense to just write it
as four literal "case"s?

	switch (ret) {
	case 0:
		pr_info("...");
		return 0;
	case SGX_NO_UPDATE:
		return 0;
	case SGX_INSUFFICIENT_ENTROPY:
		return -EAGAIN;
	default:
		break;
	}


> +	ENCLS_WARN(ret, "EUPDATESVN");
> +	return -EIO;
> +}
> +
>  int sgx_inc_usage_count(void)
>  {
>  	return 0;


  reply	other threads:[~2025-08-01 17:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-01 11:25 [PATCH v10 0/6] Enable automatic SVN updates for SGX enclaves Elena Reshetova
2025-08-01 11:25 ` [PATCH v10 1/6] x86/sgx: Convert sgx_(vepc_)open to __sgx_(vepc_)open Elena Reshetova
2025-08-01 16:42   ` Dave Hansen
2025-08-04  7:16     ` Reshetova, Elena
2025-08-01 11:25 ` [PATCH v10 2/6] x86/sgx: Introduce functions to count the sgx_(vepc_)open() Elena Reshetova
2025-08-01 16:45   ` Dave Hansen
2025-08-04  7:18     ` Reshetova, Elena
2025-08-01 11:25 ` [PATCH v10 3/6] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag Elena Reshetova
2025-08-01 16:46   ` Dave Hansen
2025-08-01 11:25 ` [PATCH v10 4/6] x86/sgx: Define error codes for use by ENCLS[EUPDATESVN] Elena Reshetova
2025-08-01 16:57   ` Dave Hansen
2025-08-04  7:21     ` Reshetova, Elena
2025-08-04 14:19       ` Dave Hansen
2025-08-05 10:11         ` Reshetova, Elena
2025-08-01 11:25 ` [PATCH v10 5/6] x86/sgx: Implement ENCLS[EUPDATESVN] Elena Reshetova
2025-08-01 17:12   ` Dave Hansen [this message]
2025-08-04  7:39     ` Reshetova, Elena
2025-08-01 11:25 ` [PATCH v10 6/6] x86/sgx: Enable automatic SVN updates for SGX enclaves Elena Reshetova

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=96866c15-2eb1-4df4-9e63-dfd5e40ecb91@intel.com \
    --to=dave.hansen@intel.com \
    --cc=asit.k.mallick@intel.com \
    --cc=bondarn@google.com \
    --cc=chongc@google.com \
    --cc=elena.reshetova@intel.com \
    --cc=erdemaktas@google.com \
    --cc=jarkko@kernel.org \
    --cc=kai.huang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=scott.raynor@intel.com \
    --cc=seanjc@google.com \
    --cc=vannapurve@google.com \
    --cc=vincent.r.scarlata@intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®