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.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to