From nobody Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997793; cv=none; d=zohomail.com; s=zohoarc; b=C5IEZiR0EtNSHsmT9VbB3+0D0UojThiqtQ6tytL5hgM+qLSvC6SjKF99WSIleh7QIkp4cim1fQAqlZaf3uiDGMQ5fTKrFFfri0PZH/NGQNeeUnY1lw94cfO0ebCExtMwJF9WNLuPBu2bpJPHAunmg+JnPossp1zE5zk27NPCtPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997793; 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=1e+L/3PIqi6UorKNK4j6ulWCMjYwBo4gA3O0a98YIhg=; b=Eb4EyLOCzmwePnPCVf691LLQDMFk+gAdMz+E50i+0b9cwLDO2z4eJ03LSuW3+zJxQZwg/jscUktgiuMg5shILla8PSlCZ7lTa8IRFGsP260DjJoCcuuLNR544PnfYtQNucIIFnTPeXW1+eAHI/nd7x2JHfLuGlGbwnIe2vYfyyI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619997792998117.78863421971369; Sun, 2 May 2021 16:23:12 -0700 (PDT) Received: from localhost ([::1]:42958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLQe-0004vK-0M for importer@patchew.org; Sun, 02 May 2021 19:23:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMS-0008B4-1p for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:52 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:55925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMO-0002pI-W2 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:51 -0400 Received: by mail-pj1-x1035.google.com with SMTP id gj14so2044718pjb.5 for ; Sun, 02 May 2021 16:18:48 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18: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=1e+L/3PIqi6UorKNK4j6ulWCMjYwBo4gA3O0a98YIhg=; b=IYiooxhHXGiQDV5fO4bQRA12LS+V+bol+eXY7OC6VIz9vaZx7QsXwywqvtDBvM16mV AOGrs4srOMN7+4+6NuGZrQ45WxFOnZzDZtVGfFTSv9JP+fmRWIFkQPscfZYcQCIA3/ir tVX9p+hjSrj8M1BvetGBE/eiFOowPK40HdEEmz8p56NwM8cn5JcJ4bGnPDHFIV52UNi2 hZJ37ipWvFNIuueh+HrZ35gKjGIdZ4U0ZMCcEfvJ5bE4mMSOSYIy+zF5GYP5VFnH9/kx PjRPg1vip+5sJGUcSYmcy/4lmcmJe9QSCXW9N3KaytJBei+RakELG0jslZYVL2HIvmwi OuIg== 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=1e+L/3PIqi6UorKNK4j6ulWCMjYwBo4gA3O0a98YIhg=; b=DjLUIqMonh93tEktqv6/yWvxUBm4eo3WLM5IbiqUmsqt0uJBnIO1d5Hflgujq6mKWN 4uREPES4J7MeBCb8B3LFyA2a52iCVaMDxWkl9sSYcosEkuOUnUTrM6ita+iM6OGBW5q9 JkwpHoO/4d9ICJALnLHabZbT5opQI3XsqPwF+BTijHJiXWm0X6m9rzkHts3xNqOt4hYY fN+lLsfM6kNTA23LI0h00LHjdYFxSV3iguMs/ng8lGYxSLBg1mcEUV7iwesqftpT5Utv Sb+jlP8Jvhcox4ObcWKR4wDLATUerjmhIQGskVpXp8pxTqE73Dsx9gCDPnxvvS0MNUna e3VQ== X-Gm-Message-State: AOAM532/AKA91GiUCvh1aMb0KRE6P22zoQKexGiLi/+OAWGTnPV/Wm5R rCrKZrUsPsV2gLXOL3ZbfJU2r74p2d7h/g== X-Google-Smtp-Source: ABdhPJyWsm8Luydj8fwnA9bwa+dokwJOBc7lc1CVwCYSkQ+umc+PxvNH35fVlCfSexfzxZyPwiYxFw== X-Received: by 2002:a17:90b:46d3:: with SMTP id jx19mr27550128pjb.31.1619997527014; Sun, 02 May 2021 16:18:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 01/28] meson: Split out tcg/meson.build Date: Sun, 2 May 2021 16:18:17 -0700 Message-Id: <20210502231844.1977630-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- meson.build | 8 +------- tcg/meson.build | 13 +++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 tcg/meson.build diff --git a/meson.build b/meson.build index d8bb1ec5aa..f04565c5bb 100644 --- a/meson.build +++ b/meson.build @@ -1934,14 +1934,7 @@ common_ss.add(capstone) specific_ss.add(files('cpu.c', 'disas.c', 'gdbstub.c'), capstone) specific_ss.add(when: 'CONFIG_TCG', if_true: files( 'fpu/softfloat.c', - 'tcg/optimize.c', - 'tcg/tcg-common.c', - 'tcg/tcg-op-gvec.c', - 'tcg/tcg-op-vec.c', - 'tcg/tcg-op.c', - 'tcg/tcg.c', )) -specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('tcg/tci.c'= )) =20 # Work around a gcc bug/misfeature wherein constant propagation looks # through an alias: @@ -1971,6 +1964,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997930; cv=none; d=zohomail.com; s=zohoarc; b=Du2niaIaOXTFCaBwonG9DwusZaF+1gMsGGbxhWYBJH6RkAUhm3pBHt1gfRrQffX7JYFLEX2VCTkkqBWEhs0L6Ul9p7R4pdrcpiFF8VW3qntrFfxesIvFWBnlZHUBL5HwnN+qfc7rOG1dlvwwC0OwVKebiU0D18+QchpQfre1pFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997930; 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=FlK8dyxPQbLKFRz76iH/wQkaHIReZuNQ/bKEPInvNwo=; b=fRZ3OkOhE1Oza2/bo38tEWwA1i0R7517khL+Wx8G85s16w4xbJz91zr4baswOPHkgniV36a+CRZvwR0jE+OZ+sshroTn4SfHTt1j4tsQLsRlzsUmhd5CrBSmn6CYbyy3bXpXX8a2t3WGuDyESSHoAzdlJE8Xwjt6WlTwQanen+g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619997930665709.9485420834022; Sun, 2 May 2021 16:25:30 -0700 (PDT) Received: from localhost ([::1]:52064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLSr-0000AV-K7 for importer@patchew.org; Sun, 02 May 2021 19:25:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMU-0008D5-33 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:54 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:36510) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMP-0002pt-IW for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:53 -0400 Received: by mail-pl1-x62e.google.com with SMTP id a11so1869707plh.3 for ; Sun, 02 May 2021 16:18:48 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18: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=FlK8dyxPQbLKFRz76iH/wQkaHIReZuNQ/bKEPInvNwo=; b=d05CtY7iayaLxJlahht6X9YsoLiKlitlJd+90CcZBNvH2AIdRE/MyjYZ78TQFTQVoo 7Ab8SJkABdHx7sgK5HWLk83WdNaP2mTrCugfH41s/gwFFTsF9c23ofZxfMx7CwoxMwqV 06V13ajTMAe2BnHDB8iEuViQaNvsh9YwvWwnXprJoETUSm5XurADS0o9qwXpD+nU80nK 6pMV9u4y5sQ7WM0tir+HP7C5APWnRzveA06SkiuynRft9rngLuSD7pV6DtbGO1jh35iV 70lXyby4GC9yJ/Df/6wO7qqHYX3LBektRHivT3Bxgyek0cBG2o9kG7dQNR7rBHrC+7VA EQFw== 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=FlK8dyxPQbLKFRz76iH/wQkaHIReZuNQ/bKEPInvNwo=; b=C81vBMx34xpCxP6nGphWSnUqqnTDX/K/W/dUI7S2ppdv4/xbpNccF0ITTcXQns+6Zg DBWwcfperPsK/QdV3CeJOnj2afTIMF8aZR1Na8DJK9beyAp+1itmJTamSe1PWc6y6P3j hQVZ/yl6LztNKK1Fhptjfi+m1wi4+RcZrRg0F5pDSBaSffJw9IcNzUa0p80+LJPPJx6/ EjytpFLOjbjBjjmPVmmJjtzerioP4SoyN3slm65z2uDroA2+bXsq2FpY/51Ytl2JaCKk scLiQqf89H8o2q+IgvBj2A1kzW5pGxadVe93P7UH1ndA9mewo0WV68ZjLL8sof0w5y7+ aYng== X-Gm-Message-State: AOAM5337zlrzU+TUVVuLijpgBcNEtK4K7T7ZTWfaORAPZvtczWfTYswf d3TLtEOc79LkuhrvCKqb2XuoCvoTWNx/ng== X-Google-Smtp-Source: ABdhPJyxHkeacYpWKKmgtBND277w9Uc8lvdIk9Ev1lqkT6ae7UIhskal4TwzQ7StrpVQBlyUe5GlOw== X-Received: by 2002:a17:90a:bf0c:: with SMTP id c12mr2978816pjs.206.1619997527518; Sun, 02 May 2021 16:18:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 02/28] meson: Split out fpu/meson.build Date: Sun, 2 May 2021 16:18:18 -0700 Message-Id: <20210502231844.1977630-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 f04565c5bb..bc70c9a2b3 100644 --- a/meson.build +++ b/meson.build @@ -1932,9 +1932,6 @@ subdir('softmmu') =20 common_ss.add(capstone) specific_ss.add(files('cpu.c', 'disas.c', 'gdbstub.c'), capstone) -specific_ss.add(when: 'CONFIG_TCG', if_true: files( - 'fpu/softfloat.c', -)) =20 # Work around a gcc bug/misfeature wherein constant propagation looks # through an alias: @@ -1965,6 +1962,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997657; cv=none; d=zohomail.com; s=zohoarc; b=QfrDuDHqNBBszhpVUSoUlplyOCrQK5FgX5C4o/Xtd/DhoaK53sMPqly2zyyIGReGP7S2EvBFgQzZ5n0SBkPepypT3bYmbYMQvtaBXe2D9yfCUgfXA1zqbt6LbjNhlQe5HyHBauuS7mYQftFmmLXksSdSz/+JrQrT8zLmKULxbUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997657; h=Content-Transfer-Encoding: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=Kr/Q5Rp+D/puQ2m1VQCJ8sEPTdRSEK7blwecPZuFo+Q=; b=F/fqwTZWfmA7+K2rHvttujlMe3iMu8mgHJRUKPqgtF7TmlnynXHmqT8b80yFMGTqCpUwfkA6cPgxJl1a4Py3QKAUAgF6vzQVfWvl8ZTzBAS4y1+7dK2G21SNj/IQw+lrFWh3CCZ51mObwa3DKftevFmcnWSjeTLoWaEHjpTOBrY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619997657515803.3655722066544; Sun, 2 May 2021 16:20:57 -0700 (PDT) Received: from localhost ([::1]:34858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLOS-0001ct-6P for importer@patchew.org; Sun, 02 May 2021 19:20:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMS-0008Bd-Oe for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:52 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:42948) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMP-0002qb-Iu for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:52 -0400 Received: by mail-pg1-x52b.google.com with SMTP id m12so2442936pgr.9 for ; Sun, 02 May 2021 16:18:49 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Kr/Q5Rp+D/puQ2m1VQCJ8sEPTdRSEK7blwecPZuFo+Q=; b=iiJcnhI5wKoANxzKF5zj9QbMyga3ZpZ5YA452dUeNw2O/+vFoQT0JFyfxGy8qk67Hq tNi1v1fbjJmeN0vTM1ULtwo2JM6urCYw4gl6mq4mm45o4YTvrbd13Xs3Od2LFnTM6T3+ W2nSdWtRjVXjvOXsxDDOV6A44FRCEaXuQoWSd0+4DgyeGh4uHNuIP8hF16SqQ3BuU7N2 2SO1eGa7PfIJLPO8XTcUza0aoS+emENhJCTfmx+38MA9Xz3upuWyaUeycvwSqWU6xAkH 6UZf5v7TPusyllBh81B2cG5VtH1z7VZ9r0KvUOWq+/BLYoaWpbvjSuwxNfHayjooOlhZ KEQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kr/Q5Rp+D/puQ2m1VQCJ8sEPTdRSEK7blwecPZuFo+Q=; b=RFybpVaKkXB5BklFU2HVApQiNwGuFo21OUAiXAEvUi9RdVoFOhXKbYJLPU55BauZCR tLxWNo1kgriX9H6Vt2NXknsQsG+eX8gKOGfzukbh0jrllH84Eik7NXsrRplfVRKlBnEm t6l0p7SSXvQKikbl+JMuLslK+A319CBGWRtnQJpHuKleQ30uPzGhH45XDqLS+oFo7ROF jaz3corHzmdxejfMpnE6aiKY+GqSlspwE7RP/ZSYO+DYtRRIMqrQKNejMuoNAKWfZl+n ArlxggueDKvqdnceFRJiY5N//e0P+v7xe5R/EcMW/DFCSBWUJ1TYz560hbCnwV58IWBx Y0Hg== X-Gm-Message-State: AOAM533MHkpi4YDFytfUL7kPqQ9Fleb9An/Y1mZjbG2mK7yLP+/fEcLA l1E/JZZz0KwsdJbtmb7fuqRC2FlObSXz7w== X-Google-Smtp-Source: ABdhPJzmqml54+twSxwCkufxTXBUOKzpM4en6VPrW3BIq2k4W7xkKbb4tT9e1UO5SXucMp5XMsCK3A== X-Received: by 2002:a65:6a0d:: with SMTP id m13mr15831312pgu.43.1619997528163; Sun, 02 May 2021 16:18:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 03/28] tcg: Re-order tcg_region_init vs tcg_prologue_init Date: Sun, 2 May 2021 16:18:19 -0700 Message-Id: <20210502231844.1977630-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 b12d0898d0..9841eb3fb6 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 f956afccab..746d842b58 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -874,7 +874,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 1fbe0b686d..795a71ff25 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1209,32 +1209,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 @@ -1251,32 +1237,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) { @@ -1290,7 +1276,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998099; cv=none; d=zohomail.com; s=zohoarc; b=ZAy92/E1G/kbWC9+uLMHKHzY6iO4Y/vyKvCIhiGSjLZnSxx361PMne2qED4TAn9SUreKoky9NoQ37ZbRgz89ElnDnoMncuD/TPkQN/wgOfFlarieUOfFwR78jUrTmz7aGsZQ0VU2VlukS84zvbA74gAdl6fjKh8k5zGYgvElHow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998099; 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=4cZuoxcwQ6eXvc/QAg7Oih5qEjK3cLKB2wBaiFUenJA=; b=L7qboEUdlORWUTzO+QeS/2wFt+g8tPHtuUarwX501bcm37F+IgVimzlRcyG+vR0KhMwYAldTWl5JAEtKIr71uFaodvgALLzxLExv3rMTxwFNltYGxD11VU5kv/Q0OFcO57mxfOg1Mwsb9G8PhGOOVclqExF9qkQ0d1PlnOSj22U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998099501503.8137177470792; Sun, 2 May 2021 16:28:19 -0700 (PDT) Received: from localhost ([::1]:60788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLVa-0003oW-H0 for importer@patchew.org; Sun, 02 May 2021 19:28:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMU-0008Dp-Gz for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:54 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:42879) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMQ-0002qn-6m for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:54 -0400 Received: by mail-pj1-x1032.google.com with SMTP id j6-20020a17090adc86b02900cbfe6f2c96so2309720pjv.1 for ; Sun, 02 May 2021 16:18:49 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18: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=4cZuoxcwQ6eXvc/QAg7Oih5qEjK3cLKB2wBaiFUenJA=; b=FTNlv1ZEPxIHdsw9/PcT6g8lFQtXzm4QImZKOKke+yIyO2Bjg+5jUivJHk9Qj9i0+K kifhEzWHyBYHzD/YR35ZMXfFKEVoiYGyDqP77uU067im+RfO4P8IBpqQgZuHIxHUhNVb OuB3wCDa6c/jWjw8wmV5yBVNjThlJN/yLQTbWORcWNRdDjanwiuqAvsVn1CtOZA0RGEd Mt7usMGanvItBxlBr2YO6d6C065+kMj8N296699Ovj26DM9c67spfSpooe6ajOyZcjn2 kQb/OcliLttwiXxU1gyJuPXOiNtAQdrfvaGjliFNU9642E1qcIGDDJD3B7xNJOa+Zexw MNKA== 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=4cZuoxcwQ6eXvc/QAg7Oih5qEjK3cLKB2wBaiFUenJA=; b=E+AtAoFo5SCI7QoC1ZLT5zH2UbNnMoqSeW9uA5HtJhuSxdJ1cr8MPELbONoa35zB+x KHyJNaksZ5r45Fa9R44OKvpPmj9SXPa6CUTcbITLfpwZQLvPHGSL0pqxJvwNS6+szNpJ z8pVUH66f+4db+Io+dyj1K+nhmkoJHPSWap2hUJvvC4T7zeKPnZ4Vjb5T6iq1ttFeuW+ R65MguNRfj2bLk//ZyboAh3n4U6moTrnhOOACt9GbhHYoTS7lRTWUa2agmni137CsPOS OezCwIz2CuGz2OpCpgOdx+dGfdeuXro52Vr8/SPvcelA/6fHagRkJSc0NRBUGMvS0Wrd PZwA== X-Gm-Message-State: AOAM530zAtxWO7vlAekFJsd/vY6stzBQwkbFVhLkLqS86D0uftFM+rXB EvPpV+pckW7KJk+Qq8o4RPd394+++DwH4A== X-Google-Smtp-Source: ABdhPJw+kRIj3qFV4bgY3mHMA0/nLrH3avNIg9P0YmdAFEsP3Bl05V5r7sSxwcTDaZ1fK0NptvQqHg== X-Received: by 2002:a17:90b:2390:: with SMTP id mr16mr11196668pjb.133.1619997528983; Sun, 02 May 2021 16:18:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 04/28] tcg: Remove error return from tcg_region_initial_alloc__locked Date: Sun, 2 May 2021 16:18:20 -0700 Message-Id: <20210502231844.1977630-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/tcg.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 795a71ff25..8b57e93ca2 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -723,9 +723,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 */ @@ -740,9 +741,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 @@ -879,11 +878,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 @@ -945,7 +940,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 @@ -969,8 +963,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997657; cv=none; d=zohomail.com; s=zohoarc; b=nXUCVhWPZutpKdAQlmDyV9aL9/Adl1cq7IWmI4xt4qlZ/kV/9n51J8sm1J8/IRNayj16qgjyD53eFWHymP5bq/n8waJTaKGk9ORYQgNnQbLhT4D+IWGGWeC9ufV08GxdO9rOJGvPH+5B2WI1vQfBfSGomAlvdMoKJE3WieYmZFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997657; h=Content-Transfer-Encoding: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=T+bwWhG2aXu2Jmbr5CuBFk282uxjI9dQD6yjHdIosCw=; b=VwMCASxi8CIN+qamdvPSWY8l2l+jt2He0/wmfCwq/ckKCSHPYlfapEqUQR+hs+Sc+YOCpLQebgRFMAL52Q2yyK99UY7wEEfe44kW30Pp9I4rnZT886FPjgmIqCJABWnLakhtJkefQFIZNRRN+VpKH019BTs6vzADjitiUaYn3pU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619997657515503.3343661333938; Sun, 2 May 2021 16:20:57 -0700 (PDT) Received: from localhost ([::1]:34864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLOS-0001d3-8V for importer@patchew.org; Sun, 02 May 2021 19:20:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMT-0008By-1O for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:53 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:35386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMR-0002rP-8b for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:52 -0400 Received: by mail-pf1-x429.google.com with SMTP id i13so2965587pfu.2 for ; Sun, 02 May 2021 16:18:50 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=T+bwWhG2aXu2Jmbr5CuBFk282uxjI9dQD6yjHdIosCw=; b=Ev9Mj1jtE97HX4Ltzg1fVGHCDILy2H4SUI9bO1k/z5GJC+oUK7BUDQkRedHF8b4uWt hpBCMbQtJ0CKL7blMr3YZxhzB8G/jJ1R2I4gczBdVnO4VLiCreApO4xyHdXbrD8eK4gw +gIyRaCL0PBBJnCJxvimw0jC1fhlbRx5JPECLrYxalD85kwZ3yum64vKmzu7bgnh6Rr4 hWwunu7kwEfEt5EX/3S0XgP20i320t1sN5s2t8BRw146bM6hNUE6NimJj6niyDSDkRDK Yx/aIy9vBQbxdTPkATLFP5Z2/HN6ZVTNANC+nWnltSu98vatoUo8BhJG/9AejYn66h/Z ZM6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T+bwWhG2aXu2Jmbr5CuBFk282uxjI9dQD6yjHdIosCw=; b=al70vKO0/Mt/MEJf24iPtCzG+uvkPlS2D86FCzVP4urULz0w1vzlE/08Bv2bLqI0jY 2ai50wAxL8Kb4NIFPT619aHh0DxNVOAav5cFDuoyjLv3s2P2Mm699HUC6B06qxAYvnrV wm1+Z+MGjfnGc1sjPrctkYf7dpF3kQpRiSJ4F8ePKIB9C4HcW+mnUhDAGH/ybuOGQq0/ z7dMKmy5eMtUX8QAhZV+qNqfI5KA5J1wfhqv11pvgDhqJZjy1l5AG5zSFYu4j7MshaqY e9LWeK1mxpno4h/i7mzEnSN+gf61ywNL1sOpNUJzBhQooufKG6FyorBS6a5DYHWqcyDz X68w== X-Gm-Message-State: AOAM530wllLvBF36akNK5zBwU0uIws0YcIUR8dt72tdTUNIQCbf9YEg/ W0Q+a5oM+B+xC0LMrhXqywIByn1D7ULE3A== X-Google-Smtp-Source: ABdhPJwE2kPbFSa9PL0QZcABUt0ICTNwGXpBne+nBIxtxvZNDCnIjWmKMOx0n6y0Cye5mqqhdiauFQ== X-Received: by 2002:a65:4548:: with SMTP id x8mr15532509pgr.413.1619997529870; Sun, 02 May 2021 16:18:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 05/28] tcg: Split out tcg_region_initial_alloc Date: Sun, 2 May 2021 16:18:21 -0700 Message-Id: <20210502231844.1977630-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/tcg.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 8b57e93ca2..df78c89673 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -729,6 +729,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) { @@ -962,9 +971,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997823; cv=none; d=zohomail.com; s=zohoarc; b=LKcSLjOgpzxmzrf+FPvIYISWaDFB/S0I4e35dHv5XscS7yDfh7jm+1Eva1lwwy4yAs8ybWUIfBDwVST3S2sDdOUscyCiqgof6XtZNHg6/gffYYYuK7GpcZHwNGm/a1O9KKGGckIKmXQuUHEnklymqA+sHaepr/T3J7GB6dSd4dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997823; h=Content-Transfer-Encoding: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=sBQ1+Rv2XXbszZHsJR/EueMHmCKRSaUBKr3RPrTCguk=; b=QMO36q/RVZHPd8D79lsL654M9/yicskzuX2a8KZUhQ41gPSP62g6Bbsy3dv+b2ANbWTKv/VbaG+Gt4tQG7UC78TPfKlqsCwA4MjWT456qqWIhpaSKCdOIYxv2xjUJqCMe1BqhEsP0gczl6LgDJryglMP3cMSoujZURxJ40jMNI0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 16199978235201000.3556516446575; Sun, 2 May 2021 16:23:43 -0700 (PDT) Received: from localhost ([::1]:43502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLR8-00058M-Af for importer@patchew.org; Sun, 02 May 2021 19:23:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMT-0008Ce-NP for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:53 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]:40792) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMR-0002s6-Us for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:53 -0400 Received: by mail-pl1-x62a.google.com with SMTP id n16so1776630plf.7 for ; Sun, 02 May 2021 16:18:51 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=sBQ1+Rv2XXbszZHsJR/EueMHmCKRSaUBKr3RPrTCguk=; b=LgNwLPFpZXkaGbqqFIqx9umW9JFiw78WHudW/YgDnQ/Z1YAF0w/plfuM5Q0kxFmvXm 5diRYWQnjGozoWHRD8gjbMFgG/IDsVpoUM/v1j0wJRKcAraswy6u3IiWHhTROZIB1ZwK O8DFvS9+P3uvdrl+1/t4s11lPvFas0kd0tHTggUZE9sk+/WuHO8/5oLd4Z92GEo58W1a 4S1Dq/uhB4u4B8lMYNT7DKKof85y3fL9SrVSWIhUpxM0WVQGhYtip3CV763K/FjaLM/C SM91exRRxiWdBCKpXprb6+QBI9WEv/gVIvLwS99YV6suoscxORmeNZ+lvfM5g8b0F9Qu IZ+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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sBQ1+Rv2XXbszZHsJR/EueMHmCKRSaUBKr3RPrTCguk=; b=AG4Qddkkxc+XRCMCIAYn0ujyN6szc0n8wDzF5JwVjJpUG0AlPzLexq603SBsQOnSFB OzFWLOUSBnguG422FkFIxGQuj3O+MvZMsBzyVXM6qpLQloEBU4T8czwisRNaxKxzTtLj +qQJE/YnqbsfHt6xFAYY56B2IAeDYhvDZY33vr0jX3z+nPmRe4ecAIWKDDPqZCVgyGOv rt+oIErese6esjW8o12VuzJd7f4gBFuTtiy7nBoIWaH+paZ+2vQUZhYqKw8AHJhJskb3 ttlePGcD0v4PqdETI4NVU5kJaa3nVWotsKbpSPFklRwu7eaT9wBSpdFj2AmfNA9qGZjQ LSbA== X-Gm-Message-State: AOAM533La4px0cYMugsmjhLfNcKbY+wH0sYivQ29xssHReDZYeym0Ow7 bgU5O/AjHCwzsGknxlnStUoHGublczteLg== X-Google-Smtp-Source: ABdhPJy40L0dtq7oAaNOYC2Z/i+tG/0dwdNFopDnm41jaDElNF1+fyrHLZ0IbR1ID1nBCEbkyvj7/A== X-Received: by 2002:a17:90b:347:: with SMTP id fh7mr18204681pjb.23.1619997530725; Sun, 02 May 2021 16:18:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 06/28] tcg: Split out tcg_region_prologue_set Date: Sun, 2 May 2021 16:18:22 -0700 Message-Id: <20210502231844.1977630-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::62a; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/tcg.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index df78c89673..ee3319e163 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -885,10 +885,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 @@ -968,10 +984,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 @@ -1211,8 +1227,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; @@ -1244,14 +1258,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998342; cv=none; d=zohomail.com; s=zohoarc; b=XC+3wx1g6Cl/qX53Tvh+268ETYsxGfMFbgPUwzSxMsWKEu67Mzw8WRqB6IGzLg4T4Swp+iVWx8aVGk5ljeq+7ak5bUMUBqNsJiil6Vhm0mv3Posn9ePJHgOM9zFloy1eUYkCrL9tVrtAEf9RzW9nLj5ioe5P8+6AiLVe0jv0AxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998342; h=Content-Transfer-Encoding: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=RG5hll6d3Z+rOlSTjQDQlSL4v8tj2OIfzaOlqk1Ic44=; b=R+8RZq19gSuuuIE4eyImfEGlVioSKTypPzvbY3CtJ8V50zSaVadlxwyoISykWQDEjjqudyMFe5cveFPjomir+pY0F0RnQshAFf69xMgYn8hfwmY0sMHLHEVoVnxq7/RE9fcxVsyFwuuoJyqEaZkTcCacENeWsunz7c139o0dPlA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998342071544.921390009369; Sun, 2 May 2021 16:32:22 -0700 (PDT) Received: from localhost ([::1]:46960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLZU-0001Ie-Le for importer@patchew.org; Sun, 02 May 2021 19:32:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMX-0008JY-Kt for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:58 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:37643) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMT-0002su-9G for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:57 -0400 Received: by mail-pf1-x42b.google.com with SMTP id b15so2955591pfl.4 for ; Sun, 02 May 2021 16:18:52 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=RG5hll6d3Z+rOlSTjQDQlSL4v8tj2OIfzaOlqk1Ic44=; b=cUJJKrn4325LLzxiQ7bJ1IwoEbDxIFC2awhoW+YG7SDPhuTOtJjYYxa4n3N+oL/wfi TCrL+HFRWzeXq62ZGE0ftixBGdrARhT1V1a1yTFmxh1Y4UkKaulYaX5p6L+EQnNF3tYZ QcjIE8yaSCKiKDg24T3B788uJIHRF7SXH8vVNftA6GutCSqpJZTrDoa62/+aUKTDop5d poTiJszOugh7mTJNKODWQxIDeX4q1B8bKlwOrF4+K4xtKkpGlql7npFQlvPZWlsMpm4a MXXrbLTsTO5B7O3nArSazZnGALGLboSRFIaRE0IMasAuMmuF17dBmLm430nCUEX/6dmu Fztg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RG5hll6d3Z+rOlSTjQDQlSL4v8tj2OIfzaOlqk1Ic44=; b=jKsX9B2HjjK+iBY5ebm3yutCuWQs19POGfV7/P6f2u4d6xWURqvtsvSa8RrlLjvt4F EWfG1yi4BW2cUEkPgScL42OnyFRZuW3zup/boFRtWkQJBCDd07Gsu+8w5V0lkIf5a4mH 09BIfOB7ohmrWeeslNli9OFPlNh3KrYdSh9JLBaPLM5foGVZbat/ZzdpWHz62wc/6PKF A2UgR5yZdMKs9F/ASnQb5FE+6RLa5nHHyQ2iNsFjtyTa0Br3DtDQJXtd5YoogUnpgeFN Z/IBs8I6M27mCJE3u8uHYL3/pnM+5TdeDU/i9IwEYNIPMbtvvLkdbkLw31FqX9q9AOXA KEiw== X-Gm-Message-State: AOAM532f+Vn/KJPiJ8M5Ruu4yM/Pzw5LX0TkQczLoeaHSeBD/HT9PMnF 4u7W6pf4vzUqOL121DnI1UTLDwbg2pU/WA== X-Google-Smtp-Source: ABdhPJw6iB3smyvbHr9T3UJUQdJWfs3T9BAo/xtu/bPeCNPJmhdQHfarJhBfpQyiGpOZskrbb79KnA== X-Received: by 2002:a63:5503:: with SMTP id j3mr15662956pgb.256.1619997531497; Sun, 02 May 2021 16:18:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 07/28] tcg: Split out region.c Date: Sun, 2 May 2021 16:18:23 -0700 Message-Id: <20210502231844.1977630-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/internal.h | 37 ++++ tcg/region.c | 572 ++++++++++++++++++++++++++++++++++++++++++++++++ tcg/tcg.c | 547 +-------------------------------------------- tcg/meson.build | 1 + 4 files changed, 613 insertions(+), 544 deletions(-) create mode 100644 tcg/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..ba3677f474 --- /dev/null +++ b/tcg/region.c @@ -0,0 +1,572 @@ +/* + * Memory region management for Tiny Code Generator for QEMU + * + * Copyright (c) 2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), 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; + + 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 in the rw buffer, as that's the one into which + * buffer overruns could occur. Do not set guard pages in the rx + * buffer -- let that one use hugepages throughout. + */ + for (i =3D 0; i < region.n; i++) { + void *start, *end; + + tcg_region_bounds(i, &start, &end); + + /* + * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprote= ct + * rejects a permission change from RWX -> NONE. Guard pages are + * nice for bug detection but are not essential; ignore any failur= e. + */ + (void)qemu_mprotect_none(end, page_size); + } + + tcg_region_trees_init(); + + /* + * Leave the initial context initialized to the first region. + * This will be the context into which we generate the prologue. + * It is also the only context for CONFIG_USER_ONLY. + */ + tcg_region_initial_alloc__locked(&tcg_init_ctx); +} + +void tcg_region_prologue_set(TCGContext *s) +{ + /* Deduct the prologue from the first region. */ + g_assert(region.start =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 ee3319e163..26eeed05d9 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. */ @@ -156,10 +157,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; @@ -168,42 +167,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 @@ -460,453 +423,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; - - 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 in the rw buffer, as that's the one into which - * buffer overruns could occur. Do not set guard pages in the rx - * buffer -- let that one use hugepages throughout. - */ - for (i =3D 0; i < region.n; i++) { - void *start, *end; - - tcg_region_bounds(i, &start, &end); - - /* - * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprote= ct - * rejects a permission change from RWX -> NONE. Guard pages are - * nice for bug detection but are not essential; ignore any failur= e. - */ - (void)qemu_mprotect_none(end, page_size); - } - - tcg_region_trees_init(); - - /* - * Leave the initial context initialized to the first region. - * This will be the context into which we generate the prologue. - * It is also the only context for CONFIG_USER_ONLY. - */ - tcg_region_initial_alloc__locked(&tcg_init_ctx); -} - -static void tcg_region_prologue_set(TCGContext *s) -{ - /* Deduct the prologue from the first region. */ - g_assert(region.start =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) { @@ -991,63 +507,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998234; cv=none; d=zohomail.com; s=zohoarc; b=axZ78aSN3MWBbxyFS/UWwCeozL9DSU54pQv79Rp2Ytxm8wCbqerIfJWyu6IJ9hl56QYYgy4+yPMrgaTzFmNx6HUZT7oaOJladH+E+Btxcj0Mv8im3mHy39si+R3n60ub+Le798FwJjob7SfZU64wlwEiso63gsoDuduEh59rAJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998234; 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=d8CBczrHncTC7jkXzgGz+cyQf3ESCXlA91ntw2lzZG8=; b=cZIU4mDZsMGn/o0QA5p9uP1W1PYGYhwHB6MyKkeXrksFpTcV9MihMiF28tIiYL5l88wotpvHqFdKyCvpbUXk98UCYYrCwnxQtXEj3KJ/tWLtUKeIY9xUTOugjbr4HpxQ6XYjB6SaknSBzCSxRNI3F5Cb179v+NSNxideFcCfhPc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998234296587.6795870663378; Sun, 2 May 2021 16:30:34 -0700 (PDT) Received: from localhost ([::1]:40186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLXl-0006tN-7r for importer@patchew.org; Sun, 02 May 2021 19:30:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMV-0008EZ-56 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:55 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:36512) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMT-0002tC-Gx for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:54 -0400 Received: by mail-pl1-x630.google.com with SMTP id a11so1869772plh.3 for ; Sun, 02 May 2021 16:18:53 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18: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=d8CBczrHncTC7jkXzgGz+cyQf3ESCXlA91ntw2lzZG8=; b=E+rva+qJrH5ryjX/w0DsX04yeyndYJamgacOvmFmRACHYpAs0grm6ePy18ilacQAsA xr4WDjYfbs+tphG5T/95j8JjFoIZWoqnlIBy7bM4zmHOqh5lxHMQLWdPeIPmPLXgcy7E Rfc28rHjHfuhdvSDpBDoKqfRQnI365+Fz1t8qM7vQRzXDbotddOL7cIhuDHk+p0aXw4x OpXQVYLXxGki1aAaJhF+AElbz5ZX14NAYnYwFV4iWLfGWvNdy2xq/5HfG0udX395MwNm /CD18DqC+6/+tbH57860V7mhuwzVI+abWLIHx7L4zS5LZ9B93TJS/06d9hmSS1tZZb5v qV0g== 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=d8CBczrHncTC7jkXzgGz+cyQf3ESCXlA91ntw2lzZG8=; b=hrx+tox4vmEuide3fV88h/PC+5S7ovCJF0fpTVWDwNLa0OJZMaZwFRmEgWLGOEOmuA qU6kzH/qLervf5EFp5MGybOJYKdeyFSTMV3uNVg2mJ+pAAlFDbEchInuzCpUIdquQgyP zPrDZJFjukrOsLJDJ1Jj/X8FPXZ/0ZF/fU/WmfId1EcU7pztdnNouK3Z+oOCJua0aHG0 wHaxsJWcIpW0gjSIv7un1+9445vVu/F3j6VHhQmzBAiMxKEaJfCIzsZ77D0xZ38Q/CLD MGyuwpNf/tfMTU3Ms3nOAEtqqp62mihqkslxs+ZwfLFop5OPS0xrWASp014YDrbOPm3F 5+cg== X-Gm-Message-State: AOAM5334R2EIlxJN05BJ2VvPdAa2CBKfnK11ZbiO3C7JEtbuXKJJolMv Z9a1u6Fu1Uw8SHFHSx5dkhe1IPF7Ycmo3w== X-Google-Smtp-Source: ABdhPJxIkpVscWH+M2KVghjjC/eW6sKgaMGpz5KucvyHG0dUzPpCjfLO3/YNSuTroBV+U9k5bYnGnw== X-Received: by 2002:a17:90a:d17:: with SMTP id t23mr5025999pja.163.1619997532215; Sun, 02 May 2021 16:18:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 08/28] accel/tcg: Inline cpu_gen_init Date: Sun, 2 May 2021 16:18:24 -0700 Message-Id: <20210502231844.1977630-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) It consists of one function call and has only one caller. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 9841eb3fb6..d55ecbe195 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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998464; cv=none; d=zohomail.com; s=zohoarc; b=e1KqCbTH4DCpJaF03rMHFfsaVDhd/BZ1jsaqoF+HRktLH9XEsxd8HzPtWgbRo0WHnfIdQixxDfhT488QQhgD4FwqxdbJ3GNgIv88ioTsyz8zEpL+iMGvniOJTuhcR22oAYVrmJfU7eCoIUL3JQ5XzHqeAozcY3mnJ5qW5ivCUWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998464; h=Content-Transfer-Encoding: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=iPIiSqY/IHv8pgYAcnIhbyeSmMZl5W5sie6hTUGBiUc=; b=oIQFmQ5h9WC5NeGhkiPmpaQ0oItMASQJTnwcYfNr3gdvUOS9wH2k4nuqOncYlkRUi75OFhNuOoKEmoY8LgI+/4Son7vFG7PXhre4u53oCkruL/Y7GkeJzFjhVxLabPCrTXJ4uCvPpK2pCPt9c+1yurJrSdXfOZo16jadSH6htQA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998464560566.8213649010581; Sun, 2 May 2021 16:34:24 -0700 (PDT) Received: from localhost ([::1]:51772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLbT-0003HY-EP for importer@patchew.org; Sun, 02 May 2021 19:34:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMY-0008Jf-51 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:58 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:34406) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMU-0002u3-J4 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:57 -0400 Received: by mail-pg1-x530.google.com with SMTP id z16so2470214pga.1 for ; Sun, 02 May 2021 16:18:54 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=iPIiSqY/IHv8pgYAcnIhbyeSmMZl5W5sie6hTUGBiUc=; b=MyTZ8t0oETSa4tvENMkA/eXOV1YwRX+ilFvX6yKB8QNmP0doDojQPxMbNyKbA0Da/D flme2yEN3B5m1l6jE1L/BfkhvX3gBMrehaitdDCT4MrPPQFR01LWZ7ykyBM32XL/vct+ aHMywk3UGROjpBOo7i59rSdxKRSIJRXYp0hOI0evbG9TU/5Wff0F/SByjejyKeQgDpgC 8E5O88GkI+BfQWief7BOraQeCLiSxx2aMaBU6ArAEhNqa0z7TdMIbPssqteZNSKNNvPs yPBqbUNDkPiFMXp/E8g3DwDKCzbR3PyiVIOXIZnMJZIRTeBycCiMVgs4SoC+nGNYbt9w Ssog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iPIiSqY/IHv8pgYAcnIhbyeSmMZl5W5sie6hTUGBiUc=; b=iFLsHzI3ONe10H/uEVXyFzwRu41/4g2gwJBbukXs809UZD8kL/X3/wYL/4bW5zDPhJ SZQZS6v4L2KPvJWEaKy0cOQsjuXMfYPZXYf6kbD0JPCslvQ7BeUclWZKrjotqFmtmMa9 Jzw35Mvua3v3sAkGDywlFDuJTd9XB6tmqJ6dscmXurJk375ae7YKyuCXORv2Qb4UsHf6 0gVKAg7uVTNwHvcWwr9TRk0NaCx3xu4aKXyktIgKB1d0rhW3poxnwhNwM3FYlW3cTK4/ 1nMhE7FCnHYC6caEfloIfuI9P219U0cwVxF4nrj9awMDGlSAiTP9wgdiQgJbzlU4MRVC 30Rg== X-Gm-Message-State: AOAM532mmUjsM5pbgBJdEEYemqOfPOqwJaJPcbSmHsemQCxZHAZmLgbv Fkh1QT78XSkv9jAtwhZeqrKqfoZlNpVi3Q== X-Google-Smtp-Source: ABdhPJxMRmkNF0nhtPKewvcEte2N2OiMT9iaKlbeBtenQLVPpFBFnUzViO635Zuofr+HgOwFX9yxLg== X-Received: by 2002:a63:5b23:: with SMTP id p35mr15446019pgb.352.1619997533016; Sun, 02 May 2021 16:18:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 09/28] accel/tcg: Move alloc_code_gen_buffer to tcg/region.c Date: Sun, 2 May 2021 16:18:25 -0700 Message-Id: <20210502231844.1977630-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 d55ecbe195..e481f23ac2 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 ba3677f474..ddcbf7113e 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,16 +838,23 @@ 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; + 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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997822; cv=none; d=zohomail.com; s=zohoarc; b=iTiE2nZ30z8iA3ssLYvXmzco+2w42NL8qVn9AcMgZ4osSiOKtNDeDX0x5JqF9iTv4G/rOWP6s8y2zWo2CHUgc10LglXK9gJw3w4FQ0ZPCMR9cWSj4Vn1YkDSTz1Pwc2E0LzN2zvHsTMy5a62KLCi0cBCnnLzJjY353KUgYMk5Ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997822; 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=Gb0nu2rL9tGYbJmbXa3njpk1bLgZEDygDFbFIhX/boL1QOZqkJkH7MxqVnKs3QRKfGisv5mh2zO4OucnpX7Q/I41VA/7+YHAaoIGn7Q/40O3By5ycuIsQh51117J/VbdCm9/Xq8iv4pIn1o352KZikGmk8k1fpMhYaU9FJuLJdU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619997822794550.7664676197013; Sun, 2 May 2021 16:23:42 -0700 (PDT) Received: from localhost ([::1]:43462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLR7-00057Z-PB for importer@patchew.org; Sun, 02 May 2021 19:23:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMW-0008HQ-DN for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:56 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:39652) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMU-0002uO-Nm for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:56 -0400 Received: by mail-pg1-x530.google.com with SMTP id s22so2452477pgk.6 for ; Sun, 02 May 2021 16:18:54 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M+GW/FjdFE0LjCNjl+PKpujGwHht+vUuynWRRTNqZ50=; b=ynpYBzhTcxaiE3SUl1tIz4geQnWN7S21LcTW9hRgX/HtOuKvCHnyPHfF4fnrDCClmA eU36oVGpjgwNvXYrE10NF2//9R8jFYJ6sSR/AQ6UPXAA+lJgjj7L5Bu7NcdCANfbQFT8 yjSUJbJo8y/YS4zbVmJYBusFRTcCQTXEXOva9Zgc4W2EjojvrtK1JWhhFiFY4b3k4tSH mnCl4AWWd15909oiI2vZcmdJh+KDT3ft82u8kuEmcEunEJWFTsf3sGEireQ4aHNic4Vv EoyEp2+03CFFOy6pr/wfVqgo2c9kNL60dRpXs+8rg/ydmUUtkXW4jFvvB/JdAMvEsAYi LBaQ== 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=N3G2GIbKI4tERc3s3rnrkax61mTCdY14W2UjMCGIWJvlvkXyLnvtYWGiNUoAvBBdtE nJXsckdg6vvkC636rS5rhCr0740vtl97P9CZugcfWyvwcuqCk4YsVSLReqkDxQaH1M4y 4L9uw8u5o1bQ8/RFJQTYx9Ei9/2tWyt2T/YmwytZj8z8M6Gb+6mOvsH06u4AnPRWohWx 9/IN/b0YlLtFDBomyJ6WUinY/h1JD+p1CkGrLDKpwDp0hLVN9/C6/Rwrhq8z+rFpTJnF PoklAfXbLabADYJ6zuEBAXlpwg+n44zCIBq3pOm6cl6M0g1c0RAHiSMgs6NKNosDEaKe FhGg== X-Gm-Message-State: AOAM532hQy7gCnahWeyCNa/q5019xhTL1+tDt50TkLE5JrhJPhZTtqG+ jImRkpqls+EgIEUF8cGTc2O8jOwW8vqffw== X-Google-Smtp-Source: ABdhPJzhBvspVZ4tfrjPi2NUfVX9brjUuAO5aqhB0oPZ4r5RIMINWgPqgm0IIZ8msplJzeNS2JeMSg== X-Received: by 2002:a63:f90d:: with SMTP id h13mr15712450pgi.18.1619997533531; Sun, 02 May 2021 16:18:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 10/28] accel/tcg: Rename tcg_init to tcg_init_machine Date: Sun, 2 May 2021 16:18:26 -0700 Message-Id: <20210502231844.1977630-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997825; cv=none; d=zohomail.com; s=zohoarc; b=Lyrob8Hrpx0YBmMn+BHySjjiSzoYNpWCLjpq87XN1OLbe1c9iRM85OeCkGzmjtgLFDhJHbie763vzC1+FXhBFhaKtd90sNxg9Fkr4+NQyYGippnS6fxT9LHRpYN0O2G2IVc0ACY273WIN/DvScSQceo9GlLHhdLL52po3IAL9jA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997825; h=Content-Transfer-Encoding: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=GXOmKXszIGwBckjBN7CglCgbQXtrKK9pBKMuXQiqDTI=; b=Ixs/oAjldLHzpohchezsJboWIYJKCmzpfRyS32qeXdbb1yinLbyzpjOvG9Kw2DVCQOaUqD+e91uv8B11X43w7MLR3esR0mTP/rEQaxOw9AzY/EgH3Xo1RwtOaIVvxhLvZGO03avgg21KBrxT2lIBBxBMXUky2CbBgfUFyqFY5kg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619997825807488.61801122490976; Sun, 2 May 2021 16:23:45 -0700 (PDT) Received: from localhost ([::1]:43776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLRA-0005F3-PE for importer@patchew.org; Sun, 02 May 2021 19:23:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36984) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMZ-0008K9-4W for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:00 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:55915) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMV-0002ue-LI for qemu-devel@nongnu.org; Sun, 02 May 2021 19:18:58 -0400 Received: by mail-pj1-x102a.google.com with SMTP id gj14so2044804pjb.5 for ; Sun, 02 May 2021 16:18:55 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=GXOmKXszIGwBckjBN7CglCgbQXtrKK9pBKMuXQiqDTI=; b=n10v2TV3GGT1QuaQkkC+yCWivJ8tX4HMofBOTk7bmUwNDmXeZnaoCLNUxW86su884n LaHUyZCNhIy253y0LMrnXoiWnYWEwrPBubRFFbNnA0XoQcjahg8WAWsnJ5Fpx3mxytHd blpxKAuhRwsgU1hCg+paqbb2I62VDcF2VC5+fjB1WAHFX1ldixb02B/+W9efJuHnmnE6 vOvLjfkPzGtf9vTthz4Jfo8zOR3FnWXxxjTCLWO2YKnan5d/htry/vAm4C30QXDm+mon Gk9UC31wfkDQC12WMNvLUwBuScqOYI7En2E61W3QqQa6Q7m+cH4uVNULbrQbBGJLqhrB LyuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GXOmKXszIGwBckjBN7CglCgbQXtrKK9pBKMuXQiqDTI=; b=pUm42E1CPvpdx4VHkkBIjo+uRqXNpBcSA1zhmq1QGb9ouECxG80asIx/82qszKrd0o +937n3kH3ClQ2SoY4V1yFvG/PgEXfPz8JZ6cG8LpsKgjuPjz515aQGOSIknMncmdS9Q4 Q9V/w+jCZcAaE2X9+SIlYnIo7DXFI+WZ7MEK+0stcZqvMv6AvUFVYuPPVHRuzsRaBhZL fx3o2QNapWZJ8mViQhEKwNh/+KOX76xPLRKVea+MNTc/Tuny3cTMEE4Fk8vAbnk6iXIb nMkgtVQuWHi51ZnIWx5NFP3lTrVUjdqj1P9+Rr8truJjR4LWMMiK1RWhaX6iwybFeOzU efWw== X-Gm-Message-State: AOAM530Kz1+MO6txebuXYBMkoKergKqLAJqdMEGD8UJYBdTh6NxVk0nx Ws7zx8FKoBjewLAkcAoY+H8vRop7OdiA6A== X-Google-Smtp-Source: ABdhPJxoncksfmyVnkAEujjW7ukVmq8spgkNA53xPlBedvmc4xYdgVGbLbcB1FbEBT2TQJrxA7lbpg== X-Received: by 2002:a17:90a:4b0e:: with SMTP id g14mr15679052pjh.48.1619997534324; Sun, 02 May 2021 16:18:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 11/28] tcg: Create tcg_init Date: Sun, 2 May 2021 16:18:27 -0700 Message-Id: <20210502231844.1977630-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 e481f23ac2..bebb3366c0 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 26eeed05d9..92749a2f8b 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -579,8 +579,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; @@ -657,6 +658,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997934; cv=none; d=zohomail.com; s=zohoarc; b=R33KhTYgyVvlbEEyTExOe4PT9J7fa6LmH/Bd/Zndnmf1a6k9T1++r9FMKQHExQOFjb923OCh2GOG83LsJV9GViDDU/78AAVwBxjEMzMx/L+hPgnhtaK2U8nQ6Bz+GpBbIiRNiJ/cUnWzpO2D+gtHujf1TDc9kFqBO2YlCI8mg0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997934; h=Content-Transfer-Encoding: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=2nk/Vuj2SdpJZ1YLzrc/VRv2Wt05fw7xVDCD8BqAg9c=; b=J6siUfc8tedU0aLuWmmqxsQhA9B0MVIAQsUrQaUh0spoRzZZg6A7G9Y1MlVV9qlwlFXN5qyuBejBm0xTUL8IpbSqSEZ7Rq3mL2TaQ1My0gX4YjEAFmVg5A2VPa+FtJfwRmQaxELu8VxU1AjDU4UdZ4KcDEd+bylXEai3jGmG+/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619997934162578.2685669997499; Sun, 2 May 2021 16:25:34 -0700 (PDT) Received: from localhost ([::1]:52404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLSv-0000Iz-0F for importer@patchew.org; Sun, 02 May 2021 19:25:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMc-0008Ki-88 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:02 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:41855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMW-0002vJ-Ao for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:01 -0400 Received: by mail-pj1-x1035.google.com with SMTP id x7-20020a17090a5307b02901589d39576eso170895pjh.0 for ; Sun, 02 May 2021 16:18:55 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=2nk/Vuj2SdpJZ1YLzrc/VRv2Wt05fw7xVDCD8BqAg9c=; b=BxYNy4PlDmNZzBWOeGz1kIKFJLqs7yN4ayJ1KwfKvBvPPXRwWGWAXq4Pus0C+mv19q R6F3qEJe3SGgwnPLendiYid0A+5iu2QQ/JOfj3DT8P8/iiY26dNwgSRmAFunatCvJXLX UVjEUSXm1GwrzAcH/PM+dkur91kEa9rAkrReVl3i8YX31zDX7t9qVdZgRuhiW5BJtQeU DlcAeK5sNeMm3KIj8ccXY4eqnbXj/ZlVXegCW6JI0yNraDYAI7pA5wo6Sb7ZhWF8G+0s xJdCxRqNrvGMOqW4qj/Aqt/PT+aqouvgHFXZ6BA0qyDPoEao9ppdSeN1p3z3DQtcWhw7 TYWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2nk/Vuj2SdpJZ1YLzrc/VRv2Wt05fw7xVDCD8BqAg9c=; b=i9ePDCRJDx6Gdm4whXIG0ZUg5nhwcpW741XU8tjlGw080WjB+L5U55M32lDhdnZsgr GB4XYbHBH8aPtOZj0ujbYEiljqGTo0Z2JncVQYSQxSGX3rSKwfqzlK6KtOBW6iHn4ZXe cU17Jpe83xetSgTHtIK8Cedu1KTPhULqK4eQHgCj1uhwWdweOJxzTKI34h0uTCDG3Xpi 3kM5OboTQZOtHlY24J0x3bmBrYBk/bb7f1gKQ7rPt1nhjacemVeWif6bHuKFLa/gZGQI zbuHttjkNoibA/jhH9A32iRP4GHK0GNZ35dSZyrIHzfl1KI7qk56VLpVxT3xaT2gAuEs +leA== X-Gm-Message-State: AOAM531E89X2EGCTbMnF6qniXZrNuyQgvZFozM6VA3q/TbhDSP5EfuWZ DUDojY+2613sdAyFxN9jonTbLqR5D2XE3A== X-Google-Smtp-Source: ABdhPJxoztoEZcx8VT+RwkIJziMcNFppvwSDfg3vgeS5uvdHqqBeyJ2oFWnBW7chY9ApKYsWatN4rg== X-Received: by 2002:a17:902:dccc:b029:ed:32ed:e7d0 with SMTP id t12-20020a170902dcccb02900ed32ede7d0mr17415097pll.79.1619997534926; Sun, 02 May 2021 16:18:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 12/28] accel/tcg: Merge tcg_exec_init into tcg_init_machine Date: Sun, 2 May 2021 16:18:28 -0700 Message-Id: <20210502231844.1977630-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 bebb3366c0..0c818c3618 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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997931; cv=none; d=zohomail.com; s=zohoarc; b=cTardSvvJsJnuK7UytJNFKLW0pZbDTJft6/2M00PNxYeYOgP20eSf0SyI40+hph+RSJB69XTVeWiguZieSNW5yglCNKQrIIDdWgwSAuGDX0W7IFQBNZrFYuzfw6eSiNEUaqHwOdb3KnPJUydHnSRBDfNWvyhjQiPS/LqP5z2pUU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997931; 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=iojAJu7Pxy1uH4OTAeQ4zSPiG2hYAgOBc04Nh+PmbfI=; b=MfS7ZMvqN6SarWXQgvuP7gCuCcB/Fsn8LZtn47bZjQYltQlimkFG43zend9cOoQfA1Td9JBL2DeyhvITcwRGhQW9bAZSYDAiGHtwhuo3nGWbfWVxkHuWhMiz0KERQ9DPTeY7DxRM3OL9H1VMFb3KexRo0xe0CckDrupQlMY169w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619997931627932.7826779878433; Sun, 2 May 2021 16:25:31 -0700 (PDT) Received: from localhost ([::1]:52150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLSs-0000Cf-Ix for importer@patchew.org; Sun, 02 May 2021 19:25:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMa-0008KT-JJ for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:00 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:44936) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMX-0002vi-Aw for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:00 -0400 Received: by mail-pf1-x42f.google.com with SMTP id m11so2921602pfc.11 for ; Sun, 02 May 2021 16:18:56 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18: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=iojAJu7Pxy1uH4OTAeQ4zSPiG2hYAgOBc04Nh+PmbfI=; b=gYDbIlFGpN7THjCgAM9gBFhjrxGphnzxbRh058uhHB4ecLDBZX6kmSybFCumwX9tSq 0F9zAW/3pXVxw5al2fafufmmnjU5PI183WlwnOOOwxa9Cy0sIAAd/dEL5j8qsna7VCz7 LvgVIPk/mgDJU/yiBKQJL0T+dagfjkCvpvm7Rpl6Bv9RCnjHaJvGm0CnI/Z249NTGSNy NBq8rZU+o2kuQgTDwTNDakgCTCx7DdnT+mJqyTdgwENxDxcNSCXosmJRdDh8eKTPkd+Z i0sTNK5t5bQOjI/IDDUB/y8FPUlPHcUbaEkTT8TJkQU4UbJV/gKwfe5Fs2AO/1nVFdFK xmiA== 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=iojAJu7Pxy1uH4OTAeQ4zSPiG2hYAgOBc04Nh+PmbfI=; b=sZSzajn+QsNf9BVlPIAhW6i+KLZfY9V+9sBxmAtOCMVzbfXj7bxwmon+Vv4aUZ9nq4 E8AjmCIyDhpcWHb2PZ2MMLx2zkKjcRwSVHQQ15AclnLPUM+fosWxjwZBRhq5nNPhwy7h 4bbtEJUB+sUqjSWjj5wPyO2n7fHo5La8uUJ1HEqSrtFRs0uTQ2s+5HlzJV3PNUsN7avs Hh7mQRWwong+RrZruIo9Kd3mUj0Qz23i16J+bBwQP92kEjeLhX+0QLgrWleWYaY4idac G6W32xeZD4NuvdE+PE8jYj9lG4vZcTTB3IQqHIJIe5CnW1O2OJN6Pejtw8gi6w7yKWuA LpRw== X-Gm-Message-State: AOAM533Io3OZrAU09uZyuuCpXMuTl3yZsIPWLz2TwloYP4JI+1nwC77S RE7zc/Q4c9IAdT4U9xmV9nkcNcN4i4g2Aw== X-Google-Smtp-Source: ABdhPJy2kvqJO8TSQjbA2gJPZrDXTyyu2CewIh2MrZT6PncsGE2PsIuor/9lL/59Prmjt4PFync39Q== X-Received: by 2002:a05:6a00:8c7:b029:20f:1cf4:d02 with SMTP id s7-20020a056a0008c7b029020f1cf40d02mr16194269pfu.49.1619997535859; Sun, 02 May 2021 16:18:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 13/28] accel/tcg: Pass down max_cpus to tcg_init Date: Sun, 2 May 2021 16:18:29 -0700 Message-Id: <20210502231844.1977630-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 ddcbf7113e..f9e93e85b3 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; @@ -855,7 +845,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 92749a2f8b..5af51d41ee 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -579,7 +579,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; @@ -648,8 +648,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 @@ -658,10 +656,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998100; cv=none; d=zohomail.com; s=zohoarc; b=my8/AzrnCGgn37/+FQiipW+dZhtMwK8f5vvzs9xMc2RtaWSe83HHpXTAolYK01bdQf1y0MHLJnIUKzbCMWprFzSmOG/6W3VU33wLT6FllT6DYkHVKfDY4SorHgQI7ErJpbaimQrC2E2yx3/n6QuuOX+bp3gqKiOQG2s/qjvE59A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998100; 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=mRgvCIDFvA5UlQTj7r2nU69wxLSUlzYCUC/NBBipjpc=; b=NxDHTwQKsZxXVPzzTF/gPbg6cczgkNzSBXWrR1juPyp2Zbw3ujKBkCnOr9GuiUsfzMsegKvoAi1jPSqRgux2/EEhM765uRzzj+ABOYRtqBBSj6PI1vCJvIcdw9FtEYpffvnkdixWi5LQSOHUC+V4NOK4B6Vh5Ucrh/E99r2+VLU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998100890865.9644733288266; Sun, 2 May 2021 16:28:20 -0700 (PDT) Received: from localhost ([::1]:60886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLVb-0003r0-S7 for importer@patchew.org; Sun, 02 May 2021 19:28:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMc-0008Ls-TC for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:05 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:40794) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMX-0002wM-RS for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:02 -0400 Received: by mail-pl1-x62c.google.com with SMTP id n16so1776686plf.7 for ; Sun, 02 May 2021 16:18:57 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18: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=mRgvCIDFvA5UlQTj7r2nU69wxLSUlzYCUC/NBBipjpc=; b=x453Sr/GcQsuehPBG/uN+gTmEmu8uS66nhghLnkTlSS7+87vLcAkqxPVY7BMev+Xx1 RI2EIBuUXagRc6QHCVnP5Izf5oTBk2Y/yma2naaPmcFhT8UE3G8+Y7ZzDElHZRAg8Jxt hMWcvZ68yzI9FW/kGozXO98Ye4PWNiV0K+vhRLsAnbvCfvFZQE1r3Q3xmAN2OXhKDCt8 D/8fArF2HVAIUPnLijooWp9zRgrKztD862K7gp3RBwPbQVO4FNb87r3X1ZA/xSoUwP0w IpSGuAmYWHNtsPgj6SwD0zykRdVjyJwWFYEfkWDJnZycBy9W4RBMOItm10RIb80tKlvq gdzQ== 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=mRgvCIDFvA5UlQTj7r2nU69wxLSUlzYCUC/NBBipjpc=; b=gC9AiXPuG0N7SKiLEix09PeQ2kKqc/oSNvOkcd3BxQLfgaWAshfy9r9f/FQL0E/iII YQSwV1ayTPW6Rs7i6FjQ+fsIQv38t+e7tJbJ08+g8P+ptYSgGjrZ9PSiPvfUw8yxuVU6 WaapocSHwryJNSCQTBOUPLIi0pBeGjgrfTQNF6aNzyTyoIHEhyh5sIs+xxM1o6zB0c/0 hahYKIInOf1QsgBPUAQ1TunaN4Y7koTHTbXsha+CbTNmPFzOU1I4QVkQUbcWYqlL5tSN iiaXGvEBSS5vyWamVLCUKqJm/+6GzjFJyVw4QK9UTEYc45pbtUXGrgK8+n39oo0h3jS0 f2MA== X-Gm-Message-State: AOAM531QfJD9hGi3mdHG6bTUn22pckGOe0QLt+Z0xofuGBf4bE00r7j8 EK+BRCrSnTWGo26VICeQRFVM4UJ/p3nGbw== X-Google-Smtp-Source: ABdhPJzWqqwJbPz1QxUW954iV+dtJi0dYIro/C6Cx2lfOiFRFB5FN2b6rFGQdSb8homwf8JY5ru41w== X-Received: by 2002:a17:90a:e615:: with SMTP id j21mr27513347pjy.43.1619997536566; Sun, 02 May 2021 16:18:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 14/28] tcg: Introduce tcg_max_ctxs Date: Sun, 2 May 2021 16:18:30 -0700 Message-Id: <20210502231844.1977630-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 f9e93e85b3..142b27276b 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); @@ -924,7 +924,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 @@ -960,7 +960,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 5af51d41ee..0926454845 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 @@ -158,7 +153,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; @@ -478,7 +474,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 @@ -494,8 +489,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) { @@ -646,9 +641,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)); @@ -3940,7 +3937,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++) { @@ -4003,7 +4000,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997660; cv=none; d=zohomail.com; s=zohoarc; b=Y1OB1O6GRlVluAgrxSMMuU1Yqz25601U6+0U1bjmz90IhLeLne8/AhN5KX0njZlLwg8gquZQ+JHS6/Kbj7uIGouzNS6stGQ8dnr0+/gKFD4QC5UiewHleRISpvF/N/1qBXODYtIPV/z1AxIb3SU+desKv+h8MHus8U/bJ3dYtoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997660; h=Content-Transfer-Encoding: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=3t8lsfbGKLoXDpmvXxZMx3IVfaXvb/XOOzS5SgrqqOU=; b=i02pcOtWnIkNU8OOfHweE3qJAR/w3Yu5xlNftLKbWul/VIGiI8T4bZycyGO05SjbwrohyUY5bvlyE8T74smkqr0RXSpmLAB6xOvXOJERnX/v8ZqlvGALNuLoJRDDuexrdWsqlqzCgZMrikhEpMaoVOkv71DcMBkNGu0tgWyjOjU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 161999766031074.82264240534448; Sun, 2 May 2021 16:21:00 -0700 (PDT) Received: from localhost ([::1]:35142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLOV-0001kw-AE for importer@patchew.org; Sun, 02 May 2021 19:20:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMa-0008KZ-Sq for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:02 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:50926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMY-0002wp-QK for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:00 -0400 Received: by mail-pj1-x1031.google.com with SMTP id md17so2066041pjb.0 for ; Sun, 02 May 2021 16:18:58 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=3t8lsfbGKLoXDpmvXxZMx3IVfaXvb/XOOzS5SgrqqOU=; b=HUa+FaKAFFxqX+O2mMAhOcsqO1Gz6jdcySkRVN1/mn0qmjh50ze0TadHbLHBgPivWX bRFOWrom5wbTZIM7aU+USC5dLduHgMUmby2sFE3Z1Xhq9ayFQnjFFggQIZHaw0wxwmZc rL1QiB3LzGMGVZ2BcjUTv2/yAgBxYpMw2bRHKmMu21DVKeK19MjKVxkd+hOdyiDgVKc8 73McT3XTZKuQjfe1UYnnslSjo8UNLj0aRY2vh1Y0ASSryHP/GngJWNiF2omreZpa9uMf hje9m3Yt/ynWDtKsVP0Sbx9Hw/sfjIN0tWIHb6Un2Tg9hjSmQv6ttak6uiVnPChUGVdF kmcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3t8lsfbGKLoXDpmvXxZMx3IVfaXvb/XOOzS5SgrqqOU=; b=dvfp1tFbb8eM8PnsaCLsNw7BLUKonW6Z0g+Ff+OC+y+UYPz3Opm6TV6AGCZI3BKlQp TspUONA31C05LQscbI1Mut6sFbYy/n2a1mz3Hn2d4bf7amz7o4pTp8Zaq9jHvOfCQnHE QAKNW5dOn9ZMoutYd2O5sM0vH5dx5hz5JIN8qaLBCgijSyX3xIbEIPgA+dN4bhl5pQ9t pDk5Qd4bX7UqL6NIzwHxYFRct+j1SvVHdDx/MOxuUAmkoEECQpxtVmXoy6vD4ZznYLtM axb513d+Gf5+k6R4/UF7DnToifp0OoBkzH5cLgPldRgZt6ttNJMz5X+IEIVyttgRVBvK glCQ== X-Gm-Message-State: AOAM532EU+p52CpJKzNXtMWabn1BaTW9vl28nzLqYwYrpxGRR3K/3Vqa OSbsAJtz6uCqgrnOiY0xw0vW1ELjwAZvcQ== X-Google-Smtp-Source: ABdhPJyMKR4kr3ik6arM8XScpUpm+BDSaviWMHfYLj4BLMXgPyZHynnBe5b98JYq8ILS+IZ5NvkPuw== X-Received: by 2002:a17:902:ea8b:b029:ed:3b25:15f7 with SMTP id x11-20020a170902ea8bb02900ed3b2515f7mr17288709plb.62.1619997537453; Sun, 02 May 2021 16:18:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 15/28] tcg: Move MAX_CODE_GEN_BUFFER_SIZE to tcg-target.h Date: Sun, 2 May 2021 16:18:31 -0700 Message-Id: <20210502231844.1977630-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 52af6d8bc5..d0b5f3fa64 100644 --- a/tcg/tci/tcg-target.h +++ b/tcg/tci/tcg-target.h @@ -43,6 +43,7 @@ #define TCG_TARGET_INTERPRETER 1 #define TCG_TARGET_INSN_UNIT_SIZE 1 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 32 +#define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) =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 142b27276b..9a1e039824 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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998656; cv=none; d=zohomail.com; s=zohoarc; b=MQgIJpYwKNQmIwWNKhJAEZnwIrLGaYJvZHj9sEYcCFVcSpEhplNtAB3jXDbGAzwbk93tVRDBN1ZLGRPG14s5tgrHyMMXyF+J6rGpazsgBCCSu3UwNIvMJXq1dbuRB9rtr378QsDnhqRAuuufEnKXMitjhPYpIKqabPCdkZlLUoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998656; h=Content-Transfer-Encoding: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=xx8tRHMyHl5/LaDMF0obGZKdN5Jc9YJNwYigENo1M50=; b=h3lUjhWY/BM5yd4ylJL4kkE8nrEAGx6gotPFifOfxWi1AzFUxbaTVAzY3XsdBvSVYRvIzR/Q5YnEoQ/fa/A9VvRexwCw3CejIcWea8gQWw50bG7Glcoczrq1SZVtW35Rx/tn+z6t1ywR2oXdnGnmf4J4IrN8uAeb4JdsiQCnzwk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 161999865613357.94059067785349; Sun, 2 May 2021 16:37:36 -0700 (PDT) Received: from localhost ([::1]:60500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLeX-0006sn-UD for importer@patchew.org; Sun, 02 May 2021 19:37:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMd-0008Lx-Bs for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:05 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:33571) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMa-0002wx-AX for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:03 -0400 Received: by mail-pf1-x42e.google.com with SMTP id h11so2993653pfn.0 for ; Sun, 02 May 2021 16:18:59 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=xx8tRHMyHl5/LaDMF0obGZKdN5Jc9YJNwYigENo1M50=; b=f9q+M7uK4Cl00bcg6ti/HakN55r6IJ4Tsvd5o7EVjfsQdGsT+enoLrtHiWVOCJ/4N7 J+hXplJ0KqN/GkK9nnpvGvJ0iRXOf6n2+3vi4aY4RahFn+29U0G2Kh65hKkE0/k+g0PS 3fTdWp+PJEAjQAGnGguGI6qNAEMFrQaPsj1OxBbXyXjJpN3+u4b0MRRL1QrxWEXtfkV+ 5gAtQkmiS2jzhm2blaLnG4l6JYa9WSogCQj+hCsSEmRiJ3+OylMjHksl5+CcucZSivfI 6aNVMorVqNQTb91eQgag/MCk6nG3NtoecZ46ysZdwW0GqH9VCB4Tj1p/vkaQC4Ijj3fM WSTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xx8tRHMyHl5/LaDMF0obGZKdN5Jc9YJNwYigENo1M50=; b=fvRAVRezBt4tfLybeTJ6YcF4xrphHQF7dpt+Wt0gcTNQIPGzgT+ocGt/2asWqNlzCd 0NTD1w9tyEmVPqwaSh5syxh3ENyey4uRo1ldejZAnhSbiNXfuK33hr20kanmENeyoUBD a1ftVAwB6PV6OhPwqdzeJv6vc/zPiEvmP/aXFvQtAdghzcQWpTI03sh6HHuOUc4qEbxL QK9LcYGeOnT2JLpNDNHgVVrW3DvCjGYGFL6tgSftSdmBJLZ5ehcH57lRx0Rrfzpytg5V Y2wqVsZOsFmxPX/nUmeaEwpWSvQuYZwA0VWAg8p6DNGmnH/eHfbypUzEHKFxIPcRVH/7 l8+w== X-Gm-Message-State: AOAM533Akxiv0kkaPiWk1r0YPIRW9XBogFwqAS5ZvXcQLOPo09x5xRhM wGSz/lXGm4UQpiR/SuHNPqHbxcyaD0sFuA== X-Google-Smtp-Source: ABdhPJwFADiXOTcIrlG6P+dO0SiNAz1eSa2pTYla6aWy5DP6nYSRlMiCAbdGaDsV5o0icJpmxjGbyQ== X-Received: by 2002:a62:754d:0:b029:289:11e7:4103 with SMTP id q74-20020a62754d0000b029028911e74103mr14416390pfc.25.1619997538205; Sun, 02 May 2021 16:18:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 16/28] tcg: Replace region.end with region.total_size Date: Sun, 2 May 2021 16:18:32 -0700 Message-Id: <20210502231844.1977630-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/region.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 9a1e039824..a17f342f38 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; @@ -826,19 +826,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 */ @@ -852,9 +853,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 in the rw buffer, as that's the one into which @@ -895,7 +898,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 /* @@ -936,8 +939,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619997923; cv=none; d=zohomail.com; s=zohoarc; b=NTlcfFYvvxsq7w4mYRXlIgjcuIeB44DqZMTAecouXeEXKVBJpCkx9zH7uzb3Y+gAivX1RNWNK29Nzom6cf7UExrxqOOHxwm4QUsLGN7uPJUUPyiwExR0mgTU0h4h84cqe4aROXLPZjkypDTqdNEh/yPiU9lCilE4NDYf2TCh5aM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619997923; h=Content-Transfer-Encoding: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=lnCJFh2Rv+h4NLtp2hQeAPYuSx8EMRNHvOCihIxCdAk=; b=HPMWCN4L/Nyggh3Ajg95fWExtpFvzFnpOZrBXtXG9somceFq6VO9fT+djbD4J7g9y4HgGxDEVBuEUOENfsY4gmvIfI7JzbGPhj0sf8uPT2VmC4RePPalgaH/IeUq9DnGbtvhFbL/vSZthv4cX/Cf5hCn0bj+8Hqe5hULZuRnaG8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619997923356293.18377962768784; Sun, 2 May 2021 16:25:23 -0700 (PDT) Received: from localhost ([::1]:51462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLSk-0008N7-8O for importer@patchew.org; Sun, 02 May 2021 19:25:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMc-0008Kn-DF for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:02 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:38837) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMa-0002x4-9u for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:02 -0400 Received: by mail-pj1-x1031.google.com with SMTP id f11-20020a17090a638bb02901524d3a3d48so4706076pjj.3 for ; Sun, 02 May 2021 16:18:59 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lnCJFh2Rv+h4NLtp2hQeAPYuSx8EMRNHvOCihIxCdAk=; b=DAtFGrlbfaE3Np+K1BiL6Sg48aLsyJ1Xe5BHVI8VMhD+CFuBSFk6yXUAVHyFIzvfMD kynXKVNzi79x59sRMwkg4WtUO68vHDnaB11BekZGgLxNczhuNuArbPZKNAdL70RfzaYl 6LAkePXuiELoCrAdOMxf07lmFN0S4cf0yv/AyiO9vdJvjajPVL8CUSgqHhgVEZCRQt6+ dg3BFZqvan/aEBaJNxe5tHqfwgtlQryKDVTkgmW6pQDoE0QWbSvGzECe2yS+qnaq7XRM n89JGqDkJn+nOi98Enn0ZT+J7JUmwa5kWrbQCMEJyM6TWImbMoUYBMPK9tyb6vJBWXMh Y7vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lnCJFh2Rv+h4NLtp2hQeAPYuSx8EMRNHvOCihIxCdAk=; b=QsA5MGaFYiK0cjQa81oDHyligKsWFUEvWHwSCCKCXhc8GIkmFsJ1jtenqUgxK0Fi24 PsGUtPe72jyWrKd2jsJ3fpWtfIBtWVoVJR1iKfyBD34RbuT2puAZiC/N+0WF23hWD04x e6Gg7DqCP9n3Kv6/RtHpArflLvjdXGc8msdU9kQG7XjBddWwyE3h6JomQRJRKLZxCm80 dif7C0hZrt5EuWDnkT/VR/FRIk8vITdaWRtH4wBmCINrR/OuRbgbO1FcvN7j9Xz7OP+A /tIYZqQEyFBt8/RekuEcy4G7vQS+8QQ0bjL7ZZiD481UWNnaHtSiz0BahN0x5MqjzZJ4 u14Q== X-Gm-Message-State: AOAM5331imG/oFKYWjhazzwToIB798uSZsPSvqoP0/6nuU4WhJS8xhXr FjZLnJW93jHEroA3pZ2Yx1b2mUKSqwZEKQ== X-Google-Smtp-Source: ABdhPJzD21efjdf4kux6P1HxOYYRI+FyuigTqliPjdj3g0HwuG4dLfTsf1kkp8Qy/He7WtN9YdGTsw== X-Received: by 2002:a17:90a:5885:: with SMTP id j5mr28024033pji.102.1619997538788; Sun, 02 May 2021 16:18:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 17/28] tcg: Rename region.start to region.after_prologue Date: Sun, 2 May 2021 16:18:33 -0700 Message-Id: <20210502231844.1977630-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Give the field a name reflecting its actual meaning. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/region.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index a17f342f38..bd81b35359 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; @@ -850,7 +850,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); @@ -890,15 +890,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998987; cv=none; d=zohomail.com; s=zohoarc; b=RtOyTazEu0ZyUJ5z8XHTOymjwDuX0E+R/WugfIghFKa6yvZobr+U7/yEfBtULsJE2pG4r4EvkxWB0Yn0lWIqfcaTtbWgQCFGQNzSL+XjFc8KoP9D5dd+oAFfaBTs7EXfyL1CK/rwYWiBKX5ynOLPNeQwCKA1M40DyFS6V3QH+p8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998987; h=Content-Transfer-Encoding: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=idNS6LRLDr7PE0vfbI3FZv/MhqMVmpiiFES5YjT5ohE=; b=crfjr6b60kQH2p8rUR7XTkc9liOMqUws6QHF8beZAUsJ/ZfiAXmz3W1j6Zw3I/JRNq9+GHdGmrHroc/q9t8WuAQHohaUSrzwnNKSjhstqFmCs3pU5teOyiyXZjC9X9Y6N+3MkPLGoI9ky1+6nZfb10y9jEIcrXbLtOCZtWO+1Lk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998987123645.1229064316273; Sun, 2 May 2021 16:43:07 -0700 (PDT) Received: from localhost ([::1]:42176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLjt-0002ir-Q8 for importer@patchew.org; Sun, 02 May 2021 19:43:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMj-0008Mw-91 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:10 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:50927) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMa-0002x9-JZ for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:09 -0400 Received: by mail-pj1-x1032.google.com with SMTP id md17so2066060pjb.0 for ; Sun, 02 May 2021 16:19:00 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=idNS6LRLDr7PE0vfbI3FZv/MhqMVmpiiFES5YjT5ohE=; b=tNxOHt39BDQ62poKmgS4JCLJpGXlYQDeySP03Yi2qiZhZ/heK/h8BEmHaqvEY8t7A4 JLFJ7E1Q6v1iBpTlORLtXKkuz2cMue6lu+nQ5VF3HMay9zMPgT8eL5dPKksM3WKdJMhY p7VNxtpXWK7HLpM78Kt01Wmdgnz2oRck11HDyFWwUmjzBPggwWUWy4AZ3xJuPyc/GNgP Nvltp4eBIqaBdqVztX9Tz99S4J1JbKfUKi+U0XmExlmNvmEBsZYRm2IACwXYrJFPdHi4 /uU6X/fU5i9rHaCy4l2By3dO7UqmlcppDnIST5uT9A/PVKX82mZk8vI5iNrZ53AQsElm L5ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=idNS6LRLDr7PE0vfbI3FZv/MhqMVmpiiFES5YjT5ohE=; b=YHsMc0D2MavY4/JzTMHfdOTJq+OW1izHIhNIdhbwWJzCOh/bBjQHCoOjnrQ/hmqD56 d2qdS4uEqQxXr2FtcVjld/xZ4Ol2oHmmA/s6NUZMZxjKElfCldiwEcco2ZiWW6VEgpge +1PMnU3DlMztHWWgvIBiShpV+VT7mOCVZN1CevSOuXs5kYP0oZ7amRQd8iPf0XTlmJHI s0i6NxXwGPsz4kdiLkG4C3dWfMZtR64mrmKtsgvHp4BY4afXkTwtJw6LjkJmwjPrnA/G 2rD+V5UD3sDoSuzJvcRc/lEjazFfCdTdAI0zM3cGVypHIQR3N/I/FbM291326lMU3P8D zDGA== X-Gm-Message-State: AOAM532l2W22iXS/5Ob1+25Bmq2x82a80ZhfLm37AUudJkWK6QaiMtSM GUWh0X55QX6CCq6u3xe9wtfcvZAYa3VsBw== X-Google-Smtp-Source: ABdhPJw55yCFEe1lMNh0ml6UG6o3MS/IRSuzzHNsan4LlJ+e1oLDX0fSZQbWQydEqgGrtn/7YeGy+g== X-Received: by 2002:a17:90a:1b62:: with SMTP id q89mr28053991pjq.141.1619997539276; Sun, 02 May 2021 16:18:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 18/28] tcg: Tidy tcg_n_regions Date: Sun, 2 May 2021 16:18:34 -0700 Message-Id: <20210502231844.1977630-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/region.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index bd81b35359..b44246e1aa 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 @@ -828,7 +823,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998573; cv=none; d=zohomail.com; s=zohoarc; b=dGfjzion8J607mgBAFANN5ZjdSYyMTPTeIN3N+/PIQ/QlHOA8ge8G2x3k7zouBMf3e4ioMHz5AAp5zYm2CMUIW8Pru5tpfQspfgZM0sEiR73dXMZo+FewEiM2eVosyNP10QjW+oagI5osf6njgpqYv/NWw4NSA42mGyeHnHzSPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998573; h=Content-Transfer-Encoding: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=+T1+Qy3MoywAjez6Ef0bmMy71JTW9fUaEucN6MXf9Xc=; b=ThhghftL3pagIO3ix6awJ/9JkFc/Fx0oQnefn7n3R+aHXzz6qBCIE0oL//RBZLZ/5gAjXDQ+2ITj776lJRMHaYb0nc0+OUxclEeNX6H6ElsorDAZ4ndk4/wu14xkea0+1UwcUIGL8bzybGfk7P5D+6AwJL2rMez/CX8AVLs+p5o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998573262369.4854782647092; Sun, 2 May 2021 16:36:13 -0700 (PDT) Received: from localhost ([::1]:56174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLdE-00059z-A8 for importer@patchew.org; Sun, 02 May 2021 19:36:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMd-0008Lz-MX for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:06 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:40600) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMb-0002xF-9B for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:03 -0400 Received: by mail-pj1-x1031.google.com with SMTP id l10-20020a17090a850ab0290155b06f6267so4700332pjn.5 for ; Sun, 02 May 2021 16:19:00 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.18.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+T1+Qy3MoywAjez6Ef0bmMy71JTW9fUaEucN6MXf9Xc=; b=tWBNMCTHNcU1/pmqgs2oD4oF6MPoTHUel6RgvFpDllUhVcjEsiBYlftsknFFcpTeAX cTl0GQR12zHDo+Jbo6WfJX8qKFan7HQuIMdooU9GFR/G1d1/ljmJtcnxmLh4WbK+xJG1 m3Nr88tyotYXA/HK85uoLD5fA2Aszqsb00iNuwGuNYPkXXYOU7iO9GrBqH4jh+mClwVY 2zo22q/FwK2KsNVICfumYY8SYxAEvRjq3xlj1p3OCpqllfHQmo7kdztnYU/df6fRj2nU 2VEe++WGkQMQ0JOKZ4HsFP1Z3dDizz8wTxinGBP/DvefD7jxrGs45tdGEbFWsJryx95Z NzqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+T1+Qy3MoywAjez6Ef0bmMy71JTW9fUaEucN6MXf9Xc=; b=q3bNr4QsQeXZfpb2UCpoz/2fCPM403nqAR/MPK/ZKof8rHDa9c69mWMh9GBC4FhYEj 9aJVFt+SUuS7J4IBfQFu4SuXrX2QmRXxcGrQ8Fo1vD9Y0yOiK8sYBhPn/AKixHCYUxdb ZGbwFyuO4S0ANYT0tW0gF6uAufZc0EvtoG7JyTX4g/LRA3AAVzgyaY0Pyde+kawpW55o oaCANjWiABVxKot8AnRmSFmTuVhd+rGjoikNcS1ZaxXsK0xjJWH9s7KgeOtBPtzKEheV FEp9MxyHkKsUehouK6DbcI/qFxZrL20jMhNTIhHKqh8cprS7cD1Uy/hYcRtdc7t8tE48 fUhg== X-Gm-Message-State: AOAM531wJWOSVs2SgdzlBAbjxmgI5GL78gL0tR3wSVtMI42P/kcK56bT AARL/V8h9IGLnN6u5om3mQytrErza/TvTg== X-Google-Smtp-Source: ABdhPJwfzSiYv5Qu6JgWI92zDvh6/5MU+jIyjOzhZ8w8I7bPmHf3NkMepljGAP+0kmaw02jngTZ46A== X-Received: by 2002:a17:90a:e64e:: with SMTP id ep14mr17940878pjb.103.1619997539975; Sun, 02 May 2021 16:18:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 19/28] tcg: Tidy split_cross_256mb Date: Sun, 2 May 2021 16:18:35 -0700 Message-Id: <20210502231844.1977630-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/region.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index b44246e1aa..652f328d2c 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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998844; cv=none; d=zohomail.com; s=zohoarc; b=RCIGVye9PHRdBtBLoLEFcaIWBb9C/6C2NRXlyM2zCZmQQ+vmvmA7J2FJgQXpcJJaOz2A+vWm/GHx+dzE70/4ggcHyfXvCMJXLdbb0uFRrrqUrN4ryAIvkTWW+XzU64MVW1DIP9zOrjGQDBEnTpqindYYDMRBzrqRkNeKbcPJmzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998844; h=Content-Transfer-Encoding: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=3+qvAys+bC4iB3oxnM72GbfzF+QWmjj72t2D1jOredk=; b=B32hZxtlBy0hz7gDNtDBTVssO50Ih1LkGWRlO8MbpxyvhHOrMBs5Fe4L2ly3+r4rNs2FPcNa8hMGlbAaVQ8nI+KhtKa1O0caOcQ2nZxZpQcsv7sKSUne6bgJ/PXyMhOfru5ZiDt9a52RXS46xXlVrCOcnSAT6OxmNJTES3xdZxk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998844088982.1663112181843; Sun, 2 May 2021 16:40:44 -0700 (PDT) Received: from localhost ([::1]:37532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLhb-0000eK-0i for importer@patchew.org; Sun, 02 May 2021 19:40:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMg-0008ME-FU for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:06 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:37501) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMc-0002xR-3m for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:03 -0400 Received: by mail-pj1-x102d.google.com with SMTP id k3-20020a17090ad083b0290155b934a295so4722326pju.2 for ; Sun, 02 May 2021 16:19:01 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.19.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=3+qvAys+bC4iB3oxnM72GbfzF+QWmjj72t2D1jOredk=; b=CY2E5kuv59LbsNiJJrF75ZkCRfFbMPUDod9g3cXTvJRKW/9vNLZLmhinuWeHrjW96q IGSCRlDP12yxLu5VDpJoVTVCSbemuLPxSqHNRx7wUo3SueOToOVFw6oX6T1bIwqky85e oKz+BXHJ7qX4IWkC0C3kI6RAfY0hsa405JvzCLT98O0nGni8ePrwdSp+bYjFKUNEZC0K GRfl6bWhDpaMDAzy8ZjJC6pmsiwlESRQ/EAQfRAB6M86fZfCGcRyr0oMCH5W4qe7hWbx t/M2enqCnaCpo92lpyA+2R+/ohepN1s4Aq/8MHsdFRZNGlZ86SHDxMBo8yvKQs/cnZpT F8yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3+qvAys+bC4iB3oxnM72GbfzF+QWmjj72t2D1jOredk=; b=kf1iJzH7gWbpIYeXzeesswbiA6Gxac/diAATDdSspFE0ndBxL4TYDogGc95TFLx/Gs 7ZUNVNAq3iDpb4dYcPv4NrGDcwZs8ymMNyshHxcs50nld7NSXhGRPC7zEL8wNVhAWrRM 3xsK1ZS/tDgV4kKWVRaGw9dOnUVuqCMO/Vu146kCOQ7E/t1xw1wKI5fNhrmUWbtQTN2a d7jmvC/GgKMF7VLdcqWLcRt0B7o+b2WrN2rvcCCsnxFiuFZVv0A1AMInWtPOhfWEYOzU TDpAE53URbiyVr9k/6s7+QSoJ59zBcfkcNOtfNge3dvPge6dNz4/cAbA3cf7Wk6c8t1X 051w== X-Gm-Message-State: AOAM533DmMzJyDnQP4b7M90/tIhtYSGfIFNgPQ7gMLEIuR1Aw2BJaR5z wAhmRsIEtbSCeCnAEacLvxkFd6ASk+jgOA== X-Google-Smtp-Source: ABdhPJzQGuCimNaJZB7KeOQgZH308ZaZ2IPAXf83MFFaw0WiTI0vkXnHclqmCn5St4Bm+yJg2BnZrQ== X-Received: by 2002:a17:90a:7063:: with SMTP id f90mr18815835pjk.95.1619997540677; Sun, 02 May 2021 16:19:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 20/28] tcg: Move in_code_gen_buffer and tests to region.c Date: Sun, 2 May 2021 16:18:36 -0700 Message-Id: <20210502231844.1977630-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 652f328d2c..893256f9f4 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 0926454845..212df31622 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -419,29 +419,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998083; cv=none; d=zohomail.com; s=zohoarc; b=ZIOfc3iTIqR+VglnGqX0LHryqQM1U5MEHvbHl8OfHiD9YBggXTCwLBokd4AV+yZNsvUVqdvdd2I2Yicg5cYL45fl2XeWK2EogMJWVm55L1cKM0Q29g7ExlwTU25gbU55dBRrsRes9U2vDrDnkjtKeQVZIJz6ddhVO7J41d+a5Dw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998083; h=Content-Transfer-Encoding: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=jSOp/9wJhN3jCWwzFvXkuBaSFQqc7XH9WxgSTuRkYOk=; b=R6sTnPiKGjgr4ayhKMWGPqetCEtSJwTbHl4zyDsSQJaT5RmGrdFuQr0cGci7yDG2SBbt8fdkhNgaetTifCHeGa8e3E+5Co3beP29wg7UStGjL/St6/ZD+6EyfK3b1ujgk1i3VudW2p3GJlo6qNeyzia3sP+3vyXsGSKOq2CV86w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998083425985.2008810309954; Sun, 2 May 2021 16:28:03 -0700 (PDT) Received: from localhost ([::1]:60076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLVK-0003X0-Ag for importer@patchew.org; Sun, 02 May 2021 19:28:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMm-0008Nf-L0 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:12 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:39627) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMd-0002y7-5K for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:12 -0400 Received: by mail-pj1-x102b.google.com with SMTP id z6-20020a17090a1706b0290155e8a752d8so4707105pjd.4 for ; Sun, 02 May 2021 16:19:02 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.19.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:19:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=jSOp/9wJhN3jCWwzFvXkuBaSFQqc7XH9WxgSTuRkYOk=; b=QDwT5swGmrYYswcDVsi1NhRzKUSK1KnqwkLVKKPYx3EZTJY8MX7lBKELYMRc9prfCk gIl5Kg79nZ1sFtD2y92nWzIWVXVrLY9yUIKsQvAa1c9sfu8qbDez6sVVYcsDbZvaun6f wPxZQtMRcQBjY2tRzKwCZWUm1IMM5i9cyqsRXb2HTobDEoANBVibs5n9w1MkIfdzF758 bSm+vuSCD1nSpQEIIVW73nX8uWN+pAuqadSFFp9L8vr+wJuLdl3zqxJqEYuFr51Q1vQ5 L98A8AzEzVyU8kd9m8GOojl+pO99W8CnSy5vzQJrpnFycgQ630MpgiLr/gJ9OsjsxH0g GaKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jSOp/9wJhN3jCWwzFvXkuBaSFQqc7XH9WxgSTuRkYOk=; b=oc3/EKpoBMHSSgpyNaRNd4ZOWcaJSz/RcQg7/Q6q7QOdgtRg5xKjLZD3IVBD1LmE+P 16qbaXMnoe2VqPdES58ERrmhuvycWlS5VphIuTiSC3pUSGGwvxgBqO6IP3h6KFMqEiFV Ck/Ygt7nYdY1HqHWFDDN/kYE1mhwCrgw443gmPEzTGWYoOTX55Xxu+3p9bCV1RhPQ8se vtl9AQVZFzeanq6T1ZS0IeT6Nbe7y5noPcf0XnHJAjA+tm2Oonrbg70Rv8kVQZ2gJpMb OVFfavO+Mmkj7K4x+UsbHLvm2E55EJibLrXu0ynPInkXXinn2bdytiFxgF60CrmjWkYY jKew== X-Gm-Message-State: AOAM533+oYV/ACjiwBGiS7kDXAerslsczL61leVk14pOsKruxxi/EgMD WkQSmcDHm63u0Q7xTo0UF5gsiVdTYyXQTA== X-Google-Smtp-Source: ABdhPJwy/yUqLRV7O47uXtAjD7aYh9aTqocyFilHetaJ/LEUcn/Rnvvwz3sS8qIMsbwAQQnL00vaPw== X-Received: by 2002:a17:90a:d24a:: with SMTP id o10mr27263235pjw.138.1619997541727; Sun, 02 May 2021 16:19:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 21/28] tcg: Allocate code_gen_buffer into struct tcg_region_state Date: Sun, 2 May 2021 16:18:37 -0700 Message-Id: <20210502231844.1977630-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/region.c | 64 ++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 893256f9f4..d6499f7d98 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; bool ok; =20 @@ -853,39 +849,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 in the rw buffer, as that's the one into which --=20 2.25.1 From nobody Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998235; cv=none; d=zohomail.com; s=zohoarc; b=OiggMtindpduLIUj+oFogRLfkVPPFlzLFOwdpOq+rKFU+dFmIX8jJtFSZ9ULAEuFYWIncaf/fCLhLiHJSG/oEI9V3AKIuF3Me6WuriSsUWAU0mh6vxmSRPR4rYAdrGTOLespW6wm6cf8Xkivgom84BrlB6XRnxO3/ifUvGFUFX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998235; h=Content-Transfer-Encoding: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=rkNhDFMpzVMqKVs5NC0YHsxzFdT5b1jVWnnYqeqC2n0=; b=RPa3fRY7B93EGM/OB6Dwer0EeE9NtUVLuX47a/YcQZMp7vF+3sUBD3ARb/3pSaeNXs2okCehAs+lp7ywEWkIqmrtw5k+VexxkdBxJFbBBX5Ow4XHE4yFNIbwicUMWBG4O0GEXZ0+lMrQ0HboGTAhV8StZIe75bA+PVw+zfOsEMk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998235536129.85707715498734; Sun, 2 May 2021 16:30:35 -0700 (PDT) Received: from localhost ([::1]:40306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLXm-0006wE-EC for importer@patchew.org; Sun, 02 May 2021 19:30:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMi-0008Mu-J7 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:10 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:54860) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMe-0002yN-LZ for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:08 -0400 Received: by mail-pj1-x1036.google.com with SMTP id g24so1267078pji.4 for ; Sun, 02 May 2021 16:19:03 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.19.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=rkNhDFMpzVMqKVs5NC0YHsxzFdT5b1jVWnnYqeqC2n0=; b=B4CvX3zNFbMW2uvHf3jmOJ7/6REpFl1rwAx9MrwKWrqCImJQIcntcqPZIA6cILLDNh 5644J/TKEFYkR3Pqo+NwQgM+dIrvw0y96BHGsZwk+OSqLfQySqm857gvPbUtNSjfEi0q p2GnWsBfkuvZgIv2Az6Wv4OXczmMuptOP6byoabLnTwH8dOj829gBE9hqswou9YuTkTc Tw8ZVIsDaMTtXHHoOnO/B94p+09Vkls7JoNRF7KMYRB+1PbuYrpBtWJka+BQYLnI+nOC /uhTno5+HKieWiHmocaIxwNLl7MYTKvETk5lEP/UMcqcImYbV6aLelk1oyc9WxIjyLlz 33uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rkNhDFMpzVMqKVs5NC0YHsxzFdT5b1jVWnnYqeqC2n0=; b=FD3z3zHo4PeDk5cAxFusUKVQH3uY6CFOWOEYXIyVeugrXUeckH9I+Bf4dvILZO1URq JbRWsACTIXoO7+IO0ijuaY21MI2+fg4tOXYvTcGUDN4j7mKVnhY/hIe9JtdhTL5yMfp2 uxDRMnEAjkmtCv1vwgILrLVbVXrEF0anivXZVtwff2dQnLYDw7sIebindSfuIvoCoL+O 4aupnkpBVri8mOJkAgM/wM/OIEWHLR1qq8FJfn2LKFyVfMWBbLws84uGuCwFnjknYcuX 27VrO6cAC1rSqSGskExK5dvnK8V7dob81PhOOh07jOZMmwgVBMwHYADzXeYIqNQdCwjw AzWA== X-Gm-Message-State: AOAM530oVrS7cHU2xlhWTLwGwB7mxcAaHXTpviXU0XxZXkTRROspLKOz WARUYb9BKOEgleLMNXOqiRogD231kZq29g== X-Google-Smtp-Source: ABdhPJxjdj4rC4a29W3+rpdsrmsbBU6fkSMYONxdEAKyoqxBRYmFmaJHjm7oL7ZTEdQw3fE/MAVhdw== X-Received: by 2002:a17:90b:e95:: with SMTP id fv21mr17884837pjb.107.1619997542545; Sun, 02 May 2021 16:19:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 22/28] tcg: Return the map protection from alloc_code_gen_buffer Date: Sun, 2 May 2021 16:18:38 -0700 Message-Id: <20210502231844.1977630-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/region.c | 63 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index d6499f7d98..23fe113750 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); } @@ -843,11 +846,11 @@ void tcg_region_init(size_t tb_size, int splitwx, uns= igned max_cpus) size_t page_size; size_t region_size; size_t i; - 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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998339; cv=none; d=zohomail.com; s=zohoarc; b=DLNTVzul8e7vBo4tmWKmZ/BRmqdlF9SgBuv1y1eHC2UeH6SuodM++foRHq/M+tdpVYLllO0ZC+hYdIqxzU1e5SbLctDefy8TMHxSZsClTX3RHF+Gg9bQYOD28Ob0pPIWWYsJmLVkTyL1fyrGDwjZyC3DjQcuM9Vbs2XzdG2+osI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998339; h=Content-Transfer-Encoding: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=Y1Xrc8fP8CZ6dZ7PAmDVWqhq2c76R5A8I5Dx2N52iow=; b=jX20qpnuxQsamjx/eLwOlGKcMv9ZI9I6CDJvOZcSxo56y4QJMvwvSQIchJMNRWISBosOdNgKTBf9VIsRmi6d5Y+uk0bIGrpRyUPhRgkPfTpV4bPIyLCtH4NlvFriKbhDkCS+FSBhJljskUAox5sWhzMXAgUQVJOZao/nFy20OaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998339182707.3111443318259; Sun, 2 May 2021 16:32:19 -0700 (PDT) Received: from localhost ([::1]:46782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLZR-0001Ea-VB for importer@patchew.org; Sun, 02 May 2021 19:32:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMm-0008NY-7F for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:12 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:43810) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMg-0002z7-88 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:11 -0400 Received: by mail-pj1-x1032.google.com with SMTP id cl24-20020a17090af698b0290157efd14899so880848pjb.2 for ; Sun, 02 May 2021 16:19:04 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.19.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Y1Xrc8fP8CZ6dZ7PAmDVWqhq2c76R5A8I5Dx2N52iow=; b=cnsPRLgY4Qjco9aukxY9euKEi5w8zIu27OnA5hyAFbpUgh3jprqo34x5gztZOrYkGH etLk47rPNcDnBZCmlurz1c37v2YzfpCR604IERWdRQTQeF2MHASEHVKPj/hiTGLWtl4L waTVVBQ3FyN7d4wV6KPQfH0WjUJPj8YcZO12aaScfQ7eLZLcQvSvGkGfwl5anwacFVwX 2pq9rYrBpxgCDA+rM8b3h7cYt+s7umDOHZQjvs2YCW6Ilhg59E1DH8mSDNAlm9R4YGzx sJTqAAch23eRg+Djr6W+mM+kVT79OFjuQTCfOYIl+rhaTb6Dn6MGLa3M5e8hrpQrY+6a Wwwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y1Xrc8fP8CZ6dZ7PAmDVWqhq2c76R5A8I5Dx2N52iow=; b=VDinwh4R78RkNnze/Dr0bDB+Efr4h1aoG/4wdMfFBOeudqxHRrdE5GXR2IML0zTPOU t2Av6cddHvy+oE02iNHGPYzw2CvOKg5o6xam2VOyE9rcZ8v4JN1a0hZIjQ46GF4vClJ/ 7Cc3cTEHUOsSzVMGufDVu3ABFGA4LcO6C+KA0t8YqzGo4LNVFHOJLv7qkEZj+99M92q/ d4FJFZpPlNSKbKe2yNMuweYpdxp2cnmA6PKUcIND896J13axZpChX8nt1wSRWBL/O0uj rWIyVU4c6WjcxjvEk9Nhq3TBgQoPF8HuXzPjFuLHl+r/oeoQAjpG5v3+VfWSwjQFqpOB TZ5Q== X-Gm-Message-State: AOAM530lG5LYSY/1DpwB7lcCrT21ZKqAROyKHFgQXc36N77ACBTkP7v8 u7D8cACZXyUQImjtkGeEsekjrNjoMJkNGQ== X-Google-Smtp-Source: ABdhPJzPXw5QyzOgkWS4er0ARMaYJSok/3xlpLI1PgIvNiuK9j+/E4DVpJ0PbrYJctvWYpK9Bq4GUQ== X-Received: by 2002:a17:90b:46c4:: with SMTP id jx4mr13700186pjb.155.1619997543356; Sun, 02 May 2021 16:19:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 23/28] tcg: Sink qemu_madvise call to common code Date: Sun, 2 May 2021 16:18:39 -0700 Message-Id: <20210502231844.1977630-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/region.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 23fe113750..b3f0b9bda5 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: @@ -852,6 +845,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998101; cv=none; d=zohomail.com; s=zohoarc; b=WINFCLkEwqlrmR7NegTss5fP3Kg9Ej1P/4ktmWlI9fhpAsywL0mKTyfwapYjGgORGcwqBxItOm7R1h0UP8H8nEz/6NYJbvmtfktUhrTQo4/yYvn/MHSrNAkCyBIp0o/ik2CWe3mNTTuWUKH6yxVHt8rnlhKmoEhYiGn6Qk2jkJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998101; 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=j2oZWIWZW+wm4CMCfiCPmwaL+UY6rp5UnrdyXg3UtJs=; b=DCxy64aAKKxS6TNLYiOANCclh8Hol3cctttHTT4+1Y8vLk43M4y7ieq5zLnmywsOafd5ikn1xH7UFhPSmTejz8LJcUzQ2h9ybqrKvay7qYEuHoQwba9CrQcD79gBqgLpjJhQMD0Mu4Chk2hxte8txJzQ6/J+G/XtLbFRcYivHNk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998101571229.0659326975583; Sun, 2 May 2021 16:28:21 -0700 (PDT) Received: from localhost ([::1]:32792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLVc-0003u9-Ia for importer@patchew.org; Sun, 02 May 2021 19:28:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMm-0008NV-5e for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:12 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:54196) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMg-0002zG-8X for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:10 -0400 Received: by mail-pj1-x1030.google.com with SMTP id p17so2049317pjz.3 for ; Sun, 02 May 2021 16:19:04 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j2oZWIWZW+wm4CMCfiCPmwaL+UY6rp5UnrdyXg3UtJs=; b=r/jvyBpzEOR249ESHxv2Gd/SQK0aEfncSClqJrIJWUSsE8q0I5ANwrg0L7gNomdZDa MME8dmO4aQbQtlqQpWnG5DJOCFHzGyQ7DUBwZinMQPRfZc1jLu/xNohDLheJ5TtB9Z+T 0EyHPSzrVWeHNGsphAgF5H+lVItGhtjcQl0eedPIq0Qn8p6GPySZLFN9QA82vEuqFwWx lp/pXvsJXJlvLe+mfSk7qYyGscF0X+kz1eXAEjYGgaeenodjWr9DYqZsd7LDb6tsGhQP qYD6XZYlBahhb5RoicHBeM1h9Q1xsbsoIklBfZ/J29kiBZ7ftLOvidqmiKrgsCLklJst Wqnw== 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=j2oZWIWZW+wm4CMCfiCPmwaL+UY6rp5UnrdyXg3UtJs=; b=FGqJjdeuD7W1dSjlMY3tvOoqsoKA0AKnZY1xofLoWxKtUn5WfUQOIQHrV2GdLXR56f yEaHj11a8t4R5ly+gHUmnvMKvHMliq38kXLDP94XkonwGSX4Wp40NQ8Vc/GEh+tmLwdr tHgub1CUY6I3hTq0pt59ZtuqLsSMXlkp525ZDgJ9ZlwudIZxxKOD/Dx1L2W6AZ3HeT7t FHcLJRDy6Z91EIDkGVN+GMBC6oES18X2kpO2lhgBCgX59VKQnNUAubLCrjaeHUGVL/5B NxeILoI/Eog0sXzdEU3cOVhAep1lZH8mvm4/CqKpXKH2Y7Z38b12bspmNev+HOnyuKdF 4r6w== X-Gm-Message-State: AOAM530xuB0Cksostaoid3qwZ4WCGoQz6UdvDLosspUm3h5EXSBZDEU5 hdaigFBx7t9VtwsF2KgPuSRD24hOFKc1Hw== X-Google-Smtp-Source: ABdhPJx2tuxG2P0LxVNIWxoL7hoYFvmfJQZDCXHXAARRImU8uhOafsTveIxp0sR8o/DVo1v+eOFhSQ== X-Received: by 2002:a17:90a:cc0b:: with SMTP id b11mr18020529pju.190.1619997543920; Sun, 02 May 2021 16:19:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 24/28] util/osdep: Add qemu_mprotect_rw Date: Sun, 2 May 2021 16:18:40 -0700 Message-Id: <20210502231844.1977630-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) For --enable-tcg-interpreter on Windows, we will need this. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 cb2a07e472..c4a675b9a3 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -512,6 +512,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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998457; cv=none; d=zohomail.com; s=zohoarc; b=ayXloWOCcL9XjqsydO9wmlTdWV5TUB93xZUe++CrDhcCBngp3UOB5YwOTigFchxlDmeAKoifIy7erPPoXgU6e1FWpMQGwVGIfaBqa4A8WL36brROkci23P81dj4H2FBM+lDEmhh4QKdMfDV9hfqHk7M8ZsD3nAAZxH5GRiG5x3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998457; h=Content-Transfer-Encoding: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=euZbMSCAnJ/aSruzU2XNeMy2K5psC8+GIr707J2MLks=; b=mUZpZj6RiPXSqKSobGPAZ4ae8B15LcxJ+KubYD1kBmXy93z+gAu+oW8htfn1fa1QK+yw3v9TYLn1CRr66/8TPSJL/jiSVDnfQ1PKoXd21+qOD01A6r9VmJMZuyrG5gv+O8zN00hSNmIScSndo3iNefZ0CFgy1WwysAMi0u3krHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998457156430.9524382896319; Sun, 2 May 2021 16:34:17 -0700 (PDT) Received: from localhost ([::1]:51396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLbM-00038B-4Y for importer@patchew.org; Sun, 02 May 2021 19:34:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMm-0008Ne-Je for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:12 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:55920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMg-0002zQ-8g for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:12 -0400 Received: by mail-pj1-x102f.google.com with SMTP id gj14so2044964pjb.5 for ; Sun, 02 May 2021 16:19:05 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.19.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=euZbMSCAnJ/aSruzU2XNeMy2K5psC8+GIr707J2MLks=; b=TGIP86FWhF7MbSaUoncx5PfFlCuHIHgjEVBQ0IBRA+IUeyizbrSbdsUBl7n1DAIrLi ahVX7QO1JCpSSQwhu/ZA5N+7++TIxW+40s0o3zJqset2Am9kB/GD+TBXUe7crRLsmhZq R2oc5W1nE5+CPuq2wimv/jNCPzFxqx7he/0UL9OpYiW2FkVPTy7gCNEryKZNRbUXDR4d Ls0THUJn3IM8s8aUq9LiutcGQGBwMCGMDIvZYzjm9iEwSE35ktfQQ6SyOIh36vN09RVm ybHa3roUpKap/uVhZW9Ebi/8/ike/BUxTg4SzkIG9uvP18XSzkysH9xrQ6HXb0K/u/jq BoKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=euZbMSCAnJ/aSruzU2XNeMy2K5psC8+GIr707J2MLks=; b=DNkH54AREBBEallL2O0YybCPunTKIy7ib1qRXZ2AWq5a414niwyHBcDAwHjY9I73QY DR2++EJd4agF76h6QqGsqcGMPDQeL205qiS0tNKpn8CqD1Ai/kNHJNJI5TiOcyiNONH8 u3a1LDb8NFaTt5fCKdUS9lzzskhLepaj6nwCy8pOUFWZnZjVQy1J4EnUOIH6yJEAtRiL 6Int651hF5cPphgdvLUlv8ofoQUNrmKXvRpokgvWEDWx30L1URYeGXOkK5ihS42swKPm vUA2qvui4NoR/FwRltwJfwmqY6tcsYWdix1L/jcvLGQxfTS832BLbF1rSwL+9o6sia9I 8IsA== X-Gm-Message-State: AOAM5322za+YxJsNEgEJ+/6FezRJQYxCwCYpWPAU85sJPNUbyDYO9moN sOdWmZ+uqnXFxhmLm6M48E6mDamtVO9F9w== X-Google-Smtp-Source: ABdhPJzXr+TKJ9Fek5fbCzdbtiVWReGwpyO65a0izv7WN5Ud8jRrfqzTG6kuwniV05qe4wjtZjIgMQ== X-Received: by 2002:a17:902:7281:b029:ea:afe2:b356 with SMTP id d1-20020a1709027281b02900eaafe2b356mr17643619pll.16.1619997544597; Sun, 02 May 2021 16:19:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 25/28] tcg: Round the tb_size default from qemu_get_host_physmem Date: Sun, 2 May 2021 16:18:41 -0700 Message-Id: <20210502231844.1977630-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/region.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index b3f0b9bda5..49764b40dc 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 Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998590; cv=none; d=zohomail.com; s=zohoarc; b=ihXPugGD2ACZjElVeXi+71hX22eK4j532uE3Bi8x+KkMiWhXB0TE3eZgt9nEplrgyy6Z8M2jLTxr8eZsyYkRP5hdxcrv9qcBHrBfiHLruOQcDKd+P2DfB2XTJufidl2j6BYUnCEJnZDrI0dBdBkUuqysFGI6Y2KqCIxBVjZyG08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998590; h=Content-Transfer-Encoding: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=5l4dTEQ+iJa2jxENce/P7jthFYg4uP2TXzJ1O/jGZ+Y=; b=RJI33Boy+cyIdZfqwfBCUIAM2ivtQzRyq+0HRIksuZWm3QI8YPXvYESss6vuINyj3RsgfjVS5bntLhl0auPBfiLBELh4SvRByIvVbPGsos2YtIGgshnhGaF+Z4ikObJduz4FmV8AYDKbx6xvZfHY2/kdZylKprFFm1UXH3eksTQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998590056215.6167500580076; Sun, 2 May 2021 16:36:30 -0700 (PDT) Received: from localhost ([::1]:57284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLdV-0005bL-0p for importer@patchew.org; Sun, 02 May 2021 19:36:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMn-0008OC-Sb for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:13 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:34534) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMh-0002zT-IC for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:13 -0400 Received: by mail-pj1-x102e.google.com with SMTP id t2-20020a17090a0242b0290155433387beso8876112pje.1 for ; Sun, 02 May 2021 16:19:06 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.19.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5l4dTEQ+iJa2jxENce/P7jthFYg4uP2TXzJ1O/jGZ+Y=; b=oWB3YD69tY3UrXqCZ6ReDTbFcFYpoaXmPC1VE50NiJB0i0AqqhPj+opLD+I07E6cCQ b4E413RmBsjfo+xRdkgRwATew9lX9+nLUd66qIiDCvuYKAvdjNc3SNEqD9Mj/L2g42BE frVGfuT+vajsHy25OJ7pzOE8S1abTS8Rsh1Z1EfEZhGDPPSB6+9xd0SeZAOMlePLcAIb yOptrfD0SDknoIhE5Unq61pd0bCX0kr3eB686obMP98PZnzM/bASOta73BIJGJVT2xHB Uh7g27iluObewQ2ZWpNEFD7vxleUpDrAbcWYq9qWtynFkqOgVewCTWSL3wozmE7bSkpP BjVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5l4dTEQ+iJa2jxENce/P7jthFYg4uP2TXzJ1O/jGZ+Y=; b=T0m+U479UnGNVBHwU73/UJC8QaQkLXj1VpCwjJZK+Xp1yTGpCvmX+ePohMQSLfwyEI QasoD18IoIHq9uPO7kWytIyLdrYWTPo+QrMUlBGK42RaNBE8GgJoNHNSDF8tFM4WEFgR uSO5sL3Y22yKA+3ZadSZboYmpUG1f7gkV0E8gVFFPY3POLpmYd164BK7X0AgWPXphabt 1ZWEmCGnDyxRmyruhi7rj8Kl2QKSbPw3XwGJ8cvDLXWRkIX36yYt1Dwdjf08uz9Qn73M E4eFEZkdRmEneZO784+aKhwvN/NN+gcjwU72dLi8MTEadMlQRnNqfs6Yqtf08tBLjwct zzeA== X-Gm-Message-State: AOAM532cRH0/KBLL/fyFIve2DS5eaJSgExzOVwOtbiRNVfQhoMjJmucz 40gKM5TOYCBUgho3uUlU8bRSEuHp07RYPQ== X-Google-Smtp-Source: ABdhPJwjFB51/J6jE7ThCv1e8B5HWqkkO5gq29LJLZuzqMp8nVjZmgfurnwIHkTyl3fnPMbEIVQGZQ== X-Received: by 2002:a17:902:6941:b029:ee:dacc:3ab1 with SMTP id k1-20020a1709026941b02900eedacc3ab1mr1003352plt.3.1619997545408; Sun, 02 May 2021 16:19:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 26/28] tcg: Merge buffer protection and guard page protection Date: Sun, 2 May 2021 16:18:42 -0700 Message-Id: <20210502231844.1977630-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- tcg/region.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 49764b40dc..604530b902 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) { @@ -879,18 +873,41 @@ void tcg_region_init(size_t tb_size, int splitwx, uns= igned max_cpus) * Set guard pages in the rw buffer, as that's the one into which * buffer overruns could occur. Do not set guard pages in the rx * buffer -- let that one use hugepages throughout. + * Work with the page protections set up with the initial mapping. */ - for (i =3D 0; i < region.n; i++) { + 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; =20 tcg_region_bounds(i, &start, &end); + if (have_prot !=3D need_prot) { + int rc; =20 - /* - * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mprote= ct - * rejects a permission change from RWX -> NONE. Guard pages are - * nice for bug detection but are not essential; ignore any failur= e. - */ - (void)qemu_mprotect_none(end, page_size); + 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) { + /* + * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mp= rotect + * rejects a permission change from RWX -> NONE. Guard pages = are + * nice for bug detection but are not essential; ignore any fa= ilure. + */ + (void)qemu_mprotect_none(end, page_size); + } } =20 tcg_region_trees_init(); --=20 2.25.1 From nobody Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998679; cv=none; d=zohomail.com; s=zohoarc; b=OJjDKmRm+24bNcPyKLkI+9s1cRVW2pmfJj6JbeWOh0o5pJLBghIncY00/iEYHiFHaXcQ8xK5Fb8hC189Mwa8I6aBHLLG4Fc8kkUYTbVtgqSY+9MAB2aJ8UYOXh68ErvyZejHT+d0s1YM0K1brCvlroNGXfwH5rzqapXKAmuqxTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998679; h=Content-Transfer-Encoding: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=IMH7OG6KjuztYAF/Ih9G+wS1HMzIPcW7GkKKX50tasw=; b=cdXS+U4fruuTs0/Br/rjwthEHvcpQX8lU+U3975vjvkYL9zx+a01P2OSKNiN8Q3b80jwtHERrE7RFLN+YBdzUS1uPenOW2h9GwgFhCXVLk3I6uIZF0/YcOQ3dZ8CaNJ+Mctm7waE1KuJ9N/Puek1Sz8RpkdtJXbb3mvTWtE9ILw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 16199986792771006.8869525951376; Sun, 2 May 2021 16:37:59 -0700 (PDT) Received: from localhost ([::1]:33340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLew-0007Ks-7U for importer@patchew.org; Sun, 02 May 2021 19:37:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMp-0008QV-Jd for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:15 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:37642) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMh-0002zc-IQ for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:15 -0400 Received: by mail-pf1-x429.google.com with SMTP id b15so2955826pfl.4 for ; Sun, 02 May 2021 16:19:06 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.19.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=IMH7OG6KjuztYAF/Ih9G+wS1HMzIPcW7GkKKX50tasw=; b=yQRkuLRQB3qzWS6HhVFazYf0EL9goICi5FTd4Lym+MSO2KwgNeslFEdq45AHh6jH/E CVYQwIyZz+10ja4mqTYB5UfckV1vccACUyKcZQ2vDiMK94MUF1AF36mDsyV7NYd0B57q TVdL6Tt0/nR7HZoc6R7p9gRZa9iHRnnQFLhFGxQZiO2bmExKw9VeWh2erzbuzZTVyznp isxZzhRMDCSoxDigJBQ8kMr+eIGzxEpL1LeNmSOE44OW0MiQT0vJOUYV9D50CPokDiL+ llX/EDPuQWw+oqNYTsoZvlGOkicmC83pr3xWRzer/HJL3ggs2hsuVAmxDYQRM2P2QPXV HjeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IMH7OG6KjuztYAF/Ih9G+wS1HMzIPcW7GkKKX50tasw=; b=jpO75RIofoHLQaaPeE7L0vprKrgtXMwI41uRv2pJhpw8jtofro2IzbAcV3+PijZz6N gu0l2emKrcp2Zx8enp3/sZWtFj/7GZSna8uHXio2aJfHPdoFDq2leZYT/MVfMie2a9Mw o1LC2+KVJmLR/71hrwzTrnBqyGyUkuD/xZlpoAfQAs3f23KEBLnx7BagiekMnYAdkHHy eYODOCrFERqHnMtYH7ico2dycnbHYCPC/OeFXal5LQxnjSxD4Cl5ymiMM+MAghtRgHrF GPY9iDsNkblJcwZiQlgCB6Eci2kIAFFK0bKqlahhnr7o2S/sGXHMLrHctJzHC1CwlJMr 84dw== X-Gm-Message-State: AOAM5313qZ++oPR9C6TiLSNBfakKMDcI6VaknpWbu/XWYdPqiV+gM8N9 8ytNTIfDXUCSlFSMzN+Djc1CEFF2g1wfwg== X-Google-Smtp-Source: ABdhPJyW3TD5xwZuAHyBsVfe2ntG+ZpJ+I6x0LO4cWAK9b/2UHUWxHExl9NgBYt0eBEvBjtZjh4r5g== X-Received: by 2002:a62:ed0f:0:b029:257:7278:e72b with SMTP id u15-20020a62ed0f0000b02902577278e72bmr16172218pfh.17.1619997546077; Sun, 02 May 2021 16:19:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 27/28] tcg: When allocating for !splitwx, begin with PROT_NONE Date: Sun, 2 May 2021 16:18:43 -0700 Message-Id: <20210502231844.1977630-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Signed-off-by: Richard Henderson Reviewed-by: Luis Pires --- tcg/region.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tcg/region.c b/tcg/region.c index 604530b902..5e00db4cfb 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; @@ -901,11 +904,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsi= gned max_cpus) } } if (have_prot !=3D 0) { - /* - * macOS 11.2 has a bug (Apple Feedback FB8994773) in which mp= rotect - * rejects a permission change from RWX -> NONE. Guard pages = are - * nice for bug detection but are not essential; ignore any fa= ilure. - */ + /* Guard pages are nice for bug detection but are not essentia= l. */ (void)qemu_mprotect_none(end, page_size); } } --=20 2.25.1 From nobody Tue Apr 16 06:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1619998222; cv=none; d=zohomail.com; s=zohoarc; b=m9/gBnNmjgvoTzTbHHrs7vFEm7QgDeinIJCU7ema6DUJguvFbqpx9KESou4nKkFRBqDgkmebrz3sDyChfpXaNpQAkd1v7qMxXzYHXlN/FbGEQG/IdkOP5pK/rh+SJwusLbHyn7rNsd93QuFqjCagsHybXjwJaof0lT4F9Fdyjgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619998222; 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=pRV7mqfMaKb7/SwKxjrezlXdNmvbN1KHw2x4aibLFRI=; b=DrV7JzGkkhcRRgcuXUwdsa6zlBROFInpQ+7NadsiyiimjLmssabRqPogFWUNcHxEr+3i5VX0LRIcSMHOo6YPsGQ/dneXyeB/ECLY4HYcs9KN91Ndvv+EjTPFWrl763AxjNPly8vA3lGOi5Uk8wbRlaQsggF3Ip8BwOuLusnbM7E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1619998222675861.3748543614163; Sun, 2 May 2021 16:30:22 -0700 (PDT) Received: from localhost ([::1]:39666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldLXZ-0006gY-Hd for importer@patchew.org; Sun, 02 May 2021 19:30:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldLMr-0008T0-SE for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:17 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:46057) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldLMi-00030Z-80 for qemu-devel@nongnu.org; Sun, 02 May 2021 19:19:17 -0400 Received: by mail-pl1-x62c.google.com with SMTP id p17so1846662plf.12 for ; Sun, 02 May 2021 16:19:07 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id k17sm7146236pfa.68.2021.05.02.16.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 May 2021 16:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pRV7mqfMaKb7/SwKxjrezlXdNmvbN1KHw2x4aibLFRI=; b=LGoDDHlBUINnmZ/r7a4AdBl7Rwi4Su7NL7d5vWZtSpdGH8R/fyqO+3Alrp5WfMAJvQ abONDHENv5r6AXGF8MwSOF+S1pHcRnilYvJceJ5PZWXMtriayhe0RyY4YsKM1suijQvr /PPQum04pIIdJTcqDIqBYi1A7HNKyKLibCChPeubLW1vajLNmuzGdbViw353EKKg7RLg E+aMyA6phtImcRAKbmOcsYFQxq/lFL+xJKkZNQ1hEw1QG+n0qUDiPMKBM26skqGF4ui+ fGQ9XNRgJw7DUkYskaWoWcOt0qpAIaaCfKDlZd2yJI8iGBZTVi6vBYIgll4rtvd5AhAF cwdA== 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=pRV7mqfMaKb7/SwKxjrezlXdNmvbN1KHw2x4aibLFRI=; b=ahgBfRF7NKEzz4aZl8b2hWSqE0tY4bRCzwM9whoUQxBx4S0Johlamlc6mhDuGLSPRw /LEZ8pFotsy52slKMxArgheKLxksbSoncUz17Fp+33wqBbHJgIphmHpv6O+lw0MxjER9 2olKMJODrB83DbXS45657+ATThj044Zzi93J92pexnmu2zdb6TsmzvReh/4D7FSuro+M FAq47RbrQnpUwkX07K8pFxooLwkvExa5y3kxbkZhwj04iRVI1hIaasEZD1ZnQHlVmaA1 CLcSoNIHuBIbvoqEp5Nlg6OIGEcYzlyM1OERIUyrewNo2xAJ32byZqIZnGZ3Bz08/e+5 ewgw== X-Gm-Message-State: AOAM531JGy0XkIX1syHZq9/+QPaQ3+pBr3YuAGhs5KmvhLc6f5vNr+x+ Np9y5/8RcsXM6Cw27pn3/YIYHnedDbpsZw== X-Google-Smtp-Source: ABdhPJxPXDc251sCewm1tK19PRcweRqFUM1OqEe2ReRyyY+qC+HZa45H7p5nuww6RaenaKIplVBxUA== X-Received: by 2002:a17:902:dac2:b029:ec:7fcb:1088 with SMTP id q2-20020a170902dac2b02900ec7fcb1088mr17509675plx.65.1619997547008; Sun, 02 May 2021 16:19:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 28/28] tcg: Move tcg_init_ctx and tcg_ctx from accel/tcg/ Date: Sun, 2 May 2021 16:18:44 -0700 Message-Id: <20210502231844.1977630-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210502231844.1977630-1-richard.henderson@linaro.org> References: <20210502231844.1977630-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::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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: Alex Benn=C3=A9e Reviewed-by: Luis Pires --- 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 0c818c3618..25f5be1c4f 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 212df31622..e4e2985276 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -152,6 +152,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