Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp812082pxf; Thu, 18 Mar 2021 12:07:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVnEWaLw5LDJfRl9knIgtXt0hoXC+S8dRT1IUVqTvdvZRa0WkS6XZEHrtYi8AtLI5afu4Y X-Received: by 2002:a17:906:c102:: with SMTP id do2mr53908ejc.305.1616094439830; Thu, 18 Mar 2021 12:07:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616094439; cv=none; d=google.com; s=arc-20160816; b=r5KCAVwl3js5QrjuWz2QTKpD4j3h3pEXa/0rVnv+1/pfGDsMmaxPXmaBkbu4/62F7a P4rnovaWH3UwbuMad264WioBCMyQJkDdXMYGdLDfC1bNURYWn0hQRVTtc++qUFzDO/+q gnYWl8fSVx+N06BfFKFtcEbyueQBD4lL8vKcUkac9R9e6m871UFTjzZSxGWj8ZFyy9VE /USCeTL8KFNSC4WaNpCuiy0r3L3PcHnQHH4hh3KAu7kkNK2f44K4fRnvGL0Gg7jdl/55 Js6bXMphdy0/YUV0VbXFXFzZsn0tiwpDLoId7deTCSekAhRGJ7W4DeBYRCizzC5xrqJB 88RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=a4XRupqv6A2cx8zMOnwQgGtym9Na93Zh7gf17YaXn+c=; b=fon0BqIp4zyoiNSsfUUlXa6Koe7y3rVvh8Af8MpHRfEExp5fGzR1vqz5aVJB/WP9ST dPxf3JNzIYlnDjpLEwAJ0uVWzIIDpl+EeOXEfozsDBy8x/V2IyDnQvtalldQouLcEJ3K oWFN8o/OrQlEw3smxS33Te6K8FYHZwhIQhzCPOdo6eT19n/zOeAqJf/1sAl9huGdiwWh V7ivjvHEKE/RalnvP6MFGQAa5EhJI81nVEW88WareD3KqTmSkov4HAJieAVfzaDzBs6T OimnKz+Dk/kLQVXxg/5F73ektWlQM4X0XF9qUvxwjgoX+TrTmlSe+VyUCEKxlsmbCi+l pp1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nUEWEzpa; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f18si2482957eja.587.2021.03.18.12.06.57; Thu, 18 Mar 2021 12:07:19 -0700 (PDT) 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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nUEWEzpa; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbhCRTFs (ORCPT + 99 others); Thu, 18 Mar 2021 15:05:48 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:59656 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229996AbhCRTFk (ORCPT ); Thu, 18 Mar 2021 15:05:40 -0400 Date: Thu, 18 Mar 2021 19:05:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1616094339; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a4XRupqv6A2cx8zMOnwQgGtym9Na93Zh7gf17YaXn+c=; b=nUEWEzpa8jzAiUjdY3bVhJvcfSjZuQxS7SpQjOf7Ww+6MFlxtXwCXTPSzVz8LoxkXcgKj1 /KcKSNI+rFgt/oiQK1uvsxW08cpJYgbUgBVeI37RkuH7FZWCQkuhKKyna4pI91CIScI+zS 0+IOgRXt5IvM5Wbk3gXTYWs/gIwUOJYJKh0fjz+yE0LM5QfXh72ebN5zuDGs6joyXOvz7H hAqSrgp2qeMUGJL71lxEhmdU6Y/V8XvLMIsCR44Qr/JclTMVEXLifsURYvXLhMsPeDxd7U Qklu+6b18+jKwGEP/2DX+Qn8ya85E39T73PYP+7UP0E+JkgyGppDglOOka5taQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1616094339; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a4XRupqv6A2cx8zMOnwQgGtym9Na93Zh7gf17YaXn+c=; b=nzuVF8PJoPLc5tcURqnyi2fjByV8CS945JBXl3bK03Hv3NCx8mZ8ak99U9RqvAALJLBXRc xgYKRwZ+R55mTWDg== From: "tip-bot2 for Jarkko Sakkinen" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sgx] x86/sgx: Replace section->init_laundry_list with sgx_dirty_page_list Cc: Jarkko Sakkinen , Borislav Petkov , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210317235332.362001-1-jarkko.sakkinen@intel.com> References: <20210317235332.362001-1-jarkko.sakkinen@intel.com> MIME-Version: 1.0 Message-ID: <161609433816.398.9992116739812428895.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/sgx branch of tip: Commit-ID: 51ab30eb2ad4c4a61f827dc18863cd70dc46dc32 Gitweb: https://git.kernel.org/tip/51ab30eb2ad4c4a61f827dc18863cd70dc46dc32 Author: Jarkko Sakkinen AuthorDate: Thu, 18 Mar 2021 01:53:30 +02:00 Committer: Borislav Petkov CommitterDate: Thu, 18 Mar 2021 16:17:26 +01:00 x86/sgx: Replace section->init_laundry_list with sgx_dirty_page_list During normal runtime, the "ksgxd" daemon behaves like a version of kswapd just for SGX. But, before it starts acting like kswapd, its first job is to initialize enclave memory. Currently, the SGX boot code places each enclave page on a epc_section->init_laundry_list. Once it starts up, the ksgxd code walks over that list and populates the actual SGX page allocator. However, the per-section structures are going away to make way for the SGX NUMA allocator. There's also little need to have a per-section structure; the enclave pages are all treated identically, and they can be placed on the correct allocator list from metadata stored in the enclave page (struct sgx_epc_page) itself. Modify sgx_sanitize_section() to take a single page list instead of taking a section and deriving the list from there. Signed-off-by: Jarkko Sakkinen Signed-off-by: Borislav Petkov Acked-by: Dave Hansen Link: https://lkml.kernel.org/r/20210317235332.362001-1-jarkko.sakkinen@intel.com --- arch/x86/kernel/cpu/sgx/main.c | 54 +++++++++++++++------------------ arch/x86/kernel/cpu/sgx/sgx.h | 7 +---- 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 8df81a3..f3a5cd2 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -26,39 +26,43 @@ static LIST_HEAD(sgx_active_page_list); static DEFINE_SPINLOCK(sgx_reclaimer_lock); +static LIST_HEAD(sgx_dirty_page_list); + /* - * Reset dirty EPC pages to uninitialized state. Laundry can be left with SECS - * pages whose child pages blocked EREMOVE. + * Reset post-kexec EPC pages to the uninitialized state. The pages are removed + * from the input list, and made available for the page allocator. SECS pages + * prepending their children in the input list are left intact. */ -static void sgx_sanitize_section(struct sgx_epc_section *section) +static void __sgx_sanitize_pages(struct list_head *dirty_page_list) { struct sgx_epc_page *page; LIST_HEAD(dirty); int ret; - /* init_laundry_list is thread-local, no need for a lock: */ - while (!list_empty(§ion->init_laundry_list)) { + /* dirty_page_list is thread-local, no need for a lock: */ + while (!list_empty(dirty_page_list)) { if (kthread_should_stop()) return; - /* needed for access to ->page_list: */ - spin_lock(§ion->lock); - - page = list_first_entry(§ion->init_laundry_list, - struct sgx_epc_page, list); + page = list_first_entry(dirty_page_list, struct sgx_epc_page, list); ret = __eremove(sgx_get_epc_virt_addr(page)); - if (!ret) - list_move(&page->list, §ion->page_list); - else + if (!ret) { + /* + * page is now sanitized. Make it available via the SGX + * page allocator: + */ + list_del(&page->list); + sgx_free_epc_page(page); + } else { + /* The page is not yet clean - move to the dirty list. */ list_move_tail(&page->list, &dirty); - - spin_unlock(§ion->lock); + } cond_resched(); } - list_splice(&dirty, §ion->init_laundry_list); + list_splice(&dirty, dirty_page_list); } static bool sgx_reclaimer_age(struct sgx_epc_page *epc_page) @@ -405,24 +409,17 @@ static bool sgx_should_reclaim(unsigned long watermark) static int ksgxd(void *p) { - int i; - set_freezable(); /* * Sanitize pages in order to recover from kexec(). The 2nd pass is * required for SECS pages, whose child pages blocked EREMOVE. */ - for (i = 0; i < sgx_nr_epc_sections; i++) - sgx_sanitize_section(&sgx_epc_sections[i]); - - for (i = 0; i < sgx_nr_epc_sections; i++) { - sgx_sanitize_section(&sgx_epc_sections[i]); + __sgx_sanitize_pages(&sgx_dirty_page_list); + __sgx_sanitize_pages(&sgx_dirty_page_list); - /* Should never happen. */ - if (!list_empty(&sgx_epc_sections[i].init_laundry_list)) - WARN(1, "EPC section %d has unsanitized pages.\n", i); - } + /* sanity check: */ + WARN_ON(!list_empty(&sgx_dirty_page_list)); while (!kthread_should_stop()) { if (try_to_freeze()) @@ -637,13 +634,12 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, section->phys_addr = phys_addr; spin_lock_init(§ion->lock); INIT_LIST_HEAD(§ion->page_list); - INIT_LIST_HEAD(§ion->init_laundry_list); for (i = 0; i < nr_pages; i++) { section->pages[i].section = index; section->pages[i].flags = 0; section->pages[i].owner = NULL; - list_add_tail(§ion->pages[i].list, §ion->init_laundry_list); + list_add_tail(§ion->pages[i].list, &sgx_dirty_page_list); } section->free_cnt = nr_pages; diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index 5fa42d1..bc8af04 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -45,13 +45,6 @@ struct sgx_epc_section { spinlock_t lock; struct list_head page_list; unsigned long free_cnt; - - /* - * Pages which need EREMOVE run on them before they can be - * used. Only safe to be accessed in ksgxd and init code. - * Not protected by locks. - */ - struct list_head init_laundry_list; }; extern struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS];