From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751055AbdAQC2M (ORCPT ); Mon, 16 Jan 2017 21:28:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35078 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750774AbdAQC2L (ORCPT ); Mon, 16 Jan 2017 21:28:11 -0500 Date: Mon, 16 Jan 2017 21:27:48 -0500 From: Jessica Yu To: Miroslav Benes Cc: Abel Vesa , linux@armlinux.org.uk, jpoimboe@redhat.com, jikos@kernel.org, pmladek@suse.com, rostedt@goodmis.org, mingo@redhat.com, gregkh@linuxfoundation.org, geert+renesas@glider.be, davem@davemloft.net, akpm@linux-foundation.org, emil.l.velikov@gmail.com, mchehab@kernel.org, linux@roeck-us.net, ard.biesheuvel@linaro.org, jens.wiklander@linaro.org, jean-philippe.brucker@arm.com, viro@zeniv.linux.org.uk, stefano.stabellini@eu.citrix.com, chris.brandt@renesas.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org Subject: Re: arm: Add livepatch arch specific code Message-ID: <20170117022748.GH9045@packer-debian-8-amd64.digitalocean.com> References: <1481043967-15602-1-git-send-email-abelvesa@linux.com> <1481043967-15602-2-git-send-email-abelvesa@linux.com> <20170117002239.GF9045@packer-debian-8-amd64.digitalocean.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20170117002239.GF9045@packer-debian-8-amd64.digitalocean.com> X-OS: Linux eisen.io 3.16.0-4-amd64 x86_64 User-Agent: Mutt/1.5.23 (2014-03-12) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 17 Jan 2017 02:27:51 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +++ Jessica Yu [16/01/17 19:22 -0500]: >+++ Miroslav Benes [16/01/17 17:47 +0100]: >>On Tue, 6 Dec 2016, Abel Vesa wrote: >> >>>klp_get_ftrace_location is used by ftrace to get the entry for a >>>specific function from the mcount list. klp_arch_set_pc is used >>>to set the pc from the regs passed as an argument to the >>>ftrace_ops_no_ops function to the starting address of the patched >>>function. klp_write_module_reloc is not doing anything at this >>>moment. >>> >>>Signed-off-by: Abel Vesa >>>--- >>> MAINTAINERS | 3 +++ >>> arch/arm/include/asm/livepatch.h | 46 ++++++++++++++++++++++++++++++++++++++++ >>> arch/arm/kernel/livepatch.c | 43 +++++++++++++++++++++++++++++++++++++ >>> 3 files changed, 92 insertions(+) >>> create mode 100644 arch/arm/include/asm/livepatch.h >>> create mode 100644 arch/arm/kernel/livepatch.c >>> >>>diff --git a/MAINTAINERS b/MAINTAINERS >>>index bd182a1..d43b790 100644 >>>--- a/MAINTAINERS >>>+++ b/MAINTAINERS >>>@@ -7466,12 +7466,15 @@ M: Josh Poimboeuf >>> M: Jessica Yu >>> M: Jiri Kosina >>> M: Miroslav Benes >>>+M: Abel Vesa >>> R: Petr Mladek >>> S: Maintained >>> F: kernel/livepatch/ >>> F: include/linux/livepatch.h >>> F: arch/x86/include/asm/livepatch.h >>> F: arch/x86/kernel/livepatch.c >>>+F: arch/arm/include/asm/livepatch.h >>>+F: arch/arm/kernel/livepatch.c >>> F: Documentation/livepatch/ >>> F: Documentation/ABI/testing/sysfs-kernel-livepatch >>> F: samples/livepatch/ >> >>Thanks for the offer but I think we manage quite well ;) >> >>>diff --git a/arch/arm/include/asm/livepatch.h b/arch/arm/include/asm/livepatch.h >>>new file mode 100644 >>>index 0000000..d4e3ff0 >>>--- /dev/null >>>+++ b/arch/arm/include/asm/livepatch.h >>>@@ -0,0 +1,46 @@ >>>+/* >>>+ * livepatch.h - arm specific Kernel Live Patching Core >>>+ * >>>+ * Copyright (C) 2016 Abel Vesa >>>+ * >>>+ * This program is free software; you can redistribute it and/or >>>+ * modify it under the terms of the GNU General Public License >>>+ * as published by the Free Software Foundation; either version 2 >>>+ * of the License, or (at your option) any later version. >>>+ * >>>+ * This program is distributed in the hope that it will be useful, >>>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of >>>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >>>+ * GNU General Public License for more details. >>>+ * >>>+ * You should have received a copy of the GNU General Public License >>>+ * along with this program; if not, see . >>>+ */ >>>+ >>>+#ifndef _ASM_ARM_LIVEPATCH_H >>>+#define _ASM_ARM_LIVEPATCH_H >>>+ >>>+#include >>>+#include >>>+#include >>>+ >>>+static inline int klp_check_compiler_support(void) >>>+{ >>>+ return 0; >>>+} >>>+ >>>+int klp_write_module_reloc(struct module *mod, unsigned long type, >>>+ unsigned long loc, unsigned long value); >> >>This is not needed. See below. >> >>>+ >>>+static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip) >>>+{ >>>+ regs->uregs[15] = ip; >>>+} >>>+ >>>+#define klp_get_ftrace_location klp_get_ftrace_location >>>+static inline unsigned long klp_get_ftrace_location(unsigned long faddr) >>>+{ >>>+ return ftrace_location_range(faddr, faddr + 24); >> >>Comment here about +24 would be great. See similar in powerpc header file. >> >>>+} >>>+ >>>+#endif /* _ASM_ARM_LIVEPATCH_H */ >>>diff --git a/arch/arm/kernel/livepatch.c b/arch/arm/kernel/livepatch.c >>>new file mode 100644 >>>index 0000000..0656cd6 >>>--- /dev/null >>>+++ b/arch/arm/kernel/livepatch.c >>>@@ -0,0 +1,43 @@ >>>+/* >>>+ * livepatch.c - arm specific Kernel Live Patching Core >>>+ * >>>+ * Copyright (C) 2016 Abel Vesa >>>+ * >>>+ * This program is free software; you can redistribute it and/or >>>+ * modify it under the terms of the GNU General Public License >>>+ * as published by the Free Software Foundation; either version 2 >>>+ * of the License, or (at your option) any later version. >>>+ * >>>+ * This program is distributed in the hope that it will be useful, >>>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of >>>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >>>+ * GNU General Public License for more details. >>>+ * >>>+ * You should have received a copy of the GNU General Public License >>>+ * along with this program; if not, see . >>>+ */ >>>+ >>>+#include >>>+#include >>>+#include >>>+#include >>>+#include >>>+#include >>>+#include >>>+ >>>+/** >>>+ * klp_write_module_reloc() - write a relocation in a module >>>+ * @mod: module in which the section to be modified is found >>>+ * @type: ELF relocation type (see asm/elf.h) >>>+ * @loc: address that the relocation should be written to >>>+ * @value: relocation value (sym address + addend) >>>+ * >>>+ * This function writes a relocation to the specified location for >>>+ * a particular module. >>>+ */ >>>+int klp_write_module_reloc(struct module *mod, unsigned long type, >>>+ unsigned long loc, unsigned long value) >>>+{ >>>+ /* Not implemented yet */ >>>+ return 0; >>>+} >> >>This whole file is not needed. Livepatching uses kernel's internal >>apply_relocate_add() for dealing with relocations. The only thing you need >>to do is to make sure that all needed arch-specific info is preserved >>during a module loading. Specifically mod_arch_specific structure needs to >>be examined in this respect. > >Yup. Since we rely on apply_relocate_add() to apply relocations, just >make sure that you preserve anything (e.g., plt tables) you need to >make that call post-module init. In the case of s390, we needed to >make sure we kept mod->arch.syminfo, so that the call to >apply_relocate_add() would succeed. > >>But apply_relocate_add() is not implemented on arm yet. I guess it would >>nice to have it... otherwise we could get to an unpleasant situation. >>Livepatch module can rely on its livepatching relocations (that is, there >>are some). apply_relocate_add() returns 0 on arm, so everything seems to >>be nice and then boom some time later. > >Doesn't it return -ENOEXEC? MODULES_USE_ELF_RELA is not defined >on arm, I think (see moduleloader.h). ...And I should have looked at the whole patchset first before replying :-) I see now that a placeholder was added in patch 3/7. Jessica