public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: Ben-Ami Yassour <benami@il.ibm.com>
Cc: Amit Shah <amit.shah@qumranet.com>,
	kvm@vger.kernel.org, Han Weidong <weidong.han@intel.com>,
	"Kay, Allen M" <allen.m.kay@intel.com>,
	Muli Ben-Yehuda <muli@il.ibm.com>
Subject: Re: KVM: PCIPT: direct mmio
Date: Wed, 04 Jun 2008 17:16:39 +0300	[thread overview]
Message-ID: <4846A3C7.8010708@qumranet.com> (raw)
In-Reply-To: <alpine.DEB.1.10.0806031418000.8803@cluwyn.haifa.ibm.com>

Ben-Ami Yassour wrote:
> Amit,
>
> Below is the patch for PCI passthrough tree, it enables a guest to 
> access a device's
> memory mapped I/O regions directly, without requiring the host to trap 
> and
> emulate every MMIO access.
>
> This patch requires only userspace changes and it is relaying on the 
> kernel patch by Anthony: "Handle vma regions with no backing page". 
> Note that this patch requires CONFIG_NUMA to be set. It does require a 
> change to the VT-d that Allen sent a while ago, to avoid mapping of 
> memory slots with no backing page.
>
>
> diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
> index d1e95a4..ce062cb 100644
> --- a/libkvm/libkvm.c
> +++ b/libkvm/libkvm.c
> @@ -400,7 +400,7 @@ void *kvm_create_userspace_phys_mem(kvm_context_t 
> kvm, unsigned long phys_start,
>  {
>      int r;
>      int prot = PROT_READ;
> -    void *ptr;
> +    void *ptr = NULL;
>      struct kvm_userspace_memory_region memory = {
>          .memory_size = len,
>          .guest_phys_addr = phys_start,
> @@ -410,16 +410,24 @@ void 
> *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long 
> phys_start,
>      if (writable)
>          prot |= PROT_WRITE;
>
> -    ptr = mmap(NULL, len, prot, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
> -    if (ptr == MAP_FAILED) {
> -        fprintf(stderr, "create_userspace_phys_mem: %s", 
> strerror(errno));
> -        return 0;
> -    }
> +    if (len > 0) {
> +        ptr = mmap(NULL, len, prot, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
> +        if (ptr == MAP_FAILED) {
> +            fprintf(stderr, "create_userspace_phys_mem: %s",
> +                strerror(errno));
> +            return 0;
> +        }

You're using 'len == 0' here to change the semantics of the function.  
It would be better to have two different APIs (perhaps sharing some of 
the implementation by calling a helper).

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


  reply	other threads:[~2008-06-04 14:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-03 11:21 KVM: PCIPT: direct mmio Ben-Ami Yassour
2008-06-04 14:16 ` Avi Kivity [this message]
     [not found] <OF02BEEB69.3AC5BC32-ONC225745E.007719ED-C225745E.00772C47@il.ibm.com>
2008-06-04 22:01 ` Ben-Ami Yassour
2008-06-05 13:20   ` Avi Kivity

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=4846A3C7.8010708@qumranet.com \
    --to=avi@qumranet.com \
    --cc=allen.m.kay@intel.com \
    --cc=amit.shah@qumranet.com \
    --cc=benami@il.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=muli@il.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