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: 117101 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp668754qgn; Wed, 25 Oct 2017 03:18:21 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QtkCoZ+Lj11YYnTiyjPuQU3QEC1r9ndJ8kAhH44fBLp6QCKzXBphTl3+JxxIZmPLYwnXeZ X-Received: by 10.129.173.99 with SMTP id l35mr13136089ywk.132.1508926701172; Wed, 25 Oct 2017 03:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508926701; cv=none; d=google.com; s=arc-20160816; b=bFRI4IEZxQ5ZJCIPbpbKQStIBKSuyxxyxY/pjHsvlm5GyETbM093ObBsqN6OkuboDs WdMaBHAt9AUgebFwnLY7u3cTmvDtv+a2bJNX/CJd9nsTG9DHlVqYeqbDfVHG8mT4KJw5 KaF9WPpG228vnMmfHwZXEGgA9Y12cioGnbFKylRnKNwYMz2VKx+PcZEF2m/qdYCIIoIQ I4VFafKHpjuVB8e9/zQMDveAV3AZJLj0lWQRnWNdyObTu9oLlSm2s78y0XG2naRKK9wF 0ZFS+kXI6eA7ck7FoyYZsvKQ+i2CgliF4jfcsqplzoXYZK9SOc1Q9/Ng47zAL1ZrFdyX 9Hiw== 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=QAy5P/DiR0V6uHx0vkD7O4ZvsE5YRZZNjBKdzWG/Qf4=; b=n5tiQyfjBqR8RKU9y8bUiRScy4Lwi4rgbhG/cr1L5Nuj59fjrh32aAQPGNPoBA4Oph Pl2Nsc2u93JjYG0pmd8R9WLRwvH0tBgOK8RZQbRgU7lJ18WD7uz36PivAyRrWaN5eRrJ +FvUsaQr9XD92Gra3FMsrWAh/SMv8qkjQrlT5rBnvb0RCXioN4zgcQWqsCI7b2lHToLO ecKd+ch9lE0+19Q8jhVw3N8/X8RAZ23yMA5Y0G7dyWJsi91TGaOyrdHNEjBQOoR7RPHZ bSSpfLASRVgDmsPYNzWopGRBjivNB+bX6moq1IHmUkltNLjBb2iali5PDDLH+MtaiuJE PrAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fXy6xgj4; 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 f138si381547yba.549.2017.10.25.03.18.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Oct 2017 03:18:21 -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=fXy6xgj4; 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]:47487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7IlQ-0000fi-MM for patch@linaro.org; Wed, 25 Oct 2017 06:18:20 -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-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+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 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;