Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp559962ybh; Wed, 11 Mar 2020 06:29:13 -0700 (PDT) X-Google-Smtp-Source: ADFU+vto4taEvsa8F7L7RlG8fv4uLNZfd/+V/9YPJ0G+kG1N86kYONPCL2SYF70+pszSByqChk8+ X-Received: by 2002:a05:6830:1e4e:: with SMTP id e14mr2384015otj.108.1583933353391; Wed, 11 Mar 2020 06:29:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583933353; cv=none; d=google.com; s=arc-20160816; b=YmbVnIS0uNqycjNkzMcspUI48K3Uckc1bajmUZb5ykqovMNu8Av0ZKfpzhycMywd83 62LCcA519ypaloIqSwJpf8BAwnGFHjLjZiezA6eL6h/HVcNnYIBIzUqdxCaFsZ+qy6FB 8cZZcz9OP/ua0F1EDMTFyuUXbKJVcRjWuYV/EorCy/yK2qTX37zTq7oLVOuACTAfuv5c jvYKEiAjSxPZ0KWXd4vDKpeP9t1vaimLvyE7re2TiL85K2fgl/7jtDvqCzvxmSs+Moel L3/dWwbrfjDijdwEYLDIynIDinlzVBQ0Ew6kHmjpLxf1hcD49Fgc7knTKdb1cwvDaJdv 8X3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8MdAuTT/Rra1eqQ5xgj8r6S4O0mwD6qkp3rOiZ+rYXU=; b=D1rf5gI2XPw1Zn33FSYyn38b1H3EgIgtQHpPgcKUhpRSF5c5x86FemzU2L3NDL605y Zqt6adqRmhiwfnt7fuLMIA28Dn52qBXJhjcSZ1AjdW5YH8W8BeYfAOochBrRXfQoW77M Iv1YqmcLuZJ+TzTLg/JZnCqPFUwjq5a1emSKUqmlptzul9gD/KsMFguQneBuuFR2taUr KxRbx9z8zBCQhDBKXS+C4Ow9wfXRjviYHEmylhN5nFud2C/IqpQu6rOyr4Z282NXc9oz EW/bPTgvPBVaH4NO2nR9Fy5xC/x0Fm5xxKp2BJ/eaTTKjAqbGx8mUnI19AR4Qy0KrwND IYuA== 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 f3si1008976oia.264.2020.03.11.06.29.01; Wed, 11 Mar 2020 06:29:13 -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 S1729532AbgCKN2m (ORCPT + 99 others); Wed, 11 Mar 2020 09:28:42 -0400 Received: from mga09.intel.com ([134.134.136.24]:27576 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729103AbgCKN2l (ORCPT ); Wed, 11 Mar 2020 09:28:41 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Mar 2020 06:28:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,541,1574150400"; d="scan'208";a="236284341" Received: from jarea-mobl.ger.corp.intel.com (HELO localhost) ([10.252.13.203]) by fmsmga008.fm.intel.com with ESMTP; 11 Mar 2020 06:28:33 -0700 Date: Wed, 11 Mar 2020 15:28:32 +0200 From: Jarkko Sakkinen To: Nathaniel McCallum Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org, akpm@linux-foundation.org, dave.hansen@intel.com, "Christopherson, Sean J" , 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: <20200311132832.GA75185@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <04362c0cf66bf66e8f7c25a531830b9f294d2d09.camel@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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