From patchwork Mon May 7 09:30:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 157282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B812FB6FAA for ; Mon, 7 May 2012 19:30:34 +1000 (EST) Received: from localhost ([::1]:35086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRKH1-0000Q7-Gy for incoming@patchwork.ozlabs.org; Mon, 07 May 2012 05:30:31 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRKGq-0000Pz-LG for qemu-devel@nongnu.org; Mon, 07 May 2012 05:30:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SRKGk-0002Af-Cx for qemu-devel@nongnu.org; Mon, 07 May 2012 05:30:20 -0400 Received: from cantor2.suse.de ([195.135.220.15]:38044 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRKGk-0002AP-6g for qemu-devel@nongnu.org; Mon, 07 May 2012 05:30:14 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 779AEA3DFC; Mon, 7 May 2012 11:30:11 +0200 (CEST) From: Alexander Graf To: qemu-devel Developers Date: Mon, 7 May 2012 11:30:10 +0200 Message-Id: <1336383010-28692-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.6.0.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Peter Maydell , Riku Voipio Subject: [Qemu-devel] [PATCH] linux-user: Fix stale tbs after mmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If we execute linux-user code that does the following: * A = mmap() * execute code in A * munmap(A) * B = mmap(), but mmap returns the same address as A * execute code in B we end up executing a stale cached tb that contains translated code from A, while we want new code from B. This patch adds a TB flush for mmap'ed regions, before we return them, avoiding the whole issue. Reported-by: Peter Maydell Signed-off-by: Alexander Graf --- linux-user/mmap.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 2620f88..390e940 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -587,6 +587,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, page_dump(stdout); printf("\n"); #endif + tb_invalidate_phys_page_range(start, start + len, 0); mmap_unlock(); return start; fail: @@ -768,6 +769,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, page_set_flags(old_addr, old_addr + old_size, 0); page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID); } + tb_invalidate_phys_page_range(new_addr, new_addr + new_size, 0); mmap_unlock(); return new_addr; }