From patchwork Thu Jan 14 06:03:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Gang X-Patchwork-Id: 567270 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 29A7F140317 for ; Thu, 14 Jan 2016 17:05:01 +1100 (AEDT) Received: from localhost ([::1]:40371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJb1n-000722-3Q for incoming@patchwork.ozlabs.org; Thu, 14 Jan 2016 01:04:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJb1Y-0006lf-9s for qemu-devel@nongnu.org; Thu, 14 Jan 2016 01:04:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJb1T-0002MD-7O for qemu-devel@nongnu.org; Thu, 14 Jan 2016 01:04:44 -0500 Received: from out1134-243.mail.aliyun.com ([42.120.134.243]:33079) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJb1S-0002JS-RB for qemu-devel@nongnu.org; Thu, 14 Jan 2016 01:04:39 -0500 X-Alimail-AntiSpam: AC=CONTINUE; BC=0.09741054|-1; FP=0|0|0|0|0|-1|-1|-1; HT=e01l10418; MF=chengang@emindsoft.com.cn; NM=1; PH=DS; RN=8; RT=7; SR=0; TI=SMTPD_----4S91HIa_1452751455; Received: from localhost.localdomain(mailfrom:chengang@emindsoft.com.cn ip:36.110.17.42) by smtp.aliyun-inc.com(10.147.42.198); Thu, 14 Jan 2016 14:04:29 +0800 From: chengang@emindsoft.com.cn To: pbonzini@redhat.com, crosthwaite.peter@gmail.com, rth@twiddle.net Date: Thu, 14 Jan 2016 14:03:42 +0800 Message-Id: <1452751422-11624-1-git-send-email-chengang@emindsoft.com.cn> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 42.120.134.243 Cc: peter.maydell@linaro.org, Chen Gang , qemu-devel@nongnu.org, Chen Gang Subject: [Qemu-devel] [PATCH] translate-all.c: Remove writable protection feature for tb_alloc_page() 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 From: Chen Gang Guest may allocate a readable, writable, and executable page, then write data on the page, and execute data as code on the page too, then write anther data still within the page. So remove this feature from linux-user: it not only consumes a little performance, but also causes issue with the old Linux kernel under some of architectures (they will directly generate segment fault for it). Signed-off-by: Chen Gang --- translate-all.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/translate-all.c b/translate-all.c index 042a857..1b6e95d 100644 --- a/translate-all.c +++ b/translate-all.c @@ -1430,34 +1430,7 @@ static inline void tb_alloc_page(TranslationBlock *tb, p->first_tb = (TranslationBlock *)((uintptr_t)tb | n); invalidate_page_bitmap(p); -#if defined(CONFIG_USER_ONLY) - if (p->flags & PAGE_WRITE) { - target_ulong addr; - PageDesc *p2; - int prot; - - /* force the host page as non writable (writes will have a - page fault + mprotect overhead) */ - page_addr &= qemu_host_page_mask; - prot = 0; - for (addr = page_addr; addr < page_addr + qemu_host_page_size; - addr += TARGET_PAGE_SIZE) { - - p2 = page_find(addr >> TARGET_PAGE_BITS); - if (!p2) { - continue; - } - prot |= p2->flags; - p2->flags &= ~PAGE_WRITE; - } - mprotect(g2h(page_addr), qemu_host_page_size, - (prot & PAGE_BITS) & ~PAGE_WRITE); -#ifdef DEBUG_TB_INVALIDATE - printf("protecting code page: 0x" TARGET_FMT_lx "\n", - page_addr); -#endif - } -#else +#if !defined(CONFIG_USER_ONLY) /* if some code is already present, then the pages are already protected. So we handle the case where only the first TB is allocated in a physical page */