diff options
| author | Jamin Lin <jamin_lin@aspeedtech.com> | 2025-05-15 16:09:48 +0800 |
|---|---|---|
| committer | Cédric Le Goater <clg@redhat.com> | 2025-05-25 23:39:11 +0200 |
| commit | 22370d29e83753e4072457541ab59189edcd3947 (patch) | |
| tree | f7f4d453d07a49fc8c8da0356f697c901f1a74b2 /hw/misc/aspeed_hace.c | |
| parent | 555167a8fde2bf6c27d0df035324743ed5bfbb0d (diff) | |
| download | focaccia-qemu-22370d29e83753e4072457541ab59189edcd3947.tar.gz focaccia-qemu-22370d29e83753e4072457541ab59189edcd3947.zip | |
hw/misc/aspeed_hace: Support to dump plaintext and digest for better debugging
1. Added "hace_hexdump()" to dump a contiguous buffer using qemu_hexdump. 2. Added "hace_iov_hexdump()" to flatten and dump scatter-gather source vectors. 3. Introduced a new trace event: "aspeed_hace_hexdump". Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> Link: https://lore.kernel.org/qemu-devel/20250515081008.583578-17-jamin_lin@aspeedtech.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
Diffstat (limited to 'hw/misc/aspeed_hace.c')
| -rw-r--r-- | hw/misc/aspeed_hace.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/hw/misc/aspeed_hace.c b/hw/misc/aspeed_hace.c index ee1d9ab58f..8924a30eff 100644 --- a/hw/misc/aspeed_hace.c +++ b/hw/misc/aspeed_hace.c @@ -10,8 +10,10 @@ */ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qemu/log.h" #include "qemu/error-report.h" +#include "qemu/iov.h" #include "hw/misc/aspeed_hace.h" #include "qapi/error.h" #include "migration/vmstate.h" @@ -88,6 +90,42 @@ static const struct { QCRYPTO_HASH_ALGO_SHA256 }, }; +static void hace_hexdump(const char *desc, const char *buf, size_t size) +{ + g_autoptr(GString) str = g_string_sized_new(64); + size_t len; + size_t i; + + for (i = 0; i < size; i += len) { + len = MIN(16, size - i); + g_string_truncate(str, 0); + qemu_hexdump_line(str, buf + i, len, 1, 4); + trace_aspeed_hace_hexdump(desc, i, str->str); + } +} + +static void hace_iov_hexdump(const char *desc, const struct iovec *iov, + const unsigned int iov_cnt) +{ + size_t size = 0; + char *buf; + int i; + + for (i = 0; i < iov_cnt; i++) { + size += iov[i].iov_len; + } + + buf = g_malloc(size); + + if (!buf) { + return; + } + + iov_to_buf(iov, iov_cnt, 0, buf, size); + hace_hexdump(desc, buf, size); + g_free(buf); +} + static int hash_algo_lookup(uint32_t reg) { int i; @@ -302,6 +340,10 @@ static void hash_write_digest_and_unmap_iov(AspeedHACEState *s, __func__, digest_addr); } + if (trace_event_get_state_backends(TRACE_ASPEED_HACE_HEXDUMP)) { + hace_hexdump("digest", (char *)digest_buf, digest_len); + } + for (; iov_idx > 0; iov_idx--) { address_space_unmap(&s->dram_as, iov[iov_idx - 1].iov_base, iov[iov_idx - 1].iov_len, false, @@ -395,6 +437,10 @@ static void do_hash_operation(AspeedHACEState *s, int algo, bool sg_mode, return; } + if (trace_event_get_state_backends(TRACE_ASPEED_HACE_HEXDUMP)) { + hace_iov_hexdump("plaintext", iov, iov_idx); + } + /* Executes the hash operation */ if (acc_mode) { hash_execute_acc_mode(s, algo, iov, iov_idx, acc_final_request); |