Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp803714imn; Tue, 26 Jul 2022 09:42:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uNr9QBkaTEnfMLHok1ljc0dEuDb0NWv12j3Rcrx1EfZOotAJWPlkJ3QJ/G+oolC6MWV3Hp X-Received: by 2002:a17:902:f816:b0:16d:2da8:64bc with SMTP id ix22-20020a170902f81600b0016d2da864bcmr17622359plb.60.1658853739988; Tue, 26 Jul 2022 09:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658853739; cv=none; d=google.com; s=arc-20160816; b=MIOF0zVhYacL4GUPSrFjuHwflvQwh3I7FjAojwMIhiklHKKEUhBwzwzGld9jwczQZJ AKBnYLSW6Xc/byWaZrfu7JMhReSdrI/00+zvyX8U0Gg4E0ef0CiM/Q6elhJUSTvb0KW/ NLqZOARm6OXR4e1A5iY2PpkQOgcM0Q5+CFMllilyyKn4fuZ+/EhnUUlqplvQsRs2yQT8 L/fh17PjgXZaY/2zoIxGpkwP+HexeDnHsHae3YgaTzk+cqt/x8JY6PuHKICKgRA/mYt8 ZcmMMYa1wTZinzQJhqP+VoPBBomM8+UTMMX7YTfy1jNb9JiId+1WI3ZgEp9+hImDYMAc 9bWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:message-id:organization :from:content-transfer-encoding:mime-version:date:references:subject :cc:to:dkim-signature; bh=e+1eyRA1DMd9+AumO0qge58slzt+jaOq4BJhEZde118=; b=yf38nQHmD98qqt5xt3mBG4x1zO6HMMq+Rphi72xMPWvDVQcMF0E0K9E7wRDKo0EDOs blv5RSH3QrUppkkd7VwKNkcKidknr4qpN4UP6Um7eVCpdjejPzpS7xhCr8/AHdRcduF/ m1JEE1xmKupbthktXLcQs1PJFvBSxXOAmU4AEwJ3T+LOJoq8Jy2IIVWBEOKICu7ES11F DKnfSvrGpkJMprUgnulyeCH7zoTaPmJrs0r/dHRY3kINLTiywqecicsc3CyU2RxLLv3N rb1jdtIa3CJi6a8QBwn+/ZKCjOv+QyMqq1CDoA9q0+94kuJ5KDMKX5h3/Qw7GCql4sD8 7kyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ebFjznKk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a170902db0c00b0016d6afdef20si9157477plx.231.2022.07.26.09.42.03; Tue, 26 Jul 2022 09:42:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ebFjznKk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234240AbiGZP3H (ORCPT + 99 others); Tue, 26 Jul 2022 11:29:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbiGZP3G (ORCPT ); Tue, 26 Jul 2022 11:29:06 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EB3FDFCF; Tue, 26 Jul 2022 08:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658849345; x=1690385345; h=to:cc:subject:references:date:mime-version: content-transfer-encoding:from:message-id:in-reply-to; bh=/PrORd58ALKhiuN1jepHSSL1AFYlYZW+6m1cjPphYV4=; b=ebFjznKkVXP1lmcLG0yIt4Essxz05N1hiO3USrePFAyCJOW9Z7S6DTbX xOnpzybzWJ9DbCF7NcWGzhNqdpzgr9rxgtcLqC0QDATCYcxwYxtuNBGeO JWmSEANlbO5qjZkOwBT853GNjLrn4TbQo/+jFsug/9frmdZlk8bIXe2A/ RofRUOQ8rfzb+fHby7HD/qDVh4Y4iHsW7rRnlSEPdKWR9wcxOEvpexDaW KaGSy+s4wA8IkZOWb4cGMpAWiRymzNTkQzqJac2lAv48EenFHNuiM9lzS DsL7EeM1Dv80owKcneQVNVTDYDAN27cKxUy52zBOaQ73r+B6ibBiNxPqU A==; X-IronPort-AV: E=McAfee;i="6400,9594,10420"; a="286738891" X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="286738891" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2022 08:29:05 -0700 X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="575534287" Received: from hhuan26-mobl1.amr.corp.intel.com (HELO hhuan26-mobl1.mshome.net) ([10.212.15.50]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 26 Jul 2022 08:29:03 -0700 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: "Dave Hansen" , "Dave Hansen" , "Kai Huang" Cc: "Jarkko Sakkinen" , "Andy Lutomirski" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "H. Peter Anvin" , "Sean Christopherson" , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] [v2] x86/sgx: Allow enclaves to use Asynchrounous Exit Notification References: <20220720191347.1343986-1-dave.hansen@linux.intel.com> <06a9fef8579e880b9b031f03911739d4d902dbe0.camel@intel.com> <4c614defad8e9ce2bccce8a062600212e4978113.camel@intel.com> Date: Tue, 26 Jul 2022 10:28:19 -0500 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Haitao Huang" Organization: Intel Corp Message-ID: In-Reply-To: <4c614defad8e9ce2bccce8a062600212e4978113.camel@intel.com> User-Agent: Opera Mail/1.0 (Win32) X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 Jul 2022 05:47:14 -0500, Kai Huang wrote: > On Tue, 2022-07-26 at 00:10 -0500, Haitao Huang wrote: >> On Mon, 25 Jul 2022 05:36:17 -0500, Kai Huang >> wrote: >> >> > On Fri, 2022-07-22 at 08:21 -0700, Dave Hansen wrote: >> > > On 7/22/22 06:26, Kai Huang wrote: >> > > > Did a quick look at the spec. It appears ENCLU[EDECCSSA] should >> be >> > > used >> > > > together with AEX-notify. So besides advertising the new >> > > > SGX_ATTR_ASYNC_EXIT_NOTIFY bit to the KVM guest, I think we should >> > > also >> > > > advertise the ENCLU[EDECCSSA] support in guest's CPUID, like below >> > > (untested)? >> > > >> > > Sounds like a great follow-on patch! It doesn't seem truly >> functionally >> > > required from the spec: >> > > >> > > > EDECCSSA is a new Intel SGX user leaf function >> > > > (ENCLU[EDECCSSA]) that can facilitate AEX notification handling... >> > > >> > > If that's wrong or imprecise, I'd love to hear more about it and >> also >> > > about how the spec will be updated. >> > > >> > >> > They are enumerated separately, but looks in practice the notify >> handler >> > will >> > use it to switch back to the correct/targeted CSSA to continue to run >> > normally >> > after handling the exit notify. This is my understanding of the >> > "facilitate" >> > mean in the spec. >> > >> > Btw, in real hardware I think the two should come together, meaning no >> > real >> > hardware will only support one. >> > >> > Haitao, could you give us more information? >> > >> You are right. They are enumerated separately and HW should come with >> both >> or neither. >> My understanding it is also possible for enclaves choose not to receive >> AEX notify >> but still use EDECCSSA. >> > > What is the use case of using EDECCSSA w/o using AEX notify? > If I understand correctly EDECCSSA effectively switches to another > thread (using > the previous SSA, which is the context of another TCS thread if I > understand > correctly). Won't this cause problem? No. Decrementing CSSA is equivalent to popping stack frames, not switching threads. In some cases such as so-called "first stage" exception handling, one could pop CSSA back to the previous after resetting CPU context and stack frame appropriate to the "second stage" or "real" exception handling routine, then jump to the handler directly. This could improve exception handling performance by saving an EEXIT/ERESUME trip. > > It probably makes sense to use only AEX notify w/o using EDECCSSA > though, but > this should be the case that the enclave detects serious attack and > don't want > to continue to run normally. In another words, it is enclave's choice, > but > hardware should always support both AEX notify and EDECCSSA.