From patchwork Tue Sep 10 17:20:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 827030 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp423522wrc; Tue, 10 Sep 2024 10:21:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWHkJ1OFl+kKuV0lijEZ88/ptZKu5UVV1yigsEirpCR/F4tAYKvY7jt8x/4DoYLf/vO+1o6rQ==@linaro.org X-Google-Smtp-Source: AGHT+IEfeEyLoaT/rr/GW4N8QrwJltCDPEsgrsZLzzsbmbSKt8WrdqykojJ14fSKvPdhDzf+3su+ X-Received: by 2002:a05:6214:428d:b0:6c5:279b:5dc7 with SMTP id 6a1803df08f44-6c5284f86bcmr230160736d6.25.1725988916245; Tue, 10 Sep 2024 10:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725988916; cv=none; d=google.com; s=arc-20240605; b=ZY12q9eypIFI0R8PxIWAOJdHgmuXxkWS3tt4IK7x0djcZvDNgqyCQOkO0XlUb5GHAw /qb2LOykeraU1desFIt+DB3fCSNCtEpDMGxQBlh1dBnVuo3+/1v7QU3DKZ/Kqoigv2kp Q10jFDKoZSXZ3S0NaYGRIxOzVqlRY+3Mm0qMFtgE1upUFIqotADjbM+1ck4g1hL5hWZx JBbLCLqhbeOwLd7mE5PlYG9cxFv7PZCzu49wG41q107ZdmKH2Q/e5gk0BHkYVL6bJmxv YgXvIYzttqTvij+FtK00CwwsrMiKhrqzWelbAuQFi1xE0RvxaXPJLCN6gwx80meY9b5Q 1OZw== 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=BtKE6YrD9GBuIRiMtCOtofmvZdOCSNCuPxabNoUjSyE=; fh=IEHMnAtVrjcZ/zwxoQMmw0V7I82lp0szHwRXh3VHgCs=; b=cWFBwDl46/MUKMMP2kuanJKt7dNYRLHNmaUj1Om5lQmY+W7GYzcolJSgZPhsuuGPJg DarzX2xilDfz+OdXWcR0IssfcYUCRgSRxnLPwXns/wuHIsjPC1QEPFUcgpqkWiIqwr4h SZ77YLVWyldC3Nz6Y8eNtZlu+44WVPCb3XEmGKQT9YliLCjcBrrrX+eY1WSbCuETkOMj mlhdWlp9oO00jEkiiYeJPJy6B2ghlU2KJ3K/nWzoH+2xvyps96biv0I06vhi1DuhY6iV qG7J61rkTnf2jUq8Fh/n7CDIa/QGyqz7tViUi0xRIcEDRqjz84nwDiSKZIkMEp4Y/GxW horA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IPljwfS/"; 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-6c53477022fsi83928136d6.203.2024.09.10.10.21.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:21: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="IPljwfS/"; 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 1so4Xu-0003C1-OT; Tue, 10 Sep 2024 13:20: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 1so4Xr-00035U-3T for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:51 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4Xo-0002mC-0L for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:50 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2d86f713557so3808812a91.2 for ; Tue, 10 Sep 2024 10:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725988846; x=1726593646; 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=BtKE6YrD9GBuIRiMtCOtofmvZdOCSNCuPxabNoUjSyE=; b=IPljwfS/U//IOrCwO8oMZiO2JvHeav+FTkINPugO6SrE8GxAppWoQmMNQE2AMl9jUD MQJODvMzQRTHJKkvgSCY9SV0NTDZiLcs9/JMT+KqQS5DcHdWNvtl4Bk4j4Ic9yVrrb4U z73p8PYS/Vhzpi1LIjyqi29xyXNoLoZSmnNaaTaZ3BwG3a4l3w8Yx0pgIiLsFlwW+PzE FfJ+aiykbKczuXNOlVklp9D2rlTWfUl0doCqdT1me7LOyHE4l1uys/NecoqpBXOr2Z8Q rD+QI2PuS8DCtFC6UFoX6xYPReGCLwm6KSprEjrPJTWY81P9pSthIMTVQsU2EXmi7n9t ojFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725988846; x=1726593646; 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=BtKE6YrD9GBuIRiMtCOtofmvZdOCSNCuPxabNoUjSyE=; b=uK/DGi9ydXAiksjMV99CMC/bgyMVF+wIzY7KY422KBvjOtXag9/u1jXnduzgfZjFFx xwkEGCvE8ujFXhH/SG+AnGqPv0cPV0SZ3mUPgg1rZaVUjQ1DtlT5bWbeorNaVMfDsFp3 stxqDxzuvcb3NEHVC5vExi3zdBTPmJ61vaBByhYtOFqkFYDpHu7TlO3iTdrgS+um7+QV ILFxoxChKnHE8f/YaUNWrX9FOl3NsEB+j57rTgLVwb1IS75v9xXUTY6e+c6p/84fNcLK Ij09dFgaGa61gtSf1rWyCvFLVA4Ratns7q3VjLrx/2tfmb4obrHmpfJsFsDLjoAAt0Ih 7hkw== X-Gm-Message-State: AOJu0YzkTJ92+a+92YPbfEV591WHA7ajJkOLnnEN/MItC36ScHlRi4+s btPFdeHDTq0VOUu36lGQhUa+y7Etb0cv7v5FXljfQEfGet0VzR4jwsDbL8mH48TVmmj5RGzxzW/ K9yUvfg== X-Received: by 2002:a17:90b:2784:b0:2cd:4100:ef17 with SMTP id 98e67ed59e1d1-2dad50cc488mr16962143a91.31.1725988846504; Tue, 10 Sep 2024 10:20:46 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::9633]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db049883e5sm6685310a91.50.2024.09.10.10.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:20:46 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Eduardo Habkost , Richard Henderson , Pierrick Bouvier , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Mahmoud Mandour , qemu-ppc@nongnu.org, Zhao Liu Subject: [PATCH v8 1/6] plugins: save value during memory accesses Date: Tue, 10 Sep 2024 10:20:28 -0700 Message-Id: <20240910172033.1427812-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> References: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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 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 --- 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 +#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 1c9c775df65..04e9ad49968 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, 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 2897453cacb..bb105e8e688 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 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 *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 95a5c5ff12d..6056598c23d 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 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 */ -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 Tue Sep 10 17:20:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 827028 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp423518wrc; Tue, 10 Sep 2024 10:21:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV6cgeQE1wdLZ03Lks0DdnxcvkdT/nFd1j5gu6nGvsRPgNbNuRCOjgpUvJzV5WUYvt0to3mlg==@linaro.org X-Google-Smtp-Source: AGHT+IF8B3zABgV6XnhPTDGjVHv1rlWven+LprbXgZKi2yVn5GxhZVgD4wKkNa9mHteHHktQhKyL X-Received: by 2002:a05:620a:1728:b0:7a9:af25:802d with SMTP id af79cd13be357-7a9af258469mr1565954685a.40.1725988914441; Tue, 10 Sep 2024 10:21:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725988914; cv=none; d=google.com; s=arc-20240605; b=HormCJLp0QVbHU7WPWtyRSANz+GUEzOykVXXHrUGpcT+VSqCi4GO3aEVDg6Su3lP2t ZAaTqD9+WHtH3wjA71v2kpqM3UqunE4sJ5r3de/c2wRTknUv30aWTR6j+uX3kPc8aQTY f5SqM6ksfzUdGf243urzOJ7z6aYPhrPQRGVxciLmOS/pJw3PpnFXu1y926uJi+bPCLTF PNhay5t2Ak4WAi2bbbBUe85lwRxteYX4Lfamy8N/t9YX4160tZj9FWsXOn6e2EnBd+zD c+XB6BnqWURUiWTYZXBRFg0oMcreIgJ/6nsnwuhDC1ixVQoywc/9+YvYBPl42hlMmlJi KLSw== 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=pjRe9WOOgnZVoD/80IX7JyvW7Ap72zwjrzdwxvANZMw=; fh=OhV3JIe6s7BYVATlKJ3Ib2ybA9N3ZJt49O4IlF1MoN4=; b=BxJecHJJVw+uSbZGeeAyd/+6u4O41lZkgU5hzCW6wWm5Zk0MGJCGUaZRA2JdRESwd2 xg4MFL+1sF1knjZlX5aaLbPPuTPpFnsgPWtXko27Cb4qSlEw71s5LXj6TpOyh60undRh YyRc2roofTRYaVgfOMWDwAuJd8kN5qGEnMJ2jVSVLLhAMVq4KHoXGuTKL7+/tqxjf1+Q B/Rlk4Al2jk+svrBfD7Xwx4W7r4TH6UjySy4h6uRdI1mmMde4bIMT/Ji+YhoZuH5hTby cPqfv/a49OBodoihw/FK3+f47Agcmwvq4fFks2ndlZC2EjNjCk16XfFtAkgUelUVG/fh pWIw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=phGalolR; 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-7a9a79ee9f9si810885485a.159.2024.09.10.10.21.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:21:54 -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=phGalolR; 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 1so4Xw-0003MV-Nv; Tue, 10 Sep 2024 13:20: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 1so4Xr-00035i-CC for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:52 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4Xp-0002mV-DM for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:51 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2d892997913so3807925a91.3 for ; Tue, 10 Sep 2024 10:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725988848; x=1726593648; 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=pjRe9WOOgnZVoD/80IX7JyvW7Ap72zwjrzdwxvANZMw=; b=phGalolROCwVN2XfIwjTJ9mGmKLK3SPrBZ2wiK4PHd0UFabmTnEsJtmgIS7G0o0ILi DnfIfrt0JmPBThB8B36IRj/r/HVh0vvBV03+7juJvnVAhWCmbhcbq6++GGCjsM7V+g9f iLe81OA7b4XT4J/zhrUtEmDJWJqQ9XAvZC1wMZhkE2Hb1tMAM9ae/lMFthVFfmZaRTiR kEK8n9rskB1f3bGTMIjlwbprNulJzvqjgwJ3hOKNPVGnDJo5bQ0aVLDRJL6Kr6R7/rVy a3hHVQ2ngZebWFpMA4vf3dFDR3h/yW1X1yZZS2qzEMWtxTa47KVRfZnulVHMl22RUMfj qGgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725988848; x=1726593648; 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=pjRe9WOOgnZVoD/80IX7JyvW7Ap72zwjrzdwxvANZMw=; b=P8uK0ovcIFzu2bqRQSI212aWZJhfitIxKZJAd218b3uRC+z37JsSWhIsO4IgycpYsd PpPm+eBBJpmcwej8/6yDbk9c02b4N4+olxJySLOsI5FUSyfmKnI6hJcTL8xG2ry72R26 F7YHJr28+XBGOPQNqOhsFQVW/vEn4PrVc3DsKvh2hDLa//x8WTY8v3BTFzTKBsr4oFkd yK2UzRPw9pLL+umxasbXX9A8fVnVIuNwzw6OI9vDF6iveRNKM/IgdpxZvOU4hcuxExxP edreeYoiKk7bl0N0urWGoHzs3Fhz4NfShOvJxI8zm/TxM29kIiGR+bDo6UyU/z6kojrN 9KEA== X-Gm-Message-State: AOJu0YyfWkRFkeAySKsKvER42eVKMk6SnKHN/QtVQEiqknO0+j8imXtf WBTgJIjX9T3+plSjASNAHZoAJR1AvpsLBIu0X/uScMZKwAGdmCDlTLWVi1+XTaQtHGfMS5c+2u5 +49NS6w== X-Received: by 2002:a17:90b:3b84:b0:2d8:8f24:bd86 with SMTP id 98e67ed59e1d1-2dad4de167dmr16170621a91.8.1725988847740; Tue, 10 Sep 2024 10:20:47 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::9633]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db049883e5sm6685310a91.50.2024.09.10.10.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:20:47 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Eduardo Habkost , Richard Henderson , Pierrick Bouvier , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Mahmoud Mandour , qemu-ppc@nongnu.org, Zhao Liu , Xingtao Yao Subject: [PATCH v8 2/6] plugins: extend API to get latest memory value accessed Date: Tue, 10 Sep 2024 10:20:29 -0700 Message-Id: <20240910172033.1427812-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> References: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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 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 --- 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, }; +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 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 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 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; From patchwork Tue Sep 10 17:20:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 827027 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp423495wrc; Tue, 10 Sep 2024 10:21:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVbdAWZ/TtXf8O/HCr1p/lD4u7X6f4kSCTrRa5rpx3rSIhfKwR4DGPCSTGPnkZtEZmxC+QwSw==@linaro.org X-Google-Smtp-Source: AGHT+IGOy/qNQVmuWo8KBl3EQQV2f2oL0N011696DLQmRJlzHL10IFHLOmvT4NFWS8jsc2GAt6N1 X-Received: by 2002:a05:6214:3c9d:b0:6c3:62f7:9458 with SMTP id 6a1803df08f44-6c532ae4c54mr183054896d6.22.1725988912028; Tue, 10 Sep 2024 10:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725988912; cv=none; d=google.com; s=arc-20240605; b=MbdSe5tLTqBamg7kk0VZSeDWkyDiN0TbeSKFOA8RrGHB6mHUYmekPi6/dL5EPFF8eT V6E1SLx5GdVEFsl6kHdNVRcscCwlEMFwy2YUCQoc2RdZNmvxLa0vZXXtr2vsvJY7Y3Wr 3da5TVF/qFPDUQi4/DP7rNvqNsl9/gtWIDPN1D93ir8cYU8MGh3C6A/AfbweJfyC/JXY hGlahVubJIjp8PP311GJ50ICclsGQNIvtxQeXd8FSptZgSRttHTJbZggzgzB4VRhPbze ECAffwmjIpiW8T5mSs/W1bXclf/1G74tZs6feg7jmEu6xNvt829oIZks0k7/Ifi6uBX8 VTSA== 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=ZdzqnkrHvupdQDomTwNQx1ejBlR6veO+3YPCqZfdKWo=; fh=OhV3JIe6s7BYVATlKJ3Ib2ybA9N3ZJt49O4IlF1MoN4=; b=bHAYGypj+HOVYovRRUz6qrUJWY91MMBM7y/hEkMGGeyqKbSJ6xoi7xC/v4l+7oifS5 wBItYzg5ijxIy85zyEOjIMCkvWgG6G1eja+pPFveDUrj9lLdP3Cr65qeRv3m0PlGIhAI YIgnr1viWC8RJXmEIbfh9pPoWnYuCK8F9QKn+dD3F9PRyAVodRDTgf5GzXFqQyTaI82c 5qB6ZxfWkLyIAV2NKS58JWILSI61Ci27wIs0gF8KgAuekol+TT8h0Snki2wW20OcyECF GUHLOJUczRwfy+oEwu3BWt9kqa/mEGknf7Qzvuii7Hxxrg8WmBYWCPnuYfOZibjCbnCi f1+g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bqZi9HZG; 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-6c534782df3si87897516d6.381.2024.09.10.10.21.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:21:52 -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=bqZi9HZG; 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 1so4Xv-0003J7-EA; Tue, 10 Sep 2024 13:20: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 1so4Xs-000381-Ix for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:52 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4Xq-0002mt-S0 for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:52 -0400 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2da4e84c198so3918050a91.0 for ; Tue, 10 Sep 2024 10:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725988849; x=1726593649; 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=ZdzqnkrHvupdQDomTwNQx1ejBlR6veO+3YPCqZfdKWo=; b=bqZi9HZGNZ4hijKZCvyC2vaOrnFkx3KTMpliQCUqDruuzoBZgNmpqHXpQuPFFtBOV7 CRpgd/oi+3KW1HybucZLZrRiSfMRPxHJk6aN4v/w/H5jwcJNIHUZflrWDTWYYODsUPvS 0/heaLaQdCguTq4/MzQtTtJLq0sx2sgpHUM6lzhLhxM4AVT9njFlAUc8csUBk8yFWd0i /lScU9KBeVOtpqJp2j0/mlEX/20vFe/jmJz9Fn6IURHnAIh6KJ+Mb12CWdRtbkp1noVg Ff8V+/cN2C11N+iXp2ky/ny7YDlvDayaLNOT9SE00jBNMQh/pkRw7/zRU7xEf2uqyZPy 8Vyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725988849; x=1726593649; 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=ZdzqnkrHvupdQDomTwNQx1ejBlR6veO+3YPCqZfdKWo=; b=nvgzP6Oe2WBwxxm8j7MSzds+yf+aMo9dc4XBa/TTPjpHFqHWcMWgzAos2xmOquh4Id 7iZh4uov29DOW6hzE/ng5ZkSf7it4EnxWaInknnEdN4d01vjzXfV/XVA2SCf/rQxZpWx 4F2jOm+aPHlBJDVF7FEm1Gr92S92AdRAQswtspP1Nn4foXZvkxA9p47C1VfWKot6sQrs pvLzeDnGKEfbGNEKuptpwIz8hdmNNleu0DfPW6bJ2hHGKThNd0aPXzOXZA00e4g6k0EM CHs4WfoxskzuRNcBF4OjFBknLXpzLY/qWb9yLK+taFrIzuIFAmitj0S2OAvyXsJvEUOQ BvWw== X-Gm-Message-State: AOJu0Yw0CryNkxJZ/GM8wuVi0eWiH14XZ8codfR1l0/twR1kKQwt+BEO nHUNcxtIfE0lQs4ZY2KWgJ1S8zFXciDfOaAq+AM0bqCcD5QRDGfjeBZiqJxajcgKY6mFTRiiKFD 7ZP1b5Q== X-Received: by 2002:a17:90b:2644:b0:2da:8730:5683 with SMTP id 98e67ed59e1d1-2daffe292a1mr12681232a91.39.1725988848970; Tue, 10 Sep 2024 10:20:48 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::9633]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db049883e5sm6685310a91.50.2024.09.10.10.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:20:48 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Eduardo Habkost , Richard Henderson , Pierrick Bouvier , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Mahmoud Mandour , qemu-ppc@nongnu.org, Zhao Liu , Xingtao Yao Subject: [PATCH v8 3/6] tests/tcg: add mechanism to run specific tests with plugins Date: Tue, 10 Sep 2024 10:20:30 -0700 Message-Id: <20240910172033.1427812-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> References: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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 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 452a2cde65e..c5b1c7a786f 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 Tue Sep 10 17:20:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 827026 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp423336wrc; Tue, 10 Sep 2024 10:21:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWHlTH7fhHN9/Z1dBsYfdigDoI+KvD5i8DtiBIfiHSEZWhxC3ak0JhNlhqndebY/cdQhpC+nQ==@linaro.org X-Google-Smtp-Source: AGHT+IFUU9vvnDRnWH1++eijgyiRBQrFRIHK+Y/R02SbiXPvGrCHCpSz24/rdTeUDB47MnuzVLow X-Received: by 2002:ac8:7d46:0:b0:458:4412:fd06 with SMTP id d75a77b69052e-4584e9366camr3880671cf.45.1725988882758; Tue, 10 Sep 2024 10:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725988882; cv=none; d=google.com; s=arc-20240605; b=SWpfTvZLf3qHvrhYTGZx6IsZ3H6Qr2xJ0Onn/w2RzORlFC/RFwQRsGDbJh0GYD+1rr gwwTb007yyrxyYCHddsmUXmqJMaqVCNJl2A7fp1Cx8gJImaw++Sx9gVVgS+x4jJcJ86A 1fj4mbEbZVDXWD2JKXORZlQUHSCe2pZoRrfrtce8oPj76Y5dJ8ue1zpD3tePhOyM7Y4K gbK+N56CARcAZsFY1yRss9S2ZhLRBOxmdWKxgE2QkLx6G2wJt3N2bnt/EgeqAmk2Hmp6 kEQ1qdgwtJU30YAbXJFXgIW9u+wVWeDe+NkvEVq9O0BUYtusIFLE3Hik+Oc3709lEUvm Kx8g== 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=8J65jia4UycAJFoDQeTPh+ZznoVYWGR7xablNp0yP3U=; fh=OhV3JIe6s7BYVATlKJ3Ib2ybA9N3ZJt49O4IlF1MoN4=; b=WTeLRH2DPllsrTCzB0AQqK14bPRBr+O064IQkBbtC3ybPe++frPX9MucTkWvKKRb3E RvmP5kEg24TBvEed7qe22j5Dw5M8jnNpqtxRFXvaCnqoi9MLK7Fb0H7UcvtzvkyRI0eA EI3UGhOPiZfC/0tkdrYNTzijsM5raWNHNrn4Q9yM6LYlaYbYadRv5ZdRGadc+gCzxNh8 ZQ7Y86RSmI+DSjPCMdXhcks4xZWknS28kYy/Hkl0F94uX9gw1wHP9O+VorvEXJNsCKNL 0WqZjsSLXfacGmplTKlVqSLDnq/wqiJNlBLuGbk8pPgVmfyATJfl7soXQCa02AgjmbH+ GXTQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FkPvzWMJ; 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-45822e7f508si84702671cf.221.2024.09.10.10.21.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:21:22 -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=FkPvzWMJ; 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 1so4Y0-0003fd-SQ; Tue, 10 Sep 2024 13:21:00 -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 1so4Xv-0003JH-CB for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:55 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4Xs-0002nK-5T for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:53 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1fee6435a34so9639405ad.0 for ; Tue, 10 Sep 2024 10:20:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725988850; x=1726593650; 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=8J65jia4UycAJFoDQeTPh+ZznoVYWGR7xablNp0yP3U=; b=FkPvzWMJQyIuTGKWPijthzEWzhv4UnTYVfdprwOOPZ09CmdF+Enqiv9K1to6yeb55D aTcC046i/SMFKb9DDo25CPE4a9Ch9DEq6STneAE6P76Vd8lkXwHZBVRwWRXNG5SpxGCX wYR2v32l82RK/tsTdWbWoi00ktlH0N/w8KhK4N3R9Xwr16T7caZx4p8Ns2SFNRTL1+P+ GGpw3m59Axu/y/sV/NbEbaiP6mi7cdtpluiB+p147XztGlIIVZg9LgpA9k63PAboLaWs LvtNIVdg2/+xKE85Vnd55hg996ppaFZyLv+TPQz6/ggxNZnYf/8EoD+QMj4xupqzCqXP l4wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725988850; x=1726593650; 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=8J65jia4UycAJFoDQeTPh+ZznoVYWGR7xablNp0yP3U=; b=tNE6hqbBi0jtAM4lGUkUmTz5IOAdUt5xgIGOvx3xl2D4bsxk8PSARPxKVtZtZoEpqT SVTWvEFv/KsD4Zs/+q3HCydEOOgrs7HvGhj7T9lulRrQX9Asp/i7vVjjFlZtDdrVmrNO Pjv6M+zxONJS831mZ30300BXPqpbpcghNvrZ4yXzFV4f1E/je9ss7iKBvjAA8GhwzVtY OUDvuQsYLJ1TPdpXlW0/0C4+U3EFvTGMKBMf0AMUFK013jpVfjyHXtOq0Ag9r+QsMvAI QB5EHVEAx39JjJ6jT9rKqPXTRzemfaPQpGeCGpDQPxP27TQDlwSZYAS+OhgX0coY8JZz 2glw== X-Gm-Message-State: AOJu0YwCdRY3evqAjs5Ql9vARYMkgk7GH0KrHNKR/LGGLags0TdTnAke /ZOuG69jSigd9u/7eQ6b8bqfkHzy1Qz72UrX50aNGugL+eb9efEZUwOmpJMegmCmwdk1LwTGDv4 otlT8WQ== X-Received: by 2002:a05:6a21:a342:b0:1cf:2f11:63f with SMTP id adf61e73a8af0-1cf62cdf83bmr551595637.30.1725988850271; Tue, 10 Sep 2024 10:20:50 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::9633]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db049883e5sm6685310a91.50.2024.09.10.10.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:20:49 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Eduardo Habkost , Richard Henderson , Pierrick Bouvier , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Mahmoud Mandour , qemu-ppc@nongnu.org, Zhao Liu , Xingtao Yao Subject: [PATCH v8 4/6] tests/tcg: allow to check output of plugins Date: Tue, 10 Sep 2024 10:20:31 -0700 Message-Id: <20240910172033.1427812-5-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> References: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x631.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 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index c5b1c7a786f..2da70b2fcfa 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 Tue Sep 10 17:20:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 827031 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp423723wrc; Tue, 10 Sep 2024 10:22:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVu/TXkmSPRu7qAdkRBAziVj/FrPzJQRNVX38Grp5Nj2qh+F+Rdz31Ktaq7lPTx3M5KUExZyA==@linaro.org X-Google-Smtp-Source: AGHT+IFW1J4FZZ4hXVtXBMghg5EQ5RpMBXGBftel7LtmXeqfJ4AqsoA3QZ3smvUCo7ia4tI/dnze X-Received: by 2002:a05:622a:1828:b0:458:4457:8e69 with SMTP id d75a77b69052e-45844579181mr31605691cf.20.1725988950337; Tue, 10 Sep 2024 10:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725988950; cv=none; d=google.com; s=arc-20240605; b=TI9gmgAVZKvzSyCAO+O2/qkjpETB7Uujy27vb8xHK44sqTFrrVO6bVfHtLy7bNilBD K1PKByvRjFSMWFxCJns/W4XyGCYJ751oO3uAM7QVLuGEO4Olip03wAHpM+zrih5q7RUN RabtPk9YImJpRvtF5dgb9Xst1Lmae6vQafNkiio0css5aR2WwQ0C5HwrWO/s/Dd06vBZ Ex+FoGlV9+z8c98FjBL46oeP9yx9HZtU9MzFkjXIrTajNzcQ9SeX5xVILFxIMo11iRdK bJ3Op9j7arW4ousJAfowTbGpKZfPIkJd5RnZ+2JIYDLUypsy0vNTuUchGrdOCv2x1Ylv 1UkQ== 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=7ZhXggMzxS5/Hj/Hre+veFUkbwOhjo3lATccHPiXGdo=; fh=OhV3JIe6s7BYVATlKJ3Ib2ybA9N3ZJt49O4IlF1MoN4=; b=McRAn1XwavFRY+N0Nz/CFmR+GnDEe6Jy+H3ffJQubgICMOhWpL8m3kiASd4QYxKXTG VV3fRVv4ZuWWuxP1fsTmXMrStHREaGozfnuVTcgcT2utkoRQ2hE3ljPmydxbYj7ofndv A9YfuQRPPKHaaZIkkd405horjRVOOlTjHCZyQ6EADvFXgVUAwTXZs2ACpC39+uN1i9h0 K83E5LzRyYF9SI7PA7JWnmw1MlUMLNlc7jTJtlRQp8S0Ce90LOI9wATj7pEfHOww2ufL dgH8372jbSA7+dRfCX+16qiAgNDnRCKQA7/bCNXYKQ+eVWZPayN9Hy04gc58yP1PZLsv mYQg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mMlMdXp+; 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-45822faffb0si80633511cf.592.2024.09.10.10.22.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:22:30 -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=mMlMdXp+; 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 1so4Y1-0003iH-JO; Tue, 10 Sep 2024 13:21:01 -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 1so4Xw-0003PK-Rp for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:56 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4Xt-0002ny-8U for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:56 -0400 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2d8f06c2459so3777484a91.0 for ; Tue, 10 Sep 2024 10:20:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725988852; x=1726593652; 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=7ZhXggMzxS5/Hj/Hre+veFUkbwOhjo3lATccHPiXGdo=; b=mMlMdXp+JDkMNPYFRSItEdB7pQdTvYVQoswW0llIFVNMV1B9Q4rnwvZ6dpGcJGJws6 fmUTLDVsoE4jo3amGF6tgl0gkmTM/+OC5BwRXtWDUOhFS7r+meiYpKpjFtgVWMlRSwe1 DZaLiUlVlUB0kFWITJlWduqctlpUjElEq3m4BSQdwmhl5FYqePPp/maaa90y9A+WmBCu RVsOg98Se3/4nJjTYc0x8Pzf0l1RjMojDmZTakB4mFlH0lU0P9kpuCKbl/JY3PIoUrD7 pVshQhK0F6ExrhYugF0KSeaV3tf/UXD/YhB4VluxUH0UKpUaRlknfF3THTHT/jVAuVhS s4Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725988852; x=1726593652; 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=7ZhXggMzxS5/Hj/Hre+veFUkbwOhjo3lATccHPiXGdo=; b=XhivUtuJ+Af5UU8jAtsx4XqN+VYYyYxn3K10e3uyHkciqu6TJ5qDwWTWJBTZrRIsWJ cHj09Nf6XNhUvOcTNZap5VMDkwTNSZmBQZjByPgIVTl3XtjIh4cOdzCvM8TaisZiFDKs hVxCzv1dEPfdbwmGxXj7348gNJFxfcxNUndwbaheK/iF2g/UO88xsFkn9e/51BfQ4LZl yg9bX4aNrkd4jE2rJod31bvRnqBwD29HfDsYrQJCQsUIAeBsJ6vDr61IYhDEXgdx5KGq kpurvyEO/jqqrE1dlBOTmMkAxC+ieiiGgiY1tST7g/LuZp7VtkkfxqPV6LesntXj+J41 +L7g== X-Gm-Message-State: AOJu0YxfVnXQ2AECFt/I2udseC7HJz9pJy64TmlukTYkukxnMyAvjsIY WTZnq3JZ57IIyMjTjt/0Q5tkKAwVjN0wwL+hWHxsiS2edw5HFCZYEalAjYydDezgBqEife3WTsv A/NPnlA== X-Received: by 2002:a17:90b:3007:b0:2d8:f0b4:9acb with SMTP id 98e67ed59e1d1-2dad513545emr14225866a91.34.1725988851772; Tue, 10 Sep 2024 10:20:51 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::9633]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db049883e5sm6685310a91.50.2024.09.10.10.20.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:20:51 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Eduardo Habkost , Richard Henderson , Pierrick Bouvier , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Mahmoud Mandour , qemu-ppc@nongnu.org, Zhao Liu , Xingtao Yao Subject: [PATCH v8 5/6] tests/tcg/plugins/mem: add option to print memory accesses Date: Tue, 10 Sep 2024 10:20:32 -0700 Message-Id: <20240910172033.1427812-6-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> References: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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 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 --- 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 b650dddcce1..086e6f5bdfc 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 Tue Sep 10 17:20:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 827029 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp423520wrc; Tue, 10 Sep 2024 10:21:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWMUuQL0WpD15MeNxZW4zjpfIUc/4r1SmieDAIJsxuboRpHzibwLL1hYRoZqHlAPOhk5ewe+g==@linaro.org X-Google-Smtp-Source: AGHT+IHR5wR7mJ6xzoi+DxiC7/TdbRaG1fNbunXnlV8TnTwqsYfp/RXwkiROX4CC3eWEUuG/XSkz X-Received: by 2002:a05:622a:1115:b0:458:4072:34e with SMTP id d75a77b69052e-4584072259bmr45940671cf.16.1725988914848; Tue, 10 Sep 2024 10:21:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725988914; cv=none; d=google.com; s=arc-20240605; b=dSRseYeb+n0e19y3TezJYXz7s2xBywPtqInjQ6tt3wH9OZ0rLsny8nbsDdGTEyJhgr GZ5Fp5fqjTq+UDr1QwqTwyFP600Url2iDICwn/b6LdiSY/zfoa3hS/pfYHk5tRzjHWKJ cTyfLTpOlb67OvlqsElxRrFulT85zKdapn4FL6jK8K6pIz4coONvkp3/ZRv367pOjr0s qcIoOGzeHfovSksSYyeDdoIexLRqSqtZaKfDvaF+9u+A/TTWA0v/m1KbHzHsXJqH5ebo v/jPJicK8orFdoL7DQ5XhO7/rDWpdXjR8tKUFijpXboI7UGyfPY1XkySHdD7X5ZGMxzv 5dHw== 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=JWmLCLoNciq5fxHCng9pTolj63fwpRl66Nb/LCsfMPA=; fh=OhV3JIe6s7BYVATlKJ3Ib2ybA9N3ZJt49O4IlF1MoN4=; b=igDB6q5w9dOO866yoV/XykwwqpqtSrJrbArb7iDb4n2I1eeixmLz0y3a68zdAkvo3K lO7DhERmftLFqtLfOzh9qaNDswfOfoxZtp80zbUM0Jw/zIeSn9Ht9dpFxIkTWfY1Qb8c hM4+9Ez+jIHrSFC2MO1f6mRCOyAwgN/TmMgWOc0tGUZ3n7/zVfZOVpxAjfyT9koVtglj NcHqURBp+tmuRhUQqL1gDWehNNl3Tgh+n0usYTso1QdljfKewxhySpxrR81KVuj9lFDL Xhdt3C2i48Gn0BmuL8EwOeVwtH1urgWFLnMBjmJJOQnhJMPlZ2Yg59R52HwLDT3WwUYk beQQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gaT3pSGY; 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-45822f826b5si80530791cf.455.2024.09.10.10.21.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:21:54 -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=gaT3pSGY; 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 1so4Y1-0003jn-Si; Tue, 10 Sep 2024 13:21:01 -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 1so4Xy-0003WV-KP for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:59 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4Xv-0002oM-4B for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:58 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2da4ea59658so4245383a91.0 for ; Tue, 10 Sep 2024 10:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725988853; x=1726593653; 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=JWmLCLoNciq5fxHCng9pTolj63fwpRl66Nb/LCsfMPA=; b=gaT3pSGYOUt8qhHZC8RIWkMe9xuasHH3JLL5T7qW78/JxRZdFOVN2xTv8KQULMeOH6 JionMOwySvlBjJfIRioLrfF2w4wfvdKMEpD9DF/YDugy9cLEcRFtzmLSnvywJVn2nLxF f/7XygzSqverfofVTO4zSz+ALZrh8U8ycR3yqOar9DpWA0mLIZL/Hn6f0SbAThl4r7nI JaF3b9FVXqAR3T5UCB4wgjRlF0M1V+og9EDXI5HuyW/CkxNXbBf1kuovemDcYEYphUkN NGXBxmrV1d/1w/HyVrSDYorhnZKCCIExyYutpn+KPyz5UY6ASMIcFwuoScwUgE0+lRKF R5fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725988853; x=1726593653; 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=JWmLCLoNciq5fxHCng9pTolj63fwpRl66Nb/LCsfMPA=; b=sz3FLZL15wPgI29NjA6jXtKhxjbuohLLIM4tBbJAWkVgvJVtv0P0dAPsH8zx1wLx/H DVuvDxXQbLNA+73tgY/MP7xONlviBbYwLG+4ub4eIrQrcfv4p0PGOvKNhMpXJf3yggk7 R0sGtqyqS/u5EpFUVNMEVUTlZcXGR3YBHSiz3FmcecTDexU7L0iuLnoZmsQaJF2RHor4 3yahpwRTvYtXZsfJ2AOfVSk5n5A0qWR3Hp78nF8QEjWGVTBMfL0lkLD/Bb18uvSEwkIh xNLRjJH60EPabUrTZ09fVZxCZQ8HY7FhBbpsa2o4uKZAw5XYazoH6z8+ZAt+xv3vThuK PDNA== X-Gm-Message-State: AOJu0YypkQmmgmLy+kzZy9XecmiBz4DTWX7yVeUAd7w5wzpmAj9oyLVG 7bbKNPJrWwA33ZOJFYONSrDlwZ3eO4riDnpiU54jVOqtou/MT4ggKb9KqKX6S7JDmKUqp0iVQB+ CGRWzTA== X-Received: by 2002:a17:90b:fcb:b0:2c9:81fd:4c27 with SMTP id 98e67ed59e1d1-2dad4ef0cfcmr15874868a91.14.1725988853260; Tue, 10 Sep 2024 10:20:53 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::9633]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db049883e5sm6685310a91.50.2024.09.10.10.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:20:52 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Eduardo Habkost , Richard Henderson , Pierrick Bouvier , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Mahmoud Mandour , qemu-ppc@nongnu.org, Zhao Liu , Xingtao Yao Subject: [PATCH v8 6/6] tests/tcg/multiarch: add test for plugin memory access Date: Tue, 10 Sep 2024 10:20:33 -0700 Message-Id: <20240910172033.1427812-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> References: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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 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 --- 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 00000000000..057b9aac9f6 --- /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 fdd7ddf64ec..36d8ed1eaea 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 5e3391ec9d2..78b83d5575a 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 00000000000..80607f04b5d --- /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 509a20be2b0..1940886c737 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)