Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp467263imm; Wed, 29 Aug 2018 04:38:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaWu55thjFOJL+nlBtv/aboO40eqOnN4WcDdwCAAOANEBc7G/M4l2VLqZBvvhqjxr641IAa X-Received: by 2002:a17:902:c6b:: with SMTP id 98-v6mr5636874pls.233.1535542737118; Wed, 29 Aug 2018 04:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535542737; cv=none; d=google.com; s=arc-20160816; b=NWv6ERH71ZgHnA7x3l8NJ/0jEirDnLUIZgm9nCEmgpSKzGgg+yEUjfm+E9FEHzOdGE NnucpiJO5nhGUPQjnc+CAeqfRP04rBr3KE+meVHmgAcSp5SrlmRWpkx5Y82tMJ1MXvjz TNT3/Y5GkkHjG7MRN6uMaTpIt3PVXe8fmBnvu9OAx8OZFrgLwb7oA39Sqhtvjw+Rq31U OuZHbnwF8gsM098hwFxRj3VSvcohg1E2+bYalAieEXgDwdHFJSmAtq5vi27gs3kR1iTA u0HHiHNJkAeNlgaYjSEfx2PogEbu4Hb2TYLjaEbMTL+YIiASQ2+HWICI7Dy1w29Z6tYh 1cLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=tcnJ7+uDmxcdjN9zjFM3EzrnaJSceJfZ4VrIvxQ97+g=; b=zUCsSeLhQsw2WbhpISUd4PUdfHd19cwT+B9+wsr7iDiXm6mJE4qS81G3/DXXhvRaGG zMOYRm/ExE/+jx57qGoIBBdTvKhCEryL7vzOSh+IzZ2Zo4fBjgeGjhiDxL6BVrLB0pVZ Y6wguAo3piXdPSVxgbTYDXm4Yg7nyjt6D5GmV5NubTJpEQ2YKLlM08JiZ1LNKSoMLSGO UxOIXE9HW6IUh1m3eYdhlr42Jss3OMTg/AiV6FkWZbej+e7bIuCk6YWZGAeuXBJAzCQA AdnThG8hJBlaiF4RsXF1wBdxJty3kzY2GSfdJnQ563ZGMMVSDABBXdpX2BnMD/bvwOaJ 473Q== ARC-Authentication-Results: i=1; mx.google.com; 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 z12-v6si3048655pgr.386.2018.08.29.04.38.42; Wed, 29 Aug 2018 04:38:57 -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; 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 S1728770AbeH2Pdd (ORCPT + 99 others); Wed, 29 Aug 2018 11:33:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:43974 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728423AbeH2Pdd (ORCPT ); Wed, 29 Aug 2018 11:33:33 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 898F7AE31; Wed, 29 Aug 2018 11:37:02 +0000 (UTC) Date: Wed, 29 Aug 2018 13:37:00 +0200 (CEST) From: Miroslav Benes To: Torsten Duwe cc: Will Deacon , Catalin Marinas , Julien Thierry , Steven Rostedt , Ingo Molnar , Ard Biesheuvel , Arnd Bergmann , AKASHI Takahiro , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org Subject: Re: [PATCH 2/3] arm64: implement live patching In-Reply-To: <20180810160306.2954D68C76@newverein.lst.de> Message-ID: References: <20180810160043.9E45568C76@newverein.lst.de> <20180810160306.2954D68C76@newverein.lst.de> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 10 Aug 2018, Torsten Duwe wrote: > Based on ftrace with regs, do the usual thing. Also allocate a > task flag for whatever consistency handling is implemented. > Watch out for interactions with the graph tracer. > This code has been compile-tested, but has not yet seen any > heavy livepatching. > > Signed-off-by: Torsten Duwe There is one thing missing. Livepatch is able to automatically resolve relocations pointing to SHN_LIVEPATCH symbols. Arch-specific apply_relocate_add() is called for the purpose. It needs all arch-specific info preserved because of that. Usually it means to keep at least mod_arch_specific struct also after a module is loaded. It depends on its content. See f31e0960f395 ("module: s390: keep mod_arch_specific for livepatch modules") for example. We discussed the issue in 2016 when you submitted the arm64 support originally. It was more or less ok back then. Jessica only proposed to update count_plts(). However, a lot has changed since then and the code must be inspected again. If everything is ok, there should be at least a note in the changelog. > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index 28c8c03..31df287 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -117,6 +117,7 @@ config ARM64 > select HAVE_GENERIC_DMA_COHERENT > select HAVE_HW_BREAKPOINT if PERF_EVENTS > select HAVE_IRQ_TIME_ACCOUNTING > + select HAVE_LIVEPATCH > select HAVE_MEMBLOCK > select HAVE_MEMBLOCK_NODE_MAP if NUMA > select HAVE_NMI > @@ -1343,4 +1344,6 @@ if CRYPTO > source "arch/arm64/crypto/Kconfig" > endif > > +source "kernel/livepatch/Kconfig" > + > source "lib/Kconfig" > --- a/arch/arm64/include/asm/thread_info.h > +++ b/arch/arm64/include/asm/thread_info.h > @@ -76,6 +76,7 @@ void arch_release_task_struct(struct tas > #define TIF_FOREIGN_FPSTATE 3 /* CPU's FP state is not current's */ > #define TIF_UPROBE 4 /* uprobe breakpoint or singlestep */ > #define TIF_FSCHECK 5 /* Check FS is USER_DS on return */ > +#define TIF_PATCH_PENDING 6 > #define TIF_NOHZ 7 > #define TIF_SYSCALL_TRACE 8 > #define TIF_SYSCALL_AUDIT 9 > @@ -94,6 +95,7 @@ void arch_release_task_struct(struct tas > #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) > #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) > #define _TIF_FOREIGN_FPSTATE (1 << TIF_FOREIGN_FPSTATE) > +#define _TIF_PATCH_PENDING (1 << TIF_PATCH_PENDING) > #define _TIF_NOHZ (1 << TIF_NOHZ) > #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) > #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) > @@ -106,7 +108,8 @@ void arch_release_task_struct(struct tas > > #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \ > _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \ > - _TIF_UPROBE | _TIF_FSCHECK) > + _TIF_UPROBE | _TIF_FSCHECK | \ > + _TIF_PATCH_PENDING) We're ok if _TIF_WORK_MASK is processed in the syscall return path and in irq return to user space. It looks like it is the case, but I'd welcome a confirmation. Anyway, one piece is still missing. _TIF_PATCH_PENDING must be cleared somewhere. I think something like if (thread_flags & _TIF_PATCH_PENDING) klp_update_patch_state(current); in do_notify_resume() (arch/arm64/kernel/signal.c) before _TIF_SIGPENDING processing should do the trick. > #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ > _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ > diff --git a/arch/arm64/include/asm/livepatch.h b/arch/arm64/include/asm/livepatch.h > new file mode 100644 > index 0000000..6b9a3d1 > --- /dev/null > +++ b/arch/arm64/include/asm/livepatch.h > @@ -0,0 +1,38 @@ > +/* SPDX-License-Identifier: GPL-2.0 > + * > + * livepatch.h - arm64-specific Kernel Live Patching Core > + * > + * Copyright (C) 2016 SUSE > + * > + * 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 . > + */ Someone could argue that GPL boilerplate is superfluous thanks to SPDX identifier. I don't, so thanks for putting it there. > +#ifndef _ASM_ARM64_LIVEPATCH_H > +#define _ASM_ARM64_LIVEPATCH_H > + > +#include > +#include > + > +#ifdef CONFIG_LIVEPATCH The guard is unnecessary, I think. The header file is included from include/linux/livepatch.h only. Right after the guard there. > +static inline int klp_check_compiler_support(void) > +{ > + return 0; > +} > + > +static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip) > +{ > + regs->pc = ip; > +} > +#endif /* CONFIG_LIVEPATCH */ > + > +#endif /* _ASM_ARM64_LIVEPATCH_H */ Regards, Miroslav