Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp471986pxk; Wed, 23 Sep 2020 07:51:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw71Yv+pb2qLEqUoaBG4bNo4GbVBPCjLq1j9w6wVF+yua9uFnFqL9d6dVOYvYfH872NySWg X-Received: by 2002:a17:907:2456:: with SMTP id yw22mr10374418ejb.337.1600872702075; Wed, 23 Sep 2020 07:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600872702; cv=none; d=google.com; s=arc-20160816; b=DtF2mAnCAO2gMP6d5e9Mdf7ovG1niie5iPaSqHPVk4aCvKFDcT9F26rtFVAiBI2EYv fEO1HyxzbAyDjznaEMcpEngNsse4gVD4mnJc4/dl6Upz4lkIQFBfVu8U7qP38FXSFvSx XBs8ALDttNbdF5+XTcUqMTiU5fYE0R/3mvV/Mb07uwn4IAA5KwDffkLVYlnurtZfqxlZ KGe6bcFNJtwZ1sRULRfb50RE7ugvcjqi9+PE6B6pss88NlNPM8pxAjVbSpAyU/xPZeaz INQfooCDJKflJVFj0PQCmX9pVDQKbpQ5NTtuNnpreXu/B9jX2s4nup5o3w9q6XgQyGkY 44aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:ironport-sdr :ironport-sdr; bh=HCaQ9ZSEsuRNHlVEZIV2d5GFJZeAEMvPSuTpTo1oJDk=; b=ohGp189jdbPyASyhfzB4KUSXDrf5C2409ETFgTDsu5XsWScvUrTWo8sIsU8/2WP4p8 lRlgeN7WO1gHTfPqyCVg4KWyDSMZtQyE0o0w0peSpWWWOqDQ08JdgIE5KB8lMVHKS5lY oL7H7/91CLbYVNxnHhzvXWIdSe/ahEHtpvwmKG/04WZLgmBoVm8RVk0h66UFP6kQ6Da+ +XuOPEEe82NOsG55TWsP7Pjmmxfb7Xa5jqRL6TLHgkpro8MZ3iF6Yac25yMgSurAlBbr A707ImvQe3lesZHBb1YpHkVT0PtNdno5lOhek8nhkZDkd0i9Mk5zUW0M70KwgcaJmdcr J1pQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id e9si25338edl.154.2020.09.23.07.51.14; Wed, 23 Sep 2020 07:51:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726656AbgIWOrQ (ORCPT + 99 others); Wed, 23 Sep 2020 10:47:16 -0400 Received: from mga02.intel.com ([134.134.136.20]:59208 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726156AbgIWOrQ (ORCPT ); Wed, 23 Sep 2020 10:47:16 -0400 IronPort-SDR: j6W3uEjE9Y+3k9zHsmzK4wHpMq25AsGUDSUcozhNIqmWB+BrOiRodR14Wv1aI/Vo+IvUykgixA r/twI1UvUjjA== X-IronPort-AV: E=McAfee;i="6000,8403,9753"; a="148555259" X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="148555259" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 07:47:16 -0700 IronPort-SDR: +Xbj246mPwIR7pSKj2Xz72hEM1umcXBC9/gNFta2Bio+n7wIj4HD2vUlCu2+KMNRXyxnLYDd3w 25GHJHBj+QqQ== X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="486464881" Received: from linortne-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.49.223]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 07:47:09 -0700 Date: Wed, 23 Sep 2020 17:47:07 +0300 From: Jarkko Sakkinen To: Borislav Petkov Cc: Jethro Beekman , Sean Christopherson , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Haitao Huang , Chunyang Hui , Jordan Hand , Nathaniel McCallum , Seth Moore , Darren Kenny , Suresh Siddha , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, josh@joshtriplett.org, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com Subject: Re: [PATCH v38 14/24] x86/sgx: Add SGX_IOC_ENCLAVE_INIT Message-ID: <20200923144707.GF5160@linux.intel.com> References: <20200915112842.897265-1-jarkko.sakkinen@linux.intel.com> <20200915112842.897265-15-jarkko.sakkinen@linux.intel.com> <20200921173514.GI5901@zn.tnic> <20200921181021.GA24481@linux.intel.com> <20200921182753.GK5901@zn.tnic> <20200921191658.GA24823@linux.intel.com> <20200922082918.GC22660@zn.tnic> <20200922142909.GI22660@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200922142909.GI22660@zn.tnic> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 22, 2020 at 04:29:09PM +0200, Borislav Petkov wrote: > On Tue, Sep 22, 2020 at 02:56:19PM +0200, Jethro Beekman wrote: > > I don't see why you'd need to retry indefinitely. Yes the MSRs may not > > match the cached value for “reasons”, but if after you've written > > them once it still doesn't work, clearly either 1) an “unhelpful” > > VMM is actively messing with the MSRs which I'd say is at best a VMM > > bug or 2) there was an EPC reset and your enclave is now invalid > > anyway, so no need to EINIT. > > /me likes that even more. OK, so I did not follow this particular discussion in high detail, so as a sanity check I'll preview my changes. I'd refine sgx_update_lepubkeyhash_msrs() to: static void sgx_update_lepubkeyhash_msrs(u64 *lepubkeyhash) { u64 *cache; int i; preempt_disable(); cache = per_cpu(sgx_lepubkeyhash_cache, smp_processor_id()); for (i = 0; i < 4; i++) { if (lepubkeyhash[i] != cache[i]) { wrmsrl(MSR_IA32_SGXLEPUBKEYHASH0 + i, lepubkeyhash[i]); cache[i] = lepubkeyhash[i]; } } preempt_enable(); } I'd drop sgx_einit() completely. Finally, in sgx_encl_init() I would call sgx_update_lepubkeyhash_msrs() directly: /* ... */ sgx_update_lepubkeyhash_msrs(mrsigner); ret = __einit(sigstruct, token, sgx_get_epc_addr(secs)); /* ... */ These staments would replace the call to sgx_einit(). Do I have the correct understanding? /Jarkko