public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Muli Ben-Yehuda <muli@il.ibm.com>
Cc: Ben-Ami Yassour1 <BENAMI@il.ibm.com>,
	amit.shah@qumranet.com, weidong.han@intel.com,
	raharper@us.ibm.com, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: PCIPT: VT-d: fix guest unmap
Date: Wed, 18 Jun 2008 16:41:23 -0500	[thread overview]
Message-ID: <48598103.8060504@codemonkey.ws> (raw)
In-Reply-To: <20080618212346.GL7186@il.ibm.com>

Muli Ben-Yehuda wrote:
> On Wed, Jun 18, 2008 at 03:48:33PM -0500, Anthony Liguori wrote:
>
>   
>> Right.  But this is not ideal.  Instead of pinning up-front, it
>> would make more sense IMHO to build the VT-d table as the shadow
>> page table gets faulted in.  In certain circumstances, this will
>> result in extraneous updates (because a GPA=>HPA mapping is already
>> present) and that's where we should eliminate iotlb flushes.
>>     
>
> As Ben wrote, we can't do this and must fault everything in up-front
> (assuming no PVDMA API). Assume we don't do this: it is valid for the
> guest to program the device with a GPA that does not yet have a
> corresponding HPA (because the guest did not write or read to/from it
> and thus we haven't yet faulted in a frame for it). Then, once the
> device DMA's to it, the DMA will be stopped incorrectly.
>   

As I've said, the lack of PVDMA API is a special case.  The key is to 
use the same internal infrastructure.

>>> Obviously, pinning the entire guest is not desirable since we waste
>>> a lot of memory resources, but this is the approach that we
>>> currently have. Do you find it good enough for a merge with the
>>> main KVM tree, and optimize later?
>>>       
>> No, it's not safe.  What happens mmap(MAP_FIXED) into phys_ram_base?
>> We need to use MMU notifiers to handle such events and appropriately
>> flush the iotlb.
>>     
>
> Could you elaborate on what you mean here and what is not safe? Our
> current approach is to just fault in all of guest memory---are you
> concerned about a case where some of the guest frames get replaced by
> other frames because of the mmap()? 
>   

Because the guest is now accessing memory that is not guest memory.  
When mmu-notifiers forcefully change a mapping, we need to react to it.

> I'd like to stress that we are shooting at the moment for the simplest
> possible solution that is good enough, so that we'll be able to
> finally merge this into the tree...
>   

I don't think what I'm suggesting is more code than the current 
implementation and it fits more cleanly into KVM.

>>> I'm not sure how we can do that... the guest can send a guest
>>> physical address to the device for DMA, even without generating a
>>> page-fault on the host for that address... which implies that the
>>> host must pin the entire guest memory in advance. agree?
>>>       
>> See above.  Ideally we would wait until the first PCI config space
>> access for a device before special casing the guest.  Otherwise,
>> there's no way to allow a DMA-aware guest to avoid pinning up front.
>>     
>
> Err, if the user gave the guest pass-through access to a PCI device,
> presumably it is because the guest will use it... What do we win by
> delaying the inevitable?
>   

s/DMA-aware/PVDMA-aware/

You do not know if a guest is PVDMA-aware until the guest tells you 
so.   If you pin all of memory before the guest starts running, you may 
not have needed to allocate all of that memory.  As we move to 
cooperative memory management between the host and guest, I expect the 
normal circumstance will be to launch a guest with far more memory than 
it needs relying on the fact that the guest will not touch that memory.  
Pinning memory unconditionally defeats this.

In terms of merging, I don't think it's going to be reasonable to merge 
for 2.6.27 so there's not much of an argument for not doing it correctly.

Regards,

Anthony Liguori

> Cheers,
> Muli
>   


  reply	other threads:[~2008-06-18 21:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-17 19:05 Patches for vtd pci passthrough benami
2008-06-17 19:05 ` [PATCH] KVM: PCIPT: fix compilation errors benami
2008-06-17 19:05   ` [PATCH] KVM: PCIPT: VT-d: fix guest unmap benami
2008-06-17 19:05     ` [PATCH] KVM: PCIPT: free device structure on vm destroy benami
2008-06-17 19:05       ` [PATCH] KVM: PCIPT: VT-d: fix context mapping benami
2008-06-17 19:25         ` KVM: PCIPT: temporary fix for pio (userspace part) benami
2008-06-17 19:25           ` [PATCH] " benami
2008-06-18 20:30         ` [PATCH] KVM: PCIPT: VT-d: fix context mapping Muli Ben-Yehuda
2008-06-19  8:59         ` Han, Weidong
2008-06-19 12:28           ` Ben-Ami Yassour
2008-06-19 14:18             ` Han, Weidong
2008-06-19 17:44               ` Ben-Ami Yassour1
2008-06-20  6:23                 ` Han, Weidong
2008-06-30 15:32                   ` Ben-Ami Yassour
2008-07-01  2:22                     ` Han, Weidong
2008-06-17 21:29     ` [PATCH] KVM: PCIPT: VT-d: fix guest unmap Anthony Liguori
2008-06-18 12:06       ` Ben-Ami Yassour
2008-06-18 20:48         ` Anthony Liguori
2008-06-18 21:23           ` Muli Ben-Yehuda
2008-06-18 21:41             ` Anthony Liguori [this message]
2008-06-20 18:59       ` Avi Kivity
2008-06-20 19:28         ` Anthony Liguori

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=48598103.8060504@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=BENAMI@il.ibm.com \
    --cc=amit.shah@qumranet.com \
    --cc=kvm@vger.kernel.org \
    --cc=muli@il.ibm.com \
    --cc=raharper@us.ibm.com \
    --cc=weidong.han@intel.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