From patchwork Fri Mar 22 12:06:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 31939 Received: (qmail 29538 invoked by alias); 22 Mar 2019 12:06:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 29525 invoked by uid 89); 22 Mar 2019 12:06:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, MIME_BASE64_BLANKS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=5018 X-HELO: EUR04-VI1-obe.outbound.protection.outlook.com Received: from mail-eopbgr80040.outbound.protection.outlook.com (HELO EUR04-VI1-obe.outbound.protection.outlook.com) (40.107.8.40) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 Mar 2019 12:06:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Wm9mk9mHqic16IhwMS6F5Es13FF1Kjnqt7qi5Nye70A=; b=QwBZ2oM97GpAsofCnUgvZkAQhEmV7CNFzdRSI6Fb1ruAEyrbZhCWKa5D35R+8SVhUxbRDqWnPdlO4XkHP3MrtIaRE7TyNRKGDZ/+ye2Ua8p7PmYdWW79Ya1xG2iJaledVLtilWFaP21jAXAmHpqcT3PBouHZSeUg3e83QZYqyDw= Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com (10.172.227.22) by DB6PR0802MB2216.eurprd08.prod.outlook.com (10.172.227.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.16; Fri, 22 Mar 2019 12:06:02 +0000 Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::2083:2d62:84fa:a547]) by DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::2083:2d62:84fa:a547%3]) with mapi id 15.20.1730.013; Fri, 22 Mar 2019 12:06:02 +0000 From: Alan Hayward To: Simon Marchi CC: "gdb-patches@sourceware.org" , nd Subject: Re: [PATCH v2 2/8] AArch64: Use HWCAP to detect pauth feature Date: Fri, 22 Mar 2019 12:06:02 +0000 Message-ID: <2D3B7D5F-55C6-40B4-A84C-29139BD18208@arm.com> References: <20190306133325.2531-1-alan.hayward@arm.com> <20190306133325.2531-3-alan.hayward@arm.com> In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 Content-ID: <1E603B95F33AF44C9AC41D628DF2D771@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-IsSubscribed: yes > On 21 Mar 2019, at 20:50, Simon Marchi wrote: > > On 2019-03-06 8:33 a.m., Alan Hayward wrote: >> Add aarch64_get_hwcap functions for reading the HWCAP. >> From this extract the PACA value and use this to enable pauth. >> gdb/ChangeLog: >> >> + > > I don't know if it actually matters, but when the target_aux_search call was in aarch64_linux_core_read_description, it used the TARGET parameter, rather than using current_top_target. So, perhaps that new function should take a target_ops parameter and use it? The other call in aarch64_linux_nat_target::read_description would pass "this”. For safety I’ve updated it to pass through the target. > > And this function does nothing AArch64-specific, so I think it would be nice to have it in linux-tdep.{h,c} and update other arches to use it. But I would say, don't bother with that in this series, we can do it after. > > Simon Agreed. And the gdbserver version should probably be moved into common code too. I’ll get a new patch together for that. Thanks for the reviews. Pushed the series. Updated version of this patch below. diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index f58a41e195..9572055d9f 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -606,8 +606,11 @@ aarch64_linux_nat_target::read_description () if (ret == 0) return tdesc_arm_with_neon; - /* pauth not yet supported. */ - return aarch64_read_description (aarch64_sve_get_vq (tid), false); + CORE_ADDR hwcap = 0; + bool pauth_p = aarch64_linux_get_hwcap (this, &hwcap) + && (hwcap & AARCH64_HWCAP_PACA); + + return aarch64_read_description (aarch64_sve_get_vq (tid), pauth_p); } /* Convert a native/host siginfo object, into/from the siginfo in the diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 445019accc..d7db23ef38 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -637,12 +637,11 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch, { CORE_ADDR aarch64_hwcap = 0; - if (target_auxv_search (target, AT_HWCAP, &aarch64_hwcap) != 1) - return NULL; + if (!aarch64_linux_get_hwcap (target, &aarch64_hwcap)) + return nullptr; - /* pauth not yet supported. */ return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd), - false); + aarch64_hwcap & AARCH64_HWCAP_PACA); } /* Implementation of `gdbarch_stap_is_single_operand', as defined in @@ -1420,6 +1419,15 @@ aarch64_linux_gcc_target_options (struct gdbarch *gdbarch) return NULL; } +/* See aarch64-linux-tdep.h. */ + +bool +aarch64_linux_get_hwcap (struct target_ops *target, CORE_ADDR *hwcap) +{ + *hwcap = 0; + return target_auxv_search (target, AT_HWCAP, hwcap) == 1; +} + static void aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { diff --git a/gdb/aarch64-linux-tdep.h b/gdb/aarch64-linux-tdep.h index 814222ead0..e9f7c9bccf 100644 --- a/gdb/aarch64-linux-tdep.h +++ b/gdb/aarch64-linux-tdep.h @@ -36,4 +36,10 @@ extern const struct regset aarch64_linux_gregset; extern const struct regset aarch64_linux_fpregset; +/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h. */ +#define AARCH64_HWCAP_PACA (1 << 30) + +/* Fetch the AT_HWCAP entry from the auxv vector for the given TARGET. */ +bool aarch64_linux_get_hwcap (struct target_ops *target, CORE_ADDR *hwcap); + #endif /* AARCH64_LINUX_TDEP_H */ diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c index db329da4dc..e2e25f0e27 100644 --- a/gdb/gdbserver/linux-aarch64-low.c +++ b/gdb/gdbserver/linux-aarch64-low.c @@ -485,6 +485,33 @@ aarch64_linux_new_fork (struct process_info *parent, *child->priv->arch_private = *parent->priv->arch_private; } +/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h. */ +#define AARCH64_HWCAP_PACA (1 << 30) + +/* Fetch the AT_HWCAP entry from the auxv vector. */ + +static bool +aarch64_get_hwcap (unsigned long *valp) +{ + unsigned char *data = (unsigned char *) alloca (16); + int offset = 0; + + while ((*the_target->read_auxv) (offset, data, 16) == 16) + { + unsigned long *data_p = (unsigned long *)data; + if (data_p[0] == AT_HWCAP) + { + *valp = data_p[1]; + return true; + } + + offset += 16; + } + + *valp = 0; + return false; +} + /* Implementation of linux_target_ops method "arch_setup". */ static void @@ -501,8 +528,10 @@ aarch64_arch_setup (void) if (is_elf64) { uint64_t vq = aarch64_sve_get_vq (tid); - /* pauth not yet supported. */ - current_process ()->tdesc = aarch64_linux_read_description (vq, false); + unsigned long hwcap = 0; + bool pauth_p = aarch64_get_hwcap (&hwcap) && (hwcap & AARCH64_HWCAP_PACA); + + current_process ()->tdesc = aarch64_linux_read_description (vq, pauth_p); } else current_process ()->tdesc = tdesc_arm_with_neon;