Re: [Qemu-devel] [PATCH 2/2 v2][UPDATED] Direct IDE I/O

2007-12-18 Thread Avi Kivity

Paul Brook wrote:

Unfortunately it is more complicated to write to the CPU memory. In
particular, specific action should be done when translated code is
present. A consistent API must include something like cpu_page_lock() /
unlock(). Look at cpu_physical_memory_rw() to see the various issues
which must be handled. Moreover, it would be better to add bus specific
APIs (at least for PCI), but I can accept a CPU memory API for now.



In general it may also be unsafe to do async writes directly to guest memory 
because you break the atomicity of loads/stores.


  


But that is true on real hardware as well, I think.  The guest cannot 
expect atomicity if it dmas into the memory it is accessing.


Also, it would be a rare guest that accesses memory while dma is active.

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





Re: [Qemu-devel] [PATCH 2/2 v2][UPDATED] Direct IDE I/O

2007-12-18 Thread Laurent Vivier
Le mardi 18 décembre 2007 à 00:03 +, Paul Brook a écrit :
> On Monday 17 December 2007, Fabrice Bellard wrote:
> > Laurent Vivier wrote:
> > > This patch enhances the "-drive ,cache=off" mode with IDE drive emulation
> > > by removing the buffer used in the IDE emulation.
> > > ---
> > >  block.c |   10 +++
> > >  block.h |2
> > >  block_int.h |1
> > >  cpu-all.h   |1
> > >  exec.c  |   19 ++
> > >  hw/ide.c|  176
> > > +--- vl.c   
> > > |1
> > >  7 files changed, 204 insertions(+), 6 deletions(-)
> > > [...]
> >
> > Unfortunately it is more complicated to write to the CPU memory. In
> > particular, specific action should be done when translated code is
> > present. A consistent API must include something like cpu_page_lock() /
> > unlock(). Look at cpu_physical_memory_rw() to see the various issues
> > which must be handled. Moreover, it would be better to add bus specific
> > APIs (at least for PCI), but I can accept a CPU memory API for now.
> 
> In general it may also be unsafe to do async writes directly to guest memory 
> because you break the atomicity of loads/stores.

Thank you for your comments.

I had some doubts on this patch too. I will not resend it.
I will resend only the first one corrected with comments from Fabrice
(malloc()/free()).

Regards,
Laurent
-- 
- [EMAIL PROTECTED]  --
  "La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry


signature.asc
Description: Ceci est une partie de message	numériquement signée


Re: [Qemu-devel] [PATCH 2/2 v2][UPDATED] Direct IDE I/O

2007-12-17 Thread Paul Brook
On Monday 17 December 2007, Fabrice Bellard wrote:
> Laurent Vivier wrote:
> > This patch enhances the "-drive ,cache=off" mode with IDE drive emulation
> > by removing the buffer used in the IDE emulation.
> > ---
> >  block.c |   10 +++
> >  block.h |2
> >  block_int.h |1
> >  cpu-all.h   |1
> >  exec.c  |   19 ++
> >  hw/ide.c|  176
> > +--- vl.c   
> > |1
> >  7 files changed, 204 insertions(+), 6 deletions(-)
> > [...]
>
> Unfortunately it is more complicated to write to the CPU memory. In
> particular, specific action should be done when translated code is
> present. A consistent API must include something like cpu_page_lock() /
> unlock(). Look at cpu_physical_memory_rw() to see the various issues
> which must be handled. Moreover, it would be better to add bus specific
> APIs (at least for PCI), but I can accept a CPU memory API for now.

In general it may also be unsafe to do async writes directly to guest memory 
because you break the atomicity of loads/stores.

Paul




Re: [Qemu-devel] [PATCH 2/2 v2][UPDATED] Direct IDE I/O

2007-12-17 Thread Fabrice Bellard
Laurent Vivier wrote:
> This patch enhances the "-drive ,cache=off" mode with IDE drive emulation
> by removing the buffer used in the IDE emulation.
> ---
>  block.c |   10 +++
>  block.h |2 
>  block_int.h |1 
>  cpu-all.h   |1 
>  exec.c  |   19 ++
>  hw/ide.c|  176 
> +---
>  vl.c|1 
>  7 files changed, 204 insertions(+), 6 deletions(-)
> [...]

Unfortunately it is more complicated to write to the CPU memory. In
particular, specific action should be done when translated code is
present. A consistent API must include something like cpu_page_lock() /
unlock(). Look at cpu_physical_memory_rw() to see the various issues
which must be handled. Moreover, it would be better to add bus specific
APIs (at least for PCI), but I can accept a CPU memory API for now.

Fabrice.




[Qemu-devel] [PATCH 2/2 v2][UPDATED] Direct IDE I/O

2007-12-17 Thread Laurent Vivier

This patch enhances the "-drive ,cache=off" mode with IDE drive emulation
by removing the buffer used in the IDE emulation.
---
 block.c |   10 +++
 block.h |2 
 block_int.h |1 
 cpu-all.h   |1 
 exec.c  |   19 ++
 hw/ide.c|  176 +---
 vl.c|1 
 7 files changed, 204 insertions(+), 6 deletions(-)

