From mboxrd@z Thu Jan 1 00:00:00 1970 From: Amit Shah Subject: Re: [patch 17/24] QEMU/KVM: add cpu_unregister_io_memory and make io mem table index dynamic Date: Tue, 18 Mar 2008 18:02:10 +0530 Message-ID: <200803181802.10575.amit.shah@qumranet.com> References: <20080311201151.959635433@localhost.localdomain> <20080311201418.562440022@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Avi Kivity , Marcelo Tosatti , qemu-devel@nongnu.org To: kvm-devel@lists.sourceforge.net Return-path: In-Reply-To: <20080311201418.562440022@localhost.localdomain> Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org This patch broke -no-kvm-irqchip: * On Wednesday 12 March 2008 01:42:08 Marcelo Tosatti wrote: > So drivers can clear their mem io table entries on exit back to unassigned > state. > > Also make the io mem index allocation dynamic. > > Signed-off-by: Marcelo Tosatti > > Index: kvm-userspace.hotplug2/qemu/cpu-all.h > =================================================================== > --- kvm-userspace.hotplug2.orig/qemu/cpu-all.h > +++ kvm-userspace.hotplug2/qemu/cpu-all.h > @@ -837,6 +837,7 @@ int cpu_register_io_memory(int io_index, > CPUReadMemoryFunc **mem_read, > CPUWriteMemoryFunc **mem_write, > void *opaque); > +void cpu_unregister_io_memory(int table_address); > CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index); > CPUReadMemoryFunc **cpu_get_io_memory_read(int io_index); > > Index: kvm-userspace.hotplug2/qemu/exec.c > =================================================================== > --- kvm-userspace.hotplug2.orig/qemu/exec.c > +++ kvm-userspace.hotplug2/qemu/exec.c > @@ -158,7 +158,7 @@ PhysPageDesc **l1_phys_map; > CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4]; > CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4]; > void *io_mem_opaque[IO_MEM_NB_ENTRIES]; > -static int io_mem_nb; > +char io_mem_used[IO_MEM_NB_ENTRIES]; > #if defined(CONFIG_SOFTMMU) > static int io_mem_watch; > #endif > @@ -2498,12 +2498,28 @@ static void *subpage_init (target_phys_a > return mmio; > } > > +static int get_free_io_mem_idx(void) > +{ > + int i; > + > + for (i = 0; i + if (!io_mem_used[i]) { > + io_mem_used[i] = 1; > + return i; > + } > + > + return -1; > +} > + > static void io_mem_init(void) > { > + int i; > + > cpu_register_io_memory(IO_MEM_ROM >> IO_MEM_SHIFT, error_mem_read, > unassigned_mem_write, NULL); cpu_register_io_memory(IO_MEM_UNASSIGNED >> > IO_MEM_SHIFT, unassigned_mem_read, unassigned_mem_write, NULL); > cpu_register_io_memory(IO_MEM_NOTDIRTY >> IO_MEM_SHIFT, error_mem_read, > notdirty_mem_write, NULL); - io_mem_nb = 5; > + for (i=0; i<5; i++) > + io_mem_used[i] = 0; The remaining bits (5..IO_MEM_NB_ENTRIES) aren't initialised. > > #if defined(CONFIG_SOFTMMU) > io_mem_watch = cpu_register_io_memory(-1, watch_mem_read, > @@ -2530,9 +2546,9 @@ int cpu_register_io_memory(int io_index, > int i, subwidth = 0; > > if (io_index <= 0) { > - if (io_mem_nb >= IO_MEM_NB_ENTRIES) > - return -1; > - io_index = io_mem_nb++; > + io_index = get_free_io_mem_idx(); > + if (io_index == -1) > + return io_index; io_mem_nb was initialised to 5 earlier; we now trample over the first 0..4 bits. This fixes the issue; please check for correctness. From: Amit Shah Date: Tue, 18 Mar 2008 18:01:05 +0530 Subject: [PATCH] QEMU/KVM: fix initialization of IO memory regions Signed-off-by: Amit Shah --- qemu/exec.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu/exec.c b/qemu/exec.c index edeb21a..be15433 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -2502,7 +2502,7 @@ static int get_free_io_mem_idx(void) { int i; - for (i = 0; i> IO_MEM_SHIFT, error_mem_read, unassigned_mem_write, NULL); cpu_register_io_memory(IO_MEM_UNASSIGNED >> IO_MEM_SHIFT, unassigned_mem_read, unassigned_mem_write, NULL); cpu_register_io_memory(IO_MEM_NOTDIRTY >> IO_MEM_SHIFT, error_mem_read, notdirty_mem_write, NULL); - for (i=0; i<5; i++) + for (i=5; i) id 1JbbL7-0000ly-W4 for qemu-devel@nongnu.org; Tue, 18 Mar 2008 08:54:50 -0400 From: Amit Shah Date: Tue, 18 Mar 2008 18:02:10 +0530 References: <20080311201151.959635433@localhost.localdomain> <20080311201418.562440022@localhost.localdomain> In-Reply-To: <20080311201418.562440022@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200803181802.10575.amit.shah@qumranet.com> Subject: [Qemu-devel] Re: [kvm-devel] [patch 17/24] QEMU/KVM: add cpu_unregister_io_memory and make io mem table index dynamic Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kvm-devel@lists.sourceforge.net Cc: Avi Kivity , Marcelo Tosatti , qemu-devel@nongnu.org This patch broke -no-kvm-irqchip: * On Wednesday 12 March 2008 01:42:08 Marcelo Tosatti wrote: > So drivers can clear their mem io table entries on exit back to unassigned > state. > > Also make the io mem index allocation dynamic. > > Signed-off-by: Marcelo Tosatti > > Index: kvm-userspace.hotplug2/qemu/cpu-all.h > =================================================================== > --- kvm-userspace.hotplug2.orig/qemu/cpu-all.h > +++ kvm-userspace.hotplug2/qemu/cpu-all.h > @@ -837,6 +837,7 @@ int cpu_register_io_memory(int io_index, > CPUReadMemoryFunc **mem_read, > CPUWriteMemoryFunc **mem_write, > void *opaque); > +void cpu_unregister_io_memory(int table_address); > CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index); > CPUReadMemoryFunc **cpu_get_io_memory_read(int io_index); > > Index: kvm-userspace.hotplug2/qemu/exec.c > =================================================================== > --- kvm-userspace.hotplug2.orig/qemu/exec.c > +++ kvm-userspace.hotplug2/qemu/exec.c > @@ -158,7 +158,7 @@ PhysPageDesc **l1_phys_map; > CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4]; > CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4]; > void *io_mem_opaque[IO_MEM_NB_ENTRIES]; > -static int io_mem_nb; > +char io_mem_used[IO_MEM_NB_ENTRIES]; > #if defined(CONFIG_SOFTMMU) > static int io_mem_watch; > #endif > @@ -2498,12 +2498,28 @@ static void *subpage_init (target_phys_a > return mmio; > } > > +static int get_free_io_mem_idx(void) > +{ > + int i; > + > + for (i = 0; i + if (!io_mem_used[i]) { > + io_mem_used[i] = 1; > + return i; > + } > + > + return -1; > +} > + > static void io_mem_init(void) > { > + int i; > + > cpu_register_io_memory(IO_MEM_ROM >> IO_MEM_SHIFT, error_mem_read, > unassigned_mem_write, NULL); cpu_register_io_memory(IO_MEM_UNASSIGNED >> > IO_MEM_SHIFT, unassigned_mem_read, unassigned_mem_write, NULL); > cpu_register_io_memory(IO_MEM_NOTDIRTY >> IO_MEM_SHIFT, error_mem_read, > notdirty_mem_write, NULL); - io_mem_nb = 5; > + for (i=0; i<5; i++) > + io_mem_used[i] = 0; The remaining bits (5..IO_MEM_NB_ENTRIES) aren't initialised. > > #if defined(CONFIG_SOFTMMU) > io_mem_watch = cpu_register_io_memory(-1, watch_mem_read, > @@ -2530,9 +2546,9 @@ int cpu_register_io_memory(int io_index, > int i, subwidth = 0; > > if (io_index <= 0) { > - if (io_mem_nb >= IO_MEM_NB_ENTRIES) > - return -1; > - io_index = io_mem_nb++; > + io_index = get_free_io_mem_idx(); > + if (io_index == -1) > + return io_index; io_mem_nb was initialised to 5 earlier; we now trample over the first 0..4 bits. This fixes the issue; please check for correctness. From: Amit Shah Date: Tue, 18 Mar 2008 18:01:05 +0530 Subject: [PATCH] QEMU/KVM: fix initialization of IO memory regions Signed-off-by: Amit Shah --- qemu/exec.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu/exec.c b/qemu/exec.c index edeb21a..be15433 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -2502,7 +2502,7 @@ static int get_free_io_mem_idx(void) { int i; - for (i = 0; i> IO_MEM_SHIFT, error_mem_read, unassigned_mem_write, NULL); cpu_register_io_memory(IO_MEM_UNASSIGNED >> IO_MEM_SHIFT, unassigned_mem_read, unassigned_mem_write, NULL); cpu_register_io_memory(IO_MEM_NOTDIRTY >> IO_MEM_SHIFT, error_mem_read, notdirty_mem_write, NULL); - for (i=0; i<5; i++) + for (i=5; i