On Fri, Oct 04, 2019 at 11:45:13AM +0200, Borislav Petkov wrote:
> On Tue, Sep 03, 2019 at 05:26:38PM +0300, Jarkko Sakkinen wrote:
> > +/**
> > + * ENCLS_FAULT_FLAG - flag signifying an ENCLS return code is a trapnr
> > + *
> > + * ENCLS has its own (positive value) error codes and also generates
> > + * ENCLS specific #GP and #PF faults.  And the ENCLS values get munged
> > + * with system error codes as everything percolates back up the stack.
> > + * Unfortunately (for us), we need to precisely identify each unique
> > + * error code, e.g. the action taken if EWB fails varies based on the
> > + * type of fault and on the exact SGX error code, i.e. we can't simply
> > + * convert all faults to -EFAULT.
> > + *
> > + * To make all three error types coexist, we set bit 30 to identify an
> > + * ENCLS fault.  Bit 31 (technically bits N:31) is used to differentiate
> > + * between positive (faults and SGX error codes) and negative (system
> > + * error codes) values.
> > + */
> > +#define ENCLS_FAULT_FLAG 0x40000000
> 
> BIT(30)

This is intentionally open coded so that it can be stringified in asm.
Alternatively, the asm could use the raw value or a different define.  Is
there a third option?

#define __encls_ret_N(rax, inputs...)                           \
        ({                                                      \
        int ret;                                                \
        asm volatile(                                           \
        "1: .byte 0x0f, 0x01, 0xcf;\n\t"                        \
        "2:\n"                                                  \
        ".section .fixup,\"ax\"\n"                              \
        "3: orl $"__stringify(ENCLS_FAULT_FLAG)",%%eax\n"       \  <----
        "   jmp 2b\n"                                           \
        ".previous\n"                                           \
        _ASM_EXTABLE_FAULT(1b, 3b)                              \
        : "=a"(ret)                                             \
        : "a"(rax), inputs                                      \
        : "memory", "cc");                                      \
        ret;                                                    \
        })

Reply via email to