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);