From: Avi Kivity <avi@qumranet.com>
To: Marcelo Tosatti <marcelo@kvack.org>
Cc: kvm-devel <kvm-devel@lists.sourceforge.net>
Subject: Re: large page support for kvm
Date: Fri, 22 Feb 2008 09:16:24 +0200 [thread overview]
Message-ID: <47BE76C8.50108@qumranet.com> (raw)
In-Reply-To: <20080222020129.GA3041@dmt>
Marcelo Tosatti wrote:
>>>
>>>
>> I don't follow. Can you describe the scenario in more detail? The state
>> of the guest and shadow page tables, and what actually happens?
>>
>
> Have a kernel level-3 table at guest physical address 0x2800000.
> The kernel direct translation which maps to that address is
> 0xffff810002800000.
>
> The problem will occur if an instruction which can't be emulated
> attempts to write via 0xffff810002800000 (optionally +4KB), with the
> 3-level table not yet shadowed.
>
> What happens then is:
>
> - mmu_page_fault()
> - is_largepage_backed() finds no entry in the 0x2800000+2MB
> shadow page count, happily saying its OK to use a largepage.
> - shadow the 4-level entry
> - shadow the 3-level entry (at 0x2800000).
> - mmu_set_spte() sets the 2MB translation to be read-only, pt_write=1.
> - the instruction emulation fails (because its not supported).
> - kvm_mmu_unprotect_page() zaps the 3-level shadow table at 0x2800000.
> - repeat
>
> Thinking this was an issue related to largepages only I decided to never
> have 2MB forced-read-only pages around.
>
> But I just noted that the same issue happens with 4kB pages too, even
> though the chance of having one of the roots cached in the area being
> mapped is much larger with 2MB pages.
>
> I could not reproduce this anymore (though I have logs of that happening
> on a stock kernel, attached), but a modified kernel allocating the
> 3-level entries at the proper place and writing to one of them through
> the virtual mapping with an instruction which can't be emulated triggers
> the issue (and its a valid scenario).
>
> That said, it does not seem this problem should be dealt with in this
> largepage patch (it can be made comparable to the current problem if we
> never attempt to emulate instructions when a forced-read-only large page
> is instantiated).
>
> Do you see any way to fix that?
>
A write to page that is a page table that also maps the instruction
itself or one of the operands must be emulated. The best fix IMO is to
implement the missing instruction in the emulator (I'm surprised we have
such a missing instruction, btw, I thought it was reasonably complete
wrt paging).
There are other potential fixes, like single-stepping the instruction in
the guest and re-shadowing the page, but they are a can of worms and I
don't think we want to go that way.
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
prev parent reply other threads:[~2008-02-22 7:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-29 17:20 large page support for kvm Avi Kivity
[not found] ` <479F604C.20107-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-01-30 18:40 ` Joerg Roedel
[not found] ` <20080130184035.GS6960-5C7GfCeVMHo@public.gmane.org>
2008-01-31 5:44 ` Avi Kivity
2008-02-11 15:49 ` Marcelo Tosatti
2008-02-12 11:55 ` Avi Kivity
2008-02-13 0:15 ` Marcelo Tosatti
2008-02-13 6:45 ` Avi Kivity
2008-02-14 23:17 ` Marcelo Tosatti
2008-02-15 7:40 ` Roedel, Joerg
2008-02-17 9:38 ` Avi Kivity
2008-02-19 20:37 ` Marcelo Tosatti
2008-02-20 14:25 ` Avi Kivity
2008-02-22 2:01 ` Marcelo Tosatti
2008-02-22 7:16 ` 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=47BE76C8.50108@qumranet.com \
--to=avi@qumranet.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=marcelo@kvack.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