From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6DnMG6RNDmaMySIAWB0awg (envelope-from ) for ; Thu, 04 Apr 2024 02:50:12 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=MRVtVSzw; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6DB5E1E0C0; Thu, 4 Apr 2024 02:50:12 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5EF691E08C for ; Thu, 4 Apr 2024 02:50:10 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 20CB43846059 for ; Thu, 4 Apr 2024 06:50:10 +0000 (GMT) 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-Google-Smtp-Source: AGHT+IE4odNxtSl2VZIY72KuXtNGP8dZgBAr9Rx1SjdiXBod3UGJeDgG8ezu+6C0PF9Gy4e5LdYo8A== 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 Content-Transfer-Encoding: 8bit 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+public-inbox=simark.ca@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. */ { -- 2.34.1