From nobody Sun Apr 12 13:49:30 2026 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1715794388; cv=none; d=zohomail.com; s=zohoarc; b=nu/eBY7QAjd8THp130Ds12BCRUVkfQtofMyK7+gxgvRzEgsJwhcuEIrYhanQPtI8Jv+5H3WeKEZ4CN0TNZJOFRMR75apUd4nBHnnWo3e08UUUdACfcGnpANwKuEem32bxqxv4muSuKPMTk/M+cQXqXjXKeXxSUTzP5EpEEhIGPg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715794388; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vcj2Py+dn09bF4yGtRILmfWfVgmwYYBz6rwT+Eir1qs=; b=iK4wu4G7hPQUzpvaeHJqIBknJyXo6cU7dF1CaLdStfUJMpu7r4dN3ZD4vkdk8ta9klV/2SLbd9BVm1QK7yYg4gj17h3h0xnlmefGcRNaWM1r6VKTnUqyDHnsm1r+VlCn8Jx3nKXXUhs8UsN5Mf73M4bU5TtfTPd4Kq8HZkoNWt0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715794388343577.4521691237176; Wed, 15 May 2024 10:33:08 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IEDkHDCKafzHLNZkL0ho5FbmdMhCQOpDkgzzOTLQyfGrDcY9VG2mrqDiRiYeIoY4VQ+tQ2YMg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1715794389511100004 Content-Type: text/plain; charset="utf-8" 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=C3=A9 --- 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 ch= ar *schema, return 0; } =20 -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 wi= th 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#Sto= p-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 (",;:=3D\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(); } =20 +/* Arch-specific qSupported */ +char *query_supported_arch =3D NULL; +void set_query_supported_arch(char *query_supported) +{ + query_supported_arch =3D 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, v= oid *user_ctx) } =20 g_string_append(gdbserver_state.str_buf, ";vContSupported+;multiproces= s+"); + + if (query_supported_arch) { + g_string_append(gdbserver_state.str_buf, query_supported_arch); + } + gdb_put_strbuf(); } =20 @@ -1765,6 +1740,16 @@ static const GdbCmdParseEntry gdb_gen_query_set_comm= on_table[] =3D { }, }; =20 + +/* Arch-specific query table */ +static GdbCmdParseEntry *gdb_gen_query_table_arch =3D NULL ; +static int gdb_gen_query_table_arch_size =3D 0; +void set_gdb_gen_query_table_arch(GdbCmdParseEntry *table, int size) +{ + gdb_gen_query_table_arch =3D table; + gdb_gen_query_table_arch_size =3D size; +} + static const GdbCmdParseEntry gdb_gen_query_table[] =3D { { .handler =3D handle_query_curr_tid, @@ -1857,6 +1842,15 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = =3D { #endif }; =20 +/* Arch-specific set table */ +static GdbCmdParseEntry *gdb_gen_set_table_arch =3D NULL; +static int gdb_gen_set_table_arch_size =3D 0; +void set_gdb_gen_set_table_arch(GdbCmdParseEntry *table, int size) +{ + gdb_gen_set_table_arch =3D table; + gdb_gen_set_table_arch_size =3D size; +} + static const GdbCmdParseEntry gdb_gen_set_table[] =3D { /* Order is important if has same prefix */ { @@ -1889,17 +1883,27 @@ static void handle_gen_query(GArray *params, void *= user_ctx) return; } =20 - 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)) =3D= =3D 0) { return; } =20 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)) =3D=3D 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) =3D=3D 0) { + return; + } + + /* Can't handle query, return Empty response. */ + gdb_put_packet(""); } =20 static void handle_gen_set(GArray *params, void *user_ctx) @@ -1908,17 +1912,27 @@ static void handle_gen_set(GArray *params, void *us= er_ctx) return; } =20 - 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)) =3D= =3D 0) { return; } =20 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)) =3D=3D 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) =3D=3D 0) { + return; + } + + /* Can't handle set, return Empty response. */ + gdb_put_packet(""); } =20 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) */ =20 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); =20 -typedef enum GDBThreadIdKind { - GDB_ONE_THREAD =3D 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" =20 /* 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[]; =20 -#endif +typedef void (*GdbCmdHandler)(GArray *params, void *user_ctx); + +typedef enum GDBThreadIdKind { + GDB_ONE_THREAD =3D 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 wi= th 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#Sto= p-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 (",;:=3D\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 qu= ery + * 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 */ --=20 2.34.1 From nobody Sun Apr 12 13:49:30 2026 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1715794431; cv=none; d=zohomail.com; s=zohoarc; b=A3XRPzLPCWRcVD1A8cRC+3NNQ0ESFiNq9LMTQvbNUQw9qimbRsx8hKS9BLUgSRGqePECBT2t/lwEU+HuMXzr6LD8pepDd4BAhAf+EvSg0SUQlv9k0EWVKq3A7JVTKoN5IwLECCq4TDSEyc2HsBTkV99iP0My83KfXiAXZ+iiais= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715794431; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MookKR+/GmP35DnsiVAP+dRajwJAWlDX42VUKJPxMJA=; b=ZxnDtC3RqPjUfrt95zMcq25hSyijvSQV4vf/uokB23ND3UZ5o3seq/LEbKUEFDjDotDufYpuDNkpn456MPaZOL4sJMn93sgOiQ6z2JeVDm4b8KowAOwaew24+oC52jKVWoKDA7iPrsen9LVi5JJRv6afiWn9g5D2i/fPEc3mGwU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715794431508921.7229691807028; Wed, 15 May 2024 10:33:51 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IG3AycnlZJFGNJFhJsPVK1ZuT6WhEtAjwuk3isCdUooMDI0Kk9BnhptbN+JBaD7Cq/kKX5Atw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1715794433421100001 Content-Type: text/plain; charset="utf-8" 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/aarch= 64-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=3Daarch64 TARGET_BASE_ARCH=3Darm -TARGET_XML_FILES=3D gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-x= ml/aarch64-pauth.xml +TARGET_XML_FILES=3D gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-x= ml/aarch64-pauth.xml gdb-xml/aarch64-mte.xml TARGET_HAS_BFLT=3Dy CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy 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) =20 register_cp_regs_for_features(cpu); arm_cpu_register_gdb_regs_for_features(cpu); + arm_cpu_register_gdb_commands(cpu); =20 init_cpreg_list(cpu); =20 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_featur= e(CPUState *cs, #endif #endif /* CONFIG_TCG */ =20 +#ifdef TARGET_AARCH64 +#ifdef CONFIG_USER_ONLY +static int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, struct _GByteArray *b= uf, int reg) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + uint64_t tcf0; + + assert(reg =3D=3D 0); + + /* TCF0, bits [39:38]. */ + tcf0 =3D 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 =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + + assert(reg =3D=3D 0); + + /* Sanitize TCF0 bits. */ + *buf &=3D 0x03; + + if (!isar_feature_aa64_mte3(&cpu->isar) && *buf =3D=3D 3) { + /* + * If FEAT_MTE3 is not implemented, the value 0b11 is reserved, he= nce + * 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 e= ffect + * 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] =3D 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 =3D get_param(params, 0)->val_ull; + uint64_t len =3D get_param(params, 1)->val_ul; + int type =3D 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 =3D g_string_new(NULL); + + /* + * GDB does not query tags for a memory range on remote targets, so th= at's + * not supported either by gdbstub. + */ + if (len !=3D 1) { + gdb_put_packet("E02"); + } + + /* GDB never queries a tag different from an allocation tag (type 1). = */ + if (type !=3D 1) { + gdb_put_packet("E02"); + } + + /* Remove any non-addressing bits. */ + clean_addr =3D 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 =3D 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 gran= ule + * tag (nibble) is found, and finally the address tag is obtained. + */ + granules_index =3D extract32(clean_addr, LOG2_TAG_GRANULE + 1, + TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1); + granule_index =3D extract32(clean_addr, LOG2_TAG_GRANULE, 1); + + addr_tag =3D *(tags + granules_index); + /* Extract tag from the right nibble. */ + if (granule_index =3D=3D 0) { + addr_tag &=3D 0xF; + } else { + addr_tag >>=3D 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 *u= ser_ctx) +{ + uint64_t addr =3D get_param(params, 0)->val_ull; + + uint64_t clean_addr; + int mflags; + + g_autoptr(GString) str_buf =3D g_string_new(NULL); + + /* Remove any non-addressing bits. */ + clean_addr =3D useronly_clean_ptr(addr); + + mflags =3D 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 =3D get_param(params, 0)->val_ull; + uint64_t len =3D get_param(params, 1)->val_ul; + int type =3D get_param(params, 2)->val_ul; + char const *new_tags =3D 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 =3D g_string_new(NULL); + + /* + * Only the allocation tag (type 1) can be set at the stub side. + */ + if (type !=3D 1) { + gdb_put_packet("E02"); + return; + } + + /* + * 'len' is always >=3D 1 and refers to the size of the memory range a= bout 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 =3D len - 1; + + /* Remove any non-addressing bits. */ + clean_addr =3D useronly_clean_ptr(addr); + + start_addr_page =3D extract64(clean_addr, TARGET_PAGE_BITS, + 64 - TARGET_PAGE_BITS); + end_addr_page =3D 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 !=3D 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 =3D page_get_target_data(clean_addr); + + /* Tag indices below refer to unpacked tags. */ + first_tag_index =3D extract32(clean_addr, LOG2_TAG_GRANULE, + TARGET_PAGE_BITS - LOG2_TAG_GRANULE); + last_tag_index =3D extract32(clean_addr + last_addr_index, LOG2_TAG_GR= ANULE, + TARGET_PAGE_BITS - LOG2_TAG_GRANULE); + + /* + * GDB sends 2 hex digits per tag number, i.e. tags are not represente= d in + * a packed way. + */ + num_new_tags =3D 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 memo= ry + * range, then the provided tags are used as a repeating pattern to fi= ll + * the tags in the provided memory range. + */ + for (int i =3D first_tag_index, j =3D 0; i <=3D 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 ta= gs + * packed in one packed index. One tag per nibble. + */ + packed_granules_index =3D i / 2; + /* Find nibble index in the packed tag from unpacked tag index. */ + nibble_index =3D i % 2; + + if (nibble_index =3D=3D 0) { /* Update low nibble */ + *(tags + packed_granules_index) &=3D 0xF0; + *(tags + packed_granules_index) |=3D (new_tag_value & 0x0F); + } else { /* Update high nibble */ + *(tags + packed_granules_index) &=3D 0x0F; + *(tags + packed_granules_index) |=3D ((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] =3D { + [qMemTags] =3D { + .handler =3D handle_q_memtag, + .cmd_startswith =3D 1, + .cmd =3D "MemTags:", + .schema =3D "L,l:l0" + }, + [qIsAddressTagged] =3D { + .handler =3D handle_q_isaddresstagged, + .cmd_startswith =3D 1, + .cmd =3D "IsAddressTagged:", + .schema =3D "L0" + }, + [QMemTags] =3D { + .handler =3D handle_Q_memtag, + .cmd_startswith =3D 1, + .cmd =3D "MemTags:", + .schema =3D "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 =3D + g_array_new(FALSE, FALSE, sizeof(GdbCmdParseEntry)); + GArray *gdb_gen_set_table_arm =3D + g_array_new(FALSE, FALSE, sizeof(GdbCmdParseEntry)); + GString *supported_features =3D 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_ar= m, + GdbCmdParseEntry, 0), + gdb_gen_query_table_ar= m->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 =3D CPU(cpu); @@ -507,6 +818,16 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cp= u) gdb_find_static_feature("aarch64-paut= h.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); =20 +void arm_cpu_register_gdb_commands(ARMCPU *cpu); + void arm_restore_state_to_opc(CPUState *cs, const TranslationBlock *tb, const uint64_t *data); --=20 2.34.1 From nobody Sun Apr 12 13:49:30 2026 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1715794450; cv=none; d=zohomail.com; s=zohoarc; b=WsnTdtiIkb8E1YBieMCsUvSYG94M7yd40x8D1F3f9ex822qX5KSFgk5RRTPuwBU9SH8qchjqU52K4tt4HxDtRxukXLQcFCicJrL980rN7sxtFjwPqlbANLCeUamZFj9VGqufZpng7Q0MxlNlB8pf+hElwyx89lOTdqExtEzZXro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715794450; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=esogItfSZKIjFBvKzqHcGNPz5akAvaVQY8PX5DqLKHw=; b=P/XX+A+/82xS0sfSz+H69b1O454Y+qz9uFUYNFfFpeK7TnrmKEl+nKqoVTnyUQC4dXI3Hukz1u0JmhtNdyh6hUdxMUlVYBs1esua37bBVGd3RydpIHDHJVS28RfCsDlVhyy0GvnYdJzi+g3p04/Wr17aQsvMbnBaF8yVsSDnxVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715794450355564.7376454545225; Wed, 15 May 2024 10:34:10 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IFl06oazkiytVtHbCQh4bBqaIT+7e7oFHNX7sVqgEygqIAb9rkXj+2fPtLsqJRgKoMBbePTIw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1715794451455100001 Content-Type: text/plain; charset="utf-8" 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=C3=A9 --- 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_gdb= stub.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=3DNone): pass =20 print("All tests complete: {} failures".format(fail_count)) - exit(fail_count) + gdb.execute(f"exit {fail_count}") --=20 2.34.1 From nobody Sun Apr 12 13:49:30 2026 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1715794446; cv=none; d=zohomail.com; s=zohoarc; b=ayZjfuXQrJsbj0HvedpcYESG7KO1IaSm24vDlJHKrvy52MktQcBxLTIUSa2Jzh/9G8HuzUHHeIn7of4VCo11MbrQMNTJIkUn5xGGIvShW9QvS6ZCHaQa7PhFdsF4h3Z8hTVVMqG8eBQ2EwtURaW43UhalRBWNJuKvbCGYcIVIWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715794446; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yk+ySqx2GWVrBg6FqHG2e9b1M5JzmHbk4G1MUS+6KS8=; b=VkupJHKQPqpIjKsNIt1DJy+aSA4fkLWzATjuvkBNK6Yp7xWt2uwhHCCFPD6tzYVlXdKNNlmgTNxH1qppVpaTlSASdNNfAWEDQ6sSbCjDT9v+1ABql+eWJG0Z+bMAj1m4U4FqO0E79CYlmcP3KCK9sQLYUIYf/eEDDK11bwvKVlo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715794446525973.9237281193577; Wed, 15 May 2024 10:34:06 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IE5KBa0NAt9ILd9epLkCMpE25x6hBD9IWfzhSIiA0gh/toURLx0YkCa/0TCFBDVIOQm7nVWEg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1715794447433100001 Content-Type: text/plain; charset="utf-8" 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 +=3D bti-2 =20 # MTE Tests ifneq ($(CROSS_CC_HAS_ARMV8_MTE),) -AARCH64_TESTS +=3D mte-1 mte-2 mte-3 mte-4 mte-5 mte-6 mte-7 +AARCH64_TESTS +=3D mte-1 mte-2 mte-3 mte-4 mte-5 mte-6 mte-7 mte-8 mte-%: CFLAGS +=3D -march=3Darmv8.5-a+memtag endif =20 @@ -127,7 +127,14 @@ run-gdbstub-sve-ioctls: sve-ioctls --bin $< --test $(AARCH64_SRC)/gdbstub/test-sve-ioctl.py, \ basic gdbstub SVE ZLEN support) =20 -EXTRA_RUNS +=3D 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 +=3D run-gdbstub-sysregs run-gdbstub-sve-ioctls run-gdbstub-mte endif endif =20 diff --git a/tests/tcg/aarch64/gdbstub/test-mte.py b/tests/tcg/aarch64/gdbs= tub/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 qIsAddressT= agged, +# 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 arr= ay +# 'a'. +# +# This is launched via tests/guest-debug/run-test.py +# + + +import gdb +import re +from test_gdbstub import main, report + + +PATTERN_0 =3D "Memory tags for address 0x[0-9a-f]+ match \(0x[0-9a-f]+\)." +PATTERN_1 =3D ".*(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 =3D gdb.execute("memory-tag check a", False, True) + tags_match =3D 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 =3D gdb.execute("memory-tag print-allocation-tag a", False, Tru= e) + first_tag =3D re.match(PATTERN_1, co)[1] + + co =3D gdb.execute("memory-tag print-allocation-tag a+16", False, = True) + second_tag =3D re.match(PATTERN_1, co)[1] + + if first_tag =3D=3D "0x4" and second_tag =3D=3D "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, Tr= ue) + + # 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 =3D gdb.execute("memory-tag print-allocation-tag a+4096-32", Fa= lse, True) + tag =3D re.match(PATTERN_1, co)[1] + + co =3D gdb.execute("memory-tag print-allocation-tag a+4096-16", Fa= lse, True) + last_tag =3D re.match(PATTERN_1, co)[1] + + if tag =3D=3D "0xa" and last_tag =3D=3D "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=3D"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=3Darmv8.5-a+memtag + * + * This test is adapted from a Linux test. Please see: + * + * https://www.kernel.org/doc/html/next/arch/arm64/memory-tagging-extensio= n.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" : "=3Dr" (__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 =3D sysconf(_SC_PAGESIZE); + unsigned long hwcap2 =3D getauxval(AT_HWCAP2); + + if (!(argc =3D=3D 2 && strcmp(argv[1], "-s") =3D=3D 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 =3D mmap(0, page_sz, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (a =3D=3D 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] =3D 1; + a[1] =3D 2; + + printf("a[0] =3D %hhu a[1] =3D %hhu\n", a[0], a[1]); + + /* set the logical and allocation tags */ + a =3D (unsigned char *)insert_random_tag(a); + set_tag(a); + + printf("%p\n", a); + + return 0; +} --=20 2.34.1