Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2211463pxb; Sat, 23 Jan 2021 22:33:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJztQeQqGtRUXGEyY14P6HcD92tJU1jYLOFKmIB3UPzA8j+RT2w2n3BXaab/0cMk3hRw0mIw X-Received: by 2002:aa7:c983:: with SMTP id c3mr474120edt.327.1611470039093; Sat, 23 Jan 2021 22:33:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611470039; cv=none; d=google.com; s=arc-20160816; b=TOVB89nnsQkTX4J0S6DyOpVFqAACpDcrdDrBF4V8z64jyXyd5gYq/+eUELObqRNABG Dxy1JsPgjmYXgxkwHxyv1PlPeO/SWaBEf7z0DMsgtbdK0rXUTYzfWfxN0Ott9yQxtWs9 abuYRCA2HhCXs+xqHHwpMxqL6C9YcKwPkjo7YVq/pNxvw66vmnE2oP/4hBC0hfMUza4v 4vmObZrDYgA0GEZZOKZUOYUboF82dz1abxOLIsMxjudJVcBi6Ia/QgefcwVEt5U2j0Zl cGWrtgOj1YAkViMOaTrIOIWsZdt7VnE2b6lxjdunCThzYu8prJ//0HQGOnwSkv6gCKZZ KZpQ== 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=JPc+1jYlCLi/PDK2qJFLZxXU9Y+iMBVEL2gzQpWfh3k=; b=oyGU31+hGdpWf6guM2hWCgpEGY9X95LVLxZ53PztgnA84M4bJPzA/V16N2RLTyM7Rm wm9J1qq55j6L0BahxufES8ryB3RODYaXgOp1iMzNUCfrMB2cRjp09RfkFH4rE4gJJERO J940e13TarC6TM950qYyDNPhlZSmjmE1isbA8Qt4JTuemMvMEeK1R2CiEOOh5a4EDrnM KLRi7Zqq3lF8QWp/KsyWXBFDBHCCyDxEn4jROSvHvQVfrq+vU4PqIp6J1Rv4Ax2IpiBo HKb7ZHDsbdaZgAJo2I9fxyUbDQpTz/NYrqNs4dEKKMWrx3XjEiDjHK7o7j6CPwuUtZ7e P/KA== 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 x20si6006253eds.7.2021.01.23.22.33.36; Sat, 23 Jan 2021 22:33:59 -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 S1726565AbhAXGam (ORCPT + 99 others); Sun, 24 Jan 2021 01:30:42 -0500 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:42676 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726054AbhAXGah (ORCPT ); Sun, 24 Jan 2021 01:30:37 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;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_---0UMf9yuo_1611469749; Received: from localhost(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0UMf9yuo_1611469749) by smtp.aliyun-inc.com(127.0.0.1); Sun, 24 Jan 2021 14:29:09 +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 v3 3/5] x86/sgx: Optimize the free_cnt count in sgx_epc_section Date: Sun, 24 Jan 2021 14:29:05 +0800 Message-Id: <20210124062907.88229-4-tianjia.zhang@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.3.ge56e4f7 In-Reply-To: <20210124062907.88229-1-tianjia.zhang@linux.alibaba.com> References: <20210124062907.88229-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