public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix destroying a userspace physical memory slot
@ 2008-06-08  8:23 Ben-Ami Yassour
  2008-06-08 10:31 ` Avi Kivity
  0 siblings, 1 reply; 5+ messages in thread
From: Ben-Ami Yassour @ 2008-06-08  8:23 UTC (permalink / raw)
  To: avi; +Cc: kvm, Muli Ben-Yehuda, Amit Shah

Avi,

This patch fixes the destruction path of a userspace physical memory 
slot, which is required for direct mmio for passthrough devices.
The problem was that the destruction was done by calling 
kvm_create_phys_mem with length 0.
kvm_create_phys_mem was calling kvm_create_userspace_phys_mem, 
which calls mmap with lenght 0,  which failed.
This patch applies to the main kvm userspace tree.
The patch was tested with direct mmio using the pci-passthrough tree.

Regards,
Ben

>From 8593ddc76a7109670eb48338eee0e94a3cfaecb2 Mon Sep 17 00:00:00 2001
From: Ben-Ami Yassour <benami@il.ibm.com>
Date: Sun, 8 Jun 2008 10:41:35 +0300
Subject: [PATCH] KVM: fix destroy userspace physical memory slot

Signed-off-by: Ben-Ami Yassour <benami@il.ibm.com>
---
  libkvm/libkvm.c |   34 +++++++++++++++++++++++++++++++++-
  1 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 1e7bbed..a49cbdc 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -431,6 +431,32 @@ void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,
          return ptr;
  }

+void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
+				    unsigned long phys_start)
+{
+	int r;
+	struct kvm_userspace_memory_region memory = {
+		.memory_size = 0,
+		.guest_phys_addr = phys_start,
+		.flags = 0,
+	};
+
+	memory.userspace_addr = 0;
+	memory.slot = get_slot(phys_start);
+
+	if (memory.slot == -1)
+		return;
+
+	r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory);
+	if (r == -1) {
+		fprintf(stderr, "destroy_userspace_phys_mem: %s",
+			strerror(errno));
+		return;
+	}
+
+	free_slot(memory.slot);
+}
+
  #endif

  void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
@@ -584,7 +610,13 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
  			__FUNCTION__, phys_start, slots[slot].phys_addr);
  		phys_start = slots[slot].phys_addr;
  	}
-	kvm_create_phys_mem(kvm, phys_start, 0, 0, 0);
+
+#ifdef KVM_CAP_USER_MEMORY
+	if (ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY) > 0)
+		kvm_destroy_userspace_phys_mem(kvm, phys_start);
+	else
+#endif
+		kvm_create_kernel_phys_mem(kvm, phys_start, 0, 0, 0);
  }

  static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf)
-- 
1.5.5.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix destroying a userspace physical memory slot
  2008-06-08  8:23 [PATCH] fix destroying a userspace physical memory slot Ben-Ami Yassour
@ 2008-06-08 10:31 ` Avi Kivity
  2008-06-08 12:07   ` fix destroy " benami
  0 siblings, 1 reply; 5+ messages in thread
From: Avi Kivity @ 2008-06-08 10:31 UTC (permalink / raw)
  To: Ben-Ami Yassour; +Cc: kvm, Muli Ben-Yehuda, Amit Shah

Ben-Ami Yassour wrote:
> Avi,
>
> This patch fixes the destruction path of a userspace physical memory 
> slot, which is required for direct mmio for passthrough devices.
> The problem was that the destruction was done by calling 
> kvm_create_phys_mem with length 0.
> kvm_create_phys_mem was calling kvm_create_userspace_phys_mem, which 
> calls mmap with lenght 0, which failed.
> This patch applies to the main kvm userspace tree.
> The patch was tested with direct mmio using the pci-passthrough tree.

Looks good, but doesn't apply. Please check your mail client's 
whitespace mangling settings (or post as attachment).

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* fix destroy userspace physical memory slot
  2008-06-08 10:31 ` Avi Kivity
@ 2008-06-08 12:07   ` benami
  2008-06-08 12:08     ` [PATCH] KVM: " benami
  0 siblings, 1 reply; 5+ messages in thread
From: benami @ 2008-06-08 12:07 UTC (permalink / raw)
  To: avi; +Cc: kvm, amit.shah, muli

here it is again, this time sent with git-send-mail.

Regards,
Ben



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] KVM: fix destroy userspace physical memory slot
  2008-06-08 12:07   ` fix destroy " benami
@ 2008-06-08 12:08     ` benami
  2008-06-09 15:55       ` Avi Kivity
  0 siblings, 1 reply; 5+ messages in thread
From: benami @ 2008-06-08 12:08 UTC (permalink / raw)
  To: avi; +Cc: kvm, amit.shah, muli, Ben-Ami Yassour

From: Ben-Ami Yassour <benami@il.ibm.com>

Signed-off-by: Ben-Ami Yassour <benami@il.ibm.com>
---
 libkvm/libkvm.c |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 1e7bbed..a49cbdc 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -431,6 +431,32 @@ void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,
         return ptr;
 }
 
+void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
+				    unsigned long phys_start)
+{
+	int r;
+	struct kvm_userspace_memory_region memory = {
+		.memory_size = 0,
+		.guest_phys_addr = phys_start,
+		.flags = 0,
+	};
+
+	memory.userspace_addr = 0;
+	memory.slot = get_slot(phys_start);
+
+	if (memory.slot == -1)
+		return;
+
+	r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory);
+	if (r == -1) {
+		fprintf(stderr, "destroy_userspace_phys_mem: %s",
+			strerror(errno));
+		return;
+	}
+
+	free_slot(memory.slot);
+}
+
 #endif
 
 void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
@@ -584,7 +610,13 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
 			__FUNCTION__, phys_start, slots[slot].phys_addr);
 		phys_start = slots[slot].phys_addr;
 	}
-	kvm_create_phys_mem(kvm, phys_start, 0, 0, 0);
+
+#ifdef KVM_CAP_USER_MEMORY
+	if (ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY) > 0)
+		kvm_destroy_userspace_phys_mem(kvm, phys_start);
+	else
+#endif
+		kvm_create_kernel_phys_mem(kvm, phys_start, 0, 0, 0);
 }
 
 static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf)
-- 
1.5.5.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: fix destroy userspace physical memory slot
  2008-06-08 12:08     ` [PATCH] KVM: " benami
@ 2008-06-09 15:55       ` Avi Kivity
  0 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2008-06-09 15:55 UTC (permalink / raw)
  To: benami; +Cc: kvm, amit.shah, muli

benami@il.ibm.com wrote:
> From: Ben-Ami Yassour <benami@il.ibm.com>
>
>   

Applied, thanks.

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-06-09 15:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-08  8:23 [PATCH] fix destroying a userspace physical memory slot Ben-Ami Yassour
2008-06-08 10:31 ` Avi Kivity
2008-06-08 12:07   ` fix destroy " benami
2008-06-08 12:08     ` [PATCH] KVM: " benami
2008-06-09 15:55       ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox