fix destroying a userspace physical memory slot
PATCH 1/1 fix destroying a userspace physical memory slot
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
Quoted 1 line
From
8593ddc76a7109670eb48338eee0e94a3cfaecb2Mon Sep 17 00:00:00 2001
From: Ben-Ami Yassour <[email protected]>
Date: Sun, 8 Jun 2008 10:41:35 +0300
Subject: [PATCH] KVM: fix destroy userspace physical memory slot
--- libkvm/libkvm.c | 34 +++++++++++++++++++++++++++++++++- 1 files changed, 33 insertions(+), 1 deletions(-)
libkvm/libkvm.c +33 -1
@@ -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)
Signature · 1 line
1.5.5.1
Quoted 7 lines · Ben-Ami Yassour
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_memwith length 0.kvm_create_phys_memwas callingkvm_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).
Signature · 1 line
error compiling committee.c: too many arguments to function
fix destroy userspace physical memory slot
here it is again, this time sent with git-send-mail.
Regards,
Ben
PATCH 1/1 KVM: fix destroy userspace physical memory slot
From: Ben-Ami Yassour <[email protected]>
--- libkvm/libkvm.c | 34 +++++++++++++++++++++++++++++++++- 1 files changed, 33 insertions(+), 1 deletions(-)
libkvm/libkvm.c +33 -1
@@ -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)
Signature · 1 line
1.5.5.1
Avi Kivity
AppliedRe: [PATCH] KVM: fix destroy userspace physical memory slot
Quoted 3 lines · [email protected] wrote:
From: Ben-Ami Yassour <[email protected]>
Applied, thanks.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.