From: Ian Jackson Date: Fri, 8 May 2009 16:26:01 +0000 (+0100) Subject: Fix DMA emualtion for ia64. X-Git-Tag: xen-4.0.0-rc1~89 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b75434dd1971faf17c06a4d67e4e1cd38097e725;p=qemu-xen-4.0-testing.git Fix DMA emualtion for ia64. For DMA in native system, operating system depends on platform flushes icache of memory touched by DMA operations. But as to virtual DMA of virtual machine, dma emulation code has to use explicit instructions to flush icahce,otherwise, guest may use old icache and leads to guest's crash. Signed-off-by: Xiantao Zhang Signed-off-by: Yang Zhang --- diff --git a/cache-utils.h b/cache-utils.h index b45fde44..561d2517 100644 --- a/cache-utils.h +++ b/cache-utils.h @@ -34,8 +34,20 @@ static inline void flush_icache_range(unsigned long start, unsigned long stop) asm volatile ("isync" : : : "memory"); } +#elif defined (__ia64__) +static inline void flush_icache_range(unsigned long start, unsigned long stop) +{ + while (start < stop) { + asm volatile ("fc %0" :: "r"(start)); + start += 32; + } + asm volatile (";;sync.i;;srlz.i;;"); +} + +#define qemu_cache_utils_init(envp) do { (void) (envp); } while (0) #else #define qemu_cache_utils_init(envp) do { (void) (envp); } while (0) #endif + #endif /* QEMU_CACHE_UTILS_H */ diff --git a/cutils.c b/cutils.c index 4541214d..5137fe13 100644 --- a/cutils.c +++ b/cutils.c @@ -23,6 +23,7 @@ */ #include "qemu-common.h" #include "host-utils.h" +#include "cache-utils.h" void pstrcpy(char *buf, size_t buf_size, const char *str) { @@ -157,6 +158,12 @@ void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count) if (copy > qiov->iov[i].iov_len) copy = qiov->iov[i].iov_len; memcpy(qiov->iov[i].iov_base, p, copy); + +#ifdef __ia64__ + flush_icache_range((unsigned long)qiov->iov[i].iov_base, + (unsigned long)(qiov->iov[i].iov_base + copy)); +#endif + p += copy; count -= copy; } diff --git a/dma-helpers.c b/dma-helpers.c index b2ade19a..0523dc8d 100644 --- a/dma-helpers.c +++ b/dma-helpers.c @@ -9,6 +9,7 @@ #include "dma.h" #include "block_int.h" +#include "cache-utils.h" void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint) { @@ -135,6 +136,19 @@ static BlockDriverAIOCB *dma_bdrv_io( dbs->bh = NULL; qemu_iovec_init(&dbs->iov, sg->nsg); dma_bdrv_cb(dbs, 0); + +#ifdef __ia64__ + if (!is_write) { + int i; + QEMUIOVector *qiov; + qiov = &dbs->iov; + for (i = 0; i < qiov->niov; ++i) { + flush_icache_range((unsigned long)qiov->iov[i].iov_base, + (unsigned long)(qiov->iov[i].iov_base + qiov->iov[i].iov_len)); + } + } +#endif + return dbs->acb; }