LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] KVM: X86: avoid unused setup_syscalls_segments call when SYSCALL check failed
@ 2019-11-09  8:58 linmiaohe
  2019-11-11 14:08 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: linmiaohe @ 2019-11-09  8:58 UTC (permalink / raw)
  To: pbonzini, rkrcmar, sean.j.christopherson, vkuznets, wanpengli,
	jmattson, joro, tglx, mingo, bp, hpa
  Cc: linmiaohe, kvm, linux-kernel, x86

From: Miaohe Lin <linmiaohe@huawei.com>

When SYSCALL/SYSENTER ability check failed, cs and ss is inited but
remain not used. Delay initializing cs and ss until SYSCALL/SYSENTER
ability check passed.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 arch/x86/kvm/emulate.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 698efb8c3897..952d1a4f4d7e 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2770,11 +2770,10 @@ static int em_syscall(struct x86_emulate_ctxt *ctxt)
 		return emulate_ud(ctxt);
 
 	ops->get_msr(ctxt, MSR_EFER, &efer);
-	setup_syscalls_segments(ctxt, &cs, &ss);
-
 	if (!(efer & EFER_SCE))
 		return emulate_ud(ctxt);
 
+	setup_syscalls_segments(ctxt, &cs, &ss);
 	ops->get_msr(ctxt, MSR_STAR, &msr_data);
 	msr_data >>= 32;
 	cs_sel = (u16)(msr_data & 0xfffc);
@@ -2838,12 +2837,11 @@ static int em_sysenter(struct x86_emulate_ctxt *ctxt)
 	if (ctxt->mode == X86EMUL_MODE_PROT64)
 		return X86EMUL_UNHANDLEABLE;
 
-	setup_syscalls_segments(ctxt, &cs, &ss);
-
 	ops->get_msr(ctxt, MSR_IA32_SYSENTER_CS, &msr_data);
 	if ((msr_data & 0xfffc) == 0x0)
 		return emulate_gp(ctxt, 0);
 
+	setup_syscalls_segments(ctxt, &cs, &ss);
 	ctxt->eflags &= ~(X86_EFLAGS_VM | X86_EFLAGS_IF);
 	cs_sel = (u16)msr_data & ~SEGMENT_RPL_MASK;
 	ss_sel = cs_sel + 8;
-- 
2.19.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: X86: avoid unused setup_syscalls_segments call when SYSCALL check failed
  2019-11-09  8:58 [PATCH] KVM: X86: avoid unused setup_syscalls_segments call when SYSCALL check failed linmiaohe
@ 2019-11-11 14:08 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2019-11-11 14:08 UTC (permalink / raw)
  To: linmiaohe, rkrcmar, sean.j.christopherson, vkuznets, wanpengli,
	jmattson, joro, tglx, mingo, bp, hpa
  Cc: kvm, linux-kernel, x86

On 09/11/19 09:58, linmiaohe wrote:
> From: Miaohe Lin <linmiaohe@huawei.com>
> 
> When SYSCALL/SYSENTER ability check failed, cs and ss is inited but
> remain not used. Delay initializing cs and ss until SYSCALL/SYSENTER
> ability check passed.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  arch/x86/kvm/emulate.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index 698efb8c3897..952d1a4f4d7e 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -2770,11 +2770,10 @@ static int em_syscall(struct x86_emulate_ctxt *ctxt)
>  		return emulate_ud(ctxt);
>  
>  	ops->get_msr(ctxt, MSR_EFER, &efer);
> -	setup_syscalls_segments(ctxt, &cs, &ss);
> -
>  	if (!(efer & EFER_SCE))
>  		return emulate_ud(ctxt);
>  
> +	setup_syscalls_segments(ctxt, &cs, &ss);
>  	ops->get_msr(ctxt, MSR_STAR, &msr_data);
>  	msr_data >>= 32;
>  	cs_sel = (u16)(msr_data & 0xfffc);
> @@ -2838,12 +2837,11 @@ static int em_sysenter(struct x86_emulate_ctxt *ctxt)
>  	if (ctxt->mode == X86EMUL_MODE_PROT64)
>  		return X86EMUL_UNHANDLEABLE;
>  
> -	setup_syscalls_segments(ctxt, &cs, &ss);
> -
>  	ops->get_msr(ctxt, MSR_IA32_SYSENTER_CS, &msr_data);
>  	if ((msr_data & 0xfffc) == 0x0)
>  		return emulate_gp(ctxt, 0);
>  
> +	setup_syscalls_segments(ctxt, &cs, &ss);
>  	ctxt->eflags &= ~(X86_EFLAGS_VM | X86_EFLAGS_IF);
>  	cs_sel = (u16)msr_data & ~SEGMENT_RPL_MASK;
>  	ss_sel = cs_sel + 8;
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-09  8:58 [PATCH] KVM: X86: avoid unused setup_syscalls_segments call when SYSCALL check failed linmiaohe
2019-11-11 14:08 ` Paolo Bonzini

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git