From nobody Sun Nov 24 19:41:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1720293322; cv=none; d=zohomail.com; s=zohoarc; b=ZnHgN9xOfHf9fGzeeu8Z9EnBBdq1pa9R08PnXCDvewm9nwrUZbqyq+I5R+PWOUo1l4GgiuVMs8Jiv2n9n/Y8NuDUsfkEh88OsbSn1IRvETXpMMkO5sBZAuo4SEpARH62AXpQxCK1ecyEz/fskUshALInWMjukPXwafw3Iip8DYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720293322; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=h1iFjXkNAAiUT1/HXJR1NSUSkejcZSCzgqp885X9UqQ=; b=AFjvqlM/Gm8m8UX4Woe62IphyXQldC51cD70DovhLVQSLqLAPsTHWvwI9Ej28E330pVxUBpSsQFku47VCkCA5cvM8FWmgmb0e8UvgZZO17SoOqqxRutDv/tJCy6+BOJHurE/HanRaS0Xb+in2TWf9qS/O+I+/IJ2GrfRec62500= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720293322199316.06745493284154; Sat, 6 Jul 2024 12:15:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQAqx-0002Bo-H2; Sat, 06 Jul 2024 15:13:47 -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 1sQAqw-0002BN-DM for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:46 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQAqu-00044N-T7 for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:46 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-754d2b05db5so1480277a12.0 for ; Sat, 06 Jul 2024 12:13:44 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb6153cb3bsm17304305ad.129.2024.07.06.12.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 12:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720293223; x=1720898023; 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=h1iFjXkNAAiUT1/HXJR1NSUSkejcZSCzgqp885X9UqQ=; b=vReNQLmVq05RDzOmAYNbScNBZjQ2SC1zVeoCxOtBLQMqqAvYp5iIjjyOU0k94yXqOp rkvhRcVPtoQYW7RiXWSD6GvSrqMG6nHHdGd7VTQ4Z5yDbYIiwPE/oShD4ZwNp/5SQDTT Av3lqEje+DqydsmtKZJpvRIsPzunbQ+7u4ydBmb6YShQy+s/gZIFtND9aHVp7TM/h4T/ b/B2Qnm68Tk/FNE+xCzBeukyNDo5PxY1tmqqeJtsoXEQxE3ZrYSE42Zp/TUZkOnwp8DD duEjPyDk7UzXR8PntLThSiC1MieAk9EQWONLPcfampwv1pS3ob/hwfiPE6rilyUqj75Y 11Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720293223; x=1720898023; 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=h1iFjXkNAAiUT1/HXJR1NSUSkejcZSCzgqp885X9UqQ=; b=FVNJ5hobAlC2MXHME31FlAUPJtew87Sru4hFtWnH0Miriwn+dEuOqGWXhLcGxt1rdq wS5iKvb3o26my/v+/MlPiwmKT+Qk8qqO5Ke9upPlh2AdHeBD0FYFR4GGIt6Bb/DsrNC8 1aOLD+urQLvU1QKtix6whZCSs/DfyH8jyIMNO+wbi2U12O1rgQeJrLv2KX/8pPzQHpb2 FIIBtGwk13oqSSjXC4YKrTTpQSc0eT+tMCyqSDG9WWfJDVdoPWdYen8DXAHVVI+6cSM5 A3ic65T4Tt3eCR7hqPp+v8/+fv0rbGbtNodD/4a5qNMNxMqEZdbMFwRQoVQ5/bXCD5Lw E2oQ== X-Gm-Message-State: AOJu0YzOFIwVMTqEj0VhNDH52e4emztja0xGJFiJ1YopH3glWg2bsJu1 Tbuy/eJoKY9Ug7Q3I2HPopuFM39KEDxXDl+Pvwo01vguKvEiraghuPMOxRJx5hX1KkOdG4p0cq9 SYB4= X-Google-Smtp-Source: AGHT+IEgLJWYW+fzNN8E7DoG6OVN7B+tHtpB7exat3ASMs2gO74W4a5QFwNejxg1LPZO0LO/bDu65w== X-Received: by 2002:a17:902:db02:b0:1fb:6a96:fc72 with SMTP id d9443c01a7336-1fb6a970334mr12396215ad.68.1720293223034; Sat, 06 Jul 2024 12:13:43 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost , Yanan Wang , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v6 1/7] plugins: fix mem callback array size Date: Sat, 6 Jul 2024 12:13:29 -0700 Message-Id: <20240706191335.878142-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240706191335.878142-1-pierrick.bouvier@linaro.org> References: <20240706191335.878142-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pg1-x52c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1720293323391100001 Content-Type: text/plain; charset="utf-8" data was correctly copied, but size of array was not set (g_array_sized_new only reserves memory, but does not set size). As a result, callbacks were not called for code path relying on plugin_register_vcpu_mem_cb(). Found when trying to trigger mem access callbacks for atomic instructions. Reviewed-by: Xingtao Yao Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Reviewed-by: Alex Benn=C3=A9e --- accel/tcg/plugin-gen.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index b6bae32b997..ec89a085b43 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -85,8 +85,7 @@ static void gen_enable_mem_helper(struct qemu_plugin_tb *= ptb, len =3D insn->mem_cbs->len; arr =3D g_array_sized_new(false, false, sizeof(struct qemu_plugin_dyn_cb), len); - memcpy(arr->data, insn->mem_cbs->data, - len * sizeof(struct qemu_plugin_dyn_cb)); + g_array_append_vals(arr, insn->mem_cbs->data, len); qemu_plugin_add_dyn_cb_arr(arr); =20 tcg_gen_st_ptr(tcg_constant_ptr((intptr_t)arr), tcg_env, --=20 2.39.2 From nobody Sun Nov 24 19:41:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1720293288; cv=none; d=zohomail.com; s=zohoarc; b=XxU+Eoo4YSKiDPV7kTjimpPhngPpJlkkru1a0/G/3cI/aPu0zh1Lzs4tySKhtYTDEyvvXM7bGXIC6TCujUNu7RH7IMXAnkKQELWWxmd9SseXK1pbJZAHu0/iGfi3lOtsS9sl3fi10KsX5LVnnYUIYn/wMeU05s6o44jLB6X1LF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720293288; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oSCkw14FBoeGNGjUHnHe2Vob0BsAYcgrTpSqhp2ESss=; b=AkV2RdHCmm2wPftnhJnPAl3fjTDIUuD8HEhVmr9lTNe750pcVO9S1o8mh3fFCi2ros/Y9huXhqWKv6v+aUZxVXbkmf45xHlXgIxVnRK7AmfQ0Q0Pt6KhxLjOgoqDLARCnxEqVLxIMRZ7D9eoEvjajSNxca+HxnQYH5aKhknSegI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720293288086286.7848791183203; Sat, 6 Jul 2024 12:14:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQAr0-0002CX-L9; Sat, 06 Jul 2024 15:13: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 1sQAqz-0002CD-3x for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:49 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQAqw-00044S-IC for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:48 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1fb222a8eaeso19598135ad.3 for ; Sat, 06 Jul 2024 12:13:46 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb6153cb3bsm17304305ad.129.2024.07.06.12.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 12:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720293224; x=1720898024; 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=oSCkw14FBoeGNGjUHnHe2Vob0BsAYcgrTpSqhp2ESss=; b=Sm6bPoTbz8GvIpEh9LfzCiPtJj++aw5ENiwmfKpIEGwZeCBI1Rvn1ZQ38I1nGDwg+j JFzXabeSMx+NA+b5XakqdsgdiVqHIBZXt2goHukq5uGOVhchzxJXiBYmyORCjX80z1fU hIxJHPoE0dJMoVVuCa+AYsxjLqq2xHWtIjyGKr9zG+hfZ9kAejamTUfIXYwKcM5FqHBe 8kYZn7IdRL8l2HpWGU+WIyMD3sHvp/gu6rjIcNVD+tAw4B3gugRNzHH9Z9roOKbz7E99 /BxN07TdgKP5ZRAbBL2RsIl+zXc/C2VdFXkvb/eR3Hfv7FWrBFdnZkgtMiEhcinDitGN wbMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720293224; x=1720898024; 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=oSCkw14FBoeGNGjUHnHe2Vob0BsAYcgrTpSqhp2ESss=; b=DVw1sW1BXFkgz+6EfCOKjPCw01JlZDV/JX7IDppY5n4K0+nUm88fNZQSB9GO+4GhG8 c9nH0DJIBrSYwYQBdUVG8h4ph64BuXdJzsvIzqiUwD7wD/0hJPuxW5cFPxz0bBAD/QwP 9XbeODfj3+I1Y75NtmrLOzLLXpu+SslzD5tR4AKgMZpWnWn0dus10UjJWlthastCRMN7 TLQ4fpIYZLLYHUsdqvtsEIjMd3gCPupzHp3b+NGscxUdf9vqnjgYcsZ3ecx+l3JAVq/6 BXe2aY6cFnR7vS2v7jLVHgfIk8RApA9QBP1QWX5HIp8nfkiGrjM6PQCOplsyeh/61fWC gCig== X-Gm-Message-State: AOJu0YxP2ug8ZAoSzaoNGqxH8zvyxg7Jnj+0Z+3f5FfBsAFTg9Q/If2M 7k1FpFZiFqRanVfFg95JuURJNHq6eNgVSQGT35FX5QdLRkbKu+WZvtgU4MdNW34Ud26syT36EuX VTe8= X-Google-Smtp-Source: AGHT+IHgNnqQjfaOyUP6+EBIMko4NoXEsg7mo4M9Njb6EMNMoCcrrC8b+7MuapA6VJjf0rmdss2hlg== X-Received: by 2002:a17:902:e74c:b0:1fb:715d:df83 with SMTP id d9443c01a7336-1fb715de31amr13225355ad.13.1720293224144; Sat, 06 Jul 2024 12:13:44 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost , Yanan Wang , Pierrick Bouvier Subject: [PATCH v6 2/7] plugins: save value during memory accesses Date: Sat, 6 Jul 2024 12:13:30 -0700 Message-Id: <20240706191335.878142-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240706191335.878142-1-pierrick.bouvier@linaro.org> References: <20240706191335.878142-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1720293289939100011 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Pierrick Bouvier Reviewed-by: Alex Benn=C3=A9e --- 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 1dc2151dafd..89593b2502f 100644 --- a/accel/tcg/atomic_template.h +++ b/accel/tcg/atomic_template.h @@ -53,6 +53,14 @@ # error unsupported data size #endif =20 +#if DATA_SIZE =3D=3D 16 +# define VALUE_LOW(val) int128_getlo(val) +# define VALUE_HIGH(val) int128_gethi(val) +#else +# define VALUE_LOW(val) val +# define VALUE_HIGH(val) 0 +#endif + #if DATA_SIZE >=3D 4 # define ABI_TYPE DATA_TYPE #else @@ -83,7 +91,12 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, abi_ptr= addr, ret =3D qatomic_cmpxchg__nocheck(haddr, cmpv, newv); #endif ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(newv), + VALUE_HIGH(newv), + oi); return ret; } =20 @@ -97,7 +110,12 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, abi_ptr a= ddr, ABI_TYPE val, =20 ret =3D qatomic_xchg__nocheck(haddr, val); ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(val), + VALUE_HIGH(val), + oi); return ret; } =20 @@ -109,7 +127,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr add= r, \ haddr =3D atomic_mmu_lookup(env_cpu(env), addr, oi, DATA_SIZE, retaddr= ); \ ret =3D qatomic_##X(haddr, val); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(ret), \ + VALUE_HIGH(ret), \ + VALUE_LOW(val), \ + VALUE_HIGH(val), \ + oi); \ return ret; \ } =20 @@ -145,7 +168,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr add= r, \ cmp =3D qatomic_cmpxchg__nocheck(haddr, old, new); \ } while (cmp !=3D old); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(old), \ + VALUE_HIGH(old), \ + VALUE_LOW(xval), \ + VALUE_HIGH(xval), \ + oi); \ return RET; \ } =20 @@ -188,7 +216,12 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, abi_p= tr addr, ret =3D qatomic_cmpxchg__nocheck(haddr, BSWAP(cmpv), BSWAP(newv)); #endif ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(newv), + VALUE_HIGH(newv), + oi); return BSWAP(ret); } =20 @@ -202,7 +235,12 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, abi_ptr = addr, ABI_TYPE val, =20 ret =3D qatomic_xchg__nocheck(haddr, BSWAP(val)); ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(val), + VALUE_HIGH(val), + oi); return BSWAP(ret); } =20 @@ -214,7 +252,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr add= r, \ haddr =3D atomic_mmu_lookup(env_cpu(env), addr, oi, DATA_SIZE, retaddr= ); \ ret =3D qatomic_##X(haddr, BSWAP(val)); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(ret), \ + VALUE_HIGH(ret), \ + VALUE_LOW(val), \ + VALUE_HIGH(val), \ + oi); \ return BSWAP(ret); \ } =20 @@ -247,7 +290,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr add= r, \ ldn =3D qatomic_cmpxchg__nocheck(haddr, ldo, BSWAP(new)); \ } while (ldo !=3D ldn); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(old), \ + VALUE_HIGH(old), \ + VALUE_LOW(xval), \ + VALUE_HIGH(xval), \ + oi); \ return RET; \ } =20 @@ -281,3 +329,5 @@ GEN_ATOMIC_HELPER_FN(add_fetch, ADD, DATA_TYPE, new) #undef SUFFIX #undef DATA_SIZE #undef SHIFT +#undef VALUE_LOW +#undef VALUE_HIGH diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index a2c8536943f..e92cba049fd 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 af5f9db4692..9726a9ebf36 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -167,6 +167,8 @@ qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, ui= nt64_t a1, void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret); =20 void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, + uint64_t value_low, + uint64_t value_high, MemOpIdx oi, enum qemu_plugin_mem_rw rw); =20 void qemu_plugin_flush_cb(void); @@ -251,6 +253,8 @@ void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_= t num, int64_t ret) { } =20 static inline void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, + uint64_t value_low, + uint64_t value_high, MemOpIdx oi, enum qemu_plugin_mem_rw rw) { } diff --git a/plugins/core.c b/plugins/core.c index 12c67b4b4eb..d353d38b8da 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -583,6 +583,8 @@ void exec_inline_op(enum plugin_dyn_cb_type type, } =20 void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, + uint64_t value_low, + uint64_t value_high, MemOpIdx oi, enum qemu_plugin_mem_rw rw) { GArray *arr =3D cpu->neg.plugin_mem_cbs; @@ -591,6 +593,10 @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t v= addr, if (arr =3D=3D NULL) { return; } + + cpu->neg.plugin_mem_value_low =3D value_low; + cpu->neg.plugin_mem_value_high =3D value_high; + for (i =3D 0; i < arr->len; i++) { struct qemu_plugin_dyn_cb *cb =3D &g_array_index(arr, struct qemu_plugin_dyn_cb, i); diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c index 85101602581..23dc807f119 100644 --- a/tcg/tcg-op-ldst.c +++ b/tcg/tcg-op-ldst.c @@ -148,11 +148,11 @@ static TCGv_i64 plugin_maybe_preserve_addr(TCGTemp *a= ddr) return NULL; } =20 +#ifdef CONFIG_PLUGIN static void plugin_gen_mem_callbacks(TCGv_i64 copy_addr, TCGTemp *orig_addr, MemOpIdx = oi, enum qemu_plugin_mem_rw rw) { -#ifdef CONFIG_PLUGIN if (tcg_ctx->plugin_insn !=3D NULL) { qemu_plugin_meminfo_t info =3D make_plugin_meminfo(oi, rw); =20 @@ -172,6 +172,54 @@ plugin_gen_mem_callbacks(TCGv_i64 copy_addr, TCGTemp *= orig_addr, MemOpIdx oi, } } } +} +#endif + +static void +plugin_gen_mem_callbacks_i32(TCGv_i32 val, + TCGv_i64 copy_addr, TCGTemp *orig_addr, + MemOpIdx oi, enum qemu_plugin_mem_rw rw) +{ +#ifdef CONFIG_PLUGIN + if (tcg_ctx->plugin_insn !=3D NULL) { + tcg_gen_st_i32(val, tcg_env, + offsetof(CPUState, neg.plugin_mem_value_low) - + sizeof(CPUState) + (HOST_BIG_ENDIAN * 4)); + plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw); + } +#endif +} + +static void +plugin_gen_mem_callbacks_i64(TCGv_i64 val, + TCGv_i64 copy_addr, TCGTemp *orig_addr, + MemOpIdx oi, enum qemu_plugin_mem_rw rw) +{ +#ifdef CONFIG_PLUGIN + if (tcg_ctx->plugin_insn !=3D NULL) { + tcg_gen_st_i64(val, tcg_env, + offsetof(CPUState, neg.plugin_mem_value_low) - + sizeof(CPUState)); + plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw); + } +#endif +} + +static void +plugin_gen_mem_callbacks_i128(TCGv_i128 val, + TCGv_i64 copy_addr, TCGTemp *orig_addr, + MemOpIdx oi, enum qemu_plugin_mem_rw rw) +{ +#ifdef CONFIG_PLUGIN + if (tcg_ctx->plugin_insn !=3D NULL) { + tcg_gen_st_i64(TCGV128_LOW(val), tcg_env, + offsetof(CPUState, neg.plugin_mem_value_low) - + sizeof(CPUState)); + tcg_gen_st_i64(TCGV128_HIGH(val), tcg_env, + offsetof(CPUState, neg.plugin_mem_value_high) - + sizeof(CPUState)); + plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw); + } #endif } =20 @@ -203,7 +251,8 @@ static void tcg_gen_qemu_ld_i32_int(TCGv_i32 val, TCGTe= mp *addr, opc =3D INDEX_op_qemu_ld_a64_i32; } gen_ldst(opc, tcgv_i32_temp(val), NULL, addr, oi); - plugin_gen_mem_callbacks(copy_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R); + plugin_gen_mem_callbacks_i32(val, copy_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_R); =20 if ((orig_memop ^ memop) & MO_BSWAP) { switch (orig_memop & MO_SIZE) { @@ -271,7 +320,7 @@ static void tcg_gen_qemu_st_i32_int(TCGv_i32 val, TCGTe= mp *addr, } } gen_ldst(opc, tcgv_i32_temp(val), NULL, addr, oi); - plugin_gen_mem_callbacks(NULL, addr, orig_oi, QEMU_PLUGIN_MEM_W); + plugin_gen_mem_callbacks_i32(val, NULL, addr, orig_oi, QEMU_PLUGIN_MEM= _W); =20 if (swap) { tcg_temp_free_i32(swap); @@ -324,7 +373,8 @@ static void tcg_gen_qemu_ld_i64_int(TCGv_i64 val, TCGTe= mp *addr, opc =3D INDEX_op_qemu_ld_a64_i64; } gen_ldst_i64(opc, val, addr, oi); - plugin_gen_mem_callbacks(copy_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R); + plugin_gen_mem_callbacks_i64(val, copy_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_R); =20 if ((orig_memop ^ memop) & MO_BSWAP) { int flags =3D (orig_memop & MO_SIGN @@ -396,7 +446,7 @@ static void tcg_gen_qemu_st_i64_int(TCGv_i64 val, TCGTe= mp *addr, opc =3D INDEX_op_qemu_st_a64_i64; } gen_ldst_i64(opc, val, addr, oi); - plugin_gen_mem_callbacks(NULL, addr, orig_oi, QEMU_PLUGIN_MEM_W); + plugin_gen_mem_callbacks_i64(val, NULL, addr, orig_oi, QEMU_PLUGIN_MEM= _W); =20 if (swap) { tcg_temp_free_i64(swap); @@ -606,7 +656,8 @@ static void tcg_gen_qemu_ld_i128_int(TCGv_i128 val, TCG= Temp *addr, tcg_constant_i32(orig_oi)); } =20 - plugin_gen_mem_callbacks(ext_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R); + plugin_gen_mem_callbacks_i128(val, ext_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_R); } =20 void tcg_gen_qemu_ld_i128_chk(TCGv_i128 val, TCGTemp *addr, TCGArg idx, @@ -722,7 +773,8 @@ static void tcg_gen_qemu_st_i128_int(TCGv_i128 val, TCG= Temp *addr, tcg_constant_i32(orig_oi)); } =20 - plugin_gen_mem_callbacks(ext_addr, addr, orig_oi, QEMU_PLUGIN_MEM_W); + plugin_gen_mem_callbacks_i128(val, ext_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_W); } =20 void tcg_gen_qemu_st_i128_chk(TCGv_i128 val, TCGTemp *addr, TCGArg idx, diff --git a/accel/tcg/atomic_common.c.inc b/accel/tcg/atomic_common.c.inc index 95a5c5ff12d..6056598c23d 100644 --- a/accel/tcg/atomic_common.c.inc +++ b/accel/tcg/atomic_common.c.inc @@ -14,9 +14,20 @@ */ =20 static void atomic_trace_rmw_post(CPUArchState *env, uint64_t addr, + uint64_t read_value_low, + uint64_t read_value_high, + uint64_t write_value_low, + uint64_t write_value_high, MemOpIdx oi) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_RW); + if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + read_value_low, read_value_high, + oi, QEMU_PLUGIN_MEM_R); + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + write_value_low, write_value_high, + oi, QEMU_PLUGIN_MEM_W); + } } =20 /* diff --git a/accel/tcg/ldst_common.c.inc b/accel/tcg/ldst_common.c.inc index 87ceb954873..ebbf380d767 100644 --- a/accel/tcg/ldst_common.c.inc +++ b/accel/tcg/ldst_common.c.inc @@ -123,10 +123,15 @@ void helper_st_i128(CPUArchState *env, uint64_t addr,= Int128 val, MemOpIdx oi) * Load helpers for cpu_ldst.h */ =20 -static void plugin_load_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi) +static void plugin_load_cb(CPUArchState *env, abi_ptr addr, + uint64_t value_low, + uint64_t value_high, + MemOpIdx oi) { if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_R); + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + value_low, value_high, + oi, QEMU_PLUGIN_MEM_R); } } =20 @@ -136,7 +141,7 @@ uint8_t cpu_ldb_mmu(CPUArchState *env, abi_ptr addr, Me= mOpIdx oi, uintptr_t ra) =20 tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_UB); ret =3D do_ld1_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } =20 @@ -147,7 +152,7 @@ uint16_t cpu_ldw_mmu(CPUArchState *env, abi_ptr addr, =20 tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_16); ret =3D do_ld2_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } =20 @@ -158,7 +163,7 @@ uint32_t cpu_ldl_mmu(CPUArchState *env, abi_ptr addr, =20 tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_32); ret =3D do_ld4_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } =20 @@ -169,7 +174,7 @@ uint64_t cpu_ldq_mmu(CPUArchState *env, abi_ptr addr, =20 tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_64); ret =3D do_ld8_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } =20 @@ -180,7 +185,7 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, =20 tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_128); ret =3D do_ld16_mmu(env_cpu(env), addr, oi, ra); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, int128_getlo(ret), int128_gethi(ret), oi); return ret; } =20 @@ -188,10 +193,15 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, * Store helpers for cpu_ldst.h */ =20 -static void plugin_store_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi) +static void plugin_store_cb(CPUArchState *env, abi_ptr addr, + uint64_t value_low, + uint64_t value_high, + MemOpIdx oi) { if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_W); + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + value_low, value_high, + oi, QEMU_PLUGIN_MEM_W); } } =20 @@ -199,7 +209,7 @@ void cpu_stb_mmu(CPUArchState *env, abi_ptr addr, uint8= _t val, MemOpIdx oi, uintptr_t retaddr) { helper_stb_mmu(env, addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } =20 void cpu_stw_mmu(CPUArchState *env, abi_ptr addr, uint16_t val, @@ -207,7 +217,7 @@ void cpu_stw_mmu(CPUArchState *env, abi_ptr addr, uint1= 6_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_16); do_st2_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } =20 void cpu_stl_mmu(CPUArchState *env, abi_ptr addr, uint32_t val, @@ -215,7 +225,7 @@ void cpu_stl_mmu(CPUArchState *env, abi_ptr addr, uint3= 2_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_32); do_st4_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } =20 void cpu_stq_mmu(CPUArchState *env, abi_ptr addr, uint64_t val, @@ -223,7 +233,7 @@ void cpu_stq_mmu(CPUArchState *env, abi_ptr addr, uint6= 4_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_64); do_st8_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } =20 void cpu_st16_mmu(CPUArchState *env, abi_ptr addr, Int128 val, @@ -231,7 +241,7 @@ void cpu_st16_mmu(CPUArchState *env, abi_ptr addr, Int1= 28 val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) =3D=3D MO_128); do_st16_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, int128_getlo(val), int128_gethi(val), oi); } =20 /* --=20 2.39.2 From nobody Sun Nov 24 19:41:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1720293299; cv=none; d=zohomail.com; s=zohoarc; b=ImJUD977cOhMIXFdRcWBxtaaxybrJLMXiVRMgbBeMOvJ4jtp6ny79/QYj0kewRKk1o5rQhxdvipps7hgrBUhIJf7/yQ/Z/Yykrb5Way7V4LYzpibv0SbfAYNArNx9mvTO4Hhi1VAv+zGACw9NKlzBXLCwhLiPNEyJYW7YfFW84g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720293299; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=29AmjN08v39I61gQ3jvm15T5PbVM6dvTT6GDpWQa9nI=; b=CIdlkc3ske01m5c5nv+0z0zOxtJ3U1Wep52BdNX0ntiyZ0X2F2mVXuD58YrkyPFk2/IDu0oVf0aw7RHiOQDsun4TQz/o2mIBzBsT6nYT98CZkX0Me1L/xgcNTiOgYLd57bt+67odOfFbghhKDh+UGC2Jp4+HdJPjGzx1B8IF/ew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720293299926640.9058292997639; Sat, 6 Jul 2024 12:14:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQAr2-0002Cj-35; Sat, 06 Jul 2024 15:13:52 -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 1sQAqz-0002CN-V5 for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:49 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQAqy-00044k-5c for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:49 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1fb05b0be01so15520275ad.2 for ; Sat, 06 Jul 2024 12:13:47 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb6153cb3bsm17304305ad.129.2024.07.06.12.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 12:13:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720293226; x=1720898026; 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=29AmjN08v39I61gQ3jvm15T5PbVM6dvTT6GDpWQa9nI=; b=SEHTXWSOEF9Ti4uIt8c8ENpHY9ryQ4U01opzwmPHBGMhbWyQe8nm4jMsRyrXUY9Mm4 IL0UGfCaJh/kyHg3zrnsYyVwPWONBeIWLsnpE9cE2Qormqr8T8JVnSwHvsmIxOXb7y29 ixh4Re+IPK03o4kbBp4OvCg86UmPfGzdRoiCcntLhOl7Y/9DtZRE0nfsqlysR9faUk1K M3bUinXMmFoBiRraVKYWv8Dos8uSkFdJOYSfJMKzHlhs16sAJtjyeN85pNmPDnSVq5pu lFMMD5NnYfX2d+YobUleetHde4x+K9nq9cdtstEYm/79n1cPuxaZNV5Wp/mSL+5aBaS6 C6yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720293226; x=1720898026; 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=29AmjN08v39I61gQ3jvm15T5PbVM6dvTT6GDpWQa9nI=; b=IDti/UylwYuHakytQj9cDp9h3UUX5+Dhagoln6teW8RWZTxWl9+/bq+jS8pbVFJMi6 IO+CT6PawVWG5olTEWRdbw+iQyNnOk9E6sXQksWhXjgqGhkgqpzrNEqVKQxWnh8DJr6f ydlPEdkKdmSXq/OfoWWAbu6y/LJW3k2pvBPm3lBQhjDNuri68uNKXf8rwNxUkIR0nhFP SytJ3gweL5OxlT4bojgenKwMCVxh2Pcj6QEHwK7Vj3naA8W7dRBhTlqKStreRcZACVwm OrmgiONOR2+fsHg8ATxRcaj0gShipc/rcF1FLepNK/dOXgrcquq+IpjPJdibahytUu2+ QRCA== X-Gm-Message-State: AOJu0YxZUrUy1LnaH6rlWoHo0K0RGTulDxtPHQmQUGKALlIc2JPG45un cmDAsfls5Lv16jBdV20ufB6iVJyAfZ4r2VrzgfUZN7bGDCJujEzpAoiEFUy+ZSTt5zjkr3S4Urv NyjA= X-Google-Smtp-Source: AGHT+IEQ8YUUTIXLW03S0KMC5gE6GQtE6k+TgQh3bRdiZIkQ+NSnzLFC45tjFuJJRtzj1yHWZCX4vA== X-Received: by 2002:a17:902:ec8c:b0:1fb:1fd6:5e48 with SMTP id d9443c01a7336-1fb33e055bbmr68609115ad.7.1720293225842; Sat, 06 Jul 2024 12:13:45 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost , Yanan Wang , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v6 3/7] plugins: extend API to get latest memory value accessed Date: Sat, 6 Jul 2024 12:13:31 -0700 Message-Id: <20240706191335.878142-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240706191335.878142-1-pierrick.bouvier@linaro.org> References: <20240706191335.878142-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1720293301093100001 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Pierrick Bouvier Reviewed-by: Alex Benn=C3=A9e --- 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 c71c705b699..649ce89815f 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -262,6 +262,29 @@ enum qemu_plugin_mem_rw { QEMU_PLUGIN_MEM_RW, }; =20 +enum qemu_plugin_mem_value_type { + QEMU_PLUGIN_MEM_VALUE_U8, + QEMU_PLUGIN_MEM_VALUE_U16, + QEMU_PLUGIN_MEM_VALUE_U32, + QEMU_PLUGIN_MEM_VALUE_U64, + QEMU_PLUGIN_MEM_VALUE_U128, +}; + +/* typedef qemu_plugin_mem_value - value accessed during a load/store */ +typedef struct { + enum qemu_plugin_mem_value_type type; + union { + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + struct { + uint64_t low; + uint64_t high; + } u128; + } data; +} qemu_plugin_mem_value; + /** * enum qemu_plugin_cond - condition to enable callback * @@ -551,6 +574,15 @@ bool qemu_plugin_mem_is_big_endian(qemu_plugin_meminfo= _t info); QEMU_PLUGIN_API bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info); =20 +/** + * qemu_plugin_mem_get_mem_value() - return last value loaded/stored + * @info: opaque memory transaction handle + * + * Returns: memory value + */ +QEMU_PLUGIN_API +qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info= ); + /** * qemu_plugin_get_hwaddr() - return handle for memory operation * @info: opaque memory info structure diff --git a/plugins/api.c b/plugins/api.c index 2ff13d09de6..3316d4a04d4 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -351,6 +351,39 @@ bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t in= fo) return get_plugin_meminfo_rw(info) & QEMU_PLUGIN_MEM_W; } =20 +qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info) +{ + uint64_t low =3D current_cpu->neg.plugin_mem_value_low; + qemu_plugin_mem_value value; + + switch (qemu_plugin_mem_size_shift(info)) { + case 0: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U8; + value.data.u8 =3D (uint8_t)low; + break; + case 1: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U16; + value.data.u16 =3D (uint16_t)low; + break; + case 2: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U32; + value.data.u32 =3D (uint32_t)low; + break; + case 3: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U64; + value.data.u64 =3D low; + break; + case 4: + value.type =3D QEMU_PLUGIN_MEM_VALUE_U128; + value.data.u128.low =3D low; + value.data.u128.high =3D current_cpu->neg.plugin_mem_value_high; + break; + default: + g_assert_not_reached(); + } + return value; +} + /* * Virtual Memory queries */ diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index ca773d8d9fe..eed9d8abd90 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -13,6 +13,7 @@ qemu_plugin_insn_size; qemu_plugin_insn_symbol; qemu_plugin_insn_vaddr; + qemu_plugin_mem_get_value; qemu_plugin_mem_is_big_endian; qemu_plugin_mem_is_sign_extended; qemu_plugin_mem_is_store; --=20 2.39.2 From nobody Sun Nov 24 19:41:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1720293304; cv=none; d=zohomail.com; s=zohoarc; b=I1kyj2nXtWCibu74d9wPBwLXsbfyafYqd+DIfjQY/JWO4diJ+Tb/ZQhFD+hCWNBSrP1UCrPLP/2132pm52MJAespcSxfzxMQTJPhICQTf0KFgx/dFM5fG6UveCiBYNM9BMow1BPn9B3V9iYckWG6Vp6mstqi/gjVMfqMbvvFoVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720293304; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EOVQG8CjYwbYZDeC+WrM19zb25ZnXpMuyBziO7HazqU=; b=Um/XWGZSV2hR3EyfKE/tQ4LHN2t8SL/EZBrCYunxj1i7KeI6VZ92DxWX9IvFbXFjl+bEyA+uHmO6LWzC0hAM2F0j6r67IopUlDpVtXi4wAFlv5jameDMX7w6RI+ohsinSFd76Gzkwchs6GoJ1fWuTP549r3Wm4T17txetCpIVmU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720293304146762.3208183469917; Sat, 6 Jul 2024 12:15:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQArH-0002Fg-FC; Sat, 06 Jul 2024 15:14:07 -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 1sQArF-0002F2-Fm for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:14:05 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQAr0-000455-Py for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:14:05 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1f9fb3ca81bso15809695ad.3 for ; Sat, 06 Jul 2024 12:13:49 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb6153cb3bsm17304305ad.129.2024.07.06.12.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 12:13:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720293227; x=1720898027; 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=EOVQG8CjYwbYZDeC+WrM19zb25ZnXpMuyBziO7HazqU=; b=wJY6/rIqDV0scUNDMzOu7Gra417DP008PHaTn9xTmlyPB773p+z0WG1lpe5hkjCkdX B204JiAxxinyc9XFezfH/PNPVRqjkv0F6oVBkJjpZr+GKYwo/GuneaqsCzpZhaTslQCn Z30b5uvYQY1BxKOBKLF+DNhXvQx1Yg2YEJ3iyhp+IWHUjUUsT3lncLbPRPfS8bmS7PA5 R6C1pvUfNLcpIFXszroZE6OCLjFTQyTFKy3HEJjwiOsaNMA2/4OmyEwEuYM9tXgetYRo tXAoGeo2P+s9JMnvpYaZczWFTUtRgiijGik6fhSDZDtrH6juydoEG6cEToK2mcGL+Ocv 5/GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720293227; x=1720898027; 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=EOVQG8CjYwbYZDeC+WrM19zb25ZnXpMuyBziO7HazqU=; b=uhSMUl7+eGTel4r2ztXHIiENYze3Avefvz1vtk4iFKo99jq0Wo8itHvlswzM5mU+YF GfX7GaFBfGdDn8XqXgakyB/qfg2HBbg1BH5gBjR7Cx3VVYmVrxeHCC0YCCEghVNYZoik O/htYoM2SirMkgKwWX2R/29QfEtrunHpELFmhLk0iMQqBjOGoVUeu2vqx1Sns3zLZgha iz7ZEyMoHGM6Az4hYz54i+TKgfj38VtrQYqjKt7Pb70kC5xSDpOzrh1oXVXtIBAkK6yS ZKyhRBPLnf45OX3NSMbr576cHVbbLcH0vQR8w/4tM25GFMWP4Nrbdde/Asmv9UH/pCmW H87w== X-Gm-Message-State: AOJu0YwLADH9lBP4kRf0HzimrjowpsseLoFblFzKshT9eRrs8o3LuxEJ gifqu+CzbKFcW03d5mpONr4FLC9mW4Pvhgufa+judFsvMKqjTc85ATS54N+h51XP4iwCOmTRP5f pPOU= X-Google-Smtp-Source: AGHT+IEFe7T1JSLTV153DdUh1RSDePZ8ViLcdAwVyS+wCxMOjahf26VLsr0B8I/4zwm5ZY0h0ounog== X-Received: by 2002:a17:903:41c7:b0:1fb:6616:9cd4 with SMTP id d9443c01a7336-1fb66169f60mr14796955ad.38.1720293227456; Sat, 06 Jul 2024 12:13:47 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost , Yanan Wang , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v6 4/7] tests/tcg: add mechanism to run specific tests with plugins Date: Sat, 6 Jul 2024 12:13:32 -0700 Message-Id: <20240706191335.878142-5-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240706191335.878142-1-pierrick.bouvier@linaro.org> References: <20240706191335.878142-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x629.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, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1720293305468100002 Content-Type: text/plain; charset="utf-8" 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 --- 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 cb8cfeb6dac..52616544d52 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -152,10 +152,11 @@ PLUGINS=3D$(patsubst %.c, lib%.so, $(notdir $(wildcar= d $(PLUGIN_SRC)/*.c))) # only expand MULTIARCH_TESTS which are common on most of our targets # to avoid an exponential explosion as new tests are added. We also # add some special helpers the run-plugin- rules can use below. +# In more, extra tests can be added using PLUGINS_TESTS variable. =20 ifneq ($(MULTIARCH_TESTS),) $(foreach p,$(PLUGINS), \ - $(foreach t,$(MULTIARCH_TESTS),\ + $(foreach t,$(MULTIARCH_TESTS) $(PLUGINS_TESTS),\ $(eval run-plugin-$(t)-with-$(p): $t $p) \ $(eval RUN_TESTS+=3Drun-plugin-$(t)-with-$(p)))) endif # MULTIARCH_TESTS --=20 2.39.2 From nobody Sun Nov 24 19:41:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1720293288; cv=none; d=zohomail.com; s=zohoarc; b=EM0lP6m0r6lYGINQY2Qi7CiAtxqsggBKPChsillQmQRTUrJ1PfCNJgCIr3jeMkGu4kprFaBb49xmha7BDN/R+cWF7tW6cYo7oHtEuwykM3MSx/SANHmFXqIg6nJs0CydncvkH6ZSJ61MHU3OOx/xgX3qHtcgvYktTUNV8HQxBiU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720293288; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=t4bNu6CI6omvOt9CPXqjom5ah5T2zFduQZDfzw7pbQM=; b=VV57/OUfa9m6MW3HcgOXVxmT5fRSQmptVMsDF+379fck7RW6WS4kXUNWkH4veJcizRGl7rh88AnanwuRQwQ0sNGmqbuS/eLSJ7CHv+m9OWFMJc5f0KZZXA9OqDF8rZ90fKHTXw02fNfjeT3MBVnD+R+4SOeWbQ4j86tWrtzTVVA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720293288101718.4189393416871; Sat, 6 Jul 2024 12:14:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQAr4-0002Da-LX; Sat, 06 Jul 2024 15:13:54 -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 1sQAr3-0002DC-1K for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:53 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0: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 1sQAr1-00045K-GB for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:52 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1fb70169c23so1703325ad.1 for ; Sat, 06 Jul 2024 12:13:50 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb6153cb3bsm17304305ad.129.2024.07.06.12.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 12:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720293229; x=1720898029; 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=t4bNu6CI6omvOt9CPXqjom5ah5T2zFduQZDfzw7pbQM=; b=JEinJQdaGKvBpFxnYUO3y66s4dl2SiY7N/3ShcSEh3qU/+Zw2vkoM6JO/Js2Qlv5DX arGbN6hu739fmrblTMJpdfGLQE0AyVZUoU4tthpMyZNZ/eSdH/2kFxqzMoB2mhBPqdmB wIO+TP9LP4Y9dM2CFkdIawTBik0EnFIwYYTwPgut10e1Kyj8FgOdJaMqvWD9pz7OtCXe VpWg4X0MXrGoBZJxwhiFqeaMBV6ZpXkk8b2DzzYkpv0yG/c001ZKhPiR/ugRLYHexLdC Tppn4KrHndGwZ2uHxV54PWRmCyYafikorsyiuU/uOO5myqChUK/VattBGoH+WUHIcffC Ntkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720293229; x=1720898029; 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=t4bNu6CI6omvOt9CPXqjom5ah5T2zFduQZDfzw7pbQM=; b=Fu8zDZROxl4krvLAwrRdL7eYjfqeuLQbnr0EcxfbidrsxkQjdnwnvXlrfLMl4aDBD2 vgYIJvvAmpnq/ksph2FwEqWaL8mY0Nj8i/PTO+qg2lhwU2OOQlLYoszxBw9c33ljugUM OyvHhDuAsmmRLDvDzW+RKfzB4dcU2C7TVqdOFsMOXdYQJEMB0h+5Rv74gegwfgaGhXPU 71YxCaim/GY3H4d2AHPWoU9WLEcgEw/E6/LjNT6iAitQ2a6qVRwOKRGCdOmoSayZFMKw cBVQSUPJ57ntXg1YROSxogblYzJU1CcE08H0lsMn1vieJaLjDIBREjF6rGzjHXRibKNy ilcQ== X-Gm-Message-State: AOJu0YwB7KDtE/OVszj+vLllan2sDNwd57fXLEbXYV22Vvll3+zxj3El 2Si6f+imhI7eIvCHD8xJpgJV9DTZ+FM41NMDj4atuG7Za4aOK4sOk9WrcE1JkNGZs+ne9jwYivM 4pMA= X-Google-Smtp-Source: AGHT+IFZCHK2O1EIiWQwWBAhjnSm3AjaBNheqhWLqOcYl7No9gcv6sWAdQOAu+rx6+OPAYpv3iAanQ== X-Received: by 2002:a17:902:e9c6:b0:1f6:89b1:a419 with SMTP id d9443c01a7336-1fb33e15326mr45465225ad.17.1720293229102; Sat, 06 Jul 2024 12:13:49 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost , Yanan Wang , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v6 5/7] tests/tcg: allow to check output of plugins Date: Sat, 6 Jul 2024 12:13:33 -0700 Message-Id: <20240706191335.878142-6-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240706191335.878142-1-pierrick.bouvier@linaro.org> References: <20240706191335.878142-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1720293289890100002 Content-Type: text/plain; charset="utf-8" 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 --- tests/tcg/Makefile.target | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index 52616544d52..6f50b0176ea 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -90,6 +90,7 @@ CFLAGS=3D LDFLAGS=3D =20 QEMU_OPTS=3D +CHECK_PLUGIN_OUTPUT_COMMAND=3Dtrue =20 =20 # If TCG debugging, or TCI is enabled things are a lot slower @@ -180,6 +181,9 @@ run-plugin-%: -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \ -d plugin -D $*.pout \ $(call strip-plugin,$<)) + $(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 +198,9 @@ run-plugin-%: -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \ -d plugin -D $*.pout \ $(QEMU_OPTS) $(call strip-plugin,$<)) + $(call quiet-command, $(CHECK_PLUGIN_OUTPUT_COMMAND) $*.pout, \ + TEST, check plugin $(call extract-plugin,$@) output \ + with $(call strip-plugin,$<)) endif =20 gdb-%: % --=20 2.39.2 From nobody Sun Nov 24 19:41:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1720293318; cv=none; d=zohomail.com; s=zohoarc; b=krmCxQaHPA0aVaoLd1sULNsf0ed4fg+1PBSdVTCp49iXpKyqXOlVuX0/r7c6jN2HfITurdfOGSYUzTrUInXDtTg69w7bfB/aTMNG1LMxWtpo77/kP9wewod+DfSH1LwSz+mEgC+BP/XyefJCbrSz+iOkZ2aoOIxaHES8XFxoxoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720293318; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Q3v41GFzb0/piPBsIvskwb3RVBKxsZFvBfDW4N/dtnI=; b=DYqL9xQiYLGKYDk2jlA1+PS0UU4FAPfQ03qJVMvk8iFjriCp/RNJoILzdFCnTzqHwRx879rTrpPgQhZQ+fsO4yhnBUSoOHNgIG1TC1RtrW/hr+Xo6SJrQcfY7SMjxDYUJe1hn0OiOnjLxESxkd6Yw//lh0dNR5dQdaSBtqvuqw4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720293318409624.8517555104936; Sat, 6 Jul 2024 12:15:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQAr6-0002Dt-6z; Sat, 06 Jul 2024 15:13:56 -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 1sQAr4-0002De-N7 for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:54 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQAr2-00045V-VK for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:54 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-70b09c2ade6so1272512b3a.3 for ; Sat, 06 Jul 2024 12:13:52 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb6153cb3bsm17304305ad.129.2024.07.06.12.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 12:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720293230; x=1720898030; 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=Q3v41GFzb0/piPBsIvskwb3RVBKxsZFvBfDW4N/dtnI=; b=Gyb52TU+XeUqFj8bI07cQmSlLXhMeL2l1kRnwAIE/KdPVuJB3T78bwVoXnypNVLZ4W jTzwHzUlfUM8DMBNYoroFp3S1PKpV0Je0ce5ZetwuHJN8HTc/vAB+FPjTU7hj/QjWjHM YA88XSCdT0fbSq0jQY/w+FyztOWEhRwyTb0mLxUZ/I6QCXS2lzW1W3Enyl5/WIGi0AxK 86XeKey6I7xwQ90zaimsWAwcuvUfI9XhFjc27BizgCzqpMzszGGmDPRrY+RISWTsuLDb BeaL1ISMWhVnWJa+VMMfN8SvexR6Czwk2QVKBTtYSj68MSa/pgELTao3TmPE9BYIfLcz 8pHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720293230; x=1720898030; 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=Q3v41GFzb0/piPBsIvskwb3RVBKxsZFvBfDW4N/dtnI=; b=uOY2HZT4UmBBarQBH2uYg4Yn4IiTuhplXjK+JunZV1orKMK6ZNVYss32uaUg6Hgwow UyvrphaWqqF02GZGuIG1qGYD43EgVJo/7CisQyZOCyzP7zb9505tpozFY6I7es+r1JPX ORtdoPrh2BJl/rOQ+GGcK6mhHr38worITiKiwHnyQpZ3XwqQmQQXobVyAlXBcW4fOQJA 2iKzEqUyJqv2KKhnBY+9y9kHNzrH+j22i3OnEc2znF/IQmqxJ/zSHg03qXwdGqIxW/le W/1bsmMGrvviDkrkGkQ2HMWLIJJfAJ+Vmfriz/uEg4YwGn2gDKQ0lhS31KBYZR0Uhh1S Ww7A== X-Gm-Message-State: AOJu0Yy/uZ0lx/4xvM49ikLnCQ/XQEsR4YcLA8ycipmb4DF8W4OgDA6M kbTN/Dd0ZVsIhbu9pYUNaaSV8CZbQA7FyBwvbmc+m4N4YU/F0aCdz+Jjh9GFv7mh9AeBi8aX31g YmYA= X-Google-Smtp-Source: AGHT+IH3cUfK1ZFgoDPsjU+AiaIoqxW2X+lQ1IASALADGHtINzjjSjq9YBRZEtj6BEx9gV8auTxg4Q== X-Received: by 2002:a05:6a20:9186:b0:1c0:ef24:4125 with SMTP id adf61e73a8af0-1c0ef24b42amr341721637.26.1720293230225; Sat, 06 Jul 2024 12:13:50 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost , Yanan Wang , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v6 6/7] tests/plugin/mem: add option to print memory accesses Date: Sat, 6 Jul 2024 12:13:34 -0700 Message-Id: <20240706191335.878142-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240706191335.878142-1-pierrick.bouvier@linaro.org> References: <20240706191335.878142-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1720293319166100001 Content-Type: text/plain; charset="utf-8" By using "print-accesses=3Dtrue" option, mem plugin will now print every value accessed, with associated size, type (store vs load), symbol, instruction address and phys/virt address accessed. Reviewed-by: Richard Henderson Reviewed-by: Xingtao Yao Signed-off-by: Pierrick Bouvier --- tests/plugin/mem.c | 69 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index b650dddcce1..086e6f5bdfc 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -21,10 +21,15 @@ typedef struct { uint64_t io_count; } CPUCount; =20 +typedef struct { + uint64_t vaddr; + const char *sym; +} InsnInfo; + static struct qemu_plugin_scoreboard *counts; static qemu_plugin_u64 mem_count; static qemu_plugin_u64 io_count; -static bool do_inline, do_callback; +static bool do_inline, do_callback, do_print_accesses; static bool do_haddr; static enum qemu_plugin_mem_rw rw =3D QEMU_PLUGIN_MEM_RW; =20 @@ -60,6 +65,44 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin= _meminfo_t meminfo, } } =20 +static void print_access(unsigned int cpu_index, qemu_plugin_meminfo_t mem= info, + uint64_t vaddr, void *udata) +{ + InsnInfo *insn_info =3D udata; + unsigned size =3D 8 << qemu_plugin_mem_size_shift(meminfo); + const char *type =3D qemu_plugin_mem_is_store(meminfo) ? "store" : "lo= ad"; + qemu_plugin_mem_value value =3D qemu_plugin_mem_get_value(meminfo); + uint64_t hwaddr =3D + qemu_plugin_hwaddr_phys_addr(qemu_plugin_get_hwaddr(meminfo, vaddr= )); + g_autoptr(GString) out =3D g_string_new(""); + g_string_printf(out, + "0x%"PRIx64",%s,0x%"PRIx64",0x%"PRIx64",%d,%s,", + insn_info->vaddr, insn_info->sym, + vaddr, hwaddr, size, type); + switch (value.type) { + case QEMU_PLUGIN_MEM_VALUE_U8: + g_string_append_printf(out, "0x%02"PRIx8, value.data.u8); + break; + case QEMU_PLUGIN_MEM_VALUE_U16: + g_string_append_printf(out, "0x%04"PRIx16, value.data.u16); + break; + case QEMU_PLUGIN_MEM_VALUE_U32: + g_string_append_printf(out, "0x%08"PRIx32, value.data.u32); + break; + case QEMU_PLUGIN_MEM_VALUE_U64: + g_string_append_printf(out, "0x%016"PRIx64, value.data.u64); + break; + case QEMU_PLUGIN_MEM_VALUE_U128: + g_string_append_printf(out, "0x%016"PRIx64"%016"PRIx64, + value.data.u128.high, value.data.u128.low); + break; + default: + g_assert_not_reached(); + } + g_string_append_printf(out, "\n"); + qemu_plugin_outs(out->str); +} + static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) { size_t n =3D qemu_plugin_tb_n_insns(tb); @@ -79,6 +122,16 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct q= emu_plugin_tb *tb) QEMU_PLUGIN_CB_NO_REGS, rw, NULL); } + if (do_print_accesses) { + /* we leak this pointer, to avoid locking to keep track of it = */ + InsnInfo *insn_info =3D g_malloc(sizeof(InsnInfo)); + const char *sym =3D qemu_plugin_insn_symbol(insn); + insn_info->sym =3D sym ? sym : ""; + insn_info->vaddr =3D qemu_plugin_insn_vaddr(insn); + qemu_plugin_register_vcpu_mem_cb(insn, print_access, + QEMU_PLUGIN_CB_NO_REGS, + rw, (void *) insn_info); + } } } =20 @@ -117,6 +170,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); return -1; } + } else if (g_strcmp0(tokens[0], "print-accesses") =3D=3D 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &do_print_accesses)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); + return -1; + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; @@ -129,6 +188,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, return -1; } =20 + if (do_print_accesses) { + g_autoptr(GString) out =3D g_string_new(""); + g_string_printf(out, + "insn_vaddr,insn_symbol,mem_vaddr,mem_hwaddr," + "access_size,access_type,mem_value\n"); + qemu_plugin_outs(out->str); + } + counts =3D qemu_plugin_scoreboard_new(sizeof(CPUCount)); mem_count =3D qemu_plugin_scoreboard_u64_in_struct( counts, CPUCount, mem_count); --=20 2.39.2 From nobody Sun Nov 24 19:41:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1720293304; cv=none; d=zohomail.com; s=zohoarc; b=aAKQJMtZZD1q2GCRrVj0VGrvFgXLzu+MjPUSYhnpe4ghzH3Z0HQ8FvpiX0VfDQUqDgDB/jzV8sRYKK5QkDHPpVN/uhrZaNCLaVCM4X5z6mox73Pdat9lxHgaaRi1ZcUgA3XxeOvLRRnNRpRlELk++hpMoZYQPuUu98K7+29BKZo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720293304; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jSYKX7tgmPWgH1eoungM9Ek83i1kIQO2hxPk9JjJ0jw=; b=erguPmvtS0yhNOmxQxfvGygsU+WPHrLARTLSSDz9EKNt1Q6khj9YKyzhAfNkSGDfn0G4zfRBfl1O8SXujn8vXMrmrIT67vC0rxxSpPNcv8T4D8dlZvjcuBvouviHyU8PqUiQZtjdvfO/tWnkhYjr4fp2DgJ12Rxg6UyyZ7Bd/W4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720293304892564.1699753227607; Sat, 6 Jul 2024 12:15:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQAr7-0002EJ-9l; Sat, 06 Jul 2024 15:13:57 -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 1sQAr6-0002Du-6D for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:56 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQAr3-00045g-Ps for qemu-devel@nongnu.org; Sat, 06 Jul 2024 15:13:55 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1f65a3abd01so18387685ad.3 for ; Sat, 06 Jul 2024 12:13:53 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb6153cb3bsm17304305ad.129.2024.07.06.12.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 12:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720293231; x=1720898031; 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=jSYKX7tgmPWgH1eoungM9Ek83i1kIQO2hxPk9JjJ0jw=; b=qqwdRoxFtouSAaXWvRQZS+ftVI+mpnYfjpyXEb6Zvxnwr6aX8ISMm/xs3b7maAT1nX Kt7/fMH2t3pPU7P/2VP0E1ydrNInkGwFVZV8ttQUQBUL1Hhrj4WU88VRxsgzDEZjlQxp FhvEQBoI69g8/nR3xfQOl2LQuWlDjUwD5RHcH2iCpwog9b/kvXhkWphxOGpe4f3VFyw2 qhzYn5jEEuEX/1crqlZoeQPbk8az1AV1ztWfdN6bEmqucmZ/Mkgp/Veyr2u0QbXLu67g zhpxTypUE+FRTZNVkwhyrevMKqSf3Jxe4p3Ipc1VNiKwAC5Kw3BW4pjv/8UH9tDux8wK nRgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720293231; x=1720898031; 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=jSYKX7tgmPWgH1eoungM9Ek83i1kIQO2hxPk9JjJ0jw=; b=oxH4S2zu8iybl20twEuKeFo3Fr2DKIUS7BUOvVMbTyrEwVt36pUitlWvMZjROLbn+i 4UZnDoLwIXV/H9vA5G0+/pzTFAdfEFRmN4AJB6pmXhEXp57fzlwwIR32fXFrRD5rfl05 NRZ0C0yv/GqFgKxfebHTLsqdb4738VZVfHMwaPcZCFkugrNl3/wG0m0eEMX91jezpxP8 ygym7Wmnur6Q/b3bLS1yxz8WerAFFO2kRXiwf9MAQTQPy23HvTIg7SFGOPq5mFjMNKlU BiiMW1n0j79UuE1QY79wOmh8C+S3gWXLc1sRm71JsAOV2tr1n3L2QtBXB8jv2PVtOuvV QOZw== X-Gm-Message-State: AOJu0YzX7zyJoW6VrFvqqH42rzt8yk8bIG2mxvWA+TrRb7SYXingTqnX c6noyEMrywqKLsRjKiKeA2x2i7lFYnQ+Akmbd62LhKlPcuYtlxA/ipaxEu+C1xZhRaaclluj5jn r2x8= X-Google-Smtp-Source: AGHT+IFLRSswI9I90e9F7ejRQ5AbBT42voEC2WFxKo2suC+B0G7v/l/zk/eWVLgouY5DebjytqeBhQ== X-Received: by 2002:a17:902:654a:b0:1fb:18a8:1939 with SMTP id d9443c01a7336-1fb33e1965dmr52716065ad.20.1720293231364; Sat, 06 Jul 2024 12:13:51 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost , Yanan Wang , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v6 7/7] tests/tcg/x86_64: add test for plugin memory access Date: Sat, 6 Jul 2024 12:13:35 -0700 Message-Id: <20240706191335.878142-8-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240706191335.878142-1-pierrick.bouvier@linaro.org> References: <20240706191335.878142-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1720293305467100001 Content-Type: text/plain; charset="utf-8" Add an explicit test to check expected memory values are read/written. For sizes 8, 16, 32, 64 and 128, we generate a load/store operation. For size 8 -> 64, we generate an atomic __sync_val_compare_and_swap too. For 128bits memory access, we rely on SSE2 instructions. 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. Can be run with: make -C build/tests/tcg/x86_64-linux-user run-plugin-test-plugin-mem-access= -with-libmem.so Tested-by: Xingtao Yao Signed-off-by: Pierrick Bouvier --- tests/tcg/x86_64/test-plugin-mem-access.c | 89 +++++++++++++++++++++ tests/tcg/x86_64/Makefile.target | 7 ++ tests/tcg/x86_64/check-plugin-mem-access.sh | 48 +++++++++++ 3 files changed, 144 insertions(+) create mode 100644 tests/tcg/x86_64/test-plugin-mem-access.c create mode 100755 tests/tcg/x86_64/check-plugin-mem-access.sh diff --git a/tests/tcg/x86_64/test-plugin-mem-access.c b/tests/tcg/x86_64/t= est-plugin-mem-access.c new file mode 100644 index 00000000000..7fdd6a55829 --- /dev/null +++ b/tests/tcg/x86_64/test-plugin-mem-access.c @@ -0,0 +1,89 @@ +#include +#include +#include +#include + +static void *data; + +#define DEFINE_STORE(name, type, value) \ +static void store_##name(void) \ +{ \ + *((type *)data) =3D value; \ +} + +#define DEFINE_ATOMIC_OP(name, type, value) \ +static void atomic_op_##name(void) \ +{ \ + *((type *)data) =3D 0x42; \ + __sync_val_compare_and_swap((type *)data, 0x42, value); \ +} + +#define DEFINE_LOAD(name, type) \ +static void load_##name(void) \ +{ \ + register type var asm("eax") =3D *((type *) data); \ + (void)var; \ +} + +DEFINE_STORE(u8, uint8_t, 0xf1) +DEFINE_ATOMIC_OP(u8, uint8_t, 0xf1) +DEFINE_LOAD(u8, uint8_t) +DEFINE_STORE(u16, uint16_t, 0xf123) +DEFINE_ATOMIC_OP(u16, uint16_t, 0xf123) +DEFINE_LOAD(u16, uint16_t) +DEFINE_STORE(u32, uint32_t, 0xff112233) +DEFINE_ATOMIC_OP(u32, uint32_t, 0xff112233) +DEFINE_LOAD(u32, uint32_t) +DEFINE_STORE(u64, uint64_t, 0xf123456789abcdef) +DEFINE_ATOMIC_OP(u64, uint64_t, 0xf123456789abcdef) +DEFINE_LOAD(u64, uint64_t) + +static void store_u128(void) +{ + _mm_store_si128(data, _mm_set_epi32(0xf1223344, 0x55667788, + 0xf1234567, 0x89abcdef)); +} + +static void load_u128(void) +{ + __m128i var =3D _mm_load_si128(data); + (void)var; +} + +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); + + data =3D malloc(sizeof(__m128i)); + atomic_op_u8(); + store_u8(); + load_u8(); + + atomic_op_u16(); + store_u16(); + load_u16(); + + atomic_op_u32(); + store_u32(); + load_u32(); + + atomic_op_u64(); + store_u64(); + load_u64(); + + store_u128(); + load_u128(); + + free(data); +} diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.t= arget index eda9bd7396c..3edc29b924d 100644 --- a/tests/tcg/x86_64/Makefile.target +++ b/tests/tcg/x86_64/Makefile.target @@ -16,6 +16,7 @@ X86_64_TESTS +=3D noexec X86_64_TESTS +=3D cmpxchg X86_64_TESTS +=3D adox X86_64_TESTS +=3D test-1648 +PLUGINS_TESTS +=3D test-plugin-mem-access TESTS=3D$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64 else TESTS=3D$(MULTIARCH_TESTS) @@ -26,6 +27,12 @@ adox: CFLAGS=3D-O2 run-test-i386-ssse3: QEMU_OPTS +=3D -cpu max run-plugin-test-i386-ssse3-%: QEMU_OPTS +=3D -cpu max =20 +run-plugin-test-plugin-mem-access-with-libmem.so: \ + PLUGIN_ARGS=3D$(COMMA)print-accesses=3Dtrue +run-plugin-test-plugin-mem-access-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=3D \ + $(SRC_PATH)/tests/tcg/x86_64/check-plugin-mem-access.sh + test-x86_64: LDFLAGS+=3D-lm -lc test-x86_64: test-i386.c test-i386.h test-i386-shift.h test-i386-muldiv.h $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) diff --git a/tests/tcg/x86_64/check-plugin-mem-access.sh b/tests/tcg/x86_64= /check-plugin-mem-access.sh new file mode 100755 index 00000000000..163f1cfad34 --- /dev/null +++ b/tests/tcg/x86_64/check-plugin-mem-access.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +set -euo pipefail + +die() +{ + echo "$@" 1>&2 + exit 1 +} + +check() +{ + file=3D$1 + pattern=3D$2 + grep "$pattern" "$file" > /dev/null || die "\"$pattern\" not found in = $file" +} + +[ $# -eq 1 ] || die "usage: plugin_out_file" + +plugin_out=3D$1 + +expected() +{ + cat << EOF +,store_u8,.*,8,store,0xf1 +,atomic_op_u8,.*,8,load,0x42 +,atomic_op_u8,.*,8,store,0xf1 +,load_u8,.*,8,load,0xf1 +,store_u16,.*,16,store,0xf123 +,atomic_op_u16,.*,16,load,0x0042 +,atomic_op_u16,.*,16,store,0xf123 +,load_u16,.*,16,load,0xf123 +,store_u32,.*,32,store,0xff112233 +,atomic_op_u32,.*,32,load,0x00000042 +,atomic_op_u32,.*,32,store,0xff112233 +,load_u32,.*,32,load,0xff112233 +,store_u64,.*,64,store,0xf123456789abcdef +,atomic_op_u64,.*,64,load,0x0000000000000042 +,atomic_op_u64,.*,64,store,0xf123456789abcdef +,load_u64,.*,64,load,0xf123456789abcdef +,store_u128,.*,128,store,0xf122334455667788f123456789abcdef +,load_u128,.*,128,load,0xf122334455667788f123456789abcdef +EOF +} + +expected | while read line; do + check "$plugin_out" "$line" +done --=20 2.39.2