Skip to content

Commit

Permalink
x86/sgx: Break up long non-preemptible delays in sgx_vepc_release()
Browse files Browse the repository at this point in the history
commit 3d7d72a upstream.

On large enclaves we hit the softlockup warning with following call trace:

	xa_erase()
	sgx_vepc_release()
	__fput()
	task_work_run()
	do_exit()

The latency issue is similar to the one fixed in:

  8795359 ("x86/sgx: Silence softlockup detection when releasing large enclaves")

The test system has 64GB of enclave memory, and all is assigned to a single VM.
Release of 'vepc' takes a longer time and causes long latencies, which triggers
the softlockup warning.

Add cond_resched() to give other tasks a chance to run and reduce
latencies, which also avoids the softlockup detector.

[ mingo: Rewrote the changelog. ]

Fixes: 540745d ("x86/sgx: Introduce virtual EPC for use by KVM guests")
Reported-by: Yu Zhang <yu.zhang@ionos.com>
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Yu Zhang <yu.zhang@ionos.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: Kai Huang <kai.huang@intel.com>
Acked-by: Haitao Huang <haitao.huang@linux.intel.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
jinpuwang authored and gregkh committed Sep 13, 2023
1 parent f705617 commit e1eb041
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arch/x86/kernel/cpu/sgx/virt.c
Expand Up @@ -204,6 +204,7 @@ static int sgx_vepc_release(struct inode *inode, struct file *file)
continue;

xa_erase(&vepc->page_array, index);
cond_resched();
}

/*
Expand All @@ -222,6 +223,7 @@ static int sgx_vepc_release(struct inode *inode, struct file *file)
list_add_tail(&epc_page->list, &secs_pages);

xa_erase(&vepc->page_array, index);
cond_resched();
}

/*
Expand All @@ -243,6 +245,7 @@ static int sgx_vepc_release(struct inode *inode, struct file *file)

if (sgx_vepc_free_page(epc_page))
list_add_tail(&epc_page->list, &secs_pages);
cond_resched();
}

if (!list_empty(&secs_pages))
Expand Down

0 comments on commit e1eb041

Please sign in to comment.