From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ED6eBy75d2HLYgAAWB0awg (envelope-from ) for ; Tue, 26 Oct 2021 08:48:46 -0400 Received: by simark.ca (Postfix, from userid 112) id 0FFC51F0BF; Tue, 26 Oct 2021 08:48:46 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,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 3D7EF1EDDB for ; Tue, 26 Oct 2021 08:48:45 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E93E385843F for ; Tue, 26 Oct 2021 12:48:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E93E385843F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635252524; bh=7DOEjC21qHBGpSfmajzJk3GqXAeDJuVWUlmEoMNcWUY=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=lUKdyI0E25wwBbELfaKIjjNX4QguWE2N0ZskuAoeob4nenIVLFc7gpPQ/X50BBKTG TAzT6jcBkuamH8U5b4YFaX/XF9iMY+HMu/wx0sDGZQmGUgmToDg3bKD11qKT33ulo6 QFOQgGQ6B/VOaXO56dRoYiyIdwyeGX/JA3JNOBbU= Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id 592153858038 for ; Tue, 26 Oct 2021 12:46:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 592153858038 Received: by mail-oi1-x22c.google.com with SMTP id s9so20389650oiw.6 for ; Tue, 26 Oct 2021 05:46:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=7DOEjC21qHBGpSfmajzJk3GqXAeDJuVWUlmEoMNcWUY=; b=camdDQp7VA7du65GNje4EjsHcvtnnDCwcZE4OMBqLC0XHjFbbNfXcAM2ODYi7piI+w uWxCO7z+hO0TKC21U1CppJSPeH5V6aBmiHXdkC3Ixq40tMQFl8MwiLtVvNxBrOHgMylu ffPI7I64aVNcw5OmXZFa6S2+SvoNTr+VC9NIB7I0f34+N4r+sSHaTBluQaUTQXAxmJJ0 hBO7BuLlCVVeB56FTTpcP3aan71KO00MJ58ecZoUefRWBLdWqk6DxXAJAbv2w0S8vS2/ 9hutSsW2l9T11+UWwZ9e+i/c8RQOmKI0h43mMzaxXYl+vbE3aozyik1CRIH0Sj8Okxpf p2kQ== X-Gm-Message-State: AOAM530agdHqH6Asj3g+VHYYV5mltZ4oGtVzmOF3X5omyTqXfDAD0c1k Cgp8bPOemhId/tYleqGMXTS1Mg== X-Google-Smtp-Source: ABdhPJyYe8LmZbIV3PJI/HknIIQ0uhsMh+Wg+gB47H+zMkWDG3Wt5jjGNsUf4yC06h3QTEKgWLsPiQ== X-Received: by 2002:aca:2406:: with SMTP id n6mr16695788oic.28.1635252416662; Tue, 26 Oct 2021 05:46:56 -0700 (PDT) Received: from ?IPv6:2804:7f0:4841:3c03:7012:cad0:f2ca:8851? ([2804:7f0:4841:3c03:7012:cad0:f2ca:8851]) by smtp.gmail.com with ESMTPSA id e22sm4410794otp.0.2021.10.26.05.46.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Oct 2021 05:46:56 -0700 (PDT) Subject: Re: [PATCH] AArch64 pauth: Indicate addresses in backtrace for kernel To: Kuan-Ying Lee , gdb-patches@sourceware.org References: <20211025114705.32548-1-Kuan-Ying.Lee@mediatek.com> Message-ID: Date: Tue, 26 Oct 2021 09:46:52 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20211025114705.32548-1-Kuan-Ying.Lee@mediatek.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: james.hsu@mediatek.com, nicholas.tang@mediatek.com, zhiyong.wang@mediatek.com, chinwen.chang@mediatek.com Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi! Second time's the charm. On 10/25/21 8:47 AM, Kuan-Ying Lee via Gdb-patches wrote: > Armv8.3-a Pointer Authentication cause the function return address to > be changed. GDB need to use address bit[55] to know which mode is active > and mask/unmask the link register in order to get backtrace. > > If address is in kernel mode, we mask the address. If address is in user mode, > we need to unmask the address. > --- > gdb/aarch64-tdep.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c > index 4b5af4616af..d4bb4305cea 100644 > --- a/gdb/aarch64-tdep.c > +++ b/gdb/aarch64-tdep.c > @@ -257,7 +257,10 @@ aarch64_frame_unmask_lr (struct gdbarch_tdep *tdep, > { > int cmask_num = AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base); > CORE_ADDR cmask = frame_unwind_register_unsigned (this_frame, cmask_num); > - addr = addr & ~cmask; > + if (addr & 0x0080000000000000ULL) I think we should define this constant in aarch64-tdep.h to make it more obvious: #define AARCH64_PAC_VA_RANGE_BIT 55 #define AARCH64_PAC_VA_RANGE_MASK (1ULL << AARCH64_PAC_VA_RANGE_BIT) > + addr = addr | cmask; > + else > + addr = addr & ~cmask; For the unmasking of the address, it would be nice to put this into a separate function that unmasks an address given a particular mask value. Something like this: static CORE_ADDR aarch64_unmask_address (CORE_ADDR address, CORE_ADDR mask) { /* Unmask kernel mode and user mode addresses appropriately based on the VA range bit. */ if (address & AARCH64_PAC_VA_RANGE_MASK) address | mask; else address & ~mask; return address; } If we ever need to unmask kernel/user addresses somewhere else in the code, we can just call this function from now on. Could you please send a v2 of the patch with the suggested changes? Thanks for the patch.