From patchwork Thu Apr 4 06:48:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 785814 Delivered-To: patch@linaro.org Received: by 2002:adf:f001:0:b0:33e:7753:30bd with SMTP id j1csp684858wro; Wed, 3 Apr 2024 23:50:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUGnsvvhCpM+flcK3FlgS02/xwCwEoIcnEh7T1uiqD3hghALWcLgTohSumoY1I0uqhT2SFJHprwugDLj5MdIlhW X-Google-Smtp-Source: AGHT+IFYX2Lehpq5MduLRgMXXSCaxZkSNUx1kmyucL/ezh2vPCyIpgXcGulpxEa/PwUq/665/T1n X-Received: by 2002:a05:620a:2908:b0:78b:e896:d6dd with SMTP id m8-20020a05620a290800b0078be896d6ddmr2181348qkp.44.1712213421838; Wed, 03 Apr 2024 23:50:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712213421; cv=pass; d=google.com; s=arc-20160816; b=Cwg1FupviJyszvqFaRrm6hYlKlJ1PwzarfsyS+gaJCYxOFUcTyLuAwBGtn9QUkBigT eBrSuls21fRLQowCsmmbdezcPk7ZcwWEMI7TG5dBeKUdef6XzEW1K/bGz48LHljJnKf9 EvHMkKjboPYEHVDBPieaXvGn/DSRKAcxjR/ZecpEBEXv+kPwASY+RIttpL56YWLsYnxd 9NwXTTw1RsyVbxt/l5pT1NcZSrk7N3u/75vy5Aps0TY2WhIXLZTNdtUXUe7GGi6nGOQW hIdbHX9omdUftqLCKReSiPo0YlN+SKlfKNW6XrwVkIFsQJOybIJapeMXZdc3H+zu2Hsn bSIg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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:arc-filter:dmarc-filter:delivered-to; bh=9HZMYDqkUwPT4I03LFdl2g+FeiecaWvFzIFhBbXjTuA=; fh=ip7+QkkM488k9wyzFaZPu3h7BUQARzj44zdeG2KNIXU=; b=Fu0yzpFbzOZeu05dVFfJRd1dV1SyHaUDBkhPXqiYcCtV8AQxeuk1gcmUK+YWoVuK17 9XnUjictkq+l8mikzwGz1aKjucz2/UGGnIwNHNmfg8zvQfqaNuaVoAZgQx4ejOeqcgfr 89ZYTXXhXH8fXbykd4lZhClKE6FQQHctc63N7rks7S2yiCdC7IG3Loc2V1PPfDwPFDPE 2D1tyZC4baVn1Q8BuWiOpd+7bwUNe0ZrlZ4RGeC01+zkMgMuB8oXpPT6VBN59Xyla7Qu kNFm/T66yvSOaML/k63idbuI1wwdXsJYLYXowvsOP890tosE3hNKrDF5z3EZgMRiJNba q2bQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MRVtVSzw; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f2-20020ae9ea02000000b0078a5ed3ccc7si1805757qkg.518.2024.04.03.23.50.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 23:50:21 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MRVtVSzw; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 702BC3858402 for ; Thu, 4 Apr 2024 06:50:21 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id B659F3858C78 for ; Thu, 4 Apr 2024 06:48:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B659F3858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B659F3858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::22d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712213340; cv=none; b=GjDqD5IvprCBjyyjXo4jge0GydZPhiCgpl4KqCAqDViIUMoRvaSdcL/9//AYnHteuNTMAQL7iPzp1axO/NxVKprtIPqfBy/qHHqqo6svGJZ5ShV7tazEqOTG1S6r7zL8I1Jpa563bFDFfmxyIgu5Bvg4O7bE4EyFIU4WjmPw/f4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712213340; c=relaxed/simple; bh=RvB+lC1m3hkqCZBVtyKqnaR5Y+gsr0I7EO/5NWNjmEY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=VcvjAMAQFHMuHlRHB1laTOntAWhZN7Yn9+zR4SZe4SBZhxZbJzbL2PyVPu7aiD+pfI7yE/Zc3WTuRoyWqTdVN5/9r8BY+iC7cGcG5sHAv7C18HwLSKQCBHUOaw8ZIcFFG+LqtR9I2KpEoMmH6zoX/5K8/Tx2hwI+20mhHpAHDFo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3c3d7e7402dso469541b6e.1 for ; Wed, 03 Apr 2024 23:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712213336; x=1712818136; darn=sourceware.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=9HZMYDqkUwPT4I03LFdl2g+FeiecaWvFzIFhBbXjTuA=; b=MRVtVSzwIkHChaTkpPumPmiKzCw+XQf+q1/6d2eIRMxJicTd2LHsBEA3v3xD9W6G9H LfmdaHuWBthwhPFG/9HZK1d61HvVEQlGTenjtCdewA6keTMMuRy+j73ZfeV9uClFLAJW OYZMgMiGumAJ4jvFWkgI5cZ9ScW2ZLgbnkbZlf7x2NScNIM49VrK5cyXOFfqjgd5haOx l2btAhZm3Qf9sId9Fup9dZua3SWK6jqAyFDjZ8v11X63rby5SxBQiHeGgpyPvWuEUudI 1JHbIhVSDx6gqXFMYNY9Y3lzI8kVZoHI2xgmAK9FVz4cCgWBGFY1bggsppwv8zrSLsle k3gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712213336; x=1712818136; 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=9HZMYDqkUwPT4I03LFdl2g+FeiecaWvFzIFhBbXjTuA=; b=Vc0t3ciuSymiIXXrSgogqaKRkIBjKerG0v/O3TNu6RvuRVWyJNOxbwTX5Zb1HRYcuI tmxHbV/AK7LMTu49B9XA8blVQ593dA+EMUKSmhGPizgmtgUWZlz8OSAdJD88cUJt1QQ+ 9pT6y690Jl8WYUj9fMO3ug9NQiSOW8zM3DAkFWkJ/j3xVehsZNQnf+pCK9oTI6facnkg bmD1n4yhs5c0xKU2UhNt0B1j45hv7hGETc+QPlkGf4e3c9OSyyCm+hLwUN9p5P3sOS8C QXT3tM0yMk/TGKrxJ/3E8cZU4Adu1utBR0UtFyf15P5eX2lED51zjl+Fmb6NevmE+tpa K1WA== X-Gm-Message-State: AOJu0Yy4z7NgIiU0Pdb8R1NbRj5ebwJmzXvWv1N0FiZPIGx/LfVyArCR D4FVFFSSfh3sdMyvA9OPpqrDhwy4tv4UNeEMrSbMnD9MKzkQBCJSfNyi3QSZ4izKnCcm7qYF3iZ + X-Received: by 2002:a05:6808:13c9:b0:3c3:72ec:cb60 with SMTP id d9-20020a05680813c900b003c372eccb60mr1792640oiw.49.1712213336590; Wed, 03 Apr 2024 23:48:56 -0700 (PDT) Received: from amd.. ([2804:7f0:b402:d0dc:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id n16-20020aa79850000000b006e64ddfa71asm13218899pfq.170.2024.04.03.23.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 23:48:56 -0700 (PDT) From: Gustavo Romero To: gdb-patches@sourceware.org Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v3 6/7] gdb: Add qMemTagAddrCheck packet Date: Thu, 4 Apr 2024 06:48:18 +0000 Message-Id: <20240404064819.2848899-7-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240404064819.2848899-1-gustavo.romero@linaro.org> References: <20240404064819.2848899-1-gustavo.romero@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patch=linaro.org@sourceware.org This commit adds a new packet, qMemTagAddrCheck, allowing GDB remote targets to use it to query the stub if a given address is tagged. It also adds a new GDB remote feature, 'memory-tagging-check-addr', which must be advertised by the GDB stub to inform it can reply to memory tagging address checks via the new qMemTagCheckAddr packet. Currently, the memory tagging address check is done via a read query, where the contents of /proc//smaps is read and the flags are inspected for memory tagging-related flags that indicate the address is in a memory tagged region. This is not ideal, for example, for QEMU stub and other cases, such as on bare-metal, where there is no notion of an OS file like 'smaps.' Hence, the qMemTagCheckAddr packet allows checking addresses in an OS-agnostic way. The is_address_tagged target hook in remote.c uses the qMemTagCheckAddr packet to check an address if the stub advertises the 'memory-tagging-check-add+' feature, otherwise it falls back to using the current mechanism, which reads the contents of /proc//smaps via vFile requests. Signed-off-by: Gustavo Romero --- gdb/remote.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/gdb/remote.c b/gdb/remote.c index 9717db55e27..94ac8520740 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -337,6 +337,9 @@ enum { packets and the tag violation stop replies. */ PACKET_memory_tagging_feature, + /* Support checking if an address is tagged via qMemTagCheckAddr packet. */ + PACKET_memory_tagging_check_addr_feature, + PACKET_MAX }; @@ -758,6 +761,10 @@ struct remote_features bool remote_memory_tagging_p () const { return packet_support (PACKET_memory_tagging_feature) == PACKET_ENABLE; } + bool remote_memory_tagging_check_addr_p () const + { return packet_support (PACKET_memory_tagging_check_addr_feature) == + PACKET_ENABLE; } + /* Reset all packets back to "unknown support". Called when opening a new connection to a remote target. */ void reset_all_packet_configs_support (); @@ -5764,6 +5771,8 @@ static const struct protocol_feature remote_protocol_features[] = { { "no-resumed", PACKET_DISABLE, remote_supported_packet, PACKET_no_resumed }, { "memory-tagging", PACKET_DISABLE, remote_supported_packet, PACKET_memory_tagging_feature }, + { "memory-tagging-check-addr", PACKET_DISABLE, remote_supported_packet, + PACKET_memory_tagging_check_addr_feature }, }; static char *remote_support_xml; @@ -5875,6 +5884,10 @@ remote_target::remote_query_supported () != AUTO_BOOLEAN_FALSE) remote_query_supported_append (&q, "memory-tagging+"); + if (m_features.packet_set_cmd_state (PACKET_memory_tagging_check_addr_feature) + != AUTO_BOOLEAN_FALSE) + remote_query_supported_append (&q, "memory-tagging-check-addr+"); + /* Keep this one last to work around a gdbserver <= 7.10 bug in the qSupported:xmlRegisters=i386 handling. */ if (remote_support_xml != NULL @@ -15534,6 +15547,21 @@ create_store_memtags_request (gdb::char_vector &packet, CORE_ADDR address, strcpy (packet.data (), request.c_str ()); } +static void +create_is_address_tagged_request (gdb::char_vector &packet, CORE_ADDR address) +{ + int addr_size; + std::string request; + + addr_size = gdbarch_addr_bit (current_inferior ()->arch()) / 8; + request = string_printf ("qMemTagCheckAddr:%s", phex_nz (address, addr_size)); + + if (packet.size () < request.length () + 1) + error (_("Contents too big for packet qMemTagCheckAddr.")); + + strcpy (packet.data (), request.c_str ()); +} + /* Implement the "fetch_memtags" target_ops method. */ bool @@ -15580,7 +15608,27 @@ remote_target::store_memtags (CORE_ADDR address, size_t len, bool remote_target::is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) { - return gdbarch_tagged_address_p (gdbarch, address); + struct remote_state *rs = get_remote_state (); + + if (!m_features.remote_memory_tagging_check_addr_p ()) + /* Fallback to arch-specific method of checking whether an address is + tagged. */ + return gdbarch_tagged_address_p (gdbarch, address); + + create_is_address_tagged_request (rs->buf, address); + + putpkt (rs->buf); + getpkt (&rs->buf); + + /* Check if reply is OK. */ + if (packet_check_result (rs->buf).status () != PACKET_OK) + return false; + + gdb_byte tagged_addr; + /* Convert only 2 hex digits, i.e. 1 byte in hex format. */ + hex2bin (rs->buf.data (), &tagged_addr , 1); + + return tagged_addr != 0; } /* Return true if remote target T is non-stop. */ @@ -16066,6 +16114,10 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL, add_packet_config_cmd (PACKET_memory_tagging_feature, "memory-tagging-feature", "memory-tagging-feature", 0); + add_packet_config_cmd (PACKET_memory_tagging_check_addr_feature, + "memory-tagging-check-addr-feature", + "memory-tagging-check-addr-feature", 0); + /* Assert that we've registered "set remote foo-packet" commands for all packet configs. */ {