Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp111516pxb; Thu, 27 Jan 2022 16:28:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmpcFE9xBUlG0cq0tZflqd/q8YlaFFkPR+ruICZhIZxg1Q+tJutQtRDbgbXggijfh8e/uc X-Received: by 2002:a05:6402:5cb:: with SMTP id n11mr1984023edx.399.1643329721174; Thu, 27 Jan 2022 16:28:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643329721; cv=none; d=google.com; s=arc-20160816; b=0NT+3yd/T07WRMDQhzaIAZwD9wuNLT8ZRm4mJIsQZtUmZ4vQkPZtjMLbnkjFV7HQh2 Dqc4dXHu6oERqcMT8hjuzkihKc/YB5mEhqNpyegKlciC/dO5KgS50DkIVPt/oaQxF9iX mOMmI54sC8BY54ru37xw2/heSieAXEmpiwUpVwAjRaawPLNYA1SYJx93HIo47mKsdDGB SzHFQd67QGG8c3Yc0QA3+T5RLLo/QO9our0sLHLfeiQigQM8AZd7Scca808MqyHbrPC7 XCkmd2aPklkobcT/qqs8JgErltRcGhOW9QE59/c8z+R6bbuc/JWy6cG4k1bCrjyyAbHJ OKag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=+dtIbfZxBsUDAD+RsloGOeMxrjRfZ+KlpIIzcBEEGIc=; b=iI8kAuQA6u5k2zkXzH4DWNXYs1p8N7emyK5Vw2iIuwMBJzv9z8SZsJY5Xf7L65u/YN Y3D5m6poWChP1CWaSqXCldAiusNg0QTUQASLL5Y9ROPkV4MK5R++fZUAGDFWC9hsEA/Y 5GPoHAHR8puo/WyDh5sM+rpW9pRsDeHIymXOeOrO2b/xmO73hlHg6e94dMaywXCU5Zpp lq0QDiq/y89URx/nattxsCrAzWVn6KSh31NabPveEHHg0aJzVBPjY8EfQRBz3GxAKwVa 4+RmEhnnvqnc5SrVY54d6tAeDw294F1r18TnpkHMmGrxVLr7KQQlyn1+n9dx291mEigZ sIpA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b7si2333900ede.180.2022.01.27.16.27.28; Thu, 27 Jan 2022 16:28: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241420AbiA0M7r (ORCPT + 99 others); Thu, 27 Jan 2022 07:59:47 -0500 Received: from foss.arm.com ([217.140.110.172]:60228 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236419AbiA0M7q (ORCPT ); Thu, 27 Jan 2022 07:59:46 -0500 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 799F21063; Thu, 27 Jan 2022 04:59:45 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.14.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 366E23F766; Thu, 27 Jan 2022 04:59:44 -0800 (PST) Date: Thu, 27 Jan 2022 12:59:31 +0000 From: Mark Rutland To: Ard Biesheuvel Cc: Yinan Liu , Steven Rostedt , "open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)" , Sachin Sant , Linux Kernel Mailing List , Kees Cook Subject: Re: [powerpc] ftrace warning kernel/trace/ftrace.c:2068 with code-patching selftests Message-ID: References: <944D10DA-8200-4BA9-8D0A-3BED9AA99F82@linux.ibm.com> <20220124114548.30241947@gandalf.local.home> <0fa0daec-881a-314b-e28b-3828e80bbd90@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks, Mark.