Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7373245rwp; Tue, 18 Jul 2023 14:26:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlH6ayj6p6mmZeWwKrWo0RDuBewVtI1+M6ywXCT0whYe6VNPi/3kU1AgTs/aUHCgzNKfF3vt X-Received: by 2002:a17:906:51ca:b0:994:1fee:3066 with SMTP id v10-20020a17090651ca00b009941fee3066mr913832ejk.15.1689715615179; Tue, 18 Jul 2023 14:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689715615; cv=none; d=google.com; s=arc-20160816; b=mPZNbLkDzNEc/4B84QL5vd2fAGoUjBGiTW7iBaTpmllstiwKGxFloorcyXgdrH3sXi zfX+3aIvPG2Zhgkixt+2NWSRmUgxnTO7iQfa95rOJff3/AYZfciywv/RlPwUb7nmuNOQ 6io2m8mWTGfFHSg3iuiVs216/uWrq47VJu5MjvaHH+AvL4/BSKzTspAl/jibRfZIW94B vlFv4JkZpz2ynY0QhBTSDWEeCz7qOB1H5RGRsEu9AYfOXIQ3t1u2oUK007ZjkJT7wEL0 ydTOtqw05qR9Qgh1RSebj6hY6+1H4c7yJJulR1EmXZTMKEC9SaVN74m+iwjCrSEI7z3l cPbA== 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=h2TBQW+nTAXXp4+8dJ4ZDciMYW73dsZLNpgq1viAaNs=; fh=TkVbJDo0Vvtz8LjoRiW/5MO289g6kUpB9sJckopOxXI=; b=mtPmG5/HcPaqdfWW5+0YkEiUwXfGC74ijhZA0C90eMiVXz68h25nEpnwlaxh7ou6dI kany43MGpXzlclNUbxnX03Dp7vKaG0b29U8onF3u/UcMtCNMWtQLttiABhc19ylOi6Rm zeVsG0SfQCOJf2xXexwxebUPj9DU9Crw4+xqaKmH+xdM4TWG3w+F2zOKAYCMCmKAodBB B1cqj0Yfar3BjKTmVcfavrmhesw5+2daF3uOURSV48A6BnICfSNjVdwwBR1pUUv2/QI7 62EXx2rnbuFsY+MdOc2zXAtzkOXfi/yMdDSx7x+rfLu0xDV+OReKWkpMjgZiQ/Ta1fuX YFNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OW7mKFiY; 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 d11-20020a170906370b00b00992f45c9343si1652472ejc.1025.2023.07.18.14.26.30; Tue, 18 Jul 2023 14:26:55 -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=OW7mKFiY; 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 S230509AbjGRVWv (ORCPT + 99 others); Tue, 18 Jul 2023 17:22:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229656AbjGRVWt (ORCPT ); Tue, 18 Jul 2023 17:22:49 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AEF79D; Tue, 18 Jul 2023 14:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689715369; x=1721251369; h=to:cc:subject:references:date:mime-version: content-transfer-encoding:from:message-id:in-reply-to; bh=pjVJw6GiD8De53zFr+sIXnTzakqEin8Mim8XJ1OncwA=; b=OW7mKFiYpq7WXHOZlkqsG5JOgEhafpqVPmYIYji4/PwtesncsI9hiG1I Fj0gFMl380KI+Z9HFsu9pzketsZJlxPjKEzOXGy9K2yYEr4/5Vrhn1kCw FhSC1IENGNFiO003OmLAY9j9XlrgBW4utfgRaC0Q4/sEbsKv+f0qxVxFU 7shRCjdsCS0OtMeDcz+SLIcNN6ba/Nrfp+mCWlPB+2ZuOCIzyUlCRcHW5 Zpj56QTApSbNT3cuvRvyJEg3G9VwewU3Wxmt5b3wlS0WgNoqY/+Wr988F IZKJXg2u/3h1xTxT4k/mJa+BYk4zBlELvm16tMpAgDGUVq6bNGfPleZMW Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="363774372" X-IronPort-AV: E=Sophos;i="6.01,215,1684825200"; d="scan'208";a="363774372" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2023 14:22:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="847837663" X-IronPort-AV: E=Sophos;i="6.01,215,1684825200"; d="scan'208";a="847837663" Received: from hhuan26-mobl.amr.corp.intel.com ([10.92.48.113]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 18 Jul 2023 14:22:46 -0700 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: "Jarkko Sakkinen" , dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , x86@kernel.org, "H. Peter Anvin" , "Dave Hansen" Cc: kai.huang@intel.com, reinette.chatre@intel.com, kristen@linux.intel.com, seanjc@google.com, stable@vger.kernel.org Subject: Re: [PATCH] x86/sgx: fix a NULL pointer References: <20230717202938.94989-1-haitao.huang@linux.intel.com> Date: Tue, 18 Jul 2023 16:22:45 -0500 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Haitao Huang" Organization: Intel Message-ID: In-Reply-To: User-Agent: Opera Mail/1.0 (Win32) X-Spam-Status: No, score=-4.3 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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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, 18 Jul 2023 15:56:27 -0500, Dave Hansen wrote: > On 7/18/23 13:32, Haitao Huang wrote: > ... >> Ignore VA pages for now. Say for a system with 10 page EPC, 2 enclaves, >> each needs 5 pages non-SECS so total demand would be 12 pages. The ksgxd >> would only need to swap out 2 pages at the most to get one enclave fully >> loaded with 6 pages, and the other one with 4 pages. There is no chance >> the ksgxd would swap any one of two SECS pages. >> >> We would need at least one enclave A of 10 pages total to squeeze out >> the other B completely. For that to happen B pretty much has to be >> sleeping all the time so the LRU based reclaiming would hit it but not >> pages of A. So no chance to hit #PF on pages of B still. >> >> So some minimal pressure is needed to ensure SECS swapped. The higher >> the pressure the higher the chance to hit #PF while SECS is swapped. > > What would the second-to-last non-SECS page be? A thread control page? > VA page? > > As long as *that* page can generate a page fault, then you only need two > pages for this scenario to happen: > > 1. Reclaimer takes encl->lock > 2. #PF occurs from another thread, blocks on encl->lock > 3. SECS is reclaimed > 4. encl->lock released > 5. #PF sees reclaimed SECS > > I agree this is the race. But for this to happen, that is at #1 you have only one non-SECS page left so #3 can happen. That means it is already high pressure because reclaimer has swapped all other non-SECS. In my example of two enclaves of 5 non-EPC pages. #3 won't happen because you don't reach #1 with only one non-SECS left. Thanks Haitao