Index: qemu/block.c
===
--- qemu.orig/block.c   2007-12-17 21:48:30.0 +0100
+++ qemu/block.c2007-12-17 22:21:23.0 +0100
@@ -758,6 +758,11 @@ void bdrv_set_translation_hint(BlockDriv
 bs->translation = translation;
 }
 
+void bdrv_set_cache_hint(BlockDriverState *bs, int cache)
+{
+bs->cache = cache;
+}
+
 void bdrv_get_geometry_hint(BlockDriverState *bs,
 int *pcyls, int *pheads, int *psecs)
 {
@@ -786,6 +791,11 @@ int bdrv_is_read_only(BlockDriverState *
 return bs->read_only;
 }
 
+int bdrv_is_cached(BlockDriverState *bs)
+{
+return bs->cache;
+}
+
 /* XXX: no longer used */
 void bdrv_set_change_cb(BlockDriverState *bs,
 void (*change_cb)(void *opaque), void *opaque)
Index: qemu/block.h
===
--- qemu.orig/block.h   2007-12-17 21:48:30.0 +0100
+++ qemu/block.h2007-12-17 22:21:23.0 +0100
@@ -113,6 +113,7 @@ void bdrv_set_geometry_hint(BlockDriverS
 int cyls, int heads, int secs);
 void bdrv_set_type_hint(BlockDriverState *bs, int type);
 void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
+void bdrv_set_cache_hint(BlockDriverState *bs, int cache);
 void bdrv_get_geometry_hint(BlockDriverState *bs,
 int *pcyls, int *pheads, int *psecs);
 int bdrv_get_type_hint(BlockDriverState *bs);
@@ -120,6 +121,7 @@ int bdrv_get_translation_hint(BlockDrive
 int bdrv_is_removable(BlockDriverState *bs);
 int bdrv_is_read_only(BlockDriverState *bs);
 int bdrv_is_inserted(BlockDriverState *bs);
+int bdrv_is_cached(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
 int bdrv_is_locked(BlockDriverState *bs);
 void bdrv_set_locked(BlockDriverState *bs, int locked);
Index: qemu/block_int.h
===
--- qemu.orig/block_int.h   2007-12-17 21:39:22.0 +0100
+++ qemu/block_int.h2007-12-17 22:21:23.0 +0100
@@ -124,6 +124,7 @@ struct BlockDriverState {
drivers. They are not used by the block driver */
 int cyls, heads, secs, translation;
 int type;
+int cache;
 char device_name[32];
 BlockDriverState *next;
 };
Index: qemu/cpu-all.h
===
--- qemu.orig/cpu-all.h 2007-12-13 09:19:28.0 +0100
+++ qemu/cpu-all.h  2007-12-17 22:21:23.0 +0100
@@ -838,6 +838,7 @@ int cpu_register_io_memory(int io_index,
 CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index);
 CPUReadMemoryFunc **cpu_get_io_memory_read(int io_index);
 
+extern uint8_t * cpu_physical_page_addr(target_phys_addr_t addr);
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
 int len, int is_write);
 static inline void cpu_physical_memory_read(target_phys_addr_t addr,
Index: qemu/exec.c
===
--- qemu.orig/exec.c2007-12-17 09:09:56.0 +0100
+++ qemu/exec.c 2007-12-17 22:21:23.0 +0100
@@ -2071,6 +2071,25 @@ void cpu_register_physical_memory(target
 }
 }
 
+uint8_t * cpu_physical_page_addr(target_phys_addr_t addr)
+{
+target_phys_addr_t page;
+unsigned long pd;
+PhysPageDesc *p;
+unsigned long addr1;
+
+page = addr & TARGET_PAGE_MASK;
+p = phys_page_find(page >> TARGET_PAGE_BITS);
+if (!p)
+   return (uint8_t*)-1;
+
+pd = p->phys_offset;
+
+addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
+
+return phys_ram_base + addr1;
+}
+
 /* XXX: temporary until new memory mapping API */
 uint32_t cpu_get_physical_page_desc(target_phys_addr_t addr)
 {
Index: qemu/hw/ide.c
===
--- qemu.orig/hw/ide.c  2007-12-17 21:48:30.0 +0100
+++ qemu/hw/ide.c   2007-12-17 22:21:23.0 +0100
@@ -815,7 +815,7 @@ static int dma_buf_rw(BMDMAState *bm, in
 }
 
 /* XXX: handle errors */
-static void ide_read_dma_cb(void *opaque, int ret)
+static void ide_read_dma_cb_buffered(void *opaque, int ret)
 {
 BMDMAState *bm = opaque;
 IDEState *s = bm->ide_if;
@@ -855,7 +855,86 @@ static void ide_read_dma_cb(void *opaque
 printf("aio_read: sector_num=%lld n=%d\n", sector_num, n);
 #endif
 bm->aiocb = bdrv_aio_read(s->bs, sector_num, s->io_buffer, n,
-  ide_read_dma_cb, bm);
+