Re: [PATCH v24 06/24] x86/sgx: Add wrappers for ENCLS leaf functions

From: Borislav Petkov
Date: Tue Dec 17 2019 - 09:45:58 EST


On Sat, Nov 30, 2019 at 01:13:08AM +0200, Jarkko Sakkinen wrote:
> +/**
> + * encls_failed() - Check if an ENCLS leaf function failed
> + * @ret: the return value of an ENCLS leaf function call
> + *
> + * Check if an ENCLS leaf function failed. This happens when the leaf function
> + * causes a fault that is not caused by an EPCM conflict or when the leaf
> + * function returns a non-zero value.
> + */
> +static inline bool encls_failed(int ret)
> +{
> + int epcm_trapnr =
> + boot_cpu_has(X86_FEATURE_SGX2) ? X86_TRAP_PF : X86_TRAP_GP;
> + bool fault = ret & ENCLS_FAULT_FLAG;
> +
> + return (fault && ENCLS_TRAPNR(ret) != epcm_trapnr) || (!fault && ret);
> +}

Can we make this function more readable?

static inline bool encls_failed(int ret)
{
int epcm_trapnr;

if (boot_cpu_has(X86_FEATURE_SGX2))
epcm_trapnr = X86_TRAP_PF;
else
epcm_trapnr = X86_TRAP_GP;

if (ret & ENCLS_FAULT_FLAG)
return ENCLS_TRAPNR(ret) != epcm_trapnr;

return !!ret;
}

I hope I've converted it correctly but I might've missed some corner
case...

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette