From patchwork Tue Jan 5 17:19:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 356916 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp194479jai; Tue, 5 Jan 2021 09:55:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2apX78WYRaorRHoifJOtvzQtzdiLM5BKyMgzFYFaBbSA/EkCxcTM1V8VNsHEV0E7ZNr6n X-Received: by 2002:a0c:fd8f:: with SMTP id p15mr713822qvr.48.1609869328539; Tue, 05 Jan 2021 09:55:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609869328; cv=none; d=google.com; s=arc-20160816; b=j0QfNVXLIKe4GqIKe9ODidQvAWAZKiuXR/Sbm78ZIOdgO4Q0N8wuLsLGbyWvZs7lbO 0FEYbcS0xRbnH6JgBy9eOC9uXYO7PIxKUAyW4Xb6wodHJRDOHkwn4UEpzA8429d2GIvl 1woTqgozOhjEOEoeBGB5qGDE5UcL7Mxq++ujI9y8SW9LMrcO9lFlMghIYtwlmXjmmlCP 3YPZXJD5CWWcOew4G7CvBE6iChM2OTlRdq4ihEmKtoIlzV/aQtRNISra4U8zXQF/N7Ka ZyXyzwzfiIErwJfHGtO6Zkoc7IiTfdSTrcXxTB+NvbW8Ofwc9bGOjphH4ykB4CRJAqDi KQug== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=GOc/QdYClClYlMp2dKbUVjQGtFUnV184hz1wUbaQM2s=; b=SPPtwJQG6FByTzihkk7Cz7d3atdtcek2XqI6+6f0AwCrao76s2q9QRz6pAwaE5r/c/ wUIhv3a0gOaf65kFhh/6hhM227uDw+EmQwBculGxU/2DwGb6/fBwIQhi7QB79+9zeFOW ZZxKu5nFaNohiZDhsj7J+0d3iua1rjmPs0FH5bXAhGOT1zJucUUSi1kok9PW9EqHDNF1 Ut/M6PucrRpfrz7oon3gmzbKoAoETuV81q6SmUxs0Rq9OZPCx3U3c8+v8kR4TtxCMDje idIW6MxlXCBaZQtynth4842H/Er/IfgLvFR+zp5Xgo/cIVKJPI9M2r/NYFHpqd9GRsdS POQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E8HzXHV0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v3si153163qvz.78.2021.01.05.09.55.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jan 2021 09:55:28 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E8HzXHV0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwqYI-00086M-6p for patch@linaro.org; Tue, 05 Jan 2021 12:55:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwq0W-0002Nd-1e for qemu-devel@nongnu.org; Tue, 05 Jan 2021 12:20:32 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]:33414) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kwq0Q-0006ap-Bj for qemu-devel@nongnu.org; Tue, 05 Jan 2021 12:20:31 -0500 Received: by mail-pl1-x62a.google.com with SMTP id b8so77403plx.0 for ; Tue, 05 Jan 2021 09:20:25 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=GOc/QdYClClYlMp2dKbUVjQGtFUnV184hz1wUbaQM2s=; b=E8HzXHV0hUWHkYw2rZ10TU4XOaQQx1E0CtiGqek0mN4dRfx5Ncvv++NuFmiAsf5poQ rRPxqCErNAiqesQxr58Fri0+sFX6IdmEK/0hCV6LjCsLbQes31bYn+nB2iEsssWaGDzS 4LAtOTDaoBp7yP+DxdA27cMIBppP19Opeibo1/t/eoft4zquMJ3jJBUmIXK3u0mKgKqo d3g2VwgyGDuDjphWGLqs5CChCSgLeUriSPbLU50H0AdCX8w+26ePU68YnhnT+pSvVmTw WN1TdyYl+iVqcQO7KDBV+HKLout8CXGN0XH0qW8UYvmdv1vsYCOGAoLgvyNy7l9pPMiw PfqA== 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:mime-version:content-transfer-encoding; bh=GOc/QdYClClYlMp2dKbUVjQGtFUnV184hz1wUbaQM2s=; b=NsknMu7hrsa0cAsde/fP+f4gdBXHjakFPrkqeNmlpQsJmPiLhnGAT2Aynlp5bIJ3pW y/fkw6GDD956jqgwZX7KYL9nLxIhhPYhfIMdVPuh9FMRxLIwL/REF11zfu0SykUxn2vp rDDAJuPSG+E8OYvLNmQR6h4qbaXNCHMJ+Ic63hIgAW994drn/pz9D4yOExyGGbga9tlx HjnOivHX5ArTd7gg5E9TGY9GAhI0X0hvaRfTPDlk1l8VAmb+hiW0KCs9cDC5bj1QleEj oBWZmGhoPzpCmNf8bgzYROUSHQTj11ZYqpxM6T+llL6oPAtbO7ytPNrPSD6hYr1rvVGE N7wg== X-Gm-Message-State: AOAM532Rjbc4nfLBK1txBgtoG192iKp6Cf06/7M2cFRcobartGYMIVpc rc/2jyOI+KmDQnUxi1y6PTP2OEq0kLf/6g== X-Received: by 2002:a17:902:7242:b029:db:d1ae:46bb with SMTP id c2-20020a1709027242b02900dbd1ae46bbmr313961pll.77.1609867224667; Tue, 05 Jan 2021 09:20:24 -0800 (PST) Received: from localhost.localdomain (rrcs-173-197-107-21.west.biz.rr.com. [173.197.107.21]) by smtp.gmail.com with ESMTPSA id u12sm2010pfh.98.2021.01.05.09.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 09:20:24 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 16/43] tcg: Use Error with alloc_code_gen_buffer Date: Tue, 5 Jan 2021 07:19:23 -1000 Message-Id: <20210105171950.415486-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210105171950.415486-1-richard.henderson@linaro.org> References: <20210105171950.415486-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joelle van Dyne Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Report better error messages than just "could not allocate". Let alloc_code_gen_buffer set ctx->code_gen_buffer_size and ctx->code_gen_buffer, and simply return bool. Reviewed-by: Joelle van Dyne Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 60 ++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 26 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 224821943b..77444ddbbd 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -59,6 +59,7 @@ #include "sysemu/cpus.h" #include "sysemu/cpu-timers.h" #include "sysemu/tcg.h" +#include "qapi/error.h" /* #define DEBUG_TB_INVALIDATE */ /* #define DEBUG_TB_FLUSH */ @@ -963,7 +964,7 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1, (DEFAULT_CODE_GEN_BUFFER_SIZE_1 < MAX_CODE_GEN_BUFFER_SIZE \ ? DEFAULT_CODE_GEN_BUFFER_SIZE_1 : MAX_CODE_GEN_BUFFER_SIZE) -static inline size_t size_code_gen_buffer(size_t tb_size) +static size_t size_code_gen_buffer(size_t tb_size) { /* Size the buffer. */ if (tb_size == 0) { @@ -1014,7 +1015,7 @@ 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))); -static inline void *alloc_code_gen_buffer(void) +static bool alloc_code_gen_buffer(size_t tb_size, Error **errp) { void *buf = static_code_gen_buffer; void *end = static_code_gen_buffer + sizeof(static_code_gen_buffer); @@ -1027,9 +1028,8 @@ static inline void *alloc_code_gen_buffer(void) size = end - buf; /* Honor a command-line option limiting the size of the buffer. */ - if (size > tcg_ctx->code_gen_buffer_size) { - size = QEMU_ALIGN_DOWN(tcg_ctx->code_gen_buffer_size, - qemu_real_host_page_size); + if (size > tb_size) { + size = QEMU_ALIGN_DOWN(tb_size, qemu_real_host_page_size); } tcg_ctx->code_gen_buffer_size = size; @@ -1041,31 +1041,43 @@ static inline void *alloc_code_gen_buffer(void) #endif if (qemu_mprotect_rwx(buf, size)) { - abort(); + error_setg_errno(errp, errno, "mprotect of jit buffer"); + return false; } qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); - return buf; + tcg_ctx->code_gen_buffer = buf; + return true; } #elif defined(_WIN32) -static inline void *alloc_code_gen_buffer(void) +static bool alloc_code_gen_buffer(size_t size, Error **errp) { - size_t size = tcg_ctx->code_gen_buffer_size; - return VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, - PAGE_EXECUTE_READWRITE); + void *buf = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, + PAGE_EXECUTE_READWRITE); + if (buf == NULL) { + error_setg_win32(errp, GetLastError(), + "allocate %zu bytes for jit buffer", size); + return false; + } + + tcg_ctx->code_gen_buffer = buf; + tcg_ctx->code_gen_buffer_size = size; + return true; } #else -static inline void *alloc_code_gen_buffer(void) +static bool alloc_code_gen_buffer(size_t size, Error **errp) { int prot = PROT_WRITE | PROT_READ | PROT_EXEC; int flags = MAP_PRIVATE | MAP_ANONYMOUS; - size_t size = tcg_ctx->code_gen_buffer_size; void *buf; buf = mmap(NULL, size, prot, flags, -1, 0); if (buf == MAP_FAILED) { - return NULL; + error_setg_errno(errp, errno, + "allocate %zu bytes for jit buffer", size); + return false; } + tcg_ctx->code_gen_buffer_size = size; #ifdef __mips__ if (cross_256mb(buf, size)) { @@ -1104,20 +1116,11 @@ static inline void *alloc_code_gen_buffer(void) /* Request large pages for the buffer. */ qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); - return buf; + tcg_ctx->code_gen_buffer = buf; + return true; } #endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */ -static inline void code_gen_alloc(size_t tb_size) -{ - tcg_ctx->code_gen_buffer_size = size_code_gen_buffer(tb_size); - tcg_ctx->code_gen_buffer = alloc_code_gen_buffer(); - if (tcg_ctx->code_gen_buffer == NULL) { - fprintf(stderr, "Could not allocate dynamic translator buffer\n"); - exit(1); - } -} - static bool tb_cmp(const void *ap, const void *bp) { const TranslationBlock *a = ap; @@ -1144,11 +1147,16 @@ static void tb_htable_init(void) size. */ void tcg_exec_init(unsigned long tb_size) { + bool ok; + tcg_allowed = true; cpu_gen_init(); page_init(); tb_htable_init(); - code_gen_alloc(tb_size); + + ok = alloc_code_gen_buffer(size_code_gen_buffer(tb_size), &error_fatal); + assert(ok); + #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and initialize the prologue now. */