From nobody Tue Feb 10 16:21:50 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; dkim=fail; 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 1508176486258130.22038391686237; Mon, 16 Oct 2017 10:54:46 -0700 (PDT) Received: from localhost ([::1]:34409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e49b2-0000PC-Fs for importer@patchew.org; Mon, 16 Oct 2017 13:54:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e49Ah-0002vy-Aw for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:27:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e49Ag-0004Aj-57 for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:27:23 -0400 Received: from mail-pg0-x22a.google.com ([2607:f8b0:400e:c05::22a]:55273) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e49Af-0004AD-Vo for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:27:22 -0400 Received: by mail-pg0-x22a.google.com with SMTP id l24so7294698pgu.11 for ; Mon, 16 Oct 2017 10:27:21 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-104-76.tukw.qwest.net. [97.126.104.76]) by smtp.gmail.com with ESMTPSA id i187sm5594249pfc.96.2017.10.16.10.27.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Oct 2017 10:27:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6e72cvxx7Qfm+Rx17cGpbHvv52iihArS/ChNd5KPwAk=; b=klz3PaqFwrVNefFXr6rr41s0veG5Oa68bskf/3lWZXSQ6LG00OIJ3LkkLMyDlRGP/d vG3GtHhBCfDCZfr23Y/xXZ4eW5cDVjIGVCqVK35lKvBI+Apsf0y0P0qTPodY4gkuwY2+ sFFoB3RvofLm81OKRV3mRdFt/pWwbDiyte2kA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6e72cvxx7Qfm+Rx17cGpbHvv52iihArS/ChNd5KPwAk=; b=uNbkaUTWyD7PO2YBgKjd/EdAArlD40b/sHHC5uSzWqr0lotPpiJoOzDXZ3SE10YhHX bVbcTvbXoFRsh3ccgagOzH9dv67hvY1BWoaH9Oi9sBjbZ8sbizj+dgQp3CrK0D033r9b KtahFn6YOt/k5M1lVsyxo+P+X2/5zW9c0kltVLg4wlPZ0uDLiljlqoc6tNx0k5Xfp31A vudzW6JXTuNVffjd0SAAVkB9ni+YXccx4v7E2uyD6ozEOpaNQNnE6YPzzHiGpqB4zTVb fw9Uvrp/l+KzX4ySqFoQgnrtBu2UE9rNzGsurusXr3k3d+Zbsm86I8HWpx+ETq5Wr6YR 3rlw== X-Gm-Message-State: AMCzsaW5O1aNaVpF1dz/MhfznN/Wq56O5zISajz51YyIqOsjMf/8nY2J +U7ydeGdutES8r2VTfMRTQRf4X7kVLQ= X-Google-Smtp-Source: AOwi7QCqfBd80YJvWpmOAP37J8Dkcb83lW11fqfsDkK4J1MvTmNJrFyfm61cvqp5ep3HOnKP5CRG7g== X-Received: by 10.84.234.199 with SMTP id i7mr9485990plt.66.1508174840825; Mon, 16 Oct 2017 10:27:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 16 Oct 2017 10:26:07 -0700 Message-Id: <20171016172609.23422-49-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171016172609.23422-1-richard.henderson@linaro.org> References: <20171016172609.23422-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22a Subject: [Qemu-devel] [PATCH v6 48/50] translate-all: use qemu_protect_rwx/none helpers 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: cota@braap.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" The helpers require the address and size to be page-aligned, so do that before calling them. Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 61 ++++++++++---------------------------------= ---- 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 614bb3adcc..cc25b7555b 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -604,63 +604,24 @@ static inline void *split_cross_256mb(void *buf1, siz= e_t size1) static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] __attribute__((aligned(CODE_GEN_ALIGN))); =20 -# ifdef _WIN32 -static inline void do_protect(void *addr, long size, int prot) -{ - DWORD old_protect; - VirtualProtect(addr, size, prot, &old_protect); -} - -static inline void map_exec(void *addr, long size) -{ - do_protect(addr, size, PAGE_EXECUTE_READWRITE); -} - -static inline void map_none(void *addr, long size) -{ - do_protect(addr, size, PAGE_NOACCESS); -} -# else -static inline void do_protect(void *addr, long size, int prot) -{ - uintptr_t start, end; - - start =3D (uintptr_t)addr; - start &=3D qemu_real_host_page_mask; - - end =3D (uintptr_t)addr + size; - end =3D ROUND_UP(end, qemu_real_host_page_size); - - mprotect((void *)start, end - start, prot); -} - -static inline void map_exec(void *addr, long size) -{ - do_protect(addr, size, PROT_READ | PROT_WRITE | PROT_EXEC); -} - -static inline void map_none(void *addr, long size) -{ - do_protect(addr, size, PROT_NONE); -} -# endif /* WIN32 */ - static inline void *alloc_code_gen_buffer(void) { void *buf =3D static_code_gen_buffer; + void *end =3D static_code_gen_buffer + sizeof(static_code_gen_buffer); size_t full_size, size; =20 - /* 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; + /* page-align the beginning and end of the buffer */ + buf =3D QEMU_ALIGN_PTR_UP(buf, qemu_real_host_page_size); + end =3D QEMU_ALIGN_PTR_DOWN(end, qemu_real_host_page_size); =20 /* Reserve a guard page. */ + full_size =3D end - buf; size =3D full_size - qemu_real_host_page_size; =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 QEMU_ALIGN_DOWN(tcg_ctx->code_gen_buffer_size, + qemu_real_host_page_size); } tcg_ctx->code_gen_buffer_size =3D size; =20 @@ -671,8 +632,12 @@ static inline void *alloc_code_gen_buffer(void) } #endif =20 - map_exec(buf, size); - map_none(buf + size, qemu_real_host_page_size); + 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; --=20 2.13.6