Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8620191rwi; Tue, 25 Oct 2022 08:50:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4USiGD6PKNQYjcgtu9E8X2xp/HQQ7M1++k/kSlnajKUl5SXII6QeucSZFzmcmygdleKzZv X-Received: by 2002:a17:907:3f27:b0:78d:ad42:f733 with SMTP id hq39-20020a1709073f2700b0078dad42f733mr33999342ejc.320.1666713022981; Tue, 25 Oct 2022 08:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666713022; cv=none; d=google.com; s=arc-20160816; b=yMjekiKQU2wDN8PibCMnWji2KVgQqIq6n5ZIn75eLcErY6vHT5jpcLi9KQVTGGBZbc o1AmuwUK6Cz8+sk12EX6mU4xdqqImUx69XtI0WLJEtHM0jXLjE8BNg/DvLvKlc8weC6F fBCyNS5yck3PmNowbTijwisOzwOyh0bqsx4m4Uha3rjccgfeLiSZeBS13tHeZ5NwKcj0 AhwQqsDC3qurqVipTqhmXLwn070OAPX6YU56N951YpDan79aI8VqhTvv8wXTXzs3Pj6k sA8ERIJNOey2rM9EzGbRRR2WlXRMKxdzXYa8fG0O6mUn7gpvt6TUIBfNZdb6UOV97Cek xuIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id; bh=Ia43mLszAKsHHV9GNzaMzdP/nta/BUy5NowwXjfQiGE=; b=nxz3zAl+2uFo53soTgNelNRrCO6XnNBYPqFQpCZUqJidu4T20I5J7YaM7fZ4rFq3T2 2MZosSpYAD04wrJOdNgzgClHcA0C0xMTYfljUiFeHjDf1XMmrfWQ9CexhB+gu3lkq1ff rfaScrDpZ1mYXDY6kyYOyqwr6AW6voQ4CLjv+kZZ1s/hI7mV5HeFtz2d48DR2WfwvPuT GOv6G4gTO675GLP7/BILx7g9GP+h32Wd3+8V2Gjv3uy45mw1Y4UYXvRv3fh7X8aclHvj Ff6hcZPEvJ/cwCBL1l3vNeouK34a5lipqrN1p0XHg9UJeLkUoyBeTJpbhX4r1TxJUCXH QHbw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a1-20020a170906368100b0078e11e92257si2785169ejc.333.2022.10.25.08.49.54; Tue, 25 Oct 2022 08:50:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233212AbiJYP2T (ORCPT + 99 others); Tue, 25 Oct 2022 11:28:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233068AbiJYP2R (ORCPT ); Tue, 25 Oct 2022 11:28:17 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3566243328; Tue, 25 Oct 2022 08:28:16 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 307ADD6E; Tue, 25 Oct 2022 08:28:22 -0700 (PDT) Received: from [10.57.1.104] (unknown [10.57.1.104]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C27A83F71A; Tue, 25 Oct 2022 08:28:13 -0700 (PDT) Message-ID: <4e50b890-0588-1551-fb7c-6cd8191d1054@arm.com> Date: Tue, 25 Oct 2022 16:28:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 From: James Clark Subject: Re: [PATCH v2 1/1] perf arm64: Send pointer auth masks to ring buffer To: Peter Zijlstra Cc: linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, broonie@kernel.org, acme@kernel.org, Andrew Kilroy , Vince Weaver , Mark Rutland , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Will Deacon , Catalin Marinas , kristina.martsenko@arm.com References: <20221020101921.1219533-1-james.clark@arm.com> <20221020101921.1219533-2-james.clark@arm.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/10/2022 17:49, Peter Zijlstra wrote: > On Thu, Oct 20, 2022 at 11:19:20AM +0100, James Clark wrote: >> From: Andrew Kilroy >> >> Perf report cannot produce callgraphs using dwarf on arm64 where pointer >> authentication is enabled. This is because libunwind and libdw cannot >> unmangle instruction pointers that have a pointer authentication code >> (PAC) embedded in them. >> >> libunwind and libdw need to be given an instruction mask which they can >> use to arrive at the correct return address that does not contain the >> PAC. >> >> The bits in the return address that contain the PAC can differ by >> process, so this patch adds a new sample field PERF_SAMPLE_ARCH_1 >> to allow the kernel to send the masks up to userspace perf. >> >> This field can be used in a architecture specific fashion, but on >> arm64, it contains the ptrauth mask information. The event will >> currently fail to open on architectures other than arm64 if >> PERF_SAMPLE_ARCH_1 is set. It will also fail to open on arm64 if >> CONFIG_ARM64_PTR_AUTH isn't set, as the data would always be zeros. > > A little more information please; wth is pointer authentication? Are we Yes the commit message could do with some links and details. I will add more background about the feature if I resend it. > going to be having the same thing with x86 LAM where only a subset of > the available bits have meaning to the hardware? If LAM is used with things like return addresses on the stack then yes. For data addresses then it wouldn't cause this exact issue. The problem is that libunwind and perf do pointer arithmetic when unwinding with other values that don't have these bits set. For example computing offset in an mmap where the base address doesn't have an authentication code but a return value does results in an incorrect value. Like x-y=offset is only correct if the PAC bits are masked out first. > > Why do we want the same mask repeated over and over with each sample; > should this not be part of the address space (side-band) data? You are probably right that it could be done that way. The reason that we did it this way was to be consistent with ptrace feature [1] where it is delivered to userspace on a per-process basis. And there is also a prctl for the enabled key types [2] which can be changed dynamically. Particularly for the last reason is why it was done per sample. Having said that, the enabled keys field is not used by perf, only the mask is used, so I can drop the per sample data until enabled keys is needed, which may be never. I'm going to assume that perf shouldn't use ptrace because of permissions and conflicts with debuggers, so I could put the mask somewhere like PERF_RECORD_FORK instead of per sample. [1]: https://lore.kernel.org/all/20181207183931.4285-9-kristina.martsenko@arm.com/ [2]: https://lore.kernel.org/all/d6609065f8f40397a4124654eb68c9f490b4d477.1616123271.git.pcc@google.com/