From patchwork Fri Sep 13 17:26: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: 828215 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp365484wra; Fri, 13 Sep 2024 10:35:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXL7y/IcM8F8YkoCUwmsbvDe5lRkfHpN7SlXJFAIwK2+/3/rlDRE0POI3K5Rq4anXvqc+LuqA==@linaro.org X-Google-Smtp-Source: AGHT+IGq4LvHjD5BADAllXy1MB7yhsbQHpJH9PIopUI3LfKNAfVk/61T1Myd1XGUPO8syzAHQGws X-Received: by 2002:a05:6902:3103:b0:e1d:2300:29a1 with SMTP id 3f1490d57ef6-e1daff94e2fmr3269149276.29.1726248955514; Fri, 13 Sep 2024 10:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726248955; cv=none; d=google.com; s=arc-20240605; b=iOFWQxFduQyLm2Cxk77qooLPUOauKVvbKWDFLQ5mFHuxLBxh4NYvCuoS6GBY6b6h+5 2BaTDShDHWxIPv37zLtX7xfgUdH8rAtLjnEVArjSq9g2nXPNLCRFgYisBwzYj7vHANS3 y18aMVx2Sjrk3bsJq9PHV4TphE1nWqQAR2XGJO2YGh2d9wYZEmdITpmH/MYcNOCC+UUy Jfmg+k0bA+FTAQIZSZgTcI10xlh294mcUG3McLhfCdZ+kZOdQhaF53lYCC006CaJ3s13 GMtIyYr9UK/pftzQfGWMzR1mXTG5jMzrBf9vrfJ2+TuFItSgCKx7VpjWa8GrPt1h42yS 4XCg== 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=hEZbqliSm3idSAY5YqSflW1IHfDQd2AMSDogcHs/b2s=; fh=GsrwtA/UDrcgEwSkY5/1kjXSExuJfr1ekbSXfoTh728=; b=cp+uLTOJNsgoLd8Qdd/Cx9MzMKnMcfAfWVgGpdKLylvXo239frFHFdLzoVXuAzAu6A E0aaOMwICsv0zeaQi+M1aWH7rvAP7trV4zpAK8XMgIjpAh+ubIGNlOVhW0DP+8rPxUNQ 0CefqAgACXHnFWAMeFkMm0mV+no+BZ+FsN1ek6Pb4X6xKNsTG4b2BuPjqXsjtjcmw3xb ieGYpb7PSAg5ZMDpDELwFai8Edl8guAKsvloX263mJ0/Zuk+TnQpGeNwJvebz0UoDrx4 yQbWI9FGA6Dq3ml0UA9DnLIjX1P/1yI9QSmzNua52fWeqQuI3WG0ZFZz+CS1r11uOdU2 M0Lg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PyB9+h26; 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-45822f815d5si162805901cf.506.2024.09.13.10.35.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 10:35: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=PyB9+h26; 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 1spAC2-0002Lh-OK; Fri, 13 Sep 2024 13:34: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 1spAC1-0002D2-10 for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:34:49 -0400 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spABx-0006gL-3l for qemu-devel@nongnu.org; Fri, 13 Sep 2024 13:34:48 -0400 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5365d3f9d34so1473596e87.3 for ; Fri, 13 Sep 2024 10:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726248881; x=1726853681; 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=hEZbqliSm3idSAY5YqSflW1IHfDQd2AMSDogcHs/b2s=; b=PyB9+h26DpG5Sm7BcJ47cSZKSdECPj6Nz7P+muBSVt7DPu3k91gbz9kFz/KbGRHyb4 WcGFXDvNHIMEYCcUxcH8d1EwF3TRiteUNUiTS9A4CVzerenMb7LFOVr1xgCgXWLa5IwZ SFMIiMz4AC3ymlkr2ZqSgZKm/5OLPiQqHei9kmsP8RuMGh8UAzQGAyQFIGs+FjkxYiNt UTm9eI0wmUS64F/+QPOiRXYgeIpCVtexiR8IkQghkU2gvhbHL3+jeBi4oFfL6DfMg7uP d0Q/kzlRGk2WMWrvV0qeDeJ243o98I0N9DK6qdWwEjvRo/N8R9TB0x4WRKJQ7K18PSwQ HFNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726248881; x=1726853681; 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=hEZbqliSm3idSAY5YqSflW1IHfDQd2AMSDogcHs/b2s=; b=sdq9l/YdbzZY6cQPrA5JZFyKQXQlrhVdXhkBPaT3ZKnEf0jKNrjunsgfgHTGyEBj6M +L7cLCtHPOdE2zMkVxRlgym1Tlitl5V0YCbGD+Uy+m2tPVwRO9ALqYOFIYr2cWUQajXw JZmXJc+/1RQrnlB9eFc73H0mK2z3g5VYgeCqeECjQXk0qXdfUFaZmhASrETOis1AVGW1 Sn4iyzuoNDM7Ex41tmPXFLi6fj7MJWuDy4coQguZVZp3bEDO+Qxk1Pz0Pt2DYmDa493Q iZQh05Q+bPwcBp2KrwMTziHMpEhyiJLvKTAn70tVy2l6YsudghoqdKSf9OLIEmihgksu cLZQ== X-Gm-Message-State: AOJu0Yz2uxgnSZJEoWjbU9yVn8sJd69/YET8qEE4C6dcyWz7NgkdFtl4 YEJmhdKshH2rU8MDJa+HgYmgMSQx0qJZz0uZ1i6UB+bGNA+a8ZeOYSzCfUVub3A= X-Received: by 2002:a05:6512:a90:b0:535:3dae:a14b with SMTP id 2adb3069b0e04-5367feba05emr2330342e87.2.1726248880496; Fri, 13 Sep 2024 10:34:40 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72eb0sm891789466b.132.2024.09.13.10.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 10:34:39 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id CAC045FBCB; Fri, 13 Sep 2024 18:26:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , devel@lists.libvirt.org, Thomas Huth , Mahmoud Mandour , Paolo Bonzini , David Hildenbrand , Ilya Leoshkevich , qemu-ppc@nongnu.org, Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , qemu-s390x@nongnu.org, Alexandre Iooss , Pierrick Bouvier , Nicholas Piggin , Daniel Henrique Barboza , Marcel Apfelbaum , Rowan Hart Subject: [PATCH 17/17] plugins: add option to dump write argument to syscall plugin Date: Fri, 13 Sep 2024 18:26:55 +0100 Message-Id: <20240913172655.173873-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org> References: <20240913172655.173873-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::135; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x135.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: 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 --- 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..647f478090 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; +}; + +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);