Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7372318rwp; Tue, 18 Jul 2023 14:25:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlECzcITwAb+8YQ46qWegIxGH7RCDk0gLKjlspqw0wk3bd5DpENxqf3Kg3Qi7th7hum9W0YT X-Received: by 2002:ac2:4d96:0:b0:4f8:5905:8e0a with SMTP id g22-20020ac24d96000000b004f859058e0amr10129491lfe.6.1689715550594; Tue, 18 Jul 2023 14:25:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689715550; cv=none; d=google.com; s=arc-20160816; b=W63EjSBLiFMjmZJwEILkaSyhI/RVO9/BoeB2xLjEHotjxpxFC32wOaSFm3KVREm8jo pHqRjXn9lvq0NjHTHlRvJdYtnRZdLYUXGDkoe+9jBQpX3Nje5VvxdAp6XB5GRjHeyIF3 F/MLJxvE47/wRbpm5fjB2APSuVocr8AWbPVIec5vVso0akFAMhOISYLmcfnl7OL9VL6o iUTxPxMNB3VNQqkYBRmtDzxKBstxrkSh1R7/1lfPhdbHRAwJc/MXQiKc7r85r7KMLZ2W d9kfl66IkoONoxfsnd/OHaHumMdYmxbNEU/KhnvdwKBnnyokQp/KoRty2TdCdkHo+i6n 3NIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=LIuZnoczYPP2Z79rFC91IeeGAL2TzLHmnorCfvkNYMM=; fh=hMV+mtlsJvcyjTJTUYSmxFecCKL83Lw/BTgebaFJrWU=; b=mlZt3KXkmSbPi97EMCOuhOo4fp0wupk64aBQ0KZbCriKE4AIU8iRdFjBvEKZ1cI5kG bbjPk3Ri2PNyxAciH6rXzg6jOAJ/Bz0K64spmpW4JnX6b4BfOzEIKRZj5h5LDM2TTXNt a4lpRgw4pyXDJcjx8+u/KghmV3JKHnSwgTe0k1FZqpqgf/NHjHm8tiv8oWLUcYThKgoi ERXcIX8HQJ4aj9Cg1kur+P7Qi7iYSZ8BNsrt2Gt9Bvwb1pE4e+jQ9vY4GibEGh/JWChG ou091tA2zYQCoDEl3gGunuKM4L4iybLLT5y2Lzp/NcKeUNvrMgcDlen45NxsdsGZhF1N c4iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=norCXKuI; 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 s9-20020a056402164900b0051dd50ceaa3si1940702edx.180.2023.07.18.14.25.26; Tue, 18 Jul 2023 14:25:50 -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=norCXKuI; 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 S231153AbjGRU4b (ORCPT + 99 others); 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 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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 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