Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a52bcdb8 authored by Haitao Shan's avatar Haitao Shan
Browse files

ANDROID: Setting up GS before calling __restore_processor_state.



Android Common Kernel compiled by clang with Shadow Call Stack will
use GS segment. However, __restore_processor_state is called when
system wakes up from S3 and at the moment GS is not restored yet.

This is a hack by copying a small code snippet(setting gs base) from
__restore_processor_state to restore_processor_state. It prepares GS
before __restore_processor_state is called. At the same time,
restore_processor_state is still small enough so that SCS is not on,
as SCS seems to be on only for large functions.

Bug: 166163480
Change-Id: I3bfe4ac61dee876da57de6578c9a7f01431a1743
Signed-off-by: default avatarHaitao Shan <hshan@google.com>
parent dea54268
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -268,6 +268,19 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
/* Needed by apm.c */
void notrace restore_processor_state(void)
{
#ifdef __clang__
	// The following code snippet is copied from __restore_processor_state.
	// Its purpose is to prepare GS segment before the function is called.
	// Since the function is compiled with SCS on, it will use GS at its
	// entry.
	// TODO: Hack to be removed later when compiler bug is fixed.
#ifdef CONFIG_X86_64
	wrmsrl(MSR_GS_BASE, saved_context.kernelmode_gs_base);
#else
	loadsegment(fs, __KERNEL_PERCPU);
	loadsegment(gs, __KERNEL_STACK_CANARY);
#endif
#endif
	__restore_processor_state(&saved_context);
}
#ifdef CONFIG_X86_32