Commit 992801ae authored by Tony Luck's avatar Tony Luck Committed by Dave Hansen

x86/sgx: Initial poison handling for dirty and free pages

A memory controller patrol scrubber can report poison in a page
that isn't currently being used.

Add "poison" field in the sgx_epc_page that can be set for an
sgx_epc_page. Check for it:
1) When sanitizing dirty pages
2) When freeing epc pages

Poison is a new field separated from flags to avoid having to make all
updates to flags atomic, or integrate poison state changes into some
other locking scheme to protect flags (Currently just sgx_reclaimer_lock
which protects the SGX_EPC_PAGE_RECLAIMER_TRACKED bit in page->flags).

In both cases place the poisoned page on a per-node list of poisoned
epc pages to make sure it will not be reallocated.
Signed-off-by: default avatarTony Luck <tony.luck@intel.com>
Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
Tested-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Link: https://lkml.kernel.org/r/20211026220050.697075-4-tony.luck@intel.com
parent 40e0e784
...@@ -62,6 +62,24 @@ static void __sgx_sanitize_pages(struct list_head *dirty_page_list) ...@@ -62,6 +62,24 @@ static void __sgx_sanitize_pages(struct list_head *dirty_page_list)
page = list_first_entry(dirty_page_list, struct sgx_epc_page, list); page = list_first_entry(dirty_page_list, struct sgx_epc_page, list);
/*
* Checking page->poison without holding the node->lock
* is racy, but losing the race (i.e. poison is set just
* after the check) just means __eremove() will be uselessly
* called for a page that sgx_free_epc_page() will put onto
* the node->sgx_poison_page_list later.
*/
if (page->poison) {
struct sgx_epc_section *section = &sgx_epc_sections[page->section];
struct sgx_numa_node *node = section->node;
spin_lock(&node->lock);
list_move(&page->list, &node->sgx_poison_page_list);
spin_unlock(&node->lock);
continue;
}
ret = __eremove(sgx_get_epc_virt_addr(page)); ret = __eremove(sgx_get_epc_virt_addr(page));
if (!ret) { if (!ret) {
/* /*
...@@ -626,7 +644,11 @@ void sgx_free_epc_page(struct sgx_epc_page *page) ...@@ -626,7 +644,11 @@ void sgx_free_epc_page(struct sgx_epc_page *page)
spin_lock(&node->lock); spin_lock(&node->lock);
list_add_tail(&page->list, &node->free_page_list); page->owner = NULL;
if (page->poison)
list_add(&page->list, &node->sgx_poison_page_list);
else
list_add_tail(&page->list, &node->free_page_list);
sgx_nr_free_pages++; sgx_nr_free_pages++;
page->flags = SGX_EPC_PAGE_IS_FREE; page->flags = SGX_EPC_PAGE_IS_FREE;
...@@ -658,6 +680,7 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, ...@@ -658,6 +680,7 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size,
section->pages[i].section = index; section->pages[i].section = index;
section->pages[i].flags = 0; section->pages[i].flags = 0;
section->pages[i].owner = NULL; section->pages[i].owner = NULL;
section->pages[i].poison = 0;
list_add_tail(&section->pages[i].list, &sgx_dirty_page_list); list_add_tail(&section->pages[i].list, &sgx_dirty_page_list);
} }
...@@ -724,6 +747,7 @@ static bool __init sgx_page_cache_init(void) ...@@ -724,6 +747,7 @@ static bool __init sgx_page_cache_init(void)
if (!node_isset(nid, sgx_numa_mask)) { if (!node_isset(nid, sgx_numa_mask)) {
spin_lock_init(&sgx_numa_nodes[nid].lock); spin_lock_init(&sgx_numa_nodes[nid].lock);
INIT_LIST_HEAD(&sgx_numa_nodes[nid].free_page_list); INIT_LIST_HEAD(&sgx_numa_nodes[nid].free_page_list);
INIT_LIST_HEAD(&sgx_numa_nodes[nid].sgx_poison_page_list);
node_set(nid, sgx_numa_mask); node_set(nid, sgx_numa_mask);
} }
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
struct sgx_epc_page { struct sgx_epc_page {
unsigned int section; unsigned int section;
unsigned int flags; u16 flags;
u16 poison;
struct sgx_encl_page *owner; struct sgx_encl_page *owner;
struct list_head list; struct list_head list;
}; };
...@@ -42,6 +43,7 @@ struct sgx_epc_page { ...@@ -42,6 +43,7 @@ struct sgx_epc_page {
*/ */
struct sgx_numa_node { struct sgx_numa_node {
struct list_head free_page_list; struct list_head free_page_list;
struct list_head sgx_poison_page_list;
spinlock_t lock; spinlock_t lock;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment