Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1154582rwb; Thu, 22 Sep 2022 10:48:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6NX6Fg5j/0urA/QXgdtjaxpohn8h2hHLVT9EMOIIllz3RmBJH+ut93CvjQHbIf3dfDRikd X-Received: by 2002:a17:90a:e7d2:b0:200:a220:6495 with SMTP id kb18-20020a17090ae7d200b00200a2206495mr4981818pjb.5.1663868892722; Thu, 22 Sep 2022 10:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663868892; cv=none; d=google.com; s=arc-20160816; b=yqMkKUxBa3AqR+6QkfdTtccHZkjCwI9T4nIYx967cjQTWiqjo2UkgV8MY2yw7XEmlI /zmv7P2XFbp82nh9T6TJGHFHaJA6JSA3JzBy52OyB9nBGKgjYKuIDyFF8NO4dEO0+SQJ MiMZvuB6WACZe8i1jdkT9U/8yhRPxRMzzL0kpeyn/lIrp/vz4yapVx8HizbIuFxY9722 SzmQTHdjdwRR7RkHPiOQYWHhcFrOa8hPpjeom/VzUoeDUIxtbMMAoyeX8yXiF98YNyy6 5/JpE7RLYfzltGa9ExRX4OB2IO9Er86XD9zf7wV/VSdju2I1jIbnhoCzvnZqDAWC4zLG j/cA== 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 :dkim-signature; bh=Bfha7FIW8W02Qngx9HWNLByiqf/PCcLrhONYw68pKx0=; b=stuWnjOOiN48v50Wvks84hea6xxCEWOmqCY3rtCNC5f6HRpB1RtknAxDvQuGp7aHyZ g/aALJZErSFRn8L9SOOmxuuDfQdPpsr/OyUfBMne879q+zHQPy99aw9CiDhyX2pwSQha bxPq3PrvIqJ2V6iHj1UQW+E3PYEIIUceK1y0lYlzpoY6hHmoXz4pg1dXfUw/kVPo/JFK 5jp8XiWnotIjJkrrNK+xU//uLeFGjU9qOUzXVl7vrCh8dcMGIpS6uV1tQGtblOKMldRL sGzxPiRQqjJ8Q0hb9wgW+rNbsQFQ5V9yLUsyrhHYVfd8PyiKf7xZ3uYUPcPx38tl+c8N 0NIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=m0HVHg6p; 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 h14-20020a056a00218e00b0052d4197336fsi7256775pfi.370.2022.09.22.10.48.01; Thu, 22 Sep 2022 10:48:12 -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=m0HVHg6p; 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 S230211AbiIVRQU (ORCPT + 99 others); Thu, 22 Sep 2022 13:16:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229713AbiIVRPz (ORCPT ); Thu, 22 Sep 2022 13:15:55 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 204C42CCAB; Thu, 22 Sep 2022 10:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663866936; x=1695402936; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DRy35tf5iLyrHuxp2SgL7lHDqjPxBWrPxC87VIa2/uA=; b=m0HVHg6povi8OQ8CI7/MQbPJwtOS+85+4I0bgmZgszRbvpObJJ9Xcxuo FyUZ7FZEeRY8Yfd3OEtEx1ppOrnDiwmL/4c+aPJAY4bC95on7k0BH2Hja 6IB1J5w+d3ovgfroMB4gOkdEl2kiLBrPF7gqD7ldTjbfNPGW6HdBCbXnc mI1uoi0c+9T3MdDkr3ccSdE4drKQGlZHOsmTfaMAf6CQ3JqsxTFjQFCE8 a3op0OBa+8DVAYxnRVLexeZ2m1fAZQtkI9xVk5vzeNLaLC+rUHTXVxSF0 WFw1zSdJydqsmYXpP2kBzH3YrrdcfHf92Ed5jEaa2RFafI6vycI79Q2FZ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10478"; a="364351940" X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="364351940" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 10:11:43 -0700 X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="762270053" Received: from sknaidu-mobl1.amr.corp.intel.com (HELO kcaccard-desk.amr.corp.intel.com) ([10.212.165.187]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 10:11:25 -0700 From: Kristen Carlson Accardi To: linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, cgroups@vger.kernel.org, Jarkko Sakkinen , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: Kristen Carlson Accardi , Sean Christopherson Subject: [RFC PATCH 07/20] x86/sgx: Use a list to track to-be-reclaimed pages during reclaim Date: Thu, 22 Sep 2022 10:10:44 -0700 Message-Id: <20220922171057.1236139-8-kristen@linux.intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220922171057.1236139-1-kristen@linux.intel.com> References: <20220922171057.1236139-1-kristen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 From: Sean Christopherson Change sgx_reclaim_pages() to use a list rather than an array for storing the epc_pages which will be reclaimed. This change is needed to transition to the LRU implementation for EPC cgroup support. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Cc: Sean Christopherson --- arch/x86/kernel/cpu/sgx/main.c | 43 +++++++++++++++------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 93aa9e09c26d..085c06fdc359 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -288,12 +288,11 @@ static void sgx_reclaimer_write(struct sgx_epc_page *epc_page, */ static void sgx_reclaim_pages(void) { - struct sgx_epc_page *chunk[SGX_NR_TO_SCAN]; struct sgx_backing backing[SGX_NR_TO_SCAN]; struct sgx_encl_page *encl_page; - struct sgx_epc_page *epc_page; + struct sgx_epc_page *epc_page, *tmp; pgoff_t page_index; - int cnt = 0; + LIST_HEAD(iso); int ret; int i; @@ -304,23 +303,26 @@ static void sgx_reclaim_pages(void) epc_page = list_first_entry(&sgx_global_lru.reclaimable, struct sgx_epc_page, list); - list_del_init(&epc_page->list); encl_page = epc_page->owner; if (kref_get_unless_zero(&encl_page->encl->refcount) != 0) { epc_page->flags |= SGX_EPC_PAGE_RECLAIM_IN_PROGRESS; - chunk[cnt++] = epc_page; + list_move_tail(&epc_page->list, &iso); } else { - /* The owner is freeing the page. No need to add the - * page back to the list of reclaimable pages. + /* The owner is freeing the page, remove it from the + * LRU list */ epc_page->flags &= ~SGX_EPC_PAGE_RECLAIMER_TRACKED; + list_del_init(&epc_page->list); } } spin_unlock(&sgx_global_lru.lock); - for (i = 0; i < cnt; i++) { - epc_page = chunk[i]; + if (list_empty(&iso)) + goto out; + + i = 0; + list_for_each_entry_safe(epc_page, tmp, &iso, list) { encl_page = epc_page->owner; if (!sgx_reclaimer_age(epc_page)) @@ -335,6 +337,7 @@ static void sgx_reclaim_pages(void) goto skip; } + i++; encl_page->desc |= SGX_ENCL_PAGE_BEING_RECLAIMED; mutex_unlock(&encl_page->encl->lock); continue; @@ -342,27 +345,19 @@ static void sgx_reclaim_pages(void) skip: spin_lock(&sgx_global_lru.lock); epc_page->flags &= ~SGX_EPC_PAGE_RECLAIM_IN_PROGRESS; - list_add_tail(&epc_page->list, &sgx_global_lru.reclaimable); + list_move_tail(&epc_page->list, &sgx_global_lru.reclaimable); spin_unlock(&sgx_global_lru.lock); kref_put(&encl_page->encl->refcount, sgx_encl_release); - - chunk[i] = NULL; - } - - for (i = 0; i < cnt; i++) { - epc_page = chunk[i]; - if (epc_page) - sgx_reclaimer_block(epc_page); } - for (i = 0; i < cnt; i++) { - epc_page = chunk[i]; - if (!epc_page) - continue; + list_for_each_entry(epc_page, &iso, list) + sgx_reclaimer_block(epc_page); + i= 0; + list_for_each_entry_safe(epc_page, tmp, &iso, list) { encl_page = epc_page->owner; - sgx_reclaimer_write(epc_page, &backing[i]); + sgx_reclaimer_write(epc_page, &backing[i++]); kref_put(&encl_page->encl->refcount, sgx_encl_release); epc_page->flags &= ~(SGX_EPC_PAGE_RECLAIMER_TRACKED | @@ -370,7 +365,7 @@ static void sgx_reclaim_pages(void) sgx_free_epc_page(epc_page); } - +out: cond_resched(); } -- 2.37.3