Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp492941yba; Mon, 1 Apr 2019 10:23:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+1cGWuiPp8/RVIz4FmEWz6WxaBDZNtFcriAQEig/iGZiPezrzY5vcMc4ISYEL+hDQRI4h X-Received: by 2002:a17:902:1:: with SMTP id 1mr63698534pla.226.1554139410392; Mon, 01 Apr 2019 10:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554139410; cv=none; d=google.com; s=arc-20160816; b=uyCXM71KIh5OoSUj8ekkfqdEo2Umxlg4ze6xCv2G52eEZ4X7PksM0MwaZvAgd7qpKj pUe5npSXWLDneiX3zRHKNm8RAtLMAh/pHtb8fS++PU4do8jvcTISlXgGfeI+Q4Eb+7RM gtJBGMA2mU16BZC23RBVUMPYK2jwUDQMQHfn4uGE+a5guvtIIgX660WTa9+fYDZZuKEr +TneXj+Zh8/vzFrmwORgHpUcJw/JGub2P/6D9vIpybHb9cdG95F2V9jiE/i72ScfgfeT SnpEs2/JV7D2Z81W7QRimI9BzmZ1mKLs4GY/SSLGZrjTY8nOyxOsRl9Y/ua77sPOZFlS w6sA== 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=Bmu0/L2ucHQksk0tJNz8c8ECa/dLf1V+nh/QPDUbUZ4=; b=a8l1RCHgeFAKYYpekYEDFwTEC7KyNF4QXZGavpGETYrd4kTIWzIP7kAV02YMaMRnn0 N4GT43A1krAByrUOtUI6PRsYup3mGdE6/W8dK+t/yQGGz7CPeu87S0xaZjtCzcfiQixq +oJNwVbrWhsFt/NjOAACuIWmRbPxzdHzaLRgtKzjZah8bDop9pS+3Audr0BRisrtYhQ1 ZBaO9r15wIpg1EMSFB2homEP/u3xATjnKPK38jb8zGAlPSEVJhK+yZNnzmPQJ3+peKvK fESMk44hUzsZJ4LU/ayrEQYBO+IV1geXymSXaGWjvm7ArhYQ7MlyRxrIWP5Pdb7YifPq bkoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PtTo5+2i; 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 r198si9747114pgr.153.2019.04.01.10.23.15; Mon, 01 Apr 2019 10:23:30 -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=PtTo5+2i; 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 S1731901AbfDARVz (ORCPT + 99 others); Mon, 1 Apr 2019 13:21:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:50820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731248AbfDARVy (ORCPT ); Mon, 1 Apr 2019 13:21:54 -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 F2A12206DD; Mon, 1 Apr 2019 17:21:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554139313; bh=fwffPyjJMQvBJRDJNo15JY3dly8GjAKOrasSNvHipjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PtTo5+2i/fZnSOD2b1SRC3hfsYMj89/sFfegouNNh/Fgy2xCvnHyKJKcfrK/QNy+w /XUdQ1A51Ku01ah6bi9uxrumE3pVmD08vnBuZg3gQSaevL+CLXfn1T9Mx2/EPqhY/r Rgarli3LvOoneRrUwDxRgaqowVlRzXIFniCnfhRk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman Subject: [PATCH 4.14 038/107] powerpc/asm: Add a patch_site macro & helpers for patching instructions Date: Mon, 1 Apr 2019 19:01:53 +0200 Message-Id: <20190401170049.100213074@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170045.246405031@linuxfoundation.org> References: <20190401170045.246405031@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael Ellerman 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: Greg Kroah-Hartman --- 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 --- /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 */ --- a/arch/powerpc/include/asm/code-patching.h +++ b/arch/powerpc/include/asm/code-patching.h @@ -32,6 +32,8 @@ unsigned int create_cond_branch(const un int patch_branch(unsigned int *addr, unsigned long target, int flags); int patch_instruction(unsigned int *addr, unsigned int instr); int raw_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); --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -206,6 +206,22 @@ int patch_branch(unsigned int *addr, uns 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); +} + bool is_offset_in_branch_range(long offset) { /*