x86/entry/64: Fix context tracking state warning when load_gs_index fails [Linux 4.4.189]

This Linux kernel change "x86/entry/64: Fix context tracking state warning when load_gs_index fails" is included in the Linux 4.4.189 release. This change is authored by Wanpeng Li <wanpeng.li [at] hotmail.com> on Fri Sep 30 09:01:06 2016 +0800. The commit for this change in Linux stable tree is 3d3e1f4 (patch) which is from upstream commit 2fa5f04. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 2fa5f04.

x86/entry/64: Fix context tracking state warning when load_gs_index fails

commit 2fa5f04f85730d0c4f49f984b7efeb4f8d5bd1fc upstream.

This warning:

 WARNING: CPU: 0 PID: 3331 at arch/x86/entry/common.c:45 enter_from_user_mode+0x32/0x50
 CPU: 0 PID: 3331 Comm: ldt_gdt_64 Not tainted 4.8.0-rc7+ #13
 Call Trace:
  ? general_protection+0x12/0x30
  ? native_load_gs_index+0xd/0x20
  ? do_set_thread_area+0x19c/0x1f0

... can be reproduced by running the GS testcase of the ldt_gdt test unit in
the x86 selftests.

do_int80_syscall_32() will call enter_form_user_mode() to convert context
tracking state from user state to kernel state. The load_gs_index() call
can fail with user gsbase, gsbase will be fixed up and proceed if this

However, enter_from_user_mode() will be called again in the fixed up path
though it is context tracking kernel state currently.

This patch fixes it by just fixing up gsbase and telling lockdep that IRQs
are off once load_gs_index() failed with user gsbase.

Signed-off-by: Wanpeng Li <[email protected]>
Acked-by: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

There are 4 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 arch/x86/entry/entry_64.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 375ed60..b952e37 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -1133,7 +1133,6 @@ ENTRY(error_entry)
    testb   $3, CS+8(%rsp)
    jz  .Lerror_kernelspace

     * We entered from user mode or we're pretending to have entered
     * from user mode due to an IRET fault.
@@ -1177,7 +1176,8 @@ ENTRY(error_entry)
     * gsbase and proceed.  We'll fix up the exception and land in
     * gs_change's error handler with kernel gsbase.
-   jmp .Lerror_entry_from_usermode_swapgs
+   jmp .Lerror_entry_done

    /* Fix truncated RIP */

Leave a Reply

Your email address will not be published. Required fields are marked *