* [PATCH 1/2] x86/sgx: Do not update sgx_nr_free_pages in sgx_setup_epc_section()
@ 2021-04-01 5:21 Jarkko Sakkinen
2021-04-01 5:21 ` [PATCH 2/2] x86/sgx: Add sgx_nr_{all, free}_pages to the debugfs Jarkko Sakkinen
0 siblings, 1 reply; 4+ messages in thread
From: Jarkko Sakkinen @ 2021-04-01 5:21 UTC (permalink / raw)
To: linux-sgx
Cc: Jarkko Sakkinen, Dave Hansen, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, x86, H. Peter Anvin, linux-kernel
Now that the sanitization process will make pages available by calling
sgx_free_epc_page(), sgx_setup_epc_section() should not touch to
sgx_nr_free_pages. This will result sgx_nr_free_pages to contain 2x the
number of actual free pages. Simply, remove the statement.
Fixes: 51ab30eb2ad4 ("x86/sgx: Replace section->init_laundry_list with sgx_dirty_page_list")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
arch/x86/kernel/cpu/sgx/main.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 13a7599ce7d4..7df7048cb1c9 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -657,7 +657,6 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size,
list_add_tail(§ion->pages[i].list, &sgx_dirty_page_list);
}
- sgx_nr_free_pages += nr_pages;
return true;
}
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] x86/sgx: Add sgx_nr_{all, free}_pages to the debugfs 2021-04-01 5:21 [PATCH 1/2] x86/sgx: Do not update sgx_nr_free_pages in sgx_setup_epc_section() Jarkko Sakkinen @ 2021-04-01 5:21 ` Jarkko Sakkinen 2021-04-01 19:32 ` Dave Hansen 0 siblings, 1 reply; 4+ messages in thread From: Jarkko Sakkinen @ 2021-04-01 5:21 UTC (permalink / raw) To: linux-sgx Cc: Jarkko Sakkinen, Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin, linux-kernel Add two debugs attributes: * /sys/kernel/debug/x86/sgx_nr_all_pages * /sys/kernel/debug/x86/sgx_nr_free_pages These provide useful statistics for testing purposes. E.g. on a NUC7CJYH2, when no enclaves are running, and EPC set to 32 MB: $ sudo cat /sys/kernel/debug/x86/sgx_nr_all_pages 5632 $ sudo cat /sys/kernel/debug/x86/sgx_nr_free_pages 5632 Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org> --- arch/x86/kernel/cpu/sgx/main.c | 53 +++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 7df7048cb1c9..190c96735c9f 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2016-20 Intel Corporation. */ +#include <linux/debugfs.h> #include <linux/freezer.h> #include <linux/highmem.h> #include <linux/kthread.h> @@ -25,7 +26,10 @@ static DECLARE_WAIT_QUEUE_HEAD(ksgxd_waitq); static LIST_HEAD(sgx_active_page_list); static DEFINE_SPINLOCK(sgx_reclaimer_lock); -/* The free page list lock protected variables prepend the lock. */ +/* The number of EPC pages in total in all nodes. */ +static unsigned long sgx_nr_all_pages; + +/* The number of free EPC pages in all nodes. */ static unsigned long sgx_nr_free_pages; /* Nodes with one or more EPC sections. */ @@ -657,6 +661,8 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, list_add_tail(§ion->pages[i].list, &sgx_dirty_page_list); } + sgx_nr_all_pages += nr_pages; + return true; } @@ -730,6 +736,44 @@ static bool __init sgx_page_cache_init(void) return true; } +#ifdef CONFIG_DEBUG_FS +static ssize_t sgx_nr_all_pages_read(struct file *file, char __user *user_buf, + size_t count, loff_t *pos) +{ + char kernel_buf[32]; + int len; + + len = snprintf(kernel_buf, sizeof(kernel_buf), "%lu\n", sgx_nr_all_pages); + if (len < 0) + return len; + + return simple_read_from_buffer(user_buf, count, pos, kernel_buf, len); +} + +static const struct file_operations sgx_nr_all_pages_fops = { + .read = sgx_nr_all_pages_read, + .llseek = default_llseek, +}; + +static ssize_t sgx_nr_free_pages_read(struct file *file, char __user *user_buf, + size_t count, loff_t *pos) +{ + char kernel_buf[32]; + int len; + + len = snprintf(kernel_buf, sizeof(kernel_buf), "%lu\n", sgx_nr_free_pages); + if (len < 0) + return len; + + return simple_read_from_buffer(user_buf, count, pos, kernel_buf, len); +} + +static const struct file_operations sgx_nr_free_pages_fops = { + .read = sgx_nr_free_pages_read, + .llseek = default_llseek, +}; +#endif /* CONFIG_DEBUG_FS */ + static int __init sgx_init(void) { int ret; @@ -750,6 +794,13 @@ static int __init sgx_init(void) if (ret) goto err_kthread; +#ifdef CONFIG_DEBUG_FS + debugfs_create_file("sgx_nr_all_pages", 0400, arch_debugfs_dir, NULL, + &sgx_nr_all_pages_fops); + debugfs_create_file("sgx_nr_free_pages", 0400, arch_debugfs_dir, NULL, + &sgx_nr_free_pages_fops); +#endif /* CONFIG_DEBUG_FS */ + return 0; err_kthread: -- 2.31.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] x86/sgx: Add sgx_nr_{all, free}_pages to the debugfs 2021-04-01 5:21 ` [PATCH 2/2] x86/sgx: Add sgx_nr_{all, free}_pages to the debugfs Jarkko Sakkinen @ 2021-04-01 19:32 ` Dave Hansen 2021-04-04 15:53 ` Jarkko Sakkinen 0 siblings, 1 reply; 4+ messages in thread From: Dave Hansen @ 2021-04-01 19:32 UTC (permalink / raw) To: Jarkko Sakkinen, linux-sgx Cc: Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin, linux-kernel On 3/31/21 10:21 PM, Jarkko Sakkinen wrote: > +#ifdef CONFIG_DEBUG_FS > + debugfs_create_file("sgx_nr_all_pages", 0400, arch_debugfs_dir, NULL, > + &sgx_nr_all_pages_fops); > + debugfs_create_file("sgx_nr_free_pages", 0400, arch_debugfs_dir, NULL, > + &sgx_nr_free_pages_fops); > +#endif /* CONFIG_DEBUG_FS */ Why not make the types u64's and use debugfs_create_u64()? That would save a ton of code. There's also debugfs_create_ulong(). ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] x86/sgx: Add sgx_nr_{all, free}_pages to the debugfs 2021-04-01 19:32 ` Dave Hansen @ 2021-04-04 15:53 ` Jarkko Sakkinen 0 siblings, 0 replies; 4+ messages in thread From: Jarkko Sakkinen @ 2021-04-04 15:53 UTC (permalink / raw) To: Dave Hansen Cc: linux-sgx, Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin, linux-kernel On Thu, Apr 01, 2021 at 12:32:58PM -0700, Dave Hansen wrote: > On 3/31/21 10:21 PM, Jarkko Sakkinen wrote: > > +#ifdef CONFIG_DEBUG_FS > > + debugfs_create_file("sgx_nr_all_pages", 0400, arch_debugfs_dir, NULL, > > + &sgx_nr_all_pages_fops); > > + debugfs_create_file("sgx_nr_free_pages", 0400, arch_debugfs_dir, NULL, > > + &sgx_nr_free_pages_fops); > > +#endif /* CONFIG_DEBUG_FS */ > > > Why not make the types u64's and use debugfs_create_u64()? That would > save a ton of code. There's also debugfs_create_ulong(). Because I was not aware of that. For sure can be used. /Jarkko ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-04-04 15:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-01 5:21 [PATCH 1/2] x86/sgx: Do not update sgx_nr_free_pages in sgx_setup_epc_section() Jarkko Sakkinen
2021-04-01 5:21 ` [PATCH 2/2] x86/sgx: Add sgx_nr_{all, free}_pages to the debugfs Jarkko Sakkinen
2021-04-01 19:32 ` Dave Hansen
2021-04-04 15:53 ` Jarkko Sakkinen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox