Received: from eggs.gnu.org ([2001:4830:134:3::10]:35449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVHYY-0005rU-1T for qemu-devel@nongnu.org; Tue, 10 Mar 2015 06:38:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVHYT-0002xb-2R for qemu-devel@nongnu.org; Tue, 10 Mar 2015 06:38:33 -0400 Received: from mail-wi0-x230.google.com ([2a00:1450:400c:c05::230]:43014) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVHYS-0002xG-NA for qemu-devel@nongnu.org; Tue, 10 Mar 2015 06:38:28 -0400 Received: by widem10 with SMTP id em10so1725109wid.2 for ; Tue, 10 Mar 2015 03:38:28 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 10 Mar 2015 11:38:00 +0100 Message-Id: <1425983880-26906-12-git-send-email-pbonzini@redhat.com> In-Reply-To: <1425983880-26906-1-git-send-email-pbonzini@redhat.com> References: <1425983880-26906-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 11/11] x86: fix SS selector in SYSRET List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Bill Paul From: Bill Paul According to my reading of the Intel documentation, the SYSRET instruction is supposed to force the RPL bits of the %ss register to 3 when returning to user mode. The actual sequence is: SS.Selector <-- (IA32_STAR[63:48]+8) OR 3; (* RPL forced to 3 *) However, the code in helper_sysret() leaves them at 0 (in other words, the "OR 3" part of the above sequence is missing). It does set the privilege level bits of %cs correctly though. This has caused me trouble with some of my VxWorks development: code that runs okay on real hardware will crash on QEMU, unless I apply the patch below. Signed-off-by: Bill Paul Message-Id: <201503091548.01462.wpaul@windriver.com> Signed-off-by: Paolo Bonzini --- target-i386/seg_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target-i386/seg_helper.c b/target-i386/seg_helper.c index fa374d0..2bc757a 100644 --- a/target-i386/seg_helper.c +++ b/target-i386/seg_helper.c @@ -1043,7 +1043,7 @@ void helper_sysret(CPUX86State *env, int dflag) DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK); env->eip = (uint32_t)env->regs[R_ECX]; } - cpu_x86_load_seg_cache(env, R_SS, selector + 8, + cpu_x86_load_seg_cache(env, R_SS, (selector + 8) | 3, 0, 0xffffffff, DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | @@ -1056,7 +1056,7 @@ void helper_sysret(CPUX86State *env, int dflag) DESC_S_MASK | (3 << DESC_DPL_SHIFT) | DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK); env->eip = (uint32_t)env->regs[R_ECX]; - cpu_x86_load_seg_cache(env, R_SS, selector + 8, + cpu_x86_load_seg_cache(env, R_SS, (selector + 8) | 3, 0, 0xffffffff, DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | -- 2.3.0