From patchwork Tue Jan 5 17:19:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 356910 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp190121jai; Tue, 5 Jan 2021 09:48:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxf4cFLqx93Ob7LVGupKsmBhAB9+V7JWZLtR1XiSFbtYZBNRCCy8NFDM7Huz623RO1Vb3dd X-Received: by 2002:a37:6744:: with SMTP id b65mr616387qkc.199.1609868928048; Tue, 05 Jan 2021 09:48:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609868928; cv=none; d=google.com; s=arc-20160816; b=tQ3Icfi5GYsButnFB/0NrXEDJ0H0IBDBHc32Fxc/uhoLP4qngp+hXiMKWERzqnHVYp Y0dFlTAFEiIJQOLlzgBkYKGX1E4fB+NNOXDW681icQH+SgZMMlRTi6HlrCxpvxGQkgHP DaVBD/dDdq+a3rmKv046JT+hwhfIJpzmmHC2MsLF7SVLUW9JkNk9CUs4hb2BvYtYXkr2 zNSr9ZxzF5JMiDRi4dyylOAkY2H801wW4wU56xYqIoi3kKSSqS19UZMLcOe7a5q3JVX0 K2hL5zJP7gOn2tcyCjLeTE8bWiaDiy+TyHkPes5Osw85ccuOnS1cDznlSvCmuYSfpCKI cqtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=PZBhVDepUcDpkv6qOWXmKFUYbcFXiGc8v0ZHGvlO+rI=; b=NHRwcmzUgUA6WtQ8TvhgjmgQU1PkeLcyyza6v2Hbv8xAaKLsz0YEZRXPDpoxVp3x7x 9U81MhZnfrs4vcWWms1PMZ2IKBVTsB3/mW3XzNZ8Q1Vv5bCwmMP4SFZRM4ULrvu3ssrq CIhXofo7W4tg2vUKCODe28BN1WEbweV+Bw+lWL9z6nu1g/4JaUE9XBIY3HIK7ajRgeLb SC2awxPk0BYvNLe94aIvEEZCxmzogP57oj7tBCs3o4Cxs2HB0HugiJEv2EiNIDfk+BC9 tJVqBJlFs1w9FhBM5IPkdsF7drtylDhudKP9Iz+Z8dw70EtLghXVXF+EQh7GmEgMA9qb FbRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YqmPi+Jh; 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 x23si227336qkm.314.2021.01.05.09.48.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jan 2021 09:48:48 -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=YqmPi+Jh; 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]:33168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwqRp-0007Dv-VS for patch@linaro.org; Tue, 05 Jan 2021 12:48:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwq0y-00033p-4Q for qemu-devel@nongnu.org; Tue, 05 Jan 2021 12:21:00 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:42811) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kwq0w-0006kv-Eg for qemu-devel@nongnu.org; Tue, 05 Jan 2021 12:20:59 -0500 Received: by mail-pf1-x42c.google.com with SMTP id h10so110696pfo.9 for ; Tue, 05 Jan 2021 09:20:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=PZBhVDepUcDpkv6qOWXmKFUYbcFXiGc8v0ZHGvlO+rI=; b=YqmPi+JhWp9PVGRjdJSJO+y2w2PYNV9xtuKuBMM7xiBJ8WgO4MK00VhGGJIPoUXrBD TgVi+7uPBWMO5lBuL2lASyHEWXZdvVB7vMRWt7JNVST7UweU3vAEf0T7XDcmRa8XbQvl eTi9x9ShGzTxyTlrbzrC38+TrUjSi41Oabsqtc2t721cynxBAwk36DcG8VRN5w7bv/5w gM9knVt4flOlzeyutik7ppySxsyb/oWS6MosinviIVc8W9GDDuvlIe++V/EVCNiCrkPB nY0VQnAmC3sA30w8Z0kblATctD28nL4pIB12KWwikJHy/cFmzgMcj5Wwp7FSCtPA/H8D MVzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PZBhVDepUcDpkv6qOWXmKFUYbcFXiGc8v0ZHGvlO+rI=; b=fu8c1e7dWkKctSnkUDbrQeyUY51elFyEJc/CzKbLOSXXlPCXNIAoVm1/SA+3SZGelS 6lAnu4XhtJhk/zJ/Al1S3aDSRD1yD1XN/cf+MMXBoxO0CgRxeLVWMGDUvHIN7t14fC74 LoAsIjHPH+ntuGo0nT9aFtrjU7vwhRR9RLF1v+r2V12tNV3wlCN35ufYM3VXm67dypGB KzsDzHfpyvGc1o923FnnuTm4ocCBGNJiTO99PHngKY610UM1jn7CyMrdy1/4CgJxHv4/ pT7xntciFAApVhbn74QR3ZvJOsxEXGJ5+SM24bJIyB9wZoamrXq0wZ7HwC5DGr/m62tQ AgQA== X-Gm-Message-State: AOAM533bwa99bKGIGXp6KyON8OK7DRYtGoL4je/WWPO7pSKVVRqKqT27 H3oNcJUJJm03RMqSAXru8jH6lRfQTbKoOg== X-Received: by 2002:a63:ea4b:: with SMTP id l11mr338097pgk.61.1609867256783; Tue, 05 Jan 2021 09:20:56 -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.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 09:20:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 37/43] accel/tcg: Add mips support to alloc_code_gen_buffer_splitwx_memfd Date: Tue, 5 Jan 2021 07:19:44 -1000 Message-Id: <20210105171950.415486-38-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::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Re-use the 256MiB region handling from alloc_code_gen_buffer_anon, and replace that with the shared file mapping. Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 46 ++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) -- 2.25.1 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 0c0f9c3e62..39a0413524 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1137,24 +1137,40 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot, static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) { - void *buf_rw, *buf_rx; + void *buf_rw = NULL, *buf_rx = MAP_FAILED; int fd = -1; +#ifdef __mips__ + /* Find space for the RX mapping, vs the 256MiB regions. */ + if (!alloc_code_gen_buffer_anon(size, PROT_NONE, + MAP_PRIVATE | MAP_ANONYMOUS | + MAP_NORESERVE, errp)) { + return false; + } + /* The size of the mapping may have been adjusted. */ + size = tcg_ctx->code_gen_buffer_size; + buf_rx = tcg_ctx->code_gen_buffer; +#endif + buf_rw = qemu_memfd_alloc("tcg-jit", size, 0, &fd, errp); if (buf_rw == NULL) { - return false; + goto fail; } +#ifdef __mips__ + void *tmp = mmap(buf_rx, size, PROT_READ | PROT_EXEC, + MAP_SHARED | MAP_FIXED, fd, 0); + if (tmp != buf_rx) { + goto fail_rx; + } +#else buf_rx = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0); if (buf_rx == MAP_FAILED) { - error_setg_errno(errp, errno, - "failed to map shared memory for execute"); - munmap(buf_rw, size); - close(fd); - return false; + goto fail_rx; } - close(fd); +#endif + close(fd); tcg_ctx->code_gen_buffer = buf_rw; tcg_ctx->code_gen_buffer_size = size; tcg_splitwx_diff = buf_rx - buf_rw; @@ -1163,6 +1179,20 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) qemu_madvise(buf_rw, size, QEMU_MADV_HUGEPAGE); qemu_madvise(buf_rx, size, QEMU_MADV_HUGEPAGE); return true; + + fail_rx: + error_setg_errno(errp, errno, "failed to map shared memory for execute"); + fail: + if (buf_rx != MAP_FAILED) { + munmap(buf_rx, size); + } + if (buf_rw) { + munmap(buf_rw, size); + } + if (fd >= 0) { + close(fd); + } + return false; } #endif /* CONFIG_POSIX */