From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Hansen Subject: Re: [PATCH RFC] selftests/x86: Add a selftest for SGX Date: Tue, 13 Nov 2018 13:51:06 -0800 Message-ID: References: <20181113214038.16136-1-jarkko.sakkinen@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: In-Reply-To: <20181113214038.16136-1-jarkko.sakkinen@linux.intel.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Jarkko Sakkinen , x86@kernel.org, platform-driver-x86@vger.kernel.org, linux-sgx@vger.kernel.org Cc: sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com, shay.katz-zamir@intel.com, haitao.huang@intel.com, andriy.shevchenko@linux.intel.com, tglx@linutronix.de, kai.svahn@intel.com, Shuah Khan , Ingo Molnar , Dominik Brodowski , Andy Lutomirski , Dmitry Safonov , Florian Weimer , "Kirill A. Shutemov" , Suresh Siddha , open list , "open list:KERNEL SELFTEST FRAMEWORK" List-Id: platform-driver-x86.vger.kernel.org On 11/13/18 1:40 PM, Jarkko Sakkinen wrote: > +int main(int argc, char **argv) > +{ > + unsigned long bin_size = (unsigned long)&encl_bin_end - > + (unsigned long)&encl_bin; > + struct sgx_secs secs; > + uint64_t result = 0; > + > + if (!encl_load(&secs, bin_size)) > + exit(1); > + > + sgx_call((void *)&MAGIC, &result, (void *)secs.base); > + if (result != MAGIC) { > + fprintf(stderr, "0x%lx != 0x%lx\n", result, MAGIC); > + exit(1); > + } > + > + exit(0); > +} Well, I guess 100 lines of code for something a wee bit shy of hello world isn't bad. :) In general, this looks fine, but probably needs some better commenting and probably some messages that make it a bit more clear what is going on. It would be _nice_, for instance to try to do some CPUID detection of SGX so that the error (or success?) message can tell you whether you're missing hardware support or kernel support. Thanks for doing this, though. It's sorely needed.