From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id 6FAC9398B85E for ; Wed, 27 Jan 2021 20:21:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6FAC9398B85E Received: by mail-qk1-x72e.google.com with SMTP id d85so3095819qkg.5 for ; Wed, 27 Jan 2021 12:21:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BP/EuPsESxXU2wWsPOu/pXEpgin2ofoeksbdnBN3r1g=; b=gJCeoNrtqO9ZjZvP084pjlPRSave0NLbILC4WsUFC8YZIzG435U2BbgAA/gmLLvo2v 0/wKCD7kTG2Z6m1y46KxHAcBGz87ksmVu5Drjqidt2ZECtDxha2MsWeqxBDPzpzpxHZL dJRpjw+HT8ShMVHyJNctrKRsc53HEyWpmbU665mQ2P6Lab3jI6i1kILbSYHSC1KP3UZ+ qWBkUcwQK3FbBM8+QEVYbvWeX5VWTLsjtzNg5uCtsNLi4mNZUMi5pdEFx9ul14tpoYn0 dDMPX+Abg+znTsqSNrZjL55YXdn0TAhcsMND5n2p4HjPc6ZmjscABT77P4QLhK0ucZ/o ZIRg== X-Gm-Message-State: AOAM531aksdwMh11lHgW/xhhh6PhAaE7XEfi3nJ3HQwyPRrTQute88JO 09WBxmZtAGwatH5m651Rr31aHqp92/HFhw== X-Google-Smtp-Source: ABdhPJxDYTojo0tpm60qgEBnffHlNG/slP5M4A5tgBWqjCPJSXtHULfNfYahX0uTrANdpDnMSe46gw== X-Received: by 2002:a37:ec8:: with SMTP id 191mr12255244qko.480.1611778906378; Wed, 27 Jan 2021 12:21:46 -0800 (PST) Received: from localhost.localdomain ([2804:7f0:8284:874d:b82c:87fc:4324:adab]) by smtp.gmail.com with ESMTPSA id b194sm1854531qkc.102.2021.01.27.12.21.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 12:21:46 -0800 (PST) From: Luis Machado To: gdb-patches@sourceware.org Subject: [PATCH v5 18/25] AArch64: Add gdbserver MTE support Date: Wed, 27 Jan 2021 17:21:05 -0300 Message-Id: <20210127202112.2485702-19-luis.machado@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127202112.2485702-1-luis.machado@linaro.org> References: <20210127202112.2485702-1-luis.machado@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.4 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jan 2021 20:21:48 -0000 Updates on v4: - Updated return types. - Fixed alphabetical order of files. - Use enum instead of magic integers. Updates on v2: - Updated target methods to contain a tag type parameter. -- Adds the AArch64-specific memory tagging support (MTE) by implementing the required hooks and checks for GDBserver. gdbserver/ChangeLog: YYYY-MM-DD Luis Machado * Makefile.in (SFILES): Add /../gdb/nat/aarch64-mte-linux-ptrace.c. * configure.srv (aarch64*-*-linux*): Add arch/aarch64-mte-linux.o and nat/aarch64-mte-linux-ptrace.o. * linux-aarch64-low.cc: Include nat/aarch64-mte-linux-ptrace.h. (class aarch64_target) : New method overrides. (aarch64_target::supports_memory_tagging) (aarch64_target::fetch_memtags) (aarch64_target::store_memtags): New methods. --- gdbserver/Makefile.in | 1 + gdbserver/configure.srv | 2 ++ gdbserver/linux-aarch64-low.cc | 61 ++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in index a14d3a7bc1..00370d55a3 100644 --- a/gdbserver/Makefile.in +++ b/gdbserver/Makefile.in @@ -229,6 +229,7 @@ SFILES = \ $(srcdir)/../gdb/arch/arm-linux.c \ $(srcdir)/../gdb/arch/ppc-linux-common.c \ $(srcdir)/../gdb/arch/riscv.c \ + $(srcdir)/../gdb/nat/aarch64-mte-linux-ptrace.c \ $(srcdir)/../gdb/nat/aarch64-sve-linux-ptrace.c \ $(srcdir)/../gdb/nat/linux-btrace.c \ $(srcdir)/../gdb/nat/linux-namespaces.c \ diff --git a/gdbserver/configure.srv b/gdbserver/configure.srv index 833ad27c4c..2dd8f75a4e 100644 --- a/gdbserver/configure.srv +++ b/gdbserver/configure.srv @@ -52,7 +52,9 @@ case "${gdbserver_host}" in srv_tgtobj="$srv_tgtobj nat/aarch64-linux.o" srv_tgtobj="$srv_tgtobj arch/aarch64-insn.o" srv_tgtobj="$srv_tgtobj arch/aarch64.o" + srv_tgtobj="$srv_tgtobj arch/aarch64-mte-linux.o" srv_tgtobj="$srv_tgtobj linux-aarch64-tdesc.o" + srv_tgtobj="$srv_tgtobj nat/aarch64-mte-linux-ptrace.o" srv_tgtobj="$srv_tgtobj nat/aarch64-sve-linux-ptrace.o" srv_tgtobj="${srv_tgtobj} $srv_linux_obj" srv_linux_regsets=yes diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index a066d963a5..daccfef746 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -43,6 +43,7 @@ #include "arch/aarch64-mte-linux.h" #include "linux-aarch32-tdesc.h" #include "linux-aarch64-tdesc.h" +#include "nat/aarch64-mte-linux-ptrace.h" #include "nat/aarch64-sve-linux-ptrace.h" #include "tdesc.h" @@ -50,6 +51,10 @@ #include #endif +#ifdef HAVE_GETAUXVAL +#include +#endif + /* Linux target op definitions for the AArch64 architecture. */ class aarch64_target : public linux_process_target @@ -82,6 +87,14 @@ public: struct emit_ops *emit_ops () override; + bool supports_memory_tagging () override; + + bool fetch_memtags (CORE_ADDR address, size_t len, + gdb::byte_vector &tags, int type) override; + + bool store_memtags (CORE_ADDR address, size_t len, + const gdb::byte_vector &tags, int type) override; + protected: void low_arch_setup () override; @@ -3223,6 +3236,54 @@ aarch64_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr) return arm_breakpoint_kind_from_current_state (pcptr); } +/* Returns true if memory tagging is supported. */ +bool +aarch64_target::supports_memory_tagging () +{ + if (current_thread == NULL) + { + /* We don't have any processes running, so don't attempt to + use linux_get_hwcap2 as it will try to fetch the current + thread id. Instead, just fetch the auxv from the self + PID. */ +#ifdef HAVE_GETAUXVAL + return (getauxval (AT_HWCAP2) & HWCAP2_MTE) != 0; +#else + return true; +#endif + } + + return (linux_get_hwcap2 (8) & HWCAP2_MTE) != 0; +} + +bool +aarch64_target::fetch_memtags (CORE_ADDR address, size_t len, + gdb::byte_vector &tags, int type) +{ + /* Allocation tags are per-process, so any tid is fine. */ + int tid = lwpid_of (current_thread); + + /* Allocation tag? */ + if (type == static_cast (aarch64_memtag_type::mte_allocation)) + return aarch64_mte_fetch_memtags (tid, address, len, tags); + + return false; +} + +bool +aarch64_target::store_memtags (CORE_ADDR address, size_t len, + const gdb::byte_vector &tags, int type) +{ + /* Allocation tags are per-process, so any tid is fine. */ + int tid = lwpid_of (current_thread); + + /* Allocation tag? */ + if (type == static_cast (aarch64_memtag_type::mte_allocation)) + return aarch64_mte_store_memtags (tid, address, len, tags); + + return false; +} + /* The linux target ops object. */ linux_process_target *the_linux_target = &the_aarch64_target; -- 2.25.1