From nobody Tue Feb 10 01:16:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500237197660718.9268611746814; Sun, 16 Jul 2017 13:33:17 -0700 (PDT) Received: from localhost ([::1]:46830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWqE8-0007zj-6f for importer@patchew.org; Sun, 16 Jul 2017 16:33:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWpmg-0001Dl-Dt for qemu-devel@nongnu.org; Sun, 16 Jul 2017 16:05:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dWpmb-0008Sl-71 for qemu-devel@nongnu.org; Sun, 16 Jul 2017 16:04:54 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:36519) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dWpma-0008Rt-U5 for qemu-devel@nongnu.org; Sun, 16 Jul 2017 16:04:49 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 60AAA20A76; Sun, 16 Jul 2017 16:04:48 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 16 Jul 2017 16:04:48 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 25D9F2450F; Sun, 16 Jul 2017 16:04:48 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=rlH 6yV1pfD9yFuJY5DqIeHk0Oo5U/p8kn0nVEEah+i8=; b=DAbjf3DQ2BlbDit442H tOTnUT9XqvHWNBUO5XeyZx7y68sXjUdk9IBHknMbm3dVn9CZi4R6cXPC7gGQRiTr omPJ7fHBYIPxqMIPVNjkApdyXZxRVsi6C8ibdV9MqlvaVgPihI/35yKerrvog8NW TABYVvjJBw5JN5IFZxHR2+MU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=rlH6yV1pfD9yFuJY5DqIeHk0Oo5U/p8kn0nVEEah+ i8=; b=QX9gLVVTkrL6NylPnaP6YR1LuEv6EtsQYUuItlp44RbVqA/GHcx3fPr7H yOOODMhZpMfOIDPPnGoQcyYvtthqWkLvyD+jIT6nTfO+Sa64orwIzuK0DsDb5One Nw9RNt41erjQ5wJdlHCPfwAkHqvMJ46D/EopIYgXr1VYd/kAt3A95oESoKimRiw2 xHgUW5P3wtoYe9vZBjZN/2X23g89vhxNqLpo3ogGhtkVDuQgO3Pjr3tQbqn8mXcG V8NcfkBxs0c4GaCzKX7pS8IH+mDkqfG5vwGmaPICtX1q8mAo0jmpf7UbjY+S6xDW MOW5KzClBgrtygUaavSZiPXMXDOUg== X-ME-Sender: X-Sasl-enc: kW5gSliKGAQmt6W24IBQRzsv1KRnsBng808FTQRmE1Q6 1500235488 From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Sun, 16 Jul 2017 16:04:27 -0400 Message-Id: <1500235468-15341-45-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500235468-15341-1-git-send-email-cota@braap.org> References: <1500235468-15341-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH v2 44/45] translate-all: do not allocate a guard page for code_gen_buffer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" TCG regions already have a guard page. Signed-off-by: Emilio G. Cota --- accel/tcg/translate-all.c | 47 ++++++++++++-------------------------------= ---- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index c30d400..98aa63e 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -608,19 +608,11 @@ static uint8_t static_code_gen_buffer[DEFAULT_CODE_GE= N_BUFFER_SIZE] static inline void *alloc_code_gen_buffer(void) { void *buf =3D static_code_gen_buffer; - size_t full_size, size; - - /* The size of the buffer, rounded down to end on a page boundary. */ - full_size =3D (((uintptr_t)buf + sizeof(static_code_gen_buffer)) - & qemu_real_host_page_mask) - (uintptr_t)buf; - - /* Reserve a guard page. */ - size =3D full_size - qemu_real_host_page_size; + size_t size =3D sizeof(static_code_gen_buffer); =20 /* Honor a command-line option limiting the size of the buffer. */ if (size > tcg_ctx->code_gen_buffer_size) { - size =3D (((uintptr_t)buf + tcg_ctx->code_gen_buffer_size) - & qemu_real_host_page_mask) - (uintptr_t)buf; + size =3D tcg_ctx->code_gen_buffer_size; } tcg_ctx->code_gen_buffer_size =3D size; =20 @@ -634,9 +626,6 @@ static inline void *alloc_code_gen_buffer(void) if (qemu_mprotect_rwx(buf, size)) { abort(); } - if (qemu_mprotect_none(buf + size, qemu_real_host_page_size)) { - abort(); - } qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); =20 return buf; @@ -645,22 +634,16 @@ static inline void *alloc_code_gen_buffer(void) static inline void *alloc_code_gen_buffer(void) { size_t size =3D tcg_ctx->code_gen_buffer_size; - void *buf1, *buf2; - - /* Perform the allocation in two steps, so that the guard page - is reserved but uncommitted. */ - buf1 =3D VirtualAlloc(NULL, size + qemu_real_host_page_size, - MEM_RESERVE, PAGE_NOACCESS); - if (buf1 !=3D NULL) { - buf2 =3D VirtualAlloc(buf1, size, MEM_COMMIT, PAGE_EXECUTE_READWRI= TE); - assert(buf1 =3D=3D buf2); - } + void *buf; =20 - return buf1; + buf =3D VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, + PAGE_EXECUTE_READWRITE); + return buf; } #else static inline void *alloc_code_gen_buffer(void) { + int prot =3D PROT_WRITE | PROT_READ | PROT_EXEC; int flags =3D MAP_PRIVATE | MAP_ANONYMOUS; uintptr_t start =3D 0; size_t size =3D tcg_ctx->code_gen_buffer_size; @@ -694,8 +677,7 @@ static inline void *alloc_code_gen_buffer(void) # endif # endif =20 - buf =3D mmap((void *)start, size + qemu_real_host_page_size, - PROT_NONE, flags, -1, 0); + buf =3D mmap((void *)start, size, prot, flags, -1, 0); if (buf =3D=3D MAP_FAILED) { return NULL; } @@ -705,24 +687,23 @@ static inline void *alloc_code_gen_buffer(void) /* Try again, with the original still mapped, to avoid re-acquiring that 256mb crossing. This time don't specify an address. */ size_t size2; - void *buf2 =3D mmap(NULL, size + qemu_real_host_page_size, - PROT_NONE, flags, -1, 0); + void *buf2 =3D mmap(NULL, size, prot, flags, -1, 0); switch ((int)(buf2 !=3D MAP_FAILED)) { case 1: if (!cross_256mb(buf2, size)) { /* Success! Use the new buffer. */ - munmap(buf, size + qemu_real_host_page_size); + munmap(buf, size); break; } /* Failure. Work with what we had. */ - munmap(buf2, size + qemu_real_host_page_size); + munmap(buf2, size); /* fallthru */ default: /* Split the original buffer. Free the smaller half. */ buf2 =3D split_cross_256mb(buf, size); size2 =3D tcg_ctx->code_gen_buffer_size; if (buf =3D=3D buf2) { - munmap(buf + size2 + qemu_real_host_page_size, size - size= 2); + munmap(buf + size2, size - size2); } else { munmap(buf, size - size2); } @@ -733,10 +714,6 @@ static inline void *alloc_code_gen_buffer(void) } #endif =20 - /* Make the final buffer accessible. The guard page at the end - will remain inaccessible with PROT_NONE. */ - mprotect(buf, size, PROT_WRITE | PROT_READ | PROT_EXEC); - /* Request large pages for the buffer. */ qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); =20 --=20 2.7.4