Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2448995yba; Mon, 15 Apr 2019 11:52:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2iEVxCEqPUT8rLLwT9bwoGhoAtsEb50gq30IS2PmT4kTmLKlYQ9Ca/d91v6qB2GDLm4sS X-Received: by 2002:a63:4e64:: with SMTP id o36mr73232504pgl.213.1555354341621; Mon, 15 Apr 2019 11:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555354341; cv=none; d=google.com; s=arc-20160816; b=mLpzfGXjBwUWRqZhoMp4131McqIgTcr5zpjGgwcy0IMZaiNFdj2QMZlOVfhzLiWxiF 9rb2GpLzMCkDLfGUGWAIZeEMMOMPUsLKLoJsFfkwXRlj/u7yHDvB+0KA/nJyYiZCNIxE bpI4RFB0TQChkRQsIW7YabQ0F7P2IoIu6nkZBvhZ3wULf/HuOpT9t1RUNChdkPE/MU34 rRzNVWNZbSwTXp4ptsLdyUPsTpsbVE9jpb9yXUcbvWr7LFM7YJWm+vSfWeFgNIVbmafC 4xWTE/+pWsBCb1k4ibX25JRzw09U9YSyrvU1mWvqn4qq5sxgzPi2aZVI5vR31SsSKXic o+Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VQpIjsDS/Nn4vdUgQaMWj81eoJYa0KjAfaqNvojLOFs=; b=NvkYkGyHeK3XCAjp6Vv6ASFCgJ8mfG4jcGafBw0Td7S/XjEcvhrpzrAJEbC4pY4dPp 716JE8MxZOW1sQGPNgrBRxI99USyV/7MFXULb4Ccjc6p8tkU1wMCkLSNgplhmEAn6aZz fy5vV8wvIbVXD9unJGMoSiASLuPLobL9eJUGwFWMZT8oZl4zalFRxGBKelV2pA39mdba jK+L2Qd1U6pV3z8if6xIejKTpkyM2FrcA+HoclA79ucS0yB1d0/jTR/C/qr2OjQGGMGY P6ZIq9mIZHadFUwSTrEKDKQ5dCb6oWIGlSYjtA03pmPiGcqiJ7NQ9jKIDu/pH7FkW5pj 6AuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Pm7s115e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4si43925686pgr.591.2019.04.15.11.52.05; Mon, 15 Apr 2019 11:52:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Pm7s115e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728584AbfDOSqY (ORCPT + 99 others); Mon, 15 Apr 2019 14:46:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:49120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728577AbfDOSqX (ORCPT ); Mon, 15 Apr 2019 14:46:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AF1332087C; Mon, 15 Apr 2019 18:46:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555353982; bh=F6vAXa6hdCxPYF4uvKhz5OrXvmiM0aKK28VgnEqL+/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pm7s115eFCUMWYBX3zlIamihij0InYGVfnSDUhcvyfTJix1xKpUnDJia31MzJ9F3L mgKXpZ4nwNenT2Gc69rGH+ROsEUWsQTjm31o07qoEHhzDlDZ9blaf1SpzcR3GvFSZl jOgqYd6bfvthi5Jc43WZK1wmRZJiTvcHYdQlPhTY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman , Sasha Levin Subject: [PATCH 4.9 27/76] powerpc/asm: Add a patch_site macro & helpers for patching instructions Date: Mon, 15 Apr 2019 20:43:51 +0200 Message-Id: <20190415183714.994496321@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183707.712011689@linuxfoundation.org> References: <20190415183707.712011689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 06d0bbc6d0f56dacac3a79900e9a9a0d5972d818 upstream. Add a macro and some helper C functions for patching single asm instructions. The gas macro means we can do something like: 1: nop patch_site 1b, patch__foo Which is less visually distracting than defining a GLOBAL symbol at 1, and also doesn't pollute the symbol table which can confuse eg. perf. These are obviously similar to our existing feature sections, but are not automatically patched based on CPU/MMU features, rather they are designed to be manually patched by C code at some arbitrary point. Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/code-patching-asm.h | 18 ++++++++++++++++++ arch/powerpc/include/asm/code-patching.h | 2 ++ arch/powerpc/lib/code-patching.c | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 arch/powerpc/include/asm/code-patching-asm.h diff --git a/arch/powerpc/include/asm/code-patching-asm.h b/arch/powerpc/include/asm/code-patching-asm.h new file mode 100644 index 000000000000..ed7b1448493a --- /dev/null +++ b/arch/powerpc/include/asm/code-patching-asm.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2018, Michael Ellerman, IBM Corporation. + */ +#ifndef _ASM_POWERPC_CODE_PATCHING_ASM_H +#define _ASM_POWERPC_CODE_PATCHING_ASM_H + +/* Define a "site" that can be patched */ +.macro patch_site label name + .pushsection ".rodata" + .balign 4 + .global \name +\name: + .4byte \label - . + .popsection +.endm + +#endif /* _ASM_POWERPC_CODE_PATCHING_ASM_H */ diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/include/asm/code-patching.h index b4ab1f497335..ab934f8232bd 100644 --- a/arch/powerpc/include/asm/code-patching.h +++ b/arch/powerpc/include/asm/code-patching.h @@ -28,6 +28,8 @@ unsigned int create_cond_branch(const unsigned int *addr, unsigned long target, int flags); int patch_branch(unsigned int *addr, unsigned long target, int flags); int patch_instruction(unsigned int *addr, unsigned int instr); +int patch_instruction_site(s32 *addr, unsigned int instr); +int patch_branch_site(s32 *site, unsigned long target, int flags); int instr_is_relative_branch(unsigned int instr); int instr_is_relative_link_branch(unsigned int instr); diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index c77c486fbf24..14535ad4cdd1 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -40,6 +40,22 @@ int patch_branch(unsigned int *addr, unsigned long target, int flags) return patch_instruction(addr, create_branch(addr, target, flags)); } +int patch_branch_site(s32 *site, unsigned long target, int flags) +{ + unsigned int *addr; + + addr = (unsigned int *)((unsigned long)site + *site); + return patch_instruction(addr, create_branch(addr, target, flags)); +} + +int patch_instruction_site(s32 *site, unsigned int instr) +{ + unsigned int *addr; + + addr = (unsigned int *)((unsigned long)site + *site); + return patch_instruction(addr, instr); +} + unsigned int create_branch(const unsigned int *addr, unsigned long target, int flags) { -- 2.19.1