From patchwork Sun Mar 14 21:26:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400121 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2920781jai; Sun, 14 Mar 2021 14:30:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqkbr4XyPCzBFbVNc5q77+haXxAy3me3wXAMG69jGaYNMaU3hWHLxIyoqzu25eX2UGDN8r X-Received: by 2002:a25:c105:: with SMTP id r5mr32732412ybf.413.1615757405695; Sun, 14 Mar 2021 14:30:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757405; cv=none; d=google.com; s=arc-20160816; b=0gQguhxiwaVz2o6rvESlKMv5eUon0JJWEenwoXqJyTaWN1CRJ9j3TlGcEeFCw2o/t7 Yjpgm2HwF7wkiTvQnNs4d3IskNHuhGx4cPwIB+CunCf6Y29coKoLaKfWi+zaCErywkfr zGMiGiLgCDCsXbkk+EjIl+bLx3zgFVbOQXbtbapSCSHisloQAWcicZeRyK4+6l36cU5e //rjPRBRy+jcAAE2R1awCIVsHYBjtCTctSEjNg2zCfoa7UEoBYNGxxY7+tNTUkN0c6VS NNqMmP4c1679/f0QJ7iImV/oFcMVJA9KmTEtn4H/d2s8eyPyCoFDmxW0F4Xni89/t6md AyLA== 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=wW16HYEEbHUJsSDEbNLyjiS39WK8C8tpisXcPK1gkso=; b=qalZO890TlFnATTIjDGR9+XLD7y4dfeGtoIDReeG5wwyG0TPGhXvOZ7h/RZZoq6odl +9Dqw+D+mMm8yUTSKrwT19quYFm3/TSnNBpm95vNzt6rNVmYzC31rktV84VMgQAIYdew 8nf3wbW+3vIijGPP+8VSmZpPgITl1KiGV/mM5YdCWhjI6W7wDkCwjTfY4Qsl1p7XoIYQ 7Y3mpNQEJKwFT6mHYGLRaZQTixmk+ju+rELTcCriCRP0+eHfPcrHHZX9NnQ+gqEZDEw0 Z5HPRCwLaqaqb4H11lFO0ygTNP9z2VVpqKUyxhUQbDNfnUndTfpSfAmNtP1KlkwB9lqF BULQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="C/grKP2v"; 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=fail (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 m9si13961866ybm.402.2021.03.14.14.30.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:30:05 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b="C/grKP2v"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYJC-0000nN-M2 for patch@linaro.org; Sun, 14 Mar 2021 17:30:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGo-0005oW-N8 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:30 -0400 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]:34586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGn-00087I-0G for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:30 -0400 Received: by mail-qk1-x733.google.com with SMTP id t4so29949619qkp.1 for ; Sun, 14 Mar 2021 14:27:28 -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 :mime-version:content-transfer-encoding; bh=wW16HYEEbHUJsSDEbNLyjiS39WK8C8tpisXcPK1gkso=; b=C/grKP2vV0jCKKC/x583F3iE1k37W7Q9gFZWzG1YAlLpnu4ndiyJ2NgRsvQ9hH4MUl mmuWjIzi9ngUeKCs6IswPMD+v92VlteN227WYgHkCpYKYw4XO0NQ8PEMLSq7EfajxTnE 1IeLWiP2RopbV1Hpu330g44wDuRWaP4toosKmeoNV5jXUkjIJv1qDT4nncU+5LjI+wgx 6wl+wTpubHS1e7MmqKZr2oZrGglK0F7KE8CAgNLFMLSdDIcghSErFJA94BME3KhKpkzT YgVee3pPWQES9tBUjY6leO4ior3G5xwkr4WKIELD9pWm1wvhfyVtlGjnpZPLiWAp6EvC /G3Q== 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=wW16HYEEbHUJsSDEbNLyjiS39WK8C8tpisXcPK1gkso=; b=dt34InA/O0gcHuLtPEV66Namm4E2zXD2m7edm5WL5h29L59A68Iramwahmy4ZbGph0 f/io8prlPLZI87xjFpqKVKiW5T674LqLjRF72si7LbPp/Wpe5COgmeFX3kXJrKJgq09w Kc7HfI9IAc38aZkCR/uO73UFvJlFLODPtiPU+C1jvZer4DMfYYflhghX8AyXEd3w4crI AT6aOB3EUsC99zB++7DFX30Os/LCU3c3qLR6Lo+a3aztU10qAK4xltrA/dinGsTcN2xD IEG/dANycs34/IswltXq7ZEoK2s9I3C+GKg5JDZmzyWb4yS8CQblOOIqyRyI74D5FF4A Fc7g== X-Gm-Message-State: AOAM531stgBTcIGo0iau4Tmv9yhIPHGbzqgs/KQ9vj6NXHQyNh/SNY9t QILlhea0bXTdNWuD7/G3Qi5vWD3FuMgfqaUH X-Received: by 2002:a37:a913:: with SMTP id s19mr22749659qke.158.1615757248110; Sun, 14 Mar 2021 14:27:28 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 01/29] meson: Split out tcg/meson.build Date: Sun, 14 Mar 2021 15:26:56 -0600 Message-Id: <20210314212724.1917075-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::733; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x733.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: r.bolshakov@yadro.com, j@getutm.app, =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- meson.build | 9 ++------- tcg/meson.build | 13 +++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 tcg/meson.build -- 2.25.1 Reviewed-by: Roman Bolshakov diff --git a/meson.build b/meson.build index a7d2dd429d..742f45c8d8 100644 --- a/meson.build +++ b/meson.build @@ -1936,14 +1936,8 @@ specific_ss.add(files('cpu.c', 'disas.c', 'gdbstub.c'), capstone) specific_ss.add(files('exec-vary.c')) specific_ss.add(when: 'CONFIG_TCG', if_true: files( 'fpu/softfloat.c', - 'tcg/optimize.c', - 'tcg/tcg-common.c', - 'tcg/tcg-op-gvec.c', - 'tcg/tcg-op-vec.c', - 'tcg/tcg-op.c', - 'tcg/tcg.c', )) -specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('disas/tci.c', 'tcg/tci.c')) +specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('disas/tci.c')) subdir('backends') subdir('disas') @@ -1953,6 +1947,7 @@ subdir('net') subdir('replay') subdir('semihosting') subdir('hw') +subdir('tcg') subdir('accel') subdir('plugins') subdir('bsd-user') diff --git a/tcg/meson.build b/tcg/meson.build new file mode 100644 index 0000000000..84064a341e --- /dev/null +++ b/tcg/meson.build @@ -0,0 +1,13 @@ +tcg_ss = ss.source_set() + +tcg_ss.add(files( + 'optimize.c', + 'tcg.c', + 'tcg-common.c', + 'tcg-op.c', + 'tcg-op-gvec.c', + 'tcg-op-vec.c', +)) +tcg_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('tci.c')) + +specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss) From patchwork Sun Mar 14 21:26:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400126 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2922483jai; Sun, 14 Mar 2021 14:34:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ0IqspdDFCBqeQY+0dayg6W4N56KUK6YXIBcu/wq3q/2dxJzX83sH+y9UqayEUZ4Rv7Nd X-Received: by 2002:a25:bec4:: with SMTP id k4mr32488077ybm.104.1615757672626; Sun, 14 Mar 2021 14:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757672; cv=none; d=google.com; s=arc-20160816; b=tiNBUOkVhAdi4E+ByoS+U5k6Ix08hzSkoAlOnVx/di+zXmKTakKEVO25hoEQjeDgQv zxtNtmZaMjQ1XL83jtoZ0RM0ahwQc7udrYh0rqjGFvMN7zcNBg8gRKjYhF09YSmNxaw0 Potecw/xcwOpsR+uxD/+Bc/pT4CWaWCzRQ23qscesNK9NKqQuLEhK/8VJVS6pMbbHHtS quap7Ux8oaM6hZG6AZBf+qXmPmZUa8Kun7UpyMsk5jBx6xeuyShPifxGrp77Khkp26lA +oN+sItXHB2oLiT0MtuyGiL7uGM9e0eL2br8EZ0aeVmG8tSUrthaPFQIdHWyO6ZX2oGN Rs8g== 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=G1cuceYNpYXAOK1j2QgIU1zwSZCr6xgnUVgDKM+l7ys=; b=01bzsGbzHvzL3INm9i1CTXkYUrTExWoKXMkMYGwo30Z21vaO9RHP8fd87jMKdnrdA/ hgPPiWnpnj57c7DNDg5sf93zklAmWFA8+ARyEROKSTfQae4myxsrX3yjPMFaHh6FuR6T 50xC4API0HMf66ek+heg4xiXnYmGFy/m+Z4U/PWBNvGrRdFHYQ0kZi96ewTF408IpC0C JNZ+PqTQRP3+Q92nuSG4eI4GW9m03thS1acvcoFoW8xUxtTcTdAx9WTseuq7S8dxjxj4 qngPtKJrfaazDkcKgQe79CaXnabIHUQsXZncEw2BVuFJqSMtgfGyHMl7yg0XFJWrqz3w XzJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BxmStJdc; 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=fail (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 126si13121376ybd.282.2021.03.14.14.34.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:34:32 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=BxmStJdc; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYNc-0004Uh-1g for patch@linaro.org; Sun, 14 Mar 2021 17:34:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGp-0005pZ-To for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:31 -0400 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]:39179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGo-000880-DC for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:31 -0400 Received: by mail-qk1-x731.google.com with SMTP id g185so29901207qkf.6 for ; Sun, 14 Mar 2021 14:27:29 -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 :mime-version:content-transfer-encoding; bh=G1cuceYNpYXAOK1j2QgIU1zwSZCr6xgnUVgDKM+l7ys=; b=BxmStJdcfxjEqRQEw3k9KNk7H2E4/bQw8U2CX4w+ESt28UmVFMca4Q4qtwV/RRHx4v JGuJ7u9zB0++Uq3yYHVECsSzhR2LyHLkTtx+s1bwY+IXlAP3gYCxl7yl5WoeESFgjyMA fxt9XVh+9zWpF+sMZzrpuAuNtlEGcCs0MZtO2PNyG1OatA1gYox3aiDj8qiy+Q5BT+ta fcpcNGo1emHe3ooedjqvLB1qkuHXfozIrpnVKiDjZAsGsyKIaMR1WKxtpBPZaYLzaVhN 6Ox83lhf2OIg4pdoHfwWgNdL7nZO2B7mtbx/ANYobKkHrQbNa4Iv4w/l5FYt0zF6hnIe Z1sw== 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=G1cuceYNpYXAOK1j2QgIU1zwSZCr6xgnUVgDKM+l7ys=; b=ReHs7T7iilfZaXswxjTIDBxhi4GUeLlpqy960UsU5kszJnJojl72PE7TzFeeGsSkBk a+S/0culbG/oxCY+VxgwcLXZ1fRA+Slq2Bby/ShKlcwVdKQHsWpsfrI1he2bimMJEmSA iLJvIacTCVUaaV3Qbw4ckgiu3vZY0j5bZImjpb1kzgDw2iIqPTEFn9gYLReaNlehmtSu ccmdGESetjH8fMAtUvo4oyAQ8x1MreEUM/nWJT7aqM6/Hn5q9KXo7fB2KHQJBCuo72jU gyCWhgkc4pO/OetCTu8VyKcw0RiXfkHxgkKBbpAdx2X9FOcjzt5Q0MOZVcqhNpCaTZc1 g0xw== X-Gm-Message-State: AOAM532fVNa1EImrliMyY4F6ct5z1ZYQJsN68ZWt5fiIXx5oI5hQtprq lIv6Y8fljXeJwimMoy8+nuhTCEwFys6S6ae8 X-Received: by 2002:a37:a404:: with SMTP id n4mr22137321qke.439.1615757249427; Sun, 14 Mar 2021 14:27:29 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 02/29] meson: Split out fpu/meson.build Date: Sun, 14 Mar 2021 15:26:57 -0600 Message-Id: <20210314212724.1917075-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::731; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x731.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: r.bolshakov@yadro.com, j@getutm.app, =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- meson.build | 4 +--- fpu/meson.build | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 fpu/meson.build -- 2.25.1 Reviewed-by: Roman Bolshakov diff --git a/meson.build b/meson.build index 742f45c8d8..bfa24b836e 100644 --- a/meson.build +++ b/meson.build @@ -1934,9 +1934,6 @@ subdir('softmmu') common_ss.add(capstone) specific_ss.add(files('cpu.c', 'disas.c', 'gdbstub.c'), capstone) specific_ss.add(files('exec-vary.c')) -specific_ss.add(when: 'CONFIG_TCG', if_true: files( - 'fpu/softfloat.c', -)) specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('disas/tci.c')) subdir('backends') @@ -1948,6 +1945,7 @@ subdir('replay') subdir('semihosting') subdir('hw') subdir('tcg') +subdir('fpu') subdir('accel') subdir('plugins') subdir('bsd-user') diff --git a/fpu/meson.build b/fpu/meson.build new file mode 100644 index 0000000000..1a9992ded5 --- /dev/null +++ b/fpu/meson.build @@ -0,0 +1 @@ +specific_ss.add(when: 'CONFIG_TCG', if_true: files('softfloat.c')) From patchwork Sun Mar 14 21:26:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400119 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2920033jai; Sun, 14 Mar 2021 14:28:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlhqU/7ETUF+Dvn2S1jnIoPNwYZbuzWWOgOKVmxNfSEcfD17ncGOnnsNh4zUkSy314es/Z X-Received: by 2002:a25:4054:: with SMTP id n81mr31548023yba.39.1615757290972; Sun, 14 Mar 2021 14:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757290; cv=none; d=google.com; s=arc-20160816; b=fjeD2BVu3v49C4jOsbMmTGbABr8kHYjMBzp6fLIQjCLjeEtvr6LRYTRTlFyLf2y7E5 NFOJzk9YXcYK6CfARr4fI7Y3uneFeTQpNUiE+GJMRkNnSulPOA+j2bF2ZHrjgVhCsxg+ Q5vtlV3LqB9WOfWNyF0LTuclf4CEjLo3T6+iu5WegRhlnuNT0VGZfO6x6hxGOduVl5oo 1u2L/hsTu3smr0Ia+v6SXScjCzA2DwI1xd4QcxQT/cyZiRNnLy443SORkhAy1fgJr338 Ztf9968AX50GH1xdECVVIa1bILhjYXCfr6h9Kb2HkRZUNqW5ewSRiTLyt1ifj0DtX1b1 eIYQ== 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=Zo0Axh7LGw4WyjdfTcLkZAEZsIuFs0M9C89s4USb0+Y=; b=tH6MMzaULvKLexz54GwwmqhZ8dugDq5Og+NB/wuRyZ8r14DPjNyMYY/ptVV1EpkiLl ZayZ+ZQJRyn56WSdGMQ7Q1ev7W9Q1xqVzo3iHIoM9RLZUViPvK7QXTeojRN8wrwqiqlt RulBgCecAvwiQE94NAWyM8ElskdIcuQI9X20i3ELpG43KPKWpOcfgFMqKx7ytrThz2h6 SbkkH5K1N/PWm//AocxOlvZkMU2/88pWGPi5zKmIuyZ8ocRVmwLIePs665jgR+z6bozm yOdS77zE+K26BbmRZqOkgIjcfsU+WGbVdiIq/6ANUAm6lSGLcAHFiJcozoKrBI/eZQKS X4xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=J4bpnwoO; 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=fail (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 p207si13447269ybg.457.2021.03.14.14.28.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:28:10 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=J4bpnwoO; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYHS-0005tY-CP for patch@linaro.org; Sun, 14 Mar 2021 17:28:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGr-0005rJ-Ha for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:33 -0400 Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]:33549) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGp-00088n-Ma for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:33 -0400 Received: by mail-qv1-xf2f.google.com with SMTP id o19so912010qvu.0 for ; Sun, 14 Mar 2021 14:27:31 -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 :mime-version:content-transfer-encoding; bh=Zo0Axh7LGw4WyjdfTcLkZAEZsIuFs0M9C89s4USb0+Y=; b=J4bpnwoOfkGpQRujYf8iLjvJiFiu4UYjzuUuMke84vAvSVt2cWST5J/Sgms13yWBFf qD1J/97G4rCqQ4dCnL0xgjQSMjC51JlNYiwSH/Koz0YdsBPgv1b+qsfhAj+YGtOG8rOt 8haoJvwGCpqEQtuFMM/aPWBYlNAJ3OPDyZj3HjtuP88f/GzCNVmzrgM/hJEf3t7b+1sB NHwV7TKPViPcqKXmhg8ZrbnwobNLTZ5XvaqOO78N/QqWGpg5tnh2ikHtK42aJFn0Zhtw 2u0/gOHNdbNoGYzWnJYiTt2fWiKm7yqtRU7U3WNfJtDM8NTX/NQ+j0BFN2tqMnd7n9EL U9+g== 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=Zo0Axh7LGw4WyjdfTcLkZAEZsIuFs0M9C89s4USb0+Y=; b=L1YfYpE6FygjE/Y7B9N9EByiuuX4ZgJbPLfdBMb/tiCaNiDDyQSpGciWtE34PUw8uB bdzxvp5bCaQ4veCjdum4YkS+8U4OmAnP7lSGfih4GKegSgZ195OzniEqHIndIiH5EiND kT53sCWckZJr+Cy6zbfCKUzR/BstZNHudRhPF4ojEyvr9PJSgwhbIh0G5oPhY6/wkDrX w9mzUivPHkM5IVvSlH/d/PkeQrWx+H7MCMfKLIXyCWnb3H+6GeGCAgV616Jmh2wGRqAF g+WoXYUV75Y2fGOHbk7ew94V7FS1c6Ok04V89x0oP0Im3/AlHAYdcLQ/8MLhYNEeHzc5 oFHw== X-Gm-Message-State: AOAM531fxzYmpMZhLqZLI/BsXbb6MGi0cBOM0xDwt5ZziZyzI8TA4Ukk lrTzsQbmfLIY/3iZxwDCfct0K5zBTkq8mzqr X-Received: by 2002:a0c:e84d:: with SMTP id l13mr7839422qvo.28.1615757250676; Sun, 14 Mar 2021 14:27:30 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 03/29] tcg: Re-order tcg_region_init vs tcg_prologue_init Date: Sun, 14 Mar 2021 15:26:58 -0600 Message-Id: <20210314212724.1917075-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f2f; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2f.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Instead of delaying tcg_region_init until after tcg_prologue_init is complete, do tcg_region_init first and let tcg_prologue_init shrink the first region by the size of the generated prologue. Signed-off-by: Richard Henderson --- accel/tcg/tcg-all.c | 11 --------- accel/tcg/translate-all.c | 3 +++ bsd-user/main.c | 1 - linux-user/main.c | 1 - tcg/tcg.c | 52 ++++++++++++++------------------------- 5 files changed, 22 insertions(+), 46 deletions(-) -- 2.25.1 diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index e378c2db73..f132033999 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -111,17 +111,6 @@ static int tcg_init(MachineState *ms) tcg_exec_init(s->tb_size * 1024 * 1024, s->splitwx_enabled); mttcg_enabled = s->mttcg_enabled; - - /* - * Initialize TCG regions only for softmmu. - * - * This needs to be done later for user mode, because the prologue - * generation needs to be delayed so that GUEST_BASE is already set. - */ -#ifndef CONFIG_USER_ONLY - tcg_region_init(); -#endif /* !CONFIG_USER_ONLY */ - return 0; } diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index f32df8b240..b9057567f4 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1339,6 +1339,9 @@ void tcg_exec_init(unsigned long tb_size, int splitwx) splitwx, &error_fatal); assert(ok); + /* TODO: allocating regions is hand-in-glove with code_gen_buffer. */ + tcg_region_init(); + #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and initialize the prologue now. */ diff --git a/bsd-user/main.c b/bsd-user/main.c index 798aba512c..3669d2b89e 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -994,7 +994,6 @@ int main(int argc, char **argv) generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ tcg_prologue_init(tcg_ctx); - tcg_region_init(); /* build Task State */ memset(ts, 0, sizeof(TaskState)); diff --git a/linux-user/main.c b/linux-user/main.c index 4f4746dce8..1bc48ca954 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -850,7 +850,6 @@ int main(int argc, char **argv, char **envp) generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ tcg_prologue_init(tcg_ctx); - tcg_region_init(); target_cpu_copy_regs(env, regs); diff --git a/tcg/tcg.c b/tcg/tcg.c index 2991112829..0a2e5710de 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1204,32 +1204,18 @@ TranslationBlock *tcg_tb_alloc(TCGContext *s) void tcg_prologue_init(TCGContext *s) { - size_t prologue_size, total_size; - void *buf0, *buf1; + size_t prologue_size; /* Put the prologue at the beginning of code_gen_buffer. */ - buf0 = s->code_gen_buffer; - total_size = s->code_gen_buffer_size; - s->code_ptr = buf0; - s->code_buf = buf0; + tcg_region_assign(s, 0); + s->code_ptr = s->code_gen_ptr; + s->code_buf = s->code_gen_ptr; s->data_gen_ptr = NULL; - /* - * The region trees are not yet configured, but tcg_splitwx_to_rx - * needs the bounds for an assert. - */ - region.start = buf0; - region.end = buf0 + total_size; - #ifndef CONFIG_TCG_INTERPRETER - tcg_qemu_tb_exec = (tcg_prologue_fn *)tcg_splitwx_to_rx(buf0); + tcg_qemu_tb_exec = (tcg_prologue_fn *)tcg_splitwx_to_rx(s->code_ptr); #endif - /* Compute a high-water mark, at which we voluntarily flush the buffer - and start over. The size here is arbitrary, significantly larger - than we expect the code generation for any one opcode to require. */ - s->code_gen_highwater = s->code_gen_buffer + (total_size - TCG_HIGHWATER); - #ifdef TCG_TARGET_NEED_POOL_LABELS s->pool_labels = NULL; #endif @@ -1246,32 +1232,32 @@ void tcg_prologue_init(TCGContext *s) } #endif - buf1 = s->code_ptr; + prologue_size = tcg_current_code_size(s); + #ifndef CONFIG_TCG_INTERPRETER - flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(buf0), (uintptr_t)buf0, - tcg_ptr_byte_diff(buf1, buf0)); + flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(s->code_buf), + (uintptr_t)s->code_buf, prologue_size); #endif - /* Deduct the prologue from the buffer. */ - prologue_size = tcg_current_code_size(s); - s->code_gen_ptr = buf1; - s->code_gen_buffer = buf1; - s->code_buf = buf1; - total_size -= prologue_size; - s->code_gen_buffer_size = total_size; + /* Deduct the prologue from the first region. */ + region.start = s->code_ptr; - tcg_register_jit(tcg_splitwx_to_rx(s->code_gen_buffer), total_size); + /* Recompute boundaries of the first region. */ + tcg_region_assign(s, 0); + + tcg_register_jit(tcg_splitwx_to_rx(region.start), + region.end - region.start); #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) { FILE *logfile = qemu_log_lock(); qemu_log("PROLOGUE: [size=%zu]\n", prologue_size); if (s->data_gen_ptr) { - size_t code_size = s->data_gen_ptr - buf0; + size_t code_size = s->data_gen_ptr - s->code_gen_ptr; size_t data_size = prologue_size - code_size; size_t i; - log_disas(buf0, code_size); + log_disas(s->code_gen_ptr, code_size); for (i = 0; i < data_size; i += sizeof(tcg_target_ulong)) { if (sizeof(tcg_target_ulong) == 8) { @@ -1285,7 +1271,7 @@ void tcg_prologue_init(TCGContext *s) } } } else { - log_disas(buf0, prologue_size); + log_disas(s->code_gen_ptr, prologue_size); } qemu_log("\n"); qemu_log_flush(); From patchwork Sun Mar 14 21:26:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400118 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2920032jai; Sun, 14 Mar 2021 14:28:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybZG/nkbVgAMByiGzkg0Vt/H9qK9csA/RkxZ87PD9ZHe5kBXwIFBV5h57R5n4/TEaM05WD X-Received: by 2002:a25:9c82:: with SMTP id y2mr9591822ybo.445.1615757290888; Sun, 14 Mar 2021 14:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757290; cv=none; d=google.com; s=arc-20160816; b=Qjjlz3qryIKvu412EvaJk/nZaT20XCQwIOyYUI0MIuhryjS1ajs28ksx0rvrouNC3o 7iNWwt1Fg6ZD1Sro7M1cPyImhRdB1sy7HjkdksM9Y2WXz87eLj2bbRrXhSTekpLvzHhq 1X6DxEO7MXnfsufeTmcO21JQmafiAVWXBfqdKyiU/mOCDLZILUORrwVCcCpdo25FkQ7+ fWnyEBueFRrahnGu7rlg4g64Z94pPyhb6OJbVM8+4GbIaWX9/IlRLbHCpuvWxemi7UZL 0u7b8XWhIti8jmkPIyNT4rICORoHnMv954sZnilXfeXU00/M5IpAP3mcWmbYzYcCs/YO 7gfw== 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=hTuU1v864u8UFjIE8dcOrpu8BoE0XeHo4HzeUlZug3Q=; b=VS+IConxNj/Ret9ZeDDRy853r6/qemqzhSlaWnLgQVyrnC8MN04l7nZrgfHNDrrO+Q tOeiXxIQvvPJpmEUwTwMvy237hEb8fsyu10M7Wge0EYXWTgJkvcAxbPu1/wsJmoT5rrc S7+pnBplg8HquGyhHhNwkHC84XRu8jRHto4krlHfb7EEnjkGmZZLRzicmDTWndnCloVt 57QiclzyCL47xiZXULUfHsRTqb0XW0XrOcX70g5/p4Nlphe8uPXS2seKDzv8g/4LaI1J mNCCOVmzi/8qkwYRQx9/+x0sx9Z9ugjQBfXVKlxlKdVwfEbWWasONfv7ZLoc8kK84kCM vncg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=j8S6fBW5; 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=fail (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 w7si12708746ybl.142.2021.03.14.14.28.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:28:10 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=j8S6fBW5; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYHS-0005uH-88 for patch@linaro.org; Sun, 14 Mar 2021 17:28:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGs-0005sI-6O for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:34 -0400 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]:40480) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGq-00088z-Ix for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:33 -0400 Received: by mail-qt1-x82d.google.com with SMTP id r14so7863616qtt.7 for ; Sun, 14 Mar 2021 14:27:32 -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 :mime-version:content-transfer-encoding; bh=hTuU1v864u8UFjIE8dcOrpu8BoE0XeHo4HzeUlZug3Q=; b=j8S6fBW52hFslSi+aKblVA4cUx8PAONrlweOV/xGSgE696Zx0FVk9nY0l2WpX6hEHd vZSSxv16nIFOKeGte26jrfpf8yCygO/PwUMj/lsaL25oMfu4f9q838nXFyvDZ9oC9SIK XEtUaBZ3GoO6JdK1us91MTHayMEauK2qBYze7XL1EcDVCjMLS7DA01kfq4FbFiD3qcnh Lm/Hjf4qJ7OTdtK1q4Q461Kpbu2XSj1Gs0GXdajiFpkn1KHVohXfl4bhGdbUUqs7JeNS 4fBvwiv6LUcv34o4q8fXrUFCKiVwWzLF3LzFutsRIOX/q+qoIViVT+qkMPm1Md696X42 fx9w== 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=hTuU1v864u8UFjIE8dcOrpu8BoE0XeHo4HzeUlZug3Q=; b=bH5Z7lc180R23UHG7v/+AErCpg0CLzlYfbm1OrX+62h4l2UdaVC826Iz40+ANc9Z0P Zamx/yo0IQlj3MIWbQmx9IxfvyPVidhuuIjZWQ/ThfDnMGWZrsZ9lx6mMPbUsbGuGwix YZ0NZKJDB58vro4e6R/eXbqWO//UqXa2zwkMxUwZziey4osEEvdSAKdlRVN7uBtINnwU bl3ndwMWb5Zt7REqLMJhQKpXzq+5wsrJ/zgXV5jaHkoXgYs9jofp85Mc0lIHGWlKzPdN 2LBysT+0japZb1MHg5IepqnK6c51gZ4JEZh03mTDctlAv67F8CezwsmxDvshlggBwce8 MNKg== X-Gm-Message-State: AOAM533Am7rNmfoj8n/iOFOK2iTIoCdPBcc0nY3fymoV95h72GHs0s3R Co3tJpa3wazudBTSacp+g+PD+ii6i0bqPJT+ X-Received: by 2002:ac8:53c2:: with SMTP id c2mr19393307qtq.166.1615757251674; Sun, 14 Mar 2021 14:27:31 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 04/29] tcg: Remove error return from tcg_region_initial_alloc__locked Date: Sun, 14 Mar 2021 15:26:59 -0600 Message-Id: <20210314212724.1917075-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::82d; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x82d.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: r.bolshakov@yadro.com, j@getutm.app, =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" All callers immediately assert on error, so move the assert into the function itself. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/tcg.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) -- 2.25.1 diff --git a/tcg/tcg.c b/tcg/tcg.c index 0a2e5710de..2b631fccdf 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -720,9 +720,10 @@ static bool tcg_region_alloc(TCGContext *s) * Perform a context's first region allocation. * This function does _not_ increment region.agg_size_full. */ -static inline bool tcg_region_initial_alloc__locked(TCGContext *s) +static void tcg_region_initial_alloc__locked(TCGContext *s) { - return tcg_region_alloc__locked(s); + bool err = tcg_region_alloc__locked(s); + g_assert(!err); } /* Call from a safe-work context */ @@ -737,9 +738,7 @@ void tcg_region_reset_all(void) for (i = 0; i < n_ctxs; i++) { TCGContext *s = qatomic_read(&tcg_ctxs[i]); - bool err = tcg_region_initial_alloc__locked(s); - - g_assert(!err); + tcg_region_initial_alloc__locked(s); } qemu_mutex_unlock(®ion.lock); @@ -874,11 +873,7 @@ void tcg_region_init(void) /* In user-mode we support only one ctx, so do the initial allocation now */ #ifdef CONFIG_USER_ONLY - { - bool err = tcg_region_initial_alloc__locked(tcg_ctx); - - g_assert(!err); - } + tcg_region_initial_alloc__locked(tcg_ctx); #endif } @@ -940,7 +935,6 @@ void tcg_register_thread(void) MachineState *ms = MACHINE(qdev_get_machine()); TCGContext *s = g_malloc(sizeof(*s)); unsigned int i, n; - bool err; *s = tcg_init_ctx; @@ -964,8 +958,7 @@ void tcg_register_thread(void) tcg_ctx = s; qemu_mutex_lock(®ion.lock); - err = tcg_region_initial_alloc__locked(tcg_ctx); - g_assert(!err); + tcg_region_initial_alloc__locked(s); qemu_mutex_unlock(®ion.lock); } #endif /* !CONFIG_USER_ONLY */ From patchwork Sun Mar 14 21:27:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400132 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2923832jai; Sun, 14 Mar 2021 14:38:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1RVqpA2sjCfpKyosw/XerM7M/vlFFrNFy+2scgv5nXaTluhwKIpA760KZeJD0PaIJdSH+ X-Received: by 2002:a5b:c4c:: with SMTP id d12mr33101921ybr.18.1615757883901; Sun, 14 Mar 2021 14:38:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757883; cv=none; d=google.com; s=arc-20160816; b=v3Ux0Bfn+P7eIOg2ajx2oydbduYZV1zOyyW7xDr7JxesHZ1orSuweU07Z8XGwfZHNZ HPDLUHPKZ6RvCn7eKiShvyIxHa6gQ5dOGGLFYuSNnpU4FKbyuuCpxcv/hxFq9RuDFFF+ kszNaySJ6oqwA4C1Q8TMeDv/7zQqNV10sd9nhJYmolBv437pZ22qhQf0jPcH49KxApxq b9Y58+wpJQmCdMoY64Z7KruxIBpwhW9nMO2ShrgEauvZ4KqFv1GtD6f0+P6lLqgyBstW ge0WvV/dDaZcFqiR4NEi8WRzG3OLVHChODnFgQh3dvPjIX3CFa2xs1gWqCa8Q8GpEgE4 WgIQ== 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=36uzHkl7+IX2hopk8rVzdZIi+gPh2gDVUz4jl8wQF7M=; b=g1HR3fCXArZvwUWTlK+qh9taKs/jjZ5JW+xf/0DFXYI4p0rdak9e1xDrQCpDxRDG0v 5y1CnaCMquaqhL/CsRgCGAHFtC22ZtTRANJ+LH/ATMj1hL6UzlaqKA1Ful864g24TXY9 tknfd5FzvoXogPKTZm/yDMpj7AWggJc00ggXCzt0eGe9bIHeIkE6YvgkhUpAG1IVgRLX yi+VW1XAfBlcZ3XP0b1tzJa49vIEB78tgmpJsDnoOmPjXWY7iKsNa3W4gI8zBtEvq7Zp wiv4eJRf6mhWsNIlLDumu6VrPn5nZ4V3IImv8kBdD+gLBG/R6SJIkUT8chdIw96cy0+0 Lj0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NblCIYGL; 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=fail (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 i81si13250383ybg.83.2021.03.14.14.38.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:38:03 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=NblCIYGL; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYR1-0000t6-Af for patch@linaro.org; Sun, 14 Mar 2021 17:38:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGt-0005tP-0p for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:35 -0400 Received: from mail-qv1-xf2a.google.com ([2607:f8b0:4864:20::f2a]:45926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGr-00089e-H2 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:34 -0400 Received: by mail-qv1-xf2a.google.com with SMTP id t16so6881752qvr.12 for ; Sun, 14 Mar 2021 14:27:33 -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 :mime-version:content-transfer-encoding; bh=36uzHkl7+IX2hopk8rVzdZIi+gPh2gDVUz4jl8wQF7M=; b=NblCIYGL4F97OVV0KPQiR7R0WSN8wmrKTT0kI4G2r0H/NcZfZbHmh2qTndV5Q4NWz8 mpSbs59ur1pptviRTTGyMeXHBBfAs6gudiZIxFlMU3M56n08SyjC30u1Yg8ay9MUPIv2 HCtXh/N6wRTspVJ895sMGecY6gAFWooCtrEhj8kfbC8jFx4yzI/LWuki/a87Z5UcF8XQ X8FhIXNqVyzq1lSAAGTRidEFA2KTI1xa7nVp6o6Tg9j5tr9YjNY8z2Qb4ejUoZG+oBiA cRwwak/PWo7LpAvZOPNtW4cQNrIzByKHJtFhcbyHer9QGQ4Mr5RX7jwaf+GH3gC1PBlw hCjg== 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=36uzHkl7+IX2hopk8rVzdZIi+gPh2gDVUz4jl8wQF7M=; b=tgjaco2dkRdIyCul/t9L2bv/kY00jRRhzzVQXs+JVbGNd1igVvlPKBfp2rUjJDnQay jYqFWpFgtXydlKk+90NOgiMC6ZwxS5jkb876W3XCb4wtDIo1soXYFxagCigtIeE4VR3e roBZY2akk0CkagVtrX7HG6gKhqUpOrgTwoe7euVB1eIht+4kXCPFlxb5wtlsgWHQ1Zaa yvPE3lOHVWDQe/nGzNkz/NYbBq+8wr8gokSKhxGQDV3BJfkc3ZI1eoVzgJl9jZueXEWf dl7ozFMdYjvgPY7fHZZwg/o1tyfoOi0vgM2Q+CQaSaPpjPNQjA3XF7TDowzCBwxGXy6z y47Q== X-Gm-Message-State: AOAM531zGX3KL+l15vNBGJUD79Gigh0OYnZRXKXTptLTtdvg7WG0/J1E IU2Ahe1AGq3SrB9rMT1VdA8lEW4L5wNnA1jR X-Received: by 2002:ad4:5d47:: with SMTP id jk7mr1718768qvb.38.1615757252684; Sun, 14 Mar 2021 14:27:32 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 05/29] tcg: Split out tcg_region_initial_alloc Date: Sun, 14 Mar 2021 15:27:00 -0600 Message-Id: <20210314212724.1917075-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f2a; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2a.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This has only one user, and currently needs an ifdef, but will make more sense after some code motion. Signed-off-by: Richard Henderson --- tcg/tcg.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) -- 2.25.1 diff --git a/tcg/tcg.c b/tcg/tcg.c index 2b631fccdf..3316a22bde 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -726,6 +726,15 @@ static void tcg_region_initial_alloc__locked(TCGContext *s) g_assert(!err); } +#ifndef CONFIG_USER_ONLY +static void tcg_region_initial_alloc(TCGContext *s) +{ + qemu_mutex_lock(®ion.lock); + tcg_region_initial_alloc__locked(s); + qemu_mutex_unlock(®ion.lock); +} +#endif + /* Call from a safe-work context */ void tcg_region_reset_all(void) { @@ -957,9 +966,7 @@ void tcg_register_thread(void) } tcg_ctx = s; - qemu_mutex_lock(®ion.lock); - tcg_region_initial_alloc__locked(s); - qemu_mutex_unlock(®ion.lock); + tcg_region_initial_alloc(s); } #endif /* !CONFIG_USER_ONLY */ From patchwork Sun Mar 14 21:27:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400120 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2920078jai; Sun, 14 Mar 2021 14:28:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6Z9AmA8/+w4wTnfnGs7j9TE9JWs5b3gFvyXeR5U9jAUS/xVa989tdiE4JltoyirFHuMC6 X-Received: by 2002:a25:f0b:: with SMTP id 11mr33251400ybp.208.1615757299658; Sun, 14 Mar 2021 14:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757299; cv=none; d=google.com; s=arc-20160816; b=FNrcA7TtXR2ZTlkC7lrKh+vaufmP27+CXdJjBdEC6FWP0AdiAjrh+ddkALmTpTmsE4 eDczYVSH44IMBPx/pQO1N/D6qo7k3pkojWBRJStkpsRNk7gE9ccFSjROW7z7Wo9qTS7/ Qix9hBGbE5uBmKsyCA3MyDbbYQSajX0fUdBTgQNsOd4mSN/mXd0ekMuRQM5RboMe7ML/ auI5wXutTnpWLqy2eFSp4F/6pSUqEHpH/MqzYgRLlis3zhBoLlOMPbJss233El/uazyE Hou8JYuAZca6KsM+zrELi9EUsteXq96IfmgHQSBhmjxfW1d/NkuRpgAQ4iUVxypitRN6 tv3A== 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=EQ+ywpBmHDVC3DOo5FVJf1bXQ/r+fWvVCtSN9ZnyiEg=; b=0uJcIWQSRyQ+j7TIXzoU4r0J+23C+YT6zzywEe0LGm/FRPUcuOCuMooUaZ5vankkcB WIbJYY/URss2J6IaUMf/FQEu977CGILs+8WqrhdkEUJoijxisDHP4AECC2fhUAWOpKfg PYrt2mOiZP2Zfu3e9OlM8ogIB+itEe8UHjt0NoyYbfc5kjJM5Sn7+4+msQOVt6kOVNva Mlqf7cRasUxsf+3TmBh8dvW/o39v6Ubu3orEbEIy5e3RPDUvJcVrsLOnlqgG9MdaEQpI BIAH4ONHNcfSSl8D6/dIboGLg+fwO5uwMg+nF9CeRL1kweMfa6+Ysc9NZfFIVPRy6chN z/1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Ragnizp7; 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=fail (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 m17si12581475ybk.194.2021.03.14.14.28.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:28:19 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=Ragnizp7; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYHa-00060S-UG for patch@linaro.org; Sun, 14 Mar 2021 17:28:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGu-0005vb-7t for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:36 -0400 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]:43552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGs-0008AR-HZ for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:35 -0400 Received: by mail-qt1-x830.google.com with SMTP id s2so7857237qtx.10 for ; Sun, 14 Mar 2021 14:27:34 -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 :mime-version:content-transfer-encoding; bh=EQ+ywpBmHDVC3DOo5FVJf1bXQ/r+fWvVCtSN9ZnyiEg=; b=Ragnizp7a27wR/YaHG4/PdoiQ+mi5w+4HE5ob8l33RZkSiGr37ViIpaHQ5NvzIjSG6 F6PrCuPp+hKKHUVUPKat79k+C64MaPg+OozY9YnJZDBHvY/+QU+Ls2yxvYpzP3eDOvgM FpMO99rE7RpaB2Ph3DeMb0jd/bErcGwXttS0itB77/fwberQ2ed/7l2zPMzctXFsgepS M8ezJNDK5c0idmWBTSE5G5Mu4FutQQZ7MnSmezjiRReELdBEuCPOfFDjFv4K2lSXhLO3 KSfFVkV2R12xCej516/VvJZ2QMQp0wa9+aYnuj3e9QLXm9KXHHM4HgZoEtBt3sZLAjli 43TA== 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=EQ+ywpBmHDVC3DOo5FVJf1bXQ/r+fWvVCtSN9ZnyiEg=; b=kFkDDzZetF9ftyzulHfBjucOaN4dlU8PzzS+lKs2Q0ZK1j7xvM4PhdjC9T5vW8L1qV a3UEv9Sc+nqqR/hOU+HHhErlPAP2IudpgBZHA9v/Lqdw6EBfhcIjJqzKy+jslDpD3ZwA XUYSqYRBgGiaYkZyVzdrBXd+fKV20HUpK8/bt+0gfT9F1dK+s7+QRw99+yDJFQV8UNan HHquJGJE2wjq90rynROWAxPlNBL0BVn1NECoCaz+3ImboyFM0aCgtM2uPdevnqW4gG0u jV5VG0uEg6JklJhILfuCAt21+dbNjxVhacjwSxdGfJYKb1APUBon26hzQf2uhoyvRrLY EvaA== X-Gm-Message-State: AOAM530eOKnl7zGKX8UEHhI2/BSMCLheTpjtQOgNExIbiA9ty5v60C1L 6I/Vuf6gIsMeMp4wH/EVg1Fer4DNE/jMgb/f X-Received: by 2002:ac8:6892:: with SMTP id m18mr20232105qtq.5.1615757253660; Sun, 14 Mar 2021 14:27:33 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 06/29] tcg: Split out tcg_region_prologue_set Date: Sun, 14 Mar 2021 15:27:01 -0600 Message-Id: <20210314212724.1917075-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::830; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x830.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This has only one user, but will make more sense after some code motion. Always leave the tcg_init_ctx initialized to the first region, in preparation for tcg_prologue_init(). This also requires that we don't re-allocate the region for the first cpu, lest we hit the assertion for total number of regions allocated . Signed-off-by: Richard Henderson --- tcg/tcg.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) -- 2.25.1 diff --git a/tcg/tcg.c b/tcg/tcg.c index 3316a22bde..5b3525d52a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -880,10 +880,26 @@ void tcg_region_init(void) tcg_region_trees_init(); - /* In user-mode we support only one ctx, so do the initial allocation now */ -#ifdef CONFIG_USER_ONLY - tcg_region_initial_alloc__locked(tcg_ctx); -#endif + /* + * Leave the initial context initialized to the first region. + * This will be the context into which we generate the prologue. + * It is also the only context for CONFIG_USER_ONLY. + */ + tcg_region_initial_alloc__locked(&tcg_init_ctx); +} + +static void tcg_region_prologue_set(TCGContext *s) +{ + /* Deduct the prologue from the first region. */ + g_assert(region.start == s->code_gen_buffer); + region.start = s->code_ptr; + + /* Recompute boundaries of the first region. */ + tcg_region_assign(s, 0); + + /* Register the balance of the buffer with gdb. */ + tcg_register_jit(tcg_splitwx_to_rx(region.start), + region.end - region.start); } #ifdef CONFIG_DEBUG_TCG @@ -963,10 +979,10 @@ void tcg_register_thread(void) if (n > 0) { alloc_tcg_plugin_context(s); + tcg_region_initial_alloc(s); } tcg_ctx = s; - tcg_region_initial_alloc(s); } #endif /* !CONFIG_USER_ONLY */ @@ -1206,8 +1222,6 @@ void tcg_prologue_init(TCGContext *s) { size_t prologue_size; - /* Put the prologue at the beginning of code_gen_buffer. */ - tcg_region_assign(s, 0); s->code_ptr = s->code_gen_ptr; s->code_buf = s->code_gen_ptr; s->data_gen_ptr = NULL; @@ -1239,14 +1253,7 @@ void tcg_prologue_init(TCGContext *s) (uintptr_t)s->code_buf, prologue_size); #endif - /* Deduct the prologue from the first region. */ - region.start = s->code_ptr; - - /* Recompute boundaries of the first region. */ - tcg_region_assign(s, 0); - - tcg_register_jit(tcg_splitwx_to_rx(region.start), - region.end - region.start); + tcg_region_prologue_set(s); #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) { From patchwork Sun Mar 14 21:27:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400134 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2924730jai; Sun, 14 Mar 2021 14:40:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJya6vNjbnsh8kw+19Iq9UDGqT3hXE8F8VKZC4QRfSCQBAkKjJhk9COHwW8nq9aOhIbNNpGx X-Received: by 2002:a25:ab29:: with SMTP id u38mr31824785ybi.327.1615758043798; Sun, 14 Mar 2021 14:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758043; cv=none; d=google.com; s=arc-20160816; b=jhUX7j9cUIdwKMHkgyY7UfaVGSKWtegvb60dUWOaM0k2Hagoq4JIWX9eIEGjPh2cdO qFQ+3wuy5xAUz6hXog71HJMu1bTmruTFcY2JqN6WSyhlkxXKlw3/98qObGYEFsz6bc8R IVXmWW1imgybW+Rl964bybig0VBqVTyIWK6YI50+c4j+TQ9PDJAH8Cw+vaYRhEp9kKKV XaKYWaV8OpKGeqIXu/3mM1p6q/PRpgVvSpKjLRbZkwffgsQmw0umrfGSO08/PySMEWRx k6u/ktB7AIflan3VueOmAuYuOztci3hMl0MtRrTaPOTlrAGzlcXCAdq/qlSqJoUwxq1n 2n9A== 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=wyDvDQt0ocC4tKD3Beu6kf+j2hjEL+nr+C+2bx47vy0=; b=ZjHqW6BFDNncdc3wcQ1ixT6KPeNk0aVstquEHvodyhkkEvpxSFajuRZ+PifSUEPOPM 9iBmrB7ykwkjScVMFeWJcKc07TiiVT3cpyLL1enABWjzs06rcK+HWtu/BxhbMOoniUdt u5TwgexEkK9exOHUcPyAiU7zzX1zYnn8fPF4hz6Ln6R4slr8x7WLPC0Ilrnd/sD9HsAM hP15q3pEuFiE4xAZCAcEQsImTXaZAP4uMwvK4p4WdpcKLDwa0785sW/dJQ5R9PxRGvXC SekSoyvMhcA00WDOEKIETAAerSRmrSntzAISKn1nj8gD+YV3xYuLcTcWH2oIglq2tJu5 6BEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nPyG4+kN; 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=fail (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 130si12769302ybu.189.2021.03.14.14.40.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:40:43 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=nPyG4+kN; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYTa-0004Ol-VP for patch@linaro.org; Sun, 14 Mar 2021 17:40:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGy-00063w-3A for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:40 -0400 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]:34418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGu-0008Ao-3T for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:39 -0400 Received: by mail-qv1-xf34.google.com with SMTP id g8so6880004qvx.1 for ; Sun, 14 Mar 2021 14:27:35 -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 :mime-version:content-transfer-encoding; bh=wyDvDQt0ocC4tKD3Beu6kf+j2hjEL+nr+C+2bx47vy0=; b=nPyG4+kNE8U5EvQrj1kTbjzGpfbp/6yQjAiS2mwLI6sxwiTeV+bTSQVep0pF9myC+r XtUP380zjpCvpsOBk96e2fxXVkpoGBuovKZbF0M/sSmlYUh3eoOUn/y+kcOUhDKnFGyl YbvqLAdm8ZOZ9P3Lh+4ATL6TVnjNxqezpTCY5qudYBSqhRdapG4ox4ekEFR3VM3vnrAt cIm/H5oFdiSx4NRC7XXH67xbqTjgWVD+cirxyKiAZM/WrixTjZ4cmw4+i+dXCHgvfuI8 13/wbcDlTJAyHGeVtBiN5bhOpODoOX3cFHR5MSMy2vcN75oMq7CZ4gB4PdvXaRYxngx5 iMEA== 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=wyDvDQt0ocC4tKD3Beu6kf+j2hjEL+nr+C+2bx47vy0=; b=LLE0May4Di54Zjd+FYjuW/CW6RUVivs0yCVsdQ4w2mqYWvsN3snWCilQRvcgZidfQu l0K+j/VDxSC3M8BvNjAXoU1yyAov2x9k68Zeoa2qMWh2m2dcKzJfIQrQ6T8XtHHc0ZC5 JEy8Hb00AIqnUmJAa7XOgdhTvNWjF/VQXOtyCWCgSYsZQPjdkd3DOxVyMS0z8JCMPJoc Wk63AuJcaV+5qIklbkQje1c+lq9wwPYlB4qa+J7/qCRNxGYQQC61+NlxQou92U2OKewi stv8Lj8qKdpn9q8Y2vzQ2ZB4qw2G+uI+SVdzBTBp5ZpnZHYoN01/k9wrilfHXBy3SGNH 1wxw== X-Gm-Message-State: AOAM530MqnVMMweJx1Tf/cFCBngrRoRmBLpFgctP8CfAlcchh+woe001 P+PigwWTgA8w6XE8MiswdUdQtHU1ktKr00PQ X-Received: by 2002:ad4:5aa3:: with SMTP id u3mr8145111qvg.0.1615757254843; Sun, 14 Mar 2021 14:27:34 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 07/29] tcg: Split out region.c Date: Sun, 14 Mar 2021 15:27:02 -0600 Message-Id: <20210314212724.1917075-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f34; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf34.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- tcg/internal.h | 37 ++++ tcg/region.c | 570 ++++++++++++++++++++++++++++++++++++++++++++++++ tcg/tcg.c | 545 +-------------------------------------------- tcg/meson.build | 1 + 4 files changed, 611 insertions(+), 542 deletions(-) create mode 100644 tcg/internal.h create mode 100644 tcg/region.c -- 2.25.1 diff --git a/tcg/internal.h b/tcg/internal.h new file mode 100644 index 0000000000..b1dda343c2 --- /dev/null +++ b/tcg/internal.h @@ -0,0 +1,37 @@ +/* + * Internal declarations for Tiny Code Generator for QEMU + * + * Copyright (c) 2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef TCG_INTERNAL_H +#define TCG_INTERNAL_H 1 + +#define TCG_HIGHWATER 1024 + +extern TCGContext **tcg_ctxs; +extern unsigned int n_tcg_ctxs; + +bool tcg_region_alloc(TCGContext *s); +void tcg_region_initial_alloc(TCGContext *s); +void tcg_region_prologue_set(TCGContext *s); + +#endif /* TCG_INTERNAL_H */ diff --git a/tcg/region.c b/tcg/region.c new file mode 100644 index 0000000000..af45a0174e --- /dev/null +++ b/tcg/region.c @@ -0,0 +1,570 @@ +/* + * Memory region management for Tiny Code Generator for QEMU + * + * Copyright (c) 2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "exec/exec-all.h" +#include "tcg/tcg.h" +#if !defined(CONFIG_USER_ONLY) +#include "hw/boards.h" +#endif +#include "internal.h" + + +struct tcg_region_tree { + QemuMutex lock; + GTree *tree; + /* padding to avoid false sharing is computed at run-time */ +}; + +/* + * We divide code_gen_buffer into equally-sized "regions" that TCG threads + * dynamically allocate from as demand dictates. Given appropriate region + * sizing, this minimizes flushes even when some TCG threads generate a lot + * more code than others. + */ +struct tcg_region_state { + QemuMutex lock; + + /* fields set at init time */ + void *start; + void *start_aligned; + void *end; + size_t n; + size_t size; /* size of one region */ + size_t stride; /* .size + guard size */ + + /* fields protected by the lock */ + size_t current; /* current region index */ + size_t agg_size_full; /* aggregate size of full regions */ +}; + +static struct tcg_region_state region; + +/* + * This is an array of struct tcg_region_tree's, with padding. + * We use void * to simplify the computation of region_trees[i]; each + * struct is found every tree_size bytes. + */ +static void *region_trees; +static size_t tree_size; + +/* compare a pointer @ptr and a tb_tc @s */ +static int ptr_cmp_tb_tc(const void *ptr, const struct tb_tc *s) +{ + if (ptr >= s->ptr + s->size) { + return 1; + } else if (ptr < s->ptr) { + return -1; + } + return 0; +} + +static gint tb_tc_cmp(gconstpointer ap, gconstpointer bp) +{ + const struct tb_tc *a = ap; + const struct tb_tc *b = bp; + + /* + * When both sizes are set, we know this isn't a lookup. + * This is the most likely case: every TB must be inserted; lookups + * are a lot less frequent. + */ + if (likely(a->size && b->size)) { + if (a->ptr > b->ptr) { + return 1; + } else if (a->ptr < b->ptr) { + return -1; + } + /* a->ptr == b->ptr should happen only on deletions */ + g_assert(a->size == b->size); + return 0; + } + /* + * All lookups have either .size field set to 0. + * From the glib sources we see that @ap is always the lookup key. However + * the docs provide no guarantee, so we just mark this case as likely. + */ + if (likely(a->size == 0)) { + return ptr_cmp_tb_tc(a->ptr, b); + } + return ptr_cmp_tb_tc(b->ptr, a); +} + +static void tcg_region_trees_init(void) +{ + size_t i; + + tree_size = ROUND_UP(sizeof(struct tcg_region_tree), qemu_dcache_linesize); + region_trees = qemu_memalign(qemu_dcache_linesize, region.n * tree_size); + for (i = 0; i < region.n; i++) { + struct tcg_region_tree *rt = region_trees + i * tree_size; + + qemu_mutex_init(&rt->lock); + rt->tree = g_tree_new(tb_tc_cmp); + } +} + +static struct tcg_region_tree *tc_ptr_to_region_tree(const void *p) +{ + size_t region_idx; + + /* + * Like tcg_splitwx_to_rw, with no assert. The pc may come from + * a signal handler over which the caller has no control. + */ + if (!in_code_gen_buffer(p)) { + p -= tcg_splitwx_diff; + if (!in_code_gen_buffer(p)) { + return NULL; + } + } + + if (p < region.start_aligned) { + region_idx = 0; + } else { + ptrdiff_t offset = p - region.start_aligned; + + if (offset > region.stride * (region.n - 1)) { + region_idx = region.n - 1; + } else { + region_idx = offset / region.stride; + } + } + return region_trees + region_idx * tree_size; +} + +void tcg_tb_insert(TranslationBlock *tb) +{ + struct tcg_region_tree *rt = tc_ptr_to_region_tree(tb->tc.ptr); + + g_assert(rt != NULL); + qemu_mutex_lock(&rt->lock); + g_tree_insert(rt->tree, &tb->tc, tb); + qemu_mutex_unlock(&rt->lock); +} + +void tcg_tb_remove(TranslationBlock *tb) +{ + struct tcg_region_tree *rt = tc_ptr_to_region_tree(tb->tc.ptr); + + g_assert(rt != NULL); + qemu_mutex_lock(&rt->lock); + g_tree_remove(rt->tree, &tb->tc); + qemu_mutex_unlock(&rt->lock); +} + +/* + * Find the TB 'tb' such that + * tb->tc.ptr <= tc_ptr < tb->tc.ptr + tb->tc.size + * Return NULL if not found. + */ +TranslationBlock *tcg_tb_lookup(uintptr_t tc_ptr) +{ + struct tcg_region_tree *rt = tc_ptr_to_region_tree((void *)tc_ptr); + TranslationBlock *tb; + struct tb_tc s = { .ptr = (void *)tc_ptr }; + + if (rt == NULL) { + return NULL; + } + + qemu_mutex_lock(&rt->lock); + tb = g_tree_lookup(rt->tree, &s); + qemu_mutex_unlock(&rt->lock); + return tb; +} + +static void tcg_region_tree_lock_all(void) +{ + size_t i; + + for (i = 0; i < region.n; i++) { + struct tcg_region_tree *rt = region_trees + i * tree_size; + + qemu_mutex_lock(&rt->lock); + } +} + +static void tcg_region_tree_unlock_all(void) +{ + size_t i; + + for (i = 0; i < region.n; i++) { + struct tcg_region_tree *rt = region_trees + i * tree_size; + + qemu_mutex_unlock(&rt->lock); + } +} + +void tcg_tb_foreach(GTraverseFunc func, gpointer user_data) +{ + size_t i; + + tcg_region_tree_lock_all(); + for (i = 0; i < region.n; i++) { + struct tcg_region_tree *rt = region_trees + i * tree_size; + + g_tree_foreach(rt->tree, func, user_data); + } + tcg_region_tree_unlock_all(); +} + +size_t tcg_nb_tbs(void) +{ + size_t nb_tbs = 0; + size_t i; + + tcg_region_tree_lock_all(); + for (i = 0; i < region.n; i++) { + struct tcg_region_tree *rt = region_trees + i * tree_size; + + nb_tbs += g_tree_nnodes(rt->tree); + } + tcg_region_tree_unlock_all(); + return nb_tbs; +} + +static gboolean tcg_region_tree_traverse(gpointer k, gpointer v, gpointer data) +{ + TranslationBlock *tb = v; + + tb_destroy(tb); + return FALSE; +} + +static void tcg_region_tree_reset_all(void) +{ + size_t i; + + tcg_region_tree_lock_all(); + for (i = 0; i < region.n; i++) { + struct tcg_region_tree *rt = region_trees + i * tree_size; + + g_tree_foreach(rt->tree, tcg_region_tree_traverse, NULL); + /* Increment the refcount first so that destroy acts as a reset */ + g_tree_ref(rt->tree); + g_tree_destroy(rt->tree); + } + tcg_region_tree_unlock_all(); +} + +static void tcg_region_bounds(size_t curr_region, void **pstart, void **pend) +{ + void *start, *end; + + start = region.start_aligned + curr_region * region.stride; + end = start + region.size; + + if (curr_region == 0) { + start = region.start; + } + if (curr_region == region.n - 1) { + end = region.end; + } + + *pstart = start; + *pend = end; +} + +static void tcg_region_assign(TCGContext *s, size_t curr_region) +{ + void *start, *end; + + tcg_region_bounds(curr_region, &start, &end); + + s->code_gen_buffer = start; + s->code_gen_ptr = start; + s->code_gen_buffer_size = end - start; + s->code_gen_highwater = end - TCG_HIGHWATER; +} + +static bool tcg_region_alloc__locked(TCGContext *s) +{ + if (region.current == region.n) { + return true; + } + tcg_region_assign(s, region.current); + region.current++; + return false; +} + +/* + * Request a new region once the one in use has filled up. + * Returns true on error. + */ +bool tcg_region_alloc(TCGContext *s) +{ + bool err; + /* read the region size now; alloc__locked will overwrite it on success */ + size_t size_full = s->code_gen_buffer_size; + + qemu_mutex_lock(®ion.lock); + err = tcg_region_alloc__locked(s); + if (!err) { + region.agg_size_full += size_full - TCG_HIGHWATER; + } + qemu_mutex_unlock(®ion.lock); + return err; +} + +/* + * Perform a context's first region allocation. + * This function does _not_ increment region.agg_size_full. + */ +static void tcg_region_initial_alloc__locked(TCGContext *s) +{ + bool err = tcg_region_alloc__locked(s); + g_assert(!err); +} + +void tcg_region_initial_alloc(TCGContext *s) +{ + qemu_mutex_lock(®ion.lock); + tcg_region_initial_alloc__locked(s); + qemu_mutex_unlock(®ion.lock); +} + +/* Call from a safe-work context */ +void tcg_region_reset_all(void) +{ + unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); + unsigned int i; + + qemu_mutex_lock(®ion.lock); + region.current = 0; + region.agg_size_full = 0; + + for (i = 0; i < n_ctxs; i++) { + TCGContext *s = qatomic_read(&tcg_ctxs[i]); + tcg_region_initial_alloc__locked(s); + } + qemu_mutex_unlock(®ion.lock); + + tcg_region_tree_reset_all(); +} + +#ifdef CONFIG_USER_ONLY +static size_t tcg_n_regions(void) +{ + return 1; +} +#else +/* + * It is likely that some vCPUs will translate more code than others, so we + * first try to set more regions than max_cpus, with those regions being of + * reasonable size. If that's not possible we make do by evenly dividing + * the code_gen_buffer among the vCPUs. + */ +static size_t tcg_n_regions(void) +{ + size_t i; + + /* Use a single region if all we have is one vCPU thread */ +#if !defined(CONFIG_USER_ONLY) + MachineState *ms = MACHINE(qdev_get_machine()); + unsigned int max_cpus = ms->smp.max_cpus; +#endif + if (max_cpus == 1 || !qemu_tcg_mttcg_enabled()) { + return 1; + } + + /* Try to have more regions than max_cpus, with each region being >= 2 MB */ + for (i = 8; i > 0; i--) { + size_t regions_per_thread = i; + size_t region_size; + + region_size = tcg_init_ctx.code_gen_buffer_size; + region_size /= max_cpus * regions_per_thread; + + if (region_size >= 2 * 1024u * 1024) { + return max_cpus * regions_per_thread; + } + } + /* If we can't, then just allocate one region per vCPU thread */ + return max_cpus; +} +#endif + +/* + * Initializes region partitioning. + * + * Called at init time from the parent thread (i.e. the one calling + * tcg_context_init), after the target's TCG globals have been set. + * + * Region partitioning works by splitting code_gen_buffer into separate regions, + * and then assigning regions to TCG threads so that the threads can translate + * code in parallel without synchronization. + * + * In softmmu the number of TCG threads is bounded by max_cpus, so we use at + * least max_cpus regions in MTTCG. In !MTTCG we use a single region. + * Note that the TCG options from the command-line (i.e. -accel accel=tcg,[...]) + * must have been parsed before calling this function, since it calls + * qemu_tcg_mttcg_enabled(). + * + * In user-mode we use a single region. Having multiple regions in user-mode + * is not supported, because the number of vCPU threads (recall that each thread + * spawned by the guest corresponds to a vCPU thread) is only bounded by the + * OS, and usually this number is huge (tens of thousands is not uncommon). + * Thus, given this large bound on the number of vCPU threads and the fact + * that code_gen_buffer is allocated at compile-time, we cannot guarantee + * that the availability of at least one region per vCPU thread. + * + * However, this user-mode limitation is unlikely to be a significant problem + * in practice. Multi-threaded guests share most if not all of their translated + * code, which makes parallel code generation less appealing than in softmmu. + */ +void tcg_region_init(void) +{ + void *buf = tcg_init_ctx.code_gen_buffer; + void *aligned; + size_t size = tcg_init_ctx.code_gen_buffer_size; + size_t page_size = qemu_real_host_page_size; + size_t region_size; + size_t n_regions; + size_t i; + uintptr_t splitwx_diff; + + n_regions = tcg_n_regions(); + + /* The first region will be 'aligned - buf' bytes larger than the others */ + aligned = QEMU_ALIGN_PTR_UP(buf, page_size); + g_assert(aligned < tcg_init_ctx.code_gen_buffer + size); + /* + * Make region_size a multiple of page_size, using aligned as the start. + * As a result of this we might end up with a few extra pages at the end of + * the buffer; we will assign those to the last region. + */ + region_size = (size - (aligned - buf)) / n_regions; + region_size = QEMU_ALIGN_DOWN(region_size, page_size); + + /* A region must have at least 2 pages; one code, one guard */ + g_assert(region_size >= 2 * page_size); + + /* init the region struct */ + qemu_mutex_init(®ion.lock); + region.n = n_regions; + region.size = region_size - page_size; + region.stride = region_size; + region.start = buf; + region.start_aligned = aligned; + /* page-align the end, since its last page will be a guard page */ + region.end = QEMU_ALIGN_PTR_DOWN(buf + size, page_size); + /* account for that last guard page */ + region.end -= page_size; + + /* set guard pages */ + splitwx_diff = tcg_splitwx_diff; + for (i = 0; i < region.n; i++) { + void *start, *end; + int rc; + + tcg_region_bounds(i, &start, &end); + rc = qemu_mprotect_none(end, page_size); + g_assert(!rc); + if (splitwx_diff) { + rc = qemu_mprotect_none(end + splitwx_diff, page_size); + g_assert(!rc); + } + } + + tcg_region_trees_init(); + + /* + * Leave the initial context initialized to the first region. + * This will be the context into which we generate the prologue. + * It is also the only context for CONFIG_USER_ONLY. + */ + tcg_region_initial_alloc__locked(&tcg_init_ctx); +} + +void tcg_region_prologue_set(TCGContext *s) +{ + /* Deduct the prologue from the first region. */ + g_assert(region.start == s->code_gen_buffer); + region.start = s->code_ptr; + + /* Recompute boundaries of the first region. */ + tcg_region_assign(s, 0); + + /* Register the balance of the buffer with gdb. */ + tcg_register_jit(tcg_splitwx_to_rx(region.start), + region.end - region.start); +} + +/* + * Returns the size (in bytes) of all translated code (i.e. from all regions) + * currently in the cache. + * See also: tcg_code_capacity() + * Do not confuse with tcg_current_code_size(); that one applies to a single + * TCG context. + */ +size_t tcg_code_size(void) +{ + unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); + unsigned int i; + size_t total; + + qemu_mutex_lock(®ion.lock); + total = region.agg_size_full; + for (i = 0; i < n_ctxs; i++) { + const TCGContext *s = qatomic_read(&tcg_ctxs[i]); + size_t size; + + size = qatomic_read(&s->code_gen_ptr) - s->code_gen_buffer; + g_assert(size <= s->code_gen_buffer_size); + total += size; + } + qemu_mutex_unlock(®ion.lock); + return total; +} + +/* + * Returns the code capacity (in bytes) of the entire cache, i.e. including all + * regions. + * See also: tcg_code_size() + */ +size_t tcg_code_capacity(void) +{ + size_t guard_size, capacity; + + /* no need for synchronization; these variables are set at init time */ + guard_size = region.stride - region.size; + capacity = region.end + guard_size - region.start; + capacity -= region.n * (guard_size + TCG_HIGHWATER); + return capacity; +} + +size_t tcg_tb_phys_invalidate_count(void) +{ + unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); + unsigned int i; + size_t total = 0; + + for (i = 0; i < n_ctxs; i++) { + const TCGContext *s = qatomic_read(&tcg_ctxs[i]); + + total += qatomic_read(&s->tb_phys_invalidate_count); + } + return total; +} diff --git a/tcg/tcg.c b/tcg/tcg.c index 5b3525d52a..10a571d41c 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -65,6 +65,7 @@ #include "elf.h" #include "exec/log.h" #include "sysemu/sysemu.h" +#include "internal.h" /* Forward declarations for functions declared in tcg-target.c.inc and used here. */ @@ -153,10 +154,8 @@ static int tcg_target_const_match(tcg_target_long val, TCGType type, static int tcg_out_ldst_finalize(TCGContext *s); #endif -#define TCG_HIGHWATER 1024 - -static TCGContext **tcg_ctxs; -static unsigned int n_tcg_ctxs; +TCGContext **tcg_ctxs; +unsigned int n_tcg_ctxs; TCGv_env cpu_env = 0; const void *tcg_code_gen_epilogue; uintptr_t tcg_splitwx_diff; @@ -165,42 +164,6 @@ uintptr_t tcg_splitwx_diff; tcg_prologue_fn *tcg_qemu_tb_exec; #endif -struct tcg_region_tree { - QemuMutex lock; - GTree *tree; - /* padding to avoid false sharing is computed at run-time */ -}; - -/* - * We divide code_gen_buffer into equally-sized "regions" that TCG threads - * dynamically allocate from as demand dictates. Given appropriate region - * sizing, this minimizes flushes even when some TCG threads generate a lot - * more code than others. - */ -struct tcg_region_state { - QemuMutex lock; - - /* fields set at init time */ - void *start; - void *start_aligned; - void *end; - size_t n; - size_t size; /* size of one region */ - size_t stride; /* .size + guard size */ - - /* fields protected by the lock */ - size_t current; /* current region index */ - size_t agg_size_full; /* aggregate size of full regions */ -}; - -static struct tcg_region_state region; -/* - * This is an array of struct tcg_region_tree's, with padding. - * We use void * to simplify the computation of region_trees[i]; each - * struct is found every tree_size bytes. - */ -static void *region_trees; -static size_t tree_size; static TCGRegSet tcg_target_available_regs[TCG_TYPE_COUNT]; static TCGRegSet tcg_target_call_clobber_regs; @@ -457,451 +420,6 @@ static const TCGTargetOpDef constraint_sets[] = { #include "tcg-target.c.inc" -/* compare a pointer @ptr and a tb_tc @s */ -static int ptr_cmp_tb_tc(const void *ptr, const struct tb_tc *s) -{ - if (ptr >= s->ptr + s->size) { - return 1; - } else if (ptr < s->ptr) { - return -1; - } - return 0; -} - -static gint tb_tc_cmp(gconstpointer ap, gconstpointer bp) -{ - const struct tb_tc *a = ap; - const struct tb_tc *b = bp; - - /* - * When both sizes are set, we know this isn't a lookup. - * This is the most likely case: every TB must be inserted; lookups - * are a lot less frequent. - */ - if (likely(a->size && b->size)) { - if (a->ptr > b->ptr) { - return 1; - } else if (a->ptr < b->ptr) { - return -1; - } - /* a->ptr == b->ptr should happen only on deletions */ - g_assert(a->size == b->size); - return 0; - } - /* - * All lookups have either .size field set to 0. - * From the glib sources we see that @ap is always the lookup key. However - * the docs provide no guarantee, so we just mark this case as likely. - */ - if (likely(a->size == 0)) { - return ptr_cmp_tb_tc(a->ptr, b); - } - return ptr_cmp_tb_tc(b->ptr, a); -} - -static void tcg_region_trees_init(void) -{ - size_t i; - - tree_size = ROUND_UP(sizeof(struct tcg_region_tree), qemu_dcache_linesize); - region_trees = qemu_memalign(qemu_dcache_linesize, region.n * tree_size); - for (i = 0; i < region.n; i++) { - struct tcg_region_tree *rt = region_trees + i * tree_size; - - qemu_mutex_init(&rt->lock); - rt->tree = g_tree_new(tb_tc_cmp); - } -} - -static struct tcg_region_tree *tc_ptr_to_region_tree(const void *p) -{ - size_t region_idx; - - /* - * Like tcg_splitwx_to_rw, with no assert. The pc may come from - * a signal handler over which the caller has no control. - */ - if (!in_code_gen_buffer(p)) { - p -= tcg_splitwx_diff; - if (!in_code_gen_buffer(p)) { - return NULL; - } - } - - if (p < region.start_aligned) { - region_idx = 0; - } else { - ptrdiff_t offset = p - region.start_aligned; - - if (offset > region.stride * (region.n - 1)) { - region_idx = region.n - 1; - } else { - region_idx = offset / region.stride; - } - } - return region_trees + region_idx * tree_size; -} - -void tcg_tb_insert(TranslationBlock *tb) -{ - struct tcg_region_tree *rt = tc_ptr_to_region_tree(tb->tc.ptr); - - g_assert(rt != NULL); - qemu_mutex_lock(&rt->lock); - g_tree_insert(rt->tree, &tb->tc, tb); - qemu_mutex_unlock(&rt->lock); -} - -void tcg_tb_remove(TranslationBlock *tb) -{ - struct tcg_region_tree *rt = tc_ptr_to_region_tree(tb->tc.ptr); - - g_assert(rt != NULL); - qemu_mutex_lock(&rt->lock); - g_tree_remove(rt->tree, &tb->tc); - qemu_mutex_unlock(&rt->lock); -} - -/* - * Find the TB 'tb' such that - * tb->tc.ptr <= tc_ptr < tb->tc.ptr + tb->tc.size - * Return NULL if not found. - */ -TranslationBlock *tcg_tb_lookup(uintptr_t tc_ptr) -{ - struct tcg_region_tree *rt = tc_ptr_to_region_tree((void *)tc_ptr); - TranslationBlock *tb; - struct tb_tc s = { .ptr = (void *)tc_ptr }; - - if (rt == NULL) { - return NULL; - } - - qemu_mutex_lock(&rt->lock); - tb = g_tree_lookup(rt->tree, &s); - qemu_mutex_unlock(&rt->lock); - return tb; -} - -static void tcg_region_tree_lock_all(void) -{ - size_t i; - - for (i = 0; i < region.n; i++) { - struct tcg_region_tree *rt = region_trees + i * tree_size; - - qemu_mutex_lock(&rt->lock); - } -} - -static void tcg_region_tree_unlock_all(void) -{ - size_t i; - - for (i = 0; i < region.n; i++) { - struct tcg_region_tree *rt = region_trees + i * tree_size; - - qemu_mutex_unlock(&rt->lock); - } -} - -void tcg_tb_foreach(GTraverseFunc func, gpointer user_data) -{ - size_t i; - - tcg_region_tree_lock_all(); - for (i = 0; i < region.n; i++) { - struct tcg_region_tree *rt = region_trees + i * tree_size; - - g_tree_foreach(rt->tree, func, user_data); - } - tcg_region_tree_unlock_all(); -} - -size_t tcg_nb_tbs(void) -{ - size_t nb_tbs = 0; - size_t i; - - tcg_region_tree_lock_all(); - for (i = 0; i < region.n; i++) { - struct tcg_region_tree *rt = region_trees + i * tree_size; - - nb_tbs += g_tree_nnodes(rt->tree); - } - tcg_region_tree_unlock_all(); - return nb_tbs; -} - -static gboolean tcg_region_tree_traverse(gpointer k, gpointer v, gpointer data) -{ - TranslationBlock *tb = v; - - tb_destroy(tb); - return FALSE; -} - -static void tcg_region_tree_reset_all(void) -{ - size_t i; - - tcg_region_tree_lock_all(); - for (i = 0; i < region.n; i++) { - struct tcg_region_tree *rt = region_trees + i * tree_size; - - g_tree_foreach(rt->tree, tcg_region_tree_traverse, NULL); - /* Increment the refcount first so that destroy acts as a reset */ - g_tree_ref(rt->tree); - g_tree_destroy(rt->tree); - } - tcg_region_tree_unlock_all(); -} - -static void tcg_region_bounds(size_t curr_region, void **pstart, void **pend) -{ - void *start, *end; - - start = region.start_aligned + curr_region * region.stride; - end = start + region.size; - - if (curr_region == 0) { - start = region.start; - } - if (curr_region == region.n - 1) { - end = region.end; - } - - *pstart = start; - *pend = end; -} - -static void tcg_region_assign(TCGContext *s, size_t curr_region) -{ - void *start, *end; - - tcg_region_bounds(curr_region, &start, &end); - - s->code_gen_buffer = start; - s->code_gen_ptr = start; - s->code_gen_buffer_size = end - start; - s->code_gen_highwater = end - TCG_HIGHWATER; -} - -static bool tcg_region_alloc__locked(TCGContext *s) -{ - if (region.current == region.n) { - return true; - } - tcg_region_assign(s, region.current); - region.current++; - return false; -} - -/* - * Request a new region once the one in use has filled up. - * Returns true on error. - */ -static bool tcg_region_alloc(TCGContext *s) -{ - bool err; - /* read the region size now; alloc__locked will overwrite it on success */ - size_t size_full = s->code_gen_buffer_size; - - qemu_mutex_lock(®ion.lock); - err = tcg_region_alloc__locked(s); - if (!err) { - region.agg_size_full += size_full - TCG_HIGHWATER; - } - qemu_mutex_unlock(®ion.lock); - return err; -} - -/* - * Perform a context's first region allocation. - * This function does _not_ increment region.agg_size_full. - */ -static void tcg_region_initial_alloc__locked(TCGContext *s) -{ - bool err = tcg_region_alloc__locked(s); - g_assert(!err); -} - -#ifndef CONFIG_USER_ONLY -static void tcg_region_initial_alloc(TCGContext *s) -{ - qemu_mutex_lock(®ion.lock); - tcg_region_initial_alloc__locked(s); - qemu_mutex_unlock(®ion.lock); -} -#endif - -/* Call from a safe-work context */ -void tcg_region_reset_all(void) -{ - unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); - unsigned int i; - - qemu_mutex_lock(®ion.lock); - region.current = 0; - region.agg_size_full = 0; - - for (i = 0; i < n_ctxs; i++) { - TCGContext *s = qatomic_read(&tcg_ctxs[i]); - tcg_region_initial_alloc__locked(s); - } - qemu_mutex_unlock(®ion.lock); - - tcg_region_tree_reset_all(); -} - -#ifdef CONFIG_USER_ONLY -static size_t tcg_n_regions(void) -{ - return 1; -} -#else -/* - * It is likely that some vCPUs will translate more code than others, so we - * first try to set more regions than max_cpus, with those regions being of - * reasonable size. If that's not possible we make do by evenly dividing - * the code_gen_buffer among the vCPUs. - */ -static size_t tcg_n_regions(void) -{ - size_t i; - - /* Use a single region if all we have is one vCPU thread */ -#if !defined(CONFIG_USER_ONLY) - MachineState *ms = MACHINE(qdev_get_machine()); - unsigned int max_cpus = ms->smp.max_cpus; -#endif - if (max_cpus == 1 || !qemu_tcg_mttcg_enabled()) { - return 1; - } - - /* Try to have more regions than max_cpus, with each region being >= 2 MB */ - for (i = 8; i > 0; i--) { - size_t regions_per_thread = i; - size_t region_size; - - region_size = tcg_init_ctx.code_gen_buffer_size; - region_size /= max_cpus * regions_per_thread; - - if (region_size >= 2 * 1024u * 1024) { - return max_cpus * regions_per_thread; - } - } - /* If we can't, then just allocate one region per vCPU thread */ - return max_cpus; -} -#endif - -/* - * Initializes region partitioning. - * - * Called at init time from the parent thread (i.e. the one calling - * tcg_context_init), after the target's TCG globals have been set. - * - * Region partitioning works by splitting code_gen_buffer into separate regions, - * and then assigning regions to TCG threads so that the threads can translate - * code in parallel without synchronization. - * - * In softmmu the number of TCG threads is bounded by max_cpus, so we use at - * least max_cpus regions in MTTCG. In !MTTCG we use a single region. - * Note that the TCG options from the command-line (i.e. -accel accel=tcg,[...]) - * must have been parsed before calling this function, since it calls - * qemu_tcg_mttcg_enabled(). - * - * In user-mode we use a single region. Having multiple regions in user-mode - * is not supported, because the number of vCPU threads (recall that each thread - * spawned by the guest corresponds to a vCPU thread) is only bounded by the - * OS, and usually this number is huge (tens of thousands is not uncommon). - * Thus, given this large bound on the number of vCPU threads and the fact - * that code_gen_buffer is allocated at compile-time, we cannot guarantee - * that the availability of at least one region per vCPU thread. - * - * However, this user-mode limitation is unlikely to be a significant problem - * in practice. Multi-threaded guests share most if not all of their translated - * code, which makes parallel code generation less appealing than in softmmu. - */ -void tcg_region_init(void) -{ - void *buf = tcg_init_ctx.code_gen_buffer; - void *aligned; - size_t size = tcg_init_ctx.code_gen_buffer_size; - size_t page_size = qemu_real_host_page_size; - size_t region_size; - size_t n_regions; - size_t i; - uintptr_t splitwx_diff; - - n_regions = tcg_n_regions(); - - /* The first region will be 'aligned - buf' bytes larger than the others */ - aligned = QEMU_ALIGN_PTR_UP(buf, page_size); - g_assert(aligned < tcg_init_ctx.code_gen_buffer + size); - /* - * Make region_size a multiple of page_size, using aligned as the start. - * As a result of this we might end up with a few extra pages at the end of - * the buffer; we will assign those to the last region. - */ - region_size = (size - (aligned - buf)) / n_regions; - region_size = QEMU_ALIGN_DOWN(region_size, page_size); - - /* A region must have at least 2 pages; one code, one guard */ - g_assert(region_size >= 2 * page_size); - - /* init the region struct */ - qemu_mutex_init(®ion.lock); - region.n = n_regions; - region.size = region_size - page_size; - region.stride = region_size; - region.start = buf; - region.start_aligned = aligned; - /* page-align the end, since its last page will be a guard page */ - region.end = QEMU_ALIGN_PTR_DOWN(buf + size, page_size); - /* account for that last guard page */ - region.end -= page_size; - - /* set guard pages */ - splitwx_diff = tcg_splitwx_diff; - for (i = 0; i < region.n; i++) { - void *start, *end; - int rc; - - tcg_region_bounds(i, &start, &end); - rc = qemu_mprotect_none(end, page_size); - g_assert(!rc); - if (splitwx_diff) { - rc = qemu_mprotect_none(end + splitwx_diff, page_size); - g_assert(!rc); - } - } - - tcg_region_trees_init(); - - /* - * Leave the initial context initialized to the first region. - * This will be the context into which we generate the prologue. - * It is also the only context for CONFIG_USER_ONLY. - */ - tcg_region_initial_alloc__locked(&tcg_init_ctx); -} - -static void tcg_region_prologue_set(TCGContext *s) -{ - /* Deduct the prologue from the first region. */ - g_assert(region.start == s->code_gen_buffer); - region.start = s->code_ptr; - - /* Recompute boundaries of the first region. */ - tcg_region_assign(s, 0); - - /* Register the balance of the buffer with gdb. */ - tcg_register_jit(tcg_splitwx_to_rx(region.start), - region.end - region.start); -} - #ifdef CONFIG_DEBUG_TCG const void *tcg_splitwx_to_rx(void *rw) { @@ -986,63 +504,6 @@ void tcg_register_thread(void) } #endif /* !CONFIG_USER_ONLY */ -/* - * Returns the size (in bytes) of all translated code (i.e. from all regions) - * currently in the cache. - * See also: tcg_code_capacity() - * Do not confuse with tcg_current_code_size(); that one applies to a single - * TCG context. - */ -size_t tcg_code_size(void) -{ - unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); - unsigned int i; - size_t total; - - qemu_mutex_lock(®ion.lock); - total = region.agg_size_full; - for (i = 0; i < n_ctxs; i++) { - const TCGContext *s = qatomic_read(&tcg_ctxs[i]); - size_t size; - - size = qatomic_read(&s->code_gen_ptr) - s->code_gen_buffer; - g_assert(size <= s->code_gen_buffer_size); - total += size; - } - qemu_mutex_unlock(®ion.lock); - return total; -} - -/* - * Returns the code capacity (in bytes) of the entire cache, i.e. including all - * regions. - * See also: tcg_code_size() - */ -size_t tcg_code_capacity(void) -{ - size_t guard_size, capacity; - - /* no need for synchronization; these variables are set at init time */ - guard_size = region.stride - region.size; - capacity = region.end + guard_size - region.start; - capacity -= region.n * (guard_size + TCG_HIGHWATER); - return capacity; -} - -size_t tcg_tb_phys_invalidate_count(void) -{ - unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); - unsigned int i; - size_t total = 0; - - for (i = 0; i < n_ctxs; i++) { - const TCGContext *s = qatomic_read(&tcg_ctxs[i]); - - total += qatomic_read(&s->tb_phys_invalidate_count); - } - return total; -} - /* pool based memory allocation */ void *tcg_malloc_internal(TCGContext *s, int size) { diff --git a/tcg/meson.build b/tcg/meson.build index 84064a341e..5be3915529 100644 --- a/tcg/meson.build +++ b/tcg/meson.build @@ -2,6 +2,7 @@ tcg_ss = ss.source_set() tcg_ss.add(files( 'optimize.c', + 'region.c', 'tcg.c', 'tcg-common.c', 'tcg-op.c', From patchwork Sun Mar 14 21:27:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400122 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2920891jai; Sun, 14 Mar 2021 14:30:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwR8KqxhSFsVmjl4rIC7nFWDRgvu9ua2EQjf0ZnWht5RkLWuvcbY/MHT2CaGqE5X+3uEnLM X-Received: by 2002:a25:e6d1:: with SMTP id d200mr11905024ybh.265.1615757419849; Sun, 14 Mar 2021 14:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757419; cv=none; d=google.com; s=arc-20160816; b=JhI+Z/llbXAmizr6lGtm524sxr+umuFJPkzBJb1i0YeLI8uKmmuDZLg00gsIiVCRXo Xo855Mgb9d3tGeUiEcZSMkAszpoT75QKTLPcT+hdy2H5C1vaqhcKHTzm1Y3/c8nzu4x/ mPymAtNfnHJJtv/mFH3Suou/mo3ArRsYGwpZn4QHnw65LbQKK+5Q2DrrUunfnmzAg6gR cy5d69V0SEgLDPo/onGjuPLj2AIDh5gDAIcbmmkS0BG1HGmHIYsq1TJs+NTn2ez6nlAr wGio992XPhDrhVeE3i2wtC7M3wm59I0peikpVixPcjIGm64MOeo2pmuZlw5T3IszGdPK MM1A== 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=yjdtKlRm3WuNdcNC9EUZQ7YJqY8dzEyQHbjSnP7J42Q=; b=sS5zSwNeW+nNv0GPJ2oQaoHxOqF/tDOQ4dnugS1nLXvAi2/hr0TBGnkjvbWh5/ieEG 9YhSo5puFeohcKpPRHo76CNG+zfI+aZQcYYzLr35Ig0JHrBTdUoqPdGN191M/fMB0S5V ohboD35blsgWOv9bnRA+m8yD1J4QBJYtWIP1caIVv1ajJ72+WrpbXwX5C8djU9Pxitp7 X+63k56yBEwLsIpJEBMWLKsoiMScWy5rWBhr6nU+b8VI8YtphAM1v4sCjyOwPqLPucxQ fqvfDnJbWkXfLyfR+9V8hFqj8Bf/ZdfLxSlgPVxwuK6Fz8ix193NpAkRyBSmnAbh/0Ny ODVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="FnH7s/f1"; 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=fail (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 w3si13638820ybg.75.2021.03.14.14.30.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:30:19 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b="FnH7s/f1"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYJX-00010Y-6D for patch@linaro.org; Sun, 14 Mar 2021 17:30:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGw-000606-A5 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:38 -0400 Received: from mail-qv1-xf2c.google.com ([2607:f8b0:4864:20::f2c]:45928) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGu-0008BW-Rx for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:38 -0400 Received: by mail-qv1-xf2c.google.com with SMTP id t16so6881805qvr.12 for ; Sun, 14 Mar 2021 14:27: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 :mime-version:content-transfer-encoding; bh=yjdtKlRm3WuNdcNC9EUZQ7YJqY8dzEyQHbjSnP7J42Q=; b=FnH7s/f17efMqPJ9qLstuHjwS5rRDyjEDSMMLbZdAB0t9XllQLAf6lw1eThds0ZpIC KYnbt2B25RT/NM+Zdgst+0ulgVqhi8dIvWTg47eyKRyMeeZ1PpcDK0VOAyI4ttBZf29m DhGt+JUdFpesssIM2Rggp//3a1TlshpfqfxLOv0GATsi1co77fTayVxjY2wa/ZWcIEX6 ngsa8PwNBlKX7lhQQ2cs2aSyNLBgql/8ZzWSZvJYbzZbRN3cqqIcsL4FwZHLehWIwfpI MIdlVlKO7G8pURPWVXsaWESbsaLwcXdZk/1C8QCz55SOFDKE6krjeEhqVRIDXLAsE8JZ wTmA== 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=yjdtKlRm3WuNdcNC9EUZQ7YJqY8dzEyQHbjSnP7J42Q=; b=HYgXvzq7O9vq/4zL6Oo8zrFfRzJxyjfFnzTI+VRNv5HmlngF6Fifk3rTVsB8nc3gz2 N6csesut2V2qV4G51bMDImQ0AVKeNMHpUngPundKT59L3FDgwEcvE+yNBppzjFzTPJ8o Yu4EywfUbWeBZ+mB/VjAZjB4qpxZy5rOd7jWR0N7Ig0ahq2rMrgKQ8NpLZyL3ThocXd3 xTjcnBwr61EmCv0HBc/EW1GvzxZRrOURVe5yti/6rzDEuUnfzW11FgytNRYFFngPbYz5 d8pxtFZqR9BJ1DdAQCjTSL2xdZguVuArcl+7TBceN3F72exu3CGxppV7JHiHb5Xo/h6G KJyw== X-Gm-Message-State: AOAM533kjGQklGHhgLOB7mTth7y0EwayTdYcmrigHy6uPGbgoUEQR7rd BHBC7dET//WSRkrkr9rKd/aKkUexBt9OVz4o X-Received: by 2002:a05:6214:268c:: with SMTP id gm12mr7883189qvb.36.1615757255954; Sun, 14 Mar 2021 14:27:35 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 08/29] accel/tcg: Inline cpu_gen_init Date: Sun, 14 Mar 2021 15:27:03 -0600 Message-Id: <20210314212724.1917075-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f2c; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2c.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: r.bolshakov@yadro.com, j@getutm.app, =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" It consists of one function call and has only one caller. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) -- 2.25.1 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index b9057567f4..6d3184e7da 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -245,11 +245,6 @@ static void page_table_config_init(void) assert(v_l2_levels >= 0); } -static void cpu_gen_init(void) -{ - tcg_context_init(&tcg_init_ctx); -} - /* Encode VAL as a signed leb128 sequence at P. Return P incremented past the encoded value. */ static uint8_t *encode_sleb128(uint8_t *p, target_long val) @@ -1331,7 +1326,7 @@ void tcg_exec_init(unsigned long tb_size, int splitwx) bool ok; tcg_allowed = true; - cpu_gen_init(); + tcg_context_init(&tcg_init_ctx); page_init(); tb_htable_init(); From patchwork Sun Mar 14 21:27:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400136 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2925581jai; Sun, 14 Mar 2021 14:43:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPSaAhRA9kJ6mYqy+MAEJw+2GlJVV1blemlmu62FRlIRHMvDJZqiN2a6JKLrseKQAOhC9E X-Received: by 2002:a25:d012:: with SMTP id h18mr33004548ybg.329.1615758180840; Sun, 14 Mar 2021 14:43:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758180; cv=none; d=google.com; s=arc-20160816; b=Uoxlm4BLoAxvHijIqh+d1XPRFUE/WSjnrfhfGlN58FMq1/X4Eo2S+xlDK3cJmT78pZ FYoJUSuiDvRL8W0+68nU+U0XC4g12mbcvlMIRDF/yVq51HSCpIgpfolDsNg7wYF0qJOx tksA/Jm42TgaaIE5fFmk+oxLvbJGxBWGsV8pc8huIwf1HpuzBF+Kk4E9ppVVZZgUFJjf TNSw2uFa15SbygrlHfNU92nHtWHGo2LzSk35BZ3aw0bQDXR1BaRgxtPsn87R1HEyIbnk 72KleLS+uNsmdyVNHZ9sfMTSR5LdpmVo316xkmJcHEwhVQLgC8bjbifBrndha3r2x3zu mMFw== 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=1kd3z5f3F5IgA4tmLR2z9IlG5FeR5TPlOdPkW3kV5W4=; b=Tv+/SCL9LPw1v2dR/xSbZvBnwOGd9Z12cv+5rFexNrNgrng1Lv+zm+05AYwGnjvcdx BvWhl/wWcD2qVVukF3Gj0G9nXFhx6+YNIWI+HnG52CJg5zu9eIiYI+p6VjN4aZvtOS2T k4Bk0A9oC1wWuXNbWRSgKUH91EwXa8xrLGn3vcXEHnlt4JxBX8sF+zQAI1p42QdFpHqM Pz03vP93fjNbb6TMjrB+EKztxODDdaUSNH+r8u5hVqf3yuQZXtTZlxZfGhAscwqLyZHk 1AVf2AzEPmjmoVqysI+P6Spl7iitJ9HZqfQiyRicBAO2tnq8z5/P9YqyecDqSDTNL7lq JGIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LW4Fs40g; 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=fail (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 d4si12458013ybs.128.2021.03.14.14.43.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:43:00 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=LW4Fs40g; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYVo-0007Qk-7k for patch@linaro.org; Sun, 14 Mar 2021 17:43:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH0-00065v-Hr for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:44 -0400 Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]:36765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGw-0008CF-BM for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:41 -0400 Received: by mail-qt1-x833.google.com with SMTP id h7so1069313qtx.3 for ; Sun, 14 Mar 2021 14:27: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 :mime-version:content-transfer-encoding; bh=1kd3z5f3F5IgA4tmLR2z9IlG5FeR5TPlOdPkW3kV5W4=; b=LW4Fs40gSKa2qtimunawKiyp3WnStzn88geTpoqDbgbWbietlp/d0ZzNAo3Z8JE5ZR zSDY7t6daONgB7Hb/W7Wz7o1q0ua6LM+w4SRwjOSP7275sdTbFsWdPVcdlNw52095j46 B4HaMQ6pJkHwCyTmeVuNuNkl5z7WpCQaaH5evNSDoZi7x4NfwUBUzYRCcHcdpQvBXIgJ dWfnPZN+HIS1jWKA+fl+jM7dW5B2JiUOPMP/MAJHzt3wyfxlGPlMxJfOc9JIMZlZYn5e jGKT9x75Q1sFgwHwn47N+0lgyj/wiNfsbZ5ioVq4pCJIZOT70EvuDyGGJYCFiBybajB0 Ki8A== 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=1kd3z5f3F5IgA4tmLR2z9IlG5FeR5TPlOdPkW3kV5W4=; b=Vw2rCKKIlNkR57+C1yd6fESKodzjL9YIr6A1aMMa1b4T8FG9lStk7OetVd2XXQSbl6 7YVBhTPAfClx74LrTaS1vf3Rkc979mCLSdSSqbWzergTW6N8YIN2jYTOu7BtU+Vk7d/u ojqPJBiQcUKqYcb9wt4QlS8xe2PfyjkIGJvrRz+NmJA/euhFobN7ijLDxxkpAkl/A3lJ OxdT7hGCctlNm9vnV3k3R3a9s5v3IBU3QK9zuCEDbJ6kulWXFE4K+Jvc5X9BgoB5/wK8 VpiUpcws+p1yTjBB+GbvHXUL6ssPnGW9HY6C9ArHrEpc2AlGUQa7XjwIo8WFCaRB5qOn mfeQ== X-Gm-Message-State: AOAM531/p2sG5UP7Y5ib4DB3weIT/OjUOaCbEY8IrWjNvwa/63q/5dcx r1+1IfKr01mW+2KZn0RjhKOj0PrCZz5HcCnU X-Received: by 2002:ac8:4d59:: with SMTP id x25mr6250061qtv.82.1615757257206; Sun, 14 Mar 2021 14:27:37 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 09/29] accel/tcg: Move alloc_code_gen_buffer to tcg/region.c Date: Sun, 14 Mar 2021 15:27:04 -0600 Message-Id: <20210314212724.1917075-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::833; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x833.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Buffer management is integral to tcg. Do not leave the allocation to code outside of tcg/. This is code movement, with further cleanups to follow. Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 2 +- accel/tcg/translate-all.c | 414 +------------------------------------ tcg/region.c | 421 +++++++++++++++++++++++++++++++++++++- 3 files changed, 418 insertions(+), 419 deletions(-) -- 2.25.1 diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 0f0695e90d..7a435bf807 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -874,7 +874,7 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); -void tcg_region_init(void); +void tcg_region_init(size_t tb_size, int splitwx); void tb_destroy(TranslationBlock *tb); void tcg_region_reset_all(void); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 6d3184e7da..4071edda16 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -18,7 +18,6 @@ */ #include "qemu/osdep.h" -#include "qemu/units.h" #include "qemu-common.h" #define NO_CPU_IO_DEFS @@ -51,7 +50,6 @@ #include "exec/tb-hash.h" #include "exec/translate-all.h" #include "qemu/bitmap.h" -#include "qemu/error-report.h" #include "qemu/qemu-print.h" #include "qemu/timer.h" #include "qemu/main-loop.h" @@ -895,408 +893,6 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1, } } -/* Minimum size of the code gen buffer. This number is randomly chosen, - but not so small that we can't have a fair number of TB's live. */ -#define MIN_CODE_GEN_BUFFER_SIZE (1 * MiB) - -/* Maximum size of the code gen buffer we'd like to use. Unless otherwise - indicated, this is constrained by the range of direct branches on the - host cpu, as used by the TCG implementation of goto_tb. */ -#if defined(__x86_64__) -# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) -#elif defined(__sparc__) -# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) -#elif defined(__powerpc64__) -# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) -#elif defined(__powerpc__) -# define MAX_CODE_GEN_BUFFER_SIZE (32 * MiB) -#elif defined(__aarch64__) -# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) -#elif defined(__s390x__) - /* We have a +- 4GB range on the branches; leave some slop. */ -# define MAX_CODE_GEN_BUFFER_SIZE (3 * GiB) -#elif defined(__mips__) - /* We have a 256MB branch region, but leave room to make sure the - main executable is also within that region. */ -# define MAX_CODE_GEN_BUFFER_SIZE (128 * MiB) -#else -# define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) -#endif - -#if TCG_TARGET_REG_BITS == 32 -#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (32 * MiB) -#ifdef CONFIG_USER_ONLY -/* - * For user mode on smaller 32 bit systems we may run into trouble - * allocating big chunks of data in the right place. On these systems - * we utilise a static code generation buffer directly in the binary. - */ -#define USE_STATIC_CODE_GEN_BUFFER -#endif -#else /* TCG_TARGET_REG_BITS == 64 */ -#ifdef CONFIG_USER_ONLY -/* - * As user-mode emulation typically means running multiple instances - * of the translator don't go too nuts with our default code gen - * buffer lest we make things too hard for the OS. - */ -#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (128 * MiB) -#else -/* - * We expect most system emulation to run one or two guests per host. - * Users running large scale system emulation may want to tweak their - * runtime setup via the tb-size control on the command line. - */ -#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (1 * GiB) -#endif -#endif - -#define DEFAULT_CODE_GEN_BUFFER_SIZE \ - (DEFAULT_CODE_GEN_BUFFER_SIZE_1 < MAX_CODE_GEN_BUFFER_SIZE \ - ? DEFAULT_CODE_GEN_BUFFER_SIZE_1 : MAX_CODE_GEN_BUFFER_SIZE) - -static size_t size_code_gen_buffer(size_t tb_size) -{ - /* Size the buffer. */ - if (tb_size == 0) { - size_t phys_mem = qemu_get_host_physmem(); - if (phys_mem == 0) { - tb_size = DEFAULT_CODE_GEN_BUFFER_SIZE; - } else { - tb_size = MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, phys_mem / 8); - } - } - if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { - tb_size = MIN_CODE_GEN_BUFFER_SIZE; - } - if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { - tb_size = MAX_CODE_GEN_BUFFER_SIZE; - } - return tb_size; -} - -#ifdef __mips__ -/* In order to use J and JAL within the code_gen_buffer, we require - that the buffer not cross a 256MB boundary. */ -static inline bool cross_256mb(void *addr, size_t size) -{ - return ((uintptr_t)addr ^ ((uintptr_t)addr + size)) & ~0x0ffffffful; -} - -/* We weren't able to allocate a buffer without crossing that boundary, - so make do with the larger portion of the buffer that doesn't cross. - Returns the new base of the buffer, and adjusts code_gen_buffer_size. */ -static inline void *split_cross_256mb(void *buf1, size_t size1) -{ - void *buf2 = (void *)(((uintptr_t)buf1 + size1) & ~0x0ffffffful); - size_t size2 = buf1 + size1 - buf2; - - size1 = buf2 - buf1; - if (size1 < size2) { - size1 = size2; - buf1 = buf2; - } - - tcg_ctx->code_gen_buffer_size = size1; - return buf1; -} -#endif - -#ifdef USE_STATIC_CODE_GEN_BUFFER -static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] - __attribute__((aligned(CODE_GEN_ALIGN))); - -static bool alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) -{ - void *buf, *end; - size_t size; - - if (splitwx > 0) { - error_setg(errp, "jit split-wx not supported"); - return false; - } - - /* page-align the beginning and end of the buffer */ - buf = static_code_gen_buffer; - end = static_code_gen_buffer + sizeof(static_code_gen_buffer); - buf = QEMU_ALIGN_PTR_UP(buf, qemu_real_host_page_size); - end = QEMU_ALIGN_PTR_DOWN(end, qemu_real_host_page_size); - - size = end - buf; - - /* Honor a command-line option limiting the size of the buffer. */ - if (size > tb_size) { - size = QEMU_ALIGN_DOWN(tb_size, qemu_real_host_page_size); - } - tcg_ctx->code_gen_buffer_size = size; - -#ifdef __mips__ - if (cross_256mb(buf, size)) { - buf = split_cross_256mb(buf, size); - size = tcg_ctx->code_gen_buffer_size; - } -#endif - - if (qemu_mprotect_rwx(buf, size)) { - error_setg_errno(errp, errno, "mprotect of jit buffer"); - return false; - } - qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); - - tcg_ctx->code_gen_buffer = buf; - return true; -} -#elif defined(_WIN32) -static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) -{ - void *buf; - - if (splitwx > 0) { - error_setg(errp, "jit split-wx not supported"); - return false; - } - - 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 bool alloc_code_gen_buffer_anon(size_t size, int prot, - int flags, Error **errp) -{ - void *buf; - - buf = mmap(NULL, size, prot, flags, -1, 0); - if (buf == MAP_FAILED) { - 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)) { - /* - * Try again, with the original still mapped, to avoid re-acquiring - * the same 256mb crossing. - */ - size_t size2; - void *buf2 = mmap(NULL, size, prot, flags, -1, 0); - switch ((int)(buf2 != MAP_FAILED)) { - case 1: - if (!cross_256mb(buf2, size)) { - /* Success! Use the new buffer. */ - munmap(buf, size); - break; - } - /* Failure. Work with what we had. */ - munmap(buf2, size); - /* fallthru */ - default: - /* Split the original buffer. Free the smaller half. */ - buf2 = split_cross_256mb(buf, size); - size2 = tcg_ctx->code_gen_buffer_size; - if (buf == buf2) { - munmap(buf + size2, size - size2); - } else { - munmap(buf, size - size2); - } - size = size2; - break; - } - buf = buf2; - } -#endif - - /* Request large pages for the buffer. */ - qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); - - tcg_ctx->code_gen_buffer = buf; - return true; -} - -#ifndef CONFIG_TCG_INTERPRETER -#ifdef CONFIG_POSIX -#include "qemu/memfd.h" - -static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) -{ - 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) { - 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) { - goto fail_rx; - } -#endif - - close(fd); - tcg_ctx->code_gen_buffer = buf_rw; - tcg_ctx->code_gen_buffer_size = size; - tcg_splitwx_diff = buf_rx - buf_rw; - - /* Request large pages for the buffer and the splitwx. */ - 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 */ - -#ifdef CONFIG_DARWIN -#include - -extern kern_return_t mach_vm_remap(vm_map_t target_task, - mach_vm_address_t *target_address, - mach_vm_size_t size, - mach_vm_offset_t mask, - int flags, - vm_map_t src_task, - mach_vm_address_t src_address, - boolean_t copy, - vm_prot_t *cur_protection, - vm_prot_t *max_protection, - vm_inherit_t inheritance); - -static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp) -{ - kern_return_t ret; - mach_vm_address_t buf_rw, buf_rx; - vm_prot_t cur_prot, max_prot; - - /* Map the read-write portion via normal anon memory. */ - if (!alloc_code_gen_buffer_anon(size, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, errp)) { - return false; - } - - buf_rw = (mach_vm_address_t)tcg_ctx->code_gen_buffer; - buf_rx = 0; - ret = mach_vm_remap(mach_task_self(), - &buf_rx, - size, - 0, - VM_FLAGS_ANYWHERE, - mach_task_self(), - buf_rw, - false, - &cur_prot, - &max_prot, - VM_INHERIT_NONE); - if (ret != KERN_SUCCESS) { - /* TODO: Convert "ret" to a human readable error message. */ - error_setg(errp, "vm_remap for jit splitwx failed"); - munmap((void *)buf_rw, size); - return false; - } - - if (mprotect((void *)buf_rx, size, PROT_READ | PROT_EXEC) != 0) { - error_setg_errno(errp, errno, "mprotect for jit splitwx"); - munmap((void *)buf_rx, size); - munmap((void *)buf_rw, size); - return false; - } - - tcg_splitwx_diff = buf_rx - buf_rw; - return true; -} -#endif /* CONFIG_DARWIN */ -#endif /* CONFIG_TCG_INTERPRETER */ - -static bool alloc_code_gen_buffer_splitwx(size_t size, Error **errp) -{ -#ifndef CONFIG_TCG_INTERPRETER -# ifdef CONFIG_DARWIN - return alloc_code_gen_buffer_splitwx_vmremap(size, errp); -# endif -# ifdef CONFIG_POSIX - return alloc_code_gen_buffer_splitwx_memfd(size, errp); -# endif -#endif - error_setg(errp, "jit split-wx not supported"); - return false; -} - -static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) -{ - ERRP_GUARD(); - int prot, flags; - - if (splitwx) { - if (alloc_code_gen_buffer_splitwx(size, errp)) { - return true; - } - /* - * If splitwx force-on (1), fail; - * if splitwx default-on (-1), fall through to splitwx off. - */ - if (splitwx > 0) { - return false; - } - error_free_or_abort(errp); - } - - prot = PROT_READ | PROT_WRITE | PROT_EXEC; - flags = MAP_PRIVATE | MAP_ANONYMOUS; -#ifdef CONFIG_TCG_INTERPRETER - /* The tcg interpreter does not need execute permission. */ - prot = PROT_READ | PROT_WRITE; -#elif defined(CONFIG_DARWIN) - /* Applicable to both iOS and macOS (Apple Silicon). */ - if (!splitwx) { - flags |= MAP_JIT; - } -#endif - - return alloc_code_gen_buffer_anon(size, prot, flags, errp); -} -#endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */ - static bool tb_cmp(const void *ap, const void *bp) { const TranslationBlock *a = ap; @@ -1323,19 +919,11 @@ static void tb_htable_init(void) size. */ void tcg_exec_init(unsigned long tb_size, int splitwx) { - bool ok; - tcg_allowed = true; tcg_context_init(&tcg_init_ctx); page_init(); tb_htable_init(); - - ok = alloc_code_gen_buffer(size_code_gen_buffer(tb_size), - splitwx, &error_fatal); - assert(ok); - - /* TODO: allocating regions is hand-in-glove with code_gen_buffer. */ - tcg_region_init(); + tcg_region_init(tb_size, splitwx); #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and diff --git a/tcg/region.c b/tcg/region.c index af45a0174e..8d88144a22 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -23,6 +23,8 @@ */ #include "qemu/osdep.h" +#include "qemu/units.h" +#include "qapi/error.h" #include "exec/exec-all.h" #include "tcg/tcg.h" #if !defined(CONFIG_USER_ONLY) @@ -406,6 +408,408 @@ static size_t tcg_n_regions(void) } #endif +/* Minimum size of the code gen buffer. This number is randomly chosen, + but not so small that we can't have a fair number of TB's live. */ +#define MIN_CODE_GEN_BUFFER_SIZE (1 * MiB) + +/* Maximum size of the code gen buffer we'd like to use. Unless otherwise + indicated, this is constrained by the range of direct branches on the + host cpu, as used by the TCG implementation of goto_tb. */ +#if defined(__x86_64__) +# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) +#elif defined(__sparc__) +# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) +#elif defined(__powerpc64__) +# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) +#elif defined(__powerpc__) +# define MAX_CODE_GEN_BUFFER_SIZE (32 * MiB) +#elif defined(__aarch64__) +# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) +#elif defined(__s390x__) + /* We have a +- 4GB range on the branches; leave some slop. */ +# define MAX_CODE_GEN_BUFFER_SIZE (3 * GiB) +#elif defined(__mips__) + /* We have a 256MB branch region, but leave room to make sure the + main executable is also within that region. */ +# define MAX_CODE_GEN_BUFFER_SIZE (128 * MiB) +#else +# define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) +#endif + +#if TCG_TARGET_REG_BITS == 32 +#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (32 * MiB) +#ifdef CONFIG_USER_ONLY +/* + * For user mode on smaller 32 bit systems we may run into trouble + * allocating big chunks of data in the right place. On these systems + * we utilise a static code generation buffer directly in the binary. + */ +#define USE_STATIC_CODE_GEN_BUFFER +#endif +#else /* TCG_TARGET_REG_BITS == 64 */ +#ifdef CONFIG_USER_ONLY +/* + * As user-mode emulation typically means running multiple instances + * of the translator don't go too nuts with our default code gen + * buffer lest we make things too hard for the OS. + */ +#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (128 * MiB) +#else +/* + * We expect most system emulation to run one or two guests per host. + * Users running large scale system emulation may want to tweak their + * runtime setup via the tb-size control on the command line. + */ +#define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (1 * GiB) +#endif +#endif + +#define DEFAULT_CODE_GEN_BUFFER_SIZE \ + (DEFAULT_CODE_GEN_BUFFER_SIZE_1 < MAX_CODE_GEN_BUFFER_SIZE \ + ? DEFAULT_CODE_GEN_BUFFER_SIZE_1 : MAX_CODE_GEN_BUFFER_SIZE) + +static size_t size_code_gen_buffer(size_t tb_size) +{ + /* Size the buffer. */ + if (tb_size == 0) { + size_t phys_mem = qemu_get_host_physmem(); + if (phys_mem == 0) { + tb_size = DEFAULT_CODE_GEN_BUFFER_SIZE; + } else { + tb_size = MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, phys_mem / 8); + } + } + if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { + tb_size = MIN_CODE_GEN_BUFFER_SIZE; + } + if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { + tb_size = MAX_CODE_GEN_BUFFER_SIZE; + } + return tb_size; +} + +#ifdef __mips__ +/* In order to use J and JAL within the code_gen_buffer, we require + that the buffer not cross a 256MB boundary. */ +static inline bool cross_256mb(void *addr, size_t size) +{ + return ((uintptr_t)addr ^ ((uintptr_t)addr + size)) & ~0x0ffffffful; +} + +/* We weren't able to allocate a buffer without crossing that boundary, + so make do with the larger portion of the buffer that doesn't cross. + Returns the new base of the buffer, and adjusts code_gen_buffer_size. */ +static inline void *split_cross_256mb(void *buf1, size_t size1) +{ + void *buf2 = (void *)(((uintptr_t)buf1 + size1) & ~0x0ffffffful); + size_t size2 = buf1 + size1 - buf2; + + size1 = buf2 - buf1; + if (size1 < size2) { + size1 = size2; + buf1 = buf2; + } + + tcg_ctx->code_gen_buffer_size = size1; + return buf1; +} +#endif + +#ifdef USE_STATIC_CODE_GEN_BUFFER +static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] + __attribute__((aligned(CODE_GEN_ALIGN))); + +static bool alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) +{ + void *buf, *end; + size_t size; + + if (splitwx > 0) { + error_setg(errp, "jit split-wx not supported"); + return false; + } + + /* page-align the beginning and end of the buffer */ + buf = static_code_gen_buffer; + end = static_code_gen_buffer + sizeof(static_code_gen_buffer); + buf = QEMU_ALIGN_PTR_UP(buf, qemu_real_host_page_size); + end = QEMU_ALIGN_PTR_DOWN(end, qemu_real_host_page_size); + + size = end - buf; + + /* Honor a command-line option limiting the size of the buffer. */ + if (size > tb_size) { + size = QEMU_ALIGN_DOWN(tb_size, qemu_real_host_page_size); + } + tcg_ctx->code_gen_buffer_size = size; + +#ifdef __mips__ + if (cross_256mb(buf, size)) { + buf = split_cross_256mb(buf, size); + size = tcg_ctx->code_gen_buffer_size; + } +#endif + + if (qemu_mprotect_rwx(buf, size)) { + error_setg_errno(errp, errno, "mprotect of jit buffer"); + return false; + } + qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); + + tcg_ctx->code_gen_buffer = buf; + return true; +} +#elif defined(_WIN32) +static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) +{ + void *buf; + + if (splitwx > 0) { + error_setg(errp, "jit split-wx not supported"); + return false; + } + + 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 bool alloc_code_gen_buffer_anon(size_t size, int prot, + int flags, Error **errp) +{ + void *buf; + + buf = mmap(NULL, size, prot, flags, -1, 0); + if (buf == MAP_FAILED) { + 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)) { + /* + * Try again, with the original still mapped, to avoid re-acquiring + * the same 256mb crossing. + */ + size_t size2; + void *buf2 = mmap(NULL, size, prot, flags, -1, 0); + switch ((int)(buf2 != MAP_FAILED)) { + case 1: + if (!cross_256mb(buf2, size)) { + /* Success! Use the new buffer. */ + munmap(buf, size); + break; + } + /* Failure. Work with what we had. */ + munmap(buf2, size); + /* fallthru */ + default: + /* Split the original buffer. Free the smaller half. */ + buf2 = split_cross_256mb(buf, size); + size2 = tcg_ctx->code_gen_buffer_size; + if (buf == buf2) { + munmap(buf + size2, size - size2); + } else { + munmap(buf, size - size2); + } + size = size2; + break; + } + buf = buf2; + } +#endif + + /* Request large pages for the buffer. */ + qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); + + tcg_ctx->code_gen_buffer = buf; + return true; +} + +#ifndef CONFIG_TCG_INTERPRETER +#ifdef CONFIG_POSIX +#include "qemu/memfd.h" + +static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) +{ + 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) { + 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) { + goto fail_rx; + } +#endif + + close(fd); + tcg_ctx->code_gen_buffer = buf_rw; + tcg_ctx->code_gen_buffer_size = size; + tcg_splitwx_diff = buf_rx - buf_rw; + + /* Request large pages for the buffer and the splitwx. */ + 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 */ + +#ifdef CONFIG_DARWIN +#include + +extern kern_return_t mach_vm_remap(vm_map_t target_task, + mach_vm_address_t *target_address, + mach_vm_size_t size, + mach_vm_offset_t mask, + int flags, + vm_map_t src_task, + mach_vm_address_t src_address, + boolean_t copy, + vm_prot_t *cur_protection, + vm_prot_t *max_protection, + vm_inherit_t inheritance); + +static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp) +{ + kern_return_t ret; + mach_vm_address_t buf_rw, buf_rx; + vm_prot_t cur_prot, max_prot; + + /* Map the read-write portion via normal anon memory. */ + if (!alloc_code_gen_buffer_anon(size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, errp)) { + return false; + } + + buf_rw = (mach_vm_address_t)tcg_ctx->code_gen_buffer; + buf_rx = 0; + ret = mach_vm_remap(mach_task_self(), + &buf_rx, + size, + 0, + VM_FLAGS_ANYWHERE, + mach_task_self(), + buf_rw, + false, + &cur_prot, + &max_prot, + VM_INHERIT_NONE); + if (ret != KERN_SUCCESS) { + /* TODO: Convert "ret" to a human readable error message. */ + error_setg(errp, "vm_remap for jit splitwx failed"); + munmap((void *)buf_rw, size); + return false; + } + + if (mprotect((void *)buf_rx, size, PROT_READ | PROT_EXEC) != 0) { + error_setg_errno(errp, errno, "mprotect for jit splitwx"); + munmap((void *)buf_rx, size); + munmap((void *)buf_rw, size); + return false; + } + + tcg_splitwx_diff = buf_rx - buf_rw; + return true; +} +#endif /* CONFIG_DARWIN */ +#endif /* CONFIG_TCG_INTERPRETER */ + +static bool alloc_code_gen_buffer_splitwx(size_t size, Error **errp) +{ +#ifndef CONFIG_TCG_INTERPRETER +# ifdef CONFIG_DARWIN + return alloc_code_gen_buffer_splitwx_vmremap(size, errp); +# endif +# ifdef CONFIG_POSIX + return alloc_code_gen_buffer_splitwx_memfd(size, errp); +# endif +#endif + error_setg(errp, "jit split-wx not supported"); + return false; +} + +static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) +{ + ERRP_GUARD(); + int prot, flags; + + if (splitwx) { + if (alloc_code_gen_buffer_splitwx(size, errp)) { + return true; + } + /* + * If splitwx force-on (1), fail; + * if splitwx default-on (-1), fall through to splitwx off. + */ + if (splitwx > 0) { + return false; + } + error_free_or_abort(errp); + } + + prot = PROT_READ | PROT_WRITE | PROT_EXEC; + flags = MAP_PRIVATE | MAP_ANONYMOUS; +#ifdef CONFIG_TCG_INTERPRETER + /* The tcg interpreter does not need execute permission. */ + prot = PROT_READ | PROT_WRITE; +#elif defined(CONFIG_DARWIN) + /* Applicable to both iOS and macOS (Apple Silicon). */ + if (!splitwx) { + flags |= MAP_JIT; + } +#endif + + return alloc_code_gen_buffer_anon(size, prot, flags, errp); +} +#endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */ + /* * Initializes region partitioning. * @@ -434,17 +838,24 @@ static size_t tcg_n_regions(void) * in practice. Multi-threaded guests share most if not all of their translated * code, which makes parallel code generation less appealing than in softmmu. */ -void tcg_region_init(void) +void tcg_region_init(size_t tb_size, int splitwx) { - void *buf = tcg_init_ctx.code_gen_buffer; - void *aligned; - size_t size = tcg_init_ctx.code_gen_buffer_size; - size_t page_size = qemu_real_host_page_size; + void *buf, *aligned; + size_t size; + size_t page_size; size_t region_size; size_t n_regions; size_t i; uintptr_t splitwx_diff; + bool ok; + ok = alloc_code_gen_buffer(size_code_gen_buffer(tb_size), + splitwx, &error_fatal); + assert(ok); + + buf = tcg_init_ctx.code_gen_buffer; + size = tcg_init_ctx.code_gen_buffer_size; + page_size = qemu_real_host_page_size; n_regions = tcg_n_regions(); /* The first region will be 'aligned - buf' bytes larger than the others */ From patchwork Sun Mar 14 21:27:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400137 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2926490jai; Sun, 14 Mar 2021 14:45:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx24rKvIIWblre8ZSC3KOjOYZuRXxW3cRjrXa8HYB4xgH3ymi5FiJpU4PyXCOY6o6QsNjH X-Received: by 2002:a25:6e02:: with SMTP id j2mr32259667ybc.247.1615758335760; Sun, 14 Mar 2021 14:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758335; cv=none; d=google.com; s=arc-20160816; b=PVdCcDqdleYGEmh3HmAQxBboZYkTo8LhVu6TZ3owGXLGL7iO6ZUOAZmzhz+aQ+Gpdh UzTHtVpUsDnc9LxC/TMCPIFiiMqjGQs6PhtVvujayWjjYGOTdWQDqJtSX6/CNNd9ELBo ksKIVAsoDTZasrsXq05j9Aae1qA/KOCjVqxkGCFBziqWze0mMw0S5biHaWVd8e/Ftina sLC28Y2O9ycZPPtw2Oh+c93Q0z0jaDgzoJ7a07KHNW2h1APVf9DudBnxYYpX76uje5Oq EtaKAk7BBmPEhISDKSC9E2Bpw8IG3z6+Ts7Fs8i4YrG5OkdF5V5n3XH2+60tMCXOyNvc TIlw== 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=M+GW/FjdFE0LjCNjl+PKpujGwHht+vUuynWRRTNqZ50=; b=xc4w2dqFRp+h9DIsNV2Fg8yUxDVSCBKGALbgwbw0Lrk+Ml4cHn8Si+tquryPpCdC6w JW7Iv4w41jwlnVCHQC647khTdNyaQii6feE+6rVkrUPtVjSJwea6x55I/GnKNtTzUVMy IFtmLVd0ulsknXl1tLH3F0Wrg02iEjBrKl5pk9ooQl1qNJGqcUdKl0sR/IhqHYK9CPI/ OGo7VycOfXfpfuWD6WHin29IsRxCVr7OmUJQchMPDkRfJsxdAAxAzx1HLkyedjRjRg6n sJ0NG+ZTuWcpCcjZgUMI2731wIdLrRohBelRO7bS9eKApJUl1eGnayALIDu4y7GjJnf3 Kz7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=W9EWIAYY; 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=fail (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 x9si13207855ybh.41.2021.03.14.14.45.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:45:35 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=W9EWIAYY; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYYJ-00010j-5g for patch@linaro.org; Sun, 14 Mar 2021 17:45:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH1-000667-Ts for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:44 -0400 Received: from mail-qv1-xf36.google.com ([2607:f8b0:4864:20::f36]:40914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGx-0008CO-95 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:42 -0400 Received: by mail-qv1-xf36.google.com with SMTP id d10so514675qve.7 for ; Sun, 14 Mar 2021 14:27:38 -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 :mime-version:content-transfer-encoding; bh=M+GW/FjdFE0LjCNjl+PKpujGwHht+vUuynWRRTNqZ50=; b=W9EWIAYYbiO2Q6ZUxeVr5YPtTr1LDApzVKQWZ2GzhKufQLanv30gPAhtF6PeHWozgu X68zP/nd66KSGUoe0/S8TGAzbi2XUgaVxh0deeARPH4dDlPfBdciinj5EIzF935ZUNP0 r8pWZ25Ju6BVc69QEmrfvmD79Kv4LiMH39DeXhnifp8QAcQkN0uYKbRJ04viTpIZ60/a DIcg4VR3fS2FjXk4EbDzC/GHEG1m604hNu9t5Xgron0XfBivW0D9lpW+lpqU7wmRoaii SYSZfr+ke1/TOUe6dm+fKTiVddSFsAwfBeBMkWF8XhVfsmUIHrju9SW6nv0Rvgiv0gjW mU2w== 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=M+GW/FjdFE0LjCNjl+PKpujGwHht+vUuynWRRTNqZ50=; b=HEk84H0FpkA0yYV8JUeYJ2RIMpBP0Zc406h8y8eVp/zWaZWB9TTJGZqpuci3D4+jin G1PBPinBScep6uZ+jTArc51NmTweu/CiyA86S8m5UhAA6PqeWHGZSqXCzZn0AcjzdKU/ dx9MrDDQ0fnite42NcBUOGVsBiNpsAyMjYqPTK26zZn+OlxwS9kFHeDZwHyTRccXpRt9 y8SrM+Z/c2vAWgfXFva6GJWM0Ur0xDVfKVRtpDulEWHh1T0btPkYtR8TSbwA1ZbyFpeV V2ROX2jsbHlfm0Cj/tTOhjOcbM2dPr/Z0ac4R16wItsb8Agn2cbOKGLcK3AEbdfwSWMs e49w== X-Gm-Message-State: AOAM532Sc+3e2TV+ICBK4eRAeYes2qCRM6rwWW7BQNwDBx6DwagYAoax GmLdtF5vJkzthDamUf8TjJQ75o7oF/gqv3V7 X-Received: by 2002:ad4:4e53:: with SMTP id eb19mr8088279qvb.8.1615757258393; Sun, 14 Mar 2021 14:27:38 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 10/29] accel/tcg: Rename tcg_init to tcg_init_machine Date: Sun, 14 Mar 2021 15:27:05 -0600 Message-Id: <20210314212724.1917075-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f36; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf36.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: r.bolshakov@yadro.com, j@getutm.app, =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We shortly want to use tcg_init for something else. Since the hook is called init_machine, match that. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/tcg-all.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index f132033999..30d81ff7f5 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -105,7 +105,7 @@ static void tcg_accel_instance_init(Object *obj) bool mttcg_enabled; -static int tcg_init(MachineState *ms) +static int tcg_init_machine(MachineState *ms) { TCGState *s = TCG_STATE(current_accel()); @@ -189,7 +189,7 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); ac->name = "tcg"; - ac->init_machine = tcg_init; + ac->init_machine = tcg_init_machine; ac->allowed = &tcg_allowed; object_class_property_add_str(oc, "thread", From patchwork Sun Mar 14 21:27:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400138 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2926834jai; Sun, 14 Mar 2021 14:46:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt0qi+kQb87lkBkokXZAT5dom4F/Zpdn/i4iPfifOV/jJu8JhovAR/uqebVeS6h1mr4y4i X-Received: by 2002:a25:d345:: with SMTP id e66mr32119565ybf.442.1615758408040; Sun, 14 Mar 2021 14:46:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758408; cv=none; d=google.com; s=arc-20160816; b=RRMftKBZiO48OQh6zi6+HL5GgX0Sl9QZSlkCKRoGWvwAonA2OOrKGKh3Se3sT0PQCg ahclynE+RwSyS0SZCyon3MoSfMUWzVAcASgUSq9J7aBzZF3TRnNpTi6vJDJKxXZ5HNOr vLjEy+0Lhw2dR55nkzoQi2ALaakV+S5lfv5h1FZKddsAhFcMmiLV+GKELCthXgdOi7hy aULS/9Q3IEOv5Ho4FjKRHUj1NJc5m6gfjP5hGQrt5ozWhYpU0TOjNBn4uKAs4pCt9j8C 5/GfFaf/iLC83c1K/dB3Qj52UUxfF6pGqhGfLnvcSc3vwcoPDgRpGYmKZikyGB6oD7hp 0okw== 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=1JDFX+MuUZit7885JaLDSIbe6sMdYH/iLicvWinCUzk=; b=AExeuftN4OPma0luS+wJVoAcnA32nhP77mS22OoY1JnmhA6lG9l+6geo6X8X5RmNVI 32pLsYQ5MOiCVy1QjEdAj3HdDcJFOT3GkAy0sWzJOhMEhWIgS/VuD6LinPpEwIN6uPA6 k1jNLvWKCGLljIGhHNG/OCxR5VoEML0sbpLu4ctFBds7Joy0KLoWWrG9fP+AgklQn78X FyLZxGGMRWbghEZ1KHwzBXEQa30oEujUpv1pasMEvCgUwGgwXVqkKaRbXatdM3TZfdtb urHGM7ChUPCbYOJeDX4NqqAOv8EzmB1siFNerj7UYiPgE4ytR4iEVHLpiO2Lgx8xK4cL eoUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jlluq46n; 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=fail (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 q11si13884841ybm.454.2021.03.14.14.46.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:46:48 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=jlluq46n; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYZT-0002q1-H5 for patch@linaro.org; Sun, 14 Mar 2021 17:46:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54664) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH2-00066Q-BC for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:46 -0400 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]:39700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGy-0008DM-HR for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:43 -0400 Received: by mail-qv1-xf34.google.com with SMTP id q9so1417698qvm.6 for ; Sun, 14 Mar 2021 14:27:40 -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 :mime-version:content-transfer-encoding; bh=1JDFX+MuUZit7885JaLDSIbe6sMdYH/iLicvWinCUzk=; b=jlluq46nphnEE4tCByl+GaP/Oz4/a37Bv8LMkZuJX1JaNzqXxz2vsi03im2SOBAnAL C+I0+HKs3jPkQb737jge7SlQ8AvIlVjyYrx7CmSSiz3v2uMJqC/s9kN6N/S0Thoys9+m Sizytk4HV5cjwCMJY8ZLf0LzqDeqYKegKbqm6cn0ezh0mY8JMdZDODgthP61V1QoszI4 8Tse0mvAlAzKaRYiQz1PiTzmp1hjLyvGDechEgdQuM6ME5zUut1TejgHSOYXaF+G9GCW +sMbwkBHJJX6C1ZKIXKWpyEDJCEHtZvdVpUYWmPNsEynSWb/gezRF4HIhFnE9Sa91yNr 3/aA== 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=1JDFX+MuUZit7885JaLDSIbe6sMdYH/iLicvWinCUzk=; b=DoFWtcmbYWBT/1vCs4ZLJKHzbVTzPugeuZn2SzY8q24osLZpV8WxkScYxP2J/87m6+ NoEkyBvEkXxEUqlBfc8pPa6gZLJm0pH2PS4sgkmT5Kh3fjGN/UXy9V5vCUdSLFI8LxTt Vs7OKvPSsiPUHcIZwQ2rrIQ26TJT4BC0vKjSCe1jOCOjUVU394sE++61HcIQYfMatXbc vJB7wrAl/It4cqEUd1ABXi0faUrABjt5tgKCBPMz4QdBjjyY85LBg7TksnEYC+bVxplC rkQdCIKxBE6ULUO9VOM8q1CDhILyy2Lx63RDsCFnveAcFb20PrR3p7K2qFIX0U5/i1IK afVA== X-Gm-Message-State: AOAM532DOAZaNUfZstEPIcaxyMdPKjuPohyDEIigpJFi8Mhj0ygyeoAW HyT4Sw1l4B5kpet33rTEijMW4yInZ8QExixd X-Received: by 2002:a05:6214:80d:: with SMTP id df13mr21956022qvb.55.1615757259733; Sun, 14 Mar 2021 14:27:39 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 11/29] tcg: Create tcg_init Date: Sun, 14 Mar 2021 15:27:06 -0600 Message-Id: <20210314212724.1917075-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f34; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf34.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Perform both tcg_context_init and tcg_region_init. Do not leave this split to the caller. Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 3 +-- tcg/internal.h | 1 + accel/tcg/translate-all.c | 3 +-- tcg/tcg.c | 9 ++++++++- 4 files changed, 11 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 7a435bf807..3ad77ec34d 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -874,7 +874,6 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); -void tcg_region_init(size_t tb_size, int splitwx); void tb_destroy(TranslationBlock *tb); void tcg_region_reset_all(void); @@ -907,7 +906,7 @@ static inline void *tcg_malloc(int size) } } -void tcg_context_init(TCGContext *s); +void tcg_init(size_t tb_size, int splitwx); void tcg_register_thread(void); void tcg_prologue_init(TCGContext *s); void tcg_func_start(TCGContext *s); diff --git a/tcg/internal.h b/tcg/internal.h index b1dda343c2..f13c564d9b 100644 --- a/tcg/internal.h +++ b/tcg/internal.h @@ -30,6 +30,7 @@ extern TCGContext **tcg_ctxs; extern unsigned int n_tcg_ctxs; +void tcg_region_init(size_t tb_size, int splitwx); bool tcg_region_alloc(TCGContext *s); void tcg_region_initial_alloc(TCGContext *s); void tcg_region_prologue_set(TCGContext *s); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 4071edda16..050b4bff46 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -920,10 +920,9 @@ static void tb_htable_init(void) void tcg_exec_init(unsigned long tb_size, int splitwx) { tcg_allowed = true; - tcg_context_init(&tcg_init_ctx); page_init(); tb_htable_init(); - tcg_region_init(tb_size, splitwx); + tcg_init(tb_size, splitwx); #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and diff --git a/tcg/tcg.c b/tcg/tcg.c index 10a571d41c..65a63bda8a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -576,8 +576,9 @@ static void process_op_defs(TCGContext *s); static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type, TCGReg reg, const char *name); -void tcg_context_init(TCGContext *s) +static void tcg_context_init(void) { + TCGContext *s = &tcg_init_ctx; int op, total_args, n, i; TCGOpDef *def; TCGArgConstraint *args_ct; @@ -654,6 +655,12 @@ void tcg_context_init(TCGContext *s) cpu_env = temp_tcgv_ptr(ts); } +void tcg_init(size_t tb_size, int splitwx) +{ + tcg_context_init(); + tcg_region_init(tb_size, splitwx); +} + /* * Allocate TBs right before their corresponding translated code, making * sure that TBs and code are on different cache lines. From patchwork Sun Mar 14 21:27:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400124 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2921776jai; Sun, 14 Mar 2021 14:32:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqrCZYkJ+qa2xgM9jR2YyXSOYBkhYFl7jgpb0hg6vu/u04i5bTCnJC/m9JWmR67qyM/vzy X-Received: by 2002:a6b:1415:: with SMTP id 21mr5544952iou.147.1615757535652; Sun, 14 Mar 2021 14:32:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757535; cv=none; d=google.com; s=arc-20160816; b=olRwVQexqPEicj8A7ax2NJHu2QDcOfeV8Nd3nhFJYi9D0bIVyGuGxT6ld2MW6+ToU3 uK2gYcW5TgXIgqtRg1+ukVseMOKB+6qRL7b9g4fPtuPxA6Z0MeYaRoNMB5NDV7Ej8w+n x51DMGNSMYABPXB99y1MuOVfbBAP+VJYRE/Q7FRmd8Ok4EZnJm/37+uwSTo/u+W2Thde Pc2W/56qf17dOaqHg+6lZ87PkScjt0VZ0xg8O6IA5qtyiwJ9QL9qIrjWifaIoj70blM9 Yw/g0FZpWzminaG2Ewu+ZaXoZwtZI5eQR1yLXn+cVpw2SGjs9IOlFiLtU4hnSL4sNFSk LKwA== 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=6fDUV0XaBa+zUybCathQxLsZ1yQJyGr4UGBPgHHGORw=; b=pqALwbs1GeqYdQTL5sOliS1gxzL1LDeCElqV1QkP6l8RK0Ttl4XO1aCThbBz3bYda/ 1uhLY+ynhp4yrlGokX8ptsprJPyJVY4su6yja23i/jsjj9Lxp3FMG6VeEn3pLztlfV7Q ouvAhliLZ96ZOef/WNLjXJyUmShHAMjmrJQ6HNeThuRs4dJceZGZf/XYU9fT6HV7cNyP m1WfW1ghl/nSHLA+lNuXYEXnpxJb8CuChFhlBIKPb+8lYqUM4898EGxqetyPlcjSfucI t3dRY/edKVFFRhQ9sohSzN8LHNRcAKWQ7qy2QNki+KTXv89GPyF7ZS24ddscAMdQLz3b iJLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QIvcmaKp; 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=fail (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 x21si9194944jaq.64.2021.03.14.14.32.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:32:15 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=QIvcmaKp; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYLO-00018V-Tx for patch@linaro.org; Sun, 14 Mar 2021 17:32:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH4-00066z-3l for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:46 -0400 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]:42813) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH0-0008Dj-65 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:45 -0400 Received: by mail-qt1-x832.google.com with SMTP id l13so7875378qtu.9 for ; Sun, 14 Mar 2021 14:27:41 -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 :mime-version:content-transfer-encoding; bh=6fDUV0XaBa+zUybCathQxLsZ1yQJyGr4UGBPgHHGORw=; b=QIvcmaKpZKQ/ZRHiFP55X33t6SYtUlBY8skpo5ap4G+IZrC3boWK/Yk2ySPoCeW0ew QhXgqbOTDFzSriE1cOvHzF0g6/2dZ/Rdpx95/I8Fj+b+hIHmQbRVykn//eXa9AwJd2a1 uHuT/5vTe/uJgwO2rNTowgcyTap05z4CcFNZErTQ8LD8ZYdaVjLKMRS9EQw5jeiVhn5n +dpwCA2g4vkl3pTfBgpY+4wSIpd0D/gJ+LgeZzZKcpwPmUozW0SszLBBiGCy8OfNUiFs CbVLTSo4sek6QGD5YKC2vWTqxgyw2LPtoWXwr5UuGUYtuJZ/MO6Jv3TUeFBA+U+apYhN CDrA== 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=6fDUV0XaBa+zUybCathQxLsZ1yQJyGr4UGBPgHHGORw=; b=klZlC/DmntZDrCrTPhDzS9UeMnhT9MdHayZvro7ziU12pCp9nHu18Lndt2iPDSGavy +atOXhmLb8IUVj+2Dq5VF8X0S6aYZs4v4jkGASvS025nUNRpcgQqctdjHWn3chXK3im0 TIh3mljMTjoYnUs7rmel7YSUlwrN0nDdnviWGulV9zDZ3JBOmzEnn2E41nO6EtiNkWC/ 9dAQBBwQnkuH0bs0brpCuf4yMoF0FN1KszI+h1a7f1L/vgqREOL0x4DNQ3Hpcs9DeE4l loOHlg6V2jQtE92XQ8wi6G2oCiHIXYzPcYfH2hWNsiVESTf3IJ4v7AflqRRmmNWP+DR0 3O+A== X-Gm-Message-State: AOAM533DTaGd+zpsfEGb36zqz3DQ/eBpXrMFcaKMzb2OoJtaP1UOjPJC YKYAb/TLVpfnwj6mudE56pESY8vt7XCpWENc X-Received: by 2002:a05:622a:1115:: with SMTP id e21mr282033qty.192.1615757260787; Sun, 14 Mar 2021 14:27:40 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 12/29] accel/tcg: Merge tcg_exec_init into tcg_init_machine Date: Sun, 14 Mar 2021 15:27:07 -0600 Message-Id: <20210314212724.1917075-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::832; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x832.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There is only one caller, and shortly we will need access to the MachineState, which tcg_init_machine already has. Signed-off-by: Richard Henderson --- accel/tcg/internal.h | 2 ++ include/sysemu/tcg.h | 2 -- accel/tcg/tcg-all.c | 14 +++++++++++++- accel/tcg/translate-all.c | 21 ++------------------- 4 files changed, 17 insertions(+), 22 deletions(-) -- 2.25.1 diff --git a/accel/tcg/internal.h b/accel/tcg/internal.h index e9c145e0fb..881bc1ede0 100644 --- a/accel/tcg/internal.h +++ b/accel/tcg/internal.h @@ -16,5 +16,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, int cflags); void QEMU_NORETURN cpu_io_recompile(CPUState *cpu, uintptr_t retaddr); +void page_init(void); +void tb_htable_init(void); #endif /* ACCEL_TCG_INTERNAL_H */ diff --git a/include/sysemu/tcg.h b/include/sysemu/tcg.h index 00349fb18a..53352450ff 100644 --- a/include/sysemu/tcg.h +++ b/include/sysemu/tcg.h @@ -8,8 +8,6 @@ #ifndef SYSEMU_TCG_H #define SYSEMU_TCG_H -void tcg_exec_init(unsigned long tb_size, int splitwx); - #ifdef CONFIG_TCG extern bool tcg_allowed; #define tcg_enabled() (tcg_allowed) diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index 30d81ff7f5..0e83acbfe5 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -32,6 +32,7 @@ #include "qemu/error-report.h" #include "qemu/accel.h" #include "qapi/qapi-builtin-visit.h" +#include "internal.h" struct TCGState { AccelState parent_obj; @@ -109,8 +110,19 @@ static int tcg_init_machine(MachineState *ms) { TCGState *s = TCG_STATE(current_accel()); - tcg_exec_init(s->tb_size * 1024 * 1024, s->splitwx_enabled); + tcg_allowed = true; mttcg_enabled = s->mttcg_enabled; + + page_init(); + tb_htable_init(); + tcg_init(s->tb_size * 1024 * 1024, s->splitwx_enabled); + +#if defined(CONFIG_SOFTMMU) + /* There's no guest base to take into account, so go ahead and + initialize the prologue now. */ + tcg_prologue_init(tcg_ctx); +#endif + return 0; } diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 050b4bff46..40aeecf611 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -408,7 +408,7 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) return false; } -static void page_init(void) +void page_init(void) { page_size_init(); page_table_config_init(); @@ -907,30 +907,13 @@ static bool tb_cmp(const void *ap, const void *bp) a->page_addr[1] == b->page_addr[1]; } -static void tb_htable_init(void) +void tb_htable_init(void) { unsigned int mode = QHT_MODE_AUTO_RESIZE; qht_init(&tb_ctx.htable, tb_cmp, CODE_GEN_HTABLE_SIZE, mode); } -/* Must be called before using the QEMU cpus. 'tb_size' is the size - (in bytes) allocated to the translation buffer. Zero means default - size. */ -void tcg_exec_init(unsigned long tb_size, int splitwx) -{ - tcg_allowed = true; - page_init(); - tb_htable_init(); - tcg_init(tb_size, splitwx); - -#if defined(CONFIG_SOFTMMU) - /* There's no guest base to take into account, so go ahead and - initialize the prologue now. */ - tcg_prologue_init(tcg_ctx); -#endif -} - /* call with @p->lock held */ static inline void invalidate_page_bitmap(PageDesc *p) { From patchwork Sun Mar 14 21:27:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400139 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2927275jai; Sun, 14 Mar 2021 14:48:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLaYvIwQTBSh+2Ejfu5keX4CD3MZeOwlTT1yHEIGgu0cbxHcYpZgZWbea9azwPQZSlVZxd X-Received: by 2002:a25:5ed5:: with SMTP id s204mr35430210ybb.121.1615758496452; Sun, 14 Mar 2021 14:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758496; cv=none; d=google.com; s=arc-20160816; b=TurDzuPTnHRsnzMGM6jHo6wMOuHBtWbiSTbsN11R1LMi2TaePZV6HfV52qGmKGxM7k yj5cF0iY3INbv4MBblWvi4K4IVK7qYMbyo51VAUQuQRYi6FvpxG+70dRHn8zprc2/uST Kghle995DPaSO8QzEHLLEQv/8OIhc8B3iylPTtHJO3CaV0jw9GIjo+2LNqStQDallePA IPssKbSkB/70PuUAgUX3i0JRQqZe36holsLrXjkIQ4nitAcF9FkQA7o1ov1adH4GPPRl +unM/VmjyOlIIxo33p+aQiHSnXmOFp5eLDwCilnxmn/EQTm3/5p7shl21FkLiSEzRwGN ksvQ== 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=hYFiBy94Dt1+MrJ1IkmuBBfk3yK1g2NK+iH3wafrLbo=; b=iGDRwHx7rZUbX2unk/AkelGhOFJJOV3XyJx6k8Zpf7Ut01Q19twctDR143G0cAlSlC HhxtkaptxJgae6+Igz8xeGLSh6JIIeZGZ3oq26kyp6JkJaKMGd09n+3C9NJeGt75NYsT 0r7vYhnOpd8zz50lZZbOT75+l1P9994Dbcg3ELMN2Cs8118yGMIhn30layq6o+k+Iy7g ZARXG5OCb+rcbQmp39vb3QHnucE6F1BXSW8v3nMkLiO35I484wUrrLTgoxONNbArQq94 gqZSNt4+2y0qdx5XQTR85GLQil1BcheZ0S+26Op84L67fMnWzd6L+s21gfXqaS57sVeJ EzdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DYXpjVCK; 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=fail (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 f89si15136841ybi.135.2021.03.14.14.48.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:48:16 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=DYXpjVCK; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYas-0003qJ-ST for patch@linaro.org; Sun, 14 Mar 2021 17:48:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH6-00069l-R9 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:48 -0400 Received: from mail-qv1-xf32.google.com ([2607:f8b0:4864:20::f32]:42956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH0-0008Do-NL for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:47 -0400 Received: by mail-qv1-xf32.google.com with SMTP id 30so6881658qva.9 for ; Sun, 14 Mar 2021 14:27:42 -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 :mime-version:content-transfer-encoding; bh=hYFiBy94Dt1+MrJ1IkmuBBfk3yK1g2NK+iH3wafrLbo=; b=DYXpjVCKfMiEqRFYfs1HPoV8iKdWiJxMefl0CJCugisOQxgL5/kh6ex/O5cvruYJRp j/dLBxrrJ8mSNCItMC82HSjfO/DpFVr733tXt8OHgKjWGhx8az3Zt2yXmUJiCCWQuiGT v0A5fQ0AMPjLvgsr2LT4Ug9ootjCQ5giOgmDjy5qvrPRnRGNR9tOJLxBM1DIDu2FDEQl zvk/tCJs72luLL5CIsC1ZVPLuvfuKxFO5Qq6ulycHjMryCftI4XgKiP6ggbxLBKiVQTD imoMqSh9eLIVTArDWIut1DYaxW8pMR3DM0Q0W0YXA5GSlCq4rMIBl7olOp/ZlJqoxHp2 n7wQ== 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=hYFiBy94Dt1+MrJ1IkmuBBfk3yK1g2NK+iH3wafrLbo=; b=AA2dde4cyMYOeXiwWhF7Yjca1SXazR3CDjyG8grBSFkDyo7XlNiDvJLsOJU1ucbSkA AoZtPo7d8lsJUSMA5dH+WJO2HnRByorLcXgq1PGFNS5OgFE/QAeFh8/uynkXXv4w1DBZ SM8VOw5QQbE1KyVsIivW4U5ShYp59VjUBZVWv5FikIFEuuDFkD9R+XTooHtvk/btkKdl AGJztxXFWa7jTKo00h2NoFTZNaY38VBd7VdniKRr1rqqnF2zm6fc8ZYWIui3ldDVmRWA d61uJ/spyCzWfillBl1ss5S1TfaR+J1oMJkk/hs3vziZJgJDjtfHhpWf12u4OWkpW59L 9ZCQ== X-Gm-Message-State: AOAM530cpsERQCPc0NPCirYP4OnKPc3EA/jR9Nri9tUCuWjVA7BOU2g7 6sndG9KLFoxTbB4BOnBwuiSDSb5a+bKBDtIQ X-Received: by 2002:ad4:4581:: with SMTP id x1mr7956846qvu.9.1615757261842; Sun, 14 Mar 2021 14:27:41 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 13/29] accel/tcg: Pass down max_cpus to tcg_init Date: Sun, 14 Mar 2021 15:27:08 -0600 Message-Id: <20210314212724.1917075-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f32; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf32.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: r.bolshakov@yadro.com, j@getutm.app, =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Start removing the include of hw/boards.h from tcg/. Pass down the max_cpus value from tcg_init_machine, where we have the MachineState already. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 2 +- tcg/internal.h | 2 +- accel/tcg/tcg-all.c | 10 +++++++++- tcg/region.c | 32 +++++++++++--------------------- tcg/tcg.c | 10 ++++------ 5 files changed, 26 insertions(+), 30 deletions(-) -- 2.25.1 diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 3ad77ec34d..a0122c0dd3 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -906,7 +906,7 @@ static inline void *tcg_malloc(int size) } } -void tcg_init(size_t tb_size, int splitwx); +void tcg_init(size_t tb_size, int splitwx, unsigned max_cpus); void tcg_register_thread(void); void tcg_prologue_init(TCGContext *s); void tcg_func_start(TCGContext *s); diff --git a/tcg/internal.h b/tcg/internal.h index f13c564d9b..fcfeca232f 100644 --- a/tcg/internal.h +++ b/tcg/internal.h @@ -30,7 +30,7 @@ extern TCGContext **tcg_ctxs; extern unsigned int n_tcg_ctxs; -void tcg_region_init(size_t tb_size, int splitwx); +void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus); bool tcg_region_alloc(TCGContext *s); void tcg_region_initial_alloc(TCGContext *s); void tcg_region_prologue_set(TCGContext *s); diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index 0e83acbfe5..d2f2ddb844 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -32,6 +32,9 @@ #include "qemu/error-report.h" #include "qemu/accel.h" #include "qapi/qapi-builtin-visit.h" +#if !defined(CONFIG_USER_ONLY) +#include "hw/boards.h" +#endif #include "internal.h" struct TCGState { @@ -109,13 +112,18 @@ bool mttcg_enabled; static int tcg_init_machine(MachineState *ms) { TCGState *s = TCG_STATE(current_accel()); +#ifdef CONFIG_USER_ONLY + unsigned max_cpus = 1; +#else + unsigned max_cpus = ms->smp.max_cpus; +#endif tcg_allowed = true; mttcg_enabled = s->mttcg_enabled; page_init(); tb_htable_init(); - tcg_init(s->tb_size * 1024 * 1024, s->splitwx_enabled); + tcg_init(s->tb_size * 1024 * 1024, s->splitwx_enabled, max_cpus); #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and diff --git a/tcg/region.c b/tcg/region.c index 8d88144a22..04b699da63 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -27,9 +27,6 @@ #include "qapi/error.h" #include "exec/exec-all.h" #include "tcg/tcg.h" -#if !defined(CONFIG_USER_ONLY) -#include "hw/boards.h" -#endif #include "internal.h" @@ -366,27 +363,20 @@ void tcg_region_reset_all(void) tcg_region_tree_reset_all(); } +static size_t tcg_n_regions(unsigned max_cpus) +{ #ifdef CONFIG_USER_ONLY -static size_t tcg_n_regions(void) -{ return 1; -} #else -/* - * It is likely that some vCPUs will translate more code than others, so we - * first try to set more regions than max_cpus, with those regions being of - * reasonable size. If that's not possible we make do by evenly dividing - * the code_gen_buffer among the vCPUs. - */ -static size_t tcg_n_regions(void) -{ + /* + * It is likely that some vCPUs will translate more code than others, + * so we first try to set more regions than max_cpus, with those regions + * being of reasonable size. If that's not possible we make do by evenly + * dividing the code_gen_buffer among the vCPUs. + */ size_t i; /* Use a single region if all we have is one vCPU thread */ -#if !defined(CONFIG_USER_ONLY) - MachineState *ms = MACHINE(qdev_get_machine()); - unsigned int max_cpus = ms->smp.max_cpus; -#endif if (max_cpus == 1 || !qemu_tcg_mttcg_enabled()) { return 1; } @@ -405,8 +395,8 @@ static size_t tcg_n_regions(void) } /* If we can't, then just allocate one region per vCPU thread */ return max_cpus; -} #endif +} /* Minimum size of the code gen buffer. This number is randomly chosen, but not so small that we can't have a fair number of TB's live. */ @@ -838,7 +828,7 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) * in practice. Multi-threaded guests share most if not all of their translated * code, which makes parallel code generation less appealing than in softmmu. */ -void tcg_region_init(size_t tb_size, int splitwx) +void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) { void *buf, *aligned; size_t size; @@ -856,7 +846,7 @@ void tcg_region_init(size_t tb_size, int splitwx) buf = tcg_init_ctx.code_gen_buffer; size = tcg_init_ctx.code_gen_buffer_size; page_size = qemu_real_host_page_size; - n_regions = tcg_n_regions(); + n_regions = tcg_n_regions(max_cpus); /* The first region will be 'aligned - buf' bytes larger than the others */ aligned = QEMU_ALIGN_PTR_UP(buf, page_size); diff --git a/tcg/tcg.c b/tcg/tcg.c index 65a63bda8a..a89d8f6b81 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -576,7 +576,7 @@ static void process_op_defs(TCGContext *s); static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type, TCGReg reg, const char *name); -static void tcg_context_init(void) +static void tcg_context_init(unsigned max_cpus) { TCGContext *s = &tcg_init_ctx; int op, total_args, n, i; @@ -645,8 +645,6 @@ static void tcg_context_init(void) tcg_ctxs = &tcg_ctx; n_tcg_ctxs = 1; #else - MachineState *ms = MACHINE(qdev_get_machine()); - unsigned int max_cpus = ms->smp.max_cpus; tcg_ctxs = g_new(TCGContext *, max_cpus); #endif @@ -655,10 +653,10 @@ static void tcg_context_init(void) cpu_env = temp_tcgv_ptr(ts); } -void tcg_init(size_t tb_size, int splitwx) +void tcg_init(size_t tb_size, int splitwx, unsigned max_cpus) { - tcg_context_init(); - tcg_region_init(tb_size, splitwx); + tcg_context_init(max_cpus); + tcg_region_init(tb_size, splitwx, max_cpus); } /* From patchwork Sun Mar 14 21:27:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400123 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2921756jai; Sun, 14 Mar 2021 14:32:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx71ufrahIB872raVqSkD3g8zxxkRdZ/JeN2Z3u4FKNClQpUdUBtxn/H/QkkmHrVizsDv94 X-Received: by 2002:a05:6e02:1d98:: with SMTP id h24mr10367803ila.88.1615757532767; Sun, 14 Mar 2021 14:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757532; cv=none; d=google.com; s=arc-20160816; b=hTv7CqXufoWHOxvcIZtj+rfmHF0slLXQkIxLuEgZHHR4TnNaqDMI7tFnG/33tpNKHR xzr017fCWsiZGnuBbtcO6muEloBxWrgOLnv7Bgxi+cRmjrnONUvbri8pA12lEmGUr4TA f+5FXkSTKLhkyobA6OC0pOD5NHnrqGz7QEuY3T/PA9rIr0Mx3rZS07jZxioOv2igXfdO 2+kmdMxxv1TRQBViBIE81/HwZNJyMuSIKl8Cu0eA6qjYsqPdUSQLOGJc95Xm+whTM94I YcJKSyOZMabR0RKMr4tY43/E2xitIw3PgSWlSNMKwli7pCYKPV70fXoF52cWkOkKBwYf fM+Q== 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=OlLc/LhYExyFieSM8eoDWZSL5lD1vPrcLRLDLT+veX8=; b=gOlMEGx6Ugz6eBy7OfZt6CVP6dmtFFuCKvO3AydvL+uUjDXgMLbNp084adtsDmkomr +Aw9UjsVWmQm3PsrTuKE38Ev/yM6fczn9YSwCcECUGjc0gy4gTnOvooKgmEYeHqLbY+0 sfL0AyQX6Z+OtAKVi92lLVHw1uyR0d33sqpSTelGogn1khYvcuYoVs+FusxOjIrhwZ3V NEtd7A0XoID6r1i8luqvSzOItZYd02UIEMjs1Pf7HRhSHywi6qQ8ENkv+gXiwwHyz+E2 w410SIssCoXODQmAVYnF/LqgZqfKwiP+liXRjjmUY2GfSnh/xjB+sC9K3RmcsDtJkRnI Hj/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=J2f0MnHD; 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=fail (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 x8si9108491ioj.36.2021.03.14.14.32.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:32:12 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=J2f0MnHD; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYLL-00014G-VC for patch@linaro.org; Sun, 14 Mar 2021 17:32:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH4-00067l-Em for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:46 -0400 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]:44585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH1-0008EX-Ol for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:45 -0400 Received: by mail-qt1-x82b.google.com with SMTP id m7so7862638qtq.11 for ; Sun, 14 Mar 2021 14:27:43 -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 :mime-version:content-transfer-encoding; bh=OlLc/LhYExyFieSM8eoDWZSL5lD1vPrcLRLDLT+veX8=; b=J2f0MnHDCT5W3lGBHZmvGxJeHT1aWZsaiZFcRCamquPJVqzS6LGt5tfLfcmKhrhBcc 3V2RtJzRxzrBwRMPSAe8eAYLRlBtqjPIdFOORR6CSxS79OudNQgcSdYCDeR6fNb1SZKK /Eaj0xSvjNR9tEab6DiONLvOrgIDUIgoep/ot04IFdU6HFz305eMekuYFJ8yScuIPu1f yExffI+3KlmehT/OPJqZC3x0orhDuXykyDT/+w64ybJ4FJ9ZEyu3F6QMYNzUKbzH+9zt wI/TegvVPQlcgX65n/UldxM8Sn5b/1rXMtfCL1328YGzxNYngblln5hp60Dtj2vJKYWL ypqw== 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=OlLc/LhYExyFieSM8eoDWZSL5lD1vPrcLRLDLT+veX8=; b=ZAGNWyrm4jUBRem76BFMRACYlXJrhs3nf+JxgQuFrhz7V1IYm2oCL1UJEDkzKBQc+r VRLZzM8GnifxWE8QJbErLiRb7wluiqasmPmGD9/ytBt6Uaq+2z3abHDk2mgoGgWPeZQY lDZXorE/Zw+yor3+M6nDBG0FDWN9XqekZ40mOjVRtaZDGNJFo0UQHfmnodzirBnutmzZ QGYT66+vtLKX7lMjqYiPTrv6eKSs/XotFKaA+E73LymKqtcqeLdABCuagr/dw1ve4jDw qwJ2vTSQc7yzN+mZZrY7P/Bl9Os351JaQxtWRHbNhbBL3XPhYf9Q5qc3kZw2MtnT26Eb 9ODw== X-Gm-Message-State: AOAM533id7T3mdfoRvxUn056M8+a/BZSlakwKpi6Uaj7YpojSrKl5t47 dO5onSGMslNLYHYlRWGW2JGzuZ7WuBX/5iQn X-Received: by 2002:ac8:43d6:: with SMTP id w22mr19539386qtn.283.1615757262905; Sun, 14 Mar 2021 14:27:42 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 14/29] tcg: Introduce tcg_max_ctxs Date: Sun, 14 Mar 2021 15:27:09 -0600 Message-Id: <20210314212724.1917075-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::82b; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x82b.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: r.bolshakov@yadro.com, j@getutm.app, =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Finish the divorce of tcg/ from hw/, and do not take the max cpu value from MachineState; just remember what we were passed in tcg_init. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/internal.h | 3 ++- tcg/region.c | 6 +++--- tcg/tcg.c | 23 ++++++++++------------- 3 files changed, 15 insertions(+), 17 deletions(-) -- 2.25.1 diff --git a/tcg/internal.h b/tcg/internal.h index fcfeca232f..f9906523da 100644 --- a/tcg/internal.h +++ b/tcg/internal.h @@ -28,7 +28,8 @@ #define TCG_HIGHWATER 1024 extern TCGContext **tcg_ctxs; -extern unsigned int n_tcg_ctxs; +extern unsigned int tcg_cur_ctxs; +extern unsigned int tcg_max_ctxs; void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus); bool tcg_region_alloc(TCGContext *s); diff --git a/tcg/region.c b/tcg/region.c index 04b699da63..e3fbf6a7e7 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -347,7 +347,7 @@ void tcg_region_initial_alloc(TCGContext *s) /* Call from a safe-work context */ void tcg_region_reset_all(void) { - unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); + unsigned int n_ctxs = qatomic_read(&tcg_cur_ctxs); unsigned int i; qemu_mutex_lock(®ion.lock); @@ -922,7 +922,7 @@ void tcg_region_prologue_set(TCGContext *s) */ size_t tcg_code_size(void) { - unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); + unsigned int n_ctxs = qatomic_read(&tcg_cur_ctxs); unsigned int i; size_t total; @@ -958,7 +958,7 @@ size_t tcg_code_capacity(void) size_t tcg_tb_phys_invalidate_count(void) { - unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); + unsigned int n_ctxs = qatomic_read(&tcg_cur_ctxs); unsigned int i; size_t total = 0; diff --git a/tcg/tcg.c b/tcg/tcg.c index a89d8f6b81..a82d3a0861 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -44,11 +44,6 @@ #include "cpu.h" #include "exec/exec-all.h" - -#if !defined(CONFIG_USER_ONLY) -#include "hw/boards.h" -#endif - #include "tcg/tcg-op.h" #if UINTPTR_MAX == UINT32_MAX @@ -155,7 +150,8 @@ static int tcg_out_ldst_finalize(TCGContext *s); #endif TCGContext **tcg_ctxs; -unsigned int n_tcg_ctxs; +unsigned int tcg_cur_ctxs; +unsigned int tcg_max_ctxs; TCGv_env cpu_env = 0; const void *tcg_code_gen_epilogue; uintptr_t tcg_splitwx_diff; @@ -475,7 +471,6 @@ void tcg_register_thread(void) #else void tcg_register_thread(void) { - MachineState *ms = MACHINE(qdev_get_machine()); TCGContext *s = g_malloc(sizeof(*s)); unsigned int i, n; @@ -491,8 +486,8 @@ void tcg_register_thread(void) } /* Claim an entry in tcg_ctxs */ - n = qatomic_fetch_inc(&n_tcg_ctxs); - g_assert(n < ms->smp.max_cpus); + n = qatomic_fetch_inc(&tcg_cur_ctxs); + g_assert(n < tcg_max_ctxs); qatomic_set(&tcg_ctxs[n], s); if (n > 0) { @@ -643,9 +638,11 @@ static void tcg_context_init(unsigned max_cpus) */ #ifdef CONFIG_USER_ONLY tcg_ctxs = &tcg_ctx; - n_tcg_ctxs = 1; + tcg_cur_ctxs = 1; + tcg_max_ctxs = 1; #else - tcg_ctxs = g_new(TCGContext *, max_cpus); + tcg_max_ctxs = max_cpus; + tcg_ctxs = g_new0(TCGContext *, max_cpus); #endif tcg_debug_assert(!tcg_regset_test_reg(s->reserved_regs, TCG_AREG0)); @@ -3937,7 +3934,7 @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp *op) static inline void tcg_profile_snapshot(TCGProfile *prof, bool counters, bool table) { - unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); + unsigned int n_ctxs = qatomic_read(&tcg_cur_ctxs); unsigned int i; for (i = 0; i < n_ctxs; i++) { @@ -4000,7 +3997,7 @@ void tcg_dump_op_count(void) int64_t tcg_cpu_exec_time(void) { - unsigned int n_ctxs = qatomic_read(&n_tcg_ctxs); + unsigned int n_ctxs = qatomic_read(&tcg_cur_ctxs); unsigned int i; int64_t ret = 0; From patchwork Sun Mar 14 21:27:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400125 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2922404jai; Sun, 14 Mar 2021 14:34:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3XfcegGbuL9OQiusXvuvlQBaOoxgBmqVpM69TDdm827yNYwI+SL5onobnkR6hm08grp2g X-Received: by 2002:a25:e010:: with SMTP id x16mr33424412ybg.511.1615757655189; Sun, 14 Mar 2021 14:34:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757655; cv=none; d=google.com; s=arc-20160816; b=dTn4VRuw5W4diSzr0LfLEgvjX0yC1PiYdKh3Rj1oTETM81XUlTvHMZozpa/CynwCWO M9+2PxcE4EBJ4rrGU0zJ2YTpL0Zp1DjOkjncddPbkGyk+itlwSvFouHYbSRyaytYyAPJ bjWdgqBITJI0WBCUXSSQC9DADCXQTag4talHDOsqfLLC4ZmzPpyy1fxi8Ta6H6kXMgny lMcWb7/b0/xvvtfPA1i0iMsS4rprTrTRzDl5jxF7p48OKISwr6phFPkId39jCyCUDXmW 1JTEv8tX2W5Vr8rGaOmT+EifOdkkH4eHGSUyVEBHPmEa5em24M91/hKryMnIgzimsbRG wkrA== 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=wTdpZA//9mM13rTDthBtwAtIDEdfj+iL3ziTKOJ9PhY=; b=c9SZ6X8NQk/v7Qc8NYNkLMeaR+dD9ftMa4pFNGtboyQ+Gn5MZ1F3O6tZw+I5Itbada 9D5dgrMndhQARn7xE+iM5211IX/NLMGSxVyoU8jaFC0y3Ar2SX/6bcqhn1sS072RMwWV 1+vw2cJDpwCT2OQiZsPDoRfbq9WwrKUvDnMlbLNLxeisDaeRpHypsX43YdWh1cCVNm3J GAbQIX4hGQydJq+DYfhqm+YdmCVtZ0Sl14kvrVzV3XSQd2CsqXUuYJ1iSfIH1T2kMwqz 8CU9WazOYIEtV6lsa/4cjqf6Unakvsn0bppK35shW5cXV9dH4ezAcweeAfjzi833U2US qv2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="U/oMvNQO"; 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=fail (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 i198si12762907ybg.238.2021.03.14.14.34.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:34:15 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b="U/oMvNQO"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYNK-0004ln-Hy for patch@linaro.org; Sun, 14 Mar 2021 17:34:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH5-00069j-Qn for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:48 -0400 Received: from mail-qv1-xf2d.google.com ([2607:f8b0:4864:20::f2d]:43620) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH2-0008Eh-PK for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:46 -0400 Received: by mail-qv1-xf2d.google.com with SMTP id cx5so6872619qvb.10 for ; Sun, 14 Mar 2021 14:27:44 -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 :mime-version:content-transfer-encoding; bh=wTdpZA//9mM13rTDthBtwAtIDEdfj+iL3ziTKOJ9PhY=; b=U/oMvNQObUmc4BNyK+I42l5cKnXwmFQY1qu62hmCiMTfFjmfvfnfHVIE+2DrEOifZH qbYG0WtAI79f3n1hASrDhwRhQCbk+DFgLZlTLvA9ZaKwfarU890OgNcnPRphAu9vXlkm gU3sPTgDAg753rHSi6QReMhx90e413XYqn0nqs/tmpFbEOMdp8l1WPV8C1JEGdhN6J7U 1YaYZoewX/hETJomDhYTr3gZi/F1nyr2lg+IS6D4nvNTyGAyUtDvg/ir76Uq1gq/Igek tA11bRu4Cd/Gq4ZEAACRR0vGzzTLVcRFDefTBsrNGcnzfQ0W6Oh1BApFy2L+7OK+2yFw lVoA== 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=wTdpZA//9mM13rTDthBtwAtIDEdfj+iL3ziTKOJ9PhY=; b=DAov+meqiFHUTIERzY0UgJdUvtsz2N9k2g5zeESF9qXuW5J1JuBP7ov4+8fJ1C5yYp 3iCzGVA5magZuFeN/auwTJmILw1IpjOOzQ/0Vej+fjUysiUnZ1ufmYuF68Y3WyqHcuyS ctKe5q61WA7uu8WPTrRlg8VeXiF7qlIwaOlM9cQKFuiufv17/idp6tCX8AG2GM37PXku MQZO1eyTUgWiIrBe3HtV2OckovTq/oGLDlteZWMlgUrCmKzvOxA1kL77mpsLUa2SuG/I IjOnNZ7WFXeg5aqWKO8GWKt60ovzduZwrkTQm+XCOkRHC9B0oFNOpFzHfzDCZ9cD+1Qt h4bA== X-Gm-Message-State: AOAM533GQiFsoF4ZfL7WiY46WLu4/79hTeebYsISuIc6N+aUytSJbxYL VgXF5W/twYEuK1r7cxf6dMtB+HI+9bJkWBsd X-Received: by 2002:a05:6214:20ed:: with SMTP id 13mr7947461qvk.34.1615757263895; Sun, 14 Mar 2021 14:27:43 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 15/29] tcg: Move MAX_CODE_GEN_BUFFER_SIZE to tcg-target.h Date: Sun, 14 Mar 2021 15:27:10 -0600 Message-Id: <20210314212724.1917075-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f2d; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2d.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Remove the ifdef ladder and move each define into the appropriate header file. Signed-off-by: Richard Henderson --- v2: Retain comment about M_C_G_B_S constraint (balaton) --- tcg/aarch64/tcg-target.h | 1 + tcg/arm/tcg-target.h | 1 + tcg/i386/tcg-target.h | 2 ++ tcg/mips/tcg-target.h | 6 ++++++ tcg/ppc/tcg-target.h | 2 ++ tcg/riscv/tcg-target.h | 1 + tcg/s390/tcg-target.h | 3 +++ tcg/sparc/tcg-target.h | 1 + tcg/tci/tcg-target.h | 1 + tcg/region.c | 35 +++++++++-------------------------- 10 files changed, 27 insertions(+), 26 deletions(-) -- 2.25.1 diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h index 5ec30dba25..ef55f7c185 100644 --- a/tcg/aarch64/tcg-target.h +++ b/tcg/aarch64/tcg-target.h @@ -15,6 +15,7 @@ #define TCG_TARGET_INSN_UNIT_SIZE 4 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 24 +#define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) #undef TCG_TARGET_STACK_GROWSUP typedef enum { diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h index 8d1fee6327..b9a85d0f83 100644 --- a/tcg/arm/tcg-target.h +++ b/tcg/arm/tcg-target.h @@ -60,6 +60,7 @@ extern int arm_arch; #undef TCG_TARGET_STACK_GROWSUP #define TCG_TARGET_INSN_UNIT_SIZE 4 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 16 +#define MAX_CODE_GEN_BUFFER_SIZE UINT32_MAX typedef enum { TCG_REG_R0 = 0, diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h index b693d3692d..ac10066c3e 100644 --- a/tcg/i386/tcg-target.h +++ b/tcg/i386/tcg-target.h @@ -31,9 +31,11 @@ #ifdef __x86_64__ # define TCG_TARGET_REG_BITS 64 # define TCG_TARGET_NB_REGS 32 +# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) #else # define TCG_TARGET_REG_BITS 32 # define TCG_TARGET_NB_REGS 24 +# define MAX_CODE_GEN_BUFFER_SIZE UINT32_MAX #endif typedef enum { diff --git a/tcg/mips/tcg-target.h b/tcg/mips/tcg-target.h index c2c32fb38f..e81e824cab 100644 --- a/tcg/mips/tcg-target.h +++ b/tcg/mips/tcg-target.h @@ -39,6 +39,12 @@ #define TCG_TARGET_TLB_DISPLACEMENT_BITS 16 #define TCG_TARGET_NB_REGS 32 +/* + * We have a 256MB branch region, but leave room to make sure the + * main executable is also within that region. + */ +#define MAX_CODE_GEN_BUFFER_SIZE (128 * MiB) + typedef enum { TCG_REG_ZERO = 0, TCG_REG_AT, diff --git a/tcg/ppc/tcg-target.h b/tcg/ppc/tcg-target.h index d1339afc66..c13ed5640a 100644 --- a/tcg/ppc/tcg-target.h +++ b/tcg/ppc/tcg-target.h @@ -27,8 +27,10 @@ #ifdef _ARCH_PPC64 # define TCG_TARGET_REG_BITS 64 +# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) #else # define TCG_TARGET_REG_BITS 32 +# define MAX_CODE_GEN_BUFFER_SIZE (32 * MiB) #endif #define TCG_TARGET_NB_REGS 64 diff --git a/tcg/riscv/tcg-target.h b/tcg/riscv/tcg-target.h index 727c8df418..87ea94666b 100644 --- a/tcg/riscv/tcg-target.h +++ b/tcg/riscv/tcg-target.h @@ -34,6 +34,7 @@ #define TCG_TARGET_INSN_UNIT_SIZE 4 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 20 #define TCG_TARGET_NB_REGS 32 +#define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) typedef enum { TCG_REG_ZERO, diff --git a/tcg/s390/tcg-target.h b/tcg/s390/tcg-target.h index 641464eea4..b04b72b7eb 100644 --- a/tcg/s390/tcg-target.h +++ b/tcg/s390/tcg-target.h @@ -28,6 +28,9 @@ #define TCG_TARGET_INSN_UNIT_SIZE 2 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 19 +/* We have a +- 4GB range on the branches; leave some slop. */ +#define MAX_CODE_GEN_BUFFER_SIZE (3 * GiB) + typedef enum TCGReg { TCG_REG_R0 = 0, TCG_REG_R1, diff --git a/tcg/sparc/tcg-target.h b/tcg/sparc/tcg-target.h index f66f5d07dc..86bb9a2d39 100644 --- a/tcg/sparc/tcg-target.h +++ b/tcg/sparc/tcg-target.h @@ -30,6 +30,7 @@ #define TCG_TARGET_INSN_UNIT_SIZE 4 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 32 #define TCG_TARGET_NB_REGS 32 +#define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) typedef enum { TCG_REG_G0 = 0, diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h index 9c0021a26f..03cf527cb4 100644 --- a/tcg/tci/tcg-target.h +++ b/tcg/tci/tcg-target.h @@ -43,6 +43,7 @@ #define TCG_TARGET_INTERPRETER 1 #define TCG_TARGET_INSN_UNIT_SIZE 1 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 32 +#define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) #if UINTPTR_MAX == UINT32_MAX # define TCG_TARGET_REG_BITS 32 diff --git a/tcg/region.c b/tcg/region.c index e3fbf6a7e7..ae22308290 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -398,34 +398,17 @@ static size_t tcg_n_regions(unsigned max_cpus) #endif } -/* Minimum size of the code gen buffer. This number is randomly chosen, - but not so small that we can't have a fair number of TB's live. */ +/* + * Minimum size of the code gen buffer. This number is randomly chosen, + * but not so small that we can't have a fair number of TB's live. + * + * Maximum size, MAX_CODE_GEN_BUFFER_SIZE, is defined in tcg-target.h. + * Unless otherwise indicated, this is constrained by the range of + * direct branches on the host cpu, as used by the TCG implementation + * of goto_tb. + */ #define MIN_CODE_GEN_BUFFER_SIZE (1 * MiB) -/* Maximum size of the code gen buffer we'd like to use. Unless otherwise - indicated, this is constrained by the range of direct branches on the - host cpu, as used by the TCG implementation of goto_tb. */ -#if defined(__x86_64__) -# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) -#elif defined(__sparc__) -# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) -#elif defined(__powerpc64__) -# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) -#elif defined(__powerpc__) -# define MAX_CODE_GEN_BUFFER_SIZE (32 * MiB) -#elif defined(__aarch64__) -# define MAX_CODE_GEN_BUFFER_SIZE (2 * GiB) -#elif defined(__s390x__) - /* We have a +- 4GB range on the branches; leave some slop. */ -# define MAX_CODE_GEN_BUFFER_SIZE (3 * GiB) -#elif defined(__mips__) - /* We have a 256MB branch region, but leave room to make sure the - main executable is also within that region. */ -# define MAX_CODE_GEN_BUFFER_SIZE (128 * MiB) -#else -# define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) -#endif - #if TCG_TARGET_REG_BITS == 32 #define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (32 * MiB) #ifdef CONFIG_USER_ONLY From patchwork Sun Mar 14 21:27:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400142 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2928992jai; Sun, 14 Mar 2021 14:53:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFaytZhyvCzCxyoVVuFx1TYcTONSz49NQZqeVPUvVqtQ3F6vxG9TJUpAwrvgY0cA7CS8nw X-Received: by 2002:a25:1e82:: with SMTP id e124mr32875574ybe.505.1615758828218; Sun, 14 Mar 2021 14:53:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758828; cv=none; d=google.com; s=arc-20160816; b=RXn4ow3tNziqWBD8Vio9QdemJEr8Vp4vEdODobDUUcuDCAZm1uC+Jawx0JNmoOT5we pz2bDvChWbXn3roGPk9rNj33b4JAjb4Xv4n9Ye7MNmhkjkVr2TC16ZL2w3FPCjMOekal Uhtm/wNtV+Nz9ESYKIu7hOz8W/VFd7wFS3AsCsqANvOD8MExPrpDXjcxO3eClCAinpaC yWRmfq6FRKC/h+kan/wU1EgIRwzrvokJi5vI4z50NiFc1CHs95Enj5W94U1pktHFKsP0 Iug5uMfX7rHxSgq3trfq0XNCDmCkPzmwS+J7vNVPMgIEGSkv96lquc1Jl+cKrooLwhvU IdTQ== 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=cCuL+0Cr0Nxn0ond/pgRLvEba3AtjzB4cSKYgtHeHws=; b=BSoLZKhATHCLPBHT4mRkPiEGW6BtNE99lkc4rizT4W5AF2XAH9KKMoASGn0AM4kmch +LKc6uEbIFdyMBltLU9CnpeWNuvjJS/KpxjUB843nhzc7xZeZHHCM+r9t67Bg8N5POuN vhdVSBYl45/L3Ozm0KlEAAAstDnXE6/q+h0IPvjsWW64VdO93EErXOvtBHzcvRCql9DK b8j/9vpfYNVIs8gtPhdcOkBe+EasA3MUQMQ8qeVg1Bzv1y2MUSA0bpU9twVHdQAYiE+7 Oe+MO91XILX1ezYZvmHlXRMkQuHOMN02yhZdwogw6w/7hCJxNGrUMBs8ULjHrrYklr1W HsFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=czkvbfTB; 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=fail (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 e11si13041755ybk.48.2021.03.14.14.53.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:53:48 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=czkvbfTB; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYgF-0007BU-MK for patch@linaro.org; Sun, 14 Mar 2021 17:53:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH9-0006Bz-Au for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:51 -0400 Received: from mail-qk1-x734.google.com ([2607:f8b0:4864:20::734]:43187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH3-0008FN-TZ for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:50 -0400 Received: by mail-qk1-x734.google.com with SMTP id b130so29890131qkc.10 for ; Sun, 14 Mar 2021 14:27:45 -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 :mime-version:content-transfer-encoding; bh=cCuL+0Cr0Nxn0ond/pgRLvEba3AtjzB4cSKYgtHeHws=; b=czkvbfTBUnwW/ScjIkq8zyezdsj/aif2NiRQFji6uiQUVHhRqMBZxsmLtVpo0eFlG7 2L0FsnvP09dSc6s9aweOr65WpM71H0pwtVXCoBBbrRQlyKHvI2/Fx9mUqm5B2HCtpHXZ D02U0MA+sI7C6UeAUnFQP98i72VRtI7rQLlB+YiEN+Ge+bQj9+kCe30LjUXqkHha83FQ ia799cvCfvxzH9/MjC3jbPia7MSYF+9hwKQk41fJwzYEatXLT3AqWe+Vt7UuGYjXzi/w lQ1R+ecmwovuk3/jFUOkrnAnWMn/6N2uzq9uc5GP9GG+5ObERzb1/E+z8EjD/N8BBoPl /MjA== 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=cCuL+0Cr0Nxn0ond/pgRLvEba3AtjzB4cSKYgtHeHws=; b=GCBtBJixaGFp9Q6FktCr0u3d2Gt1OSh2fmjls8jxtJA2lT0IENCIHR3JYWdZdme4VJ aNvdg5t+n97lBL/Ih6S+QGD0/QTr74NqRNpXaa+3N87J4jXHYR+tZ0XD2+wY+P4MoMHH Rm5TFWXxLqVlbgW+QgnHZO7pxuGPOPThG8Nc3GGGiqPGZufXPzGqM9w47Ne3blmGm5Og a6xSlzdlrZwGSexYR4sfQilkoKQ/pqmrO943EUYew0lP29vB3Zdip/jymPA7EMo6Y6dA rRoKs8PW8DnN4EaXsaHaCY8Yal5PELZFeE6TuXixpg+xB0TAwb4ayuSCuQB7YV+l/HHW mAGw== X-Gm-Message-State: AOAM5332M/FJ82JoDWEModS0gUZxHL8+cCphYfOiAX8tp/oEcTqmcFXq uuA1IjZZkb/lC5LdLIIWtCfIhmtXTdmup7W9 X-Received: by 2002:a05:620a:1353:: with SMTP id c19mr23065731qkl.392.1615757264880; Sun, 14 Mar 2021 14:27:44 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 16/29] tcg: Replace region.end with region.total_size Date: Sun, 14 Mar 2021 15:27:11 -0600 Message-Id: <20210314212724.1917075-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::734; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x734.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" A size is easier to work with than an end point, particularly during initial buffer allocation. Signed-off-by: Richard Henderson --- tcg/region.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index ae22308290..8e4dd0480b 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -48,7 +48,7 @@ struct tcg_region_state { /* fields set at init time */ void *start; void *start_aligned; - void *end; + size_t total_size; /* size of entire buffer */ size_t n; size_t size; /* size of one region */ size_t stride; /* .size + guard size */ @@ -279,7 +279,7 @@ static void tcg_region_bounds(size_t curr_region, void **pstart, void **pend) start = region.start; } if (curr_region == region.n - 1) { - end = region.end; + end = region.start_aligned + region.total_size; } *pstart = start; @@ -813,8 +813,8 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) */ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) { - void *buf, *aligned; - size_t size; + void *buf, *aligned, *end; + size_t total_size; size_t page_size; size_t region_size; size_t n_regions; @@ -827,19 +827,20 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) assert(ok); buf = tcg_init_ctx.code_gen_buffer; - size = tcg_init_ctx.code_gen_buffer_size; + total_size = tcg_init_ctx.code_gen_buffer_size; page_size = qemu_real_host_page_size; n_regions = tcg_n_regions(max_cpus); /* The first region will be 'aligned - buf' bytes larger than the others */ aligned = QEMU_ALIGN_PTR_UP(buf, page_size); - g_assert(aligned < tcg_init_ctx.code_gen_buffer + size); + g_assert(aligned < tcg_init_ctx.code_gen_buffer + total_size); + /* * Make region_size a multiple of page_size, using aligned as the start. * As a result of this we might end up with a few extra pages at the end of * the buffer; we will assign those to the last region. */ - region_size = (size - (aligned - buf)) / n_regions; + region_size = (total_size - (aligned - buf)) / n_regions; region_size = QEMU_ALIGN_DOWN(region_size, page_size); /* A region must have at least 2 pages; one code, one guard */ @@ -853,9 +854,11 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) region.start = buf; region.start_aligned = aligned; /* page-align the end, since its last page will be a guard page */ - region.end = QEMU_ALIGN_PTR_DOWN(buf + size, page_size); + end = QEMU_ALIGN_PTR_DOWN(buf + total_size, page_size); /* account for that last guard page */ - region.end -= page_size; + end -= page_size; + total_size = end - aligned; + region.total_size = total_size; /* set guard pages */ splitwx_diff = tcg_splitwx_diff; @@ -893,7 +896,7 @@ void tcg_region_prologue_set(TCGContext *s) /* Register the balance of the buffer with gdb. */ tcg_register_jit(tcg_splitwx_to_rx(region.start), - region.end - region.start); + region.start_aligned + region.total_size - region.start); } /* @@ -934,8 +937,10 @@ size_t tcg_code_capacity(void) /* no need for synchronization; these variables are set at init time */ guard_size = region.stride - region.size; - capacity = region.end + guard_size - region.start; - capacity -= region.n * (guard_size + TCG_HIGHWATER); + capacity = region.total_size; + capacity -= (region.n - 1) * guard_size; + capacity -= region.n * TCG_HIGHWATER; + return capacity; } From patchwork Sun Mar 14 21:27:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400127 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2922504jai; Sun, 14 Mar 2021 14:34:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXBtBiDThiy3kJb3bBWxvAMZ96GP8XUwIYOI9TstErOjFiPrK8g3Fu0UDFEBux479cOHyI X-Received: by 2002:a25:cfc5:: with SMTP id f188mr33228130ybg.485.1615757677113; Sun, 14 Mar 2021 14:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757677; cv=none; d=google.com; s=arc-20160816; b=E+VhLfwN0oxebacea3nSoAckLoi1QfJ1aR0OOT8h6HPn84SxiB5lXezDRtg5RFTqwi KZTfG03DTvQcYbavPBT7qWb0qFz0Cq03GUJQxH/rkMRRVMmyadRvb43WS1ZKa8Dbfr6H RsXvL2ELfeAJKUbK3gp6dm8LwwWuaZH0+5DWFiQLbZVZC49PNLrhYdc1GAcExrQU7IcW dj0R7bnC87YYUAe8DIuU4vwPfGR6yEDvVVuT3y+ZCn3SWJwqCoSRQYIfN/n0AYZ0wGiV m7Cz0ARUVXICHt2r316NmiseMAo2CRlIPVUoCD3MocCqx+krxyXK072V+3RtetpcRMlv 6kBA== 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=sT6m1DvpyLSK/jDOR0ljz9XPvbGUXpvhChthbdvn53o=; b=m5u8GlkyIKjcPfweNx4qNokH5hQJvpOgNweYhqEXa5kNZh6VZ/2B7PkYDm1UT6fpf8 VrA3Wa2uBaYnGRGEO5wr7pw9CLEgCOImyz8anz1cMFA9i7PT4RWN0jlf2vynWNazUSgG Z6E1Q5cGcVDjYJGrbSbcaWxV8GLY1NqnlDSZEwHpZrAQ0+y4BTFnXaMXh1Vj84dSeRW/ 6MHLTD4kJwTUp9NY7f+QuyYbd1ykIfXH/ejCs9Ecqv4UTsz9uk+8z5NUSedZZ3gq5gbX o8FgrzkGNdN+1xIUxSFdOO9uOPLN0PnhDmtFesA0iZqxvIWaYXRgRJhiyhM3NlvMckhE HF6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IeOquCAS; 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=fail (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 o139si13201929ybg.199.2021.03.14.14.34.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:34:37 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=IeOquCAS; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYNg-0004er-Gm for patch@linaro.org; Sun, 14 Mar 2021 17:34:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH7-0006Af-8X for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:50 -0400 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]:44253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH4-0008FX-UY for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:48 -0400 Received: by mail-qk1-x72b.google.com with SMTP id 130so29879780qkh.11 for ; Sun, 14 Mar 2021 14:27:46 -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 :mime-version:content-transfer-encoding; bh=sT6m1DvpyLSK/jDOR0ljz9XPvbGUXpvhChthbdvn53o=; b=IeOquCASz++uCfIdkVxgpsokUq3b6/XFmUwxxHnNoDlD/Keo8t8Aupy+esjdmvOxPK k1qLAeD9nKE2Udc3HW41gY499a+FF7kKTu89jC1qfcFA6syooUgYg8tXClPWDND+yeQc t3n3sXxb+hwEqyggy9aw6VSth3q7wZpdFOPioZPmsSdSGCLHQX8/GESD7Kty0YC+Ph7x JjngljYuHVyysLmCb2AcPkuxUYhrgZGoa8zLo/zSA9x2UW6c1xgNhKP4p+a4OnmUhEii wj1/+1y6GtUgxkb2rfBuc9OOM7tcV1AXgJsY+7csl4qPuBpluO+YCHqnDShhqx8O2TYC jwwQ== 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=sT6m1DvpyLSK/jDOR0ljz9XPvbGUXpvhChthbdvn53o=; b=nIVrWcOxipi+Mo/H+Fl9z/+dUT+wYyCMTXedb9l34zobkxHQOawEYRd8Ir8uUK7zHf oGM/an0cTwdhX1i7BaGDJKMMrftiI8/q+RYRzDGZY5edipKzFoOVzBh/qYHhOSj01gtq 7U7bdtt+UY66yID1ZLRo+wBDwxAFEW/2nUPeVGtd0dZLHskBpaTrZWxYFDSe308udjUY k4oexXfiISiJ0iJgo0s2LkllT4Qg3bF76Le1tAh7sGg+le0TSTfCWHvAPsIAOSLYDAVP 2Bxt5BMqEmlplw8sqQlZMigwMQf1SEwxXVQppwWpiRDe2qFMIP/vzZ2Z6SXLRW8J0ghH A5uw== X-Gm-Message-State: AOAM531tBWE5SyU+E+iqEMC6RowHqFtAzER1tsoHXW8R6dLlW+3XIM4d F/SOAimX65ECGeFhFE8gnfFzNIwGkum4yZHA X-Received: by 2002:a05:620a:14f:: with SMTP id e15mr22266912qkn.315.1615757265954; Sun, 14 Mar 2021 14:27:45 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 17/29] tcg: Rename region.start to region.after_prologue Date: Sun, 14 Mar 2021 15:27:12 -0600 Message-Id: <20210314212724.1917075-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72b; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72b.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Give the field a name reflecting its actual meaning. Signed-off-by: Richard Henderson --- tcg/region.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 8e4dd0480b..23261561a1 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -46,8 +46,8 @@ struct tcg_region_state { QemuMutex lock; /* fields set at init time */ - void *start; void *start_aligned; + void *after_prologue; size_t total_size; /* size of entire buffer */ size_t n; size_t size; /* size of one region */ @@ -276,7 +276,7 @@ static void tcg_region_bounds(size_t curr_region, void **pstart, void **pend) end = start + region.size; if (curr_region == 0) { - start = region.start; + start = region.after_prologue; } if (curr_region == region.n - 1) { end = region.start_aligned + region.total_size; @@ -851,7 +851,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) region.n = n_regions; region.size = region_size - page_size; region.stride = region_size; - region.start = buf; + region.after_prologue = buf; region.start_aligned = aligned; /* page-align the end, since its last page will be a guard page */ end = QEMU_ALIGN_PTR_DOWN(buf + total_size, page_size); @@ -888,15 +888,16 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) void tcg_region_prologue_set(TCGContext *s) { /* Deduct the prologue from the first region. */ - g_assert(region.start == s->code_gen_buffer); - region.start = s->code_ptr; + g_assert(region.start_aligned == s->code_gen_buffer); + region.after_prologue = s->code_ptr; /* Recompute boundaries of the first region. */ tcg_region_assign(s, 0); /* Register the balance of the buffer with gdb. */ - tcg_register_jit(tcg_splitwx_to_rx(region.start), - region.start_aligned + region.total_size - region.start); + tcg_register_jit(tcg_splitwx_to_rx(region.after_prologue), + region.start_aligned + region.total_size - + region.after_prologue); } /* From patchwork Sun Mar 14 21:27:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400140 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2927618jai; Sun, 14 Mar 2021 14:49:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzugzKrRZIvQVCtKiZ8m7Xqaa9HYd7Qfz9tgjltOShIlKWmn3/BpBuz1dGox4BIRpMKurRt X-Received: by 2002:a25:ad5c:: with SMTP id l28mr29731760ybe.307.1615758569139; Sun, 14 Mar 2021 14:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758569; cv=none; d=google.com; s=arc-20160816; b=OOBDgTcV0qUbRNWeSFG0CfmW5SqvbL8cL6DgWgh6kIkA3CrdV8Sv05qAOmOhiaxXA7 AyN+hZx6qCjTMe7jdcKPczG9ZSGWvltoL8byWujUqDl11flXCP6mWdVWVb0OQmuYM6R3 QKGS344QVsC01nlvSv+B2KcMm6oN9oidaeWV/HC4iKawT4HHS6HBNRq+dDx3s5rxZgs4 8F5OZvmm6Z0E8mC3OvoBclCSo0reOl5EDstkGHs7MY5PeKZ0QLf/sePx4x7MRahsaTPa j4+bNJITdgTtWfggD94D1FpqKvbVhRPGIQzB/W+VdwibAbGx5JKW/Br+V7zmvDmZUHrd uBow== 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=dKl3plwM0T4wQ2XEJ99rVXo5h1hjm+9QWf83bPhdblE=; b=xqFdxGKG57MazkpYvE7TZkKoGwl4QiQEvm3BJY/0MzTwXeEPE0OulZFPJYZrbcOXeZ 6Xt/iHZHDBHw49FhffwucwYD10DSqGk/PkZi9sdO0WQd93FpUM/BqdV1HUQLJ2RrXnh1 cdkgcB0LPYFlNDCppYgctagpZh4qtgq7U3uu/s2PBGd1IbG4n0VOX3asatMOWzNYG/Iv TJ7AboGVlhCuq4zVI7EaNCalEuJdFXFl+HOcW8i4xBd07f0uBktqX3UwCIw+Sd3ArX10 TatQMWqmhm4FlzAXy/RCnY1RcYZKFULwd8BEmiPnxddn1GUahxlZ1FDEReepChsvQbhJ PElQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UZsDacHJ; 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=fail (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 j3si12104992ybh.368.2021.03.14.14.49.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:49:29 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=UZsDacHJ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYc4-0004nh-KT for patch@linaro.org; Sun, 14 Mar 2021 17:49:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH8-0006BH-6w for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:50 -0400 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:46668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH6-0008Fy-HS for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:49 -0400 Received: by mail-qk1-x72a.google.com with SMTP id a9so29868593qkn.13 for ; Sun, 14 Mar 2021 14:27:47 -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 :mime-version:content-transfer-encoding; bh=dKl3plwM0T4wQ2XEJ99rVXo5h1hjm+9QWf83bPhdblE=; b=UZsDacHJ4pECD/381oH/pFqrUGiK9d6goWxrumgVIsyCtFxOlC3wNh5kcocFv3sl8L LQT9mzBDDwPjZsZzNzRr6SJA6OA0PXuvjOu+8s/Nyyo5YJLJ+OvDvVeTjAtKPgENH9BV 1byZW/SkjlPtblJwN52tCDvWFxonfhFjIGcGdZaIhhux7egXUFomeLgDzMBx4S2QCaya IWC6pesfozYHhG5tb+XCM6vMeD458/HL7Txv6GHchrRMFt0pxGzNuTEzVsDdMufRZW38 YafFR1BGF7WubLYSkZQ6FoEEu3+H1IB1RwTg0cum9aotQOjB2ZF3UwTAwC/XEZJKEptP Je5w== 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=dKl3plwM0T4wQ2XEJ99rVXo5h1hjm+9QWf83bPhdblE=; b=RnxHfTciWonpI+b3lNUKlPpREW2V14GxyuVdKd+FWqXnUb1/sGYugUArXyF9K7Z+I+ tfV49hNKELN0kcNnQBqh9e1pUswKhvLAg7qEyjYw8uLrNKNwRI6KO4opLpsZAGYzvZLb NGoewBOwRJfIookFjxfmJrtS6dYAzKQHcel6JIeWcB6TmJm21ZeYOHtR7p4UHE+6D1sj TYXg0HLgCTHUmeeq1JlxtmLw5uXIBoPqIT083EK23FqbgaZzTFEsB54E+q0Ulvnm8fyr NpsfARjpF5KM4UF8gQppU8JD0TWEODpPhAzXDv0UURGdLrkpTzUA+vKBrNl4+u0+WtW+ tqBw== X-Gm-Message-State: AOAM531Km86NgASHyaH/NAv7ANlo6jRp5VQKkk8ZZnKPlt+u6B+bhR3p IYRW3w8oGcBdiKLV1Z3Dcl+wz32HDJdE2U3n X-Received: by 2002:a05:620a:414e:: with SMTP id k14mr23558721qko.243.1615757267024; Sun, 14 Mar 2021 14:27:47 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 18/29] tcg: Tidy tcg_n_regions Date: Sun, 14 Mar 2021 15:27:13 -0600 Message-Id: <20210314212724.1917075-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72a.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Compute the value using straight division and bounds, rather than a loop. Pass in tb_size rather than reading from tcg_init_ctx.code_gen_buffer_size, Signed-off-by: Richard Henderson --- tcg/region.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 23261561a1..23b3459c61 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -363,38 +363,33 @@ void tcg_region_reset_all(void) tcg_region_tree_reset_all(); } -static size_t tcg_n_regions(unsigned max_cpus) +static size_t tcg_n_regions(size_t tb_size, unsigned max_cpus) { #ifdef CONFIG_USER_ONLY return 1; #else + size_t n_regions; + /* * It is likely that some vCPUs will translate more code than others, * so we first try to set more regions than max_cpus, with those regions * being of reasonable size. If that's not possible we make do by evenly * dividing the code_gen_buffer among the vCPUs. */ - size_t i; - /* Use a single region if all we have is one vCPU thread */ if (max_cpus == 1 || !qemu_tcg_mttcg_enabled()) { return 1; } - /* Try to have more regions than max_cpus, with each region being >= 2 MB */ - for (i = 8; i > 0; i--) { - size_t regions_per_thread = i; - size_t region_size; - - region_size = tcg_init_ctx.code_gen_buffer_size; - region_size /= max_cpus * regions_per_thread; - - if (region_size >= 2 * 1024u * 1024) { - return max_cpus * regions_per_thread; - } + /* + * Try to have more regions than max_cpus, with each region being >= 2 MB. + * If we can't, then just allocate one region per vCPU thread. + */ + n_regions = tb_size / (2 * MiB); + if (n_regions <= max_cpus) { + return max_cpus; } - /* If we can't, then just allocate one region per vCPU thread */ - return max_cpus; + return MIN(n_regions, max_cpus * 8); #endif } @@ -829,7 +824,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) buf = tcg_init_ctx.code_gen_buffer; total_size = tcg_init_ctx.code_gen_buffer_size; page_size = qemu_real_host_page_size; - n_regions = tcg_n_regions(max_cpus); + n_regions = tcg_n_regions(total_size, max_cpus); /* The first region will be 'aligned - buf' bytes larger than the others */ aligned = QEMU_ALIGN_PTR_UP(buf, page_size); From patchwork Sun Mar 14 21:27:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400141 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2928462jai; Sun, 14 Mar 2021 14:51:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtxk3x5I2JE6wCspb9j150ZD2l20QjiLgDJQZgqKImFAaz1cHQV21T/nSCci7dB1s5DeXL X-Received: by 2002:a25:bd89:: with SMTP id f9mr33766064ybh.380.1615758714818; Sun, 14 Mar 2021 14:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758714; cv=none; d=google.com; s=arc-20160816; b=JQUvnRdL81UeIH/nwxOh2Ys+cSAnay2PGJNCewRNs3S+4IvY/Avl2fVsihtb3Y+6bd 9FncjuzdqxZ+b9Y1/QggNdaFMSHRKqcyK9eWDNB0GL6hTAUICd+YiAcG6EHWPDjbXgYv RUGVZ9PRvNDbEMUtq8GOG8zx7nTBDN1th11tQONSppzx1H7DsUZrQHmeJYy3fNa5otqC g1w+huHZqcj7eapDyrFuiP/mWdv44KaIznY4m3u7l0Ya8FDkNNSkrQdIJ9eTX9RFtXP1 a04V9C0QJ5Zy2luH9/v6cytM1c8CIRoVZSv+JnxvhxNI0FeCztROYMECUwGS7QvfQwrt HrVQ== 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=eK04d/bo+QTgBddX7q0xdbozbAL0+oUVhNKLX/4OLZA=; b=oHRevH7ktceux78LAFPzDGkMjpgIuKJOLKJ/c5PwRJ4E7EdydLmxFnjBbYzTKLJgCU d+OMYLnSnxUQtgLuZYC1lbfeYeXuEGqtc4RdQtu5QDC8djUeEzvktH2y5efqERP69L4B vzAtpjaIxJXQ6MyoOLvH4XjmOw0MhcM6YawBS8a2lZv9glU/hdms+hAJqKKBnQMZsYIl o+p0ObC+1iqrdRNKwk6mVY9x3lq7KQy5Frg0Lm4ZrAW2SrTkpbar7tDc5HqrKuwASsYt EqI9IkkXvi1otmrIBvKLivS3WQsbG7wLHoqfYnYxQyEj7+J2djZmP8xS6B2OSYrnkcR/ R7ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=zmL8y45J; 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=fail (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 r10si13064820ybk.242.2021.03.14.14.51.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:51:54 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=zmL8y45J; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYeQ-00064D-AB for patch@linaro.org; Sun, 14 Mar 2021 17:51:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH8-0006BK-Mo for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:50 -0400 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]:34582) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH7-0008GN-0L for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:50 -0400 Received: by mail-qk1-x72c.google.com with SMTP id t4so29950123qkp.1 for ; Sun, 14 Mar 2021 14:27:48 -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 :mime-version:content-transfer-encoding; bh=eK04d/bo+QTgBddX7q0xdbozbAL0+oUVhNKLX/4OLZA=; b=zmL8y45JHUuZuFhWXxgi/ZsDWCdDLKmNjJdywF8q2VlzzTQh7n+wawJvyaliJAd7NQ LsHFQXoSde6Go3YQbMn9Ci4sWPGTz/HhBZZi+OAa3vOxTQ8rp1fpUkfuMX6jo5FFxY5M +JQEWLSxLL3GImIjDfHBkCYgmdoL9UlWO2hc2ZJWysveDFsfoZ8/TCxvxWNnA43mOmHV jE1mqK+kxLHWXu6IAze7Tb6XXgAlDid71c/DtrpB+fOaHmEdyoI50BXsRmbFcjHHRKkS YRLweATzhQuDiXRdq5gF7ITPUfZCVm9RBX6Da9jL/9CimE4hVmujE601EaqzD2QTIxCi D+OA== 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=eK04d/bo+QTgBddX7q0xdbozbAL0+oUVhNKLX/4OLZA=; b=JbZANrDqO6IWink3iCFtSBLOAiWjdnhhkZXtCaWE3jcoKU6beKGIbnSxrW0VPYJtCn fZOOCi6Vc6/Kwg/Cyltl/c6A3LRvxSN/kZcv3MxpFXSzLr+qZlY0gIt3llpiHbf3xRUX vFIU8v5XMhF9lFFlUlTd0GXd9dc0HLYYA48shbF0OpyEDjXLy2K+e5OXqjyCpFPE4vI0 ka+egSPqX4j/79EbODOqRruXnYk4U9V0ZWqhxHMB5EdNu8r297KJ72vK8toR0HRApr/X uCz42KT/wA3Lro9hiI5Kc0e/ib+JJnbbJFlJEQPCycU2SCkz2PaZjtLmEh9xaFW1ii/Q Zqqw== X-Gm-Message-State: AOAM532RCTTNp+oYI1kuFVeYD4jpSrTeNtrWXFPOwnkFlL4g5mTrI0gg RoVdtDOWrsZC0xmu8Bo+Nrk6lcOUba9nHCo2 X-Received: by 2002:a37:4690:: with SMTP id t138mr22528857qka.394.1615757268014; Sun, 14 Mar 2021 14:27:48 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 19/29] tcg: Tidy split_cross_256mb Date: Sun, 14 Mar 2021 15:27:14 -0600 Message-Id: <20210314212724.1917075-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72c; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72c.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Return output buffer and size via output pointer arguments, rather than returning size via tcg_ctx->code_gen_buffer_size. Signed-off-by: Richard Henderson --- tcg/region.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 23b3459c61..45c1178815 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -467,7 +467,8 @@ static inline bool cross_256mb(void *addr, size_t size) /* We weren't able to allocate a buffer without crossing that boundary, so make do with the larger portion of the buffer that doesn't cross. Returns the new base of the buffer, and adjusts code_gen_buffer_size. */ -static inline void *split_cross_256mb(void *buf1, size_t size1) +static inline void split_cross_256mb(void **obuf, size_t *osize, + void *buf1, size_t size1) { void *buf2 = (void *)(((uintptr_t)buf1 + size1) & ~0x0ffffffful); size_t size2 = buf1 + size1 - buf2; @@ -478,8 +479,8 @@ static inline void *split_cross_256mb(void *buf1, size_t size1) buf1 = buf2; } - tcg_ctx->code_gen_buffer_size = size1; - return buf1; + *obuf = buf1; + *osize = size1; } #endif @@ -509,12 +510,10 @@ static bool alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) if (size > tb_size) { size = QEMU_ALIGN_DOWN(tb_size, qemu_real_host_page_size); } - tcg_ctx->code_gen_buffer_size = size; #ifdef __mips__ if (cross_256mb(buf, size)) { - buf = split_cross_256mb(buf, size); - size = tcg_ctx->code_gen_buffer_size; + split_cross_256mb(&buf, &size, buf, size); } #endif @@ -525,6 +524,7 @@ static bool alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); tcg_ctx->code_gen_buffer = buf; + tcg_ctx->code_gen_buffer_size = size; return true; } #elif defined(_WIN32) @@ -583,8 +583,7 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot, /* fallthru */ default: /* Split the original buffer. Free the smaller half. */ - buf2 = split_cross_256mb(buf, size); - size2 = tcg_ctx->code_gen_buffer_size; + split_cross_256mb(&buf2, &size2, buf, size); if (buf == buf2) { munmap(buf + size2, size - size2); } else { From patchwork Sun Mar 14 21:27:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400128 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2922602jai; Sun, 14 Mar 2021 14:34:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzplw2wBBdgv1H273OmlqFgnuVPtfwbZxb5GE+DDJrvQqjXCjfBQWnkb6rAEAqAVQMuCUfQ X-Received: by 2002:a25:e0d7:: with SMTP id x206mr34360478ybg.159.1615757692169; Sun, 14 Mar 2021 14:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757692; cv=none; d=google.com; s=arc-20160816; b=I/YyhKvNdSygkzXTDs74c0t4ezYsgHsQQnDEOWllmC/187WMT50Qclp77/KGGaT91v W3GhZuPX+9ZDpP8wQQ+wpAhD173bcBkXWf/As/STOL+Am6NG5AI5Vt8KCNFZTXaTrNKh iGypa9pXXqXXqgu97FGE1HgQ04Nu51ztSNNRdxXsP9SzbXIyj2XlrjHxhje657tGmpuY kw1s5snqRXeaFVG8ikxcCBhRkK8zrhY6QhTqnIo8qLL4tLP1IUc3u2+7w4oWrlBTQL/p xejY5I725RX2rKKcoRomc/8ZIz+Ut5i355k7U4QqcCsTQvgoYRhh9Nx8c9NmaSZq8wlc XgPA== 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=R00g9ZT+DJOPXUc3gA2QBcnKHFBUn5tI+Lb3fkrnwOQ=; b=EI57CQbqV7gKeZLJV8CZztGovX6NifYwxWqBBNs1ZLkbaHlDV1BBL2245LMGJCOUJJ CmPj4OYX6NmlI62U97wvxecam0n9fpjSmSOqktpi+Ku5yAap5OPg4Gj8s/Bw6mlNPkFJ q8IoyZtsSD1VnF9eKZh5T1rkmjAh6YlGWbe1XZvBKVpXWcHcK0434B22nXWoONMdHVEL lcXWwrZ16txObzxqd7LdOr0AqZzu+h4zqbyInZ4aVgky583jtoTQj07OpysBU2+YvzLx AtSx2JBVHsnmwfGhS+wmwMwbqrm55GDPMiZnr1NQ1tC3VY1c6hOQv9aEGX2nCyZtpfF6 H+pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tcLx2D+t; 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=fail (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 r6si13161219ybl.176.2021.03.14.14.34.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:34:52 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=tcLx2D+t; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYNv-0006Dj-Jm for patch@linaro.org; Sun, 14 Mar 2021 17:34:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH9-0006DI-UZ for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:51 -0400 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]:39184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH7-0008GZ-Tw for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:51 -0400 Received: by mail-qk1-x735.google.com with SMTP id g185so29901634qkf.6 for ; Sun, 14 Mar 2021 14:27:49 -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 :mime-version:content-transfer-encoding; bh=R00g9ZT+DJOPXUc3gA2QBcnKHFBUn5tI+Lb3fkrnwOQ=; b=tcLx2D+tAV0YN0uVdnNouyBX0515LSM0jCunsUStY2Rv/JmyybskjxmMWpMj5Lb2QY H6zfxnZ+FpYk7fjSAM6oVRNi4jUStpHcof8Sc0bkXq7AdTPlQfa/0PgNXHzgpuAJ1Xft rc5b7lmi7Cw7vSrdqckIa08VVrkXpIShiSH3t4bHGgBU5cPJ3dlls/bJC7wh9ghluRNd 7Pl6OKTmrCU+yqLJ3/uKUzqJPZwLFEUvo3USq+Orq8OcBy7JSF+i55GKFLDsLeKElK44 3MCqCuBRqSp62dr2c8Zmgp8v7rkS3r+V6mmByNo/NubCDf/4tiKG/zg9HZrde5DkBQ2f inVQ== 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=R00g9ZT+DJOPXUc3gA2QBcnKHFBUn5tI+Lb3fkrnwOQ=; b=KrPBLGgAtFS+mdiaCRItnug2504gYM31BMnI+TTxeevpdBjlPvuKAO28sjNApWCOkA tFAg9hCobXryA/+4orA2A4nKwcvpmfL8F+QUhBdQZD2FPJxEexwiFCeysW/KT79oRhfd 7pVb4eHYdQjcQlTxL6CNMcSrE1/92zNvv/LJQoicDdDvpCORAe6vwv2IrCtlAEbndmqT OOnxx2XrHDC2et8iBwCmQYcJNKBH9GnynHixz4UModrOZs9MXTPW8Xx/0VgK4zVDVTo6 ljll24gAJEKm8PrPnfY3U0pR1mNcqvSj0txO9Vj0ggcH9qSonYCpKddZsRG7LshA8p8d K0VQ== X-Gm-Message-State: AOAM532ylmz7NwCRqx87eHDe+zGgk4KAu0PTfBy1PVwm4bb8ZY3+KnVa Ic4/O+SrOwjEAOaGBN6PBZeFasEb7ng0MXMG X-Received: by 2002:a05:620a:14ae:: with SMTP id x14mr22275820qkj.237.1615757269013; Sun, 14 Mar 2021 14:27:49 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 20/29] tcg: Move in_code_gen_buffer and tests to region.c Date: Sun, 14 Mar 2021 15:27:15 -0600 Message-Id: <20210314212724.1917075-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x735.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Shortly, the full code_gen_buffer will only be visible to region.c, so move in_code_gen_buffer out-of-line. Move the debugging versions of tcg_splitwx_to_{rx,rw} to region.c as well, so that the compiler gets to see the implementation of in_code_gen_buffer. This leaves exactly one use of in_code_gen_buffer outside of region.c, in cpu_restore_state. Which, being on the exception path, is not performance critical. Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 11 +---------- tcg/region.c | 34 ++++++++++++++++++++++++++++++++++ tcg/tcg.c | 23 ----------------------- 3 files changed, 35 insertions(+), 33 deletions(-) -- 2.25.1 diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index a0122c0dd3..a19deb529f 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -696,16 +696,7 @@ extern const void *tcg_code_gen_epilogue; extern uintptr_t tcg_splitwx_diff; extern TCGv_env cpu_env; -static inline bool in_code_gen_buffer(const void *p) -{ - const TCGContext *s = &tcg_init_ctx; - /* - * Much like it is valid to have a pointer to the byte past the - * end of an array (so long as you don't dereference it), allow - * a pointer to the byte past the end of the code gen buffer. - */ - return (size_t)(p - s->code_gen_buffer) <= s->code_gen_buffer_size; -} +bool in_code_gen_buffer(const void *p); #ifdef CONFIG_DEBUG_TCG const void *tcg_splitwx_to_rx(void *rw); diff --git a/tcg/region.c b/tcg/region.c index 45c1178815..bf4167e467 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -68,6 +68,40 @@ static struct tcg_region_state region; static void *region_trees; static size_t tree_size; +bool in_code_gen_buffer(const void *p) +{ + const TCGContext *s = &tcg_init_ctx; + /* + * Much like it is valid to have a pointer to the byte past the + * end of an array (so long as you don't dereference it), allow + * a pointer to the byte past the end of the code gen buffer. + */ + return (size_t)(p - s->code_gen_buffer) <= s->code_gen_buffer_size; +} + +#ifdef CONFIG_DEBUG_TCG +const void *tcg_splitwx_to_rx(void *rw) +{ + /* Pass NULL pointers unchanged. */ + if (rw) { + g_assert(in_code_gen_buffer(rw)); + rw += tcg_splitwx_diff; + } + return rw; +} + +void *tcg_splitwx_to_rw(const void *rx) +{ + /* Pass NULL pointers unchanged. */ + if (rx) { + rx -= tcg_splitwx_diff; + /* Assert that we end with a pointer in the rw region. */ + g_assert(in_code_gen_buffer(rx)); + } + return (void *)rx; +} +#endif /* CONFIG_DEBUG_TCG */ + /* compare a pointer @ptr and a tb_tc @s */ static int ptr_cmp_tb_tc(const void *ptr, const struct tb_tc *s) { diff --git a/tcg/tcg.c b/tcg/tcg.c index a82d3a0861..65f9cf01d5 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -416,29 +416,6 @@ static const TCGTargetOpDef constraint_sets[] = { #include "tcg-target.c.inc" -#ifdef CONFIG_DEBUG_TCG -const void *tcg_splitwx_to_rx(void *rw) -{ - /* Pass NULL pointers unchanged. */ - if (rw) { - g_assert(in_code_gen_buffer(rw)); - rw += tcg_splitwx_diff; - } - return rw; -} - -void *tcg_splitwx_to_rw(const void *rx) -{ - /* Pass NULL pointers unchanged. */ - if (rx) { - rx -= tcg_splitwx_diff; - /* Assert that we end with a pointer in the rw region. */ - g_assert(in_code_gen_buffer(rx)); - } - return (void *)rx; -} -#endif /* CONFIG_DEBUG_TCG */ - static void alloc_tcg_plugin_context(TCGContext *s) { #ifdef CONFIG_PLUGIN From patchwork Sun Mar 14 21:27:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400133 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2924722jai; Sun, 14 Mar 2021 14:40:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzY051H5bOx0V6vBxIYCMJF25xuPdXlayhWJe9Gp+oOt3NNPwn/nObJ7nDCPrOAnecEfQUo X-Received: by 2002:a25:d84d:: with SMTP id p74mr29486470ybg.463.1615758043358; Sun, 14 Mar 2021 14:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758043; cv=none; d=google.com; s=arc-20160816; b=XZqqdQ4di6fNKbI2Q5+6+TLNJaJ9e6t0KYlnWUqKzoH//kmkfGHi04yvFjbSbIR7O0 RrsdTXYVjXgHOmbQuP3qBqWjunem3FiVj2C8w7PM5fj6ItdZ/A6YTygDo+5BzIHzgRie 4Q7XcOxhXnj6CSmnkZW3IW0ReYqvdl3Y/KJEtHWinG5989bfNLCd6+rdfRKT+gxT6JV4 k1S74AzNmEGOAUhLZAylgl4eefavAoTvDiFLsEIItRe8CL4yeCxlqi2f7vINk8dunlak Z8zrefzvd2gNw+MOemiXoanNVvnQiwoNTYkvPksoVeBKDXATAjsvlRfgfO60uf66lPOY 4t3g== 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=pGsgpXwTM6hxqYx7HXtoXmPFsuT3pbQk6IhBOzlzD0Y=; b=IJg9FlyV0OL/lXy8ZalrY7Y6N9s53tNdYJZejO7rjIDU08R0iFW3uvsLD0rHbnnsj5 dmtCdfpjjdTmBfmk7q8pi6OUqdy363+EiZWp0LmbjDg9ic/Eh50q0PA1OPdb6Jwbr+9N 8TZ7YKcRqQ3QGY/IfsUVubnSQig6OlYplV0gLza9+wrwkg3FKiGHCe+tALn+fGEssZ0/ XIwXNsIU4mzFnFxFA40UuMvEX+Cpv0WvsNIAdfou7skYgUDcX47fwnHEqcX+tEfFN6I9 Srw9FIN4v9PvUAtHHop+Os0ICRk8m+pQdVz26m93jhsUN0eL9fO89P8yq9cGrVgp6pb7 rjTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=d6SrVOrg; 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=fail (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 b10si2201086ybr.458.2021.03.14.14.40.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:40:43 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=d6SrVOrg; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYTa-0003NN-Nk for patch@linaro.org; Sun, 14 Mar 2021 17:40:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHG-0006Jc-T4 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:59 -0400 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]:40974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH9-0008HC-39 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:58 -0400 Received: by mail-qk1-x732.google.com with SMTP id x10so29909537qkm.8 for ; Sun, 14 Mar 2021 14:27:50 -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 :mime-version:content-transfer-encoding; bh=pGsgpXwTM6hxqYx7HXtoXmPFsuT3pbQk6IhBOzlzD0Y=; b=d6SrVOrgusSushCXa6lEK6+gpvsflECleEFk5qW/xBL5r+VNXe4I/d61j1/rUPkoDO EY35Wjpe9TEw0A2Hh/Tt3TpS9qQ97h22tyv4Uc1/lr8TqPQSC3hrOR1JhpjaK2HmZ9hP wjONXH44pR0uw6zZjlJvPJtAdSHUC4kKHrl4Hxu6w+9BctnweeF+W+u6TR3L9NvCZ+eP XHkftTYNtSU4Xx6BE1puQM8UXMZ7OSmT91HmcwgHTOpFYGYCtcevEzR/emBWoFIpXBpY 6FD4aknhXKPJ0NZJow3r/cHkmYLWGwuVzjOqBq8EPgETQQNDmgtIoDXAWKStAOc58/OE 8/GA== 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=pGsgpXwTM6hxqYx7HXtoXmPFsuT3pbQk6IhBOzlzD0Y=; b=mHIS1RK6Vvg8UCCh2a4tsmVeIqVKENlpW5O+BMMQIxNpj7IB11JLYUdiDJp+7p7q6l aA8Ou5Hh2SAYolO0yAB/VqigRra3ozNjBVAUCTrb4wuq+452YM0J1XnXlyqLwRnF3Y3U 1/Hsv6MK8+TZNTcWSYBhXnzDNIEvb/X0ofdLLQRPsgubzPCtCO6k3Z95JEJrdU85KmGA YNejU/QdomJ2Rpxudxuec3vz0nxB+yrtSSmujfmW2r2mQnLjQyhZrmSUxV+5Ct0CEkA2 dn333eoyZR4akqHN1MML1aiS8DmRflMM9hn28ihygqHzI7HpQbMj6+cJ7U6nPhWdO7Y4 qVyg== X-Gm-Message-State: AOAM530z7P+8Wmo0eb628I1n8WmIu9iJ6Iv3uTrAS6Ke50hBbAABJdpT n1Tb+5jwMStId1ISIX3hrVJdlyQHevqXqtpy X-Received: by 2002:a05:620a:1528:: with SMTP id n8mr869589qkk.329.1615757269989; Sun, 14 Mar 2021 14:27:49 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 21/29] tcg: Allocate code_gen_buffer into struct tcg_region_state Date: Sun, 14 Mar 2021 15:27:16 -0600 Message-Id: <20210314212724.1917075-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::732; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x732.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Do not mess around with setting values within tcg_init_ctx. Put the values into 'region' directly, which is where they will live for the lifetime of the program. Signed-off-by: Richard Henderson --- tcg/region.c | 64 ++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 37 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index bf4167e467..9a2b014838 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -70,13 +70,12 @@ static size_t tree_size; bool in_code_gen_buffer(const void *p) { - const TCGContext *s = &tcg_init_ctx; /* * Much like it is valid to have a pointer to the byte past the * end of an array (so long as you don't dereference it), allow * a pointer to the byte past the end of the code gen buffer. */ - return (size_t)(p - s->code_gen_buffer) <= s->code_gen_buffer_size; + return (size_t)(p - region.start_aligned) <= region.total_size; } #ifdef CONFIG_DEBUG_TCG @@ -557,8 +556,8 @@ static bool alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) } qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); - tcg_ctx->code_gen_buffer = buf; - tcg_ctx->code_gen_buffer_size = size; + region.start_aligned = buf; + region.total_size = size; return true; } #elif defined(_WIN32) @@ -579,8 +578,8 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) return false; } - tcg_ctx->code_gen_buffer = buf; - tcg_ctx->code_gen_buffer_size = size; + region.start_aligned = buf; + region.total_size = size; return true; } #else @@ -595,7 +594,6 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot, "allocate %zu bytes for jit buffer", size); return false; } - tcg_ctx->code_gen_buffer_size = size; #ifdef __mips__ if (cross_256mb(buf, size)) { @@ -633,7 +631,8 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot, /* Request large pages for the buffer. */ qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); - tcg_ctx->code_gen_buffer = buf; + region.start_aligned = buf; + region.total_size = size; return true; } @@ -654,8 +653,8 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **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; + buf_rx = region.start_aligned; + size = region.total_size; #endif buf_rw = qemu_memfd_alloc("tcg-jit", size, 0, &fd, errp); @@ -677,8 +676,8 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) #endif close(fd); - tcg_ctx->code_gen_buffer = buf_rw; - tcg_ctx->code_gen_buffer_size = size; + region.start_aligned = buf_rw; + region.total_size = size; tcg_splitwx_diff = buf_rx - buf_rw; /* Request large pages for the buffer and the splitwx. */ @@ -729,7 +728,7 @@ static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp) return false; } - buf_rw = (mach_vm_address_t)tcg_ctx->code_gen_buffer; + buf_rw = region.start_aligned; buf_rx = 0; ret = mach_vm_remap(mach_task_self(), &buf_rx, @@ -841,11 +840,8 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) */ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) { - void *buf, *aligned, *end; - size_t total_size; size_t page_size; size_t region_size; - size_t n_regions; size_t i; uintptr_t splitwx_diff; bool ok; @@ -854,39 +850,33 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) splitwx, &error_fatal); assert(ok); - buf = tcg_init_ctx.code_gen_buffer; - total_size = tcg_init_ctx.code_gen_buffer_size; - page_size = qemu_real_host_page_size; - n_regions = tcg_n_regions(total_size, max_cpus); - - /* The first region will be 'aligned - buf' bytes larger than the others */ - aligned = QEMU_ALIGN_PTR_UP(buf, page_size); - g_assert(aligned < tcg_init_ctx.code_gen_buffer + total_size); - /* * Make region_size a multiple of page_size, using aligned as the start. * As a result of this we might end up with a few extra pages at the end of * the buffer; we will assign those to the last region. */ - region_size = (total_size - (aligned - buf)) / n_regions; + region.n = tcg_n_regions(region.total_size, max_cpus); + page_size = qemu_real_host_page_size; + region_size = region.total_size / region.n; region_size = QEMU_ALIGN_DOWN(region_size, page_size); /* A region must have at least 2 pages; one code, one guard */ g_assert(region_size >= 2 * page_size); + region.stride = region_size; + + /* Reserve space for guard pages. */ + region.size = region_size - page_size; + region.total_size -= page_size; + + /* + * The first region will be smaller than the others, via the prologue, + * which has yet to be allocated. For now, the first region begins at + * the page boundary. + */ + region.after_prologue = region.start_aligned; /* init the region struct */ qemu_mutex_init(®ion.lock); - region.n = n_regions; - region.size = region_size - page_size; - region.stride = region_size; - region.after_prologue = buf; - region.start_aligned = aligned; - /* page-align the end, since its last page will be a guard page */ - end = QEMU_ALIGN_PTR_DOWN(buf + total_size, page_size); - /* account for that last guard page */ - end -= page_size; - total_size = end - aligned; - region.total_size = total_size; /* set guard pages */ splitwx_diff = tcg_splitwx_diff; From patchwork Sun Mar 14 21:27:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400129 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2923551jai; Sun, 14 Mar 2021 14:37:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvLg1ajSIIZbIvUAkxVIKmDNzvL+Hx/xnICcDfBi/f3+46IsVOK22k2lunl1ESsRwAF5Gl X-Received: by 2002:a25:da0e:: with SMTP id n14mr33942895ybf.356.1615757837912; Sun, 14 Mar 2021 14:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757837; cv=none; d=google.com; s=arc-20160816; b=oBHAFjxpgDavKIw1utt4kT7S7WZOwnNAus5Tdl0pByPnjn+80RauQ533Ws6LpFjSE5 QuOMWKCh0vQurfb7J5jr04/kMkckObvpyd3vImSM65c1onVA8RAate+VYMfyure71Vfw hL21KC1NhIuEP3gWsIKvMBY5p1Yn0vTODo4JAeKwyUNXhjtzgra35sNTnddDX+a62f0R 8HqS+aIRNbzDNN5AD389wz+YyPKK2pODbEpzZrEklgjQufODnlusByGY7LyTvtdmKS9C pHF5l/hM7nvApqBZmr3QxpEEDb0nNTzM5JytIjxBVOhj/q5EinEumF6M9Y/ywtFv1Rq8 AP/w== 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=YV8ZNMURZZ3L0f8Vp87koNwJMeD7v42xnjMnrSbn74s=; b=X/B49LExS4TGFj6yslw/PE0qiaTCu0Kzq/6/1P4XsovdIzS8qRlRO4KYIU1VgfDMhL ptSkTFmdYo3yOhVzuX757ftEb4yZxxy3k0PHTyARzzTHEY+2K5IDOFIErLT4MmQ/sR7f d3EQ5uxN3a1ZuDCcqa+NsbVUcGiHCw3F/aqdkgAmfmpNjYN9lseGseuXA/pNRgGahGbF mWl8tgqbyD9UYcuQ93qNoDGou58T8Cp8lzALqR5tl2R/qYyjMfbl1cBD7emznJ/GOKPD QN3ctLnv4anlrbJ6Nur9fxho0X0ABkzohu3VD6UpIESylVXikHFl3TW4TmrM9xxALSbb 0rGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="G/GKf+jy"; 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=fail (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 q12si13411422ybm.8.2021.03.14.14.37.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:37:17 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b="G/GKf+jy"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYQH-0008EX-8M for patch@linaro.org; Sun, 14 Mar 2021 17:37:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHF-0006IO-Dk for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:57 -0400 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:40077) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH9-0008I2-Up for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:57 -0400 Received: by mail-qk1-x729.google.com with SMTP id l132so29919835qke.7 for ; Sun, 14 Mar 2021 14:27:51 -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 :mime-version:content-transfer-encoding; bh=YV8ZNMURZZ3L0f8Vp87koNwJMeD7v42xnjMnrSbn74s=; b=G/GKf+jyTtrCb5jZ/WK4pjpQvUY2h+fSYS8bgspdsQ4WTmcyBPk5un0d26TiKoevlr pUo+2uhOMxy652NJ3qV7SBu9G5NQBSrDormieg71n6+L1n/mFdwzbwdjX7kFVjuB5dg/ L1edFEZIdcTo2F2dvG1Z+li6g44Ce8YyM4Xu13mAwZlhuA0XXxD8eaKlIxm8Sw0RfsGC sJK8rJ3g2GYR6QFrjk8OSEMjo6fbXrVQ9fDvkbI2HKaXrFVuA+1ivZXycc2cZOayLJLE r3cgVTt8weZOjGLUSItsCKc5n9JYVQEBglLHYYv0uovMF3qhT3lJh3PN0j0lKJ8DdFOR I9/g== 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=YV8ZNMURZZ3L0f8Vp87koNwJMeD7v42xnjMnrSbn74s=; b=Rt3l3ZEAGr0ZrEJPstWYbcU9MmbLNbFT6fgO1BVEciqWuBXO75TCP3UVzyA2lOMEBb pVFsBBl+hJCfWOLZRzq2z1tD8t/f3K9BX033pnWDaENdKHjgmfQdTUCVw4JTTCCXE6TU wh4Cu9OsJ4Q0XyzWyiF4M5VBDPhzwZYv7q6ED8mKEikdNJ7cnM6YQ+i76Cjbd2iP/aGS ohe18tZMtmjbe+Ljdmyr9xsWUlLfN734ytButPLxVFB2N9yAiC5rEAxlYSiKperrFJvf 3ts/0cZlMhxCwG+QzHR/O9N1/lyYoT+CbJHGZ126v3xQEmk4/TvfY9WbOpKrN6S8STU4 GBIg== X-Gm-Message-State: AOAM530HgSX0ERkBeYrsXlmhUDm77IL88eI3NkOgBdWBMI2jWrLxqOv/ wVkXmS81o9GJsR5Pn0FN1jkRWOp+aY1Qhlyy X-Received: by 2002:a05:620a:9c6:: with SMTP id y6mr22722924qky.39.1615757270982; Sun, 14 Mar 2021 14:27:50 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 22/29] tcg: Return the map protection from alloc_code_gen_buffer Date: Sun, 14 Mar 2021 15:27:17 -0600 Message-Id: <20210314212724.1917075-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::729; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x729.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Change the interface from a boolean error indication to a negative error vs a non-negative protection. For the moment this is only interface change, not making use of the new data. Signed-off-by: Richard Henderson --- tcg/region.c | 63 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/tcg/region.c b/tcg/region.c index 9a2b014838..3ca0d01fa4 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -521,14 +521,14 @@ static inline void split_cross_256mb(void **obuf, size_t *osize, static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] __attribute__((aligned(CODE_GEN_ALIGN))); -static bool alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) +static int alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) { void *buf, *end; size_t size; if (splitwx > 0) { error_setg(errp, "jit split-wx not supported"); - return false; + return -1; } /* page-align the beginning and end of the buffer */ @@ -558,16 +558,17 @@ static bool alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) region.start_aligned = buf; region.total_size = size; - return true; + + return PROT_READ | PROT_WRITE; } #elif defined(_WIN32) -static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) +static int alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) { void *buf; if (splitwx > 0) { error_setg(errp, "jit split-wx not supported"); - return false; + return -1; } buf = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, @@ -580,11 +581,12 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) region.start_aligned = buf; region.total_size = size; - return true; + + return PAGE_READ | PAGE_WRITE | PAGE_EXEC; } #else -static bool alloc_code_gen_buffer_anon(size_t size, int prot, - int flags, Error **errp) +static int alloc_code_gen_buffer_anon(size_t size, int prot, + int flags, Error **errp) { void *buf; @@ -592,7 +594,7 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot, if (buf == MAP_FAILED) { error_setg_errno(errp, errno, "allocate %zu bytes for jit buffer", size); - return false; + return -1; } #ifdef __mips__ @@ -633,7 +635,7 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot, region.start_aligned = buf; region.total_size = size; - return true; + return prot; } #ifndef CONFIG_TCG_INTERPRETER @@ -647,9 +649,9 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) #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)) { + if (alloc_code_gen_buffer_anon(size, PROT_NONE, + MAP_PRIVATE | MAP_ANONYMOUS | + MAP_NORESERVE, errp) < 0) { return false; } /* The size of the mapping may have been adjusted. */ @@ -683,7 +685,7 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) /* Request large pages for the buffer and the splitwx. */ qemu_madvise(buf_rw, size, QEMU_MADV_HUGEPAGE); qemu_madvise(buf_rx, size, QEMU_MADV_HUGEPAGE); - return true; + return PROT_READ | PROT_WRITE; fail_rx: error_setg_errno(errp, errno, "failed to map shared memory for execute"); @@ -697,7 +699,7 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) if (fd >= 0) { close(fd); } - return false; + return -1; } #endif /* CONFIG_POSIX */ @@ -716,7 +718,7 @@ extern kern_return_t mach_vm_remap(vm_map_t target_task, vm_prot_t *max_protection, vm_inherit_t inheritance); -static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp) +static int alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp) { kern_return_t ret; mach_vm_address_t buf_rw, buf_rx; @@ -725,7 +727,7 @@ static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp) /* Map the read-write portion via normal anon memory. */ if (!alloc_code_gen_buffer_anon(size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, errp)) { - return false; + return -1; } buf_rw = region.start_aligned; @@ -745,23 +747,23 @@ static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp) /* TODO: Convert "ret" to a human readable error message. */ error_setg(errp, "vm_remap for jit splitwx failed"); munmap((void *)buf_rw, size); - return false; + return -1; } if (mprotect((void *)buf_rx, size, PROT_READ | PROT_EXEC) != 0) { error_setg_errno(errp, errno, "mprotect for jit splitwx"); munmap((void *)buf_rx, size); munmap((void *)buf_rw, size); - return false; + return -1; } tcg_splitwx_diff = buf_rx - buf_rw; - return true; + return PROT_READ | PROT_WRITE; } #endif /* CONFIG_DARWIN */ #endif /* CONFIG_TCG_INTERPRETER */ -static bool alloc_code_gen_buffer_splitwx(size_t size, Error **errp) +static int alloc_code_gen_buffer_splitwx(size_t size, Error **errp) { #ifndef CONFIG_TCG_INTERPRETER # ifdef CONFIG_DARWIN @@ -772,24 +774,25 @@ static bool alloc_code_gen_buffer_splitwx(size_t size, Error **errp) # endif #endif error_setg(errp, "jit split-wx not supported"); - return false; + return -1; } -static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) +static int alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) { ERRP_GUARD(); int prot, flags; if (splitwx) { - if (alloc_code_gen_buffer_splitwx(size, errp)) { - return true; + prot = alloc_code_gen_buffer_splitwx(size, errp); + if (prot >= 0) { + return prot; } /* * If splitwx force-on (1), fail; * if splitwx default-on (-1), fall through to splitwx off. */ if (splitwx > 0) { - return false; + return -1; } error_free_or_abort(errp); } @@ -844,11 +847,11 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) size_t region_size; size_t i; uintptr_t splitwx_diff; - bool ok; + int have_prot; - ok = alloc_code_gen_buffer(size_code_gen_buffer(tb_size), - splitwx, &error_fatal); - assert(ok); + have_prot = alloc_code_gen_buffer(size_code_gen_buffer(tb_size), + splitwx, &error_fatal); + assert(have_prot >= 0); /* * Make region_size a multiple of page_size, using aligned as the start. From patchwork Sun Mar 14 21:27:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400130 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2923560jai; Sun, 14 Mar 2021 14:37:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7+qNUVM2P2tnKfEZEDksGTkJ8wBjyAluy+2h9I7etB4ykXkFXcRQZpbl96P3tkZJFrg8q X-Received: by 2002:a25:cb8a:: with SMTP id b132mr33961957ybg.58.1615757838769; Sun, 14 Mar 2021 14:37:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757838; cv=none; d=google.com; s=arc-20160816; b=NZUlZaS9Tnso15EQW5hA483jHm2+KkljyojuzjCLIFKJBWyq8WEMH9cbZE0E8aZDhC PPHIilvvaKffEN4AwdrRBo69Y+inZ+INuc17GtEBJoPPtc7J0wAO50EYds2Y++NZiVrl UvmYurONFObtFobou6c0XEgcYS7jkh2ouwqqSckImTm4A8XnitmHrIsUX+B1nmN/eovZ iJseEEbR6OToAoLVn4HO1A/sv04YwZo6gX8/++ZjhrTd1rjW0Lvvc7C3t5P5XUwtniDA AIDQatPtuoM/ckpD9tcIVmOyg1F86+vZdM3sXMeX9pbvoO20ZugAILVhuB7alvMuJCWk mfng== 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=GL6gIGaWt/dCjMwMHmq6bzPQkZftRPDs8LLZAcbEC+c=; b=n0ZOkBNM2pYuDaPTGPUOv/0humpsCTJKZGQT2Z9/iJi8MX6r3woxH5iHy0bwblSPgI UxBGpm9TdZ54GgbUT1axaz1++q9Bey+cbRwNEBf+f7nVQdgKrKU40FT3+/2OVXHn2ZvQ g5BiexyxFRn314S+5jPEWopSLIoLMBs4r23SqcX9e5VD9rLDctx5vkA588EK1ZyKGTRO YiPRawUoyG8uZ0b76IR5eFjxlE3DVT1G/zwOqovCdeKLmPeJgKuirxnGaNS3AQZvFcCs yMJjTWvJqu08AP1tdtPcJVtT+i7KRNdKcf6Ou1Nfo039zpiBo5kaRshnnqGcHOcDWq87 N9pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ARggv7oK; 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=fail (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 c13si13284661ybr.140.2021.03.14.14.37.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:37:18 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=ARggv7oK; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYQI-0008Jd-6F for patch@linaro.org; Sun, 14 Mar 2021 17:37:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHD-0006Hf-G5 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:56 -0400 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]:43182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHB-0008IA-0y for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:55 -0400 Received: by mail-qk1-x72e.google.com with SMTP id b130so29890291qkc.10 for ; Sun, 14 Mar 2021 14:27:52 -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 :mime-version:content-transfer-encoding; bh=GL6gIGaWt/dCjMwMHmq6bzPQkZftRPDs8LLZAcbEC+c=; b=ARggv7oKTaE1LTeM3+EVE4/BvENkXP73vxe7LDDMK+nUoL6FGWX1icF4vulJ/1VAKr izTIfBcb166OcJZEfzZNj8BCj3bM2tQGH+Cr8eiYSeXjBVNXCWulAPiWCjlq9mLrWTO2 5eD7GAx6K22O88aq/DTg+S/R1QsaTwhheIRqkHeIh2uxM/vfbzwvwWt5RcvKT7nr4/qZ fNsYFRtuzgJNJ7UV/6NB67SLPLkfBilkJm5nWnVnZACtKxtMGhluCSnFb4DGKfm9ONqC 06GOKgWlQKnABLIZ3QUt/cYys15XMdnPlPpSDUWTtrkzO8nmWLX+pG7JSRIMuVyatoNr rilg== 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=GL6gIGaWt/dCjMwMHmq6bzPQkZftRPDs8LLZAcbEC+c=; b=MK+lHwdKDI/+z+WXJJEPl4Tj3GYz9FazLIyLWpzR70MtsGTyzKMN/c32hWqXpSMkNZ Px+w3/CVfdKqHlWemBwEWjUwbFI2YaG7Nt2vKHiJ/TICBcXKZu9fiDhtLp6H/od4PlOR kZoBJrS30D1DUOETmXyb0YKnnoafrpfAH1UWKzsHGaSV3Tm1uP7tHAcQPGvtAuC85h2g 02IX/TQsJGTbEirNOl2GLuAbLFqNVD0hfo5qd3YbDNXkytFPhoJ4WgwQnKnXeyo9wcsB 7I6WVHXr0lE5UApTl7OP6GRSt8zd05mC/Y6xYdAeBlB250FSxXd+ViDrOQfXpUgE3NB2 vRTQ== X-Gm-Message-State: AOAM530PV4FSDQo1dJ/5hbNzg1F3PpParz6NjBsNFCtepog2A4CYvW8b 01UgCxsNLf8Jg2zagTVHbs2Eh6E2/PR40Ij/ X-Received: by 2002:a05:620a:404a:: with SMTP id i10mr22773089qko.2.1615757272103; Sun, 14 Mar 2021 14:27:52 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 23/29] tcg: Sink qemu_madvise call to common code Date: Sun, 14 Mar 2021 15:27:18 -0600 Message-Id: <20210314212724.1917075-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72e; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72e.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Move the call out of the N versions of alloc_code_gen_buffer and into tcg_region_init. Signed-off-by: Richard Henderson --- tcg/region.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 3ca0d01fa4..994c083343 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -554,7 +554,6 @@ static int alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) error_setg_errno(errp, errno, "mprotect of jit buffer"); return false; } - qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); region.start_aligned = buf; region.total_size = size; @@ -630,9 +629,6 @@ static int alloc_code_gen_buffer_anon(size_t size, int prot, } #endif - /* Request large pages for the buffer. */ - qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); - region.start_aligned = buf; region.total_size = size; return prot; @@ -682,9 +678,6 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) region.total_size = size; tcg_splitwx_diff = buf_rx - buf_rw; - /* Request large pages for the buffer and the splitwx. */ - qemu_madvise(buf_rw, size, QEMU_MADV_HUGEPAGE); - qemu_madvise(buf_rx, size, QEMU_MADV_HUGEPAGE); return PROT_READ | PROT_WRITE; fail_rx: @@ -853,6 +846,13 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) splitwx, &error_fatal); assert(have_prot >= 0); + /* Request large pages for the buffer and the splitwx. */ + qemu_madvise(region.start_aligned, region.total_size, QEMU_MADV_HUGEPAGE); + if (tcg_splitwx_diff) { + qemu_madvise(region.start_aligned + tcg_splitwx_diff, + region.total_size, QEMU_MADV_HUGEPAGE); + } + /* * Make region_size a multiple of page_size, using aligned as the start. * As a result of this we might end up with a few extra pages at the end of From patchwork Sun Mar 14 21:27:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400131 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2923645jai; Sun, 14 Mar 2021 14:37:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0CJKQ8UJuCfTSx9Dzyywi6WNxB5VfMthIoqza+DNqzLLfNmZwhNxSzMKTfyn9yfVHl/Z3 X-Received: by 2002:a25:8006:: with SMTP id m6mr33164839ybk.336.1615757849991; Sun, 14 Mar 2021 14:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615757849; cv=none; d=google.com; s=arc-20160816; b=ddFX1C4QTjxspLMLoijIkB4J6NAs3mTQqMHCIYufSFWSUKNfBvXUmzBgwIOD685ADD srw7J16GCru0O/hKcyZPoU+UO/HitZfQ8bg5+DU839H5hKVQs05Eh/05v+VA0hWi2oEo gts0qy5IIgfa3FxiY+JtX+xWCpzOD4IfxxTJ8WhpZ2VEmjBpKp3RcF7DdeKHK/dUhSrz vHqzC5UEFlCmn48SGEdVh4axebC5IGjNK0YlcLjAaeyo/kOC+i0bWmi5LmmVoXiPsJ1j g8BFvoZWzFgl/1pk3igsxuK/PqE2mVXCX0QU/9Uwau38SWBRQcxXoQZEHzjVXDCT7DXY 6k6Q== 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=dbOIDgtK5Y740kNmX5rEOHFZVjBYbVNjCLgwvbDsCnc=; b=LuWkJnjnVb5k6pba9lMU0ZepqAL20FzNGqyDJ/mO/2MNs6MbeOaS9nozpymPee0OgB lPLUmFIIng2XxgOBellEtYxRqRXN6eMLD14MHlmFPQmmwVq4b2Pj7j53sRgBQK3cfZJd F89/blRgyH0aSKJnXXdef6Zev7GMJ8hV0tLPyMZNhEjT4EJfOZaPR/PI1qM+0SSA5W6b ykqnDDKzSEBHpx5WXhUSRmQciDMWadSjGogo+L1A8Iiiew1LUDF5XkEG7bT35AhXHH6W TmM0rQBCwDOJTW+wz1MBCiMmXK1og7cpj7Qw0039+suDlPsJDyUkaiyhwIdYr+oWa4Fv 2/Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="wSkZk/aX"; 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=fail (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 x17si12993936ybl.290.2021.03.14.14.37.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:37:29 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b="wSkZk/aX"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYQT-0001Nl-CO for patch@linaro.org; Sun, 14 Mar 2021 17:37:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHH-0006K9-Em for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:59 -0400 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]:35368) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHC-0008IF-TU for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:59 -0400 Received: by mail-qk1-x735.google.com with SMTP id d20so29929245qkc.2 for ; Sun, 14 Mar 2021 14:27:53 -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 :mime-version:content-transfer-encoding; bh=dbOIDgtK5Y740kNmX5rEOHFZVjBYbVNjCLgwvbDsCnc=; b=wSkZk/aXvYc046TWbwqTWpUsoI81YkzWwYchqJLNrF1yWkytSHqGix+Q6UlE8oQ0Kh MPPWns5Q2+x30dqUyMDPf5jyF052zQH8fECOrobmbJGPK0p56dQTSdz0GRt8O20QMwNO pukS+KE8ErqgZl/OwH764fVjv1rSngiJ+d7It5ux+w+0ejKcgP3d8gPWIDvwzzi0a8NL puGqnRs1cXrmf4EeJc2djcdSSdtnYRfqzTxIytZmyByg49MzGMd543CbSXDhoGviQPws ElUVk/O2x1IFAEJC5FPIXJu7nvBSRja7m851n9ZRqlO9w0i5gx08clNwTaPJoMUu+c+w rOjw== 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=dbOIDgtK5Y740kNmX5rEOHFZVjBYbVNjCLgwvbDsCnc=; b=qo7zWSf8qgMnhfRFA7fNLHiwtHqceu6vZq9NUbdYspP5NyRtqGf7bcxXXBXyF8Duzw 4vKVK+FWRBdesMERWd3Hn5cmkrl50EKlAFAzLibcyfCliXOsPLt5/2+dWa3WUZFhk6pe puw+EVrrcBntRfrr037pfrEdTcbteQlBDJDfwD04Tb7w2Oi8yMfwfpalOmHnwWlb02cu SQSs+cpQzyM7pTCypVTPiuHv8McqdrxM+kyWdc+UkiKcW4Y4hqZflKgZk2DmbZG93w+/ PHPjlDcgtI0rkyDkbgpk9r4+MPqGixduXtd4/RpSODW4k8kJdWIb0AAtMDdsjYB6ZRvx /W6A== X-Gm-Message-State: AOAM531uxj/ELg7S2I7CSJaEdO5wK3G+SR5bXHcyXyczcd3SZB2n5d9E lZbcHU1f7MhXHV3fdv/6Nzh5Doxn7NjyMmdG X-Received: by 2002:a37:8743:: with SMTP id j64mr21469640qkd.299.1615757273247; Sun, 14 Mar 2021 14:27:53 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 24/29] tcg: Do not set guard pages in the rx buffer Date: Sun, 14 Mar 2021 15:27:19 -0600 Message-Id: <20210314212724.1917075-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x735.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We only need guard pages in the rw buffer to avoid buffer overruns. Let the rx buffer keep large pages all the way through. Signed-off-by: Richard Henderson --- tcg/region.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 994c083343..27a7e35c8e 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -839,7 +839,6 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) size_t page_size; size_t region_size; size_t i; - uintptr_t splitwx_diff; int have_prot; have_prot = alloc_code_gen_buffer(size_code_gen_buffer(tb_size), @@ -881,8 +880,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) /* init the region struct */ qemu_mutex_init(®ion.lock); - /* set guard pages */ - splitwx_diff = tcg_splitwx_diff; + /* Set guard pages. No need to do this for the rx_buf, only the rw_buf. */ for (i = 0; i < region.n; i++) { void *start, *end; int rc; @@ -890,10 +888,6 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) tcg_region_bounds(i, &start, &end); rc = qemu_mprotect_none(end, page_size); g_assert(!rc); - if (splitwx_diff) { - rc = qemu_mprotect_none(end + splitwx_diff, page_size); - g_assert(!rc); - } } tcg_region_trees_init(); From patchwork Sun Mar 14 21:27:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400146 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2931693jai; Sun, 14 Mar 2021 15:01:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzI8Y3niQ1G1a5G06h5TatE7o44a7543kbLX1eVAXhwbazGIgwHWVQilVOuvp2IQMZyhLp9 X-Received: by 2002:a02:7419:: with SMTP id o25mr7107998jac.100.1615759272436; Sun, 14 Mar 2021 15:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615759272; cv=none; d=google.com; s=arc-20160816; b=JMcM6ZkhxzonIfXluW2R+hrx17El2DRtKIfbwXqOTguSOPbtAfbeTv4Jt5TsrWHTtj fZwdoIWoJz1PKf3V8vZcPTGIkKBRFmUy46cz06TDRls7yLhuZZdkVz5BRT6VVBvhg8Gb BnNIJViIepeWJqNzLAJd77c32wpONeK7h0X9DANbuet0tJQ0+6F5oH+Z6lnYl9uBVz2U GeE83VHWyk3zwxAHeqRzq3NMCRiSzn4roBml9pripMHZayKybk4WhdNU76yc/T0iePTn 4ut5L+GEP+k7lA8lZmZCHf+L2ZZ2PN6WmhdQfyRnbJZcc+GhAlyDTHPJQoklvoiIwE/N 7lzw== 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=4eSiYZLqamkXwsALfLyClM+caXgQ2VvDhj6YMhAvyBg=; b=AN+a4Gq0SG/DqcVMGsAluT6AasohN+ZAmUpbQCfMYlnovni8czsSufhW5GSoAiJSU7 hOszfsVdI25ryZYAV8ye3UJuCEcorXDGww5D8L/2RTidN59rLooucLGgHY4/ifSO9oLA 2Fbod2Lxt2CV8vGsWMHnIisR46NKncswGJREMLJ2n+OMJE2iywnEq3ViKg+LMrQm2VoA NVzDy0nJtMG80IKPZWoTgn5MST1SvBTdIKoAesL3qHKVHksQriPN5tZeB7ObYzxM1vCZ qWpqnywoczXAhd9EDxWAf2zB9ZXkDx/bha1Nf4/+gQTIGbTo7Tjz0umrizHSZXOU5TZA 07CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DiVwRfe2; 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=fail (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 b3si10329802ile.22.2021.03.14.15.01.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 15:01:12 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=DiVwRfe2; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYnP-00033F-Rz for patch@linaro.org; Sun, 14 Mar 2021 18:01:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHK-0006Qi-ON for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:02 -0400 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]:46076) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHE-0008IK-PD for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:02 -0400 Received: by mail-qk1-x72e.google.com with SMTP id m186so13276889qke.12 for ; Sun, 14 Mar 2021 14:27:55 -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 :mime-version:content-transfer-encoding; bh=4eSiYZLqamkXwsALfLyClM+caXgQ2VvDhj6YMhAvyBg=; b=DiVwRfe2SuZ8YJjM8a5GDNpBlolBIM5CsmH/gblZWiUdd9HlkpYZZP8obkufpJLUIt gCM3OJNOJp3Oy4b4UdhuZIURNcoAaKJPgF7DeitKjuL+tirjER7rVXkENPM3KE3T3GD1 IRbIdVleijvG8mcKc7Wk1N1Uwtn9mQLJqVCVIc5Fno37BdSc3gPy8crgXvkbqwrfVCrT XXIOjXjRxtQiGQTFIpA6K36IJJFqsvYjZ8/q1xWA95JtXZYpi+jy1X/ghIMI1YPgrt82 snuQOYCdaAKOtl34eosIIf+DaGGK4YK/wJCy495vYKqfHK2iIa9hvSBaLrj/ZxUnGtS3 N08w== 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=4eSiYZLqamkXwsALfLyClM+caXgQ2VvDhj6YMhAvyBg=; b=g5Q1Qs7FeMVokMmp5wottd70bEB6ZurKYIm2cjAlM6aynTl6Em76euOqzMBEKF9+vR eYhtAgNC/Unp1sOgXwjoPmOHeNuzurKsMLgqDOYMb3/1CJvByG5Q/2wLLYh3ysrPqKFu 1Dt0LiMKOLJyI0edYM8BUyOCA0WH3H4gTOZ1XgpB+/PHGMyOpwMN1d2Q0aXX15Lge1Cj Elrert41uetbxpo2NSjBdWo1NxRVrnV9k9hShRUoYh4PKiAY2eTEHK78Nvr+tYppHp0D R8icZRnmUUWhj2mxnukXQEJ/h4IL6HoJixi1iWLGxjsNQOW2BS9FPv0YBV6khL8x3ESI H7Mg== X-Gm-Message-State: AOAM531DC4XxPlGfeidJv7C9c2v9OGj3K9hKWIy/zBJOffVdHRNIJAzS 88KrcyCYcXub1uKx4Jg/qwfDUTLDV76B5ZWn X-Received: by 2002:a05:620a:1001:: with SMTP id z1mr21770585qkj.364.1615757274702; Sun, 14 Mar 2021 14:27:54 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 25/29] util/osdep: Add qemu_mprotect_rw Date: Sun, 14 Mar 2021 15:27:20 -0600 Message-Id: <20210314212724.1917075-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72e; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72e.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: r.bolshakov@yadro.com, j@getutm.app, =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For --enable-tcg-interpreter on Windows, we will need this. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/qemu/osdep.h | 1 + util/osdep.c | 9 +++++++++ 2 files changed, 10 insertions(+) -- 2.25.1 diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index ba15be9c56..5cc2e57bdf 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -494,6 +494,7 @@ void sigaction_invoke(struct sigaction *action, #endif int qemu_madvise(void *addr, size_t len, int advice); +int qemu_mprotect_rw(void *addr, size_t size); int qemu_mprotect_rwx(void *addr, size_t size); int qemu_mprotect_none(void *addr, size_t size); diff --git a/util/osdep.c b/util/osdep.c index 66d01b9160..42a0a4986a 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -97,6 +97,15 @@ static int qemu_mprotect__osdep(void *addr, size_t size, int prot) #endif } +int qemu_mprotect_rw(void *addr, size_t size) +{ +#ifdef _WIN32 + return qemu_mprotect__osdep(addr, size, PAGE_READWRITE); +#else + return qemu_mprotect__osdep(addr, size, PROT_READ | PROT_WRITE); +#endif +} + int qemu_mprotect_rwx(void *addr, size_t size) { #ifdef _WIN32 From patchwork Sun Mar 14 21:27:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400143 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2929653jai; Sun, 14 Mar 2021 14:55:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjcEyEx2ic/QpUbRC7zO1GaXnL6HLCu9+OiVWhTwdsqIRQUXwKg8yPXbz74u3dQ1eUbmkh X-Received: by 2002:a25:254a:: with SMTP id l71mr33096824ybl.204.1615758930663; Sun, 14 Mar 2021 14:55:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758930; cv=none; d=google.com; s=arc-20160816; b=wOXMIzXvKo5dqafa5XiKQTYeU4K/It2zU9Y8FoOYpcLcs/BZUQTqISPtjefWjmHox/ +q0S5w7w4Dmw2JS9l4FyC6UXfpnV/8KHXXRghs4pw3gZOzztjFSuWM1LFQRriDqwdj+K 8sonOtHRkQs+YPYbGQB57ncH3udcU5VTdPt9Z4IB15Bcx6szPCnRl+tolR9R23fp9acq bWhABZ9ypa5boxb8cLYay5nd13Z1lRh0JW+vcbsgffLGBgvLdFzDoA+y8o8JyIdFq0Zq 31j21c+KqPzMiay4flb4GVySydG6rDCXRE8cZGh3n+0SNxcxNeeRktoB/zZP8GfmT43l vc3Q== 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=JZdn6ANaU4aV5zRIqP0A2KkQ5u2MmsLTSCDf8HK0t+o=; b=IGgSILUgOJzWp2iQieLXC/Rv/jfoeSfRBBcgSBbo8SSrmxXRlWqJnjhifJ/uuH66L7 gtD+HbbN/dtXDfk5G836uxsPQfF7Ge+6fiSSWSfpgIBb4Ack5VGtf08UNDFp8nqH9bAb hKyIhvvC5G7rFeD3azR42i4zb8uQThSQBaKSfRQ5xnL7Vwb+a71v4IyYMT6AleJPeX3W hVrDm/3SbmhlNFcxsPAvW1uEntCDm14giu/adFgEQNAE1Mz7rs/wbKjwDnoIWzmHeDu0 PXWQf33RAPP11X9rnAesbiETZYLfOcBcxbkbCFz1IGiAFGm0fEp6aSYekt9gj0Kh75fA v0Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oF0BZfdM; 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=fail (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 o9si12669454ybm.455.2021.03.14.14.55.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:55:30 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=oF0BZfdM; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYht-0008Ab-V2 for patch@linaro.org; Sun, 14 Mar 2021 17:55:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHJ-0006Po-Dw for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]:40083) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHE-0008J1-PX for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: by mail-qk1-x72f.google.com with SMTP id l132so29919945qke.7 for ; Sun, 14 Mar 2021 14:27:56 -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 :mime-version:content-transfer-encoding; bh=JZdn6ANaU4aV5zRIqP0A2KkQ5u2MmsLTSCDf8HK0t+o=; b=oF0BZfdMnQYHe7obz9wj63Y+CtaRLHXmCoc5Rd1IXR+Fof6wYaelQZq/sNdPYVFCkG N2Pa4zZZAMaxJp10rIGCS3M3zN6nSDjM+9xNFtQujdp5FuYK/LbzO65IqMFwak+Lw6Sf rTtDggvzXETMplHx20+hexBqxDNIprLOq5ia/XuZBSMULrmmW5pMQvI+50G0+3nJoUO7 fisRiuo7Zbx0mi1I6eUMeHCruY0/8U3F+UHD68GQn7XdzLNvZA1u2yM4yAgRH1nZ7ak7 zHDxS/dR+yfmRRM3GPeSxLy7kqCqtGlO5sgghWnFGpSI3bRgFLO2hJOvWp7mLTWHAcuh 7LFA== 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=JZdn6ANaU4aV5zRIqP0A2KkQ5u2MmsLTSCDf8HK0t+o=; b=tLEH6IsJxlUXTEQM9sI8BVOu7s6AL3hoanXOALg4Aew9OC18cM/8D6DLln3sBz9CSX fYPCVWr6toBw406zFSp9Ddt8ipnPj5UHT8eSUfOT9yQQl281QrZWFB5Pq+jhMDGsRimO SAiNDJniTZcF3pQXIfEBqemQXsotNzCE46LdzSreLnmgbu/aNmXOgCja6z0sCoQ22mLG 2djtBGlkmbjG7HFzpnd45FaIBJY8+Tyn310XrnRuvuO7A6uIw6aDonl0gKDSZSp0EE5x bxslPhp0jDM+QgPiS5uJoPnBWPXCtMmGF/XFTRhDsBK/o4BUxIK61xCQDLqbVxRrT4Eg jXCQ== X-Gm-Message-State: AOAM530r2scL6LATBo7VwZoeMxA7H956eDCQP3cVyJUWXu9QFwPq4ka8 v4k3Pak9TQUXnYhSimnb8+O4WozpBumPNRpU X-Received: by 2002:a37:9f91:: with SMTP id i139mr22409218qke.72.1615757275673; Sun, 14 Mar 2021 14:27:55 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 26/29] tcg: Round the tb_size default from qemu_get_host_physmem Date: Sun, 14 Mar 2021 15:27:21 -0600 Message-Id: <20210314212724.1917075-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72f; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72f.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" If qemu_get_host_physmem returns an odd number of pages, then physmem / 8 will not be a multiple of the page size. The following was observed on a gitlab runner: ERROR qtest-arm/boot-serial-test - Bail out! ERROR:../util/osdep.c:80:qemu_mprotect__osdep: \ assertion failed: (!(size & ~qemu_real_host_page_mask)) Signed-off-by: Richard Henderson --- tcg/region.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 27a7e35c8e..4dc1237ff4 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -469,26 +469,6 @@ static size_t tcg_n_regions(size_t tb_size, unsigned max_cpus) (DEFAULT_CODE_GEN_BUFFER_SIZE_1 < MAX_CODE_GEN_BUFFER_SIZE \ ? DEFAULT_CODE_GEN_BUFFER_SIZE_1 : MAX_CODE_GEN_BUFFER_SIZE) -static size_t size_code_gen_buffer(size_t tb_size) -{ - /* Size the buffer. */ - if (tb_size == 0) { - size_t phys_mem = qemu_get_host_physmem(); - if (phys_mem == 0) { - tb_size = DEFAULT_CODE_GEN_BUFFER_SIZE; - } else { - tb_size = MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, phys_mem / 8); - } - } - if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { - tb_size = MIN_CODE_GEN_BUFFER_SIZE; - } - if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { - tb_size = MAX_CODE_GEN_BUFFER_SIZE; - } - return tb_size; -} - #ifdef __mips__ /* In order to use J and JAL within the code_gen_buffer, we require that the buffer not cross a 256MB boundary. */ @@ -836,13 +816,29 @@ static int alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) */ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) { - size_t page_size; + const size_t page_size = qemu_real_host_page_size; size_t region_size; size_t i; int have_prot; - have_prot = alloc_code_gen_buffer(size_code_gen_buffer(tb_size), - splitwx, &error_fatal); + /* Size the buffer. */ + if (tb_size == 0) { + size_t phys_mem = qemu_get_host_physmem(); + if (phys_mem == 0) { + tb_size = DEFAULT_CODE_GEN_BUFFER_SIZE; + } else { + tb_size = QEMU_ALIGN_DOWN(phys_mem / 8, page_size); + tb_size = MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, tb_size); + } + } + if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { + tb_size = MIN_CODE_GEN_BUFFER_SIZE; + } + if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { + tb_size = MAX_CODE_GEN_BUFFER_SIZE; + } + + have_prot = alloc_code_gen_buffer(tb_size, splitwx, &error_fatal); assert(have_prot >= 0); /* Request large pages for the buffer and the splitwx. */ @@ -857,9 +853,8 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) * As a result of this we might end up with a few extra pages at the end of * the buffer; we will assign those to the last region. */ - region.n = tcg_n_regions(region.total_size, max_cpus); - page_size = qemu_real_host_page_size; - region_size = region.total_size / region.n; + region.n = tcg_n_regions(tb_size, max_cpus); + region_size = tb_size / region.n; region_size = QEMU_ALIGN_DOWN(region_size, page_size); /* A region must have at least 2 pages; one code, one guard */ From patchwork Sun Mar 14 21:27:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400135 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2924945jai; Sun, 14 Mar 2021 14:41:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8WAT5ZdfPMxCL9c1RpcuNbiQhs02HwnwSCQ63Pq2c5FFCSieu/eqCcafYRE7T1HVepD/y X-Received: by 2002:a25:e752:: with SMTP id e79mr34702274ybh.373.1615758075431; Sun, 14 Mar 2021 14:41:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615758075; cv=none; d=google.com; s=arc-20160816; b=wW9P7RJB1nFCQk3KgAgcG+ilv0IHICgTVoqnCt6uYQn6XkbhQZWlUP5iuxNN4SrMAl 74Ec55pxWSQlpo/EdGTqkE2CqJWXVdqyXQMMahbB8UOeS+eD8l2DBl08ZUjRq9gZqlRP /dUdqGXdlJ2cM0k1zJ0tq73xO3CFh4YFC9vRVs+iN8senhWKtm9CLnJQCa+H0ZObDfke aXYr4cCO0p72AZNc/T9LhrdjPy3oAg3yFjynMCk9Ust9xr7GubDHT+WBOwxHtOCOA0yN 76iFyAnj8+SFkx+Gnw4yOcjCGEhPObYdg5LZx4fBqyT4qii7HIfqW49Nc+NUR+OaJNYZ 4HBQ== 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=pRz3FkmnhYrvDheUkOUyMc6EESrwISuc2jP3jfo+afs=; b=aa7FfOYiNHnBKI9akWa40HDH3VjzsHVMtAiIfZttpYRJytF9zkRrvkSG0mdbcmGFYJ waP2I3LpzBgLVMc9hXgRAWoVPX6Z3QnzYP22Dekm7vtsvHcqB+f3iUdMMy3rtfISNFPq 4jGtrcXVC+iziA5oLEuN3A/Td0tMFXwyJVTKeUbfYd9UT+4wMDNMdzszpBGOph8xibzT aB+/6c9LqLly44G+XKEu0Ax92br7FIz8xeLfKUzSLoBnt9X4j2LN8Dc5J8710BD3B861 Rk7wu838gh2CETcreL96IReoTFLmjlz4aABLYPfw+sUDzXWBGZ+sqBuTnW26gNJaN2ri Spcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=T6qzpQF4; 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=fail (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 n1si12729165ybf.237.2021.03.14.14.41.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:41:15 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=T6qzpQF4; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYU6-0004wZ-Ri for patch@linaro.org; Sun, 14 Mar 2021 17:41:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHJ-0006Of-1R for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:42127) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHG-0008JB-3B for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:00 -0400 Received: by mail-qk1-x729.google.com with SMTP id z190so29892144qka.9 for ; Sun, 14 Mar 2021 14:27:57 -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 :mime-version:content-transfer-encoding; bh=pRz3FkmnhYrvDheUkOUyMc6EESrwISuc2jP3jfo+afs=; b=T6qzpQF40EwKSOnTbv8BIpH8oM4f5VDVFntt/319krpghQfldwdtDnK3mS84WMwI5w Vj9b9t9Q70pvP6GXPu0wNIgDndr1Y/G/naYbP09FkrpDHIp3DB/syEsyl3K6YSE/+PMQ EABylMr5oXCKpSoDt4KW/ir1ul9VqrI/1cV+rxYz5aPzaT9CBJYJCHEQJTWnEIiSZoDa WuJjV+aJg7LOnuGbkyAxWZb9t1Y9VfCfEbqrI1ZUTp2tzjkAnbrftdWe+LVDZKOll8Fm YXzislGDv/VwR4HF3suJUspTeODH1GsEaXafuJHfGLYZQP5pYsn/7twIYs1rNY/CztpT utUA== 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=pRz3FkmnhYrvDheUkOUyMc6EESrwISuc2jP3jfo+afs=; b=i2oCIh5ZKepHegsMQBNR8nTmAE7/2sq3fzTnYKImF5FUpKoYDSa5ist25349mZj6TL S0X3sqF0z2cQeUTBQSKpJHiA83c5cuBVn/Xc6qFwhOeaYRz1GEHAIHdel8EQqQIvBNcm 3CJW1wox7OGfvEZdEKvA+25td5gql+eDX+18tA3nViIZe4jaZAsO1qOuZfneOfKlFdKJ K9eFznGVB29cnoCEuCNTUE1CxFi2r8jt2tG7VncKuTQIjhMjnaUTEk0M3xJuNZ6zfjtb gadWqwMQ9WacjZ0QoqDSAQuzvgmFL0jdOMA8TyHXSVHqRRXK5m7Dfm6b//vFaMewrbiP gMkw== X-Gm-Message-State: AOAM532sXyJ/UBgf8CMkwhznjG34ETyYK1DhKJLqMcAJudO17VLT5CYf FzBm/4DnabwNK//9MU2016w3Fygqk7Kx1KsW X-Received: by 2002:a05:620a:13db:: with SMTP id g27mr23096202qkl.367.1615757276743; Sun, 14 Mar 2021 14:27:56 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 27/29] tcg: Merge buffer protection and guard page protection Date: Sun, 14 Mar 2021 15:27:22 -0600 Message-Id: <20210314212724.1917075-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::729; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x729.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Do not handle protections on a case-by-case basis in the various alloc_code_gen_buffer instances; do it within a single loop in tcg_region_init. Signed-off-by: Richard Henderson --- tcg/region.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 4dc1237ff4..fac416ebf5 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -530,11 +530,6 @@ static int alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) } #endif - if (qemu_mprotect_rwx(buf, size)) { - error_setg_errno(errp, errno, "mprotect of jit buffer"); - return false; - } - region.start_aligned = buf; region.total_size = size; @@ -818,8 +813,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) { const size_t page_size = qemu_real_host_page_size; size_t region_size; - size_t i; - int have_prot; + int have_prot, need_prot; /* Size the buffer. */ if (tb_size == 0) { @@ -875,14 +869,38 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) /* init the region struct */ qemu_mutex_init(®ion.lock); - /* Set guard pages. No need to do this for the rx_buf, only the rw_buf. */ - for (i = 0; i < region.n; i++) { + /* + * Set guard pages. No need to do this for the rx_buf, only the rw_buf. + * Work with the page protections set up with the initial mapping. + */ + need_prot = PAGE_READ | PAGE_WRITE; +#ifndef CONFIG_TCG_INTERPRETER + if (tcg_splitwx_diff == 0) { + need_prot |= PAGE_EXEC; + } +#endif + for (size_t i = 0, n = region.n; i < n; i++) { void *start, *end; int rc; tcg_region_bounds(i, &start, &end); - rc = qemu_mprotect_none(end, page_size); - g_assert(!rc); + if (have_prot != need_prot) { + if (need_prot == (PAGE_READ | PAGE_WRITE | PAGE_EXEC)) { + rc = qemu_mprotect_rwx(start, end - start); + } else if (need_prot == (PAGE_READ | PAGE_WRITE)) { + rc = qemu_mprotect_rw(start, end - start); + } else { + g_assert_not_reached(); + } + if (rc) { + error_setg_errno(&error_fatal, errno, + "mprotect of jit buffer"); + } + } + if (have_prot != 0) { + /* If guard-page permissions don't change, it isn't fatal. */ + (void)qemu_mprotect_none(end, page_size); + } } tcg_region_trees_init(); From patchwork Sun Mar 14 21:27:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400144 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2930252jai; Sun, 14 Mar 2021 14:57:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSnXeN9C5LFc1PvjmNje2Ft15PSCqCSGEPrwr+wxJRAkRosijrSYs5OZSorQaS9BgSZeOC X-Received: by 2002:a25:7784:: with SMTP id s126mr33549781ybc.475.1615759047203; Sun, 14 Mar 2021 14:57:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615759047; cv=none; d=google.com; s=arc-20160816; b=sbJvnMr9pRMjLSNilo8YVlbQlg9wwOeKljwU/UaGZVPub7+WNE5Ts5PoprN1KW6qPq i+PDrLtPFM/t9lqG/OKWVGOvSsBRkM8jJVksS9V/gd2AGigXaUj+Cn9jauBwISFm+hiG UvjQcsc4qZxMhSND2bKLY9B/2qBWTQ8x8jKQ2mQKfs8upssfrwo+56/vlplQ0a6KRWKj lJEqMUUh/IsQIz7z3wKB0CUb65nYi9Mzx07j4V2TmVNmHA5PNP/cOthshB+W/AGVlwTz m2y9/zOao8H8fD3CRBQIJm3jN/qr0J+upXK3T8OTGD/yW+LsNYGRdEhWjyMSwrW+DK4P ropA== 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=HDjwEv5UIDqEnZnnB6TE5sHqCsoYg0tX8iQJ/X9PYNw=; b=TYsafCpA0g9KkBJ3xlf9GcYOINr3d+8qevjzY4JwpqXdKGnFYg0Z7YF1Vsu8PYdGPm ElMEr/NSz+IyGt1KP0ACKitBDvQZbYuzZgIbfMOEuEQmRxLpHlCHm/KkL0GaZb75frQ2 DXZ1/ATBA2DILRI4SCwiYXK9Hz1Bvgkv7SLUM+aeTL/AE+R8u2nSeYEawokD9+FSF0j/ XjXxO3CtuAOriwMudCFwWlqvCBj3Q0Joo16aSPcevFt5h+HB6OVgygWRDingmhADAyV1 4G3Q1vEgh97Iuzfw3/93NuXCxMD59+L+ApCetheCn4npNdVs0Sdvf1aw4QFUBJe0T6Ff ZUlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ay2hUMtI; 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=fail (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 v15si13552284ybb.119.2021.03.14.14.57.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:57:27 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=ay2hUMtI; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYjm-0000qg-Lm for patch@linaro.org; Sun, 14 Mar 2021 17:57:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHJ-0006QC-O4 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:02 -0400 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]:42129) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHG-0008Jr-KL for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: by mail-qk1-x72b.google.com with SMTP id z190so29892161qka.9 for ; Sun, 14 Mar 2021 14:27:58 -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 :mime-version:content-transfer-encoding; bh=HDjwEv5UIDqEnZnnB6TE5sHqCsoYg0tX8iQJ/X9PYNw=; b=ay2hUMtI2wg2+819Yv47rInMk8PbuPyYnWXCAuzb1WZSqwXaUz64ubtNJ6k9x6ZAwS M1rA69q+02NIG27UWQPDkWZ3ykv0h2Ba40boO68hWOFILLfbRmW877CfQHBa/OCnOXCW YhW9TItp9FOFddszYGtnQsNczgcqRPevdx0D45fq4iXHgR23rM1Dii3vAZs4s76B0GuG 8KmHNjSwAVrB1zpldtTv6av+jYB0mjPGNC/tHjKVXehxLiamJF0sWhYTo7FIe8riDLqM Y4HcvgnE03NC4hT7PyVcoMKYZVHh9bVqDRsULz955nH6U9CsuqrrzcXr3Rahz78Dcsuj eNOg== 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=HDjwEv5UIDqEnZnnB6TE5sHqCsoYg0tX8iQJ/X9PYNw=; b=TRBcnnzbsNf4/+BLYTCgqVF1679Tl0GGPCHw+eTCSVLfne0eWUG2hKG92TF0hmaELQ qn18Zo66ePyGKe8Vwk16Sg2T9/Gk13V9lumiE0SD0edPO9Kmr20FHOVfTpkZXmvcZ4pz WxMV/Jp5aCPiWQ/Qk8imCl3nY8vguuFYNIvrs1iT1wHHnt13CtMneypHBkvzVtS8QClF R5o72PXUpDjLOdXfInCNUBBaj6Lz7o9VVgApza3S2C7GWESaBmWpCzPUTFulTsXOFKtn O9TxOTR+R3mIDRqRdL5YCDVYTfNAiwgmaDnPsBJuIP1RFwvZ94G0D+m8GdqF9n/QdC4A /BrQ== X-Gm-Message-State: AOAM5332OwVRzT8oNEyKZiUYbr77SHh8aem7L62um6Sj+EGSHKBki9aV s8ieUgqP50rHRIyMd7fIpSxuO+Q5vyKXz+VD X-Received: by 2002:a05:620a:527:: with SMTP id h7mr22323566qkh.108.1615757277705; Sun, 14 Mar 2021 14:27:57 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 28/29] tcg: When allocating for !splitwx, begin with PROT_NONE Date: Sun, 14 Mar 2021 15:27:23 -0600 Message-Id: <20210314212724.1917075-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72b; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72b.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There's a change in mprotect() behaviour [1] in the latest macOS on M1 and it's not yet clear if it's going to be fixed by Apple. In this case, instead of changing permissions of N guard pages, we change permissions of N rwx regions. The same number of syscalls are required either way. [1] https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f Buglink: https://bugs.launchpad.net/qemu/+bug/1914849 Signed-off-by: Richard Henderson --- tcg/region.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index fac416ebf5..53f78965c7 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -765,12 +765,15 @@ static int alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) error_free_or_abort(errp); } - prot = PROT_READ | PROT_WRITE | PROT_EXEC; + /* + * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprotect + * rejects a permission change from RWX -> NONE when reserving the + * guard pages later. We can go the other way with the same number + * of syscalls, so always begin with PROT_NONE. + */ + prot = PROT_NONE; flags = MAP_PRIVATE | MAP_ANONYMOUS; -#ifdef CONFIG_TCG_INTERPRETER - /* The tcg interpreter does not need execute permission. */ - prot = PROT_READ | PROT_WRITE; -#elif defined(CONFIG_DARWIN) +#ifdef CONFIG_DARWIN /* Applicable to both iOS and macOS (Apple Silicon). */ if (!splitwx) { flags |= MAP_JIT; From patchwork Sun Mar 14 21:27:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400145 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2930672jai; Sun, 14 Mar 2021 14:58:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmIvrpXjwPSnhhAX/Em86j704zw2wbYoT+ixVMCBPiqjqWjaVLjbf6OFiWEuWU5kAaIH7C X-Received: by 2002:a25:d214:: with SMTP id j20mr30965041ybg.147.1615759135279; Sun, 14 Mar 2021 14:58:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615759135; cv=none; d=google.com; s=arc-20160816; b=d9IpVXPgfsqk3RG2b/81SijSTdmUVvQJKtOHITM/YYZpXUG4sn2FodbKc8rgcfH1pf L/sDvbZ4e0XT8ZGU9PdeqiPTy+pbPN9cNprP7FQwIRUNKtFWiqRPdPtfhWVQjOPcNC4g pa20HArto6EALOmJIM6Y7emDS3vSpecKaNDofb77KcrsO1SJbv9+laF9UCA4BeomxDNe gcfN5qZGEM0MOo4+QKs6WWznIqj+OgtzVw7meIf6i1lSX09ysZL0oTflDIqrzF0FuBww qgep2mA5U93+TcpMaqq/nug5fBP0PaJT3dVrafMHCdlPsUVQRVAeVP0a7aiq/qMgH4Fc KPqg== 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=Ikw13dOWP7lAlgKFWW7kJaboNeemcm515c1euWh3qoM=; b=lkQWEpOwN6i7XENLZEC4wXVNI71/ZzxrubnaVcVOyD4ZMXLWQ4R3tZeik6J0mQT7Vh k0VDwwzKBAiLKOslFSOSmIUi8GmWy7662iN9adtsSIQmZxOfR7C9dBNqxtW93EIzJWUH zAvhael/jNtS7UdCEq+jxP0fdBfmoj5wbV6kBrowWbHGwEftAmcSFF6mSUPUC1rMn/c8 hn8fy1sAwxNjqn+XrJLzust4p6mfdWoi/10um1FB1DaE1vTjeboPmVk4JxEBxXW6vZc7 K4FhN+haICCKuYdayk8eUUEf1TDw4GxSMS8cN4jioLdDwW84KZxScQGe1TmllxIIP0E0 a4eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XbhgSV0+; 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=fail (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 v10si14057175ybq.162.2021.03.14.14.58.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 14:58:55 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=XbhgSV0+; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYlC-0001q8-PI for patch@linaro.org; Sun, 14 Mar 2021 17:58:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHK-0006QE-1W for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:02 -0400 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]:42133) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHH-0008K1-QR for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: by mail-qk1-x72f.google.com with SMTP id z190so29892186qka.9 for ; Sun, 14 Mar 2021 14:27:59 -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 :mime-version:content-transfer-encoding; bh=Ikw13dOWP7lAlgKFWW7kJaboNeemcm515c1euWh3qoM=; b=XbhgSV0+XSAV3sXwI0vtpgVL+rOXB5MIKHC9EmSPetHvOchpFtEnUbij/s39OiPeqR xqzWkP148XpBe4jlXW+UyugLp9TLHda45zw7AWYUQ7jzl1kOP9ebuLXelTTiwtrmyGAp /UuJzkG+sH0mOjAltt/HGXckk+IrI9xY7I1pkZM0dKe2oNHJdlKFZrp6omVL3kmgK79J ytbBtPUeTVJDtqyyVPcZow6RFmt+IchKj5OnJijMecIa6MWkXrwfyjUGyWwGlrvIVRfo OFgiBIhWFn04e2j2BYKZ0Z2VtDPjg77ZGKhTuA1OUc9pyeQc2FN3g/sEcSihTH0rMG61 r1BQ== 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=Ikw13dOWP7lAlgKFWW7kJaboNeemcm515c1euWh3qoM=; b=KNl8I4eK6c9SbLaZyPKXECO92aY8Z4osbPtDErIJVsYGomFMsAtYvoHX6LhKbouA9u n+5a3Ol96kbPPaRBcRCrH/uA7wDZr+bGyCOiq2kAUNSJ4UWlY4G7tZPbQWkqKrq9N3WH rEYDzLb1wa4/50d0ZV8mAjdTNCyFEKQau6dD9BLpyr5gJNbD0wVuX60yf/yfQnMJ1FIs uafJkxvK84dSglpLDCZYuU3hnksxGOUEduM9df5Z/YSAlMSkqRqJouMQqPYx1kqmqJ4S R79RdT7E/bqOCOKAkDs7j4cj/BP5Im0Wxftyg3LZwD6Rv0sDxXOIdh8K6526gEWnwBJX ohkw== X-Gm-Message-State: AOAM533ZVKOYUMcd8PB2525/azGzmgkIwS4lBQ+RTmYA9fpJMmTNnur9 w5E6eIvw9KvlvyfW5MegYqZkyaBWQ6QU4qTK X-Received: by 2002:a37:a404:: with SMTP id n4mr22138457qke.439.1615757279036; Sun, 14 Mar 2021 14:27:59 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 29/29] tcg: Move tcg_init_ctx and tcg_ctx from accel/tcg/ Date: Sun, 14 Mar 2021 15:27:24 -0600 Message-Id: <20210314212724.1917075-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72f; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72f.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: r.bolshakov@yadro.com, j@getutm.app, =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These variables belong to the jit side, not the user side. Since tcg_init_ctx is no longer used outside of tcg/, move the declaration to tcg/internal.h. Suggested-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 1 - tcg/internal.h | 1 + accel/tcg/translate-all.c | 3 --- tcg/tcg.c | 3 +++ 4 files changed, 4 insertions(+), 4 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index a19deb529f..eef8857cca 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -690,7 +690,6 @@ static inline bool temp_readonly(TCGTemp *ts) return ts->kind >= TEMP_FIXED; } -extern TCGContext tcg_init_ctx; extern __thread TCGContext *tcg_ctx; extern const void *tcg_code_gen_epilogue; extern uintptr_t tcg_splitwx_diff; diff --git a/tcg/internal.h b/tcg/internal.h index f9906523da..181f86507a 100644 --- a/tcg/internal.h +++ b/tcg/internal.h @@ -27,6 +27,7 @@ #define TCG_HIGHWATER 1024 +extern TCGContext tcg_init_ctx; extern TCGContext **tcg_ctxs; extern unsigned int tcg_cur_ctxs; extern unsigned int tcg_max_ctxs; diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 40aeecf611..b32760c253 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -218,9 +218,6 @@ static int v_l2_levels; static void *l1_map[V_L1_MAX_SIZE]; -/* code generation context */ -TCGContext tcg_init_ctx; -__thread TCGContext *tcg_ctx; TBContext tb_ctx; static void page_table_config_init(void) diff --git a/tcg/tcg.c b/tcg/tcg.c index 65f9cf01d5..77335fb60f 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -149,6 +149,9 @@ static int tcg_target_const_match(tcg_target_long val, TCGType type, static int tcg_out_ldst_finalize(TCGContext *s); #endif +TCGContext tcg_init_ctx; +__thread TCGContext *tcg_ctx; + TCGContext **tcg_ctxs; unsigned int tcg_cur_ctxs; unsigned int tcg_max_ctxs;