linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Marc Orr <marcorr@google.com>
To: dave.hansen@intel.com
Cc: kvm@vger.kernel.org, Jim Mattson <jmattson@google.com>,
	David Rientjes <rientjes@google.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	linux-mm@kvack.org, akpm@linux-foundation.org,
	pbonzini@redhat.com, rkrcmar@redhat.com, willy@infradead.org,
	sean.j.christopherson@intel.com, dave.hansen@linux.intel.com,
	Wanpeng Li <kernellwp@gmail.com>
Subject: Re: [kvm PATCH v5 2/4] kvm: x86: Dynamically allocate guest_fpu
Date: Wed, 31 Oct 2018 14:39:20 -0700	[thread overview]
Message-ID: <CAA03e5FBri+LSZoGKJpJJruSEoNZ39DTbJMRhJbatgQAs6BiaA@mail.gmail.com> (raw)
In-Reply-To: <07251c42-e9d9-6428-60cd-6ecbaf78c3a5@intel.com>

On Wed, Oct 31, 2018 at 2:30 PM Dave Hansen <dave.hansen@intel.com> wrote:
>
> On 10/31/18 2:24 PM, Marc Orr wrote:
> >> It can get set to sizeof(struct fregs_state) for systems where XSAVE is
> >> not in use.  I was neglecting to mention those when I said the "~500
> >> byte" number.
> >>
> >> My point was that it can vary wildly and that any static allocation
> >> scheme will waste lots of memory when we have small hardware-supported
> >> buffers.
> >
> > Got it. Then I think we need to set the size for the kmem cache to
> > max(fpu_kernel_xstate_size, sizeof(fxregs_state)), unless I'm missing
> > something. I'll send out a version of the patch that does this in a
> > bit. Thanks!
>
> Despite its name, fpu_kernel_xstate_size *should* always be the "size of
> the hardware buffer we need to back 'struct fpu'".  That's true for all
> of the various formats we support: XSAVE, fxregs, swregs, etc...
>
> fpu__init_system_xstate_size_legacy() does that when XSAVE itself is not
> in play.

That makes sense. But my specific concern is the code I've copied
below, from arch/x86/kvm/x86.c. Notice on a system where
guest_fpu.state is a fregs_state, this code would generate garbage for
some fields. With the new code we're talking about, it will cause
memory corruption. But maybe it's not possible to run this code on a
system with an fregs_state, because such systems would predate VMX?

8382 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
8383 {
8384         struct fxregs_state *fxsave;
8385
8386         vcpu_load(vcpu);
8387
8388         fxsave = &vcpu->arch.guest_fpu->state.fxsave;
8389         memcpy(fpu->fpr, fxsave->st_space, 128);
8390         fpu->fcw = fxsave->cwd;
8391         fpu->fsw = fxsave->swd;
8392         fpu->ftwx = fxsave->twd;
8393         fpu->last_opcode = fxsave->fop;
8394         fpu->last_ip = fxsave->rip;
8395         fpu->last_dp = fxsave->rdp;
8396         memcpy(fpu->xmm, fxsave->xmm_space, sizeof fxsave->xmm_space);
8397
8398         vcpu_put(vcpu);
8399         return 0;
8400 }

  reply	other threads:[~2018-10-31 21:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-31 13:26 [kvm PATCH v5 0/4] shrink vcpu_vmx down to order 2 Marc Orr
2018-10-31 13:26 ` [kvm PATCH v5 1/4] kvm: x86: Use task structs fpu field for user Marc Orr
2018-10-31 13:26 ` [kvm PATCH v5 2/4] kvm: x86: Dynamically allocate guest_fpu Marc Orr
2018-10-31 14:11   ` Dave Hansen
2018-10-31 21:13     ` Marc Orr
2018-10-31 21:21       ` Dave Hansen
2018-10-31 21:24         ` Marc Orr
2018-10-31 21:30           ` Dave Hansen
2018-10-31 21:39             ` Marc Orr [this message]
2018-10-31 21:44               ` Dave Hansen
2018-10-31 13:26 ` [kvm PATCH v5 3/4] kvm: vmx: refactor vmx_msrs struct for vmalloc Marc Orr
2018-10-31 14:12   ` Dave Hansen
2018-10-31 14:15     ` Sean Christopherson
2018-10-31 14:19       ` Marc Orr
2018-10-31 13:26 ` [kvm PATCH v5 4/4] kvm: vmx: use vmalloc() to allocate vcpus Marc Orr

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=CAA03e5FBri+LSZoGKJpJJruSEoNZ39DTbJMRhJbatgQAs6BiaA@mail.gmail.com \
    --to=marcorr@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=jmattson@google.com \
    --cc=kernellwp@gmail.com \
    --cc=konrad.wilk@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pbonzini@redhat.com \
    --cc=rientjes@google.com \
    --cc=rkrcmar@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=willy@infradead.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