From patchwork Mon May 7 11:38:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 157295 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 F16D6B6FB9 for ; Mon, 7 May 2012 21:38:45 +1000 (EST) Received: from localhost ([::1]:38808 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRMH5-00053Y-T3 for incoming@patchwork.ozlabs.org; Mon, 07 May 2012 07:38:43 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRMGv-000539-TI for qemu-devel@nongnu.org; Mon, 07 May 2012 07:38:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SRMGn-0004Tk-U5 for qemu-devel@nongnu.org; Mon, 07 May 2012 07:38:33 -0400 Received: from cantor2.suse.de ([195.135.220.15]:43171 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRMGn-0004Sa-Nh for qemu-devel@nongnu.org; Mon, 07 May 2012 07:38:25 -0400 Received: from relay2.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 63B208FFEB; Mon, 7 May 2012 13:38:24 +0200 (CEST) Mime-Version: 1.0 (Apple Message framework v1257) From: Alexander Graf In-Reply-To: Date: Mon, 7 May 2012 13:38:23 +0200 Message-Id: References: <1336383010-28692-1-git-send-email-agraf@suse.de> To: Peter Maydell X-Mailer: Apple Mail (2.1257) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Riku Voipio , qemu-devel Developers Subject: Re: [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 On 07.05.2012, at 13:32, Alexander Graf wrote: > > On 07.05.2012, at 12:37, Peter Maydell wrote: > >> On 7 May 2012 10:30, Alexander Graf wrote: >>> @@ -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; >> >> The comment at the top of tb_invalidate_phys_page_range() says >> "start and end must refer to the same physical page" -- is it >> out of date or does that not apply to user-mode? >> >> Do you need to also invalidate the range on munmap() and >> mprotect-to-not-executable in order to correctly fault on >> the case of: >> map something >> execute it >> unmap it >> try to execute it again >> >> ? (haven't tested that case but it seems like it might be an issue) > > Yeah, the issue does exist: And the below patch on top of my revised patch fixes it. The question is whether we still need to flush on mmap() then? Alex diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 3611deb..bb4e752 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -690,8 +690,10 @@ int target_munmap(abi_ulong start, abi_ulong len) } } - if (ret == 0) + if (ret == 0) { page_set_flags(start, start + len, 0); + tb_invalidate_phys_range(start, start + len, 0); + } mmap_unlock(); return ret; }