From patchwork Thu Apr 21 11:03:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Cathy" X-Patchwork-Id: 12821471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DD0BC433EF for ; Thu, 21 Apr 2022 11:05:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231478AbiDULIe (ORCPT ); Thu, 21 Apr 2022 07:08:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388825AbiDULHx (ORCPT ); Thu, 21 Apr 2022 07:07:53 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70B8E3055D for ; Thu, 21 Apr 2022 04:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650539086; x=1682075086; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=/OYeFfhaL98wr7wOHl4mf2MKjSXpF9b8n7EMCgY88pI=; b=bAMAz0zxwKdCvAQLZK2K91oEQltThrhZmtT7udFpg33N6ZHVVCAsM7zJ TogRINgI/g/pUhMbebX+EenZ+FGyq+Q/BlBWhDjrjR7WsafdYBv2N1XsJ xV9wP3YL0+XiSyj6EyMwlZnc05EGv6m16FFMlZR05GOt+XqoLq7JKcXeZ xibAy9lFKudsUQvt8QalUzzefEmP8pKxG4mmVApc0GJBlHPGDYj+LEc0q +dfupJw6MggXKYfkoTStVMjXs+0GAgwI6Yb5Znla+sDwBXotyKViAKfCZ O5JNYecvkO/wU81gSrRZB2WwEEH1LnNPQUUGb/z4SRHdxUbER9Mk7HsgP A==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="324759119" X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="324759119" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2022 04:04:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="703039254" Received: from cathy-vostro-3670.bj.intel.com ([10.238.156.128]) by fmsmga001.fm.intel.com with ESMTP; 21 Apr 2022 04:04:42 -0700 From: Cathy Zhang To: linux-sgx@vger.kernel.org, x86@kernel.org Cc: jarkko@kernel.org, reinette.chatre@intel.com, dave.hansen@intel.com, ashok.raj@intel.com, cathy.zhang@intel.com, chao.p.peng@intel.com, yang.zhong@intel.com Subject: [PATCH v4 9/9] x86/sgx: Call ENCLS[EUPDATESVN] during SGX initialization Date: Thu, 21 Apr 2022 19:03:26 +0800 Message-Id: <20220421110326.856-10-cathy.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220421110326.856-1-cathy.zhang@intel.com> References: <20220421110326.856-1-cathy.zhang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org A snapshot of the processor microcode SVN is taken each boot cycle at the time when Intel SGX is first used. This results in microcode updates being loadable at any time, fixing microcode issues. However, if system boot up through kexec() from error recovery, no hardware reset happens, any SGX leaf execution during boot up is not assumed as the first use in such case, and no snapshot of SVN is taken. So, it's necessary to call ENCLS[EUPDATESVN] to update SVN automatically, rather than waiting for the admin to do it when he/she is even not aware of that. Call ENCLS[EUPDATESVN] after sanitizing pages will increase the chance of success, for it requires that EPC is empty. Signed-off-by: Cathy Zhang --- Changes since v3: - Rename as sgx_update_cpusvn_intel(). Changes since v1: - Update accordingly for update_cpusvn_intel() return *void*. --- arch/x86/kernel/cpu/sgx/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 20be96a79cc1..caf4f0db47f9 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -426,6 +426,7 @@ static bool sgx_should_reclaim(unsigned long watermark) !list_empty(&sgx_active_page_list); } +void sgx_update_cpusvn_intel(void); static int ksgxd(void *p) { int srcu_idx; @@ -440,7 +441,14 @@ static int ksgxd(void *p) __sgx_sanitize_pages(&sgx_dirty_page_list); /* sanity check: */ - WARN_ON(!list_empty(&sgx_dirty_page_list)); + if (!WARN_ON(!list_empty(&sgx_dirty_page_list))) { + /* + * Do SVN update for kexec(). It should complete without error, for + * all EPC pages are unused at this point. + */ + if (cpuid_eax(SGX_CPUID) & SGX_CPUID_EUPDATESVN) + sgx_update_cpusvn_intel(); + } while (!kthread_should_stop()) { if (try_to_freeze())