KVM ivshmem enquiry
Subsystems (3)
Cam,I am interested in the shared memory support you developed on
KVM, but the whole process is not very clear to me. I patched the kernel on the
guest OSs and used the samples codes found in http://www.mail-archive.com/[email protected]/msg13328.html, but the applications fails in mmap.
I have not done anything at booting the guest OS, and I am using vanilla qemu-kvm. I guest I am missing something for initialization.
Do I need to patch qemu/kvm also? Where can I find the most recent ivshmem patches for the guest kernel and kvm if applicable. What is the proper way to start the guest OS to enable shared memory?
If you have developed a documentation or a complete working example, please refer me to it.
I appreciate your help.
Thank you,
-Khaled
_________________________________________________________________
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/201469227/direct/01/
Hi Khaled,
Quoted 8 lines · Khaled Ibrahim
Cam,I am interested in the shared memory support you developed on
KVM, but the whole process is not very clear to me. I patched the kernel on the
guest OSs and used the samples codes found in http://www.mail-archive.com/[email protected]/msg13328.html, but the applications fails in mmap.I have not done anything at booting the guest OS, and I am using vanilla qemu-kvm. I guest I am missing something for initialization.
Do I need to patch qemu/kvm also? Where can I find the most recent ivshmem patches for the guest kernel and kvm if applicable. What is the proper way to start the guest OS to enable shared memory?
You need two patches, one for qemu and one of the linux kernel. The linux kernel patch is just a driver, so you could compile it separately (you don't need to re-compile the whole kernel). I will send two patches soon, one is for qemu-kvm and the other is the driver.
Once you have patches and compiled qemu-kvm, you need to add a command-line argument
-ivshmem <size>,<name>
where <size> is the size in MB of the POSIX shared object you want to create and <name> is the name to use for it (not a full path). After you start kvm with this command-line argument, a file will be created at /dev/shm/<name> of the size you specify.
Quoted 2 lines
If you have developed a documentation or a complete working example, please refer me to it.
Documentation is scarce at this point as the implementation is still under development, but feel free to ask any questions you have via email.
I do have a set of sample code and OS init scripts (to create the device file in the guest) here:
http://www.gitorious.org/nahanni/
Cheers,
Cam
Quoted 14 lines
I appreciate your help.
Thank you,
-Khaled
_________________________________________________________________
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/201469227/direct/01/
PATCH 1/1 Support an inter-vm shared memory device that maps a shared-memory object
This device now creates a qemu character device and sends 1-bytes messages to trigger interrupts. Writes are trigger by writing to the "Doorbell" register on the shared memory PCI device. The lower 8-bits of the value written to this register are sent as the 1-byte message so different meanings of interrupts can be supported.
Interrupts are supported between multiple VMs by using a shared memory server
-ivshmem <shm object>,<size in MB>,[unix:<path>][file]
Interrupts can also be used between host and guest as well by implementing a listener on the host that talks to shared memory server. The shared memory server passes file descriptors for the shared memory object and eventfds (our interrupt mechanism) to the respective qemu instances.
Sample programs and init scripts are available in a git repo here:
www.gitorious.org/nahanni
--- Makefile.target | 3 + hw/ivshmem.c | 678 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pc.c | 6 + hw/pc.h | 3 + qemu-char.c | 7 + qemu-char.h | 3 + qemu-options.hx | 12 + sysemu.h | 8 + vl.c | 13 + 9 files changed, 733 insertions(+), 0 deletions(-) create mode 100644 hw/ivshmem.c
Makefile.target +3 -0
@@ -216,6 +216,9 @@ obj-y += pcnet.o obj-y += rtl8139.o obj-y += e1000.o +# Inter-VM PCI shared memory +obj-y += ivshmem.o + # Hardware support obj-i386-y = ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/piix.o obj-i386-y += pckbd.o $(sound-obj-y) dma.o
hw/ivshmem.c new file +678 -0
678 lines not on this page · raw message
hw/pc.c +6 -0
@@ -74,6 +74,8 @@ static PCII440FXState *i440fx_state;qemu_irq *ioapic_irq_hack; +extern int ivshmem_enabled; + typedef struct isa_irq_state { qemu_irq *i8259; qemu_irq *ioapic;
@@ -938,6 +940,10 @@ static void pc_init1(ram_addr_t ram_size, } } +if (pci_enabled && ivshmem_enabled) { +pci_ivshmem_init (pci_bus); + } + rtc_state =rtc_init (2000 );qemu_register_boot_set (pc_boot_set, rtc_state);
hw/pc.h +3 -0
@@ -167,6 +167,9 @@ void isa_ne2000_init(int base, int irq, NICInfo *nd);void extboot_init (BlockDriverState *bs); +/* ivshmem.c */ +int pci_ivshmem_init (PCIBus *bus); +int cpu_is_bsp (CPUState *env);#endif
qemu-char.c +7 -0
@@ -1706,6 +1706,7 @@ static CharDriverState *qemu_chr_open_win_pipe(QemuOpts *opts)WinCharState *s; chr =qemu_mallocz (sizeof (CharDriverState)); + s =qemu_mallocz (sizeof (WinCharState)); chr->opaque = s; chr->chr_write = win_chr_write;
@@ -2049,6 +2050,12 @@ static void tcp_chr_read(void *opaque) } } +CharDriverState *qemu_chr_open_eventfd (int eventfd){ + +return qemu_chr_open_fd (eventfd, eventfd); + +} +static void tcp_chr_connect (void *opaque) {CharDriverState *chr = opaque;
qemu-char.h +3 -0
@@ -93,6 +93,9 @@ void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);void qemu_chr_info (Monitor *mon,QObject **ret_data);CharDriverState *qemu_chr_find (const char *name); +/* add an eventfd to the qemu devices that are polled */ +CharDriverState *qemu_chr_open_eventfd (int eventfd); +extern int term_escape_char;/* async I/O support */
qemu-options.hx +12 -0
@@ -1679,6 +1679,18 @@ STEXI Setup monitor on chardev @var{name}. ETEXI +DEF("ivshmem", HAS_ARG, QEMU_OPTION_ivshmem, \ + "-ivshmem size,unix:file connects to shared memory PCI card server \ + listening on unix domain socket 'path' of at least 'size' (in MB) and \ + exposes as a PCI device in the guest\n") +STEXI +@item -ivshmem @var{size},unix:@var{file} +Connects to a shared memory PCI server at UDS @var{file} that shares a POSIX +shared object of size @var{size} and creates a PCI device of the same size that +maps the shared object (received from the server) into the device for guests to +access. The servers also sends eventfds to the guest to support interrupts. +ETEXI + DEF("debugcon", HAS_ARG, QEMU_OPTION_debugcon, \ "-debugcon dev redirect the debug console to char device 'dev'\n") STEXI
sysemu.h +8 -0
@@ -237,6 +237,14 @@ extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS ]; +/* inter-VM shared memory devices */ + +#define MAX_IVSHMEM_DEVICES 1 + +extern CharDriverState * ivshmem_chardev; +void ivshmem_init (const char * optarg); +int ivshmem_get_size (void ); +#define TFR (expr) do { if ((expr) != -1) break; } while (errno == EINTR)#ifdef HAS_AUDIO
vl.c +13 -0
@@ -195,6 +195,7 @@ int autostart;static int rtc_utc =1 ;static int rtc_date_offset =-1 ;/* -1 means no change */ QEMUClock *rtc_clock; +int ivshmem_enabled =0 ;int vga_interface_type =VGA_NONE ;#ifdef TARGET_SPARC int graphic_width =1024 ;
@@ -213,6 +214,8 @@ int no_quit = 0;CharDriverState *serial_hds[MAX_SERIAL_PORTS ];CharDriverState *parallel_hds[MAX_PARALLEL_PORTS ];CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES ]; +CharDriverState *ivshmem_chardev; +const char * ivshmem_device;#ifdef TARGET_I386 int win2k_install_hack =0 ;int rtc_td_hack =0 ;
@@ -4885,6 +4888,8 @@ int main(int argc, char **argv, char **envp) kernel_cmdline ="" ; cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ; + ivshmem_device =NULL ; + ivshmem_chardev =NULL ;for (i =0 ; i <MAX_NODES ; i++) { node_mem[i] =0 ;
@@ -5366,6 +5371,10 @@ int main(int argc, char **argv, char **envp)add_device_config (DEV_PARALLEL , optarg); default_parallel =0 ;break ; +case QEMU_OPTION_ivshmem: + ivshmem_device = optarg; + ivshmem_enabled =1 ; +break ;case QEMU_OPTION_debugcon:add_device_config (DEV_DEBUGCON , optarg);break ;
@@ -5883,6 +5892,10 @@ int main(int argc, char **argv, char **envp)if (ram_size ==0 ) ram_size =DEFAULT_RAM_SIZE *1024 *1024 ; +if (ivshmem_enabled) { +ivshmem_init (ivshmem_device); + } +/* init the dynamic translator */ cpu_exec_init_all (tb_size *1024 *1024 );
Signature · 1 line
1.6.0.6
IVSHMEM and limits on shared memory
Hi Cam,
I used your patches successfully to support shared memory on KVM and used the test cases successfully, but qemu-kvm crashes when I increased the size of the shared memory. I
applied the ivshmem patch to qemu-kvm-0.12.3 (some manual patching was needed). It worked flawlessly for
up to 128MB of shared memory on my system. I am running on a machine with 64GB memory running opensuse (kernel 2.6.27) on AMD opteron.
Qemu crashes with
smp=4 and the shared memory requested in 256MB, (512MB with smp=1), even though the shared memory file is created. I debugged the problem and it seems that some memory corruptions happens.
It crashes in the subpage_register for rtl8139 pci driver!, tracked back to rtl8139_mmio_map. The problem starts with corrupted value in the config field in the struct for the rtl8139 driver. At offset 20 of this field the address should indicate that the address is uninitialized at that time of crash, but surprisingly the value changes over the course of execution and gets the SIZE of the shared memory allocated (related to ivshmem). I failed to identify what changes/corrupts that field. I tried some padding for allocation but the field always gets updated with the size of the shared memory in a very consistent way.
Do you have clue what might be causing this problem?
Thanks,
-Khaled
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/201469230/direct/01/
Re: IVSHMEM and limits on shared memory
Quoted 11 lines · Khaled Ibrahim
Hi Cam,
I used your patches successfully to support shared memory on KVM and used the test cases successfully, but qemu-kvm crashes when I increased the size of the shared memory. I
applied the ivshmem patch to qemu-kvm-0.12.3 (some manual patching was needed). It worked flawlessly for
up to 128MB of shared memory on my system. I am running on a machine with 64GB memory running opensuse (kernel 2.6.27) on AMD opteron.
Quoted 4 lines
Qemu crashes with
smp=4 and the shared memory requested in 256MB, (512MB with smp=1), even though the shared memory file is created. I debugged the problem and it seems that some memory corruptions happens.
Can you please provide the full command-line for the smp=1 instance?
Quoted 11 lines
It crashes in the
subpage_registerfor rtl8139 pci driver!, tracked back tortl8139_mmio_map. The problem starts with corrupted value in the config field in the struct for the rtl8139 driver. At offset 20 of this field the address should indicate that the address is uninitialized at that time of crash, but surprisingly the value changes over the course of execution and gets the SIZE of the shared memory allocated (related to ivshmem). I failed to identify what changes/corrupts that field. I tried some padding for allocation but the field always gets updated with the size of the shared memory in a very consistent way.
As far as you know does anything in the guest trigger the corruption? Does the corruption happen immediately or after running some of the test programs?
Thanks,
Cam
RE: IVSHMEM and limits on shared memory
----------------------------------------
Quoted 18 lines
Date: Wed, 3 Mar 2010 15:09:17 -0700
Subject: Re: IVSHMEM and limits on shared memory
From: [email protected]
To: [email protected]
CC: [email protected]Quoted 11 lines · Khaled Ibrahim
Hi Cam,
I used your patches successfully to support shared memory on KVM and used the test cases successfully, but qemu-kvm crashes when I increased the size of the shared memory. I
applied the ivshmem patch to qemu-kvm-0.12.3 (some manual patching was needed). It worked flawlessly for
up to 128MB of shared memory on my system. I am running on a machine with 64GB memory running opensuse (kernel 2.6.27) on AMD opteron.
Quoted 6 lines
Quoted 4 lines
Qemu crashes with
smp=4 and the shared memory requested in 256MB, (512MB with smp=1), even though the shared memory file is created. I debugged the problem and it seems that some memory corruptions happens.Can you please provide the full command-line for the smp=1 instance?
qemu-system-x86_64 ./qemudisk0.raw \ -net nic,model=rtl8139,macaddr=52:54:00:12:34:50\ -net tap,ifname=tap0,script=no,downscript=no \ -m 4096 \ -ivshmem 512,kvmshmem\ -smp 1 \ -usb \ -usbdevice tablet \ -localtime
Quoted 13 lines
Quoted 12 lines
It crashes in the
subpage_registerfor rtl8139 pci driver!, tracked back tortl8139_mmio_map. The problem starts with corrupted value in the config field in the struct for the rtl8139 driver. At offset 20 of this field the address should indicate that the address is uninitialized at that time of crash, but surprisingly the value changes over the course of execution and gets the SIZE of the shared memory allocated (related to ivshmem). I failed to identify what changes/corrupts that field. I tried some padding for allocation but the field always gets updated with the size of the shared memory in a very consistent way.
Quoted 3 lines
As far as you know does anything in the guest trigger the corruption? Does the corruption happen immediately or after running some of the test programs?
The boot process does not complete, and it fails before it reach grub.
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/201469226/direct/01/
Re: IVSHMEM and limits on shared memory
Quoted 22 lines · Khaled Ibrahim
----------------------------------------
Quoted 18 lines
Date: Wed, 3 Mar 2010 15:09:17 -0700
Subject: Re: IVSHMEM and limits on shared memory
From: [email protected]
To: [email protected]
CC: [email protected]Quoted 11 lines · Khaled Ibrahim
Hi Cam,
I used your patches successfully to support shared memory on KVM and used the test cases successfully, but qemu-kvm crashes when I increased the size of the shared memory. I
applied the ivshmem patch to qemu-kvm-0.12.3 (some manual patching was needed). It worked flawlessly for
up to 128MB of shared memory on my system. I am running on a machine with 64GB memory running opensuse (kernel 2.6.27) on AMD opteron.
Quoted 21 lines
Quoted 6 lines
Quoted 4 lines
Qemu crashes with
smp=4 and the shared memory requested in 256MB, (512MB with smp=1), even though the shared memory file is created. I debugged the problem and it seems that some memory corruptions happens.Can you please provide the full command-line for the smp=1 instance?
qemu-system-x86_64 ./qemudisk0.raw \ -net nic,model=rtl8139,macaddr=52:54:00:12:34:50\ -net tap,ifname=tap0,script=no,downscript=no \ -m 4096 \ -ivshmem 512,kvmshmem\ -smp 1 \ -usb \ -usbdevice tablet \ -localtime
Quoted 11 lines
Quoted 11 lines
It crashes in the
subpage_registerfor rtl8139 pci driver!, tracked back tortl8139_mmio_map. The problem starts with corrupted value in the config field in the struct for the rtl8139 driver. At offset 20 of this field the address should indicate that the address is uninitialized at that time of crash, but surprisingly the value changes over the course of execution and gets the SIZE of the shared memory allocated (related to ivshmem). I failed to identify what changes/corrupts that field. I tried some padding for allocation but the field always gets updated with the size of the shared memory in a very consistent way.
Good debugging. I've been able to reproduce your error when applying my patch to qemu-kvm-0.12.3 and can trace the error to the subpage_register. Curiously, this bug does not occur with the latest version from the git repo. I've tested up to 1 GB without problem. So I'm not sure if it's an error in my patch or elsewhere in the memory management that has since been fixed.
As a test, I removed anywhere my patch stored the size of the shared memory region and hard coded the size of 512 MB into qemu_ram_alloc and pci_register_bar, so that my patch never writes the size of the memory region anywhere. And I discovered that the value of 512MB still shows up at the offset you mention, so it seems something else is storing that value in the wrong location and corrupting memory.
Can you try using the version from the git repo and see if the error recurs?
Cam
Quoted 12 lines
Quoted 5 lines
Quoted 1 line
As far as you know does anything in the guest trigger the corruption? Does the corruption happen immediately or after running some of the test programs?
The boot process does not complete, and it fails before it reach grub.
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/201469226/direct/01/
RE: IVSHMEM and limits on shared memory
Quoted 10 lines
As a test, I removed anywhere my patch stored the size of the shared memory region and hard coded the size of 512 MB into
qemu_ram_allocandpci_register_bar, so that my patch never writes the size of the memory region anywhere. And I discovered that the value of 512MB still shows up at the offset you mention, so it seems something else is storing that value in the wrong location and corrupting memory.Can you try using the version from the git repo and see if the error recurs?
Thank you Cam. I tried to build using git repo, but the build crashes while booting on my machine without the shared memory patch. I used git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git. Which git repo are you using? Can you send me a ivshmem patched qemu-kvm, or tell me which stable qemu-kvm repo should I use?
Thanks,
-Khaled
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/201469226/direct/01/
Re: IVSHMEM and limits on shared memory
Quoted 9 lines · Khaled Ibrahim
Quoted 9 lines
As a test, I removed anywhere my patch stored the size of the shared memory region and hard coded the size of 512 MB into
qemu_ram_allocandpci_register_bar, so that my patch never writes the size of the memory region anywhere. And I discovered that the value of 512MB still shows up at the offset you mention, so it seems something else is storing that value in the wrong location and corrupting memory.
Quoted 3 lines
Quoted 1 line
Can you try using the version from the git repo and see if the error recurs?
Thank you Cam. I tried to build using git repo, but the build crashes while booting on my machine without the shared memory patch. I used
git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git. Which git repo are you using? Can you send me a ivshmem patched qemu-kvm, or tell me which stable qemu-kvm repo should I use?
That's the correct repo.
Your VM crashes using the latest git repo? That is unusual. I'll send you a tar ball off-list of a patched version of KVM.
Quoted 9 lines
Thanks,
-Khaled_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/201469226/direct/01/
PATCH 1/1 Driver to support shared memory device with inerrupts
In reply to Cam MacdonellThis driver allows the guest VM to access shared memory between other guest that is a POSIX shared memory object on the host. The driver can also send interrupts by writing to the DoorBell register.
With interrupts, the ioctl must specify the ID of the VM to receive the interrupt or '255' for broadcast to all active VMs. The 'arg' parameter is the destination VM and 'cmd' is the interrupt code. The value written to the register is a bit messy. 32-bits are written to the register, the upper 16 are the destination VM, and the lower 16 are the interrupt 'code' that the destination guest will receive. Implemented codes (see the interrupt handler) either call up on the device's semaphore or wake up on the wait_event queue. These codes' uses are at the discretion of the driver so they could be customized.
For ioctls that read values from the device (such as for getting the global ID of the guest) the arg parameter is unused.
Cam
--- drivers/char/Kconfig | 8 + drivers/char/Makefile | 2 + drivers/char/kvm_ivshmem.c | 455 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 465 insertions(+), 0 deletions(-) create mode 100644 drivers/char/kvm_ivshmem.c
drivers/char/Kconfig +8 -0
@@ -1103,6 +1103,14 @@ config DEVPORT depends on ISA || PCI default y +config KVM_IVSHMEM + tristate "Inter-VM Shared Memory Device" + depends on PCI + default m + help + This device maps a region of shared memory between the host OS and any + number of virtual machines. + source "drivers/s390/char/Kconfig" endmenu
drivers/char/Makefile +2 -0
@@ -111,6 +111,8 @@ obj-$(CONFIG_PS3_FLASH) += ps3flash.o obj-$(CONFIG_JS_RTC) += js-rtc.o js-rtc-y = rtc.o +obj-$(CONFIG_KVM_IVSHMEM) += kvm_ivshmem.o + # Files generated that shall be removed upon make clean clean-files := consolemap_deftbl.c defkeymap.c
drivers/char/kvm_ivshmem.c new file +455 -0
455 lines not on this page · raw message
Signature · 1 line
1.6.0.6