From patchwork Fri Oct 20 23:20:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 116590 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2247620qgn; Fri, 20 Oct 2017 17:03:35 -0700 (PDT) X-Received: by 10.55.26.138 with SMTP id l10mr9903731qkh.71.1508544215144; Fri, 20 Oct 2017 17:03:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508544215; cv=none; d=google.com; s=arc-20160816; b=tM6FMPW+LhW5PS1CQqgTF7uzEM4bcnJ3g9JFzDxZRi2Aoc7iM5PAIJNnXTNvjj9Uey UIykRAu9ATS1188BFxbfcNjc7xFSxv8ai27l5IkODwoIKyXhqJaGsvSknJbyKphX7SxE IO4z/QcB00isN2YH3dXGgF/1Ft8GzOUFSrlBy8N9C2cgNyqA8SSeqPQIegmtUfJKN2EH dL4CPPZo9UdzyAccJX5Qrkni/XxR22DDqTyIBRxBGO1am6xeGzu10n43zNU0+YFOobT7 CW263aO5o7NgF7xXFtbSmn5XWDg2KiJvcItCWwgGoFHJJ/aCIsjCr8vacFQsZo40WR93 7uTQ== 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=tlch/PxOT6nCG6/MDdTv7vYP2LcN2dPEBNzcrCyWYi8ORmynD0rBtsG+eOv2VjWdER 8Ny7suZFsdjkcVnMeGbapgwVQ0ykUwccKJ4dHFSkicZpkWQxpLbmBLOgmAWEOqdIRCc2 fHdPkwH3yI5ncGxJs0h8e0ohnUp0RrOkkeXf917CGACe8kJvHbZqfJXkNs9Ckt3PwFj5 lSGLLnHUcAVuiVSY/RR6C56+32mtKHb0K/785BTaxztNTuXunH4aTYSRW+MH8z0/l9yn I70J71hak4ZXboSE10CFewYxsHeamesdo746L1Ryy1ABHQ92T7IqCbrUkQSMW8xadcWl SwNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JqDfNprn; 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 q16si1755961qkh.107.2017.10.20.17.03.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 20 Oct 2017 17:03:35 -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=JqDfNprn; 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]:56159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5hGH-0008Oi-6o for patch@linaro.org; Fri, 20 Oct 2017 20:03:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5gbi-0006kS-4r for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5gbh-00083I-4D for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:38 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:55384) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5gbg-000834-UF for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:37 -0400 Received: by mail-pf0-x241.google.com with SMTP id 17so13068272pfn.12 for ; Fri, 20 Oct 2017 16:21:36 -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=JqDfNprn1hcLMHRHINfnIEUsmtrJ/CoedxR10ANG66q3JqH1inrwRt2k4Ff3RI0yzZ 1Wx/F/fnt85tytda6peTPpfus1xoImJa5UkzwEAMloKaSscX4C3VBNdCiFcrqo2NKbgc QJvkwzIBrfa9xUYYM13asz78qNqqu9VrvAV3g= 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=UBiAQBv+iCcULpZEUbw4a32q3OSVdSt42rn5q0er+2YVBTWt4iCXZ4rzu55P0YwTxv X25+Q2R2Le4DFkOQ3Ms0OMHmYRRecZVHZWgK4HNBcXPoAJEs5Ln+iYXTIgUyo62T5wBh J4xCEBVSFVNcK5+o6DOTLjnnsmOMMpkAUzmgXC4alYsfWSZP86mx1JBhY/pn2+bISEmQ WzjP0G+tkdd+BpDEBSU3EhBh0DtSv2yGYeqFOE/37RKJBq0Ie23nEqvJ3zI11NGHdPoQ g+l8tnUSEaUFHCsOOqDWEJS4jDjvmIWtZrPn+k6DV7Ya6w/Z7YCB50YNWNDeRCFpqrvW zyig== X-Gm-Message-State: AMCzsaWjV5xX2I9F5fs3TbJVmOOb9ecFpq3X9sVAVWEI5UyKwVfiuT1D AdGtJTE8PLXW/gmFvGJAio7XUGUbNFo= X-Google-Smtp-Source: ABhQp+T+KT0w59fgp3EXCx+bpt92qF/2/MZjl+tdoqzlUk6eSzH4V4BYlZnAG2n1unYk21Z9PncZ5A== X-Received: by 10.99.7.133 with SMTP id 127mr5753738pgh.147.1508541695669; Fri, 20 Oct 2017 16:21:35 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-165-104.tukw.qwest.net. [97.113.165.104]) by smtp.gmail.com with ESMTPSA id a17sm3532594pfk.173.2017.10.20.16.21.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 16:21:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 20 Oct 2017 16:20:19 -0700 Message-Id: <20171020232023.15010-49-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171020232023.15010-1-richard.henderson@linaro.org> References: <20171020232023.15010-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::241 Subject: [Qemu-devel] [PATCH v7 48/52] 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: pbonzini@redhat.com, cota@braap.org, f4bug@amsat.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 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;