Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp112038pxb; Thu, 27 Jan 2022 16:29:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrzrw0NNBjrvTRSQJky67aNOms74PUXbS6T/cCcUNYqDFKbKciJvlM9+pPtl5L1javmWW3 X-Received: by 2002:a05:6402:3c3:: with SMTP id t3mr5861371edw.336.1643329781173; Thu, 27 Jan 2022 16:29:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643329781; cv=none; d=google.com; s=arc-20160816; b=zkolzxgJq9yjzT9ZrBe+25D94fyqo5GnPs3s1sSYv1A5yXxgho6yiQhqFa4g68eRzD f5Tdw9HO+kCFcr9IiqEBiK4KkxLFlxJ/bBhixzFyBJW6QmWsUN4BrOxjjjMn3n4bs7X6 9MRRHhxGZ3c7H7TsWTrLpuonMYwOExTP26a4s14dc3ro7Rbtjjqh1iOp0j8UFUlWy3a2 hGlg8aUrTeEEpl+RL9ahRGUr2zEZMP+zOhQXO1f9GV5Nw0DI9Vbd69nNpWiM0jNkVpPc BjqsGYjBnwRgkMNBBlgSItksKnguVWEdKuD/yDqrkDoRu2dCmtot6/zud+/vA+4/0q+V Drfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=vTO3JKAHEngE4OMjen99aMhfc6Wq+xWShuaHaE6GAmI=; b=DTTCDdO5MFiZ8tss0iCxCCtBpIXFinoy+lsZ+6Dx3uyK+693ZO2qBaAMaBlD2/aWWa TFfxQanFMJlvoyXRhKnNoXOoOlQGQ2chY2qVPcpP1s33YttuEykPz7Q7mJXDlz3qB9+P XwOFCa2oiyPDTdGB2Xw8xEMHevOys52hnOjyXlHuv/KDyMLxN2m1KlGvre+0yBvPzxfB UY3c8iMFZ6ESqvmA7Nd75iWmOATT0ZLXl5ygQJQSiGvvvUd2OlkQhOVtnTnmYuB/kcqF jaz90yOdQe9ayc9YFH4hoNdLPzc0ALTzKFgzoXwTcIxwAIIL1YQD0g9K4LfVDYzLHS1G IXZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cHc5VHli; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si2143015eda.526.2022.01.27.16.29.16; Thu, 27 Jan 2022 16:29:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cHc5VHli; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241529AbiA0NHT (ORCPT + 99 others); Thu, 27 Jan 2022 08:07:19 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:55034 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241475AbiA0NHS (ORCPT ); Thu, 27 Jan 2022 08:07:18 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CA90161B68 for ; Thu, 27 Jan 2022 13:07:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35200C340EE for ; Thu, 27 Jan 2022 13:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643288837; bh=xjiolTwYVgGM09+KCzAYuvgj9y0KyzZcSIFHpSpItXk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=cHc5VHlihuPJPzEw19OXPSBoYC9RPfNlXkwGNLkvm+KUQudBmM9Sj8rWPQTZMmfbf EXV7wCWkZ13UfOiHLWeh+cnQFFdgrk/c/vfxQzGlscQO2EEqJCVrtZUnPqES1t/8Fk tPKfBFWLFUE6xLTdUddIqtF54ycDJu5xvJZ1KmVpuDRij580Fwcx+WUn6MONstaCPg Zbkny7OxzuqjoMsChYY6YxTs9rDl4lVupvUl/IuVvZnoPIYw18E/Yr7kNZXz6ORYSY eEsqjOeE5qWSQBotsndY/ru7EX8FhcaeZ0TYTjKM0z9az+dp6EaWyTxMPiciikQO2z aqcRUGlrfUxzw== Received: by mail-wm1-f43.google.com with SMTP id l35-20020a05600c1d2300b0034d477271c1so1811933wms.3 for ; Thu, 27 Jan 2022 05:07:17 -0800 (PST) X-Gm-Message-State: AOAM533Femq8wo53Z16yHPKISCF3ngLCx/tz/1nX5o5M5HKXYCFPCRNq 4cho42F3UzDexqq5/imkS/CKb0DD4mr+izYnoqk= X-Received: by 2002:a05:600c:a47:: with SMTP id c7mr3158487wmq.25.1643288834852; Thu, 27 Jan 2022 05:07:14 -0800 (PST) MIME-Version: 1.0 References: <944D10DA-8200-4BA9-8D0A-3BED9AA99F82@linux.ibm.com> <20220124114548.30241947@gandalf.local.home> <0fa0daec-881a-314b-e28b-3828e80bbd90@linux.alibaba.com> In-Reply-To: From: Ard Biesheuvel Date: Thu, 27 Jan 2022 14:07:03 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [powerpc] ftrace warning kernel/trace/ftrace.c:2068 with code-patching selftests To: Mark Rutland Cc: Yinan Liu , Steven Rostedt , "open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)" , Sachin Sant , Linux Kernel Mailing List , Kees Cook Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 27 Jan 2022 at 13:59, Mark Rutland wrote: > > On Thu, Jan 27, 2022 at 01:22:17PM +0100, Ard Biesheuvel wrote: > > On Thu, 27 Jan 2022 at 13:20, Mark Rutland wrote: > > > On Thu, Jan 27, 2022 at 01:03:34PM +0100, Ard Biesheuvel wrote: > > > > > > > These architectures use place-relative extables for the same reason: > > > > place relative references are resolved at build time rather than at > > > > runtime during relocation, making a build time sort feasible. > > > > > > > > arch/alpha/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE > > > > arch/arm64/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE > > > > arch/ia64/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE > > > > arch/parisc/include/asm/uaccess.h:#define ARCH_HAS_RELATIVE_EXTABLE > > > > arch/powerpc/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE > > > > arch/riscv/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE > > > > arch/s390/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE > > > > arch/x86/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE > > > > > > > > Note that the swap routine becomes something like the below, given > > > > that the relative references need to be fixed up after the entry > > > > changes place in the sorted list. > > > > > > > > static void swap_ex(void *a, void *b, int size) > > > > { > > > > struct exception_table_entry *x = a, *y = b, tmp; > > > > int delta = b - a; > > > > > > > > tmp = *x; > > > > x->insn = y->insn + delta; > > > > y->insn = tmp.insn - delta; > > > > ... > > > > } > > > > > > > > As a bonus, the resulting footprint of the table in the image is > > > > reduced by 8x, given that every 8 byte pointer has an accompanying 24 > > > > byte RELA record, so we go from 32 bytes to 4 bytes for every call to > > > > __gnu_mcount_mc. > > > > > > Absolutely -- it'd be great if we could do that for the callsite locations; the > > > difficulty is that the entries are generated by the compiler itself, so we'd > > > either need some build/link time processing to convert each absolute 64-bit > > > value to a relative 32-bit offset, or new compiler options to generate those as > > > relative offsets from the outset. > > > > Don't we use scripts/recordmcount.pl for that? > > Not quite -- we could adjust it to do so, but today it doesn't consider > existing mcount_loc entries, and just generates new ones where the compiler has > generated calls to mcount, which it finds by scanning the instructions in the > binary. Today it is not used: > > * On arm64 when we default to using `-fpatchable-function-entry=N`. That makes > the compiler insert 2 NOPs in the function prologue, and log the location of > that NOP sled to a section called. `__patchable_function_entries`. > > We need the compiler to do that since we can't reliably identify 2 NOPs in a > function prologue as being intended to be a patch site, as e.g. there could > be notrace functions where the compiler had to insert NOPs for alignment of a > subsequent brnach or similar. > > * On architectures with `-nop-mcount`. On these, it's necessary to use > `-mrecord-mcount` to have the compiler log the patch-site, for the same > reason as with `-fpatchable-function-entry`. > > * On architectures with `-mrecord-mcount` generally, since this avoids the > overhead of scanning each object. > > * On x86 when objtool is used. > Right. I suppose that on arm64, we can work around this by passing --apply-dynamic-relocs to the linker, so that all R_AARCH64_RELATIVE targets are prepopulated with the link time value of the respective addresses. It does cause some bloat, which is why we disable that today, but we could make that dependent on ftrace being enabled. I do wonder how much over head we accumulate, though, by having all these relocations, but I suppose that is the situation today in any case.