All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Liran Alon <liran.alon@oracle.com>
Cc: max@m00nbsd.net, Joao Martins <joao.m.martins@oracle.com>,
	pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: nVMX: Ignore segment base for VMX memory operand when segment not FS or GS
Date: Mon, 15 Jul 2019 18:22:52 +0200	[thread overview]
Message-ID: <87r26rw9lv.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <20190715154744.36134-1-liran.alon@oracle.com>

Liran Alon <liran.alon@oracle.com> writes:

> As reported by Maxime at
> https://bugzilla.kernel.org/show_bug.cgi?id=204175:
>
> In vmx/nested.c::get_vmx_mem_address(), when the guest runs in long mode,
> the base address of the memory operand is computed with a simple:
>     *ret = s.base + off;
>
> This is incorrect, the base applies only to FS and GS, not to the others.
> Because of that, if the guest uses a VMX instruction based on DS and has
> a DS.base that is non-zero, KVM wrongfully adds the base to the
> resulting address.
>
> Reported-by: Maxime Villard <max@m00nbsd.net>
> Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
> Signed-off-by: Liran Alon <liran.alon@oracle.com>
> ---
>  arch/x86/kvm/vmx/nested.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 18efb338ed8a..e01e1b6b8167 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -4068,6 +4068,8 @@ int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification,
>  		 * mode, e.g. a 32-bit address size can yield a 64-bit virtual
>  		 * address when using FS/GS with a non-zero base.
>  		 */
> +		if ((seg_reg != VCPU_SREG_FS) && (seg_reg != VCPU_SREG_GS))
> +			s.base = 0;

(personal preference)
 
 I'd rather write this as

    /* In long mode only FS and GS bases are considered */
    if (seg_reg == VCPU_SREG_FS || seg_reg == VCPU_SREG_GS)
       *ret = s.base + off;
    else 
       *ret = off;

>  		*ret = s.base + off;
>  
>  		/* Long mode: #GP(0)/#SS(0) if the memory address is in a

As-is or rewritten with my suggestion,

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

-- 
Vitaly

  reply	other threads:[~2019-07-15 16:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-15 15:47 [PATCH] KVM: nVMX: Ignore segment base for VMX memory operand when segment not FS or GS Liran Alon
2019-07-15 16:22 ` Vitaly Kuznetsov [this message]
2019-07-15 17:21   ` Sean Christopherson
2019-07-15 18:28     ` Paolo Bonzini
2019-07-15 18:30       ` Liran Alon
2019-07-15 18:44         ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r26rw9lv.fsf@vitty.brq.redhat.com \
    --to=vkuznets@redhat.com \
    --cc=joao.m.martins@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=liran.alon@oracle.com \
    --cc=max@m00nbsd.net \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.