From patchwork Wed Oct 25 09:35:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 830221 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="fXy6xgj4"; dkim-atps=neutral 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 3yMR0B6FdHz9sDB for ; Wed, 25 Oct 2017 21:17:30 +1100 (AEDT) Received: from localhost ([::1]:47485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7Ika-000064-Ux for incoming@patchwork.ozlabs.org; Wed, 25 Oct 2017 06:17:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7I76-0000Qa-LI for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7I74-0000LP-1s for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:40 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:45468) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7I73-0000K9-Qx for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:37 -0400 Received: by mail-wr0-x242.google.com with SMTP id y9so11089034wrb.2 for ; Wed, 25 Oct 2017 02:36:37 -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=QAy5P/DiR0V6uHx0vkD7O4ZvsE5YRZZNjBKdzWG/Qf4=; b=fXy6xgj4ibB/nTs3mg6maEzKBLCX96l4n9qdg448vifXW+wpymiFHPYIo8qABlgDtd eirQaW8+EZUdU/rFU7U+owGAGCO119qgV09ck1UvTuXk/mQA6nL8AoD7EQSI6brwKt3+ KlrgpBwhz1QStgWBDz0cSTEKzYY9GkzOd21Mg= 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=QAy5P/DiR0V6uHx0vkD7O4ZvsE5YRZZNjBKdzWG/Qf4=; b=KtgQoIKFzelKGmf43iDfUmfzoDP/8om23Z4OJWmRi/xR89vaePVXS6Dz2Xgenwbb/5 SkppxHL7ThiVOP2G8CTyCBhyCyzfI4TluKslZCfqXJx+KT/1Cwl8hYPTuQl0TaBXLtZd +kdOPErQxKRFTrj+mgznM2LUgAKI+DYIXx5LhXt2E3knBqfCVunl+nb6luL+dUJVvd7F PzTvBdtBv6gCA9Vb4rph5cOso7N4flNekP87RYUOo/+fw0eItqO/LBVOaLAC+uD5SYZl dtIb8mV1ZwkD2C5WgitIbFAmiM0lqAvrr8v+8F4nECkcMFYq7zrHMkODn6wm59xO1ivI z7VA== X-Gm-Message-State: AMCzsaWi3Jjk2Lx9/zDijWj8GFGYPAPuhvkLW8UX2QWWeJLifkAD7UV9 BgC0DRgQj46CZyJzXiI9LMUQpUWi1ZM= X-Google-Smtp-Source: ABhQp+To5eYyuYLYWFqOGUfE+XlHTL7X82diMtFMUG9G3diYEQ5vc2pwv4K+XcssXuU1VgV1wixt6w== X-Received: by 10.223.163.143 with SMTP id l15mr1494048wrb.65.1508924196626; Wed, 25 Oct 2017 02:36:36 -0700 (PDT) Received: from cloudburst.twiddle.net ([62.168.35.107]) by smtp.gmail.com with ESMTPSA id v23sm2751025wmh.8.2017.10.25.02.36.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2017 02:36:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 25 Oct 2017 11:35:31 +0200 Message-Id: <20171025093535.10175-48-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171025093535.10175-1-richard.henderson@linaro.org> References: <20171025093535.10175-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PULL 47/51] 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+incoming=patchwork.ozlabs.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(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 78c150af3e..9061c0508c 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -602,63 +602,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; @@ -669,8 +630,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;