Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp732652ybh; Wed, 11 Mar 2020 09:41:41 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs5ZqPTHSkxYFEqhUvMb63ydmQXrTNgtGdRQaEgRqECYtUqJswTCh20T+QTSlnGCmcZRdzj X-Received: by 2002:a9d:d0f:: with SMTP id 15mr3129945oti.161.1583944901719; Wed, 11 Mar 2020 09:41:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583944901; cv=none; d=google.com; s=arc-20160816; b=viq8zpsMAlIcnOGPlbaAqghzqZhsav7DHSKlHMCvaoDdK1m4G9akCUYkD7I5eSWG2/ r+qWI8dkScGH8a9Mdxh392Pw4ks2Wl2ySftzrvXgi+d7E56UW4uMTfMPCzMRtMQWWAEB RCsnEWtkPZcumFYQBP+4up+MAe+BFh7jYnVhifurWHlEwKpYme0zF5lRFAD1h+DtUzih 3D4oKDajGqavaa3NOtXYHtrNSEztvErUWcNradp31X6Epq7ARXMFdzjHj8TKcZh7xYtg krWFQDANqzYtvTMZMM5eQw1UBNNHpaARLr6NxMB+/23g7uywuFpXZzh6i9iIBBQVc3ph HEXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=mRe2Y9zVvQnp/9JE2Xy7V74jCRkWAxE1+VbPQFdWzYg=; b=eG4XcSxng0udaiKch3rDYYxzBqKO+IU1BhOhgZfZIoEGF0/iXoDFm0hUmzledCJ5zd OtnyC3V9MRokYjy9eHFiBfaxD7oMb6VE0CATUC7lR75BE/b8l4YBzvENkPR5hBi+X816 xJ1Q67s0g5LrdbNgt8Cfr3ipF5C6J1lKDzvz08MASDAclv2UfmHQii18RTY/4WE99oBA SsmSeYLB//UwWDNqhQm/RacY0cQaondUcHfMzdXjIlKhRSR1BM311/i8tCZsIlbECoIz 9NqQuzIKjZAIR4t9ujE4emFqZBo2hw5GM/P1A4Z/dJj3ypEtGXNOivu7tLjbZ+YG2bi6 /Ugw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si1456255ota.239.2020.03.11.09.41.29; Wed, 11 Mar 2020 09:41:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730201AbgCKQkt (ORCPT + 99 others); Wed, 11 Mar 2020 12:40:49 -0400 Received: from mga01.intel.com ([192.55.52.88]:14056 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726314AbgCKQkt (ORCPT ); Wed, 11 Mar 2020 12:40:49 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Mar 2020 09:40:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,541,1574150400"; d="scan'208";a="246083979" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by orsmga006.jf.intel.com with ESMTP; 11 Mar 2020 09:40:47 -0700 Date: Wed, 11 Mar 2020 09:40:47 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: Nathaniel McCallum , linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org, akpm@linux-foundation.org, dave.hansen@intel.com, Neil Horman , "Huang, Haitao" , andriy.shevchenko@linux.intel.com, tglx@linutronix.de, "Svahn, Kai" , bp@alien8.de, Josh Triplett , luto@kernel.org, kai.huang@intel.com, rientjes@google.com, cedric.xing@intel.com, Patrick Uiterwijk , linux-kselftest@vger.kernel.org Subject: Re: [PATCH v28 14/22] selftests/x86: Add a selftest for SGX Message-ID: <20200311164047.GG21852@linux.intel.com> References: <20200303233609.713348-1-jarkko.sakkinen@linux.intel.com> <20200303233609.713348-15-jarkko.sakkinen@linux.intel.com> <04362c0cf66bf66e8f7c25a531830b9f294d2d09.camel@linux.intel.com> <20200311132832.GA75185@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200311132832.GA75185@linux.intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 11, 2020 at 03:28:32PM +0200, Jarkko Sakkinen wrote: > On Thu, Mar 05, 2020 at 01:33:28PM +0200, Jarkko Sakkinen wrote: > > On Wed, 2020-03-04 at 14:27 -0500, Nathaniel McCallum wrote: > > > > > +xsave_area: > > > > + .fill 1, 4, 0x037F # FCW > > > > + .fill 5, 4, 0 > > > > + .fill 1, 4, 0x1F80 # MXCSR > > > > + .fill 1, 4, 0xFFFF # MXCSR_MASK > > > > + .fill 123, 4, 0 > > > > + .fill 1, 4, 0x80000000 # XCOMP_BV[63] = 1, compaction mode > > > > + .fill 12, 4, 0 > > > > > > I find this much more readable: > > > > And I always aim to get things more readable. Thank you. > > > > > xsave_area: > > > # Legacy > > > .fill 1, 4, 0x037F # FCW > > > .fill 5, 4, 0 > > > .fill 1, 4, 0x1F80 # MXCSR > > > .fill 1, 4, 0xFFFF # MXCSR_MASK > > > .fill 60, 8, 0 > > > > > > # Header > > > .fill 1, 8, 0 # XSTATE_BV > > > .fill 1, 8, 1 << 63 # XCOMP_BV (compaction mode) > > > .fill 6, 8, 0 > > > > > > Also, since people are likely to copy this code for their own > > > enclaves, it would be helpful to document which flags are set in FCW > > > and MXCSR. > > > > It was meant as a test program but I'd guess what you say is true > > because it also might be the only alternative user space to Intel's > > :-) And a great starting point if you want to do things from scratch. > > > > Because I meant it as a smoke test program for SGX, not everything is > > too well documented but given the multipurpose use for that code I'll > > make the improvements that you are suggesting. > > For FPU Control World (FCW), I think 0x037F is not the right value even > if section 18.5 in the x86 SDM says that it is the initial value for it. > > I took that value from that section. > > The reason I think that there is an error in the SDM is that if you look > at the section 8.1.5, you'll see that bit 6 is a reserved bit. Thus, > does not make to set it on. > > I think the legit value ought to be 0x33F i.e. unset bit 6. Bit 6 is reserved, but it's forced to '1' by the CPU. Regardless, IMO it'd be better to drop this code entirely, it's all kinds of wonky. The label says "xsave_area" and implies XSAVE state is being loaded, but the code uses FXRSTOR, which will only load x86/MMX/XMM state, i.e. the first 512 bytes of the so called xsave_area. The test enclave doesn't touch state managed by XSAVE, let alone put secrets into said state. I see no reason to bother purging anything. > In any case check: > > https://raw.githubusercontent.com/jsakkine-intel/linux-sgx/master/tools/testing/selftests/x86/sgx/encl_bootstrap.S > > I.e. both have now a reference: > > 1. To the section that describes the default. > 2. To the section that describes what the bits mean. > > /Jarkko