From mboxrd@z Thu Jan 1 00:00:00 1970 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 ED952EB64DD for ; Tue, 18 Jul 2023 20:56:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231140AbjGRU4b (ORCPT ); Tue, 18 Jul 2023 16:56:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231135AbjGRU4a (ORCPT ); Tue, 18 Jul 2023 16:56:30 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76F75BD; Tue, 18 Jul 2023 13:56:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689713788; x=1721249788; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=L2CHxsdqnuMK/0tTAv6QiGDs4KnYWikJEDc+5R9q3y0=; b=norCXKuIqDkYtRAyqLibra2b/IiQ8n3fgdGxD5yua8L5UWayNcdmbmIp V2EBSFW4eapd4JsB7C8VAiDS0PBy3E/j51/pngLsG6LLPyhWgRxKILwwl SCpHuUBpJzpKi8dBP0hIDTenwYEcAc0xvWBL7ThU3LakCwFo+t2QKe5GE oIW/MQL6h10hMBpLP32YbDqwpkAi0DNPi5o6D31wOc4nVkhdKxiUpjNfo 5mC5qpECu2qVJCPQtN6/ZXsnip859IG3UFIfzfqIZ9zWcYhnfGn87rc7U VA1/lCwYNU4NTtZP1BbSzOngEBnIaPkdQggNdf1oIw7WNfo22fTQIaIyF g==; X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="397158587" X-IronPort-AV: E=Sophos;i="6.01,215,1684825200"; d="scan'208";a="397158587" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2023 13:56:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="789203306" X-IronPort-AV: E=Sophos;i="6.01,215,1684825200"; d="scan'208";a="789203306" Received: from unknown (HELO [10.209.37.195]) ([10.209.37.195]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2023 13:56:28 -0700 Message-ID: Date: Tue, 18 Jul 2023 13:56:27 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH] x86/sgx: fix a NULL pointer Content-Language: en-US To: Haitao Huang , 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" Cc: kai.huang@intel.com, reinette.chatre@intel.com, kristen@linux.intel.com, seanjc@google.com, stable@vger.kernel.org References: <20230717202938.94989-1-haitao.huang@linux.intel.com> From: Dave Hansen In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org 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