Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3812457pxb; Mon, 1 Feb 2021 05:31:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQbJR7kJmreWrMIo8GFzCtuSGc0ZnXJCAl86Q2/aU+HNaL/Py5cNIQUkilz+Z2sTv2brug X-Received: by 2002:a17:906:7c57:: with SMTP id g23mr17551815ejp.364.1612186297878; Mon, 01 Feb 2021 05:31:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612186297; cv=none; d=google.com; s=arc-20160816; b=TKVuuZ3lyM4F+iGzhU8gwOuVwAkfUUqdhnhgNnABK+hmcQuOkj4H4x1dNVErd8tafi cEF1iIlhfoEBZ5QooDyXX1cPkd5hVaK4t4XVNcANXfN6YmlKNjhfRTO0GEDjSfVJ/DSQ nbbRnJ5nPfrpYHnJr5P3QiS30XWNCnuch6DT9MBQY91C45mQcSTAC1QXcNf6VST3Nba9 fv7qZE79K/buxAE1/XKZVSuY/C4+9PFmtOmvfvse8KwXNqf/DT/wJuVsdKiKTs5Pi3ef vJAAG2NU0qWEIkIgUNmP4U0XBwO5lKBNiwoZ485BN/nHM8Jieel2mvPBJpZM7NfxzA0R dlYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ah/dLCDvVDaXQRVU/RJJIotWWiGDRW7lvyEpMj0LCjI=; b=rzoNQbrPsdJWlvXGEF/NzFP/VKHWMxsYIy1liYYDSFlopMdzZH6flDu2ExgAbzyuZ4 Ktcrx28dml6VPS64jEpkfQGIjwRRtnGo9/S3MT3LB004TgTWt0+q4IXpXRAAEewNxxuc 2pmtx4P+gA2GyLjQXndT55v91BMH9evJpwM4urYEusl16Zx5D+hCwSh6MgKJLceb1EV4 paMer0dtGVYkqLTzgKYT7FLRgOJy95wQhMwz1mVNpcdSdiqx9pXe6qFeVZHIt0578Gkb XPfjxlEq6nazmSS1Xz7nGcFukoet/2dstjI9K2LUpZ+rGUPs6mMNqV+QEMcyilOlMlUP hLdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d30si11468390edd.488.2021.02.01.05.31.04; Mon, 01 Feb 2021 05:31:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232261AbhBAN3c (ORCPT + 99 others); Mon, 1 Feb 2021 08:29:32 -0500 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:47747 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231776AbhBAN2i (ORCPT ); Mon, 1 Feb 2021 08:28:38 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R731e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04420;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0UNbByqi_1612186014; Received: from localhost(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0UNbByqi_1612186014) by smtp.aliyun-inc.com(127.0.0.1); Mon, 01 Feb 2021 21:26:54 +0800 From: Tianjia Zhang To: Jarkko Sakkinen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Sean Christopherson , Shuah Khan , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Jia Zhang Cc: Tianjia Zhang Subject: [PATCH v4 3/5] x86/sgx: Optimize the free_cnt count in sgx_epc_section Date: Mon, 1 Feb 2021 21:26:51 +0800 Message-Id: <20210201132653.35690-4-tianjia.zhang@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.3.ge56e4f7 In-Reply-To: <20210201132653.35690-1-tianjia.zhang@linux.alibaba.com> References: <20210201132653.35690-1-tianjia.zhang@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'section->free_cnt' represents the free page in sgx_epc_section, which is assigned once after initialization. In fact, just after the initialization is completed, the pages are in the init_laundry_list list and cannot be allocated. This needs to be recovered by EREMOVE of function sgx_sanitize_section() before it can be used as a page that can be allocated. The sgx_sanitize_section() will be called in the kernel thread ksgxd. This patch moves the initialization of 'section->free_cnt' from the initialization function sgx_setup_epc_section() to the function sgx_sanitize_section(), and then accumulates the count after the successful execution of EREMOVE. This seems to be more reasonable, free_cnt will also truly reflect the allocatable free pages in EPC. Sined-off-by: Tianjia Zhang Reviewed-by: Sean Christopherson --- arch/x86/kernel/cpu/sgx/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 4465912174fd..e455ec7b3449 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -48,6 +48,7 @@ static void sgx_sanitize_section(struct sgx_epc_section *section) if (!ret) { spin_lock(§ion->lock); list_move(&page->list, §ion->page_list); + section->free_cnt++; spin_unlock(§ion->lock); } else list_move_tail(&page->list, &dirty); @@ -643,7 +644,6 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, list_add_tail(§ion->pages[i].list, §ion->init_laundry_list); } - section->free_cnt = nr_pages; return true; } -- 2.19.1.3.ge56e4f7