kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Gabe Black <gblack@eecs.umich.edu>
Cc: kvm@vger.kernel.org, nathan binkert <nate@binkert.org>,
	Steve Reinhardt <stever@gmail.com>
Subject: Re: potential tss trampling, assumptions about physical memory layout
Date: Mon, 25 May 2009 14:58:08 +0300	[thread overview]
Message-ID: <4A1A87D0.4020404@redhat.com> (raw)
In-Reply-To: <4A19BFC2.8000309@eecs.umich.edu>

Gabe Black wrote:
>     While continuing to try to get KVM and our M5 simulator to work
> together, I ran into another issue.
>
>     During VCPU bring up in x86 under VMX, the function init_rmode_tss
> is called which seems to be writing an initial version of a TSS into
> guest memory. It's not immediately clear to me why that would be a
> necessary part of CPU initialization since, according to my
> understanding of the ISA, the TSS should only be written by CPU itself
> (as apposed to a regular load or store) when doing a task switch. This
> doesn't present an immediate problem for us, but if CPUs are not all
> started at the same time, it would be possible for them to trample a
> shared TSS or whatever would end up beneath it.
>
>     There has also been a strange problem that crops up when the tss is
> put at an unusual address (more on that next) where copy_to_user within
> kvm_clear_guest_page will work or not work depending on seemingly
> arbitrary circumstances. Are there any restrictions on how to mmap the
> backing memory or on how it's used at that point in CPU initialization?
> I'd need to look into this more to get a good idea of what's going on,
> but it seems to defy logic and any guidance would be useful.
>
>     init_rmode_tss uses a function called rmode_tss_base to figure out
> where to put this initial tss, and there seem to be a few assumptions
> about what the physical memory layout looks like that are not
> necessarily true. The version of the code in the kernel I'm working with
> (2.6.28.9) looks like the following:
>
> static gva_t rmode_tss_base(struct kvm *kvm)
> {
>         if (!kvm->arch.tss_addr) {
>                 gfn_t base_gfn = kvm->memslots[0].base_gfn +
>                                  kvm->memslots[0].npages - 3;
>                 return base_gfn << PAGE_SHIFT;
>         }
>         return kvm->arch.tss_addr;
> }
>
>     The first assumption is that there is a valid element in the
> memslots array. If not the guest may be in trouble anyway, but the
> kernel may behave unpredictably in that case. Second, this code seems to
> assume what I believe is the standard QEMU style memory layout with a
> chunk of physical memory from 0x0 - 0xA0000, the VGA framebuffer, and
> then 0xC0000 and upwards. In that case, memslots[0] would end at
> 0xA0000, and going three pages back from the end would still be a valid
> realmode address. In our case, I was not leaving a gap for VGA and
> instead allocating all ~500 MB of memory in one chunk, so three pages
> from the end of memslot[0] was WAY outside the bounds of real mode
> addressing. If this TSS is indeed for use by the guest in real mode,
> that doesn't seem like it would work. Finally, it assumes that
> memslots[0].npages is greater than 3 in the first place. If it isn't,
> you'll end up with wrapping and try to install a real mode TSS at the
> end of the address space, even farther from what real mode can handle
> and potentially entirely invalid.
>   

That's an early kvm design error, it was corrected with KVM_SET_TSS_ADDR.


-- 
error compiling committee.c: too many arguments to function


      reply	other threads:[~2009-05-25 11:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-24 21:44 potential tss trampling, assumptions about physical memory layout Gabe Black
2009-05-25 11:58 ` Avi Kivity [this message]

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=4A1A87D0.4020404@redhat.com \
    --to=avi@redhat.com \
    --cc=gblack@eecs.umich.edu \
    --cc=kvm@vger.kernel.org \
    --cc=nate@binkert.org \
    --cc=stever@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).