From patchwork Mon Sep 16 08:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828989 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681553wrb; Mon, 16 Sep 2024 01:56:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVt4QM8gb99aDaA9FbEmd8ujLkxQLQZtGaiWPB9A+ihEQ2C4YCJqwDp1YFKqZfpxnrcyVKc2Q==@linaro.org X-Google-Smtp-Source: AGHT+IEnQfZcAtier+siWTNK72rIcah/n1vQjSj2vYn8HVqvsbKizd2lX67FV/RXCPlBxy9KCbWv X-Received: by 2002:a05:6214:3c9a:b0:6c5:20c2:f34f with SMTP id 6a1803df08f44-6c57dfa58f9mr173036966d6.21.1726476959937; Mon, 16 Sep 2024 01:55:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726476959; cv=none; d=google.com; s=arc-20240605; b=VVdtAXkCdDwJiPQg6XrYYQftx1LbonybC0GaHM9i8EzqrJsmEpZyeQREcDNVasOElv rpVmUdX44KmDra9qPq08HLcjs08LqEIH441AbT0TpLZb+VoaJ5DLO4F+tFxwcDTV6Db7 jDLw1QNNZ9Wcg4ieatEaxK2dXJwfrXtmchxtnpWwQqqpSre+I75L/YTAS9GiSLieLhiZ 2X0k/rljs/UfKPL5ec9OhxxE62ZhF2+FJNvYZl1HvhLmGXAIYRoslnQ9p7wGwvFZqFhx zpj/4mjMwfg1icOnwupK0YwugFw0j54DubOenHyjaxHx33+k7CBxkyFv3TsC24rRw0hG YyMw== 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=g1JvwHXPGniWx90hoBGphHU2aQhl5TWKaQOcgoSEIT4=; fh=ATDHygEnrhDZDytw2YSa+GgRs9jfnpjrC7XifhYWFyU=; b=ZC+p6j0MR0F/bDPkeZ9r9OXE0AWhCggs0UgDUr6ejgVbnGiGQXV2yoLUPNagev20y3 GS85iQQcdzk21nRepIdaXVGdaOhbSw5H12gD4anHoRrf0ohxq03SN9k0xmajwbv/CS+D qChwitk4MJKVcR832l5eTRuaBeftTeKDZZqgTivvVFCJg4xPdFOV0Z/efm5/aXWZQNmZ sKX007m4RbBM5RvmXxFJTx/VEoIG5fwrJ/5nSUqvLTQbd32V+V5EuU+86vWa6L2CQuXj CX8RnCF3aDiMb5tl/dqx5KKh41RlMsl9Diao0Km19E1XKH1hAdZCVOUAq0AK9BGdOtQY npGA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WvMho+ob; 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-6c58c68b1fesi52840186d6.309.2024.09.16.01.55.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:55:59 -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=WvMho+ob; 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 1sq7VS-0001Jp-Gx; Mon, 16 Sep 2024 04:54: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 1sq7V0-0000B4-WA for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:24 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Uj-0005CY-NB for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:22 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-375e5c12042so2248634f8f.3 for ; Mon, 16 Sep 2024 01:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476844; x=1727081644; 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=g1JvwHXPGniWx90hoBGphHU2aQhl5TWKaQOcgoSEIT4=; b=WvMho+obEiEAO9MHvby1wVvbvvaOpuc9q+gOyCchNCuZhKpBYei0CyVuw19+IXrrwL QD6MbU5LBzMMWfpcwthm98roGQKIJH6LtGYvsblskVdmaYcTcTSOcMXoczgx9gGmRPJ0 C1I9klDXjBykyTsbF7zU1ZafPQLF4ZcxLsHb2Wq5C2OqVYDGbdsiGKMXHbYHcsi8IPzp 5OLreOASr0e1VqQbx4fVEYNUPXY7bPSRQj4g4fO9i0WVVlIqE0WAGHYstZi5c3fxDdkO zhHToSG6seK4fqmQIeoWepxA5ejWGLJYhoq8VnUcS7LB5TeghiCALicIGK9YpIIj5IEt zuaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476844; x=1727081644; 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=g1JvwHXPGniWx90hoBGphHU2aQhl5TWKaQOcgoSEIT4=; b=OyaFc1UynSIeWFPC/pqPG4hRpraA/06n9uK4ZbKLi2XV3Yx+aNt1VkrNvpnfyydS+Z xZG15GtVQApHdMV90v470v8fFdHFPrZobCfg8YrLZZUd+nQRoW9dmHkFqOMFse0uYhpa o3eruYPTH5fzutsq+V2Q8A7EXnJ03ihA7/ls7E5/jLTyqyGI+b9lVSZiYD+ULx/kG4IK E59Tq1jMLDxyQBwfyRu30UDIr/tXCWrV8mrJT5eP+DIPMfTq0k06rUB/XoVNx+oJuYKH zOK4hdZnDnK6KL8nmwgrEPgbysTvVTNsdJUACZu/sZtAd3F42NOEaFO0Y0S6X0WxYxQd +jsQ== X-Gm-Message-State: AOJu0YwlAXP/9tUtJmlUEx92W/XscOQKSRlv+5NEa7U21OJF2MGM1SZR xHh15/nZnjnemH5OKMSuuDsh7VMLz17atEwKxVRKtrovaNCp8ruvAevxh1C864Q= X-Received: by 2002:a05:6000:18c2:b0:374:ce15:998c with SMTP id ffacd0b85a97d-378c2d1345dmr7263913f8f.30.1726476844079; Mon, 16 Sep 2024 01:54:04 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cc1375189sm215892785e9.1.2024.09.16.01.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:01 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id ABB525F90C; Mon, 16 Sep 2024 09:54:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier Subject: [PATCH v2 04/18] plugins: save value during memory accesses Date: Mon, 16 Sep 2024 09:53:46 +0100 Message-Id: <20240916085400.1046925-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier Different code paths handle memory accesses: - tcg generated code - load/store helpers - atomic helpers This value is saved in cpu->neg.plugin_mem_value_{high,low}. Values are written only for accessed word size (upper bits are not set). Atomic operations are doing read/write at the same time, so we generate two memory callbacks instead of one, to allow plugins to access distinct values. For now, we can have access only up to 128 bits, thus split this in two 64 bits words. When QEMU will support wider operations, we'll be able to reconsider this. Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-2-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- accel/tcg/atomic_template.h | 66 ++++++++++++++++++++++++++++++----- include/hw/core/cpu.h | 4 +++ include/qemu/plugin.h | 4 +++ plugins/core.c | 6 ++++ tcg/tcg-op-ldst.c | 66 +++++++++++++++++++++++++++++++---- accel/tcg/atomic_common.c.inc | 13 ++++++- accel/tcg/ldst_common.c.inc | 38 ++++++++++++-------- 7 files changed, 167 insertions(+), 30 deletions(-) diff --git a/accel/tcg/atomic_template.h b/accel/tcg/atomic_template.h index 1dc2151daf..89593b2502 100644 --- a/accel/tcg/atomic_template.h +++ b/accel/tcg/atomic_template.h @@ -53,6 +53,14 @@ # error unsupported data size #endif +#if DATA_SIZE == 16 +# define VALUE_LOW(val) int128_getlo(val) +# define VALUE_HIGH(val) int128_gethi(val) +#else +# define VALUE_LOW(val) val +# define VALUE_HIGH(val) 0 +#endif + #if DATA_SIZE >= 4 # define ABI_TYPE DATA_TYPE #else @@ -83,7 +91,12 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, abi_ptr addr, ret = qatomic_cmpxchg__nocheck(haddr, cmpv, newv); #endif ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(newv), + VALUE_HIGH(newv), + oi); return ret; } @@ -97,7 +110,12 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, abi_ptr addr, ABI_TYPE val, ret = qatomic_xchg__nocheck(haddr, val); ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(val), + VALUE_HIGH(val), + oi); return ret; } @@ -109,7 +127,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ haddr = atomic_mmu_lookup(env_cpu(env), addr, oi, DATA_SIZE, retaddr); \ ret = qatomic_##X(haddr, val); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(ret), \ + VALUE_HIGH(ret), \ + VALUE_LOW(val), \ + VALUE_HIGH(val), \ + oi); \ return ret; \ } @@ -145,7 +168,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ cmp = qatomic_cmpxchg__nocheck(haddr, old, new); \ } while (cmp != old); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(old), \ + VALUE_HIGH(old), \ + VALUE_LOW(xval), \ + VALUE_HIGH(xval), \ + oi); \ return RET; \ } @@ -188,7 +216,12 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, abi_ptr addr, ret = qatomic_cmpxchg__nocheck(haddr, BSWAP(cmpv), BSWAP(newv)); #endif ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(newv), + VALUE_HIGH(newv), + oi); return BSWAP(ret); } @@ -202,7 +235,12 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, abi_ptr addr, ABI_TYPE val, ret = qatomic_xchg__nocheck(haddr, BSWAP(val)); ATOMIC_MMU_CLEANUP; - atomic_trace_rmw_post(env, addr, oi); + atomic_trace_rmw_post(env, addr, + VALUE_LOW(ret), + VALUE_HIGH(ret), + VALUE_LOW(val), + VALUE_HIGH(val), + oi); return BSWAP(ret); } @@ -214,7 +252,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ haddr = atomic_mmu_lookup(env_cpu(env), addr, oi, DATA_SIZE, retaddr); \ ret = qatomic_##X(haddr, BSWAP(val)); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(ret), \ + VALUE_HIGH(ret), \ + VALUE_LOW(val), \ + VALUE_HIGH(val), \ + oi); \ return BSWAP(ret); \ } @@ -247,7 +290,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ ldn = qatomic_cmpxchg__nocheck(haddr, ldo, BSWAP(new)); \ } while (ldo != ldn); \ ATOMIC_MMU_CLEANUP; \ - atomic_trace_rmw_post(env, addr, oi); \ + atomic_trace_rmw_post(env, addr, \ + VALUE_LOW(old), \ + VALUE_HIGH(old), \ + VALUE_LOW(xval), \ + VALUE_HIGH(xval), \ + oi); \ return RET; \ } @@ -281,3 +329,5 @@ GEN_ATOMIC_HELPER_FN(add_fetch, ADD, DATA_TYPE, new) #undef SUFFIX #undef DATA_SIZE #undef SHIFT +#undef VALUE_LOW +#undef VALUE_HIGH diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 1c9c775df6..04e9ad4996 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -350,6 +350,8 @@ typedef union IcountDecr { * from CPUArchState, via small negative offsets. * @can_do_io: True if memory-mapped IO is allowed. * @plugin_mem_cbs: active plugin memory callbacks + * @plugin_mem_value_low: 64 lower bits of latest accessed mem value. + * @plugin_mem_value_high: 64 higher bits of latest accessed mem value. */ typedef struct CPUNegativeOffsetState { CPUTLB tlb; @@ -358,6 +360,8 @@ typedef struct CPUNegativeOffsetState { * The callback pointer are accessed via TCG (see gen_empty_mem_helper). */ GArray *plugin_mem_cbs; + uint64_t plugin_mem_value_low; + uint64_t plugin_mem_value_high; #endif IcountDecr icount_decr; bool can_do_io; diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index af5f9db469..9726a9ebf3 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -167,6 +167,8 @@ qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, uint64_t a1, void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret); void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, + uint64_t value_low, + uint64_t value_high, MemOpIdx oi, enum qemu_plugin_mem_rw rw); void qemu_plugin_flush_cb(void); @@ -251,6 +253,8 @@ void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret) { } static inline void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, + uint64_t value_low, + uint64_t value_high, MemOpIdx oi, enum qemu_plugin_mem_rw rw) { } diff --git a/plugins/core.c b/plugins/core.c index 2897453cac..bb105e8e68 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -602,6 +602,8 @@ void exec_inline_op(enum plugin_dyn_cb_type type, } void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, + uint64_t value_low, + uint64_t value_high, MemOpIdx oi, enum qemu_plugin_mem_rw rw) { GArray *arr = cpu->neg.plugin_mem_cbs; @@ -610,6 +612,10 @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, if (arr == NULL) { return; } + + cpu->neg.plugin_mem_value_low = value_low; + cpu->neg.plugin_mem_value_high = value_high; + for (i = 0; i < arr->len; i++) { struct qemu_plugin_dyn_cb *cb = &g_array_index(arr, struct qemu_plugin_dyn_cb, i); diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c index 8510160258..23dc807f11 100644 --- a/tcg/tcg-op-ldst.c +++ b/tcg/tcg-op-ldst.c @@ -148,11 +148,11 @@ static TCGv_i64 plugin_maybe_preserve_addr(TCGTemp *addr) return NULL; } +#ifdef CONFIG_PLUGIN static void plugin_gen_mem_callbacks(TCGv_i64 copy_addr, TCGTemp *orig_addr, MemOpIdx oi, enum qemu_plugin_mem_rw rw) { -#ifdef CONFIG_PLUGIN if (tcg_ctx->plugin_insn != NULL) { qemu_plugin_meminfo_t info = make_plugin_meminfo(oi, rw); @@ -172,6 +172,54 @@ plugin_gen_mem_callbacks(TCGv_i64 copy_addr, TCGTemp *orig_addr, MemOpIdx oi, } } } +} +#endif + +static void +plugin_gen_mem_callbacks_i32(TCGv_i32 val, + TCGv_i64 copy_addr, TCGTemp *orig_addr, + MemOpIdx oi, enum qemu_plugin_mem_rw rw) +{ +#ifdef CONFIG_PLUGIN + if (tcg_ctx->plugin_insn != NULL) { + tcg_gen_st_i32(val, tcg_env, + offsetof(CPUState, neg.plugin_mem_value_low) - + sizeof(CPUState) + (HOST_BIG_ENDIAN * 4)); + plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw); + } +#endif +} + +static void +plugin_gen_mem_callbacks_i64(TCGv_i64 val, + TCGv_i64 copy_addr, TCGTemp *orig_addr, + MemOpIdx oi, enum qemu_plugin_mem_rw rw) +{ +#ifdef CONFIG_PLUGIN + if (tcg_ctx->plugin_insn != NULL) { + tcg_gen_st_i64(val, tcg_env, + offsetof(CPUState, neg.plugin_mem_value_low) - + sizeof(CPUState)); + plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw); + } +#endif +} + +static void +plugin_gen_mem_callbacks_i128(TCGv_i128 val, + TCGv_i64 copy_addr, TCGTemp *orig_addr, + MemOpIdx oi, enum qemu_plugin_mem_rw rw) +{ +#ifdef CONFIG_PLUGIN + if (tcg_ctx->plugin_insn != NULL) { + tcg_gen_st_i64(TCGV128_LOW(val), tcg_env, + offsetof(CPUState, neg.plugin_mem_value_low) - + sizeof(CPUState)); + tcg_gen_st_i64(TCGV128_HIGH(val), tcg_env, + offsetof(CPUState, neg.plugin_mem_value_high) - + sizeof(CPUState)); + plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw); + } #endif } @@ -203,7 +251,8 @@ static void tcg_gen_qemu_ld_i32_int(TCGv_i32 val, TCGTemp *addr, opc = INDEX_op_qemu_ld_a64_i32; } gen_ldst(opc, tcgv_i32_temp(val), NULL, addr, oi); - plugin_gen_mem_callbacks(copy_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R); + plugin_gen_mem_callbacks_i32(val, copy_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_R); if ((orig_memop ^ memop) & MO_BSWAP) { switch (orig_memop & MO_SIZE) { @@ -271,7 +320,7 @@ static void tcg_gen_qemu_st_i32_int(TCGv_i32 val, TCGTemp *addr, } } gen_ldst(opc, tcgv_i32_temp(val), NULL, addr, oi); - plugin_gen_mem_callbacks(NULL, addr, orig_oi, QEMU_PLUGIN_MEM_W); + plugin_gen_mem_callbacks_i32(val, NULL, addr, orig_oi, QEMU_PLUGIN_MEM_W); if (swap) { tcg_temp_free_i32(swap); @@ -324,7 +373,8 @@ static void tcg_gen_qemu_ld_i64_int(TCGv_i64 val, TCGTemp *addr, opc = INDEX_op_qemu_ld_a64_i64; } gen_ldst_i64(opc, val, addr, oi); - plugin_gen_mem_callbacks(copy_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R); + plugin_gen_mem_callbacks_i64(val, copy_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_R); if ((orig_memop ^ memop) & MO_BSWAP) { int flags = (orig_memop & MO_SIGN @@ -396,7 +446,7 @@ static void tcg_gen_qemu_st_i64_int(TCGv_i64 val, TCGTemp *addr, opc = INDEX_op_qemu_st_a64_i64; } gen_ldst_i64(opc, val, addr, oi); - plugin_gen_mem_callbacks(NULL, addr, orig_oi, QEMU_PLUGIN_MEM_W); + plugin_gen_mem_callbacks_i64(val, NULL, addr, orig_oi, QEMU_PLUGIN_MEM_W); if (swap) { tcg_temp_free_i64(swap); @@ -606,7 +656,8 @@ static void tcg_gen_qemu_ld_i128_int(TCGv_i128 val, TCGTemp *addr, tcg_constant_i32(orig_oi)); } - plugin_gen_mem_callbacks(ext_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R); + plugin_gen_mem_callbacks_i128(val, ext_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_R); } void tcg_gen_qemu_ld_i128_chk(TCGv_i128 val, TCGTemp *addr, TCGArg idx, @@ -722,7 +773,8 @@ static void tcg_gen_qemu_st_i128_int(TCGv_i128 val, TCGTemp *addr, tcg_constant_i32(orig_oi)); } - plugin_gen_mem_callbacks(ext_addr, addr, orig_oi, QEMU_PLUGIN_MEM_W); + plugin_gen_mem_callbacks_i128(val, ext_addr, addr, orig_oi, + QEMU_PLUGIN_MEM_W); } void tcg_gen_qemu_st_i128_chk(TCGv_i128 val, TCGTemp *addr, TCGArg idx, diff --git a/accel/tcg/atomic_common.c.inc b/accel/tcg/atomic_common.c.inc index 95a5c5ff12..6056598c23 100644 --- a/accel/tcg/atomic_common.c.inc +++ b/accel/tcg/atomic_common.c.inc @@ -14,9 +14,20 @@ */ static void atomic_trace_rmw_post(CPUArchState *env, uint64_t addr, + uint64_t read_value_low, + uint64_t read_value_high, + uint64_t write_value_low, + uint64_t write_value_high, MemOpIdx oi) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_RW); + if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + read_value_low, read_value_high, + oi, QEMU_PLUGIN_MEM_R); + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + write_value_low, write_value_high, + oi, QEMU_PLUGIN_MEM_W); + } } /* diff --git a/accel/tcg/ldst_common.c.inc b/accel/tcg/ldst_common.c.inc index 87ceb95487..ebbf380d76 100644 --- a/accel/tcg/ldst_common.c.inc +++ b/accel/tcg/ldst_common.c.inc @@ -123,10 +123,15 @@ void helper_st_i128(CPUArchState *env, uint64_t addr, Int128 val, MemOpIdx oi) * Load helpers for cpu_ldst.h */ -static void plugin_load_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi) +static void plugin_load_cb(CPUArchState *env, abi_ptr addr, + uint64_t value_low, + uint64_t value_high, + MemOpIdx oi) { if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_R); + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + value_low, value_high, + oi, QEMU_PLUGIN_MEM_R); } } @@ -136,7 +141,7 @@ uint8_t cpu_ldb_mmu(CPUArchState *env, abi_ptr addr, MemOpIdx oi, uintptr_t ra) tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_UB); ret = do_ld1_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } @@ -147,7 +152,7 @@ uint16_t cpu_ldw_mmu(CPUArchState *env, abi_ptr addr, tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_16); ret = do_ld2_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } @@ -158,7 +163,7 @@ uint32_t cpu_ldl_mmu(CPUArchState *env, abi_ptr addr, tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_32); ret = do_ld4_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } @@ -169,7 +174,7 @@ uint64_t cpu_ldq_mmu(CPUArchState *env, abi_ptr addr, tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_64); ret = do_ld8_mmu(env_cpu(env), addr, oi, ra, MMU_DATA_LOAD); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, ret, 0, oi); return ret; } @@ -180,7 +185,7 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_128); ret = do_ld16_mmu(env_cpu(env), addr, oi, ra); - plugin_load_cb(env, addr, oi); + plugin_load_cb(env, addr, int128_getlo(ret), int128_gethi(ret), oi); return ret; } @@ -188,10 +193,15 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, * Store helpers for cpu_ldst.h */ -static void plugin_store_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi) +static void plugin_store_cb(CPUArchState *env, abi_ptr addr, + uint64_t value_low, + uint64_t value_high, + MemOpIdx oi) { if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_W); + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, + value_low, value_high, + oi, QEMU_PLUGIN_MEM_W); } } @@ -199,7 +209,7 @@ void cpu_stb_mmu(CPUArchState *env, abi_ptr addr, uint8_t val, MemOpIdx oi, uintptr_t retaddr) { helper_stb_mmu(env, addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } void cpu_stw_mmu(CPUArchState *env, abi_ptr addr, uint16_t val, @@ -207,7 +217,7 @@ void cpu_stw_mmu(CPUArchState *env, abi_ptr addr, uint16_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_16); do_st2_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } void cpu_stl_mmu(CPUArchState *env, abi_ptr addr, uint32_t val, @@ -215,7 +225,7 @@ void cpu_stl_mmu(CPUArchState *env, abi_ptr addr, uint32_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_32); do_st4_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } void cpu_stq_mmu(CPUArchState *env, abi_ptr addr, uint64_t val, @@ -223,7 +233,7 @@ void cpu_stq_mmu(CPUArchState *env, abi_ptr addr, uint64_t val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_64); do_st8_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, val, 0, oi); } void cpu_st16_mmu(CPUArchState *env, abi_ptr addr, Int128 val, @@ -231,7 +241,7 @@ void cpu_st16_mmu(CPUArchState *env, abi_ptr addr, Int128 val, { tcg_debug_assert((get_memop(oi) & MO_SIZE) == MO_128); do_st16_mmu(env_cpu(env), addr, val, oi, retaddr); - plugin_store_cb(env, addr, oi); + plugin_store_cb(env, addr, int128_getlo(val), int128_gethi(val), oi); } /* From patchwork Mon Sep 16 08:53:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828986 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681509wrb; Mon, 16 Sep 2024 01:55:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVcHoPv3ARsRQaFRNP/4iUXmcyLfuz4fcj9zzoN+yOfwOHq8WDsNTazDMFaItGRnvRg0ZB4Hw==@linaro.org X-Google-Smtp-Source: AGHT+IFND3jsUak7ehBgPphQKny3CtfCJh3CjL5ciD5trodBlmqpldS9WmitT+ya3K8CQLl/jI8i X-Received: by 2002:a05:620a:4514:b0:7a9:a1f4:d4e1 with SMTP id af79cd13be357-7ab30d5eacbmr1655945885a.39.1726476950806; Mon, 16 Sep 2024 01:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726476950; cv=none; d=google.com; s=arc-20240605; b=TFDk/C7vWcJe4nrST/3zVI+f7uurvfeeo7qnujcX5M4ngxH9U/kd0XwY9AIOZ3Oos2 0UlQMlS/1h5JxZR8iNfzzHnua7qO1CN0uJkjvi+HKII0PnLO9nuXCevUb8doUT0LPK0Y cORqdJD0aCAUFu/itgW+xl0WTpkhsR+nRKIetQwSYCdPZp/wt8OJgCBlbkdntL31FcJC z80PGWRMxkB+taHEfk62HQJhixzn4uSCYJwi4e9SQUNe4fJ1JNf/n57sw6Ls8vuJDjq+ P3NQlV8j4jl/57pYy91tqoAs/ip0TIKZzVSG8wh79sobmGGlcFr4y1PQbenZC36sFnW7 Sk3g== 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=fLxUQUnLDvLi/r8JTuG1fjcjViW7gUT9q/lZ9pYtQys=; fh=J7xxoiH/FgLINVeQdLJSQ9A6Jne2JYMDx39ZFxN4EsU=; b=SpegqYpaGKjfl7XqqHJc7fPfZ4265/IMnE78stHbl3kbQccU2cEeAEh+QVA6ZrQaHw zzo8z91/lRHagSPhrSc6SdVqTy1b0Fiw7yfcUPShbx42Q0XMLOEhUCmAWrEAohupNDDL yNuFnihjrQY4gI1te2Hvdt3xmxjFpbFpKpbkndRrc4QodCSbXELRyRMijBIIENEH+pcF 7XxpO0fTqHbbRriy3baKwsdy/tzqmTOvExUdgMi/ZajrOTKWDJ8sV50r99XQckdEqMae hYA8BJfWjN3sZ5jK3ixAEZ2QWJ9it6TyZ2M5csl2XFvXN4Efy7GAWibTH0R8CfvkLRN2 eOZQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JUIUAfib; 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-7ab3eb652e2si512463385a.515.2024.09.16.01.55.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:55:50 -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=JUIUAfib; 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 1sq7VU-0001Rn-LQ; Mon, 16 Sep 2024 04:54: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 1sq7V3-0000GQ-T2 for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:26 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Um-0005Cw-CY for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:24 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42cb2191107so31972335e9.1 for ; Mon, 16 Sep 2024 01:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476846; x=1727081646; 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=fLxUQUnLDvLi/r8JTuG1fjcjViW7gUT9q/lZ9pYtQys=; b=JUIUAfibIm77eE3GtairYaltNz9w1t7AAo+Paar/KxqEOH5nGqRHpct3LMCUkmom0l jnXR7LY4lX66FB22a6ZAnnpXat9WuCnV2V1erJ39Pv28S8ByIwFcQmwxhr7m4q5DJKKl K5b0CCuI4J3qRH3/VwlzUbSXJ/ur7nruN8S0jNVSvk6BUAeD3kiIqi/zPfugn8bRv0pb IGSRkvGrVD0Dw8+7x0hDNvsdRPhMtheYcslgB29CixrdGdFdlK3e+lecdR5qE+gI/+p3 9REXUWPf+JqAtyb4FKsY/MYW0bYlvOPXHnMQT6cab9zOQyVhXcY/FR7jULWaekSKjyX0 14UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476846; x=1727081646; 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=fLxUQUnLDvLi/r8JTuG1fjcjViW7gUT9q/lZ9pYtQys=; b=qHTUzMxSKrBW2E2AXakUCui1YYhbh2+JFgXdFJr4ZmCQk1soN+fhlxKHYZLqsL28JX k4ScuawHKMTRpibMhamupYHvbEwo+Ic44oRTEEjTOuQWmcf2VrfW4N4SkE/smEJOMe2N stAqJKzbsxXg4iipDEqu0w+jlsDU4VjQXu7/ZGdQnRQNGSFOhffkkNzDfvH9BLzNHAgR PUwATr3vHheXJkbzSEjA5+eAkRYXSesoPBpmtOZrcyiWMk8oe5MGF9Vh0Df0GazRWBc2 h9j35G5b3+FepetRuMQpo6aFjaGgi0I91UFqnA3IrusT9f5Fe5n4Dv9DWy9q8vRYmzNg EzBw== X-Gm-Message-State: AOJu0YyYKzfhj2BMaHJ/IiQwjkA1EyInLrhgS5ve6tG+KYn+K+Jut40I eE/X0i5C/I85E7Hv4EwDgrS005mWoRa18Ub/JCTDnIMKLcuujKQVm1tUup7qMSU= X-Received: by 2002:a5d:4092:0:b0:374:c481:3f6 with SMTP id ffacd0b85a97d-378c2cd58c5mr7633901f8f.8.1726476845854; Mon, 16 Sep 2024 01:54:05 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e71f0683sm6632128f8f.13.2024.09.16.01.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C4BF85F91C; Mon, 16 Sep 2024 09:54:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v2 05/18] plugins: extend API to get latest memory value accessed Date: Mon, 16 Sep 2024 09:53:47 +0100 Message-Id: <20240916085400.1046925-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier This value can be accessed only during a memory callback, using new qemu_plugin_mem_get_value function. Returned value can be extended when QEMU will support accesses wider than 128 bits. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1719 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2152 Reviewed-by: Richard Henderson Reviewed-by: Xingtao Yao Reviewed-by: Alex Bennée Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- include/qemu/qemu-plugin.h | 32 ++++++++++++++++++++++++++++++++ plugins/api.c | 33 +++++++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 1 + 3 files changed, 66 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index c71c705b69..649ce89815 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -262,6 +262,29 @@ enum qemu_plugin_mem_rw { QEMU_PLUGIN_MEM_RW, }; +enum qemu_plugin_mem_value_type { + QEMU_PLUGIN_MEM_VALUE_U8, + QEMU_PLUGIN_MEM_VALUE_U16, + QEMU_PLUGIN_MEM_VALUE_U32, + QEMU_PLUGIN_MEM_VALUE_U64, + QEMU_PLUGIN_MEM_VALUE_U128, +}; + +/* typedef qemu_plugin_mem_value - value accessed during a load/store */ +typedef struct { + enum qemu_plugin_mem_value_type type; + union { + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + struct { + uint64_t low; + uint64_t high; + } u128; + } data; +} qemu_plugin_mem_value; + /** * enum qemu_plugin_cond - condition to enable callback * @@ -551,6 +574,15 @@ bool qemu_plugin_mem_is_big_endian(qemu_plugin_meminfo_t info); QEMU_PLUGIN_API bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info); +/** + * qemu_plugin_mem_get_mem_value() - return last value loaded/stored + * @info: opaque memory transaction handle + * + * Returns: memory value + */ +QEMU_PLUGIN_API +qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info); + /** * qemu_plugin_get_hwaddr() - return handle for memory operation * @info: opaque memory info structure diff --git a/plugins/api.c b/plugins/api.c index 2ff13d09de..3316d4a04d 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -351,6 +351,39 @@ bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info) return get_plugin_meminfo_rw(info) & QEMU_PLUGIN_MEM_W; } +qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info) +{ + uint64_t low = current_cpu->neg.plugin_mem_value_low; + qemu_plugin_mem_value value; + + switch (qemu_plugin_mem_size_shift(info)) { + case 0: + value.type = QEMU_PLUGIN_MEM_VALUE_U8; + value.data.u8 = (uint8_t)low; + break; + case 1: + value.type = QEMU_PLUGIN_MEM_VALUE_U16; + value.data.u16 = (uint16_t)low; + break; + case 2: + value.type = QEMU_PLUGIN_MEM_VALUE_U32; + value.data.u32 = (uint32_t)low; + break; + case 3: + value.type = QEMU_PLUGIN_MEM_VALUE_U64; + value.data.u64 = low; + break; + case 4: + value.type = QEMU_PLUGIN_MEM_VALUE_U128; + value.data.u128.low = low; + value.data.u128.high = current_cpu->neg.plugin_mem_value_high; + break; + default: + g_assert_not_reached(); + } + return value; +} + /* * Virtual Memory queries */ diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index ca773d8d9f..eed9d8abd9 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -13,6 +13,7 @@ qemu_plugin_insn_size; qemu_plugin_insn_symbol; qemu_plugin_insn_vaddr; + qemu_plugin_mem_get_value; qemu_plugin_mem_is_big_endian; qemu_plugin_mem_is_sign_extended; qemu_plugin_mem_is_store; From patchwork Mon Sep 16 08:53:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828988 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681525wrb; Mon, 16 Sep 2024 01:55:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVBZRPtnsjpRAUudxNw07KzYZk4wyBFjP7lWjxz+BRhQRHMmsOKBAPxmFm/eAs/AyfNk5Yxfw==@linaro.org X-Google-Smtp-Source: AGHT+IE39zDiWyCxbk1dHivACPsY32l9jjFuE97BcsLlfCqOq4gr+kTo/66/WGfrjallfIGWtwGW X-Received: by 2002:a05:620a:2447:b0:7a9:bdac:6405 with SMTP id af79cd13be357-7ab30d23df0mr2137462485a.17.1726476952842; Mon, 16 Sep 2024 01:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726476952; cv=none; d=google.com; s=arc-20240605; b=fNIU9i8VPRKEtFYucWMtZ9sc7Uy6tmqNPgoA4gisV82fAz6iIwsk649wU8DEJZNFtV DKQ1MhExmTYIutb3BX05N0GojarACsQyLbdtxJZZzRIZM/5Pf+0CRX+z4MFMam3m4CCg 0tFr+dDest53sR1RV0JcysOuu3MXQyYdXiIkZzThhwtXyOgC/WaG4W2jl7xqvLIv8J5U J/qv8tueqkK9Vuq7UlshF2yq6d1FeYl/mHKyrcrhSup6veai9sN0o/bVoEr0DVsWt3rt VyTTBEilqmB+d2BjWiFOvX/iPqhCryUHx/Olgvn/Lt4Gg5deoiYHPttMFrYIh3vWu5Hu Quug== 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=yUal07zdcm4Ygo3M2xPY0Gx5kjUZNu1C0Q2GU9EplJc=; fh=J7xxoiH/FgLINVeQdLJSQ9A6Jne2JYMDx39ZFxN4EsU=; b=J0+WS9a9L24IfhqdtMQbrk1/NQ/BRrqy1f7xdUSr4kBLOPBHj2mqbjeBlGnpBiftYF mGMRE2OzALijhj5943j4ztsNMntlXfVekSv233nXoa40U9Zu8WNz3OgYkImXW9nwX5Xh F4f/BUd61Bc0BjVb8OdSTp5/s8Ftyq4/w7h/brHUkXiaQ7tD3AeHKnpUL5F445F/SzQC JVnm0XLPfah8H7uRXwvY63cFoGq4oFeVBTdu+z6rF0V2B8BIHeCx7MjCd4dj3g26nwes YFM5ckKUeVmSXUFrSlfiIU8H51vc2XMCVGimsPMlwlI7lNWOHVNJkF+Lg6sIzzQ3lK4p UGUg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MjhT80Z1; 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-7ab3eb86f6dsi537715385a.693.2024.09.16.01.55.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:55: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=MjhT80Z1; 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 1sq7VT-0001Pq-Vf; Mon, 16 Sep 2024 04:54: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 1sq7V3-0000F3-6c for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:26 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Un-0005D7-8N for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:24 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-42cb5b3c57eso41372195e9.2 for ; Mon, 16 Sep 2024 01:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476847; x=1727081647; 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=yUal07zdcm4Ygo3M2xPY0Gx5kjUZNu1C0Q2GU9EplJc=; b=MjhT80Z1H1MhvVaVj20l4mE0xDhHvEx23edFmML0ZbxFLMg6TOmN09ph4499PzNkBV xb98ViK7d9d1OMadPMwgT/Y0xHX98fyk/KphkLSsztMH0u857sxxg//dqfV0Pkxl1NCE LQYR4LxzA/RL/ptwhdxyDpYyJWERR5s8pD/M+VQBMjZHCVBOmXX3UKf3ITcfQPd+BQ1K hjqfAq1VT8EDYOl9yKjf9JNp3/t1ODN7P30Gbk64MtH1YEygGrwdFZxqxBhl4Bv77CIu +ggzHTmoxArhM+BfbXpwoImnzlB+lGUJcr/H2PnBwy+xjAeZmCvfvrp/96F2bp+F0Evu M8Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476847; x=1727081647; 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=yUal07zdcm4Ygo3M2xPY0Gx5kjUZNu1C0Q2GU9EplJc=; b=Ke9R1KWczr/vL+PXlTKOy1nnR1/LbW76az2Rv49MDKbte36XUg0YMZwIWxxOoAF+qX SEsO4w9OLQyj8EYazhj+WmPGrSY59Z+DbZU42g7YgtaSRxwo25YcMK9FHP1VaDWn1f1k rR16RDUe2CZRNq4IE4BRCpUsjkwao/RxXiRmzYAQItZo9aWjDbylJnyBYXWxTu8jxkhs EWRmkQL/o6HmjDNOfJNiluBK05q3Z1lDNiVAyXBSfc4a2gu6LfYB7gLF7GNSpDQ4Dhpe p5xzqPyXwoI1uncG5cIvSeDhzRrRim/xbayG9nD6uC0VoU8sdJX5GvJBoy2MZBEUMp7q guwg== X-Gm-Message-State: AOJu0Yy0LdgPR87noPG7TXtW5kAYJPW+N1pdUMjqH1/Zn34IBgwTpKoZ yIMiw9oayp9EH+XPH125WFk5ET4fN/G8tYX8mpJ6iRn0hidseQhpluUjy671ceU= X-Received: by 2002:a05:6000:1448:b0:378:a935:482 with SMTP id ffacd0b85a97d-378c2d621c1mr10585661f8f.58.1726476847478; Mon, 16 Sep 2024 01:54:07 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42d9b054d7esm104993085e9.1.2024.09.16.01.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id DA8565F938; Mon, 16 Sep 2024 09:54:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v2 06/18] tests/tcg: add mechanism to run specific tests with plugins Date: Mon, 16 Sep 2024 09:53:48 +0100 Message-Id: <20240916085400.1046925-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier Only multiarch tests are run with plugins, and we want to be able to run per-arch test with plugins too. Tested-by: Xingtao Yao Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-4-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- tests/tcg/Makefile.target | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index 452a2cde65..c5b1c7a786 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -152,10 +152,11 @@ PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c))) # only expand MULTIARCH_TESTS which are common on most of our targets # to avoid an exponential explosion as new tests are added. We also # add some special helpers the run-plugin- rules can use below. +# In more, extra tests can be added using ADDITIONAL_PLUGINS_TESTS variable. ifneq ($(MULTIARCH_TESTS),) $(foreach p,$(PLUGINS), \ - $(foreach t,$(MULTIARCH_TESTS),\ + $(foreach t,$(MULTIARCH_TESTS) $(ADDITIONAL_PLUGINS_TESTS),\ $(eval run-plugin-$(t)-with-$(p): $t $p) \ $(eval RUN_TESTS+=run-plugin-$(t)-with-$(p)))) endif # MULTIARCH_TESTS From patchwork Mon Sep 16 08:53:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828990 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681570wrb; Mon, 16 Sep 2024 01:56:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWiIgROAa24r+FCIouFaij0zwxN+fTfrMwYxX4RGvmLaBbCm3wiRzLAsYMWEyeNXGAFmEgXyQ==@linaro.org X-Google-Smtp-Source: AGHT+IHIPIEeMazIAJYM6gjDFtmVKfrDokMzRqoPuqmrrq3NH/KJ7IiW+wBtnNH+Szl1kFBZpY+q X-Received: by 2002:a05:6214:450a:b0:6c5:55d5:f53d with SMTP id 6a1803df08f44-6c57350b9e6mr212794336d6.8.1726476964023; Mon, 16 Sep 2024 01:56:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726476964; cv=none; d=google.com; s=arc-20240605; b=ar9cduv1AfrgNv+874+JLEsP3MPappv4SWuQuOkL+j4t7pMhIVSJZ4yvnjqD9qVQbM B2P6VYXXgvGXWhOXiW4uTfTf9A2ipGNjaLnziDkxP50gUPUT9sU4S/z8s7QHjFb92ynb DXhaotEo8UvHk223cvCVchdVlhWQqpVvROPOT9pqXQ25/WtSyc7Ay2WAPUFRtKnAyA87 lfd8OyWWObiP48gcca6CC6CwG2h+kaUhmOiZTjZHF6lZJzIkPWiAhqs7Iw4qoyg6lqxf rwI4mDAwYvuFTAnoUjyW8Gk66jCUPpFs83qVqrFLoLUOO8ibhzCzHQzvR+2M7gJ7iZfg /BwA== 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=Uke3qYlJar9aO7gasrp34dE9JqnQR3uW9hBIj7y5AhM=; fh=J7xxoiH/FgLINVeQdLJSQ9A6Jne2JYMDx39ZFxN4EsU=; b=QJdSSB7Ybt0OzXlDkP0cE8v4b2E7lWPAowLC8uD5IMgL9C/Xn7Tpg3eODs36+q5AAp e9Bc0s9l8pD/h8mcB45UxaSra97VROpCRalJ38Dl/CgAoQ6L+Mgpl4c2BFH9+ZZ1g1a/ cuvEUyIx4RmdStd8jKBQ3EHGessvhd3pijqcd0KskVgrtUN3NQrhRicYfUoBW45Grvs2 m+5PO6tTJx5+2MlysQ6gSDqB6ivC/nLbm/PYsEqG2z1MfIArvbA+nsIYljlfv1WaKX2f 7jqB0yBTTYbCbZzcMH4i8s2RK7WgC8JqMkF66ESDq2SOjQAkw7XkATdhuzMiGo095FWS 6QzA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="LFp/X58L"; 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-6c58c6211a4si53091596d6.118.2024.09.16.01.56.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:56:04 -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="LFp/X58L"; 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 1sq7Vb-0001vK-2Y; Mon, 16 Sep 2024 04:54:59 -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 1sq7VC-0000l3-9M for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:35 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Un-0005DE-N9 for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:34 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42cc43454d5so23822965e9.3 for ; Mon, 16 Sep 2024 01:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476848; x=1727081648; 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=Uke3qYlJar9aO7gasrp34dE9JqnQR3uW9hBIj7y5AhM=; b=LFp/X58Lx/azJhRQ0g2eSMNg/OSHJQB1YF8y/sj7EVkaBYTwQyLRbfbSKzwSGzyhF8 Ae8ws3qWcZPy6JnQwKPZuwcpVqR3yRcVlbj4FKLSZJRhWqP2vtqBrUjesO3XbsPmkQsA WJfQcWge6MXxbkEN+mO18E3BKiUPHLu5UuFYjoFE5cJK3kh6hqWukiYGFN9DJ7ZAiuYj G0jYvwB8EZu1EzR0JUeqYS4bi8kBItsUO3Ztan6rG+cG2RxnlPoXRESgiQDx3QVd+JfY 1rg/1vnrRKx27CfAr8xGvsIsmXd6NSn9iRUif3sYeu9jH8ZOe6oloujO3K7KTG/wiFjy Od2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476848; x=1727081648; 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=Uke3qYlJar9aO7gasrp34dE9JqnQR3uW9hBIj7y5AhM=; b=uMZ0cu2/9mxkJCjUt01dFMjJu8L+YZfupW2J0Mgo6E7YkWhlUqc/IsXzYxqVt4/+y4 XqZu+NmqouoJ2rUiae3E51/A8sdVneDt77EcB9iX6Ms/6G5ueMZ8/uQBXeZ9t63wdzEN 5p8WCINI+nYPdyZN75Ax6hiKiKFYBmYVPXCD7Pc2P1i9EL9QC+7KYe4YFR7xCL2WLuw1 rnPGCKiqOs+9RmXkBcMSW2FiSU+aACdDzZpRWrSNf4BnDIHB/phcX3rqucBdj7qV7wtj SmnwiyyoBIaA7fNs1jZkr3xc05Gsq6b8Ir49VA8/crO/MBR9pNjdtvIV+nJmz/pQVJVW sVJg== X-Gm-Message-State: AOJu0YzJfJxVheBEdoCCVhETYPsKpmC2qN2pPl1GfK18Yjf4GUAx2MTm MxCXpNLZWiuma/P1FsV8cBSdNiGeNYJj5HpvzMdA35IxfUq2Kx2pK/M9Ec0Huo4= X-Received: by 2002:adf:b219:0:b0:374:ca4f:bd70 with SMTP id ffacd0b85a97d-378d62537c7mr4746205f8f.53.1726476847831; Mon, 16 Sep 2024 01:54:07 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e780028esm6574261f8f.71.2024.09.16.01.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id F08B65F947; Mon, 16 Sep 2024 09:54:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v2 07/18] tests/tcg: allow to check output of plugins Date: Mon, 16 Sep 2024 09:53:49 +0100 Message-Id: <20240916085400.1046925-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier A specific plugin test can now read and check a plugin output, to ensure it contains expected values. Tested-by: Xingtao Yao Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-5-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- tests/tcg/Makefile.target | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index c5b1c7a786..2da70b2fcf 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -90,6 +90,7 @@ CFLAGS= LDFLAGS= QEMU_OPTS= +CHECK_PLUGIN_OUTPUT_COMMAND= # If TCG debugging, or TCI is enabled things are a lot slower @@ -180,6 +181,10 @@ run-plugin-%: -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \ -d plugin -D $*.pout \ $(call strip-plugin,$<)) + $(if $(CHECK_PLUGIN_OUTPUT_COMMAND), \ + $(call quiet-command, $(CHECK_PLUGIN_OUTPUT_COMMAND) $*.pout, \ + TEST, check plugin $(call extract-plugin,$@) output \ + with $(call strip-plugin,$<))) else run-%: % $(call run-test, $<, \ @@ -194,6 +199,10 @@ run-plugin-%: -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \ -d plugin -D $*.pout \ $(QEMU_OPTS) $(call strip-plugin,$<)) + $(if $(CHECK_PLUGIN_OUTPUT_COMMAND), \ + $(call quiet-command, $(CHECK_PLUGIN_OUTPUT_COMMAND) $*.pout, \ + TEST, check plugin $(call extract-plugin,$@) output \ + with $(call strip-plugin,$<))) endif gdb-%: % From patchwork Mon Sep 16 08:53:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828992 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681781wrb; Mon, 16 Sep 2024 01:56:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWGIhUZkiZumMR+2K6vUJN4PzwCgwojFtTCmOCog+FaBe3IEDMFtLQOXH1v0WbvAA+zEky7Lg==@linaro.org X-Google-Smtp-Source: AGHT+IFzBtkWAJvvuG7AXtMoOFoZSojqNywVX3r5Pg9ouwdcQPoEe9SwNeMQnJTl38VmNOa0l5Wu X-Received: by 2002:ad4:5011:0:b0:6c5:8ecd:41fc with SMTP id 6a1803df08f44-6c58ecd430bmr86482716d6.15.1726477014321; Mon, 16 Sep 2024 01:56:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726477014; cv=none; d=google.com; s=arc-20240605; b=fOERNz6ghMQqoQgaNt2xGeGBHTgNC99C/kgvRNq6n27h+gJN+DvlYEsZANCdby16sv lkTtdBY/CJocIHRnaldIkZmKQwgZW1+5uw/Z/rPOhxiC6ag0lGB5x8W6pa1BMQ90fgkZ sSqamMst9o2nf3NcFE2r7oD2zV5rjdvSC+oWqrUVgdtdi5vax2NVuTFRiI97IK6vfRZE rhEXUjYClKAkMc2Js6ivRY/jutnCSGtJEOzxaWy0bDu8F4FAILpsvMkhE7wzAgqlPPqo Rhtdy8r3ODlR+ER8w9q9YBeAcALU9qm8I88YKmn/66y5IwWaTKR/1OSVO9gPVYIDmKmG kQsg== 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=R3mmoZsXxDlfMOCui4cd46NxPRxHQYb5G17T8SSWAU4=; fh=J7xxoiH/FgLINVeQdLJSQ9A6Jne2JYMDx39ZFxN4EsU=; b=UEyO4UoKkTg1f8/8Vb6NxNIKam76TE2AOcubdk6JgSGwrsY3RmIu/+DoksiHM7As7b nUSFPDjWSsOqS5Z1em4k1a8UzFF1aPpCW88OZBEnXEy1AwgS/H1ICckxnVilj8SwNspH 4UtBRSJ/yl9xVuBqjsjtnGfGZBtgoYZ6NtnBeFYgN79SARgQbmoa9qLxCejS/DXRxAHR hd0WWFEVgN45ZXy5sgyAonTF6tfqhDGcpj3j8WOOEF5A4fFTp7VdBnyAkZhnkQPj0QPb AIeYidKvv25rB3ZnimPipuOW3dBD9uuduoYC5j/MQdgB6bVWhhXHqmfcTWm3/y6075eA T/Jg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lY7O8PMT; 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-6c58c7f9e34si53195956d6.607.2024.09.16.01.56.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:56: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=lY7O8PMT; 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 1sq7VW-0001dX-VC; Mon, 16 Sep 2024 04:54:55 -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 1sq7V4-0000Ha-TC for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:26 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Un-0005DM-RN for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:26 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-374c7d14191so3247170f8f.0 for ; Mon, 16 Sep 2024 01:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476848; x=1727081648; 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=R3mmoZsXxDlfMOCui4cd46NxPRxHQYb5G17T8SSWAU4=; b=lY7O8PMTukMMCH+Vhn5rT6ODQKoeV4hvffJr0twrSpk7ZWszM3Pr1+7qogO5hfEtXg lICjYWuH3BBkyq6U3EStb3AiiwSE1Ib/R0Ke7+YsqWRfH2GOKH17kM5g6soBXIQugM3y 2TeVspcyLO1DCE4JBxwjCALyUa8FSV5NJPNWGxJ+98QRXO21KMD999MhS056AkoXvNUd OMdSwPba2+yxAlVMEvFLCGxhar0k5NGEkRm42oZvgkl4igTT11Q3YxFzdEewAmkhWitj BF14Pm4ImiX5Y5XOA5rVPMXQ42Jn+X1GXHB2slKJ0Q67iNU7Ex0GDGJpM7JP9sW7rfc4 0Kmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476848; x=1727081648; 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=R3mmoZsXxDlfMOCui4cd46NxPRxHQYb5G17T8SSWAU4=; b=k62CpwY196TmcEt/Z8FX5lY8s7rRJYsZy5sA9lt8FxahxDeSlP6seKx/1+Lz6ZKeaS rvi2CdqbjBcn1uUroZ9xRJ3tclWxzxItuugklYepCMUi+lwP1XOuWKC2YxH/6ZlGNNnA ATFetnhY+DMvpfMmmTP1TtxoExD5fgkSXhkfThI859S6we69WZWzsRKCwKKOGg4G0h2R kfGX2eMTcQNM3kBSpjKx2tdPOIGwn9zOqMNXCvOHh6g6rQ5c+ztdlwjBGF4tJEK92cY7 s7oDs8LJnMRxvPWP7NGTAfT23emrqfD/LW9tRoIL058fxpP715GPIqZD3I7pTnjXJOlZ 2IMw== X-Gm-Message-State: AOJu0Yzx5BH0HjteKRKqAqyyQQrUKeoenF9kv0vcEhI8knndffBskRB4 Mr/1x5wzV+c/jFWynxQIIxFQetQSXmei+/o5SRM6UhdMKBnN3qW7VIFuxg4t5u0= X-Received: by 2002:a5d:598a:0:b0:374:c6b6:c656 with SMTP id ffacd0b85a97d-378c27f94bbmr10245527f8f.21.1726476848139; Mon, 16 Sep 2024 01:54:08 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e73e80dbsm6620754f8f.33.2024.09.16.01.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 117885F94D; Mon, 16 Sep 2024 09:54:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v2 08/18] tests/tcg/plugins/mem: add option to print memory accesses Date: Mon, 16 Sep 2024 09:53:50 +0100 Message-Id: <20240916085400.1046925-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier By using "print-accesses=true" option, mem plugin will now print every value accessed, with associated size, type (store vs load), symbol, instruction address and phys/virt address accessed. Reviewed-by: Richard Henderson Reviewed-by: Xingtao Yao Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-6-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- tests/tcg/plugins/mem.c | 69 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c index b650dddcce..086e6f5bdf 100644 --- a/tests/tcg/plugins/mem.c +++ b/tests/tcg/plugins/mem.c @@ -21,10 +21,15 @@ typedef struct { uint64_t io_count; } CPUCount; +typedef struct { + uint64_t vaddr; + const char *sym; +} InsnInfo; + static struct qemu_plugin_scoreboard *counts; static qemu_plugin_u64 mem_count; static qemu_plugin_u64 io_count; -static bool do_inline, do_callback; +static bool do_inline, do_callback, do_print_accesses; static bool do_haddr; static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW; @@ -60,6 +65,44 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, } } +static void print_access(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, + uint64_t vaddr, void *udata) +{ + InsnInfo *insn_info = udata; + unsigned size = 8 << qemu_plugin_mem_size_shift(meminfo); + const char *type = qemu_plugin_mem_is_store(meminfo) ? "store" : "load"; + qemu_plugin_mem_value value = qemu_plugin_mem_get_value(meminfo); + uint64_t hwaddr = + qemu_plugin_hwaddr_phys_addr(qemu_plugin_get_hwaddr(meminfo, vaddr)); + g_autoptr(GString) out = g_string_new(""); + g_string_printf(out, + "0x%"PRIx64",%s,0x%"PRIx64",0x%"PRIx64",%d,%s,", + insn_info->vaddr, insn_info->sym, + vaddr, hwaddr, size, type); + switch (value.type) { + case QEMU_PLUGIN_MEM_VALUE_U8: + g_string_append_printf(out, "0x%02"PRIx8, value.data.u8); + break; + case QEMU_PLUGIN_MEM_VALUE_U16: + g_string_append_printf(out, "0x%04"PRIx16, value.data.u16); + break; + case QEMU_PLUGIN_MEM_VALUE_U32: + g_string_append_printf(out, "0x%08"PRIx32, value.data.u32); + break; + case QEMU_PLUGIN_MEM_VALUE_U64: + g_string_append_printf(out, "0x%016"PRIx64, value.data.u64); + break; + case QEMU_PLUGIN_MEM_VALUE_U128: + g_string_append_printf(out, "0x%016"PRIx64"%016"PRIx64, + value.data.u128.high, value.data.u128.low); + break; + default: + g_assert_not_reached(); + } + g_string_append_printf(out, "\n"); + qemu_plugin_outs(out->str); +} + static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) { size_t n = qemu_plugin_tb_n_insns(tb); @@ -79,6 +122,16 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) QEMU_PLUGIN_CB_NO_REGS, rw, NULL); } + if (do_print_accesses) { + /* we leak this pointer, to avoid locking to keep track of it */ + InsnInfo *insn_info = g_malloc(sizeof(InsnInfo)); + const char *sym = qemu_plugin_insn_symbol(insn); + insn_info->sym = sym ? sym : ""; + insn_info->vaddr = qemu_plugin_insn_vaddr(insn); + qemu_plugin_register_vcpu_mem_cb(insn, print_access, + QEMU_PLUGIN_CB_NO_REGS, + rw, (void *) insn_info); + } } } @@ -117,6 +170,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", opt); return -1; } + } else if (g_strcmp0(tokens[0], "print-accesses") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &do_print_accesses)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + return -1; + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; @@ -129,6 +188,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, return -1; } + if (do_print_accesses) { + g_autoptr(GString) out = g_string_new(""); + g_string_printf(out, + "insn_vaddr,insn_symbol,mem_vaddr,mem_hwaddr," + "access_size,access_type,mem_value\n"); + qemu_plugin_outs(out->str); + } + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); mem_count = qemu_plugin_scoreboard_u64_in_struct( counts, CPUCount, mem_count); From patchwork Mon Sep 16 08:53:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828997 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp682144wrb; Mon, 16 Sep 2024 01:58:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVJM7ovsceM9BGwIkMR1XaMtQwRmAvsCrS2mazznktF9ddJLKOLyy/mavQi9X44JhVig41HIQ==@linaro.org X-Google-Smtp-Source: AGHT+IF6xFaf/4FGctFRAJoP/x5rUzqIAK3OKnDRmwfjQINYDivMm4j3a6SDF1Od+Cl60ifMSMXz X-Received: by 2002:a05:6214:5503:b0:6c5:e6c:d5fb with SMTP id 6a1803df08f44-6c57df568e5mr171712156d6.25.1726477094434; Mon, 16 Sep 2024 01:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726477094; cv=none; d=google.com; s=arc-20240605; b=NZzDlULP07gfluq6gY009b+i05FsbKu1NBvDW/3WrgP3Q9ibpVHqsBKOEgfgUh58+g g68kCChHsySL73G2YUK6YdDQBcaJSipoNPs8nPk8SNWJWPLyMj7DwVSjhXAC2mG8whZd snjZJRuFddClRI7uIl/S6kf3QwllDkTJb7zlexN231VSzqbH/Kg0yulEHtZM97EhiH0w t7VcJnPuiReiEMpG1YaImEDKi6+kJF/bANdLf5TGLBbOG4XUlIHXEjm3AZFuQr0X6+ZQ JsgH7mMVahKymKpLWf10zdi+CtHpB7U4KPNn+qDH+NRlCU3XuwGAQ+lg4fJveYCZcvSh V+VA== 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=wdCrRRlRbQfrNYdX9012mUfHcuVziNRXWE1crIIitX8=; fh=J7xxoiH/FgLINVeQdLJSQ9A6Jne2JYMDx39ZFxN4EsU=; b=ifER4CSq7mbYGE23VlM96SyMeSs8S/VTgk21clKKSvY9tWdzOHZ89iOm4yqXuXj0tQ wDWJwf+RtdgUH1dthk2PZt8NjH4BQurfGZbAhARXoZ3bQ/PHDHhDNLQjHl+dwyDNq3eL IQxlruz+HGHeis4yPLFvvn5C7H5QYXcwXMhNonyQMWl+XSp6UtF6kQGakaKBMfraVmqg 2h/LHne/0U7rqX9kZq7gO1KLIlwE28ZBRt/zs5/h3gpGVB04PkI9+66DW2XYBRSJU/Xp ODTd/WrR/JIfXrFmQn06VDNjW7zseZKFX82R2yyWCowExYiD93828G07HIIUC57Hnz8k PoSQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aAj8LQO8; 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-6c58c7d737dsi52682796d6.416.2024.09.16.01.58.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:58:14 -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=aAj8LQO8; 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 1sq7VZ-0001ot-B2; Mon, 16 Sep 2024 04:54: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 1sq7V6-0000QL-MB for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:29 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Up-0005Dp-8U for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:28 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42cb2191107so31972825e9.1 for ; Mon, 16 Sep 2024 01:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476850; x=1727081650; 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=wdCrRRlRbQfrNYdX9012mUfHcuVziNRXWE1crIIitX8=; b=aAj8LQO8sfdN72nmwp/oeo9vlw+PQbC1gqmemm77W3q5YPwZA6hs3C6kf4X1MQTKXL 4TWNnxwv72dp2oVGuidg6ktEgrxyeOepeV8GmXbitd5wrfwBMRJfjBJyaY9RwRT7C3Zx zv/rI3tyCsHKWua0WJiiVXGZW3xu9lWCuVAR6ctPvjS6tzB0KPTZyyuIreOdo8E7HbGC IC/t3MawgqA31sRA0LQfHBcSXXZxBc65bP3Lz/pm3/3kXgOvDSlCrAWx80etOruryNTf 6CiNMpx1WKi+RfZ4xITFyAtsMxMYpVzQ1M865J6HWzjU6vsx5mJEGbZUm6iBErMUNJML Rl6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476850; x=1727081650; 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=wdCrRRlRbQfrNYdX9012mUfHcuVziNRXWE1crIIitX8=; b=iSXLRADJkfYB1Go5TaYgFjT8iRLx0JO9D8hIOvFfOg8GT4u5jW2vDOlkwIXkGHCSl6 E2KG9MMJMN0n4t/ZyO/HyPCLBqFV86x189X7p4/DZXavBhzohYJYrKVAp00A15kI+/YE wAMMO5y4bjXesWu0wrMQo+23gL9FxgAcwnD99GKSNZwOFRuRYbWy44vGRi2/Tn1DE8+Q uRb4xndovPZNav7krWoraqTQbm1GjUHBTIPPQtUwe4qNR3AmK0qwyPNngAiljW16RAUp d/tcWwOoizWchchVn6ne6mje/Eya2JmHCs6KmYpxLrjIZWodq9TW+Wz67VAziY4u+g8+ i3ww== X-Gm-Message-State: AOJu0Yy3NxKZXC9/7246cB8pJDfme8AiXDYyDh11KJ99uYNS3ncWT7Zn Oz+USIY4GkGZNBIjATOrQVOhuyVeNfm0/pdVM14Sgg9pCoN2NP/VhZTnTfsY8LA= X-Received: by 2002:a05:600c:3b1d:b0:42a:a6aa:4135 with SMTP id 5b1f17b1804b1-42cdb53fab7mr86097495e9.20.1726476849465; Mon, 16 Sep 2024 01:54:09 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e78044dfsm6572115f8f.94.2024.09.16.01.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 2CD275F952; Mon, 16 Sep 2024 09:54:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v2 09/18] tests/tcg/multiarch: add test for plugin memory access Date: Mon, 16 Sep 2024 09:53:51 +0100 Message-Id: <20240916085400.1046925-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier Add an explicit test to check expected memory values are read/written. 8,16,32 load/store are tested for all arch. 64,128 load/store are tested for aarch64/x64. atomic operations (8,16,32,64) are tested for x64 only. By default, atomic accesses are non atomic if a single cpu is running, so we force creation of a second one by creating a new thread first. load/store helpers code path can't be triggered easily in user mode (no softmmu), so we can't test it here. Output of test-plugin-mem-access.c is the list of expected patterns in plugin output. By reading stdout, we can compare to plugins output and have a multiarch test. Can be run with: make -C build/tests/tcg/$ARCH-linux-user run-plugin-test-plugin-mem-access-with-libmem.so Tested-by: Xingtao Yao Signed-off-by: Pierrick Bouvier Message-Id: <20240910172033.1427812-7-pierrick.bouvier@linaro.org> --- tests/tcg/multiarch/test-plugin-mem-access.c | 177 +++++++++++++++++++ tests/tcg/alpha/Makefile.target | 3 + tests/tcg/multiarch/Makefile.target | 11 ++ tests/tcg/multiarch/check-plugin-output.sh | 36 ++++ tests/tcg/ppc64/Makefile.target | 5 + 5 files changed, 232 insertions(+) create mode 100644 tests/tcg/multiarch/test-plugin-mem-access.c create mode 100755 tests/tcg/multiarch/check-plugin-output.sh diff --git a/tests/tcg/multiarch/test-plugin-mem-access.c b/tests/tcg/multiarch/test-plugin-mem-access.c new file mode 100644 index 0000000000..057b9aac9f --- /dev/null +++ b/tests/tcg/multiarch/test-plugin-mem-access.c @@ -0,0 +1,177 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * Check if we detect all memory accesses expected using plugin API. + * Used in conjunction with ./check-plugin-mem-access.sh check script. + * Output of this program is the list of patterns expected in plugin output. + * + * 8,16,32 load/store are tested for all arch. + * 64,128 load/store are tested for aarch64/x64. + * atomic operations (8,16,32,64) are tested for x64 only. + */ + +#include +#include +#include +#include + +#if defined(__x86_64__) +#include +#elif defined(__aarch64__) +#include +#endif /* __x86_64__ */ + +static void *data; + +/* ,store_u8,.*,8,store,0xf1 */ +#define PRINT_EXPECTED(function, type, value, action) \ +do { \ + printf(",%s,.*,%d,%s,%s\n", \ + #function, (int) sizeof(type) * 8, action, value); \ +} \ +while (0) + +#define DEFINE_STORE(name, type, value) \ + \ +static void print_expected_store_##name(void) \ +{ \ + PRINT_EXPECTED(store_##name, type, #value, "store"); \ +} \ + \ +static void store_##name(void) \ +{ \ + *((type *)data) = value; \ + print_expected_store_##name(); \ +} + +#define DEFINE_ATOMIC_OP(name, type, value) \ + \ +static void print_expected_atomic_op_##name(void) \ +{ \ + PRINT_EXPECTED(atomic_op_##name, type, "0x0*42", "load"); \ + PRINT_EXPECTED(atomic_op_##name, type, #value, "store"); \ +} \ + \ +static void atomic_op_##name(void) \ +{ \ + *((type *)data) = 0x42; \ + __sync_val_compare_and_swap((type *)data, 0x42, value); \ + print_expected_atomic_op_##name(); \ +} + +#define DEFINE_LOAD(name, type, value) \ + \ +static void print_expected_load_##name(void) \ +{ \ + PRINT_EXPECTED(load_##name, type, #value, "load"); \ +} \ + \ +static void load_##name(void) \ +{ \ + \ + /* volatile forces load to be generated. */ \ + volatile type src = *((type *) data); \ + volatile type dest = src; \ + (void)src, (void)dest; \ + print_expected_load_##name(); \ +} + +DEFINE_STORE(u8, uint8_t, 0xf1) +DEFINE_LOAD(u8, uint8_t, 0xf1) +DEFINE_STORE(u16, uint16_t, 0xf123) +DEFINE_LOAD(u16, uint16_t, 0xf123) +DEFINE_STORE(u32, uint32_t, 0xff112233) +DEFINE_LOAD(u32, uint32_t, 0xff112233) + +#if defined(__x86_64__) || defined(__aarch64__) +DEFINE_STORE(u64, uint64_t, 0xf123456789abcdef) +DEFINE_LOAD(u64, uint64_t, 0xf123456789abcdef) + +static void print_expected_store_u128(void) +{ + PRINT_EXPECTED(store_u128, __int128, + "0xf122334455667788f123456789abcdef", "store"); +} + +static void store_u128(void) +{ +#ifdef __x86_64__ + _mm_store_si128(data, _mm_set_epi32(0xf1223344, 0x55667788, + 0xf1234567, 0x89abcdef)); +#else + const uint32_t init[4] = {0x89abcdef, 0xf1234567, 0x55667788, 0xf1223344}; + uint32x4_t vec = vld1q_u32(init); + vst1q_u32(data, vec); +#endif /* __x86_64__ */ + print_expected_store_u128(); +} + +static void print_expected_load_u128(void) +{ + PRINT_EXPECTED(load_u128, __int128, + "0xf122334455667788f123456789abcdef", "load"); +} + +static void load_u128(void) +{ +#ifdef __x86_64__ + __m128i var = _mm_load_si128(data); +#else + uint32x4_t var = vld1q_u32(data); +#endif + (void) var; + print_expected_load_u128(); +} +#endif /* __x86_64__ || __aarch64__ */ + +#if defined(__x86_64__) +DEFINE_ATOMIC_OP(u8, uint8_t, 0xf1) +DEFINE_ATOMIC_OP(u16, uint16_t, 0xf123) +DEFINE_ATOMIC_OP(u32, uint32_t, 0xff112233) +DEFINE_ATOMIC_OP(u64, uint64_t, 0xf123456789abcdef) +#endif /* __x86_64__ */ + +static void *f(void *p) +{ + return NULL; +} + +int main(void) +{ + /* + * We force creation of a second thread to enable cpu flag CF_PARALLEL. + * This will generate atomic operations when needed. + */ + pthread_t thread; + pthread_create(&thread, NULL, &f, NULL); + pthread_join(thread, NULL); + + /* allocate storage up to 128 bits */ + data = malloc(16); + + store_u8(); + load_u8(); + + store_u16(); + load_u16(); + + store_u32(); + load_u32(); + +#if defined(__x86_64__) || defined(__aarch64__) + store_u64(); + load_u64(); + + store_u128(); + load_u128(); +#endif /* __x86_64__ || __aarch64__ */ + +#if defined(__x86_64__) + atomic_op_u8(); + atomic_op_u16(); + atomic_op_u32(); + atomic_op_u64(); +#endif /* __x86_64__ */ + + free(data); +} diff --git a/tests/tcg/alpha/Makefile.target b/tests/tcg/alpha/Makefile.target index fdd7ddf64e..36d8ed1eae 100644 --- a/tests/tcg/alpha/Makefile.target +++ b/tests/tcg/alpha/Makefile.target @@ -12,4 +12,7 @@ test-cmov: EXTRA_CFLAGS=-DTEST_CMOV test-cmov: test-cond.c $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) +# Force generation of byte read/write +test-plugin-mem-access: CFLAGS+=-mbwx + run-test-cmov: test-cmov diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target index 5e3391ec9d..78b83d5575 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -170,5 +170,16 @@ run-plugin-semiconsole-with-%: TESTS += semihosting semiconsole endif +# Test plugin memory access instrumentation +run-plugin-test-plugin-mem-access-with-libmem.so: \ + PLUGIN_ARGS=$(COMMA)print-accesses=true +run-plugin-test-plugin-mem-access-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND= \ + $(SRC_PATH)/tests/tcg/multiarch/check-plugin-output.sh \ + $(QEMU) $< + +test-plugin-mem-access: CFLAGS+=-pthread -O0 +test-plugin-mem-access: LDFLAGS+=-pthread -O0 + # Update TESTS TESTS += $(MULTIARCH_TESTS) diff --git a/tests/tcg/multiarch/check-plugin-output.sh b/tests/tcg/multiarch/check-plugin-output.sh new file mode 100755 index 0000000000..80607f04b5 --- /dev/null +++ b/tests/tcg/multiarch/check-plugin-output.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# This script runs a given executable using qemu, and compare its standard +# output with an expected plugin output. +# Each line of output is searched (as a regexp) in the expected plugin output. + +set -euo pipefail + +die() +{ + echo "$@" 1>&2 + exit 1 +} + +check() +{ + file=$1 + pattern=$2 + grep "$pattern" "$file" > /dev/null || die "\"$pattern\" not found in $file" +} + +[ $# -eq 3 ] || die "usage: qemu_bin exe plugin_out_file" + +qemu_bin=$1; shift +exe=$1;shift +plugin_out=$1; shift + +expected() +{ + $qemu_bin $exe || + die "running $exe failed" +} + +expected | while read line; do + check "$plugin_out" "$line" +done diff --git a/tests/tcg/ppc64/Makefile.target b/tests/tcg/ppc64/Makefile.target index 509a20be2b..1940886c73 100644 --- a/tests/tcg/ppc64/Makefile.target +++ b/tests/tcg/ppc64/Makefile.target @@ -55,4 +55,9 @@ PPC64_TESTS += signal_save_restore_xer PPC64_TESTS += xxspltw PPC64_TESTS += test-aes +# ppc64 ABI uses function descriptors, and thus, QEMU can't find symbol for a +# given instruction. Thus, we don't check output of mem-access plugin. +run-plugin-test-plugin-mem-access-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND= + TESTS += $(PPC64_TESTS) From patchwork Mon Sep 16 08:53:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828995 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681917wrb; Mon, 16 Sep 2024 01:57:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXpIUBdm1KzLfr6vOAma0Kptr5Z96oKe4RhbXgGcoxSK67/yXV4DcW/dN2a0r+DaAj/Vg5iGw==@linaro.org X-Google-Smtp-Source: AGHT+IEBV5MMBy4euI5F2uK/stkLQdqGXMS0ZYac+H7h1URyL5SVf1XKbu29iJqVV8dMdQrXLFQ/ X-Received: by 2002:a05:6214:2b8b:b0:6c3:67b3:4c1d with SMTP id 6a1803df08f44-6c573519b5bmr261766656d6.13.1726477041512; Mon, 16 Sep 2024 01:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726477041; cv=none; d=google.com; s=arc-20240605; b=OEGjT8R82qhlOwukM2UHOC9fde23XXuJjlI8Zk+oDgM5pSPwGBYJ0uHCOq/TS/4+Y7 B/sy4f4SPh4styKqyo2FmQBGZ7HZEzeeKpLzs6XCGpJJfAwmhgzJQ5NhLNmNGGdrxUwd s48/e0wtCrTfyfniBtO/Hv6uX9yRCF7FHRlHlEHYnRwOOfzUUpb3b+m4zQyWaLbq3uCb y1FwUgazHcaXs5XfDnt7tLg2k/Fbpgg8otuJqBhgKA3UY4V50QIJ4IqoiI9amIhkLVK3 THSoyOv2y4eCIseMPBEErDciSP9rdn8OM8WiLUy0nO+JyvwhQHCQvEnaU9dj4ipLPvKk koXw== 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=mlT6xKCM1MHGEdfr2CcDhKWOabJzOeHlvX+jZ2i+MVk=; fh=ATDHygEnrhDZDytw2YSa+GgRs9jfnpjrC7XifhYWFyU=; b=jtjWc/XQ4DN4k3K2snyKMQdbWprmznLYKteD/O3gLI98yEJ9UAISkM/nJZHDSb7Tyv J8JsWB6f8uJFNPHbG0HHpWDmn3d4GVBMDkXEZ0bpLqbWCr/JmaqRJH58VRa82JJKSqxB bW8oD5JqOl6XwaRQi8JDpVJc72z2Pqk14kk+J4B6tX/vSD6CplDxEGiIlRylSUJzLMOb zr/MDG20GN1kItPPdP+e3q/wWppt7/vQzcCv6bcGXEfft2BtU1kNMZpIsSEIkM/2//8A 9Qv4QZ3d+DI4VMycIkiXSJMzdRAmrUQT56frZGVaRoXMvT5GuTDRBDkG7akOiMcxRCvK mNRQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xMK+nSwB; 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-6c58c7a5468si53107546d6.314.2024.09.16.01.57.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:57:21 -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=xMK+nSwB; 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 1sq7VX-0001j4-V0; Mon, 16 Sep 2024 04:54:55 -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 1sq7V8-0000XT-Ar for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:31 -0400 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Uq-0005E2-Rk for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:30 -0400 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-5367ae52a01so3294291e87.3 for ; Mon, 16 Sep 2024 01:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476851; x=1727081651; 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=mlT6xKCM1MHGEdfr2CcDhKWOabJzOeHlvX+jZ2i+MVk=; b=xMK+nSwB9XzwUW5iheJut5EN9Q0Pl/TC6LbBgQyO/rU7/1sDEIEgy0Q1SD0glREyJl 0n8UXrLOpJow8U+i/Fu+B1ou+F6NAbPJHNm/yHvxAuXV/XR4ueRwLOnilq2eHp7EyYo/ ryrGSk/dwrsxNEiOhwHVFGrr4gYr4Iv8YIU+yXPYaI1rIs1Izdrf5+keATzWXUSV0MDs 946a7p/nGT/XOwwZu6S8oZAqt1d03DrlGIZluSf0gZro2Q/NEAREN0OxNreh8T9QAgdb JA645aiBPY1HSivVSBDfqvqFZIY3A2pThC3n0cNYt91tM8ZnwNuBQdUhqEjXyJ2PfPMh w8xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476851; x=1727081651; 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=mlT6xKCM1MHGEdfr2CcDhKWOabJzOeHlvX+jZ2i+MVk=; b=ToI1VaKyiTIWLjMp6UBqT9blqM9VTPYHpXv+X4u1VK2XFWjvz0JKbnjoy5A67HCijL 5mdinZd6LR1x2/WaqHwMDyzMoYVbtC83l6hICbtmjlzzfsOYgcmC9dNzGDs+ULDG6bmz enpuAJ2dJpl7nMRer3Ab3KKWc2IMOO4Zr3g8XZq22bqcSw9HPXmySLk6aVDXIJxLdBVi +oG8y0mvqcRmKX63AlpgIyhpouaYjt3sqPCm2b3JqRCr8raI5wUWI7GuceWeKPwMUOp/ GdwDmL5VjvHgopQPwNwqOU3KQBtGjmCnk7oahndFrnhRY12d5A8fW0Z0dCCLxOvdRVSp WDEQ== X-Gm-Message-State: AOJu0YyOkkXdvMthw0G+HT0Ix7qo3WaQ/5dW8HOshU8K0QVkhWoMRDXn wfI9LObnghfKY71Tx+dQuB5Qo2jnJV82z/qzAIpnRUEP9ULn6u8QTV+Tsxq0j8I= X-Received: by 2002:a05:6512:3a8c:b0:52e:987f:cfc6 with SMTP id 2adb3069b0e04-5367ff32c42mr4417081e87.51.1726476849860; Mon, 16 Sep 2024 01:54:09 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42da242138bsm70655045e9.35.2024.09.16.01.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 444DC5FC60; Mon, 16 Sep 2024 09:54:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier Subject: [PATCH v2 10/18] tests/tcg: clean up output of memory system test Date: Mon, 16 Sep 2024 09:53:52 +0100 Message-Id: <20240916085400.1046925-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::132; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x132.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This is useful information when debugging memory issues so lets improve by: - include the ptr address for u8 fills (like the others) - indicate the number of operations for reads and writes - explicitly note when we are flushing - move the fill printf to after the reset Message-Id: <20240910140733.4007719-20-alex.bennee@linaro.org> Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Bennée --- tests/tcg/multiarch/system/memory.c | 47 ++++++++++++++++++----------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/memory.c index 6eb2eb16f7..8f2371975d 100644 --- a/tests/tcg/multiarch/system/memory.c +++ b/tests/tcg/multiarch/system/memory.c @@ -63,12 +63,14 @@ static void init_test_data_u8(int unused_offset) int i; (void)(unused_offset); - ml_printf("Filling test area with u8:"); + ml_printf("Filling test area with u8 (%p):", ptr); + for (i = 0; i < TEST_SIZE; i++) { *ptr++ = BYTE_NEXT(count); pdot(i); } - ml_printf("done\n"); + + ml_printf("done %d @ %p\n", i, ptr); } /* @@ -94,7 +96,7 @@ static void init_test_data_s8(bool neg_first) *ptr++ = get_byte(i, !neg_first); pdot(i); } - ml_printf("done\n"); + ml_printf("done %d @ %p\n", i * 2, ptr); } /* @@ -105,9 +107,18 @@ static void reset_start_data(int offset) { uint32_t *ptr = (uint32_t *) &test_data[0]; int i; + + if (!offset) { + return; + } + + ml_printf("Flushing %d bytes from %p: ", offset, ptr); + for (i = 0; i < offset; i++) { *ptr++ = 0; } + + ml_printf("done %d @ %p\n", i, ptr); } static void init_test_data_u16(int offset) @@ -117,17 +128,17 @@ static void init_test_data_u16(int offset) const int max = (TEST_SIZE - offset) / sizeof(word); int i; - ml_printf("Filling test area with u16 (offset %d, %p):", offset, ptr); - reset_start_data(offset); + ml_printf("Filling test area with u16 (offset %d, %p):", offset, ptr); + for (i = 0; i < max; i++) { uint16_t low = BYTE_NEXT(count), high = BYTE_NEXT(count); word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0); *ptr++ = word; pdot(i); } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); } static void init_test_data_u32(int offset) @@ -137,10 +148,10 @@ static void init_test_data_u32(int offset) const int max = (TEST_SIZE - offset) / sizeof(word); int i; - ml_printf("Filling test area with u32 (offset %d, %p):", offset, ptr); - reset_start_data(offset); + ml_printf("Filling test area with u32 (offset %d, %p):", offset, ptr); + for (i = 0; i < max; i++) { uint32_t b4 = BYTE_NEXT(count), b3 = BYTE_NEXT(count); uint32_t b2 = BYTE_NEXT(count), b1 = BYTE_NEXT(count); @@ -149,7 +160,7 @@ static void init_test_data_u32(int offset) *ptr++ = word; pdot(i); } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); } static void init_test_data_u64(int offset) @@ -159,10 +170,10 @@ static void init_test_data_u64(int offset) const int max = (TEST_SIZE - offset) / sizeof(word); int i; - ml_printf("Filling test area with u64 (offset %d, %p):", offset, ptr); - reset_start_data(offset); + ml_printf("Filling test area with u64 (offset %d, %p):", offset, ptr); + for (i = 0; i < max; i++) { uint64_t b8 = BYTE_NEXT(count), b7 = BYTE_NEXT(count); uint64_t b6 = BYTE_NEXT(count), b5 = BYTE_NEXT(count); @@ -174,7 +185,7 @@ static void init_test_data_u64(int offset) *ptr++ = word; pdot(i); } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); } static bool read_test_data_u16(int offset) @@ -198,7 +209,7 @@ static bool read_test_data_u16(int offset) } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } @@ -239,7 +250,7 @@ static bool read_test_data_u32(int offset) pdot(i); } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } @@ -293,7 +304,7 @@ static bool read_test_data_u64(int offset) pdot(i); } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } @@ -365,7 +376,7 @@ static bool read_test_data_s8(int offset, bool neg_first) return false; } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i * 2, ptr); return true; } @@ -398,7 +409,7 @@ static bool read_test_data_s16(int offset, bool neg_first) return false; } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } @@ -431,7 +442,7 @@ static bool read_test_data_s32(int offset, bool neg_first) return false; } } - ml_printf("done @ %p\n", ptr); + ml_printf("done %d @ %p\n", i, ptr); return true; } From patchwork Mon Sep 16 08:53:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828993 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681790wrb; Mon, 16 Sep 2024 01:56:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVL4JRnX8Y77r4n2EBzyfji/ph/7BZAtTYPOOLCJaVLgrrcmq0PiWaTetcIpk5BHYLs+eGMlA==@linaro.org X-Google-Smtp-Source: AGHT+IGWFLOnB0haidxIfNm/4999r7cRhxYwC2LlYIqi3BnCOLmVHct5gPC40dVIkkZk2VD8xHb+ X-Received: by 2002:a05:6214:5549:b0:6c5:8601:fdf7 with SMTP id 6a1803df08f44-6c58601ffd4mr143708046d6.41.1726477016001; Mon, 16 Sep 2024 01:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726477015; cv=none; d=google.com; s=arc-20240605; b=iuTxJp70tV+N5mjPLEWu9bZbxIGpVE88AQFRwcfKlgMnUs3BK/E9OfHrsGlrAgdqXa bm26HbdA70GLqN6kucPkRqchn5rmWgCRd2v7vSsYd1fDP5dIcoda41x9N+x0EQDgwQmx Bvp0rBu1kcPtNGOCLHrpX6Ww7Dh2luG/ibCM5hhNNW6mU4xsw2mBIx23DNVQuR2ZR52h Zg/4PpoAzCXBHb+jkHsj59XqC4G8u9sPBs3jBgFSTIeYbtfeQjFZ1MfiR2kqdAol92DR HcPw/4R9s4EdNnaI3d00JbZ98H+vj/ilM1fGCW8Qu9Xtu1cSfSJv1yyBHKzHOJCCEvai x4EQ== 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=4Wv8Q736t11KQJ7N/ppo9YJRYi/AHu9klf968DMJMmk=; fh=ATDHygEnrhDZDytw2YSa+GgRs9jfnpjrC7XifhYWFyU=; b=efXqX/alfcIjHasLMXt3Je0btwM+TiMs/MEemlhPfOrhOx3bKvIt+awQ0HAx0Q9LQk yhWdz1MKBvn/kQEsjMHKUhn7ckZcLUM2aGbpdCy3B5cTFIjCU25brAKu0Wv8D+Zm7J95 L5CSIHb33+5CUkP5KGPYl0xpZlgc1/r/KH1dG7pkjTEeoGdfU7AOUTqMWM2tOoS6wt7R AKg8U+kN4fnGWySMlIc8ClRUnwJjkzXsf/U86vQNjaFAiupC6pxKg2reWiaSVWUTtX20 kYk9+7rfhce8ieqmFB/vSKwPtOVroGQ3FcQ1lWkYIS1Bp9yF98TQQq/LRytwtVLQksoV 2Yrw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xh4MlOJA; 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-6c58c6210e3si52649066d6.95.2024.09.16.01.56.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:56:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xh4MlOJA; 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 1sq7VZ-0001rp-Sz; Mon, 16 Sep 2024 04:54: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 1sq7VK-00010w-2K for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:44 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Us-0005EH-FV for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:41 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-42cbc22e1c4so23832355e9.2 for ; Mon, 16 Sep 2024 01:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476852; x=1727081652; 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=4Wv8Q736t11KQJ7N/ppo9YJRYi/AHu9klf968DMJMmk=; b=Xh4MlOJAHndo67/P7Ljlh3F/xRGgdZDfA1iEG8k/DSPKtXAp90h44T9BvILdtVquYc iUJdm6dUF7Yamoq8U1BrQBdSC08d2zzA24wO+TgdOG+HHmnXH3/pqDVN5xznkNTOQXFP tUOirf/qSYMXyuD+RrC92aaK1v7kPAp1hGeSrggeyIx4jOgOm2e/JABB67O4nbimDDUz FR80uuMHDgr0tR5ZzWXN9UktSZ9cZ9x0ATTbyEvqZ7afX7P4E3QjS6oMVr6YDYk09/+T CWVgC4M7KuKDuO7L3ISxlgb+SYmaXQYyqvcrfyUsxAJ361hxRasvUi2tp9R3cq1HkfpS R2Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476852; x=1727081652; 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=4Wv8Q736t11KQJ7N/ppo9YJRYi/AHu9klf968DMJMmk=; b=mP52lh+zcGEHLBjR0I5bC/UQtK9mbk+1SNhQZ5klfAmHArkJ3VkK0SD0N5GRFQHJjq ra8IdhuME2I3LqOAnrLqf8fUWIFSejm6K4CbldTxAK7y/0+KMCkycF/D/MTBe0rsBKHL XV6f/NHkunZ7LCxqoCaQCbWcB6cgYsD8LNCrUk9brcr52T53MZ9omeUAVVdXGqFFnEDq lWCl55HClCffGIO3hm4FKZjNFiX1Q+EuXiSyisRmIfRBazs9P8pMB27v+NVQaHr/868I O2MMEonQcCsU1TGXvDvMA9I77pogCHJbQfrTK8YUkD0mZhDL/ijuwVZjyuGiaT18Mh10 bfWQ== X-Gm-Message-State: AOJu0YwysIiyxvuma1p1BpUu4EXES9TlZS7Z8y2FKFEOiLQdowKppRVc Yt5gaXGK/Il9M7eUBPNAaCFFAZgDt142wHlNWnDuywUnep6uGQSPuIkktI+hNJ4= X-Received: by 2002:a05:6000:1546:b0:374:b5af:710c with SMTP id ffacd0b85a97d-378d61f0d6cmr6976677f8f.26.1726476852125; Mon, 16 Sep 2024 01:54:12 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42da22d8212sm70383055e9.14.2024.09.16.01.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:07 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 599BA5FC6C; Mon, 16 Sep 2024 09:54:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier Subject: [PATCH v2 11/18] tests/tcg: only read/write 64 bit words on 64 bit systems Date: Mon, 16 Sep 2024 09:53:53 +0100 Message-Id: <20240916085400.1046925-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.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_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org While the compilers will generally happily synthesise a 64 bit value for you on 32 bit systems it doesn't exercise anything on QEMU. It also makes it hard to accurately compare the accesses to test_data when instrumenting. Message-Id: <20240910140733.4007719-21-alex.bennee@linaro.org> Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Bennée --- v2 - >= test of __SIZEOF_POINTER__ --- tests/tcg/multiarch/system/memory.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/memory.c index 8f2371975d..28080767b2 100644 --- a/tests/tcg/multiarch/system/memory.c +++ b/tests/tcg/multiarch/system/memory.c @@ -163,6 +163,7 @@ static void init_test_data_u32(int offset) ml_printf("done %d @ %p\n", i, ptr); } +#if __SIZEOF_POINTER__ >= 8 static void init_test_data_u64(int offset) { uint8_t count = 0; @@ -187,6 +188,7 @@ static void init_test_data_u64(int offset) } ml_printf("done %d @ %p\n", i, ptr); } +#endif static bool read_test_data_u16(int offset) { @@ -254,6 +256,7 @@ static bool read_test_data_u32(int offset) return true; } +#if __SIZEOF_POINTER__ >= 8 static bool read_test_data_u64(int offset) { uint64_t word, *ptr = (uint64_t *)&test_data[offset]; @@ -307,11 +310,16 @@ static bool read_test_data_u64(int offset) ml_printf("done %d @ %p\n", i, ptr); return true; } +#endif /* Read the test data and verify at various offsets */ -read_ufn read_ufns[] = { read_test_data_u16, - read_test_data_u32, - read_test_data_u64 }; +read_ufn read_ufns[] = { + read_test_data_u16, + read_test_data_u32, +#if __SIZEOF_POINTER__ >= 8 + read_test_data_u64 +#endif +}; bool do_unsigned_reads(int start_off) { @@ -476,10 +484,14 @@ bool do_signed_reads(bool neg_first) return ok; } -init_ufn init_ufns[] = { init_test_data_u8, - init_test_data_u16, - init_test_data_u32, - init_test_data_u64 }; +init_ufn init_ufns[] = { + init_test_data_u8, + init_test_data_u16, + init_test_data_u32, +#if __SIZEOF_POINTER__ >= 8 + init_test_data_u64 +#endif +}; int main(void) { From patchwork Mon Sep 16 08:53:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828991 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681736wrb; Mon, 16 Sep 2024 01:56:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUcqscisOZR2ipM0Vwm/TrwT6oYluxlrpP/V8jvKdGXYdvdFrTouG6rCwKZMNQ9cgdaZhABGw==@linaro.org X-Google-Smtp-Source: AGHT+IGfBrJYRuEGoupTP7gKWM7lv8JX2pcfyvIuVJ0hssC7tWfJWmF1ju7sTBcIqhc5INFzP8cz X-Received: by 2002:a05:6214:328f:b0:6c3:6b35:ac73 with SMTP id 6a1803df08f44-6c573ace26bmr212544476d6.11.1726477001178; Mon, 16 Sep 2024 01:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726477001; cv=none; d=google.com; s=arc-20240605; b=ZLLuIbGoEA67Mh/7OBOCV0pteOk4on0XfiqUexOg+wQs89P8pQHkUbt12M0uNKDHhT 8CZtMGOgxNc5w4Po7r5bx2VDY3X4SR/AdoZmYxcU9PdyqtflUr5zGET1oyBuiiMOmopp YO8ormms2o569Hix3rxL9+Ru6Z/vxrD541WPEPuzv0dM2qL57HbwYNMaSkJta4kl01RL Vq0lws3KSCBkUIte1K2sRjskMsn6F8UOD03TPrLA/6806OingkB40ZZoIWNWr/9AgKBI nAJZ/NQmOq3knnvh09rHzuwvHdI09FSLxoB/LzOa6s1kDWhGquBWUmvDwdvOJTHCAQ3S TG/Q== 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=aXyb7NcpmUG1NyUq2Ba7XIovKN57PGi0mUZtpk0zTz0=; fh=ATDHygEnrhDZDytw2YSa+GgRs9jfnpjrC7XifhYWFyU=; b=GY8ZhLjZ1V7nzz3GeeJM1XzIUzq8t76ItFjEdo+MnyrKh7OZL+4WqlR2AUDGzVMvEt FgawQuR+AyWxuAxU0ZQlWZGmIztwXdFrUaARZSJzDIz4/4XFDGOiQNffMpNOiuopoAZv 2XeuYj+E43h8EFCY+HLNJBZ5a377urjTDzVT/kRmN+tEiUesOcp90yokm2oBC2yYY4l5 0r9lDuAj5BKV4Dl81ChvXssvGXKv8EdupU8Dbk8rm9FYAmTOQD3dZTs3N0Wr/G1O+A/X xObxUKRX7ejAE00JL+ubEZVr4Ix8u9JLu3BnChzmGM203RPioYJfmn+jgocaUuMC5QhG F8hg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HOuXcTTu; 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-6c58c620f60si53846926d6.23.2024.09.16.01.56.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:56:41 -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=HOuXcTTu; 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 1sq7VX-0001g9-C5; Mon, 16 Sep 2024 04:54:55 -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 1sq7V9-0000b4-Mc for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:32 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Us-0005EP-Fj for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:31 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42cbface8d6so39655245e9.3 for ; Mon, 16 Sep 2024 01:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476853; x=1727081653; 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=aXyb7NcpmUG1NyUq2Ba7XIovKN57PGi0mUZtpk0zTz0=; b=HOuXcTTuJVilcBBtYm32nGrknUj5JWYdDgjcbs1684MuTX//mgozLWCvRNw1Zg0U0J SOzpqUxkfJnsy/Og3M3LvZCIXnhNCD2xS8N67o+Y/GtvGrP3t15bHIZMPkC7gsNil1tQ NYqz3JJfydsjVMNwaWUVVUEsbFI/h3UH8Ux0gn8LIt1h1SwEDnrxi5PmFqKkRLQigXF6 2zPl6Q1bKVS+bGL2yBURQxwUVWeBH7pEUCgbdlgvgxDqxUwAqDHT6DAksPyjGdq0B1xK 4anrlThj4cxr8jmiow8iYwAW4c7tO4PK6gokGRy/mDf1yFZtpxamm9Rm75IRz/GeR9u6 cE2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476853; x=1727081653; 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=aXyb7NcpmUG1NyUq2Ba7XIovKN57PGi0mUZtpk0zTz0=; b=RzxZKEdjHpZdr4WGVMSFnN8hJN2rCgC78tjMXvG4TMcX4MGzlq9gzFQrMxFfnjsqA4 Bci4MXr/V6KDSNUb7oS4V8okL7OSnAwK/NC1qhukzUl4waf3fXpaYJ/KeRkoZk43Ja67 nan2BCFKdqAH9qvA2CFh9zEmyk36eDyVT0Y9XVdgFTK2xtVzndzsGWm90SoXf9U4sTAj mOVLo70VvORkzz6QKPAEuJM4pbv7W5TnxliI8FRhAefhgA2SCwl1TEUnrL6iHSbWSpHS 6ClC74BD7iScDfys0cZhlcOYSICHVYZfcVst6S7bpuTnl6XQSo6D3LqI+CDWnRHk+268 KDhw== X-Gm-Message-State: AOJu0YxEBLLEMiki7fDSMHFlCVxFGmx+dSRzVBIWTJ16/zVGSwW9Dc3G TxP9byv7Md7sQ/aCTBiZhDCkI7VaKsoA6gtjBAILVH4PourKtsyKubSCmYih5Xc= X-Received: by 2002:a05:600c:1d1b:b0:42c:b555:43dd with SMTP id 5b1f17b1804b1-42d9070a3f2mr112008505e9.3.1726476852466; Mon, 16 Sep 2024 01:54:12 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e72e49bfsm6609974f8f.21.2024.09.16.01.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:09 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 6E7BD5FC7F; Mon, 16 Sep 2024 09:54:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier Subject: [PATCH v2 12/18] tests/tcg: ensure s390x-softmmu output redirected Date: Mon, 16 Sep 2024 09:53:54 +0100 Message-Id: <20240916085400.1046925-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The multiarch system tests output serial data which should be redirected to the "output" chardev rather than echoed to the console. Comment the use of EXTFLAGS variable while we are at it. Signed-off-by: Alex Bennée Acked-by: Ilya Leoshkevich --- v2 - don't remove EXTFLAGS, add comment --- tests/tcg/s390x/Makefile.softmmu-target | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/tcg/s390x/Makefile.softmmu-target b/tests/tcg/s390x/Makefile.softmmu-target index f60f94b090..be242ba8f1 100644 --- a/tests/tcg/s390x/Makefile.softmmu-target +++ b/tests/tcg/s390x/Makefile.softmmu-target @@ -1,6 +1,7 @@ S390X_SRC=$(SRC_PATH)/tests/tcg/s390x VPATH+=$(S390X_SRC) -QEMU_OPTS+=-action panic=exit-failure -nographic $(EXTFLAGS) -kernel +# EXTFLAGS can be passed by the user, e.g. to override the --accel +QEMU_OPTS+=-action panic=exit-failure -nographic -serial chardev:output $(EXTFLAGS) -kernel LINK_SCRIPT=$(S390X_SRC)/softmmu.ld CFLAGS+=-ggdb -O0 LDFLAGS=-nostdlib -static From patchwork Mon Sep 16 08:53:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828987 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681508wrb; Mon, 16 Sep 2024 01:55:50 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUbjbmYGZ0l20BHLFBH/Ny8eofb0gYMTJYZvgi7J4BSO3jGNqdjscb11TWQVXebkBNta/Zcsw==@linaro.org X-Google-Smtp-Source: AGHT+IGqtf+Xq9vDuj92n5F6wRLTxl9IWNW2lXkkU2RQkISrrwQJumlF9V/LjaFBjuRMEy68vDLu X-Received: by 2002:a05:6214:4387:b0:6c5:5094:e02f with SMTP id 6a1803df08f44-6c5736c8e61mr285282876d6.40.1726476950709; Mon, 16 Sep 2024 01:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726476950; cv=none; d=google.com; s=arc-20240605; b=C0k3MscSMhUeHdE3JS85qDNf+W/FSMIdWhYhhNhSn1zIO76LbvPesTRx8vHR0/+rGt 6vm8Nsmo9X3a7sTu5CojLGhYWs4RJrcEaq1+sYVFlc8FQcOh1mOkHgZZ2FVE+c58giK7 dlg33gGDGTcGWF427jVuj13kdjOyU8yBg22u7Y2n1t48VOc/AMGiCb6S0tm0ZMEv60e7 xtq+rEPMscnbs5eeVuGxW4wlRDR53ETuTCMx0S4YPksATaHLCZ8rYF+AqY6hzCU5lKNT GQ9wp+GsdptYNSDiC1EwgkkF5Fr9c4iQfPZtfTypv15IfwZxEdPtMY6U2MonU72dVdiq Z2sQ== 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=XI2ZB7ht+jWUnsopVYut1HBH2DcGJZdW0/fpt5ErYg0=; fh=ATDHygEnrhDZDytw2YSa+GgRs9jfnpjrC7XifhYWFyU=; b=gEs7/HGGafUSrfZ/AY0H53VVMRIU2l/eavo0Q4t0qhA+NLzozNsiilySjFW6eMJcRA W7DwnzyVmAzV9z3cHgnDIZSSXBQjD6qzM/nC2mXcMCbh35UkuFsPP4/syXj/Nz4eEYjR 7vdRC+lHfH74vXNZ/gloQIK/GvWv1+bxOJ8p2ni4uPMWuN/zgEVUL0j4Gy1t+pEkUw4V 9vwHp0o6nZ9DC4ApWRZ+cgbkrIQgXKMfT6ve5o+FP3mj4w/PFMvhtSv24mzEUL4PzDI6 CHyl+58djOMCOFKUdkgeYZ3OXfo+ERGOkzQNIShO2DCpyobrC+KFQGzGPGUmtO5jAuJN ioiw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vB2t9Qkv; 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-6c58c7a7a72si52579896d6.344.2024.09.16.01.55.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:55:50 -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=vB2t9Qkv; 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 1sq7Va-0001td-Bs; Mon, 16 Sep 2024 04:54:58 -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 1sq7VC-0000mO-Kg for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:35 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Ut-0005Eb-K2 for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:34 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4280ca0791bso41106305e9.1 for ; Mon, 16 Sep 2024 01:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476853; x=1727081653; 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=XI2ZB7ht+jWUnsopVYut1HBH2DcGJZdW0/fpt5ErYg0=; b=vB2t9Qkvtwpy0q3LuPEZ7L+Ikzog8y55678csKbi2t/WhAIEfaqolbNuKJMNxgZXi2 zY8obhVLEun7/IjmHg9QlLWSBrthhVfBgk6ZKxDm7+jUYtW81A5eqPjJIuLMOlBXrxSP X2hA2DeuYWeKIUbUQHQBTfFAYobU27BWTRUB9gn06EbpvypjognhM8tAg11t5DdvVpU5 b4E2SNwIzs77JpRJp2JDCvmTWH4KHmsIq3aQLTTR3ctZZwlzYiOX3C1CRQ+zrQnQy3vT lXVRwHsn82REi5McaNLE/unUykdFj5RJZdKf3fEJQeU5WH5ieQncdAFSgiyZcKGxymQZ oweQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476853; x=1727081653; 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=XI2ZB7ht+jWUnsopVYut1HBH2DcGJZdW0/fpt5ErYg0=; b=UtvkBDAgczd2yxGfkcT7s2F1fmd6175mfNNg+J8vmWtRv6NaCoOPy9Ed4s/J7BRe5P eOPqtl7zjXarx53s4xCPjaQotrDn5lZz3pu1g2r8hB5bykTSlS1uPiaa8vEtBLo8N0L4 E6m3gl/QuTahUIHmPwL+sLuQvjgf6A736q33S1IyiGHaI9Kur8/GqE0k/1caQQXYO+5C hY6iKgVRqheixFB5RxoiSG0kqdH2L0cQcTeGWkWiCN+HndRAqH13g46nuM54faGJDBn9 Xv4nNKrgdW5J/YE+yQTkrUlCsbZKS7bOit0XdGKY/AnNfWA1KgIqVlzzcDDM41zJYlV7 T9Ew== X-Gm-Message-State: AOJu0YzEWO1Rhr/g8ZcZFt1EKtuv3x8uyvpRuxGu6xT+rbmt+swDw2F5 sndvCRSNpXLeRdGYWmPsOeoGtXEqgzWiyEKQGSGG93662b+EjiW7pDI3OvYEE+8= X-Received: by 2002:a05:600c:1d1b:b0:42c:cdcf:2fef with SMTP id 5b1f17b1804b1-42cdb540484mr117143505e9.15.1726476852816; Mon, 16 Sep 2024 01:54:12 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e780da68sm6602754f8f.111.2024.09.16.01.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:09 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 8C0A55FC95; Mon, 16 Sep 2024 09:54:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier Subject: [PATCH v2 13/18] tests/tcg: add a system test to check memory instrumentation Date: Mon, 16 Sep 2024 09:53:55 +0100 Message-Id: <20240916085400.1046925-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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 At first I thought I could compile the user-mode test for system mode however we already have a fairly comprehensive test case for system mode in "memory" so lets use that. As tracking every access will quickly build up with "print-access" we add a new mode to track groups of reads and writes to regions. Because the test_data is 16k aligned we can be sure all accesses to it are ones we can count. First we extend the test to report where the test_data region is. Then we expand the pdot() function to track the total number of reads and writes to the region. We have to add some addition pdot() calls to take into account multiple reads/writes in the test loops. Finally we add a python script to integrate the data from the plugin and the output of the test and validate they both agree on the total counts. As some boot codes clear the bss we also add a flag to add a regions worth of writes to the expected total. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier --- v2 - aggressively align test_data on "region size" - sort the regions in the final report - ensure alpha-softmmu uses byte access when it can v3 - fix thinko while iterating through the regions - fix the LE/BE storage of values in the mirror section - add --bss-cleared to script - clean-up some long lines in the script --- tests/tcg/multiarch/system/memory.c | 50 +++-- tests/tcg/plugins/mem.c | 181 +++++++++++++++++- tests/tcg/alpha/Makefile.softmmu-target | 2 +- .../multiarch/system/Makefile.softmmu-target | 6 + .../system/validate-memory-counts.py | 129 +++++++++++++ tests/tcg/s390x/Makefile.softmmu-target | 5 + 6 files changed, 354 insertions(+), 19 deletions(-) create mode 100755 tests/tcg/multiarch/system/validate-memory-counts.py diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/memory.c index 28080767b2..65a6038a24 100644 --- a/tests/tcg/multiarch/system/memory.c +++ b/tests/tcg/multiarch/system/memory.c @@ -14,26 +14,35 @@ #include #include +#include #include #ifndef CHECK_UNALIGNED # error "Target does not specify CHECK_UNALIGNED" #endif +uint32_t test_read_count; +uint32_t test_write_count; + #define MEM_PAGE_SIZE 4096 /* nominal 4k "pages" */ #define TEST_SIZE (MEM_PAGE_SIZE * 4) /* 4 pages */ #define ARRAY_SIZE(x) ((sizeof(x) / sizeof((x)[0]))) -__attribute__((aligned(MEM_PAGE_SIZE))) +__attribute__((aligned(TEST_SIZE))) static uint8_t test_data[TEST_SIZE]; typedef void (*init_ufn) (int offset); typedef bool (*read_ufn) (int offset); typedef bool (*read_sfn) (int offset, bool nf); -static void pdot(int count) +static void pdot(int count, bool write) { + if (write) { + test_write_count++; + } else { + test_read_count++; + } if (count % 128 == 0) { ml_printf("."); } @@ -67,7 +76,7 @@ static void init_test_data_u8(int unused_offset) for (i = 0; i < TEST_SIZE; i++) { *ptr++ = BYTE_NEXT(count); - pdot(i); + pdot(i, true); } ml_printf("done %d @ %p\n", i, ptr); @@ -93,8 +102,9 @@ static void init_test_data_s8(bool neg_first) neg_first ? "neg first" : "pos first"); for (i = 0; i < TEST_SIZE / 2; i++) { *ptr++ = get_byte(i, neg_first); + pdot(i, true); *ptr++ = get_byte(i, !neg_first); - pdot(i); + pdot(i, true); } ml_printf("done %d @ %p\n", i * 2, ptr); } @@ -116,6 +126,7 @@ static void reset_start_data(int offset) for (i = 0; i < offset; i++) { *ptr++ = 0; + pdot(i, true); } ml_printf("done %d @ %p\n", i, ptr); @@ -136,7 +147,7 @@ static void init_test_data_u16(int offset) uint16_t low = BYTE_NEXT(count), high = BYTE_NEXT(count); word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0); *ptr++ = word; - pdot(i); + pdot(i, true); } ml_printf("done %d @ %p\n", i, ptr); } @@ -158,7 +169,7 @@ static void init_test_data_u32(int offset) word = BYTE_SHIFT(b1, 3) | BYTE_SHIFT(b2, 2) | BYTE_SHIFT(b3, 1) | BYTE_SHIFT(b4, 0); *ptr++ = word; - pdot(i); + pdot(i, true); } ml_printf("done %d @ %p\n", i, ptr); } @@ -184,7 +195,7 @@ static void init_test_data_u64(int offset) BYTE_SHIFT(b4, 4) | BYTE_SHIFT(b5, 3) | BYTE_SHIFT(b6, 2) | BYTE_SHIFT(b7, 1) | BYTE_SHIFT(b8, 0); *ptr++ = word; - pdot(i); + pdot(i, true); } ml_printf("done %d @ %p\n", i, ptr); } @@ -207,7 +218,7 @@ static bool read_test_data_u16(int offset) ml_printf("Error %d < %d\n", high, low); return false; } else { - pdot(i); + pdot(i, false); } } @@ -249,7 +260,7 @@ static bool read_test_data_u32(int offset) ml_printf("Error %d, %d, %d, %d", b1, b2, b3, b4); return false; } else { - pdot(i); + pdot(i, false); } } ml_printf("done %d @ %p\n", i, ptr); @@ -304,7 +315,7 @@ static bool read_test_data_u64(int offset) b1, b2, b3, b4, b5, b6, b7, b8); return false; } else { - pdot(i); + pdot(i, false); } } ml_printf("done %d @ %p\n", i, ptr); @@ -376,9 +387,11 @@ static bool read_test_data_s8(int offset, bool neg_first) second = *ptr++; if (neg_first && first < 0 && second > 0) { - pdot(i); + pdot(i, false); + pdot(i, false); } else if (!neg_first && first > 0 && second < 0) { - pdot(i); + pdot(i, false); + pdot(i, false); } else { ml_printf("Error %d %c %d\n", first, neg_first ? '<' : '>', second); return false; @@ -409,9 +422,9 @@ static bool read_test_data_s16(int offset, bool neg_first) int32_t data = *ptr++; if (neg_first && data < 0) { - pdot(i); + pdot(i, false); } else if (!neg_first && data > 0) { - pdot(i); + pdot(i, false); } else { ml_printf("Error %d %c 0\n", data, neg_first ? '<' : '>'); return false; @@ -442,9 +455,9 @@ static bool read_test_data_s32(int offset, bool neg_first) int64_t data = *ptr++; if (neg_first && data < 0) { - pdot(i); + pdot(i, false); } else if (!neg_first && data > 0) { - pdot(i); + pdot(i, false); } else { ml_printf("Error %d %c 0\n", data, neg_first ? '<' : '>'); return false; @@ -498,6 +511,9 @@ int main(void) int i; bool ok = true; + ml_printf("Test data start: 0x%"PRIxPTR"\n", &test_data[0]); + ml_printf("Test data end: 0x%"PRIxPTR"\n", &test_data[TEST_SIZE]); + /* Run through the unsigned tests first */ for (i = 0; i < ARRAY_SIZE(init_ufns) && ok; i++) { ok = do_unsigned_test(init_ufns[i]); @@ -513,6 +529,8 @@ int main(void) ok = do_signed_reads(true); } + ml_printf("Test data read: %"PRId32"\n", test_read_count); + ml_printf("Test data write: %"PRId32"\n", test_write_count); ml_printf("Test complete: %s\n", ok ? "PASSED" : "FAILED"); return ok ? 0 : -1; } diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c index 086e6f5bdf..c28eedbed0 100644 --- a/tests/tcg/plugins/mem.c +++ b/tests/tcg/plugins/mem.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -26,13 +27,46 @@ typedef struct { const char *sym; } InsnInfo; +/* + * For the "memory" system test we need to track accesses to + * individual regions. We mirror the data written to the region and + * then check when it is read that it matches up. + * + * We do this as regions rather than pages to save on complications + * with page crossing and the fact the test only cares about the + * test_data region. + */ +static uint64_t region_size = 4096 * 4; +static uint64_t region_mask; + +typedef struct { + uint64_t region_address; + uint64_t reads; + uint64_t writes; + uint8_t *data; + bool seen_all; /* Did we see every write and read with correct values? */ +} RegionInfo; + static struct qemu_plugin_scoreboard *counts; static qemu_plugin_u64 mem_count; static qemu_plugin_u64 io_count; -static bool do_inline, do_callback, do_print_accesses; +static bool do_inline, do_callback, do_print_accesses, do_region_summary; static bool do_haddr; static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW; + +static GMutex lock; +static GHashTable *regions; + +static gint addr_order(gconstpointer a, gconstpointer b) +{ + RegionInfo *na = (RegionInfo *) a; + RegionInfo *nb = (RegionInfo *) b; + + return na->region_address > nb->region_address ? 1 : -1; +} + + static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) out = g_string_new(""); @@ -46,9 +80,132 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) qemu_plugin_u64_sum(io_count)); } qemu_plugin_outs(out->str); + + + if (do_region_summary) { + GList *counts = g_hash_table_get_values(regions); + + counts = g_list_sort(counts, addr_order); + + g_string_printf(out, "Region Base, Reads, Writes, Seen all\n"); + + if (counts && g_list_next(counts)) { + for (/* counts */; counts; counts = counts->next) { + RegionInfo *ri = (RegionInfo *) counts->data; + + g_string_append_printf(out, + "0x%016"PRIx64", " + "%"PRId64", %"PRId64", %s\n", + ri->region_address, + ri->reads, + ri->writes, + ri->seen_all ? "true" : "false"); + } + } + qemu_plugin_outs(out->str); + } + qemu_plugin_scoreboard_free(counts); } +/* + * Update the region tracking info for the access. We split up accesses + * that span regions even though the plugin infrastructure will deliver + * it as a single access. + */ +static void update_region_info(uint64_t region, uint64_t offset, + qemu_plugin_meminfo_t meminfo, + qemu_plugin_mem_value value, + unsigned size) +{ + bool be = qemu_plugin_mem_is_big_endian(meminfo); + bool is_store = qemu_plugin_mem_is_store(meminfo); + RegionInfo *ri; + bool unseen_data = false; + + g_assert(offset + size <= region_size); + + g_mutex_lock(&lock); + ri = (RegionInfo *) g_hash_table_lookup(regions, GUINT_TO_POINTER(region)); + + if (!ri) { + ri = g_new0(RegionInfo, 1); + ri->region_address = region; + ri->data = g_malloc0(region_size); + ri->seen_all = true; + g_hash_table_insert(regions, GUINT_TO_POINTER(region), (gpointer) ri); + } + + if (is_store) { + ri->writes++; + } else { + ri->reads++; + } + + switch (value.type) { + case QEMU_PLUGIN_MEM_VALUE_U8: + if (is_store) { + ri->data[offset] = value.data.u8; + } else if (ri->data[offset] != value.data.u8) { + unseen_data = true; + } + break; + case QEMU_PLUGIN_MEM_VALUE_U16: + { + uint16_t *p = (uint16_t *) &ri->data[offset]; + uint16_t val = be ? htobe16(value.data.u16) : htole16(value.data.u16); + if (is_store) { + *p = val; + } else if (*p != val) { + unseen_data = true; + } + break; + } + case QEMU_PLUGIN_MEM_VALUE_U32: + { + uint32_t *p = (uint32_t *) &ri->data[offset]; + uint32_t val = be ? htobe32(value.data.u32) : htole32(value.data.u32); + if (is_store) { + *p = val; + } else if (*p != val) { + unseen_data = true; + } + break; + } + case QEMU_PLUGIN_MEM_VALUE_U64: + { + uint64_t *p = (uint64_t *) &ri->data[offset]; + uint64_t val = be ? htobe64(value.data.u64) : htole64(value.data.u64); + if (is_store) { + *p = val; + } else if (*p != val) { + unseen_data = true; + } + break; + } + case QEMU_PLUGIN_MEM_VALUE_U128: + /* non in test so skip */ + break; + default: + g_assert_not_reached(); + } + + /* + * This is expected for regions initialised by QEMU (.text etc) but we + * expect to see all data read and written to the test_data region + * of the memory test. + */ + if (unseen_data && ri->seen_all) { + g_autoptr(GString) error = g_string_new("Warning: "); + g_string_append_printf(error, "0x%016"PRIx64":%"PRId64" read an un-instrumented value\n", + region, offset); + qemu_plugin_outs(error->str); + ri->seen_all = false; + } + + g_mutex_unlock(&lock); +} + static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, uint64_t vaddr, void *udata) { @@ -63,6 +220,15 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, } else { qemu_plugin_u64_add(mem_count, cpu_index, 1); } + + if (do_region_summary) { + uint64_t region = vaddr & ~region_mask; + uint64_t offset = vaddr & region_mask; + qemu_plugin_mem_value value = qemu_plugin_mem_get_value(meminfo); + unsigned size = 1 << qemu_plugin_mem_size_shift(meminfo); + + update_region_info(region, offset, meminfo, value, size); + } } static void print_access(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, @@ -117,7 +283,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) QEMU_PLUGIN_INLINE_ADD_U64, mem_count, 1); } - if (do_callback) { + if (do_callback || do_region_summary) { qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem, QEMU_PLUGIN_CB_NO_REGS, rw, NULL); @@ -176,6 +342,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", opt); return -1; } + } else if (g_strcmp0(tokens[0], "region-summary") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &do_region_summary)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + return -1; + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; @@ -196,6 +368,11 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, qemu_plugin_outs(out->str); } + if (do_region_summary) { + region_mask = (region_size - 1); + regions = g_hash_table_new(NULL, g_direct_equal); + } + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); mem_count = qemu_plugin_scoreboard_u64_in_struct( counts, CPUCount, mem_count); diff --git a/tests/tcg/alpha/Makefile.softmmu-target b/tests/tcg/alpha/Makefile.softmmu-target index a0eca4d6ea..a944102a3c 100644 --- a/tests/tcg/alpha/Makefile.softmmu-target +++ b/tests/tcg/alpha/Makefile.softmmu-target @@ -28,7 +28,7 @@ LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc %: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS) $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) -memory: CFLAGS+=-DCHECK_UNALIGNED=0 +memory: CFLAGS+=-DCHECK_UNALIGNED=0 -mbwx # Running QEMU_OPTS+=-serial chardev:output -kernel diff --git a/tests/tcg/multiarch/system/Makefile.softmmu-target b/tests/tcg/multiarch/system/Makefile.softmmu-target index 32dc0f9830..07be001102 100644 --- a/tests/tcg/multiarch/system/Makefile.softmmu-target +++ b/tests/tcg/multiarch/system/Makefile.softmmu-target @@ -65,3 +65,9 @@ endif MULTIARCH_RUNS += run-gdbstub-memory run-gdbstub-interrupt \ run-gdbstub-untimely-packet run-gdbstub-registers + +# Test plugin memory access instrumentation +run-plugin-memory-with-libmem.so: \ + PLUGIN_ARGS=$(COMMA)region-summary=true +run-plugin-memory-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=$(MULTIARCH_SYSTEM_SRC)/validate-memory-counts.py $@.out diff --git a/tests/tcg/multiarch/system/validate-memory-counts.py b/tests/tcg/multiarch/system/validate-memory-counts.py new file mode 100755 index 0000000000..418862d5d3 --- /dev/null +++ b/tests/tcg/multiarch/system/validate-memory-counts.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python3 +# +# validate-memory-counts.py: check we instrumented memory properly +# +# This program takes two inputs: +# - the mem plugin output +# - the memory binary output +# +# Copyright (C) 2024 Linaro Ltd +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import sys +from argparse import ArgumentParser + +def extract_counts(path): + """ + Load the output from path and extract the lines containing: + + Test data start: 0x40214000 + Test data end: 0x40218001 + Test data read: 2522280 + Test data write: 262111 + + From the stream of data. Extract the values for use in the + validation function. + """ + start_address = None + end_address = None + read_count = 0 + write_count = 0 + with open(path, 'r') as f: + for line in f: + if line.startswith("Test data start:"): + start_address = int(line.split(':')[1].strip(), 16) + elif line.startswith("Test data end:"): + end_address = int(line.split(':')[1].strip(), 16) + elif line.startswith("Test data read:"): + read_count = int(line.split(':')[1].strip()) + elif line.startswith("Test data write:"): + write_count = int(line.split(':')[1].strip()) + return start_address, end_address, read_count, write_count + + +def parse_plugin_output(path, start, end): + """ + Load the plugin output from path in the form of: + + Region Base, Reads, Writes, Seen all + 0x0000000040004000, 31093, 0, false + 0x0000000040214000, 2522280, 278579, true + 0x0000000040000000, 137398, 0, false + 0x0000000040210000, 54727397, 33721956, false + + And extract the ranges that match test data start and end and + return the results. + """ + total_reads = 0 + total_writes = 0 + seen_all = False + + with open(path, 'r') as f: + next(f) # Skip the header + for line in f: + + if line.startswith("Region Base"): + continue + + parts = line.strip().split(', ') + if len(parts) != 4: + continue + + region_base = int(parts[0], 16) + reads = int(parts[1]) + writes = int(parts[2]) + + if start <= region_base < end: # Checking if within range + total_reads += reads + total_writes += writes + seen_all = parts[3] == "true" + + return total_reads, total_writes, seen_all + +def main() -> None: + """ + Process the arguments, injest the program and plugin out and + verify they match up and report if they do not. + """ + parser = ArgumentParser(description="Validate memory instrumentation") + parser.add_argument('test_output', + help="The output from the test itself") + parser.add_argument('plugin_output', + help="The output from memory plugin") + parser.add_argument('--bss-cleared', + action='store_true', + help='Assume bss was cleared (and adjusts counts).') + + args = parser.parse_args() + + # Extract counts from memory binary + start, end, exp_reads, exp_writes = extract_counts(args.test_output) + + # Some targets clear BSS before running but the test doesn't know + # that so we adjust it by the size of the test region. + if args.bss_cleared: + exp_writes += 16384 + + if start is None or end is None: + print("Failed to test_data boundaries from output.") + sys.exit(1) + + # Parse plugin output + preads, pwrites, seen_all = parse_plugin_output(args.plugin_output, start, end) + + if not seen_all: + print("Fail: didn't instrument all accesses to test_data.") + sys.exit(1) + + # Compare and report + if preads == exp_reads and pwrites == exp_writes: + sys.exit(0) + else: + print("Fail: The memory reads and writes count does not match.") + print(f"Expected Reads: {exp_reads}, Actual Reads: {preads}") + print(f"Expected Writes: {exp_writes}, Actual Writes: {pwrites}") + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/tests/tcg/s390x/Makefile.softmmu-target b/tests/tcg/s390x/Makefile.softmmu-target index be242ba8f1..3227903348 100644 --- a/tests/tcg/s390x/Makefile.softmmu-target +++ b/tests/tcg/s390x/Makefile.softmmu-target @@ -47,3 +47,8 @@ $(MULTIARCH_TESTS): $(S390X_MULTIARCH_RUNTIME_OBJS) $(MULTIARCH_TESTS): LDFLAGS += $(S390X_MULTIARCH_RUNTIME_OBJS) $(MULTIARCH_TESTS): CFLAGS += $(MINILIB_INC) memory: CFLAGS += -DCHECK_UNALIGNED=0 + +# s390x clears the BSS section so we need to account for that +run-plugin-memory-with-libmem.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=$(MULTIARCH_SYSTEM_SRC)/validate-memory-counts.py \ + --bss-cleared $@.out From patchwork Mon Sep 16 08:53:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828994 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681846wrb; Mon, 16 Sep 2024 01:57:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUQNQkM2+QJ2RVB5aagxq3UY4rOgjSkwUBi7QNNdSHUQfWMjs+t9aGfbRi7GyaMMd1fZTinqg==@linaro.org X-Google-Smtp-Source: AGHT+IHnqgZAD8bliSySytOtWLo6loC6HDAZ6/2DbwbMVss0OzXfd2204y+t6/XJRCZJHSm0QO23 X-Received: by 2002:a05:620a:4593:b0:7a9:db7d:11f8 with SMTP id af79cd13be357-7a9e5ee21bemr2631962785a.7.1726477026931; Mon, 16 Sep 2024 01:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726477026; cv=none; d=google.com; s=arc-20240605; b=N22pshawnLuqDw4zOq0GBmCgdrn067WIhP/vPjIiQxH/1JkzAwvR5kVRhXBy77MB21 S4OJhPWcahN+c95Mj4lexid4TYwz/wxrsmu4EN/I7GwY79y3KYfkPH+sWy7HYiSXik3O RJZmOsVzlq0RGfP5ddkm/5jq/lchSLAST3u/MwB8soEBMAnaMYkCECRKmkzZLXLawpw5 GWdqI0lohEn+B/EUYK/ii25YEsfB23qC/DCeoMxnyYfb1F6zm/Fj+kH5surZk6P1dwK3 lD1VhVvBaLEqXmQ7qYzDXzYKwVuTM3PLL/THF7bLbt3BbxDbCMIvlu9Krf34kGPONdl+ ydUQ== 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=2OJksstmsifZmCUPWtvTuS/7OYa4HHWDbSpalmz/esw=; fh=EUSMNgYjwj4GGVay3LBMQ2Gpqe70dd1O82wcFkfan2U=; b=clpwjDFKY9KwqrUv+YNKTNFzYYmyk2HKpPTLiROHdN05u4ZcARGaCqszgRPPm8q1lc pq5sAa1woC3lyWgbGyQiBrO6Ws3dpGZWW/mWxn0lo2Eq1p1geSBZUpMwJSDC0dnUFX8b 2nTWt6bpKjyZA6g/vEMmuRuwfHydluGNC4l7FflEuGjNsDSYPWN/b0XuE3mfIUlBYvUO xeX0OTRKUo/o5vQzLyFlZwcj0mluki32G/pGg8q38SdkK7+0YcTHEQJRYlKFBjxUb8kr gbSF2azUhmsomDoWH2inuOR8RFWTNskWQVXRK69mLgSgMSpk6uja4Pkzs8dMnvvJVSWR /LQA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MYMZz8df; 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-7ab3e97179bsi536146685a.29.2024.09.16.01.57.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:57:06 -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=MYMZz8df; 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 1sq7Ve-0002Cc-9f; Mon, 16 Sep 2024 04:55:02 -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 1sq7VG-00010N-Gk for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:42 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Uv-0005F1-IX for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:36 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-42cacabd2e0so35331715e9.3 for ; Mon, 16 Sep 2024 01:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476855; x=1727081655; 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=2OJksstmsifZmCUPWtvTuS/7OYa4HHWDbSpalmz/esw=; b=MYMZz8dfTHhx+zBGnP1Eo9BsA2oXgrI8uqfrr/7s5fod+WjeLcjn4FL1iwmnu+HekP O1zpQCNMKM/cPQz3x8+Xmul/R4OXY3kBQ4eu4lqZOSKnSPek/lAfEF/z6liTTuL9Jws6 vK72ctw78hL3rgT6vRs7JP60v+7sNel6wkEDWFhugZlXJPv1ZogM+j4poVWDy31dBEOp 73L8xgYURYbB5oFwfxd1OOY5ynDxzpxyLyv8TfY5wcYH15geHtgqV3FQCSXh79BLwn4h Pz5/Rm/kd+Wla+7IaGtKgbobk0k8HkB0Qhh5WZlWkgCjRK0rP1AAhABI4BoqjBYhcWrU mfpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476855; x=1727081655; 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=2OJksstmsifZmCUPWtvTuS/7OYa4HHWDbSpalmz/esw=; b=RsXjyzpz1axHdW1LeLcH9ARt6nbXHUsL4+9+s6xSSHFZrRfgbBq9I92q7Am+0w6wRx Qti4ptuhgiME68QI57HISsqw/6/YmN9gkLeVuE86JKZ+VImtmGY40YjVqSLK9ZA5fXgX Wzp4wgn8nX0xupa31LHACkOdTn2erwcogRb5+eoicKj5uBxDOWgst7vaZ249DcDW4oaW KqdoF2F884S1pbFqpV5iKbsemKFIdFi89ZWJDOaVfxpH+WazosWD5bTB0Y27zBrDLPK5 WYAFG4IsdpNbqQ2rMKibt2Yqh6jNHnBZ9o9tHBrMYtDEru1MRK95hNq+8KU0EnIGPOeC 8UPA== X-Gm-Message-State: AOJu0YzTiQaQoaFp19eQ+1GS3Jv2GEWHEM+VV+QYwNpzSyKXlb675YnZ eITflD04829bnrw1ScehUKxpGqJMTUR22MD2jqhWXaDaFpc27zvvo/xnUGn9ELk= X-Received: by 2002:a05:600c:468a:b0:42c:b309:8d18 with SMTP id 5b1f17b1804b1-42cdb53be54mr96726175e9.19.1726476854713; Mon, 16 Sep 2024 01:54:14 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42d9b15d5bcsm104745815e9.26.2024.09.16.01.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:09 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id A39BF5FCAE; Mon, 16 Sep 2024 09:54:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Elisha Hollander Subject: [PATCH v2 14/18] util/timer: avoid deadlock when shutting down Date: Mon, 16 Sep 2024 09:53:56 +0100 Message-Id: <20240916085400.1046925-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org When we shut down a guest we disable the timers. However this can cause deadlock if the guest has queued some async work that is trying to advance system time and spins forever trying to wind time forward. Pay attention to the return code and bail early if we can't wind time forward. Signed-off-by: Alex Bennée Reported-by: Elisha Hollander Reviewed-by: Pierrick Bouvier --- util/qemu-timer.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 213114be68..6b1533bc2a 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -685,10 +685,17 @@ int64_t qemu_clock_advance_virtual_time(int64_t dest) { int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); AioContext *aio_context; + int64_t deadline; + aio_context = qemu_get_aio_context(); - while (clock < dest) { - int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, + + deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, QEMU_TIMER_ATTR_ALL); + /* + * A deadline of < 0 indicates this timer is not enabled, so we + * won't get far trying to run it forward. + */ + while (deadline >= 0 && clock < dest) { int64_t warp = qemu_soonest_timeout(dest - clock, deadline); qemu_virtual_clock_set_ns(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + warp); @@ -696,6 +703,9 @@ int64_t qemu_clock_advance_virtual_time(int64_t dest) qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); timerlist_run_timers(aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL]); clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + + deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, + QEMU_TIMER_ATTR_ALL); } qemu_clock_notify(QEMU_CLOCK_VIRTUAL); From patchwork Mon Sep 16 08:53:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828998 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp684267wrb; Mon, 16 Sep 2024 02:03:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW+InP1OOoPuhl6wXZ0B77djlcyxboPVWky4O4JHbq3KnDWzco5pTcvaQr9aYtCnIhijsAGVA==@linaro.org X-Google-Smtp-Source: AGHT+IF1gXeyVO9eR+bo7mUztuV5zyodhQBDhFyUeN2vGfZww9Eq9ARXLouN5DyT8FdvFMutT8XF X-Received: by 2002:a05:622a:34f:b0:458:38d1:df31 with SMTP id d75a77b69052e-458603338edmr229375951cf.35.1726477412840; Mon, 16 Sep 2024 02:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726477412; cv=none; d=google.com; s=arc-20240605; b=EJ6cL3c+hJXuEybWYc59TaakDCv50tSLbk/e5HtTzfJJ41qQhIymcH+7YOFQuZTqUX BSOgJQ/qodtlIBRR4eykDmJKcOSEFCYblBpyXf5forxkfM73KGQt07p/Y4Hj1NL1bj7T av8fYIwZCIO/wZQxMti5exKisGXBbEWsfkW3iSbwp37wjTBMyex6/9taiojCp0OQRsdP uDn5LP61OPuEKCVPHkPrgd+wP4U+48Ycaz81omZcQwUazGoqRu/mwR9VaNQzyMp3GZXi erVurwgKUgTMhFpB3PqHc6iZ/Wn8y2zTZSqMVLGIsLFYz6+QP8q5SmT/VnfWD/+dEeOH Awiw== 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=aeKWF4400mkgzW6RNuwJ6RAXELhPq+3Dr2Xaak76GOQ=; fh=a7frfjY7MDqXjhHIQ2aUrbbijlFO4uvaCJFMAxqaKQo=; b=MUwlykCbaNIGcvuaSUDV9CRWC9ATmiNvE0FgN0hYhFb/czxKw3LSXQFiyV6/2J2KtC 2Zg56QhB0kjyFT61d6aH46ngHrpHj18t93fi2QakunEzuNV8ADh6XQ81NJ17j8Z/75PO EMHr90F3kbgHtv6zYBPHJBeU7BtIkUpD14isDDgdDe1Zh/McljHuN5ejfAOos70NPgR+ BlnAW/StcvzxkkPqEmWEth1fW1v/6c6ssqLt/GDxNXfCz4+YGpFHIwnqHu4kNNUBsppG acuJmdRirGWweOMq/H4N5dUdwK+t6XeriRnu0pi6F9My80BV6oDcaJ9Q8dtrAigCxk0K ghIQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jfm0o3ua; 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-459aaf16c17si52470321cf.427.2024.09.16.02.03.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 02:03:32 -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=jfm0o3ua; 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 1sq7dd-0008Vd-Lb; Mon, 16 Sep 2024 05:03:17 -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 1sq7dc-0008Ri-E1 for qemu-devel@nongnu.org; Mon, 16 Sep 2024 05:03:16 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7dZ-0006TN-HC for qemu-devel@nongnu.org; Mon, 16 Sep 2024 05:03:15 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-374ba74e9b6so2803488f8f.0 for ; Mon, 16 Sep 2024 02:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726477392; x=1727082192; 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=aeKWF4400mkgzW6RNuwJ6RAXELhPq+3Dr2Xaak76GOQ=; b=jfm0o3ua329vLQroc6npiW4oK4XmIAtX0eakOgv4z8JdG3vHoFeuG0FeKbjz8Xv1ZO 3HBXiuzSF8+bNSDMcdtazDyCGA0fHLHCDrmBNbx9AnH8Qj6z1/14qJcul0GUX8REAy/x mVdNQYtYJUgvnnn3xN0EAsD/V1RMRiIR/hKbEZeHxpuoP6mm0XrfUNlte3dbGUI7JRgH 1f30UpgKLaDzaJhXJkkaXscn9CIFWMFaTD5TGZJvV8z2xMjolZ/XRlyrwzup1MYEPOf1 SXi0QFta+H/QF9ltKlNFEzEa424sopMSejHrknsY64UZlsncNexZ3RnBE/dt1AOwOgCv YakA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726477392; x=1727082192; 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=aeKWF4400mkgzW6RNuwJ6RAXELhPq+3Dr2Xaak76GOQ=; b=GCTDZxHWlVF+m7L2Fi2QcQZsoOI4eThvptBU4vqbQHbjL9A78Uc//qJ/OoQBl48vwI j30ejE0N9p5TyEl2CQC9893AtScIipGB5YyfMmgDV/dX8txCUCoAQ64LLuejGaYpU8Nh wiNCg2MUZaxayVTAI1S5madAevrdbL42lkDt5Qk+od7Cip8G7DSUHsST5OA35sEt0oC1 x2Y3khlOgBYV5tOdC27NqN3jDw4/R5kn09cdcFhubBGtUOksyS3+K7P55U/FgXM2ZFWY pNJ8SXYJljAzxOm9iMsIbv06eE1rXh8WzoJt4EzMUxo/9bI6tZpyQUg91lHmNZJhue4f 4YgA== X-Gm-Message-State: AOJu0YzqzcMYsPBMRxug3Yt995XOaijGtTDsp4/8ukUrWckas71d7MD8 Wy40GUl4wz0M/Xymv2pT1Zaw9avlG1POmwMtc12jjyG6G6nTTcOZOHhdBvvIYEE= X-Received: by 2002:a05:6000:bd2:b0:374:c512:87ce with SMTP id ffacd0b85a97d-378d61f0beemr9107108f8f.30.1726477391525; Mon, 16 Sep 2024 02:03:11 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e78054absm6651151f8f.106.2024.09.16.02.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:03:11 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id BC3035F87D; Mon, 16 Sep 2024 09:54:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Akihiko Odaki , Yotaro Nada Subject: [PATCH v2 15/18] contrib/plugins: Add a plugin to generate basic block vectors Date: Mon, 16 Sep 2024 09:53:57 +0100 Message-Id: <20240916085400.1046925-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki SimPoint is a widely used tool to find the ideal microarchitecture simulation points so Valgrind[2] and Pin[3] support generating basic block vectors for use with them. Let's add a corresponding plugin to QEMU too. Note that this plugin has a different goal with tests/plugin/bb.c. This plugin creates a vector for each constant interval instead of counting the execution of basic blocks for the entire run and able to describe the change of execution behavior. Its output is also syntactically simple and better suited for parsing, while the output of tests/plugin/bb.c is more human-readable. [1] https://cseweb.ucsd.edu/~calder/simpoint/ [2] https://valgrind.org/docs/manual/bbv-manual.html [3] https://www.intel.com/content/www/us/en/developer/articles/tool/pin-a-dynamic-binary-instrumentation-tool.html Signed-off-by: Yotaro Nada Signed-off-by: Akihiko Odaki Reviewed-by: Pierrick Bouvier Message-Id: <20240816-bb-v3-1-b9aa4a5c75c5@daynix.com> Signed-off-by: Alex Bennée --- docs/about/emulation.rst | 30 ++++++++ contrib/plugins/bbv.c | 158 +++++++++++++++++++++++++++++++++++++++ contrib/plugins/Makefile | 1 + 3 files changed, 189 insertions(+) create mode 100644 contrib/plugins/bbv.c diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index eea1261baa..a4470127c9 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -272,6 +272,36 @@ Behaviour can be tweaked with the following arguments: * - idle=true|false - Dump the current execution stats whenever the guest vCPU idles +Basic Block Vectors +................... + +``contrib/plugins/bbv.c`` + +The bbv plugin allows you to generate basic block vectors for use with the +`SimPoint `__ analysis tool. + +.. list-table:: Basic block vectors arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - interval=N + - The interval to generate a basic block vector specified by the number of + instructions (Default: N = 100000000) + * - outfile=PATH + - The path to output files. + It will be suffixed with ``.N.bb`` where ``N`` is a vCPU index. + +Example:: + + $ qemu-aarch64 \ + -plugin contrib/plugins/libbbv.so,interval=100,outfile=sha1 \ + tests/tcg/aarch64-linux-user/sha1 + SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6 + $ du sha1.0.bb + 23128 sha1.0.bb + Instruction ........... diff --git a/contrib/plugins/bbv.c b/contrib/plugins/bbv.c new file mode 100644 index 0000000000..a5256517dd --- /dev/null +++ b/contrib/plugins/bbv.c @@ -0,0 +1,158 @@ +/* + * Generate basic block vectors for use with the SimPoint analysis tool. + * SimPoint: https://cseweb.ucsd.edu/~calder/simpoint/ + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include + +#include + +typedef struct Bb { + uint64_t vaddr; + struct qemu_plugin_scoreboard *count; + unsigned int index; +} Bb; + +typedef struct Vcpu { + uint64_t count; + FILE *file; +} Vcpu; + +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; +static GHashTable *bbs; +static GRWLock bbs_lock; +static char *filename; +static struct qemu_plugin_scoreboard *vcpus; +static uint64_t interval = 100000000; + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + for (int i = 0; i < qemu_plugin_num_vcpus(); i++) { + fclose(((Vcpu *)qemu_plugin_scoreboard_find(vcpus, i))->file); + } + + g_hash_table_unref(bbs); + g_free(filename); + qemu_plugin_scoreboard_free(vcpus); +} + +static void free_bb(void *data) +{ + qemu_plugin_scoreboard_free(((Bb *)data)->count); + g_free(data); +} + +static qemu_plugin_u64 count_u64(void) +{ + return qemu_plugin_scoreboard_u64_in_struct(vcpus, Vcpu, count); +} + +static qemu_plugin_u64 bb_count_u64(Bb *bb) +{ + return qemu_plugin_scoreboard_u64(bb->count); +} + +static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) +{ + g_autofree gchar *vcpu_filename = NULL; + Vcpu *vcpu = qemu_plugin_scoreboard_find(vcpus, vcpu_index); + + vcpu_filename = g_strdup_printf("%s.%u.bb", filename, vcpu_index); + vcpu->file = fopen(vcpu_filename, "w"); +} + +static void vcpu_interval_exec(unsigned int vcpu_index, void *udata) +{ + Vcpu *vcpu = qemu_plugin_scoreboard_find(vcpus, vcpu_index); + GHashTableIter iter; + void *value; + + if (!vcpu->file) { + return; + } + + vcpu->count -= interval; + + fputc('T', vcpu->file); + + g_rw_lock_reader_lock(&bbs_lock); + g_hash_table_iter_init(&iter, bbs); + + while (g_hash_table_iter_next(&iter, NULL, &value)) { + Bb *bb = value; + uint64_t bb_count = qemu_plugin_u64_get(bb_count_u64(bb), vcpu_index); + + if (!bb_count) { + continue; + } + + fprintf(vcpu->file, ":%u:%" PRIu64 " ", bb->index, bb_count); + qemu_plugin_u64_set(bb_count_u64(bb), vcpu_index, 0); + } + + g_rw_lock_reader_unlock(&bbs_lock); + fputc('\n', vcpu->file); +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + uint64_t n_insns = qemu_plugin_tb_n_insns(tb); + uint64_t vaddr = qemu_plugin_tb_vaddr(tb); + Bb *bb; + + g_rw_lock_writer_lock(&bbs_lock); + bb = g_hash_table_lookup(bbs, &vaddr); + if (!bb) { + bb = g_new(Bb, 1); + bb->vaddr = vaddr; + bb->count = qemu_plugin_scoreboard_new(sizeof(uint64_t)); + bb->index = g_hash_table_size(bbs); + g_hash_table_replace(bbs, &bb->vaddr, bb); + } + g_rw_lock_writer_unlock(&bbs_lock); + + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, count_u64(), n_insns); + + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, bb_count_u64(bb), n_insns); + + qemu_plugin_register_vcpu_tb_exec_cond_cb( + tb, vcpu_interval_exec, QEMU_PLUGIN_CB_NO_REGS, + QEMU_PLUGIN_COND_GE, count_u64(), interval, NULL); +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, + int argc, char **argv) +{ + for (int i = 0; i < argc; i++) { + char *opt = argv[i]; + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); + if (g_strcmp0(tokens[0], "interval") == 0) { + interval = g_ascii_strtoull(tokens[1], NULL, 10); + } else if (g_strcmp0(tokens[0], "outfile") == 0) { + filename = tokens[1]; + tokens[1] = NULL; + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + if (!filename) { + fputs("outfile unspecified\n", stderr); + return -1; + } + + bbs = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, free_bb); + vcpus = qemu_plugin_scoreboard_new(sizeof(Vcpu)); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + qemu_plugin_register_vcpu_init_cb(id, vcpu_init); + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + + return 0; +} diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index d4ac599f93..bbddd4800f 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -13,6 +13,7 @@ TOP_SRC_PATH = $(SRC_PATH)/../.. VPATH += $(SRC_PATH) NAMES := +NAMES += bbv NAMES += execlog NAMES += hotblocks NAMES += hotpages From patchwork Mon Sep 16 08:53:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828999 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp684467wrb; Mon, 16 Sep 2024 02:04:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXHJvP+FsNtwFrNN13xwPWWqbD8qTkeD6WolK3RLefJ7trO7ZfzPaFUggqqCwVoR/VfgAoIsQ==@linaro.org X-Google-Smtp-Source: AGHT+IEb020s/hjxQYJ1xrREWk/ZWLbqQ+vd5ACT+fI6SuaGrn+9jV1afEKGw16D0MUsnwKqvmx1 X-Received: by 2002:a05:6214:3b84:b0:6c5:17cf:d9fc with SMTP id 6a1803df08f44-6c5736ecb6dmr234130666d6.46.1726477443520; Mon, 16 Sep 2024 02:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726477443; cv=none; d=google.com; s=arc-20240605; b=YdprzWfhs2xvBtSRw8nCP/yXSx6PJeTZNfDmQSd8JreEyqTzwEOCOFYRhRjM9Fo8El QESOEdqjbxAiznI7cdYT87bONhD5dcD+ed6iOAioFpyISA8zIlxCY9f8wDN91OJmx425 SS9aiwD1AW17vrLQQQnzM2gPdumc+wiJHlUAEHuD3R5TCk9sb6xIx3eqj8+mcj79YYwd 1NDIJhDGN4d6MhB53fy11Xuamx0jh38BUVQuKSyxUHhkO/rDc0iEJK6AGfhXCH0wcZKp MHmj0SOiWEAmUHwKCeouE9bNvXf+c6sV9idOtSC9YLdogJDbiqLZcMPEEeCBplyi31Vy rwVA== 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=U65BhC2x8p0opV4eVz/mjZrnRxZWN1usFEftwKCpBYI=; fh=FcL6WAzC5/LCYlHd2eowAbdDk796O0W7IzRnsTD4DEM=; b=kxnBwUqyxmsFrgb4Yc3mubGev8hyG6GpaKusRmxDp9bfuLfazuxfnVyD8Qx27NQta2 PCs0bjZPpuQNxF4ulbNsfHMfc0GQvpM6HJ4/MQF69peb7P5pcv/iGzWl27r68ujCWonE niGKm+8MTou2z0nksGHmJtisy0aRIDER+PylnQpxjULJJ8DdI5LOkW5C5Q4rMuFud1nb R7Fh9/ghdu7tCZdHpXTdozgm6GMl56/Zid8mzmIcU2+90J+VokUTPUhFByxHNwhSJ5Fy 8JTuAoX8IjrbO+9pdjVw7DDCAvdpFar5ToIR1pgUMxESz7goT9/40a4IrXi0ur8EAqeX mhZw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WfrT7smF; 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-6c58c7da380si53121526d6.418.2024.09.16.02.04.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 02:04:03 -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=WfrT7smF; 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 1sq7dg-0000HY-PN; Mon, 16 Sep 2024 05:03:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sq7dd-00004r-PK for qemu-devel@nongnu.org; Mon, 16 Sep 2024 05:03:17 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7da-0006TX-24 for qemu-devel@nongnu.org; Mon, 16 Sep 2024 05:03:17 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-375e5c12042so2254272f8f.3 for ; Mon, 16 Sep 2024 02:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726477392; x=1727082192; 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=U65BhC2x8p0opV4eVz/mjZrnRxZWN1usFEftwKCpBYI=; b=WfrT7smF8riUJdd/6h145zPnBnuj2TnoIxvE98DCg8xqOd+WjozSpuXmXhIt5z8k0E t7wsmzbLmJcAFGk+xGvxKZVvqlrSzvtNCql5wRASvaJOnO1oOJLCkzcpTThYqbqoUxpe TThVm+SakRWV+yoeTuEPtl1KxVD186+Z8LzXczxPUT8SkEZXAtzFaU3fqmJEH6QeUDhT vr/y7iy9oiSGkYltCb7TVAFFdc+plxm7j2QBTfAbi1VX8iTi2cNWtZkjM1Shs8fMbzT9 qq0Sjm+Z4IdtDIab/7p3EBM8yKkcVgieIA5PvQH0lIzjFvGBusOK1pM678yg3Ilkypmi 7Chg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726477392; x=1727082192; 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=U65BhC2x8p0opV4eVz/mjZrnRxZWN1usFEftwKCpBYI=; b=d2/iMhV0oUMltKX4sCCuCwsVCPfF8pcgaM74TEqlr7SJ6uEfCHpsVygbYXMKQD+cxA nJ1NfRCi2F6Gf8JKldtvpqihSNfJasSerOPZi+uj+Fey/c0KXhzM8/1mh+URWPNKG8II CUhOlNfYAEEScqImM/t+e7wAQ72jKKm9cL4+HHhFJghhtyC3T8nKFtP9r2MFUCdngoLW uVrrEy7cdzEvJy/lxZ/CxVBFHgMeV+DEsrm0GR+YUWDIPwVzMjSLx3VMiNVFuQLfN7nn nSuzDf+m6fo5W/bpjt9kIrXKm0fFLDhRZfYweA4hJ00kGmrIDFndk1uQlaN2sHfEVBNK pcSA== X-Gm-Message-State: AOJu0YyexnCwluaX7Q2h9Jqz5lsQqLcLSif94RbPfyLcdgCmXx7AodAH wp7a8x3pgVym2gCkT74ZNsfS3m+EIJsfcLJUP0VAa30XO/iCrrLJA2HGJsKw+fE= X-Received: by 2002:adf:fc0a:0:b0:371:8c61:577c with SMTP id ffacd0b85a97d-378c2d121c0mr7853546f8f.26.1726477392184; Mon, 16 Sep 2024 02:03:12 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e780015dsm6635115f8f.69.2024.09.16.02.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:03:11 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id F1A375FCE4; Mon, 16 Sep 2024 09:54:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Rowan Hart Subject: [PATCH v2 17/18] plugins: add option to dump write argument to syscall plugin Date: Mon, 16 Sep 2024 09:53:59 +0100 Message-Id: <20240916085400.1046925-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Rowan Hart Signed-off-by: Rowan Hart Reviewed-by: Pierrick Bouvier Tested-by: Pierrick Bouvier Message-Id: <20240827215329.248434-3-rowanbhart@gmail.com> [AJB: tweak fmt string for vaddr] Signed-off-by: Alex Bennée --- vAJB - tweak fmt string for PRIu64 v2 - add static to arch_syscall_info --- docs/about/emulation.rst | 14 ++++- tests/tcg/plugins/syscall.c | 117 ++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index a4470127c9..23e4949049 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -418,6 +418,19 @@ run:: 160 1 0 135 1 0 +Behaviour can be tweaked with the following arguments: + +.. list-table:: Syscall plugin arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - print=true|false + - Print the number of times each syscall is called + * - log_writes=true|false + - Log the buffer of each write syscall in hexdump format + Test inline operations ...................... @@ -807,4 +820,3 @@ Other emulation features When running system emulation you can also enable deterministic execution which allows for repeatable record/replay debugging. See :ref:`Record/Replay` for more details. - diff --git a/tests/tcg/plugins/syscall.c b/tests/tcg/plugins/syscall.c index 72e1a5bf90..89dc7f49b1 100644 --- a/tests/tcg/plugins/syscall.c +++ b/tests/tcg/plugins/syscall.c @@ -22,8 +22,57 @@ typedef struct { int64_t errors; } SyscallStats; +struct SyscallInfo { + const char *name; + int64_t write_sysno; +}; + +static const struct SyscallInfo arch_syscall_info[] = { + { "aarch64", 64 }, + { "aarch64_be", 64 }, + { "alpha", 4 }, + { "arm", 4 }, + { "armeb", 4 }, + { "avr", -1 }, + { "cris", -1 }, + { "hexagon", 64 }, + { "hppa", -1 }, + { "i386", 4 }, + { "loongarch64", -1 }, + { "m68k", 4 }, + { "microblaze", 4 }, + { "microblazeel", 4 }, + { "mips", 1 }, + { "mips64", 1 }, + { "mips64el", 1 }, + { "mipsel", 1 }, + { "mipsn32", 1 }, + { "mipsn32el", 1 }, + { "or1k", -1 }, + { "ppc", 4 }, + { "ppc64", 4 }, + { "ppc64le", 4 }, + { "riscv32", 64 }, + { "riscv64", 64 }, + { "rx", -1 }, + { "s390x", -1 }, + { "sh4", -1 }, + { "sh4eb", -1 }, + { "sparc", 4 }, + { "sparc32plus", 4 }, + { "sparc64", 4 }, + { "tricore", -1 }, + { "x86_64", 1 }, + { "xtensa", 13 }, + { "xtensaeb", 13 }, + { NULL, -1 }, +}; + static GMutex lock; static GHashTable *statistics; +static GByteArray *memory_buffer; +static bool do_log_writes; +static int64_t write_sysno = -1; static SyscallStats *get_or_create_entry(int64_t num) { @@ -39,6 +88,44 @@ static SyscallStats *get_or_create_entry(int64_t num) return entry; } +/* + * Hex-dump a GByteArray to the QEMU plugin output in the format: + * 61 63 63 65 6c 09 09 20 20 20 66 70 75 09 09 09 | accel.....fpu... + * 20 6d 6f 64 75 6c 65 2d 63 6f 6d 6d 6f 6e 2e 63 | .module-common.c + */ +static void hexdump(const GByteArray *data) +{ + g_autoptr(GString) out = g_string_new(""); + + for (guint index = 0; index < data->len; index += 16) { + for (guint col = 0; col < 16; col++) { + if (index + col < data->len) { + g_string_append_printf(out, "%02x ", data->data[index + col]); + } else { + g_string_append(out, " "); + } + } + + g_string_append(out, " | "); + + for (guint col = 0; col < 16; col++) { + if (index + col >= data->len) { + break; + } + + if (g_ascii_isgraph(data->data[index + col])) { + g_string_append_printf(out, "%c", data->data[index + col]); + } else { + g_string_append(out, "."); + } + } + + g_string_append(out, "\n"); + } + + qemu_plugin_outs(out->str); +} + static void vcpu_syscall(qemu_plugin_id_t id, unsigned int vcpu_index, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, @@ -54,6 +141,14 @@ static void vcpu_syscall(qemu_plugin_id_t id, unsigned int vcpu_index, g_autofree gchar *out = g_strdup_printf("syscall #%" PRIi64 "\n", num); qemu_plugin_outs(out); } + + if (do_log_writes && num == write_sysno) { + if (qemu_plugin_read_memory_vaddr(a2, memory_buffer, a3)) { + hexdump(memory_buffer); + } else { + fprintf(stderr, "Error reading memory from vaddr %"PRIu64"\n", a2); + } + } } static void vcpu_syscall_ret(qemu_plugin_id_t id, unsigned int vcpu_idx, @@ -127,6 +222,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_print)) { fprintf(stderr, "boolean argument parsing failed: %s\n", opt); } + } else if (g_strcmp0(tokens[0], "log_writes") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_log_writes)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + } } else { fprintf(stderr, "unsupported argument: %s\n", argv[i]); return -1; @@ -137,6 +236,24 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, statistics = g_hash_table_new_full(NULL, g_direct_equal, NULL, g_free); } + if (do_log_writes) { + for (const struct SyscallInfo *syscall_info = arch_syscall_info; + syscall_info->name != NULL; syscall_info++) { + + if (g_strcmp0(syscall_info->name, info->target_name) == 0) { + write_sysno = syscall_info->write_sysno; + break; + } + } + + if (write_sysno == -1) { + fprintf(stderr, "write syscall number not found\n"); + return -1; + } + + memory_buffer = g_byte_array_new(); + } + qemu_plugin_register_vcpu_syscall_cb(id, vcpu_syscall); qemu_plugin_register_vcpu_syscall_ret_cb(id, vcpu_syscall_ret); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); From patchwork Mon Sep 16 08:54:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828996 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp682119wrb; Mon, 16 Sep 2024 01:58:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX7sqJHMMic3Fr5Dd86srLcCoSKSC4IdvcsTdfxAdDKFCSVazApqRN3KhpeeBLFg+Kzpkrtiw==@linaro.org X-Google-Smtp-Source: AGHT+IFG97yUs0QSNW9RO7qknkh85NnHn7QH274ZI82vvTnxfuBtvxZdyujic9g/rajfNTuxX/3Q X-Received: by 2002:a05:622a:d2:b0:458:5011:666c with SMTP id d75a77b69052e-4599d219fdcmr158802341cf.4.1726477088854; Mon, 16 Sep 2024 01:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726477088; cv=none; d=google.com; s=arc-20240605; b=PzG3tQz2i6CgXGKY/2+3NPlkpYAwMsQXBWv/wSd+jXLEGArdatCj99bfiKTl1H6MY+ dw17PSezjolhE+ARXcjB6jJsBb71urze6ukPn9DJ69Ya6PEV+D2OqBOh8OWS1co7IUmb MG85+cYhI06/7Sy3wK+MK5KQt5Wo/HFf8cHzPuX54kCygqZfFq/I4is0Ge22qcNwYXqO HPBXh3EaAkWNV19whmzlQA3fpdkQrirjklJb/K2XHcejeCR9czkafw5e0I5aYcQRkKW/ rikbfY8Gmh8xLwnA/s856C7Rttx2cfDHU8ne2Rw1vWP6H+N7yeyg5CjNiYZnXWwmQ9D8 7bUQ== 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=WWhpWDyIZgZQNjk9OdCuUgywH4MF2qEBFr+67oTYvJA=; fh=EUSMNgYjwj4GGVay3LBMQ2Gpqe70dd1O82wcFkfan2U=; b=KK9cZDuX3rIhMcxMhdXXDzgyCGTMxzkb+pjEb9mXqZZn+j+lkBxIknabdDFmb6YGvo 1wyIsJcDlyCsivwj4BE3uX9GXH4dQZ0EAxBNjtksTkG2K2LkUfxysNBSdcIaDRTiZFVX Er7Yht9EbXH9YVVXsCNBpb5H8s7j2ENsIcC8iG34J+bklkqq0SPm40U9BqbOjKHuqJRe 1/rBHaN5bwLg2RHtWOEIA9vQ9aSwENZLhEUyQ3lIL8L5QJiPd3aT6Gr6yDv3w9w8iNE0 Z2sCgkBEalJurilXxcUg6QZmXj74DtN3pwqTOIlxgDpzsZ5epIdYffsSs1fpablx917m VlgQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DmMnDlOL; 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-459aad0ef1asi55262371cf.337.2024.09.16.01.58.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:58:08 -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=DmMnDlOL; 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 1sq7VZ-0001of-8c; Mon, 16 Sep 2024 04:54: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 1sq7VD-0000ps-LQ for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:35 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Uu-0005F7-GF for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:35 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-42cb6f3a5bcso39669845e9.2 for ; Mon, 16 Sep 2024 01:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476855; x=1727081655; 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=WWhpWDyIZgZQNjk9OdCuUgywH4MF2qEBFr+67oTYvJA=; b=DmMnDlOL3I0RX9ozBGc/MI6CrqvDC/IoEUA+2p9DIMNQDBZ3nKChnWdVtdXbX9ArbC C13UsPs38xYYVQEzYfQwBKH0DM9eD2tEIOsOlfurpyjpd4AyhLgRAZbAkcQVjPIv9WN/ PDTGDHI4A1pouRYHgD+5DgRwyKQjixzgJDBqMBpww5dsagPmRXqEFAK/JZ3ocTEVMM0Q ROYufXHg/9S5kv6pJwJC1pVQt2FPdmYfFTzl2Pxhe5tGlQH845gpnXIBcFrlW9HY91Ne uowSyhA1Kg0q/fIehbTDfRAS1+VBytbuaXAg9QqlIyovnftVyMjmorZ6zYjFKY3Lwbzl Tggw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476855; x=1727081655; 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=WWhpWDyIZgZQNjk9OdCuUgywH4MF2qEBFr+67oTYvJA=; b=o5JTCuzqZ5B9L5mV6dYfdn+p+ZHrU8afIx//qXpf5b/zElDjcMChuUG29mJghyxTsr GM4OmxSupmM/V2O7CsGCPdsWfdRCAnGR0ngsoVIDgHc0/yPbhJVuQZKaiUWVOHJWlOzs emfP1iiYeAGGszLa3brnHoHDwToEAckP0NnVY1eTm4BBLzCDpNqo318W12oJEV3xP2dU INV/XKWXUGvoAI3Vffgt3BhXP7XdORORHpaePnhe0CJ1Df1DNy10a20GrlIXGt1snDLq mUw2OjqE+5+u/+6fEi5T2ROFFmyPyMmmZ8s514Hda7dzC7znZX7c6xGXupH08eCC4pVP czoA== X-Gm-Message-State: AOJu0YyLp5Vt0F8U4Kh/W2FNVec64lIH4G5oRK2V+9adLUekwKapT2KA fwf3VR3CMNwviH2J1PGVORk/TCvDmT/BKpxcOg4Qrg91JyUYqkmOJ6on4SLNjFk= X-Received: by 2002:a05:600c:4f01:b0:42c:aeaa:6b0d with SMTP id 5b1f17b1804b1-42d907205a5mr105040045e9.9.1726476855029; Mon, 16 Sep 2024 01:54:15 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42d9b05da47sm106194315e9.17.2024.09.16.01.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:10 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 124CA5F8F2; Mon, 16 Sep 2024 09:54:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Elisha Hollander Subject: [PATCH v2 18/18] contrib/plugins: avoid hanging program Date: Mon, 16 Sep 2024 09:54:00 +0100 Message-Id: <20240916085400.1046925-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.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 Although we asks for instructions per second we work in quanta and that cannot be 0. Fail to load the plugin instead and report the minimum IPS we can handle. Signed-off-by: Alex Bennée Reported-by: Elisha Hollander Reviewed-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- contrib/plugins/ips.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/plugins/ips.c b/contrib/plugins/ips.c index 29fa556d0f..6f078689dc 100644 --- a/contrib/plugins/ips.c +++ b/contrib/plugins/ips.c @@ -152,6 +152,11 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, vcpus = qemu_plugin_scoreboard_new(sizeof(vCPUTime)); max_insn_per_quantum = max_insn_per_second / NUM_TIME_UPDATE_PER_SEC; + if (max_insn_per_quantum == 0) { + fprintf(stderr, "minimum of %d instructions per second needed\n", NUM_TIME_UPDATE_PER_SEC); + return -1; + } + time_handle = qemu_plugin_request_time_control(); g_assert(time_handle);