lkml.org 
[lkml]   [2019]   [Dec]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v24 06/24] x86/sgx: Add wrappers for ENCLS leaf functions
From
Date
On Tue, 2019-12-17 at 15:45 +0100, Borislav Petkov wrote:
> 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.

Absolutely. I absolutely hate too "clever code".

/Jarkko

\
 
 \ /
  Last update: 2019-12-19 01:40    [W:0.056 / U:2.144 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site