From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id EI5hKFqf7F8ACwAAWB0awg (envelope-from ) for ; Wed, 30 Dec 2020 10:40:10 -0500 Received: by simark.ca (Postfix, from userid 112) id 3B3581F0B7; Wed, 30 Dec 2020 10:40:09 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 77C3F1F075 for ; Wed, 30 Dec 2020 10:40:03 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4D46388E812; Wed, 30 Dec 2020 15:40:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4D46388E812 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609342802; bh=0fUihQExVNgzCMuzrgyRIUybS7QpIQD+Q4eGvISHjp8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=pUtsrRMB7v78QlTBRIWrEEpDoUq1HefjNoUtF6xQEJGcbHZWh/QAioNOSLHbJFJF5 dPawZlx/tcE2ES9h71oSOSCZbeHA5NowytFGFagZHNE60XXlz+M7HXf6Yeg24FB2d4 W0VxfDOt/oGROz9Q7PSNPgJF1/sihf0XHw/TVVGA= Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by sourceware.org (Postfix) with ESMTPS id 63E5B388C023 for ; Wed, 30 Dec 2020 15:40:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 63E5B388C023 Received: by mail-qt1-x82b.google.com with SMTP id c14so11168665qtn.0 for ; Wed, 30 Dec 2020 07:40:00 -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:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0fUihQExVNgzCMuzrgyRIUybS7QpIQD+Q4eGvISHjp8=; b=CzEdw7j0uG2lAYM39bmot7fpVZx6M1MN0vLsdVYPpBGv25bj2w5QgVJGPnbGUw458u qz9SapjlFaqQES00+z/w0GRgEo8O+XRzHc8G4ScWTBM2DusbF87HNKDSOPQMhzvsrF6G jGCM4HsTTZuiD6dk4GXkFL5tIc7EPuDOR/vgIt3ox/8dkra0duFO/Cmfe5DwDtgvEPx8 2yxViZSNhoZypZ3Sn9p/uGsOn17U7wcq4T00zZ11Pk5v7kL8MuxuPn5ssSodHNhTp5xw m+BfVkjPp/uZOIul2ZrAfOqeIIUDUgR6hYvyXefxsFRh6bpAWPPvGM6zkSKMAgUez05r IWKA== X-Gm-Message-State: AOAM533RyMCxg70GMdm/qUy2pg6JUWS6NudDdtjnV2Ato3y6W5jJhiGz kjM/POWnl2qqKsLeYnq3aFkqETnptXUrFQ== X-Google-Smtp-Source: ABdhPJx2ArVwffJEKEN4PT4rdNsxgbrohTqRhwkvNZTSDWnc9gJQPW4AnqOqFtOY8jkNeTCuo5HNTw== X-Received: by 2002:aed:2c66:: with SMTP id f93mr54427525qtd.14.1609342799815; Wed, 30 Dec 2020 07:39:59 -0800 (PST) Received: from localhost.localdomain ([2804:7f0:8284:370e:c9ba:c4ec:737b:57da]) by smtp.gmail.com with ESMTPSA id f6sm28589336qkh.2.2020.12.30.07.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:39:59 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCH v4 18/25] AArch64: Add gdbserver MTE support Date: Wed, 30 Dec 2020 12:39:09 -0300 Message-Id: <20201230153916.1586725-19-luis.machado@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201230153916.1586725-1-luis.machado@linaro.org> References: <20201230153916.1586725-1-luis.machado@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , From: Luis Machado via Gdb-patches Reply-To: Luis Machado Cc: david.spickett@linaro.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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 e12848c1ce..d51d7083cd 100644 --- a/gdbserver/Makefile.in +++ b/gdbserver/Makefile.in @@ -220,6 +220,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 b1e591af47..0ef0eaebf1 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