From patchwork Fri Jun 11 23:41:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458531 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp704089ejc; Fri, 11 Jun 2021 16:42:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiGJ3SqhXOfEYt/J8T8uBOaBH+DIkQKqRxGlz2WRGiTENkIOB6QREpD70LmIUcJf15LnuB X-Received: by 2002:ac8:7399:: with SMTP id t25mr6203488qtp.228.1623454955466; Fri, 11 Jun 2021 16:42:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623454955; cv=none; d=google.com; s=arc-20160816; b=gyPo0jX4pUUPsXcLCIYslsnfCAhETRHoY9+im2ZUot8HI5dSScpVaYKkmyDkeLYZTq ndZImTpmVVUw7jdgy5Bxjkuim24AzJOqSVnjMnW28N8DlQyqFNLgmsXntzslIT6wbX9e gApV6ltikaGNNPbXzj1G2LTUWfHQJtjgkgr9fL4dCB3ntqq8boO9c4M0n1TXl811NsFu F3oGN1p0GNwG0UK6jvocaTE4s4d0EcUGRqXGyz8xJqt/S9DFEbELNVP6RlTSZYLYHaGA nHexwqVVoWrJ5wl3ifEYjrVdOw9W8ZIHfGNoALl32jTbU9Jfw2cAt+q+OdmtlLflLX/u AeNw== 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=5uMDnDezH8ov3NNnW0R3HVYll0BfUqU9E5lc10lEDLE=; b=z2oMdV30wvYhgXclf55tO0Nk9Ei8pMv6/NupNsPWCrDpSHr1h6XF6mKXZ1nItkWGtL munEDJ/7t8wDg5+dXs9EZAr0ClUCkgkBwMMG1lpYj963n4k4y79HQGFm/e1ofFCXeJao 9EOTbxHBR7cfUMfIcAsgm+XWDXRLrMF99B6bYiTfTTeQ2Adjgnq9xlxRgcD47w/Glv82 9VfWS76axrvlKLWmjnGjsm+PfSjuA6qEqLP2PEqsL9nKu/fOKl1dot6LUXN3Vy2rxF+f oUHc1ZigiiDfGQN8WO946hADTwfatCg7JvgcE5YDNH/Uai6atkmIzepujImAKekP8Sxy /eig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b6WPe+KT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h4si4654974qka.47.2021.06.11.16.42.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:42: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=pass header.i=@linaro.org header.s=google header.b=b6WPe+KT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqnK-00037h-Qx for patch@linaro.org; Fri, 11 Jun 2021 19:42:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmb-0002CJ-3b for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:49 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:40457) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmZ-0002Ww-7d for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:48 -0400 Received: by mail-pl1-x635.google.com with SMTP id e7so3597130plj.7 for ; Fri, 11 Jun 2021 16:41: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=5uMDnDezH8ov3NNnW0R3HVYll0BfUqU9E5lc10lEDLE=; b=b6WPe+KTdqsJPklkzvOPNM3pYY0KxQJgFZiXbbtRZYiY6tpIahZlG7PP97FDeQPZfh P9ifPm0cacZyRlvzddG4rO3PK4wRniIg2tkGyXblGneLzEU1k223fpBmEOdQz7CsNqzR tojyhupRXNcBPpKGQfD+Gh/RCcKbGFxuENl7N7Zl4/poVopW2gOqjt/YfTL89lCz3aeB a/cuhUNezVDpcK2/RBduNqceu2zKT4LWP7VHtXfUB8ZPFA9ivhwYRoea8u3XS5r3WYtq zWshI3W5lSPjIqhGpQNNqvlnZe/BQqWyrJN8DHWd/hqy5RksxPnxPsz7a79LP+oZRkG0 1LLw== 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=5uMDnDezH8ov3NNnW0R3HVYll0BfUqU9E5lc10lEDLE=; b=e2ZZiLVhjKNUd1uPxl5aTKfqlli9X3RiAFYxGqpNr1RXZggjRwwku9a5gRqQCYeltr ejBvD7hFUHK1CAP/CpS9a7Rvw4AcUx4VE8BiU57EaOpeF1z/awjaY8wkQvtTKkiyPcPn y2F2SX8FtbOtcaZs/zt5VhEVC1FVfGMs+W3LdD4XUJmv7gzeCZKEaQfd0RBax9S7W5qq iOxLXO1C2ZD4zDTE+8oR3iHDwUbXIsSV+pF9Lr8APw9OvYolRJHfOq8bCMSzz12uJctr Wz0KE42LYp+8PBFJMAWpPc4CQbzBcV2aAvFWkd6bH4/O8qRs2fWQH3d0ex8u4vsmR2Zr qojg== X-Gm-Message-State: AOAM531Y7AbztgiaIbO24L7LSAw/v2m2qwRokygCsR9DRxEEjG7PRd6N Ody9G61gzdaVzPYi+A1bSyilvQxeuZPjpQ== X-Received: by 2002:a17:90a:d590:: with SMTP id v16mr6737382pju.205.1623454905921; Fri, 11 Jun 2021 16:41:45 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 01/34] meson: Split out tcg/meson.build Date: Fri, 11 Jun 2021 16:41:11 -0700 Message-Id: <20210611234144.653682-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Luis Pires Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- meson.build | 8 +------- tcg/meson.build | 13 +++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 tcg/meson.build -- 2.25.1 diff --git a/meson.build b/meson.build index d2a9ce91f5..b5b2cf9e04 100644 --- a/meson.build +++ b/meson.build @@ -1970,14 +1970,7 @@ common_ss.add(capstone) specific_ss.add(files('cpu.c', 'disas.c', 'gdbstub.c'), capstone) 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('tcg/tci.c')) # Work around a gcc bug/misfeature wherein constant propagation looks # through an alias: @@ -2007,6 +2000,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 Fri Jun 11 23:41:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458538 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp705730ejc; Fri, 11 Jun 2021 16:46:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzj+nXQpNjd6YWb/5Jd5y9ujiY6mA454bHp26wNBSk8R2d1rE1RrZQ71yVxIzdUBtZYFxV2 X-Received: by 2002:ad4:4ee3:: with SMTP id dv3mr7405171qvb.6.1623455166531; Fri, 11 Jun 2021 16:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455166; cv=none; d=google.com; s=arc-20160816; b=cNMOhXok0N9ji0UzWE6WV6ildEyAq5MowG7TeEzN8pBd+ZltKars6MOfDmpYeA4rDQ KOVZHHc4dq/1CQB3SBKTUeK4V8+GxkUJRzeB296OfxhYF3760KTdC9f+hyfATrtoBWzN mMQx630LeIzQRdmgzBDpjGCyTc/Qj7HUdpPTUZDeE9tFPy8CrVKLf5RBIf+G6pPqFDZY nMbUK5EGit46e4M4oi/ON6FxRlAO1zLQ4J7HaW7JmUfavfyYELPUpYH5Z48AM0HYCR/x fk5aU3VmlJ87kHGNGdw8gfHD71JarXJBvNLWSeofcU/596/cwqdSWvAxFanOa/gq5sBh q8+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=Xdsc1hH1Evyr3+MMvXt/sFiU8GAdG4NN+6ZZZYHh5K0=; b=AXYY+NAeBIZckGw2Ah1jndQt6XBE9TkvF+j71dBJF2D0BPUTTWBtatWHBjCuEQPDtX dhvk46vUfToYmR4hilKFB7e63VmhD/1EwAPzvECnXyj97LxvbUxNC8J9NYAqNgrKd5XO 5Dz9e7Gvq6wS89d0hbx9RAREWmM9EU4kiMdmnJaU9nZtHJQV1a5upHfAmP3BMFQ/yujm zNKis0U9LlhRCxFwXiQcLUuf0RxbY8aI7cJr5vpumKhHZJvSM74sVlBLUv2GlOOc8gTq 0bhQce/or1DXx9tvPWZPYXuANmoBYOD/gJRL0Q5PoIIOdFbmM+MFCSi4kG1tnZwKuHX+ Skaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LZukvZrw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o5si544079qtm.150.2021.06.11.16.46.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:46:06 -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=pass header.i=@linaro.org header.s=google header.b=LZukvZrw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqqj-0000EZ-SU for patch@linaro.org; Fri, 11 Jun 2021 19:46:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmb-0002FM-Ni for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:49 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:42840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmZ-0002XY-SA for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:49 -0400 Received: by mail-pf1-x42a.google.com with SMTP id s14so5672478pfd.9 for ; Fri, 11 Jun 2021 16:41: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=Xdsc1hH1Evyr3+MMvXt/sFiU8GAdG4NN+6ZZZYHh5K0=; b=LZukvZrw+g3QI7xBmOQwwO/VMu4n+W2Sjs9nti+wuDdYxYxz1lAsO/gaElZrjiV9RJ Xck+eneXgmUfhfP5J4F24uB2cfI53xVYiG6/Dr57bPuwbwiv/Qb2Okb8Xqga1Ae47hj6 +PX27QPXaR+qkyUt6b4hy9gQpF/kgSvc53APQSukBvRYDnApBfVqLi/PXVMjAaJX+C4B rwYqXGGtxnoFHRbxQzJ7c9vKsesb/VwoE3jZ7392roIlrpDdJeyPvEErwJOKZxQy2DMQ QTK/d+UIHNQ7vkccuLxE0o5R+d4fMvDd//3taetdCSB1TOgDxTVyccNQQcEH2djF+Wd6 kNfA== 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=Xdsc1hH1Evyr3+MMvXt/sFiU8GAdG4NN+6ZZZYHh5K0=; b=OTgzMrlIef4zV7h2CTuX+rFE8L5phABIBU8y+Q9jo4IEnI0xVmwMpPg1HykhLXLoK7 rsukmEFUmi3pQvIPoISKOt77SYuluENPvKUi9MsVP/jWDe9lhS/OHSVk4JeUztEPLk8T S8a0atw+OP8InWqFs3KtNxMEbdd7WCAHydLS+fpog5w1isH6OwOwSBVQMF6BMiNqRm6t 7bxXQswyiATks6noUblEzCOTdbAJFhpX7aBAMs2mvKncaFnsqMw+lezvdRg4OTsUtRYW 7tTdkzuYzspo1UzGJHYIWI3B1bQPBTVx9Xt7xrODYxkbKa7yHNR4qlQWVLoH7lKGS/pM WmPQ== X-Gm-Message-State: AOAM533F50y5bG+msMgs3bJyMxcMm6BOWNcH1CRqxdmI6OkdZ4szkfgW mmFT12Nn8i+k9K43xNzTVfuouoCHLNSFtw== X-Received: by 2002:a62:687:0:b029:2ef:be02:c346 with SMTP id 129-20020a6206870000b02902efbe02c346mr10701294pfg.51.1623454906508; Fri, 11 Jun 2021 16:41:46 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 02/34] meson: Split out fpu/meson.build Date: Fri, 11 Jun 2021 16:41:12 -0700 Message-Id: <20210611234144.653682-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Luis Pires Reviewed-by: Alex Bennée 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 diff --git a/meson.build b/meson.build index b5b2cf9e04..a2311eda6e 100644 --- a/meson.build +++ b/meson.build @@ -1968,9 +1968,6 @@ subdir('softmmu') common_ss.add(capstone) specific_ss.add(files('cpu.c', 'disas.c', 'gdbstub.c'), capstone) -specific_ss.add(when: 'CONFIG_TCG', if_true: files( - 'fpu/softfloat.c', -)) # Work around a gcc bug/misfeature wherein constant propagation looks # through an alias: @@ -2001,6 +1998,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 Fri Jun 11 23:41:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458539 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp706517ejc; Fri, 11 Jun 2021 16:47:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMMG/Wvk3wwsaMTGsvNUFrF9HjtOOMEXkBXdQzFuSP26wa1Su8TO8pmQzWoeE8YRluuec4 X-Received: by 2002:a92:d08c:: with SMTP id h12mr5018671ilh.294.1623455262162; Fri, 11 Jun 2021 16:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455262; cv=none; d=google.com; s=arc-20160816; b=a0227Fp+Ib7FOPrEnHoNYcKytr2RU5+V9vYm6Hh364fEOi+q6zuyhKhNSD/0jH3goY gd53XNtGjhEmHyYefms1T+w6rhITTWc+gZ7CY74dwHPe/E84fKtut69mBFdqvdYQBe+e 25qBuF3lzluqN8fM2fQ7xR2gDAwsu3tY1489bzGraO6nZW+XLD+dbJFSDQOEoagdT/o9 SAhvXbcvzWDCK+2NwmRBAVVUTpxG0GMbVI71hjGc3Jj6OZXEj7kD8cCVFiPlL33z4CA2 H8WUuLpO3VrZ1Uiqvx34yQYRHCKcUOepAL6mpBc9+5vh4nqNJPIPdjMYw4z8aVPAtsKj BQpg== 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=jUhltgRrfndDs4n5FmV9GeamF0gX7OjPbnRpqT98ftE=; b=uArqc66wp7tHAVfPdFIoq3KKUZKMVsPl9EthJj2wd6/abFE+9uO9Ix+8aw/1VR5HOp PQfmVAZo7U5YlEg9gTz9DqdEGKJ+YtVxuO4RDO13qDYZoocQ/iPu6zABFQpavyotfsZg QdFyID5M/m+KRW36h7mFEnhCuOw7vMJX3OD2qJfd5BoJT8G4ishCqmFz5nTKSKMPHNqh 45m0YsCyJe/gwY/BjIKRDQYHDN/ITjM1FmgC1KPd28Yxzl+Pc2iXVxn1RX6CH1yuVqfJ tqM9DglZYv1o+DZe9kG4njRTAOJGY7EVHxP/w3LNUuq8af9GmmiXaNXvM3/9jhU2CkGc OffA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D1NX6Grw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m19si8623910jat.118.2021.06.11.16.47.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:47:42 -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=pass header.i=@linaro.org header.s=google header.b=D1NX6Grw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqsH-000625-Ft for patch@linaro.org; Fri, 11 Jun 2021 19:47:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmc-0002Ia-S3 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:50 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:46609) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqma-0002Y1-KP for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:50 -0400 Received: by mail-pg1-x52b.google.com with SMTP id n12so3640985pgs.13 for ; Fri, 11 Jun 2021 16:41: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=jUhltgRrfndDs4n5FmV9GeamF0gX7OjPbnRpqT98ftE=; b=D1NX6Grw0beaZFJpdfrOKyDsHdk4mVHnaPwx0LZkMJnjeWHEJfxF0uZNGVh4vgM9jy FJmI0tP5RigKDPtaIWHyxLEBDLNtvzBZ/2xWkrQ5vL3mKgp/Daw22sQtpMAL1igo8/re YJ9ZJtNRHjkkcte3jLrDOz8kZeFqITZTccfWaD8X5TEKXyDr/hfZNiRJvD6lb9jCgsui aWY7bPrNxrgFDCW2FpMVotZFpggAS+Iysdm1ToUy0UnAxLUHXjUZSdhEOd5RcGQa7n3P CKMJEGivD4FljUslLaO/wXOacOsUrYndflKJf1OOGwqwi1DwMiNIoXdsFE3N2/AJkGmW bJAg== 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=jUhltgRrfndDs4n5FmV9GeamF0gX7OjPbnRpqT98ftE=; b=VzcmYatdJenT3f7TmvnyeOvDheHdgTUe/ovGBzIu43UNk0aN54NLB/MoR94BEF8QME aviFjgXOnrD1PNyx10igpLyTpI/VZH7yxFYIxDVZCkIBWGV9bv/yXmiWDVDln2+HaRxt VMSOi7coMhNAKjqLcXTHzxVCjgrPyuCIuMtHPo2WVWNB1qGwhg83SQV21uFDKv27kU6h qF1iFr9RVnEHphqoT7IcjEv2axmKaWOs22kAhf12v4dMVlRdkaUP1dHOGGVbibTLcgkm x029z1yDJLU+co3XEg3DCjCfI/WYDcUUlNv68r12s0B1S2ZQB+ZoBR2qCnS4REDfoIbC s38Q== X-Gm-Message-State: AOAM530M1g61cUK3i17XfNIM/u6Joq7GR5T1QK/4UdzyMs0SQCOZSyYK OXmMND2ep9DHxzj/BA+7U7+VcKGZ253I5g== X-Received: by 2002:aa7:8119:0:b029:2b5:7e51:274b with SMTP id b25-20020aa781190000b02902b57e51274bmr10676298pfi.32.1623454907159; Fri, 11 Jun 2021 16:41:47 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 03/34] tcg: Re-order tcg_region_init vs tcg_prologue_init Date: Fri, 11 Jun 2021 16:41:13 -0700 Message-Id: <20210611234144.653682-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Luis Pires Reviewed-by: Alex Bennée 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 1eefe6ea8d..04764626bc 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 9d370bc8f6..270cf2ca70 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -879,7 +879,6 @@ int main(int argc, char **argv) * 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 4dfc47ad3b..2fb3a366a6 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -868,7 +868,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 0dc271aac9..1e683b80e4 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1206,32 +1206,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 @@ -1248,32 +1234,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) { @@ -1287,7 +1273,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 Fri Jun 11 23:41:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458541 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp707002ejc; Fri, 11 Jun 2021 16:48:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy5LbNgTEJrer+hiN6QQT9yjyBH4AGg4UxQCJggCAW3RWIVyT8h/Mr92nJfHwSUuIqGdJf X-Received: by 2002:a05:6e02:20e8:: with SMTP id q8mr5093886ilv.84.1623455321015; Fri, 11 Jun 2021 16:48:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455321; cv=none; d=google.com; s=arc-20160816; b=bHLN6E7E3Fnx1aOExgDYRyUdVMomcGEUnG01BnQGA9TaCGZF0L6k1cFAPi7dHAru2B R5U7JMFCpL02yROjt93mr4pjwBFjG8Cwu7G7J6S40sYOc01slLT9CEbkMqkxlyfIco39 ma8OgVXPEeVOEc7yBXI8GKLqspQjtmgPEb+VtXBKUN2V8BJHj+L8rRT8UPoGFO8y+Fkk 60OE9maEoud+6bohLo86ckzAmOPLTDWF7yqmVtr07cU0l145RDpZXv3ztJgyRIFQKudX DrCs0b/CvvYm6tQeitjU5ezrl1VmMrzks0oaDmXQc95HzRBwKuLoXOGqgWvitfHWfAuk jKVg== 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=QSl6OeNN4w6woYqVHZ//vjb0CKaJZ9EhsQMGYBZHzX0=; b=0LePpoa1Wpw1wg+QQk/frcpHdKkuN1C7ivFBu4k9p763yQdQa1OimHlAEiOuSbOFbY dgVHQ9niD8luQe051gu5c5DJ6dzSPG7QBXf100cJ4O4KwGu360tkExq9lZX23Cyt8gPe t9C+QsuTjMzOk8anoYz8Cg79PVmed1qjY9uFX1CDjrQffxy6NC9ktgLBvqkYkjyJYXgF Z8tMfjOGtRvDQb2AXAh/B6po37SPn5KvZQHBOk659PaOweU61Yxvrg7Z6y5/PlzOTMQ1 ripTWOMdE3u/qthP4FH1Afco9iVV/wrdJZSI10ak6MYAWOVw5/WtiWP4AiDAarPmDJi2 /EIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ujaWAxJT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s4si7951818ilj.142.2021.06.11.16.48.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:48:41 -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=pass header.i=@linaro.org header.s=google header.b=ujaWAxJT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqtE-0006DT-Cd for patch@linaro.org; Fri, 11 Jun 2021 19:48:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmf-0002Qe-Qs for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:53 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:46775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmb-0002YA-3g for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:53 -0400 Received: by mail-pj1-x102e.google.com with SMTP id o10-20020a17090aac0ab029016e92770073so913024pjq.5 for ; Fri, 11 Jun 2021 16:41: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=QSl6OeNN4w6woYqVHZ//vjb0CKaJZ9EhsQMGYBZHzX0=; b=ujaWAxJTq9EVXFRDHSs/+k5dLhv50RMH+jSj21qmkrPeEm5GC0ZUKuIOXumFbBSQnb 8CkYfDxugiHKYCxCTcaMzyeFq1nyY96Crjyy0Ez6fTp8bjpifZ7vdzZr2lygA4cjYX8z qZv9g2HUNCfw7E7eiIVPV8ctHFpEiXZ/5ztTZz1yKDC0Qeqb87JFmRrLimL4HNu7W9lP zRDGoMk3rvrgkxmmEEQ5NvVRybqG6wFucVfGG7GdLSrCj/zKn/bSxp4C8udv5aDPkT2q bB3Ddf/OFH3jLk9T+qHWm46bmk1/mtxizz4bl5hwpCd4PkjYTdyKo7kuPNM8Q8IrpW5V fKyA== 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=QSl6OeNN4w6woYqVHZ//vjb0CKaJZ9EhsQMGYBZHzX0=; b=F9ZFM0g6jzG86yzbY93jv61a6Nb7vviUCEhfGO/1uiwUxItoEPu0o3sQZ4OLEKY91T dHhRBZSU5rIadqEaWAcdThOtnfThe9ruiR8K8rCq3t4YPWFdoUazzkTqzNRCinMKB/32 bVGY97X5NN4+7QgCE3TruEyHbTGyKdcesXLRbhUdG2UyIGmvcj2s8zKc+ZUfNWZzvQqw 0gqWEv9kbdhW7CIJEKboBD9XXnAFg/2La/P5bgSJ2kBm+qJUC9GwEFjk/uI31U/yZRSB pZNhD2jYu9q8uCS5t4w8/dFU2+Ft/0rLNs5H5Ub/bEZuznviTmg4Ah89jDq0yW6OdWdO /N9w== X-Gm-Message-State: AOAM5339KYDQB6UQBigZTmINoLYGtY5xl/AAyOoeRXkopA5/LIqIVfj3 Lo/tZT+NwNKhRfmLJZpfbKIR7BDSAC7YOQ== X-Received: by 2002:a17:90b:3ec3:: with SMTP id rm3mr7031298pjb.105.1623454907787; Fri, 11 Jun 2021 16:41:47 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 04/34] tcg: Remove error return from tcg_region_initial_alloc__locked Date: Fri, 11 Jun 2021 16:41:14 -0700 Message-Id: <20210611234144.653682-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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: Luis Pires Reviewed-by: Alex Bennée 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 1e683b80e4..ba690e0483 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); @@ -876,11 +875,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 } @@ -942,7 +937,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; @@ -966,8 +960,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 Fri Jun 11 23:41:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458534 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp704457ejc; Fri, 11 Jun 2021 16:43:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrCIxH4tnMQo/KIulLf5PK+7QdmU8z8cOY4N5zrLxMPtme/wwOFLoziveGwvvNR1lob/I/ X-Received: by 2002:a92:cb41:: with SMTP id f1mr4657459ilq.199.1623455003676; Fri, 11 Jun 2021 16:43:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455003; cv=none; d=google.com; s=arc-20160816; b=Ge8Tf/ptfU6A4eOJh4uVLuxeQHY/MBnztFKIs8/7iwTJP7eUgkCixeBNgxmy1COa8S sQU5Rwtq1/pZwVQj5HuGcukToF4Loxm50jXsc5kvCEV/SUG2SZdGsSONU+H0R5AEgFza Kon0lAL81yuk9nr9/nsZeYJUqkFeG9DW5tH9vOMiYWnC7K80/ygS4i6LU+zJThTki18q /ahVh2/bv6p4aoG0kP+KiTKJK7svikaSrTJsJIMd+SYOaXx29Qi/E97oeFFzB/FkVDEc 6V3N38n1dRPP4qZwcf2fHBebtnGx+XzFZEtBe+CPS4hU59+mgtDgGqORnuWfc4QhVk1v UypQ== 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=NXkVHH+0m+9DTaglRp9AWRxTZMLmg8AZ8T8ieoPznkg=; b=J7WWlAOuEfpXiZblg1NIoO5qeiDOq40dxhM48pc+W4zo1M5lGAKaJObpj3bkvzSRok oiYb9YTHBquEIxOeKT7uLvHGPUQbAE6v9QCgTxvzS54JsAXrww8TeWlgtHN2IkdRvfeK E4nErnFBNZJt5oLB9bPw+p1RQR/ZF1e9D56lJuv82s63ipNARjHKDtbIkUcOphVizirO Ebq3Rrc3kvnbVztPs1BZ9Wmxex+UJBveqrDDoqLsq5B6pO2i+FqKbJPBpJR6Z22Jo1db LvTeDuqEXHXgu3xYvAaiemGCGfxRe1Lx8PaI5Pku4Zislm125DS4BtymjOnE1+P82Jnf NDRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tVBlvmyC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k24si9012612jan.49.2021.06.11.16.43.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:43:23 -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=pass header.i=@linaro.org header.s=google header.b=tVBlvmyC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqo7-0004a2-2F for patch@linaro.org; Fri, 11 Jun 2021 19:43:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmd-0002K2-BG for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:51 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:41926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmb-0002ZS-KM for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:51 -0400 Received: by mail-pg1-x531.google.com with SMTP id l184so3666643pgd.8 for ; Fri, 11 Jun 2021 16:41: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=NXkVHH+0m+9DTaglRp9AWRxTZMLmg8AZ8T8ieoPznkg=; b=tVBlvmyC7AMuZWyWFtIR05OHgy+kZjx2oCs1E561qzo8NeaeLo2c4Qcr72jpYolIa9 /4U747DQIE7a3m0Av51qzX0Zta4az6zjIW79oTt0162MvkZqw8MyYtcIkSq7WQO+Piu5 tgwGtLEg1GgF0qe6v6pl7KHEQFO2p8c/d/+h+vZrBk26gNEXUwU+Y/gpILEPLIuY96a2 T1he5SWRMRyGdFCkgktozTMYxX+ezsYPcieKY09NqZB5vQi5oLc+Xy4opH46GJO5u3xj kjBivzSXsleNs/lBiWptQyB64SKisc2XM9wmZ4IoggVW4TGHR+YrVp0ONarK6Icu4Pzj iO3w== 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=NXkVHH+0m+9DTaglRp9AWRxTZMLmg8AZ8T8ieoPznkg=; b=jpvf+UZNiXtfiMrbxkdqilzn4SfapeXOSI/BhGZ/awakhcp8exuT1miWMEb8xFFZvr DB4Z/sOqXQOIRSsEGD8P4CosIav+bGv0IbAcci8ELFXCjwRHaXgaiMO7pez99oZEINw6 Vwjt20NcYD/sGmrUQFT9+oPa9vNtcAUUcL/gMXnXub2wfD/5dLySrf9wbVPlvyjJeIlT 8hWhe8p7AjjV/meDlIpyloD+1T9Si4tnJmVfDVwqqbTt8ScH5jW7Nu2OpCcX8KRyZc8/ 4xo1+B7+VhJnsTOeNme+CBKcXbJ/IRdw7ZLrR1RqIEX8Sumji5rYw5gd9z2MbjFzfyn1 yANg== X-Gm-Message-State: AOAM531kzvVjtVyNzALz0mGUQ7R1vFf+l3vd2JzpHVWISKpOdNt5Omsr wFQpkmAUsNXwg8+Q282D1vci+9aNIqIMHg== X-Received: by 2002:a05:6a00:1794:b029:2ee:c59c:56bf with SMTP id s20-20020a056a001794b02902eec59c56bfmr10584276pfg.2.1623454908355; Fri, 11 Jun 2021 16:41:48 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 05/34] tcg: Split out tcg_region_initial_alloc Date: Fri, 11 Jun 2021 16:41:15 -0700 Message-Id: <20210611234144.653682-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Luis Pires Reviewed-by: Alex Bennée 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 ba690e0483..36ea21d596 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) { @@ -959,9 +968,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 Fri Jun 11 23:41:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458537 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp705714ejc; Fri, 11 Jun 2021 16:46:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNxmdZjPfZrEj/RBLQk/IGFt5Bg9v5Mqrfl1acGCF/wvJBbuyoFM3yBnH5FbNnenHoRZNs X-Received: by 2002:a05:6602:1810:: with SMTP id t16mr4996230ioh.48.1623455164528; Fri, 11 Jun 2021 16:46:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455164; cv=none; d=google.com; s=arc-20160816; b=JVq5uLhQPthwqTijzaIpk/V/v/57dshFFMyczi5ZARQLlm5ctXu975Ct4oGbcU+qpM Xsb9IYzPa54f6jZeCXtLqOPCQhXBVZTCeKAiMMMJsogWsoZIYsBh221P2mqHv/Ws9LDp Pqm2SRGGD6lA8xrKRlbN0KknjO3TWs1FSDRDVcv8bUxPxvQ1Cw15M5ckbj8vcPrlzAXp dM2mxvBTaVTllxrcjoFhvecBx9c1Ud9oXxq9Xza4mKA7m8kbdQ6+BlxukIDwxa+APVO0 NSsZuDVTFmDRvwWEBptKpaEpqs0rlL+V2TUiDWBBu83IS72li8v3Vz0VJFArz8pMFsMM Kk/A== 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=UGCE0hBuujlu+HiYuNrthLkWxka9AZtIh3/7kEDtjdA=; b=s4nT+Yj1xcUAMNVK80Zwo1cOn7YJWOltncrPqlwAzZ+PQn5Ns/w3eF6NQY00CRRKI5 Oz/znD7Z8MrEQJKtb3chMCoqLj30/RLtrfEoL4rxOvHLnt+5cR2b4ZlfwsK9ObFTz0q0 favKXtU2xzJdHKvGAhED7dxyG3z91wE6r2R3vmcrp+d9sVn5Ta+cMVfcyuTHybj5NfkA GitOU2iCZxKTJCnd9XH5SuR3oAlm4EtS+tZrX81vXwUJUOzNG47YOWGCOd87rMwDW70D yTfZAc8FME+v4kkZh3ii27I5gIz+Pkx/6PK8CZe04h+tPWg0zgJQM+6HYct6IPP+s2y1 QD1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i1NngS7b; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i1si7640495ilq.80.2021.06.11.16.46.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:46:04 -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=pass header.i=@linaro.org header.s=google header.b=i1NngS7b; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqqh-0001rO-R4 for patch@linaro.org; Fri, 11 Jun 2021 19:46:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqme-0002Lj-04 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:52 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:38435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmc-0002Zu-6n for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:51 -0400 Received: by mail-pg1-x529.google.com with SMTP id t17so3679517pga.5 for ; Fri, 11 Jun 2021 16:41: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=UGCE0hBuujlu+HiYuNrthLkWxka9AZtIh3/7kEDtjdA=; b=i1NngS7b7TVu0uaIggAkqclZ4+BbnJ1A3bvlRY5SD+J8SE5JgHNndSGA/RqZ9ZvSwa 4uke/wDxu1SAHz77wxLCf/ysnwQ4PLcTrHmaYxkYEMINfxtMom5ASUJlw+GgWc0Yd8Jo iOJs9BNVCdF5f1MFGWeWsCKzFeVmKBHumQSuE52Icl3KSHVtwDsw/f2tqfyDlSbjV2sk 1aFGkIoVRwVFugX+8OF6E66ts6m6NfdcUG5eO7WYpMHSAp2qltK3uqPd270+7tdNYHpG Vhdg0vBsH+2ef9YJBZNX/cDM7PK2ayA20+RTO4Pg75N8a9iIb7fvkY1E3tK51UkGZ/yP u4Aw== 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=UGCE0hBuujlu+HiYuNrthLkWxka9AZtIh3/7kEDtjdA=; b=XjTlnxCuYJoJM1iaPuvG+EQmd+Qlm1u3Y3PDrsOnFgc8gU43EDvUwAaHUhzxQzpC8G INxZfRDDFeGygfZhCAm10tbbB/mT8o+8SWEuAwr/CUs0vVcd00c/RvyBpltDcRKHXc5R OBD437658PhTzPgdpakwS959nJiMHlAiXVYEAFeXylpigKH/rCh+kK+//cTUUn3EwkWP 5AMAzhcgBUBLK7nTKADPIMy1DQWV2OmZo7TyddQVThd4MAo1HVvuGR5hS6D8m3TiUVE9 h1XBC9j2WrEim3TxNwIBQ1yI156kJbyh3KDYVUuOOQjmxqlEIzP5X3FrVQ/XjNxvAqsQ JSlA== X-Gm-Message-State: AOAM531YADv5NM70H7YnmY1dxcsJ8B4djVPsCBBXXMJDrLJGsZURvdkr MJZ1uuZv+SH0SzWsANFDyt8axEW0PEGmww== X-Received: by 2002:a63:e0e:: with SMTP id d14mr5877297pgl.426.1623454909009; Fri, 11 Jun 2021 16:41:49 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 06/34] tcg: Split out tcg_region_prologue_set Date: Fri, 11 Jun 2021 16:41:16 -0700 Message-Id: <20210611234144.653682-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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 . Reviewed-by: Luis Pires Reviewed-by: Alex Bennée 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 36ea21d596..eca72990c1 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -882,10 +882,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 @@ -965,10 +981,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 */ @@ -1208,8 +1224,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; @@ -1241,14 +1255,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 Fri Jun 11 23:41: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: 458623 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp709350ejc; Fri, 11 Jun 2021 16:53:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwop8agmiu7nlJm96ofbc3PKuH0LzH3XG9g2HzN9wzlV726joG/ixgIxC/ibbjzo4QIh6OR X-Received: by 2002:a6b:b7d6:: with SMTP id h205mr5225227iof.188.1623455595450; Fri, 11 Jun 2021 16:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455595; cv=none; d=google.com; s=arc-20160816; b=Azi6ZN3y5OKPnybYz/tlPQyYZtSA8ZhEWwV6RKuxShzATmz5HrEAFpjfUcVJYp2iiL fOHHzJczAhgA7SvwFwd1cazkNZga/lS/ivFeEfB+gZTLYN2s6FsdVSXNgOX8g4/BXBVT a8tIDRtXoXI+7pJSzHMHVvEdnnXcwg6qWcD+k0Q0yZYdxyZvie5iTa5EuAP1LYwzS505 izbE2yTr4E6SzNDKgG9Z0R08eErRPD79io70D/zl8mdgWzviUD6jzFX5N/W4oXSKsXDd RP6AuB26DUrM9xR0TB/J81ME419WXKlY0hmQghS2PrUzdtMPtQMcde2u6jyptnkoRrvj kN4Q== 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=Ckmgu6xkFrumPVTVPqWAkYR5TKM7Uc1N43XEA579zJc=; b=up6s73d/LupC66wQrD1c8fYDyYJZhaw/R/3hZPB5naxxD9UmfUiN4VExGBiH/BcPKa CR9wC6hdyNdC4dCqw9nQpFl9FBEiZ/Wd0l97kK622Z7prmc8OU27bCIDIx0V3w1nJXzn MW3aLIyKuJlQt7NcuSYQz21Elg2idymkSnPhk9jWM0CVvOf+4fzqxCQvNtLBLgAU3kRf QAVJfwduotYmDpNm533tPifejPRPdrnwR9stmXGU5dABhKSCP2pMhH9tGqRwmBk5vuux 5EAaUY5JQ/oO87LeCs2mSdhTNv9oV9rc74swtLjWPW5L25Dm/mC7EjHGnEzFlrSpz/wv H9bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BV4uAJM9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z3si7850931jaq.30.2021.06.11.16.53.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:53: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=pass header.i=@linaro.org header.s=google header.b=BV4uAJM9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqxe-0007WA-O4 for patch@linaro.org; Fri, 11 Jun 2021 19:53:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmh-0002Wa-Pm for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:55 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:46004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmd-0002bW-Ek for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:55 -0400 Received: by mail-pf1-x432.google.com with SMTP id d16so5669167pfn.12 for ; Fri, 11 Jun 2021 16:41: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=Ckmgu6xkFrumPVTVPqWAkYR5TKM7Uc1N43XEA579zJc=; b=BV4uAJM9KcnEijnvGj/SkVE4JpyemKj68phT5BYQpXC+sA48c1fkJ8YwY+onfENNYC OxivLy/ZV1dwNhi9kzwI0Yl8Zhg8u6EzKtXC3CuGUgUIL/XjusfWJI3JvEzmdxzxAsrz zEtBewdH9MqP4HeVyBxl4a+qXLkcUexPkG9icclHRyfZ9ULGIc1r0ZJxC5CiYYwuoCJI vnbvWjhN2saqtF48FCpZfGC1pDgAJ5YCqE/E7HNG1pfNADweyFWUs4JoAt4F14xEOAz2 Id7//DNBFwRe1w8NI+8J78o6KzoIttB8mjwEpmhskH8PVh3D2wyAywaGxxeLtifoTdut i7XA== 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=Ckmgu6xkFrumPVTVPqWAkYR5TKM7Uc1N43XEA579zJc=; b=clF+divuZZZHGkbEVo4EJluleitG4nO72cTmYkBs3aTbIRlPaQ6Mrh+X3Qm1DaiSTL Cq4szTjPIXikF25so9Vzu9NUbHetnfBTWpXV9LEu5xM+7DciAz8o4ajnXazt0zc5T8aL xVtTO4zQ5juiV9a7yn1+y91+HFO68nCqrLC/wlL0c4wKg3PrvYvTLmUOVmx0J5AUCENN SVs5k+oYnGtA/VlkgpkjkzGiAAOfkLNXHiv+brcwXl+ppC2eCkjr2VaWDnT96i23weIR Lo97lP1lsIeLBtdLld86fBXle9T+eD0xVytA2dgCcGjU5h9Lwwvxfxz374CMepz6OeIk CZuQ== X-Gm-Message-State: AOAM533YuCdb0HJEv7VFYzLWx3i1Z0fbgctsEf0oaeXNtwks4SJv6Khb gKjHkw4JesWnLD0LQtuz5rIRSk3oDycwzA== X-Received: by 2002:a62:2901:0:b029:28e:ef3d:10d2 with SMTP id p1-20020a6229010000b029028eef3d10d2mr10520721pfp.45.1623454909615; Fri, 11 Jun 2021 16:41:49 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 07/34] tcg: Split out region.c Date: Fri, 11 Jun 2021 16:41:17 -0700 Message-Id: <20210611234144.653682-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Luis Pires Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- tcg/tcg-internal.h | 37 +++ tcg/region.c | 572 +++++++++++++++++++++++++++++++++++++++++++++ tcg/tcg.c | 547 +------------------------------------------ tcg/meson.build | 1 + 4 files changed, 613 insertions(+), 544 deletions(-) create mode 100644 tcg/tcg-internal.h create mode 100644 tcg/region.c -- 2.25.1 diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h new file mode 100644 index 0000000000..b1dda343c2 --- /dev/null +++ b/tcg/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..6e34fcf775 --- /dev/null +++ b/tcg/region.c @@ -0,0 +1,572 @@ +/* + * 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 "tcg-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; + + 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 in the rw buffer, as that's the one into which + * buffer overruns could occur. Do not set guard pages in the rx + * buffer -- let that one use hugepages throughout. + */ + for (i = 0; i < region.n; i++) { + void *start, *end; + + tcg_region_bounds(i, &start, &end); + + /* + * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprotect + * rejects a permission change from RWX -> NONE. Guard pages are + * nice for bug detection but are not essential; ignore any failure. + */ + (void)qemu_mprotect_none(end, page_size); + } + + 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 eca72990c1..8c43c0f316 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -63,6 +63,7 @@ #include "elf.h" #include "exec/log.h" +#include "tcg-internal.h" /* Forward declarations for functions declared in tcg-target.c.inc and used here. */ @@ -153,10 +154,8 @@ static bool tcg_target_const_match(int64_t val, TCGType type, int ct); 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,453 +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; - - 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 in the rw buffer, as that's the one into which - * buffer overruns could occur. Do not set guard pages in the rx - * buffer -- let that one use hugepages throughout. - */ - for (i = 0; i < region.n; i++) { - void *start, *end; - - tcg_region_bounds(i, &start, &end); - - /* - * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprotect - * rejects a permission change from RWX -> NONE. Guard pages are - * nice for bug detection but are not essential; ignore any failure. - */ - (void)qemu_mprotect_none(end, page_size); - } - - 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) { @@ -988,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 Fri Jun 11 23:41:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458613 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp707627ejc; Fri, 11 Jun 2021 16:50:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8+aT13YW+avbUemjmt8+Jlch5uhU9kgDcrHEfLzsoLdcbQoB/6PEo6ZfQ4z8K49aMmfg6 X-Received: by 2002:a92:cd46:: with SMTP id v6mr5187993ilq.146.1623455402265; Fri, 11 Jun 2021 16:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455402; cv=none; d=google.com; s=arc-20160816; b=y7mHhdVNPkVnOaJNVH74ydHy0mxeiB1fJZcY+G3dkyS6xafMNXbQgUNa5Prgqdc1oW PVkLzbMQKJcy/ScjIkGBiAShZcwreHIk/grJaVHDZJWbxprlIKF5+unXp6blFQqa7nEl XO6pxlf6nHT8203GUBwy7IpGDdLsevgm7XNileaMi/5/nbfkFF1+SBtlcM40rJf3daRo nC7On2hf5Sx0nYp1rbHGoCmwHKG9ED9xHI/F5Av6ttPWqurHhwWbTT+N9nlOB0lBin3D hGepEs3T4IZVp6DfWRXSgLI3TIGm7tV+ysz/CeE0Bx5d6nHyuv3R5WJkBidlAiY5W67g 41pw== 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=Jny2BOuw8fi5i5pkScXK8a6G/xlMZW6X9SAJzS70TA4=; b=hMSvsoMmlHVZTwvqDWfm5S6y4XuCfQD5lIBBSPcAQJdTpcTIuWghylDgNQrvD86apJ GBAPPU6Y2vVQ/xBPjmvsjeM3A+T709qn3pOmotS+wxwSUEs9wLNaGfcUhRf4p7VZkVIa Cj7jYjSlbUG3uIkpKbtBZil8IlaQ2QPH/idf0+fTdj/4gaWA2ho3zMlxKPUxgU4n4ped XCVWWFaIwrFpILsUQeTL+xaZYNtG/WUmyUs6RqVm+pMfG3PMVs8ecM8YlJR1Ou0/OjVI hpPCO43jSz9ijwS4vrAC8GSBapKubGz7J3ESbTzUcVz34viIzrkm/QyVSSBUMwI004zL P1lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QDOqi2q0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g20si9264001jat.74.2021.06.11.16.50.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:50:02 -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=pass header.i=@linaro.org header.s=google header.b=QDOqi2q0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrquX-0003HI-ID for patch@linaro.org; Fri, 11 Jun 2021 19:50:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmf-0002Om-2n for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:53 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:36396) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmd-0002ba-ER for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:52 -0400 Received: by mail-pg1-x529.google.com with SMTP id 27so3678928pgy.3 for ; Fri, 11 Jun 2021 16:41: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=Jny2BOuw8fi5i5pkScXK8a6G/xlMZW6X9SAJzS70TA4=; b=QDOqi2q0hdwoLJUh1hs4iBexdH8qPBxjDOv+QdYPilPQLBK0O1u0sbBIfrDk6DpQpV 0pagxSnmvYFjy0MXt6Dw83KoV06ZLFzoKa8DIO5CCBeiRYle2uVdhrENsrmLOajhjllY lXNWEeSR1wH9ifPpVFov1j7dMofoA/HJ66gUU7j6TeIr2OkNjNZptoEshSMzOxpy5Nj9 K9l2pd/kC60Gm9GOJNCMng4TSCtd5FcxmtBV0VFIqqoGHIfp4FSlEjJdIA4GndejvmEg yFfSAqbGT6BkmkhKCnyM3jjiHuBvlQx5bD64PkkIU0FCVOkSnr8VMj3fPs7V6cXJDfGU J2uA== 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=Jny2BOuw8fi5i5pkScXK8a6G/xlMZW6X9SAJzS70TA4=; b=QLHL2mpuufovsZUDhi/YGh4EDiPVMjCDeS/WnOlOhRffPnPMF6ICGrnVjiA5HbvwSY UX5MqxoGRgMNK75hBYz1TI2eTY0RSHXjFKNgRnVDdJ7wQCF2kbGa3V1Xjm9Gh1bBeo2j 5GXov8XBJonuDEFbb51RhCVcvAYWR8LdVHo757TdqfLeAXHe00SejAoNVscwO0nyWL3s 3btWdnr78QRNuxy92qFRMjzKSkzXdzY0y4rC9RiunHJZymKYleWotUzeEEUX39mpSDze 3wRoP6NxwbcTtiDM3ETxigtd6xX5juMtSa3Cxzo/icasOO5pNQwJI0gaL2SFZVc/o4vY NDwA== X-Gm-Message-State: AOAM532VCr74txSbW5EX36XV07QlwJK+pNv8apEkJWNFlScV+eXOC9qO j46Hbz7BmfmYvqtUdsMrBmFIbGlo0S/mgw== X-Received: by 2002:a63:514f:: with SMTP id r15mr5829404pgl.374.1623454910270; Fri, 11 Jun 2021 16:41:50 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 08/34] accel/tcg: Inline cpu_gen_init Date: Fri, 11 Jun 2021 16:41:18 -0700 Message-Id: <20210611234144.653682-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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: Luis Pires Reviewed-by: Alex Bennée 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 04764626bc..337fbb11fa 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 Fri Jun 11 23:41:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458621 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp707642ejc; Fri, 11 Jun 2021 16:50:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywC/o1WQy83tTNSORp/eA9RKXXchWFfsGAsl4iiJ/09KTugojMHoygdeW0rVE9pyEKRR95 X-Received: by 2002:a05:6602:54:: with SMTP id z20mr5107955ioz.25.1623455404441; Fri, 11 Jun 2021 16:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455404; cv=none; d=google.com; s=arc-20160816; b=aUL0dGUkcyqBqviVEJa1LDbZfv7X6KyVOjcTdi5GWgK1YBTGVrV2snRlHVPhH45zfQ WJYjGo9RtvYavIjN/KoYLtKows6yxND3qV7OPV3z0AlQJXfghs6huSGx3QFM7I8hyCkY j9TWldyUdLYYPtvnqtxkJ9sXQiaAHHoF0HIgp+bdPx45Rjh5wH+K86BUxi4goiANlsCH 85BxGy1Uwu7KP73AJRjNnEary2ScZ6gS5YGXQFREsnDXiIZGmnVy6jhZB7KCfIy4SvSi xPd5qcFZKQ++Uk7Qbf5fXHOWfx13DcgRSbE14VlS261MqfGA/LQRIAuKs8bqw/3V15+8 OfbA== 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=2253jJ5p4Vo497H/gur1JJFAgAQrIuYpqdCY/mWMaZ8=; b=apfftZRJg/pVjZUuwI4z4G/JH6GQPo22lvShANdSU8UzwEIlVSnUR0T5ZUqoNGsJZ+ L6Jwp94BodC1vtC83FGqeg7OgMUZMa68YNbL1xgFlld9IUrwZS2rcnfhSj8co1nxiC++ o2ZSiydtdg+XUVJv8u8T47CiwFtfpe/nKnm+JtFWFM5V4QZt2xh0bU25yrmLbDGoscxq NUe0LxouUw9hLdodED8Bm4XHOKzmSP6uZFfeFv+AkRYfHBVPCHHy3I0kwn/Z5PwybOzu UQa4JILiiHoyWj5tZzwcFmdsjdEDtNo3bklNKD8il6YfUlL2mj2o0pjC8/GeW9q/oJR7 3Djg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i4jWYGjh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i10si9241021ioo.56.2021.06.11.16.50.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:50:04 -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=pass header.i=@linaro.org header.s=google header.b=i4jWYGjh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrquZ-0003LR-Mz for patch@linaro.org; Fri, 11 Jun 2021 19:50:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmi-0002a6-Ne for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:56 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:35455) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqme-0002ci-Eo for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:56 -0400 Received: by mail-pg1-x52e.google.com with SMTP id o9so3687755pgd.2 for ; Fri, 11 Jun 2021 16:41: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=2253jJ5p4Vo497H/gur1JJFAgAQrIuYpqdCY/mWMaZ8=; b=i4jWYGjhx1LBIdV3NB1NOp/IVyfgZMS2AtzugAFspIoMnLgZuMycdQhrpySjTy1vnp j1C6HBuTZ/0nxhc1O7m5mIzoqMzbmYx0TOTag1znvktH8b2YfI7XCGmV4zR18ajXdLRm yRo5UkfqIB/t6rZbeVFRmO2KO5RTGpE4CA2p7JaIQh8s0KfGR7yVzCRhoMHgf35cnxL7 +e6Jk2ZPPJqxaXFfEPIaN5xA/CaXDSpHTpiBuq343u0ecY4WJ4XBN8Lqi+/RarXakQQT 5FeQV3IRhVtW9gY74YfImQc4DrN2clr3CiD7paZ3+YKpSXmaRUzyI70gvVmdISBDH7cJ hwow== 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=2253jJ5p4Vo497H/gur1JJFAgAQrIuYpqdCY/mWMaZ8=; b=sFYJ/8LSHm7duRHTiY90cc57i5QbTZfxiXv1j85/i7TqHo+cO39ZNVEMZ/eQCRRW7z lJYH5zxvnWb1x1ICvI2AFIivQiWn+Z7OnBO317OUX6UXwUxX/kee/1buALSU1XDYra4q dII+1bm29KgYhS+balUO43Tj/OVkwzZIc0+aTKQoHnDy5TL4twLFNlLz70Mhfzu7hGfq UiQy9DstyazpmI7BDOMzjjmnivLMTAhxi4z3r9cWAh/PBjoORna7ON7HxwhlsndDu4Nx 7IJ0GyCpdQJNhJ7BqOzEDRpxxue4kVnO2cbgymu+zK8fqRiOWY1356D8KRO94445b1di Rjzg== X-Gm-Message-State: AOAM531qECo2I08Xjy2AgGv/LZ2vMHVRFH5ZkqcVMnneCgS/N1oJL9RZ EyKERQO3MlXq9SecfO2x6j4gg4Ufv2lLMw== X-Received: by 2002:a65:48c5:: with SMTP id o5mr4370491pgs.397.1623454910910; Fri, 11 Jun 2021 16:41:50 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 09/34] accel/tcg: Move alloc_code_gen_buffer to tcg/region.c Date: Fri, 11 Jun 2021 16:41:19 -0700 Message-Id: <20210611234144.653682-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Luis Pires Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 2 +- accel/tcg/translate-all.c | 414 +----------------------------------- tcg/region.c | 431 +++++++++++++++++++++++++++++++++++++- 3 files changed, 428 insertions(+), 419 deletions(-) -- 2.25.1 diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 74cb345308..834785fc23 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -873,7 +873,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 337fbb11fa..ad7a25d9f0 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 @@ -49,7 +48,6 @@ #include "exec/cputlb.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 6e34fcf775..162b4d6486 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,418 @@ 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,16 +848,23 @@ 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; + 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 Fri Jun 11 23:41: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: 458533 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp704440ejc; Fri, 11 Jun 2021 16:43:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3gRM6XEFQx2eRkJZdoxxiw2+X/8FtO2JttJhGPAm2kmRy5zGi39lbbL+sCjvDIpelEvXT X-Received: by 2002:a92:dd89:: with SMTP id g9mr5121431iln.209.1623455001186; Fri, 11 Jun 2021 16:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455001; cv=none; d=google.com; s=arc-20160816; b=iKx4ZgQXj59y4DQO8HRjGAtrHONcm900Y/6VTQykOKb6H8YDkx+ewNKVhFehowx8zs H0EiTKIqqPUorRywK/VycbY1xDnRbfqRgJDI1qA9pZ66hbU5p+js5r13QmItmmuSS7sG samwpRbnf9qFNpDOC4APL4TRs5tDDbr4wPiL0+ch5fHGnwo4JmGL16MOlaI1xesYu5qZ 3M55i+VV65A9BzP1ASTi18PaZ2/MOu74KK4SqHQHkO8FTlQtoeRFRH4FCj4ArFUun0DJ 6Jprq25/9pxH3lT1L6XWPjC26ECuaQphkSToly/UIXgNSx85UeWK4QAHbYh+9LFxpARy dVUQ== 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=20wQQlls/fCaj92TazJBcMQ1M/HJlvVa/gvE7cqK+n4=; b=0to6eT7Urn+6Y6u0D3ucKDhTR10reMirDm8dM7P86ygPt740WUNoRYyQ/PHvlsbH7J 1zHWDxN+iLdZD+ovToc58Nqk9RayAWzLvLfkElbV5wrp9dfBoSE4uTkVWF7XyJxsgIB/ qy7j2P3m2S8iiHr8SbgWYrbNbvZjjjAretHPHigbtFdXFBWwe1MCDcytWuUXnTcyR7P5 kvBVwjQSGfYJV7Z8FBXv4sJaZWDRfRC68pcZCpeOkzVbGlLZ9muTEoLq2OqEvnaNZo0x SxnA1saEmsvH1/zmve/rBeMuYZEzQs4pd0yfym/kAj97uuMbxQGQEuGUPA+PK89k+nyC jNMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AKGQ2jPv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v9si9248280ilu.78.2021.06.11.16.43.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:43:21 -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=pass header.i=@linaro.org header.s=google header.b=AKGQ2jPv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqo4-0002XQ-8J for patch@linaro.org; Fri, 11 Jun 2021 19:43:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmg-0002Ty-TR for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:54 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:40916) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmf-0002d8-4H for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:54 -0400 Received: by mail-pg1-x532.google.com with SMTP id j12so3672821pgh.7 for ; Fri, 11 Jun 2021 16:41: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=20wQQlls/fCaj92TazJBcMQ1M/HJlvVa/gvE7cqK+n4=; b=AKGQ2jPvAkyElvDqa9QIYvsAuMiBeSvLPL0aLeAbRPCiGw7aoynD8Zn3Px1FsLw8vT YSpgXI1VCKE+i/6zpkgkHeMHPM1Wl/g5gzjxA8ujEKlMYb9fAIF5/Y5/SSVpxIzQ8JOR 6ux1mbCk8VEbKZutYXjwYrlUYTuJmI9j4hUUkqIdmGconCmDwIVjXQH1YmsUm8CFxm6q hLH7wBBTtZbU+TfdHWwwSo40DxOOcqdWMXIZlWvqw3FXy0P2N/Ka3UgMbWsoc2fQtOJk EXObcgQD7mM3MsDI/4uIQCtNI01AuDEK+LiaS82WGRGxBGIeOm0+xkfFEUSbuAzRQq6C b9tA== 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=20wQQlls/fCaj92TazJBcMQ1M/HJlvVa/gvE7cqK+n4=; b=rPciTwMV9SmeyGnGE/kADTgN5htQWRy9VEvtH4px1FOW3l3Lbryr8ay1iJJbpHgSKt CO4AK3hxJjV10b8Kf091CGzFNlahPbnqiycr4dop2odlU/w/3OnmPhD4WJ3y1v+i1ZOT 2ufvCrWeUs3CE+vvOYr2tOR4Zz8bE9ErAGur6uOIrTELUZED4Wbmqrtelrc/PoJEorUu oQu/WXoiS507MLruTvb3WzbmYciaqVVXAtACwgOqu3NeV4YlXInTZhQNSw/DPZSWJYz9 othGdxhOzxB1UVdOy6X9Cz01UPdpm/5vpPSKPfsTY4NUbbk5CONQFS5kCq1PJAk6Kaho o7eA== X-Gm-Message-State: AOAM533Jly4bBG1VDVO2Hm8JNF4IVTQspaUzYpywAS6mkjtKEaYoH2wn pNFLbGkV9OUbKxHVjKKhEtOQCMjCQuv1Ag== X-Received: by 2002:a63:fe4a:: with SMTP id x10mr5944803pgj.132.1623454911566; Fri, 11 Jun 2021 16:41:51 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 10/34] accel/tcg: Rename tcg_init to tcg_init_machine Date: Fri, 11 Jun 2021 16:41:20 -0700 Message-Id: <20210611234144.653682-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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: Luis Pires Reviewed-by: Alex Bennée 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 Fri Jun 11 23:41:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458535 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp705192ejc; Fri, 11 Jun 2021 16:45:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHtK8vLl5C3Y2ZLuUDMed76iHOJYtofMSE1SVZdhGYgrpzDmEPaThnITFEei3ynAMiOvkQ X-Received: by 2002:a92:3610:: with SMTP id d16mr4855973ila.16.1623455100406; Fri, 11 Jun 2021 16:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455100; cv=none; d=google.com; s=arc-20160816; b=LF1rsqGdcjwImpm/w7ZHXkUPm/CzYti8MzHXleWL8ddfANrlSzHiD54xWtpXMVmc+K rYqYEy09fhsxWfQjVR2ngFzwRl3/Fh4N1kqs6EGeUuEc1LGVsdRfjsgHqmurSKhB18rt pwhCt9pfx9vcDWhldiPpkJdoye0laHv3/zt2RhcqbXII2/859AOJQWu8coRZlmsGJrvy PMkNydoL5BWipqJz7sqSWKiUZ8xjVUVZwkU+B0wUhUsMWTkg51sPe4asf2kD6xdlERXF 06JxVx2xAQUMgx/boBM2TqWrF+EuHtYicz0mU5sh+Idu4xDRsXZw27Qh5o6yQEXRPmJk ZBDA== 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=V0czrnxS9aM+DQ7xCluYyJs7kI06p24rRdcOwsnauus=; b=UbF4JOzsxFmmylrju7mRYSUOBPcBnu0ZpCyRKwVtGJrszZFFOndZTlo5HKCxauopQc /IM7tH1D8Q5WiWXBNrQFM2ZpNHc/3cW8idsodf1C2C7A76cJja2ZrKLiLRkqow87EeeE 2bEF0AQO5RIyXZLGOeZOFNIkmIXIaCyKkQqrJ8MX6YhZv54Y54jdJXt35gBw6PvUBVRu LKj2mxeILU/E6PWDGF22dTB1tpFOlG5dVK+9Py5RbHMMDpb21bEgb9gl2viYA8ay0udV cDqOLgxhDM3iMjIfyu/ZcuJGztFnX+nBqO7UN5ChBLGmM6E6SX3YbTfibEm4i+Y9Zk4S GDhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hbJJWqer; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v12si8355746jat.51.2021.06.11.16.45.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:45: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=pass header.i=@linaro.org header.s=google header.b=hbJJWqer; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqpf-0008NV-P8 for patch@linaro.org; Fri, 11 Jun 2021 19:44:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmh-0002VK-Al for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:55 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:35456) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmf-0002dY-HI for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:55 -0400 Received: by mail-pg1-x52f.google.com with SMTP id o9so3687772pgd.2 for ; Fri, 11 Jun 2021 16:41: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=V0czrnxS9aM+DQ7xCluYyJs7kI06p24rRdcOwsnauus=; b=hbJJWqerp2RAPX2vQZwmCmmdjkQpyUle3JTbjNxEzep6VQ2bWu0r13atInerV0cVev o9fn/AxqLX28godeD6qVc3nQvvR45r3Ur+WSaL1YPhOb9htNqs7QSy3Lxx3ApN97/OHb /S8UJfyWc2YDDDmk5UI1JeYE7LxCf/2mqRxWXBGpaNOUh1qQJHM7f+vRLEh2K9N8GRmz dtWaH6yRiLjaTuKk5NjFMjZy2KAYLJSIedOtcZ4XSp8xOKVpAm5iMdMvSqJ0GV4DbhXS 89PYtBSMA7xWht6CECDyDRpb8X91OlmjPyWhDteljqlxxWwp/DjiU0GX+DYZU1J47I2P lDtw== 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=V0czrnxS9aM+DQ7xCluYyJs7kI06p24rRdcOwsnauus=; b=nXBNiEqMUAsI57yC+m3I7Nt8BjngOvyx45KZ0OWbBzbCvJ3sx9SUBYuuGbv2z9bedB EdDv46jA/jy0kuy80H1srQf2G+uW7KhZf5rcKQgCdFvnl/+p/ymofwivCAcom9zvUnxc pCpvACtll8QwsfxYjg/tTJ5xU6Gu9qD+YwAXiXjED/qkRYpdqZd0j5tahuELCzAds/pE SGHZUN+1xkLuAdgeyZFgY60pb+NO2QlD5kQCeg2wabVL9tjWcQUmNsFS/B1o8ufuY/5W NHwuOg5T0mUoqFp/MriPJXqjGQwrKIGNSqhKkezWRs+PJQ6saTMNaHUcGIY/m3SuL0nF nyPg== X-Gm-Message-State: AOAM533wfh4o6AZI1CfiKvuSDv5snrsY4R9zx9i7N99dGbVHLDcEBFhM u6Tu5VqI7W/k0KJJgDCtzbGtZB50Xri+mg== X-Received: by 2002:a05:6a00:1a48:b029:2f4:4632:ff14 with SMTP id h8-20020a056a001a48b02902f44632ff14mr10524560pfv.44.1623454912289; Fri, 11 Jun 2021 16:41:52 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 11/34] tcg: Create tcg_init Date: Fri, 11 Jun 2021 16:41:21 -0700 Message-Id: <20210611234144.653682-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Luis Pires Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 3 +-- tcg/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 834785fc23..b3304ce095 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -873,7 +873,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); @@ -906,7 +905,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/tcg-internal.h b/tcg/tcg-internal.h index b1dda343c2..f13c564d9b 100644 --- a/tcg/tcg-internal.h +++ b/tcg/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 ad7a25d9f0..4f563b8724 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 8c43c0f316..2625d9e502 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 Fri Jun 11 23:41:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458627 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp710445ejc; Fri, 11 Jun 2021 16:55:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn7cA1sSCOJz1+jbHjeExvOmCMHo3gxyLIYo5aVN4/hOqcyxU7oppwZx5MCU4mzRfHunY1 X-Received: by 2002:a37:aa50:: with SMTP id t77mr257591qke.102.1623455722483; Fri, 11 Jun 2021 16:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455722; cv=none; d=google.com; s=arc-20160816; b=LUEi2uCdXKkc8rISXrG0umJFx1rkhYsLgrvWoLqoV3DSjPJRtqIlyOc/NUKRJmX8p0 jGHFR+tMjLjQQQa+ged/1QZ21fdBx4R8dMfrEVX0ivMqjxLXWRQCl60QpKi3mPolXLX4 wy5EFCI9OT9QubXctRa9D+oagHVkPSAorPebB/8z8JBZdaAg2kVyl8V/JK8Ht45exdE3 6YN6FHgmQAKcalO4kL8l0wkEWtonqQqFpGD9k2Psp0d951DLkxV+SkXiTgJHOu4ufxBX nhzH8bOEzF95Qxq2DIYcuCn2C5jLlJD0r3lsxyv/h9z9OR8yKdcjEJhXEeuDHopJ5lMz MkpQ== 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=rVXDKDz9VV+CueY0JW5pxfv4fXwklGCn3HdEg7Jb5yI=; b=DNdriDfXPUo7rXKy9JT1bB+zb+A3GBykbnkDJM2fuKAVsMiW9LE94mpZAw/ChrJni9 g5UzM4sVM6ksOqzvk5zZy9bg7nUh7V0Y6bRd51vxnHOtFAN4XdaKY+4zpJ1ZQFYV7oR0 YhRXGfWt8om8rj340YlgrN3n4YeljBazkCwOZhze1XuR5C285F87zEcaOyCZDgpLzejA tjrPByzIirRu3QHlkySxL0Bo8SZY2YTz0V9RqvpJqK36CN+SYo9zA1ilOrxfQUseH3lp J5IMg3rAVOpCE/32rROZ/TSQAeJnCYVU2zOxe7zc2k3rWry06cnm+ryKqsYw3Kk7EKxI R8bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q9cfMLAu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t63si5411367qkb.199.2021.06.11.16.55.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:55:22 -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=pass header.i=@linaro.org header.s=google header.b=Q9cfMLAu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:32872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqzh-0004vd-Oh for patch@linaro.org; Fri, 11 Jun 2021 19:55:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmk-0002ft-P1 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:58 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:39764) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmg-0002e4-6d for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:58 -0400 Received: by mail-pf1-x429.google.com with SMTP id k15so5692617pfp.6 for ; Fri, 11 Jun 2021 16:41: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=rVXDKDz9VV+CueY0JW5pxfv4fXwklGCn3HdEg7Jb5yI=; b=Q9cfMLAuN8JYVME3XH38A1xn5P1ELwmFrcR7Xthz+RL2ccSYOIgmtoPa5UMiFoaHOg 4IYUz/Ko6S2G6QzQoiOGu47IdGNFSu5Z4RWogXNEz2WK0z2lnfNjP1NSA/bcROncAZIh jIpaEgJY3oebgDu9RqdAyi4oFOPDWCwr5k4EHVGx+Zp08WP3WdNWKbOz/PCFQ8WeoJMy NSWJahdgLOcfwvk/A4IeIy6c9BqtdlNV4JXaxeuC35VItkNvLmurhQxnNQFDwMaCLauD PH1S5iY0F47+le5Jdc3lmJ8+7hA2/5C4sUstJkOpXcS7eJrG3VYRfRpWzxr/0kP9s+Q7 +ebA== 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=rVXDKDz9VV+CueY0JW5pxfv4fXwklGCn3HdEg7Jb5yI=; b=R5++/nYACrzhvOKH/del64I7ijRr9ze3m4c4rwLVwyXR+nX12hZa6MCAp8OresycUg 33tTHys0avv6oUBL9teAj2+eJjR7ksjYWvLJp7J41YlymmzE3cpnPPea9Oo4UZ9a4gVo iByvs5D/X12XRHGicqxbNKJpL13X+a5IHJYQGSVyAMTVWMYVuP7tOwG+EeSL292t2ALp 6ExLvT7AIfpuQrn7UNU/bAy481V8GR3Pt6HXk4/9hgM56b8jnGRjYvS00iZf9DJaS1MI c/Pce1aVLf/hoH7PSTfL37hZ+JR2Gv9BrO2Z7xv4eRcHBWaDGJERkOCAM7Ses2DYWfmu OFMg== X-Gm-Message-State: AOAM5302y9TzhRMJUzF9EnNn/sNjDmHuzqn32rbU/ATWs/mBav1T23ON vpflBLJdi2IlTCBegv/RqKRPCNHFja07zw== X-Received: by 2002:a65:6114:: with SMTP id z20mr5981132pgu.249.1623454912873; Fri, 11 Jun 2021 16:41:52 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 12/34] accel/tcg: Merge tcg_exec_init into tcg_init_machine Date: Fri, 11 Jun 2021 16:41:22 -0700 Message-Id: <20210611234144.653682-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Luis Pires Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- accel/tcg/internal.h | 2 ++ include/sysemu/tcg.h | 2 -- accel/tcg/tcg-all.c | 16 +++++++++++++++- accel/tcg/translate-all.c | 21 ++------------------- bsd-user/main.c | 2 +- 5 files changed, 20 insertions(+), 23 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..e990180c4b 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,21 @@ 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 4f563b8724..59609d62d5 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) { diff --git a/bsd-user/main.c b/bsd-user/main.c index 270cf2ca70..fe66204b6b 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -813,7 +813,7 @@ int main(int argc, char **argv) envlist_free(envlist); /* - * Now that page sizes are configured in tcg_exec_init() we can do + * Now that page sizes are configured we can do * proper page alignment for guest_base. */ guest_base = HOST_PAGE_ALIGN(guest_base); From patchwork Fri Jun 11 23:41:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458633 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1374379jae; Fri, 11 Jun 2021 16:57:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDuxrpqbuOYrBPjmK1uE77C2gTtFHmDRDwG15Qzri4D9KWbEdlP9nhNrCLVzmfhRjVzQTb X-Received: by 2002:a05:6e02:12c9:: with SMTP id i9mr4999412ilm.17.1623455853611; Fri, 11 Jun 2021 16:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455853; cv=none; d=google.com; s=arc-20160816; b=A1E0fuipeqbKhTILA7+C46QVyXKv73WWJRjv6a/0pf3YaX9ZiLzFJVNBQOQTWL992y K5SlAr2S7mii74OBlYgj/ZQH3J3YomoADwxeEREkywH6uE10yOjnccRMYOkRyi+fzUcM gtrK+YuOQnkxC/+nmMysYBAf5G9zyveApjzqJeALjQXDDEwdMYbO0NHqnkTUPSJI/NcF HPtuheKHovnc/JFXDVDtJwI0YQkj+OrW4NoTWPa6vGL6sJGAG0gp0gViKb0qLxJw2E/o mWqlG+ru5u0Dj1Sz1DJPee02Yg/b3i5CIx7m+51q0Ntt5PuZANx7QYnlZtHfGjunfoTI q4dQ== 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=qR3R54ldm2hlks4jTNDifo1l/88jznlHccjT2381AZE=; b=lSM3F+xUMDyRw5qe12VbX/uZWe1CGdLsExI6UxLKH/T9JRoL0WJjgygArXKyzIku3K m13QP3iXhw0D7BcRo5Upr6BQryrPOzA5/iwSGOLAF+5XTKD400NkfomKJbbDvaXMBV6W DYXuH0ZNwxXwnxsV2oFvmpZ0BFsfApynkDIfsld/T5mEUF5wfWQHd16PvhtG28bOXkbu v6IX2OQfQrD9bO/RICsPCUaQa+hqoCEzjdOpJ/c04d1Gh7XqhQeGoH5Qqo3RYwZGZ6bL l1yuXxKULaFV1RfbgRDPy8Uf8tcxCG2OpVxy6+hToYzAVUw9NoUm/dq4zjMMXJyQcN+g QcMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HFqOKFv1; 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 n6si7601780ili.152.2021.06.11.16.57.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:57:33 -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=HFqOKFv1; 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]:39442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr1p-00010e-2L for patch@linaro.org; Fri, 11 Jun 2021 19:57:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmq-00031V-LR for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:04 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:38835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmg-0002ep-R8 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:04 -0400 Received: by mail-pl1-x631.google.com with SMTP id 69so3599959plc.5 for ; Fri, 11 Jun 2021 16:41:54 -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=qR3R54ldm2hlks4jTNDifo1l/88jznlHccjT2381AZE=; b=HFqOKFv1yij89TQD7WLpcIcI/eicB91mmdQf2Lx/EmLYmGjWoKs/53PcYJEFJAF5BD Cv8uMZ+DFxb198ZMSrOGz7JRIysCxcm2AlevJbKsFOYxu3KJqnfxfO6QaBPK8pHio2H5 eFtoGBERNo9kMRRfnkEzhaXt03k/JSMJwCqSR4UGGNKpZykvri2TfkCZBYp7WtOYemcM /eqtAfMlsA6qWE2A3Sd2jiGn5uN3ZtH0jhtOC96vmINFQ1rsUkWWGADEACD4SLdg04dh oDmU8YTmmsGXmx0dUYuFyUZmHBhOiUxzD1iBr0ug/a6kOBFyQZQZ/4ptfctAUa28U9sc zAIw== 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=qR3R54ldm2hlks4jTNDifo1l/88jznlHccjT2381AZE=; b=WU6K3UOm1QHmQXCo/WFGUrHNlS07+SpqQnx2O/LTLBB5zt5/vbMD1qZZVRvHalMjtb ErcDqAByZCVSPARBmZPv1HqzTRkOlpnk/nbzd7EszMg7VOaxArZneZZ78s6zubS2laVy EONhTJYYDUCBg5XMu8y4fDTUFUsxaIQX8jXnFOz++UBuWukSWCouSt/H6KocIjAaH99Y RS6TIm1iY99fYMxNnLrUykPHc9lNIwOh3Pz4UzbO4NONF0R8ZNoGN9nI3x7MrNEJ+2BJ C0a2ggjfXNMnrF2B4CkcOwo3v3+bBWah/LVSoZHShr2EgJv74Ragh0eFGDdwWVqOB/8J JTAg== X-Gm-Message-State: AOAM532HnHqcy4G8NGMDQ3IV+rhpvNc9QU9OzxKNlcowXfA/rTbWFeCl UJQwm31t6nItGYt6QbitUoY6l8y0jplrOQ== X-Received: by 2002:a17:90a:4a89:: with SMTP id f9mr11571593pjh.50.1623454913496; Fri, 11 Jun 2021 16:41:53 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 13/34] accel/tcg: Use MiB in tcg_init_machine Date: Fri, 11 Jun 2021 16:41:23 -0700 Message-Id: <20210611234144.653682-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.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=unavailable 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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Alex Bennée Reviewed-by: Luis Pires Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/tcg-all.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.25.1 diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index e990180c4b..1ee89902c3 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 "qemu/units.h" #include "internal.h" struct TCGState { @@ -115,7 +116,7 @@ static int tcg_init_machine(MachineState *ms) page_init(); tb_htable_init(); - tcg_init(s->tb_size * 1024 * 1024, s->splitwx_enabled); + tcg_init(s->tb_size * MiB, s->splitwx_enabled); #if defined(CONFIG_SOFTMMU) /* From patchwork Fri Jun 11 23:41: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: 458624 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp709536ejc; Fri, 11 Jun 2021 16:53:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwK5lV9bCCOlxZ1atZSFcTPRkJDPaMqP4IfYAClTa2nqWTzK9iRDj7cM48awuyRG885gFmr X-Received: by 2002:a05:6e02:c33:: with SMTP id q19mr5140669ilg.2.1623455617315; Fri, 11 Jun 2021 16:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455617; cv=none; d=google.com; s=arc-20160816; b=Nb0tiKXZPpKWPYvX4TM6H5YmHPKzGPyiD9HhyagOZLD22+INIUmbdxPZw939riwyLb V8esO3mWzz++ZXpECzt+Ga5Bu18NAx9kaCeiDQsD6aEMPk1IQXhABSzs2tFGbQdAqbQJ gzyH+YhwawM9YOc+0AG+Gzwsr93jO+CleUsk+ZaCWJJBK/rM/7QDZxazHEx5tqaDbv0X IgtSXAU/9RksPGPMXuP6fPsMFcPneSyDuMP1eSWB9nEwTL0J9q5Kcm8RhV8IRaVCO8E7 BbhfZ595UHQ17LOasx9ZqEiOlDiz9S2O2YKezzp5VIX0uoqrn+hZ/0PaEqM5stjoxLYD n8ug== 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=iD7yxVWh28zLth+n9Lv4DaX50utGIU5Dj8a00XRtdrI=; b=XxSOUTFikJoV04OFkIIHX8TNZuBWZbVSn8Nf1OaqrIZemMhjqdeRhD6Psusq0DsLdT mzLXoLAuWXiO9RPj9+15Ds061ZQIw+5bBjv6zpWnZmyJqdGm4ECPYDWAGdj2GfIkgPho eFfcTdvY+E1v4Yw8ecBvp8bEltVM967bq0qDc9p0DZKrFM1+vg1OD84JXoEfz6zSNYfQ B70ElfP70QUuZkt+VIMP+tRoW1VDt0GdyyJmNLRi4XIx2aN1kK4ktNk0TvxfzmyrOohk 7qP7eUkF9/IB1hRybyBnslOZiqvODikv51ej+euXrlAVMWoq1pug+Qc9QUNiJZU4x40m YA2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VLls0+rL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x15si6886327ilu.105.2021.06.11.16.53.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:53: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=pass header.i=@linaro.org header.s=google header.b=VLls0+rL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqy0-0007wa-KQ for patch@linaro.org; Fri, 11 Jun 2021 19:53:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqml-0002i4-CJ for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:59 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:33739) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmh-0002fU-FV for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:59 -0400 Received: by mail-pf1-x435.google.com with SMTP id p13so5713972pfw.0 for ; Fri, 11 Jun 2021 16:41:54 -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=iD7yxVWh28zLth+n9Lv4DaX50utGIU5Dj8a00XRtdrI=; b=VLls0+rLBWFQAL6q/M4y39R3MuWoqUQWxCASwKomRwCR9BsNL2Ce/J/Ynst4DphROb hMhy+igqjJ1CLgn6Sn+HPCRsUOgY4Djqtrxt4w7lihusUzUrPM/21v+d13jhu35X7pQX 6bH/FzxrbXUXLjoZiVqEo7/sfHOWo4PEb3KuS2rjl5yOZUWFDR0cINgWqyw34gvs+i5L M4uN6xj/bNCDuNQ+W6fIu1F6YirFSJoceWw0iqaiQPlNsm7adXOicd+3/Psg5xqyt33X xw0vSpm2D9DL3zjbfzOEUZL+LiuLkC8tHaOX+VKHy8XIYUvOFqR6gQaAg7RIeIlLFirp Z94Q== 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=iD7yxVWh28zLth+n9Lv4DaX50utGIU5Dj8a00XRtdrI=; b=X2NMsfvPQRtns8/Vc/1jJ5ZB8waL0A4NI2RkvVdYaQJeYFk1IGQ62OF1fAiNVsvuai IRmDvQfYhC694rIj7xqtaGm/+Vvg4eyBt4NwAlJA3tg/VqG5UnQqzTIw+FeQk/FsNPLy mhaAkZYmcQaA6pokD7gkQHV/ywx/zkgy3By9EAOu62PjL8Uzd96obWKuZnBPqT+tLFMA fdyg8YRurkqOo99uu4rZNAxg/xtopMUK54P//9SoKncAE1uTad7srFfYLJhPF9pWe1lw SRysXHccz/XZLsyBMVe6zpnVaS3iXW39ra9vtjqr5srBnIr17p01QSVB9hjkwrWjrs+y vk6w== X-Gm-Message-State: AOAM531jPxKObALXIVCVtEDji8vLSlwaCcZYD69CNh1+m3JniT9W6AEu 31Iv+HGw7yoniBRe6Q98vaFAYYbV2N2jtw== X-Received: by 2002:a63:ff43:: with SMTP id s3mr6002879pgk.86.1623454914120; Fri, 11 Jun 2021 16:41:54 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 14/34] accel/tcg: Pass down max_cpus to tcg_init Date: Fri, 11 Jun 2021 16:41:24 -0700 Message-Id: <20210611234144.653682-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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: Luis Pires Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 2 +- tcg/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 b3304ce095..2316a64139 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -905,7 +905,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/tcg-internal.h b/tcg/tcg-internal.h index f13c564d9b..fcfeca232f 100644 --- a/tcg/tcg-internal.h +++ b/tcg/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 1ee89902c3..00803f76d8 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -33,6 +33,9 @@ #include "qemu/accel.h" #include "qapi/qapi-builtin-visit.h" #include "qemu/units.h" +#if !defined(CONFIG_USER_ONLY) +#include "hw/boards.h" +#endif #include "internal.h" struct TCGState { @@ -110,13 +113,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 * MiB, s->splitwx_enabled); + tcg_init(s->tb_size * MiB, s->splitwx_enabled, max_cpus); #if defined(CONFIG_SOFTMMU) /* diff --git a/tcg/region.c b/tcg/region.c index 162b4d6486..877baf16f5 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 "tcg-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, @@ -848,7 +838,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; @@ -865,7 +855,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 2625d9e502..5cc384e205 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 Fri Jun 11 23:41:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458542 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp707281ejc; Fri, 11 Jun 2021 16:49:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAc/Tl0kPmmnyKWSm47yhaHmUTkL/RubF0qifA4iCj3u6D2/3YN61f0wBzylS9Zx5/8+q7 X-Received: by 2002:a05:6602:2215:: with SMTP id n21mr5143102ion.80.1623455361117; Fri, 11 Jun 2021 16:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455361; cv=none; d=google.com; s=arc-20160816; b=c8PKwheVPg0yNFJetZ9Gho0ARCLkR8Vvu5ZK4x5OSbhsr0h7teNsbWQy+p72HqqxXv FrlYEDkk1AzXlF5nWuhNox2+xjUBRTGeMMnNh3ikZSH9axIbrX9vYOxAgl79/tiqU0xo DuxfVQKg/zY5RsF3m/j2fqs5fyDgBjeyIjaRD0sMxGAPPDTdrnN8HjZL7lc95Lv/TAjW 75eQwdGXrQglKWwmo4cmS0HgROBKmIOa45Jk3Uh4D0oHag1zc5l+NXCNqjwthEz7FuKl F5ZHcQZj6YrBluDVCqLsbRSQ/bxqnhEeEEHXOmRWJwtPysq4XlYZyJeJE6fNJ0UIEUqq ArHg== 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=iYzRJ65/H4fLD/mZbc5LqELD84drbVwSLcSFgKAxf3E=; b=Gqf2/rBkiMAxyVI64UMpceXk+g17xgXGB9+Zg2Ktjh5HELFv5ZN8NqD3yIJocnkBQf WRCjP6agBi4Q8C+sbBCjVxOut9NvnLf0xt2xoIioQrWyw2K6ToQINRdXrBaO0sFQVSYy okyaSk6agjw17iBPqrSkja8vqSvzPrmBxIN/3IdXaAUks24Z1emsh6I3JxAt3ucxmsXE bMuCcPb75opNT2nkNSnCBFgFziBBhvDU2aDQNcXdrxKmCW/nl+C4Zn7sX4vSdaYvB7D/ PcN6GFGz/1sjeqkK93bdmY1T9rtRzVHKK/sabgpL6C3TpWVlkQgeh3Ecz08X979e5n0c B4Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mmEhLw68; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i13si9794990ilm.45.2021.06.11.16.49.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:49:21 -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=pass header.i=@linaro.org header.s=google header.b=mmEhLw68; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqts-0001Mz-9d for patch@linaro.org; Fri, 11 Jun 2021 19:49:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqml-0002gy-36 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:59 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:37558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmh-0002gM-Vq for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:58 -0400 Received: by mail-pl1-x62b.google.com with SMTP id h12so3599742plf.4 for ; Fri, 11 Jun 2021 16:41: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=iYzRJ65/H4fLD/mZbc5LqELD84drbVwSLcSFgKAxf3E=; b=mmEhLw68a9vsbek7USdTzB4NDKKrrcGQkon4VMBgVVZYNzY6go3QKre4VkvArwmoJT hiC3HfuE5VoktDdLtfSgkdXmM1hF4w7Ev4HWwIK20G94wMPJrrliPa8tTVbttAc4Q9Es 2M5RpGYQQ2vVxIQeEapqbkeFlc1cqJDvJHmbx6cScNh/fCbuOQfJK+MB1EPbEWkKYfYG 5FphL3RnPGWRrH6/DPpoqkr1bGdY4GTUgHSAPMETSFHh1VcKHEobKpz5wVScaMlvi9QD sB9YTPEuPQsTloRsiTWSZJIUYWgY6XjLNhSjatLHWwF1b7TZ4URNSzLtscuMHkATExWl 7wIQ== 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=iYzRJ65/H4fLD/mZbc5LqELD84drbVwSLcSFgKAxf3E=; b=E5hINmK54qhge6ackav44X2grWOskyuNbaM7LEMxHvz1N+f5RRBBhvgzhwEbhUZfke uc0lW928x3lz1AYSHGEfxQPmxLA7gTIf+R0l1Uw4Fpfu4+iEyPsSUxQ64JxdQ9iDmujT yAD++Au8JHOHmcV/lWsr7ottkRjnalwFVMic7Jsr4hCKNUxjswyS8tTWN+SG+fHfiheR IHwu77GR7tuWPDokL5mwZgFqWRnsEB91QP4JgS8wTZ6uFfjVGMGcP2VSCOBTLWvoKw3t cOKmT/2vjw07W6nbP0Q4ND6rHEcNE/2A9MB42I3j3kKv0K9TyNQB9hG64oYlJUXqA/nG kZag== X-Gm-Message-State: AOAM532/TdUeYDoEBW8NHoQ0PcOiTr3ajqf+zth10Dk2PPnJ54TpuOhB 2wf7g4x/ZYpqjBQjrftLFH8zTfJv5FTsRg== X-Received: by 2002:a17:90a:4f0a:: with SMTP id p10mr11551371pjh.36.1623454914732; Fri, 11 Jun 2021 16:41:54 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 15/34] tcg: Introduce tcg_max_ctxs Date: Fri, 11 Jun 2021 16:41:25 -0700 Message-Id: <20210611234144.653682-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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: Luis Pires Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/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/tcg-internal.h b/tcg/tcg-internal.h index fcfeca232f..f9906523da 100644 --- a/tcg/tcg-internal.h +++ b/tcg/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 877baf16f5..57069a38ff 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); @@ -934,7 +934,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; @@ -970,7 +970,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 5cc384e205..9880d5205e 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -43,11 +43,6 @@ #define NO_CPU_IO_DEFS #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 Fri Jun 11 23:41:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458645 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1374598jae; Fri, 11 Jun 2021 16:58:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXVzx5W2HhDguxC8E4O5dEEn3FI7jzcwp7SkbybrjFo7YRlLyxjMc+UlcJxfsLty9tKW04 X-Received: by 2002:ac8:12ca:: with SMTP id b10mr6161080qtj.108.1623455887508; Fri, 11 Jun 2021 16:58:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455887; cv=none; d=google.com; s=arc-20160816; b=gbmReafM4+E92EPDgvv3LZBizya7z8taIhHqWtRNPFN7UjLFpsW95SNrh2om6Xu+TL RdMc4axvf9MfJj5oeKpKjgliDCebrWNCAf3clh7bK7tL0xHMtYS3N2LgxG3PuUK+wVLs kp7f+F8YjzLJ1w62wN9osQvW+i7kyFjiQhRrl0mOw8gigwRDOTKvPVOjFCNf2HVLkMc1 YEOApnUE/qIWxRWCyOe7HvwXTk0L3SPGkclAaWG0sMIef4IeYoeVG1s0tO/dVKyabY4C +0yfKDMBiSUlPFplHXtAMC/vip9/3Kry0AsAiwwpltNaGGMuq7qewLxo4rwaFmyGTDD0 PREA== 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=8HsYggvbdO2XX20gPsB7M9d1CYcUQ1Rbefdqb0m3BAQ=; b=PkmdMK1SkchoFdStqdSQdmWY3Z0CT7ReDn/jGnfv5ULsF6VnnlJPvutIy1b8mbjRRQ MXRXyTxpfEZ0VTHNWm5meeNmRUbijMf46D+jUhmwsdNj27bZA4PL8mfWJceFX5LrvHwp jJOjlBUWQ8AEt9AtTr2M9tum1pkEvjVNmSe4tZcaRFeRlIjs9GK0u2oozcwtKsy1gCuH z4wRk5pJYu+d6ceZve037tgjdupx3gYZgHxoN+mFsxOccoUPXo+Z3t7irv64k5uNUqpV UBiV08h/tCGBt8rCZo5CJRTx7p1Cxg6FscuIJM9PlX/Vt3UmqPQDmrDCemOWnYwaOpuO mlRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WgpGzuPG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e5si1015605qtw.11.2021.06.11.16.58.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:58:07 -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=pass header.i=@linaro.org header.s=google header.b=WgpGzuPG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr2M-0000om-IY for patch@linaro.org; Fri, 11 Jun 2021 19:58:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqml-0002k2-T6 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:59 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:37413) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmi-0002gT-Np for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:41:59 -0400 Received: by mail-pg1-x534.google.com with SMTP id t9so3667591pgn.4 for ; Fri, 11 Jun 2021 16:41: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=8HsYggvbdO2XX20gPsB7M9d1CYcUQ1Rbefdqb0m3BAQ=; b=WgpGzuPGbGWB9yCqw8OF/kAfulQuoAP69/26JjEdl9iUcocP2v7Nv3I4egLVtN4oD/ 2ZY6VMMdC1HGTFxfLmNVUBLVz6sE7rWYsULgApMZbv1iTUAh5sksdA1XcOB6iIfYC5JF 10qRfDx9EXwEJhmoGDDG96PVd2oHiNjkt425DVTsrWQ1fzLKrFfQFix352yPTAqQ05dy 1ecEN4A28RfECorTcOLZxsgDWxStraJyQ3CZxFOLT3RJoaQuDadQSQGuB0eaueIJlN8o yzNXbYXQEfOvalbtmwE/CTmvxEjjKU8WMhme9FdVNYqiN0dGET1I1GfMKdhH+jtVHu2D QgUA== 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=8HsYggvbdO2XX20gPsB7M9d1CYcUQ1Rbefdqb0m3BAQ=; b=CsCUd2a/NKhwLowYhSB3F8e98wxrKPxOuTzmRhiNaGNm1JSoXPFOZqhbVbS3GciAcS gtA8NRO5B0pzwne69Gv6AeOAzgzCC9Ep9XN8WyiguVwENqQa0C/dXhc4BmKYJBOE8RXF qImTNo3d6grtljs6yW2thMrPnIUQeKR/GpLRkSRexJzDKO8y46VMVVDcYiQ4z673r6Qo Kh9x/EQZyq3SiquY+8HZJzhLxm/ZGiBkaBBY+scVfxeSdZc8nnss2giEvtyc5ubk7yNc xSP5No4vCeVqV8nDFnnH+s9foobOC7+BKpZtXXZ9LWdPPrU6QQbG96vUYJTJgR4PAsRD DSGg== X-Gm-Message-State: AOAM5333KlI61jktiQvBrc422tWeaLfxR5dop5IO4zyWdhuq0CSV1ako yhpLxUOErjZdzBclkkXhsTPKaVbCSvud/g== X-Received: by 2002:a62:78d4:0:b029:2ea:ba:234c with SMTP id t203-20020a6278d40000b02902ea00ba234cmr10615690pfc.53.1623454915220; Fri, 11 Jun 2021 16:41:55 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 16/34] tcg: Move MAX_CODE_GEN_BUFFER_SIZE to tcg-target.h Date: Fri, 11 Jun 2021 16:41:26 -0700 Message-Id: <20210611234144.653682-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Luis Pires Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- 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 | 33 +++++---------------------------- 10 files changed, 23 insertions(+), 28 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 d6222ba2db..57fd0c0c74 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 52af6d8bc5..d0b5f3fa64 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 57069a38ff..13087aa0c9 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -401,37 +401,14 @@ static size_t tcg_n_regions(unsigned max_cpus) /* * 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 Fri Jun 11 23:41:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458625 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp709859ejc; Fri, 11 Jun 2021 16:54:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw39tkhYkdhsYPEnLfijIM8CpEF/SVmgxDMYcIGVE9hsNvgbNUAqF45p0hT01ZHEeJQabHJ X-Received: by 2002:a05:6e02:1284:: with SMTP id y4mr5276778ilq.240.1623455654712; Fri, 11 Jun 2021 16:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455654; cv=none; d=google.com; s=arc-20160816; b=TZgi4YaLsOjMGEoNe2f4QU5YMOOtbewfGAJvulMlREmbTknXukuo6f5QVFwDXT9DsX sgs97WKrlY9JbE8lRCEwECnljtNZwy/wTLKPjMTEliK1157+TwgYkNebGzpCevyxo2RH I7O9678Q4711O7auTAkZABkM8EYsvfIXH9c0kpRXViunBxzmTZXjPUU3ltjIuwytxkO+ F06ppb6NVbK1Ibds8VqdI7xcefrSYJ//gwG5mTgAH6zuXg0+RyVZWSZbmQUJR1/1UCJl kYp6tL7hPCu2LbRP+JJbtGG+wHpJBqeaZd2PSuWwPEWm2737+BepAho7Yj7hUrTgjnHm 26tQ== 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=v3dqO5xG9NML/3lBzhEEI0lp1xg70tk/1JnUT4HyRn4=; b=H4nxLEBTPet9l0Qbw1fVs1JkIc/DJyqhbG9UkEMVCd0pASU2NOfDViIfSwfly1nubS 6okdQ7vQn23/fqIN9aQ6wwFFoYhRUqdhyVq63fHRkoviaQSAeEpM7z+GPZ2duawRxnyn 80pR/yEA7c2APdONYaUUf/jYGkDsuQRfazIX0TzIca72J2dClUo42icVQVAm5D2fMDnw dI28IJECBZjlIiK0LtyNshjpe10qS0otKiWQljvlF2ZmEk3JGbkSgMive89I0Y3sipwx 9YGGtWe+ZpKpaCSPtGzRWD8bj+I2dcEHsaf7y9LMQzy8C9S07w+BFgAODsdnkaGnzQoz Agyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SgzSfOLg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 17si7963362ilg.11.2021.06.11.16.54.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:54:14 -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=pass header.i=@linaro.org header.s=google header.b=SgzSfOLg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqyc-0002er-1a for patch@linaro.org; Fri, 11 Jun 2021 19:54:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmn-0002pt-GM for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:01 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:42634) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmj-0002gd-0W for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:01 -0400 Received: by mail-pl1-x62b.google.com with SMTP id v13so3599477ple.9 for ; Fri, 11 Jun 2021 16:41: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=v3dqO5xG9NML/3lBzhEEI0lp1xg70tk/1JnUT4HyRn4=; b=SgzSfOLgLvR+/tldyUQnrXnw3IY2Z8dZdrWpIBwdGL8clujPdTWGOpSZjQf8/39uMh u68JqX7yNQeKioPWaR5aY5L1PoSjMkxvA607R90LDXYHMLdb7ucox2RTl6t819/ax/25 X3xPZDEru+9ELaSUZDHXfAHbrS/ogG12DD3/3AH4sOhPMEw7Nf+0yTv5Cte0X80XCtmA IowTR4XT69QITBK3j9z6an1b30gqEZW034coJIFmJY4+NMQtC8YogvxRbDFERy1meG3U Pmyt++uVnaOJXEsnPJXFlLSJWZoKBOOjTTNQNVa/rrM07m09sC3k5dvjTntLqD7pPGIF VeYg== 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=v3dqO5xG9NML/3lBzhEEI0lp1xg70tk/1JnUT4HyRn4=; b=L2v7voRhaTFgopzCWGcB2SU+TpKhmK18YBmzJOna5xTJ0OHnRjOO+jB5/faDu7ea6p H2npe/nm2/IqVtY1QHMZc2Fzs09W/SiAkHdwtYiZMiVFwtk7U+rGCN49YzFQkG/RJoc8 ICNlhIAoLWFv7yg38ZboAAlHGjeutP0tLmFb0mDAu/FBN8twZK1xiSb/vV02z7M6sqrp hu/Qk/2+B2G5osyGIgZ/cInXjdzE/K0RciqKcOWktlzRGrGoFdF5gKhCFscf6lOlRRYq eJC2nUic10KICQMaSIERbxXFOr3yPdbajtSsKTm4yAywIyi25DTMUVrgcDF/BIP8Bku3 aC0Q== X-Gm-Message-State: AOAM532h8EnNa0PJ2xRBV0mjKK9Z4SYHbQddQ+6xGZxcOVOznLlmiD00 vGPvB9ehce0ZlLJU/WtdUg0y06S8QcEgeQ== X-Received: by 2002:a17:90a:de04:: with SMTP id m4mr6713608pjv.40.1623454915732; Fri, 11 Jun 2021 16:41:55 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 17/34] tcg: Replace region.end with region.total_size Date: Fri, 11 Jun 2021 16:41:27 -0700 Message-Id: <20210611234144.653682-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Luis Pires Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- tcg/region.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 13087aa0c9..7a34c96d74 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -48,10 +48,10 @@ struct tcg_region_state { /* 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 */ + size_t total_size; /* size of entire buffer, >= n * stride */ /* fields protected by the lock */ size_t current; /* current region index */ @@ -278,8 +278,9 @@ static void tcg_region_bounds(size_t curr_region, void **pstart, void **pend) if (curr_region == 0) { start = region.start; } + /* The final region may have a few extra pages due to earlier rounding. */ if (curr_region == region.n - 1) { - end = region.end; + end = region.start_aligned + region.total_size; } *pstart = start; @@ -817,8 +818,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; @@ -830,19 +831,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 */ @@ -856,9 +858,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 in the rw buffer, as that's the one into which @@ -899,7 +903,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); } /* @@ -940,8 +944,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 Fri Jun 11 23:41:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458658 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1375150jae; Fri, 11 Jun 2021 16:59:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWHrMyoGDFYIKQfQaunX4r5r+I7/bixMhjF9rGrwge6x9DPaaVnOUtBA+e8ywg7KfsWK42 X-Received: by 2002:a0c:ff48:: with SMTP id y8mr7453319qvt.29.1623455965950; Fri, 11 Jun 2021 16:59:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455965; cv=none; d=google.com; s=arc-20160816; b=P+HCrnb5CZavYIfAxZs+jUJpWzwT3kZRIplnPykvTjnlOB8ZKad+b0wu6YECTRp8Kn D9DIMUUfYikGUouByKpSfx1oc6t29ZvFktBW8H++dc3JxRiwED/UtMUVBErFdnl0DKzq 8ruee4MpN7OXQz/QK/yC2iBdEgL1+NDKikaHbZ0ogk6fyw2wkfAbbLDusgwGHI+eswHw BXMu5U00nyaRs2sYRptKtLQDwbEQoVefJ0LJ3D6MMVbEBS459JchrYQp/Fy/NrX8bK/j FS1Hw3/SI0J3g8az6HtaE1GTErW5p23sw45fZ5kYwXPfqc7rMFLjuxIzE7bKi5bYMaEc jq9Q== 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=MbFhWXhNwq6PG/hB7MohFhOazYLOvAHs1WJapBuDbmg=; b=zKeO2T8kQtPEl/X7TM4JijgJVE9tP/N8hqLyEZlRof+SSRkpxY+VMEa7aClGzvZrve 9CH5oIOjLCcdwDlAnCsHuJh0ev9v/7zfSMRsVbWmmnXTLKnyDOxiCY3QTFbGgX1jrtGq oeB5ZAhOZ8YcJ2KSvu6gemR9Lua0d8WLiCxw0Xcgtr3buofL8PQp3evduuim0FukqKfg Yazhsw+pHBLBmxLDwJem56PdbMcVWjQJ+z+ticpvQ5jHsDZ2FcCjhbUzJZHLfCATP6vm HhnAj9jMwPyd/EAvoYmNBHp3VAHTPb/sj9NkKc20epil07g1YQL//QPrgA+FIGX/GG2Y sgig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AnShf189; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 93si5063860qtc.30.2021.06.11.16.59.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:59:25 -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=pass header.i=@linaro.org header.s=google header.b=AnShf189; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr3d-00059L-DS for patch@linaro.org; Fri, 11 Jun 2021 19:59:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmm-0002mh-Le for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:00 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:41664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmj-0002gr-JX for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:00 -0400 Received: by mail-pf1-x434.google.com with SMTP id x73so5687480pfc.8 for ; Fri, 11 Jun 2021 16:41: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=MbFhWXhNwq6PG/hB7MohFhOazYLOvAHs1WJapBuDbmg=; b=AnShf189ta5981zcmxajc7/xV5Or5tg65ztR9jtcOwHFzSXNxPAmrDLHSVspV265f2 8yfAzyYMspWQ0z2g4WFwqj/VXTfw66BC9coz0BcRIW4IkulPCNPKAReRgFRnz6o4CS0q MMGj152ICJPLjK/CbAC5nsuUC3DE9hUnexXxjaT9wbHNnb7hTe5AS92xlH66hVP/R3aY Jn9ZtoL2aiQcAG3pitT9/ZzYdJBTGwJOECAF5xg8GYCFQUauLos/A2lNsjiKHYt18p/q 3ZCpcUSUrJNvVbyrO8oZAQ1D97qCQYeMoXULsgX7q9UapzUrRwh/gy+mzQ0nENep8Mnh tYuA== 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=MbFhWXhNwq6PG/hB7MohFhOazYLOvAHs1WJapBuDbmg=; b=YbjBQ5WI9mejTDE9IAAm0svA4v3Ox/NQq3YxCSE1YKTX6pvL+IuaqP39cTrH4y79Ci tjy6HAtcl/kv76t908A0Z+MrwZiqACJQo2sVAl6XYPJm9Y7/Fn9vWgy5mH5ovFopJKpe /qRotmui3Mezkgwgwg94EBTGntd3jfQeBFjO26PkEAn02zWzC1C5C9B9lL0qSqUuD9Pv IbUQoUmkT+FSYiVdN40i+baQJZH8+dtg2XIuzJnX0fAQsZ6f9g5Me8CFHLropQLFpzsA NMF57sTXemjGRtQFlS6l0hHf1NqkD2qyNxD5RICFVnSRPHW4gFO1QnKP4XS1PKF8Fc+9 DUNQ== X-Gm-Message-State: AOAM5327xHIi46s9kXZ6nAoIZdD/A/wr2eL56KGcvTTiw8oBA+gB3zov xTnryEhvM9ZiZptzV0xMv3qeVNikTk/8Tg== X-Received: by 2002:a05:6a00:10:b029:2f5:9339:1e8c with SMTP id h16-20020a056a000010b02902f593391e8cmr9819647pfk.42.1623454916351; Fri, 11 Jun 2021 16:41:56 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 18/34] tcg: Rename region.start to region.after_prologue Date: Fri, 11 Jun 2021 16:41:28 -0700 Message-Id: <20210611234144.653682-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Give the field a name reflecting its actual meaning. Reviewed-by: Luis Pires Reviewed-by: Alex Bennée 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 7a34c96d74..b143eaf69c 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 n; size_t size; /* size of one region */ size_t stride; /* .size + guard size */ @@ -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; } /* The final region may have a few extra pages due to earlier rounding. */ if (curr_region == region.n - 1) { @@ -855,7 +855,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); @@ -895,15 +895,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 Fri Jun 11 23:41:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458622 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp708785ejc; Fri, 11 Jun 2021 16:52:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzX7Ar2vAG87J3kSGI57eg/UT04BTCd+8m6OsedcpxCAEC1NMC85+m0/7qqWzG9LGv0ddR X-Received: by 2002:a92:c6ce:: with SMTP id v14mr4965878ilm.249.1623455538603; Fri, 11 Jun 2021 16:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455538; cv=none; d=google.com; s=arc-20160816; b=HKWrCgaUHKmeASTJKkX0q+/OOZ3djE7g84qzE4z0WRJmtzsPfklfMomw+ilLsuQyPP LshF4gNhxbkMiNBZ/cDa+Rx1GjfOpWrSycVlwHIxmWcpWu5eWMp5coJ5KTzrOjjqK481 8N+Ee5eICXpxMean97hmUb8tGUGl6AnjDXDitKmRATqUDmaAXugdOtH9TnrZpk3tUH5/ aU/V92z+ASpV/8vh43ehwq21yQkXl34pnprZb18gUgeCpnjuV6rXk4aY1DtY7r33k+EK LLtoUvfVZDAB/hQO85ZRaOixXUKWxhhwylABmW229dr2qYmi0ndBNFp5UhzItTsnIo3z glQw== 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=YgKo8PzUJ/RjzvpHHwpb7sclY+pASE32tnOuKWOtjvE=; b=BW9LeWqmGjgiqX7KZmZudXHOgTYsU+QSGPNaHtWiuNpeUkd83zg7dV1z0AxwQY/dJB Fyk/bAm1YMwtdv1pd/SAUvv2VToh3QDwv8XeDW0dDdArFtKvzEpH5UvJ8pegWa1wi+C8 TxNkm6Ss+ZPI6/u30atXhwv9w2iSqNgjLR7U3Rj/ySUzwjtZLDOXaFtsmXpNr4T2gK/O kvpPbm6LgNVH+g2vxWMdsdY42sGNK5iK6lx0X61fhz7JhsM3N1QjgGOKbUwSTPOkNmJK Ms1oqn6NZctKnNi/qa136f4daEReU5m++kyv3dbb3gSyIANsy1PNpnhv57O2mh3tqoPx b0iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OjjPvZk9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w20si7648541ioc.104.2021.06.11.16.52.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:52: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=pass header.i=@linaro.org header.s=google header.b=OjjPvZk9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqwj-00067x-Je for patch@linaro.org; Fri, 11 Jun 2021 19:52:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmm-0002ne-V3 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:00 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:38837) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmk-0002hK-Bi for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:00 -0400 Received: by mail-pl1-x633.google.com with SMTP id 69so3600018plc.5 for ; Fri, 11 Jun 2021 16:41: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=YgKo8PzUJ/RjzvpHHwpb7sclY+pASE32tnOuKWOtjvE=; b=OjjPvZk9B0mzN15VTJvKeyNHbic7oAMnr6MJmD8Ba8D56E232KicoZlKNOaGVR03QA Y4PtH0bnxGy/ZOHgm44odkkfHgWBRer+FF2agVzXkC87s3E2tGjwXa5zLKtsdy67XIp7 u2XJAbb+X1WeAp7wmXlG7QpQhv7RCgHYXuy3qqyg0A9BQ222k1T4Rji9tXWSyxeEBcug 31+rc2hd8pAN5eHwKcUuV/a5avTLrGdLTW2wU+EDUr3UrDCg5JUYCyMzyBbC0feUirkY qOOwWova/GayyUGnlCc2Z6WCL/Pcif8SjYS/LxRHALqCz0I/rveydL51RACic7I2rzZV ZV6g== 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=YgKo8PzUJ/RjzvpHHwpb7sclY+pASE32tnOuKWOtjvE=; b=qHTG2TGsXJ5p3SBlKblQTBl+fylFMBAz4Nqae1BaL4CL2v1aAOfrg8rLGahxRxg48n 5PW9bpfUs41lrxSKJPdtnkPvro/7CV9+R8x7dkoE3JHKjQRIm9RFVsG9kxgHUK7sAtvb VMZzOEmdCKY55pbFURCShOptieSJH/GL3QBsMJWmIQdrfNueGBf1Lje84O0Hpt6oWxcl ZwfqQDTBofWbWZ4MBGw0UKjB5/kgDyK2oVDVHvnCjCCnxIKi7P6qxVSmqYhJ+Q3GQM15 b5NKgNNcVF/j3Irb0xGlSpCktG9d6Le7+VlvbaMAm22ZNEKl1PhMyjJnI6eWcsrQfVhp kaKQ== X-Gm-Message-State: AOAM530afQxQcteNTMfFi5u9AluQLh95yEPM4d735DpQ6LqcIYkurfWt RW3AGogIIauaR0vgZl8pKhJPSNdhDMHi6g== X-Received: by 2002:a17:90a:7c43:: with SMTP id e3mr6730715pjl.5.1623454916937; Fri, 11 Jun 2021 16:41:56 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 19/34] tcg: Tidy tcg_n_regions Date: Fri, 11 Jun 2021 16:41:29 -0700 Message-Id: <20210611234144.653682-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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, Reviewed-by: Luis Pires Reviewed-by: Alex Bennée 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 b143eaf69c..037a01e4ed 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -364,38 +364,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 } @@ -833,7 +828,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 Fri Jun 11 23:41:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458631 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1374284jae; Fri, 11 Jun 2021 16:57:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLJ3N9sAgfmnxEcFSQwG1K6P5Akph333WrHKTvaR4XkbgrJvTCHmzs+UgBgjXaO7TEW/tU X-Received: by 2002:a05:6e02:1c44:: with SMTP id d4mr4996898ilg.49.1623455839535; Fri, 11 Jun 2021 16:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455839; cv=none; d=google.com; s=arc-20160816; b=vxbuiQIvnmuopTtL17SAwDhqQO1r82JPt0SbHmLu0diu6RB4RfCdGWJN3PJIAWk/qK 5mlsIB7FKrnWcefgG1A3LhBe5e9i4rg6ZCrb+c4SDeEi/sgVrmoGpZHWJAuttCr2BnSv Juk8NehAbLOHqwbDZkpRCnq8cTyNDwCPvi8DyWnTyabIYaJ6PjTW17+gJefZN+pEt12H lpX+AqAZqy8LdnKXJ3QTJSEREZWMZVQNgOe/D7UDFWPaD1kiJyrNUB54kjZ/b20NcSAv H4h6Wwf0oU7jsL19/doUEItNIzdrWG3ZSNP1jCdTiJd1/umohhbsne5RIU/IpuNFaF/N iDcw== 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=Epfwc7nVLk2TJt9lsf9tUTggNPYxuLWV6aCxBH+NF1Y=; b=smZAU3uqBs02NqsBZMeBPjIAA26rUJSa9VyEij9ZB2GZNclnTbNXIaSwqctEL1ekPu 2xQOAizGWTHUvIu+touzMADtguIYnQ1LITvEyH3W72pNabsIMAlEk2HHtMVEQkgsZHup 1Q7+UaM7ewZ1V16nPXXrzl/58VzGUt5RHAsIBOU1tfct9hFDyig7a1wqSKx5VG8EbGy9 zXpmjosPUaYBCLYzKyDpLLP7GLdC1YrLfwZYAcV0lYIrpkDFUiC92dFWrX/7CWsqKBAg isSpRalgFsxgdtX2+CMRkDdyJvZouQb+QFDkA7Z/z+fKjXrREZHY4oH9IayCNkNOZFJR 1Lsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kAltVy+O; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t9si8909187jan.117.2021.06.11.16.57.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:57: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=pass header.i=@linaro.org header.s=google header.b=kAltVy+O; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr1a-0007VA-GN for patch@linaro.org; Fri, 11 Jun 2021 19:57:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmp-0002we-Ke for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:03 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:35462) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqml-0002il-2T for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:03 -0400 Received: by mail-pg1-x535.google.com with SMTP id o9so3687920pgd.2 for ; Fri, 11 Jun 2021 16:41: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=Epfwc7nVLk2TJt9lsf9tUTggNPYxuLWV6aCxBH+NF1Y=; b=kAltVy+Op8N5hAXmCNrsrhmeoPDBNtV+h78rIlVA5B+y8wDs1encc1G/LOao4f9KeS jVFssaWWn5Kd6CwYtBVpKE2APOJRqs55On370Kv0lfZhjNesCAuV8B2EhnfHL6aWSKpW mLKxREHuooK7Ba6NA8djJGVHhB2LvD7ikYlPcH43DA7Owjzg6dqM9B9VRBacm/y5IkrW Fa+4j4HavzBlshoUQ1/Bk2CJEgCm5Kw6zcZf3f7qh9QpTE/TrNmf+2YCYHZdFRMG8d+U rp/1SV3+bGGBJ0qHbUXfPeL0T2tm6CQjdm4+iQKX8evzoHMyxblj4GFWLZeaqTCjK8jo rMOQ== 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=Epfwc7nVLk2TJt9lsf9tUTggNPYxuLWV6aCxBH+NF1Y=; b=NbnLNdO49bbS8NIf5TUNY0D0v+ATfwZMbIgb55qRNfOLryLvhZnacVm0hN9Ry3ifsl 7lPKOrRihgEtQmE+i24rZuxOw2J9NVNMuWXnYKQv/rjteQhLwYn9R+yThOc4e0OPslsI /pxAEDrAfi+SnbqOFbaYX/GQ4Gc6BiS4ocAX1klIORAQpHTqdEyavoNY11clNuQPCsUs /sIiWicacetJpOWzSxnTT1lVab/a5W1fLOaNg7evh+p79rcoKoddQtcJdogjXpaX+ADl yLOaiP7dKXI6FRgu/1NIg9vgR5zx/cqdVbPFHarYwlUZqpKMw/6gyemeO4OHMGhg0K6U 7JFg== X-Gm-Message-State: AOAM532QRwDd6RcrNY1dpw6JxWByoogUvjQ3rOErIftS/fBdFgU5qK4G CXID0hTGB0klnBjsHBB6WtR3Z4a4xeUp/w== X-Received: by 2002:aa7:8ec8:0:b029:2ea:32b:9202 with SMTP id b8-20020aa78ec80000b02902ea032b9202mr10508385pfr.36.1623454917589; Fri, 11 Jun 2021 16:41:57 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 20/34] tcg: Tidy split_cross_256mb Date: Fri, 11 Jun 2021 16:41:30 -0700 Message-Id: <20210611234144.653682-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Luis Pires Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- tcg/region.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 037a01e4ed..445a278702 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -470,9 +470,10 @@ 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. + * Returns the new base and size of the buffer in *obuf and *osize. */ -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; @@ -483,8 +484,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 @@ -514,12 +515,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 @@ -530,6 +529,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) @@ -566,7 +566,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)) { @@ -588,8 +587,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 { @@ -606,6 +604,7 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot, qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); tcg_ctx->code_gen_buffer = buf; + tcg_ctx->code_gen_buffer_size = size; return true; } From patchwork Fri Jun 11 23:41:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458671 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1377282jae; Fri, 11 Jun 2021 17:02:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytwGM3qDyBNySzmi7bjefUdN66dLR3cJ+s+sGQRT4kfcoJ398JF6VW40nUvwEkomt7Pmj+ X-Received: by 2002:a17:906:eb88:: with SMTP id mh8mr5698641ejb.540.1623456154291; Fri, 11 Jun 2021 17:02:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456154; cv=none; d=google.com; s=arc-20160816; b=rt+1958iDym1ZYxT4SZBYxRIerI0eCe04OUe2ZYyO6BoxWrZvj9Op9bLOrdZDVcSQw UnLNL2eelQV8tPdoUGy6uYOReDpZIKRWMdqBm94SkjDtBHDN2IrtBS+72+CO4eCxOj/z sNwECCagVSYbK7udR46urV2/puQnHs6OylTZFiIM89QRKQhJsPJ0p9RDS7jvhFDds6iK OPcP0KwwhFG1PJhprM+L3dmEtHdXkD9bTUenMoPeRy2dwzyPFvg3e50mB/9dAIyf+wHj wG7vi7OyDAyUcG1LXR30+HxLb3H5hJ/DlXAj+hiAYTYDDvxCdSNZ+pgz7Rlwc/6v7EUn LnIQ== 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=1l+8M2L0wM1oDKnQt56uL3Y/0V+moZ9SU9/ZN2FXsyc=; b=Ns36OA8ntwKyseEJyPwpUflyuKajDINH4kDP2GLT/+dKbyBvZEcEnH9+Mnq8iH0vJ2 Tw4hzFJ3VLH+Sm9E+2ym6FHKqCmtdsMZ3ZNM9/WmGe9pMHe5mxKi0P9N7oQtIUns/3Eg f38ApdiODJuIZg82poXjakVhDzfz/0az4tFAjztdRwLWBR0jZxGbG/ffco2oR1du0+7U 9bMW5JIC7zoN4S8731KoT2hJU3jfjy79idS1dQ3VmnMlDyH2mhyWkL6HJT57q4MHqjy+ CfGhPS1S/Sm8cOkpCGWdGyseOnFRdPWR2NwWbBjIsVFhicjWy1NOGc99OZLnrG9ENpCo wUjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LpqQjzRD; 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 e10si5099700edz.393.2021.06.11.17.02.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:02:34 -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=LpqQjzRD; 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]:51784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr6f-00012l-5b for patch@linaro.org; Fri, 11 Jun 2021 20:02:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmo-0002se-9t for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:02 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:50861) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqml-0002iv-IC for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:02 -0400 Received: by mail-pj1-x1032.google.com with SMTP id g4so6555196pjk.0 for ; Fri, 11 Jun 2021 16:41: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=1l+8M2L0wM1oDKnQt56uL3Y/0V+moZ9SU9/ZN2FXsyc=; b=LpqQjzRDOp/KwKC7cR3el/L2ynR/z99L+eZO8A+EjkXKAwElngsq+IWbBwbYkY5kYX TL7wBkGUBz1d7CVHKdrIzBAfKYYEkEt0HSiph23n23POaxPSzR/cStEuqR7v/K7to9CV u0ICT3KNyMSxCU5rojczg4ApxhCyclf/eEuA4ENAnw+s7PAZNq7Qja9SHyCtMRqJzzv5 BNh9X273ldSMvCVmzr/Bg0/lObwn5N7nJagIPZ3R/W1zbF9NjmZC0ev2SpDJI6gBiQTy 6QAFWan0Y+iQuOpdKuYITS2rxlshzkWx3SHfvGnAGSyHmUhtWb0KPhMmMm66fKqRNIwx iiCw== 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=1l+8M2L0wM1oDKnQt56uL3Y/0V+moZ9SU9/ZN2FXsyc=; b=Dvub7SQnDHvqUr9sre3fCGwKXj7oq9pFwoTFbKaDpcpECB1HkiJsM3fRN434GruE/n 8aKpNf5I+2gt2EWW8XBo0LCs+92yeiSM6WRiIuFxLTMeJDxx4z13ywLtZ1PnlsOQQ0y/ LCavCsekhIEYQBovvfNZMrPHKmWb/NZXeAw4gKrVhEqKxRhEHQitTbuwfKnfArWHcVyn t+E3Um58IFK4pUjPKyHqBEjlfn9gsSAu/FmLQ1IdvSj7MuqNV2kFWZgtrunKar3dC1X9 +gsrf2MAgG8pcbLLEKo+lxuP40/i7W5B0sf3NCpqxbWrwqT7r3DJMXBUzdxiIBobvot/ 28pg== X-Gm-Message-State: AOAM530AKNkwLIx32qyEiVMo6f6Df5Yzt43Vc+y9Ao6VA4xdgDKW35/z b2qaElmadMkM7OqcGRKxEqfVXRjsrRRttg== X-Received: by 2002:a17:90a:c8b:: with SMTP id v11mr11148113pja.114.1623454918187; Fri, 11 Jun 2021 16:41:58 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 21/34] tcg: Move in_code_gen_buffer and tests to region.c Date: Fri, 11 Jun 2021 16:41:31 -0700 Message-Id: <20210611234144.653682-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Alex Bennée Reviewed-by: Luis Pires 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 2316a64139..f48b5aa166 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -695,16 +695,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 445a278702..5beba41412 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 9880d5205e..4bb35b455b 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 Fri Jun 11 23:41:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458672 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1377315jae; Fri, 11 Jun 2021 17:02:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYBHBDZf+/z+e5HPffpnEp0IbRjAE/hR3T/8pHkvT7uhQWShubk+hh4ytHmWManzNbvSxf X-Received: by 2002:a05:6402:1906:: with SMTP id e6mr6129439edz.14.1623456156404; Fri, 11 Jun 2021 17:02:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456156; cv=none; d=google.com; s=arc-20160816; b=kWxWxvCKVX2aSa71Yps5nMRyVEhycHvDsKQ1wZtzurY5KawgqA4oq49sLW85mk3uDH DR9RVsvqC/EWmojWNC0yOAVREAi6Lw1Y5AH4s1+euPO882F4ljFktV6YzaWAfJsVK43C IyzyZRwnuiJ1CUmiNvKkAmc1H2eGeg1B7ET6JYSZzsN4PJhQoeKzb3DwKKgYFZiC1P+k ICOHtHJY7GuCzOQj4C7Qt20bD2wjzBC17lmJA9c18ePf82WLsZk95lgegA8Jbf4BGX0T J7owU2oPNJQRIJOkJSU59FdzgXjicmjnRoQo2tKW9LynOaZQ0Awxk5vYR/TzXO4Ag63x Dy5Q== 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=YckM4rrXqWzq3iloRH/M5Y1yXJHaBzItIjFSA6/6d8o=; b=xSj9VQvJFjwl6IEMUNzquj2Mq5yH2blfPEg3/Zg32ELB4FpumdWu7RkTzCuITQSWFr qj+hs2mW0C9QFQtvRcClpAW56RDM96eYHd1fiovuDr0rEvW+4HyRl5q9RagGFwNklRAy M1n4MG1K9Nvl8WL4AX+rHOIT9FWxvTrrYlC29XXnp96IHJfNXhrhZHDNsYabGCrik9hw ppPLrv2DTPxLwauQEfZejomvIZXwqQTR7gFE6t7U2jn4+xy/igme5gobbD34dC/fdaf9 RqBTEv9f+O1ffW0KqdFu2xifA43V90UckncOpjES6jHmhq+LNZUqFXf+Vu+8wbIIG7H9 gbdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=AUHYX218; 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 hp21si6706128ejc.360.2021.06.11.17.02.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:02:36 -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=AUHYX218; 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]:51926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr6h-00018O-8O for patch@linaro.org; Fri, 11 Jun 2021 20:02:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmo-0002u5-OU for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:02 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:46678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmm-0002j9-6k for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:02 -0400 Received: by mail-pl1-x634.google.com with SMTP id e1so3588660pld.13 for ; Fri, 11 Jun 2021 16:41: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=YckM4rrXqWzq3iloRH/M5Y1yXJHaBzItIjFSA6/6d8o=; b=AUHYX218chIllIBKLN7GnpXohlc2gfPsy7xV4GE8dnKbzLkmc9XX2RaPHk41szXOy0 Y1gXknYqE8tNcBbXTT/HbhNyrofee9QijoqbjruRxGKbh5lQXJEQPFUiG7T7xB13DSkU tUD2B0xH/KW537xLa8emnDpfPHB9m+kQ1UpRzbqhihQ7WL83IlpqMeg3BKKICjuggDrQ 7Da3oOqaUUNV4eUri+J8D9YhNeolmF3wulijIbZrrQ7nM/Ux25TI1HzwmSrCgn+fe+4v TeJwvT/S8jo+YsJMf7WbP5B09n2lTUOMl90yf0NIPxW4NRXgLs93Meh5KDasuiX3Lpgp p2zQ== 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=YckM4rrXqWzq3iloRH/M5Y1yXJHaBzItIjFSA6/6d8o=; b=VfSnkQQHUROBHSsYo5l941qoQVBhsi74qpFkWmWBmIOAc0BuWs2kmE1unIKlAb/FMo zZqSn7YEWD1Meya7WwWnGylVavT9cYyLcZ/ls51VGmfg16oqCdCf5lHjUVHxIoJatVtd 2KNHYtnAfDPuMB3gWr9E80hiNbG3/LeGHbORS2sVkGNYkkSyXxtKy2wDEUu4TBFxWfpp thSDR27otBRuS7+plzuxX4GnG0rEyz+V7uRVW68095s0EgObxo+BBNtZ3IQuxJD/RL70 Im9ahi8gJ6Db9YnD9R66Dc7fxdR6jZAeNGJZsRXmaOe0zAX7xUY/qsbkaeOG0nd/udfT MVKw== X-Gm-Message-State: AOAM5319/civYIuK0tuQI4u5q6YTOX6p5COTPe0M0MAlPcF9KhsIbnu2 i7NPuz8VGZH6BD+6OhEnJKeb/riWvW8Zbg== X-Received: by 2002:a17:90a:f317:: with SMTP id ca23mr7039972pjb.174.1623454918837; Fri, 11 Jun 2021 16:41:58 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 22/34] tcg: Allocate code_gen_buffer into struct tcg_region_state Date: Fri, 11 Jun 2021 16:41:32 -0700 Message-Id: <20210611234144.653682-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Alex Bennée Reviewed-by: Luis Pires 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 5beba41412..ed7efba4b4 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 @@ -562,8 +561,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) @@ -584,8 +583,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 @@ -637,8 +636,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; - tcg_ctx->code_gen_buffer_size = size; + region.start_aligned = buf; + region.total_size = size; return true; } @@ -659,8 +658,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); @@ -682,8 +681,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. */ @@ -734,7 +733,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, @@ -846,11 +845,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; bool ok; @@ -858,39 +854,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 in the rw buffer, as that's the one into which From patchwork Fri Jun 11 23:41:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458628 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp710488ejc; Fri, 11 Jun 2021 16:55:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyARLjaHM8OzWql5GqW6asZm7bnXXdT4fw6I0a9yBxuhTKOWEAu0s9PPqLYdTuYYDnR9kjh X-Received: by 2002:a05:6638:2491:: with SMTP id x17mr6285468jat.33.1623455725674; Fri, 11 Jun 2021 16:55:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455725; cv=none; d=google.com; s=arc-20160816; b=zewDHUIfZWFeJBg+QzRhj3ZBxNGCI+cFbyOtsR/O+ZYC+bKFNSApfY52QPFbfnukpE 907g0G5cpWqVmK5aFru+Cb32Bl13JTb6XlUN9xPkVWmbBNoFfulMr7Ih+4TvnGxPDX38 Adq3k+qcBFLNUjjajAWwcBCUbB2FJWyghhsDIRMXVBKF3/PFXioWBA83HJ+4vMzs8wuW ch68+K6ba8mOWzt3+DwF4FoiN9nx4TqQkw+murtfsWZYl0zRmHo71t0r9EQkY2IxGPBH 4/TEOmF82RG3KleBizOh7cZr2wokc2ZMZopJEYFlEAVqkI2YJ4UjevBNmysxcQi0sBkA C7fw== 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=xvQ1foWcYjEjn0WVi/whCjaQe18yQNKefXnuEUc9Cy0=; b=X+iAudzrpehBqNuiIDPO1Kwa/oWUlxuy8odOpM5oehxxP748YHkmgNWC7+crMlcoFx zkl/Hbv1BpQukJnzSmMDQDzogFoWKqsRx9Ewkrkt5ULPxz9cG+Llv41yiH+caJDrnTUt DxtoTV5JYFLqzDWAjvlRE7b9aycs+aAaJFE+OD24G556uPw27JaDnSDwA3OBWgy2jQpc SzojHieMpvyGz03xMAHCzzUyrfqpGan2WcHcptpqbdRTlZjqzhW/98Q3O3cZ5E+G2vBH PX3liAl5nbXPnC7hp5q/9W9ZMEeOGFXRwoyTMMLcXxGdfkAwLmumLF8N2JVeQeHySWSC EHrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="Pk//YZPG"; 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 q8si8464295ior.12.2021.06.11.16.55.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:55:25 -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="Pk//YZPG"; 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]:33108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqzk-00054p-Uq for patch@linaro.org; Fri, 11 Jun 2021 19:55:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmp-0002vw-9i for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:03 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:54830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmm-0002jJ-Kr for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:03 -0400 Received: by mail-pj1-x1033.google.com with SMTP id g24so6520291pji.4 for ; Fri, 11 Jun 2021 16:42:00 -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=xvQ1foWcYjEjn0WVi/whCjaQe18yQNKefXnuEUc9Cy0=; b=Pk//YZPGEMU5bXFcayMlPq9NGlVNIByok2GwmoKfXvN5D++WKa0xweCKkaXQU0EOxe sFxK37UR1ighgM+GsTdG1Wf7821D2ksqAVhKEju/23tjFQkDMcEGnh2yJxhdqjuYv0mk pIHhWuYW2yqXY6oDSQGGqrqFMkk687aBSx1zUB7Z1AavBBfJryLunZedvZJySlUTVELf xwVY01k1KAoSwGnljYTCsqLdL6stop10aY0jjJ98Oobg6cTaoIUW+HqN6n7QeqILVYTX RGjG4eQxtz5TMKwFR9bUfzf3d71xn1nA3lDTgdJ9dPfOVUqh7TW4XVcbmM2MGgE8Ovuh hffw== 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=xvQ1foWcYjEjn0WVi/whCjaQe18yQNKefXnuEUc9Cy0=; b=N6vw4pfmooQkl3/p7EOHdKYZ6e5vVZVKAi78vhj7b+1e2IHEzU/A/XPFZGlaKTikL4 SSl41nw2qQ/PFbdDj77rLNKubzv5VEJNzYMERbB9ef9E0UC405wtaDD+fLePKMhpLAd1 UcvTpadYwayPlwDJiootmIgjZFoLuT3aFt+7jAcA3GQOgYDm+UBFDmo2UDxhsvG4sBW2 XwNuuzSFkNJD2TukPZaEo9V0TG8aMQT/2rdqVRg8L7Ku9hOEnZna0/Ej1AEe3E8goZWI bJUje3PHmbs+Ubrxa/Aq4CIYaqcRxydiRcwdpZws28a6wtxspRuXA592WFz2YD+HBDt6 rf3Q== X-Gm-Message-State: AOAM532GvP2YaXc/jHhKEKDnCTJmVCdTiUfq3cxmtxUlAppcaWaHHvGT JPBg7D0j9XUofedpBTckJ1/uLAxBZOh0Ww== X-Received: by 2002:a17:90a:4a0e:: with SMTP id e14mr11589836pjh.209.1623454919426; Fri, 11 Jun 2021 16:41:59 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 23/34] tcg: Return the map protection from alloc_code_gen_buffer Date: Fri, 11 Jun 2021 16:41:33 -0700 Message-Id: <20210611234144.653682-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Alex Bennée Reviewed-by: Luis Pires Signed-off-by: Richard Henderson --- tcg/region.c | 63 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index ed7efba4b4..e6c80b35b1 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -526,14 +526,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 */ @@ -563,16 +563,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, @@ -585,11 +586,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; @@ -597,7 +599,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__ @@ -638,7 +640,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 @@ -652,9 +654,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. */ @@ -688,7 +690,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"); @@ -702,7 +704,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 */ @@ -721,7 +723,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; @@ -730,7 +732,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; @@ -750,23 +752,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 @@ -777,24 +779,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); } @@ -848,11 +851,11 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) size_t page_size; size_t region_size; size_t i; - 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 Fri Jun 11 23:41:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458777 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1379064jae; Fri, 11 Jun 2021 17:05:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk9KP3v5EO0taoCTrPCMo7x8A1hro/sWK9ML3eMSUHW0ah0Sh0uu+5U2QrG7jzMA+yfG/R X-Received: by 2002:a5d:4610:: with SMTP id t16mr6205237wrq.324.1623456309447; Fri, 11 Jun 2021 17:05:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456309; cv=none; d=google.com; s=arc-20160816; b=cB+nVwEB+nRe1fJqGMXoESDrSpVubGc4C+b4k5cwRTZFsYPxCm+NOdpJBNJqOnMfB+ JBU1Dtawc3UAfLNh3p5MqEO6eRnuC/pylPo4ptea7Yy60IZohCs8cuntB+l8k+mg9U74 cteaB0ZiBUZmbG8jagea2fIO+2bvLkJyme+eQrXUe+Z8lxL24S4+DxKQQyaVgRuMxIRP N5kBnFoRBE0Hb9thZPiCgi6SuqD73/FW5c8+DgmyUGGoMmAS3D23jfLpnphZHR4Xl74H v9pn5+KfVSQPH23UB4zK0QJMs9sgSQXX7Sgn8aNsBiNvY8znPfD7pMi+yWR01LlJhZ54 IZnw== 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=oGlm/QkFrT3k7s3B4Mdy2N+YuMxL0+85EjDFAhTeOqA=; b=1ImuEu253cy28jH0DPJYYoX5MI8IEp5z/EMsv+MNAIdCs1wagcxY4YVyrgkZGLkKoc VIJlvAbVKTaY9OdVKH5cCgST4jMZLlZxhiY903TM2ojqKIuo+yJn63tH1KiczQqoo9vv x697sRL1Jedyj3+43svNpt2j1sqgC/UoNR1CsRCiWXwD/6ClUNNHXDW+eqY4KETpauip zcBWStNv74QhNhXuxUmhb4Xc29tvP6YKpv0Bx7rCfw1TE/GeK16i1gi2QLjnDY5nFN6Z fqp9GqPWLexQlX758S1c8o3orCjyxYGzxnmG1hVDYWk/lItsP3poozD5xxsFJUgB54R3 3igQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="Ec6x/vq2"; 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 g12si8268389wrd.272.2021.06.11.17.05.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:05:09 -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="Ec6x/vq2"; 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]:58236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr9A-0005KY-7P for patch@linaro.org; Fri, 11 Jun 2021 20:05:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmp-0002xd-R0 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:03 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:45589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmn-0002ji-81 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:03 -0400 Received: by mail-pj1-x1031.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso6852360pjb.4 for ; Fri, 11 Jun 2021 16:42:00 -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=oGlm/QkFrT3k7s3B4Mdy2N+YuMxL0+85EjDFAhTeOqA=; b=Ec6x/vq2wkKpCa2bzY9c0MUR1Jgjz6JvfO5KTP/n+Fg0psi2PzlBpXcPINJx+Wfzj+ aGnhrzRyDEgswHNGnP/kq6FowPybs8rCbaBKAg7m8Wt4SFNl8nzoVlqn/s6Sof7LIBdW Co5Jmu1c9wUlAgTqIh/akT8OUrR8ycRTDx6t5MPfKs9UIQoq/p1ZrXF6QvkCoGzle33w DP9GsKCT9lHn2W0ex39gup8tEmxRoq1zM1Ce3ODlXhv5UxS276+GHvfe5V1Kphu+YGvj OSl/d4CzGGVB7fETBSTf/U0pdcBaA6IxNQqeC0yOQjuF0aSaN7yoq8odrDMQmBDcG6pu iPxA== 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=oGlm/QkFrT3k7s3B4Mdy2N+YuMxL0+85EjDFAhTeOqA=; b=giz0DK6xulNqt5XN5tL8v0HVx4faodv7wGCLDRShyTLoExFS3JXmdqVBQgBCZV0jET eYa0UN3ZPy2I0EJasgu5DTY0NW68sXaSMbB8MuffOFejCbTSlxgg2PL/GlM4oa3D+gJF qHepn5tnlxWq2YoQoVheV4H88or73ApZn+lHQetFNc4JY98g/W/lwv451Fqjy2Cdqu1Y sb8EuCwfhn79yYBil66tSBUStakW95+SpJCEq7MrjHw8Mb/0PdDkIVWhFwf7Zcck7sgJ TxbKAKqA6+5V5jt6Upj1T5DsUIPqP7lSNOWc8wfK2LDyxaWdluBsXK0ivnP5L0vP2JD6 cXWA== X-Gm-Message-State: AOAM531MyKS5OcBYV2l9BEVFZXnlkk9CJPDHbeY/2BjW/TT/tFu9Fi+J bi5OSmITQ/DU4thCGp+r9lwmk8Oc2qwmzg== X-Received: by 2002:a17:90a:4404:: with SMTP id s4mr11544556pjg.218.1623454920007; Fri, 11 Jun 2021 16:42:00 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.41.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:41:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 24/34] tcg: Sink qemu_madvise call to common code Date: Fri, 11 Jun 2021 16:41:34 -0700 Message-Id: <20210611234144.653682-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Alex Bennée Reviewed-by: Luis Pires 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 e6c80b35b1..2e541cd2bf 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -559,7 +559,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; @@ -635,9 +634,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; @@ -687,9 +683,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: @@ -857,6 +850,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 Fri Jun 11 23:41:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458783 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1380874jae; Fri, 11 Jun 2021 17:08:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJtT4UEj0/MbPty6gO3ktS+Pk6N0COu8PNeVP4vbhIGj5ADlzYLMcleOppPpoNuIoVTIth X-Received: by 2002:ab0:176:: with SMTP id 109mr6240031uak.68.1623456480504; Fri, 11 Jun 2021 17:08:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456480; cv=none; d=google.com; s=arc-20160816; b=llat9Mr+ssvidjikJZsiT2apoXWCYf5oZGkmPEuzy2A/9C4N+s6Ch7jTg2yUNGMFGt 4EX9Wzvq38yPTXcZdxop1VMuJK3h4tDKXXyNunCCgmfc0WNonLExE1Ya+lHaSVFFMhhW WipFLLAl6gn0dNfUf1DSsiAWYuiU9gsnGXUG+XLGebHzqNYgUAQY5krnNAx5T+/A44n1 oQ8Yvw1GB4CPQQLWwl2gRjsno+2hul6W2e0iiplXpDmSgutVEtQpRL+0XZw0UOrwMFW6 V0LyJeg0IhYVzdFnZR75QUIc3Im/b+wjhW84w+jEV44PIZy7vhJJVKHKfP7danblF/HS pGiw== 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=YYv9tcvc0r6vqymr5HM4dazO/PQp1jnHK04uYsgFVEA=; b=vNq18wfXlnh2ECKNjENgwSnHC2sFGKKh6p7LXvqCMm/NZnpqJyakRAD4qiDMcS3NjN ubNc5qqi29WxwVYek9GEt5E62z8o/JJOunPd39ZrYkzdvMYcl9LZRRcYMhyIsF3A4Bvu scxrj3Q/Vq9ZZysksfO92/Qq7SBtinoVp2VpKXMIVqygoCzrBLNapaXyCFYzIDlR2T/L w0145iATYMMlCcDebONjMJMvjAbRx38MtcVtdKKpYb+Ui9lKfuscPFMtSCukYeVVP41O j/pM2UbbDYvcw5K9j8bXwlEmkaPZB5vKggWqqJkRTBaZT59T662upadYxgef0skqpqCW xm8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=H+3Uncb8; 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 j15si970518vsq.115.2021.06.11.17.08.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:08: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=H+3Uncb8; 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]:36480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrrBv-0001Gz-Ij for patch@linaro.org; Fri, 11 Jun 2021 20:07:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmq-0002zU-Aa for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:04 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:37862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmn-0002kE-VL for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:03 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 22-20020a17090a0c16b0290164a5354ad0so6725246pjs.2 for ; Fri, 11 Jun 2021 16:42:01 -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=YYv9tcvc0r6vqymr5HM4dazO/PQp1jnHK04uYsgFVEA=; b=H+3Uncb8d14Dt53JbLo6+lZp8HApGG3t8BXr1sGiLfx3S2ens9SjAtNLRpd50J6tFx YcvkW+80ZEaeU1A0DQXjK+OIJPWq0G6LYJK/aWy+HZnV/ZAqP0ejVmMRWT7u4b2ijWcQ Ir4DJAQzixM6dEQb0xAu41RuJgq1u8Drv6yF+KSa3EtiqmjKWApnuDBLMfc1MT7Gdg+p Ph+6ALhN6ULoubu6oHuyAasGkHr3Ss+AOrV4x+87yHx/+6WummqIJmgn6u7OM2Yc37tE cu38g/a7XKHYy/+xvuexD20PTNtW0Jr5XOM9Hgqj3kAANCVMLNDzOaYvUPu5x2e3Mudd xdOA== 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=YYv9tcvc0r6vqymr5HM4dazO/PQp1jnHK04uYsgFVEA=; b=Q6slM48FxRX/htQh1aQkU1kLwm2Kb9EESVRdrJjLcxtUVn/HGPXWHHNnuuG/0gyUTz Suk1KUxIhBrTXMBHfKKGU9gxaklvJvCowZN4tVkWVIZ4k2z+3upM/Yjbfs58yqnCdeUy fNGeGGCGcWME9Jv+jc79N//RsY7ZOwQ43ZZfKr/9PFV7rJ4/v3uSEQhNkMzS8ASRuoSr ofLLASgRsV5MR9GoK6TUqObKmzop2Oppz//3nS4Bakw92sirULo/l2P/tsaUQqJt22aL fbjwYumCqN3UL1Ri8ZSKjKwViGUKOjFN8gGfwijyo9UHy33kDV1+MvfdsW2Pvg7Qesbi 4luw== X-Gm-Message-State: AOAM531kCMHxMSOYL4bsz78rv2kVXlprQzJ7k611AAR5gZq27fxIVRo6 WbiVY1SKkgx5Nd+cMsRhLvnFCgKOqWdEsA== X-Received: by 2002:a17:90a:ea95:: with SMTP id h21mr7012566pjz.90.1623454920663; Fri, 11 Jun 2021 16:42:00 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 25/34] util/osdep: Add qemu_mprotect_rw Date: Fri, 11 Jun 2021 16:41:35 -0700 Message-Id: <20210611234144.653682-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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: Alex Bennée Reviewed-by: Luis Pires 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 4c6f2390be..236a045671 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -512,6 +512,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 Fri Jun 11 23:41:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458663 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1375332jae; Fri, 11 Jun 2021 16:59:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpXtHNTVdtwSwpPKAu+Sz54wi3GsUMwiWaFMHlQ1q1Q/tuTLPgMRh6iuwI0t3cA1LC22/5 X-Received: by 2002:ac8:5986:: with SMTP id e6mr6335980qte.203.1623455989984; Fri, 11 Jun 2021 16:59:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455989; cv=none; d=google.com; s=arc-20160816; b=ljwrU00f1c8unX8sUTdymqLy5udhwUexU11LqsBpuiDa1Ns3SipidO8aM5NX4FeDZ0 k+OjOyUByZ3ldh9UURGtOz0HGGW0um42mid3zPWlg77MKyPXkWDlU+6sYB4D7n2TXb76 /Enz5sX/pZMy8drL8rYlIuZbLSc07Qcx1176HTyx2Vk2faEJcGhbAsFu7rctYVTWu8D3 xP3Egt7p779cKrV4VJwZOPeRUzBOhgvu8shDunqq1WP78f/nmBd4XVCRaMA0qUNQbRdl jkMEkYicZHlVXDxWLuI/1pjl0e0dpIREZpzHmkz9u5hEUgpmXxYOZwshPSeYNRRetqZx b47w== 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=2wvd/6SGk1w8OXui4/FBWGSYpErzZvV+B9LV37fcakY=; b=hMus0aDoKWOP3ewJm2dOlumvFTKqd90H0Fhain9plfzYiUJHfx1jnHKjnj4V5asjvS rqUufeZaVLBbKWR4jL1m1PjN695IS6CBneJ3E8TcsARBH5OoThcumoanv9VwWqzvcbnT hXQIt8mXjyx0L+JwZNVteXXgkXexInY4zWSKJ/lqPWvpKyI8cctzxAvC68uti2/iqwP9 JIQWDq9dn7lkvt22bQ8oRc8nwT1G9PBay5NF9zLpqvLDaxzmeE5YAbJBwfEzve6CnK16 1yigHCXMQaqMy+rlLkE0/BJcPXmC8awb/hncjyVFM8vP36cJ8n37cBUhUhwXZTC4XtVZ V4Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bdLFHHPw; 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 l24si4961310qkg.200.2021.06.11.16.59.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:59:49 -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=bdLFHHPw; 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]:45636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr41-0005E9-DL for patch@linaro.org; Fri, 11 Jun 2021 19:59:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmr-00032o-1P for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:05 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:33455) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmo-0002kN-F4 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:04 -0400 Received: by mail-pj1-x102a.google.com with SMTP id k22-20020a17090aef16b0290163512accedso8024785pjz.0 for ; Fri, 11 Jun 2021 16:42:02 -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=2wvd/6SGk1w8OXui4/FBWGSYpErzZvV+B9LV37fcakY=; b=bdLFHHPwOlW4VyQm3We/eXb+tvzIbp+VmnB2Zly8tWpPgPtoeRvAv1cIGMxSgYlY3V f+Veegvt7fssgEJ40mQZFwEcIDHKqK5WYB6fGkyCYJSIRDdFeoUGqc2vUSvaONXmaPsw q8FigcpwXC4XRlAI38t8RWF9JyIBiYFk+pH5kgFf04Xm8XuVwpjDWjNwIdkL4D7VwlNY tuLckFRAzHYwoRv3M55EznPELFIm9XK6WFocRN9hNgxOuHBVbPVn4YSXRc3iir+eE/7u SmZ/fCWUCd0UE8G7o3d9e8k/0RvYyDRki+a4Yze+M73i1tYNQmROeewjg9NgPTtaBkvF 1Feg== 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=2wvd/6SGk1w8OXui4/FBWGSYpErzZvV+B9LV37fcakY=; b=nROPJDFoXdkITSSMj/FqjTOHkLkOFalvJ9Xi9IxF6Ol1idsQbg5A6TvZ4Y43PsM4sm sIqGPoP+JtuwUQAz5WJJVtb2ra9RHsNjsyst0QEb489twO1/+Lsj+a3Qgmp6ac97+IXu NXFudXt8TekH3UX7h44bJb9ACIJqnGEvqm0m8+wnZRmzjqhRDBzb+wMJQbXnxBfKvNbv Sq6zxjrWDeYhrdAeaUDDTyR1qwSGIjuWUxKKKBP/QYswYGJc7GcGlzU9VrW51wm4ktQl sJA2YG3GOpdwfIWfTHCggaqUka+vtHQnLYvu5XivR3YMymniwf7y6evx5BW4vvAnom+y LF2Q== X-Gm-Message-State: AOAM533vFATkhG1NbDb78goMxsd2xZTDvLlKQL9MsXXh6ZYHP/uEpFrW oYStemTHrbAFwxhTQX4CAz106TbLCnbsyQ== X-Received: by 2002:a17:902:c789:b029:110:4933:71ce with SMTP id w9-20020a170902c789b0290110493371cemr6151169pla.56.1623454921175; Fri, 11 Jun 2021 16:42:01 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 26/34] tcg: Round the tb_size default from qemu_get_host_physmem Date: Fri, 11 Jun 2021 16:41:36 -0700 Message-Id: <20210611234144.653682-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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)) Reviewed-by: Alex Bennée Reviewed-by: Luis Pires 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 2e541cd2bf..e1790ce1e4 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -470,26 +470,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 @@ -841,13 +821,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. */ @@ -862,9 +858,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 Fri Jun 11 23:41:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458650 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1374840jae; Fri, 11 Jun 2021 16:58:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5mZM19/K6AECMs2fr6gjtQ4ey+ZKe/lXdo8y7O6HnFh+6TAw8kKXBbV7P8YaSuK0mVr0+ X-Received: by 2002:ad4:45a6:: with SMTP id y6mr7437297qvu.54.1623455921671; Fri, 11 Jun 2021 16:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455921; cv=none; d=google.com; s=arc-20160816; b=Jtzn6UfOij30NVdq3s2d/q1v1oATTH+4Asa6wm20hFkgpuE6k+BglYRLNU7yl/3NXI ydhyDmdNfgh3MHzoUOUP8U0UKx4U4YIG21FqPf3/J33zHq6wFvO6xT5AzUBkVvWcT28a 4YqNDaX8sazL7zt2NOGRHHxD+SDD8uAtjezpBmH1PFDJa9m03SUiWxcdnsQ2AdN1qsBx dTA0RwZqBFWILDTg0950sErPgocEuBYDPbMUOkvdyBfcTzf13o+UJPjD8ZJF8/uTgYnm Ol+AiA85F9gTgoPLUrwbl+/221/RNcFvoTtO0/nxl/tviwdJwR3Q5rp1ARb779EDUVOs c4jQ== 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=y0NBhQuf2KfybteRYM2KfBpCijz1I25HMN5sM61Z6v0=; b=0yuqyWm5/D2b9idHyjUyniGxwqk3Lh/wngy3cl4YfzQ9LWCfvWW/0kntHayMD2quHP polPLKuBaBrZqBr0A/QPB+iukqkFOr8JwB4+IvOwvRhFKsDd47eYFqtz7+ZC9+394HWA 0yRmO4nqj0UN67leNbCSHMGRjDqC9fojhmsNZFpeqSZl3+/Tk8NZqiLEtNzA37bc+qqi VDeHSiJs2HhyqGMjLROTp8fCl0sZOteh9eimDIfp3RnU1Hl+bjpRNwF5wftegMzBfjgz 9EOhSiFX3so0Nxp5iamkB/MTXdY2zUG/d8mL9uMsq7mVaXDP14nMhRqfHnNAuF0XX1Ia gaow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="o/uGJs1g"; 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 a20si5074987qtj.369.2021.06.11.16.58.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:58:41 -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="o/uGJs1g"; 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]:42832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr2v-0003JU-2r for patch@linaro.org; Fri, 11 Jun 2021 19:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqms-00034x-M3 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:07 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:54832) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmp-0002lC-84 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:04 -0400 Received: by mail-pj1-x1035.google.com with SMTP id g24so6520329pji.4 for ; Fri, 11 Jun 2021 16:42:02 -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=y0NBhQuf2KfybteRYM2KfBpCijz1I25HMN5sM61Z6v0=; b=o/uGJs1gxi/tL/H5aFJh5EEYEMxG/xjxCjqMitcEU8cNEwcaDp1ptEcvUbxUYkAHYY +oYzgvCmCb3DfTvIBDv66oZ5bhyxo94SpqCvV8aePG+7s7hPWZjOWLKHwZOhfPALEBy0 Vc9SLxa2iVzVnkowG/QROcHchOgAK8fgXYfjH/yFk7P4C71OTmTL9enqIOBqSpNS4Z5j 1O3lfHNtCQPrS+nznV+sfxWwDK/MZTGOxxzntq9UgqLW+7MdMeOB3sni9LEUQxB8gV6m 5QzowGJ0ECMxEMmQ0eMlxltxT+MgnUFaKybcyORS6+1xvK3vDIW/nLOngpDZPNj7iYXf 0uzg== 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=y0NBhQuf2KfybteRYM2KfBpCijz1I25HMN5sM61Z6v0=; b=TUJZm5aIFatEgyFXTSMGwvihK1LrJjo2zln2+fOBF5EI/c8FHlCGRddG4G4yt5Y7o9 1kTascazNKLE/Qtn2SFo1iv/V09FgEtQG4Wntu6CZNgkKvXSZfcn8mQm85DtqBTsDcsm OAWnZbbLLaq1VwKEIVmoL2cjGxXzw4wWg9ldpbvp95MjBtVeY/t+r3Xd+DJYWBYBv/oi DXAFQ29HeZKpo8dKv0fQGtD33EqG+JC38dggPSolAjRLBk/BqP+okfI7e4OiRV0SHMNP P0Nq0dTawLr+xL4yBW5X8JcvJrl98QLOGgaYWN/Qywx3o2zUHNL3vg1Xer2jZlX+OmrT 3Rqg== X-Gm-Message-State: AOAM5310o2xNVPG0HHYPeNP5wrIvEu52uruuujGVaPeV5aXPqgKVDA4R i0K+WQDR4BRXWB0rXriUg7X8crfA/sWMJg== X-Received: by 2002:a17:90a:4817:: with SMTP id a23mr11795414pjh.192.1623454921966; Fri, 11 Jun 2021 16:42:01 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 27/34] tcg: Merge buffer protection and guard page protection Date: Fri, 11 Jun 2021 16:41:37 -0700 Message-Id: <20210611234144.653682-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Reviewed-by: Alex Bennée Reviewed-by: Luis Pires Signed-off-by: Richard Henderson --- tcg/region.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index e1790ce1e4..294cbd8e65 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -535,11 +535,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; @@ -823,8 +818,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) { @@ -884,18 +878,41 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) * Set guard pages in the rw buffer, as that's the one into which * buffer overruns could occur. Do not set guard pages in the rx * buffer -- let that one use hugepages throughout. + * Work with the page protections set up with the initial mapping. */ - for (i = 0; i < region.n; i++) { + 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; tcg_region_bounds(i, &start, &end); + if (have_prot != need_prot) { + int rc; - /* - * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprotect - * rejects a permission change from RWX -> NONE. Guard pages are - * nice for bug detection but are not essential; ignore any failure. - */ - (void)qemu_mprotect_none(end, page_size); + 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) { + /* + * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprotect + * rejects a permission change from RWX -> NONE. Guard pages are + * nice for bug detection but are not essential; ignore any failure. + */ + (void)qemu_mprotect_none(end, page_size); + } } tcg_region_trees_init(); From patchwork Fri Jun 11 23:41:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458670 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1375609jae; Fri, 11 Jun 2021 17:00:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyN4KgGNpkSqaxXcREq9VWsDKKgbGnolJbOc8R5Wihbe0gPthSVrJHlchjOuXdXrNIQrru X-Received: by 2002:ad4:5005:: with SMTP id s5mr7316998qvo.25.1623456017273; Fri, 11 Jun 2021 17:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456017; cv=none; d=google.com; s=arc-20160816; b=F/e/MDs1N1EBTv3zOsBpC5zKwOHgUd7AWwlxpoFc54LzuBC+kd0DS6+kA7NQUg0VBL QVw6/WPdFCHFBxhgXS0dl3TjvGYiAHeoRU31zJXuGceP1A2v4O9VYW4tWBrfG+y7kJ0h 2ONUC8gc5FG+4WQ6lr6go/GJ2OmT5zE9CVGzwPgDDdiSgFA7A6emPF4690zUye2J4BCG lqgzzl5sLhLKRfAk4fVAONbzH/rm+i2/dXSWNhlTn+W6Amp+Cq7cr6KI/EhgcwHWOPwx TVJXv0CHmMnOIs3bKgeqLrQVkBcxqTLYoDljaB8BY7mhNGNm+LzBfnLGvGVZcl3q/oFU VZzQ== 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=yutB5Hql0pmq+RPOoPP4QbECTT+S/kQDBGlJZPPQ9bQ=; b=gf3ZzMThmiJCjbLYbJK60Qj7H8rQ65J/SsnagBkpvkRGvO115YQ1oqFERgNRm9FCvC 0KR7kWcNf/12m0RdW0oOwa+K9lw2+yuGLZhSuPAMJ2DvR3pkDBMrBpyqTsRIh8jd3+aE ytU7heFGE5FPChBQQCfPVvhvZuQTjBOuQM3eM2xyXpi1M3r/4RjN9FRI+2+wPWfpPSgu 2mvg2pD8ePGlLGzNMvBjk5f7Qeh+FfBIYLitDVTeGrAcxOvw126QDIN8FMlN+Zmznzv5 WmpJ8/VwKIdLICwxHeGC78itwPpyBtZk3D+0BE1D2gUtWtMmhEe3ETzvHiXvOhw1ThA7 enpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OGvRN9iB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f9si5186974qkg.301.2021.06.11.17.00.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:00: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=pass header.i=@linaro.org header.s=google header.b=OGvRN9iB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr4S-0007bN-M6 for patch@linaro.org; Fri, 11 Jun 2021 20:00:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqms-000352-OI for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:07 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:56102) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmp-0002lN-Su for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:06 -0400 Received: by mail-pj1-x1029.google.com with SMTP id k7so6524818pjf.5 for ; Fri, 11 Jun 2021 16:42:03 -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=yutB5Hql0pmq+RPOoPP4QbECTT+S/kQDBGlJZPPQ9bQ=; b=OGvRN9iBjuorOC574RzX+WSlNAbzHwtkztdR8lNqKi7aCcRXhN3zeJj8H6q8QYAoiQ Caw7DLXUhbHz+CV+wcwBhE48iIJr9SWDDhFl9EBwrjO/agq4Go8h0F5lwrrqyxQhm+/r O+wa80oSq8sIzV7jWsopLS6dR2HEaQm5Vscp/ZW9NAf9LR3UqZfJHmXaE9j5jo5BjlzD sIUL8olCDor2TG75hYxr+/Szwg3aChe/aA4Xxb0oTND5FeQ1UUEJiZy2DVpqk/lSkCa2 ZjabL1hVe5+7GiwyM7SqLPS/VnRC9EH9dbGXzPbz8SugRd/wZWsReYUmgZSbk7AYrtQk lbAw== 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=yutB5Hql0pmq+RPOoPP4QbECTT+S/kQDBGlJZPPQ9bQ=; b=fMECbPfGUCQf0BtLDHQbdYvJWW3ISA6/OqDSwcMaDhNWeUnLFqDiZhAygRJ5kX4tIL XLR/ddEVD170GVSDkocfym4KbZf7iKeogdEWrcil9UfqaSG1F5QGfD1mq7118P+w84DX gS2xaHcH2VlfFMzfgkxx21IwUQVd0YX0ycM4UGvu0lu+FBtRFcxnek2uiV9XiRCq6WkB O+HAwWceMBXrKTUSK+eTTY4zztg9EnsrqZ+tNESm7G6FSQ8ocluKGEWW1PBv0b726EIA icD1JA8sqCgr1HvK8mlFehchQLjvdgPdB2Jt4YV6YaOqPTpz9vgLvEdw7iulNnZoxZ6L rZYQ== X-Gm-Message-State: AOAM533M/ixeNNjjxL/GnxVtf8CLZNSn6Txu/O3d8dc4Rh6YFTME5lSp wmOFMipXojj0+L86FDKUAzhk2R6X9tpYMw== X-Received: by 2002:a17:90a:8001:: with SMTP id b1mr11424065pjn.17.1623454922465; Fri, 11 Jun 2021 16:42:02 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 28/34] tcg: When allocating for !splitwx, begin with PROT_NONE Date: Fri, 11 Jun 2021 16:41:38 -0700 Message-Id: <20210611234144.653682-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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: Luis Pires 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 Reviewed-by: Luis Pires Signed-off-by: Richard Henderson --- tcg/region.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 294cbd8e65..0f6808afdb 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -770,12 +770,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; @@ -906,11 +909,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) } } if (have_prot != 0) { - /* - * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprotect - * rejects a permission change from RWX -> NONE. Guard pages are - * nice for bug detection but are not essential; ignore any failure. - */ + /* Guard pages are nice for bug detection but are not essential. */ (void)qemu_mprotect_none(end, page_size); } } From patchwork Fri Jun 11 23:41:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458778 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1379244jae; Fri, 11 Jun 2021 17:05:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOLwXJqS0k4VZWUxTdwP14DAspATJdeVcT8zLO1Kd1tRzA99iKQfqvIsJmbkYsR8MTY6mA X-Received: by 2002:a05:600c:290:: with SMTP id 16mr6229481wmk.162.1623456328533; Fri, 11 Jun 2021 17:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456328; cv=none; d=google.com; s=arc-20160816; b=WoWeXqBAVSAbd8YuugREbSChMP0uQH+eB94d8Xcc6QaObf5j6/BXrJgKOxJ8gY7ggc rx6e5lDI6iadU5ts6cY2NsEy2fOM0Wuk/62qoWqoILJhld8wVimAqAY6Y8jCZ/brKxJ5 OtVCUgTtV59O/E3rLytDla9gFKRSzRjbtzYLJNA5jXBozJTjEISQiLNApnkB25fAYlGp ho4F0Fme3YLnOjXrbO+jzFBndlPxrcK7Y+45ysW4veRw/tUjzSVH1B3Y/2TQeyo8zTYk JPaTboINiwL5ZAr5GRMd4OMazws1YEMUjg9KC17BJjb8ori+3iYyiZsmKlSiPULVoaHr Ps/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=svHo4xej4hLH/cZ+9yekBSSnKW0cEWwyz3UL+6E6tak=; b=DLz+JHoRcmaSkuRZoZVTG+7uAv4sNnggajv4qzV5fOXJOcRd5OlKPPrw5p8NBdkWbv wTPpLsGDCqYXGLy7kI2svepTuXHwsDrqE5BVFuZkzFRRNsVIe5mtHHB/BKfnRP7B+B/o OaDxN9triKpPbUbRncak5ptZdoUWcivZpwT+wN1qRMqjqTWokH6uQ7yXtQ2uyMKt1Te1 pSOPGK4hhCliL4XedcN8l67uHxcr/P9V2lJqS6vYlMNBn+ILX+F2otqzMH7ygsLoBGik QGVfAYQWXqdvgesOn3iCMTZ6DJAuG8F4TAfzrY9guoBECxHiN1V5FzB1l8aX2Jyz/VBN +HpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LsSnWWNh; 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 r3si8226270wru.226.2021.06.11.17.05.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:05:28 -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=LsSnWWNh; 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]:58506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr9T-0005Ur-KV for patch@linaro.org; Fri, 11 Jun 2021 20:05:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmu-000364-8B for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:08 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:37864) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmq-0002m8-D5 for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:07 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 22-20020a17090a0c16b0290164a5354ad0so6725283pjs.2 for ; Fri, 11 Jun 2021 16:42:03 -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=svHo4xej4hLH/cZ+9yekBSSnKW0cEWwyz3UL+6E6tak=; b=LsSnWWNhZCKZXxErGASaJSbSaVhnrMmLqcL986FDj0XABrKmWhkKC7fKSPr5fg31q1 DB7tr4/JV9cc5FpDgX3x7KMN8pebQxZDhSitSmNqX0o1n7gLbv8TS2pfwfyqoyp/tmIk rWmMWxc74IT/mAXOp9yjhRemrdtineOCL1D0WfGVHqguhOoYLx4GjjsNGOS0Tat7cjAM zulwdL3LdfuovuGbo5rAVxYlcgSNuwiA/ihow40J3vryD7COrl8tpYaIiuNBGBTGQ8Dr rq3hsHVhDVS+rw4ih+6ltQds6dSXc7T+KPmuIBWLU8duaib3AZzVsSZbKyw1tBqQsPpo epXA== 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=svHo4xej4hLH/cZ+9yekBSSnKW0cEWwyz3UL+6E6tak=; b=UXzXDEoHetqDLrMXiv7Upw/9tZ+2BHv7+I2Miz0m6anUtZA8giao5SZCGUluLTfjeW Eire4yr2X6unJNH8MOGDSBTTcqYUl07zS3Hu3B1RCFzK67eSF6xLQ9KBo75nvtFKsGpU KxTLAME1WurrcrZdL5wiBAFphzi7q6kmdGHRVy6CR8tODF9mftUuBuAfxiahipHP93h4 NwJ8BCGZdgIYDN5wlJISX6OLThyGIvoLhk9wBh5IcosiRTC/cYAaS/LiBGgbixgF/pMY 9d9F5VECQ2mYO1ZF2kNHZ7bmFSawbSF/4Frhmi7qRJww7L+A1gt9ho6MOgoRewghFf32 90eQ== X-Gm-Message-State: AOAM533ookCP+DB5fWAx730LyxiuquRem6pwHx7bDghd1VPqgjvqfM/9 KQ/4mQeLwDcfq15lYrnUqp/I1sFYRT649w== X-Received: by 2002:a17:903:8b:b029:119:7c28:727 with SMTP id o11-20020a170903008bb02901197c280727mr860199pld.3.1623454923084; Fri, 11 Jun 2021 16:42:03 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 29/34] tcg: Move tcg_init_ctx and tcg_ctx from accel/tcg/ Date: Fri, 11 Jun 2021 16:41:39 -0700 Message-Id: <20210611234144.653682-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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: Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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. Reviewed-by: Alex Bennée Reviewed-by: Luis Pires Suggested-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 1 - tcg/tcg-internal.h | 1 + accel/tcg/translate-all.c | 3 --- tcg/tcg.c | 3 +++ 4 files changed, 4 insertions(+), 4 deletions(-) -- 2.25.1 diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index f48b5aa166..e95abac9f4 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -689,7 +689,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/tcg-internal.h b/tcg/tcg-internal.h index f9906523da..181f86507a 100644 --- a/tcg/tcg-internal.h +++ b/tcg/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 59609d62d5..7929a7e320 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 4bb35b455b..81da553244 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -149,6 +149,9 @@ static bool tcg_target_const_match(int64_t val, TCGType type, int ct); 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; From patchwork Fri Jun 11 23:41:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458675 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1377924jae; Fri, 11 Jun 2021 17:03:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmgjXyeOiUytl6wemz807vV0jUMqCzF6ipZUcY1/x1utGJtRlgLLuQKrNdfBnojY8+nbyk X-Received: by 2002:a05:600c:3581:: with SMTP id p1mr20004521wmq.109.1623456209528; Fri, 11 Jun 2021 17:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456209; cv=none; d=google.com; s=arc-20160816; b=OCRvL4JqgupFUkNw+xSG+hzvzhYznWCgL+YK5gZSxaGWmxaZNwQhu9q81fUxacl1IC oZW96yrk90OcaPCGDnYRjWhB9aNMEhcRsgeSx8nihyeLNt4VplB106Pd/eprf2A9Dgpq 5uuNaW34FvrfOL9Aj5tBvVhCrPyN7PK7KVEpo93ndGHEU3XuHY8h0gKFg+k+qzD/43Bw MtTAE1w3UtJ8LYLfNjL20Ssm4m+t0xZusTMFTHZcS9lOo03x0vNEluIZy67Ow/WgATBf z4GnvqiJ8RMcjDNxuMtZkKXU2J8ylu7oC6jhJgTecddlk6BOrtCLlX4Xs04Ul+yjRVZ6 3vNA== 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=TzNUcN4JD2JTYnUB/p6WRvyMqqqhllIV6sanl9jNAWM=; b=b+vHcZsKbYkfpd5CO6aeqmmYMqxSS1mylqDZlhrFusm251b++IQlsC1CksuhJGE3c9 57ESO+gVKdSR+ydv0rMJPQffO5wCp5y069giGhg8PimA4rvvZjZ8mG6MagPfhw+xDj4b HuO/I36as7p6f/mqR3zAq9re7cnLp37hQsYd8UHl0lowhlvuYZSgTSiMOLEsK1nDaQYk Espz7NKbfvK7pT4kJyV3/VxYw2WKw8kHMTMeovZKoc/5objseXoFGzJ9VmPh/CfYNLly rF0n92GoxwGYVwKyr70riheYCeDMekcXhYGgkaEh58Tbi3vrSQDW7KUH/TqCA17cE58j 5d7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TW8EEaBn; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z17si14543490wmk.166.2021.06.11.17.03.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:03: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=pass header.i=@linaro.org header.s=google header.b=TW8EEaBn; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrr7Y-0003Xe-Jy for patch@linaro.org; Fri, 11 Jun 2021 20:03:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmv-00036Z-CQ for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:09 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:50864) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqms-0002mS-9U for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:09 -0400 Received: by mail-pj1-x1035.google.com with SMTP id g4so6555273pjk.0 for ; Fri, 11 Jun 2021 16:42:04 -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=TzNUcN4JD2JTYnUB/p6WRvyMqqqhllIV6sanl9jNAWM=; b=TW8EEaBnKSjAMr2mJYfc9yiD8SenEuoi/UuqdLPKWcX0J+34+tOBHNzNPsNOV+uxn0 QvrvEc7h2W442IaC8vgZ/yXwKIfzkEpq9hICNMqQSt7X7YyGWgtvEH7g5Mf3avEkTS9Q Dut9fq6wX4TlkYytJPNKhCC3eO3kg5wNaDT2pJrR1i7e6Za0yPeF3ZRdpTUkHK+H82jR oIS/A3fqyRRbQHLB46cv6eewpLO71g5qqU/OnkkxmFMQgpGyebl3mYLICPJs8mCtT9mE qifbH8m/ri+o9yFRmbcKxsNAKBHMpmwKn8e3ZaqvxeQrpHGAVtofUePZHmFPbyuIfScR hwZw== 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=TzNUcN4JD2JTYnUB/p6WRvyMqqqhllIV6sanl9jNAWM=; b=VzhOedsgyo2vDVxXl52LDhR/PLYUIJIDHmkh0zlEwUPBwCusbr/NctWEwgMsYl3qjz 4u0gHOXW6htasggT0+IGU0TrBSdymB7rhO411onGIbLdrHBptn0HRmdys+x5eoCPqMn7 GU0T6JZy7JWr+zbTLB505INV/WCD5l9HD5FRMbOqKxvK0z1TbXH4VP0M7gjZoR2jfOnv ErSg12AFiXsNSIuAbGdflZVnB3jYOlX2E6vVd65VYaC+T97ooWK+OCtXTfqNSaOs7n3R VZX9uDV0p5dOQ56n8E0WD8aW4x02P7zUH10q13HfCc2v8KYLMoDSGxborhC6L+5enowm sDqg== X-Gm-Message-State: AOAM530QnHFkjH2f4q0NudLZKt2l5OUTl5cJsrJD4Mewngisj1vpArex jCvtgWk+TXB674V+BZFJPTAmk2ivM6b2ig== X-Received: by 2002:a17:903:2093:b029:117:6a8a:f7aa with SMTP id d19-20020a1709032093b02901176a8af7aamr6210507plc.6.1623454923724; Fri, 11 Jun 2021 16:42:03 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 30/34] tcg: Introduce tcg_remove_ops_after Date: Fri, 11 Jun 2021 16:41:40 -0700 Message-Id: <20210611234144.653682-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.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: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Introduce a function to remove everything emitted since a given point. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 10 ++++++++++ tcg/tcg.c | 13 +++++++++++++ 2 files changed, 23 insertions(+) -- 2.25.1 diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index e95abac9f4..1d056ed0ed 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -1071,6 +1071,16 @@ void tcg_op_remove(TCGContext *s, TCGOp *op); TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op, TCGOpcode opc); TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *op, TCGOpcode opc); +/** + * tcg_remove_ops_after: + * @op: target operation + * + * Discard any opcodes emitted since @op. Expected usage is to save + * a starting point with tcg_last_op(), speculatively emit opcodes, + * then decide whether or not to keep those opcodes after the fact. + */ +void tcg_remove_ops_after(TCGOp *op); + void tcg_optimize(TCGContext *s); /* Allocate a new temporary and initialize it with a constant. */ diff --git a/tcg/tcg.c b/tcg/tcg.c index 81da553244..ca482c2301 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2083,6 +2083,19 @@ void tcg_op_remove(TCGContext *s, TCGOp *op) #endif } +void tcg_remove_ops_after(TCGOp *op) +{ + TCGContext *s = tcg_ctx; + + while (true) { + TCGOp *last = tcg_last_op(); + if (last == op) { + return; + } + tcg_op_remove(s, last); + } +} + static TCGOp *tcg_op_alloc(TCGOpcode opc) { TCGContext *s = tcg_ctx; From patchwork Fri Jun 11 23:41:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458540 Delivered-To: patch@linaro.org Received: by 2002:a17:907:7409:0:0:0:0 with SMTP id gj9csp706862ejc; Fri, 11 Jun 2021 16:48:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdLDJT3+wNyRaculzXY9KJ/aPOD8UFwHECvXUdZtdLoiYHIx0hn/nfOr7Fal4rncJiLk/3 X-Received: by 2002:a02:7110:: with SMTP id n16mr6089172jac.69.1623455299035; Fri, 11 Jun 2021 16:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623455299; cv=none; d=google.com; s=arc-20160816; b=ms/fWunUuwptEzU664x4Mp/KIEElyw+aYv8tzTK6ImBAAkNo7xpdc9e+lv2ouDlb29 f8jbS0P0Z4uAHFezGkDZI1Q2Xqc7IAD4WRHOwQokfNMnOEqfzVhgHrzrbOYzeXjaUrKG J8vZrOK++1qSUyqkr7Sp5LE9iDW2cXc7A74U/nY3K+3PqSSW2Z6htCx/qhYAtr3qRh+q qjI+slP0R7ozeN+wGdZJ9/IeYvgTUVRmeCOtDKRb5mEDKIGKLTpdFta9mSGaxccAwaPb FsqkUmwEjNcXFOEBjymvjkWuzTs/ftIs4+v+FHu4ag6cMX338/fn3box4Z6IR5LRYKYE nZXg== 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=DEGK7taWTLgaAQxBCsJBdKV8XPOvsryzrwUIPNhMs30=; b=wVDIDyvSOiXoUSUqJ0Kw1po6HdAucM3soxOfM79B+OX/QmsNDGGM37fxgQPtoFOxcq rbYuGkwsHxCRse1q92kq8yOFyWtd4YLRRRuRB87gBUC+3Gu8KMW8yohil+mWb7BfCFV6 qqzfbWnr3QCjTDFq0cHD3/4jri4kMKGQP9QcIFPgp2l1PIdk26Dbp4VuyybglNO/yYuA 1wXJy9NwZz14YSR+UK6I5Dm4sTLCBaK0p13nQmk+73VrVwEGwCN8N144Y3l1ekG0bc9b h2j/xL4QOesBZbt4DrPCXx7SaS90Ul8XkVoFPGME+FjtJbl2/huRYiwYJKx/92ndugjR ZhLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RDS9NXO3; 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 z4si8495865iod.34.2021.06.11.16.48.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 16:48: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=RDS9NXO3; 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]:37276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrqss-0005is-Ac for patch@linaro.org; Fri, 11 Jun 2021 19:48:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmv-00036f-Su for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:10 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:35491) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqms-0002mj-BA for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:09 -0400 Received: by mail-pf1-x432.google.com with SMTP id h12so5700133pfe.2 for ; Fri, 11 Jun 2021 16:42:05 -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=DEGK7taWTLgaAQxBCsJBdKV8XPOvsryzrwUIPNhMs30=; b=RDS9NXO3+DcqOqnv2DsN5MNdOijH1reVjSyDyGV8MktpCEEGOPAwucFlVtC19IDmAW FL1sl2e1JhDY7W0DXQ9sGKIpjP6+E6DektVlBkeCCJwbDCh9befju9zMSA1a4p2jtwHy 0iwnUOLaRvWubB1t9eMjxYGTOBBBkhGsECQQK6d0mCl9dobr2dIqIwPmyNuzrPpM5YXX dft3jLUr2V72/4Wc40pCZV6Y2F7LRGS+8+TGWyDc3Tv89GTl0OljILyWMxeQ/hn79oxv x8nOMBA5tO+vwrRe7XoEaC1m28A6LGKyTZukcDkOVkRVi5xxDiHj/mQM/Ds/9c2pmtqF zpnA== 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=DEGK7taWTLgaAQxBCsJBdKV8XPOvsryzrwUIPNhMs30=; b=a2epc9UG0VfUH4WQYr4puLGrn+OJ4CPO8oo4b8pfPlzSQLKMjJBab3u9tI0QphWjZx HcpXwFxd/ECEuQPdeqym6Qb3MB3Hq6DmmracXRdAQrnVb6UrHMW9T3/m6Hgexcbzikxl Vyzc5amz16ztmqrQ75xozIQWvtAOjGwxlSl/NUKZEQ95jRSxc3yxDgyEKQuv7FlXK0yq eCswplFePXf000+B6w0YGl3rvBwjscDFcVyiBCyAXFNu0ma2QY5F4cMdet/6I2WdhB0M vCPh+J1BKLdwcbyJFLsuiZYDiaG6wPYnGxDhlO+FlyJYFv+DrHvdLGVO/yedxa9n3Nbd BScw== X-Gm-Message-State: AOAM532g/dpgIkxGYPEnoTB6EX4Af4AfpwWSg+VOdUTtj1BoSfJ92zjw lrm3+PWHFyTie/P5+5mL9QprZykRzB6rxA== X-Received: by 2002:a65:64c8:: with SMTP id t8mr5969601pgv.96.1623454924415; Fri, 11 Jun 2021 16:42:04 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 31/34] tcg: Fix documentation for tcg_constant_* vs tcg_temp_free_* Date: Fri, 11 Jun 2021 16:41:41 -0700 Message-Id: <20210611234144.653682-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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: Peter Maydell , Luis Pires , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" At some point during the development of tcg_constant_*, I changed my mind about whether such temps should be able to be passed to tcg_temp_free_*. The final version committed allows this, but the commentary was not updated to match. Fixes: c0522136adf Reported-by: Peter Maydell Reviewed-by: Alex Bennée Reviewed-by: Luis Pires Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.25.1 diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 1d056ed0ed..064dab383b 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -1095,7 +1095,8 @@ TCGv_vec tcg_const_ones_vec_matching(TCGv_vec); /* * Locate or create a read-only temporary that is a constant. - * This kind of temporary need not and should not be freed. + * This kind of temporary need not be freed, but for convenience + * will be silently ignored by tcg_temp_free_*. */ TCGTemp *tcg_constant_internal(TCGType type, int64_t val); From patchwork Fri Jun 11 23:41:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458917 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1383778jae; Fri, 11 Jun 2021 17:13:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJww4UsiaR0ZG6wiCZN6r0kkody7qlugMjLHe7hAHDdbAHqcEfDCTa0jXG+TPBCJj8K3EKH2 X-Received: by 2002:a67:fe8c:: with SMTP id b12mr12068644vsr.1.1623456781057; Fri, 11 Jun 2021 17:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456781; cv=none; d=google.com; s=arc-20160816; b=w4HVoEhX7mWpmzw5OAr1Im3u/EBow/p//Cs68o9F2tR6g4a+usOhMWXGdPs/hKhtJc rcEBjj0V0X6dv4ty9/R90caEGI44aZDT/TaZZpvLOKLfoSYifENMyuglVwDhKWi62Q6x fQHss7Q3fpb00r6/asWA41D67TNMnb1tYnG4ArcJQWkxWF0amEjqTyYqQQB7jRFoHHVL dA8nPa+JRkKiLYnCD4ewcMc4NgpJUgHWJw339P/b56xPgE6TI5MKy2BWph4rISNOUtwA oLhSRm1Ob9T+4Tp3MUBklX08CNVux5ra/RyBjJBYqPTISceUEzF+1uwFt8rrLwecOeiq /C7A== 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=JF1Hf1+TdXcOHMQWjuxHp6sHzQbmxSqgzI3Kb+3k2Wc=; b=C/IQPHOCVq/lXb+7BY3t1MpiAGEYkLEWcS2X+y6VmNrye+cjZmeRI1J9gpQQV+hA6V gsuQHfl3KD9+RRlldH/PXtltGvVNJT5XKr+sEtSmmdEkHSLYynLJVHBytmlriksOH/5R HjuKh9tTkQn0oFgtDPG7D1Qghz/5pNrHanebVQ90P5jpj6wmMSvPgu1DGSIRk69zbeZ1 8sdHNPbXkqRPJvEdCaNCb4p4tk0TwiyAYC34371/WVjm6gUEdEhZZUWELKKaUYed/0hv 6xqBQ4tvQJoO8/eoEauLQ0G1yM0FAGeErRx605yb5fqSdpAC0v1C7+s1W5UZ/vdw8GC9 MT0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mcSZhwgI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v5si2824496uaa.180.2021.06.11.17.13.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:13:01 -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=pass header.i=@linaro.org header.s=google header.b=mcSZhwgI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrrGm-0005pP-D9 for patch@linaro.org; Fri, 11 Jun 2021 20:13:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmv-00036T-0l for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:09 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:46775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqms-0002nN-Di for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:08 -0400 Received: by mail-pj1-x102d.google.com with SMTP id o10-20020a17090aac0ab029016e92770073so913282pjq.5 for ; Fri, 11 Jun 2021 16:42:05 -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=JF1Hf1+TdXcOHMQWjuxHp6sHzQbmxSqgzI3Kb+3k2Wc=; b=mcSZhwgIQsUXktt+bP95/Tfa9HfZQARxFR16Ba0mQmtWQcMCJKtuHsAihjxXPYHMZp HOnNfvytNfI7F2ld9ex3ECVKVC0isv/3CMYvfqdKAu7mbhmsd3MJzST9JtG4vf/zlyPE +I1dKDggEKyalBPIcyZ0oZVw4TcMNtDZpB9xZvxJWox4B/Vk30AmqtdK3wolZEOtfA11 F07pE8t3HCnT5vBgZM2O0eh/NPnkFOBXmMw9a/PDu4QpPRDILZu5dMhEpGJ1JNiRjgac fUZGUsAtMl0OKZFfoYjg3VgJhKicXAk5zqepKpGWbBzvfigj4oLzp84NgTc38GTYg7dN 05uw== 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=JF1Hf1+TdXcOHMQWjuxHp6sHzQbmxSqgzI3Kb+3k2Wc=; b=YY/JxJpwMh4kxgpHK1qMuAKdLOhkGHs61t7TijNW41cxvCLVmpYQUWZeRayCb9z6SR a6THh48EbwgQf38g0cdzaXXO6y4Kmyql3Vz0p765g/euEjgm8yTYk026RmkRTYp6rxa1 O+I+s5Z9IvaUKHVWurIlCUc9BDaLgd/ikL7MK+bjNbiiY3nBtsTFVh40y+AiCehvWeS/ sDzHx1HiUj156DHNnnShqEeG1v3ssfMlkjxmry15crrsVQyD0z3mIAwA5FeOIQaz82s0 nUyCk7RKIJFLmkA1fz9fDvwlnV0xYuqUEzb1Ai0bibMyA8ypKtR8YAROMsyDT/zNoFvm fEbA== X-Gm-Message-State: AOAM533Pgqc5AWFBRblY15+YuPa08xUzvRhQBKrgY+Rrvq/JcbLotn7V ZWvcbl0chBMQLEZxN0FTiP7KDFuHL4Tpdw== X-Received: by 2002:a17:902:9a85:b029:10f:45c4:b40f with SMTP id w5-20020a1709029a85b029010f45c4b40fmr6121450plp.32.1623454924966; Fri, 11 Jun 2021 16:42:04 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 32/34] tcg/arm: Fix tcg_out_op function signature Date: Fri, 11 Jun 2021 16:41:42 -0700 Message-Id: <20210611234144.653682-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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: "Jose R. Ziviani" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Jose R. Ziviani" Commit 5e8892db93 fixed several function signatures but tcg_out_op for arm is missing. This patch fixes it as well. Signed-off-by: Jose R. Ziviani Message-Id: <20210610224450.23425-1-jziviani@suse.de> Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.c.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.25.1 diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc index f4c9cb8f9f..5157143246 100644 --- a/tcg/arm/tcg-target.c.inc +++ b/tcg/arm/tcg-target.c.inc @@ -1984,7 +1984,8 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) static void tcg_out_epilogue(TCGContext *s); static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, - const TCGArg *args, const int *const_args) + const TCGArg args[TCG_MAX_OP_ARGS], + const int const_args[TCG_MAX_OP_ARGS]) { TCGArg a0, a1, a2, a3, a4, a5; int c; From patchwork Fri Jun 11 23:41:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458779 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1379695jae; Fri, 11 Jun 2021 17:06:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmOQ7VfEIM6FYxOiBxQaQg1JPJf+/l70E3vX73f6JOhflYc3zBc/e9fzV0tl3jo1QwcnjF X-Received: by 2002:a1c:1dd3:: with SMTP id d202mr6166759wmd.78.1623456372812; Fri, 11 Jun 2021 17:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456372; cv=none; d=google.com; s=arc-20160816; b=M66zqQ5FDQSy/ZaQv5kqdTwHzHiZdnELIDKVJzEPy57kbxTkDoqPWrY4rf+3HwaYBm gUJvjadEOLZRJHHNDF+O3AfJM0KINOSwlYJ+I903OGEZiKBHbBgZ3migXfaTZW8jn553 WqK0pRgEQyqkWCp5T/fX6QvBsaBnN17u5ocP0VJ2jogq/YQjoZZ/qLtoA5fCZE/SGJKv fMZc2hvwTtUGDaxdGL7Nye+40Tuk6MLwLbg18Usp8HkIRDb3eunJrpNidu2qnblJ3GBR KGoNq+JiTn/shToY5yxhbzFO0PtYRPCnFGh/kamkGWZCYci8S2zq4DXcDGrpe1AKNsCA oe5g== 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=b2B+8zz4r3rzDW6XJQUxvqU5pgzCPun35EtW6hJayB8=; b=aManT3hYt9I03qRihgQjv1BRufZ7UGUWhBjNBUFXiTlupfGnzkHS8wwu9IHXfi21kX mYmgvovoGpogYEIpg7HY0oC+ghtX3/I7/LcCKMcBPjPyCiQki76L92rt4wIdKF9LITRF RjVW+Vc3gE/fp/x4liI/Y7hGZxEBkxTLXw86Lsu8GTxiTgSKyGVbWn9vbrHcbkpU7wh4 JVcILkaJWmjhLGqg+2z94UOfpZmY1TIHQBoeF6XZFGU1X7ne9ROr+/VwXDce56LL7UOM K/692fnFd2atnpyoOrPPSpfyQb1OVts5TUfYb2ybUEKIeyMrs9vBXJ/a9NkgzCSH5Nf5 VIeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="nA/+k6Is"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6si8557863wrb.237.2021.06.11.17.06.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:06: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=pass header.i=@linaro.org header.s=google header.b="nA/+k6Is"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrrAB-0007oQ-SO for patch@linaro.org; Fri, 11 Jun 2021 20:06:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmw-00037g-At for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:10 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:39766) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmt-0002nU-5h for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:10 -0400 Received: by mail-pf1-x42a.google.com with SMTP id k15so5692965pfp.6 for ; Fri, 11 Jun 2021 16:42:06 -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=b2B+8zz4r3rzDW6XJQUxvqU5pgzCPun35EtW6hJayB8=; b=nA/+k6IssAQirvFo5B6zylhJ8zl/YNDds04dx99IhTSLbdl6eO/BFmxdMvm7AKRb+c 0tg09IpDsUfIxMi3pVWfPWhmT9BubWXgOJQEN/DjbpqdeSaAH9/uKhv4n0NaA7dkgUZL FC8bBI7wCI2L7YJNaX6fRstBRjLR/FNMhdgYld4u1xcsP4JicB5tlnBgH5/LEQ+qK548 02d2UL8n9+0OPB/L7SgrbSt+xoQN56RSQLgRRJ/JdK70rvumTF5W3w2W7umu2UJUWgFx 7EOk/Ly9xCFsqBTJx9zx4aH8IXIpHDUFa9hLs/rJ/r4zFniDgPo+j8S5AuSh0iqRlEQ9 QBDg== 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=b2B+8zz4r3rzDW6XJQUxvqU5pgzCPun35EtW6hJayB8=; b=WJFVEfCH/69jYKt6e1wpBWPx8hwr+MVOLHk6jK5KT/KR9uczrDewH5Dx+J0DAhQkVj 18WYdmwCd4tIxf7v9ucolN1XKrfJSvFiR55f41QCR8wI3cY1QAIvJtESXzj88e6uKEOz 4MZogDliNT1he/O3d8BS5JTr/kzRFDcSTK0p8fkNEl2zQjmHAP+T7PFdFqrea1UV7H9f avIbv0OBLM5v9cwugDmOn2GeZkRntTWw4f8t4+A0brFt+7kuoqwyUBkqY53HDn8hYtfD iyJ53yxTsILkZZ3hL2P/8iR5Y7c8OFBIdgVHENQncw8L/iw6vvn4bOYs6lCLFPg0U1KN tQAw== X-Gm-Message-State: AOAM533pSJPeWqho0vnkpkmbvnst2w7kzBKsaoIofRCDYIzzSdB2pHFa r2PLEULkBS501tWHhAHRNgcthdi4pAg2VQ== X-Received: by 2002:a63:1210:: with SMTP id h16mr5949953pgl.189.1623454925562; Fri, 11 Jun 2021 16:42:05 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 33/34] softfloat: Fix tp init in float32_exp2 Date: Fri, 11 Jun 2021 16:41:43 -0700 Message-Id: <20210611234144.653682-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.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: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Typo in the conversion to FloatParts64. Fixes: 572c4d862ff2 Fixes: Coverity CID 1457457 Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Message-Id: <20210607223812.110596-1-richard.henderson@linaro.org> Signed-off-by: Richard Henderson --- fpu/softfloat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.25.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 1cb162882b..4d0160fe9c 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -4818,7 +4818,7 @@ float32 float32_exp2(float32 a, float_status *status) float_raise(float_flag_inexact, status); - float64_unpack_canonical(&xnp, float64_ln2, status); + float64_unpack_canonical(&tp, float64_ln2, status); xp = *parts_mul(&xp, &tp, status); xnp = xp; From patchwork Fri Jun 11 23:41:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 458918 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp1384949jae; Fri, 11 Jun 2021 17:15:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEg5AyveV2eT8FBTm/tD3MUDjx0G9vGdTGTkxSj/Uik1X0QJRtb2ZjRG9o78+ft9Gd33Pl X-Received: by 2002:a05:6638:168d:: with SMTP id f13mr6214112jat.124.1623456907497; Fri, 11 Jun 2021 17:15:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623456907; cv=none; d=google.com; s=arc-20160816; b=Faxoz09UUoQSykOhJT6j/iNEbHFu1KNkV1/osFiJKMX7sQEuGzaPlD2E2J5ZxvXKmV 8kqMoVVjoYGfyWSat+LAfUFiNbLqk4Szu+I2Zuub9Xj2V3YOcOZvrXnvbvtk5tZakwn4 fUaqac1HMxI5nDP8vBjq/o78+6ngXxKREN7bVNNfiorV3l1SYp7vdzNuCkyXX3xukk/N GnheL2ZVXutPlaCnWXqc5nyVyRJNybTWax0CUiCkvRb1F+kYDZxrubHi4/U4WJeIRwS9 J+t5frI/U6NMG8IlVYfdOfeQw1su98H9eNMi+Xy30M5cx/RDbICMqgbcPA7WD+tWxtTj W1zA== 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=lWH9d8CyMl+D9rIbVRzVUg98zD+hFqxk964ZJWbRkCY=; b=zLzXfDwbBu5W8n5tOBap1udbk2bXoqMWn5xOGBB5lH0aI5icqndnYdjoGuLVsJHX5T FcqoCIBsbUii7IesWCIc8km17ASP/negh32Wx6azEQlyBVNO9HqNxdGN37i4iKO53Da6 xsMI2kWLvEH79/vq5ZkkGDDSiCGf89qCactFN6gte/WodEG2jIXCnerWytmhAc/g7346 K46jijXEIbrj6IjCCPuq0UTpR5pvVaqH2OTN54+nWKUgciCJ+OB+ZG9zOI2CLnV9NoB9 4JQrU66bQKutaVfZVx1hhpdr9YddhdYp1oAwBcDjrxHKDXKxB7qA8MTk+sdnQNjrGRee MF9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b1ZHwq7G; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h26si7360368ila.124.2021.06.11.17.15.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jun 2021 17:15:07 -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=pass header.i=@linaro.org header.s=google header.b=b1ZHwq7G; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrrIo-0001Vl-Sl for patch@linaro.org; Fri, 11 Jun 2021 20:15:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqmw-00038c-Vc for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:12 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:52779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqmu-0002ni-Lz for qemu-devel@nongnu.org; Fri, 11 Jun 2021 19:42:10 -0400 Received: by mail-pj1-x1033.google.com with SMTP id h16so6530857pjv.2 for ; Fri, 11 Jun 2021 16:42:07 -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=lWH9d8CyMl+D9rIbVRzVUg98zD+hFqxk964ZJWbRkCY=; b=b1ZHwq7GkL7G7s/Jq+KE481xt7rbKWgN17UVGAy0Rq0GT2TNPMd4JL9n7EsdeMbgqU VGU/pMuDD0AdeG/AIfah3M0dP+e/g2LAyn3Sj4gFBgNUxgPBtVWkrYqft3cAKXdSqKtt TDmUWk0qt+EaY3gZYCrAIZvwvrl7K1nEEoHzwTpHxIch5PfiUNqVMYD69x0qRHIIyzqP JyvUdE8DpfRu8I0l0nc7MejX7B1dJeuE2e/VZRkrDHPFcJ+Hb6fzCEAVIl5RLipwap9E UxHdfKLQzV0Hih88m3cOs6qDzztcMiY03kpPKW2hf2MjnXImPCXvYpWGi4L15vFuL7HN EDZA== 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=lWH9d8CyMl+D9rIbVRzVUg98zD+hFqxk964ZJWbRkCY=; b=Xll2dZPuzGwM1ZxQt21MGPgHVJfrLD26AySOgHZtHmVuUrq56zSHHlr97MsI/kqMuU H/6h15ePN0sp5q0IO4O07Bc5JuSSLqBGeP5FWGYJfSGh330GMu+aoA6eaTdXlPTZint4 marlzq1KNBgW1Lld6IOXah8/rY7edSNtBFevHIx0e4PBmlYba8S8mmkz5SYH7dfLtgXR WrH1QHnjZ9+/Hd8A9EYdYV/1F8cZQQ7Y5S4GtDY3D3t7lnPJty9BYy00VAeyHse2k1vb wviP5KEwumRrup7UqjBa0lRtceKXKk1FWSlQqfBmC4cpv6WR1z0A15Q4jNEy59B0Rz/r bJpw== X-Gm-Message-State: AOAM533JikkkfHY5N4J8kaaaLZlnfi3rQyvIQoVCxmY6w55ylRsYGhBa vfr9NwPzrg7na90lz7TWZGg3Szw3ELgXbw== X-Received: by 2002:a17:902:f54d:b029:107:b14c:423d with SMTP id h13-20020a170902f54db0290107b14c423dmr6151973plf.77.1623454926229; Fri, 11 Jun 2021 16:42:06 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id q23sm6139829pgm.31.2021.06.11.16.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 16:42:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 34/34] docs/devel: Explain in more detail the TB chaining mechanisms Date: Fri, 11 Jun 2021 16:41:44 -0700 Message-Id: <20210611234144.653682-35-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611234144.653682-1-richard.henderson@linaro.org> References: <20210611234144.653682-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.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: Luis Pires Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Luis Pires Signed-off-by: Luis Pires Message-Id: <20210601125143.191165-1-luis.pires@eldorado.org.br> Signed-off-by: Richard Henderson --- docs/devel/tcg.rst | 101 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 11 deletions(-) -- 2.25.1 diff --git a/docs/devel/tcg.rst b/docs/devel/tcg.rst index 4ebde44b9d..a65fb7b1c4 100644 --- a/docs/devel/tcg.rst +++ b/docs/devel/tcg.rst @@ -11,13 +11,14 @@ performances. QEMU's dynamic translation backend is called TCG, for "Tiny Code Generator". For more information, please take a look at ``tcg/README``. -Some notable features of QEMU's dynamic translator are: +The following sections outline some notable features and implementation +details of QEMU's dynamic translator. CPU state optimisations ----------------------- -The target CPUs have many internal states which change the way it -evaluates instructions. In order to achieve a good speed, the +The target CPUs have many internal states which change the way they +evaluate instructions. In order to achieve a good speed, the translation phase considers that some state information of the virtual CPU cannot change in it. The state is recorded in the Translation Block (TB). If the state changes (e.g. privilege level), a new TB will @@ -31,17 +32,95 @@ Direct block chaining --------------------- After each translated basic block is executed, QEMU uses the simulated -Program Counter (PC) and other cpu state information (such as the CS +Program Counter (PC) and other CPU state information (such as the CS segment base value) to find the next basic block. -In order to accelerate the most common cases where the new simulated PC -is known, QEMU can patch a basic block so that it jumps directly to the -next one. +In its simplest, less optimized form, this is done by exiting from the +current TB, going through the TB epilogue, and then back to the +main loop. That’s where QEMU looks for the next TB to execute, +translating it from the guest architecture if it isn’t already available +in memory. Then QEMU proceeds to execute this next TB, starting at the +prologue and then moving on to the translated instructions. -The most portable code uses an indirect jump. An indirect jump makes -it easier to make the jump target modification atomic. On some host -architectures (such as x86 or PowerPC), the ``JUMP`` opcode is -directly patched so that the block chaining has no overhead. +Exiting from the TB this way will cause the ``cpu_exec_interrupt()`` +callback to be re-evaluated before executing additional instructions. +It is mandatory to exit this way after any CPU state changes that may +unmask interrupts. + +In order to accelerate the cases where the TB for the new +simulated PC is already available, QEMU has mechanisms that allow +multiple TBs to be chained directly, without having to go back to the +main loop as described above. These mechanisms are: + +``lookup_and_goto_ptr`` +^^^^^^^^^^^^^^^^^^^^^^^ + +Calling ``tcg_gen_lookup_and_goto_ptr()`` will emit a call to +``helper_lookup_tb_ptr``. This helper will look for an existing TB that +matches the current CPU state. If the destination TB is available its +code address is returned, otherwise the address of the JIT epilogue is +returned. The call to the helper is always followed by the tcg ``goto_ptr`` +opcode, which branches to the returned address. In this way, we either +branch to the next TB or return to the main loop. + +``goto_tb + exit_tb`` +^^^^^^^^^^^^^^^^^^^^^ + +The translation code usually implements branching by performing the +following steps: + +1. Call ``tcg_gen_goto_tb()`` passing a jump slot index (either 0 or 1) + as a parameter. + +2. Emit TCG instructions to update the CPU state with any information + that has been assumed constant and is required by the main loop to + correctly locate and execute the next TB. For most guests, this is + just the PC of the branch destination, but others may store additional + data. The information updated in this step must be inferable from both + ``cpu_get_tb_cpu_state()`` and ``cpu_restore_state()``. + +3. Call ``tcg_gen_exit_tb()`` passing the address of the current TB and + the jump slot index again. + +Step 1, ``tcg_gen_goto_tb()``, will emit a ``goto_tb`` TCG +instruction that later on gets translated to a jump to an address +associated with the specified jump slot. Initially, this is the address +of step 2's instructions, which update the CPU state information. Step 3, +``tcg_gen_exit_tb()``, exits from the current TB returning a tagged +pointer composed of the last executed TB’s address and the jump slot +index. + +The first time this whole sequence is executed, step 1 simply jumps +to step 2. Then the CPU state information gets updated and we exit from +the current TB. As a result, the behavior is very similar to the less +optimized form described earlier in this section. + +Next, the main loop looks for the next TB to execute using the +current CPU state information (creating the TB if it wasn’t already +available) and, before starting to execute the new TB’s instructions, +patches the previously executed TB by associating one of its jump +slots (the one specified in the call to ``tcg_gen_exit_tb()``) with the +address of the new TB. + +The next time this previous TB is executed and we get to that same +``goto_tb`` step, it will already be patched (assuming the destination TB +is still in memory) and will jump directly to the first instruction of +the destination TB, without going back to the main loop. + +For the ``goto_tb + exit_tb`` mechanism to be used, the following +conditions need to be satisfied: + +* The change in CPU state must be constant, e.g., a direct branch and + not an indirect branch. + +* The direct branch cannot cross a page boundary. Memory mappings + may change, causing the code at the destination address to change. + +Note that, on step 3 (``tcg_gen_exit_tb()``), in addition to the +jump slot index, the address of the TB just executed is also returned. +This address corresponds to the TB that will be patched; it may be +different than the one that was directly executed from the main loop +if the latter had already been chained to other TBs. Self-modifying code and translated code invalidation ----------------------------------------------------