From patchwork Wed May 15 17:31:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 796987 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3100754wra; Wed, 15 May 2024 10:33:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXtsCQacvVg24zEl6sIrnBkEMqp4/AAZEWLZDWY5GQzLUYW0bo9Pwa4kx+IlKmHHti6i0nqmtngNlKsiFv28FAb X-Google-Smtp-Source: AGHT+IFVUL/DuKsdTiTsLOdiczpgJv7EQELH+RmN3aTSWICXHIKN+yepXKw0+4KPpaTTh8ovKnoS X-Received: by 2002:a05:622a:1344:b0:43a:dd5b:d306 with SMTP id d75a77b69052e-43dfdd0ade0mr211917801cf.55.1715794387554; Wed, 15 May 2024 10:33:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715794387; cv=none; d=google.com; s=arc-20160816; b=hru3lIj3yEsdxZqwUr3bDBu19y/5HzwgWuSUZTXBwwNRYnoKwbfzzv3kH2JpgYTWQB kH1YUp0Q5FS3u9zycwYvdCEvQ++Su+/NlcGcgh1FUkuNMOXzWKi95oD3lOJ742bRXOZC gDLIZWFSAWBhGZwlpHW1fwLr41cpxAPxjhvRH6MXVTC9uqWmgmCvfER7gRP+GNbyvJAO 2sEjEZkBjjnIzIIoWoYjdMoee7uFz3vSnN2wR/+kenzXXo0qqVA5h8SaGbMgITIpo/e2 j+icnVMM1Ucz8j/wafNxljMqtTSPzjrkG52u+Vs5rhJp95LYZVWyHC2zeihxKioi5HGe 5XWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=vcj2Py+dn09bF4yGtRILmfWfVgmwYYBz6rwT+Eir1qs=; fh=ZLVo7h1WCYX+mCQET83n+8bPmyNFw4pMQxFlbH8xyms=; b=id4jJ+8+E9KlfM9y6Pt6DkaK8H6xryUOZ9nehp9cuc6unSXXf++Kx73RoGXuL2wVLz IMXQDduVeNGNK9FujatfhAIn9CaPfZnst8Ur2ep1Jysnr68BvC3z5wJOJ2Ah0hD8IUmp J/u2NZ6o7RGmeWrwYkKe5ZZTDNFV2xqh+mkBQbfJUEyG5sRyoSXVSWDFT94C8mGN5RUA U58qCNN+PMViuGLZuYaRAU1rPCfI2fvX8kxrjwRBFwY1H5gXXilbTdTsqS1F1U1rGjgK Mj7Phu0icE12OE1i1Ig+mSpyDEI+gha33h5Nw3Ho8EBvPGdLwHMIijkHUvwmTsfGjaYg esjQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yoF98k5k; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-43e0d65e31asi93970261cf.167.2024.05.15.10.33.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 10:33:07 -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=yoF98k5k; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7IUR-0005EX-U2; Wed, 15 May 2024 13:32:31 -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 1s7IUK-0005DH-Pk for qemu-devel@nongnu.org; Wed, 15 May 2024 13:32:25 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0: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 1s7IUI-0002Dx-Hv for qemu-devel@nongnu.org; Wed, 15 May 2024 13:32:24 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6f44a2d1e3dso6399542b3a.3 for ; Wed, 15 May 2024 10:32:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715794341; x=1716399141; 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=vcj2Py+dn09bF4yGtRILmfWfVgmwYYBz6rwT+Eir1qs=; b=yoF98k5kBwun4mRCDD19bMLP9gsEiSB6KjA0ciBYFODMVrGhN45tk+aKizre2PEFtj IAvX9gfDx7Q/M8Ka3WLRGFSP3pvkUVGHbplg0p4nHC2vRfAJDIfslMOEQrkgl/KCFX38 d7KCKpK64AbqVJR6LEtdQkE3DOwhDTdkNsSkANg7+z25v8Y8y9ntoBxhitWvXd3AX+4D 8a20W3erWbX4yIsKjd8SwKQsVq5sfWYzIhoplEPfWrqVJLJBGPtTsm8VWevr3UxDKDsu CBFeybe0Drwm7fkZd79J2I2U9FshXB8rZlf2lK/Ol/3smu3ouSTyGHzXqYQiX19zAV/3 q+Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715794341; x=1716399141; 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=vcj2Py+dn09bF4yGtRILmfWfVgmwYYBz6rwT+Eir1qs=; b=doI9cMeRPvrGN8GfdpAtNWMLj7Se5Wyp1CXaeFkFAonUdcqVvlTaAMXVb0ZXhwSUKZ wYatuCU4c4fDRytmaKxoTvY8ZjQethDDc+UxY+Tl0WEqQWsIQwGFusQZrT6092wz1hou n7iMPQ1JNIH+sYTfx4kwGz31dHX6WOTjzzG3BKpdiEpWeRNwX9xRmNXLWrLZa5xMwSjL rzDQUgCSX5E8PLQNrjAG6XWluZw2WvenazTmYwcPDVahgNGSEcRDej7TCDP62kmBb42q PGl0ft3nR7S+t1Ho6Vw1T+Teg6zZ8sLLIpNV+lSm9SBRv2DssGSQPcunRHr0wSdPCvMF l7Sw== X-Gm-Message-State: AOJu0YxLu9gba6oO69UDxeW2nj6hvrxPFWpWcbcZAhv1DO+E9AfLzfb9 0oILH0XkhrYqvTwDq8NwnUsT3XYkB30vcIkZu+yJJDvZi88i5WTyQMQrFW9xme7T0EHd6JdQCFt ge+g= X-Received: by 2002:a05:6a20:430e:b0:1af:dd77:86ab with SMTP id adf61e73a8af0-1afde1faeadmr16681248637.54.1715794340627; Wed, 15 May 2024 10:32:20 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:224b:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a66c6asm11365133b3a.6.2024.05.15.10.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 10:32:20 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, peter.maydell@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: gustavo.romero@linaro.org Subject: [PATCH 1/4] gdbstub: Add support for target-specific stubs Date: Wed, 15 May 2024 17:31:29 +0000 Message-Id: <20240515173132.2462201-2-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515173132.2462201-1-gustavo.romero@linaro.org> References: <20240515173132.2462201-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-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 Currently, it's not possible to have stubs specific to a given target, even though there are GDB features which are target-specific, like, for instance, memory tagging. This commit introduces set_query_supported_arch, set_gdb_gen_query_table_arch, and set_gdb_gen_set_table_arch functions as interfaces to extend the qSupported string, the query handler table, and set handler table per target, so allowing target-specific stub implementation. Besides that, it moves GdbCmdParseEntry struct, its related types, and gdb_put_packet to include/exec/gdbstub.h so they are also available in the target-specific stubs. Signed-off-by: Gustavo Romero Reviewed-by: Philippe Mathieu-Daudé --- gdbstub/gdbstub.c | 108 +++++++++++++++++++++++------------------ gdbstub/internals.h | 22 --------- gdbstub/syscalls.c | 1 + include/exec/gdbstub.h | 86 +++++++++++++++++++++++++++++++- 4 files changed, 147 insertions(+), 70 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index b3574997ea..4996530fde 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -920,43 +920,6 @@ static int cmd_parse_params(const char *data, const char *schema, return 0; } -typedef void (*GdbCmdHandler)(GArray *params, void *user_ctx); - -/* - * cmd_startswith -> cmd is compared using startswith - * - * allow_stop_reply -> true iff the gdbstub can respond to this command with a - * "stop reply" packet. The list of commands that accept such response is - * defined at the GDB Remote Serial Protocol documentation. see: - * https://sourceware.org/gdb/onlinedocs/gdb/Stop-Reply-Packets.html#Stop-Reply-Packets. - * - * schema definitions: - * Each schema parameter entry consists of 2 chars, - * the first char represents the parameter type handling - * the second char represents the delimiter for the next parameter - * - * Currently supported schema types: - * 'l' -> unsigned long (stored in .val_ul) - * 'L' -> unsigned long long (stored in .val_ull) - * 's' -> string (stored in .data) - * 'o' -> single char (stored in .opcode) - * 't' -> thread id (stored in .thread_id) - * '?' -> skip according to delimiter - * - * Currently supported delimiters: - * '?' -> Stop at any delimiter (",;:=\0") - * '0' -> Stop at "\0" - * '.' -> Skip 1 char unless reached "\0" - * Any other value is treated as the delimiter value itself - */ -typedef struct GdbCmdParseEntry { - GdbCmdHandler handler; - const char *cmd; - bool cmd_startswith; - const char *schema; - bool allow_stop_reply; -} GdbCmdParseEntry; - static inline int startswith(const char *string, const char *pattern) { return !strncmp(string, pattern, strlen(pattern)); @@ -1645,6 +1608,13 @@ static void handle_query_thread_extra(GArray *params, void *user_ctx) gdb_put_strbuf(); } +/* Arch-specific qSupported */ +char *query_supported_arch = NULL; +void set_query_supported_arch(char *query_supported) +{ + query_supported_arch = query_supported; +} + static void handle_query_supported(GArray *params, void *user_ctx) { CPUClass *cc; @@ -1684,6 +1654,11 @@ static void handle_query_supported(GArray *params, void *user_ctx) } g_string_append(gdbserver_state.str_buf, ";vContSupported+;multiprocess+"); + + if (query_supported_arch) { + g_string_append(gdbserver_state.str_buf, query_supported_arch); + } + gdb_put_strbuf(); } @@ -1765,6 +1740,16 @@ static const GdbCmdParseEntry gdb_gen_query_set_common_table[] = { }, }; + +/* Arch-specific query table */ +static GdbCmdParseEntry *gdb_gen_query_table_arch = NULL ; +static int gdb_gen_query_table_arch_size = 0; +void set_gdb_gen_query_table_arch(GdbCmdParseEntry *table, int size) +{ + gdb_gen_query_table_arch = table; + gdb_gen_query_table_arch_size = size; +} + static const GdbCmdParseEntry gdb_gen_query_table[] = { { .handler = handle_query_curr_tid, @@ -1857,6 +1842,15 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = { #endif }; +/* Arch-specific set table */ +static GdbCmdParseEntry *gdb_gen_set_table_arch = NULL; +static int gdb_gen_set_table_arch_size = 0; +void set_gdb_gen_set_table_arch(GdbCmdParseEntry *table, int size) +{ + gdb_gen_set_table_arch = table; + gdb_gen_set_table_arch_size = size; +} + static const GdbCmdParseEntry gdb_gen_set_table[] = { /* Order is important if has same prefix */ { @@ -1889,17 +1883,27 @@ static void handle_gen_query(GArray *params, void *user_ctx) return; } - if (!process_string_cmd(get_param(params, 0)->data, - gdb_gen_query_set_common_table, - ARRAY_SIZE(gdb_gen_query_set_common_table))) { + if (process_string_cmd(get_param(params, 0)->data, + gdb_gen_query_set_common_table, + ARRAY_SIZE(gdb_gen_query_set_common_table)) == 0) { return; } if (process_string_cmd(get_param(params, 0)->data, gdb_gen_query_table, - ARRAY_SIZE(gdb_gen_query_table))) { - gdb_put_packet(""); + ARRAY_SIZE(gdb_gen_query_table)) == 0) { + return; } + + if (gdb_gen_query_table_arch && + process_string_cmd(get_param(params, 0)->data, + gdb_gen_query_table_arch, + gdb_gen_query_table_arch_size) == 0) { + return; + } + + /* Can't handle query, return Empty response. */ + gdb_put_packet(""); } static void handle_gen_set(GArray *params, void *user_ctx) @@ -1908,17 +1912,27 @@ static void handle_gen_set(GArray *params, void *user_ctx) return; } - if (!process_string_cmd(get_param(params, 0)->data, - gdb_gen_query_set_common_table, - ARRAY_SIZE(gdb_gen_query_set_common_table))) { + if (process_string_cmd(get_param(params, 0)->data, + gdb_gen_query_set_common_table, + ARRAY_SIZE(gdb_gen_query_set_common_table)) == 0) { return; } if (process_string_cmd(get_param(params, 0)->data, gdb_gen_set_table, - ARRAY_SIZE(gdb_gen_set_table))) { - gdb_put_packet(""); + ARRAY_SIZE(gdb_gen_set_table)) == 0) { + return; } + + if (gdb_gen_set_table_arch && + process_string_cmd(get_param(params, 0)->data, + gdb_gen_set_table_arch, + gdb_gen_set_table_arch_size) == 0) { + return; + } + + /* Can't handle set, return Empty response. */ + gdb_put_packet(""); } static void handle_target_halt(GArray *params, void *user_ctx) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 32f9f63297..34121dc61a 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -106,7 +106,6 @@ static inline int tohex(int v) */ void gdb_put_strbuf(void); -int gdb_put_packet(const char *buf); int gdb_put_packet_binary(const char *buf, int len, bool dump); void gdb_hextomem(GByteArray *mem, const char *buf, int len); void gdb_memtohex(GString *buf, const uint8_t *mem, int len); @@ -166,27 +165,6 @@ void gdb_put_buffer(const uint8_t *buf, int len); */ void gdb_init_gdbserver_state(void); -typedef enum GDBThreadIdKind { - GDB_ONE_THREAD = 0, - GDB_ALL_THREADS, /* One process, all threads */ - GDB_ALL_PROCESSES, - GDB_READ_THREAD_ERR -} GDBThreadIdKind; - -typedef union GdbCmdVariant { - const char *data; - uint8_t opcode; - unsigned long val_ul; - unsigned long long val_ull; - struct { - GDBThreadIdKind kind; - uint32_t pid; - uint32_t tid; - } thread_id; -} GdbCmdVariant; - -#define get_param(p, i) (&g_array_index(p, GdbCmdVariant, i)) - void gdb_handle_query_rcmd(GArray *params, void *ctx); /* system */ void gdb_handle_query_offsets(GArray *params, void *user_ctx); /* user */ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */ diff --git a/gdbstub/syscalls.c b/gdbstub/syscalls.c index 02e3a8f74c..ee9a16495e 100644 --- a/gdbstub/syscalls.c +++ b/gdbstub/syscalls.c @@ -18,6 +18,7 @@ #include "gdbstub/syscalls.h" #include "trace.h" #include "internals.h" +#include "exec/gdbstub.h" /* Syscall specific state */ typedef struct { diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index eb14b91139..7bf189d7f3 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -144,4 +144,88 @@ void gdb_set_stop_cpu(CPUState *cpu); /* in gdbstub-xml.c, generated by scripts/feature_to_c.py */ extern const GDBFeature gdb_static_features[]; -#endif +typedef void (*GdbCmdHandler)(GArray *params, void *user_ctx); + +typedef enum GDBThreadIdKind { + GDB_ONE_THREAD = 0, + GDB_ALL_THREADS, /* One process, all threads */ + GDB_ALL_PROCESSES, + GDB_READ_THREAD_ERR +} GDBThreadIdKind; + +typedef union GdbCmdVariant { + const char *data; + uint8_t opcode; + unsigned long val_ul; + unsigned long long val_ull; + struct { + GDBThreadIdKind kind; + uint32_t pid; + uint32_t tid; + } thread_id; +} GdbCmdVariant; + +#define get_param(p, i) (&g_array_index(p, GdbCmdVariant, i)) + +/* + * cmd_startswith -> cmd is compared using startswith + * + * allow_stop_reply -> true iff the gdbstub can respond to this command with a + * "stop reply" packet. The list of commands that accept such response is + * defined at the GDB Remote Serial Protocol documentation. see: + * https://sourceware.org/gdb/onlinedocs/gdb/Stop-Reply-Packets.html#Stop-Reply-Packets. + * + * schema definitions: + * Each schema parameter entry consists of 2 chars, + * the first char represents the parameter type handling + * the second char represents the delimiter for the next parameter + * + * Currently supported schema types: + * 'l' -> unsigned long (stored in .val_ul) + * 'L' -> unsigned long long (stored in .val_ull) + * 's' -> string (stored in .data) + * 'o' -> single char (stored in .opcode) + * 't' -> thread id (stored in .thread_id) + * '?' -> skip according to delimiter + * + * Currently supported delimiters: + * '?' -> Stop at any delimiter (",;:=\0") + * '0' -> Stop at "\0" + * '.' -> Skip 1 char unless reached "\0" + * Any other value is treated as the delimiter value itself + */ +typedef struct GdbCmdParseEntry { + GdbCmdHandler handler; + const char *cmd; + bool cmd_startswith; + const char *schema; + bool allow_stop_reply; +} GdbCmdParseEntry; + +#define get_cmd_parsers(p) (&g_array_index(p, GdbCmdParseEntry, 0)) + +/** + * set_gdb_gen_query_table_arch() - set a table to handle arch-specific query + * packets + */ +void set_gdb_gen_query_table_arch(GdbCmdParseEntry *table, int size); + +/** + * set_gdb_gen_set_table_arch() - set a table to handle arch-specific set + * packets + */ +void set_gdb_gen_set_table_arch(GdbCmdParseEntry *, int size); + +/** + * set_query_supported_arch() - set arch-specific features in qSupported + * features + */ +void set_query_supported_arch(char *); + +/** + * gdb_put_packet() - put string into gdb server's buffer so it is sent + * to the client + */ +int gdb_put_packet(const char *buf); + +#endif /* GDBSTUB_H */ From patchwork Wed May 15 17:31:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 796989 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3101071wra; Wed, 15 May 2024 10:33:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVKsJx4aHkDTqVwW1lXSGYlwvdzlj9qDC0n10Z0Ulcm2DRmkPt2xvWZ6nXo7uofwPJt+CkBBbNezftTx7+OUxo+ X-Google-Smtp-Source: AGHT+IEIhU4u/RKjcAlAJbaUo/Vie3k9PKrjzZkO2Uyi2nS7lhJmkIb4Yy1FgYYjEA99k26bv1Nb X-Received: by 2002:a05:6871:7410:b0:23e:ed07:2d43 with SMTP id 586e51a60fabf-24172bf84d2mr19432489fac.35.1715794431837; Wed, 15 May 2024 10:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715794431; cv=none; d=google.com; s=arc-20160816; b=Q0Z/FLrlq+vtvbzFJO6amvPw5NAHBqc+et/PjoXIph4H/tiZXpRd0QE/1pErTltOfN lb5auxolDqOj+zcggBvxJQl0JYoxzfPvFDIHGVN83tkeHtB3ORe9nkGGQG1D+mBVi7IZ ZU4A997caJwcm0hGii8TM+HmyzkumQKBZq/j6Nlg/J3cdeQeiZ/lRZ8zF43ibsgFBHKU u5z5YaZxynMN5MLIMID8cuuGPPXNb9zCw1Oy/QJBot5ONhTLP+vto8PRxpnVaTxSrlNn kI9rjBXsxRuRDFj4OIe40z5HEuD5zHiFQV53JlLd7pIjFnmgzbiXdY9MWg5HXDrqCzCu AkZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=MookKR+/GmP35DnsiVAP+dRajwJAWlDX42VUKJPxMJA=; fh=ZLVo7h1WCYX+mCQET83n+8bPmyNFw4pMQxFlbH8xyms=; b=T3FKFeqUPBjnD/Ds0cECEntjuxRaa9T8zxrSVIeoRmgaYFtE9/79w9Ro9+SFhNRVgA 6V2EW3l3cp1y8QnR5NKzsdDMqruTFs5mjJgou5mClBB16k4uWWddGDZK+WPyUXC1/5ox oKmGEUlvwof+OX0K+uSD7NrHtwUY5yHJWnGOzzqQbpb9NMzJMpWgW56eEoIkHLTQTWWm dLmplRUZFbtO1PaQe8/y8/3v4UsqMYNyB5s1bS5o1QkKgNq1x1y/rxPvius+8lxnkl3g K9SPdKfY21fIcEeX0shI2LTBf3fPEqMPCNgrIal77rv7Ww25Fd7+QdYDm0e/rp2nGDze iQeQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uy4zcatI; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-43e2cd69fdcsi36047021cf.693.2024.05.15.10.33.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 10:33:51 -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=Uy4zcatI; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7IUU-0005Ew-4V; Wed, 15 May 2024 13:32:34 -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 1s7IUN-0005Dk-Qb for qemu-devel@nongnu.org; Wed, 15 May 2024 13:32:28 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7IUL-0002Lo-Gd for qemu-devel@nongnu.org; Wed, 15 May 2024 13:32:27 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6f6765226d0so863648b3a.3 for ; Wed, 15 May 2024 10:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715794344; x=1716399144; 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=MookKR+/GmP35DnsiVAP+dRajwJAWlDX42VUKJPxMJA=; b=Uy4zcatInChOMXqn6crPWOjGfXXI73UFeU/3firoY/F8Mxiiae4NeghHcjy0GrlRmu CFJjd+S3L0ZODhAn1gln60ngc+JCub1X1Qf+UXD9l9lnjdWz4TlWQXUKJxwGTo+QrWWH IcjF5p/UMZ7lIz6VyRHrbvhV4QuWSJB3d3JL6TrgviwFGCZkpiB2THEFA6h45QpBj4YB XV6RGgi+R9YYKogEKDqlFUp7ZzRJsr7w1zg7EKbtL+uk9c8G+DhRLx0kDBg1LEZ0aPlm opge+2vcqbN4MAH2ffkL8kkFqMclOv5+fue2AWgZM6mXhLWvLMKd3lHohZkImGOkga18 AGtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715794344; x=1716399144; 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=MookKR+/GmP35DnsiVAP+dRajwJAWlDX42VUKJPxMJA=; b=bjjHsYzOlvkvQjeBYdfX7EJ3BOXOGBvUdsniikus6ZCpHkqxsG83nYvPyBlMtjF+V6 8MJujQOXwyaXY9sM9mKEntf3diA81QcCLLOlk1wC9jkERNfgnThZIwcRdbCzyJU7PGS1 2w8dAz4MjwEAz/7f4zS+gYqaxT/J/Bo8EOJ0GbC1jNGh3zG2RHpBD4c3eCrRqjXzx7Mw yNX3B4Pyfp74wau6zl057Mv29e3JFd28xkejuhH1kteUdWeTUHYV6WvdnOep0dFTtJem rOD3+uHryV9D0u/apEZjjSYeFN9kpn/n/acDqzD+FgcBJfwKJ+f+wFRkqbRQGuLM4jd5 t4lw== X-Gm-Message-State: AOJu0YxQdPCA2ulpYlzCZ9DRMrgIHMGAGEtt5rThUsdETA89w9Z65Keg TuWR9QW+ygmUVjKhLh5sA8RG3Y1GhYJzuSUZyGxEZI+uAfdmr6X17A18fdmfHb5qYbzBzC+1SYN D+xc= X-Received: by 2002:a05:6a20:9697:b0:1af:d1b2:4c21 with SMTP id adf61e73a8af0-1afde197972mr15766294637.41.1715794343629; Wed, 15 May 2024 10:32:23 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:224b:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a66c6asm11365133b3a.6.2024.05.15.10.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 10:32:23 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, peter.maydell@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: gustavo.romero@linaro.org Subject: [PATCH 2/4] gdbstub: Add support for MTE in user mode Date: Wed, 15 May 2024 17:31:30 +0000 Message-Id: <20240515173132.2462201-3-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515173132.2462201-1-gustavo.romero@linaro.org> References: <20240515173132.2462201-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This commit implements the stubs to handle the qIsAddressTagged, qMemTag, and QMemTag GDB packets, allowing all GDB 'memory-tag' subcommands to work with QEMU gdbstub on aarch64 user mode. It also implements the get/set function for the special GDB MTE register 'tag_ctl', used to control the MTE fault type at runtime. Signed-off-by: Gustavo Romero --- configs/targets/aarch64-linux-user.mak | 2 +- target/arm/cpu.c | 1 + target/arm/gdbstub.c | 321 +++++++++++++++++++++++++ target/arm/internals.h | 2 + 4 files changed, 325 insertions(+), 1 deletion(-) diff --git a/configs/targets/aarch64-linux-user.mak b/configs/targets/aarch64-linux-user.mak index ba8bc5fe3f..8f0ed21d76 100644 --- a/configs/targets/aarch64-linux-user.mak +++ b/configs/targets/aarch64-linux-user.mak @@ -1,6 +1,6 @@ TARGET_ARCH=aarch64 TARGET_BASE_ARCH=arm -TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml +TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml gdb-xml/aarch64-mte.xml TARGET_HAS_BFLT=y CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 77f8c9c748..29f7b99a88 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2479,6 +2479,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) register_cp_regs_for_features(cpu); arm_cpu_register_gdb_regs_for_features(cpu); + arm_cpu_register_gdb_commands(cpu); init_cpreg_list(cpu); diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index a3bb73cfa7..f3897f75b3 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -474,6 +474,317 @@ static GDBFeature *arm_gen_dynamic_m_secextreg_feature(CPUState *cs, #endif #endif /* CONFIG_TCG */ +#ifdef TARGET_AARCH64 +#ifdef CONFIG_USER_ONLY +static int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, struct _GByteArray *buf, int reg) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + uint64_t tcf0; + + assert(reg == 0); + + /* TCF0, bits [39:38]. */ + tcf0 = extract64(env->cp15.sctlr_el[1], 38, 2); + + return gdb_get_reg64(buf, tcf0); +} + +static int aarch64_gdb_set_tag_ctl_reg(CPUState *cs, uint8_t *buf, int reg) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + + assert(reg == 0); + + /* Sanitize TCF0 bits. */ + *buf &= 0x03; + + if (!isar_feature_aa64_mte3(&cpu->isar) && *buf == 3) { + /* + * If FEAT_MTE3 is not implemented, the value 0b11 is reserved, hence + * ignore setting it. + */ + return 0; + } + + /* + * 'tag_ctl' register is actually a "pseudo-register" provided by GDB to + * expose options that can be controlled at runtime and has the same effect + * of prctl() with option PR_SET_TAGGED_ADDR_CTRL, + * i.e. prctl(PR_SET_TAGGED_ADDR_CTRL, tcf, 0, 0, 0), hence it controls + * the effect of Tag Check Faults (TCF) due to Loads and Stores in EL0. + */ + env->cp15.sctlr_el[1] = deposit64(env->cp15.sctlr_el[1], 38, 2, *buf); + + return 1; +} + +static void handle_q_memtag(GArray *params, G_GNUC_UNUSED void *user_ctx) +{ + uint64_t addr = get_param(params, 0)->val_ull; + uint64_t len = get_param(params, 1)->val_ul; + int type = get_param(params, 2)->val_ul; + + uint64_t clean_addr; + uint8_t *tags; + int granules_index; + int granule_index; + uint8_t addr_tag; + + g_autoptr(GString) str_buf = g_string_new(NULL); + + /* + * GDB does not query tags for a memory range on remote targets, so that's + * not supported either by gdbstub. + */ + if (len != 1) { + gdb_put_packet("E02"); + } + + /* GDB never queries a tag different from an allocation tag (type 1). */ + if (type != 1) { + gdb_put_packet("E02"); + } + + /* Remove any non-addressing bits. */ + clean_addr = useronly_clean_ptr(addr); + + /* + * Get pointer to all tags in the page where the address is. Note that tags + * are packed, so there are 2 tags packed in one byte. + */ + tags = page_get_target_data(clean_addr); + + /* + * Tags are per granule (16 bytes). 2 tags (4 bits each) are kept in a + * single byte for compactness, so first a page tag index for 2 packed + * granule tags (1 byte) is found, and then an index for a single granule + * tag (nibble) is found, and finally the address tag is obtained. + */ + granules_index = extract32(clean_addr, LOG2_TAG_GRANULE + 1, + TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1); + granule_index = extract32(clean_addr, LOG2_TAG_GRANULE, 1); + + addr_tag = *(tags + granules_index); + /* Extract tag from the right nibble. */ + if (granule_index == 0) { + addr_tag &= 0xF; + } else { + addr_tag >>= 4; + } + + g_string_printf(str_buf, "m%.2x", addr_tag); + + gdb_put_packet(str_buf->str); +} + +static void handle_q_isaddresstagged(GArray *params, G_GNUC_UNUSED void *user_ctx) +{ + uint64_t addr = get_param(params, 0)->val_ull; + + uint64_t clean_addr; + int mflags; + + g_autoptr(GString) str_buf = g_string_new(NULL); + + /* Remove any non-addressing bits. */ + clean_addr = useronly_clean_ptr(addr); + + mflags = page_get_flags(clean_addr); + if (mflags & PAGE_ANON && mflags & PAGE_MTE) { + /* Address is tagged. */ + g_string_printf(str_buf, "%.2x", 1 /* true */); + } else { + /* Address is not tagged. */ + g_string_printf(str_buf, "%.2x", 0 /* false */); + } + + gdb_put_packet(str_buf->str); +} + +static void handle_Q_memtag(GArray *params, G_GNUC_UNUSED void *user_ctx) +{ + uint64_t addr = get_param(params, 0)->val_ull; + uint64_t len = get_param(params, 1)->val_ul; + int type = get_param(params, 2)->val_ul; + char const *new_tags = get_param(params, 3)->data; + + uint64_t clean_addr; + int last_addr_index; + + uint64_t start_addr_page; + uint64_t end_addr_page; + + uint32_t first_tag_index; + uint32_t last_tag_index; + + uint8_t *tags; /* Pointer to the current tags in a page. */ + int num_new_tags; + + g_autoptr(GString) str_buf = g_string_new(NULL); + + /* + * Only the allocation tag (type 1) can be set at the stub side. + */ + if (type != 1) { + gdb_put_packet("E02"); + return; + } + + /* + * 'len' is always >= 1 and refers to the size of the memory range about to + * have its tags updated. However, it's convenient to obtain the index for + * the last byte of the memory range for page boundary checks and for + * obtaining the indexes for the tags in the page. + */ + last_addr_index = len - 1; + + /* Remove any non-addressing bits. */ + clean_addr = useronly_clean_ptr(addr); + + start_addr_page = extract64(clean_addr, TARGET_PAGE_BITS, + 64 - TARGET_PAGE_BITS); + end_addr_page = extract64(clean_addr + last_addr_index, TARGET_PAGE_BITS, + 64 - TARGET_PAGE_BITS); + + /* + * Check if memory range is within page boundaries. + */ + if (start_addr_page != end_addr_page) { + gdb_put_packet("E03"); + return; + } + + /* + * Get pointer to all tags in the page where the address is. Note that here + * tags are packed, so there are 2 tags packed in one byte. + */ + tags = page_get_target_data(clean_addr); + + /* Tag indices below refer to unpacked tags. */ + first_tag_index = extract32(clean_addr, LOG2_TAG_GRANULE, + TARGET_PAGE_BITS - LOG2_TAG_GRANULE); + last_tag_index = extract32(clean_addr + last_addr_index, LOG2_TAG_GRANULE, + TARGET_PAGE_BITS - LOG2_TAG_GRANULE); + + /* + * GDB sends 2 hex digits per tag number, i.e. tags are not represented in + * a packed way. + */ + num_new_tags = strlen(new_tags) / 2; + + /* + * If the number of tags provided is greater than the number of tags + * in the provided memory range, the exceeding tags are ignored. If the + * number of tags is less than the number of tags in the provided memory + * range, then the provided tags are used as a repeating pattern to fill + * the tags in the provided memory range. + */ + for (int i = first_tag_index, j = 0; i <= last_tag_index; i++, j++) { + int new_tag_value; + int packed_granules_index; + int nibble_index; + + sscanf(new_tags + 2 * (j % num_new_tags), "%2x", &new_tag_value); + /* + * Find packed tag index from unpacked tag index. There are two tags + * packed in one packed index. One tag per nibble. + */ + packed_granules_index = i / 2; + /* Find nibble index in the packed tag from unpacked tag index. */ + nibble_index = i % 2; + + if (nibble_index == 0) { /* Update low nibble */ + *(tags + packed_granules_index) &= 0xF0; + *(tags + packed_granules_index) |= (new_tag_value & 0x0F); + } else { /* Update high nibble */ + *(tags + packed_granules_index) &= 0x0F; + *(tags + packed_granules_index) |= ((new_tag_value & 0x0F) << 4); + } + } + + g_string_printf(str_buf, "OK"); + + gdb_put_packet(str_buf->str); +} + +enum Packet { + qMemTags, + qIsAddressTagged, + QMemTags, + NUM_PACKETS +}; + +static GdbCmdParseEntry packet_handler_table[NUM_PACKETS] = { + [qMemTags] = { + .handler = handle_q_memtag, + .cmd_startswith = 1, + .cmd = "MemTags:", + .schema = "L,l:l0" + }, + [qIsAddressTagged] = { + .handler = handle_q_isaddresstagged, + .cmd_startswith = 1, + .cmd = "IsAddressTagged:", + .schema = "L0" + }, + [QMemTags] = { + .handler = handle_Q_memtag, + .cmd_startswith = 1, + .cmd = "MemTags:", + .schema = "L,l:l:s0" + }, +}; + +static void add_packet_handler(GArray *handlers, enum Packet packet) { + g_array_append_val(handlers, packet_handler_table[packet]); +} +#endif /* CONFIG_USER_ONLY */ +#endif /* TARGET_AARCH64 */ + +void arm_cpu_register_gdb_commands(ARMCPU *cpu) +{ + GArray *gdb_gen_query_table_arm = + g_array_new(FALSE, FALSE, sizeof(GdbCmdParseEntry)); + GArray *gdb_gen_set_table_arm = + g_array_new(FALSE, FALSE, sizeof(GdbCmdParseEntry)); + GString *supported_features = g_string_new(NULL); + +#ifdef TARGET_AARCH64 +#ifdef CONFIG_USER_ONLY + /* MTE */ + if (isar_feature_aa64_mte(&cpu->isar)) { + g_string_append(supported_features, ";memory-tagging+"); + + add_packet_handler(gdb_gen_query_table_arm, qMemTags); + add_packet_handler(gdb_gen_query_table_arm, qIsAddressTagged); + + add_packet_handler(gdb_gen_set_table_arm, QMemTags); + } +#endif +#endif + + /* Set arch-specific handlers for 'q' commands. */ + if (gdb_gen_query_table_arm->len) { + set_gdb_gen_query_table_arch(&g_array_index(gdb_gen_query_table_arm, + GdbCmdParseEntry, 0), + gdb_gen_query_table_arm->len); + } + + /* Set arch-specific handlers for 'Q' commands. */ + if (gdb_gen_set_table_arm->len) { + set_gdb_gen_set_table_arch(&g_array_index(gdb_gen_set_table_arm, + GdbCmdParseEntry, 0), + gdb_gen_set_table_arm->len); + } + + /* Set arch-specific qSupported feature. */ + if (supported_features->len) { + set_query_supported_arch(supported_features->str); + } +} + void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) { CPUState *cs = CPU(cpu); @@ -507,6 +818,16 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) gdb_find_static_feature("aarch64-pauth.xml"), 0); } + +#ifdef CONFIG_USER_ONLY + /* Memory Tagging Extension (MTE) 'tag_ctl' register. */ + if (isar_feature_aa64_mte(&cpu->isar)) { + gdb_register_coprocessor(cs, aarch64_gdb_get_tag_ctl_reg, + aarch64_gdb_set_tag_ctl_reg, + gdb_find_static_feature("aarch64-mte.xml"), + 0); + } +#endif #endif } else { if (arm_feature(env, ARM_FEATURE_NEON)) { diff --git a/target/arm/internals.h b/target/arm/internals.h index ee3ebd383e..3750591b44 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -358,6 +358,8 @@ void init_cpreg_list(ARMCPU *cpu); void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu); void arm_translate_init(void); +void arm_cpu_register_gdb_commands(ARMCPU *cpu); + void arm_restore_state_to_opc(CPUState *cs, const TranslationBlock *tb, const uint64_t *data); From patchwork Wed May 15 17:31:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 796991 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3101171wra; Wed, 15 May 2024 10:34:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVVa0+iRuoMrx9H3+6Ch08yjga+khLd1wStFa8r7xfReD1sL7fomKZ/jAdHXbd0vFx0IHZpmShH8zf4u8163Bp9 X-Google-Smtp-Source: AGHT+IFxasNTrI70RcQplwPyJFmYdCGvSjTd6OSJdDDmf1sQ/2okJu7zSz6sZBYa+YgkKOU65aoi X-Received: by 2002:a05:620a:4905:b0:792:c243:3270 with SMTP id af79cd13be357-792c7577b4dmr1850745785a.7.1715794450002; Wed, 15 May 2024 10:34:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715794449; cv=none; d=google.com; s=arc-20160816; b=UNMw6dQ8d0CgN93P0Xu0179f5nWG0YNH4dNc9ZhISvsgibIXMM3/1sQJAlxU30DAnJ Leh47YQr7HRWSJL2cabedoEs15txGdR+0iXFEkjcdwcP8hT6MyU5WtCfgcnUNKkdu67r nMRzOVMcCJOcAnHrVdF+r9KLFGw27AO2ijewudK+BREUs2fNAFzUdd5ysy95rMN5Sp9d Rxu908wQ2stsIAPnv8YlwpKoJkKkEeNg2OAwU3HiGrjMfhryWjbh2nfGfe3ak/IG+/q5 pmh0t7ZfKWK7U8UBlghAGLaoLLIJR6latE7OnfT/Pl+JWWhvO9QbuiK8dPixLP7Qnedv xX/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=esogItfSZKIjFBvKzqHcGNPz5akAvaVQY8PX5DqLKHw=; fh=ZLVo7h1WCYX+mCQET83n+8bPmyNFw4pMQxFlbH8xyms=; b=S5xMc7zE8r8vk8kBXalvM0YyP7k5sTW7+mczV3FCVKL2sk+/S9TTRK8ERqGQS/SOnq Pndy85siSCg/BILXjFxytHyE99ZfzjX5htXL8dJ8TY+yKmV6j2gs5lPzRZYRI3WFkLWJ sbev0EnmA8Xe7LckQ3sCl8p6MOaCl7jS/Dtd5/xjj1hZ13vM3qRbl/9/p9msW+IJI/7u HrZTf2v6OU3Zx2WrvgLN/e/DeDKo5cr9llzvOV6og+etyGpQwCkSmuglNcq4cra/hhrK lasjNI2pc3ei2pKfgi4LIgayUVUCyqvmtLoYIPaK34Pvsfg1rwtmaDO24LkfTCu4DMdp WbAA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uWsVhxja; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-792bf365b92si1402523485a.662.2024.05.15.10.34.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 10:34:09 -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=uWsVhxja; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7IUU-0005F1-AZ; Wed, 15 May 2024 13:32:34 -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 1s7IUQ-0005EU-RV for qemu-devel@nongnu.org; Wed, 15 May 2024 13:32:31 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7IUO-0002PU-EC for qemu-devel@nongnu.org; Wed, 15 May 2024 13:32:30 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6f449ea8e37so6127838b3a.3 for ; Wed, 15 May 2024 10:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715794347; x=1716399147; 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=esogItfSZKIjFBvKzqHcGNPz5akAvaVQY8PX5DqLKHw=; b=uWsVhxja3h2c9ptnbQkIHAUsNjvfcazb0kqweIxSuC3Gb1nsYvZCqf2Lyt/r+7whKx C1e/k8lOQ503PllrcmYuWyO8hJKcb5HrnN3i1CyZtw+9pFYhcAxbMUlJNJpsZnwrCanu T0vAojFlaFfv03kk/2iBXmjbQthNxowyZ6o9s9jlUVF5NlmeZ8gUjlDByJUSFqomUoB/ 4bw/DOCz/XvDLwIj45PpZ02/KoWYk8AP3LcgpJ8Pj/1vmXijVO9IW/9+EmactQl/1eeC RHXv6gNvb8DOZj/NvGO1bE/PUndFmt3NA1YBhw8s3XWjiVUjPOVpziD7d43NzwJYfUSq Q9Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715794347; x=1716399147; 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=esogItfSZKIjFBvKzqHcGNPz5akAvaVQY8PX5DqLKHw=; b=M13uP7gYncc1DdMW9q9IZjzRONZqAF45qfEHPiFrGaodjTJybWs7pi5ZKfibFTBzyA mmP+iYJagF+1eZD15s78rHLIiKPtloScMzfF9B2C+nj8Hny5VbakDSZ//6HbB9fhChf/ ESgQwJOPVBViqpYMXR/XqfEzW98jlcqpmqFliplS2AyC2dMpZwQ+T5YmBt+J7OhUvagG WRlwciB3qK3EU8ucULbjpBnBsEVXuvj4xpW16ieKHdvTuOPIsjQBnJuWnmJI3K8s/lF8 4dy60yY8cVhTnfAfYS6S4IPG2SkMJ2wrB+QxW4aLHSJSxg19vyeWxwTThZxKqge/6SsY rmwA== X-Gm-Message-State: AOJu0YxCRYwL4+xqFq2gwMRfSJSq8FFpmRE9Ya9mbxkLrHA9fhgX3NyN zPtjD9aJqC2JLrIZW5UJiW93OEODfSTp7CjWTJPKNMEjXpip1/q2+Fn6vLd7yhWsCc+EISNFMYT ovcI= X-Received: by 2002:a05:6a00:1990:b0:6ed:de86:be57 with SMTP id d2e1a72fcca58-6f4e034850dmr26472314b3a.25.1715794346786; Wed, 15 May 2024 10:32:26 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:224b:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a66c6asm11365133b3a.6.2024.05.15.10.32.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 10:32:25 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, peter.maydell@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: gustavo.romero@linaro.org Subject: [PATCH 3/4] tests: Gently exit from GDB when tests complete Date: Wed, 15 May 2024 17:31:31 +0000 Message-Id: <20240515173132.2462201-4-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515173132.2462201-1-gustavo.romero@linaro.org> References: <20240515173132.2462201-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x42b.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 GDB commit a207f6b3a38 ('Rewrite "python" command exception handling') changed how exit() called from Python scripts loaded by GDB behave, turning it into an exception instead of a generic error code that is returned. This change caused several QEMU tests to crash with the following exception: Python Exception : 0 Error occurred in Python: 0 This happens because in tests/guest-debug/test_gdbstub.py exit is called after the tests have completed. This commit fixes it by politely asking GDB to exit via gdb.execute, passing the proper fail_count to be reported to 'make', instead of abruptly calling exit() from the Python script. Signed-off-by: Gustavo Romero Reviewed-by: Philippe Mathieu-Daudé --- tests/guest-debug/test_gdbstub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/guest-debug/test_gdbstub.py b/tests/guest-debug/test_gdbstub.py index 7f71d34da1..46fbf98f0c 100644 --- a/tests/guest-debug/test_gdbstub.py +++ b/tests/guest-debug/test_gdbstub.py @@ -57,4 +57,4 @@ def main(test, expected_arch=None): pass print("All tests complete: {} failures".format(fail_count)) - exit(fail_count) + gdb.execute(f"exit {fail_count}") From patchwork Wed May 15 17:31:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 796990 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3101150wra; Wed, 15 May 2024 10:34:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWp4OjIXS6xTVBH+nBonMN2sO6U4lysPtudppoV6RxYcTg7YyczQ7DfJ9vf+sXki/yzWdE/r42rr1Wnkokab8wd X-Google-Smtp-Source: AGHT+IGE3SUztbUDTbNYaK7NM2LRgIOR6ZL1hyGUFHpCr4cWBpCZKmkb2qwX53aoaFrcaPQPhkfp X-Received: by 2002:a05:6808:343:b0:3c8:6223:c7bc with SMTP id 5614622812f47-3c997025c9emr20134777b6e.7.1715794446339; Wed, 15 May 2024 10:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715794446; cv=none; d=google.com; s=arc-20160816; b=KQG7tAY9lw9QZ+aQy4ENMotsV1YKA5itMsNghu1U6emQzyUsYgQaChL0eQM0dLyvfV ICPxBRKpgcCUMzbNEeMuHVAzSSPTKq2Swxs2Vj+a20wmTwrj94SkcrD69RhPaed6SKcg 85eYaHf8wUwg5PJmwcfqICjltdyX+7+vUx4nIpND15GxDFgrubvgK4HVSdA8WppfiJMs arApgCh64spl9DbZPLKpqcJsn4+2LaRKVlveZd1eq+XX0qxRr/RoqTIK+F76rbrnBFh8 5XlQHkITP5jL5CMvUrKRv8QiaWQwX3k4T8HBFe6+UmSy/kjBEXBK2JfxDKky66zoR+6i YA4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=yk+ySqx2GWVrBg6FqHG2e9b1M5JzmHbk4G1MUS+6KS8=; fh=ZLVo7h1WCYX+mCQET83n+8bPmyNFw4pMQxFlbH8xyms=; b=YLTgaqZgqG3NXHEuw1CPFgQK0HlQeVnImNvbljsYhW/RsMmd0GvGrKwax5QYitG4zu HVSvUVwQqIyFJpDSsPoafVyyezlAKKP67U+prY637dXQTCFJF5w79pgcAUdIbjifJMnn AcRjpfTNVw9aC5Td0gJAPhKu8UZobeybm8Cvl9h/bx1VCLdMzLv/FL0S6OKWXBqetiV7 3hnw78CN8G2pd7jzUHaFYCU1LDGzGmfwU8uI5KjUUxWg99rZuInd674FQz0JOcU1rowm DNQTY+zZ6xAsxDGDFXM0Bf2EhDzTwGV9p+9uIcvwbEX2jCb8k/P6ecxepuhQUEZK6dK7 p+Ig==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QzqEA9Wa; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-792d2f65856si964170985a.307.2024.05.15.10.34.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 10:34: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=QzqEA9Wa; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7IUX-0005Fk-Tz; Wed, 15 May 2024 13:32:37 -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 1s7IUU-0005Ex-41 for qemu-devel@nongnu.org; Wed, 15 May 2024 13:32:34 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7IUR-0002Qi-VG for qemu-devel@nongnu.org; Wed, 15 May 2024 13:32:33 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6f44d2b3130so5953626b3a.2 for ; Wed, 15 May 2024 10:32:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715794350; x=1716399150; 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=yk+ySqx2GWVrBg6FqHG2e9b1M5JzmHbk4G1MUS+6KS8=; b=QzqEA9WaJ0mM4XUjLXERKJ42QKuJ9SMuNZMzkmOu6GLw+qJCX5Hlgukj1LHuI7pId+ d03/lCX/yCZVHEDUG9O/ScmSj6aCCQggatAta6LA47nhz/YQKVJgUwLlT1EeDa67dbcd C1D4/biVjMEvpt7evAtziGVb4nZXv374PtE5TnFEk1SRHHzTEXnoKcz5a0jHX/xpesjl x3jWLqkIClus4norGC/NlGbEmAFdAgMRQvtSJL1mjMLKLbfT6kRR+KruBF9KI3/z1G5w 4s+3Du2w7Ey65Iun3ALv1TiHKKmkl8gXhXfhNTIxzw4hr+xl9G2m8sVwlRVxuMjUV6HA ryng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715794350; x=1716399150; 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=yk+ySqx2GWVrBg6FqHG2e9b1M5JzmHbk4G1MUS+6KS8=; b=fVZsiYzht3FLucG1JvwsVhQKLhEzg3fYnmWFpK+oCTSrWwvCBO/G81ZlgACgxB4fy/ Zre8nuDAA3RUJ9/3WCmpZCADHXWkEvZ+E1f1QL3wx3djxafl1AL7wi6lDPU6GeCr3Iu8 9rLPXBo6wGdAMuKrrUNEExH/v2Ua4b0k5QvVFNGhdnRg38ANtYm3WanK+/Af9e7rmmIT riyqpPqT7g14AsvmqEWp2bPZeY5xJfQYAwh1o/ER2e6D8cF/aFT+nUzkJwK5MIpzrYX9 nG2oPFwGXSjAQ7AGMrljNpjdITM3tpOLmbAZs11Pq7Qk1qgdItQ8RIIOwMWsXtY3bjlX aehg== X-Gm-Message-State: AOJu0YxfGBmbQm4j8jmYSMDP3OZKECSPUT6JMb8wm1UgiWAXbeI8bDwU SnrpsgAWEZoVmsiT4RwcYZzoM199MF+5WNxNDA2rBBpY0AnyiVIo3cpSoAaA2ELO0EBhWsM86gn pnVQ= X-Received: by 2002:a05:6a00:3994:b0:6f4:3b76:ebf7 with SMTP id d2e1a72fcca58-6f4e02db452mr16724323b3a.20.1715794349751; Wed, 15 May 2024 10:32:29 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:224b:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a66c6asm11365133b3a.6.2024.05.15.10.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 10:32:29 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, peter.maydell@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: gustavo.romero@linaro.org Subject: [PATCH 4/4] tests/tcg/aarch64: Add MTE gdbstub tests Date: Wed, 15 May 2024 17:31:32 +0000 Message-Id: <20240515173132.2462201-5-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515173132.2462201-1-gustavo.romero@linaro.org> References: <20240515173132.2462201-1-gustavo.romero@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Add tests to exercise the MTE stubs. Signed-off-by: Gustavo Romero --- tests/tcg/aarch64/Makefile.target | 11 ++- tests/tcg/aarch64/gdbstub/test-mte.py | 86 ++++++++++++++++++++++ tests/tcg/aarch64/mte-8.c | 102 ++++++++++++++++++++++++++ 3 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/aarch64/gdbstub/test-mte.py create mode 100644 tests/tcg/aarch64/mte-8.c diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target index 70d728ae9a..d2e3f251eb 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -62,7 +62,7 @@ AARCH64_TESTS += bti-2 # MTE Tests ifneq ($(CROSS_CC_HAS_ARMV8_MTE),) -AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4 mte-5 mte-6 mte-7 +AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4 mte-5 mte-6 mte-7 mte-8 mte-%: CFLAGS += -march=armv8.5-a+memtag endif @@ -127,7 +127,14 @@ run-gdbstub-sve-ioctls: sve-ioctls --bin $< --test $(AARCH64_SRC)/gdbstub/test-sve-ioctl.py, \ basic gdbstub SVE ZLEN support) -EXTRA_RUNS += run-gdbstub-sysregs run-gdbstub-sve-ioctls +run-gdbstub-mte: mte-8 + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(GDB) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin "$< -s" --test $(AARCH64_SRC)/gdbstub/test-mte.py, \ + gdbstub MTE support) + +EXTRA_RUNS += run-gdbstub-sysregs run-gdbstub-sve-ioctls run-gdbstub-mte endif endif diff --git a/tests/tcg/aarch64/gdbstub/test-mte.py b/tests/tcg/aarch64/gdbstub/test-mte.py new file mode 100644 index 0000000000..6530f33ad8 --- /dev/null +++ b/tests/tcg/aarch64/gdbstub/test-mte.py @@ -0,0 +1,86 @@ +from __future__ import print_function +# +# Test GDB memory-tag commands that exercise the stubs for the qIsAddressTagged, +# qMemTag, and QMemTag packets. Logical tag-only commands rely on local +# operations, hence don't exercise any stub. +# +# The test consists in breaking just after a atag() call (which sets the +# allocation tag -- see mte-8.c for details) and setting/getting tags in +# different memory locations and ranges starting at the address of the array +# 'a'. +# +# This is launched via tests/guest-debug/run-test.py +# + + +import gdb +import re +from test_gdbstub import main, report + + +PATTERN_0 = "Memory tags for address 0x[0-9a-f]+ match \(0x[0-9a-f]+\)." +PATTERN_1 = ".*(0x[0-9a-f]+)" + + +def run_test(): + gdb.execute("break 94", False, True) + gdb.execute("continue", False, True) + try: + # Test if we can check correctly that the allocation tag for + # array 'a' matches the logical tag after atag() is called. + co = gdb.execute("memory-tag check a", False, True) + tags_match = re.findall(PATTERN_0, co, re.MULTILINE) + if tags_match: + report(True, "Logical and allocation tags match.") + else: + report(False, "Logical and allocation tags don't match!") + + # Test allocation tag 'set and print' commands. Commands on logical + # tags rely on local operation and so don't exercise any stub. + + # Set the allocation tag for the first granule (16 bytes) of + # address starting at 'a' address to a known value, i.e. 0x04. + gdb.execute("memory-tag set-allocation-tag a 1 04", False, True) + + # Then set the allocation tag for the second granule to a known + # value, i.e. 0x06. This tests that contiguous tag granules are + # set correct and don't run over each other. + gdb.execute("memory-tag set-allocation-tag a+16 1 06", False, True) + + # Read the known values back and check if they remain the same. + + co = gdb.execute("memory-tag print-allocation-tag a", False, True) + first_tag = re.match(PATTERN_1, co)[1] + + co = gdb.execute("memory-tag print-allocation-tag a+16", False, True) + second_tag = re.match(PATTERN_1, co)[1] + + if first_tag == "0x4" and second_tag == "0x6": + report(True, "Allocation tags are correctly set/printed.") + else: + report(False, "Can't set/print allocation tags!") + + # Now test fill pattern by setting a whole page with a pattern. + gdb.execute("memory-tag set-allocation-tag a 4096 0a0b", False, True) + + # And read back the tags of the last two granules in page so + # we also test if the pattern is set correctly up to the end of + # the page. + co = gdb.execute("memory-tag print-allocation-tag a+4096-32", False, True) + tag = re.match(PATTERN_1, co)[1] + + co = gdb.execute("memory-tag print-allocation-tag a+4096-16", False, True) + last_tag = re.match(PATTERN_1, co)[1] + + if tag == "0xa" and last_tag == "0xb": + report(True, "Fill pattern is ok.") + else: + report(False, "Fill pattern failed!") + + except gdb.error: + # This usually happens because a GDB version that does not + # support memory tagging was used to run the test. + report(False, "'memory-tag' command failed!") + + +main(run_test, expected_arch="aarch64") diff --git a/tests/tcg/aarch64/mte-8.c b/tests/tcg/aarch64/mte-8.c new file mode 100644 index 0000000000..367768e6b6 --- /dev/null +++ b/tests/tcg/aarch64/mte-8.c @@ -0,0 +1,102 @@ +/* + * To be compiled with -march=armv8.5-a+memtag + * + * This test is adapted from a Linux test. Please see: + * + * https://www.kernel.org/doc/html/next/arch/arm64/memory-tagging-extension.html#example-of-correct-usage + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* + * From arch/arm64/include/uapi/asm/hwcap.h + */ +#define HWCAP2_MTE (1 << 18) + +/* + * From arch/arm64/include/uapi/asm/mman.h + */ +#define PROT_MTE 0x20 + +/* + * Insert a random logical tag into the given pointer. + */ +#define insert_random_tag(ptr) ({ \ + uint64_t __val; \ + asm("irg %0, %1" : "=r" (__val) : "r" (ptr)); \ + __val; \ +}) + +/* + * Set the allocation tag on the destination address. + */ +#define set_tag(tagged_addr) do { \ + asm volatile("stg %0, [%0]" : : "r" (tagged_addr) : "memory"); \ +} while (0) + + +int main(int argc, char *argv[]) +{ + unsigned char *a; + unsigned long page_sz = sysconf(_SC_PAGESIZE); + unsigned long hwcap2 = getauxval(AT_HWCAP2); + + if (!(argc == 2 && strcmp(argv[1], "-s") == 0)) { + return 0; + } + + /* check if MTE is present */ + if (!(hwcap2 & HWCAP2_MTE)) + return EXIT_FAILURE; + + /* + * Enable the tagged address ABI, synchronous or asynchronous MTE + * tag check faults (based on per-CPU preference) and allow all + * non-zero tags in the randomly generated set. + */ + if (prctl(PR_SET_TAGGED_ADDR_CTRL, + PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC | PR_MTE_TCF_ASYNC | + (0xfffe << PR_MTE_TAG_SHIFT), + 0, 0, 0)) { + perror("prctl() failed"); + return EXIT_FAILURE; + } + + a = mmap(0, page_sz, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (a == MAP_FAILED) { + perror("mmap() failed"); + return EXIT_FAILURE; + } + + printf("a[] address is %p\n", a); + + /* + * Enable MTE on the above anonymous mmap. The flag could be passed + * directly to mmap() and skip this step. + */ + if (mprotect(a, page_sz, PROT_READ | PROT_WRITE | PROT_MTE)) { + perror("mprotect() failed"); + return EXIT_FAILURE; + } + + /* access with the default tag (0) */ + a[0] = 1; + a[1] = 2; + + printf("a[0] = %hhu a[1] = %hhu\n", a[0], a[1]); + + /* set the logical and allocation tags */ + a = (unsigned char *)insert_random_tag(a); + set_tag(a); + + printf("%p\n", a); + + return 0; +}