From patchwork Fri Sep 13 17:26:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828204 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362168wra; Fri, 13 Sep 2024 10:28:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVYsS1qfMV5LNchOPjz0fbBCQ2XYmbTupW/mNKaDvSWcjB839KtFQHjJObZTS1ntTHHSx5+zQ==@linaro.org X-Google-Smtp-Source: AGHT+IFpwWp0aQvckHAT+lulIaM3e5/Ke4tpdOSSfYU9OxqRtjaq4dkRuefDqckfEmR4JFzAhVKD X-Received: by 2002:a05:6214:1749:b0:6c5:891b:15d1 with SMTP id 6a1803df08f44-6c5891b1625mr7061216d6.25.1726248531377; Fri, 13 Sep 2024 10:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248531; cv=none; d=google.com; s=arc-20240605; b=M+9kZyuYUL2oqGaXE+JxcomIKXrf8bCbjoRbYXUx00tJu9DgQvI1GplkJxCe5FlKHs EtYLmGF/M5iTXo+95zS/BuCWrP24ht+BSTJG0YrOSlGamNqET8Zrmb35gYqM/u+ZawbR QrFHS3uHEVRGdVZWS8IaPROXj0xvZ17lDJEKT8LhI53EnRZaHqe3vkPZK52L11e+9Dts W/4sGOmPlVgoE1dIyQeiNEt8dq9ApbbFsd3u8TVPOj+Qju88iPolP58aw15b60eU9YY+ ZZocIuuEyURsRAqxzLQhdY85OrdyuMdiAPMm2x9yVHu3gcTWaQEbvvZjzwM5xta9N4U6 ISWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NUatFApg2Cs5Vc3/hwC8i7ZiRClvTT8CyVvcfUZaS0U=; fh=Yn9Rr5YRWo7nHBEBYPErLs0SzN9tKEIm+tjOgOQtjBE=; b=DVlbIqzGUTPogQiOWY692jcwN2sQComPDZ86QLcf5M8U3uMXRdnCAo/UiNU6rLPT73 +qFvPJGWuaZKySgTb70ym4ZtAyaBE6e1U80KJt8miKN9VhsZzE9BebmQqiXsoQirizlx FHMl8TqVgAaH3YMG7SIB0RFVI+59r4aWSI2rDrK0OsLGCV6ej8CCXYHRZxa109WDpUiH bkw3Z43FyRVNJ3+68o8ZoLQwILZcqy86OS7qLNwkbbvRAr3/X32mCS7LTnqTxc+DipcP UmO286FKKCTF67vUkv6JHYU+xWwD5OPRrbIedhOYxY1Xfo/8Q+wG1XavEgzmaJNPj6Ao UOIg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="SfV/SHA/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6c5343302desi152063916d6.52.2024.09.13.10.28.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="SfV/SHA/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4f-00063C-Mo; Fri, 13 Sep 2024 13:27:13 -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 1spA4Z-0005ia-4R for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:07 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spA4V-0005tJ-4z for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:06 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-42cae102702so10876105e9.0 for ; Fri, 13 Sep 2024 10:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248421; x=1726853221; 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=NUatFApg2Cs5Vc3/hwC8i7ZiRClvTT8CyVvcfUZaS0U=; b=SfV/SHA/A0qZKSWMRg0XKzti8Rm2VxvFPzywVgOTHzQPaDL+Or95UrfFUP+2888rrK vGOR8Indmq9N7+tC9rmmas0/pB2uHBXdwdhrsPgH7A9sEGGAtNmwC8SL6xhd3+gm5LBv WZQHnoyS6fVnAHilV6d+jhbSkU9Epb8tOPjsIb/ArnDF4IgGldoZde1AMh6LUN1nasX3 zznNG7Lchfmt6iz8j77PREuV1TidVNGULdiGwBVN+G5sS0XDaXAU+caMEjIeeAZYogk0 MKC8yQPMNRow26lSpd7qmVHv9WecdgrOrFmiR9ZK8vxU4dPSqw/A6kCkEr2uxtjoMHip 8+5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248421; x=1726853221; 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=NUatFApg2Cs5Vc3/hwC8i7ZiRClvTT8CyVvcfUZaS0U=; b=qsHK3dgbIc5IWLulWvpys6LgvK2rDTHCsYEZhaqxwOccAaptNT5Lxkwagb3D7YbAc3 XKJKM3yt7UjHZ031buzxHjwwY+IcKLW10whSX7+0I3lTiyEj3mjtWZKJgzPCBJ+8MljL BC1KoCmoeSwX3vCixWOceW/YfR4yBh0Xkdhoav6B/L4bBWDrnQulkUoym/HES8BkpO8/ 87AdSOWkzN3vCFPS3Vsv+W3CF5Z8QJ7Rf79IuYM224q5HxtIhrk2UdqgAKUmWH4AUQ+d L134gjpumYqCgFFvW1nW8oxnMmFudm2MoXmqQJgwMp2qi+prWErIWb/+1FbhPgluQpjs H26g== X-Gm-Message-State: AOJu0YwVv9kmq+nIDICyjTtIc6NG2tdUV+6xOzMcuV81ID0ecOgnz/2W 8siZ/j3sJkrFGpxg7nDjrmNsWb7c41tTVEsDpzhan8ek2m0zr68VUl0IXd7YHvw= X-Received: by 2002:adf:cd8b:0:b0:374:b5fc:68df with SMTP id ffacd0b85a97d-378d61d4f96mr2116520f8f.4.1726248420508; Fri, 13 Sep 2024 10:27:00 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd5212asm7864030a12.57.2024.09.13.10.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:26:57 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 317965F8C3; Fri, 13 Sep 2024 18:26:56 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum Subject: [PATCH 01/17] deprecation: don't enable TCG plugins by default on 32 bit hosts Date: Fri, 13 Sep 2024 18:26:39 +0100 Message-Id: <20240913172655.173873-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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. Message-Id: <20240910140733.4007719-12-alex.bennee@linaro.org> Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Bennée --- v2 - don't manually set based on CPU type, use __SIZEOF_POINTER__ --- docs/about/deprecated.rst | 11 +++++++++++ configure | 21 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 88f0f03786..f7c7c33d39 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. +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. System emulator CPUs -------------------- diff --git a/configure b/configure index 7f6eb6b331..f376fa24b3 100755 --- a/configure +++ b/configure @@ -516,6 +516,25 @@ case "$cpu" in ;; esac +# Now we have our CPU_CFLAGS we can check if we are targeting a 32 or +# 64 bit host. + +check_64bit_host() { +cat > $TMPC < X-Patchwork-Id: 828206 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362362wra; Fri, 13 Sep 2024 10:29:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXOlRMwIafsOY1hlbTUg9HjZsHE2ZRopIuDpTMj1Zhnu13Si4985hSriABTmnzudSy53JMtoA==@linaro.org X-Google-Smtp-Source: AGHT+IGDpOkW9hcuha52Nl2cDVglIFy3OR8D4lH7WRgql2MJPyTUHzY1Vm9Kf71no77IboZM6QfP X-Received: by 2002:ac8:5a05:0:b0:458:3399:5177 with SMTP id d75a77b69052e-45860326440mr111677271cf.27.1726248557411; Fri, 13 Sep 2024 10:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248557; cv=none; d=google.com; s=arc-20240605; b=fWZPnQfvfluHkNotb8Nl1TtpDUuH6F0jldfiENiQELJT2VRJaBN8Vutvwe26w2A66l 9qwGXxfhw6PPFhUenw2SBOmMKXv8iLJJIQdJx88fcWd+OSflZ2sy9DxfhKbbuK60jBE9 YUQE2P0m4GYafeP02YlbEkpGQhAQ2z7w8o7DwkSYL42RGdy0mSlljoM50apyeDyr5X9y lDgtviczuDL+7SaFWZa/RHx/tTs+5EQ1g3ehrQT+t/gYNdGyJYCGEAqyKcLgaEJZ93Me HsysgOyLdqgGMHGjT9m/hpSC6ZgDiRhBSBBFSnwkTQ5EtmSoMFidg9tbaWN5ym4wLa4Z 76/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QnElM81hCsi1ZuPnpFOx/34GLOM47VGqPSwGZVF4S40=; fh=Yn9Rr5YRWo7nHBEBYPErLs0SzN9tKEIm+tjOgOQtjBE=; b=RZzf1SXRWMYocDfE/EZnodvgwhInmZTnuXJZa4uNRQnwtmMYBKijeaz4o/y32fluP8 Ov9wU9rQA1Z/IGHVNNRnXCZi2sEzmhYMgCbjHeEk2EcfywIaj3BzPAqqINgO3zJAR4wS OzcTRy3EFoj9UvCZVUBOQUlPsgsJsyh808cc05qbZUOYp0LNa0MbpO6dr9DfPsMX+ea3 1eXIjRqdmNPRHcu507MBnCvkS2avJXIF+r1B+bfH9ThGAlZpc/EgZ2/GOieeBBFlP80o fxdT84ZuhaNNVpEvjP5TVN9PXLVbbgozTAs7IqEPiO9/vYurIPmV5Px5zkfCR7cs++/y r0IA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MnvrLn+e; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45822fb4b39si151595741cf.637.2024.09.13.10.29.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:29:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MnvrLn+e; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4h-0006Fa-6q; Fri, 13 Sep 2024 13:27:15 -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 1spA4c-0005uj-33 for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:10 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spA4V-0005tI-58 for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:09 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42cb57f8b41so15846445e9.0 for ; Fri, 13 Sep 2024 10:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248421; x=1726853221; 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=QnElM81hCsi1ZuPnpFOx/34GLOM47VGqPSwGZVF4S40=; b=MnvrLn+e+fa5fwK1sqtNfHUnRQLYz6ly7oazG07ynwhlwTk/nHZ/bkLevzbv9wElnm ixSEWaUnAjy0yLRIjLcUeH9c69wj8I82iMUDgmhVb3LLL/3b3aHnNXvebsrWxnduJ9MJ kV0NN8ag3cDcn8frd1JaNNo+9F/WUhqmn43uwulM7GhgBlPR76gWIbY/Jjv64/UUsssp 1GHdfNBF7sCRHavu41pHpsbNxIVs6TEeRD3CsBiK8wNwtD0Mbw4BxFQHunFYeXOvtf+x tPyUoBe6VThIsFzcnPzZsTtsDaJg0isaAZKjJKH5r/DHZEMETmu90qx/HTgUlPOy9jGr xybQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248421; x=1726853221; 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=QnElM81hCsi1ZuPnpFOx/34GLOM47VGqPSwGZVF4S40=; b=N+jNFitk4PSGjlQyW3vWaYywyVSSSNzsfOyK4FbncNMeWkoA28Ice9bZYvuF0S6JPj 6Ir1DgQV8eQDDEFc5wGYvQWzxI1D/VGmG2fQ2MXQUQpjPanSiKv1yZvS/r5SMTRvYGcA CkQgS/ej3h9Rorg7+DZ0CuIHVks492hO4W5/GoJyGjXgO23PJKJGZkO9JAtnr1ydDbZs v6Kc92rmMdU5wO6UMqODyS0QBud1Ip1MAlawYFxQwl6lBiVJVJbob25Jg59HBHbpyQOO 0XD7FnjAu/1/n1wRPsBHqjzwQhiItyVt9UIWms+we3JjOm/s79LZTdKT9MTZX5lb88os A6kQ== X-Gm-Message-State: AOJu0Yz32kJgiRISTBRF5qk78oKz6dauvAyNI0XrKTz8AcgcbXTYDmYX /ZRFhQIeL13ZrEY3+eIXM2Yfc/LHRJqMIMIlozs78mX8YUF2yph/3KKKZiXLHSo= X-Received: by 2002:a05:6000:51:b0:374:d07a:c136 with SMTP id ffacd0b85a97d-378d6236043mr3096202f8f.36.1726248420165; Fri, 13 Sep 2024 10:27:00 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25d5da53sm885301666b.209.2024.09.13.10.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:26:57 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 803705F9DA; Fri, 13 Sep 2024 18:26:56 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum Subject: [PATCH 04/17] plugins: save value during memory accesses Date: Fri, 13 Sep 2024 18:26:42 +0100 Message-Id: <20240913172655.173873-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-2-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- accel/tcg/atomic_template.h | 66 ++++++++++++++++++++++++++++++----- include/hw/core/cpu.h | 4 +++ include/qemu/plugin.h | 4 +++ plugins/core.c | 6 ++++ tcg/tcg-op-ldst.c | 66 +++++++++++++++++++++++++++++++---- accel/tcg/atomic_common.c.inc | 13 ++++++- accel/tcg/ldst_common.c.inc | 38 ++++++++++++-------- 7 files changed, 167 insertions(+), 30 deletions(-) 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 +#if DATA_SIZE == 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 >= 4 # define ABI_TYPE DATA_TYPE #else @@ -83,7 +91,12 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, abi_ptr addr, ret = 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; } @@ -97,7 +110,12 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, abi_ptr addr, ABI_TYPE val, ret = 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; } @@ -109,7 +127,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ haddr = atomic_mmu_lookup(env_cpu(env), addr, oi, DATA_SIZE, retaddr); \ ret = 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; \ } @@ -145,7 +168,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ cmp = qatomic_cmpxchg__nocheck(haddr, old, new); \ } while (cmp != 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; \ } @@ -188,7 +216,12 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, abi_ptr addr, ret = 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); } @@ -202,7 +235,12 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, abi_ptr addr, ABI_TYPE val, ret = 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); } @@ -214,7 +252,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ haddr = atomic_mmu_lookup(env_cpu(env), addr, oi, DATA_SIZE, retaddr); \ ret = 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); \ } @@ -247,7 +290,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ ldn = qatomic_cmpxchg__nocheck(haddr, ldo, BSWAP(new)); \ } while (ldo != 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; \ } @@ -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, uint64_t a1, void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret); 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); void qemu_plugin_flush_cb(void); @@ -251,6 +253,8 @@ void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret) { } 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, } 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 = cpu->neg.plugin_mem_cbs; @@ -610,6 +612,10 @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, if (arr == NULL) { return; } + + cpu->neg.plugin_mem_value_low = value_low; + cpu->neg.plugin_mem_value_high = value_high; + for (i = 0; i < arr->len; i++) { struct qemu_plugin_dyn_cb *cb = &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 *addr) return NULL; } +#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 != NULL) { qemu_plugin_meminfo_t info = make_plugin_meminfo(oi, rw); @@ -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 != 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 != 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 != 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 } @@ -203,7 +251,8 @@ static void tcg_gen_qemu_ld_i32_int(TCGv_i32 val, TCGTemp *addr, opc = 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); 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, TCGTemp *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); if (swap) { tcg_temp_free_i32(swap); @@ -324,7 +373,8 @@ static void tcg_gen_qemu_ld_i64_int(TCGv_i64 val, TCGTemp *addr, opc = 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); if ((orig_memop ^ memop) & MO_BSWAP) { int flags = (orig_memop & MO_SIGN @@ -396,7 +446,7 @@ static void tcg_gen_qemu_st_i64_int(TCGv_i64 val, TCGTemp *addr, opc = 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); if (swap) { tcg_temp_free_i64(swap); @@ -606,7 +656,8 @@ static void tcg_gen_qemu_ld_i128_int(TCGv_i128 val, TCGTemp *addr, tcg_constant_i32(orig_oi)); } - 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); } 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, TCGTemp *addr, tcg_constant_i32(orig_oi)); } - 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); } 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 @@ */ 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); + } } /* 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 */ -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); } } @@ -136,7 +141,7 @@ uint8_t cpu_ldb_mmu(CPUArchState *env, abi_ptr addr, MemOpIdx oi, uintptr_t ra) tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_UB); ret = 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; } @@ -147,7 +152,7 @@ uint16_t cpu_ldw_mmu(CPUArchState *env, abi_ptr addr, tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_16); ret = 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; } @@ -158,7 +163,7 @@ uint32_t cpu_ldl_mmu(CPUArchState *env, abi_ptr addr, tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_32); ret = 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; } @@ -169,7 +174,7 @@ uint64_t cpu_ldq_mmu(CPUArchState *env, abi_ptr addr, tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_64); ret = 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; } @@ -180,7 +185,7 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_128); ret = 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; } @@ -188,10 +193,15 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, * Store helpers for cpu_ldst.h */ -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); } } @@ -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); } 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, uint16_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) == 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); } 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, uint32_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) == 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); } 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, uint64_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) == 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); } void cpu_st16_mmu(CPUArchState *env, abi_ptr addr, Int128 val, @@ -231,7 +241,7 @@ void cpu_st16_mmu(CPUArchState *env, abi_ptr addr, Int128 val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) == 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); } /* From patchwork Fri Sep 13 17:26:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828209 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362549wra; Fri, 13 Sep 2024 10:29:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVIfUsAAoA8bMHCoL930ZZUdjh/0uDVPSZhADBH0vbILjjbxf4wCChB0nsb40mlqiULcwYemw==@linaro.org X-Google-Smtp-Source: AGHT+IGXFF9qnZPqprm/CS8+eR7ZuCxafGbzP/ZL5QuwFYyjznrEPWZrkAGGA4SB9fexFVO7CzSa X-Received: by 2002:a05:6902:e08:b0:e1d:8ac4:f509 with SMTP id 3f1490d57ef6-e1d9dc47f9amr6534992276.49.1726248583770; Fri, 13 Sep 2024 10:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248583; cv=none; d=google.com; s=arc-20240605; b=IFYQmo1U+o7xCxtYWY+3Dfg0+T2yMZF48Y+/2wrYw5Azt5c6WVngA7kV6ZePyGBe3K FN17GGOl1kgcyxUd23nExiL6toiPjktNxCxaSZxMogPdGGFNT33DgxnovBeToVDmQ6CV 8Z1HihClT4gxRh56M2XDzWqcUCehQ3lur5MFF8prPsZm97xi77oBNBLCxyyu2J96rECF qu08IVo1ITcyU8nKsch7pXWmvprmtduaQz9m72+QFP33jEvZfz3BE+cyq5j0neCJ1VZf KRoV6eYAL1vR7OZlzUls+VL6wDc7x8GVMpguQKL5rfwONrqkfSV15ndf8TneU4aVqjT8 pfuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bg1S7MpqFLKynDQMTW/BgVqsjzz9T+4SZvu94a93bN0=; fh=F5awbK741II+wT+mHTjf48yqF0ogIKVBroCor9WBHkU=; b=gSgIU3mn06FUDuhwTHKt2zY8RwgBibIpL9yqx6Wf9BMtdUh2oGXBXT4Vvuf0X2HRDj PN+/apGpvEYIpG3NYxMEB5PGhCtoBR3Uh8empSVtm6RMdFT3SR1A6PKpiGMus/DPItzV KCid+69rLFxRMCgumGVEPeJyAXtOED43WjbZ5L72vLPjAB2tqQg+kpAqk92DSFMk/Oz1 U8O/0pYN/rRgN5OCxiDQ+oDJ6LMf/LWhRKeTrB8CgvV53nH/QsDqC8O51opNdRNrGZ9A oFf76ftl+P5bQppRc3/3F2in0yk6r6JMh9F2ntEW0NG7jEFOhe2b1DBq72kgPQbiS9tZ J2VQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xSeZG2ee; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6c5347c2e6fsi152559256d6.532.2024.09.13.10.29.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:29:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xSeZG2ee; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4m-0006dj-Op; Fri, 13 Sep 2024 13:27:21 -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 1spA4c-0005y8-T3 for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:11 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spA4V-0005tk-QP for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:10 -0400 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5c260b19f71so2697334a12.1 for ; Fri, 13 Sep 2024 10:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248422; x=1726853222; 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=bg1S7MpqFLKynDQMTW/BgVqsjzz9T+4SZvu94a93bN0=; b=xSeZG2eeWB+UFjTeZ8P4bdSFNXAnl+iYXQFhu6X1A7YqbjXYm0Xfw0230nIWivbG9u RSSrTu7PjR79It19K2iNQD2FMlvqA8aRur1mRAbrRAWlCc9dMJjIyShfqPh4w78RgUDz qZZ6kkbYXGSOVwM2+zOqGJxeErpDLSFWAI4ZkajmN9IEbtKGsNzQQmTHqOWIYinAddI/ Nrk1mczg+sagJNVgXet64wNiYileIi3aQa6G72BcIiXbUoVXQikPwV2JFS8VjggLmeRV 9FjKewZOxU+XfS47eJtaAatFon06F0pp3qdH3M+2RFYFH4UvT3sbVAY+B/cKljTNiW/I 1Kiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248422; x=1726853222; 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=bg1S7MpqFLKynDQMTW/BgVqsjzz9T+4SZvu94a93bN0=; b=VVUAlMtApQwzVpphfJWkS6VdJMBR+5vzC/xnaMPE6zRYGlleWwhMZeej3U6ACyYPad jU+RvUPUb39Cg9Y6sTjPw14iLxUU5W4Qn8d2MCx8up61Wa0ION2G+EEsLhB5ejq9VdiL xhHMT2VYd+ul9pq+HLngqSHFaEoZtWjpgapNt0QiGpX7UACYLFU04HSdQZwn24Y3p4PS Q+WClWU2VL7xoDpAJjNZQaYJ6XjJF+U+foaMhM/u0p05bwZB1OSV3Im63oO4rkIfMgPS LY9piDiuakZB46MCL7/ZNgkr31yrW+BsrR7Emugy7QkV7qFIw3gCZ8OmzJ8im9Nbx6cA ntFw== X-Gm-Message-State: AOJu0YyCrwN/utrb5WKNFr+Y3dHTX+aFKT0aEglcOxjjCRqUkUb6v9Ay nz884Z94+/qeYSLjKE8Sy39MkYrBQFSSP7LLdl3PvhNWSLq7LTBTjVpfGQ33QRk= X-Received: by 2002:a17:907:3e8b:b0:a8b:6ee7:ba1b with SMTP id a640c23a62f3a-a902943de74mr591772366b.15.1726248421629; Fri, 13 Sep 2024 10:27:01 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72861sm890889266b.105.2024.09.13.10.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 9C1255F9E2; Fri, 13 Sep 2024 18:26:56 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum , Xingtao Yao Subject: [PATCH 05/17] plugins: extend API to get latest memory value accessed Date: Fri, 13 Sep 2024 18:26:43 +0100 Message-Id: <20240913172655.173873-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- include/qemu/qemu-plugin.h | 32 ++++++++++++++++++++++++++++++++ plugins/api.c | 33 +++++++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 1 + 3 files changed, 66 insertions(+) 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, }; +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); +/** + * 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 info) return get_plugin_meminfo_rw(info) & QEMU_PLUGIN_MEM_W; } +qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info) +{ + uint64_t low = current_cpu->neg.plugin_mem_value_low; + qemu_plugin_mem_value value; + + switch (qemu_plugin_mem_size_shift(info)) { + case 0: + value.type = QEMU_PLUGIN_MEM_VALUE_U8; + value.data.u8 = (uint8_t)low; + break; + case 1: + value.type = QEMU_PLUGIN_MEM_VALUE_U16; + value.data.u16 = (uint16_t)low; + break; + case 2: + value.type = QEMU_PLUGIN_MEM_VALUE_U32; + value.data.u32 = (uint32_t)low; + break; + case 3: + value.type = QEMU_PLUGIN_MEM_VALUE_U64; + value.data.u64 = low; + break; + case 4: + value.type = QEMU_PLUGIN_MEM_VALUE_U128; + value.data.u128.low = low; + value.data.u128.high = 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; From patchwork Fri Sep 13 17:26:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828205 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362347wra; Fri, 13 Sep 2024 10:29:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUHuigdka/osQMeV1W8agy9t5ZDf2G7UNZamF/aj/QcLxnRqf/Mt9+kebxruvEiX9eCNQbmnQ==@linaro.org X-Google-Smtp-Source: AGHT+IH1i5jSCKb6t9ZwgxZouyrbjWe0n96X0L6LFqcpQbCXsOdhUX6/VDSHFBfpUgQtzdiAF5iF X-Received: by 2002:a05:622a:d2:b0:458:1749:e17b with SMTP id d75a77b69052e-4599d224679mr43890151cf.7.1726248555928; Fri, 13 Sep 2024 10:29:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248555; cv=none; d=google.com; s=arc-20240605; b=U5Yh0K4Zi9PoREZmbZO37ATr8HuS9vMB04GQUtB0ORaY+2Ot/rjTfmDZmHenatMQi1 1Jb4fphpfPJjYe6ReWzlpTS9ApMJ/+7CrY6YTGbpmk/ITEpvJPyKT8MP5li1h10IM5jA HvDn0htHNqnZvh9OU7Z78h0owod4mz1VvZz3cGmppnlw8z/T87me/ikMmoje6hshL6of vronZEtS2n6pbU4Q+jvDvjiwUDZiLcREO84jueHMsr2OTSccM/k2f6Epj4JGbeRY32tL dK3l/0lNkv1DE3WegeQFjkxiPZQpYvjWeyIXJ5vxX5GsBMobWp2ogtZzXUCXKMQyyTqK IjUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ULpurcGomJFFFXGFveTbWvPTjZlX1tphSs0Gpvsy70s=; fh=F5awbK741II+wT+mHTjf48yqF0ogIKVBroCor9WBHkU=; b=KXrhlHMaj/02gSzaIrfGJkl3qtwpF1p4wIbnFWkpQBA0O2+xIFGaOwKzpWjlmJfswo YT8CbLlKgiD605W3nNn54GKX1ylS0D17+yLvCs+HF3TDLzHVp0g9YW1OVPQqrymvqWaE xZzyTzIDquBo9xUo1OlYCruMHSugWXwucr6hRbqJCt1X0cOQXsG2z81zasPJCNk074zE ajbbcsmNeZ/OXfu09O89YeX6lA05Coqo2WPJ3202cCnLVE+oRenFuIDQEypv97cBJsdw YBowt5LygzgxJvvSFK0zvK1idyLWXjtZLMffMKbB0J+HobrVgZ1qUj8cOBDtm57ZvWg6 Oexg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TjyONR+5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45822fa1f2csi153759141cf.535.2024.09.13.10.29.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:29:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TjyONR+5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4s-00073u-AJ; Fri, 13 Sep 2024 13:27: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 1spA4g-0006CZ-BK for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:14 -0400 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spA4Y-0005ud-UY for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:12 -0400 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2f75c205e4aso28588761fa.0 for ; Fri, 13 Sep 2024 10:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248424; x=1726853224; 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=ULpurcGomJFFFXGFveTbWvPTjZlX1tphSs0Gpvsy70s=; b=TjyONR+5oJ4CLd0adPktjCagrT3leHJfAEvubcExyQij7XKGks2SVaZbP3yDwrWhmd kga+5q5QfWZDiY4x0VuH9Ir6A+VJxaSfDBbYabz9Ag3oT39mLhj02llO8JEH3d2m6tIL wO+cL2iZRUmRDsicfH+ygWJfUHfuy8XI4WisS76zUbouQhJTo/o66nqGA6JqQE4PCrpM fjAKEFaErqZnVJ24qbV9UU8JQs/JWegoxa6YyBFHHvafwkOg16z6gUUOa/3RmfnQjrAZ YyL44yAuEOzHgYNNQrqHTk5pXa9V/ie5ZRz2LVH+5KhqeRce5KWhXXDJORlHxnsDMFx8 TLbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248424; x=1726853224; 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=ULpurcGomJFFFXGFveTbWvPTjZlX1tphSs0Gpvsy70s=; b=bH9Q+06+QLVKwVecQhuHey0ALC5EL7NITIircctxxS09pd96VzzXMUMBUvKWSmqinF qoTG0Drkc9Zp+JCm0V2kPh5tZxyHyItdQKeY1qGLUj1mq7nR2DPE97dNKkxQNjR3+mmQ sPph6N0JEQC82sA9A8yWNmyQyGZpqMRI1MayALOH05TD+3tajxJA8A+WVSzLCcJVZlf7 HwovJ86fC7rBX03n1p4dzyEIqHD6fbuQh2oJiSzRklgNxRagMI7RJCPJSG2RSKuvCO8H xCZY6OnlHM9fnUEI4BtGjhCdO7Xp9+pPOMeNmEiPmBb7XMMM8T5MH6V75mOLHP0tQNCM KDmg== X-Gm-Message-State: AOJu0YxhEavniM2+98rwlGqLtZlr0/cMVuKvArNfg1CQ66S7T/oZUXHx jExMYX+zb2ptIldAVUDFwdSwktvbRXtlgPUDWmkIRvnjktSxBK/HawiEp9V92lo= X-Received: by 2002:a2e:a595:0:b0:2f3:fd6a:d170 with SMTP id 38308e7fff4ca-2f787f2e59cmr39386161fa.36.1726248424070; Fri, 13 Sep 2024 10:27:04 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd41cc1sm7879905a12.1.2024.09.13.10.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id B1D4E5F9FB; Fri, 13 Sep 2024 18:26:56 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum , Xingtao Yao Subject: [PATCH 06/17] tests/tcg: add mechanism to run specific tests with plugins Date: Fri, 13 Sep 2024 18:26:44 +0100 Message-Id: <20240913172655.173873-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::231; envelope-from=alex.bennee@linaro.org; helo=mail-lj1-x231.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée --- tests/tcg/Makefile.target | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(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 variable. 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+=run-plugin-$(t)-with-$(p)))) endif # MULTIARCH_TESTS From patchwork Fri Sep 13 17:26:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828208 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362501wra; Fri, 13 Sep 2024 10:29:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXtydhIb1XcZd4+pNSerwrXedKqHIDU/NyBaIsNwOPLJptHHWGKA1Ci0+kqTB3q4OlRJYbz8A==@linaro.org X-Google-Smtp-Source: AGHT+IGJzKrFW4CK5xwiQ9DL5RDHkkMkRd8mt2EXtwd7tBgOLMJeZt8QaQQjudrKBHoT9cKR6mo6 X-Received: by 2002:a05:622a:5e8e:b0:455:a52:926c with SMTP id d75a77b69052e-458602f0032mr109956581cf.13.1726248578748; Fri, 13 Sep 2024 10:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248578; cv=none; d=google.com; s=arc-20240605; b=bWB2aNDdDEAlUF8VN9FOo4J0XkM/Vg/66H6moLMzdw3eDURG76ZegW+wGBht34gmVD tfbkL0FxPM49T677yMdpDi7h49LvOqGx4I1nSTLZgcw2VINWniLe1jZQOn8Dxhxrplbd geX+sDzdvqLm1XVJlL7gWB+ZrSQd6dxPPFBE5vcK9+fSb8DNBILJnLSMpESIs5T9LMI/ dzO2FZv1h7Qz1MFnGst9q6/tfCiEkWMaoBUAZ35a2IVNUF6Aqd0lBezI3tWZrkqdoKSL ja/QtUYpRLXSOCAcXTrqID9ENUydGDIhMho2TIQ8nEKkJzXKS8NMunsVaOldXObuGEBt LX4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XLtSiC/Qmy/Q/dtQX8Zk8sWvmopgnkSy4LkF7QeFpv4=; fh=F5awbK741II+wT+mHTjf48yqF0ogIKVBroCor9WBHkU=; b=Puluhd0PAjSz6AeOMdTrF3eqNOyL2I7TpLLzXpQijFo2s812q07wapLO7AISsBAteR 0r+nFm0ijAaJ1ve0BQDinRkHbHqMqjsHX5TaKHa8066OGz5hFjbyiq0vt2y3uSt22M5q quivjugJLrBeuqvIdnZXanjZVapK2FfFYi9OBYnxFrD7Sn31m4V8qWECu6AP7llZUzA+ 6AOeHCYLniyvXOZk4ywPbLuVpRHTvbcl3jeRxBFu3o5C6rit/8L5mwWJM5YFP7tAoHPc 9zME1Oo3EW0v7aIpG7ujePHtsUAa/eQ+1hv7d27MMgqD0UeesOoaS8pB9CTIEpif6sDe gSnw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JITw5UeM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4583129c0a3si139714121cf.552.2024.09.13.10.29.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:29:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JITw5UeM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4m-0006ZH-Gs; Fri, 13 Sep 2024 13:27: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 1spA4c-0005xs-RI for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:11 -0400 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spA4X-0005uW-R5 for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:10 -0400 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5c255e3c327so2772504a12.1 for ; Fri, 13 Sep 2024 10:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248424; x=1726853224; 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=XLtSiC/Qmy/Q/dtQX8Zk8sWvmopgnkSy4LkF7QeFpv4=; b=JITw5UeMtK/350EYxkHcACmVWMq7lyjDsrc1oUZc5L2gRMN1niIVDqMFDYVZ9hN+5S 0ZWewREjiwIeXw11AskTQyzqUelKEVWF/ZuIdi7amLjaPEIZr5nG4aouebltjHTPXAz/ 3uFTxVsBuAMqKxh12mdv5cgZo38IUwHkXDdiSNH67PiAc6kcPAIH54XHmMVH4THg1sh8 2HAlAJ5Mi0maR3WD+kT5tFiRZzFy8Dn5EmNh4L282MLN6dLUDdxsGGLyd+XxeWtO8ZBb qji5SaYWb3amaiRSSrlWeaZXUzyPIByHkHcAlPuShI9iBr8VDMfgEotc45mGzEfBQUUd amkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248424; x=1726853224; 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=XLtSiC/Qmy/Q/dtQX8Zk8sWvmopgnkSy4LkF7QeFpv4=; b=a/I8sLom+kwZdGE1uLENAhAqDFY/etH7howLdjoA8hyhXyxQPwKsvfJIeJjCAmQIQs EGsuzYkVubW4hqa7L6MK+zLQdwWxL/l2JH9SXNLdzkA9K2vpCGqjIumsPbfEHUZY9Gu/ m4tSe+gKn8zds26KLxgWijk2tfkuk+BAXSs2spyU/Rvj3V017oB7+jexpLfyumpFa2W7 uEz1dNWUqOUdpTqqjE50+yWTFAYhHle54khJOPq9Kyy8ylzdgu89CL/fEYcUNgX7FoEd pzluWZ8O8sUkfzFCR67I88iXa3YvXgT0iOZXC5N7BhX9qoGT/HjG+4rMZvo/MzWQdaXB EVoQ== X-Gm-Message-State: AOJu0YxU36vZETpzkrQe/cx3QRE6Ydx8fuvB6PdJJOeJcQfilqdfTv19 PmiJevHqAcKDu0m4Odp1vFK3RCxXz3DVxFBzOhpujINPOjD0ODMCpQZue9ima9M= X-Received: by 2002:a05:6402:24a5:b0:5c4:b00:5e62 with SMTP id 4fb4d7f45d1cf-5c413e2a27cmr5376289a12.20.1726248423625; Fri, 13 Sep 2024 10:27:03 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c401420b55sm4748991a12.38.2024.09.13.10.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C58AD5FA03; Fri, 13 Sep 2024 18:26:56 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum , Xingtao Yao Subject: [PATCH 07/17] tests/tcg: allow to check output of plugins Date: Fri, 13 Sep 2024 18:26:45 +0100 Message-Id: <20240913172655.173873-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée --- tests/tcg/Makefile.target | 9 +++++++++ 1 file changed, 9 insertions(+) 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= LDFLAGS= QEMU_OPTS= +CHECK_PLUGIN_OUTPUT_COMMAND= # 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 gdb-%: % From patchwork Fri Sep 13 17:26:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828202 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp361793wra; Fri, 13 Sep 2024 10:28:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXiMOpiuduLZOx8WywUC577StpzDWCnAa5+6s71A1GspirbP8C+V32DOz/QM3Dh2tqafrChFA==@linaro.org X-Google-Smtp-Source: AGHT+IF9hcJgetOCIJtQOl04OKBF/o6aPZaxJxaGrXJ6VevpD0Ctm91Juw8cmvfFq6nKhoBzYy/J X-Received: by 2002:a05:6102:e0b:b0:48f:461b:c9ac with SMTP id ada2fe7eead31-49d414b32f9mr6660739137.14.1726248480316; Fri, 13 Sep 2024 10:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248480; cv=none; d=google.com; s=arc-20240605; b=I1N3XsSFH1fL4SGunVk6Y1TcSe1Xdg3Ka7BPvgcZ5w6aZB8aGx1CUubqQZxOgI1R1a uWfDu2uK54ym1TrzelZg8ydutpagtcMrqaOzyj3zapf1RdyxmiUsOf53PdY1CHIb0l7S wrYy7252nQFZfVqJHrmdEsXsdw+s+Nfvkl9X8bdZCGvCEFuFuz9Mlj6NDEAzvtL+0rpO jBPVHzCBQT5OfxTSEucvHT4ZvU3bzquV3xlVCr0nLB3Qwc/C5LZ49yeNfiVKXuJVSJVG FoazTRLWtj/jS1aiy60VSxN5IjUdH3MT8iIuYlHl6bW/tMBNewZpKPYb+wZt1/QDYpMa GYng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tNcKpK3gqW5pd0AiX4NmCCbDvgLi1QOfUkQVya3+J3c=; fh=F5awbK741II+wT+mHTjf48yqF0ogIKVBroCor9WBHkU=; b=LfLkRV6zJ6WnitzUm4gDFqfSkrsHrcbVk6ntz6YQ9Zs6I65Bjk9gLUAcneVtcatiF5 MHxhTQOlsOuXq97SiILvXb7MXY0snlwiFn7MyIPAD4mey4GB8761ijDxCrp1W5Th0OkV M1fZtzKL+xHpm0DzMqLFDg6nIpI5kP7Vadr3jBvig058gmec0RyId8/sA96BnZmLPcct y+J8RxlTsWPXqjzLZqOPS2Lb3+xc1xlW8gyFg6rNVwT0nkTwpcMlT3/du6qerqRDotyZ ecfdrpXXzszM8Jlltd7UpxB9djvu2e2DIkG3DkdLqhrw0WihcBKjcSdg0/OjiqVHsmcQ TtRA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dMhgqKHt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ada2fe7eead31-49c16e3dd66si2508266137.759.2024.09.13.10.27.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:28:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dMhgqKHt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4p-0006rd-QU; Fri, 13 Sep 2024 13:27: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 1spA4g-0006Ci-Bt for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:14 -0400 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spA4Y-0005v0-T6 for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:12 -0400 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-5367ae52a01so1701296e87.3 for ; Fri, 13 Sep 2024 10:27:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248425; x=1726853225; 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=tNcKpK3gqW5pd0AiX4NmCCbDvgLi1QOfUkQVya3+J3c=; b=dMhgqKHttWXwg9Hh6JYeL1Tj8VkZyAbigPLnhy/oIv+rApl6Lv0uhT2bATbqWvIhvm QNhR0b0KaIaeMvBls27WvnIE0lDwgHB0EMIH2AS3Z0X/6Wal+fMman/ISsf/XbvFjvlu W0xuT7GG9jYjXpctWgENIf8LEq48nUfoCOOl12bkmVKMqlkvF8omOM53R7kgx1tmJ0Jc akgUMZKwy/T0tiMjg/sLd/Dlzi/gSFRrpEWGUxeepznASLM0D9XgW6COyBqLnMgG0DVM 14fra2FuRO0SSpE2rMJLrnc4MZX0T+s+a/DoKEY4CAkauZE835VGVq1/X9Q6GmiJcwZk 5VRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248425; x=1726853225; 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=tNcKpK3gqW5pd0AiX4NmCCbDvgLi1QOfUkQVya3+J3c=; b=C4LuD/FH/acL0ZDUDuxqAFRTRZUK1QjkBYG6WhJ5RlIuSEu7d8VgOM+3xbNCR9S2Pb aG5j1xEGhxsylofKYNq2IkutJB8ImTMeaYPMjwhWxDLekcR6/oNCRxvfr83cyJ3q0RCM RYHyuA3+begkCEZAp6F3onHRzplXbBMUO9Vbu+BN522ThnzsYq+2wuEMeUvugvazx/Ak CufjZHqI58QMxUkwSUSyEdNHn4wJgjf4H1jkTQ3cl+YcYXEwstsn8TKns8WzQEIQozj7 a3I1xJgzqvB6XuJF7e0buNhB3sAz0dTwua4Vea6VRbbwB+kZjzceBTDN+f2d8HdDP48K 6ifg== X-Gm-Message-State: AOJu0YzNI4hSey/VbZKN3g6vq8noGZh5OizEJudhnC1Lln2zUConbgpe YksM+XOvBYZvQYx5H16dTUz/fBfSvB0KmIQuPd47ofQs1TrB+RCgtd9HrVEEo+g= X-Received: by 2002:a05:6512:224f:b0:530:aa09:b6bf with SMTP id 2adb3069b0e04-5367fee270emr2138919e87.24.1726248424436; Fri, 13 Sep 2024 10:27:04 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25d400afsm894067866b.189.2024.09.13.10.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id DCE115FA0F; Fri, 13 Sep 2024 18:26:56 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum , Xingtao Yao Subject: [PATCH 08/17] tests/tcg/plugins/mem: add option to print memory accesses Date: Fri, 13 Sep 2024 18:26:46 +0100 Message-Id: <20240913172655.173873-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12e; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x12e.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier By using "print-accesses=true" 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ée --- tests/tcg/plugins/mem.c | 69 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) 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; +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 = QEMU_PLUGIN_MEM_RW; @@ -60,6 +65,44 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, } } +static void print_access(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, + uint64_t vaddr, void *udata) +{ + InsnInfo *insn_info = udata; + unsigned size = 8 << qemu_plugin_mem_size_shift(meminfo); + const char *type = qemu_plugin_mem_is_store(meminfo) ? "store" : "load"; + qemu_plugin_mem_value value = qemu_plugin_mem_get_value(meminfo); + uint64_t hwaddr = + qemu_plugin_hwaddr_phys_addr(qemu_plugin_get_hwaddr(meminfo, vaddr)); + g_autoptr(GString) out = 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 = qemu_plugin_tb_n_insns(tb); @@ -79,6 +122,16 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_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 = g_malloc(sizeof(InsnInfo)); + const char *sym = qemu_plugin_insn_symbol(insn); + insn_info->sym = sym ? sym : ""; + insn_info->vaddr = qemu_plugin_insn_vaddr(insn); + qemu_plugin_register_vcpu_mem_cb(insn, print_access, + QEMU_PLUGIN_CB_NO_REGS, + rw, (void *) insn_info); + } } } @@ -117,6 +170,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", opt); return -1; } + } else if (g_strcmp0(tokens[0], "print-accesses") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &do_print_accesses)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + 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; } + if (do_print_accesses) { + g_autoptr(GString) out = 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 = qemu_plugin_scoreboard_new(sizeof(CPUCount)); mem_count = qemu_plugin_scoreboard_u64_in_struct( counts, CPUCount, mem_count); From patchwork Fri Sep 13 17:26:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828207 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362492wra; Fri, 13 Sep 2024 10:29:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVtoNkOkfPGfMBgkvaQfNmAglvzcRdU7tSta4PtPhEp8uiT40OC/1I9B2mZ+3j/5vsfEdK7jw==@linaro.org X-Google-Smtp-Source: AGHT+IGENK/Ls/P8EtWgxJsHVCHgpxbQgilUBw5SMuPlwtKYprqt45UbBqgYUByw0Yj5SHOYar1J X-Received: by 2002:ac8:584d:0:b0:458:3e20:65d3 with SMTP id d75a77b69052e-4586045d335mr93197741cf.60.1726248576644; Fri, 13 Sep 2024 10:29:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248576; cv=none; d=google.com; s=arc-20240605; b=dgDXAgFdIpOdl1EJUliCdpSR4UVmBwzf4FkEAQ9v2Mr+jj9HLbxiCZg5uKNgGicK68 VePdFiA3XDobr2kt4dCoRrIOCPRLk0DetSaXEhCgAjXZuNVkHG2WkOBB6LBOmBkaZvO5 /S6auRG5FDLMxKNofwu5j0HYSYF9ULHpKN0vQvcWFeOTFOHzgFwPaty27nuWCKu+dc+T CzUWUbAhx6co5zv9C4qdax/X7MzSLYBbgEt8kutYas7sHHrKdlbiLlRPQpOyUp5OVv9s U2OeDUwGo2YRP17W3/4XSsVOvFS/xvTK31EIRxK3qFA0KIhQ8G72HibbLbXUY6Mm9EQD mnfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=reQ0RNQCypKAdEXf96hopek227oB6f9dFG3OWWq4314=; fh=F5awbK741II+wT+mHTjf48yqF0ogIKVBroCor9WBHkU=; b=EmwcM0xIYAKqgHoUcDXIqSBAuf5n/R820zvQubIeX0ybPPUXy62U+971kkqRVx/B6J O3xuwZqZ4+cBmhvmErKg4G+bEKUWExFWtk0fn+qTTW6IMRHapA0PEpmmhCFvxBDYbo+m UVBMrnVlQ7myrbqWrDTpefzuF9Ro4p2VtceK5ldb5DN67FLvv/W0zTVSZX8HcXhQ23wE Cl70IZhs2hb8oSTqnqf+Z7uAvbzK78SW2gh9Gew2KGA6wjrprmP3KkXJhAgnQuyCqMBN F4XqnQt5lvo4EdOTECHQz8+tNM9sZIUT0DrCbhJs5qHdZAUSiu4dV7t4sU8B9QJQUD2r FIhw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L2fz0Zuk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45822fb48f8si150370781cf.572.2024.09.13.10.29.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:29:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L2fz0Zuk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4t-0007BE-JZ; Fri, 13 Sep 2024 13:27:27 -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 1spA4h-0006I9-JT for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:18 -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 1spA4a-0005wD-5X for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:15 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a8a706236bfso61080466b.0 for ; Fri, 13 Sep 2024 10:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248426; x=1726853226; 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=reQ0RNQCypKAdEXf96hopek227oB6f9dFG3OWWq4314=; b=L2fz0ZukWQKEcLaE6uA4lEip/p/c31x2jZ1DAWXNssn+PQonQzNGsXrvTr09llE3vv CONKR+hNm4eQK+rYVU9UMyGKp1vJOqOYB0zEtX0TRFK7IqAiIDgBThra7TyULy9567qp bMb14JOGlv3pcfK5339bN6TtwAd5MJDvyPNtfIx0EuHxioKQm12GL/lH8oWt2T6ipO2g kqCzn+OnOWCcvrkiO5rcUsaZ35AvmRCRahibHrZLadtSQOKOFk+b05vQYiHAxXZ3n9oJ +AldFLvFf1nTm9CIygfkmDVdVwnVAgwadTmnFqvrGhFreDlN92BTs7LIvIG/wb4z4wLS 9taw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248426; x=1726853226; 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=reQ0RNQCypKAdEXf96hopek227oB6f9dFG3OWWq4314=; b=K259OmmhM0ArndG4id2VnSQRNJtloYEVyS9uKXhlVMttTJu/e+l0XSjGZyYGsNQwmb C5fvN5ly8Mk/Uz/nMlNslpT6RcuM8uDXxrXuVa2f2W2jPbNi87yltC6xOlcK3A/lxOBD aJ9w8CWhX92Rcb1pGBF9KQNGD4yJqDHDTmUu1cJprtV6upNhB7h6H6Sl4oIkRF+ajyax 1HItrFGRsb+LVPUJqYxamtYOtEmhGIShhE5yaljZfF538Umz1TxlzLkg06P8p4duvChT fsEAdcrxwDw2t41/dBgH3p6jYNWIvuMWUs6EYh3mv0pDRRqMGV32MZPIf9g9nb9If1qC 41LQ== X-Gm-Message-State: AOJu0YwAOuKTu4H1TIRKon1vBPVTT5EZyNK48Pk8pU/0sTnsh0mJGYwA Cd2rTgwfgMT5LH6UMcQBeMBm4cxwbMX1H9CvFR78kMNSl7zk4caJQiCMrd9/eBw= X-Received: by 2002:a05:6402:2551:b0:5c2:6d13:c583 with SMTP id 4fb4d7f45d1cf-5c41e1b5354mr3294265a12.28.1726248426227; Fri, 13 Sep 2024 10:27:06 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd8adaasm8236187a12.80.2024.09.13.10.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 044945FA16; Fri, 13 Sep 2024 18:26:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum , Xingtao Yao Subject: [PATCH 09/17] tests/tcg/multiarch: add test for plugin memory access Date: Fri, 13 Sep 2024 18:26:47 +0100 Message-Id: <20240913172655.173873-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 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=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 Message-Id: <20240910172033.1427812-7-pierrick.bouvier@linaro.org> --- tests/tcg/multiarch/test-plugin-mem-access.c | 177 +++++++++++++++++++ tests/tcg/alpha/Makefile.target | 3 + tests/tcg/multiarch/Makefile.target | 11 ++ tests/tcg/multiarch/check-plugin-output.sh | 36 ++++ tests/tcg/ppc64/Makefile.target | 5 + 5 files changed, 232 insertions(+) create mode 100644 tests/tcg/multiarch/test-plugin-mem-access.c create mode 100755 tests/tcg/multiarch/check-plugin-output.sh diff --git a/tests/tcg/multiarch/test-plugin-mem-access.c b/tests/tcg/multiarch/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 output. + * + * 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) = 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) = 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 = *((type *) data); \ + volatile type dest = 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] = {0x89abcdef, 0xf1234567, 0x55667788, 0xf1223344}; + uint32x4_t vec = 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 = _mm_load_si128(data); +#else + uint32x4_t var = 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 = 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.target index fdd7ddf64e..36d8ed1eae 100644 --- a/tests/tcg/alpha/Makefile.target +++ b/tests/tcg/alpha/Makefile.target @@ -12,4 +12,7 @@ test-cmov: EXTRA_CFLAGS=-DTEST_CMOV test-cmov: test-cond.c $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) +# Force generation of byte read/write +test-plugin-mem-access: CFLAGS+=-mbwx + run-test-cmov: test-cmov diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.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 += semihosting semiconsole endif +# Test plugin memory access instrumentation +run-plugin-test-plugin-mem-access-with-libmem.so: \ + PLUGIN_ARGS=$(COMMA)print-accesses=true +run-plugin-test-plugin-mem-access-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND= \ + $(SRC_PATH)/tests/tcg/multiarch/check-plugin-output.sh \ + $(QEMU) $< + +test-plugin-mem-access: CFLAGS+=-pthread -O0 +test-plugin-mem-access: LDFLAGS+=-pthread -O0 + # Update TESTS TESTS += $(MULTIARCH_TESTS) diff --git a/tests/tcg/multiarch/check-plugin-output.sh b/tests/tcg/multiarch/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 output. + +set -euo pipefail + +die() +{ + echo "$@" 1>&2 + exit 1 +} + +check() +{ + file=$1 + pattern=$2 + grep "$pattern" "$file" > /dev/null || die "\"$pattern\" not found in $file" +} + +[ $# -eq 3 ] || die "usage: qemu_bin exe plugin_out_file" + +qemu_bin=$1; shift +exe=$1;shift +plugin_out=$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.target index 509a20be2b..1940886c73 100644 --- a/tests/tcg/ppc64/Makefile.target +++ b/tests/tcg/ppc64/Makefile.target @@ -55,4 +55,9 @@ PPC64_TESTS += signal_save_restore_xer PPC64_TESTS += xxspltw PPC64_TESTS += test-aes +# ppc64 ABI uses function descriptors, and thus, QEMU can't find symbol for 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= + TESTS += $(PPC64_TESTS) From patchwork Fri Sep 13 17:26:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828212 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362663wra; Fri, 13 Sep 2024 10:29:57 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXCiIVcphYtFpqogdPTRw38jXlzb/E/+tpqzMG3UcoydYpZeU306Ynj8vQxooVCc2bdmvjlwQ==@linaro.org X-Google-Smtp-Source: AGHT+IGiiwZjt39ROb2hkZKGuPFNG/v9Kg+cSuoo3TiFUUWMXxwK3CTAXqcRcvQE0Squ3sU8+KnX X-Received: by 2002:ac8:7c52:0:b0:458:306c:1da3 with SMTP id d75a77b69052e-4599d23c4eamr62744621cf.19.1726248596874; Fri, 13 Sep 2024 10:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248596; cv=none; d=google.com; s=arc-20240605; b=RvZ2+KyDdltXNs+Cn91ybJhN17MJ8vyu2nFMXP7x6UpqAlU5zAGnV6UjICO2bMgG/S PD7jiJy6VGg5t+CJgbsZROzVyylyw9mDfgum+KS8+JEHAPihGc7lJLtyP+Tut+z60Q5J Zgw+47j75u3EavJzYv53Vm7L25uHWnxBbHXMu0bDcqUKy9P9Xt3XC5IUrn/CWWufJ93W fakYviwH0xkHvUMoCziziB0FAbBYWM1RrLbIkePbFwvYaXmh3LOS34ar3JtzTChRegRm SeY+YAj37PKqls0iO2AbR8dD+7tgCd8ldG5ntwRj6XYaqefRwwO0gJ+AgKvLIXsMe51L iPdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qJmFYzrzBJkStmV1LFnozcM8CHfOVSOnWWdPSAqY7Qc=; fh=Yn9Rr5YRWo7nHBEBYPErLs0SzN9tKEIm+tjOgOQtjBE=; b=Pgb5QwCJ007dSMnXXKcundMChfnmTIpgbG6egO0r0dC5looOaNo6XvmMoWcX3mgg8I uptwaAvE5XOOXjvuXUtxs9VltFldJGBQsoqqVqYMFfgOU4qTIEpkuFLiyjq4neMLCv7k 3PLa6evfP0AskMN0014xXyxSJuvW/sbM2AVnRWMUszXQnLa5AdK/bradsYlGrevrAD7S wsL3sfVnbBiphffDDQkSTWSvlsfSgzlesBHyZDGTkjD4jqN+w0j7CW5J7iqLqASiNk1p c5geKxMZFZcr+keRVB636BwpLQQxqKXzhF7CLvTzFTWUGYHDW3Gjo0AEu4p8ODYHsbUu 37BA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qw+Vtzd6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45822f3e8a1si153461711cf.323.2024.09.13.10.29.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qw+Vtzd6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4q-0006ud-Ey; Fri, 13 Sep 2024 13:27: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 1spA4g-0006CO-AI for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:14 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spA4Y-0005vL-US for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:13 -0400 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5c4146c7d5dso1401064a12.3 for ; Fri, 13 Sep 2024 10:27:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248425; x=1726853225; 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=qJmFYzrzBJkStmV1LFnozcM8CHfOVSOnWWdPSAqY7Qc=; b=Qw+Vtzd6IVAGId4iOttExRLVzUDJ7++KJPl2YS6RliwFJTJjVCrZ0bQk5yUWmOJgvb 5p36vx9A/W/wzy/S31W5bzvdqD0cjPOYfzyDS29E6KH4xFSa97x5LLfnaxGoRRmYef/R /2yRKDjIv8jGP0T2uKIO338yRGGBGrzINXWewmvHII+WfCrPYgQgLCIeFYg8xUeBL8dY n+y/Mfrt7Rhld3BvxLVcanwTboMp7tlMxs3XaKoJvtvQVTOhSrmLskjyj2ZEtf59ANY0 5J7p6/dS2TSMmbhBM9gAKh4z8fV+ZxQtx8tcJPTEFW6tQchHBRh/dVhy9qr1nTzo529F oASg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248425; x=1726853225; 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=qJmFYzrzBJkStmV1LFnozcM8CHfOVSOnWWdPSAqY7Qc=; b=dwTqNJPa6o/qlRwLkP3fW0idqsCj8Y2yxeT1sHKG1xsc1ZF/vmUC6OropWzUmltKx0 2AptrQpHCn16zIN0n73noOd/BDEajN7lfH0QbsQVTjUGrxHvLOhe/Ft0K6EVnD5Yw+oq rDFWyPE9hSVJXB8EN9A+LVoNJWI1fXocaesN5D7+5/HHaufIjxI5wfhF3dWYIzqVbcO7 r3BGXCRQLIkrQmUoICLSHZAQSKlcS/BrsKFJmscw4jiv/V7/vxdriAZASgJLVODvAcH7 UA5SsRH8hRWurhkhJ2zoN9j8J8uwLTYnWSUnbf2r8mbbov5anGdXtQ4bEQa/7JHQjDF2 xqUQ== X-Gm-Message-State: AOJu0YzCwU5r6ZY9LH/6LCSm4vZFXOO+UnBsMf7mGJfcR1WjSaDXTzZ3 gXz0bbGqYwPynCUKmYn/vj9bdtzt8uXy+Je56w/OO5KZAF8451yR7uptCLaUtM0= X-Received: by 2002:a17:907:25ca:b0:a90:348f:fad7 with SMTP id a640c23a62f3a-a9047d3dd87mr313071766b.38.1726248424761; Fri, 13 Sep 2024 10:27:04 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25830efdsm891313366b.41.2024.09.13.10.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 1D6275FA2D; Fri, 13 Sep 2024 18:26:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum Subject: [PATCH 10/17] tests/tcg: clean up output of memory system test Date: Fri, 13 Sep 2024 18:26:48 +0100 Message-Id: <20240913172655.173873-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52a.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 Message-Id: <20240910140733.4007719-20-alex.bennee@linaro.org> Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Bennée --- tests/tcg/multiarch/system/memory.c | 47 ++++++++++++++++++----------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/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); - ml_printf("Filling test area with u8:"); + ml_printf("Filling test area with u8 (%p):", ptr); + for (i = 0; i < TEST_SIZE; i++) { *ptr++ = BYTE_NEXT(count); pdot(i); } - ml_printf("done\n"); + + ml_printf("done %d @ %p\n", i, ptr); } /* @@ -94,7 +96,7 @@ static void init_test_data_s8(bool neg_first) *ptr++ = get_byte(i, !neg_first); pdot(i); } - ml_printf("done\n"); + ml_printf("done %d @ %p\n", i * 2, ptr); } /* @@ -105,9 +107,18 @@ static void reset_start_data(int offset) { uint32_t *ptr = (uint32_t *) &test_data[0]; int i; + + if (!offset) { + return; + } + + ml_printf("Flushing %d bytes from %p: ", offset, ptr); + for (i = 0; i < offset; i++) { *ptr++ = 0; } + + ml_printf("done %d @ %p\n", i, ptr); } static void init_test_data_u16(int offset) @@ -117,17 +128,17 @@ static void init_test_data_u16(int offset) const int max = (TEST_SIZE - offset) / sizeof(word); int i; - ml_printf("Filling test area with u16 (offset %d, %p):", offset, ptr); - reset_start_data(offset); + ml_printf("Filling test area with u16 (offset %d, %p):", offset, ptr); + for (i = 0; i < max; i++) { uint16_t low = BYTE_NEXT(count), high = BYTE_NEXT(count); word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0); *ptr++ = word; pdot(i); } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); } static void init_test_data_u32(int offset) @@ -137,10 +148,10 @@ static void init_test_data_u32(int offset) const int max = (TEST_SIZE - offset) / sizeof(word); int i; - ml_printf("Filling test area with u32 (offset %d, %p):", offset, ptr); - reset_start_data(offset); + ml_printf("Filling test area with u32 (offset %d, %p):", offset, ptr); + for (i = 0; i < max; i++) { uint32_t b4 = BYTE_NEXT(count), b3 = BYTE_NEXT(count); uint32_t b2 = BYTE_NEXT(count), b1 = BYTE_NEXT(count); @@ -149,7 +160,7 @@ static void init_test_data_u32(int offset) *ptr++ = word; pdot(i); } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); } static void init_test_data_u64(int offset) @@ -159,10 +170,10 @@ static void init_test_data_u64(int offset) const int max = (TEST_SIZE - offset) / sizeof(word); int i; - ml_printf("Filling test area with u64 (offset %d, %p):", offset, ptr); - reset_start_data(offset); + ml_printf("Filling test area with u64 (offset %d, %p):", offset, ptr); + for (i = 0; i < max; i++) { uint64_t b8 = BYTE_NEXT(count), b7 = BYTE_NEXT(count); uint64_t b6 = BYTE_NEXT(count), b5 = BYTE_NEXT(count); @@ -174,7 +185,7 @@ static void init_test_data_u64(int offset) *ptr++ = word; pdot(i); } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); } static bool read_test_data_u16(int offset) @@ -198,7 +209,7 @@ static bool read_test_data_u16(int offset) } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } @@ -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; } @@ -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; } @@ -365,7 +376,7 @@ static bool read_test_data_s8(int offset, bool neg_first) return false; } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i * 2, ptr); return true; } @@ -398,7 +409,7 @@ static bool read_test_data_s16(int offset, bool neg_first) return false; } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } @@ -431,7 +442,7 @@ static bool read_test_data_s32(int offset, bool neg_first) return false; } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } From patchwork Fri Sep 13 17:26:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828210 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362555wra; Fri, 13 Sep 2024 10:29:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWwWwfQICu3GzEC3xH3sU8PBlclf8YiNCaGv4yRXp1cBpXrIUnnGUCXuAd55dhKDiaNrNO87w==@linaro.org X-Google-Smtp-Source: AGHT+IHDAZXVfNOuq89ReTJC1ststzPVnAlA5nLcYx+HYqFig4bgTTzn/SWgxD+boSpOJPsfLA4I X-Received: by 2002:a05:6102:3a0b:b0:498:ea30:6bfb with SMTP id ada2fe7eead31-49d414eaaf3mr8991839137.14.1726248584300; Fri, 13 Sep 2024 10:29:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248584; cv=none; d=google.com; s=arc-20240605; b=UourNGrLWcB/upN8MmWgvbD7hvUrMIuagm3WC7kOZZvJl1ZGkhwrGzSIehhDJxHg1/ AuVkJBfU8VV1L1H0Dh7hC8jpMuGfWKAgrybyW5FWp4kdAHDFOyMGtyO1wZQ58zHxHnq4 jHZ821rmyUi8E8oW9xYFoKaDxpL8I8X8tEo1kuBrt2sLpMHPBkmXYaFYM9ZIqZcpq6nk 9uek9uHDnYuCGFk31geGb5y1roI3xyN9YP4aoW8MYeGp1ufIBH2J2iujsXs4Q1mRQyZp 7GxqI56pYfi/QVsruHjYVjBMb1Z/394sn7x4JXPWnTUgvenZnOggLGJdE6At7CIg4iKY F9kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nKDdDxN3APIqbfrXr39czdsb/f5XxemGM9ivAMoMPDg=; fh=Yn9Rr5YRWo7nHBEBYPErLs0SzN9tKEIm+tjOgOQtjBE=; b=WNyXubCigGJu4MrAu/5njU/6yPT4Nveixx9Ei0t19YpLPk/st0CphkZzLnsnuj3IG4 /NSBcZlng4MjkN3Glja6i1aftwpkY/W5uWUfp/Z/6IvuKDLBenPfvKp87go3wG6wrtvI oHizPIfDO+PWrqlRGfR9i8zkiSZAr6HI+yH04bqZ74Vk/7v2McXZaFT39VImSEPXpTvc tI1QqRYBcBjvNb754Y3JzS50kWuxknubesEn7zobln4P50Dux84penHeo1LCdJzGCe9m jKFsrotQvKNQRiUsw9rHSr9eGseuGlJ//FONl0m2KznSLslFUTTbx67rVfMeS4mfLupk ce7A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fPBx9TEI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ada2fe7eead31-49c16ccddc0si2490961137.197.2024.09.13.10.29.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:29:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fPBx9TEI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4r-00070F-Mi; Fri, 13 Sep 2024 13:27: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 1spA4l-0006Zo-W2 for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:20 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spA4b-0005wt-SX for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:17 -0400 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5c4226a5af8so1034710a12.1 for ; Fri, 13 Sep 2024 10:27:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248428; x=1726853228; 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=nKDdDxN3APIqbfrXr39czdsb/f5XxemGM9ivAMoMPDg=; b=fPBx9TEIQb3ACTGpLP9oYdwHqCVs4seMfMKYpSOhyjeo2+HN1x8FFdxZvc/L1z1tZD ogwnA5rdxIVmcY7nqbhR2H6oSCJvAu5eVQfj9JJlo5ilKhzuNTm+RzixJHT673G02XGU +bE7D9Gv9PM/WZqfm1NYJTSfqpfyt1EMdBfJsbejiGfRc5z7YRzDyxIVtu8wdwK3UArE OM2I6JflhWcVqZtMzheE32bgdhLoDRlkvaivv1gmRAPDgOBxkRD+8ZdOoly0M4MELPn3 H6oFBjm33Q5u7pel/Ld+/vYc2mTGWtNpgYkorGncdWFAbCNB4wUvf6wOVOesRWqEU8sk LS2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248428; x=1726853228; 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=nKDdDxN3APIqbfrXr39czdsb/f5XxemGM9ivAMoMPDg=; b=W3aQGyjgdZTPLmQ9wDk+MtOI47ktZWx/Epwf70XrKuWBhPY3yd9G6VYf3s1zUqAZ0m oue5DOfbqw4N0Pc0kY6v9PUEcOfmgbIRkpra33kXvGxBqPnRwMAe2+5vnYflZ30//owk pIfLYNWA+4xTNci+R5sS8VCqKzF+/hBuFPTRYIxTrf6KzfVs+i+qcM65WwU9qlDspkDA IH/ngVNkrbnt0EBPqcIlw8lwLhdcLEu/KiR55cTcXDWpFf6G+hXKWlCow3LbLe+Pqf2U 5i+SSQUCzDwQdcQsCXQQRIv7FhEQ30oRKlUYInXJGSCeZSEPpI6UIOHlmFEPQS+Z6Bew 3CmQ== X-Gm-Message-State: AOJu0YwxNlDPj1ODpfFV1H7u/FGqcKfEoz1T1qUD0E/fAz24gPFi9qCw EcEEmDvgzVeZGk86ATDu/n7zdhNPBQKJRiklwrPYus2X3lDFu0aBq/6+EKXj0TQ= X-Received: by 2002:aa7:d9c4:0:b0:5c0:903e:963a with SMTP id 4fb4d7f45d1cf-5c413e5367cmr4076130a12.29.1726248427640; Fri, 13 Sep 2024 10:27:07 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd8cc28sm7886984a12.83.2024.09.13.10.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:06 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 3295C5FA2F; Fri, 13 Sep 2024 18:26:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum Subject: [PATCH 11/17] tests/tcg: only read/write 64 bit words on 64 bit systems Date: Fri, 13 Sep 2024 18:26:49 +0100 Message-Id: <20240913172655.173873-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52a.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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. Message-Id: <20240910140733.4007719-21-alex.bennee@linaro.org> Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Bennée --- tests/tcg/multiarch/system/memory.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/memory.c index 8f2371975d..680dd4800b 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); } +#if __SIZEOF_POINTER__ == 8 static void init_test_data_u64(int offset) { uint8_t count = 0; @@ -187,6 +188,7 @@ static void init_test_data_u64(int offset) } ml_printf("done %d @ %p\n", i, ptr); } +#endif static bool read_test_data_u16(int offset) { @@ -254,6 +256,7 @@ static bool read_test_data_u32(int offset) return true; } +#if __SIZEOF_POINTER__ == 8 static bool read_test_data_u64(int offset) { uint64_t word, *ptr = (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 /* Read the test data and verify at various offsets */ -read_ufn read_ufns[] = { read_test_data_u16, - read_test_data_u32, - read_test_data_u64 }; +read_ufn read_ufns[] = { + read_test_data_u16, + read_test_data_u32, +#if __SIZEOF_POINTER__ == 8 + read_test_data_u64 +#endif +}; bool do_unsigned_reads(int start_off) { @@ -476,10 +484,14 @@ bool do_signed_reads(bool neg_first) return ok; } -init_ufn init_ufns[] = { init_test_data_u8, - init_test_data_u16, - init_test_data_u32, - init_test_data_u64 }; +init_ufn init_ufns[] = { + init_test_data_u8, + init_test_data_u16, + init_test_data_u32, +#if __SIZEOF_POINTER__ == 8 + init_test_data_u64 +#endif +}; int main(void) { From patchwork Fri Sep 13 17:26:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828203 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362028wra; Fri, 13 Sep 2024 10:28:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWeG1sRusAw5JS0Mr+7OYzZkMCL56Z837es1a9kVEPLGpvYrEmIkvA/kPFjH6MFixw3vWlrxw==@linaro.org X-Google-Smtp-Source: AGHT+IH20F6hD1xisbZH35tJ7qzPBC4Bn4jUelTDx3Q/sPJeLzZIBhXJ4Cv1qaB72wLGXpcLzGwl X-Received: by 2002:a05:622a:24e:b0:458:34b4:7cd with SMTP id d75a77b69052e-4586044e784mr100624281cf.58.1726248514394; Fri, 13 Sep 2024 10:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248514; cv=none; d=google.com; s=arc-20240605; b=fyvlD6gDjqH0DoRkFTmlo2KsuBw7/r8uFg28pFn59C6MEKeFsBdgdHmsflyEKl04ug MKqaFSkUpcSmw/CPZ3fZkkLs/RdHaMoSZmWivy1ykI8eiJe0UtXa+D7TsrJghHqGvDZe ImIovMqlB+50GHy3x+zh1CqPD6GaZx00sVjo6yckqORyUj9OsnQ5C+itBSHUH5YVGemN ximw6uJL8TPm6zkDegUQuUi5Hdr31XdcN4i3ZF8+Uu1M3Leiz2g8uNGmW+wXP90y1Hvj QIyjt0fm3EhRNWm7cjvSiKF2Ry8AZefK3YGG1lKislrPx+eD0BrLWYolJkBQldIJcwoK y/pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KsHs41jQS6tBRZCgUdTKbBtzyuLG6Q+tQiFLGPFknkg=; fh=Yn9Rr5YRWo7nHBEBYPErLs0SzN9tKEIm+tjOgOQtjBE=; b=LALCbhXVM6FkoHYxQtqIbi3WfjLZu+2NuB5g9VtvayqSBYSVJW8iSTb8qwo2g9fKrZ t9mt00LNIcmyw8XizxabTKZUc8KudBpVZC0pzzUiHZxI8iUlVX+FlXzicjNOq/izd6fd THZwT3nxr4kfx8k9SEiHg2l3RCk+AFWl6mzxSfwz4IPXLeSSsxpca4n62UfSncTX6YqO UUpBlOoQ4gRKSyptvEUvwqtFb+uJpVVqUe78JXBwnGu0XYu8MFaTpiL5fN3oTeGwbHSj /oGs7JDAjnta1qRan0PpwMFqy+x2xM+QPAG3PNQP4HooJfS5b5Y9sAXFbuMbGZQ1TVki 2Y4w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KDI3uMmA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45822e623ddsi162110011cf.62.2024.09.13.10.28.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KDI3uMmA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4q-0006w8-Mt; Fri, 13 Sep 2024 13:27: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 1spA4l-0006Zh-VB for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:20 -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 1spA4d-0005y6-Sl for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:18 -0400 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5c413cf5de5so3000398a12.0 for ; Fri, 13 Sep 2024 10:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248430; x=1726853230; 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=KsHs41jQS6tBRZCgUdTKbBtzyuLG6Q+tQiFLGPFknkg=; b=KDI3uMmA7d4T53D9UFIX1baVVjMi5AJjM7nfZWJl94KrZexKIwZo65CBVEgHKePH+f GT3ciE5XhhQdkwknJqcwc3pvXOIqnrRhzwRiS+KkXxd/dcE+cF3+UxeHAHeS7q7I1iTk /Ow0k/Hl1tDrk+dECvBJFbeqh+aTxNdsXSH1NHoav7JwYVNVgQbhoTWILKW7zTM4wvFD TucmHp/5qYkLuuRUJqr9EG6/V0izeiEtf2W4rE636/ngLbaPoaNNeNI69Pk2hElmNCNw b5/lWL0LKp4Klbp0RPDeNGKJDS9YYzwbKBeZ813jHpLshY/P4iftrRNlu0RxZXfSRhC5 bOoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248430; x=1726853230; 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=KsHs41jQS6tBRZCgUdTKbBtzyuLG6Q+tQiFLGPFknkg=; b=kJd0ns44TT5U21gA6kJ2wiVwNvenSHBIPU/TCd6S8VmhdldOfQ51B1bkDd2QG7mHPy 6ApjDB3eHYalh577DQlRqiNliRDRCL91gRUCMc9zpEC+Z6aiPZSoj2AjMZv2m0tc0Nx5 RTq/89TpK1QIhd5WOUUC2ZZjKtODZ9HKXJvRCJRFFit9mhN4NHi1Uycu93uHHM/whxTw PhVEBlP4fhrYvUpdzgJyQhRNN9uuqpZaNrkgSQswjAG3Dx6Usxqzt6eiu1sV0tQNgeJ2 d8x30IYmwPfuYtzp8uNYQNFMcjJHiktcEeH4P69c4KYOfbF2Dyd/IZXZmX++YXR3MBP1 qWyw== X-Gm-Message-State: AOJu0YzDTb6MPvv+4ZkR3Kb80Ctlxn5y/EXIvHK9gdaeEE/GYz0R4SjU Q1cVhq2q18G1BMHb0OwlgBUA8GGhDs1yOeFAA8EJ1g2fK1Q7sfhCrejL7aa7NxA= X-Received: by 2002:a17:907:d5a2:b0:a86:96d1:d1f with SMTP id a640c23a62f3a-a902943a557mr705628666b.26.1726248429541; Fri, 13 Sep 2024 10:27:09 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d259528ecsm892292666b.67.2024.09.13.10.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:06 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 49A515FA40; Fri, 13 Sep 2024 18:26:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum Subject: [PATCH 12/17] tests/tcg: ensure s390x-softmmu output redirected Date: Fri, 13 Sep 2024 18:26:50 +0100 Message-Id: <20240913172655.173873-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The multiarch system tests output serial data which should be redirected to the "output" chardev rather than echoed to the console. Remove the unused EXTFLAGS variable while we are at it. Signed-off-by: Alex Bennée --- tests/tcg/s390x/Makefile.softmmu-target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tcg/s390x/Makefile.softmmu-target b/tests/tcg/s390x/Makefile.softmmu-target index f60f94b090..ad681bbe40 100644 --- a/tests/tcg/s390x/Makefile.softmmu-target +++ b/tests/tcg/s390x/Makefile.softmmu-target @@ -1,6 +1,6 @@ S390X_SRC=$(SRC_PATH)/tests/tcg/s390x VPATH+=$(S390X_SRC) -QEMU_OPTS+=-action panic=exit-failure -nographic $(EXTFLAGS) -kernel +QEMU_OPTS+=-action panic=exit-failure -nographic -serial chardev:output -kernel LINK_SCRIPT=$(S390X_SRC)/softmmu.ld CFLAGS+=-ggdb -O0 LDFLAGS=-nostdlib -static From patchwork Fri Sep 13 17:26:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828213 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362706wra; Fri, 13 Sep 2024 10:30:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX6jU8Q5NTQBpYMCIuUxrSaoCNO4wSV0UG/gAhtI09OxSh5dmRb/+eR9gr4j8zpML2OtjZBVA==@linaro.org X-Google-Smtp-Source: AGHT+IHwxHbZJT7EdquoX5LT5GfStl4KUuzXUiO4Uhc7iZOxGryjdHfRAvXvASvy0hItY5hZrEzq X-Received: by 2002:a05:620a:4620:b0:7a9:d171:62db with SMTP id af79cd13be357-7ab30d1529cmr538241585a.11.1726248601680; Fri, 13 Sep 2024 10:30:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248601; cv=none; d=google.com; s=arc-20240605; b=Dra/VDp8zPesGi/jEhKUZnt3YKZtKItwoBoPeCQ8JV9ek+pC7eEEcH4haMwdvag4Dx 37EVwtM2mNbpaVisaMVvm4Ampk9dPEbYVCNfELJQvofYEpbwQxV/3xgy3IWIfHf/FwqR hreRwVWZpiMrtVjVSTU34kI9cbsRDmxhxZlwcY55Mo8gawX00bHGqZytVNnrI+AZHRLF sVt8ybR0zFPBKdov2pn6x6JNx2ZsydTxRMdqEbTZaQVXLewvyC5hooBWp7mRzYn3rLEZ 6PI7PGiZQPQ+/rEI/Likd9A46arlYncwOH7whVGUJ0OvYddlQbO6T20cY79vTqP9wZ2+ Qo5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VtGynklwfAQu3ROhwrXRdqcRVrQbQrKUw1qc30A1YZY=; fh=Yn9Rr5YRWo7nHBEBYPErLs0SzN9tKEIm+tjOgOQtjBE=; b=BEeSKPKPgIVo4TkVUVEZa8R0YBD/4if/itUjgTUdbjkqWxVRrkIvyzalBI/sc2Z4hc 3Ze+SN+9PN6y58wyzgL4I7LtGehOgCT82Ju0hRgZXX6+VSrmXG0k8/loYYvnNQZAtT8L dxJxo9j5OqINEYB0a447SVg5CN1t3vg5uXUoLSF/QOGzkNWQe2e29cHcHTI4hfsn9hPd wA+S/poRFK7CVvdhi/E84D7cXWVnp9XKY/1z6I0W8GMPh+2MORRMhhAp5/908uzLwcyd gqjkB+EOdg9zuDdAwRXRgXJLity3weHRqeFJk9fkaMbfBCD7EsuwhLuXDPLf5cxr6+51 E8lQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O8dNukvg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a9acd0cbdesi1472206685a.681.2024.09.13.10.30.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:30:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O8dNukvg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA50-0007T3-A0; Fri, 13 Sep 2024 13:27:34 -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 1spA4l-0006Zk-VS for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:20 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spA4b-0005xE-SG for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:17 -0400 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5c42384c517so909843a12.3 for ; Fri, 13 Sep 2024 10:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248428; x=1726853228; 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=VtGynklwfAQu3ROhwrXRdqcRVrQbQrKUw1qc30A1YZY=; b=O8dNukvgKkHWu/F3jFCbI1ofwwBE2zF6fUlYscm0GVX9N2edNewxtX/Q/HdHjU4Vxb qwUkCdZQN5wxa6pqbJW7QJWzhE7mDFwvPcKAp80r7EGRL3VpwX8VT33j/fgA/JxWi36v zC5iYjybtgyEIKjN5IRM3YJkbGFkl+EgympYNhrG7OtQ5We/EATe+fCEm2+LjySGcU0u aMeFka4CFxRZ7+PDWRq63rQKt0aMPzPlUotkDT1W7nnuiJkZTUscMcZuVAnovIvRjQTo PKKgP0/YjfYJPm3IZp1ke+ouenpPK0BEjopnmEAsjWNwq+SY07tuOZYoAH9qmrbgmZp/ 5gCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248428; x=1726853228; 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=VtGynklwfAQu3ROhwrXRdqcRVrQbQrKUw1qc30A1YZY=; b=DI1ttPLxZCiNpvjNm7NZP1tuPP3IKW6QSlkH4L7KGh5xS4PVt+PSI9SoVIYTYEd0Xo mBw+VPPIPbmqa3z2tRK3Cvau4hE7GfVktdvtoJdyZxXcME5bVFlWml9eoOl3ykPsglHp 5/IcJTqCFysoU4Vm3AYATScpjpPizzKL/k3QJRninR1swc/OFutgdpja1BlLBEYa9HKW 7WbKNNr9gpMsFu+PgEGvk45Z/G6fZym2MSA3rQ7tmdp0DBD+KA09FI2hvPnxFhUEl833 xWxJdeJFs25UpCBP3naV1DqXScVx86nzdpgmT7q+K1/qklFogqPyBX0mqlppll6LihMN NYKw== X-Gm-Message-State: AOJu0YzCnW4Y/MM6C1QxS1IYaPyn4uhX7WlU2d153SGHFHewEnkfzsCN wcIJUmOqVguW+9X1ylOHAwbxEbhkXDkmuwhdqOely2COPph6yj48ajCHEBxaHG8= X-Received: by 2002:a17:907:961e:b0:a8d:4f8e:f64d with SMTP id a640c23a62f3a-a902966826dmr691616166b.54.1726248427978; Fri, 13 Sep 2024 10:27:07 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25cea3e1sm884788666b.167.2024.09.13.10.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:06 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 698E85FA88; Fri, 13 Sep 2024 18:26:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum Subject: [PATCH 13/17] tests/tcg: add a system test to check memory instrumentation Date: Fri, 13 Sep 2024 18:26:51 +0100 Message-Id: <20240913172655.173873-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x536.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée --- v2 - aggressively align test_data on "region size" - sort the regions in the final report - ensure alpha-softmmu uses byte access when it can v3 - fix thinko while iterating through the regions - fix the LE/BE storage of values in the mirror section - add --bss-cleared to script - clean-up some long lines in the script --- tests/tcg/multiarch/system/memory.c | 50 +++-- tests/tcg/plugins/mem.c | 181 +++++++++++++++++- tests/tcg/alpha/Makefile.softmmu-target | 2 +- .../multiarch/system/Makefile.softmmu-target | 6 + .../system/validate-memory-counts.py | 129 +++++++++++++ tests/tcg/s390x/Makefile.softmmu-target | 5 + 6 files changed, 354 insertions(+), 19 deletions(-) create mode 100755 tests/tcg/multiarch/system/validate-memory-counts.py diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/memory.c index 680dd4800b..ccff699015 100644 --- a/tests/tcg/multiarch/system/memory.c +++ b/tests/tcg/multiarch/system/memory.c @@ -14,26 +14,35 @@ #include #include +#include #include #ifndef CHECK_UNALIGNED # error "Target does not specify CHECK_UNALIGNED" #endif +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 */ #define ARRAY_SIZE(x) ((sizeof(x) / sizeof((x)[0]))) -__attribute__((aligned(MEM_PAGE_SIZE))) +__attribute__((aligned(TEST_SIZE))) static uint8_t test_data[TEST_SIZE]; typedef void (*init_ufn) (int offset); typedef bool (*read_ufn) (int offset); typedef bool (*read_sfn) (int offset, bool nf); -static void pdot(int count) +static void pdot(int count, bool write) { + if (write) { + test_write_count++; + } else { + test_read_count++; + } if (count % 128 == 0) { ml_printf("."); } @@ -67,7 +76,7 @@ static void init_test_data_u8(int unused_offset) for (i = 0; i < TEST_SIZE; i++) { *ptr++ = BYTE_NEXT(count); - pdot(i); + pdot(i, true); } 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 = 0; i < TEST_SIZE / 2; i++) { *ptr++ = get_byte(i, neg_first); + pdot(i, true); *ptr++ = 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) for (i = 0; i < offset; i++) { *ptr++ = 0; + pdot(i, true); } ml_printf("done %d @ %p\n", i, ptr); @@ -136,7 +147,7 @@ static void init_test_data_u16(int offset) uint16_t low = BYTE_NEXT(count), high = BYTE_NEXT(count); word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0); *ptr++ = 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 = BYTE_SHIFT(b1, 3) | BYTE_SHIFT(b2, 2) | BYTE_SHIFT(b3, 1) | BYTE_SHIFT(b4, 0); *ptr++ = 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++ = 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); } } @@ -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_first) second = *ptr++; 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 ? '<' : '>', second); return false; @@ -409,9 +422,9 @@ static bool read_test_data_s16(int offset, bool neg_first) int32_t data = *ptr++; 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_first) int64_t data = *ptr++; 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 = true; + 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 = 0; i < ARRAY_SIZE(init_ufns) && ok; i++) { ok = do_unsigned_test(init_ufns[i]); @@ -513,6 +529,8 @@ int main(void) ok = do_signed_reads(true); } + 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..c28eedbed0 100644 --- a/tests/tcg/plugins/mem.c +++ b/tests/tcg/plugins/mem.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -26,13 +27,46 @@ typedef struct { const char *sym; } InsnInfo; +/* + * 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 = 4096 * 4; +static uint64_t region_mask; + +typedef struct { + uint64_t region_address; + uint64_t reads; + uint64_t writes; + uint8_t *data; + bool seen_all; /* Did we see every write and read with correct values? */ +} 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 = QEMU_PLUGIN_MEM_RW; + +static GMutex lock; +static GHashTable *regions; + +static gint addr_order(gconstpointer a, gconstpointer b) +{ + RegionInfo *na = (RegionInfo *) a; + RegionInfo *nb = (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 = g_string_new(""); @@ -46,9 +80,132 @@ 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 = g_hash_table_get_values(regions); + + counts = 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 = counts->next) { + RegionInfo *ri = (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); } +/* + * 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 = qemu_plugin_mem_is_big_endian(meminfo); + bool is_store = qemu_plugin_mem_is_store(meminfo); + RegionInfo *ri; + bool unseen_data = false; + + g_assert(offset + size <= region_size); + + g_mutex_lock(&lock); + ri = (RegionInfo *) g_hash_table_lookup(regions, GUINT_TO_POINTER(region)); + + if (!ri) { + ri = g_new0(RegionInfo, 1); + ri->region_address = region; + ri->data = g_malloc0(region_size); + ri->seen_all = 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] = value.data.u8; + } else if (ri->data[offset] != value.data.u8) { + unseen_data = true; + } + break; + case QEMU_PLUGIN_MEM_VALUE_U16: + { + uint16_t *p = (uint16_t *) &ri->data[offset]; + uint16_t val = be ? htobe16(value.data.u16) : htole16(value.data.u16); + if (is_store) { + *p = val; + } else if (*p != val) { + unseen_data = true; + } + break; + } + case QEMU_PLUGIN_MEM_VALUE_U32: + { + uint32_t *p = (uint32_t *) &ri->data[offset]; + uint32_t val = be ? htobe32(value.data.u32) : htole32(value.data.u32); + if (is_store) { + *p = val; + } else if (*p != val) { + unseen_data = true; + } + break; + } + case QEMU_PLUGIN_MEM_VALUE_U64: + { + uint64_t *p = (uint64_t *) &ri->data[offset]; + uint64_t val = be ? htobe64(value.data.u64) : htole64(value.data.u64); + if (is_store) { + *p = val; + } else if (*p != val) { + unseen_data = 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 = 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 = 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 +220,15 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, } else { qemu_plugin_u64_add(mem_count, cpu_index, 1); } + + if (do_region_summary) { + uint64_t region = vaddr & ~region_mask; + uint64_t offset = vaddr & region_mask; + qemu_plugin_mem_value value = qemu_plugin_mem_get_value(meminfo); + unsigned size = 1 << qemu_plugin_mem_size_shift(meminfo); + + update_region_info(region, offset, meminfo, value, size); + } } static void print_access(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, @@ -117,7 +283,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_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 +342,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", opt); return -1; } + } else if (g_strcmp0(tokens[0], "region-summary") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &do_region_summary)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + return -1; + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; @@ -196,6 +368,11 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, qemu_plugin_outs(out->str); } + if (do_region_summary) { + region_mask = (region_size - 1); + regions = g_hash_table_new(NULL, g_direct_equal); + } + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); mem_count = qemu_plugin_scoreboard_u64_in_struct( counts, CPUCount, mem_count); diff --git a/tests/tcg/alpha/Makefile.softmmu-target b/tests/tcg/alpha/Makefile.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+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc %: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS) $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) -memory: CFLAGS+=-DCHECK_UNALIGNED=0 +memory: CFLAGS+=-DCHECK_UNALIGNED=0 -mbwx # Running QEMU_OPTS+=-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 MULTIARCH_RUNS += 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=$(COMMA)region-summary=true +run-plugin-memory-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=$(MULTIARCH_SYSTEM_SRC)/validate-memory-counts.py $@.out diff --git a/tests/tcg/multiarch/system/validate-memory-counts.py b/tests/tcg/multiarch/system/validate-memory-counts.py new file mode 100755 index 0000000000..418862d5d3 --- /dev/null +++ b/tests/tcg/multiarch/system/validate-memory-counts.py @@ -0,0 +1,129 @@ +#!/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 = None + end_address = None + read_count = 0 + write_count = 0 + with open(path, 'r') as f: + for line in f: + if line.startswith("Test data start:"): + start_address = int(line.split(':')[1].strip(), 16) + elif line.startswith("Test data end:"): + end_address = int(line.split(':')[1].strip(), 16) + elif line.startswith("Test data read:"): + read_count = int(line.split(':')[1].strip()) + elif line.startswith("Test data write:"): + write_count = 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 = 0 + total_writes = 0 + seen_all = False + + with open(path, 'r') as f: + next(f) # Skip the header + for line in f: + + if line.startswith("Region Base"): + continue + + parts = line.strip().split(', ') + if len(parts) != 4: + continue + + region_base = int(parts[0], 16) + reads = int(parts[1]) + writes = int(parts[2]) + + if start <= region_base < end: # Checking if within range + total_reads += reads + total_writes += writes + seen_all = parts[3] == "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 = ArgumentParser(description="Validate memory instrumentation") + parser.add_argument('test_output', + help="The output from the test itself") + parser.add_argument('plugin_output', + help="The output from memory plugin") + parser.add_argument('--bss-cleared', + action='store_true', + help='Assume bss was cleared (and adjusts counts).') + + args = parser.parse_args() + + # Extract counts from memory binary + start, end, exp_reads, exp_writes = 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 += 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 = 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 == exp_reads and pwrites == 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__ == "__main__": + main() diff --git a/tests/tcg/s390x/Makefile.softmmu-target b/tests/tcg/s390x/Makefile.softmmu-target index ad681bbe40..d647093679 100644 --- a/tests/tcg/s390x/Makefile.softmmu-target +++ b/tests/tcg/s390x/Makefile.softmmu-target @@ -46,3 +46,8 @@ $(MULTIARCH_TESTS): $(S390X_MULTIARCH_RUNTIME_OBJS) $(MULTIARCH_TESTS): LDFLAGS += $(S390X_MULTIARCH_RUNTIME_OBJS) $(MULTIARCH_TESTS): CFLAGS += $(MINILIB_INC) memory: CFLAGS += -DCHECK_UNALIGNED=0 + +# s390x clears the BSS section so we need to account for that +run-plugin-memory-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=$(MULTIARCH_SYSTEM_SRC)/validate-memory-counts.py \ + --bss-cleared $@.out From patchwork Fri Sep 13 17:26:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828211 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp362661wra; Fri, 13 Sep 2024 10:29:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWwPHrw4+VD7tUl9jJUhqpCJ/Oz4tKhS65bzeHnBGNB7qd8N9zJ+9q9bFsa9QPOvcqlm0yqXA==@linaro.org X-Google-Smtp-Source: AGHT+IENSaNF4m12MDzwDJyvdGkRChjsiS1TO6PObJFsHhga+g8ams8NkPnK+phiS4UlZpRlg5HL X-Received: by 2002:a05:690c:f96:b0:6d3:82d0:fe4f with SMTP id 00721157ae682-6dbb6add3edmr80490997b3.6.1726248596686; Fri, 13 Sep 2024 10:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248596; cv=none; d=google.com; s=arc-20240605; b=IVsEVhYnAPYFQoe99DqCqtmb5WruAiQq44hKD79K2eQ/h0aN2p1/Q2OUJNhq+qjG1E SBeaKS/3EZPKHi+mE1M/sui+R2Kt9NU9VxcvJ1GCPezbTvEeR8imocw9pL2eF1nyon0a 1rndeoocXqK2bOiMKMZKAAdxucaTBOAowLREDwOwmsQab1pPudjsxX/NGqtkZhAz20wU j5yef7VmwithNCATwvb1h7rW7bOcY1gZvuHtmU2uXWWuQbgnS/NNuLH5ehOzW5GRhGHu YvZwUtXatzPOaA4uZ5FmkhiyIiWfWN44vE+oMUZ1Ou+W1PTXXhWVcpJC4Vwm60ku08+V 5YXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cRFhj2SyvQ/EIwHMRij/KsWIl6x9+a8v4XWFbD+c1P0=; fh=q5khnLXJ27a1TDUqc7RHOp19ruAkYYnLBIeCzqGkcps=; b=gEZgw7AA+0lBho2OaE3qFFr5fM8kN1eR05P1tb6M73i1ZODEuGtrhIbA3rd2AEyLdB PB/RvDopDsQodzJ2InyO7KxB4IL8uCH7xERwOGloKC1TDWStxk1jFRxiht5i5xZd/RbK Nikp9PsIVdTM4hz4LPYuiub9t/IwbnYtV81LIgXlX1u1JwJ0fTh4W0BcbaGUr5Od+3JV XXjppfEVk1zLyxOuUYnjHf/EpXATDk7z8apL9lys1ThLB8ybIgB/CDD1zYRYDYM3sGdm ExGSE2/rnSUpO7AZwHfqDTaOyZ3GCfxEwEr5f0+zSYkpwxdMA7VxQMWOdHspS7fzPRUw CQNg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DX6jTn7s; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6c5343302bdsi156444106d6.55.2024.09.13.10.29.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DX6jTn7s; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spA4r-00070a-Nq; Fri, 13 Sep 2024 13:27: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 1spA4l-0006ZL-SV for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:20 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spA4b-0005wk-0T for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:27:16 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a8d56155f51so287872766b.2 for ; Fri, 13 Sep 2024 10:27:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248427; x=1726853227; 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=cRFhj2SyvQ/EIwHMRij/KsWIl6x9+a8v4XWFbD+c1P0=; b=DX6jTn7seE8vwRwsLwL+3+FTsU1smTjiFVjGrTqcKNA6gC0gvJOJGUepSEV1pODg69 HZSdq8ffQ7r6kfDUHuhHoYjULl7hHR0C1Gfo6yWO7rxfeGUPmdg6lryZSUdoSYJTEnMT SVg7tcsZidJ3esPbBpju/CPg/gn0crSRgCFgF8mhkkZv7nZ202Xx20XA89FtHNQqCVbd FF/pGEA3LXXTiXNv2pnBqC2VWgyo0zA87JLYVFg2RbSFi5pR+DCdLTxyXjyys/Nh+au+ c0c+PBSqPiF7ASuJmWjk6o7NDhQlzAh61A2VZCCXQIR+ITYDwRHWoz3eJjwtTZPBcIhA tDhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248427; x=1726853227; 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=cRFhj2SyvQ/EIwHMRij/KsWIl6x9+a8v4XWFbD+c1P0=; b=RnmyMZ0PYthmvWUdkDYmArtXeMui5l6U4tvqS9R0cubyeFpJWcJyqz/CpBMe8F0Egg a9QVtv21o4d7sM0nc91hu1OITLKmlZSkIIJZcjFTzmy7NmBX2DF+3vsDF16IdfHWEFdi E3SVMA2zPCx1l4flQaHPQuzwbUbZ8lm9SlPbqhS4WYrqv+16VMB0tUw0PSXsOer7qWUZ PGgK0T6a8fR4TB4E66sPf6RxXbIrIFK4FRz0ltu4nRqkA4E8FQNt1hlvSEBqzhOG3MsN MCWaTcTDBfeD1s5WnKauZNcLY4/nUWBbl6ien8YnJ6Wmub4XLY6amX2sKRDZxS15d1+o gTPA== X-Gm-Message-State: AOJu0YzzCOf2offFyWFKeB+S1Afv9SQfKmih8RwZ+KYW6B7fsGhv33Vf PExEK12dk7RzlUa4hKgmkS9AsKo7bZgg/+pwZP+mOX1014sG5XSgd7cVT8st4yM= X-Received: by 2002:a17:907:60d5:b0:a8a:cc5a:7f3c with SMTP id a640c23a62f3a-a90296715f7mr632864466b.58.1726248427294; Fri, 13 Sep 2024 10:27:07 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25d657fesm896408366b.221.2024.09.13.10.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:27:06 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 832615FB3A; Fri, 13 Sep 2024 18:26:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum , Elisha Hollander Subject: [PATCH 14/17] util/timer: avoid deadlock when shutting down Date: Fri, 13 Sep 2024 18:26:52 +0100 Message-Id: <20240913172655.173873-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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. Signed-off-by: Alex Bennée Reported-by: Elisha Hollander --- util/qemu-timer.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); AioContext *aio_context; + int64_t deadline; + aio_context = qemu_get_aio_context(); - while (clock < dest) { - int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, + + deadline = 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 >= 0 && clock < dest) { int64_t warp = qemu_soonest_timeout(dest - clock, deadline); 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 = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + + deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, + QEMU_TIMER_ATTR_ALL); } qemu_clock_notify(QEMU_CLOCK_VIRTUAL); From patchwork Fri Sep 13 17:26:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828214 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp365345wra; Fri, 13 Sep 2024 10:35:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXjx1JtIH9OlrXfSnZ1lSn3/OSJKnjGH9oXQs7LnnROfWIZipmSoj85aTQ2FmcmKYLi9dTf0Q==@linaro.org X-Google-Smtp-Source: AGHT+IH/BZVLW8/js2q4yxtAft/++RSi5LE0DF8iS6sN39Ofm62rAh6rtzR/+lViwIrEz93O8T/X X-Received: by 2002:a05:620a:4016:b0:7a1:df6f:3625 with SMTP id af79cd13be357-7a9e5f32b9dmr952283085a.37.1726248940012; Fri, 13 Sep 2024 10:35:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248939; cv=none; d=google.com; s=arc-20240605; b=RwCugqwCI3mj77vYmEQT6eZ+HUTUA8PZIOQPzfllmOfVV8kBNobaIE+TXAMfEMQsX7 d67bquhr/kbbgmEZ98N4d6CQ/Y5pkYUo6WsVOP0wO/iAzyUb359OlYt/1N8QkpqBrT7E qg1mOkzPIUWqdpycThB2r0aP3rPGUyD1/gIrd5/SCw+HQs7cPmFy6cO6sp68GYXVNh+B rgCjWb+aXJ/wOKtgYI9mlN7+X42/2j79mSCb+bbiCMmlUIp3wDq2gzy1cC3Dv5CUFZZd sBK0mTMlVFkOlNwzTAJkttXqxsrKFtejJdEmPjAwewFOgkXw7X/6QQWX3AGRGxdvZvrO KPSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S6DKrSbtb2UyOkFJWx3GO7dDs+1RREyLEnRKm6VRifM=; fh=8joqmoYWqdPkWrrKLFuzghfTdVC3sysswKxv2apojPk=; b=eT0UHxfhyNaRYAuqFolajKSWvj0tGndKrB+3pO3DLudIEeldLCXsvQyMXVaNCvliPb BYccoC8EOEZgrpBuJT3kd744SWCydouvYtBZq06wU7kTR1s4i4N/iq498iB+qfK4dxwk Q0eblBzSZId25rqBbFPaZh2vUBmI95Xz89iuWdqeD+hmAGSWLeLEZUA4X8xVXZvn9AY3 ESDgvajyFKXyxAkTIqhj/BDDwiyW6ngzP03EWqo8NM0tuo5EKZm4znLLYTrKK+5witIO /rLkWaJzEJyfRRa9b5kVkttCKJPgxOromkUenQJ8w66gbuN5eeeW2JzQwaEkDojvnzSw aXFg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a05em95Y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a9a7a34d26si1544690385a.238.2024.09.13.10.35.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:35:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a05em95Y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spAC2-0002Kv-JE; Fri, 13 Sep 2024 13:34:50 -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 1spABz-00027F-Lz for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:34:47 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spABu-0006gD-6T for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:34:47 -0400 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5c241feb80dso6681456a12.0 for ; Fri, 13 Sep 2024 10:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248880; x=1726853680; 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=S6DKrSbtb2UyOkFJWx3GO7dDs+1RREyLEnRKm6VRifM=; b=a05em95Yo7dnLQdrJQWeofkn+u8mkjmSWtQ+mbplTZ1IiZ+s51FcLcfK7J+zQ/zl3o ifsVY5ylLv3ZtncfJT6nC4LD9AVzYRZBM+LW2SIdO+xkIivypC3dLu7MTvyd+u0/Y3O+ aEuE6sQLWT4DqZDX4CZYW9s8aYQr+Bg2pa9mc5s/g0zTQUH2h8rK9pjz+qZWTqyee3Qd cVHyrUnh0EbacoT1hOVn+OkGd32PMk2dWCXM0fxjsS9yNQcnM8xHXmJCc54dTGatuCi/ zd13kVa+hHErUtWRMCvVYI0vMuOqQsPsl35qSdeXfhYw+ej8VWCH8N8Ypc2wEhELY/oN RSHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248880; x=1726853680; 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=S6DKrSbtb2UyOkFJWx3GO7dDs+1RREyLEnRKm6VRifM=; b=VnhA9StvEqk2tuahDjI0nsQkL1aEM+wN2AjBaPkBZIh/Hhipyy69iubnGicdrohg4Z vxpqw7C/0yqoglHzvuGdj0c8oT3KjsxHay+m4aeysNzwBw6DYMHVJ0y7oIJqKiXQ0wsd IClhbFKml7XWasFHvZV+usvIstDfl37ngAhTQN0ujx6yAq1zrwdqumCMjo4o5se7SAKM dwmX4BL4dnE5/WjNP5ofK+krslWGaj8I+H4N2nf9Sr9I1gfpBaNy4lOlf/w4YA0gZ+DO VmKX6y+pYiQxDMmLfv71fO1FPL5oYaMZOLEdCSNDSY5sfMU4nhQ7JyhTaYk8jX7pDUKl 9Mbg== X-Gm-Message-State: AOJu0YxGKvzUcKlHCwNxtU+wDnb6iNOXnUKdLvVcHpQK8+UQkTqzEEQb hsL/gAR0mmUmlfZC9RFcoSjGJ9crKgzCHfLXJ5U1OfRC5VQSEDAJM+DgZwy6+sk= X-Received: by 2002:a17:907:3da0:b0:a8d:498f:640 with SMTP id a640c23a62f3a-a8ffae03f50mr1217006366b.21.1726248880097; Fri, 13 Sep 2024 10:34:40 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c61279sm889929166b.108.2024.09.13.10.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:34:39 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 9BBAC5FBC2; Fri, 13 Sep 2024 18:26:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum , Akihiko Odaki , Yotaro Nada Subject: [PATCH 15/17] contrib/plugins: Add a plugin to generate basic block vectors Date: Fri, 13 Sep 2024 18:26:53 +0100 Message-Id: <20240913172655.173873-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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-dynamic-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ée --- docs/about/emulation.rst | 30 ++++++++ contrib/plugins/bbv.c | 158 +++++++++++++++++++++++++++++++++++++++ contrib/plugins/Makefile | 1 + 3 files changed, 189 insertions(+) create mode 100644 contrib/plugins/bbv.c diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index eea1261baa..a4470127c9 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -272,6 +272,36 @@ Behaviour can be tweaked with the following arguments: * - idle=true|false - Dump the current execution stats whenever the guest vCPU idles +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=N + - The interval to generate a basic block vector specified by the number of + instructions (Default: N = 100000000) + * - outfile=PATH + - 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=100,outfile=sha1 \ + tests/tcg/aarch64-linux-user/sha1 + SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6 + $ du sha1.0.bb + 23128 sha1.0.bb + Instruction ........... 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 = QEMU_PLUGIN_VERSION; +static GHashTable *bbs; +static GRWLock bbs_lock; +static char *filename; +static struct qemu_plugin_scoreboard *vcpus; +static uint64_t interval = 100000000; + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + for (int i = 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 = NULL; + Vcpu *vcpu = qemu_plugin_scoreboard_find(vcpus, vcpu_index); + + vcpu_filename = g_strdup_printf("%s.%u.bb", filename, vcpu_index); + vcpu->file = fopen(vcpu_filename, "w"); +} + +static void vcpu_interval_exec(unsigned int vcpu_index, void *udata) +{ + Vcpu *vcpu = qemu_plugin_scoreboard_find(vcpus, vcpu_index); + GHashTableIter iter; + void *value; + + if (!vcpu->file) { + return; + } + + vcpu->count -= 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 = value; + uint64_t bb_count = qemu_plugin_u64_get(bb_count_u64(bb), vcpu_index); + + 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 = qemu_plugin_tb_n_insns(tb); + uint64_t vaddr = qemu_plugin_tb_vaddr(tb); + Bb *bb; + + g_rw_lock_writer_lock(&bbs_lock); + bb = g_hash_table_lookup(bbs, &vaddr); + if (!bb) { + bb = g_new(Bb, 1); + bb->vaddr = vaddr; + bb->count = qemu_plugin_scoreboard_new(sizeof(uint64_t)); + bb->index = 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 = 0; i < argc; i++) { + char *opt = argv[i]; + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); + if (g_strcmp0(tokens[0], "interval") == 0) { + interval = g_ascii_strtoull(tokens[1], NULL, 10); + } else if (g_strcmp0(tokens[0], "outfile") == 0) { + filename = tokens[1]; + tokens[1] = NULL; + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + if (!filename) { + fputs("outfile unspecified\n", stderr); + return -1; + } + + bbs = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, free_bb); + vcpus = 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 = $(SRC_PATH)/../.. VPATH += $(SRC_PATH) NAMES := +NAMES += bbv NAMES += execlog NAMES += hotblocks NAMES += hotpages From patchwork Fri Sep 13 17:26:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828215 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp365484wra; Fri, 13 Sep 2024 10:35:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXL7y/IcM8F8YkoCUwmsbvDe5lRkfHpN7SlXJFAIwK2+/3/rlDRE0POI3K5Rq4anXvqc+LuqA==@linaro.org X-Google-Smtp-Source: AGHT+IGq4LvHjD5BADAllXy1MB7yhsbQHpJH9PIopUI3LfKNAfVk/61T1Myd1XGUPO8syzAHQGws X-Received: by 2002:a05:6902:3103:b0:e1d:2300:29a1 with SMTP id 3f1490d57ef6-e1daff94e2fmr3269149276.29.1726248955514; Fri, 13 Sep 2024 10:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248955; cv=none; d=google.com; s=arc-20240605; b=iOFWQxFduQyLm2Cxk77qooLPUOauKVvbKWDFLQ5mFHuxLBxh4NYvCuoS6GBY6b6h+5 2BaTDShDHWxIPv37zLtX7xfgUdH8rAtLjnEVArjSq9g2nXPNLCRFgYisBwzYj7vHANS3 y18aMVx2Sjrk3bsJq9PHV4TphE1nWqQAR2XGJO2YGh2d9wYZEmdITpmH/MYcNOCC+UUy Jfmg+k0bA+FTAQIZSZgTcI10xlh294mcUG3McLhfCdZ+kZOdQhaF53lYCC006CaJ3s13 GMtIyYr9UK/pftzQfGWMzR1mXTG5jMzrBf9vrfJ2+TuFItSgCKx7VpjWa8GrPt1h42yS 4XCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hEZbqliSm3idSAY5YqSflW1IHfDQd2AMSDogcHs/b2s=; fh=GsrwtA/UDrcgEwSkY5/1kjXSExuJfr1ekbSXfoTh728=; b=cp+uLTOJNsgoLd8Qdd/Cx9MzMKnMcfAfWVgGpdKLylvXo239frFHFdLzoVXuAzAu6A E0aaOMwICsv0zeaQi+M1aWH7rvAP7trV4zpAK8XMgIjpAh+ubIGNlOVhW0DP+8rPxUNQ 0CefqAgACXHnFWAMeFkMm0mV+no+BZ+FsN1ek6Pb4X6xKNsTG4b2BuPjqXsjtjcmw3xb ieGYpb7PSAg5ZMDpDELwFai8Edl8guAKsvloX263mJ0/Zuk+TnQpGeNwJvebz0UoDrx4 yQbWI9FGA6Dq3ml0UA9DnLIjX1P/1yI9QSmzNua52fWeqQuI3WG0ZFZz+CS1r11uOdU2 M0Lg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PyB9+h26; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45822f815d5si162805901cf.506.2024.09.13.10.35.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:35:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PyB9+h26; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spAC2-0002Lh-OK; Fri, 13 Sep 2024 13:34:50 -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 1spAC1-0002D2-10 for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:34:49 -0400 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spABx-0006gL-3l for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:34:48 -0400 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5365d3f9d34so1473596e87.3 for ; Fri, 13 Sep 2024 10:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248881; x=1726853681; 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=hEZbqliSm3idSAY5YqSflW1IHfDQd2AMSDogcHs/b2s=; b=PyB9+h26DpG5Sm7BcJ47cSZKSdECPj6Nz7P+muBSVt7DPu3k91gbz9kFz/KbGRHyb4 WcGFXDvNHIMEYCcUxcH8d1EwF3TRiteUNUiTS9A4CVzerenMb7LFOVr1xgCgXWLa5IwZ SFMIiMz4AC3ymlkr2ZqSgZKm/5OLPiQqHei9kmsP8RuMGh8UAzQGAyQFIGs+FjkxYiNt UTm9eI0wmUS64F/+QPOiRXYgeIpCVtexiR8IkQghkU2gvhbHL3+jeBi4oFfL6DfMg7uP d0Q/kzlRGk2WMWrvV0qeDeJ243o98I0N9DK6qdWwEjvRo/N8R9TB0x4WRKJQ7K18PSwQ HFNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248881; x=1726853681; 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=hEZbqliSm3idSAY5YqSflW1IHfDQd2AMSDogcHs/b2s=; b=sdq9l/YdbzZY6cQPrA5JZFyKQXQlrhVdXhkBPaT3ZKnEf0jKNrjunsgfgHTGyEBj6M +L7cLCtHPOdE2zMkVxRlgym1Tlitl5V0YCbGD+Uy+m2tPVwRO9ALqYOFIYr2cWUQajXw JZmXJc+/1RQrnlB9eFc73H0mK2z3g5VYgeCqeECjQXk0qXdfUFaZmhASrETOis1AVGW1 Sn4iyzuoNDM7Ex41tmPXFLi6fj7MJWuDy4coQguZVZp3bEDO+Qxk1Pz0Pt2DYmDa493Q iZQh05Q+bPwcBp2KrwMTziHMpEhyiJLvKTAn70tVy2l6YsudghoqdKSf9OLIEmihgksu cLZQ== X-Gm-Message-State: AOJu0Yz2uxgnSZJEoWjbU9yVn8sJd69/YET8qEE4C6dcyWz7NgkdFtl4 YEJmhdKshH2rU8MDJa+HgYmgMSQx0qJZz0uZ1i6UB+bGNA+a8ZeOYSzCfUVub3A= X-Received: by 2002:a05:6512:a90:b0:535:3dae:a14b with SMTP id 2adb3069b0e04-5367feba05emr2330342e87.2.1726248880496; Fri, 13 Sep 2024 10:34:40 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72eb0sm891789466b.132.2024.09.13.10.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:34:39 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id CAC045FBCB; Fri, 13 Sep 2024 18:26:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum , Rowan Hart Subject: [PATCH 17/17] plugins: add option to dump write argument to syscall plugin Date: Fri, 13 Sep 2024 18:26:55 +0100 Message-Id: <20240913172655.173873-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::135; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x135.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée --- vAJB - tweak fmt string for PRIu64 --- docs/about/emulation.rst | 14 ++++- tests/tcg/plugins/syscall.c | 117 ++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index a4470127c9..23e4949049 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -418,6 +418,19 @@ run:: 160 1 0 135 1 0 +Behaviour can be tweaked with the following arguments: + +.. list-table:: Syscall plugin arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - print=true|false + - Print the number of times each syscall is called + * - log_writes=true|false + - Log the buffer of each write syscall in hexdump format + Test inline operations ...................... @@ -807,4 +820,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..647f478090 100644 --- a/tests/tcg/plugins/syscall.c +++ b/tests/tcg/plugins/syscall.c @@ -22,8 +22,57 @@ typedef struct { int64_t errors; } SyscallStats; +struct SyscallInfo { + const char *name; + int64_t write_sysno; +}; + +const struct SyscallInfo arch_syscall_info[] = { + { "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 = -1; static SyscallStats *get_or_create_entry(int64_t num) { @@ -39,6 +88,44 @@ static SyscallStats *get_or_create_entry(int64_t num) return entry; } +/* + * 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 = g_string_new(""); + + for (guint index = 0; index < data->len; index += 16) { + for (guint col = 0; col < 16; col++) { + if (index + col < data->len) { + g_string_append_printf(out, "%02x ", data->data[index + col]); + } else { + g_string_append(out, " "); + } + } + + g_string_append(out, " | "); + + for (guint col = 0; col < 16; col++) { + if (index + col >= 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 = g_strdup_printf("syscall #%" PRIi64 "\n", num); qemu_plugin_outs(out); } + + if (do_log_writes && num == 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); + } + } } 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", opt); } + } else if (g_strcmp0(tokens[0], "log_writes") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_log_writes)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + } } 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 = g_hash_table_new_full(NULL, g_direct_equal, NULL, g_free); } + if (do_log_writes) { + for (const struct SyscallInfo *syscall_info = arch_syscall_info; + syscall_info->name != NULL; syscall_info++) { + + if (g_strcmp0(syscall_info->name, info->target_name) == 0) { + write_sysno = syscall_info->write_sysno; + break; + } + } + + if (write_sysno == -1) { + fprintf(stderr, "write syscall number not found\n"); + return -1; + } + + memory_buffer = 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);