From patchwork Tue Dec 6 17:06:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 9462923 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2575060231 for ; Tue, 6 Dec 2016 17:09:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EAC92842B for ; Tue, 6 Dec 2016 17:09:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02EDE28480; Tue, 6 Dec 2016 17:09:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E1E82842B for ; Tue, 6 Dec 2016 17:09:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cEJDB-0004Xw-8G; Tue, 06 Dec 2016 17:07:25 +0000 Received: from mail-wj0-f194.google.com ([209.85.210.194]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cEJCa-00044L-Gj for linux-arm-kernel@lists.infradead.org; Tue, 06 Dec 2016 17:06:52 +0000 Received: by mail-wj0-f194.google.com with SMTP id xy5so45019982wjc.1 for ; Tue, 06 Dec 2016 09:06:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VbQuk2w1EP/w+71oDMluHPw/cj20Ek7ijhx8KCfjlH8=; b=Cvc480PruHumBKZ+HQwvmhl+H0fs9SXT6SETyorKW1RibuE1hEDjpoJWyXGlQVaDmI OBVRfrTFQ4XQc1Gm/57XHUC4EyyS1H2J9c5cpuk6o67h4lwgIfzROh0Wa/rvh7NtcDFT wZLrpl5T0iaIYEDDiu2/KkV+4JGXN6PyNhwUsth2B3WyZU276qgSxp/yDFxrNbVRbPCs Z/f7t9wJWryQ1vsXPOCRkWLhFMUJeNBzf1wH2khf18UtncoGprCn9iMaZctps/eZ5HHo ZgOVJ+oOoZMcploYoEYTM8u5r3XQXGbHbbKQlYAz4SmUpk5AY2Gm2N9WnCbsXs3iHYlM kjnA== X-Gm-Message-State: AKaTC03e1XB2EYJU1EUA2Zh7K2zMMalZrP4wqJ8Djntjv7tpofAtxht/Yf2MrnzGObobnQ== X-Received: by 10.194.21.35 with SMTP id s3mr54604941wje.192.1481043984209; Tue, 06 Dec 2016 09:06:24 -0800 (PST) Received: from gce.c.kernel-work.internal (115.57.155.104.bc.googleusercontent.com. [104.155.57.115]) by smtp.gmail.com with ESMTPSA id l67sm4942458wmf.20.2016.12.06.09.06.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Dec 2016 09:06:23 -0800 (PST) From: Abel Vesa To: linux@armlinux.org.uk, jpoimboe@redhat.com, jeyu@redhat.com, jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com Subject: [PATCH 1/7] arm: Add livepatch arch specific code Date: Tue, 6 Dec 2016 17:06:01 +0000 Message-Id: <1481043967-15602-2-git-send-email-abelvesa@linux.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481043967-15602-1-git-send-email-abelvesa@linux.com> References: <1481043967-15602-1-git-send-email-abelvesa@linux.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161206_090648_918359_BA3630DA X-CRM114-Status: GOOD ( 19.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, geert+renesas@glider.be, ard.biesheuvel@linaro.org, jean-philippe.brucker@arm.com, gregkh@linuxfoundation.org, stefano.stabellini@eu.citrix.com, emil.l.velikov@gmail.com, linux-kernel@vger.kernel.org, rostedt@goodmis.org, jens.wiklander@linaro.org, Abel Vesa , chris.brandt@renesas.com, mingo@redhat.com, viro@zeniv.linux.org.uk, live-patching@vger.kernel.org, akpm@linux-foundation.org, mchehab@kernel.org, davem@davemloft.net, linux@roeck-us.net MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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/ 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); + +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); +} + +#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; +}