Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp322680pxb; Thu, 27 Jan 2022 23:10:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJy22LcwxKdszRn+bci4e+aRgVQsdTE+BgXPTRz9D9xHCa27HvxIQPEJmaSFF/mwVxf71MTX X-Received: by 2002:a17:907:a0ce:: with SMTP id hw14mr5894870ejc.105.1643353841220; Thu, 27 Jan 2022 23:10:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643353841; cv=none; d=google.com; s=arc-20160816; b=YGnfGwOuuDayZoO3+FpzAw6QGbh9IvyVuJt1amYjdfNpUmnrJhJB+Ji+0vlgZYny+H 5a3Sw6kaE2WBBuuMJbOrKbXa1jWFeadv1Cx1VwFfHsKBFaEYVWCBSUJX6S3uThQAo8Wr 7O0oIiTLPNXJ4mqjAvAeVWVAF0Ge0/w5518K/gyA1/dbc5ij5e0q45pj9IPYcn/Pstsd RZxbHW9hBngaISILbVpjQyRieF1NdlR/bks7DsGvYNi/E2H9g97JnWhEq5VjYLJRRYKs ynA/jMfjS/vNK+xU+l74IMjTC/2zmJMo0T9+mVOFA+zc5nljDbrSUOlh/AQ7edX0ifDD gP4g== 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=9M72epFLBM9TW7p7G4qVlxvQbfghAqp0eT5brsAm1jQ=; b=k8hgK0Mv4mrOzXjzkKEHfkxhZEMw0KdFvam2EwNHzkmp+XrPBTmcHm/uQXcLZCk2P/ 1FDmMLJI8dEh/yyhFbAb9SxNvlGOD8amzEFuU9398aS1qFhjmCHXmD1X7Wc5CmHdw0/6 t17N1e7aL5UoWVcvDtcjr9kisjz98JZhh6aJBPsCXJLd3KWa827A/dBy/0dz31HJhvPO uaqzFIlvWkWbGPDTTgtWsN857/TXQVh9OazP6gtkxXbyQkWugst6NECKEOvRGMIElo8u sXEIYTSh1S3iAgZD58yfyk/qBjyvs45b4yEqfV8mAVHFn9znlXP89kkhh5eF5sJXl0g/ GT+g== 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 g2si2554599ejt.974.2022.01.27.23.10.16; Thu, 27 Jan 2022 23:10: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 S242714AbiA0OzD (ORCPT + 99 others); Thu, 27 Jan 2022 09:55:03 -0500 Received: from foss.arm.com ([217.140.110.172]:37474 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238310AbiA0OzB (ORCPT ); Thu, 27 Jan 2022 09:55:01 -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 F19D81063; Thu, 27 Jan 2022 06:55:00 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.14.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A6F8B3F766; Thu, 27 Jan 2022 06:54:59 -0800 (PST) Date: Thu, 27 Jan 2022 14:54:47 +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: <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 02:59:31PM +0100, Ard Biesheuvel wrote: > On Thu, 27 Jan 2022 at 14:24, Mark Rutland wrote: > > > > On Thu, Jan 27, 2022 at 02:07:03PM +0100, Ard Biesheuvel wrote: > > > 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. > > > > We'd also need to teach the build-time sort to update the relocations, unless > > you mean to also change the boot-time reloc code to RMW with the offset? > > Why would that be necessary? Every RELA entry has the same effect on > its target address, as it just adds a fixed offset. Currently in relocate_kernel() we generate the absolute address from the relocation alone, with the core of the relocation logic being as follows, with x9 being the pointer to a RELA entry, and x23 being the offset relative to the default load address: ldp x12, x13, [x9], #24 ldr x14, [x9, #-8] add x14, x14, x23 // relocate str x14, [x12, x23] ... and (as per another reply), a sample RELA entry currently contains: 0xffff8000090b1ab0 // default load VA of pointer to update 0x0000000000000403 // R_AARCH64_RELATIVE 0xffff8000090b6000 // default load VA of addr to write So either: * That code stays as-is, and we must update the relocs to correspond to their new sorted locations, or we'll blat the sorted values with the original relocs as we do today. * The code needs to change to RMW: read the existing value, add the offset (ignoring the content of the RELA entry's addend field), and write it back. This is what I meant when I said "change the boot-time reloc code to RMW with the offset". Does that make sense, or have I misunderstood? Thanks, Mark.