mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Andy Lutomirski <luto@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, kvm list <kvm@vger.kernel.org>
Subject: Re: [PATCH v2] KVM: x86: do not read FS/GS base MSRs when saving them
Date: Thu, 4 Jan 2018 00:42:30 +0100	[thread overview]
Message-ID: <6d10cdd5-e8d8-f5ed-e039-c71df9d0ea9e@redhat.com> (raw)
In-Reply-To: <CALCETrXJdwkELu81wj2rXdKcK-TXPmBO1y8hDxi7B1zkSa=WgQ@mail.gmail.com>

On 03/01/2018 23:20, Andy Lutomirski wrote:
>> On Jan 2, 2018, at 5:59 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> The FS and userspace GS bases are available in current->thread, while the
>> kernel GS base is a percpu variable.  Skip the expensive rdmsr and just
>> get the values from memory.
> 
> That fsbase change is wrong: thread->fsbase is not guaranteed to be
> correct for current.

Note that the value I'm storing in HOST_FS_BASE and HOST_GS_BASE is only
used if FS/GS selector is zero.  If FS/GS selector is not zero, it is
not used.  Does that avoid this issue?

Certainly worth a comment or clearer code though.

>> +#ifdef CONFIG_X86_64
>> +/* Provide the current kernel GS base.  */
>> +static inline void *get_current_kernel_gs_base(void)
>> +{
>> +    return this_cpu_ptr(irq_stack_union.gs_base);
>> +}
>> +#endif
> 
> This is an awful name because MSR_KERNEL_GS_BASE means the user gs
> base.  How about calling it something like
> get_this_cpu_kernelmode_gs_base() or similar?

True, I'll adopt your name.

Paolo

>> #ifdef CONFIG_X86_64
>> -    vmcs_writel(HOST_FS_BASE, read_msr(MSR_FS_BASE));
>> -    vmcs_writel(HOST_GS_BASE, read_msr(MSR_GS_BASE));
>> +    vmcs_writel(HOST_FS_BASE, current->thread.fsbase);
> 
> That's wrong.  thread->fsbase isn't kept up to date while the thread
> is running.  You could potentially try to expose an interface to get
> save_base_legacy() called to update it.
> 

  reply	other threads:[~2018-01-03 23:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-02 13:59 Paolo Bonzini
2018-01-03 22:20 ` Andy Lutomirski
2018-01-03 23:42   ` Paolo Bonzini [this message]
2018-01-04  0:16     ` Andy Lutomirski
2018-01-04  1:17       ` Paolo Bonzini

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=6d10cdd5-e8d8-f5ed-e039-c71df9d0ea9e@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®