From patchwork Mon Oct 16 17:26:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 115965 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3957882qgn; Mon, 16 Oct 2017 10:54:50 -0700 (PDT) X-Received: by 10.200.23.82 with SMTP id u18mr15177991qtk.163.1508176490595; Mon, 16 Oct 2017 10:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508176490; cv=none; d=google.com; s=arc-20160816; b=gZ4WZQfm53ghX7tWjiMG8shGua1Yd/vphvqD1L4pTplhsvX3VI1JuAPLn30OnDwh/+ KHpLuOO6ZBQR5bqfQ5OsUWVrf1FTceLc+dRuCSKMLe2AJ6dt0vWV0Lunkr6SlwAHqLsC 7WycjIUaCupgXlqlki6RLycQdZaLCu+5dQ2+l4CZzIj2oJChWhN2UDVgD3qYbg7Bi47j NvyITKsx54BcHUkFwnAAxgoNiqqpPRzqM6Qk5icZ/Ccr3X0K5O1PfVKPTkZZStRdt+9M fok8Rn4V8JJhRI+kjKqwZzCW7RIiEWGygYUdL9vvbvFA5H41d3h4WDP0GOt53UysADXn KiIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=6e72cvxx7Qfm+Rx17cGpbHvv52iihArS/ChNd5KPwAk=; b=MnuEw+sT7EmloY1FQN/h8Xnd+qIJsDu2R1Wz5LgPcbEsM53fBKmcJpNuOdvbZH7GTx sg8wp54ro7f/wLvmdr6lmDdYizy8FwEUVMUxpnCixYD5eqrqaK0LQVR+CGvXj+yvkTIl NDK95eMRN0FwPE28jcBp11V4+K4he8Vf9MOqkIvhumwD+TlrAfW4o4VdeN4rint8ShuU Kwje3D75FNtulcTZNNuXuL5XkcERcBXeWQlOCpsD+cd51rHZWxOXYShHLgb/a2HvoIgy gyOjcN0eNAqcYeMuZCaZDMSkL9lb/KrSyNw4z5WvhhWbwddf3oRYyhhlqO27IlaI1ZHH c/Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=klz3PaqF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v12si6994686qta.252.2017.10.16.10.54.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 16 Oct 2017 10:54:50 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=klz3PaqF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e49bE-0000PC-Jj for patch@linaro.org; Mon, 16 Oct 2017 13:54:48 -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) 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) 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) 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.13.6 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, size_t size1) static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] __attribute__((aligned(CODE_GEN_ALIGN))); -# 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 = (uintptr_t)addr; - start &= qemu_real_host_page_mask; - - end = (uintptr_t)addr + size; - end = 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 = static_code_gen_buffer; + void *end = static_code_gen_buffer + sizeof(static_code_gen_buffer); size_t full_size, size; - /* The size of the buffer, rounded down to end on a page boundary. */ - full_size = (((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 = QEMU_ALIGN_PTR_UP(buf, qemu_real_host_page_size); + end = QEMU_ALIGN_PTR_DOWN(end, qemu_real_host_page_size); /* Reserve a guard page. */ + full_size = end - buf; size = full_size - qemu_real_host_page_size; /* Honor a command-line option limiting the size of the buffer. */ if (size > tcg_ctx->code_gen_buffer_size) { - size = (((uintptr_t)buf + tcg_ctx->code_gen_buffer_size) - & qemu_real_host_page_mask) - (uintptr_t)buf; + size = QEMU_ALIGN_DOWN(tcg_ctx->code_gen_buffer_size, + qemu_real_host_page_size); } tcg_ctx->code_gen_buffer_size = size; @@ -671,8 +632,12 @@ static inline void *alloc_code_gen_buffer(void) } #endif - 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); return buf;