From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=36623 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q8FzA-0002SO-Bs for qemu-devel@nongnu.org; Fri, 08 Apr 2011 14:00:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q8Fz8-0005J1-7B for qemu-devel@nongnu.org; Fri, 08 Apr 2011 14:00:44 -0400 Received: from ch1ehsobe003.messaging.microsoft.com ([216.32.181.183]:34486 helo=ch1outboundpool.messaging.microsoft.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q8Fz8-0005Ih-0Y for qemu-devel@nongnu.org; Fri, 08 Apr 2011 14:00:42 -0400 Received: from mail142-ch1 (localhost.localdomain [127.0.0.1]) by mail142-ch1-R.bigfish.com (Postfix) with ESMTP id 9F0A11BE86A6 for ; Fri, 8 Apr 2011 18:00:39 +0000 (UTC) Received: from CH1EHSMHS023.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.254]) by mail142-ch1.bigfish.com (Postfix) with ESMTP id 7B6B417004F for ; Fri, 8 Apr 2011 18:00:39 +0000 (UTC) Date: Fri, 8 Apr 2011 13:00:29 -0500 From: Scott Wood Message-ID: <20110408180028.GA22376@schlenkerla.am.freescale.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline Subject: [Qemu-devel] [PATCH] KVM: flush icache after writing to RAM List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is required so that the guest does not execute any stale instructions. qemu-kvm does this in cpu_physical_memory_rw, but not in cpu_physical_memory_write_rom. Signed-off-by: Scott Wood --- exec.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/exec.c b/exec.c index 983c0db..055d304 100644 --- a/exec.c +++ b/exec.c @@ -33,6 +33,7 @@ #include "osdep.h" #include "kvm.h" #include "qemu-timer.h" +#include "cache-utils.h" #if defined(CONFIG_USER_ONLY) #include #include @@ -3768,6 +3769,12 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, cpu_physical_memory_set_dirty_flags( addr1, (0xff & ~CODE_DIRTY_FLAG)); } + /* qemu doesn't execute guest code directly, but kvm does + therefore flush instruction caches */ + if (kvm_enabled()) { + flush_icache_range((unsigned long)ptr, + (unsigned long)ptr + l); + } } } else { if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && @@ -3838,6 +3845,13 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr, /* ROM/RAM case */ ptr = qemu_get_ram_ptr(addr1); memcpy(ptr, buf, l); + + /* qemu doesn't execute guest code directly, but kvm does + therefore flush instruction caches */ + if (kvm_enabled()) { + flush_icache_range((unsigned long)ptr, + (unsigned long)ptr + l); + } } len -= l; buf += l; -- 1.7.1