From patchwork Tue Oct 10 00:55:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 115318 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3169958qgn; Mon, 9 Oct 2017 18:02:32 -0700 (PDT) X-Received: by 10.55.162.198 with SMTP id l189mr12105128qke.168.1507597352508; Mon, 09 Oct 2017 18:02:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507597352; cv=none; d=google.com; s=arc-20160816; b=t64JrPs8swB/q4oLEg3CESLGZzse+68J1m6+wHqXss8nVy0Yl5PHh+9QVAtxZNOkcF qxve/kgWvI7HFcfDagwLXtyso4WKuB9FAMXpxyuoEdbncjU3deNby1xnZ5Qz5g2GiJg8 0P02vgFqXRxcsUOsbPoqHpKB1kkOHhUjMegM9MJL3ZI9u3wTco1mkju5uSZMfvPQu5xC qetQ1P1Vt4TdGepA8bQzDQe1oBmZBmCnETP5qkHVIsd0g6pqHJq6S8sKQNH7UuaAssHE djzmNE52lxc8l/i/fh9b9XeDCq0V6BhP3NH4eWk0YktypRxkbqwxgQQmAL9D6cn4/drA EVrg== 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=z+pefpIGLM8aANgmdhXMT5MM3MztYymtG/VEnRTl2d8=; b=ft5nmwuvOoJH+KxoA9RJ2I9GjKGEzEChAGfALc2wF/VIBmsP39prGE//LTnRP1XpvW W8ykiIFM+bLTc9mS7rPiPANYnp+i1/nlOufV8BPgo6UtEK105w5+mV9RhXn1mLhtiTFT etkRhVnKi2wQLdShIonBx9Pfx0oVhPayKvRTfPKBRbpfVMTw3ZQJ/2nt8OWsMVeWgN4z awI/9d116o1KYu3HTxQ5LyZZeiE2DWxzp7f1oS1T8yfmRkqcP+KfYbwgRS0GgGvdoh4l kEYgR4pL1ycDXpvSRVhYC0LjahbESuLmDrCTceBIrbtNfts8zEzK6j1SEAy4OP4eJGSC EAuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IT/rwST3; 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 n23si687905qkn.377.2017.10.09.18.02.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 09 Oct 2017 18:02:32 -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=IT/rwST3; 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]:60511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1iwI-00075i-D4 for patch@linaro.org; Mon, 09 Oct 2017 21:02:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1iqY-0002XF-HH for qemu-devel@nongnu.org; Mon, 09 Oct 2017 20:56:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1iqV-0004bM-Js for qemu-devel@nongnu.org; Mon, 09 Oct 2017 20:56:34 -0400 Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]:48100) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1iqV-0004am-E7 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 20:56:31 -0400 Received: by mail-pf0-x235.google.com with SMTP id z11so5533583pfk.4 for ; Mon, 09 Oct 2017 17:56:31 -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=z+pefpIGLM8aANgmdhXMT5MM3MztYymtG/VEnRTl2d8=; b=IT/rwST3VdW2JT4MKyi7i6A66hvcJ/TQWIVzAXctv8uGbYTH8Nh9QRAMc6jNmrrAO6 7Kf5lWYzL9KZZydLut1HrP4ShQnSk1xWVObGD7gRHPODAxReiWkpOmBivV7yqM4EKNzA wr/WDeCBiKymaQO6SEcsykniDgfpD0S0HGYI0= 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=z+pefpIGLM8aANgmdhXMT5MM3MztYymtG/VEnRTl2d8=; b=cFLYO07RqHk5uarILT662TPF9QaBQBTrglzcDGVAceQUpVzMEb6pamQPkbyWuIh2jq OlNPDUvMzsSR3icpjMgruraUIRDI6nfvELPNzZUYUZxDh4as82rG0RHRzmMEJuddrYzD thB3MHSlLJJgsDUqseMshmyiwhYLiCfmgCDAmVBHLErPdg/DC/S0g40p+KLwO91Duxxl 2Ulsf0XBYaE8WHTFaDgVzQ9mO3KMTA4Def+Bn8Fwl4K+nRXiaoAwAbab1op6Fzp/4Kgz vGpWHKQgtp4c0Oqg17tnNPJenDPGmrwV5LgcdkVl+4P1oYacgqHMAgMopSdDdoJJzIXk wrvQ== X-Gm-Message-State: AMCzsaUaq+uwRiGplDcRgSchijltUD9MeaA86RCIrdCGnOu/cvfiyzjY b8m8fewulsdYZekO0R5j1gahcq55hxw= X-Google-Smtp-Source: AOwi7QBy4MYVLsT+36qgrIijmxG+eotb1UI3/xp+4m0ySJVSl8CM6A8gzAFlgdGOXQGxi84nyPCmPw== X-Received: by 10.84.247.16 with SMTP id n16mr10643632pll.180.1507596990197; Mon, 09 Oct 2017 17:56:30 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-104-76.tukw.qwest.net. [97.126.104.76]) by smtp.gmail.com with ESMTPSA id n19sm17121368pfj.52.2017.10.09.17.56.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Oct 2017 17:56:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 9 Oct 2017 17:55:58 -0700 Message-Id: <20171010005600.28735-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171010005600.28735-1-richard.henderson@linaro.org> References: <20171010005600.28735-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:c00::235 Subject: [Qemu-devel] [PULL 21/23] 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: peter.maydell@linaro.org, "Emilio G. Cota" 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 c5ce99d549..d5195a0f5a 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -600,63 +600,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; @@ -667,8 +628,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;