From nobody Sun Nov 24 04:00:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1726693675437571.4686887899965; Wed, 18 Sep 2024 14:07:55 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 54C8B14F8; Wed, 18 Sep 2024 17:07:54 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CCD741526; Wed, 18 Sep 2024 17:07:22 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3279314DF; Wed, 18 Sep 2024 17:07:18 -0400 (EDT) Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 669E114C9 for ; Wed, 18 Sep 2024 17:07:17 -0400 (EDT) Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5c3d2f9f896so214133a12.1 for ; Wed, 18 Sep 2024 14:07:17 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c42bb89e07sm5328729a12.76.2024.09.18.14.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:14 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 536405F8A7; Wed, 18 Sep 2024 22:07:12 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693636; x=1727298436; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3/HyHbGcSckOdKLF1EYAUB114Xir6Orehr4YuOmz0iw=; b=Pp/oGPHA/i/vNd/qtqcvfLeUgQmSlW4PTVRvU9AZQ5sC0TBzyc1FQwRl2fsm0Yd1Ix sA8vyYXwFyviJTaX6LSnYYxcCT9bSbV276WF1P/opCDdXyfLV1YrByZ5PLX3q7gOlpBL d4agMIdEXWTX9nc655zDX+Jpx/Dcw+yiy95FZlxVgICeVazJXeGnTA9eiSOezLYImgvx jGy+hjQ20hJOxmpQvN7thxoJfsoe7sDO7TZ3LhGzJH3lSM/vWsBkUOstpMLvmKFZ3z9J awclMYOm1KEEJSZpZUUBAsKdbtu6hmoJm0L/5Rd3L2QPOgS5nG9zbvsaplXpW3jRpDoB HjBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693636; x=1727298436; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3/HyHbGcSckOdKLF1EYAUB114Xir6Orehr4YuOmz0iw=; b=GT7X11iuFYK4IhRNfObVYP1stbxKN9JMHvMv2c3SedtOHBfpitc+SYsIr/srlc/uxH AJLUDrF2U9WLbuiirMsBBcjVWDOD64uM7bcttjbQ/YfRmV0SelCU9gaXDp6uQ7VUKqNA iCh/UALcX5vobpRkOCQclcdFtOxKDwlOAG4IDrWNbzyDNtxBhBrA8NN8SR75kGNGgxAU W5oR0nES4C3PksG/hz3RqUy6bh8Dc5ykpWXY2iO5lIMzoYXqtR5IfXOvnDxJAtKfe909 eDLtzx3+sHmu2w5je7YmBlW05yMUukhYEfKMBze/CPnLu/bN7t+00d/hUH1fHQYS51eb GsWg== X-Forwarded-Encrypted: i=1; AJvYcCVJN4Rc1fbNW/PHACrALYy4nuIkoNnHJsw3jNgbeDSJQb21Tw+QNi2GohKuFfnEvVGsKK3hcQ==@lists.libvirt.org X-Gm-Message-State: AOJu0YwDbxaA/SEwJAge2L8MJ6cRsozYjjtQmuqbHPW3wdcOMGZfBPY1 2RdVwQLV0PPBZV3yGCbWh8I3A/2TQHIkpwvcad6BRCF0aOHYJ3f4ehEIc1MWa0c= X-Google-Smtp-Source: AGHT+IHV58QftuvwXXi76HH8XPGKkDy1FaR5lmC5k3xJm23VXa7bFtHvHqFj0VNXwS2rCu/Nz9RQTw== X-Received: by 2002:a05:6402:3551:b0:5c4:1c74:56f2 with SMTP id 4fb4d7f45d1cf-5c41e1904edmr14275902a12.15.1726693635673; Wed, 18 Sep 2024 14:07:15 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PULL 01/18] deprecation: don't enable TCG plugins by default on 32 bit hosts Date: Wed, 18 Sep 2024 22:06:55 +0100 Message-Id: <20240918210712.2336854-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: EE2T5MUW6OPKVD5MJJRRRZ6FC4YPSMVR X-Message-ID-Hash: EE2T5MUW6OPKVD5MJJRRRZ6FC4YPSMVR X-MailFrom: alex.bennee@linaro.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier , Paolo Bonzini , Thomas Huth , "reviewer:Incompatible changes" X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1726693676024116600 Content-Type: text/plain; charset="utf-8" The existing plugins already liberally use host pointer stuffing for passing user data which will fail when doing 64 bit guests on 32 bit hosts. We should discourage this by officially deprecating support and adding another nail to the 32 bit host coffin. Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-2-alex.bennee@linaro.org> diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index ed31d4b0b2..809b2b9b81 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -184,6 +184,17 @@ be an effective use of its limited resources, and thus= intends to discontinue it. Since all recent x86 hardware from the past >10 years is capable of the 64-bit x86 extensions, a corresponding 64-bit OS should be used instead. =20 +TCG Plugin support not enabled by default on 32-bit hosts (since 9.2) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +While it is still possible to enable TCG plugin support for 32-bit +hosts there are a number of potential pitfalls when instrumenting +64-bit guests. The plugin APIs typically pass most addresses as +uint64_t but practices like encoding that address in a host pointer +for passing as user-data will lose data. As most software analysis +benefits from having plenty of host memory it seems reasonable to +encourage users to use 64 bit builds of QEMU for analysis work +whatever targets they are instrumenting. =20 System emulator CPUs -------------------- diff --git a/configure b/configure index f3e7572afb..cc8e1ed5b8 100755 --- a/configure +++ b/configure @@ -516,6 +516,25 @@ case "$cpu" in ;; esac =20 +# Now we have our CPU_CFLAGS we can check if we are targeting a 32 or +# 64 bit host. + +check_64bit_host() { +cat > $TMPC < (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693657824431.1785202791134; Wed, 18 Sep 2024 14:07:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tS-0004vC-0Y; Wed, 18 Sep 2024 17:07:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tP-0004oy-Kg for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:19 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tM-0001ZT-Iw for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:19 -0400 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5c43003a667so195811a12.3 for ; Wed, 18 Sep 2024 14:07:16 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a908d2305e3sm397557866b.186.2024.09.18.14.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:13 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 6C6845F8C8; Wed, 18 Sep 2024 22:07:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693634; x=1727298434; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l8PYdaTTNho7oFbmy/119cv/0Q+vgu2VyKL3FrL1OWo=; b=DAs5e9+LSK4IzqwVqOfWl3Co0XFAyFBlvztIlKmzpg3GOFwFUkHXNI9deOmtdrwlwn +xWxoO51PMB73cPQt6V2+zGv15kU4BjNp9Li8t+ofT7QGmEI4NBiPDXhYSXUxF+2nfhE OLEwQwmuhy3zU7NwnhPDKPpEIyPkkhBJCjR2DxRoL+kDQih5Su2fj82NOwVHA8RiZaRg CR3pN9QWJpNDcEW42mRZvRmoD5rw8Anr5lQCin6WDLgwkxJ+0sf9smR1CmosPzPRzrjg 2rKfismxW8kWauHFmGOx4zDSDa4UZ8ejfqHXaiyjVdY7HBK8p2nQyL/I7y5aoz7WM2JC A/VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693634; x=1727298434; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l8PYdaTTNho7oFbmy/119cv/0Q+vgu2VyKL3FrL1OWo=; b=OYqIidfF59hMFNGOEgaZ++gsOZDXXrYhoDF9/fp7AJ4fY750J3Z2H0qsZ0Ez0LJRsV lP109UUvLKRcGfx8uGVA0feAvd88U3IXDAP9Qc8KPMDX85jl7GJCYxGwYsUrNbL8g4tY fw6ZKDx5WNtVMwuqFSFv8vvRQn4AxMMUPpEzf3OnA9M6x3UGt/4ANByAy8KNq/Ui84Yq YeeaBgXfGXpY1nTp5Tx/zVvojC5rG1bi+vatL0cajW7vPMqjup/HioYn178VGwIEbW4u ANMn2XiBORuK2oaWt0h1cT6tHhuxGcekOt0eRgnG3CLA+YCdV3XUQTbTGu9Tulghrg4n LyhQ== X-Gm-Message-State: AOJu0Yw39dISa/nmHjSzHWjfjY02dacN3zY6xmo8xI+38AqsNA3L0SuY nUIH8uablRExo2ETuUo1o6zXfWeJYY+KdxraI0Urr6ddrIKnDphEzx1zAGtYz7Y= X-Google-Smtp-Source: AGHT+IHTdZsIWdnnS4bkrBdNFJUXjNP2PC7ITAztPPydpFpWb8uQlRw5M68rNLCWswq9yB4RH3G78Q== X-Received: by 2002:a17:907:3d91:b0:a86:8ff8:1dd8 with SMTP id a640c23a62f3a-a9048044a21mr2014339166b.46.1726693633817; Wed, 18 Sep 2024 14:07:13 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier , Paolo Bonzini , Thomas Huth , devel@lists.libvirt.org (reviewer:Incompatible changes) Subject: [PULL 02/18] deprecation: don't enable TCG plugins by default with TCI Date: Wed, 18 Sep 2024 22:06:56 +0100 Message-Id: <20240918210712.2336854-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::531; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693659951116600 The softmmu memory instrumentation test sees so many more accesses than a normal translated host and its really not worth fixing up. Lets deprecate this odd configuration and save on the CI cycles. Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-3-alex.bennee@linaro.org> diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 809b2b9b81..c0aa52def5 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -196,6 +196,14 @@ benefits from having plenty of host memory it seems re= asonable to encourage users to use 64 bit builds of QEMU for analysis work whatever targets they are instrumenting. =20 +TCG Plugin support not enabled by default with TCI (since 9.2) +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +While the TCG interpreter can interpret the TCG ops used by plugins it +is going to be so much slower it wouldn't make sense for any serious +instrumentation. Due to implementation differences there will also be +anomalies in things like memory instrumentation. + System emulator CPUs -------------------- =20 diff --git a/configure b/configure index cc8e1ed5b8..aa7aae70fa 100755 --- a/configure +++ b/configure @@ -629,6 +629,9 @@ meson_option_parse() { exit 1 fi } +has_meson_option() { + test "${meson_options#*"$1"}" !=3D "$meson_options" +} =20 meson_add_machine_file() { if test "$cross_compile" =3D "yes"; then @@ -1048,8 +1051,12 @@ if test "$static" =3D "yes" ; then plugins=3D"no" fi if test "$plugins" !=3D "no" && test $host_bits -eq 64; then - plugins=3Dyes - subdirs=3D"$subdirs contrib/plugins" + if has_meson_option "-Dtcg_interpreter=3Dtrue"; then + plugins=3D"no" + else + plugins=3Dyes + subdirs=3D"$subdirs contrib/plugins" + fi fi =20 cat > $TMPC << EOF --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693765; cv=none; d=zohomail.com; s=zohoarc; b=EHc6mMVuD7WXErDk8SZMmf8EMY9R0mDJkb+Za1Q3WKuDdq8dMK051DHnKoYFk9Bi60V+pL2+X9Euqo8YTtAM9Tw0D+QsY3GrhKBRC+Si3T7FU9MBgpcfpyCnoe0IFqxy7oIDG1vd4U82lvs0Dj2ln0Z/NQkMmiMCpoHRggLErZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693765; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=diSn4mrhaw+TlxcBATzSgJEMltlc4QxqrTJlAiDxcps=; b=oKuldmhSKAE9MefJJf/IxKwVHGTGTYAPD6+8aBE5zlj2XyQWICwBp156Z3ADCBtH6bRzfJs3N8lG1uPE6VgFCLcu+yqW9BRRcuDXkPQR4hCOq3NkH+tL/kS6T3PJyyvRmAu2VlSIZL/xz0bQOM5eO7IIvzEZbUt38urJVmXwncM= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693765551387.51320349575474; Wed, 18 Sep 2024 14:09:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tQ-0004pw-DO; Wed, 18 Sep 2024 17:07:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tO-0004oJ-Mt for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:18 -0400 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tM-0001ZV-6h for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:18 -0400 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5c27067b81aso204088a12.0 for ; Wed, 18 Sep 2024 14:07:15 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612e56a1sm642408566b.171.2024.09.18.14.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:13 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 84A235F8DA; Wed, 18 Sep 2024 22:07:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693634; x=1727298434; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=diSn4mrhaw+TlxcBATzSgJEMltlc4QxqrTJlAiDxcps=; b=krwoDnY0dveSxZZ7nrK1k3bCBFs8LDTBcIMd3Q2JALP2d+situWw34RlSraP/J+04+ frk4YGPyXJz26f18izEssOot9M0aMUDpv1A6y72nCqEEs3LtF1esxvpNSrjBgs5EqBR4 V621+6NlAHLsxT4c4Pkl6qn0Dk99enTIwkKRr0aoSZf1gLGVA9Ninn/1UYB7/Yi+HOIg OS02JngkVvQs2Zuso6ZEFZehgdZ0XXCLOwq4LbAxdgWwEpUoImTHFfSEfBmYLZfDDTLz tPUzU254geJfi2uwlwfeNup+5tgUBGSupB/62ekou1lJIs9yYHwy7Pk25tgwaUeniAcd VTAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693634; x=1727298434; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=diSn4mrhaw+TlxcBATzSgJEMltlc4QxqrTJlAiDxcps=; b=Xr2s3zI0jCngK4tj/j/htW/1KoseutJ5WhtDa8+2rGkY16NsnixoHIx3cPw/ZKtVDd Q0JbS4ec9JB7+ZZWwXRy6LNkBb6XTXgABo6Rr5XfRyaQUEJ7wFnUykmZgVoiP1amIqzt bL0kYRHa4Xkl0mXAVYzhpF7dftGvsgB0dZmlfMJU7Hi3/LMxyzABQ98NZuAtvb7NoHA5 b5VEpCsvBh0cHBjLG/tdqjd2HuwuDrCJKWTifdxAjdmgFdzjv86QgycF+QEYXop7+iXz Zd97LJ+8vd7gdVX3HItvE0sAex3N/V+p9gskBew4OkSP6nyCY78oEcc6tvCM28hWoQ8Q nhhw== X-Gm-Message-State: AOJu0YyhLxqqQ7QDpxTMyc1xYWqO4GZnS206EH8Tw1aNijZ9Ms7OVbbb LSKG3UsF9EmYvZBYFlWg0++rhC+7M+X6sLfs3ZP/N9a83B+VaaAR9JlubDHyuIiGxSbmreT8Y4C D2zk= X-Google-Smtp-Source: AGHT+IEeyhF4/+RG/b4mwRldmhB34hffYtf9ww9o3eWV+VRBBkb0dJk4fhHQ+HCAK2SeN3zRH9F/yQ== X-Received: by 2002:a17:907:9443:b0:a7d:a00a:a9fe with SMTP id a640c23a62f3a-a9047ca9533mr1919028866b.17.1726693634166; Wed, 18 Sep 2024 14:07:14 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 03/18] contrib/plugins: control flow plugin Date: Wed, 18 Sep 2024 22:06:57 +0100 Message-Id: <20240918210712.2336854-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::532; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x532.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693766495116600 This is a simple control flow tracking plugin that uses the latest inline and conditional operations to detect and track control flow changes. It is currently an exercise at seeing how useful the changes are. Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-4-alex.bennee@linaro.org> diff --git a/contrib/plugins/cflow.c b/contrib/plugins/cflow.c new file mode 100644 index 0000000000..6faa55d10d --- /dev/null +++ b/contrib/plugins/cflow.c @@ -0,0 +1,388 @@ +/* + * Control Flow plugin + * + * This plugin will track changes to control flow and detect where + * instructions fault. + * + * Copyright (c) 2024 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include +#include +#include +#include +#include + +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +typedef enum { + SORT_HOTTEST, /* hottest branch insn */ + SORT_EXCEPTION, /* most early exits */ + SORT_POPDEST, /* most destinations (usually ret's) */ +} ReportType; + +ReportType report =3D SORT_HOTTEST; +int topn =3D 10; + +typedef struct { + uint64_t daddr; + uint64_t dcount; +} DestData; + +/* A node is an address where we can go to multiple places */ +typedef struct { + GMutex lock; + /* address of the branch point */ + uint64_t addr; + /* array of DestData */ + GArray *dests; + /* early exit/fault count */ + uint64_t early_exit; + /* jump destination count */ + uint64_t dest_count; + /* instruction data */ + char *insn_disas; + /* symbol? */ + const char *symbol; + /* times translated as last in block? */ + int last_count; + /* times translated in the middle of block? */ + int mid_count; +} NodeData; + +typedef enum { + /* last insn in block, expected flow control */ + LAST_INSN =3D (1 << 0), + /* mid-block insn, can only be an exception */ + EXCP_INSN =3D (1 << 1), + /* multiple disassembly, may have changed */ + MULT_INSN =3D (1 << 2), +} InsnTypes; + +typedef struct { + /* address of the branch point */ + uint64_t addr; + /* disassembly */ + char *insn_disas; + /* symbol? */ + const char *symbol; + /* types */ + InsnTypes type_flag; +} InsnData; + +/* We use this to track the current execution state */ +typedef struct { + /* address of end of block */ + uint64_t end_block; + /* next pc after end of block */ + uint64_t pc_after_block; + /* address of last executed PC */ + uint64_t last_pc; +} VCPUScoreBoard; + +/* descriptors for accessing the above scoreboard */ +static qemu_plugin_u64 end_block; +static qemu_plugin_u64 pc_after_block; +static qemu_plugin_u64 last_pc; + + +static GMutex node_lock; +static GHashTable *nodes; +struct qemu_plugin_scoreboard *state; + +/* SORT_HOTTEST */ +static gint hottest(gconstpointer a, gconstpointer b) +{ + NodeData *na =3D (NodeData *) a; + NodeData *nb =3D (NodeData *) b; + + return na->dest_count > nb->dest_count ? -1 : + na->dest_count =3D=3D nb->dest_count ? 0 : 1; +} + +static gint exception(gconstpointer a, gconstpointer b) +{ + NodeData *na =3D (NodeData *) a; + NodeData *nb =3D (NodeData *) b; + + return na->early_exit > nb->early_exit ? -1 : + na->early_exit =3D=3D nb->early_exit ? 0 : 1; +} + +static gint popular(gconstpointer a, gconstpointer b) +{ + NodeData *na =3D (NodeData *) a; + NodeData *nb =3D (NodeData *) b; + + return na->dests->len > nb->dests->len ? -1 : + na->dests->len =3D=3D nb->dests->len ? 0 : 1; +} + +/* Filter out non-branches - returns true to remove entry */ +static gboolean filter_non_branches(gpointer key, gpointer value, + gpointer user_data) +{ + NodeData *node =3D (NodeData *) value; + + return node->dest_count =3D=3D 0; +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + g_autoptr(GString) result =3D g_string_new("collected "); + GList *data; + GCompareFunc sort =3D &hottest; + int n =3D 0; + + g_mutex_lock(&node_lock); + g_string_append_printf(result, "%d control flow nodes in the hash tabl= e\n", + g_hash_table_size(nodes)); + + /* remove all nodes that didn't branch */ + g_hash_table_foreach_remove(nodes, filter_non_branches, NULL); + + data =3D g_hash_table_get_values(nodes); + + switch (report) { + case SORT_HOTTEST: + sort =3D &hottest; + break; + case SORT_EXCEPTION: + sort =3D &exception; + break; + case SORT_POPDEST: + sort =3D &popular; + break; + } + + data =3D g_list_sort(data, sort); + + for (GList *l =3D data; + l !=3D NULL && n < topn; + l =3D l->next, n++) { + NodeData *n =3D l->data; + const char *type =3D n->mid_count ? "sync fault" : "branch"; + g_string_append_printf(result, " addr: 0x%"PRIx64 " %s: %s (%s)\n= ", + n->addr, n->symbol, n->insn_disas, type); + if (n->early_exit) { + g_string_append_printf(result, " early exits %"PRId64"\n", + n->early_exit); + } + g_string_append_printf(result, " branches %"PRId64"\n", + n->dest_count); + for (int j =3D 0; j < n->dests->len; j++) { + DestData *dd =3D &g_array_index(n->dests, DestData, j); + g_string_append_printf(result, " to 0x%"PRIx64" (%"PRId64= ")\n", + dd->daddr, dd->dcount); + } + } + + qemu_plugin_outs(result->str); + + g_mutex_unlock(&node_lock); +} + +static void plugin_init(void) +{ + g_mutex_init(&node_lock); + nodes =3D g_hash_table_new(NULL, g_direct_equal); + state =3D qemu_plugin_scoreboard_new(sizeof(VCPUScoreBoard)); + + /* score board declarations */ + end_block =3D qemu_plugin_scoreboard_u64_in_struct(state, VCPUScoreBoa= rd, + end_block); + pc_after_block =3D qemu_plugin_scoreboard_u64_in_struct(state, VCPUSco= reBoard, + pc_after_block); + last_pc =3D qemu_plugin_scoreboard_u64_in_struct(state, VCPUScoreBoard, + last_pc); +} + +static NodeData *create_node(uint64_t addr) +{ + NodeData *node =3D g_new0(NodeData, 1); + g_mutex_init(&node->lock); + node->addr =3D addr; + node->dests =3D g_array_new(true, true, sizeof(DestData)); + return node; +} + +static NodeData *fetch_node(uint64_t addr, bool create_if_not_found) +{ + NodeData *node =3D NULL; + + g_mutex_lock(&node_lock); + node =3D (NodeData *) g_hash_table_lookup(nodes, (gconstpointer) addr); + if (!node && create_if_not_found) { + node =3D create_node(addr); + g_hash_table_insert(nodes, (gpointer) addr, (gpointer) node); + } + g_mutex_unlock(&node_lock); + return node; +} + +/* + * Called when we detect a non-linear execution (pc !=3D + * pc_after_block). This could be due to a fault causing some sort of + * exit exception (if last_pc !=3D block_end) or just a taken branch. + */ +static void vcpu_tb_branched_exec(unsigned int cpu_index, void *udata) +{ + uint64_t lpc =3D qemu_plugin_u64_get(last_pc, cpu_index); + uint64_t ebpc =3D qemu_plugin_u64_get(end_block, cpu_index); + uint64_t npc =3D qemu_plugin_u64_get(pc_after_block, cpu_index); + uint64_t pc =3D GPOINTER_TO_UINT(udata); + + /* return early for address 0 */ + if (!lpc) { + return; + } + + NodeData *node =3D fetch_node(lpc, true); + DestData *data =3D NULL; + bool early_exit =3D (lpc !=3D ebpc); + GArray *dests; + + /* the condition should never hit */ + g_assert(pc !=3D npc); + + g_mutex_lock(&node->lock); + + if (early_exit) { + fprintf(stderr, "%s: pc=3D%"PRIx64", epbc=3D%"PRIx64 + " npc=3D%"PRIx64", lpc=3D%"PRIx64"\n", + __func__, pc, ebpc, npc, lpc); + node->early_exit++; + if (!node->mid_count) { + /* count now as we've only just allocated */ + node->mid_count++; + } + } + + dests =3D node->dests; + for (int i =3D 0; i < dests->len; i++) { + if (g_array_index(dests, DestData, i).daddr =3D=3D pc) { + data =3D &g_array_index(dests, DestData, i); + } + } + + /* we've never seen this before, allocate a new entry */ + if (!data) { + DestData new_entry =3D { .daddr =3D pc }; + g_array_append_val(dests, new_entry); + data =3D &g_array_index(dests, DestData, dests->len - 1); + g_assert(data->daddr =3D=3D pc); + } + + data->dcount++; + node->dest_count++; + + g_mutex_unlock(&node->lock); +} + +/* + * At the start of each block we need to resolve two things: + * + * - is last_pc =3D=3D block_end, if not we had an early exit + * - is start of block last_pc + insn width, if not we jumped + * + * Once those are dealt with we can instrument the rest of the + * instructions for their execution. + * + */ +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + uint64_t pc =3D qemu_plugin_tb_vaddr(tb); + size_t insns =3D qemu_plugin_tb_n_insns(tb); + struct qemu_plugin_insn *first_insn =3D qemu_plugin_tb_get_insn(tb, 0); + struct qemu_plugin_insn *last_insn =3D qemu_plugin_tb_get_insn(tb, ins= ns - 1); + + /* + * check if we are executing linearly after the last block. We can + * handle both early block exits and normal branches in the + * callback if we hit it. + */ + gpointer udata =3D GUINT_TO_POINTER(pc); + qemu_plugin_register_vcpu_tb_exec_cond_cb( + tb, vcpu_tb_branched_exec, QEMU_PLUGIN_CB_NO_REGS, + QEMU_PLUGIN_COND_NE, pc_after_block, pc, udata); + + /* + * Now we can set start/end for this block so the next block can + * check where we are at. Do this on the first instruction and not + * the TB so we don't get mixed up with above. + */ + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(first_insn, + QEMU_PLUGIN_INLINE_S= TORE_U64, + end_block, qemu_plug= in_insn_vaddr(last_insn)); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(first_insn, + QEMU_PLUGIN_INLINE_S= TORE_U64, + pc_after_block, + qemu_plugin_insn_vad= dr(last_insn) + + qemu_plugin_insn_siz= e(last_insn)); + + for (int idx =3D 0; idx < qemu_plugin_tb_n_insns(tb); ++idx) { + struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, idx); + uint64_t ipc =3D qemu_plugin_insn_vaddr(insn); + /* + * If this is a potential branch point check if we could grab + * the disassembly for it. If it is the last instruction + * always create an entry. + */ + NodeData *node =3D fetch_node(ipc, last_insn); + if (node) { + g_mutex_lock(&node->lock); + if (!node->insn_disas) { + node->insn_disas =3D qemu_plugin_insn_disas(insn); + } + if (!node->symbol) { + node->symbol =3D qemu_plugin_insn_symbol(insn); + } + if (last_insn =3D=3D insn) { + node->last_count++; + } else { + node->mid_count++; + } + g_mutex_unlock(&node->lock); + } + + /* Store the PC of what we are about to execute */ + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(insn, + QEMU_PLUGIN_IN= LINE_STORE_U64, + last_pc, ipc); + } +} + +QEMU_PLUGIN_EXPORT +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, + int argc, char **argv) +{ + for (int i =3D 0; i < argc; i++) { + char *opt =3D argv[i]; + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); + if (g_strcmp0(tokens[0], "sort") =3D=3D 0) { + if (g_strcmp0(tokens[1], "hottest") =3D=3D 0) { + report =3D SORT_HOTTEST; + } else if (g_strcmp0(tokens[1], "early") =3D=3D 0) { + report =3D SORT_EXCEPTION; + } else if (g_strcmp0(tokens[1], "exceptions") =3D=3D 0) { + report =3D SORT_POPDEST; + } else { + fprintf(stderr, "failed to parse: %s\n", tokens[1]); + return -1; + } + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + plugin_init(); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + return 0; +} diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index 05a2a45c5c..d4ac599f93 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -29,6 +29,7 @@ NAMES +=3D cache NAMES +=3D drcov NAMES +=3D ips NAMES +=3D stoptrigger +NAMES +=3D cflow =20 ifeq ($(CONFIG_WIN32),y) SO_SUFFIX :=3D .dll --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693685; cv=none; d=zohomail.com; s=zohoarc; b=WtdMAvmvbh6rO6a1rqPzLQIva1Oyrb1QRFrxj9ZfV7aafTHeupc9zvzAyVVCipX/fI0F1QYXYbMuW/ff05/cIC80C4cGxYM2STzrwDK42YStAUlfLRWZXbLTKeIB64fv7LAIr5AzkZSsVGuH2duxIX8duwveYZGf84aqsn1r5as= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693685; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sZKHjA4bIfkKrx0hOXWJlXxjiJciHNcD2g6ZdZWFPKM=; b=Vn+PXl4vVH5wYG7SFin4cuxW/MFbepC/GOT0oxn3JsdnFrQxc+ZKuK+a4RLkeFuy7kHB9aMlRL5TeS7hf/QoEhTh2U1c1ngWT4qsJg2aZ9jB8wT+vNGtzYg1A65xdzD3bxNzhontteY99gMlcoCUJHgVWxBeTo5f1cAQaXscVos= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172669368556649.23190467025324; Wed, 18 Sep 2024 14:08:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tS-0004xx-NC; Wed, 18 Sep 2024 17:07:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tQ-0004qx-KT for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:21 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tM-0001ZZ-K4 for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:20 -0400 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5c413cf5de5so219888a12.0 for ; Wed, 18 Sep 2024 14:07:16 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612e1a55sm632367366b.157.2024.09.18.14.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:13 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id A0CD95F8FD; Wed, 18 Sep 2024 22:07:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693635; x=1727298435; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sZKHjA4bIfkKrx0hOXWJlXxjiJciHNcD2g6ZdZWFPKM=; b=TA0oHQAhYmUMiT1o9NVGIzcgiIb94gKijeLSlJnMthiqc6DwwjiDWiqyW7DuXrIj4x 4qTkbJFvScOIliZ+DIyAhhxKIgyeDBsnP3EtLDLKM39bHhwfR+y1r9YFQ9qWa+v1mux4 jMRa0KTEq0Hj12r+SbAvRpBS56W9x477MtkYlV8bWbkQQBI6wMa4CQJ4awspELvk6Mj8 rWBdVwBlVPrLBU/MMPjeGispQ6bsSYQy2YqKj15O0SCMQqGeGFm9tbsTegUYHkd0jmA8 YF2I/tnHxkmXnPNwtigFP++d1OFmwZvCo8dvDoTEfvYEzYxDtqUP7h2P4LJL8zXlXAGy G0Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693635; x=1727298435; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sZKHjA4bIfkKrx0hOXWJlXxjiJciHNcD2g6ZdZWFPKM=; b=nPtwdArVWlk7zPRsgYpViSmVW60/hkLQA9F9mCdCJlwb3JTctRWfNDTOr4VGuYKMpe UWfTmTHtj6P+cqLd/56KFbrylnp68f9nE0R71VsWRzV3WxyPL2gOjZU1LBM9iQKlYn60 GVjOiyu8bv2yoPmHGN7kxEvRoAT7wqFYBQROa1t/b1ZqHtSkUcppjPhoRCpfYC+fssGX WVgU5bsdlzkX+OwHEohcBiWrCjwyhFPipQUxzMT1w3nEXruOXJo0EPUEX7zEdTixzwrB Sp/2/SD+Tmu1EgDcFBZ35fAUrrAgMyqGzoBuUMbrixequaZLhORq0NpVv/6t50+vcNfU JwAA== X-Gm-Message-State: AOJu0YypkdSEHS6mKFqtbLFCvCzImRLChP1u77tSW6BO9+kgp0QVO5+A 3o0qyhwyTs6LSXSlAiABFnS8oXaRK4wGX+wPWqsqk/KZVmNr+/p545j0QdkOOY8= X-Google-Smtp-Source: AGHT+IEgy+p9rdOvsqC3jqncKf0mo5o6cVxAQ3sVN0iPsYTQSsTVoNfDSLhzdlQBVMX8NW+oS9pgdg== X-Received: by 2002:a17:907:8686:b0:a86:82e2:8c6d with SMTP id a640c23a62f3a-a90296718d4mr2502798966b.62.1726693634513; Wed, 18 Sep 2024 14:07:14 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Zhao Liu , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 04/18] plugins: save value during memory accesses Date: Wed, 18 Sep 2024 22:06:58 +0100 Message-Id: <20240918210712.2336854-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::52b; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-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.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693686448116600 From: Pierrick Bouvier Different code paths handle memory accesses: - tcg generated code - load/store helpers - atomic helpers This value is saved in cpu->neg.plugin_mem_value_{high,low}. Values are written only for accessed word size (upper bits are not set). Atomic operations are doing read/write at the same time, so we generate two memory callbacks instead of one, to allow plugins to access distinct values. For now, we can have access only up to 128 bits, thus split this in two 64 bits words. When QEMU will support wider operations, we'll be able to reconsider this. Reviewed-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-2-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-5-alex.bennee@linaro.org> diff --git a/accel/tcg/atomic_template.h b/accel/tcg/atomic_template.h index 1dc2151daf..89593b2502 100644 --- a/accel/tcg/atomic_template.h +++ b/accel/tcg/atomic_template.h @@ -53,6 +53,14 @@ # error unsupported data size #endif =20 +#if DATA_SIZE =3D=3D 16 +# define VALUE_LOW(val) int128_getlo(val) +# define VALUE_HIGH(val) int128_gethi(val) +#else +# define VALUE_LOW(val) val +# define VALUE_HIGH(val) 0 +#endif + #if DATA_SIZE >=3D 4 # define ABI_TYPE DATA_TYPE #else @@ -83,7 +91,12 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, abi_ptr= addr, ret =3D qatomic_cmpxchg__nocheck(haddr, cmpv, newv); #endif ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(newv), + VALUE_HIGH(newv), + oi); return ret; } =20 @@ -97,7 +110,12 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, abi_ptr a= ddr, ABI_TYPE val, =20 ret =3D qatomic_xchg__nocheck(haddr, val); ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(val), + VALUE_HIGH(val), + oi); return ret; } =20 @@ -109,7 +127,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr add= r, \ haddr =3D atomic_mmu_lookup(env_cpu(env), addr, oi, DATA_SIZE, retaddr= ); \ ret =3D qatomic_##X(haddr, val); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(ret), \ + VALUE_HIGH(ret), \ + VALUE_LOW(val), \ + VALUE_HIGH(val), \ + oi); \ return ret; \ } =20 @@ -145,7 +168,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr add= r, \ cmp =3D qatomic_cmpxchg__nocheck(haddr, old, new); \ } while (cmp !=3D old); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(old), \ + VALUE_HIGH(old), \ + VALUE_LOW(xval), \ + VALUE_HIGH(xval), \ + oi); \ return RET; \ } =20 @@ -188,7 +216,12 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, abi_p= tr addr, ret =3D qatomic_cmpxchg__nocheck(haddr, BSWAP(cmpv), BSWAP(newv)); #endif ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(newv), + VALUE_HIGH(newv), + oi); return BSWAP(ret); } =20 @@ -202,7 +235,12 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, abi_ptr = addr, ABI_TYPE val, =20 ret =3D qatomic_xchg__nocheck(haddr, BSWAP(val)); ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(val), + VALUE_HIGH(val), + oi); return BSWAP(ret); } =20 @@ -214,7 +252,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr add= r, \ haddr =3D atomic_mmu_lookup(env_cpu(env), addr, oi, DATA_SIZE, retaddr= ); \ ret =3D qatomic_##X(haddr, BSWAP(val)); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(ret), \ + VALUE_HIGH(ret), \ + VALUE_LOW(val), \ + VALUE_HIGH(val), \ + oi); \ return BSWAP(ret); \ } =20 @@ -247,7 +290,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr add= r, \ ldn =3D qatomic_cmpxchg__nocheck(haddr, ldo, BSWAP(new)); \ } while (ldo !=3D ldn); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(old), \ + VALUE_HIGH(old), \ + VALUE_LOW(xval), \ + VALUE_HIGH(xval), \ + oi); \ return RET; \ } =20 @@ -281,3 +329,5 @@ GEN_ATOMIC_HELPER_FN(add_fetch, ADD, DATA_TYPE, new) #undef SUFFIX #undef DATA_SIZE #undef SHIFT +#undef VALUE_LOW +#undef VALUE_HIGH diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 1c9c775df6..04e9ad4996 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -350,6 +350,8 @@ typedef union IcountDecr { * from CPUArchState, via small negative offsets. * @can_do_io: True if memory-mapped IO is allowed. * @plugin_mem_cbs: active plugin memory callbacks + * @plugin_mem_value_low: 64 lower bits of latest accessed mem value. + * @plugin_mem_value_high: 64 higher bits of latest accessed mem value. */ typedef struct CPUNegativeOffsetState { CPUTLB tlb; @@ -358,6 +360,8 @@ typedef struct CPUNegativeOffsetState { * The callback pointer are accessed via TCG (see gen_empty_mem_helper= ). */ GArray *plugin_mem_cbs; + uint64_t plugin_mem_value_low; + uint64_t plugin_mem_value_high; #endif IcountDecr icount_decr; bool can_do_io; diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index af5f9db469..9726a9ebf3 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -167,6 +167,8 @@ qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, ui= nt64_t a1, void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret); =20 void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, + uint64_t value_low, + uint64_t value_high, MemOpIdx oi, enum qemu_plugin_mem_rw rw); =20 void qemu_plugin_flush_cb(void); @@ -251,6 +253,8 @@ void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_= t num, int64_t ret) { } =20 static inline void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, + uint64_t value_low, + uint64_t value_high, MemOpIdx oi, enum qemu_plugin_mem_rw rw) { } diff --git a/plugins/core.c b/plugins/core.c index 2897453cac..bb105e8e68 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -602,6 +602,8 @@ void exec_inline_op(enum plugin_dyn_cb_type type, } =20 void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, + uint64_t value_low, + uint64_t value_high, MemOpIdx oi, enum qemu_plugin_mem_rw rw) { GArray *arr =3D cpu->neg.plugin_mem_cbs; @@ -610,6 +612,10 @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t v= addr, if (arr =3D=3D NULL) { return; } + + cpu->neg.plugin_mem_value_low =3D value_low; + cpu->neg.plugin_mem_value_high =3D value_high; + for (i =3D 0; i < arr->len; i++) { struct qemu_plugin_dyn_cb *cb =3D &g_array_index(arr, struct qemu_plugin_dyn_cb, i); diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c index 8510160258..23dc807f11 100644 --- a/tcg/tcg-op-ldst.c +++ b/tcg/tcg-op-ldst.c @@ -148,11 +148,11 @@ static TCGv_i64 plugin_maybe_preserve_addr(TCGTemp *a= ddr) return NULL; } =20 +#ifdef CONFIG_PLUGIN static void plugin_gen_mem_callbacks(TCGv_i64 copy_addr, TCGTemp *orig_addr, MemOpIdx = oi, enum qemu_plugin_mem_rw rw) { -#ifdef CONFIG_PLUGIN if (tcg_ctx->plugin_insn !=3D NULL) { qemu_plugin_meminfo_t info =3D make_plugin_meminfo(oi, rw); =20 @@ -172,6 +172,54 @@ plugin_gen_mem_callbacks(TCGv_i64 copy_addr, TCGTemp *= orig_addr, MemOpIdx oi, } } } +} +#endif + +static void +plugin_gen_mem_callbacks_i32(TCGv_i32 val, + TCGv_i64 copy_addr, TCGTemp *orig_addr, + MemOpIdx oi, enum qemu_plugin_mem_rw rw) +{ +#ifdef CONFIG_PLUGIN + if (tcg_ctx->plugin_insn !=3D NULL) { + tcg_gen_st_i32(val, tcg_env, + offsetof(CPUState, neg.plugin_mem_value_low) - + sizeof(CPUState) + (HOST_BIG_ENDIAN * 4)); + plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw); + } +#endif +} + +static void +plugin_gen_mem_callbacks_i64(TCGv_i64 val, + TCGv_i64 copy_addr, TCGTemp *orig_addr, + MemOpIdx oi, enum qemu_plugin_mem_rw rw) +{ +#ifdef CONFIG_PLUGIN + if (tcg_ctx->plugin_insn !=3D NULL) { + tcg_gen_st_i64(val, tcg_env, + offsetof(CPUState, neg.plugin_mem_value_low) - + sizeof(CPUState)); + plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw); + } +#endif +} + +static void +plugin_gen_mem_callbacks_i128(TCGv_i128 val, + TCGv_i64 copy_addr, TCGTemp *orig_addr, + MemOpIdx oi, enum qemu_plugin_mem_rw rw) +{ +#ifdef CONFIG_PLUGIN + if (tcg_ctx->plugin_insn !=3D NULL) { + tcg_gen_st_i64(TCGV128_LOW(val), tcg_env, + offsetof(CPUState, neg.plugin_mem_value_low) - + sizeof(CPUState)); + tcg_gen_st_i64(TCGV128_HIGH(val), tcg_env, + offsetof(CPUState, neg.plugin_mem_value_high) - + sizeof(CPUState)); + plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw); + } #endif } =20 @@ -203,7 +251,8 @@ static void tcg_gen_qemu_ld_i32_int(TCGv_i32 val, TCGTe= mp *addr, opc =3D INDEX_op_qemu_ld_a64_i32; } gen_ldst(opc, tcgv_i32_temp(val), NULL, addr, oi); - plugin_gen_mem_callbacks(copy_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R); + plugin_gen_mem_callbacks_i32(val, copy_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_R); =20 if ((orig_memop ^ memop) & MO_BSWAP) { switch (orig_memop & MO_SIZE) { @@ -271,7 +320,7 @@ static void tcg_gen_qemu_st_i32_int(TCGv_i32 val, TCGTe= mp *addr, } } gen_ldst(opc, tcgv_i32_temp(val), NULL, addr, oi); - plugin_gen_mem_callbacks(NULL, addr, orig_oi, QEMU_PLUGIN_MEM_W); + plugin_gen_mem_callbacks_i32(val, NULL, addr, orig_oi, QEMU_PLUGIN_MEM= _W); =20 if (swap) { tcg_temp_free_i32(swap); @@ -324,7 +373,8 @@ static void tcg_gen_qemu_ld_i64_int(TCGv_i64 val, TCGTe= mp *addr, opc =3D INDEX_op_qemu_ld_a64_i64; } gen_ldst_i64(opc, val, addr, oi); - plugin_gen_mem_callbacks(copy_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R); + plugin_gen_mem_callbacks_i64(val, copy_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_R); =20 if ((orig_memop ^ memop) & MO_BSWAP) { int flags =3D (orig_memop & MO_SIGN @@ -396,7 +446,7 @@ static void tcg_gen_qemu_st_i64_int(TCGv_i64 val, TCGTe= mp *addr, opc =3D INDEX_op_qemu_st_a64_i64; } gen_ldst_i64(opc, val, addr, oi); - plugin_gen_mem_callbacks(NULL, addr, orig_oi, QEMU_PLUGIN_MEM_W); + plugin_gen_mem_callbacks_i64(val, NULL, addr, orig_oi, QEMU_PLUGIN_MEM= _W); =20 if (swap) { tcg_temp_free_i64(swap); @@ -606,7 +656,8 @@ static void tcg_gen_qemu_ld_i128_int(TCGv_i128 val, TCG= Temp *addr, tcg_constant_i32(orig_oi)); } =20 - plugin_gen_mem_callbacks(ext_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R); + plugin_gen_mem_callbacks_i128(val, ext_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_R); } =20 void tcg_gen_qemu_ld_i128_chk(TCGv_i128 val, TCGTemp *addr, TCGArg idx, @@ -722,7 +773,8 @@ static void tcg_gen_qemu_st_i128_int(TCGv_i128 val, TCG= Temp *addr, tcg_constant_i32(orig_oi)); } =20 - plugin_gen_mem_callbacks(ext_addr, addr, orig_oi, QEMU_PLUGIN_MEM_W); + plugin_gen_mem_callbacks_i128(val, ext_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_W); } =20 void tcg_gen_qemu_st_i128_chk(TCGv_i128 val, TCGTemp *addr, TCGArg idx, diff --git a/accel/tcg/atomic_common.c.inc b/accel/tcg/atomic_common.c.inc index 95a5c5ff12..6056598c23 100644 --- a/accel/tcg/atomic_common.c.inc +++ b/accel/tcg/atomic_common.c.inc @@ -14,9 +14,20 @@ */ =20 static void atomic_trace_rmw_post(CPUArchState *env, uint64_t addr, + uint64_t read_value_low, + uint64_t read_value_high, + uint64_t write_value_low, + uint64_t write_value_high, MemOpIdx oi) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_RW); + if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + read_value_low, read_value_high, + oi, QEMU_PLUGIN_MEM_R); + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + write_value_low, write_value_high, + oi, QEMU_PLUGIN_MEM_W); + } } =20 /* diff --git a/accel/tcg/ldst_common.c.inc b/accel/tcg/ldst_common.c.inc index 87ceb95487..ebbf380d76 100644 --- a/accel/tcg/ldst_common.c.inc +++ b/accel/tcg/ldst_common.c.inc @@ -123,10 +123,15 @@ void helper_st_i128(CPUArchState *env, uint64_t addr,= Int128 val, MemOpIdx oi) * Load helpers for cpu_ldst.h */ =20 -static void plugin_load_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi) +static void plugin_load_cb(CPUArchState *env, abi_ptr addr, + uint64_t value_low, + uint64_t value_high, + MemOpIdx oi) { if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_R); + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + value_low, value_high, + oi, QEMU_PLUGIN_MEM_R); } } =20 @@ -136,7 +141,7 @@ uint8_t cpu_ldb_mmu(CPUArchState *env, abi_ptr addr, Me= mOpIdx oi, uintptr_t ra) =20 tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_UB); ret =3D do_ld1_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } =20 @@ -147,7 +152,7 @@ uint16_t cpu_ldw_mmu(CPUArchState *env, abi_ptr addr, =20 tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_16); ret =3D do_ld2_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } =20 @@ -158,7 +163,7 @@ uint32_t cpu_ldl_mmu(CPUArchState *env, abi_ptr addr, =20 tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_32); ret =3D do_ld4_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } =20 @@ -169,7 +174,7 @@ uint64_t cpu_ldq_mmu(CPUArchState *env, abi_ptr addr, =20 tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_64); ret =3D do_ld8_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } =20 @@ -180,7 +185,7 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, =20 tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_128); ret =3D do_ld16_mmu(env_cpu(env), addr, oi, ra); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, int128_getlo(ret), int128_gethi(ret), oi); return ret; } =20 @@ -188,10 +193,15 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, * Store helpers for cpu_ldst.h */ =20 -static void plugin_store_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi) +static void plugin_store_cb(CPUArchState *env, abi_ptr addr, + uint64_t value_low, + uint64_t value_high, + MemOpIdx oi) { if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_W); + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + value_low, value_high, + oi, QEMU_PLUGIN_MEM_W); } } =20 @@ -199,7 +209,7 @@ void cpu_stb_mmu(CPUArchState *env, abi_ptr addr, uint8= _t val, MemOpIdx oi, uintptr_t retaddr) { helper_stb_mmu(env, addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } =20 void cpu_stw_mmu(CPUArchState *env, abi_ptr addr, uint16_t val, @@ -207,7 +217,7 @@ void cpu_stw_mmu(CPUArchState *env, abi_ptr addr, uint1= 6_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_16); do_st2_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } =20 void cpu_stl_mmu(CPUArchState *env, abi_ptr addr, uint32_t val, @@ -215,7 +225,7 @@ void cpu_stl_mmu(CPUArchState *env, abi_ptr addr, uint3= 2_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_32); do_st4_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } =20 void cpu_stq_mmu(CPUArchState *env, abi_ptr addr, uint64_t val, @@ -223,7 +233,7 @@ void cpu_stq_mmu(CPUArchState *env, abi_ptr addr, uint6= 4_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_64); do_st8_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } =20 void cpu_st16_mmu(CPUArchState *env, abi_ptr addr, Int128 val, @@ -231,7 +241,7 @@ void cpu_st16_mmu(CPUArchState *env, abi_ptr addr, Int1= 28 val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_128); do_st16_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, int128_getlo(val), int128_gethi(val), oi); } =20 /* --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693740; cv=none; d=zohomail.com; s=zohoarc; b=TvvOgqxnnuUmIcBUDNnv5f+92zBLS3wtek+A5zyThysWg0tPRSB0igxaBUWxP+BBG9Yk1+YsupnGuexdd4JH73pPYmW/u0Lsh7RYeyBPr9mLyHM/DYHe4SEpAqkbyvwObuVaBdSsuijFy5cLY0H05f083oQVwG84J62j+9HlKls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693740; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=N+FbOV5cANak4tvS11G6TRWhb5xp2aE/sDGBKNdQXN8=; b=JkVgJx4GhYc2Kxu9d4xOSAehGt8JIclnlokQefyw79sQK/AzLtK31xzjaUzbu2ykINGufPIhYh48+PbG6WskExS4bJXblJt4CYfl6LtMgTHoyho+i09I89yt1qLRmjKQn+0xgJ5n4HQNrQ6N6gMOq23m5+OQ31YlzGRoyw8rLXM= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693740902155.4407123726645; Wed, 18 Sep 2024 14:09:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tT-00051N-FC; Wed, 18 Sep 2024 17:07:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tQ-0004qi-IW for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:21 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tO-0001bF-OV for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:20 -0400 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5356bb55224so184243e87.0 for ; Wed, 18 Sep 2024 14:07:18 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90613303b4sm629745866b.213.2024.09.18.14.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:14 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id BBF0D5F90C; Wed, 18 Sep 2024 22:07:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693637; x=1727298437; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N+FbOV5cANak4tvS11G6TRWhb5xp2aE/sDGBKNdQXN8=; b=s569fDSxJFvhx5IkcfJvm5D7LA2djEYPxZOlNNTQPe2+kgLnTDWGA5vy6hIktlHAZv N0yywnal2dOC9y8LaE979z1YZLknWF05sK7RBFomgE1T+vWakKyC065s+34PgsqrF/sJ 0zcBl0c4g3qM/trGm3Ee2zyOCAC2d6pclj9XfUqF0giMnPiSTFER5UveQR3Tte1n7SJi WSuvRUDclZBys1RkRBO81hMIuAonpyDf6yfS4fv14+smAxc03Idc+1zeCXzZ6xhFeDIj b1aOHBTKG32CjrRIYagd5KdzPw8avS/Vw713I3G0RWivgJSnDq086TlGpzaqmMD/ndHy 2Lqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693637; x=1727298437; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N+FbOV5cANak4tvS11G6TRWhb5xp2aE/sDGBKNdQXN8=; b=PTRwDNz4OHbHosa4jYUIUnFlyPV+qTfVGWNl4jr4JNagt8BNtUUGm2NK+IpC3+6DBh PdGK/I0QJoswdkJB8VTdcNlS4n68eVSbLF+R1g/FNxE7U9zr2KEyDCUX47FrrqW2/fhs HZ1qSwyJ6sfewJcsrE0kYKOxPvY3a+mOaupS+jixluokeD+waqFaO9pCp+1YLDI074UY d8DZ6xJxUdXBaCPiaVX0y7jtBL/viiiOR2Vuduik1DCOXfyZuksHKS3UXNqkVWk8ejWI PksaUQV40ezGJjQidlDfg4Ak6an93BjMXRoUJ2raNvW3qyZhXMYRC7EUfyK3dx4SHfDF j3qQ== X-Gm-Message-State: AOJu0YyeO6K8xH7dVulyVRD9rk+goMhq3hufy+9dEjQU+HKN73YcBFz0 u+PwtRZDDsKhCRo3yfiyiXlNsT/Jz4VCGmUgoSEa9k2mxJCyAVpjYe7iBVpwJSw= X-Google-Smtp-Source: AGHT+IEp6fTJxY/j2S51BW7MiCjkKds9grj+5Jug2wGokBe6c7zZtRGT3vzVlr0u5lXzOww2gjwI1A== X-Received: by 2002:a05:6512:3350:b0:536:7a88:6185 with SMTP id 2adb3069b0e04-5367a8862e7mr10410876e87.15.1726693636428; Wed, 18 Sep 2024 14:07:16 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Xingtao Yao , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 05/18] plugins: extend API to get latest memory value accessed Date: Wed, 18 Sep 2024 22:06:59 +0100 Message-Id: <20240918210712.2336854-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::12a; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x12a.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.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693742351116600 From: Pierrick Bouvier This value can be accessed only during a memory callback, using new qemu_plugin_mem_get_value function. Returned value can be extended when QEMU will support accesses wider than 128 bits. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1719 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2152 Reviewed-by: Richard Henderson Reviewed-by: Xingtao Yao Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-6-alex.bennee@linaro.org> diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index c71c705b69..649ce89815 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -262,6 +262,29 @@ enum qemu_plugin_mem_rw { QEMU_PLUGIN_MEM_RW, }; =20 +enum qemu_plugin_mem_value_type { + QEMU_PLUGIN_MEM_VALUE_U8, + QEMU_PLUGIN_MEM_VALUE_U16, + QEMU_PLUGIN_MEM_VALUE_U32, + QEMU_PLUGIN_MEM_VALUE_U64, + QEMU_PLUGIN_MEM_VALUE_U128, +}; + +/* typedef qemu_plugin_mem_value - value accessed during a load/store */ +typedef struct { + enum qemu_plugin_mem_value_type type; + union { + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + struct { + uint64_t low; + uint64_t high; + } u128; + } data; +} qemu_plugin_mem_value; + /** * enum qemu_plugin_cond - condition to enable callback * @@ -551,6 +574,15 @@ bool qemu_plugin_mem_is_big_endian(qemu_plugin_meminfo= _t info); QEMU_PLUGIN_API bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info); =20 +/** + * qemu_plugin_mem_get_mem_value() - return last value loaded/stored + * @info: opaque memory transaction handle + * + * Returns: memory value + */ +QEMU_PLUGIN_API +qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info= ); + /** * qemu_plugin_get_hwaddr() - return handle for memory operation * @info: opaque memory info structure diff --git a/plugins/api.c b/plugins/api.c index 2ff13d09de..3316d4a04d 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -351,6 +351,39 @@ bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t in= fo) return get_plugin_meminfo_rw(info) & QEMU_PLUGIN_MEM_W; } =20 +qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info) +{ + uint64_t low =3D current_cpu->neg.plugin_mem_value_low; + qemu_plugin_mem_value value; + + switch (qemu_plugin_mem_size_shift(info)) { + case 0: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U8; + value.data.u8 =3D (uint8_t)low; + break; + case 1: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U16; + value.data.u16 =3D (uint16_t)low; + break; + case 2: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U32; + value.data.u32 =3D (uint32_t)low; + break; + case 3: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U64; + value.data.u64 =3D low; + break; + case 4: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U128; + value.data.u128.low =3D low; + value.data.u128.high =3D current_cpu->neg.plugin_mem_value_high; + break; + default: + g_assert_not_reached(); + } + return value; +} + /* * Virtual Memory queries */ diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index ca773d8d9f..eed9d8abd9 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -13,6 +13,7 @@ qemu_plugin_insn_size; qemu_plugin_insn_symbol; qemu_plugin_insn_vaddr; + qemu_plugin_mem_get_value; qemu_plugin_mem_is_big_endian; qemu_plugin_mem_is_sign_extended; qemu_plugin_mem_is_store; --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693789; cv=none; d=zohomail.com; s=zohoarc; b=OVxRGxDcg0dhgCu6s+1psNgFG7wUeZ4mjr6k5pKL08ovRGME1uSMa2VcSzP/dCprFZY2Wcts9uIV4ZpssfFvoM6Bs3gBnY+ztblQNwquSLFb79UJEXY5GgH1r4A4Fia5PpfNJ0Mhu7PbRPoTtrbswLx8UyLE6TavL6+ccDuqWxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693789; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5hPYnws2CPsfhEtfVIm4JM3/IzZjfJCyZOBoN4xWTqc=; b=JBGWyvcrJUj7+rya17IBhouhueQvSaa+IIcl2ccQkU7nOpbR1P24BVHqqhxOM8cbNRG6AIF2Bk4jacmHr9NwAB3IOUKFQXjcxSxj+3RmyrmeedGRw732A5Qv1DKL8vyeSLDUPtOXQvHcplYEmkYQwSjQzfZoBclrDNnUizsqtv0= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693789245782.4700396384615; Wed, 18 Sep 2024 14:09:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tU-00054R-32; Wed, 18 Sep 2024 17:07:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tR-0004rn-4d for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:21 -0400 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tP-0001bk-JA for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:20 -0400 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2f75aa08a96so1052201fa.1 for ; Wed, 18 Sep 2024 14:07:19 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c42bb8a428sm5339909a12.71.2024.09.18.14.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:16 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id D1A4B5F90D; Wed, 18 Sep 2024 22:07:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693638; x=1727298438; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5hPYnws2CPsfhEtfVIm4JM3/IzZjfJCyZOBoN4xWTqc=; b=ayydsn91G+nUmPpv9xPPyYOkJbeMUKZcCrUnBqqaUslrAadyddxa8AG6uU1iOjBD7R dFh3CDb3O3NDQiTiW97Yp1Ekb1BlbHQwu3d7paUHULxd4deiCM5PsQ4R5EC+Y9zsNzHd B7Ilnnr9rQF807AX/0/7g22UwxNKs0ewq9Qra37zwJU1xqEGuTr9sQBrQP8b6E40ieoz UTowwmwfhGQ1a7R2xrSe/OsWxPxcpzuCiwE1e90G3YEC/e+Kym3/oYCp6J6D8eaHHO4Y KqGqm2GDldX3Aa+64ppaHcOdukrfvVdpol/O7KDySYr0G5nw9Op3Nh/cy2DM2jwaxTtO WNjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693638; x=1727298438; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5hPYnws2CPsfhEtfVIm4JM3/IzZjfJCyZOBoN4xWTqc=; b=ZJS/yMxRMT2QH6eSKSFlEBDmVvX0hLKcgiHgtwtbxBe8ox1LQM009LrdSe2BW+irBS KkUewnPD4TU/JbUMENHZPG/uOquU/9pZ7ddKNO3iotn5eaMGcJc8eH10YpMbAFRGn/8P 22o2owdiv2jzvNrGclcuiqIu+8QCfxTpbyAFMNAORaH8ze4qA+A9jQ3jeMyicIkQPfvT vqsxfx0DcaxCfhFH4MdAI73pImDouHfznDH3rtON04SYvHk7QMxPDDYrwOouz7UX0Wi3 I/DTG9iXQhroYAhdpaP6XkvKoIm2Llnz4yLtCeQxbPv/BwL0kIlVNCTY5EYggG5HTNQw wFZA== X-Gm-Message-State: AOJu0Yy7mzGC/yu7NKabC2Lxmtyfn3zBQRQg5NJg9Hr5FS9/N2t0iOkf 07Ueh4N4uvz1RPBaao4fEI+GkSDjA4tujaB3PwmgMmXjIaoldd+PCRZRcgYOkcE= X-Google-Smtp-Source: AGHT+IEnvjLMHLinVv+EhQk56jEdhD4T8ezGvIWrqMtsdpWXfl9Wmjh2jAhE2/7jpCkrzi5itR2RoA== X-Received: by 2002:a05:651c:1548:b0:2f7:5bcd:ab52 with SMTP id 38308e7fff4ca-2f787edca58mr121477401fa.25.1726693637736; Wed, 18 Sep 2024 14:07:17 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Xingtao Yao , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 06/18] tests/tcg: add mechanism to run specific tests with plugins Date: Wed, 18 Sep 2024 22:07:00 +0100 Message-Id: <20240918210712.2336854-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::229; envelope-from=alex.bennee@linaro.org; helo=mail-lj1-x229.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.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693790446116600 From: Pierrick Bouvier Only multiarch tests are run with plugins, and we want to be able to run per-arch test with plugins too. Tested-by: Xingtao Yao Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-4-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-7-alex.bennee@linaro.org> diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index 452a2cde65..c5b1c7a786 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -152,10 +152,11 @@ PLUGINS=3D$(patsubst %.c, lib%.so, $(notdir $(wildcar= d $(PLUGIN_SRC)/*.c))) # only expand MULTIARCH_TESTS which are common on most of our targets # to avoid an exponential explosion as new tests are added. We also # add some special helpers the run-plugin- rules can use below. +# In more, extra tests can be added using ADDITIONAL_PLUGINS_TESTS variabl= e. =20 ifneq ($(MULTIARCH_TESTS),) $(foreach p,$(PLUGINS), \ - $(foreach t,$(MULTIARCH_TESTS),\ + $(foreach t,$(MULTIARCH_TESTS) $(ADDITIONAL_PLUGINS_TESTS),\ $(eval run-plugin-$(t)-with-$(p): $t $p) \ $(eval RUN_TESTS+=3Drun-plugin-$(t)-with-$(p)))) endif # MULTIARCH_TESTS --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693701; cv=none; d=zohomail.com; s=zohoarc; b=U7oN24Ip67WhkzyKJ1QMZBOmPSmGlVzeFTtG1F5G4FuHO0keu7ozaw+KZI9X6HSvdV3wmhkL36lwmxp2BReez+hguJTfZltN+4vTJlHHQKMQecfcfOVbc1YVdG93VtbOe5sbdPV0/+61M672CwfdlKxYwTwXyGcYafwAvDJGjVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693701; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rI5TLawxN3XyN9WoPBlVoz7ngejExnr3r/CzR6HnTEw=; b=U8xLjopCWsx4voM7hx7C16CDm0QFjvFbRdFDzthrmsOC3FPA8DZH15x0WWvP6p2NkldnNz1aSAikwXdYFs3DBb3l6OEnfcrHJbh7uNPXmaglkzvDyCoCBJDjP8AdDF+bpDPJcsTQSOWGBkswzH9TNUjV3e9tWXUqNod3tvOU/78= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172669370113571.40253482302808; Wed, 18 Sep 2024 14:08:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tS-0004xG-JM; Wed, 18 Sep 2024 17:07:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tP-0004pT-UY for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:19 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tO-0001bD-Bw for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:19 -0400 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5c2561e8041so178895a12.2 for ; Wed, 18 Sep 2024 14:07:17 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c42bb56b8bsm5388386a12.38.2024.09.18.14.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:15 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id E97E75F915; Wed, 18 Sep 2024 22:07:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693637; x=1727298437; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rI5TLawxN3XyN9WoPBlVoz7ngejExnr3r/CzR6HnTEw=; b=ePkdgPe0gcPr6nOaB5z1PtrkqCfoNwc7jf83SPU6KK53OqYrwfOaT07xZYoTGmnxWi 8Tj0Pb3vM4buIIeITZjoccZFqDC6DcMO2+WY5nLkmQrDoXiW5Ngxd6tc3Rx6UawO+P0p wQUweYqX1acOqw1GL6afMk2uC1YcGdwQcxKBxEO7S41WSML3rJfQFe8KUz/18w1wmxF5 wdjLcoy24SrA0Q8lBeiWZdRrKTw/qWtmNS9mzmyXoAql55t/5OzkqIKiiJ69eyLAvPrI u5aGQu9oElwD05IpNeOKmzHRVVanlfGhKn/eP8n6+heehu6D8yKM2OozZ6Gu2IlWcHKL ZhnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693637; x=1727298437; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rI5TLawxN3XyN9WoPBlVoz7ngejExnr3r/CzR6HnTEw=; b=ANDn7d6xLcK5UJ4KVPKXgOc6w36C9ei5gihgAAxUdKA5WvE+8wYSNdFoce9xD927gF EKx2f9Mdnc0dsnUS55nr3v0GOXKjY3UwyCTLN9tEHs2LjdAwo028MDDnEAoU18eb6cJ9 yE1Va5CDeJusuUVxjb0bPPLl19g+exkyLZlMheUrIaRvdjQixrlRPkxXfczeSKvM2yUB eUiMydje/ZdDcJt8JDSCVlcZwqBOX9jSStXKLFWP6EOw3lS91ogQEjRKR/PELDCWwGkM KvxWnqEBdgsQf16BYxbSYoRxJisb+nD8Krbc7t2SD7v772Ya3KMx755b4V0K0PBLCUbm oAnA== X-Gm-Message-State: AOJu0Yw2Mmm8fDCtE+WEx6jK7o2+1daM5OltN78adx5Xiq0UHbnZwRIr QYmbKwLNOzsASZDDPYA5YPi6L/d89jRAM3Y+9WCjgc8oLeAyoo/lG92U5L2iy4s= X-Google-Smtp-Source: AGHT+IFrzLV+tyZj9XLtohYflGz6GBsLa8ldZJM6I5s9hcmwOt0nDLT4iupCkVIq+IktCRB//9cQxQ== X-Received: by 2002:a05:6402:518a:b0:5c3:cd88:a0a with SMTP id 4fb4d7f45d1cf-5c41e19063bmr17990636a12.18.1726693636778; Wed, 18 Sep 2024 14:07:16 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Xingtao Yao , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 07/18] tests/tcg: allow to check output of plugins Date: Wed, 18 Sep 2024 22:07:01 +0100 Message-Id: <20240918210712.2336854-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::531; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693702124116600 From: Pierrick Bouvier A specific plugin test can now read and check a plugin output, to ensure it contains expected values. Tested-by: Xingtao Yao Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-5-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-8-alex.bennee@linaro.org> diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index c5b1c7a786..2da70b2fcf 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -90,6 +90,7 @@ CFLAGS=3D LDFLAGS=3D =20 QEMU_OPTS=3D +CHECK_PLUGIN_OUTPUT_COMMAND=3D =20 =20 # If TCG debugging, or TCI is enabled things are a lot slower @@ -180,6 +181,10 @@ run-plugin-%: -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \ -d plugin -D $*.pout \ $(call strip-plugin,$<)) + $(if $(CHECK_PLUGIN_OUTPUT_COMMAND), \ + $(call quiet-command, $(CHECK_PLUGIN_OUTPUT_COMMAND) $*.pout, \ + TEST, check plugin $(call extract-plugin,$@) output \ + with $(call strip-plugin,$<))) else run-%: % $(call run-test, $<, \ @@ -194,6 +199,10 @@ run-plugin-%: -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \ -d plugin -D $*.pout \ $(QEMU_OPTS) $(call strip-plugin,$<)) + $(if $(CHECK_PLUGIN_OUTPUT_COMMAND), \ + $(call quiet-command, $(CHECK_PLUGIN_OUTPUT_COMMAND) $*.pout, \ + TEST, check plugin $(call extract-plugin,$@) output \ + with $(call strip-plugin,$<))) endif =20 gdb-%: % --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693776; cv=none; d=zohomail.com; s=zohoarc; b=kbKvBkTrwgiU+gc8aZSRw7hEoycT8uw4kZ33jl8f9wS52EJPR9QEdrgybwWePtz5ipf2OD2Ljfeo53mPDlqLwx3mJBtVCc1qbGxkFawjrc303aUV8ik9n/QcBQlCWEhRy9gFfF9fn9BHHSdm8trTb8Xk0hPinylExBGotrr/ki8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693776; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i1kXUvvvaOTMo8s7e2uG5gEP5uMQuh7mg8YfEGDANcA=; b=ir9x5of5/KfeN4WWixa96aY5LSqS4qkEREzVKlRIZ0et3pUGBXLiMecfAcT6D1Wbjr5yEoJIixEmow06X5V5bgrTD6UDlzpXQcDRJKSLjenTxInN1gISJ5rAGR0DvaC7rIunw91n9Lp/IcCQPl1acNfLjQUJQebVkLEiPx8VeV8= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172669377641768.29218911224905; Wed, 18 Sep 2024 14:09:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tV-00059C-8T; Wed, 18 Sep 2024 17:07:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tT-0004zS-1A for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:23 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tR-0001d5-Av for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:22 -0400 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a8d13b83511so10464666b.2 for ; Wed, 18 Sep 2024 14:07:20 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612b38d3sm632934066b.120.2024.09.18.14.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:16 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 0CCB65F91C; Wed, 18 Sep 2024 22:07:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693640; x=1727298440; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i1kXUvvvaOTMo8s7e2uG5gEP5uMQuh7mg8YfEGDANcA=; b=E0bRbln++7rnDSPjbqcWC1UgwpS3F4t588omY36asmqK781BV9jJWF4J++56yXpGOc K5YjhFqZjmyvdZrlMloNEU/P1imPIpww7gl6WVfHGDniwQ4WnA9zi711v8FdXD7uBhn8 f5d7RxuM7EIME5AKCpU7fJDhO3mPuTawLUmrzJkwUffK9HtFJWoz+V4Q0d5Y8bTb0ETL 5To9EwAcB44VixnzGAARgIZGV+Nvzrw+AlWwYWTVcSdlhMshiJ5bXtLJwYzxSHkFK66i cmmtTBw1lz5UO4m/ILWEOwFV7HId9m25AjsV9YrJD4k0nfj31HteYyqxZP/7amjJMYq1 bUzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693640; x=1727298440; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i1kXUvvvaOTMo8s7e2uG5gEP5uMQuh7mg8YfEGDANcA=; b=NsSVqkErvJt/mDV5jCmuMud5NDiRLZXDpYSDFHUdY6nz19w86yTBAqDW6g7BUhajAR fw0WPOKbIV6XBMZl5Qu6ctwnR+q2jF726EztUcjwly7VsDL2j3+CzDx/smAIVoQqpF+z WanEw/+Vk6XDu63vSlK4/hoW5xVVXLq6P/94WWzTzUAazgXDlPtxaLgx4ratl1X7EnTb qgED6HAY96no4ht1gch/42QQYi/4yWw1llp1AT5djjQUTRdGKvK09in6MUN6IZ8UjGlj xVpVwOOL9gN0Et/RmtClu0C3jv5Yn716mN7Dy4u26nC3fktIiNLMqmJ0eU+859588IsE uQoA== X-Gm-Message-State: AOJu0Yxeujzzv2tYjzUdshYYBxDr7i1HyKfASnLaoLxdr6DqbUfgWZgA Ox4bf3wUNtF5h7CVnWHlMxt/itJ5kz3nXW3Bg4URDGsXedSm0wvLqON/UpayE1o= X-Google-Smtp-Source: AGHT+IHtjN+HO9qUip40GECxTEQ4EykwTUjhojt2P1WXY5LQr//NpT5nRROO1yROjV+vzJrxVsCoCA== X-Received: by 2002:a17:906:fd8b:b0:a8a:8915:6bf6 with SMTP id a640c23a62f3a-a9029617974mr2354964066b.52.1726693639565; Wed, 18 Sep 2024 14:07:19 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Xingtao Yao , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 08/18] tests/tcg/plugins/mem: add option to print memory accesses Date: Wed, 18 Sep 2024 22:07:02 +0100 Message-Id: <20240918210712.2336854-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::632; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x632.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.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693778414116600 From: Pierrick Bouvier By using "print-accesses=3Dtrue" option, mem plugin will now print every value accessed, with associated size, type (store vs load), symbol, instruction address and phys/virt address accessed. Reviewed-by: Richard Henderson Reviewed-by: Xingtao Yao Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-6-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-9-alex.bennee@linaro.org> diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c index b650dddcce..086e6f5bdf 100644 --- a/tests/tcg/plugins/mem.c +++ b/tests/tcg/plugins/mem.c @@ -21,10 +21,15 @@ typedef struct { uint64_t io_count; } CPUCount; =20 +typedef struct { + uint64_t vaddr; + const char *sym; +} InsnInfo; + static struct qemu_plugin_scoreboard *counts; static qemu_plugin_u64 mem_count; static qemu_plugin_u64 io_count; -static bool do_inline, do_callback; +static bool do_inline, do_callback, do_print_accesses; static bool do_haddr; static enum qemu_plugin_mem_rw rw =3D QEMU_PLUGIN_MEM_RW; =20 @@ -60,6 +65,44 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin= _meminfo_t meminfo, } } =20 +static void print_access(unsigned int cpu_index, qemu_plugin_meminfo_t mem= info, + uint64_t vaddr, void *udata) +{ + InsnInfo *insn_info =3D udata; + unsigned size =3D 8 << qemu_plugin_mem_size_shift(meminfo); + const char *type =3D qemu_plugin_mem_is_store(meminfo) ? "store" : "lo= ad"; + qemu_plugin_mem_value value =3D qemu_plugin_mem_get_value(meminfo); + uint64_t hwaddr =3D + qemu_plugin_hwaddr_phys_addr(qemu_plugin_get_hwaddr(meminfo, vaddr= )); + g_autoptr(GString) out =3D g_string_new(""); + g_string_printf(out, + "0x%"PRIx64",%s,0x%"PRIx64",0x%"PRIx64",%d,%s,", + insn_info->vaddr, insn_info->sym, + vaddr, hwaddr, size, type); + switch (value.type) { + case QEMU_PLUGIN_MEM_VALUE_U8: + g_string_append_printf(out, "0x%02"PRIx8, value.data.u8); + break; + case QEMU_PLUGIN_MEM_VALUE_U16: + g_string_append_printf(out, "0x%04"PRIx16, value.data.u16); + break; + case QEMU_PLUGIN_MEM_VALUE_U32: + g_string_append_printf(out, "0x%08"PRIx32, value.data.u32); + break; + case QEMU_PLUGIN_MEM_VALUE_U64: + g_string_append_printf(out, "0x%016"PRIx64, value.data.u64); + break; + case QEMU_PLUGIN_MEM_VALUE_U128: + g_string_append_printf(out, "0x%016"PRIx64"%016"PRIx64, + value.data.u128.high, value.data.u128.low); + break; + default: + g_assert_not_reached(); + } + g_string_append_printf(out, "\n"); + qemu_plugin_outs(out->str); +} + static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) { size_t n =3D qemu_plugin_tb_n_insns(tb); @@ -79,6 +122,16 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct q= emu_plugin_tb *tb) QEMU_PLUGIN_CB_NO_REGS, rw, NULL); } + if (do_print_accesses) { + /* we leak this pointer, to avoid locking to keep track of it = */ + InsnInfo *insn_info =3D g_malloc(sizeof(InsnInfo)); + const char *sym =3D qemu_plugin_insn_symbol(insn); + insn_info->sym =3D sym ? sym : ""; + insn_info->vaddr =3D qemu_plugin_insn_vaddr(insn); + qemu_plugin_register_vcpu_mem_cb(insn, print_access, + QEMU_PLUGIN_CB_NO_REGS, + rw, (void *) insn_info); + } } } =20 @@ -117,6 +170,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); return -1; } + } else if (g_strcmp0(tokens[0], "print-accesses") =3D=3D 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &do_print_accesses)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); + return -1; + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; @@ -129,6 +188,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, return -1; } =20 + if (do_print_accesses) { + g_autoptr(GString) out =3D g_string_new(""); + g_string_printf(out, + "insn_vaddr,insn_symbol,mem_vaddr,mem_hwaddr," + "access_size,access_type,mem_value\n"); + qemu_plugin_outs(out->str); + } + counts =3D qemu_plugin_scoreboard_new(sizeof(CPUCount)); mem_count =3D qemu_plugin_scoreboard_u64_in_struct( counts, CPUCount, mem_count); --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693888; cv=none; d=zohomail.com; s=zohoarc; b=LBSbriXBPelxjKVJ3UBwsrj9neRYUb1jLYgah4qDzpYdIlI7vr6Mr+WLOp9FguQAnpngLJYrGjAr0yy823PgXre9bi6aA3/1S2Ev0h2UKdiUERUzl4iJ5FYy1qow+hKDri0hrWPt5XvO0IRrSiPLBVO2I062PBJgrbfC3bWIAeE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693888; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hb8yLghAtC/pu08FHFoyfQSeSGmKFv1fHdJy4n4nII4=; b=e4M2pQLiOqYNocnXtU4+XViO5lEZqI+Edi7xKMF6edGQjmvpC9vq6lZAch6yHSznBQS9tJK5+PYLlx57tWHo39cC6/FnAXHNq//EPOBlhij+TAMYarUBqEOGncPIFfFnJk7RwhUt3fc+loUHUiSYX6BFt4BC1blS4QXEGCEUi2E= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693888644769.5879497109032; Wed, 18 Sep 2024 14:11:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tV-0005Aj-Ie; Wed, 18 Sep 2024 17:07:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tU-000564-Bw for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:24 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tR-0001dG-FT for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:24 -0400 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a7a843bef98so11691266b.2 for ; Wed, 18 Sep 2024 14:07:21 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a906109637esm634344566b.40.2024.09.18.14.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:16 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 248AD5F938; Wed, 18 Sep 2024 22:07:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693640; x=1727298440; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hb8yLghAtC/pu08FHFoyfQSeSGmKFv1fHdJy4n4nII4=; b=Oi0bvtzOzvTMf544NctOgWJkS3PyEYzv1q2iol4BZsOUGLPfsR4vRJ5MOfUcw99QkB LXfVwOtMM5fDuU0SZN4D95iua8XMcC/iGxUmr5lHHGokcWSKi8qye5SSDjtfC6WlIGPf VQtq646jTzbSTA1MIP7ahyLa9qfnKMm8hNr/EAMxvYkKFiKSrbQD5GbrFnDiG8dt0a0U 10Q6K3FWES/PzUyFVs3fOafAu6r16KX++xl5ruxYfoemgweKhUdg0qHaYWFDVS8C8gPC e7TJbpyBViAGPY+3t08KFUiGFyW+54Zjc2FXn4vENtzLBOWcv+SN6zx/Wfr+mNXVDrC5 c+xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693640; x=1727298440; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hb8yLghAtC/pu08FHFoyfQSeSGmKFv1fHdJy4n4nII4=; b=VJkSEoIgVt4aM6XXz7SJ4lIEVXsNfnxVGrMJsxDQHaoaKqsufu7qubIvQZxyQmtrP3 y0syvHGhGXpXF/5RMeM8S/4JKBuh2vWSB0KBZUZnatoAAzbv0j5YhiPDvFB9mAsf39fp F8WENFA33IVF4dWF8rNE+690famR9+pFKxnYIOzGQaor24QEAUeTB1q7er7CihyK1aui qvD4PiUcEZKmsPI8szDrGrnZs3z0kcm+y560IGGTb1S8OhKcp6zM3ZcjYATexRFJbfCX GnszhOTFfsPTZy9A/SbKIMWgLSFu/kRst4OBhv/Jg8UXi51GZtLSKouQu/4X3Xu4ExjB vFCg== X-Gm-Message-State: AOJu0YzPDmGGiAwbIl+3AGqxHctB0f2k4+Ue5wKA0s7fy2szYUViSLNR fjkx3XJaTIlN6vkbxQMbljL44KOtOKqhViY+Vr9xiiRa1Ia5rN21oUefDqGG4jY= X-Google-Smtp-Source: AGHT+IGodNdGE/ZsN22HxPAwfzNvhaNcpVNX7bytMQazkZV1LcesfjB2TBVpI3Et3hDzSLxeFPxlOQ== X-Received: by 2002:a17:906:f5a9:b0:a8d:51a7:d5ec with SMTP id a640c23a62f3a-a9047b4af68mr1928413366b.13.1726693639854; Wed, 18 Sep 2024 14:07:19 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Xingtao Yao , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson , Nicholas Piggin , Daniel Henrique Barboza , qemu-ppc@nongnu.org (open list:PowerPC TCG CPUs) Subject: [PULL 09/18] tests/tcg/multiarch: add test for plugin memory access Date: Wed, 18 Sep 2024 22:07:03 +0100 Message-Id: <20240918210712.2336854-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::636; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693889126116600 From: Pierrick Bouvier Add an explicit test to check expected memory values are read/written. 8,16,32 load/store are tested for all arch. 64,128 load/store are tested for aarch64/x64. atomic operations (8,16,32,64) are tested for x64 only. By default, atomic accesses are non atomic if a single cpu is running, so we force creation of a second one by creating a new thread first. load/store helpers code path can't be triggered easily in user mode (no softmmu), so we can't test it here. Output of test-plugin-mem-access.c is the list of expected patterns in plugin output. By reading stdout, we can compare to plugins output and have a multiarch test. Can be run with: make -C build/tests/tcg/$ARCH-linux-user run-plugin-test-plugin-mem-access-= with-libmem.so Tested-by: Xingtao Yao Signed-off-by: Pierrick Bouvier Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240910172033.1427812-7-pierrick.bouvier@linaro.org> Message-Id: <20240916085400.1046925-10-alex.bennee@linaro.org> diff --git a/tests/tcg/multiarch/test-plugin-mem-access.c b/tests/tcg/multi= arch/test-plugin-mem-access.c new file mode 100644 index 0000000000..057b9aac9f --- /dev/null +++ b/tests/tcg/multiarch/test-plugin-mem-access.c @@ -0,0 +1,177 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * Check if we detect all memory accesses expected using plugin API. + * Used in conjunction with ./check-plugin-mem-access.sh check script. + * Output of this program is the list of patterns expected in plugin outpu= t. + * + * 8,16,32 load/store are tested for all arch. + * 64,128 load/store are tested for aarch64/x64. + * atomic operations (8,16,32,64) are tested for x64 only. + */ + +#include +#include +#include +#include + +#if defined(__x86_64__) +#include +#elif defined(__aarch64__) +#include +#endif /* __x86_64__ */ + +static void *data; + +/* ,store_u8,.*,8,store,0xf1 */ +#define PRINT_EXPECTED(function, type, value, action) \ +do { \ + printf(",%s,.*,%d,%s,%s\n", \ + #function, (int) sizeof(type) * 8, action, value); \ +} \ +while (0) + +#define DEFINE_STORE(name, type, value) \ + \ +static void print_expected_store_##name(void) \ +{ \ + PRINT_EXPECTED(store_##name, type, #value, "store"); \ +} \ + \ +static void store_##name(void) \ +{ \ + *((type *)data) =3D value; \ + print_expected_store_##name(); \ +} + +#define DEFINE_ATOMIC_OP(name, type, value) \ + \ +static void print_expected_atomic_op_##name(void) \ +{ \ + PRINT_EXPECTED(atomic_op_##name, type, "0x0*42", "load"); \ + PRINT_EXPECTED(atomic_op_##name, type, #value, "store"); \ +} \ + \ +static void atomic_op_##name(void) \ +{ \ + *((type *)data) =3D 0x42; \ + __sync_val_compare_and_swap((type *)data, 0x42, value); \ + print_expected_atomic_op_##name(); \ +} + +#define DEFINE_LOAD(name, type, value) \ + \ +static void print_expected_load_##name(void) \ +{ \ + PRINT_EXPECTED(load_##name, type, #value, "load"); \ +} \ + \ +static void load_##name(void) \ +{ \ + \ + /* volatile forces load to be generated. */ \ + volatile type src =3D *((type *) data); \ + volatile type dest =3D src; \ + (void)src, (void)dest; \ + print_expected_load_##name(); \ +} + +DEFINE_STORE(u8, uint8_t, 0xf1) +DEFINE_LOAD(u8, uint8_t, 0xf1) +DEFINE_STORE(u16, uint16_t, 0xf123) +DEFINE_LOAD(u16, uint16_t, 0xf123) +DEFINE_STORE(u32, uint32_t, 0xff112233) +DEFINE_LOAD(u32, uint32_t, 0xff112233) + +#if defined(__x86_64__) || defined(__aarch64__) +DEFINE_STORE(u64, uint64_t, 0xf123456789abcdef) +DEFINE_LOAD(u64, uint64_t, 0xf123456789abcdef) + +static void print_expected_store_u128(void) +{ + PRINT_EXPECTED(store_u128, __int128, + "0xf122334455667788f123456789abcdef", "store"); +} + +static void store_u128(void) +{ +#ifdef __x86_64__ + _mm_store_si128(data, _mm_set_epi32(0xf1223344, 0x55667788, + 0xf1234567, 0x89abcdef)); +#else + const uint32_t init[4] =3D {0x89abcdef, 0xf1234567, 0x55667788, 0xf122= 3344}; + uint32x4_t vec =3D vld1q_u32(init); + vst1q_u32(data, vec); +#endif /* __x86_64__ */ + print_expected_store_u128(); +} + +static void print_expected_load_u128(void) +{ + PRINT_EXPECTED(load_u128, __int128, + "0xf122334455667788f123456789abcdef", "load"); +} + +static void load_u128(void) +{ +#ifdef __x86_64__ + __m128i var =3D _mm_load_si128(data); +#else + uint32x4_t var =3D vld1q_u32(data); +#endif + (void) var; + print_expected_load_u128(); +} +#endif /* __x86_64__ || __aarch64__ */ + +#if defined(__x86_64__) +DEFINE_ATOMIC_OP(u8, uint8_t, 0xf1) +DEFINE_ATOMIC_OP(u16, uint16_t, 0xf123) +DEFINE_ATOMIC_OP(u32, uint32_t, 0xff112233) +DEFINE_ATOMIC_OP(u64, uint64_t, 0xf123456789abcdef) +#endif /* __x86_64__ */ + +static void *f(void *p) +{ + return NULL; +} + +int main(void) +{ + /* + * We force creation of a second thread to enable cpu flag CF_PARALLEL. + * This will generate atomic operations when needed. + */ + pthread_t thread; + pthread_create(&thread, NULL, &f, NULL); + pthread_join(thread, NULL); + + /* allocate storage up to 128 bits */ + data =3D malloc(16); + + store_u8(); + load_u8(); + + store_u16(); + load_u16(); + + store_u32(); + load_u32(); + +#if defined(__x86_64__) || defined(__aarch64__) + store_u64(); + load_u64(); + + store_u128(); + load_u128(); +#endif /* __x86_64__ || __aarch64__ */ + +#if defined(__x86_64__) + atomic_op_u8(); + atomic_op_u16(); + atomic_op_u32(); + atomic_op_u64(); +#endif /* __x86_64__ */ + + free(data); +} diff --git a/tests/tcg/alpha/Makefile.target b/tests/tcg/alpha/Makefile.tar= get index fdd7ddf64e..36d8ed1eae 100644 --- a/tests/tcg/alpha/Makefile.target +++ b/tests/tcg/alpha/Makefile.target @@ -12,4 +12,7 @@ test-cmov: EXTRA_CFLAGS=3D-DTEST_CMOV test-cmov: test-cond.c $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) =20 +# Force generation of byte read/write +test-plugin-mem-access: CFLAGS+=3D-mbwx + run-test-cmov: test-cmov diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Make= file.target index 5e3391ec9d..78b83d5575 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -170,5 +170,16 @@ run-plugin-semiconsole-with-%: TESTS +=3D semihosting semiconsole endif =20 +# Test plugin memory access instrumentation +run-plugin-test-plugin-mem-access-with-libmem.so: \ + PLUGIN_ARGS=3D$(COMMA)print-accesses=3Dtrue +run-plugin-test-plugin-mem-access-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=3D \ + $(SRC_PATH)/tests/tcg/multiarch/check-plugin-output.sh \ + $(QEMU) $< + +test-plugin-mem-access: CFLAGS+=3D-pthread -O0 +test-plugin-mem-access: LDFLAGS+=3D-pthread -O0 + # Update TESTS TESTS +=3D $(MULTIARCH_TESTS) diff --git a/tests/tcg/multiarch/check-plugin-output.sh b/tests/tcg/multiar= ch/check-plugin-output.sh new file mode 100755 index 0000000000..80607f04b5 --- /dev/null +++ b/tests/tcg/multiarch/check-plugin-output.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# This script runs a given executable using qemu, and compare its standard +# output with an expected plugin output. +# Each line of output is searched (as a regexp) in the expected plugin out= put. + +set -euo pipefail + +die() +{ + echo "$@" 1>&2 + exit 1 +} + +check() +{ + file=3D$1 + pattern=3D$2 + grep "$pattern" "$file" > /dev/null || die "\"$pattern\" not found in = $file" +} + +[ $# -eq 3 ] || die "usage: qemu_bin exe plugin_out_file" + +qemu_bin=3D$1; shift +exe=3D$1;shift +plugin_out=3D$1; shift + +expected() +{ + $qemu_bin $exe || + die "running $exe failed" +} + +expected | while read line; do + check "$plugin_out" "$line" +done diff --git a/tests/tcg/ppc64/Makefile.target b/tests/tcg/ppc64/Makefile.tar= get index 509a20be2b..1940886c73 100644 --- a/tests/tcg/ppc64/Makefile.target +++ b/tests/tcg/ppc64/Makefile.target @@ -55,4 +55,9 @@ PPC64_TESTS +=3D signal_save_restore_xer PPC64_TESTS +=3D xxspltw PPC64_TESTS +=3D test-aes =20 +# ppc64 ABI uses function descriptors, and thus, QEMU can't find symbol fo= r a +# given instruction. Thus, we don't check output of mem-access plugin. +run-plugin-test-plugin-mem-access-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=3D + TESTS +=3D $(PPC64_TESTS) --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693701; cv=none; d=zohomail.com; s=zohoarc; b=MgsCoEbA9egV948aAGLnOmCyQmByPgqM1XOeX76eQbf9tMnnK1BhHG2B2S2JCX0YyUSo2CSJoRObF3Giqo/cqkdk6bgJZQ9LJqF1zg92NkJEdpmj91IFG8WCjLJa5cyUc+A4JGmtaeGh9mYtliWYSCn+QRrj7KPxkRlomntrwCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693701; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iLLNzDuXO6l38mWtmOPS4GSPo9r5e2DeNF89YDm6xy8=; b=WsZLBpjuBou5B+n3F4RykZUJSSheFI4m16oFFapbVO0fvjc5IQ/xB0sehJn9AU9skpMB1ZOjqUXp16vTfMD0yDEMl9zufrkk2EHnG45wrnV1akZtlIodStdMoQSdMudeQHggttFxZw0riJrowl/3XW5dDlfqyp0stQPfJlS3VNo= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693701151177.75058535927462; Wed, 18 Sep 2024 14:08:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tU-00058O-W6; Wed, 18 Sep 2024 17:07:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tS-0004xL-Hi for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:22 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tQ-0001d0-Qb for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:22 -0400 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a8d6ac24a3bso25856366b.1 for ; Wed, 18 Sep 2024 14:07:20 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612b99c3sm636282566b.127.2024.09.18.14.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:16 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 3BD1E5F947; Wed, 18 Sep 2024 22:07:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693639; x=1727298439; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iLLNzDuXO6l38mWtmOPS4GSPo9r5e2DeNF89YDm6xy8=; b=mK4YNyQQgoZdgOSXfBNOOzCpweP/n1CNjzsgjBubO/D5VBib13+Zna6M/1GoJvaabv gayqH2H+YlZhh0yETAfYaLl0Mkx79GTVbDtyR/nk+qRS7S+gzZpz9KycZTw8QO8f/TK1 LA9iAYy78sQgLprK17Q9eXTLmXxvJdMN0h2qSfac49vXJEWRhBKLMe0VWoGWWXTf7xE4 bBPTWUizC9feYNcsP3rWUNNLpMh/o4GKr3+rWHTMidS+nvBSWnldcaStxDvGpz4b5qIa zZzaBhAAAKgbCI3VIzfSwnHxah2q78rJB5tGHKB7U3BKspgUGaWmGjcT7dzktdOxkdmp y2FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693639; x=1727298439; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iLLNzDuXO6l38mWtmOPS4GSPo9r5e2DeNF89YDm6xy8=; b=QCdc6T33qumaQl6OS/EWIPGCodU6H2C+3hMo2zGnBTVBxKzp8XtQt01E7b4Cm8Lg1X 6tsNY6zGzik/y5721aei+ZGzqxTGbwXX1Ye6BU4sTfEhy+Sk/0gtiegzD9CUuw79wuI2 1+y5ed7f93CYWapet5vTihTdgqjQVCyTFVsL1ohd75QLqr24U1M9na7cmDDk8h8tqQVz QJwVsqPFEzELQt58Ji5rm1w5Zqpx6BFGJTb4eqg/41LIVOHmeUbWWUdRraFTwrGeHzPm vVHPn2YVRXh/+kTwXDAvPs1eXlRgWtf3zfzvLNRkzDJlZcspNX7LEOdDct9TXXmyIn2k YoLg== X-Gm-Message-State: AOJu0Yyz14HYBZvLthC85dS2r4TMHTP8JdbD9ZO2m8jbB8AJJXYbASeQ 5cbdiRiaCRwe1NksbiKG7qbNkkejnPqt2VuN0C8iLWPY2oMj4WbhEhw28aO4Xr4= X-Google-Smtp-Source: AGHT+IG05uFpzjIxHINLNtbWTYHY8K7udQNhDV0atz3u24AxboKq09Pp3MVKKur2QIMNUuq4akL9gA== X-Received: by 2002:a17:907:3f88:b0:a6f:996f:23ea with SMTP id a640c23a62f3a-a90c1ce8ea1mr83755966b.15.1726693639225; Wed, 18 Sep 2024 14:07:19 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier Subject: [PULL 10/18] tests/tcg: clean up output of memory system test Date: Wed, 18 Sep 2024 22:07:04 +0100 Message-Id: <20240918210712.2336854-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::635; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693702233116600 This is useful information when debugging memory issues so lets improve by: - include the ptr address for u8 fills (like the others) - indicate the number of operations for reads and writes - explicitly note when we are flushing - move the fill printf to after the reset Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-11-alex.bennee@linaro.org> diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/syst= em/memory.c index 6eb2eb16f7..8f2371975d 100644 --- a/tests/tcg/multiarch/system/memory.c +++ b/tests/tcg/multiarch/system/memory.c @@ -63,12 +63,14 @@ static void init_test_data_u8(int unused_offset) int i; (void)(unused_offset); =20 - ml_printf("Filling test area with u8:"); + ml_printf("Filling test area with u8 (%p):", ptr); + for (i =3D 0; i < TEST_SIZE; i++) { *ptr++ =3D BYTE_NEXT(count); pdot(i); } - ml_printf("done\n"); + + ml_printf("done %d @ %p\n", i, ptr); } =20 /* @@ -94,7 +96,7 @@ static void init_test_data_s8(bool neg_first) *ptr++ =3D get_byte(i, !neg_first); pdot(i); } - ml_printf("done\n"); + ml_printf("done %d @ %p\n", i * 2, ptr); } =20 /* @@ -105,9 +107,18 @@ static void reset_start_data(int offset) { uint32_t *ptr =3D (uint32_t *) &test_data[0]; int i; + + if (!offset) { + return; + } + + ml_printf("Flushing %d bytes from %p: ", offset, ptr); + for (i =3D 0; i < offset; i++) { *ptr++ =3D 0; } + + ml_printf("done %d @ %p\n", i, ptr); } =20 static void init_test_data_u16(int offset) @@ -117,17 +128,17 @@ static void init_test_data_u16(int offset) const int max =3D (TEST_SIZE - offset) / sizeof(word); int i; =20 - ml_printf("Filling test area with u16 (offset %d, %p):", offset, ptr); - reset_start_data(offset); =20 + ml_printf("Filling test area with u16 (offset %d, %p):", offset, ptr); + for (i =3D 0; i < max; i++) { uint16_t low =3D BYTE_NEXT(count), high =3D BYTE_NEXT(count); word =3D BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0); *ptr++ =3D word; pdot(i); } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); } =20 static void init_test_data_u32(int offset) @@ -137,10 +148,10 @@ static void init_test_data_u32(int offset) const int max =3D (TEST_SIZE - offset) / sizeof(word); int i; =20 - ml_printf("Filling test area with u32 (offset %d, %p):", offset, ptr); - reset_start_data(offset); =20 + ml_printf("Filling test area with u32 (offset %d, %p):", offset, ptr); + for (i =3D 0; i < max; i++) { uint32_t b4 =3D BYTE_NEXT(count), b3 =3D BYTE_NEXT(count); uint32_t b2 =3D BYTE_NEXT(count), b1 =3D BYTE_NEXT(count); @@ -149,7 +160,7 @@ static void init_test_data_u32(int offset) *ptr++ =3D word; pdot(i); } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); } =20 static void init_test_data_u64(int offset) @@ -159,10 +170,10 @@ static void init_test_data_u64(int offset) const int max =3D (TEST_SIZE - offset) / sizeof(word); int i; =20 - ml_printf("Filling test area with u64 (offset %d, %p):", offset, ptr); - reset_start_data(offset); =20 + ml_printf("Filling test area with u64 (offset %d, %p):", offset, ptr); + for (i =3D 0; i < max; i++) { uint64_t b8 =3D BYTE_NEXT(count), b7 =3D BYTE_NEXT(count); uint64_t b6 =3D BYTE_NEXT(count), b5 =3D BYTE_NEXT(count); @@ -174,7 +185,7 @@ static void init_test_data_u64(int offset) *ptr++ =3D word; pdot(i); } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); } =20 static bool read_test_data_u16(int offset) @@ -198,7 +209,7 @@ static bool read_test_data_u16(int offset) } =20 } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } =20 @@ -239,7 +250,7 @@ static bool read_test_data_u32(int offset) pdot(i); } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } =20 @@ -293,7 +304,7 @@ static bool read_test_data_u64(int offset) pdot(i); } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } =20 @@ -365,7 +376,7 @@ static bool read_test_data_s8(int offset, bool neg_firs= t) return false; } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i * 2, ptr); return true; } =20 @@ -398,7 +409,7 @@ static bool read_test_data_s16(int offset, bool neg_fir= st) return false; } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } =20 @@ -431,7 +442,7 @@ static bool read_test_data_s32(int offset, bool neg_fir= st) return false; } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } =20 --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693654; cv=none; d=zohomail.com; s=zohoarc; b=fFYyCqR6PnCV5GQaAaXI66Kji6zCUHfDglChsekqKC+HAb1pxV5TQkaCFjjjTQT9r5zt48qeIVSEY+4dBtN5nKtdbGOLAqxyuMiIyliOynVwMv8BWySSmXQmfrGyhzpZqbGx+iYfrB+dhbPdb0dAZnZ5FUh20viwRShWxwEr1Oc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693654; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0gcAPVufwlARI8k9tEcW8Q+w96+wb8gfpJ78TxPW758=; b=KLRE2HuE9eisq2cSSg2EWBCcdKMdIy9Km2w2O1C2+AX9cOr2v4lYpv1r11exJn9+S7j8+JEVgxl1piaaMiosRwmfJX0/azevixc2Dd67itQtjwFA5eUo0JxtMWfDZi95Ic5NcqGSxaKY1cWBSsB6pDtL5nlk80GEIswrZVxmWAg= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693654934233.55337515031613; Wed, 18 Sep 2024 14:07:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tW-0005Fn-RR; Wed, 18 Sep 2024 17:07:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tV-0005AU-Ew for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:25 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tT-0001ds-Rx for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:25 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a8a7cdfdd80so14217166b.0 for ; Wed, 18 Sep 2024 14:07:23 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9060f39a8fsm636426366b.0.2024.09.18.14.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:16 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 510BF5F94D; Wed, 18 Sep 2024 22:07:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693642; x=1727298442; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0gcAPVufwlARI8k9tEcW8Q+w96+wb8gfpJ78TxPW758=; b=A8EXm7xev3SU5LCSyM53jaU6iAQ54gAk+wpy1jNf5qzJLtogzkVaF2ZiBHMXBb6P9x TvMKKLp7gakCmYXR2bYBPcAwF4gemIedMMIFiOl0C/V2mhPvfKBv+EvpqzuT3Dojpk8d dEzaQt+ndpe9bhLdeJUJazW4G83igfPtO7nGtVH6m20I4R53R/hG6cUK9odrhs9bWF1r IGnHfNrdC9Y8nGsqlyHjSu+eEDOp2Qn64xaW6Ose+KtarfAXckHSolYNHpNARAztX9Ej cAEoOpjx6Cjv3vHBqti3Z/rEN52pI2rhGKgQ7ZNMVdS8s60hBovqCqouWvUlcnxJKItQ FW6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693642; x=1727298442; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0gcAPVufwlARI8k9tEcW8Q+w96+wb8gfpJ78TxPW758=; b=wU0Jwlk+gMrRMXzUiAkuEELlg2ySqcfeoHKzFije1msAWCh+8am0RBKYzw0Xs/Mm1D 2bO/ZelIt1QcoLaXBqElkRaa52EoVaaJzElTx6bbkbUwAax4VMtriGV324TzZXYHh9Bd NxXT1/lcw8UDk2c4Vu7LKL4Wge29psAC3imrp8ACsXu51/0QiEPl+fZMKK31SQyStm+P pRxt4ARRcdNau0X5uiNYdLYKbXZZ0z90N7bgsjsbt5uJgtmmytOOg+gn7jtIltqUxSJC kBlBuIuuh3j077fVNQFxiOEEjdBnUxIcRsdfUTkdvvwQQbF3cwii629DhD5hE8RnbPh9 S9Jg== X-Gm-Message-State: AOJu0Yz1piezIiB4rs3oOkETGK5rnEPqWcbFtoR5uENiYKNYOv9B8iOI JpnFuP7L6z04WvJ0tMnWybsUKa3+zUK6ENAjcDJMWo2/BN65NzVpyyUvyB9Ub+4= X-Google-Smtp-Source: AGHT+IEB7cgYaHWQBvau9yo4rvoNzkL6GxQWhVCdbmPtKTx6c+sZMh6JomCoXZMKDlxnugYenp/C0w== X-Received: by 2002:a17:906:794a:b0:a8a:8c8e:f5e6 with SMTP id a640c23a62f3a-a9048108fe6mr2110191066b.49.1726693642099; Wed, 18 Sep 2024 14:07:22 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier Subject: [PULL 11/18] tests/tcg: only read/write 64 bit words on 64 bit systems Date: Wed, 18 Sep 2024 22:07:05 +0100 Message-Id: <20240918210712.2336854-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::62e; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-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.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693656002116600 While the compilers will generally happily synthesise a 64 bit value for you on 32 bit systems it doesn't exercise anything on QEMU. It also makes it hard to accurately compare the accesses to test_data when instrumenting. Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-12-alex.bennee@linaro.org> diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/syst= em/memory.c index 8f2371975d..28080767b2 100644 --- a/tests/tcg/multiarch/system/memory.c +++ b/tests/tcg/multiarch/system/memory.c @@ -163,6 +163,7 @@ static void init_test_data_u32(int offset) ml_printf("done %d @ %p\n", i, ptr); } =20 +#if __SIZEOF_POINTER__ >=3D 8 static void init_test_data_u64(int offset) { uint8_t count =3D 0; @@ -187,6 +188,7 @@ static void init_test_data_u64(int offset) } ml_printf("done %d @ %p\n", i, ptr); } +#endif =20 static bool read_test_data_u16(int offset) { @@ -254,6 +256,7 @@ static bool read_test_data_u32(int offset) return true; } =20 +#if __SIZEOF_POINTER__ >=3D 8 static bool read_test_data_u64(int offset) { uint64_t word, *ptr =3D (uint64_t *)&test_data[offset]; @@ -307,11 +310,16 @@ static bool read_test_data_u64(int offset) ml_printf("done %d @ %p\n", i, ptr); return true; } +#endif =20 /* Read the test data and verify at various offsets */ -read_ufn read_ufns[] =3D { read_test_data_u16, - read_test_data_u32, - read_test_data_u64 }; +read_ufn read_ufns[] =3D { + read_test_data_u16, + read_test_data_u32, +#if __SIZEOF_POINTER__ >=3D 8 + read_test_data_u64 +#endif +}; =20 bool do_unsigned_reads(int start_off) { @@ -476,10 +484,14 @@ bool do_signed_reads(bool neg_first) return ok; } =20 -init_ufn init_ufns[] =3D { init_test_data_u8, - init_test_data_u16, - init_test_data_u32, - init_test_data_u64 }; +init_ufn init_ufns[] =3D { + init_test_data_u8, + init_test_data_u16, + init_test_data_u32, +#if __SIZEOF_POINTER__ >=3D 8 + init_test_data_u64 +#endif +}; =20 int main(void) { --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693892; cv=none; d=zohomail.com; s=zohoarc; b=fj7Cg+6aIiNevXz0GQB/wzBcyMukOx8T95jOR/lyOew8j/i5Qh2q0EJFKtj1iqm8EN/P1ZLPg3Pc9MBxR3QHOdOvZ8IFhB1gM718fWtEmRhMrlENSv0Tn3CBVB9rLGtHd+cNZU9a2mSCbzqGB5ljL2VF2gMI0Q4vKrHvQhpkwWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693892; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UmSUHnclueWy8Ml22HesraUXC/kTCDRkeEOTmo3FB50=; b=cjN3FX9Vdyf+xMEzPi1MLzT6GWrxNZFDJoNyZIF4rrAAhPRNesnnhdUP10qi0vC6So6KCVp3N4sAUTrO/zf+aOoLQZ7v9gAUnVFz9zSAU1gentP/el5ovHbP624Smla/1WgscphaBs65yhsULgSgpK/gip1LkqZJ9ADOZjkMA5o= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17266938929221.8775605163882574; Wed, 18 Sep 2024 14:11:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tV-0005CG-W9; Wed, 18 Sep 2024 17:07:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tU-00054P-1q for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:24 -0400 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tS-0001da-Cg for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:23 -0400 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5c255e3c327so183596a12.1 for ; Wed, 18 Sep 2024 14:07:22 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90c39cbceesm19101966b.132.2024.09.18.14.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:16 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 66C115F952; Wed, 18 Sep 2024 22:07:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693641; x=1727298441; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UmSUHnclueWy8Ml22HesraUXC/kTCDRkeEOTmo3FB50=; b=U0a7lhO+52zXIJIdSaS74PFsbu2v/3DDiloB666ehZ9zvlAsvjPOle/oLcWh/cJfDe uz8Ta4Yv1yYUfoSwuES/lcevGsYAz08nZ8d1spoVZooKCY93xi0ApPriaqoCx3JqR0uw mc8WfPJJH1AuGC1XvSYaj7FS1DVQ31mge8LxkUH8N+WOrPpZKK6g+Geng2DKCupJ83E1 fGjgTTwI0qNc+4FKYkDqUwSaGhiM2UNlwiGpBkwle8UoACqZHVe1bCdhTJyAzbk8fJwn q7zu0cuNt6kTJzAZd8604Fl7kH0UgwSXk8rAG6o1u+YaMmt7+kUkGt4LsIuU94UhTUCw QJ1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693641; x=1727298441; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UmSUHnclueWy8Ml22HesraUXC/kTCDRkeEOTmo3FB50=; b=wzLQQdP4GiB6JpJ6J4KJl5H8scNB6mDPixKzBmyJwyw4ytQyqG/EjNSbaJ+RDlRBDX AQ/J9/kIR9bu4S5YxiKCXlc9AZGUL+SyLJlq0bBgI91gnLOMaopSluCHgk/oDnEo7bN1 N+buOwukBTO3EY/Dv0wiE1EqezcFRl252pewBUVFd+kytbt/qKUpKo2BO0NsxUbARBeK Fr9B9mAMc+aJ/nNqpWPuUrIzm2WmUyX/O3bKY6+bV/xN9ltUrLdRhvNAVIEQUsakV11X ia3suCpGNXOOxamkvGGZkusUjQ4gtYtOW6rYk/P6J+qSq4vzwZcwk91gBdgHt4n9xzLy z+ow== X-Gm-Message-State: AOJu0Yw0dMKDArfOr69huLaqZk0nsXVcVvqRuXulgaI2rFpElCxHHjNT gbLwiIaI2souZ13X5WCx84P0hldxgt+PzBx4kTpxOzaWd1kbTDXWXCFSnIzHWkJ+I0Am8FwdOmj okmY= X-Google-Smtp-Source: AGHT+IHKglD4VZubdtombQ7TWRD5KD2sMQek+AkV3m+AYfVCtOIdqGgNUKBO0LaJJn1jGSDbBXRPMg== X-Received: by 2002:a17:907:1c11:b0:a7a:acae:3415 with SMTP id a640c23a62f3a-a90293dbffbmr2470346866b.10.1726693640783; Wed, 18 Sep 2024 14:07:20 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Ilya Leoshkevich , Thomas Huth , Richard Henderson , David Hildenbrand , qemu-s390x@nongnu.org (open list:S390 TCG CPUs) Subject: [PULL 12/18] tests/tcg: ensure s390x-softmmu output redirected Date: Wed, 18 Sep 2024 22:07:06 +0100 Message-Id: <20240918210712.2336854-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::52d; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52d.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.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693895020116600 The multiarch system tests output serial data which should be redirected to the "output" chardev rather than echoed to the console. Comment the use of EXTFLAGS variable while we are at it. Acked-by: Ilya Leoshkevich Reviewed-by: Thomas Huth Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-13-alex.bennee@linaro.org> diff --git a/tests/tcg/s390x/Makefile.softmmu-target b/tests/tcg/s390x/Make= file.softmmu-target index f60f94b090..be242ba8f1 100644 --- a/tests/tcg/s390x/Makefile.softmmu-target +++ b/tests/tcg/s390x/Makefile.softmmu-target @@ -1,6 +1,7 @@ S390X_SRC=3D$(SRC_PATH)/tests/tcg/s390x VPATH+=3D$(S390X_SRC) -QEMU_OPTS+=3D-action panic=3Dexit-failure -nographic $(EXTFLAGS) -kernel +# EXTFLAGS can be passed by the user, e.g. to override the --accel +QEMU_OPTS+=3D-action panic=3Dexit-failure -nographic -serial chardev:outpu= t $(EXTFLAGS) -kernel LINK_SCRIPT=3D$(S390X_SRC)/softmmu.ld CFLAGS+=3D-ggdb -O0 LDFLAGS=3D-nostdlib -static --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693872; cv=none; d=zohomail.com; s=zohoarc; b=YmK2AKMzSgoJm0f+A66ukvjTXlMfeSsYZ3+lCx9f53ED8ywi2EIXw1taydtEQ8y3XBCd9ceRZE2AZmAIa6kJTsEHeIZqLXBzIARqJ/+ARq1tQ1D9vBgUXgsaQYT7Bm9x/BNZSYPxiarsCY5vhTkQeyWonbasTXEjGUc++BkkEGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693872; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5KlXLWKKsuXZCMNQAjhT7RVnkOlSJNAfyDCRZsaBjZ4=; b=Oszf0H5eJ8m1xvLKqsJnhdVvUSkGvN87QD0JUeKyG8pvXgtbA1Jd2i2fWfU9imDpWrNOQeqvzJcWPHVDVCkSlhuCD2g37URDnzVoMnbIW7euQrOpJTtf3i3Z5Zn4tH2dGm3f1bJwMmgexuqm6+/mKRoDVppdjNUvVX1EBDBj9BU= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172669387291264.18515170696253; Wed, 18 Sep 2024 14:11:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tc-0005dD-9U; Wed, 18 Sep 2024 17:07:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1ta-0005XF-TL for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:30 -0400 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tX-0001ev-Hv for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:30 -0400 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5c42bda005eso219314a12.0 for ; Wed, 18 Sep 2024 14:07:27 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c42bb492a1sm5347298a12.8.2024.09.18.14.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:22 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 847015FC60; Wed, 18 Sep 2024 22:07:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693646; x=1727298446; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5KlXLWKKsuXZCMNQAjhT7RVnkOlSJNAfyDCRZsaBjZ4=; b=VgrEg0TVAgNAe6/eNxcSoPBGTex1+CwM0coff/yu8i+MVDozbd88Sfn6Jncelk++3y SQ/BYCttLHVeRsdwnEKsL5nEtxZKxCacNSU2JHDOwSa9l8Yiyfln5VBxB8FYw/wXPnVU Bip+KgBbXFMqWA/DWkreSM6LqBSpnWT8uxu+iGFieuELhwgZE4L/IpXFF98wEj85jmuP B1c+vk/ujoIAOGbHDCNa/2dN0n5Vdj05u7qa7sqO2r0DdIr1SLAjII1zCF+Ml2+3qZem fca3dQsskQYquf+waGmglqJpbtNEkx8m3nzuZsjrY565y1azC6iH4u8+YryDruNJtrF1 WXyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693646; x=1727298446; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5KlXLWKKsuXZCMNQAjhT7RVnkOlSJNAfyDCRZsaBjZ4=; b=YyOujG07WPTAYy3AQrszBCGP4tsa3ba72ZlCSTFz2PhhiOgX3ahiv4pDwXJD87FJjn F8oq8cU+8X0p4G4/ePfe3txewuR0MK9N1hiogqVbK35kpU6a5tMUFb0Rnw8x2F0tJ+Lu f/TOEePzPtll2ttdfr5fF4ByNa5kS5LLTeZk9oBuLaSzg9P8kcz60QNHzCtpoXt6RMz6 2/WXQLAWKMLn9c5AphH3YCPNWMzY12mOdqCdapxqpRE5hX1DOdsvqOj4RftrTw3rae9P rS7dd8al19apGIfq5etSyGWQzezcZtDzmce5pgOayrdaUhsn1JuYXeURF8DP8obWkR8m OCDw== X-Gm-Message-State: AOJu0YwcMk0twqGlI6rhbGr9fi6qE0sUFLVO73bdXC4yG8lcTqjXW7FA X7XUYpKylIJYTzbJRK+FwG0zihJOJ6qAUhSADpik2bGGvsLfWPT/Ys+wSedVvvw= X-Google-Smtp-Source: AGHT+IE6zIfETBeiJE+ocGnZWg/V0ih0uTqDuK4/siP4pD90Wr58IF1W5EpNyAOKDy/fJp3+XT07xA== X-Received: by 2002:a05:6402:5193:b0:5c2:7002:7cf8 with SMTP id 4fb4d7f45d1cf-5c413e1f43bmr18489470a12.17.1726693645809; Wed, 18 Sep 2024 14:07:25 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier , Richard Henderson , Alexandre Iooss , Mahmoud Mandour , David Hildenbrand , Ilya Leoshkevich , qemu-s390x@nongnu.org (open list:S390 TCG CPUs) Subject: [PULL 13/18] tests/tcg: add a system test to check memory instrumentation Date: Wed, 18 Sep 2024 22:07:07 +0100 Message-Id: <20240918210712.2336854-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::52e; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693875034116600 At first I thought I could compile the user-mode test for system mode however we already have a fairly comprehensive test case for system mode in "memory" so lets use that. As tracking every access will quickly build up with "print-access" we add a new mode to track groups of reads and writes to regions. Because the test_data is 16k aligned we can be sure all accesses to it are ones we can count. First we extend the test to report where the test_data region is. Then we expand the pdot() function to track the total number of reads and writes to the region. We have to add some addition pdot() calls to take into account multiple reads/writes in the test loops. Finally we add a python script to integrate the data from the plugin and the output of the test and validate they both agree on the total counts. As some boot codes clear the bss we also add a flag to add a regions worth of writes to the expected total. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Pierrick Bouvier Message-Id: <20240916085400.1046925-14-alex.bennee@linaro.org> diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/syst= em/memory.c index 28080767b2..65a6038a24 100644 --- a/tests/tcg/multiarch/system/memory.c +++ b/tests/tcg/multiarch/system/memory.c @@ -14,26 +14,35 @@ =20 #include #include +#include #include =20 #ifndef CHECK_UNALIGNED # error "Target does not specify CHECK_UNALIGNED" #endif =20 +uint32_t test_read_count; +uint32_t test_write_count; + #define MEM_PAGE_SIZE 4096 /* nominal 4k "pages" */ #define TEST_SIZE (MEM_PAGE_SIZE * 4) /* 4 pages */ =20 #define ARRAY_SIZE(x) ((sizeof(x) / sizeof((x)[0]))) =20 -__attribute__((aligned(MEM_PAGE_SIZE))) +__attribute__((aligned(TEST_SIZE))) static uint8_t test_data[TEST_SIZE]; =20 typedef void (*init_ufn) (int offset); typedef bool (*read_ufn) (int offset); typedef bool (*read_sfn) (int offset, bool nf); =20 -static void pdot(int count) +static void pdot(int count, bool write) { + if (write) { + test_write_count++; + } else { + test_read_count++; + } if (count % 128 =3D=3D 0) { ml_printf("."); } @@ -67,7 +76,7 @@ static void init_test_data_u8(int unused_offset) =20 for (i =3D 0; i < TEST_SIZE; i++) { *ptr++ =3D BYTE_NEXT(count); - pdot(i); + pdot(i, true); } =20 ml_printf("done %d @ %p\n", i, ptr); @@ -93,8 +102,9 @@ static void init_test_data_s8(bool neg_first) neg_first ? "neg first" : "pos first"); for (i =3D 0; i < TEST_SIZE / 2; i++) { *ptr++ =3D get_byte(i, neg_first); + pdot(i, true); *ptr++ =3D get_byte(i, !neg_first); - pdot(i); + pdot(i, true); } ml_printf("done %d @ %p\n", i * 2, ptr); } @@ -116,6 +126,7 @@ static void reset_start_data(int offset) =20 for (i =3D 0; i < offset; i++) { *ptr++ =3D 0; + pdot(i, true); } =20 ml_printf("done %d @ %p\n", i, ptr); @@ -136,7 +147,7 @@ static void init_test_data_u16(int offset) uint16_t low =3D BYTE_NEXT(count), high =3D BYTE_NEXT(count); word =3D BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0); *ptr++ =3D word; - pdot(i); + pdot(i, true); } ml_printf("done %d @ %p\n", i, ptr); } @@ -158,7 +169,7 @@ static void init_test_data_u32(int offset) word =3D BYTE_SHIFT(b1, 3) | BYTE_SHIFT(b2, 2) | BYTE_SHIFT(b3, 1)= | BYTE_SHIFT(b4, 0); *ptr++ =3D word; - pdot(i); + pdot(i, true); } ml_printf("done %d @ %p\n", i, ptr); } @@ -184,7 +195,7 @@ static void init_test_data_u64(int offset) BYTE_SHIFT(b4, 4) | BYTE_SHIFT(b5, 3) | BYTE_SHIFT(b6, 2) | BYTE_SHIFT(b7, 1) | BYTE_SHIFT(b8, 0); *ptr++ =3D word; - pdot(i); + pdot(i, true); } ml_printf("done %d @ %p\n", i, ptr); } @@ -207,7 +218,7 @@ static bool read_test_data_u16(int offset) ml_printf("Error %d < %d\n", high, low); return false; } else { - pdot(i); + pdot(i, false); } =20 } @@ -249,7 +260,7 @@ static bool read_test_data_u32(int offset) ml_printf("Error %d, %d, %d, %d", b1, b2, b3, b4); return false; } else { - pdot(i); + pdot(i, false); } } ml_printf("done %d @ %p\n", i, ptr); @@ -304,7 +315,7 @@ static bool read_test_data_u64(int offset) b1, b2, b3, b4, b5, b6, b7, b8); return false; } else { - pdot(i); + pdot(i, false); } } ml_printf("done %d @ %p\n", i, ptr); @@ -376,9 +387,11 @@ static bool read_test_data_s8(int offset, bool neg_fir= st) second =3D *ptr++; =20 if (neg_first && first < 0 && second > 0) { - pdot(i); + pdot(i, false); + pdot(i, false); } else if (!neg_first && first > 0 && second < 0) { - pdot(i); + pdot(i, false); + pdot(i, false); } else { ml_printf("Error %d %c %d\n", first, neg_first ? '<' : '>', se= cond); return false; @@ -409,9 +422,9 @@ static bool read_test_data_s16(int offset, bool neg_fir= st) int32_t data =3D *ptr++; =20 if (neg_first && data < 0) { - pdot(i); + pdot(i, false); } else if (!neg_first && data > 0) { - pdot(i); + pdot(i, false); } else { ml_printf("Error %d %c 0\n", data, neg_first ? '<' : '>'); return false; @@ -442,9 +455,9 @@ static bool read_test_data_s32(int offset, bool neg_fir= st) int64_t data =3D *ptr++; =20 if (neg_first && data < 0) { - pdot(i); + pdot(i, false); } else if (!neg_first && data > 0) { - pdot(i); + pdot(i, false); } else { ml_printf("Error %d %c 0\n", data, neg_first ? '<' : '>'); return false; @@ -498,6 +511,9 @@ int main(void) int i; bool ok =3D true; =20 + ml_printf("Test data start: 0x%"PRIxPTR"\n", &test_data[0]); + ml_printf("Test data end: 0x%"PRIxPTR"\n", &test_data[TEST_SIZE]); + /* Run through the unsigned tests first */ for (i =3D 0; i < ARRAY_SIZE(init_ufns) && ok; i++) { ok =3D do_unsigned_test(init_ufns[i]); @@ -513,6 +529,8 @@ int main(void) ok =3D do_signed_reads(true); } =20 + ml_printf("Test data read: %"PRId32"\n", test_read_count); + ml_printf("Test data write: %"PRId32"\n", test_write_count); ml_printf("Test complete: %s\n", ok ? "PASSED" : "FAILED"); return ok ? 0 : -1; } diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c index 086e6f5bdf..121210157f 100644 --- a/tests/tcg/plugins/mem.c +++ b/tests/tcg/plugins/mem.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include =20 @@ -26,13 +27,47 @@ typedef struct { const char *sym; } InsnInfo; =20 +/* + * For the "memory" system test we need to track accesses to + * individual regions. We mirror the data written to the region and + * then check when it is read that it matches up. + * + * We do this as regions rather than pages to save on complications + * with page crossing and the fact the test only cares about the + * test_data region. + */ +static uint64_t region_size =3D 4096 * 4; +static uint64_t region_mask; + +typedef struct { + uint64_t region_address; + uint64_t reads; + uint64_t writes; + uint8_t *data; + /* Did we see every write and read with correct values? */ + bool seen_all; +} RegionInfo; + static struct qemu_plugin_scoreboard *counts; static qemu_plugin_u64 mem_count; static qemu_plugin_u64 io_count; -static bool do_inline, do_callback, do_print_accesses; +static bool do_inline, do_callback, do_print_accesses, do_region_summary; static bool do_haddr; static enum qemu_plugin_mem_rw rw =3D QEMU_PLUGIN_MEM_RW; =20 + +static GMutex lock; +static GHashTable *regions; + +static gint addr_order(gconstpointer a, gconstpointer b) +{ + RegionInfo *na =3D (RegionInfo *) a; + RegionInfo *nb =3D (RegionInfo *) b; + + return na->region_address > nb->region_address ? 1 : -1; +} + + static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) out =3D g_string_new(""); @@ -46,9 +81,133 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) qemu_plugin_u64_sum(io_count)); } qemu_plugin_outs(out->str); + + + if (do_region_summary) { + GList *counts =3D g_hash_table_get_values(regions); + + counts =3D g_list_sort(counts, addr_order); + + g_string_printf(out, "Region Base, Reads, Writes, Seen all\n"); + + if (counts && g_list_next(counts)) { + for (/* counts */; counts; counts =3D counts->next) { + RegionInfo *ri =3D (RegionInfo *) counts->data; + + g_string_append_printf(out, + "0x%016"PRIx64", " + "%"PRId64", %"PRId64", %s\n", + ri->region_address, + ri->reads, + ri->writes, + ri->seen_all ? "true" : "false"); + } + } + qemu_plugin_outs(out->str); + } + qemu_plugin_scoreboard_free(counts); } =20 +/* + * Update the region tracking info for the access. We split up accesses + * that span regions even though the plugin infrastructure will deliver + * it as a single access. + */ +static void update_region_info(uint64_t region, uint64_t offset, + qemu_plugin_meminfo_t meminfo, + qemu_plugin_mem_value value, + unsigned size) +{ + bool be =3D qemu_plugin_mem_is_big_endian(meminfo); + bool is_store =3D qemu_plugin_mem_is_store(meminfo); + RegionInfo *ri; + bool unseen_data =3D false; + + g_assert(offset + size <=3D region_size); + + g_mutex_lock(&lock); + ri =3D (RegionInfo *) g_hash_table_lookup(regions, GUINT_TO_POINTER(re= gion)); + + if (!ri) { + ri =3D g_new0(RegionInfo, 1); + ri->region_address =3D region; + ri->data =3D g_malloc0(region_size); + ri->seen_all =3D true; + g_hash_table_insert(regions, GUINT_TO_POINTER(region), (gpointer) = ri); + } + + if (is_store) { + ri->writes++; + } else { + ri->reads++; + } + + switch (value.type) { + case QEMU_PLUGIN_MEM_VALUE_U8: + if (is_store) { + ri->data[offset] =3D value.data.u8; + } else if (ri->data[offset] !=3D value.data.u8) { + unseen_data =3D true; + } + break; + case QEMU_PLUGIN_MEM_VALUE_U16: + { + uint16_t *p =3D (uint16_t *) &ri->data[offset]; + uint16_t val =3D be ? htobe16(value.data.u16) : htole16(value.data= .u16); + if (is_store) { + *p =3D val; + } else if (*p !=3D val) { + unseen_data =3D true; + } + break; + } + case QEMU_PLUGIN_MEM_VALUE_U32: + { + uint32_t *p =3D (uint32_t *) &ri->data[offset]; + uint32_t val =3D be ? htobe32(value.data.u32) : htole32(value.data= .u32); + if (is_store) { + *p =3D val; + } else if (*p !=3D val) { + unseen_data =3D true; + } + break; + } + case QEMU_PLUGIN_MEM_VALUE_U64: + { + uint64_t *p =3D (uint64_t *) &ri->data[offset]; + uint64_t val =3D be ? htobe64(value.data.u64) : htole64(value.data= .u64); + if (is_store) { + *p =3D val; + } else if (*p !=3D val) { + unseen_data =3D true; + } + break; + } + case QEMU_PLUGIN_MEM_VALUE_U128: + /* non in test so skip */ + break; + default: + g_assert_not_reached(); + } + + /* + * This is expected for regions initialised by QEMU (.text etc) but we + * expect to see all data read and written to the test_data region + * of the memory test. + */ + if (unseen_data && ri->seen_all) { + g_autoptr(GString) error =3D g_string_new("Warning: "); + g_string_append_printf(error, "0x%016"PRIx64":%"PRId64 + " read an un-instrumented value\n", + region, offset); + qemu_plugin_outs(error->str); + ri->seen_all =3D false; + } + + g_mutex_unlock(&lock); +} + static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, uint64_t vaddr, void *udata) { @@ -63,6 +222,15 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugi= n_meminfo_t meminfo, } else { qemu_plugin_u64_add(mem_count, cpu_index, 1); } + + if (do_region_summary) { + uint64_t region =3D vaddr & ~region_mask; + uint64_t offset =3D vaddr & region_mask; + qemu_plugin_mem_value value =3D qemu_plugin_mem_get_value(meminfo); + unsigned size =3D 1 << qemu_plugin_mem_size_shift(meminfo); + + update_region_info(region, offset, meminfo, value, size); + } } =20 static void print_access(unsigned int cpu_index, qemu_plugin_meminfo_t mem= info, @@ -117,7 +285,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct q= emu_plugin_tb *tb) QEMU_PLUGIN_INLINE_ADD_U64, mem_count, 1); } - if (do_callback) { + if (do_callback || do_region_summary) { qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem, QEMU_PLUGIN_CB_NO_REGS, rw, NULL); @@ -176,6 +344,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); return -1; } + } else if (g_strcmp0(tokens[0], "region-summary") =3D=3D 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &do_region_summary)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); + return -1; + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; @@ -196,6 +370,11 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, qemu_plugin_outs(out->str); } =20 + if (do_region_summary) { + region_mask =3D (region_size - 1); + regions =3D g_hash_table_new(NULL, g_direct_equal); + } + counts =3D qemu_plugin_scoreboard_new(sizeof(CPUCount)); mem_count =3D qemu_plugin_scoreboard_u64_in_struct( counts, CPUCount, mem_count); diff --git a/tests/tcg/alpha/Makefile.softmmu-target b/tests/tcg/alpha/Make= file.softmmu-target index a0eca4d6ea..a944102a3c 100644 --- a/tests/tcg/alpha/Makefile.softmmu-target +++ b/tests/tcg/alpha/Makefile.softmmu-target @@ -28,7 +28,7 @@ LDFLAGS+=3D-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) = -lgcc %: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS) $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) =20 -memory: CFLAGS+=3D-DCHECK_UNALIGNED=3D0 +memory: CFLAGS+=3D-DCHECK_UNALIGNED=3D0 -mbwx =20 # Running QEMU_OPTS+=3D-serial chardev:output -kernel diff --git a/tests/tcg/multiarch/system/Makefile.softmmu-target b/tests/tcg= /multiarch/system/Makefile.softmmu-target index 32dc0f9830..07be001102 100644 --- a/tests/tcg/multiarch/system/Makefile.softmmu-target +++ b/tests/tcg/multiarch/system/Makefile.softmmu-target @@ -65,3 +65,9 @@ endif =20 MULTIARCH_RUNS +=3D run-gdbstub-memory run-gdbstub-interrupt \ run-gdbstub-untimely-packet run-gdbstub-registers + +# Test plugin memory access instrumentation +run-plugin-memory-with-libmem.so: \ + PLUGIN_ARGS=3D$(COMMA)region-summary=3Dtrue +run-plugin-memory-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=3D$(MULTIARCH_SYSTEM_SRC)/validate-memory-cou= nts.py $@.out diff --git a/tests/tcg/multiarch/system/validate-memory-counts.py b/tests/t= cg/multiarch/system/validate-memory-counts.py new file mode 100755 index 0000000000..5b8bbf3ef3 --- /dev/null +++ b/tests/tcg/multiarch/system/validate-memory-counts.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +# +# validate-memory-counts.py: check we instrumented memory properly +# +# This program takes two inputs: +# - the mem plugin output +# - the memory binary output +# +# Copyright (C) 2024 Linaro Ltd +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import sys +from argparse import ArgumentParser + +def extract_counts(path): + """ + Load the output from path and extract the lines containing: + + Test data start: 0x40214000 + Test data end: 0x40218001 + Test data read: 2522280 + Test data write: 262111 + + From the stream of data. Extract the values for use in the + validation function. + """ + start_address =3D None + end_address =3D None + read_count =3D 0 + write_count =3D 0 + with open(path, 'r') as f: + for line in f: + if line.startswith("Test data start:"): + start_address =3D int(line.split(':')[1].strip(), 16) + elif line.startswith("Test data end:"): + end_address =3D int(line.split(':')[1].strip(), 16) + elif line.startswith("Test data read:"): + read_count =3D int(line.split(':')[1].strip()) + elif line.startswith("Test data write:"): + write_count =3D int(line.split(':')[1].strip()) + return start_address, end_address, read_count, write_count + + +def parse_plugin_output(path, start, end): + """ + Load the plugin output from path in the form of: + + Region Base, Reads, Writes, Seen all + 0x0000000040004000, 31093, 0, false + 0x0000000040214000, 2522280, 278579, true + 0x0000000040000000, 137398, 0, false + 0x0000000040210000, 54727397, 33721956, false + + And extract the ranges that match test data start and end and + return the results. + """ + total_reads =3D 0 + total_writes =3D 0 + seen_all =3D False + + with open(path, 'r') as f: + next(f) # Skip the header + for line in f: + + if line.startswith("Region Base"): + continue + + parts =3D line.strip().split(', ') + if len(parts) !=3D 4: + continue + + region_base =3D int(parts[0], 16) + reads =3D int(parts[1]) + writes =3D int(parts[2]) + + if start <=3D region_base < end: # Checking if within range + total_reads +=3D reads + total_writes +=3D writes + seen_all =3D parts[3] =3D=3D "true" + + return total_reads, total_writes, seen_all + +def main() -> None: + """ + Process the arguments, injest the program and plugin out and + verify they match up and report if they do not. + """ + parser =3D ArgumentParser(description=3D"Validate memory instrumentati= on") + parser.add_argument('test_output', + help=3D"The output from the test itself") + parser.add_argument('plugin_output', + help=3D"The output from memory plugin") + parser.add_argument('--bss-cleared', + action=3D'store_true', + help=3D'Assume bss was cleared (and adjusts counts= ).') + + args =3D parser.parse_args() + + # Extract counts from memory binary + start, end, exp_reads, exp_writes =3D extract_counts(args.test_output) + + # Some targets clear BSS before running but the test doesn't know + # that so we adjust it by the size of the test region. + if args.bss_cleared: + exp_writes +=3D 16384 + + if start is None or end is None: + print("Failed to test_data boundaries from output.") + sys.exit(1) + + # Parse plugin output + preads, pwrites, seen_all =3D parse_plugin_output(args.plugin_output, + start, end) + + if not seen_all: + print("Fail: didn't instrument all accesses to test_data.") + sys.exit(1) + + # Compare and report + if preads =3D=3D exp_reads and pwrites =3D=3D exp_writes: + sys.exit(0) + else: + print("Fail: The memory reads and writes count does not match.") + print(f"Expected Reads: {exp_reads}, Actual Reads: {preads}") + print(f"Expected Writes: {exp_writes}, Actual Writes: {pwrites}") + sys.exit(1) + +if __name__ =3D=3D "__main__": + main() diff --git a/tests/tcg/s390x/Makefile.softmmu-target b/tests/tcg/s390x/Make= file.softmmu-target index be242ba8f1..3227903348 100644 --- a/tests/tcg/s390x/Makefile.softmmu-target +++ b/tests/tcg/s390x/Makefile.softmmu-target @@ -47,3 +47,8 @@ $(MULTIARCH_TESTS): $(S390X_MULTIARCH_RUNTIME_OBJS) $(MULTIARCH_TESTS): LDFLAGS +=3D $(S390X_MULTIARCH_RUNTIME_OBJS) $(MULTIARCH_TESTS): CFLAGS +=3D $(MINILIB_INC) memory: CFLAGS +=3D -DCHECK_UNALIGNED=3D0 + +# s390x clears the BSS section so we need to account for that +run-plugin-memory-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=3D$(MULTIARCH_SYSTEM_SRC)/validate-memory-cou= nts.py \ + --bss-cleared $@.out --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726694022; cv=none; d=zohomail.com; s=zohoarc; b=Pl3/hDNw2da2AOsLgNLPWMUgFqeTk1J/zpmvfmT3qdjobvysK62YYe9YByI0QqVaG2KjxnS5WQTDLhKOhVOVrUInnEtvaVa6bUhV6m/TVCA30SkXK7rXTKI8yaiuI6at19nHxsyRoX34hZfPghzeh6tQOAe6ooyrFYq0a42JyRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726694022; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=njwup9bdkkn3Pmq6MgNZmWDd6Jmwa84hQ2yWGTmpHoI=; b=EBvp010plT8fMCt1Ij5gWf7PVYA8GZ3V3ojmbxKcEtrihqMj/ADU3ItIZGlGILUXVeOn+zhRiVoHIzgLQU+2VZbVwBWN8zhCcbmkCYigtYmL2Uk9tdAMa6ZUrRCFZ6Wh0Bpu6C5XTHOWLsn222+Yii+o7x8MRez6GMZ+4VoGwec= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726694022919275.762855221344; Wed, 18 Sep 2024 14:13:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1zU-0007vU-UF; Wed, 18 Sep 2024 17:13:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1zS-0007gg-5j for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:13:34 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1zQ-0002Di-IB for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:13:33 -0400 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a8d6ac24a3bso26731566b.1 for ; Wed, 18 Sep 2024 14:13:31 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612e4b87sm644766366b.179.2024.09.18.14.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:13:30 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 9A24B5F885; Wed, 18 Sep 2024 22:07:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726694011; x=1727298811; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=njwup9bdkkn3Pmq6MgNZmWDd6Jmwa84hQ2yWGTmpHoI=; b=aBe0ym9ZbcgL0aG11GJLg8PVCM4f10DVuaqrSi70cs5MkMyynY3j0ysWXwDD2ziBPP zObRCJPqoTzBwOGAPU0FnN9zia0cyBUmvB6ytRBH5f+XAN7Ke9UPpmKZA/u/RoQpetdc ekt9zgmEyEzT+DKiD+TwCWhrVlQRZlGNw/3VGtCloRqvoXxTS5+W/B+ML8TmDbE/CEYD vbaCD4G5rth1dw0uqfxRAp6Ex7rJ3vLBNeNPNToWbbJpXuJ5pFWQEkjB+x2Mvh/9BnWM 9nZu9gS5XnhOMZCHRmnlgZ3vHcg30bPjLtOBl1ltshhcniJmuebbLTEhmaIE49zWBTYg 8L3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726694011; x=1727298811; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=njwup9bdkkn3Pmq6MgNZmWDd6Jmwa84hQ2yWGTmpHoI=; b=nMw+JwmDJdxKUugjAqcU2N85N2srzUouWpml32GyGWhK26SIFexCmgjNmuttNKSQwB tSdmpQhzJVMH7WdGZ3jIiM1qUH8lpgZHlTA2bOAVzbeZoJSJjZNRwTsUyoLkFF+UcseP O+TWaZGOCvXMeFSoFJMDhqAHX0TFcSJIHJDPzxpvvxeKIYHt80Tvg/0y2HbU1Fxw2Lx+ 8C+fwLbV4m6GeD6huCdFU2pW42ZNNzAvLnsiH3WlMtSImiZU6HnR2729uNTmUBl9qmNc Z80RoOpaQmUqkLiz7CT7Pl+B3L1FiOhmhu949ijHA6iqIrm72/c72hqR5l/gKhtMrzN6 EiDA== X-Gm-Message-State: AOJu0Yx05fgQTeEAjhohrG/u4S2bUhcSB3cMVkdIWBmHq/98CRXeQ8zL BnDY1BLUFFKBwrAbulIpcVM2EKmArjH65iEV9MlW+G7uYuAFLIvu7Gm4aRg1DIU= X-Google-Smtp-Source: AGHT+IFgUaMh83XdHml1ayAdv3b2I/RAdmvJ5owbx0Rw75ng6AYmvaL1/iuXN7j7FHP3K5SiUTCaWw== X-Received: by 2002:a17:907:7288:b0:a8d:4c83:d85d with SMTP id a640c23a62f3a-a90c1c77fc6mr100022766b.12.1726694010605; Wed, 18 Sep 2024 14:13:30 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Elisha Hollander , Pierrick Bouvier , Paolo Bonzini Subject: [PULL 14/18] util/timer: avoid deadlock when shutting down Date: Wed, 18 Sep 2024 22:07:08 +0100 Message-Id: <20240918210712.2336854-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::62c; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-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.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726694023570116600 When we shut down a guest we disable the timers. However this can cause deadlock if the guest has queued some async work that is trying to advance system time and spins forever trying to wind time forward. Pay attention to the return code and bail early if we can't wind time forward. Reported-by: Elisha Hollander Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Pierrick Bouvier Message-Id: <20240916085400.1046925-15-alex.bennee@linaro.org> diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 213114be68..6b1533bc2a 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -685,10 +685,17 @@ int64_t qemu_clock_advance_virtual_time(int64_t dest) { int64_t clock =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); AioContext *aio_context; + int64_t deadline; + aio_context =3D qemu_get_aio_context(); - while (clock < dest) { - int64_t deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, + + deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, QEMU_TIMER_ATTR_ALL); + /* + * A deadline of < 0 indicates this timer is not enabled, so we + * won't get far trying to run it forward. + */ + while (deadline >=3D 0 && clock < dest) { int64_t warp =3D qemu_soonest_timeout(dest - clock, deadline); =20 qemu_virtual_clock_set_ns(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + = warp); @@ -696,6 +703,9 @@ int64_t qemu_clock_advance_virtual_time(int64_t dest) qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); timerlist_run_timers(aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL]); clock =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + + deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, + QEMU_TIMER_ATTR_ALL); } qemu_clock_notify(QEMU_CLOCK_VIRTUAL); =20 --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693706; cv=none; d=zohomail.com; s=zohoarc; b=T3L+jomhEThRM7Aq8ZIsLYcS2JKrN2s2b9dm2f+jvUuiFVbM9Ymm6OLiUobn/VugARqCeRACni+PFUYV5uzrbLeNVnnTcE70Xws4uVT6C1E9BwXVz68RIKUc3vcCGWV3jN4XPluvFXnN3VTJYk4gqxcQf1APlBv7fdJ+hhC/WOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693706; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PRgP2XxtmdYadkvbz2HyALpuQEGhfglAJrK8k/4Hb84=; b=U/nDv3oPKw8eJZYwmcEJAJabardxT1iEg8Pgpwc/4Xgnu8mEx5ocqys2r2ERJd4v5OKhi4Xxbipr/7BZveWh0jtcyDmac9VeM9qWnkHVYNRYUBuBLXS388r9GNAsFxGYcWEnxk0zNLDulFCLKhsyngRXI1CAUEn3MWsbdQRkhh0= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693706943946.9252072607491; Wed, 18 Sep 2024 14:08:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1ta-0005VJ-Fg; Wed, 18 Sep 2024 17:07:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tX-0005J7-Hu for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:27 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tV-0001eU-9u for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:27 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-374c1e5fe79so64009f8f.1 for ; Wed, 18 Sep 2024 14:07:24 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c42bb53620sm5375341a12.27.2024.09.18.14.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:22 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id B486E5FC6C; Wed, 18 Sep 2024 22:07:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693644; x=1727298444; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PRgP2XxtmdYadkvbz2HyALpuQEGhfglAJrK8k/4Hb84=; b=hhE8/8r8xIAJgPlo12dcQgAMIqhpH6gfSuo3mC8EUGi8bgB+RjsRtCa3X1gps9YNHF sGjdPtTAseEak7WL8vxSwrChGcITpe702p4au6wWCWdmDqJ6MuBb0hPQefGNHA/njlVd nEn27Nr9fFPriH6azuFzNdrkgf3Xc0ELturWpfmc/x7phi1d3hZ5weG/xIKfZIaocmfh wzDorodaKFAfc1/2eQPvcDwglo6+gysZrMv//JzP6OgDmupcKnYrqD+LSSVUTzkgeNUY PIwAXe2DADWkLqz1km0AgvXpm5gy3AHFplZkmKAj4KccuvbFgiBWswFA96lquBjJWBnJ Tzmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693644; x=1727298444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PRgP2XxtmdYadkvbz2HyALpuQEGhfglAJrK8k/4Hb84=; b=oSa7qoiEcSLCDy52UvYjpZbM4utYlmbrtURrgvzoIewuVt7l0APirxAaVQfEoKNMcJ ws1zMgnfC/uDyTEFj31QdJqDMEL72IaF835Hpt9vlZFVKItq55ey6ccYAcxaBDeEL/Ni Gch+8LkG5UZ3qO5ykWLd3q+yeYErnLaVVPmU6zVRqS/ou+tZ7Mf0QM2i7hUzY1+rqgs1 wh/yry4zxyTcg7P0fHOOCWv4VotDghuKAkK4fq+BriSf8Kh4IHccBoORvpqiHIuNW1Ox KMh9Vxaz8cCRMjLap3GXYR1Uo1sKF6gE3tBRA55HCLSeu3hYwVS3LQtaWMat0ZPnEKBS SekQ== X-Gm-Message-State: AOJu0YxwRfAIcFWI/Pm/fSOi3jNSKzmhhnFvW6Pj5GaV8+1piDTLb1Sn fzLDfvnypI6UdhkbZoUSDV04iuEKwbeBGw86HYWxbds3yDjyAaO3WJrFEo0+o2c= X-Google-Smtp-Source: AGHT+IFpB7H+l5vT5xQS2Ue1EVBOGDsULEMLnXaXci2HZa6mSOSLlYFcBbHmBiq5bm663HJPVybH4g== X-Received: by 2002:adf:ec07:0:b0:374:c61a:69b8 with SMTP id ffacd0b85a97d-378c2d058abmr13874725f8f.15.1726693643580; Wed, 18 Sep 2024 14:07:23 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Yotaro Nada , Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 15/18] contrib/plugins: Add a plugin to generate basic block vectors Date: Wed, 18 Sep 2024 22:07:09 +0100 Message-Id: <20240918210712.2336854-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::42f; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-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.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693708518116600 From: Akihiko Odaki SimPoint is a widely used tool to find the ideal microarchitecture simulation points so Valgrind[2] and Pin[3] support generating basic block vectors for use with them. Let's add a corresponding plugin to QEMU too. Note that this plugin has a different goal with tests/plugin/bb.c. This plugin creates a vector for each constant interval instead of counting the execution of basic blocks for the entire run and able to describe the change of execution behavior. Its output is also syntactically simple and better suited for parsing, while the output of tests/plugin/bb.c is more human-readable. [1] https://cseweb.ucsd.edu/~calder/simpoint/ [2] https://valgrind.org/docs/manual/bbv-manual.html [3] https://www.intel.com/content/www/us/en/developer/articles/tool/pin-a-d= ynamic-binary-instrumentation-tool.html Signed-off-by: Yotaro Nada Signed-off-by: Akihiko Odaki Reviewed-by: Pierrick Bouvier Message-Id: <20240816-bb-v3-1-b9aa4a5c75c5@daynix.com> Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-16-alex.bennee@linaro.org> diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index 05f54d3f27..ee59c2fa9b 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -268,6 +268,36 @@ Behaviour can be tweaked with the following arguments: * - idle=3Dtrue|false - Dump the current execution stats whenever the guest vCPU idles =20 +Basic Block Vectors +................... + +``contrib/plugins/bbv.c`` + +The bbv plugin allows you to generate basic block vectors for use with the +`SimPoint `__ analysis tool. + +.. list-table:: Basic block vectors arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - interval=3DN + - The interval to generate a basic block vector specified by the numbe= r of + instructions (Default: N =3D 100000000) + * - outfile=3DPATH + - The path to output files. + It will be suffixed with ``.N.bb`` where ``N`` is a vCPU index. + +Example:: + + $ qemu-aarch64 \ + -plugin contrib/plugins/libbbv.so,interval=3D100,outfile=3Dsha1 \ + tests/tcg/aarch64-linux-user/sha1 + SHA1=3D15dd99a1991e0b3826fede3deffc1feba42278e6 + $ du sha1.0.bb + 23128 sha1.0.bb + Instruction ........... =20 diff --git a/contrib/plugins/bbv.c b/contrib/plugins/bbv.c new file mode 100644 index 0000000000..a5256517dd --- /dev/null +++ b/contrib/plugins/bbv.c @@ -0,0 +1,158 @@ +/* + * Generate basic block vectors for use with the SimPoint analysis tool. + * SimPoint: https://cseweb.ucsd.edu/~calder/simpoint/ + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include + +#include + +typedef struct Bb { + uint64_t vaddr; + struct qemu_plugin_scoreboard *count; + unsigned int index; +} Bb; + +typedef struct Vcpu { + uint64_t count; + FILE *file; +} Vcpu; + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; +static GHashTable *bbs; +static GRWLock bbs_lock; +static char *filename; +static struct qemu_plugin_scoreboard *vcpus; +static uint64_t interval =3D 100000000; + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + for (int i =3D 0; i < qemu_plugin_num_vcpus(); i++) { + fclose(((Vcpu *)qemu_plugin_scoreboard_find(vcpus, i))->file); + } + + g_hash_table_unref(bbs); + g_free(filename); + qemu_plugin_scoreboard_free(vcpus); +} + +static void free_bb(void *data) +{ + qemu_plugin_scoreboard_free(((Bb *)data)->count); + g_free(data); +} + +static qemu_plugin_u64 count_u64(void) +{ + return qemu_plugin_scoreboard_u64_in_struct(vcpus, Vcpu, count); +} + +static qemu_plugin_u64 bb_count_u64(Bb *bb) +{ + return qemu_plugin_scoreboard_u64(bb->count); +} + +static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + g_autofree gchar *vcpu_filename =3D NULL; + Vcpu *vcpu =3D qemu_plugin_scoreboard_find(vcpus, vcpu_index); + + vcpu_filename =3D g_strdup_printf("%s.%u.bb", filename, vcpu_index); + vcpu->file =3D fopen(vcpu_filename, "w"); +} + +static void vcpu_interval_exec(unsigned int vcpu_index, void *udata) +{ + Vcpu *vcpu =3D qemu_plugin_scoreboard_find(vcpus, vcpu_index); + GHashTableIter iter; + void *value; + + if (!vcpu->file) { + return; + } + + vcpu->count -=3D interval; + + fputc('T', vcpu->file); + + g_rw_lock_reader_lock(&bbs_lock); + g_hash_table_iter_init(&iter, bbs); + + while (g_hash_table_iter_next(&iter, NULL, &value)) { + Bb *bb =3D value; + uint64_t bb_count =3D qemu_plugin_u64_get(bb_count_u64(bb), vcpu_i= ndex); + + if (!bb_count) { + continue; + } + + fprintf(vcpu->file, ":%u:%" PRIu64 " ", bb->index, bb_count); + qemu_plugin_u64_set(bb_count_u64(bb), vcpu_index, 0); + } + + g_rw_lock_reader_unlock(&bbs_lock); + fputc('\n', vcpu->file); +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + uint64_t n_insns =3D qemu_plugin_tb_n_insns(tb); + uint64_t vaddr =3D qemu_plugin_tb_vaddr(tb); + Bb *bb; + + g_rw_lock_writer_lock(&bbs_lock); + bb =3D g_hash_table_lookup(bbs, &vaddr); + if (!bb) { + bb =3D g_new(Bb, 1); + bb->vaddr =3D vaddr; + bb->count =3D qemu_plugin_scoreboard_new(sizeof(uint64_t)); + bb->index =3D g_hash_table_size(bbs); + g_hash_table_replace(bbs, &bb->vaddr, bb); + } + g_rw_lock_writer_unlock(&bbs_lock); + + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, count_u64(), n_insns); + + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, bb_count_u64(bb), n_insns); + + qemu_plugin_register_vcpu_tb_exec_cond_cb( + tb, vcpu_interval_exec, QEMU_PLUGIN_CB_NO_REGS, + QEMU_PLUGIN_COND_GE, count_u64(), interval, NULL); +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, + int argc, char **argv) +{ + for (int i =3D 0; i < argc; i++) { + char *opt =3D argv[i]; + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); + if (g_strcmp0(tokens[0], "interval") =3D=3D 0) { + interval =3D g_ascii_strtoull(tokens[1], NULL, 10); + } else if (g_strcmp0(tokens[0], "outfile") =3D=3D 0) { + filename =3D tokens[1]; + tokens[1] =3D NULL; + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + if (!filename) { + fputs("outfile unspecified\n", stderr); + return -1; + } + + bbs =3D g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, free_= bb); + vcpus =3D qemu_plugin_scoreboard_new(sizeof(Vcpu)); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + qemu_plugin_register_vcpu_init_cb(id, vcpu_init); + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + + return 0; +} diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index d4ac599f93..bbddd4800f 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -13,6 +13,7 @@ TOP_SRC_PATH =3D $(SRC_PATH)/../.. VPATH +=3D $(SRC_PATH) =20 NAMES :=3D +NAMES +=3D bbv NAMES +=3D execlog NAMES +=3D hotblocks NAMES +=3D hotpages --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693701; cv=none; d=zohomail.com; s=zohoarc; b=I9K+MGV4FLnsWCyTtO9w1ucsT5rG3FlO+bWaURVnLiF3ORYq4nN02Q2mlM5Cn6lePea0oj3Pa2ZUIVh20l0Z1+AqWSS66m3Fl39/rXlYXtsnvf77eYbP5NTkbt3H/ooflhmltktm+/yYl0QMAWJn8/WzKHoHTBrapHLVMUHTHpY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693701; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pdv6FZr762UL3zV+OCpAf4ICN/LAqMV42uOsRe1XxtM=; b=PVJN5UzK2Gjlbu6Kwg7G3t+WVG2nvreQEmiRBMkNghzabJxVUL+swlv6U7s+GaGB29UblM+CO5FTgHVOaspBGW72jez2N8pcQm/zhsD0L4ysHkdG4hkil1kna1JdcENCbMeATkJ0pvpCracDcS1mb7LysW0vYhDDGlJ6SuJD50E= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693701053282.67090332584223; Wed, 18 Sep 2024 14:08:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tc-0005fO-Qj; Wed, 18 Sep 2024 17:07:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tY-0005OE-O2 for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:28 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tV-0001ed-Oe for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:28 -0400 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5c4226a5af8so209365a12.1 for ; Wed, 18 Sep 2024 14:07:25 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c42bb532a8sm5376035a12.28.2024.09.18.14.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:22 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id CCDBD5FC7F; Wed, 18 Sep 2024 22:07:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693644; x=1727298444; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pdv6FZr762UL3zV+OCpAf4ICN/LAqMV42uOsRe1XxtM=; b=TxnAfILG2FBaRPo9p4k+oalXWLOjoSZJbSlb8+qDXzj5Bwsj1QV7lB9HJmThrOeAnP /8cMBfJnAhloAmE7zmScn0Nb+Kd3erNC9WKHYpLDQGYZhMGTcig9pF4xv8zkWdS1KuBW 4wEc5+Z1MxXQHv/MWM1BdCyRFD3i8KopS12KzbiXf+VwKu0wLyBoKXdENIgJfVvVATk2 ElWiusP6wW811bmOMgvxp9X0r4AQJeaW/wLcshWDCMyblB1ruoaCWbZdCR8kGV0sLr3d G56o/KKNBGIYz72+N9p5eWHM+71teOOuBfZ3VJu3ZlCmvqHCG0uVoFyS8oiWECJTps6l p+xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693644; x=1727298444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pdv6FZr762UL3zV+OCpAf4ICN/LAqMV42uOsRe1XxtM=; b=EIZLhntAZAnGZMziuJMqImPKWCzDhBvJIaN7BuXV5FMpJgxLp8P1TD6atX8bxwGGHp ptNfWCVjbWZx2F5RJCETZ75dCmSuSP32QJeTERz2MefQW6WQMBOqP4DbNl2+TOJGxIpJ qguyOy+IUVZXDEHlLREO+N1xwcHol5CN/7fjoWKr0UtZrYm8JK+VPEllp3SsNSCp/iFk ogADYOoVTqYKYEFsmtDx7HjBmIUxVuQ9S4UoF/G+eeC+07phtJx9g6gZkLuHJbosQpC6 jb9W9kGiZVpcdR/iIH+cz69bZwB5r/1kkQNnq91nfrezhMnHmJNsZAbmaBaNohnxKZ82 jjyw== X-Gm-Message-State: AOJu0YyWwILlVGkwuHFSC4valVsMsh1KXhV0jQ5vuwtrkpZ7ax0VwHKg VUz6REJKl+/RLP/gKzRQ02VINRSj83iFDWEk3prRIUdJsPwGM5YEE9X+xPTZWCY= X-Google-Smtp-Source: AGHT+IG4z8nJLGHFYjOdGE3LACJ7h/onpdpDp/3txyg2TdPgeZ+JqVxjoZ2wUfqsRsnfhkog6O2KjA== X-Received: by 2002:a05:6402:4022:b0:5a1:c496:2447 with SMTP id 4fb4d7f45d1cf-5c413e36c60mr22603579a12.21.1726693644252; Wed, 18 Sep 2024 14:07:24 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Rowan Hart , Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 16/18] plugins: add plugin API to read guest memory Date: Wed, 18 Sep 2024 22:07:10 +0100 Message-Id: <20240918210712.2336854-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::531; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693702344116600 From: Rowan Hart Signed-off-by: Rowan Hart Reviewed-by: Pierrick Bouvier Message-Id: <20240827215329.248434-2-rowanbhart@gmail.com> [AJB: tweaked cpu_memory_rw_debug call] Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-17-alex.bennee@linaro.org> diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 649ce89815..622c9a0232 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -57,11 +57,19 @@ typedef uint64_t qemu_plugin_id_t; * - Remove qemu_plugin_register_vcpu_{tb, insn, mem}_exec_inline. * Those functions are replaced by *_per_vcpu variants, which guarantee * thread-safety for operations. + * + * version 3: + * - modified arguments and return value of qemu_plugin_insn_data to copy + * the data into a user-provided buffer instead of returning a pointer + * to the data. + * + * version 4: + * - added qemu_plugin_read_memory_vaddr */ =20 extern QEMU_PLUGIN_EXPORT int qemu_plugin_version; =20 -#define QEMU_PLUGIN_VERSION 3 +#define QEMU_PLUGIN_VERSION 4 =20 /** * struct qemu_info_t - system information for plugins @@ -884,6 +892,28 @@ typedef struct { QEMU_PLUGIN_API GArray *qemu_plugin_get_registers(void); =20 +/** + * qemu_plugin_read_memory_vaddr() - read from memory using a virtual addr= ess + * + * @addr: A virtual address to read from + * @data: A byte array to store data into + * @len: The number of bytes to read, starting from @addr + * + * @len bytes of data is read starting at @addr and stored into @data. If = @data + * is not large enough to hold @len bytes, it will be expanded to the nece= ssary + * size, reallocating if necessary. @len must be greater than 0. + * + * This function does not ensure writes are flushed prior to reading, so + * callers should take care when calling this function in plugin callbacks= to + * avoid attempting to read data which may not yet be written and should u= se + * the memory callback API instead. + * + * Returns true on success and false on failure. + */ +QEMU_PLUGIN_API +bool qemu_plugin_read_memory_vaddr(uint64_t addr, + GByteArray *data, size_t len); + /** * qemu_plugin_read_register() - read register for current vCPU * diff --git a/plugins/api.c b/plugins/api.c index 3316d4a04d..24ea64e2de 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -560,6 +560,26 @@ GArray *qemu_plugin_get_registers(void) return create_register_handles(regs); } =20 +bool qemu_plugin_read_memory_vaddr(vaddr addr, GByteArray *data, size_t le= n) +{ + g_assert(current_cpu); + + if (len =3D=3D 0) { + return false; + } + + g_byte_array_set_size(data, len); + + int result =3D cpu_memory_rw_debug(current_cpu, addr, data->data, + data->len, false); + + if (result < 0) { + return false; + } + + return true; +} + int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray= *buf) { g_assert(current_cpu); diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index eed9d8abd9..032661f9ea 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -21,6 +21,7 @@ qemu_plugin_num_vcpus; qemu_plugin_outs; qemu_plugin_path_to_binary; + qemu_plugin_read_memory_vaddr; qemu_plugin_read_register; qemu_plugin_register_atexit_cb; qemu_plugin_register_flush_cb; --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693744; cv=none; d=zohomail.com; s=zohoarc; b=HcBUGWaJVyowxpgR90H/VCs/AMMfUoZavmKTr3w5cH8mMHChM3Xf+1QW0UkKHzFown6JFSDmUXolQuvhLsPGluB7SPU5rNDw4iTipTZJ/eDWBXmSqgol2J2JDlkQDpPXNuwm7QHGL4LNeYTnzQ6L6JS3DjC7rGiAJXyT+xFCEow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693744; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O2qjDyra0c4+qL6NzNT5YzyZzRtZBLugi4bg2B/w4/Q=; b=LO63O376wkLGIc+qEbTSrD7QIuJ1KABPgYJ0cOWAHncI5Xjmq293Kb1sIgtX/8OMOqwYK3QWWsFTSLqR/wqjvsXTcUafK46sC1jfXY3slr7N1altIRHXmNb92kb6ZUmZPXsAFI1NgW9Z7+GEjevvdWt4h3/A7hSNpCWhqT8Dr1o= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693744690139.46791435872876; Wed, 18 Sep 2024 14:09:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tZ-0005Qy-IM; Wed, 18 Sep 2024 17:07:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tX-0005IQ-Cq for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:27 -0400 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tV-0001eW-It for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:27 -0400 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a90188ae58eso13144666b.1 for ; Wed, 18 Sep 2024 14:07:25 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9061116d67sm638576166b.94.2024.09.18.14.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:22 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id E40185F8C8; Wed, 18 Sep 2024 22:07:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693644; x=1727298444; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O2qjDyra0c4+qL6NzNT5YzyZzRtZBLugi4bg2B/w4/Q=; b=c2u37rs4nXIJnCtXY8PIbob/NWyIwhU2yxXlGXWC/fPArJIs1uyiNqhopkaIBuxFy4 10quSNi3ld7Tw1n4b974y8GCXAffLi46UcjX/yUYxJQcDI32lKy3AyOfMUzSCwnrYcl+ MikMdNG0ZNouInssYKo65518+ZvTiRtHCbDuLWm/Y+wkHo9KatHlNlD7sY6PTk67NWGJ DAGWHx6rzRsY5ESTYeKeE5IHEaxuVSmTlCAtJGkrukitYNH4GIl3AbTX/XOD+iUP3309 2oAP0DBHqqYnqlJHNa6UxZaavK+tywa0h3r4n3FpmFTUTxvm5NJvWDjwAtYbvFMxhvC2 pSQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693644; x=1727298444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O2qjDyra0c4+qL6NzNT5YzyZzRtZBLugi4bg2B/w4/Q=; b=Z2W7umhnLrosqjlxpBcN5HzEoLo2Gzbnq30ZmtCWKIfEyQSir1gP0iZJCbQhZPk80L pFAGuahtZ7NgkD7qRFl959wJXsjYJbWKQtyrWHxxSfWp3kO+NPQIJ5FlT0dhXGobc7Hl tIFjv6qUnPvkDyLMPMFr/ft3dj/K5IfYL9OeNzf7P2HliSkJcRZO87mynT/FSHxkf3TM LB/9bxLAmA0KMhYVkWA5+3Nl3JCLyZ7sw59ZVg6Mv1N/GvTQ1Ho4L9v5d2KRxgeUCOL4 d0OyxTSJHgPxXiXZUhaLXGQZObKvOqimmlleb6RB3xi/Ega3O8gu7XGqTBDzAFEw1uUp Eerw== X-Gm-Message-State: AOJu0YxxHZJd2Bi14UOg3gYkE795ukEmMakZZwIGUXrgWdUBsEh65jWl ZHtBrwG9+wBnspD4pGadSGWezzUpeHHWmoVgr6HILnZwCqabczfxxAj6Zi9kICE= X-Google-Smtp-Source: AGHT+IG0dSOqoKgIlBznJfmwmSoMWz7uTbIdw8UtftKA9/Eo1Lk5y9pq6R/z6T/7AXWrK+aYtbX/Qg== X-Received: by 2002:a17:907:f1c6:b0:a86:a30f:4aef with SMTP id a640c23a62f3a-a9029446fdbmr2146689866b.22.1726693643917; Wed, 18 Sep 2024 14:07:23 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Rowan Hart , Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 17/18] plugins: add option to dump write argument to syscall plugin Date: Wed, 18 Sep 2024 22:07:11 +0100 Message-Id: <20240918210712.2336854-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::633; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693746375116600 From: Rowan Hart Signed-off-by: Rowan Hart Reviewed-by: Pierrick Bouvier Tested-by: Pierrick Bouvier Message-Id: <20240827215329.248434-3-rowanbhart@gmail.com> [AJB: tweak fmt string for vaddr] Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240916085400.1046925-18-alex.bennee@linaro.org> diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index ee59c2fa9b..3028d5fff7 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -414,6 +414,19 @@ run:: 160 1 0 135 1 0 =20 +Behaviour can be tweaked with the following arguments: + +.. list-table:: Syscall plugin arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - print=3Dtrue|false + - Print the number of times each syscall is called + * - log_writes=3Dtrue|false + - Log the buffer of each write syscall in hexdump format + Test inline operations ...................... =20 @@ -803,4 +816,3 @@ Other emulation features When running system emulation you can also enable deterministic execution which allows for repeatable record/replay debugging. See :ref:`Record/Replay` for more details. - diff --git a/tests/tcg/plugins/syscall.c b/tests/tcg/plugins/syscall.c index 72e1a5bf90..89dc7f49b1 100644 --- a/tests/tcg/plugins/syscall.c +++ b/tests/tcg/plugins/syscall.c @@ -22,8 +22,57 @@ typedef struct { int64_t errors; } SyscallStats; =20 +struct SyscallInfo { + const char *name; + int64_t write_sysno; +}; + +static const struct SyscallInfo arch_syscall_info[] =3D { + { "aarch64", 64 }, + { "aarch64_be", 64 }, + { "alpha", 4 }, + { "arm", 4 }, + { "armeb", 4 }, + { "avr", -1 }, + { "cris", -1 }, + { "hexagon", 64 }, + { "hppa", -1 }, + { "i386", 4 }, + { "loongarch64", -1 }, + { "m68k", 4 }, + { "microblaze", 4 }, + { "microblazeel", 4 }, + { "mips", 1 }, + { "mips64", 1 }, + { "mips64el", 1 }, + { "mipsel", 1 }, + { "mipsn32", 1 }, + { "mipsn32el", 1 }, + { "or1k", -1 }, + { "ppc", 4 }, + { "ppc64", 4 }, + { "ppc64le", 4 }, + { "riscv32", 64 }, + { "riscv64", 64 }, + { "rx", -1 }, + { "s390x", -1 }, + { "sh4", -1 }, + { "sh4eb", -1 }, + { "sparc", 4 }, + { "sparc32plus", 4 }, + { "sparc64", 4 }, + { "tricore", -1 }, + { "x86_64", 1 }, + { "xtensa", 13 }, + { "xtensaeb", 13 }, + { NULL, -1 }, +}; + static GMutex lock; static GHashTable *statistics; +static GByteArray *memory_buffer; +static bool do_log_writes; +static int64_t write_sysno =3D -1; =20 static SyscallStats *get_or_create_entry(int64_t num) { @@ -39,6 +88,44 @@ static SyscallStats *get_or_create_entry(int64_t num) return entry; } =20 +/* + * Hex-dump a GByteArray to the QEMU plugin output in the format: + * 61 63 63 65 6c 09 09 20 20 20 66 70 75 09 09 09 | accel.....fpu... + * 20 6d 6f 64 75 6c 65 2d 63 6f 6d 6d 6f 6e 2e 63 | .module-common.c + */ +static void hexdump(const GByteArray *data) +{ + g_autoptr(GString) out =3D g_string_new(""); + + for (guint index =3D 0; index < data->len; index +=3D 16) { + for (guint col =3D 0; col < 16; col++) { + if (index + col < data->len) { + g_string_append_printf(out, "%02x ", data->data[index + co= l]); + } else { + g_string_append(out, " "); + } + } + + g_string_append(out, " | "); + + for (guint col =3D 0; col < 16; col++) { + if (index + col >=3D data->len) { + break; + } + + if (g_ascii_isgraph(data->data[index + col])) { + g_string_append_printf(out, "%c", data->data[index + col]); + } else { + g_string_append(out, "."); + } + } + + g_string_append(out, "\n"); + } + + qemu_plugin_outs(out->str); +} + static void vcpu_syscall(qemu_plugin_id_t id, unsigned int vcpu_index, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, @@ -54,6 +141,14 @@ static void vcpu_syscall(qemu_plugin_id_t id, unsigned = int vcpu_index, g_autofree gchar *out =3D g_strdup_printf("syscall #%" PRIi64 "\n"= , num); qemu_plugin_outs(out); } + + if (do_log_writes && num =3D=3D write_sysno) { + if (qemu_plugin_read_memory_vaddr(a2, memory_buffer, a3)) { + hexdump(memory_buffer); + } else { + fprintf(stderr, "Error reading memory from vaddr %"PRIu64"\n",= a2); + } + } } =20 static void vcpu_syscall_ret(qemu_plugin_id_t id, unsigned int vcpu_idx, @@ -127,6 +222,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_print)) { fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); } + } else if (g_strcmp0(tokens[0], "log_writes") =3D=3D 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_log_writ= es)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); + } } else { fprintf(stderr, "unsupported argument: %s\n", argv[i]); return -1; @@ -137,6 +236,24 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, statistics =3D g_hash_table_new_full(NULL, g_direct_equal, NULL, g= _free); } =20 + if (do_log_writes) { + for (const struct SyscallInfo *syscall_info =3D arch_syscall_info; + syscall_info->name !=3D NULL; syscall_info++) { + + if (g_strcmp0(syscall_info->name, info->target_name) =3D=3D 0)= { + write_sysno =3D syscall_info->write_sysno; + break; + } + } + + if (write_sysno =3D=3D -1) { + fprintf(stderr, "write syscall number not found\n"); + return -1; + } + + memory_buffer =3D g_byte_array_new(); + } + qemu_plugin_register_vcpu_syscall_cb(id, vcpu_syscall); qemu_plugin_register_vcpu_syscall_ret_cb(id, vcpu_syscall_ret); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); --=20 2.39.5 From nobody Sun Nov 24 04:00:46 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=1726693741; cv=none; d=zohomail.com; s=zohoarc; b=P71CnBsdYLQ6Jr7qeTVM9Q9og/8M3NgfnzbMu2SQiqhkp27V5P9tu36eBAd/QWOoqkJpAOsdL5jkunCSz3OGzm3eks8FhIsZHt26FcMFmpvIA6L9E854/Aak0Zd1rrvXyOWmNphKuq1jnLm54ET7LkrqQq3KytDp53ZO+AyuHdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726693741; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cJpVIU5QQnwL+VksdQ4VURK2afv6KY7pJOWQu7Phvmw=; b=nX59SLF60dq6GrRqWEZIFeLCUedSjMhbuYWzwR7N5L/CObYH2LZ4nPwIm/gaogzpFl2yIx50sToyZzEuYf7WnVvDg1DcEH+HobRZEc13VW0V+n1T1a6BUwDnu5EezibRnbw6b1eK+//IoOIroDcfqNvSgwl2NN8847QkEXFXh60= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726693741252663.4325939388727; Wed, 18 Sep 2024 14:09:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tb-0005ad-MJ; Wed, 18 Sep 2024 17:07:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr1tZ-0005QM-9S for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:29 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tX-0001ey-Jx for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:28 -0400 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5c42f406fa5so108497a12.0 for ; Wed, 18 Sep 2024 14:07:27 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c42bb89d50sm5389238a12.78.2024.09.18.14.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:22 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 075ED5FC95; Wed, 18 Sep 2024 22:07:14 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693646; x=1727298446; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cJpVIU5QQnwL+VksdQ4VURK2afv6KY7pJOWQu7Phvmw=; b=SWUvD0+AqGdL22pOh/W4tLpWRbF+KPSX+mWCJpLSwUeqSWIwrhhrWP/6kWx0Cwo742 JNxYDQU1ayVWTvkm97spYOtipr4Y+/BSmIFL2EC8rGxxgYtDCZb3oV81YX5K/hcnW0E6 fDV6KdmrJqu2KQmVCTUNx+472PywKPOCVQ6fCrUckg/MZOCC7pSf9HRNPIcTc2xXLwXN jYtY3N5HO+BJv6eyxWfoRaG4QwSt53vg0duc0/K7HowHkmW60uq1pTsOsqiKBIFhGBG7 1LjFNnCCyCXyola9aJ5hqYLBpRDaV3He4DLKJqkQW4cu1+iONfFFZx3roXWZqfe9YBzb 9SCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693646; x=1727298446; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cJpVIU5QQnwL+VksdQ4VURK2afv6KY7pJOWQu7Phvmw=; b=rF1pJ21l4nlkFcg3nk9XeiDX/nLeJKSlZEoWYHh/ZcqNz3sr09JLn8A7fqcYAVhA0a wog3TBYvW7C8If70A7Qq711kAlfZ2SvlaQSYdRPLK5WKSxmK4UsDAsZu5cyc7YuABfdA AIkkebDcljN6vYSO39sP2rRZyl5DI5iBTNm63cRDp4Ra9pOrO7hvjf1qQEU6jXFmTAzm YHRjHVJDsHvR+9wWz7Kk8J4/HUNTaregwnfM4qjTjQR6BdzaKClqRT/cvvGdeR5uLYfP 4eHNPnBaNupd6sYg06K5TwwVEgF2nMPN0Zx/xWm/GUp1NuAt4HkZgFepLozh7DFpcT0v SSdQ== X-Gm-Message-State: AOJu0Yzsl6j9q4JRKyFg9LBnsnjnvESXMfn6qN/2Gunk+IxopqY/l2gN odHgG/3qrkhpNALtujMzjbLGPEowAdo7oqn0rg7SvNeH6GX6HcqcCV5fVGXmfUA= X-Google-Smtp-Source: AGHT+IHeXBCMp+lPkW5qsWyBrr8B0Tf6YEaWCT1pKwmSEC4U+puObq/jK4qo7MSxxqKSQO/XMhj/RA== X-Received: by 2002:a05:6402:5d3:b0:5c3:c530:e99a with SMTP id 4fb4d7f45d1cf-5c41e1930c7mr29715024a12.15.1726693646069; Wed, 18 Sep 2024 14:07:26 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Elisha Hollander , Richard Henderson , Pierrick Bouvier , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 18/18] contrib/plugins: avoid hanging program Date: Wed, 18 Sep 2024 22:07:12 +0100 Message-Id: <20240918210712.2336854-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@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=2a00:1450:4864:20::52b; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-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.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726693742215116600 Although we asks for instructions per second we work in quanta and that cannot be 0. Fail to load the plugin instead and report the minimum IPS we can handle. Reported-by: Elisha Hollander Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Pierrick Bouvier Message-Id: <20240916085400.1046925-19-alex.bennee@linaro.org> diff --git a/contrib/plugins/ips.c b/contrib/plugins/ips.c index 29fa556d0f..e5297dbb01 100644 --- a/contrib/plugins/ips.c +++ b/contrib/plugins/ips.c @@ -152,6 +152,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, vcpus =3D qemu_plugin_scoreboard_new(sizeof(vCPUTime)); max_insn_per_quantum =3D max_insn_per_second / NUM_TIME_UPDATE_PER_SEC; =20 + if (max_insn_per_quantum =3D=3D 0) { + fprintf(stderr, "minimum of %d instructions per second needed\n", + NUM_TIME_UPDATE_PER_SEC); + return -1; + } + time_handle =3D qemu_plugin_request_time_control(); g_assert(time_handle); =20 --=20 2.39.5