From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757558; cv=none; d=zohomail.com; s=zohoarc; b=hsK/Sq1P6Nn1gX6sdQh4nh7PJAupMH1PpNUlTzlp4V+m7MT7cXE6/mm5Grs9Yp2EsZpoqFkJ4mLzdMRxa/RobezmTgK/zMx93sH3ngyAviE3Pt8sVHUZ3DNrzdTNnojwNbs+IttqBy+Y8/C5397G+v+5JJJ8gzjoZfnmFbTLpTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757558; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wW16HYEEbHUJsSDEbNLyjiS39WK8C8tpisXcPK1gkso=; b=SXWahWVBeuHILWW8O4toSzMRZVvaWExhPZDuxoByjZ8ISCmBlfnhE8YcSjnBs836ACoKuPr9RCebrzaLwS+RYm5zQqIphKTaXBIwrMLjE2HwVFI4o1c4ZVtRv2+X4+yyD1avhYCjIsNKpRRvQGrgDebKAqgxQmSxAoZ2bgq/6OI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757558459361.18008820258365; Sun, 14 Mar 2021 14:32:38 -0700 (PDT) Received: from localhost ([::1]:39004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYLl-0002dg-0r for importer@patchew.org; Sun, 14 Mar 2021 17:32:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGo-0005oW-N8 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:30 -0400 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]:34586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGn-00087I-0G for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:30 -0400 Received: by mail-qk1-x733.google.com with SMTP id t4so29949619qkp.1 for ; Sun, 14 Mar 2021 14:27:28 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wW16HYEEbHUJsSDEbNLyjiS39WK8C8tpisXcPK1gkso=; b=C/grKP2vV0jCKKC/x583F3iE1k37W7Q9gFZWzG1YAlLpnu4ndiyJ2NgRsvQ9hH4MUl mmuWjIzi9ngUeKCs6IswPMD+v92VlteN227WYgHkCpYKYw4XO0NQ8PEMLSq7EfajxTnE 1IeLWiP2RopbV1Hpu330g44wDuRWaP4toosKmeoNV5jXUkjIJv1qDT4nncU+5LjI+wgx 6wl+wTpubHS1e7MmqKZr2oZrGglK0F7KE8CAgNLFMLSdDIcghSErFJA94BME3KhKpkzT YgVee3pPWQES9tBUjY6leO4ior3G5xwkr4WKIELD9pWm1wvhfyVtlGjnpZPLiWAp6EvC /G3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wW16HYEEbHUJsSDEbNLyjiS39WK8C8tpisXcPK1gkso=; b=dt34InA/O0gcHuLtPEV66Namm4E2zXD2m7edm5WL5h29L59A68Iramwahmy4ZbGph0 f/io8prlPLZI87xjFpqKVKiW5T674LqLjRF72si7LbPp/Wpe5COgmeFX3kXJrKJgq09w Kc7HfI9IAc38aZkCR/uO73UFvJlFLODPtiPU+C1jvZer4DMfYYflhghX8AyXEd3w4crI AT6aOB3EUsC99zB++7DFX30Os/LCU3c3qLR6Lo+a3aztU10qAK4xltrA/dinGsTcN2xD IEG/dANycs34/IswltXq7ZEoK2s9I3C+GKg5JDZmzyWb4yS8CQblOOIqyRyI74D5FF4A Fc7g== X-Gm-Message-State: AOAM531stgBTcIGo0iau4Tmv9yhIPHGbzqgs/KQ9vj6NXHQyNh/SNY9t QILlhea0bXTdNWuD7/G3Qi5vWD3FuMgfqaUH X-Google-Smtp-Source: ABdhPJxammNS/CgjrG52rHRKw5xt0t71iqRxS9iAH8e6C7G5Mf3Toesz6anFOT2ZQCy0Gd3UslHf2g== X-Received: by 2002:a37:a913:: with SMTP id s19mr22749659qke.158.1615757248110; Sun, 14 Mar 2021 14:27:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 01/29] meson: Split out tcg/meson.build Date: Sun, 14 Mar 2021 15:26:56 -0600 Message-Id: <20210314212724.1917075-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::733; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x733.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- meson.build | 9 ++------- tcg/meson.build | 13 +++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 tcg/meson.build diff --git a/meson.build b/meson.build index a7d2dd429d..742f45c8d8 100644 --- a/meson.build +++ b/meson.build @@ -1936,14 +1936,8 @@ specific_ss.add(files('cpu.c', 'disas.c', 'gdbstub.c= '), capstone) specific_ss.add(files('exec-vary.c')) specific_ss.add(when: 'CONFIG_TCG', if_true: files( 'fpu/softfloat.c', - 'tcg/optimize.c', - 'tcg/tcg-common.c', - 'tcg/tcg-op-gvec.c', - 'tcg/tcg-op-vec.c', - 'tcg/tcg-op.c', - 'tcg/tcg.c', )) -specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('disas/tci.= c', 'tcg/tci.c')) +specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('disas/tci.= c')) =20 subdir('backends') subdir('disas') @@ -1953,6 +1947,7 @@ subdir('net') subdir('replay') subdir('semihosting') subdir('hw') +subdir('tcg') subdir('accel') subdir('plugins') subdir('bsd-user') diff --git a/tcg/meson.build b/tcg/meson.build new file mode 100644 index 0000000000..84064a341e --- /dev/null +++ b/tcg/meson.build @@ -0,0 +1,13 @@ +tcg_ss =3D 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) --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757697; cv=none; d=zohomail.com; s=zohoarc; b=MlccOh0xCMn1CxTwfIGeziOo+Zgq1luAeMTNy1YEeDwUZUA9DEvM6uDm6QpAHlJ8ohn7ZUR3rdZBAlJCwSNAPrpFgqzzE9Aho+OWDlCqe6qRF3g70GbRjn7gkfflZCQW0bQ3xzXXgCOPvZ1ipg904257tW7mgh1gGz/xbgTch+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757697; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=G1cuceYNpYXAOK1j2QgIU1zwSZCr6xgnUVgDKM+l7ys=; b=ar56F+bnS6dQrDV4Bk2jtbo+amz7kSXxhIrsA/1OgdBKR6PWBCbbPCgw0FfYuKpDttRFETGaM8cHXzW6LfMUqhpmljBrjQn2EHdjlC46dQ3CjVCNyoasLzBtLPIKKbA5tsAKHz4kUVXH94DkWYKHMy6A4NCJO5a2hnArp6M6Pns= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757697278772.5455337715324; Sun, 14 Mar 2021 14:34:57 -0700 (PDT) Received: from localhost ([::1]:47374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYNz-00067B-0W for importer@patchew.org; Sun, 14 Mar 2021 17:34:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGp-0005pZ-To for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:31 -0400 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]:39179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGo-000880-DC for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:31 -0400 Received: by mail-qk1-x731.google.com with SMTP id g185so29901207qkf.6 for ; Sun, 14 Mar 2021 14:27:29 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G1cuceYNpYXAOK1j2QgIU1zwSZCr6xgnUVgDKM+l7ys=; b=BxmStJdcfxjEqRQEw3k9KNk7H2E4/bQw8U2CX4w+ESt28UmVFMca4Q4qtwV/RRHx4v JGuJ7u9zB0++Uq3yYHVECsSzhR2LyHLkTtx+s1bwY+IXlAP3gYCxl7yl5WoeESFgjyMA fxt9XVh+9zWpF+sMZzrpuAuNtlEGcCs0MZtO2PNyG1OatA1gYox3aiDj8qiy+Q5BT+ta fcpcNGo1emHe3ooedjqvLB1qkuHXfozIrpnVKiDjZAsGsyKIaMR1WKxtpBPZaYLzaVhN 6Ox83lhf2OIg4pdoHfwWgNdL7nZO2B7mtbx/ANYobKkHrQbNa4Iv4w/l5FYt0zF6hnIe Z1sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G1cuceYNpYXAOK1j2QgIU1zwSZCr6xgnUVgDKM+l7ys=; b=ReHs7T7iilfZaXswxjTIDBxhi4GUeLlpqy960UsU5kszJnJojl72PE7TzFeeGsSkBk a+S/0culbG/oxCY+VxgwcLXZ1fRA+Slq2Bby/ShKlcwVdKQHsWpsfrI1he2bimMJEmSA iLJvIacTCVUaaV3Qbw4ckgiu3vZY0j5bZImjpb1kzgDw2iIqPTEFn9gYLReaNlehmtSu ccmdGESetjH8fMAtUvo4oyAQ8x1MreEUM/nWJT7aqM6/Hn5q9KXo7fB2KHQJBCuo72jU gyCWhgkc4pO/OetCTu8VyKcw0RiXfkHxgkKBbpAdx2X9FOcjzt5Q0MOZVcqhNpCaTZc1 g0xw== X-Gm-Message-State: AOAM532fVNa1EImrliMyY4F6ct5z1ZYQJsN68ZWt5fiIXx5oI5hQtprq lIv6Y8fljXeJwimMoy8+nuhTCEwFys6S6ae8 X-Google-Smtp-Source: ABdhPJzVxbBzScfY5gv5cH+9lmkygYrJgKH0bWvzcymlbjujYlsLNbuHc9ZnUgZ9fwc+jR/lCwiilQ== X-Received: by 2002:a37:a404:: with SMTP id n4mr22137321qke.439.1615757249427; Sun, 14 Mar 2021 14:27:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 02/29] meson: Split out fpu/meson.build Date: Sun, 14 Mar 2021 15:26:57 -0600 Message-Id: <20210314212724.1917075-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::731; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x731.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Reviewed-by: Philippe Mathieu-Daud=C3=A9 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 diff --git a/meson.build b/meson.build index 742f45c8d8..bfa24b836e 100644 --- a/meson.build +++ b/meson.build @@ -1934,9 +1934,6 @@ subdir('softmmu') common_ss.add(capstone) specific_ss.add(files('cpu.c', 'disas.c', 'gdbstub.c'), capstone) specific_ss.add(files('exec-vary.c')) -specific_ss.add(when: 'CONFIG_TCG', if_true: files( - 'fpu/softfloat.c', -)) specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('disas/tci.= c')) =20 subdir('backends') @@ -1948,6 +1945,7 @@ subdir('replay') subdir('semihosting') subdir('hw') subdir('tcg') +subdir('fpu') subdir('accel') subdir('plugins') subdir('bsd-user') diff --git a/fpu/meson.build b/fpu/meson.build new file mode 100644 index 0000000000..1a9992ded5 --- /dev/null +++ b/fpu/meson.build @@ -0,0 +1 @@ +specific_ss.add(when: 'CONFIG_TCG', if_true: files('softfloat.c')) --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757355; cv=none; d=zohomail.com; s=zohoarc; b=a08p0+iaeS/pgaaVpk85Wg27sXkpo0aTa7F5TmwFpmv90mg9t2qlbj1DjoRCZ1D4TTGXN9nw8RGGx96P+0owVZBPIH+hw+98pFiFdIRL/tCXnwNEMz4JCIrmZ3chcf29YAoKepZyT+fAnn/e83c2oKUxpSeGCgmcE8s6t+a90Pk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757355; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Zo0Axh7LGw4WyjdfTcLkZAEZsIuFs0M9C89s4USb0+Y=; b=E8PCsgAZI0qRGLjkZ0Z0udX7MAjjRO5Z+iHTsJvNedULLEzpN2o8fOmnAAsk8BCbXKzKVDWo/iCFB2PzUxc8Ot5W5jqNwMSJ2QqqTrxqnLoJx8KlHrqiS0QOekmIDozi/6Deic2DNl6kbbu7z4cVjlfUGQqq3XVkFlBqJ42zqFo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757355330935.7943952801103; Sun, 14 Mar 2021 14:29:15 -0700 (PDT) Received: from localhost ([::1]:59220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYIU-0007eu-6H for importer@patchew.org; Sun, 14 Mar 2021 17:29:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGr-0005rJ-Ha for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:33 -0400 Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]:33549) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGp-00088n-Ma for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:33 -0400 Received: by mail-qv1-xf2f.google.com with SMTP id o19so912010qvu.0 for ; Sun, 14 Mar 2021 14:27:31 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zo0Axh7LGw4WyjdfTcLkZAEZsIuFs0M9C89s4USb0+Y=; b=J4bpnwoOfkGpQRujYf8iLjvJiFiu4UYjzuUuMke84vAvSVt2cWST5J/Sgms13yWBFf qD1J/97G4rCqQ4dCnL0xgjQSMjC51JlNYiwSH/Koz0YdsBPgv1b+qsfhAj+YGtOG8rOt 8haoJvwGCpqEQtuFMM/aPWBYlNAJ3OPDyZj3HjtuP88f/GzCNVmzrgM/hJEf3t7b+1sB NHwV7TKPViPcqKXmhg8ZrbnwobNLTZ5XvaqOO78N/QqWGpg5tnh2ikHtK42aJFn0Zhtw 2u0/gOHNdbNoGYzWnJYiTt2fWiKm7yqtRU7U3WNfJtDM8NTX/NQ+j0BFN2tqMnd7n9EL U9+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Zo0Axh7LGw4WyjdfTcLkZAEZsIuFs0M9C89s4USb0+Y=; b=L1YfYpE6FygjE/Y7B9N9EByiuuX4ZgJbPLfdBMb/tiCaNiDDyQSpGciWtE34PUw8uB bdzxvp5bCaQ4veCjdum4YkS+8U4OmAnP7lSGfih4GKegSgZ195OzniEqHIndIiH5EiND kT53sCWckZJr+Cy6zbfCKUzR/BstZNHudRhPF4ojEyvr9PJSgwhbIh0G5oPhY6/wkDrX w9mzUivPHkM5IVvSlH/d/PkeQrWx+H7MCMfKLIXyCWnb3H+6GeGCAgV616Jmh2wGRqAF g+WoXYUV75Y2fGOHbk7ew94V7FS1c6Ok04V89x0oP0Im3/AlHAYdcLQ/8MLhYNEeHzc5 oFHw== X-Gm-Message-State: AOAM531fxzYmpMZhLqZLI/BsXbb6MGi0cBOM0xDwt5ZziZyzI8TA4Ukk lrTzsQbmfLIY/3iZxwDCfct0K5zBTkq8mzqr X-Google-Smtp-Source: ABdhPJzls4RSh/Hekj9uKHkMPlPbkwcBO72k8B8JeR/OFeqR674+DUTqQVHn6H4qUBf9gH2SVj6OGg== X-Received: by 2002:a0c:e84d:: with SMTP id l13mr7839422qvo.28.1615757250676; Sun, 14 Mar 2021 14:27:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 03/29] tcg: Re-order tcg_region_init vs tcg_prologue_init Date: Sun, 14 Mar 2021 15:26:58 -0600 Message-Id: <20210314212724.1917075-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::f2f; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of delaying tcg_region_init until after tcg_prologue_init is complete, do tcg_region_init first and let tcg_prologue_init shrink the first region by the size of the generated prologue. Signed-off-by: Richard Henderson --- accel/tcg/tcg-all.c | 11 --------- accel/tcg/translate-all.c | 3 +++ bsd-user/main.c | 1 - linux-user/main.c | 1 - tcg/tcg.c | 52 ++++++++++++++------------------------- 5 files changed, 22 insertions(+), 46 deletions(-) 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) =20 tcg_exec_init(s->tb_size * 1024 * 1024, s->splitwx_enabled); mttcg_enabled =3D 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; } =20 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index f32df8b240..b9057567f4 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1339,6 +1339,9 @@ void tcg_exec_init(unsigned long tb_size, int splitwx) splitwx, &error_fatal); assert(ok); =20 + /* TODO: allocating regions is hand-in-glove with code_gen_buffer. */ + tcg_region_init(); + #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and initialize the prologue now. */ diff --git a/bsd-user/main.c b/bsd-user/main.c index 798aba512c..3669d2b89e 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -994,7 +994,6 @@ int main(int argc, char **argv) generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ tcg_prologue_init(tcg_ctx); - tcg_region_init(); =20 /* build Task State */ memset(ts, 0, sizeof(TaskState)); diff --git a/linux-user/main.c b/linux-user/main.c index 4f4746dce8..1bc48ca954 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -850,7 +850,6 @@ int main(int argc, char **argv, char **envp) generating the prologue until now so that the prologue can take the real value of GUEST_BASE into account. */ tcg_prologue_init(tcg_ctx); - tcg_region_init(); =20 target_cpu_copy_regs(env, regs); =20 diff --git a/tcg/tcg.c b/tcg/tcg.c index 2991112829..0a2e5710de 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1204,32 +1204,18 @@ TranslationBlock *tcg_tb_alloc(TCGContext *s) =20 void tcg_prologue_init(TCGContext *s) { - size_t prologue_size, total_size; - void *buf0, *buf1; + size_t prologue_size; =20 /* Put the prologue at the beginning of code_gen_buffer. */ - buf0 =3D s->code_gen_buffer; - total_size =3D s->code_gen_buffer_size; - s->code_ptr =3D buf0; - s->code_buf =3D buf0; + tcg_region_assign(s, 0); + s->code_ptr =3D s->code_gen_ptr; + s->code_buf =3D s->code_gen_ptr; s->data_gen_ptr =3D NULL; =20 - /* - * The region trees are not yet configured, but tcg_splitwx_to_rx - * needs the bounds for an assert. - */ - region.start =3D buf0; - region.end =3D buf0 + total_size; - #ifndef CONFIG_TCG_INTERPRETER - tcg_qemu_tb_exec =3D (tcg_prologue_fn *)tcg_splitwx_to_rx(buf0); + tcg_qemu_tb_exec =3D (tcg_prologue_fn *)tcg_splitwx_to_rx(s->code_ptr); #endif =20 - /* 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 =3D s->code_gen_buffer + (total_size - TCG_HIGHW= ATER); - #ifdef TCG_TARGET_NEED_POOL_LABELS s->pool_labels =3D NULL; #endif @@ -1246,32 +1232,32 @@ void tcg_prologue_init(TCGContext *s) } #endif =20 - buf1 =3D s->code_ptr; + prologue_size =3D tcg_current_code_size(s); + #ifndef CONFIG_TCG_INTERPRETER - flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(buf0), (uintptr_t)buf= 0, - 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 =20 - /* Deduct the prologue from the buffer. */ - prologue_size =3D tcg_current_code_size(s); - s->code_gen_ptr =3D buf1; - s->code_gen_buffer =3D buf1; - s->code_buf =3D buf1; - total_size -=3D prologue_size; - s->code_gen_buffer_size =3D total_size; + /* Deduct the prologue from the first region. */ + region.start =3D s->code_ptr; =20 - 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); =20 #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) { FILE *logfile =3D qemu_log_lock(); qemu_log("PROLOGUE: [size=3D%zu]\n", prologue_size); if (s->data_gen_ptr) { - size_t code_size =3D s->data_gen_ptr - buf0; + size_t code_size =3D s->data_gen_ptr - s->code_gen_ptr; size_t data_size =3D prologue_size - code_size; size_t i; =20 - log_disas(buf0, code_size); + log_disas(s->code_gen_ptr, code_size); =20 for (i =3D 0; i < data_size; i +=3D sizeof(tcg_target_ulong)) { if (sizeof(tcg_target_ulong) =3D=3D 8) { @@ -1285,7 +1271,7 @@ void tcg_prologue_init(TCGContext *s) } } } else { - log_disas(buf0, prologue_size); + log_disas(s->code_gen_ptr, prologue_size); } qemu_log("\n"); qemu_log_flush(); --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757354; cv=none; d=zohomail.com; s=zohoarc; b=ZvkCtyxVO6d9ZH/wS5sxGgUeyH7ZZNDoCwXpubnaL+RcE6EiMeNjE2IM0LGH5+XcZS+QLQbCFFG5P4huCo7NPcO6tSziT3Wqt/H0UdVmySfor3l4AcHOsN0E85K4TpSDMTe0wEjgAhdGcXoVoa628bAZOdaX2i+0ceT/1sGdB/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757354; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hTuU1v864u8UFjIE8dcOrpu8BoE0XeHo4HzeUlZug3Q=; b=gdYJ282/xNmh8y5bXsqqllYBisruUdZ5GxH8M4Pez72iExEvQ0etnQzMIbzC0i1X24llNALeBxwK5F4GVUvJA7lem/T69cKiyKhc/vnlQxPLzTBMhRiIs2RIJdMDU4UUJmcci/e69iVfuGHo8p2PDexHYS4dBIGdG6TiEvYG91A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757354558580.4735490985726; Sun, 14 Mar 2021 14:29:14 -0700 (PDT) Received: from localhost ([::1]:59196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYIT-0007eN-G8 for importer@patchew.org; Sun, 14 Mar 2021 17:29:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGs-0005sI-6O for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:34 -0400 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]:40480) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGq-00088z-Ix for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:33 -0400 Received: by mail-qt1-x82d.google.com with SMTP id r14so7863616qtt.7 for ; Sun, 14 Mar 2021 14:27:32 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hTuU1v864u8UFjIE8dcOrpu8BoE0XeHo4HzeUlZug3Q=; b=j8S6fBW52hFslSi+aKblVA4cUx8PAONrlweOV/xGSgE696Zx0FVk9nY0l2WpX6hEHd vZSSxv16nIFOKeGte26jrfpf8yCygO/PwUMj/lsaL25oMfu4f9q838nXFyvDZ9oC9SIK XEtUaBZ3GoO6JdK1us91MTHayMEauK2qBYze7XL1EcDVCjMLS7DA01kfq4FbFiD3qcnh Lm/Hjf4qJ7OTdtK1q4Q461Kpbu2XSj1Gs0GXdajiFpkn1KHVohXfl4bhGdbUUqs7JeNS 4fBvwiv6LUcv34o4q8fXrUFCKiVwWzLF3LzFutsRIOX/q+qoIViVT+qkMPm1Md696X42 fx9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hTuU1v864u8UFjIE8dcOrpu8BoE0XeHo4HzeUlZug3Q=; b=bH5Z7lc180R23UHG7v/+AErCpg0CLzlYfbm1OrX+62h4l2UdaVC826Iz40+ANc9Z0P Zamx/yo0IQlj3MIWbQmx9IxfvyPVidhuuIjZWQ/ThfDnMGWZrsZ9lx6mMPbUsbGuGwix YZ0NZKJDB58vro4e6R/eXbqWO//UqXa2zwkMxUwZziey4osEEvdSAKdlRVN7uBtINnwU bl3ndwMWb5Zt7REqLMJhQKpXzq+5wsrJ/zgXV5jaHkoXgYs9jofp85Mc0lIHGWlKzPdN 2LBysT+0japZb1MHg5IepqnK6c51gZ4JEZh03mTDctlAv67F8CezwsmxDvshlggBwce8 MNKg== X-Gm-Message-State: AOAM533Am7rNmfoj8n/iOFOK2iTIoCdPBcc0nY3fymoV95h72GHs0s3R Co3tJpa3wazudBTSacp+g+PD+ii6i0bqPJT+ X-Google-Smtp-Source: ABdhPJwtJ8MPaoFjW+cYyMSUn99NPj9sQzloczeswL7qBsrIpR9F5PuSkPdE1GQ4bMl/EcH8n1tbMQ== X-Received: by 2002:ac8:53c2:: with SMTP id c2mr19393307qtq.166.1615757251674; Sun, 14 Mar 2021 14:27:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 04/29] tcg: Remove error return from tcg_region_initial_alloc__locked Date: Sun, 14 Mar 2021 15:26:59 -0600 Message-Id: <20210314212724.1917075-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::82d; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x82d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) All callers immediately assert on error, so move the assert into the function itself. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- tcg/tcg.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 0a2e5710de..2b631fccdf 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -720,9 +720,10 @@ static bool tcg_region_alloc(TCGContext *s) * Perform a context's first region allocation. * This function does _not_ increment region.agg_size_full. */ -static inline bool tcg_region_initial_alloc__locked(TCGContext *s) +static void tcg_region_initial_alloc__locked(TCGContext *s) { - return tcg_region_alloc__locked(s); + bool err =3D tcg_region_alloc__locked(s); + g_assert(!err); } =20 /* Call from a safe-work context */ @@ -737,9 +738,7 @@ void tcg_region_reset_all(void) =20 for (i =3D 0; i < n_ctxs; i++) { TCGContext *s =3D qatomic_read(&tcg_ctxs[i]); - bool err =3D tcg_region_initial_alloc__locked(s); - - g_assert(!err); + tcg_region_initial_alloc__locked(s); } qemu_mutex_unlock(®ion.lock); =20 @@ -874,11 +873,7 @@ void tcg_region_init(void) =20 /* In user-mode we support only one ctx, so do the initial allocation = now */ #ifdef CONFIG_USER_ONLY - { - bool err =3D tcg_region_initial_alloc__locked(tcg_ctx); - - g_assert(!err); - } + tcg_region_initial_alloc__locked(tcg_ctx); #endif } =20 @@ -940,7 +935,6 @@ void tcg_register_thread(void) MachineState *ms =3D MACHINE(qdev_get_machine()); TCGContext *s =3D g_malloc(sizeof(*s)); unsigned int i, n; - bool err; =20 *s =3D tcg_init_ctx; =20 @@ -964,8 +958,7 @@ void tcg_register_thread(void) =20 tcg_ctx =3D s; qemu_mutex_lock(®ion.lock); - err =3D 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 */ --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757905; cv=none; d=zohomail.com; s=zohoarc; b=amN0yJ4lwo9hkRijPGXyMcGo0nLdl1lNribHgBJIUTQoPfKNGqLpouNl7OLFddQ/wBM9cij8BV5dQck0R9oc3yhW7F8cak2Lxq9SNUbXTG6XG187KL0srNBqr7SfV6HJQt1WqFJTFdSUbvzG875r272gb/3mrxiBHbxQHINCCvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757905; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=36uzHkl7+IX2hopk8rVzdZIi+gPh2gDVUz4jl8wQF7M=; b=FlnYgW/szmU+ksoEB0CHCGCRxRQCPDSJEVN0xeAaUxzobGsQEB+EfujQkJOOQrHAcn8g+KcEAtVgZS+xY5vFon6kdRE/NXxdjZeZGiVTAaEMBvfliA1CkRMOHcbVCPeD0yQfY2i1ifKbjZo08r6s2L5nvZpf4jqEn88HyKMqkoo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757905606144.57318080953473; Sun, 14 Mar 2021 14:38:25 -0700 (PDT) Received: from localhost ([::1]:58842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYRM-0002VG-Gq for importer@patchew.org; Sun, 14 Mar 2021 17:38:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGt-0005tP-0p for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:35 -0400 Received: from mail-qv1-xf2a.google.com ([2607:f8b0:4864:20::f2a]:45926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGr-00089e-H2 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:34 -0400 Received: by mail-qv1-xf2a.google.com with SMTP id t16so6881752qvr.12 for ; Sun, 14 Mar 2021 14:27:33 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=36uzHkl7+IX2hopk8rVzdZIi+gPh2gDVUz4jl8wQF7M=; b=NblCIYGL4F97OVV0KPQiR7R0WSN8wmrKTT0kI4G2r0H/NcZfZbHmh2qTndV5Q4NWz8 mpSbs59ur1pptviRTTGyMeXHBBfAs6gudiZIxFlMU3M56n08SyjC30u1Yg8ay9MUPIv2 HCtXh/N6wRTspVJ895sMGecY6gAFWooCtrEhj8kfbC8jFx4yzI/LWuki/a87Z5UcF8XQ X8FhIXNqVyzq1lSAAGTRidEFA2KTI1xa7nVp6o6Tg9j5tr9YjNY8z2Qb4ejUoZG+oBiA cRwwak/PWo7LpAvZOPNtW4cQNrIzByKHJtFhcbyHer9QGQ4Mr5RX7jwaf+GH3gC1PBlw hCjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=36uzHkl7+IX2hopk8rVzdZIi+gPh2gDVUz4jl8wQF7M=; b=tgjaco2dkRdIyCul/t9L2bv/kY00jRRhzzVQXs+JVbGNd1igVvlPKBfp2rUjJDnQay jYqFWpFgtXydlKk+90NOgiMC6ZwxS5jkb876W3XCb4wtDIo1soXYFxagCigtIeE4VR3e roBZY2akk0CkagVtrX7HG6gKhqUpOrgTwoe7euVB1eIht+4kXCPFlxb5wtlsgWHQ1Zaa yvPE3lOHVWDQe/nGzNkz/NYbBq+8wr8gokSKhxGQDV3BJfkc3ZI1eoVzgJl9jZueXEWf dl7ozFMdYjvgPY7fHZZwg/o1tyfoOi0vgM2Q+CQaSaPpjPNQjA3XF7TDowzCBwxGXy6z y47Q== X-Gm-Message-State: AOAM531zGX3KL+l15vNBGJUD79Gigh0OYnZRXKXTptLTtdvg7WG0/J1E IU2Ahe1AGq3SrB9rMT1VdA8lEW4L5wNnA1jR X-Google-Smtp-Source: ABdhPJzTHPxy5upymFNolcpvQefbrmqy58YpOGQrX6C8P8qGs8MHME8uGZVw7Ry3OWkCd7rath/VZQ== X-Received: by 2002:ad4:5d47:: with SMTP id jk7mr1718768qvb.38.1615757252684; Sun, 14 Mar 2021 14:27:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 05/29] tcg: Split out tcg_region_initial_alloc Date: Sun, 14 Mar 2021 15:27:00 -0600 Message-Id: <20210314212724.1917075-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::f2a; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This has only one user, and currently needs an ifdef, but will make more sense after some code motion. Signed-off-by: Richard Henderson --- tcg/tcg.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 2b631fccdf..3316a22bde 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -726,6 +726,15 @@ static void tcg_region_initial_alloc__locked(TCGContex= t *s) g_assert(!err); } =20 +#ifndef CONFIG_USER_ONLY +static void tcg_region_initial_alloc(TCGContext *s) +{ + qemu_mutex_lock(®ion.lock); + tcg_region_initial_alloc__locked(s); + qemu_mutex_unlock(®ion.lock); +} +#endif + /* Call from a safe-work context */ void tcg_region_reset_all(void) { @@ -957,9 +966,7 @@ void tcg_register_thread(void) } =20 tcg_ctx =3D 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 */ =20 --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757357; cv=none; d=zohomail.com; s=zohoarc; b=Do5OIHcJDtr6zYZ6AX/t2oz9AuL552gQmJbtvO6gWRcjqaeA0q7m14DpNUpquMrQ+UxV1szDWHmCwdF25XovQsw50SFlLZexeQ+PNb1PImGS6x9yyhOJws9xW1tBUhxtg9t9lVMXnHp7dsSvhgemgnDta9LqaLNvhPeyN5JxnvQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757357; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EQ+ywpBmHDVC3DOo5FVJf1bXQ/r+fWvVCtSN9ZnyiEg=; b=MbJfWNDPGynNZRnzYJ30beS7zyJnS4wSkMbil1s5icOKmR3KgPdwBndtjTwAHamgN1Cz3tP8pLfRWQVeOYqLI+gXn5Im7XrWWajb/Va5K+yFaeZ5A1S9nYH9GAapfHqGifMoeOyFY+Ryw+HsNd4fsFbM3Tj01ytn720ebJAA8Mk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757357894577.1237825233293; Sun, 14 Mar 2021 14:29:17 -0700 (PDT) Received: from localhost ([::1]:59510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYIW-0007lp-LV for importer@patchew.org; Sun, 14 Mar 2021 17:29:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGu-0005vb-7t for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:36 -0400 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]:43552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGs-0008AR-HZ for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:35 -0400 Received: by mail-qt1-x830.google.com with SMTP id s2so7857237qtx.10 for ; Sun, 14 Mar 2021 14:27:34 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EQ+ywpBmHDVC3DOo5FVJf1bXQ/r+fWvVCtSN9ZnyiEg=; b=Ragnizp7a27wR/YaHG4/PdoiQ+mi5w+4HE5ob8l33RZkSiGr37ViIpaHQ5NvzIjSG6 F6PrCuPp+hKKHUVUPKat79k+C64MaPg+OozY9YnJZDBHvY/+QU+Ls2yxvYpzP3eDOvgM FpMO99rE7RpaB2Ph3DeMb0jd/bErcGwXttS0itB77/fwberQ2ed/7l2zPMzctXFsgepS M8ezJNDK5c0idmWBTSE5G5Mu4FutQQZ7MnSmezjiRReELdBEuCPOfFDjFv4K2lSXhLO3 KSfFVkV2R12xCej516/VvJZ2QMQp0wa9+aYnuj3e9QLXm9KXHHM4HgZoEtBt3sZLAjli 43TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EQ+ywpBmHDVC3DOo5FVJf1bXQ/r+fWvVCtSN9ZnyiEg=; b=kFkDDzZetF9ftyzulHfBjucOaN4dlU8PzzS+lKs2Q0ZK1j7xvM4PhdjC9T5vW8L1qV a3UEv9Sc+nqqR/hOU+HHhErlPAP2IudpgBZHA9v/Lqdw6EBfhcIjJqzKy+jslDpD3ZwA XUYSqYRBgGiaYkZyVzdrBXd+fKV20HUpK8/bt+0gfT9F1dK+s7+QRw99+yDJFQV8UNan HHquJGJE2wjq90rynROWAxPlNBL0BVn1NECoCaz+3ImboyFM0aCgtM2uPdevnqW4gG0u jV5VG0uEg6JklJhILfuCAt21+dbNjxVhacjwSxdGfJYKb1APUBon26hzQf2uhoyvRrLY EvaA== X-Gm-Message-State: AOAM530eOKnl7zGKX8UEHhI2/BSMCLheTpjtQOgNExIbiA9ty5v60C1L 6I/Vuf6gIsMeMp4wH/EVg1Fer4DNE/jMgb/f X-Google-Smtp-Source: ABdhPJxCEcMMK2wDFqBYVd6SshfSnopv5/cHp7DD3EIJne0dAsXfTqI3eKq7XDp/6nGEov0H4vdiIw== X-Received: by 2002:ac8:6892:: with SMTP id m18mr20232105qtq.5.1615757253660; Sun, 14 Mar 2021 14:27:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 06/29] tcg: Split out tcg_region_prologue_set Date: Sun, 14 Mar 2021 15:27:01 -0600 Message-Id: <20210314212724.1917075-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::830; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x830.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This has only one user, but will make more sense after some code motion. Always leave the tcg_init_ctx initialized to the first region, in preparation for tcg_prologue_init(). This also requires that we don't re-allocate the region for the first cpu, lest we hit the assertion for total number of regions allocated . Signed-off-by: Richard Henderson --- tcg/tcg.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 3316a22bde..5b3525d52a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -880,10 +880,26 @@ void tcg_region_init(void) =20 tcg_region_trees_init(); =20 - /* 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 =3D=3D s->code_gen_buffer); + region.start =3D 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); } =20 #ifdef CONFIG_DEBUG_TCG @@ -963,10 +979,10 @@ void tcg_register_thread(void) =20 if (n > 0) { alloc_tcg_plugin_context(s); + tcg_region_initial_alloc(s); } =20 tcg_ctx =3D s; - tcg_region_initial_alloc(s); } #endif /* !CONFIG_USER_ONLY */ =20 @@ -1206,8 +1222,6 @@ void tcg_prologue_init(TCGContext *s) { size_t prologue_size; =20 - /* Put the prologue at the beginning of code_gen_buffer. */ - tcg_region_assign(s, 0); s->code_ptr =3D s->code_gen_ptr; s->code_buf =3D s->code_gen_ptr; s->data_gen_ptr =3D NULL; @@ -1239,14 +1253,7 @@ void tcg_prologue_init(TCGContext *s) (uintptr_t)s->code_buf, prologue_size); #endif =20 - /* Deduct the prologue from the first region. */ - region.start =3D 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); =20 #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) { --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758145; cv=none; d=zohomail.com; s=zohoarc; b=kf+56s+O2xT+ao1xpqcGPAiqsoOdNB4evtq6yFXq0wSCP8byCFgqMhwB9/FvCnGyOwPUsxj1lBqnqDCGFuVdVh48IsPw7cN9vZgkioyi0rB0FXVZbud/ZvmS64Zeof2U/h6J43d89mCZQtdVDGnnMsMDI8dqn+Niz+IxhrB3tno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758145; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wyDvDQt0ocC4tKD3Beu6kf+j2hjEL+nr+C+2bx47vy0=; b=SGCHNDJA5QwsIwhlqKjfFUXql8lyRH+c7YagCb1s/kYqPvvfV9QERn1c+P2MrydVypMymzYF7Fr5WjPo9oAsw6R0CH25PhzGANekLpnHX0OixALTN3NGEmknrLhyJXKQ6PKyg/xSfWH6ZlHijQFWIpLKzEBJaPHc9Uvmly9mhDA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615758145836921.099958523558; Sun, 14 Mar 2021 14:42:25 -0700 (PDT) Received: from localhost ([::1]:38662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYVE-0005xt-Kh for importer@patchew.org; Sun, 14 Mar 2021 17:42:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGy-00063w-3A for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:40 -0400 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]:34418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGu-0008Ao-3T for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:39 -0400 Received: by mail-qv1-xf34.google.com with SMTP id g8so6880004qvx.1 for ; Sun, 14 Mar 2021 14:27:35 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wyDvDQt0ocC4tKD3Beu6kf+j2hjEL+nr+C+2bx47vy0=; b=nPyG4+kNE8U5EvQrj1kTbjzGpfbp/6yQjAiS2mwLI6sxwiTeV+bTSQVep0pF9myC+r XtUP380zjpCvpsOBk96e2fxXVkpoGBuovKZbF0M/sSmlYUh3eoOUn/y+kcOUhDKnFGyl YbvqLAdm8ZOZ9P3Lh+4ATL6TVnjNxqezpTCY5qudYBSqhRdapG4ox4ekEFR3VM3vnrAt cIm/H5oFdiSx4NRC7XXH67xbqTjgWVD+cirxyKiAZM/WrixTjZ4cmw4+i+dXCHgvfuI8 13/wbcDlTJAyHGeVtBiN5bhOpODoOX3cFHR5MSMy2vcN75oMq7CZ4gB4PdvXaRYxngx5 iMEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wyDvDQt0ocC4tKD3Beu6kf+j2hjEL+nr+C+2bx47vy0=; b=LLE0May4Di54Zjd+FYjuW/CW6RUVivs0yCVsdQ4w2mqYWvsN3snWCilQRvcgZidfQu l0K+j/VDxSC3M8BvNjAXoU1yyAov2x9k68Zeoa2qMWh2m2dcKzJfIQrQ6T8XtHHc0ZC5 JEy8Hb00AIqnUmJAa7XOgdhTvNWjF/VQXOtyCWCgSYsZQPjdkd3DOxVyMS0z8JCMPJoc Wk63AuJcaV+5qIklbkQje1c+lq9wwPYlB4qa+J7/qCRNxGYQQC61+NlxQou92U2OKewi stv8Lj8qKdpn9q8Y2vzQ2ZB4qw2G+uI+SVdzBTBp5ZpnZHYoN01/k9wrilfHXBy3SGNH 1wxw== X-Gm-Message-State: AOAM530MqnVMMweJx1Tf/cFCBngrRoRmBLpFgctP8CfAlcchh+woe001 P+PigwWTgA8w6XE8MiswdUdQtHU1ktKr00PQ X-Google-Smtp-Source: ABdhPJxp6/JABpkBfnkxZFqLWx4kyQPs9gLsMvtcHs3Z0dKrHnNRM4JZQUn4sIDnnzeiRXEWmqUhPg== X-Received: by 2002:ad4:5aa3:: with SMTP id u3mr8145111qvg.0.1615757254843; Sun, 14 Mar 2021 14:27:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 07/29] tcg: Split out region.c Date: Sun, 14 Mar 2021 15:27:02 -0600 Message-Id: <20210314212724.1917075-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::f34; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf34.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- tcg/internal.h | 37 ++++ tcg/region.c | 570 ++++++++++++++++++++++++++++++++++++++++++++++++ tcg/tcg.c | 545 +-------------------------------------------- tcg/meson.build | 1 + 4 files changed, 611 insertions(+), 542 deletions(-) create mode 100644 tcg/internal.h create mode 100644 tcg/region.c diff --git a/tcg/internal.h b/tcg/internal.h new file mode 100644 index 0000000000..b1dda343c2 --- /dev/null +++ b/tcg/internal.h @@ -0,0 +1,37 @@ +/* + * Internal declarations for Tiny Code Generator for QEMU + * + * Copyright (c) 2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef TCG_INTERNAL_H +#define TCG_INTERNAL_H 1 + +#define TCG_HIGHWATER 1024 + +extern TCGContext **tcg_ctxs; +extern unsigned int n_tcg_ctxs; + +bool tcg_region_alloc(TCGContext *s); +void tcg_region_initial_alloc(TCGContext *s); +void tcg_region_prologue_set(TCGContext *s); + +#endif /* TCG_INTERNAL_H */ diff --git a/tcg/region.c b/tcg/region.c new file mode 100644 index 0000000000..af45a0174e --- /dev/null +++ b/tcg/region.c @@ -0,0 +1,570 @@ +/* + * Memory region management for Tiny Code Generator for QEMU + * + * Copyright (c) 2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "exec/exec-all.h" +#include "tcg/tcg.h" +#if !defined(CONFIG_USER_ONLY) +#include "hw/boards.h" +#endif +#include "internal.h" + + +struct tcg_region_tree { + QemuMutex lock; + GTree *tree; + /* padding to avoid false sharing is computed at run-time */ +}; + +/* + * We divide code_gen_buffer into equally-sized "regions" that TCG threads + * dynamically allocate from as demand dictates. Given appropriate region + * sizing, this minimizes flushes even when some TCG threads generate a lot + * more code than others. + */ +struct tcg_region_state { + QemuMutex lock; + + /* fields set at init time */ + void *start; + void *start_aligned; + void *end; + size_t n; + size_t size; /* size of one region */ + size_t stride; /* .size + guard size */ + + /* fields protected by the lock */ + size_t current; /* current region index */ + size_t agg_size_full; /* aggregate size of full regions */ +}; + +static struct tcg_region_state region; + +/* + * This is an array of struct tcg_region_tree's, with padding. + * We use void * to simplify the computation of region_trees[i]; each + * struct is found every tree_size bytes. + */ +static void *region_trees; +static size_t tree_size; + +/* compare a pointer @ptr and a tb_tc @s */ +static int ptr_cmp_tb_tc(const void *ptr, const struct tb_tc *s) +{ + if (ptr >=3D 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 =3D ap; + const struct tb_tc *b =3D 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 =3D=3D b->ptr should happen only on deletions */ + g_assert(a->size =3D=3D 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. How= ever + * the docs provide no guarantee, so we just mark this case as likely. + */ + if (likely(a->size =3D=3D 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 =3D ROUND_UP(sizeof(struct tcg_region_tree), qemu_dcache_lin= esize); + region_trees =3D qemu_memalign(qemu_dcache_linesize, region.n * tree_s= ize); + for (i =3D 0; i < region.n; i++) { + struct tcg_region_tree *rt =3D region_trees + i * tree_size; + + qemu_mutex_init(&rt->lock); + rt->tree =3D 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 -=3D tcg_splitwx_diff; + if (!in_code_gen_buffer(p)) { + return NULL; + } + } + + if (p < region.start_aligned) { + region_idx =3D 0; + } else { + ptrdiff_t offset =3D p - region.start_aligned; + + if (offset > region.stride * (region.n - 1)) { + region_idx =3D region.n - 1; + } else { + region_idx =3D offset / region.stride; + } + } + return region_trees + region_idx * tree_size; +} + +void tcg_tb_insert(TranslationBlock *tb) +{ + struct tcg_region_tree *rt =3D tc_ptr_to_region_tree(tb->tc.ptr); + + g_assert(rt !=3D 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 =3D tc_ptr_to_region_tree(tb->tc.ptr); + + g_assert(rt !=3D 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 <=3D 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 =3D tc_ptr_to_region_tree((void *)tc_ptr); + TranslationBlock *tb; + struct tb_tc s =3D { .ptr =3D (void *)tc_ptr }; + + if (rt =3D=3D NULL) { + return NULL; + } + + qemu_mutex_lock(&rt->lock); + tb =3D 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 =3D 0; i < region.n; i++) { + struct tcg_region_tree *rt =3D region_trees + i * tree_size; + + qemu_mutex_lock(&rt->lock); + } +} + +static void tcg_region_tree_unlock_all(void) +{ + size_t i; + + for (i =3D 0; i < region.n; i++) { + struct tcg_region_tree *rt =3D 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 =3D 0; i < region.n; i++) { + struct tcg_region_tree *rt =3D 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 =3D 0; + size_t i; + + tcg_region_tree_lock_all(); + for (i =3D 0; i < region.n; i++) { + struct tcg_region_tree *rt =3D region_trees + i * tree_size; + + nb_tbs +=3D 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 =3D v; + + tb_destroy(tb); + return FALSE; +} + +static void tcg_region_tree_reset_all(void) +{ + size_t i; + + tcg_region_tree_lock_all(); + for (i =3D 0; i < region.n; i++) { + struct tcg_region_tree *rt =3D 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 **pe= nd) +{ + void *start, *end; + + start =3D region.start_aligned + curr_region * region.stride; + end =3D start + region.size; + + if (curr_region =3D=3D 0) { + start =3D region.start; + } + if (curr_region =3D=3D region.n - 1) { + end =3D region.end; + } + + *pstart =3D start; + *pend =3D 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 =3D start; + s->code_gen_ptr =3D start; + s->code_gen_buffer_size =3D end - start; + s->code_gen_highwater =3D end - TCG_HIGHWATER; +} + +static bool tcg_region_alloc__locked(TCGContext *s) +{ + if (region.current =3D=3D 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 succes= s */ + size_t size_full =3D s->code_gen_buffer_size; + + qemu_mutex_lock(®ion.lock); + err =3D tcg_region_alloc__locked(s); + if (!err) { + region.agg_size_full +=3D 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 =3D 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 =3D qatomic_read(&n_tcg_ctxs); + unsigned int i; + + qemu_mutex_lock(®ion.lock); + region.current =3D 0; + region.agg_size_full =3D 0; + + for (i =3D 0; i < n_ctxs; i++) { + TCGContext *s =3D 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 =3D MACHINE(qdev_get_machine()); + unsigned int max_cpus =3D ms->smp.max_cpus; +#endif + if (max_cpus =3D=3D 1 || !qemu_tcg_mttcg_enabled()) { + return 1; + } + + /* Try to have more regions than max_cpus, with each region being >=3D= 2 MB */ + for (i =3D 8; i > 0; i--) { + size_t regions_per_thread =3D i; + size_t region_size; + + region_size =3D tcg_init_ctx.code_gen_buffer_size; + region_size /=3D max_cpus * regions_per_thread; + + if (region_size >=3D 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 re= gions, + * and then assigning regions to TCG threads so that the threads can trans= late + * 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=3Dtc= g,[...]) + * 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-m= ode + * 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 t= he + * 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 prob= lem + * in practice. Multi-threaded guests share most if not all of their trans= lated + * code, which makes parallel code generation less appealing than in softm= mu. + */ +void tcg_region_init(void) +{ + void *buf =3D tcg_init_ctx.code_gen_buffer; + void *aligned; + size_t size =3D tcg_init_ctx.code_gen_buffer_size; + size_t page_size =3D qemu_real_host_page_size; + size_t region_size; + size_t n_regions; + size_t i; + uintptr_t splitwx_diff; + + n_regions =3D tcg_n_regions(); + + /* The first region will be 'aligned - buf' bytes larger than the othe= rs */ + aligned =3D 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 star= t. + * As a result of this we might end up with a few extra pages at the e= nd of + * the buffer; we will assign those to the last region. + */ + region_size =3D (size - (aligned - buf)) / n_regions; + region_size =3D QEMU_ALIGN_DOWN(region_size, page_size); + + /* A region must have at least 2 pages; one code, one guard */ + g_assert(region_size >=3D 2 * page_size); + + /* init the region struct */ + qemu_mutex_init(®ion.lock); + region.n =3D n_regions; + region.size =3D region_size - page_size; + region.stride =3D region_size; + region.start =3D buf; + region.start_aligned =3D aligned; + /* page-align the end, since its last page will be a guard page */ + region.end =3D QEMU_ALIGN_PTR_DOWN(buf + size, page_size); + /* account for that last guard page */ + region.end -=3D page_size; + + /* set guard pages */ + splitwx_diff =3D tcg_splitwx_diff; + for (i =3D 0; i < region.n; i++) { + void *start, *end; + int rc; + + tcg_region_bounds(i, &start, &end); + rc =3D qemu_mprotect_none(end, page_size); + g_assert(!rc); + if (splitwx_diff) { + rc =3D qemu_mprotect_none(end + splitwx_diff, page_size); + g_assert(!rc); + } + } + + tcg_region_trees_init(); + + /* + * Leave the initial context initialized to the first region. + * This will be the context into which we generate the prologue. + * It is also the only context for CONFIG_USER_ONLY. + */ + tcg_region_initial_alloc__locked(&tcg_init_ctx); +} + +void tcg_region_prologue_set(TCGContext *s) +{ + /* Deduct the prologue from the first region. */ + g_assert(region.start =3D=3D s->code_gen_buffer); + region.start =3D 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 regio= ns) + * currently in the cache. + * See also: tcg_code_capacity() + * Do not confuse with tcg_current_code_size(); that one applies to a sing= le + * TCG context. + */ +size_t tcg_code_size(void) +{ + unsigned int n_ctxs =3D qatomic_read(&n_tcg_ctxs); + unsigned int i; + size_t total; + + qemu_mutex_lock(®ion.lock); + total =3D region.agg_size_full; + for (i =3D 0; i < n_ctxs; i++) { + const TCGContext *s =3D qatomic_read(&tcg_ctxs[i]); + size_t size; + + size =3D qatomic_read(&s->code_gen_ptr) - s->code_gen_buffer; + g_assert(size <=3D s->code_gen_buffer_size); + total +=3D size; + } + qemu_mutex_unlock(®ion.lock); + return total; +} + +/* + * Returns the code capacity (in bytes) of the entire cache, i.e. includin= g 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 =3D region.stride - region.size; + capacity =3D region.end + guard_size - region.start; + capacity -=3D region.n * (guard_size + TCG_HIGHWATER); + return capacity; +} + +size_t tcg_tb_phys_invalidate_count(void) +{ + unsigned int n_ctxs =3D qatomic_read(&n_tcg_ctxs); + unsigned int i; + size_t total =3D 0; + + for (i =3D 0; i < n_ctxs; i++) { + const TCGContext *s =3D qatomic_read(&tcg_ctxs[i]); + + total +=3D qatomic_read(&s->tb_phys_invalidate_count); + } + return total; +} diff --git a/tcg/tcg.c b/tcg/tcg.c index 5b3525d52a..10a571d41c 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -65,6 +65,7 @@ #include "elf.h" #include "exec/log.h" #include "sysemu/sysemu.h" +#include "internal.h" =20 /* Forward declarations for functions declared in tcg-target.c.inc and used here. */ @@ -153,10 +154,8 @@ static int tcg_target_const_match(tcg_target_long val,= TCGType type, static int tcg_out_ldst_finalize(TCGContext *s); #endif =20 -#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 =3D 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 =20 -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; =20 @@ -457,451 +420,6 @@ static const TCGTargetOpDef constraint_sets[] =3D { =20 #include "tcg-target.c.inc" =20 -/* 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 >=3D 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 =3D ap; - const struct tb_tc *b =3D 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 =3D=3D b->ptr should happen only on deletions */ - g_assert(a->size =3D=3D 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. How= ever - * the docs provide no guarantee, so we just mark this case as likely. - */ - if (likely(a->size =3D=3D 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 =3D ROUND_UP(sizeof(struct tcg_region_tree), qemu_dcache_lin= esize); - region_trees =3D qemu_memalign(qemu_dcache_linesize, region.n * tree_s= ize); - for (i =3D 0; i < region.n; i++) { - struct tcg_region_tree *rt =3D region_trees + i * tree_size; - - qemu_mutex_init(&rt->lock); - rt->tree =3D 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 -=3D tcg_splitwx_diff; - if (!in_code_gen_buffer(p)) { - return NULL; - } - } - - if (p < region.start_aligned) { - region_idx =3D 0; - } else { - ptrdiff_t offset =3D p - region.start_aligned; - - if (offset > region.stride * (region.n - 1)) { - region_idx =3D region.n - 1; - } else { - region_idx =3D offset / region.stride; - } - } - return region_trees + region_idx * tree_size; -} - -void tcg_tb_insert(TranslationBlock *tb) -{ - struct tcg_region_tree *rt =3D tc_ptr_to_region_tree(tb->tc.ptr); - - g_assert(rt !=3D 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 =3D tc_ptr_to_region_tree(tb->tc.ptr); - - g_assert(rt !=3D 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 <=3D 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 =3D tc_ptr_to_region_tree((void *)tc_ptr); - TranslationBlock *tb; - struct tb_tc s =3D { .ptr =3D (void *)tc_ptr }; - - if (rt =3D=3D NULL) { - return NULL; - } - - qemu_mutex_lock(&rt->lock); - tb =3D 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 =3D 0; i < region.n; i++) { - struct tcg_region_tree *rt =3D region_trees + i * tree_size; - - qemu_mutex_lock(&rt->lock); - } -} - -static void tcg_region_tree_unlock_all(void) -{ - size_t i; - - for (i =3D 0; i < region.n; i++) { - struct tcg_region_tree *rt =3D 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 =3D 0; i < region.n; i++) { - struct tcg_region_tree *rt =3D 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 =3D 0; - size_t i; - - tcg_region_tree_lock_all(); - for (i =3D 0; i < region.n; i++) { - struct tcg_region_tree *rt =3D region_trees + i * tree_size; - - nb_tbs +=3D 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 =3D v; - - tb_destroy(tb); - return FALSE; -} - -static void tcg_region_tree_reset_all(void) -{ - size_t i; - - tcg_region_tree_lock_all(); - for (i =3D 0; i < region.n; i++) { - struct tcg_region_tree *rt =3D 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 **pe= nd) -{ - void *start, *end; - - start =3D region.start_aligned + curr_region * region.stride; - end =3D start + region.size; - - if (curr_region =3D=3D 0) { - start =3D region.start; - } - if (curr_region =3D=3D region.n - 1) { - end =3D region.end; - } - - *pstart =3D start; - *pend =3D 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 =3D start; - s->code_gen_ptr =3D start; - s->code_gen_buffer_size =3D end - start; - s->code_gen_highwater =3D end - TCG_HIGHWATER; -} - -static bool tcg_region_alloc__locked(TCGContext *s) -{ - if (region.current =3D=3D 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 succes= s */ - size_t size_full =3D s->code_gen_buffer_size; - - qemu_mutex_lock(®ion.lock); - err =3D tcg_region_alloc__locked(s); - if (!err) { - region.agg_size_full +=3D 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 =3D 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 =3D qatomic_read(&n_tcg_ctxs); - unsigned int i; - - qemu_mutex_lock(®ion.lock); - region.current =3D 0; - region.agg_size_full =3D 0; - - for (i =3D 0; i < n_ctxs; i++) { - TCGContext *s =3D 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 =3D MACHINE(qdev_get_machine()); - unsigned int max_cpus =3D ms->smp.max_cpus; -#endif - if (max_cpus =3D=3D 1 || !qemu_tcg_mttcg_enabled()) { - return 1; - } - - /* Try to have more regions than max_cpus, with each region being >=3D= 2 MB */ - for (i =3D 8; i > 0; i--) { - size_t regions_per_thread =3D i; - size_t region_size; - - region_size =3D tcg_init_ctx.code_gen_buffer_size; - region_size /=3D max_cpus * regions_per_thread; - - if (region_size >=3D 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 re= gions, - * and then assigning regions to TCG threads so that the threads can trans= late - * 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=3Dtc= g,[...]) - * 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-m= ode - * 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 t= he - * 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 prob= lem - * in practice. Multi-threaded guests share most if not all of their trans= lated - * code, which makes parallel code generation less appealing than in softm= mu. - */ -void tcg_region_init(void) -{ - void *buf =3D tcg_init_ctx.code_gen_buffer; - void *aligned; - size_t size =3D tcg_init_ctx.code_gen_buffer_size; - size_t page_size =3D qemu_real_host_page_size; - size_t region_size; - size_t n_regions; - size_t i; - uintptr_t splitwx_diff; - - n_regions =3D tcg_n_regions(); - - /* The first region will be 'aligned - buf' bytes larger than the othe= rs */ - aligned =3D 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 star= t. - * As a result of this we might end up with a few extra pages at the e= nd of - * the buffer; we will assign those to the last region. - */ - region_size =3D (size - (aligned - buf)) / n_regions; - region_size =3D QEMU_ALIGN_DOWN(region_size, page_size); - - /* A region must have at least 2 pages; one code, one guard */ - g_assert(region_size >=3D 2 * page_size); - - /* init the region struct */ - qemu_mutex_init(®ion.lock); - region.n =3D n_regions; - region.size =3D region_size - page_size; - region.stride =3D region_size; - region.start =3D buf; - region.start_aligned =3D aligned; - /* page-align the end, since its last page will be a guard page */ - region.end =3D QEMU_ALIGN_PTR_DOWN(buf + size, page_size); - /* account for that last guard page */ - region.end -=3D page_size; - - /* set guard pages */ - splitwx_diff =3D tcg_splitwx_diff; - for (i =3D 0; i < region.n; i++) { - void *start, *end; - int rc; - - tcg_region_bounds(i, &start, &end); - rc =3D qemu_mprotect_none(end, page_size); - g_assert(!rc); - if (splitwx_diff) { - rc =3D qemu_mprotect_none(end + splitwx_diff, page_size); - g_assert(!rc); - } - } - - tcg_region_trees_init(); - - /* - * Leave the initial context initialized to the first region. - * This will be the context into which we generate the prologue. - * It is also the only context for CONFIG_USER_ONLY. - */ - tcg_region_initial_alloc__locked(&tcg_init_ctx); -} - -static void tcg_region_prologue_set(TCGContext *s) -{ - /* Deduct the prologue from the first region. */ - g_assert(region.start =3D=3D s->code_gen_buffer); - region.start =3D s->code_ptr; - - /* Recompute boundaries of the first region. */ - tcg_region_assign(s, 0); - - /* Register the balance of the buffer with gdb. */ - tcg_register_jit(tcg_splitwx_to_rx(region.start), - region.end - region.start); -} - #ifdef CONFIG_DEBUG_TCG const void *tcg_splitwx_to_rx(void *rw) { @@ -986,63 +504,6 @@ void tcg_register_thread(void) } #endif /* !CONFIG_USER_ONLY */ =20 -/* - * Returns the size (in bytes) of all translated code (i.e. from all regio= ns) - * currently in the cache. - * See also: tcg_code_capacity() - * Do not confuse with tcg_current_code_size(); that one applies to a sing= le - * TCG context. - */ -size_t tcg_code_size(void) -{ - unsigned int n_ctxs =3D qatomic_read(&n_tcg_ctxs); - unsigned int i; - size_t total; - - qemu_mutex_lock(®ion.lock); - total =3D region.agg_size_full; - for (i =3D 0; i < n_ctxs; i++) { - const TCGContext *s =3D qatomic_read(&tcg_ctxs[i]); - size_t size; - - size =3D qatomic_read(&s->code_gen_ptr) - s->code_gen_buffer; - g_assert(size <=3D s->code_gen_buffer_size); - total +=3D size; - } - qemu_mutex_unlock(®ion.lock); - return total; -} - -/* - * Returns the code capacity (in bytes) of the entire cache, i.e. includin= g 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 =3D region.stride - region.size; - capacity =3D region.end + guard_size - region.start; - capacity -=3D region.n * (guard_size + TCG_HIGHWATER); - return capacity; -} - -size_t tcg_tb_phys_invalidate_count(void) -{ - unsigned int n_ctxs =3D qatomic_read(&n_tcg_ctxs); - unsigned int i; - size_t total =3D 0; - - for (i =3D 0; i < n_ctxs; i++) { - const TCGContext *s =3D qatomic_read(&tcg_ctxs[i]); - - total +=3D 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 =3D ss.source_set() =20 tcg_ss.add(files( 'optimize.c', + 'region.c', 'tcg.c', 'tcg-common.c', 'tcg-op.c', --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757574; cv=none; d=zohomail.com; s=zohoarc; b=Por5CBP/Lstt69YX9z1kSd3Fh7KljDyNMbKdwo90cAacnhYRx8bsDGK9gHYNeoDmTRbXXcQZc8s0YWNO1HiF8yf+FoMEhY6KN1dHs+oMTilQF1ByDvhY/xkOXiHg54WhNpZjCzLxVlAl2BKiayuJB25uZ1E361Cm3j+VOcoKDPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757574; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yjdtKlRm3WuNdcNC9EUZQ7YJqY8dzEyQHbjSnP7J42Q=; b=dj49NJqBe9qBTAT9yy/tG7urKGeJ8t5corLsrypnS/CF63TD1AzyNcLZNcnZlWc36fYZJfZYQooHwjuLQFM7EKFnfzHFprKSWBAPwvurDe+iSGfke1q7l8eoQezrDO5tMI9vRIR6iqfF3OuPqoK9KSpSeyo+iHc+ldbpQjWCnho= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757574073908.0918925705362; Sun, 14 Mar 2021 14:32:54 -0700 (PDT) Received: from localhost ([::1]:39380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYM0-0002oa-AW for importer@patchew.org; Sun, 14 Mar 2021 17:32:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYGw-000606-A5 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:38 -0400 Received: from mail-qv1-xf2c.google.com ([2607:f8b0:4864:20::f2c]:45928) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGu-0008BW-Rx for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:38 -0400 Received: by mail-qv1-xf2c.google.com with SMTP id t16so6881805qvr.12 for ; Sun, 14 Mar 2021 14:27:36 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yjdtKlRm3WuNdcNC9EUZQ7YJqY8dzEyQHbjSnP7J42Q=; b=FnH7s/f17efMqPJ9qLstuHjwS5rRDyjEDSMMLbZdAB0t9XllQLAf6lw1eThds0ZpIC KYnbt2B25RT/NM+Zdgst+0ulgVqhi8dIvWTg47eyKRyMeeZ1PpcDK0VOAyI4ttBZf29m DhGt+JUdFpesssIM2Rggp//3a1TlshpfqfxLOv0GATsi1co77fTayVxjY2wa/ZWcIEX6 ngsa8PwNBlKX7lhQQ2cs2aSyNLBgql/8ZzWSZvJYbzZbRN3cqqIcsL4FwZHLehWIwfpI MIdlVlKO7G8pURPWVXsaWESbsaLwcXdZk/1C8QCz55SOFDKE6krjeEhqVRIDXLAsE8JZ wTmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yjdtKlRm3WuNdcNC9EUZQ7YJqY8dzEyQHbjSnP7J42Q=; b=HYgXvzq7O9vq/4zL6Oo8zrFfRzJxyjfFnzTI+VRNv5HmlngF6Fifk3rTVsB8nc3gz2 N6csesut2V2qV4G51bMDImQ0AVKeNMHpUngPundKT59L3FDgwEcvE+yNBppzjFzTPJ8o Yu4EywfUbWeBZ+mB/VjAZjB4qpxZy5rOd7jWR0N7Ig0ahq2rMrgKQ8NpLZyL3ThocXd3 xTjcnBwr61EmCv0HBc/EW1GvzxZRrOURVe5yti/6rzDEuUnfzW11FgytNRYFFngPbYz5 d8pxtFZqR9BJ1DdAQCjTSL2xdZguVuArcl+7TBceN3F72exu3CGxppV7JHiHb5Xo/h6G KJyw== X-Gm-Message-State: AOAM533kjGQklGHhgLOB7mTth7y0EwayTdYcmrigHy6uPGbgoUEQR7rd BHBC7dET//WSRkrkr9rKd/aKkUexBt9OVz4o X-Google-Smtp-Source: ABdhPJyGZuxWKrxE4/gxMY8JnOC9Uab3azSs7IecQiDfBzll72wW8pH0F5bq7/GHmsUPvo5lv0gPsg== X-Received: by 2002:a05:6214:268c:: with SMTP id gm12mr7883189qvb.36.1615757255954; Sun, 14 Mar 2021 14:27:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 08/29] accel/tcg: Inline cpu_gen_init Date: Sun, 14 Mar 2021 15:27:03 -0600 Message-Id: <20210314212724.1917075-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::f2c; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) It consists of one function call and has only one caller. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index b9057567f4..6d3184e7da 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -245,11 +245,6 @@ static void page_table_config_init(void) assert(v_l2_levels >=3D 0); } =20 -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; =20 tcg_allowed =3D true; - cpu_gen_init(); + tcg_context_init(&tcg_init_ctx); page_init(); tb_htable_init(); =20 --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758252; cv=none; d=zohomail.com; s=zohoarc; b=XA5lYBIXeUmZN0Dlr2ia+tVS+orLK4S60t4LkYOQ6ltVjm1W7iOqZ91EaUcY8d3sarmzpbsGngUeYW8TP/geQE+JkHBHmW6X2mnRkx/GeCkONCgCVnI5iqxWkRZSXmK0PQ27CGZ8qpW1JPYmrLX+AhfUlM6LcKt8kw8vI3NFqoI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758252; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1kd3z5f3F5IgA4tmLR2z9IlG5FeR5TPlOdPkW3kV5W4=; b=IxViP/ntAYHC9SDwhEGxj34syENJaiILboW7Fw24Xzm3EeSFm2d2SkF+94OOS3vEPyb73g2+OFLVw04NjIhO7ka78SHigPbdjlUzDtZIgXmXz3hOfOcJ+7Wz+afYd2xGNNx0mw7jSoULk8KCGEe3xVyMIA6df6m03a2psuFaxko= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161575825263125.30250525802137; Sun, 14 Mar 2021 14:44:12 -0700 (PDT) Received: from localhost ([::1]:44374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYWx-0008K0-Aq for importer@patchew.org; Sun, 14 Mar 2021 17:44:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH0-00065v-Hr for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:44 -0400 Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]:36765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGw-0008CF-BM for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:41 -0400 Received: by mail-qt1-x833.google.com with SMTP id h7so1069313qtx.3 for ; Sun, 14 Mar 2021 14:27:37 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1kd3z5f3F5IgA4tmLR2z9IlG5FeR5TPlOdPkW3kV5W4=; b=LW4Fs40gSKa2qtimunawKiyp3WnStzn88geTpoqDbgbWbietlp/d0ZzNAo3Z8JE5ZR zSDY7t6daONgB7Hb/W7Wz7o1q0ua6LM+w4SRwjOSP7275sdTbFsWdPVcdlNw52095j46 B4HaMQ6pJkHwCyTmeVuNuNkl5z7WpCQaaH5evNSDoZi7x4NfwUBUzYRCcHcdpQvBXIgJ dWfnPZN+HIS1jWKA+fl+jM7dW5B2JiUOPMP/MAJHzt3wyfxlGPlMxJfOc9JIMZlZYn5e jGKT9x75Q1sFgwHwn47N+0lgyj/wiNfsbZ5ioVq4pCJIZOT70EvuDyGGJYCFiBybajB0 Ki8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1kd3z5f3F5IgA4tmLR2z9IlG5FeR5TPlOdPkW3kV5W4=; b=Vw2rCKKIlNkR57+C1yd6fESKodzjL9YIr6A1aMMa1b4T8FG9lStk7OetVd2XXQSbl6 7YVBhTPAfClx74LrTaS1vf3Rkc979mCLSdSSqbWzergTW6N8YIN2jYTOu7BtU+Vk7d/u ojqPJBiQcUKqYcb9wt4QlS8xe2PfyjkIGJvrRz+NmJA/euhFobN7ijLDxxkpAkl/A3lJ OxdT7hGCctlNm9vnV3k3R3a9s5v3IBU3QK9zuCEDbJ6kulWXFE4K+Jvc5X9BgoB5/wK8 VpiUpcws+p1yTjBB+GbvHXUL6ssPnGW9HY6C9ArHrEpc2AlGUQa7XjwIo8WFCaRB5qOn mfeQ== X-Gm-Message-State: AOAM531/p2sG5UP7Y5ib4DB3weIT/OjUOaCbEY8IrWjNvwa/63q/5dcx r1+1IfKr01mW+2KZn0RjhKOj0PrCZz5HcCnU X-Google-Smtp-Source: ABdhPJxE8XLaWtq+DT/H9h0g0Cw8bLeD3Uw4SxUadCF7ZwYMEYnmSpsBiqU6D/GZ/mcVkQEIf+FtvQ== X-Received: by 2002:ac8:4d59:: with SMTP id x25mr6250061qtv.82.1615757257206; Sun, 14 Mar 2021 14:27:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 09/29] accel/tcg: Move alloc_code_gen_buffer to tcg/region.c Date: Sun, 14 Mar 2021 15:27:04 -0600 Message-Id: <20210314212724.1917075-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::833; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x833.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Buffer management is integral to tcg. Do not leave the allocation to code outside of tcg/. This is code movement, with further cleanups to follow. Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 2 +- accel/tcg/translate-all.c | 414 +------------------------------------ tcg/region.c | 421 +++++++++++++++++++++++++++++++++++++- 3 files changed, 418 insertions(+), 419 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 0f0695e90d..7a435bf807 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -874,7 +874,7 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); =20 -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); =20 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 6d3184e7da..4071edda16 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -18,7 +18,6 @@ */ =20 #include "qemu/osdep.h" -#include "qemu/units.h" #include "qemu-common.h" =20 #define NO_CPU_IO_DEFS @@ -51,7 +50,6 @@ #include "exec/tb-hash.h" #include "exec/translate-all.h" #include "qemu/bitmap.h" -#include "qemu/error-report.h" #include "qemu/qemu-print.h" #include "qemu/timer.h" #include "qemu/main-loop.h" @@ -895,408 +893,6 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page= _addr_t phys1, } } =20 -/* 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 =3D=3D 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 =3D=3D 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 =3D=3D 0) { - size_t phys_mem =3D qemu_get_host_physmem(); - if (phys_mem =3D=3D 0) { - tb_size =3D DEFAULT_CODE_GEN_BUFFER_SIZE; - } else { - tb_size =3D MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, phys_mem / 8); - } - } - if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { - tb_size =3D MIN_CODE_GEN_BUFFER_SIZE; - } - if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { - tb_size =3D 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 =3D (void *)(((uintptr_t)buf1 + size1) & ~0x0ffffffful); - size_t size2 =3D buf1 + size1 - buf2; - - size1 =3D buf2 - buf1; - if (size1 < size2) { - size1 =3D size2; - buf1 =3D buf2; - } - - tcg_ctx->code_gen_buffer_size =3D 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 **err= p) -{ - 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 =3D static_code_gen_buffer; - end =3D static_code_gen_buffer + sizeof(static_code_gen_buffer); - buf =3D QEMU_ALIGN_PTR_UP(buf, qemu_real_host_page_size); - end =3D QEMU_ALIGN_PTR_DOWN(end, qemu_real_host_page_size); - - size =3D end - buf; - - /* Honor a command-line option limiting the size of the buffer. */ - if (size > tb_size) { - size =3D QEMU_ALIGN_DOWN(tb_size, qemu_real_host_page_size); - } - tcg_ctx->code_gen_buffer_size =3D size; - -#ifdef __mips__ - if (cross_256mb(buf, size)) { - buf =3D split_cross_256mb(buf, size); - size =3D 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 =3D 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 =3D VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, - PAGE_EXECUTE_READWRITE); - if (buf =3D=3D NULL) { - error_setg_win32(errp, GetLastError(), - "allocate %zu bytes for jit buffer", size); - return false; - } - - tcg_ctx->code_gen_buffer =3D buf; - tcg_ctx->code_gen_buffer_size =3D size; - return true; -} -#else -static bool alloc_code_gen_buffer_anon(size_t size, int prot, - int flags, Error **errp) -{ - void *buf; - - buf =3D mmap(NULL, size, prot, flags, -1, 0); - if (buf =3D=3D MAP_FAILED) { - error_setg_errno(errp, errno, - "allocate %zu bytes for jit buffer", size); - return false; - } - tcg_ctx->code_gen_buffer_size =3D 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 =3D mmap(NULL, size, prot, flags, -1, 0); - switch ((int)(buf2 !=3D 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 =3D split_cross_256mb(buf, size); - size2 =3D tcg_ctx->code_gen_buffer_size; - if (buf =3D=3D buf2) { - munmap(buf + size2, size - size2); - } else { - munmap(buf, size - size2); - } - size =3D size2; - break; - } - buf =3D buf2; - } -#endif - - /* Request large pages for the buffer. */ - qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); - - tcg_ctx->code_gen_buffer =3D 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 =3D NULL, *buf_rx =3D MAP_FAILED; - int fd =3D -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 =3D tcg_ctx->code_gen_buffer_size; - buf_rx =3D tcg_ctx->code_gen_buffer; -#endif - - buf_rw =3D qemu_memfd_alloc("tcg-jit", size, 0, &fd, errp); - if (buf_rw =3D=3D NULL) { - goto fail; - } - -#ifdef __mips__ - void *tmp =3D mmap(buf_rx, size, PROT_READ | PROT_EXEC, - MAP_SHARED | MAP_FIXED, fd, 0); - if (tmp !=3D buf_rx) { - goto fail_rx; - } -#else - buf_rx =3D mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0); - if (buf_rx =3D=3D MAP_FAILED) { - goto fail_rx; - } -#endif - - close(fd); - tcg_ctx->code_gen_buffer =3D buf_rw; - tcg_ctx->code_gen_buffer_size =3D size; - tcg_splitwx_diff =3D 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 !=3D MAP_FAILED) { - munmap(buf_rx, size); - } - if (buf_rw) { - munmap(buf_rw, size); - } - if (fd >=3D 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 **err= p) -{ - 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 =3D (mach_vm_address_t)tcg_ctx->code_gen_buffer; - buf_rx =3D 0; - ret =3D 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 !=3D 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) !=3D 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 =3D 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 =3D PROT_READ | PROT_WRITE | PROT_EXEC; - flags =3D MAP_PRIVATE | MAP_ANONYMOUS; -#ifdef CONFIG_TCG_INTERPRETER - /* The tcg interpreter does not need execute permission. */ - prot =3D PROT_READ | PROT_WRITE; -#elif defined(CONFIG_DARWIN) - /* Applicable to both iOS and macOS (Apple Silicon). */ - if (!splitwx) { - flags |=3D 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 =3D 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 =3D true; tcg_context_init(&tcg_init_ctx); page_init(); tb_htable_init(); - - ok =3D 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); =20 #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and diff --git a/tcg/region.c b/tcg/region.c index af45a0174e..8d88144a22 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -23,6 +23,8 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/units.h" +#include "qapi/error.h" #include "exec/exec-all.h" #include "tcg/tcg.h" #if !defined(CONFIG_USER_ONLY) @@ -406,6 +408,408 @@ static size_t tcg_n_regions(void) } #endif =20 +/* 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 =3D=3D 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 =3D=3D 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 =3D=3D 0) { + size_t phys_mem =3D qemu_get_host_physmem(); + if (phys_mem =3D=3D 0) { + tb_size =3D DEFAULT_CODE_GEN_BUFFER_SIZE; + } else { + tb_size =3D MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, phys_mem / 8); + } + } + if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { + tb_size =3D MIN_CODE_GEN_BUFFER_SIZE; + } + if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { + tb_size =3D 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 =3D (void *)(((uintptr_t)buf1 + size1) & ~0x0ffffffful); + size_t size2 =3D buf1 + size1 - buf2; + + size1 =3D buf2 - buf1; + if (size1 < size2) { + size1 =3D size2; + buf1 =3D buf2; + } + + tcg_ctx->code_gen_buffer_size =3D 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 **err= p) +{ + 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 =3D static_code_gen_buffer; + end =3D static_code_gen_buffer + sizeof(static_code_gen_buffer); + buf =3D QEMU_ALIGN_PTR_UP(buf, qemu_real_host_page_size); + end =3D QEMU_ALIGN_PTR_DOWN(end, qemu_real_host_page_size); + + size =3D end - buf; + + /* Honor a command-line option limiting the size of the buffer. */ + if (size > tb_size) { + size =3D QEMU_ALIGN_DOWN(tb_size, qemu_real_host_page_size); + } + tcg_ctx->code_gen_buffer_size =3D size; + +#ifdef __mips__ + if (cross_256mb(buf, size)) { + buf =3D split_cross_256mb(buf, size); + size =3D 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 =3D 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 =3D VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, + PAGE_EXECUTE_READWRITE); + if (buf =3D=3D NULL) { + error_setg_win32(errp, GetLastError(), + "allocate %zu bytes for jit buffer", size); + return false; + } + + tcg_ctx->code_gen_buffer =3D buf; + tcg_ctx->code_gen_buffer_size =3D size; + return true; +} +#else +static bool alloc_code_gen_buffer_anon(size_t size, int prot, + int flags, Error **errp) +{ + void *buf; + + buf =3D mmap(NULL, size, prot, flags, -1, 0); + if (buf =3D=3D MAP_FAILED) { + error_setg_errno(errp, errno, + "allocate %zu bytes for jit buffer", size); + return false; + } + tcg_ctx->code_gen_buffer_size =3D 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 =3D mmap(NULL, size, prot, flags, -1, 0); + switch ((int)(buf2 !=3D 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 =3D split_cross_256mb(buf, size); + size2 =3D tcg_ctx->code_gen_buffer_size; + if (buf =3D=3D buf2) { + munmap(buf + size2, size - size2); + } else { + munmap(buf, size - size2); + } + size =3D size2; + break; + } + buf =3D buf2; + } +#endif + + /* Request large pages for the buffer. */ + qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); + + tcg_ctx->code_gen_buffer =3D 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 =3D NULL, *buf_rx =3D MAP_FAILED; + int fd =3D -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 =3D tcg_ctx->code_gen_buffer_size; + buf_rx =3D tcg_ctx->code_gen_buffer; +#endif + + buf_rw =3D qemu_memfd_alloc("tcg-jit", size, 0, &fd, errp); + if (buf_rw =3D=3D NULL) { + goto fail; + } + +#ifdef __mips__ + void *tmp =3D mmap(buf_rx, size, PROT_READ | PROT_EXEC, + MAP_SHARED | MAP_FIXED, fd, 0); + if (tmp !=3D buf_rx) { + goto fail_rx; + } +#else + buf_rx =3D mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0); + if (buf_rx =3D=3D MAP_FAILED) { + goto fail_rx; + } +#endif + + close(fd); + tcg_ctx->code_gen_buffer =3D buf_rw; + tcg_ctx->code_gen_buffer_size =3D size; + tcg_splitwx_diff =3D 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 !=3D MAP_FAILED) { + munmap(buf_rx, size); + } + if (buf_rw) { + munmap(buf_rw, size); + } + if (fd >=3D 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 **err= p) +{ + 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 =3D (mach_vm_address_t)tcg_ctx->code_gen_buffer; + buf_rx =3D 0; + ret =3D 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 !=3D 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) !=3D 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 =3D 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 =3D PROT_READ | PROT_WRITE | PROT_EXEC; + flags =3D MAP_PRIVATE | MAP_ANONYMOUS; +#ifdef CONFIG_TCG_INTERPRETER + /* The tcg interpreter does not need execute permission. */ + prot =3D PROT_READ | PROT_WRITE; +#elif defined(CONFIG_DARWIN) + /* Applicable to both iOS and macOS (Apple Silicon). */ + if (!splitwx) { + flags |=3D MAP_JIT; + } +#endif + + return alloc_code_gen_buffer_anon(size, prot, flags, errp); +} +#endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */ + /* * Initializes region partitioning. * @@ -434,17 +838,24 @@ static size_t tcg_n_regions(void) * in practice. Multi-threaded guests share most if not all of their trans= lated * code, which makes parallel code generation less appealing than in softm= mu. */ -void tcg_region_init(void) +void tcg_region_init(size_t tb_size, int splitwx) { - void *buf =3D tcg_init_ctx.code_gen_buffer; - void *aligned; - size_t size =3D tcg_init_ctx.code_gen_buffer_size; - size_t page_size =3D qemu_real_host_page_size; + void *buf, *aligned; + size_t size; + size_t page_size; size_t region_size; size_t n_regions; size_t i; uintptr_t splitwx_diff; + bool ok; =20 + ok =3D alloc_code_gen_buffer(size_code_gen_buffer(tb_size), + splitwx, &error_fatal); + assert(ok); + + buf =3D tcg_init_ctx.code_gen_buffer; + size =3D tcg_init_ctx.code_gen_buffer_size; + page_size =3D qemu_real_host_page_size; n_regions =3D tcg_n_regions(); =20 /* The first region will be 'aligned - buf' bytes larger than the othe= rs */ --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758373; cv=none; d=zohomail.com; s=zohoarc; b=iKc4bqTJIG0EQu6FUUrJHcmxB/x0G2zHrWXMrM/YdJnWDeeJ+RBeWpd2hHQeBhSAOxgFBvhDLUaGFGw4+BhvEYTFYg0/LXZzkuHxK8JNV7K72D1UResBcCh+V/1mSy+NTMACFjR4KwCz6B4ipyBzHpuGLfKETqnT1Dx3Te9GJTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758373; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=M+GW/FjdFE0LjCNjl+PKpujGwHht+vUuynWRRTNqZ50=; b=OJPz30P2bibLUtMn3e8T9ULB98n4LbvPBYeM3fGAL6iV0kmRPwTABVWSZCriqYxAXLjQyv09t9ddO7VVERCBOIDpjSzN6KpBp7pVFLNg9KT5hlahOID9h7hhP7EVcFAFEEDWZ7fHOI96yuwcgQWqLPWeVzKfbWqntYWcPsiWHc0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615758373748522.5437178514762; Sun, 14 Mar 2021 14:46:13 -0700 (PDT) Received: from localhost ([::1]:48758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYYu-0001xw-PR for importer@patchew.org; Sun, 14 Mar 2021 17:46:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH1-000667-Ts for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:44 -0400 Received: from mail-qv1-xf36.google.com ([2607:f8b0:4864:20::f36]:40914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGx-0008CO-95 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:42 -0400 Received: by mail-qv1-xf36.google.com with SMTP id d10so514675qve.7 for ; Sun, 14 Mar 2021 14:27:38 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M+GW/FjdFE0LjCNjl+PKpujGwHht+vUuynWRRTNqZ50=; b=W9EWIAYYbiO2Q6ZUxeVr5YPtTr1LDApzVKQWZ2GzhKufQLanv30gPAhtF6PeHWozgu X68zP/nd66KSGUoe0/S8TGAzbi2XUgaVxh0deeARPH4dDlPfBdciinj5EIzF935ZUNP0 r8pWZ25Ju6BVc69QEmrfvmD79Kv4LiMH39DeXhnifp8QAcQkN0uYKbRJ04viTpIZ60/a DIcg4VR3fS2FjXk4EbDzC/GHEG1m604hNu9t5Xgron0XfBivW0D9lpW+lpqU7wmRoaii SYSZfr+ke1/TOUe6dm+fKTiVddSFsAwfBeBMkWF8XhVfsmUIHrju9SW6nv0Rvgiv0gjW mU2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M+GW/FjdFE0LjCNjl+PKpujGwHht+vUuynWRRTNqZ50=; b=HEk84H0FpkA0yYV8JUeYJ2RIMpBP0Zc406h8y8eVp/zWaZWB9TTJGZqpuci3D4+jin G1PBPinBScep6uZ+jTArc51NmTweu/CiyA86S8m5UhAA6PqeWHGZSqXCzZn0AcjzdKU/ dx9MrDDQ0fnite42NcBUOGVsBiNpsAyMjYqPTK26zZn+OlxwS9kFHeDZwHyTRccXpRt9 y8SrM+Z/c2vAWgfXFva6GJWM0Ur0xDVfKVRtpDulEWHh1T0btPkYtR8TSbwA1ZbyFpeV V2ROX2jsbHlfm0Cj/tTOhjOcbM2dPr/Z0ac4R16wItsb8Agn2cbOKGLcK3AEbdfwSWMs e49w== X-Gm-Message-State: AOAM532Sc+3e2TV+ICBK4eRAeYes2qCRM6rwWW7BQNwDBx6DwagYAoax GmLdtF5vJkzthDamUf8TjJQ75o7oF/gqv3V7 X-Google-Smtp-Source: ABdhPJy1s8Q4SEFBr7HTmMDqzo411lI0IoPR4kRh9KdkkbZ7h95g0C3tdNBBlx7ZZpo2ir0XF6i1Hw== X-Received: by 2002:ad4:4e53:: with SMTP id eb19mr8088279qvb.8.1615757258393; Sun, 14 Mar 2021 14:27:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 10/29] accel/tcg: Rename tcg_init to tcg_init_machine Date: Sun, 14 Mar 2021 15:27:05 -0600 Message-Id: <20210314212724.1917075-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::f36; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf36.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We shortly want to use tcg_init for something else. Since the hook is called init_machine, match that. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- accel/tcg/tcg-all.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) =20 bool mttcg_enabled; =20 -static int tcg_init(MachineState *ms) +static int tcg_init_machine(MachineState *ms) { TCGState *s =3D TCG_STATE(current_accel()); =20 @@ -189,7 +189,7 @@ static void tcg_accel_class_init(ObjectClass *oc, void = *data) { AccelClass *ac =3D ACCEL_CLASS(oc); ac->name =3D "tcg"; - ac->init_machine =3D tcg_init; + ac->init_machine =3D tcg_init_machine; ac->allowed =3D &tcg_allowed; =20 object_class_property_add_str(oc, "thread", --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758454; cv=none; d=zohomail.com; s=zohoarc; b=eeuushxfvt2f8mQHn7NVN0IB2TnQn9JUFnIraephOUPZzVAq0YY+CR6L+ZW3E2Sfdi7sJIaQR2KXcJm7TBoYpXgCbUkx8za+rIdrzqkvhzock3NBYgMkH4ZpML+frr3tIw3r2Fyl8VHHG+2yurwKq8syBAPLfGDVWFfw+0y06+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758454; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1JDFX+MuUZit7885JaLDSIbe6sMdYH/iLicvWinCUzk=; b=MwT60o0zOaosm6T/4kpWZMf7OAE43Ac+H4TEtaxVBmFjKU41yCA2gDF0cLfNLHwspgLK09weO3a9Chgmr7WIXV9AgGWwBLb5AC0Rujuo31KsegqDYULG0ZOz/L56tj/L1kPb03qmuK6nrwknAG7wTic57pTcuyG/KmVeoVG54xU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615758454763684.724520350473; Sun, 14 Mar 2021 14:47:34 -0700 (PDT) Received: from localhost ([::1]:51786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYaD-0003IQ-Ne for importer@patchew.org; Sun, 14 Mar 2021 17:47:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54664) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH2-00066Q-BC for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:46 -0400 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]:39700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYGy-0008DM-HR for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:43 -0400 Received: by mail-qv1-xf34.google.com with SMTP id q9so1417698qvm.6 for ; Sun, 14 Mar 2021 14:27:40 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1JDFX+MuUZit7885JaLDSIbe6sMdYH/iLicvWinCUzk=; b=jlluq46nphnEE4tCByl+GaP/Oz4/a37Bv8LMkZuJX1JaNzqXxz2vsi03im2SOBAnAL C+I0+HKs3jPkQb737jge7SlQ8AvIlVjyYrx7CmSSiz3v2uMJqC/s9kN6N/S0Thoys9+m Sizytk4HV5cjwCMJY8ZLf0LzqDeqYKegKbqm6cn0ezh0mY8JMdZDODgthP61V1QoszI4 8Tse0mvAlAzKaRYiQz1PiTzmp1hjLyvGDechEgdQuM6ME5zUut1TejgHSOYXaF+G9GCW +sMbwkBHJJX6C1ZKIXKWpyEDJCEHtZvdVpUYWmPNsEynSWb/gezRF4HIhFnE9Sa91yNr 3/aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1JDFX+MuUZit7885JaLDSIbe6sMdYH/iLicvWinCUzk=; b=DoFWtcmbYWBT/1vCs4ZLJKHzbVTzPugeuZn2SzY8q24osLZpV8WxkScYxP2J/87m6+ NoEkyBvEkXxEUqlBfc8pPa6gZLJm0pH2PS4sgkmT5Kh3fjGN/UXy9V5vCUdSLFI8LxTt Vs7OKvPSsiPUHcIZwQ2rrIQ26TJT4BC0vKjSCe1jOCOjUVU394sE++61HcIQYfMatXbc vJB7wrAl/It4cqEUd1ABXi0faUrABjt5tgKCBPMz4QdBjjyY85LBg7TksnEYC+bVxplC rkQdCIKxBE6ULUO9VOM8q1CDhILyy2Lx63RDsCFnveAcFb20PrR3p7K2qFIX0U5/i1IK afVA== X-Gm-Message-State: AOAM532DOAZaNUfZstEPIcaxyMdPKjuPohyDEIigpJFi8Mhj0ygyeoAW HyT4Sw1l4B5kpet33rTEijMW4yInZ8QExixd X-Google-Smtp-Source: ABdhPJzkQzM1Xst+GFozaT4NeqjCN9hkjSxpzlT4mTVwcDJFvEYVcdwMY5TX/35rg5T/6U/4U1mooA== X-Received: by 2002:a05:6214:80d:: with SMTP id df13mr21956022qvb.55.1615757259733; Sun, 14 Mar 2021 14:27:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 11/29] tcg: Create tcg_init Date: Sun, 14 Mar 2021 15:27:06 -0600 Message-Id: <20210314212724.1917075-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::f34; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf34.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Perform both tcg_context_init and tcg_region_init. Do not leave this split to the caller. Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 3 +-- tcg/internal.h | 1 + accel/tcg/translate-all.c | 3 +-- tcg/tcg.c | 9 ++++++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 7a435bf807..3ad77ec34d 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -874,7 +874,6 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); =20 -void tcg_region_init(size_t tb_size, int splitwx); void tb_destroy(TranslationBlock *tb); void tcg_region_reset_all(void); =20 @@ -907,7 +906,7 @@ static inline void *tcg_malloc(int size) } } =20 -void tcg_context_init(TCGContext *s); +void tcg_init(size_t tb_size, int splitwx); void tcg_register_thread(void); void tcg_prologue_init(TCGContext *s); void tcg_func_start(TCGContext *s); diff --git a/tcg/internal.h b/tcg/internal.h index b1dda343c2..f13c564d9b 100644 --- a/tcg/internal.h +++ b/tcg/internal.h @@ -30,6 +30,7 @@ extern TCGContext **tcg_ctxs; extern unsigned int n_tcg_ctxs; =20 +void tcg_region_init(size_t tb_size, int splitwx); bool tcg_region_alloc(TCGContext *s); void tcg_region_initial_alloc(TCGContext *s); void tcg_region_prologue_set(TCGContext *s); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 4071edda16..050b4bff46 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -920,10 +920,9 @@ static void tb_htable_init(void) void tcg_exec_init(unsigned long tb_size, int splitwx) { tcg_allowed =3D true; - tcg_context_init(&tcg_init_ctx); page_init(); tb_htable_init(); - tcg_region_init(tb_size, splitwx); + tcg_init(tb_size, splitwx); =20 #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and diff --git a/tcg/tcg.c b/tcg/tcg.c index 10a571d41c..65a63bda8a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -576,8 +576,9 @@ static void process_op_defs(TCGContext *s); static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type, TCGReg reg, const char *name); =20 -void tcg_context_init(TCGContext *s) +static void tcg_context_init(void) { + TCGContext *s =3D &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 =3D temp_tcgv_ptr(ts); } =20 +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. --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757580; cv=none; d=zohomail.com; s=zohoarc; b=BACo2rCwSNJy91gVMvjObJHa678uDmy7ZErfD2n6rGqgBkZjrfmbd4A1ragDvXfXU6PsDfeW47N8BS8syNQq+GcYZmdXSU5gDXcCT5MOGKBYy6+bLQv98Wk8BiZdD+6akLwbmSfyqibHzGuBgQ6U6Uu7khH59XFjpFd8eRG38/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757580; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6fDUV0XaBa+zUybCathQxLsZ1yQJyGr4UGBPgHHGORw=; b=csaseeP8K2gI0sUfZnWTttNewSMoEnMGcZZnbMKPHnKpDrQGFscAZieFd7ruVnNaa31FX1N+3nqKh+sxG4bIdxSkXOaR0pOHhWh77wwPv7254FTNN/T0Sx/TgECu9sZ6Se6XPZ0Z7DQ7JfcgJ5+IdSVcyauqUDs1uGbp40IQ45w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757580536478.6010785744038; Sun, 14 Mar 2021 14:33:00 -0700 (PDT) Received: from localhost ([::1]:39836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYM7-00030L-Dt for importer@patchew.org; Sun, 14 Mar 2021 17:32:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH4-00066z-3l for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:46 -0400 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]:42813) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH0-0008Dj-65 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:45 -0400 Received: by mail-qt1-x832.google.com with SMTP id l13so7875378qtu.9 for ; Sun, 14 Mar 2021 14:27:41 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6fDUV0XaBa+zUybCathQxLsZ1yQJyGr4UGBPgHHGORw=; b=QIvcmaKpZKQ/ZRHiFP55X33t6SYtUlBY8skpo5ap4G+IZrC3boWK/Yk2ySPoCeW0ew QhXgqbOTDFzSriE1cOvHzF0g6/2dZ/Rdpx95/I8Fj+b+hIHmQbRVykn//eXa9AwJd2a1 uHuT/5vTe/uJgwO2rNTowgcyTap05z4CcFNZErTQ8LD8ZYdaVjLKMRS9EQw5jeiVhn5n +dpwCA2g4vkl3pTfBgpY+4wSIpd0D/gJ+LgeZzZKcpwPmUozW0SszLBBiGCy8OfNUiFs CbVLTSo4sek6QGD5YKC2vWTqxgyw2LPtoWXwr5UuGUYtuJZ/MO6Jv3TUeFBA+U+apYhN CDrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6fDUV0XaBa+zUybCathQxLsZ1yQJyGr4UGBPgHHGORw=; b=klZlC/DmntZDrCrTPhDzS9UeMnhT9MdHayZvro7ziU12pCp9nHu18Lndt2iPDSGavy +atOXhmLb8IUVj+2Dq5VF8X0S6aYZs4v4jkGASvS025nUNRpcgQqctdjHWn3chXK3im0 TIh3mljMTjoYnUs7rmel7YSUlwrN0nDdnviWGulV9zDZ3JBOmzEnn2E41nO6EtiNkWC/ 9dAQBBwQnkuH0bs0brpCuf4yMoF0FN1KszI+h1a7f1L/vgqREOL0x4DNQ3Hpcs9DeE4l loOHlg6V2jQtE92XQ8wi6G2oCiHIXYzPcYfH2hWNsiVESTf3IJ4v7AflqRRmmNWP+DR0 3O+A== X-Gm-Message-State: AOAM533DTaGd+zpsfEGb36zqz3DQ/eBpXrMFcaKMzb2OoJtaP1UOjPJC YKYAb/TLVpfnwj6mudE56pESY8vt7XCpWENc X-Google-Smtp-Source: ABdhPJwdlRzJqCTV/E6IdrIWUIMxJwZusP+iqulNzDU0w8xdeBHKOyheTnvTq8n3t0sFSi83lhGxQA== X-Received: by 2002:a05:622a:1115:: with SMTP id e21mr282033qty.192.1615757260787; Sun, 14 Mar 2021 14:27:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 12/29] accel/tcg: Merge tcg_exec_init into tcg_init_machine Date: Sun, 14 Mar 2021 15:27:07 -0600 Message-Id: <20210314212724.1917075-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::832; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x832.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There is only one caller, and shortly we will need access to the MachineState, which tcg_init_machine already has. Signed-off-by: Richard Henderson --- accel/tcg/internal.h | 2 ++ include/sysemu/tcg.h | 2 -- accel/tcg/tcg-all.c | 14 +++++++++++++- accel/tcg/translate-all.c | 21 ++------------------- 4 files changed, 17 insertions(+), 22 deletions(-) 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); =20 void QEMU_NORETURN cpu_io_recompile(CPUState *cpu, uintptr_t retaddr); +void page_init(void); +void tb_htable_init(void); =20 #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 =20 -void tcg_exec_init(unsigned long tb_size, int splitwx); - #ifdef CONFIG_TCG extern bool tcg_allowed; #define tcg_enabled() (tcg_allowed) diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index 30d81ff7f5..0e83acbfe5 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -32,6 +32,7 @@ #include "qemu/error-report.h" #include "qemu/accel.h" #include "qapi/qapi-builtin-visit.h" +#include "internal.h" =20 struct TCGState { AccelState parent_obj; @@ -109,8 +110,19 @@ static int tcg_init_machine(MachineState *ms) { TCGState *s =3D TCG_STATE(current_accel()); =20 - tcg_exec_init(s->tb_size * 1024 * 1024, s->splitwx_enabled); + tcg_allowed =3D true; mttcg_enabled =3D 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; } =20 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 050b4bff46..40aeecf611 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -408,7 +408,7 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc= , bool will_exit) return false; } =20 -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] =3D=3D b->page_addr[1]; } =20 -static void tb_htable_init(void) +void tb_htable_init(void) { unsigned int mode =3D QHT_MODE_AUTO_RESIZE; =20 qht_init(&tb_ctx.htable, tb_cmp, CODE_GEN_HTABLE_SIZE, mode); } =20 -/* 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 =3D 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) { --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758544; cv=none; d=zohomail.com; s=zohoarc; b=JVKwojF5rZ/diV2p/g7WqwsZkQdz3++AwrxXiOQv2CLqmEgS+lGnm05wnnWIGfIDvQspn1P2k7B8x+aO5Jga67cTaYgZrnfRmkRrQBEHzrP+XJ/dWH++BXN6PkKa7ckbzii4MV2fSOayEmqVyXbn6cPi6UCPOnnjjRCipH8DNko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758544; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hYFiBy94Dt1+MrJ1IkmuBBfk3yK1g2NK+iH3wafrLbo=; b=HPRNZ//Nez93r3UJwAIGWObAbTcb/BaWNFHk88L6e4PX6uIzcB1uQNiI197pIwlal2GFo5txxSLOxX9ZRYCIkq10YTHx08tKYKnyauEmzgBR7yF5fTq2g6A1y5DVKM4HSe2wLKHY6J0gh8MK5EH0acJtyvoqfOFKQsyXTA5djU8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615758544930974.0459425392406; Sun, 14 Mar 2021 14:49:04 -0700 (PDT) Received: from localhost ([::1]:53942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYbf-0004JY-Ul for importer@patchew.org; Sun, 14 Mar 2021 17:49:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH6-00069l-R9 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:48 -0400 Received: from mail-qv1-xf32.google.com ([2607:f8b0:4864:20::f32]:42956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH0-0008Do-NL for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:47 -0400 Received: by mail-qv1-xf32.google.com with SMTP id 30so6881658qva.9 for ; Sun, 14 Mar 2021 14:27:42 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hYFiBy94Dt1+MrJ1IkmuBBfk3yK1g2NK+iH3wafrLbo=; b=DYXpjVCKfMiEqRFYfs1HPoV8iKdWiJxMefl0CJCugisOQxgL5/kh6ex/O5cvruYJRp j/dLBxrrJ8mSNCItMC82HSjfO/DpFVr733tXt8OHgKjWGhx8az3Zt2yXmUJiCCWQuiGT v0A5fQ0AMPjLvgsr2LT4Ug9ootjCQ5giOgmDjy5qvrPRnRGNR9tOJLxBM1DIDu2FDEQl zvk/tCJs72luLL5CIsC1ZVPLuvfuKxFO5Qq6ulycHjMryCftI4XgKiP6ggbxLBKiVQTD imoMqSh9eLIVTArDWIut1DYaxW8pMR3DM0Q0W0YXA5GSlCq4rMIBl7olOp/ZlJqoxHp2 n7wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hYFiBy94Dt1+MrJ1IkmuBBfk3yK1g2NK+iH3wafrLbo=; b=AA2dde4cyMYOeXiwWhF7Yjca1SXazR3CDjyG8grBSFkDyo7XlNiDvJLsOJU1ucbSkA AoZtPo7d8lsJUSMA5dH+WJO2HnRByorLcXgq1PGFNS5OgFE/QAeFh8/uynkXXv4w1DBZ SM8VOw5QQbE1KyVsIivW4U5ShYp59VjUBZVWv5FikIFEuuDFkD9R+XTooHtvk/btkKdl AGJztxXFWa7jTKo00h2NoFTZNaY38VBd7VdniKRr1rqqnF2zm6fc8ZYWIui3ldDVmRWA d61uJ/spyCzWfillBl1ss5S1TfaR+J1oMJkk/hs3vziZJgJDjtfHhpWf12u4OWkpW59L 9ZCQ== X-Gm-Message-State: AOAM530cpsERQCPc0NPCirYP4OnKPc3EA/jR9Nri9tUCuWjVA7BOU2g7 6sndG9KLFoxTbB4BOnBwuiSDSb5a+bKBDtIQ X-Google-Smtp-Source: ABdhPJy4GP1fQwIQ5pfsZNzRB5tUelIk20yRNhLIfT0I8/BprtjkTpa4t93dIRqrnvkbyADamH6ltg== X-Received: by 2002:ad4:4581:: with SMTP id x1mr7956846qvu.9.1615757261842; Sun, 14 Mar 2021 14:27:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 13/29] accel/tcg: Pass down max_cpus to tcg_init Date: Sun, 14 Mar 2021 15:27:08 -0600 Message-Id: <20210314212724.1917075-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::f32; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Start removing the include of hw/boards.h from tcg/. Pass down the max_cpus value from tcg_init_machine, where we have the MachineState already. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 2 +- tcg/internal.h | 2 +- accel/tcg/tcg-all.c | 10 +++++++++- tcg/region.c | 32 +++++++++++--------------------- tcg/tcg.c | 10 ++++------ 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 3ad77ec34d..a0122c0dd3 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -906,7 +906,7 @@ static inline void *tcg_malloc(int size) } } =20 -void tcg_init(size_t tb_size, int splitwx); +void tcg_init(size_t tb_size, int splitwx, unsigned max_cpus); void tcg_register_thread(void); void tcg_prologue_init(TCGContext *s); void tcg_func_start(TCGContext *s); diff --git a/tcg/internal.h b/tcg/internal.h index f13c564d9b..fcfeca232f 100644 --- a/tcg/internal.h +++ b/tcg/internal.h @@ -30,7 +30,7 @@ extern TCGContext **tcg_ctxs; extern unsigned int n_tcg_ctxs; =20 -void tcg_region_init(size_t tb_size, int splitwx); +void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus); bool tcg_region_alloc(TCGContext *s); void tcg_region_initial_alloc(TCGContext *s); void tcg_region_prologue_set(TCGContext *s); diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index 0e83acbfe5..d2f2ddb844 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -32,6 +32,9 @@ #include "qemu/error-report.h" #include "qemu/accel.h" #include "qapi/qapi-builtin-visit.h" +#if !defined(CONFIG_USER_ONLY) +#include "hw/boards.h" +#endif #include "internal.h" =20 struct TCGState { @@ -109,13 +112,18 @@ bool mttcg_enabled; static int tcg_init_machine(MachineState *ms) { TCGState *s =3D TCG_STATE(current_accel()); +#ifdef CONFIG_USER_ONLY + unsigned max_cpus =3D 1; +#else + unsigned max_cpus =3D ms->smp.max_cpus; +#endif =20 tcg_allowed =3D true; mttcg_enabled =3D s->mttcg_enabled; =20 page_init(); tb_htable_init(); - tcg_init(s->tb_size * 1024 * 1024, s->splitwx_enabled); + tcg_init(s->tb_size * 1024 * 1024, s->splitwx_enabled, max_cpus); =20 #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and diff --git a/tcg/region.c b/tcg/region.c index 8d88144a22..04b699da63 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -27,9 +27,6 @@ #include "qapi/error.h" #include "exec/exec-all.h" #include "tcg/tcg.h" -#if !defined(CONFIG_USER_ONLY) -#include "hw/boards.h" -#endif #include "internal.h" =20 =20 @@ -366,27 +363,20 @@ void tcg_region_reset_all(void) tcg_region_tree_reset_all(); } =20 +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 regio= ns + * being of reasonable size. If that's not possible we make do by even= ly + * dividing the code_gen_buffer among the vCPUs. + */ size_t i; =20 /* Use a single region if all we have is one vCPU thread */ -#if !defined(CONFIG_USER_ONLY) - MachineState *ms =3D MACHINE(qdev_get_machine()); - unsigned int max_cpus =3D ms->smp.max_cpus; -#endif if (max_cpus =3D=3D 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 +} =20 /* Minimum size of the code gen buffer. This number is randomly chosen, but not so small that we can't have a fair number of TB's live. */ @@ -838,7 +828,7 @@ static bool alloc_code_gen_buffer(size_t size, int spli= twx, Error **errp) * in practice. Multi-threaded guests share most if not all of their trans= lated * code, which makes parallel code generation less appealing than in softm= mu. */ -void tcg_region_init(size_t tb_size, int splitwx) +void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) { void *buf, *aligned; size_t size; @@ -856,7 +846,7 @@ void tcg_region_init(size_t tb_size, int splitwx) buf =3D tcg_init_ctx.code_gen_buffer; size =3D tcg_init_ctx.code_gen_buffer_size; page_size =3D qemu_real_host_page_size; - n_regions =3D tcg_n_regions(); + n_regions =3D tcg_n_regions(max_cpus); =20 /* The first region will be 'aligned - buf' bytes larger than the othe= rs */ aligned =3D QEMU_ALIGN_PTR_UP(buf, page_size); diff --git a/tcg/tcg.c b/tcg/tcg.c index 65a63bda8a..a89d8f6b81 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -576,7 +576,7 @@ static void process_op_defs(TCGContext *s); static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type, TCGReg reg, const char *name); =20 -static void tcg_context_init(void) +static void tcg_context_init(unsigned max_cpus) { TCGContext *s =3D &tcg_init_ctx; int op, total_args, n, i; @@ -645,8 +645,6 @@ static void tcg_context_init(void) tcg_ctxs =3D &tcg_ctx; n_tcg_ctxs =3D 1; #else - MachineState *ms =3D MACHINE(qdev_get_machine()); - unsigned int max_cpus =3D ms->smp.max_cpus; tcg_ctxs =3D g_new(TCGContext *, max_cpus); #endif =20 @@ -655,10 +653,10 @@ static void tcg_context_init(void) cpu_env =3D temp_tcgv_ptr(ts); } =20 -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); } =20 /* --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757578; cv=none; d=zohomail.com; s=zohoarc; b=l7m8pK/Ni1UEIZt1VYx6RIblD12jmsubIG2POt5ii/OLojWbjdIukWsKYOsTsAQRXrzaIN7kYAg06rTiT55TcyVLcsYaRN6QoP2sbhSYwuMOHUKlsj2q8LuU1+oOISd5nXw8KaWBQg1FHNVsAX3ibmWI7IlSSOHUA0JiiR/QH6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757578; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OlLc/LhYExyFieSM8eoDWZSL5lD1vPrcLRLDLT+veX8=; b=Ycl4zZSAx8ZBJ83a7eDQmxxE9wbMsLUYMS41T1xoXdCHmdBNTJq+c/eazAN4gJcgDaO4WxqMmg7YZiEqdJzaqWEjqpDIRdf7cdGeAwVy4SUI49YCEyED5eHoiVIuQYMp7mBHssjmPzDS+ZMAjI4szknZTLGrdebvGGu6ftBsDAY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757578344448.22398089754176; Sun, 14 Mar 2021 14:32:58 -0700 (PDT) Received: from localhost ([::1]:39604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYM5-0002uZ-9D for importer@patchew.org; Sun, 14 Mar 2021 17:32:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH4-00067l-Em for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:46 -0400 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]:44585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH1-0008EX-Ol for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:45 -0400 Received: by mail-qt1-x82b.google.com with SMTP id m7so7862638qtq.11 for ; Sun, 14 Mar 2021 14:27:43 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OlLc/LhYExyFieSM8eoDWZSL5lD1vPrcLRLDLT+veX8=; b=J2f0MnHDCT5W3lGBHZmvGxJeHT1aWZsaiZFcRCamquPJVqzS6LGt5tfLfcmKhrhBcc 3V2RtJzRxzrBwRMPSAe8eAYLRlBtqjPIdFOORR6CSxS79OudNQgcSdYCDeR6fNb1SZKK /Eaj0xSvjNR9tEab6DiONLvOrgIDUIgoep/ot04IFdU6HFz305eMekuYFJ8yScuIPu1f yExffI+3KlmehT/OPJqZC3x0orhDuXykyDT/+w64ybJ4FJ9ZEyu3F6QMYNzUKbzH+9zt wI/TegvVPQlcgX65n/UldxM8Sn5b/1rXMtfCL1328YGzxNYngblln5hp60Dtj2vJKYWL ypqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OlLc/LhYExyFieSM8eoDWZSL5lD1vPrcLRLDLT+veX8=; b=ZAGNWyrm4jUBRem76BFMRACYlXJrhs3nf+JxgQuFrhz7V1IYm2oCL1UJEDkzKBQc+r VRLZzM8GnifxWE8QJbErLiRb7wluiqasmPmGD9/ytBt6Uaq+2z3abHDk2mgoGgWPeZQY lDZXorE/Zw+yor3+M6nDBG0FDWN9XqekZ40mOjVRtaZDGNJFo0UQHfmnodzirBnutmzZ QGYT66+vtLKX7lMjqYiPTrv6eKSs/XotFKaA+E73LymKqtcqeLdABCuagr/dw1ve4jDw qwJ2vTSQc7yzN+mZZrY7P/Bl9Os351JaQxtWRHbNhbBL3XPhYf9Q5qc3kZw2MtnT26Eb 9ODw== X-Gm-Message-State: AOAM533id7T3mdfoRvxUn056M8+a/BZSlakwKpi6Uaj7YpojSrKl5t47 dO5onSGMslNLYHYlRWGW2JGzuZ7WuBX/5iQn X-Google-Smtp-Source: ABdhPJxKuoW9lpw34+vnh1T3iqvABZ5VvpuwTvdAypmHFTPjlgWYrmjJU1lt/4pU2Ito4qfOndDc1Q== X-Received: by 2002:ac8:43d6:: with SMTP id w22mr19539386qtn.283.1615757262905; Sun, 14 Mar 2021 14:27:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 14/29] tcg: Introduce tcg_max_ctxs Date: Sun, 14 Mar 2021 15:27:09 -0600 Message-Id: <20210314212724.1917075-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::82b; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x82b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Finish the divorce of tcg/ from hw/, and do not take the max cpu value from MachineState; just remember what we were passed in tcg_init. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- tcg/internal.h | 3 ++- tcg/region.c | 6 +++--- tcg/tcg.c | 23 ++++++++++------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/tcg/internal.h b/tcg/internal.h index fcfeca232f..f9906523da 100644 --- a/tcg/internal.h +++ b/tcg/internal.h @@ -28,7 +28,8 @@ #define TCG_HIGHWATER 1024 =20 extern TCGContext **tcg_ctxs; -extern unsigned int n_tcg_ctxs; +extern unsigned int tcg_cur_ctxs; +extern unsigned int tcg_max_ctxs; =20 void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus); bool tcg_region_alloc(TCGContext *s); diff --git a/tcg/region.c b/tcg/region.c index 04b699da63..e3fbf6a7e7 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -347,7 +347,7 @@ void tcg_region_initial_alloc(TCGContext *s) /* Call from a safe-work context */ void tcg_region_reset_all(void) { - unsigned int n_ctxs =3D qatomic_read(&n_tcg_ctxs); + unsigned int n_ctxs =3D qatomic_read(&tcg_cur_ctxs); unsigned int i; =20 qemu_mutex_lock(®ion.lock); @@ -922,7 +922,7 @@ void tcg_region_prologue_set(TCGContext *s) */ size_t tcg_code_size(void) { - unsigned int n_ctxs =3D qatomic_read(&n_tcg_ctxs); + unsigned int n_ctxs =3D qatomic_read(&tcg_cur_ctxs); unsigned int i; size_t total; =20 @@ -958,7 +958,7 @@ size_t tcg_code_capacity(void) =20 size_t tcg_tb_phys_invalidate_count(void) { - unsigned int n_ctxs =3D qatomic_read(&n_tcg_ctxs); + unsigned int n_ctxs =3D qatomic_read(&tcg_cur_ctxs); unsigned int i; size_t total =3D 0; =20 diff --git a/tcg/tcg.c b/tcg/tcg.c index a89d8f6b81..a82d3a0861 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -44,11 +44,6 @@ #include "cpu.h" =20 #include "exec/exec-all.h" - -#if !defined(CONFIG_USER_ONLY) -#include "hw/boards.h" -#endif - #include "tcg/tcg-op.h" =20 #if UINTPTR_MAX =3D=3D UINT32_MAX @@ -155,7 +150,8 @@ static int tcg_out_ldst_finalize(TCGContext *s); #endif =20 TCGContext **tcg_ctxs; -unsigned int n_tcg_ctxs; +unsigned int tcg_cur_ctxs; +unsigned int tcg_max_ctxs; TCGv_env cpu_env =3D 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 =3D MACHINE(qdev_get_machine()); TCGContext *s =3D g_malloc(sizeof(*s)); unsigned int i, n; =20 @@ -491,8 +486,8 @@ void tcg_register_thread(void) } =20 /* Claim an entry in tcg_ctxs */ - n =3D qatomic_fetch_inc(&n_tcg_ctxs); - g_assert(n < ms->smp.max_cpus); + n =3D qatomic_fetch_inc(&tcg_cur_ctxs); + g_assert(n < tcg_max_ctxs); qatomic_set(&tcg_ctxs[n], s); =20 if (n > 0) { @@ -643,9 +638,11 @@ static void tcg_context_init(unsigned max_cpus) */ #ifdef CONFIG_USER_ONLY tcg_ctxs =3D &tcg_ctx; - n_tcg_ctxs =3D 1; + tcg_cur_ctxs =3D 1; + tcg_max_ctxs =3D 1; #else - tcg_ctxs =3D g_new(TCGContext *, max_cpus); + tcg_max_ctxs =3D max_cpus; + tcg_ctxs =3D g_new0(TCGContext *, max_cpus); #endif =20 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 =3D qatomic_read(&n_tcg_ctxs); + unsigned int n_ctxs =3D qatomic_read(&tcg_cur_ctxs); unsigned int i; =20 for (i =3D 0; i < n_ctxs; i++) { @@ -4000,7 +3997,7 @@ void tcg_dump_op_count(void) =20 int64_t tcg_cpu_exec_time(void) { - unsigned int n_ctxs =3D qatomic_read(&n_tcg_ctxs); + unsigned int n_ctxs =3D qatomic_read(&tcg_cur_ctxs); unsigned int i; int64_t ret =3D 0; =20 --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757703; cv=none; d=zohomail.com; s=zohoarc; b=cIOPH9T2XhqVd7+ojra1kK2mOpctmC6Jr9WHxD7pPkO9e+L+IFalvPW/X4jVnP0qJfKuQ6DnfPRp3CVwrWehp6BOBkXHk03vGEBh23oqUGW+iV2e2+C7wAfxqjiNME3+i6J5qllOCrJ102p6pI71yXB5vE+Pu+VcBX0K2LQzlSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757703; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wTdpZA//9mM13rTDthBtwAtIDEdfj+iL3ziTKOJ9PhY=; b=JjzLtnJkjjCpHYXnU+XLl3O3ObTPhwFt2tatzWdaLEFWUQIlnR3L477ot720N2qeaNsGH/RBRX113SS4sxjAz+2iTMl1dmVBeO92J8I4Mv6t8qV2u0g8I+41EsF0vGsSF6JleYZFHmrV0etTH5cxxoBLj7jU3J9TQJRx7ss5epY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757703343432.7603203802911; Sun, 14 Mar 2021 14:35:03 -0700 (PDT) Received: from localhost ([::1]:48050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYO6-0006P8-6Q for importer@patchew.org; Sun, 14 Mar 2021 17:35:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH5-00069j-Qn for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:48 -0400 Received: from mail-qv1-xf2d.google.com ([2607:f8b0:4864:20::f2d]:43620) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH2-0008Eh-PK for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:46 -0400 Received: by mail-qv1-xf2d.google.com with SMTP id cx5so6872619qvb.10 for ; Sun, 14 Mar 2021 14:27:44 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wTdpZA//9mM13rTDthBtwAtIDEdfj+iL3ziTKOJ9PhY=; b=U/oMvNQObUmc4BNyK+I42l5cKnXwmFQY1qu62hmCiMTfFjmfvfnfHVIE+2DrEOifZH qbYG0WtAI79f3n1hASrDhwRhQCbk+DFgLZlTLvA9ZaKwfarU890OgNcnPRphAu9vXlkm gU3sPTgDAg753rHSi6QReMhx90e413XYqn0nqs/tmpFbEOMdp8l1WPV8C1JEGdhN6J7U 1YaYZoewX/hETJomDhYTr3gZi/F1nyr2lg+IS6D4nvNTyGAyUtDvg/ir76Uq1gq/Igek tA11bRu4Cd/Gq4ZEAACRR0vGzzTLVcRFDefTBsrNGcnzfQ0W6Oh1BApFy2L+7OK+2yFw lVoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wTdpZA//9mM13rTDthBtwAtIDEdfj+iL3ziTKOJ9PhY=; b=DAov+meqiFHUTIERzY0UgJdUvtsz2N9k2g5zeESF9qXuW5J1JuBP7ov4+8fJ1C5yYp 3iCzGVA5magZuFeN/auwTJmILw1IpjOOzQ/0Vej+fjUysiUnZ1ufmYuF68Y3WyqHcuyS ctKe5q61WA7uu8WPTrRlg8VeXiF7qlIwaOlM9cQKFuiufv17/idp6tCX8AG2GM37PXku MQZO1eyTUgWiIrBe3HtV2OckovTq/oGLDlteZWMlgUrCmKzvOxA1kL77mpsLUa2SuG/I IjOnNZ7WFXeg5aqWKO8GWKt60ovzduZwrkTQm+XCOkRHC9B0oFNOpFzHfzDCZ9cD+1Qt h4bA== X-Gm-Message-State: AOAM533GQiFsoF4ZfL7WiY46WLu4/79hTeebYsISuIc6N+aUytSJbxYL VgXF5W/twYEuK1r7cxf6dMtB+HI+9bJkWBsd X-Google-Smtp-Source: ABdhPJwOnk0j0fA5AuDm7eUdFZLshdjzNWyFbmfDnRlYiVw+G+vvCbbLFzUFLOZjYwkhdfqEWT1gUg== X-Received: by 2002:a05:6214:20ed:: with SMTP id 13mr7947461qvk.34.1615757263895; Sun, 14 Mar 2021 14:27:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 15/29] tcg: Move MAX_CODE_GEN_BUFFER_SIZE to tcg-target.h Date: Sun, 14 Mar 2021 15:27:10 -0600 Message-Id: <20210314212724.1917075-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::f2d; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove the ifdef ladder and move each define into the appropriate header file. Signed-off-by: Richard Henderson --- v2: Retain comment about M_C_G_B_S constraint (balaton) --- tcg/aarch64/tcg-target.h | 1 + tcg/arm/tcg-target.h | 1 + tcg/i386/tcg-target.h | 2 ++ tcg/mips/tcg-target.h | 6 ++++++ tcg/ppc/tcg-target.h | 2 ++ tcg/riscv/tcg-target.h | 1 + tcg/s390/tcg-target.h | 3 +++ tcg/sparc/tcg-target.h | 1 + tcg/tci/tcg-target.h | 1 + tcg/region.c | 35 +++++++++-------------------------- 10 files changed, 27 insertions(+), 26 deletions(-) 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 @@ =20 #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 =20 typedef enum { diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h index 8d1fee6327..b9a85d0f83 100644 --- a/tcg/arm/tcg-target.h +++ b/tcg/arm/tcg-target.h @@ -60,6 +60,7 @@ extern int arm_arch; #undef TCG_TARGET_STACK_GROWSUP #define TCG_TARGET_INSN_UNIT_SIZE 4 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 16 +#define MAX_CODE_GEN_BUFFER_SIZE UINT32_MAX =20 typedef enum { TCG_REG_R0 =3D 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 =20 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 =20 +/* + * 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 =3D 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 @@ =20 #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 =20 #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) =20 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 =20 +/* 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 =3D 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) =20 typedef enum { TCG_REG_G0 =3D 0, diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h index 9c0021a26f..03cf527cb4 100644 --- a/tcg/tci/tcg-target.h +++ b/tcg/tci/tcg-target.h @@ -43,6 +43,7 @@ #define TCG_TARGET_INTERPRETER 1 #define TCG_TARGET_INSN_UNIT_SIZE 1 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 32 +#define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) =20 #if UINTPTR_MAX =3D=3D UINT32_MAX # define TCG_TARGET_REG_BITS 32 diff --git a/tcg/region.c b/tcg/region.c index e3fbf6a7e7..ae22308290 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -398,34 +398,17 @@ static size_t tcg_n_regions(unsigned max_cpus) #endif } =20 -/* Minimum size of the code gen buffer. This number is randomly chosen, - but not so small that we can't have a fair number of TB's live. */ +/* + * Minimum size of the code gen buffer. This number is randomly chosen, + * but not so small that we can't have a fair number of TB's live. + * + * Maximum size, MAX_CODE_GEN_BUFFER_SIZE, is defined in tcg-target.h. + * Unless otherwise indicated, this is constrained by the range of + * direct branches on the host cpu, as used by the TCG implementation + * of goto_tb. + */ #define MIN_CODE_GEN_BUFFER_SIZE (1 * MiB) =20 -/* 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 =3D=3D 32 #define DEFAULT_CODE_GEN_BUFFER_SIZE_1 (32 * MiB) #ifdef CONFIG_USER_ONLY --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758862; cv=none; d=zohomail.com; s=zohoarc; b=G2GrJDLtzUfi/XpNMe3yxwjKZi47bUzk5JVgZzl0eLQHaCcMAoeYtustLdZCVxUfxTzUAUemo3CV1vn6U/B0Ky7412sDxn66p/pIIjBz/zPEwuYCDdX8izCRm/6eXiWGI0TrAG5oq+ZM6zqCGAi5ADS9Bdtg25YUyPpKVbsw0n8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758862; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cCuL+0Cr0Nxn0ond/pgRLvEba3AtjzB4cSKYgtHeHws=; b=IA9+J2lYBo1JnSvCYhxCBnG5XfZlfmBjPlD4b3gJ1aKAcRGtvdDnmZPH4dQ2cvaRS3hATjb2yRZnVNcriPf8X6Exg2CguAzZM60RaoyFJGQExnfcF3uxlakBVNJpBJtvd3JVFEBL6V3w5vc7wNaxzCjF9iHkIPLSpJQdDFoynK4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161575886261312.81327777354818; Sun, 14 Mar 2021 14:54:22 -0700 (PDT) Received: from localhost ([::1]:60942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYgn-0007dk-Jn for importer@patchew.org; Sun, 14 Mar 2021 17:54:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH9-0006Bz-Au for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:51 -0400 Received: from mail-qk1-x734.google.com ([2607:f8b0:4864:20::734]:43187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH3-0008FN-TZ for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:50 -0400 Received: by mail-qk1-x734.google.com with SMTP id b130so29890131qkc.10 for ; Sun, 14 Mar 2021 14:27:45 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cCuL+0Cr0Nxn0ond/pgRLvEba3AtjzB4cSKYgtHeHws=; b=czkvbfTBUnwW/ScjIkq8zyezdsj/aif2NiRQFji6uiQUVHhRqMBZxsmLtVpo0eFlG7 2L0FsnvP09dSc6s9aweOr65WpM71H0pwtVXCoBBbrRQlyKHvI2/Fx9mUqm5B2HCtpHXZ D02U0MA+sI7C6UeAUnFQP98i72VRtI7rQLlB+YiEN+Ge+bQj9+kCe30LjUXqkHha83FQ ia799cvCfvxzH9/MjC3jbPia7MSYF+9hwKQk41fJwzYEatXLT3AqWe+Vt7UuGYjXzi/w lQ1R+ecmwovuk3/jFUOkrnAnWMn/6N2uzq9uc5GP9GG+5ObERzb1/E+z8EjD/N8BBoPl /MjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cCuL+0Cr0Nxn0ond/pgRLvEba3AtjzB4cSKYgtHeHws=; b=GCBtBJixaGFp9Q6FktCr0u3d2Gt1OSh2fmjls8jxtJA2lT0IENCIHR3JYWdZdme4VJ aNvdg5t+n97lBL/Ih6S+QGD0/QTr74NqRNpXaa+3N87J4jXHYR+tZ0XD2+wY+P4MoMHH Rm5TFWXxLqVlbgW+QgnHZO7pxuGPOPThG8Nc3GGGiqPGZufXPzGqM9w47Ne3blmGm5Og a6xSlzdlrZwGSexYR4sfQilkoKQ/pqmrO943EUYew0lP29vB3Zdip/jymPA7EMo6Y6dA rRoKs8PW8DnN4EaXsaHaCY8Yal5PELZFeE6TuXixpg+xB0TAwb4ayuSCuQB7YV+l/HHW mAGw== X-Gm-Message-State: AOAM5332M/FJ82JoDWEModS0gUZxHL8+cCphYfOiAX8tp/oEcTqmcFXq uuA1IjZZkb/lC5LdLIIWtCfIhmtXTdmup7W9 X-Google-Smtp-Source: ABdhPJxcf27vhg3+wKc99eklNOWAs6vXjS83KU407qfv45l22m/U4e2mHRuNTPhS/fY17y7Q/D1QMA== X-Received: by 2002:a05:620a:1353:: with SMTP id c19mr23065731qkl.392.1615757264880; Sun, 14 Mar 2021 14:27:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 16/29] tcg: Replace region.end with region.total_size Date: Sun, 14 Mar 2021 15:27:11 -0600 Message-Id: <20210314212724.1917075-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::734; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x734.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" A size is easier to work with than an end point, particularly during initial buffer allocation. Signed-off-by: Richard Henderson --- tcg/region.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index ae22308290..8e4dd0480b 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -48,7 +48,7 @@ struct tcg_region_state { /* fields set at init time */ void *start; void *start_aligned; - void *end; + size_t total_size; /* size of entire buffer */ size_t n; size_t size; /* size of one region */ size_t stride; /* .size + guard size */ @@ -279,7 +279,7 @@ static void tcg_region_bounds(size_t curr_region, void = **pstart, void **pend) start =3D region.start; } if (curr_region =3D=3D region.n - 1) { - end =3D region.end; + end =3D region.start_aligned + region.total_size; } =20 *pstart =3D start; @@ -813,8 +813,8 @@ static bool alloc_code_gen_buffer(size_t size, int spli= twx, Error **errp) */ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) { - void *buf, *aligned; - size_t size; + void *buf, *aligned, *end; + size_t total_size; size_t page_size; size_t region_size; size_t n_regions; @@ -827,19 +827,20 @@ void tcg_region_init(size_t tb_size, int splitwx, uns= igned max_cpus) assert(ok); =20 buf =3D tcg_init_ctx.code_gen_buffer; - size =3D tcg_init_ctx.code_gen_buffer_size; + total_size =3D tcg_init_ctx.code_gen_buffer_size; page_size =3D qemu_real_host_page_size; n_regions =3D tcg_n_regions(max_cpus); =20 /* The first region will be 'aligned - buf' bytes larger than the othe= rs */ aligned =3D 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 star= t. * As a result of this we might end up with a few extra pages at the e= nd of * the buffer; we will assign those to the last region. */ - region_size =3D (size - (aligned - buf)) / n_regions; + region_size =3D (total_size - (aligned - buf)) / n_regions; region_size =3D QEMU_ALIGN_DOWN(region_size, page_size); =20 /* A region must have at least 2 pages; one code, one guard */ @@ -853,9 +854,11 @@ void tcg_region_init(size_t tb_size, int splitwx, unsi= gned max_cpus) region.start =3D buf; region.start_aligned =3D aligned; /* page-align the end, since its last page will be a guard page */ - region.end =3D QEMU_ALIGN_PTR_DOWN(buf + size, page_size); + end =3D QEMU_ALIGN_PTR_DOWN(buf + total_size, page_size); /* account for that last guard page */ - region.end -=3D page_size; + end -=3D page_size; + total_size =3D end - aligned; + region.total_size =3D total_size; =20 /* set guard pages */ splitwx_diff =3D tcg_splitwx_diff; @@ -893,7 +896,7 @@ void tcg_region_prologue_set(TCGContext *s) =20 /* 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.sta= rt); } =20 /* @@ -934,8 +937,10 @@ size_t tcg_code_capacity(void) =20 /* no need for synchronization; these variables are set at init time */ guard_size =3D region.stride - region.size; - capacity =3D region.end + guard_size - region.start; - capacity -=3D region.n * (guard_size + TCG_HIGHWATER); + capacity =3D region.total_size; + capacity -=3D (region.n - 1) * guard_size; + capacity -=3D region.n * TCG_HIGHWATER; + return capacity; } =20 --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757701; cv=none; d=zohomail.com; s=zohoarc; b=JNj3gUga7hqII6D7vXvVcTprAIZcfhYQDQZX3RkUshjt8352e6MJlwZGRV33jwXeJJ+a8PcIuGoIfDuVD9KO9/s1dJQ+G2VRKlG8/rjf38RAh95JsKNLSv565M7ax7BIBsM2tOtGJ8S3EUapAku680uYBUGJ7oZsXjiCcbqjTRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757701; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sT6m1DvpyLSK/jDOR0ljz9XPvbGUXpvhChthbdvn53o=; b=G5owcYx7EdytwuB+0582++adHHi//DQIuNwDO8+VbINRTSTfNRJYwAblMiEgaGWNQ3H9GmXtWrqq26v1Y50eeBMuxIkVzonFmQiGHUVkY94VXErDrgz1CH/jxOuUK8ojrrRjN6wyz9TcgWwN7+ws6nLLeGadjhe95A1iEXfqEck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757701158192.6188215622634; Sun, 14 Mar 2021 14:35:01 -0700 (PDT) Received: from localhost ([::1]:47840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYO3-0006Jx-UD for importer@patchew.org; Sun, 14 Mar 2021 17:34:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH7-0006Af-8X for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:50 -0400 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]:44253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH4-0008FX-UY for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:48 -0400 Received: by mail-qk1-x72b.google.com with SMTP id 130so29879780qkh.11 for ; Sun, 14 Mar 2021 14:27:46 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sT6m1DvpyLSK/jDOR0ljz9XPvbGUXpvhChthbdvn53o=; b=IeOquCASz++uCfIdkVxgpsokUq3b6/XFmUwxxHnNoDlD/Keo8t8Aupy+esjdmvOxPK k1qLAeD9nKE2Udc3HW41gY499a+FF7kKTu89jC1qfcFA6syooUgYg8tXClPWDND+yeQc t3n3sXxb+hwEqyggy9aw6VSth3q7wZpdFOPioZPmsSdSGCLHQX8/GESD7Kty0YC+Ph7x JjngljYuHVyysLmCb2AcPkuxUYhrgZGoa8zLo/zSA9x2UW6c1xgNhKP4p+a4OnmUhEii wj1/+1y6GtUgxkb2rfBuc9OOM7tcV1AXgJsY+7csl4qPuBpluO+YCHqnDShhqx8O2TYC jwwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sT6m1DvpyLSK/jDOR0ljz9XPvbGUXpvhChthbdvn53o=; b=nIVrWcOxipi+Mo/H+Fl9z/+dUT+wYyCMTXedb9l34zobkxHQOawEYRd8Ir8uUK7zHf oGM/an0cTwdhX1i7BaGDJKMMrftiI8/q+RYRzDGZY5edipKzFoOVzBh/qYHhOSj01gtq 7U7bdtt+UY66yID1ZLRo+wBDwxAFEW/2nUPeVGtd0dZLHskBpaTrZWxYFDSe308udjUY k4oexXfiISiJ0iJgo0s2LkllT4Qg3bF76Le1tAh7sGg+le0TSTfCWHvAPsIAOSLYDAVP 2Bxt5BMqEmlplw8sqQlZMigwMQf1SEwxXVQppwWpiRDe2qFMIP/vzZ2Z6SXLRW8J0ghH A5uw== X-Gm-Message-State: AOAM531tBWE5SyU+E+iqEMC6RowHqFtAzER1tsoHXW8R6dLlW+3XIM4d F/SOAimX65ECGeFhFE8gnfFzNIwGkum4yZHA X-Google-Smtp-Source: ABdhPJz2qk/nm4DqEav8rl8SKLbeZdZtz7x70fefLczJYoApEwyMau8xFljjggHxFr3GE2M4OsBuJw== X-Received: by 2002:a05:620a:14f:: with SMTP id e15mr22266912qkn.315.1615757265954; Sun, 14 Mar 2021 14:27:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 17/29] tcg: Rename region.start to region.after_prologue Date: Sun, 14 Mar 2021 15:27:12 -0600 Message-Id: <20210314212724.1917075-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72b; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Give the field a name reflecting its actual meaning. Signed-off-by: Richard Henderson --- tcg/region.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 8e4dd0480b..23261561a1 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -46,8 +46,8 @@ struct tcg_region_state { QemuMutex lock; =20 /* fields set at init time */ - void *start; void *start_aligned; + void *after_prologue; size_t total_size; /* size of entire buffer */ size_t n; size_t size; /* size of one region */ @@ -276,7 +276,7 @@ static void tcg_region_bounds(size_t curr_region, void = **pstart, void **pend) end =3D start + region.size; =20 if (curr_region =3D=3D 0) { - start =3D region.start; + start =3D region.after_prologue; } if (curr_region =3D=3D region.n - 1) { end =3D region.start_aligned + region.total_size; @@ -851,7 +851,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsig= ned max_cpus) region.n =3D n_regions; region.size =3D region_size - page_size; region.stride =3D region_size; - region.start =3D buf; + region.after_prologue =3D buf; region.start_aligned =3D aligned; /* page-align the end, since its last page will be a guard page */ end =3D QEMU_ALIGN_PTR_DOWN(buf + total_size, page_size); @@ -888,15 +888,16 @@ void tcg_region_init(size_t tb_size, int splitwx, uns= igned max_cpus) void tcg_region_prologue_set(TCGContext *s) { /* Deduct the prologue from the first region. */ - g_assert(region.start =3D=3D s->code_gen_buffer); - region.start =3D s->code_ptr; + g_assert(region.start_aligned =3D=3D s->code_gen_buffer); + region.after_prologue =3D s->code_ptr; =20 /* Recompute boundaries of the first region. */ tcg_region_assign(s, 0); =20 /* Register the balance of the buffer with gdb. */ - tcg_register_jit(tcg_splitwx_to_rx(region.start), - region.start_aligned + region.total_size - region.sta= rt); + tcg_register_jit(tcg_splitwx_to_rx(region.after_prologue), + region.start_aligned + region.total_size - + region.after_prologue); } =20 /* --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758629; cv=none; d=zohomail.com; s=zohoarc; b=fBvmnm09VtlT27WaJKIvGsvw0gU5Y1dmdEO5no++OnUvPEAMDMISsbBLYXasUmIoJjledUl9bVDs2+JCrg6AARK2KtFKLWwYGBaLkO/jS798PXzBNb+XUKzc9WEA7Y1gWlnP9DQUqG1yA8aEKPDJY4dz51m9yfCvRh/jlrvw+oY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758629; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dKl3plwM0T4wQ2XEJ99rVXo5h1hjm+9QWf83bPhdblE=; b=eNW3DvUfJ3bWxJtOUqxV5xAR613rjeGKsiYkhgkptm+0xLChvyl/NFryIRCazMLnkMf+K83ot15inCssfyY41f+tewy6C7O1Z1yOVPPLCd0LGt7D3bpMGtSwTJa43C6txa4Z8Mcom13+0ErKlr3DBCwX2OWPtOTFk5bKCQUHo1w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615758629865984.8668829882682; Sun, 14 Mar 2021 14:50:29 -0700 (PDT) Received: from localhost ([::1]:56128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYd0-0005F0-OE for importer@patchew.org; Sun, 14 Mar 2021 17:50:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH8-0006BH-6w for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:50 -0400 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:46668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH6-0008Fy-HS for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:49 -0400 Received: by mail-qk1-x72a.google.com with SMTP id a9so29868593qkn.13 for ; Sun, 14 Mar 2021 14:27:47 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dKl3plwM0T4wQ2XEJ99rVXo5h1hjm+9QWf83bPhdblE=; b=UZsDacHJ4pECD/381oH/pFqrUGiK9d6goWxrumgVIsyCtFxOlC3wNh5kcocFv3sl8L LQT9mzBDDwPjZsZzNzRr6SJA6OA0PXuvjOu+8s/Nyyo5YJLJ+OvDvVeTjAtKPgENH9BV 1byZW/SkjlPtblJwN52tCDvWFxonfhFjIGcGdZaIhhux7egXUFomeLgDzMBx4S2QCaya IWC6pesfozYHhG5tb+XCM6vMeD458/HL7Txv6GHchrRMFt0pxGzNuTEzVsDdMufRZW38 YafFR1BGF7WubLYSkZQ6FoEEu3+H1IB1RwTg0cum9aotQOjB2ZF3UwTAwC/XEZJKEptP Je5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dKl3plwM0T4wQ2XEJ99rVXo5h1hjm+9QWf83bPhdblE=; b=RnxHfTciWonpI+b3lNUKlPpREW2V14GxyuVdKd+FWqXnUb1/sGYugUArXyF9K7Z+I+ tfV49hNKELN0kcNnQBqh9e1pUswKhvLAg7qEyjYw8uLrNKNwRI6KO4opLpsZAGYzvZLb NGoewBOwRJfIookFjxfmJrtS6dYAzKQHcel6JIeWcB6TmJm21ZeYOHtR7p4UHE+6D1sj TYXg0HLgCTHUmeeq1JlxtmLw5uXIBoPqIT083EK23FqbgaZzTFEsB54E+q0Ulvnm8fyr NpsfARjpF5KM4UF8gQppU8JD0TWEODpPhAzXDv0UURGdLrkpTzUA+vKBrNl4+u0+WtW+ tqBw== X-Gm-Message-State: AOAM531Km86NgASHyaH/NAv7ANlo6jRp5VQKkk8ZZnKPlt+u6B+bhR3p IYRW3w8oGcBdiKLV1Z3Dcl+wz32HDJdE2U3n X-Google-Smtp-Source: ABdhPJx39ffIFwb8DWAZoIzoRZj0Rzyw+P3poZEa3xTIYVtbFczoOCXkRjwlXw8Ba6XbeYbys4P7eg== X-Received: by 2002:a05:620a:414e:: with SMTP id k14mr23558721qko.243.1615757267024; Sun, 14 Mar 2021 14:27:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 18/29] tcg: Tidy tcg_n_regions Date: Sun, 14 Mar 2021 15:27:13 -0600 Message-Id: <20210314212724.1917075-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Compute the value using straight division and bounds, rather than a loop. Pass in tb_size rather than reading from tcg_init_ctx.code_gen_buffer_size, Signed-off-by: Richard Henderson --- tcg/region.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 23261561a1..23b3459c61 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -363,38 +363,33 @@ void tcg_region_reset_all(void) tcg_region_tree_reset_all(); } =20 -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 regio= ns * being of reasonable size. If that's not possible we make do by even= ly * 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 =3D=3D 1 || !qemu_tcg_mttcg_enabled()) { return 1; } =20 - /* Try to have more regions than max_cpus, with each region being >=3D= 2 MB */ - for (i =3D 8; i > 0; i--) { - size_t regions_per_thread =3D i; - size_t region_size; - - region_size =3D tcg_init_ctx.code_gen_buffer_size; - region_size /=3D max_cpus * regions_per_thread; - - if (region_size >=3D 2 * 1024u * 1024) { - return max_cpus * regions_per_thread; - } + /* + * Try to have more regions than max_cpus, with each region being >=3D= 2 MB. + * If we can't, then just allocate one region per vCPU thread. + */ + n_regions =3D tb_size / (2 * MiB); + if (n_regions <=3D 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 } =20 @@ -829,7 +824,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsig= ned max_cpus) buf =3D tcg_init_ctx.code_gen_buffer; total_size =3D tcg_init_ctx.code_gen_buffer_size; page_size =3D qemu_real_host_page_size; - n_regions =3D tcg_n_regions(max_cpus); + n_regions =3D tcg_n_regions(total_size, max_cpus); =20 /* The first region will be 'aligned - buf' bytes larger than the othe= rs */ aligned =3D QEMU_ALIGN_PTR_UP(buf, page_size); --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758755; cv=none; d=zohomail.com; s=zohoarc; b=MZ1d3XIQNUW/5ZnvBRINcg/6NwkusmfpA50Q05G3SNn4MbdGfHOZ/xMZj5ajbf7omeX2CdYsoej0UVHVhznlF55XwhK7sZD21CBouYGInJdODe/TdT7jYRxVw9ubBS9Zm2WQWnlYfTdiRlNnQKwXP1FLzvYYHTT62oOLhSh0510= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758755; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eK04d/bo+QTgBddX7q0xdbozbAL0+oUVhNKLX/4OLZA=; b=S6LKXqEVVayj+0rDTuQicZiG+NHmqWaHeT0P3SrwKQ4zTwyMO+KF6TEMoYrcTJsUIirgHy8cZ6SkVvYBM/KOMLx8yipTgdbytMmxYdqSkg3bIzVMSnrydUwmIAMVPmivTm7Zff+3JOEc3+PR0U/LrJ9XOtyzWFXPQnSshs22foQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615758755002207.20390185479118; Sun, 14 Mar 2021 14:52:35 -0700 (PDT) Received: from localhost ([::1]:58762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYf3-0006XY-VL for importer@patchew.org; Sun, 14 Mar 2021 17:52:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH8-0006BK-Mo for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:50 -0400 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]:34582) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH7-0008GN-0L for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:50 -0400 Received: by mail-qk1-x72c.google.com with SMTP id t4so29950123qkp.1 for ; Sun, 14 Mar 2021 14:27:48 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eK04d/bo+QTgBddX7q0xdbozbAL0+oUVhNKLX/4OLZA=; b=zmL8y45JHUuZuFhWXxgi/ZsDWCdDLKmNjJdywF8q2VlzzTQh7n+wawJvyaliJAd7NQ LsHFQXoSde6Go3YQbMn9Ci4sWPGTz/HhBZZi+OAa3vOxTQ8rp1fpUkfuMX6jo5FFxY5M +JQEWLSxLL3GImIjDfHBkCYgmdoL9UlWO2hc2ZJWysveDFsfoZ8/TCxvxWNnA43mOmHV jE1mqK+kxLHWXu6IAze7Tb6XXgAlDid71c/DtrpB+fOaHmEdyoI50BXsRmbFcjHHRKkS YRLweATzhQuDiXRdq5gF7ITPUfZCVm9RBX6Da9jL/9CimE4hVmujE601EaqzD2QTIxCi D+OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eK04d/bo+QTgBddX7q0xdbozbAL0+oUVhNKLX/4OLZA=; b=JbZANrDqO6IWink3iCFtSBLOAiWjdnhhkZXtCaWE3jcoKU6beKGIbnSxrW0VPYJtCn fZOOCi6Vc6/Kwg/Cyltl/c6A3LRvxSN/kZcv3MxpFXSzLr+qZlY0gIt3llpiHbf3xRUX vFIU8v5XMhF9lFFlUlTd0GXd9dc0HLYYA48shbF0OpyEDjXLy2K+e5OXqjyCpFPE4vI0 ka+egSPqX4j/79EbODOqRruXnYk4U9V0ZWqhxHMB5EdNu8r297KJ72vK8toR0HRApr/X uCz42KT/wA3Lro9hiI5Kc0e/ib+JJnbbJFlJEQPCycU2SCkz2PaZjtLmEh9xaFW1ii/Q Zqqw== X-Gm-Message-State: AOAM532RCTTNp+oYI1kuFVeYD4jpSrTeNtrWXFPOwnkFlL4g5mTrI0gg RoVdtDOWrsZC0xmu8Bo+Nrk6lcOUba9nHCo2 X-Google-Smtp-Source: ABdhPJzZ6YUURZ8xl8exLQ5pYjOud2b0uRx0fREUTB6geYeOxE/QtOKpGYy2id79SUeTtkP7A3beBA== X-Received: by 2002:a37:4690:: with SMTP id t138mr22528857qka.394.1615757268014; Sun, 14 Mar 2021 14:27:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 19/29] tcg: Tidy split_cross_256mb Date: Sun, 14 Mar 2021 15:27:14 -0600 Message-Id: <20210314212724.1917075-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72c; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Return output buffer and size via output pointer arguments, rather than returning size via tcg_ctx->code_gen_buffer_size. Signed-off-by: Richard Henderson --- tcg/region.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 23b3459c61..45c1178815 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -467,7 +467,8 @@ static inline bool cross_256mb(void *addr, size_t size) /* We weren't able to allocate a buffer without crossing that boundary, so make do with the larger portion of the buffer that doesn't cross. Returns the new base of the buffer, and adjusts code_gen_buffer_size. = */ -static inline void *split_cross_256mb(void *buf1, size_t size1) +static inline void split_cross_256mb(void **obuf, size_t *osize, + void *buf1, size_t size1) { void *buf2 =3D (void *)(((uintptr_t)buf1 + size1) & ~0x0ffffffful); size_t size2 =3D buf1 + size1 - buf2; @@ -478,8 +479,8 @@ static inline void *split_cross_256mb(void *buf1, size_= t size1) buf1 =3D buf2; } =20 - tcg_ctx->code_gen_buffer_size =3D size1; - return buf1; + *obuf =3D buf1; + *osize =3D size1; } #endif =20 @@ -509,12 +510,10 @@ static bool alloc_code_gen_buffer(size_t tb_size, int= splitwx, Error **errp) if (size > tb_size) { size =3D QEMU_ALIGN_DOWN(tb_size, qemu_real_host_page_size); } - tcg_ctx->code_gen_buffer_size =3D size; =20 #ifdef __mips__ if (cross_256mb(buf, size)) { - buf =3D split_cross_256mb(buf, size); - size =3D tcg_ctx->code_gen_buffer_size; + split_cross_256mb(&buf, &size, buf, size); } #endif =20 @@ -525,6 +524,7 @@ static bool alloc_code_gen_buffer(size_t tb_size, int s= plitwx, Error **errp) qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); =20 tcg_ctx->code_gen_buffer =3D buf; + tcg_ctx->code_gen_buffer_size =3D size; return true; } #elif defined(_WIN32) @@ -583,8 +583,7 @@ static bool alloc_code_gen_buffer_anon(size_t size, int= prot, /* fallthru */ default: /* Split the original buffer. Free the smaller half. */ - buf2 =3D split_cross_256mb(buf, size); - size2 =3D tcg_ctx->code_gen_buffer_size; + split_cross_256mb(&buf2, &size2, buf, size); if (buf =3D=3D buf2) { munmap(buf + size2, size - size2); } else { --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757796; cv=none; d=zohomail.com; s=zohoarc; b=P/7jtHCM/CMrFyO7gk06GlukUaTLrm7QvH6WgkQcgGNtp81MlfozKtXgYF1B4kgFvysKG45oPwcpG+TnOI1A2N8PaHIMhc/ie/IP7MM6shM7eZL1UhOrT6Ax25oyzC2d7RJwJ+cRg58iBsPk7+zoY377JU7uYH2H8tCaMXYpK74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757796; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=R00g9ZT+DJOPXUc3gA2QBcnKHFBUn5tI+Lb3fkrnwOQ=; b=QfD5GKpy/jHWgB5OEyvaovSnm3huHzJCjcNpnDpn9mE9zhHCKp1wd1bS2GcCFL4ufpFWr9ttf61WfZPW1yTcbSYEy27ODH5iWTN4R6cnbdXutknmoakg9MEz3XfY+OcUNnWa/t4zjnZdOR+oc8d/wiJlKXShXuP2moe6XnntGmI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757796820792.3704131722296; Sun, 14 Mar 2021 14:36:36 -0700 (PDT) Received: from localhost ([::1]:51614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYPb-0007wS-RZ for importer@patchew.org; Sun, 14 Mar 2021 17:36:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYH9-0006DI-UZ for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:51 -0400 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]:39184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH7-0008GZ-Tw for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:51 -0400 Received: by mail-qk1-x735.google.com with SMTP id g185so29901634qkf.6 for ; Sun, 14 Mar 2021 14:27:49 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R00g9ZT+DJOPXUc3gA2QBcnKHFBUn5tI+Lb3fkrnwOQ=; b=tcLx2D+tAV0YN0uVdnNouyBX0515LSM0jCunsUStY2Rv/JmyybskjxmMWpMj5Lb2QY H6zfxnZ+FpYk7fjSAM6oVRNi4jUStpHcof8Sc0bkXq7AdTPlQfa/0PgNXHzgpuAJ1Xft rc5b7lmi7Cw7vSrdqckIa08VVrkXpIShiSH3t4bHGgBU5cPJ3dlls/bJC7wh9ghluRNd 7Pl6OKTmrCU+yqLJ3/uKUzqJPZwLFEUvo3USq+Orq8OcBy7JSF+i55GKFLDsLeKElK44 3MCqCuBRqSp62dr2c8Zmgp8v7rkS3r+V6mmByNo/NubCDf/4tiKG/zg9HZrde5DkBQ2f inVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R00g9ZT+DJOPXUc3gA2QBcnKHFBUn5tI+Lb3fkrnwOQ=; b=KrPBLGgAtFS+mdiaCRItnug2504gYM31BMnI+TTxeevpdBjlPvuKAO28sjNApWCOkA tFAg9hCobXryA/+4orA2A4nKwcvpmfL8F+QUhBdQZD2FPJxEexwiFCeysW/KT79oRhfd 7pVb4eHYdQjcQlTxL6CNMcSrE1/92zNvv/LJQoicDdDvpCORAe6vwv2IrCtlAEbndmqT OOnxx2XrHDC2et8iBwCmQYcJNKBH9GnynHixz4UModrOZs9MXTPW8Xx/0VgK4zVDVTo6 ljll24gAJEKm8PrPnfY3U0pR1mNcqvSj0txO9Vj0ggcH9qSonYCpKddZsRG7LshA8p8d K0VQ== X-Gm-Message-State: AOAM532ylmz7NwCRqx87eHDe+zGgk4KAu0PTfBy1PVwm4bb8ZY3+KnVa Ic4/O+SrOwjEAOaGBN6PBZeFasEb7ng0MXMG X-Google-Smtp-Source: ABdhPJwGzHFcHDjINUA/di0CZ+SbL5n3/+UZXqfIekOd4I8JkKaG7PW0jJg9fxmKMDDZnKrSUPRBYw== X-Received: by 2002:a05:620a:14ae:: with SMTP id x14mr22275820qkj.237.1615757269013; Sun, 14 Mar 2021 14:27:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 20/29] tcg: Move in_code_gen_buffer and tests to region.c Date: Sun, 14 Mar 2021 15:27:15 -0600 Message-Id: <20210314212724.1917075-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x735.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Shortly, the full code_gen_buffer will only be visible to region.c, so move in_code_gen_buffer out-of-line. Move the debugging versions of tcg_splitwx_to_{rx,rw} to region.c as well, so that the compiler gets to see the implementation of in_code_gen_buffer. This leaves exactly one use of in_code_gen_buffer outside of region.c, in cpu_restore_state. Which, being on the exception path, is not performance critical. Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 11 +---------- tcg/region.c | 34 ++++++++++++++++++++++++++++++++++ tcg/tcg.c | 23 ----------------------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index a0122c0dd3..a19deb529f 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -696,16 +696,7 @@ extern const void *tcg_code_gen_epilogue; extern uintptr_t tcg_splitwx_diff; extern TCGv_env cpu_env; =20 -static inline bool in_code_gen_buffer(const void *p) -{ - const TCGContext *s =3D &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) <=3D s->code_gen_buffer_size; -} +bool in_code_gen_buffer(const void *p); =20 #ifdef CONFIG_DEBUG_TCG const void *tcg_splitwx_to_rx(void *rw); diff --git a/tcg/region.c b/tcg/region.c index 45c1178815..bf4167e467 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -68,6 +68,40 @@ static struct tcg_region_state region; static void *region_trees; static size_t tree_size; =20 +bool in_code_gen_buffer(const void *p) +{ + const TCGContext *s =3D &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) <=3D 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 +=3D tcg_splitwx_diff; + } + return rw; +} + +void *tcg_splitwx_to_rw(const void *rx) +{ + /* Pass NULL pointers unchanged. */ + if (rx) { + rx -=3D tcg_splitwx_diff; + /* Assert that we end with a pointer in the rw region. */ + g_assert(in_code_gen_buffer(rx)); + } + return (void *)rx; +} +#endif /* CONFIG_DEBUG_TCG */ + /* compare a pointer @ptr and a tb_tc @s */ static int ptr_cmp_tb_tc(const void *ptr, const struct tb_tc *s) { diff --git a/tcg/tcg.c b/tcg/tcg.c index a82d3a0861..65f9cf01d5 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -416,29 +416,6 @@ static const TCGTargetOpDef constraint_sets[] =3D { =20 #include "tcg-target.c.inc" =20 -#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 +=3D tcg_splitwx_diff; - } - return rw; -} - -void *tcg_splitwx_to_rw(const void *rx) -{ - /* Pass NULL pointers unchanged. */ - if (rx) { - rx -=3D 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 --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758103; cv=none; d=zohomail.com; s=zohoarc; b=Dj3WPTJvg50V8uvJPr9mfwqApiiIfSLIsM/qjTB0bP+LQdnAoNGLuv3PzSeMo3WeHFLS+znTe+AiWqBxW677TZTB6qJl2kLLqY9l3SybJ5W6SO/W0bQyKIwa8bbfsSute4Vr8tKVw+INsj53PimEIl5LefIgMDN3xrFRg8Bufn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758103; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pGsgpXwTM6hxqYx7HXtoXmPFsuT3pbQk6IhBOzlzD0Y=; b=mANGpOfpbdIcykh0dSLHn0pWqi6cqTOvEAw+V++MqEeyJ1YgHfNSyT+MWOMguZxg/jkrCr0U7baivATi64iuRN9O2OISnizQXiXwVQZH4Sgfkl2qWGKQlumb/vbxlWSBM9wj1oSExgONjq8Nl475PyIbQZhfVF0izBok2GVbV4w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615758103325237.7279910719235; Sun, 14 Mar 2021 14:41:43 -0700 (PDT) Received: from localhost ([::1]:36760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYUY-00059l-72 for importer@patchew.org; Sun, 14 Mar 2021 17:41:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHG-0006Jc-T4 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:59 -0400 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]:40974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH9-0008HC-39 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:58 -0400 Received: by mail-qk1-x732.google.com with SMTP id x10so29909537qkm.8 for ; Sun, 14 Mar 2021 14:27:50 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pGsgpXwTM6hxqYx7HXtoXmPFsuT3pbQk6IhBOzlzD0Y=; b=d6SrVOrgusSushCXa6lEK6+gpvsflECleEFk5qW/xBL5r+VNXe4I/d61j1/rUPkoDO EY35Wjpe9TEw0A2Hh/Tt3TpS9qQ97h22tyv4Uc1/lr8TqPQSC3hrOR1JhpjaK2HmZ9hP wjONXH44pR0uw6zZjlJvPJtAdSHUC4kKHrl4Hxu6w+9BctnweeF+W+u6TR3L9NvCZ+eP XHkftTYNtSU4Xx6BE1puQM8UXMZ7OSmT91HmcwgHTOpFYGYCtcevEzR/emBWoFIpXBpY 6FD4aknhXKPJ0NZJow3r/cHkmYLWGwuVzjOqBq8EPgETQQNDmgtIoDXAWKStAOc58/OE 8/GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pGsgpXwTM6hxqYx7HXtoXmPFsuT3pbQk6IhBOzlzD0Y=; b=mHIS1RK6Vvg8UCCh2a4tsmVeIqVKENlpW5O+BMMQIxNpj7IB11JLYUdiDJp+7p7q6l aA8Ou5Hh2SAYolO0yAB/VqigRra3ozNjBVAUCTrb4wuq+452YM0J1XnXlyqLwRnF3Y3U 1/Hsv6MK8+TZNTcWSYBhXnzDNIEvb/X0ofdLLQRPsgubzPCtCO6k3Z95JEJrdU85KmGA YNejU/QdomJ2Rpxudxuec3vz0nxB+yrtSSmujfmW2r2mQnLjQyhZrmSUxV+5Ct0CEkA2 dn333eoyZR4akqHN1MML1aiS8DmRflMM9hn28ihygqHzI7HpQbMj6+cJ7U6nPhWdO7Y4 qVyg== X-Gm-Message-State: AOAM530z7P+8Wmo0eb628I1n8WmIu9iJ6Iv3uTrAS6Ke50hBbAABJdpT n1Tb+5jwMStId1ISIX3hrVJdlyQHevqXqtpy X-Google-Smtp-Source: ABdhPJyvLk6l5InVBxNR5pL66bVgHhDtgRr3wB3UZPTZeL6PJwtgnfuGUdeJjl1FVn7vS+SJbceOjQ== X-Received: by 2002:a05:620a:1528:: with SMTP id n8mr869589qkk.329.1615757269989; Sun, 14 Mar 2021 14:27:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 21/29] tcg: Allocate code_gen_buffer into struct tcg_region_state Date: Sun, 14 Mar 2021 15:27:16 -0600 Message-Id: <20210314212724.1917075-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::732; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x732.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Do not mess around with setting values within tcg_init_ctx. Put the values into 'region' directly, which is where they will live for the lifetime of the program. Signed-off-by: Richard Henderson --- tcg/region.c | 64 ++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index bf4167e467..9a2b014838 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -70,13 +70,12 @@ static size_t tree_size; =20 bool in_code_gen_buffer(const void *p) { - const TCGContext *s =3D &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) <=3D s->code_gen_buffer_size; + return (size_t)(p - region.start_aligned) <=3D region.total_size; } =20 #ifdef CONFIG_DEBUG_TCG @@ -557,8 +556,8 @@ static bool alloc_code_gen_buffer(size_t tb_size, int s= plitwx, Error **errp) } qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); =20 - tcg_ctx->code_gen_buffer =3D buf; - tcg_ctx->code_gen_buffer_size =3D size; + region.start_aligned =3D buf; + region.total_size =3D size; return true; } #elif defined(_WIN32) @@ -579,8 +578,8 @@ static bool alloc_code_gen_buffer(size_t size, int spli= twx, Error **errp) return false; } =20 - tcg_ctx->code_gen_buffer =3D buf; - tcg_ctx->code_gen_buffer_size =3D size; + region.start_aligned =3D buf; + region.total_size =3D size; return true; } #else @@ -595,7 +594,6 @@ static bool alloc_code_gen_buffer_anon(size_t size, int= prot, "allocate %zu bytes for jit buffer", size); return false; } - tcg_ctx->code_gen_buffer_size =3D size; =20 #ifdef __mips__ if (cross_256mb(buf, size)) { @@ -633,7 +631,8 @@ static bool alloc_code_gen_buffer_anon(size_t size, int= prot, /* Request large pages for the buffer. */ qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); =20 - tcg_ctx->code_gen_buffer =3D buf; + region.start_aligned =3D buf; + region.total_size =3D size; return true; } =20 @@ -654,8 +653,8 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t = size, Error **errp) return false; } /* The size of the mapping may have been adjusted. */ - size =3D tcg_ctx->code_gen_buffer_size; - buf_rx =3D tcg_ctx->code_gen_buffer; + buf_rx =3D region.start_aligned; + size =3D region.total_size; #endif =20 buf_rw =3D qemu_memfd_alloc("tcg-jit", size, 0, &fd, errp); @@ -677,8 +676,8 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t = size, Error **errp) #endif =20 close(fd); - tcg_ctx->code_gen_buffer =3D buf_rw; - tcg_ctx->code_gen_buffer_size =3D size; + region.start_aligned =3D buf_rw; + region.total_size =3D size; tcg_splitwx_diff =3D buf_rx - buf_rw; =20 /* Request large pages for the buffer and the splitwx. */ @@ -729,7 +728,7 @@ static bool alloc_code_gen_buffer_splitwx_vmremap(size_= t size, Error **errp) return false; } =20 - buf_rw =3D (mach_vm_address_t)tcg_ctx->code_gen_buffer; + buf_rw =3D region.start_aligned; buf_rx =3D 0; ret =3D mach_vm_remap(mach_task_self(), &buf_rx, @@ -841,11 +840,8 @@ static bool alloc_code_gen_buffer(size_t size, int spl= itwx, Error **errp) */ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) { - void *buf, *aligned, *end; - size_t total_size; size_t page_size; size_t region_size; - size_t n_regions; size_t i; uintptr_t splitwx_diff; bool ok; @@ -854,39 +850,33 @@ void tcg_region_init(size_t tb_size, int splitwx, uns= igned max_cpus) splitwx, &error_fatal); assert(ok); =20 - buf =3D tcg_init_ctx.code_gen_buffer; - total_size =3D tcg_init_ctx.code_gen_buffer_size; - page_size =3D qemu_real_host_page_size; - n_regions =3D tcg_n_regions(total_size, max_cpus); - - /* The first region will be 'aligned - buf' bytes larger than the othe= rs */ - aligned =3D 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 star= t. * As a result of this we might end up with a few extra pages at the e= nd of * the buffer; we will assign those to the last region. */ - region_size =3D (total_size - (aligned - buf)) / n_regions; + region.n =3D tcg_n_regions(region.total_size, max_cpus); + page_size =3D qemu_real_host_page_size; + region_size =3D region.total_size / region.n; region_size =3D QEMU_ALIGN_DOWN(region_size, page_size); =20 /* A region must have at least 2 pages; one code, one guard */ g_assert(region_size >=3D 2 * page_size); + region.stride =3D region_size; + + /* Reserve space for guard pages. */ + region.size =3D region_size - page_size; + region.total_size -=3D 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 =3D region.start_aligned; =20 /* init the region struct */ qemu_mutex_init(®ion.lock); - region.n =3D n_regions; - region.size =3D region_size - page_size; - region.stride =3D region_size; - region.after_prologue =3D buf; - region.start_aligned =3D aligned; - /* page-align the end, since its last page will be a guard page */ - end =3D QEMU_ALIGN_PTR_DOWN(buf + total_size, page_size); - /* account for that last guard page */ - end -=3D page_size; - total_size =3D end - aligned; - region.total_size =3D total_size; =20 /* set guard pages */ splitwx_diff =3D tcg_splitwx_diff; --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757883; cv=none; d=zohomail.com; s=zohoarc; b=fexeimpMbgChPTVBjCnArfPGoZH4NbO7TVr40R5yr3YAyuUH6uumQbUWwEG4Sv7jFOBLU79BB8fJcUPrdjW6B2+w1H/ASpBueuA6cWIfXaw8ssaH7bMkwuLS6JrxjCPFkPyvheLokNmxHCZnbaO9Vxa9BgGAbWB/JhiOpgpzI3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757883; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YV8ZNMURZZ3L0f8Vp87koNwJMeD7v42xnjMnrSbn74s=; b=fpfmiE+noG9Rz2BKaXD25SS3yfy8xms7bO4atFl/aAItBPpoZLkwMoB0z3esfWyNqQIZZMd2lq5PdDzH6ReJVChrIM3/fXi/1gzWOwoxrsFu40Elnps9H/DH0fI/ASvSYQNcv7tzBK8avkPx41mSkl4LAf4KSz/baTve2wQDh6I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757883365228.59951155274314; Sun, 14 Mar 2021 14:38:03 -0700 (PDT) Received: from localhost ([::1]:56432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYR0-0001WR-5u for importer@patchew.org; Sun, 14 Mar 2021 17:38:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHF-0006IO-Dk for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:57 -0400 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:40077) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYH9-0008I2-Up for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:57 -0400 Received: by mail-qk1-x729.google.com with SMTP id l132so29919835qke.7 for ; Sun, 14 Mar 2021 14:27:51 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YV8ZNMURZZ3L0f8Vp87koNwJMeD7v42xnjMnrSbn74s=; b=G/GKf+jyTtrCb5jZ/WK4pjpQvUY2h+fSYS8bgspdsQ4WTmcyBPk5un0d26TiKoevlr pUo+2uhOMxy652NJ3qV7SBu9G5NQBSrDormieg71n6+L1n/mFdwzbwdjX7kFVjuB5dg/ L1edFEZIdcTo2F2dvG1Z+li6g44Ce8YyM4Xu13mAwZlhuA0XXxD8eaKlIxm8Sw0RfsGC sJK8rJ3g2GYR6QFrjk8OSEMjo6fbXrVQ9fDvkbI2HKaXrFVuA+1ivZXycc2cZOayLJLE r3cgVTt8weZOjGLUSItsCKc5n9JYVQEBglLHYYv0uovMF3qhT3lJh3PN0j0lKJ8DdFOR I9/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YV8ZNMURZZ3L0f8Vp87koNwJMeD7v42xnjMnrSbn74s=; b=Rt3l3ZEAGr0ZrEJPstWYbcU9MmbLNbFT6fgO1BVEciqWuBXO75TCP3UVzyA2lOMEBb pVFsBBl+hJCfWOLZRzq2z1tD8t/f3K9BX033pnWDaENdKHjgmfQdTUCVw4JTTCCXE6TU wh4Cu9OsJ4Q0XyzWyiF4M5VBDPhzwZYv7q6ED8mKEikdNJ7cnM6YQ+i76Cjbd2iP/aGS ohe18tZMtmjbe+Ljdmyr9xsWUlLfN734ytButPLxVFB2N9yAiC5rEAxlYSiKperrFJvf 3ts/0cZlMhxCwG+QzHR/O9N1/lyYoT+CbJHGZ126v3xQEmk4/TvfY9WbOpKrN6S8STU4 GBIg== X-Gm-Message-State: AOAM530HgSX0ERkBeYrsXlmhUDm77IL88eI3NkOgBdWBMI2jWrLxqOv/ wVkXmS81o9GJsR5Pn0FN1jkRWOp+aY1Qhlyy X-Google-Smtp-Source: ABdhPJyzEdSlF7dxnX6MWk2lgAIzR0CeEuJ0gVSjOqjdPmjqBrbE5zpIeZ0bxBUH2JvR7ioPi5xYFg== X-Received: by 2002:a05:620a:9c6:: with SMTP id y6mr22722924qky.39.1615757270982; Sun, 14 Mar 2021 14:27:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 22/29] tcg: Return the map protection from alloc_code_gen_buffer Date: Sun, 14 Mar 2021 15:27:17 -0600 Message-Id: <20210314212724.1917075-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::729; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x729.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Change the interface from a boolean error indication to a negative error vs a non-negative protection. For the moment this is only interface change, not making use of the new data. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tcg/region.c | 63 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 9a2b014838..3ca0d01fa4 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -521,14 +521,14 @@ static inline void split_cross_256mb(void **obuf, siz= e_t *osize, static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] __attribute__((aligned(CODE_GEN_ALIGN))); =20 -static bool alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **err= p) +static int alloc_code_gen_buffer(size_t tb_size, int splitwx, Error **errp) { void *buf, *end; size_t size; =20 if (splitwx > 0) { error_setg(errp, "jit split-wx not supported"); - return false; + return -1; } =20 /* page-align the beginning and end of the buffer */ @@ -558,16 +558,17 @@ static bool alloc_code_gen_buffer(size_t tb_size, int= splitwx, Error **errp) =20 region.start_aligned =3D buf; region.total_size =3D 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; =20 if (splitwx > 0) { error_setg(errp, "jit split-wx not supported"); - return false; + return -1; } =20 buf =3D VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, @@ -580,11 +581,12 @@ static bool alloc_code_gen_buffer(size_t size, int sp= litwx, Error **errp) =20 region.start_aligned =3D buf; region.total_size =3D 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; =20 @@ -592,7 +594,7 @@ static bool alloc_code_gen_buffer_anon(size_t size, int= prot, if (buf =3D=3D MAP_FAILED) { error_setg_errno(errp, errno, "allocate %zu bytes for jit buffer", size); - return false; + return -1; } =20 #ifdef __mips__ @@ -633,7 +635,7 @@ static bool alloc_code_gen_buffer_anon(size_t size, int= prot, =20 region.start_aligned =3D buf; region.total_size =3D size; - return true; + return prot; } =20 #ifndef CONFIG_TCG_INTERPRETER @@ -647,9 +649,9 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t = size, Error **errp) =20 #ifdef __mips__ /* Find space for the RX mapping, vs the 256MiB regions. */ - if (!alloc_code_gen_buffer_anon(size, PROT_NONE, - MAP_PRIVATE | MAP_ANONYMOUS | - MAP_NORESERVE, errp)) { + if (alloc_code_gen_buffer_anon(size, PROT_NONE, + MAP_PRIVATE | MAP_ANONYMOUS | + MAP_NORESERVE, errp) < 0) { return false; } /* The size of the mapping may have been adjusted. */ @@ -683,7 +685,7 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t = size, Error **errp) /* Request large pages for the buffer and the splitwx. */ qemu_madvise(buf_rw, size, QEMU_MADV_HUGEPAGE); qemu_madvise(buf_rx, size, QEMU_MADV_HUGEPAGE); - return true; + return PROT_READ | PROT_WRITE; =20 fail_rx: error_setg_errno(errp, errno, "failed to map shared memory for execute= "); @@ -697,7 +699,7 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t = size, Error **errp) if (fd >=3D 0) { close(fd); } - return false; + return -1; } #endif /* CONFIG_POSIX */ =20 @@ -716,7 +718,7 @@ extern kern_return_t mach_vm_remap(vm_map_t target_task, vm_prot_t *max_protection, vm_inherit_t inheritance); =20 -static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **err= p) +static int alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp) { kern_return_t ret; mach_vm_address_t buf_rw, buf_rx; @@ -725,7 +727,7 @@ static bool alloc_code_gen_buffer_splitwx_vmremap(size_= t size, Error **errp) /* Map the read-write portion via normal anon memory. */ if (!alloc_code_gen_buffer_anon(size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, errp)) { - return false; + return -1; } =20 buf_rw =3D region.start_aligned; @@ -745,23 +747,23 @@ static bool alloc_code_gen_buffer_splitwx_vmremap(siz= e_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; } =20 if (mprotect((void *)buf_rx, size, PROT_READ | PROT_EXEC) !=3D 0) { error_setg_errno(errp, errno, "mprotect for jit splitwx"); munmap((void *)buf_rx, size); munmap((void *)buf_rw, size); - return false; + return -1; } =20 tcg_splitwx_diff =3D buf_rx - buf_rw; - return true; + return PROT_READ | PROT_WRITE; } #endif /* CONFIG_DARWIN */ #endif /* CONFIG_TCG_INTERPRETER */ =20 -static bool alloc_code_gen_buffer_splitwx(size_t size, Error **errp) +static int alloc_code_gen_buffer_splitwx(size_t size, Error **errp) { #ifndef CONFIG_TCG_INTERPRETER # ifdef CONFIG_DARWIN @@ -772,24 +774,25 @@ static bool alloc_code_gen_buffer_splitwx(size_t size= , Error **errp) # endif #endif error_setg(errp, "jit split-wx not supported"); - return false; + return -1; } =20 -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; =20 if (splitwx) { - if (alloc_code_gen_buffer_splitwx(size, errp)) { - return true; + prot =3D alloc_code_gen_buffer_splitwx(size, errp); + if (prot >=3D 0) { + return prot; } /* * If splitwx force-on (1), fail; * if splitwx default-on (-1), fall through to splitwx off. */ if (splitwx > 0) { - return false; + return -1; } error_free_or_abort(errp); } @@ -844,11 +847,11 @@ void tcg_region_init(size_t tb_size, int splitwx, uns= igned max_cpus) size_t region_size; size_t i; uintptr_t splitwx_diff; - bool ok; + int have_prot; =20 - ok =3D alloc_code_gen_buffer(size_code_gen_buffer(tb_size), - splitwx, &error_fatal); - assert(ok); + have_prot =3D alloc_code_gen_buffer(size_code_gen_buffer(tb_size), + splitwx, &error_fatal); + assert(have_prot >=3D 0); =20 /* * Make region_size a multiple of page_size, using aligned as the star= t. --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757883; cv=none; d=zohomail.com; s=zohoarc; b=T3SW8yN8QJzF9JmsctWaS9HNurP/UCs1kG1abvbJcCz0pr9zTMIg6NADeDpXCfdxMtw4AuIsr2PVh+cduA1L+rcmPkDMMukiBuXS28bF2uGf5cYjuRBRtzeouTob3Fsc1D18QSXi/BJrpxOyBNjguEDfdnfPYjAxAwM/FybDDUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757883; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GL6gIGaWt/dCjMwMHmq6bzPQkZftRPDs8LLZAcbEC+c=; b=I88nrIyk7bBj1zAchFDPwniXH4Cm/ASk9m7xpObwD5F69K/QLuLVPootXlv804vYiQKTzqbE+O4TUlHuwSFPdSvWQnQor79/RtyCUM0V0XB1RIcR6u9hkbic/nVmhSdBPAq1JhWhgQ5HAtrLkQ6BkcB5p44eyI2moPB5uFPMLqg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757883893932.2232854519378; Sun, 14 Mar 2021 14:38:03 -0700 (PDT) Received: from localhost ([::1]:56560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYR0-0001ZV-RH for importer@patchew.org; Sun, 14 Mar 2021 17:38:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHD-0006Hf-G5 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:56 -0400 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]:43182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHB-0008IA-0y for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:55 -0400 Received: by mail-qk1-x72e.google.com with SMTP id b130so29890291qkc.10 for ; Sun, 14 Mar 2021 14:27:52 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GL6gIGaWt/dCjMwMHmq6bzPQkZftRPDs8LLZAcbEC+c=; b=ARggv7oKTaE1LTeM3+EVE4/BvENkXP73vxe7LDDMK+nUoL6FGWX1icF4vulJ/1VAKr izTIfBcb166OcJZEfzZNj8BCj3bM2tQGH+Cr8eiYSeXjBVNXCWulAPiWCjlq9mLrWTO2 5eD7GAx6K22O88aq/DTg+S/R1QsaTwhheIRqkHeIh2uxM/vfbzwvwWt5RcvKT7nr4/qZ fNsYFRtuzgJNJ7UV/6NB67SLPLkfBilkJm5nWnVnZACtKxtMGhluCSnFb4DGKfm9ONqC 06GOKgWlQKnABLIZ3QUt/cYys15XMdnPlPpSDUWTtrkzO8nmWLX+pG7JSRIMuVyatoNr rilg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GL6gIGaWt/dCjMwMHmq6bzPQkZftRPDs8LLZAcbEC+c=; b=MK+lHwdKDI/+z+WXJJEPl4Tj3GYz9FazLIyLWpzR70MtsGTyzKMN/c32hWqXpSMkNZ Px+w3/CVfdKqHlWemBwEWjUwbFI2YaG7Nt2vKHiJ/TICBcXKZu9fiDhtLp6H/od4PlOR kZoBJrS30D1DUOETmXyb0YKnnoafrpfAH1UWKzsHGaSV3Tm1uP7tHAcQPGvtAuC85h2g 02IX/TQsJGTbEirNOl2GLuAbLFqNVD0hfo5qd3YbDNXkytFPhoJ4WgwQnKnXeyo9wcsB 7I6WVHXr0lE5UApTl7OP6GRSt8zd05mC/Y6xYdAeBlB250FSxXd+ViDrOQfXpUgE3NB2 vRTQ== X-Gm-Message-State: AOAM530PV4FSDQo1dJ/5hbNzg1F3PpParz6NjBsNFCtepog2A4CYvW8b 01UgCxsNLf8Jg2zagTVHbs2Eh6E2/PR40Ij/ X-Google-Smtp-Source: ABdhPJwdfelBCcGzVUTB4+4p64jbStbFwDGBP8+KicBtLF+aZbWYGjPvKzqmHnBE6z+5Uqq+JmDNgw== X-Received: by 2002:a05:620a:404a:: with SMTP id i10mr22773089qko.2.1615757272103; Sun, 14 Mar 2021 14:27:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 23/29] tcg: Sink qemu_madvise call to common code Date: Sun, 14 Mar 2021 15:27:18 -0600 Message-Id: <20210314212724.1917075-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72e; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Move the call out of the N versions of alloc_code_gen_buffer and into tcg_region_init. Signed-off-by: Richard Henderson --- tcg/region.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 3ca0d01fa4..994c083343 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -554,7 +554,6 @@ static int alloc_code_gen_buffer(size_t tb_size, int sp= litwx, Error **errp) error_setg_errno(errp, errno, "mprotect of jit buffer"); return false; } - qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); =20 region.start_aligned =3D buf; region.total_size =3D size; @@ -630,9 +629,6 @@ static int alloc_code_gen_buffer_anon(size_t size, int = prot, } #endif =20 - /* Request large pages for the buffer. */ - qemu_madvise(buf, size, QEMU_MADV_HUGEPAGE); - region.start_aligned =3D buf; region.total_size =3D size; return prot; @@ -682,9 +678,6 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t = size, Error **errp) region.total_size =3D size; tcg_splitwx_diff =3D buf_rx - buf_rw; =20 - /* 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; =20 fail_rx: @@ -853,6 +846,13 @@ void tcg_region_init(size_t tb_size, int splitwx, unsi= gned max_cpus) splitwx, &error_fatal); assert(have_prot >=3D 0); =20 + /* Request large pages for the buffer and the splitwx. */ + qemu_madvise(region.start_aligned, region.total_size, QEMU_MADV_HUGEPA= GE); + 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 star= t. * As a result of this we might end up with a few extra pages at the e= nd of --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615757941; cv=none; d=zohomail.com; s=zohoarc; b=nVFhzl5oJ1Fb87IFZlZNNm/Kjaa/kQifpT/tWXBE4v7UQP+Jm51S0l8xXB6mGGfdFK80Q6UpBGca27MaLGsxyTRe/uedYlruWxLfSy4p3knQcXyOft76KMFT3rujZAjL1ceAQjE0RdTf1IdaFm3hMJfF2/g/RT04KZYMXLYruUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615757941; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dbOIDgtK5Y740kNmX5rEOHFZVjBYbVNjCLgwvbDsCnc=; b=XiHV/2f3vqMCG4Mn2Fud9uUJmTvaP4uQgCKiVRWDHIwgYDpcrUH89pc8gYtvEKcd24OrCN7rUPD9nbLO6/0xWFBebXYfV1kzzPukTF+EueEVuMhygIGk86f7aJU/NiuznwWMcWckX4cxqT4HuIp4WWVhVurDgs627mj86NXxnlQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615757941972301.676116478998; Sun, 14 Mar 2021 14:39:01 -0700 (PDT) Received: from localhost ([::1]:60024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYRw-0002zq-VK for importer@patchew.org; Sun, 14 Mar 2021 17:39:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHH-0006K9-Em for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:59 -0400 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]:35368) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHC-0008IF-TU for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:27:59 -0400 Received: by mail-qk1-x735.google.com with SMTP id d20so29929245qkc.2 for ; Sun, 14 Mar 2021 14:27:53 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dbOIDgtK5Y740kNmX5rEOHFZVjBYbVNjCLgwvbDsCnc=; b=wSkZk/aXvYc046TWbwqTWpUsoI81YkzWwYchqJLNrF1yWkytSHqGix+Q6UlE8oQ0Kh MPPWns5Q2+x30dqUyMDPf5jyF052zQH8fECOrobmbJGPK0p56dQTSdz0GRt8O20QMwNO pukS+KE8ErqgZl/OwH764fVjv1rSngiJ+d7It5ux+w+0ejKcgP3d8gPWIDvwzzi0a8NL puGqnRs1cXrmf4EeJc2djcdSSdtnYRfqzTxIytZmyByg49MzGMd543CbSXDhoGviQPws ElUVk/O2x1IFAEJC5FPIXJu7nvBSRja7m851n9ZRqlO9w0i5gx08clNwTaPJoMUu+c+w rOjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dbOIDgtK5Y740kNmX5rEOHFZVjBYbVNjCLgwvbDsCnc=; b=qo7zWSf8qgMnhfRFA7fNLHiwtHqceu6vZq9NUbdYspP5NyRtqGf7bcxXXBXyF8Duzw 4vKVK+FWRBdesMERWd3Hn5cmkrl50EKlAFAzLibcyfCliXOsPLt5/2+dWa3WUZFhk6pe puw+EVrrcBntRfrr037pfrEdTcbteQlBDJDfwD04Tb7w2Oi8yMfwfpalOmHnwWlb02cu SQSs+cpQzyM7pTCypVTPiuHv8McqdrxM+kyWdc+UkiKcW4Y4hqZflKgZk2DmbZG93w+/ PHPjlDcgtI0rkyDkbgpk9r4+MPqGixduXtd4/RpSODW4k8kJdWIb0AAtMDdsjYB6ZRvx /W6A== X-Gm-Message-State: AOAM531uxj/ELg7S2I7CSJaEdO5wK3G+SR5bXHcyXyczcd3SZB2n5d9E lZbcHU1f7MhXHV3fdv/6Nzh5Doxn7NjyMmdG X-Google-Smtp-Source: ABdhPJw9G1jNx2mqEoIjzbS+dfKvVho4uRR3VRz2mZBdUa7QPkTnet5NHYHcFp3r2mNqhLlS+YNunw== X-Received: by 2002:a37:8743:: with SMTP id j64mr21469640qkd.299.1615757273247; Sun, 14 Mar 2021 14:27:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 24/29] tcg: Do not set guard pages in the rx buffer Date: Sun, 14 Mar 2021 15:27:19 -0600 Message-Id: <20210314212724.1917075-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x735.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We only need guard pages in the rw buffer to avoid buffer overruns. Let the rx buffer keep large pages all the way through. Signed-off-by: Richard Henderson --- tcg/region.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 994c083343..27a7e35c8e 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -839,7 +839,6 @@ void tcg_region_init(size_t tb_size, int splitwx, unsig= ned max_cpus) size_t page_size; size_t region_size; size_t i; - uintptr_t splitwx_diff; int have_prot; =20 have_prot =3D alloc_code_gen_buffer(size_code_gen_buffer(tb_size), @@ -881,8 +880,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsig= ned max_cpus) /* init the region struct */ qemu_mutex_init(®ion.lock); =20 - /* set guard pages */ - splitwx_diff =3D tcg_splitwx_diff; + /* Set guard pages. No need to do this for the rx_buf, only the rw_bu= f. */ for (i =3D 0; i < region.n; i++) { void *start, *end; int rc; @@ -890,10 +888,6 @@ void tcg_region_init(size_t tb_size, int splitwx, unsi= gned max_cpus) tcg_region_bounds(i, &start, &end); rc =3D qemu_mprotect_none(end, page_size); g_assert(!rc); - if (splitwx_diff) { - rc =3D qemu_mprotect_none(end + splitwx_diff, page_size); - g_assert(!rc); - } } =20 tcg_region_trees_init(); --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615759430; cv=none; d=zohomail.com; s=zohoarc; b=JJmspWFJ4n8+T0tbYmsloXxWKn954pKmC0Ij+eRyMDMWuH4GAdatgoJXjkQDKWho1k+Dts4/aq04SPdV8bH5MxBbhT13IPIC62LG70Q1rtrA77nA1fUXoG+78wSZ5tN3Cq5VKF1LkzczME1Ah/MwZ6RzxCLtp+mhEWI8yUjtvIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615759430; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4eSiYZLqamkXwsALfLyClM+caXgQ2VvDhj6YMhAvyBg=; b=L9q5axhnkNTH3pR9OLgGBCbn79zEUu6/EJ+63XaGy2lGaiydncIMOgXTfBIqAWlLqEak+gxgEWIFRHUIYZ2EdBtbKwEDgWlkbbmhn0Aq+aVYS1ym/HSAtSIih+5ZMZ6K8a5hmADHymaKtZOEY7z7kFPtJZ53+18yGjcKGCBPFqQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161575943038925.90039624520182; Sun, 14 Mar 2021 15:03:50 -0700 (PDT) Received: from localhost ([::1]:43868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYpv-0004ax-JK for importer@patchew.org; Sun, 14 Mar 2021 18:03:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHK-0006Qi-ON for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:02 -0400 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]:46076) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHE-0008IK-PD for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:02 -0400 Received: by mail-qk1-x72e.google.com with SMTP id m186so13276889qke.12 for ; Sun, 14 Mar 2021 14:27:55 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4eSiYZLqamkXwsALfLyClM+caXgQ2VvDhj6YMhAvyBg=; b=DiVwRfe2SuZ8YJjM8a5GDNpBlolBIM5CsmH/gblZWiUdd9HlkpYZZP8obkufpJLUIt gCM3OJNOJp3Oy4b4UdhuZIURNcoAaKJPgF7DeitKjuL+tirjER7rVXkENPM3KE3T3GD1 IRbIdVleijvG8mcKc7Wk1N1Uwtn9mQLJqVCVIc5Fno37BdSc3gPy8crgXvkbqwrfVCrT XXIOjXjRxtQiGQTFIpA6K36IJJFqsvYjZ8/q1xWA95JtXZYpi+jy1X/ghIMI1YPgrt82 snuQOYCdaAKOtl34eosIIf+DaGGK4YK/wJCy495vYKqfHK2iIa9hvSBaLrj/ZxUnGtS3 N08w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4eSiYZLqamkXwsALfLyClM+caXgQ2VvDhj6YMhAvyBg=; b=g5Q1Qs7FeMVokMmp5wottd70bEB6ZurKYIm2cjAlM6aynTl6Em76euOqzMBEKF9+vR eYhtAgNC/Unp1sOgXwjoPmOHeNuzurKsMLgqDOYMb3/1CJvByG5Q/2wLLYh3ysrPqKFu 1Dt0LiMKOLJyI0edYM8BUyOCA0WH3H4gTOZ1XgpB+/PHGMyOpwMN1d2Q0aXX15Lge1Cj Elrert41uetbxpo2NSjBdWo1NxRVrnV9k9hShRUoYh4PKiAY2eTEHK78Nvr+tYppHp0D R8icZRnmUUWhj2mxnukXQEJ/h4IL6HoJixi1iWLGxjsNQOW2BS9FPv0YBV6khL8x3ESI H7Mg== X-Gm-Message-State: AOAM531DC4XxPlGfeidJv7C9c2v9OGj3K9hKWIy/zBJOffVdHRNIJAzS 88KrcyCYcXub1uKx4Jg/qwfDUTLDV76B5ZWn X-Google-Smtp-Source: ABdhPJzDa2yoWzwgQa5rbwXZM7egcYEmbsKYZSd1f8Wcw4hVgA2w8XEW7F51aEMcNFCRqschVfExMQ== X-Received: by 2002:a05:620a:1001:: with SMTP id z1mr21770585qkj.364.1615757274702; Sun, 14 Mar 2021 14:27:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 25/29] util/osdep: Add qemu_mprotect_rw Date: Sun, 14 Mar 2021 15:27:20 -0600 Message-Id: <20210314212724.1917075-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72e; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) For --enable-tcg-interpreter on Windows, we will need this. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- include/qemu/osdep.h | 1 + util/osdep.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index ba15be9c56..5cc2e57bdf 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -494,6 +494,7 @@ void sigaction_invoke(struct sigaction *action, #endif =20 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); =20 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 } =20 +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 --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758956; cv=none; d=zohomail.com; s=zohoarc; b=k6QIA6oeQgTYjv8Rz7NuXqRVnFxCvkqmKAJ6UYsDa0zFbjuSS6Gpf7qxMKHn4J3pKDmkFlCpqyC+49RDdxgqjc4GFarertK7A8YCnIS3/V0P6iVj8UWJZM2/tA/0A22JARbgKuzcqf/dbd8AWwvFgZcESYcPnZRtdwnJcCqUhtk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758956; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JZdn6ANaU4aV5zRIqP0A2KkQ5u2MmsLTSCDf8HK0t+o=; b=Ox+lD1TgAJrT+fZhvGBc2zY6ztBVA0G5oJtLqfnpXlFrc/tNEAi5NV5q+p0Uo/ej3VS58PpJ4QzaF6KErTvb6Fsb34f3hD/EFfOb5ZXytlLxizK9jfFZdFuAC/JvEVRTmgfHDzNU2tlHrQEjEwOpmZY7HMFRiVj9A+4tQS5cOHM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615758956154594.5777478630189; Sun, 14 Mar 2021 14:55:56 -0700 (PDT) Received: from localhost ([::1]:34884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYiH-0000Ie-L9 for importer@patchew.org; Sun, 14 Mar 2021 17:55:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHJ-0006Po-Dw for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]:40083) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHE-0008J1-PX for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: by mail-qk1-x72f.google.com with SMTP id l132so29919945qke.7 for ; Sun, 14 Mar 2021 14:27:56 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JZdn6ANaU4aV5zRIqP0A2KkQ5u2MmsLTSCDf8HK0t+o=; b=oF0BZfdMnQYHe7obz9wj63Y+CtaRLHXmCoc5Rd1IXR+Fof6wYaelQZq/sNdPYVFCkG N2Pa4zZZAMaxJp10rIGCS3M3zN6nSDjM+9xNFtQujdp5FuYK/LbzO65IqMFwak+Lw6Sf rTtDggvzXETMplHx20+hexBqxDNIprLOq5ia/XuZBSMULrmmW5pMQvI+50G0+3nJoUO7 fisRiuo7Zbx0mi1I6eUMeHCruY0/8U3F+UHD68GQn7XdzLNvZA1u2yM4yAgRH1nZ7ak7 zHDxS/dR+yfmRRM3GPeSxLy7kqCqtGlO5sgghWnFGpSI3bRgFLO2hJOvWp7mLTWHAcuh 7LFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JZdn6ANaU4aV5zRIqP0A2KkQ5u2MmsLTSCDf8HK0t+o=; b=tLEH6IsJxlUXTEQM9sI8BVOu7s6AL3hoanXOALg4Aew9OC18cM/8D6DLln3sBz9CSX fYPCVWr6toBw406zFSp9Ddt8ipnPj5UHT8eSUfOT9yQQl281QrZWFB5Pq+jhMDGsRimO SAiNDJniTZcF3pQXIfEBqemQXsotNzCE46LdzSreLnmgbu/aNmXOgCja6z0sCoQ22mLG 2djtBGlkmbjG7HFzpnd45FaIBJY8+Tyn310XrnRuvuO7A6uIw6aDonl0gKDSZSp0EE5x bxslPhp0jDM+QgPiS5uJoPnBWPXCtMmGF/XFTRhDsBK/o4BUxIK61xCQDLqbVxRrT4Eg jXCQ== X-Gm-Message-State: AOAM530r2scL6LATBo7VwZoeMxA7H956eDCQP3cVyJUWXu9QFwPq4ka8 v4k3Pak9TQUXnYhSimnb8+O4WozpBumPNRpU X-Google-Smtp-Source: ABdhPJzA/FaDTADtIiZXIjp9xeRbhWkjvzpNfH4JzhwJI5rKraMlomOttoyh9o6W3FiVmk/Leb7Z6w== X-Received: by 2002:a37:9f91:: with SMTP id i139mr22409218qke.72.1615757275673; Sun, 14 Mar 2021 14:27:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 26/29] tcg: Round the tb_size default from qemu_get_host_physmem Date: Sun, 14 Mar 2021 15:27:21 -0600 Message-Id: <20210314212724.1917075-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72f; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If qemu_get_host_physmem returns an odd number of pages, then physmem / 8 will not be a multiple of the page size. The following was observed on a gitlab runner: ERROR qtest-arm/boot-serial-test - Bail out! ERROR:../util/osdep.c:80:qemu_mprotect__osdep: \ assertion failed: (!(size & ~qemu_real_host_page_mask)) Signed-off-by: Richard Henderson --- tcg/region.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 27a7e35c8e..4dc1237ff4 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -469,26 +469,6 @@ static size_t tcg_n_regions(size_t tb_size, unsigned m= ax_cpus) (DEFAULT_CODE_GEN_BUFFER_SIZE_1 < MAX_CODE_GEN_BUFFER_SIZE \ ? DEFAULT_CODE_GEN_BUFFER_SIZE_1 : MAX_CODE_GEN_BUFFER_SIZE) =20 -static size_t size_code_gen_buffer(size_t tb_size) -{ - /* Size the buffer. */ - if (tb_size =3D=3D 0) { - size_t phys_mem =3D qemu_get_host_physmem(); - if (phys_mem =3D=3D 0) { - tb_size =3D DEFAULT_CODE_GEN_BUFFER_SIZE; - } else { - tb_size =3D MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, phys_mem / 8); - } - } - if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { - tb_size =3D MIN_CODE_GEN_BUFFER_SIZE; - } - if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { - tb_size =3D MAX_CODE_GEN_BUFFER_SIZE; - } - return tb_size; -} - #ifdef __mips__ /* In order to use J and JAL within the code_gen_buffer, we require that the buffer not cross a 256MB boundary. */ @@ -836,13 +816,29 @@ static int alloc_code_gen_buffer(size_t size, int spl= itwx, Error **errp) */ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) { - size_t page_size; + const size_t page_size =3D qemu_real_host_page_size; size_t region_size; size_t i; int have_prot; =20 - have_prot =3D alloc_code_gen_buffer(size_code_gen_buffer(tb_size), - splitwx, &error_fatal); + /* Size the buffer. */ + if (tb_size =3D=3D 0) { + size_t phys_mem =3D qemu_get_host_physmem(); + if (phys_mem =3D=3D 0) { + tb_size =3D DEFAULT_CODE_GEN_BUFFER_SIZE; + } else { + tb_size =3D QEMU_ALIGN_DOWN(phys_mem / 8, page_size); + tb_size =3D MIN(DEFAULT_CODE_GEN_BUFFER_SIZE, tb_size); + } + } + if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { + tb_size =3D MIN_CODE_GEN_BUFFER_SIZE; + } + if (tb_size > MAX_CODE_GEN_BUFFER_SIZE) { + tb_size =3D MAX_CODE_GEN_BUFFER_SIZE; + } + + have_prot =3D alloc_code_gen_buffer(tb_size, splitwx, &error_fatal); assert(have_prot >=3D 0); =20 /* Request large pages for the buffer and the splitwx. */ @@ -857,9 +853,8 @@ void tcg_region_init(size_t tb_size, int splitwx, unsig= ned max_cpus) * As a result of this we might end up with a few extra pages at the e= nd of * the buffer; we will assign those to the last region. */ - region.n =3D tcg_n_regions(region.total_size, max_cpus); - page_size =3D qemu_real_host_page_size; - region_size =3D region.total_size / region.n; + region.n =3D tcg_n_regions(tb_size, max_cpus); + region_size =3D tb_size / region.n; region_size =3D QEMU_ALIGN_DOWN(region_size, page_size); =20 /* A region must have at least 2 pages; one code, one guard */ --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615758152; cv=none; d=zohomail.com; s=zohoarc; b=oDw/OVw9t3wjT3C2DHPgSICJExlguPMVwJX1zGq4kctdPBRLJ3l3W7qs1dJaoM/t4S/IR7WziQ+gFsYpWpIdsz48Cm4HT+66ECrlFx6qnVUHbHk0Mtiq9/LMKpwrKyRlWasR2QcbqJv5fgJn16DgfcdMkH6WU2YWQ6COW88agP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615758152; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pRz3FkmnhYrvDheUkOUyMc6EESrwISuc2jP3jfo+afs=; b=Z0XhRznV91EW4svUsjpw1KN/D3PviTWdu62Khf4o730+Dc2AVFiGvSFYnaAT4daUiCCy6tS+5eKhbSyvfsNwTI/bBUD0CIIzfrSsX5MtEH/IzEk+jStF+qhzZr/QonMlcOzOr1sFrf1qA5jwz1jNGAntKUbxYXxl99Yga+oVorg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615758152409209.48904753180796; Sun, 14 Mar 2021 14:42:32 -0700 (PDT) Received: from localhost ([::1]:39308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYVL-0006H0-Al for importer@patchew.org; Sun, 14 Mar 2021 17:42:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHJ-0006Of-1R for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:42127) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHG-0008JB-3B for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:00 -0400 Received: by mail-qk1-x729.google.com with SMTP id z190so29892144qka.9 for ; Sun, 14 Mar 2021 14:27:57 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pRz3FkmnhYrvDheUkOUyMc6EESrwISuc2jP3jfo+afs=; b=T6qzpQF40EwKSOnTbv8BIpH8oM4f5VDVFntt/319krpghQfldwdtDnK3mS84WMwI5w Vj9b9t9Q70pvP6GXPu0wNIgDndr1Y/G/naYbP09FkrpDHIp3DB/syEsyl3K6YSE/+PMQ EABylMr5oXCKpSoDt4KW/ir1ul9VqrI/1cV+rxYz5aPzaT9CBJYJCHEQJTWnEIiSZoDa WuJjV+aJg7LOnuGbkyAxWZb9t1Y9VfCfEbqrI1ZUTp2tzjkAnbrftdWe+LVDZKOll8Fm YXzislGDv/VwR4HF3suJUspTeODH1GsEaXafuJHfGLYZQP5pYsn/7twIYs1rNY/CztpT utUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pRz3FkmnhYrvDheUkOUyMc6EESrwISuc2jP3jfo+afs=; b=i2oCIh5ZKepHegsMQBNR8nTmAE7/2sq3fzTnYKImF5FUpKoYDSa5ist25349mZj6TL S0X3sqF0z2cQeUTBQSKpJHiA83c5cuBVn/Xc6qFwhOeaYRz1GEHAIHdel8EQqQIvBNcm 3CJW1wox7OGfvEZdEKvA+25td5gql+eDX+18tA3nViIZe4jaZAsO1qOuZfneOfKlFdKJ K9eFznGVB29cnoCEuCNTUE1CxFi2r8jt2tG7VncKuTQIjhMjnaUTEk0M3xJuNZ6zfjtb gadWqwMQ9WacjZ0QoqDSAQuzvgmFL0jdOMA8TyHXSVHqRRXK5m7Dfm6b//vFaMewrbiP gMkw== X-Gm-Message-State: AOAM532sXyJ/UBgf8CMkwhznjG34ETyYK1DhKJLqMcAJudO17VLT5CYf FzBm/4DnabwNK//9MU2016w3Fygqk7Kx1KsW X-Google-Smtp-Source: ABdhPJzLpvrklawwJDQTJbvS+hCJFmUJb/kQa8qz8ySh5TbjCQhlV4PQLjPfHCaFUkrB+9fuDQGPmA== X-Received: by 2002:a05:620a:13db:: with SMTP id g27mr23096202qkl.367.1615757276743; Sun, 14 Mar 2021 14:27:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 27/29] tcg: Merge buffer protection and guard page protection Date: Sun, 14 Mar 2021 15:27:22 -0600 Message-Id: <20210314212724.1917075-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::729; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x729.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Do not handle protections on a case-by-case basis in the various alloc_code_gen_buffer instances; do it within a single loop in tcg_region_init. Signed-off-by: Richard Henderson --- tcg/region.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 4dc1237ff4..fac416ebf5 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -530,11 +530,6 @@ static int alloc_code_gen_buffer(size_t tb_size, int s= plitwx, Error **errp) } #endif =20 - if (qemu_mprotect_rwx(buf, size)) { - error_setg_errno(errp, errno, "mprotect of jit buffer"); - return false; - } - region.start_aligned =3D buf; region.total_size =3D size; =20 @@ -818,8 +813,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsig= ned max_cpus) { const size_t page_size =3D qemu_real_host_page_size; size_t region_size; - size_t i; - int have_prot; + int have_prot, need_prot; =20 /* Size the buffer. */ if (tb_size =3D=3D 0) { @@ -875,14 +869,38 @@ void tcg_region_init(size_t tb_size, int splitwx, uns= igned max_cpus) /* init the region struct */ qemu_mutex_init(®ion.lock); =20 - /* Set guard pages. No need to do this for the rx_buf, only the rw_bu= f. */ - for (i =3D 0; i < region.n; i++) { + /* + * Set guard pages. No need to do this for the rx_buf, only the rw_bu= f. + * Work with the page protections set up with the initial mapping. + */ + need_prot =3D PAGE_READ | PAGE_WRITE; +#ifndef CONFIG_TCG_INTERPRETER + if (tcg_splitwx_diff =3D=3D 0) { + need_prot |=3D PAGE_EXEC; + } +#endif + for (size_t i =3D 0, n =3D region.n; i < n; i++) { void *start, *end; int rc; =20 tcg_region_bounds(i, &start, &end); - rc =3D qemu_mprotect_none(end, page_size); - g_assert(!rc); + if (have_prot !=3D need_prot) { + if (need_prot =3D=3D (PAGE_READ | PAGE_WRITE | PAGE_EXEC)) { + rc =3D qemu_mprotect_rwx(start, end - start); + } else if (need_prot =3D=3D (PAGE_READ | PAGE_WRITE)) { + rc =3D 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 !=3D 0) { + /* If guard-page permissions don't change, it isn't fatal. */ + (void)qemu_mprotect_none(end, page_size); + } } =20 tcg_region_trees_init(); --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615759066; cv=none; d=zohomail.com; s=zohoarc; b=BnQjPWw8XSQIFGkMo0g1WKg7AxAIWm6h+DqUx/z1K7cVoyRKfrda3JBfTQbdd0YCUzYpEdTfFbriDlk6rMKDYhS4z9j4Ja+DGXIUcmcc0LaFgCxE7RihRnA1oxk1/jj4Z6kbdSti1jDRY4pqpDofWM6B1NkCa6i2YJHNp03Y/OE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615759066; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HDjwEv5UIDqEnZnnB6TE5sHqCsoYg0tX8iQJ/X9PYNw=; b=KrCGIJ7RdI8N1VlpuI5uEuUu1Fq9UCHiA8FbeFiinlcOzWy9It4gahhu0U468VA3JMYDOUefaIKOUezARQAn+rU70RkIDO5m7xkFPkhybatk+Yv+w3UDT0zpUcNA/HsuABuZHk5AOVcE0ldxTpj4qf48adW39LnLmdPLM+IPDr0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615759066835528.7118647285579; Sun, 14 Mar 2021 14:57:46 -0700 (PDT) Received: from localhost ([::1]:37010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYk5-0001JW-MZ for importer@patchew.org; Sun, 14 Mar 2021 17:57:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHJ-0006QC-O4 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:02 -0400 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]:42129) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHG-0008Jr-KL for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: by mail-qk1-x72b.google.com with SMTP id z190so29892161qka.9 for ; Sun, 14 Mar 2021 14:27:58 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HDjwEv5UIDqEnZnnB6TE5sHqCsoYg0tX8iQJ/X9PYNw=; b=ay2hUMtI2wg2+819Yv47rInMk8PbuPyYnWXCAuzb1WZSqwXaUz64ubtNJ6k9x6ZAwS M1rA69q+02NIG27UWQPDkWZ3ykv0h2Ba40boO68hWOFILLfbRmW877CfQHBa/OCnOXCW YhW9TItp9FOFddszYGtnQsNczgcqRPevdx0D45fq4iXHgR23rM1Dii3vAZs4s76B0GuG 8KmHNjSwAVrB1zpldtTv6av+jYB0mjPGNC/tHjKVXehxLiamJF0sWhYTo7FIe8riDLqM Y4HcvgnE03NC4hT7PyVcoMKYZVHh9bVqDRsULz955nH6U9CsuqrrzcXr3Rahz78Dcsuj eNOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HDjwEv5UIDqEnZnnB6TE5sHqCsoYg0tX8iQJ/X9PYNw=; b=TRBcnnzbsNf4/+BLYTCgqVF1679Tl0GGPCHw+eTCSVLfne0eWUG2hKG92TF0hmaELQ qn18Zo66ePyGKe8Vwk16Sg2T9/Gk13V9lumiE0SD0edPO9Kmr20FHOVfTpkZXmvcZ4pz WxMV/Jp5aCPiWQ/Qk8imCl3nY8vguuFYNIvrs1iT1wHHnt13CtMneypHBkvzVtS8QClF R5o72PXUpDjLOdXfInCNUBBaj6Lz7o9VVgApza3S2C7GWESaBmWpCzPUTFulTsXOFKtn O9TxOTR+R3mIDRqRdL5YCDVYTfNAiwgmaDnPsBJuIP1RFwvZ94G0D+m8GdqF9n/QdC4A /BrQ== X-Gm-Message-State: AOAM5332OwVRzT8oNEyKZiUYbr77SHh8aem7L62um6Sj+EGSHKBki9aV s8ieUgqP50rHRIyMd7fIpSxuO+Q5vyKXz+VD X-Google-Smtp-Source: ABdhPJyEy9a6Y+gIMnLqElqkHkymIk1lVYSHYB54tmlufZy6XlDFYvYZxlQe47umt61XXelcmG6u7g== X-Received: by 2002:a05:620a:527:: with SMTP id h7mr22323566qkh.108.1615757277705; Sun, 14 Mar 2021 14:27:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 28/29] tcg: When allocating for !splitwx, begin with PROT_NONE Date: Sun, 14 Mar 2021 15:27:23 -0600 Message-Id: <20210314212724.1917075-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72b; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There's a change in mprotect() behaviour [1] in the latest macOS on M1 and it's not yet clear if it's going to be fixed by Apple. In this case, instead of changing permissions of N guard pages, we change permissions of N rwx regions. The same number of syscalls are required either way. [1] https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f Buglink: https://bugs.launchpad.net/qemu/+bug/1914849 Signed-off-by: Richard Henderson --- tcg/region.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index fac416ebf5..53f78965c7 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -765,12 +765,15 @@ static int alloc_code_gen_buffer(size_t size, int spl= itwx, Error **errp) error_free_or_abort(errp); } =20 - prot =3D 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 =3D PROT_NONE; flags =3D MAP_PRIVATE | MAP_ANONYMOUS; -#ifdef CONFIG_TCG_INTERPRETER - /* The tcg interpreter does not need execute permission. */ - prot =3D PROT_READ | PROT_WRITE; -#elif defined(CONFIG_DARWIN) +#ifdef CONFIG_DARWIN /* Applicable to both iOS and macOS (Apple Silicon). */ if (!splitwx) { flags |=3D MAP_JIT; --=20 2.25.1 From nobody Fri May 17 17:20:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1615759153; cv=none; d=zohomail.com; s=zohoarc; b=mabJ+UMqtNmcTcUnIbJ7rk/TdPMOA7/+7mJxl8Qs6Cg+OSojHBfFS6a1D4kXlgTZF8H1DpRXU1+hwqfg1jLBmReP+LM7S06NIf0mCQ/ks7gg3yP5nRrrmKubIWl3e0sOQYyEYdPWKKyWddbRjlo1ralLycxm40ouwp1t0I17s30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615759153; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ikw13dOWP7lAlgKFWW7kJaboNeemcm515c1euWh3qoM=; b=aPEAVNILwfz/hHjLqbH58JT1/v4fCGhVNcp53IBnDPvc5y4kvEbipcsIwNUStN/hBY/wimRTe5PHnqBlhoOfWmGydKY1G6Le/KiCkrYJaNEZf2aQOnSFc5qgPQiCs5HpX6t/291/rpJKZcKh8YmvaWzPvQ7KySNHUKWq9SaehpA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615759153754278.1960256296337; Sun, 14 Mar 2021 14:59:13 -0700 (PDT) Received: from localhost ([::1]:39154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLYlU-0002GQ-Oj for importer@patchew.org; Sun, 14 Mar 2021 17:59:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLYHK-0006QE-1W for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:02 -0400 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]:42133) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLYHH-0008K1-QR for qemu-devel@nongnu.org; Sun, 14 Mar 2021 17:28:01 -0400 Received: by mail-qk1-x72f.google.com with SMTP id z190so29892186qka.9 for ; Sun, 14 Mar 2021 14:27:59 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t2sm9337749qtd.13.2021.03.14.14.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 14:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ikw13dOWP7lAlgKFWW7kJaboNeemcm515c1euWh3qoM=; b=XbhgSV0+XSAV3sXwI0vtpgVL+rOXB5MIKHC9EmSPetHvOchpFtEnUbij/s39OiPeqR xqzWkP148XpBe4jlXW+UyugLp9TLHda45zw7AWYUQ7jzl1kOP9ebuLXelTTiwtrmyGAp /UuJzkG+sH0mOjAltt/HGXckk+IrI9xY7I1pkZM0dKe2oNHJdlKFZrp6omVL3kmgK79J ytbBtPUeTVJDtqyyVPcZow6RFmt+IchKj5OnJijMecIa6MWkXrwfyjUGyWwGlrvIVRfo OFgiBIhWFn04e2j2BYKZ0Z2VtDPjg77ZGKhTuA1OUc9pyeQc2FN3g/sEcSihTH0rMG61 r1BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ikw13dOWP7lAlgKFWW7kJaboNeemcm515c1euWh3qoM=; b=KNl8I4eK6c9SbLaZyPKXECO92aY8Z4osbPtDErIJVsYGomFMsAtYvoHX6LhKbouA9u n+5a3Ol96kbPPaRBcRCrH/uA7wDZr+bGyCOiq2kAUNSJ4UWlY4G7tZPbQWkqKrq9N3WH rEYDzLb1wa4/50d0ZV8mAjdTNCyFEKQau6dD9BLpyr5gJNbD0wVuX60yf/yfQnMJ1FIs uafJkxvK84dSglpLDCZYuU3hnksxGOUEduM9df5Z/YSAlMSkqRqJouMQqPYx1kqmqJ4S R79RdT7E/bqOCOKAkDs7j4cj/BP5Im0Wxftyg3LZwD6Rv0sDxXOIdh8K6526gEWnwBJX ohkw== X-Gm-Message-State: AOAM533ZVKOYUMcd8PB2525/azGzmgkIwS4lBQ+RTmYA9fpJMmTNnur9 w5E6eIvw9KvlvyfW5MegYqZkyaBWQ6QU4qTK X-Google-Smtp-Source: ABdhPJzBHS9tvbMYGkQbIYSp130yJNGn4It37GzCfEAEaoZlYQxkWipSwo5gvy3KFVYFuzRx0U4Meg== X-Received: by 2002:a37:a404:: with SMTP id n4mr22138457qke.439.1615757279036; Sun, 14 Mar 2021 14:27:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 29/29] tcg: Move tcg_init_ctx and tcg_ctx from accel/tcg/ Date: Sun, 14 Mar 2021 15:27:24 -0600 Message-Id: <20210314212724.1917075-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314212724.1917075-1-richard.henderson@linaro.org> References: <20210314212724.1917075-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::72f; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: r.bolshakov@yadro.com, j@getutm.app, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) These variables belong to the jit side, not the user side. Since tcg_init_ctx is no longer used outside of tcg/, move the declaration to tcg/internal.h. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/tcg/tcg.h | 1 - tcg/internal.h | 1 + accel/tcg/translate-all.c | 3 --- tcg/tcg.c | 3 +++ 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index a19deb529f..eef8857cca 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -690,7 +690,6 @@ static inline bool temp_readonly(TCGTemp *ts) return ts->kind >=3D TEMP_FIXED; } =20 -extern TCGContext tcg_init_ctx; extern __thread TCGContext *tcg_ctx; extern const void *tcg_code_gen_epilogue; extern uintptr_t tcg_splitwx_diff; diff --git a/tcg/internal.h b/tcg/internal.h index f9906523da..181f86507a 100644 --- a/tcg/internal.h +++ b/tcg/internal.h @@ -27,6 +27,7 @@ =20 #define TCG_HIGHWATER 1024 =20 +extern TCGContext tcg_init_ctx; extern TCGContext **tcg_ctxs; extern unsigned int tcg_cur_ctxs; extern unsigned int tcg_max_ctxs; diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 40aeecf611..b32760c253 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -218,9 +218,6 @@ static int v_l2_levels; =20 static void *l1_map[V_L1_MAX_SIZE]; =20 -/* code generation context */ -TCGContext tcg_init_ctx; -__thread TCGContext *tcg_ctx; TBContext tb_ctx; =20 static void page_table_config_init(void) diff --git a/tcg/tcg.c b/tcg/tcg.c index 65f9cf01d5..77335fb60f 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -149,6 +149,9 @@ static int tcg_target_const_match(tcg_target_long val, = TCGType type, static int tcg_out_ldst_finalize(TCGContext *s); #endif =20 +TCGContext tcg_init_ctx; +__thread TCGContext *tcg_ctx; + TCGContext **tcg_ctxs; unsigned int tcg_cur_ctxs; unsigned int tcg_max_ctxs; --=20 2.25.1