Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp205434imd; Fri, 26 Oct 2018 07:21:28 -0700 (PDT) X-Google-Smtp-Source: AJdET5dThaF7z66a8F6rCi+c1HIwCSsDbI129DoKWMhr5t9RoT14sqm3GuYiLWZJekZZQDY9PhmY X-Received: by 2002:a63:f444:: with SMTP id p4mr3689357pgk.124.1540563688302; Fri, 26 Oct 2018 07:21:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540563688; cv=none; d=google.com; s=arc-20160816; b=LyCuNswKrxJEnf+ltSy+PysA6xrFpgKA/L5gHDww9vJ645uR3fE4FlTPQxYWQTsG8a 79x+9hjDL+BWm/JnuUnKwB85MroR1aWCJoabKiEScxtPS/4do8PgHLIUKs2RHcjTy8XX pGW9Tp0YTS/L707bnW0GJZ0d3cwzhWRTS/s7Yuqzk8SG7yYI7Cht83d7El/VhwMLi8oE 8F+VQ2b1aJ5aW6dm8QcFZlmPwkuncK2rzkWC4TnqktoxhM6cJg4G8wC/8047xrS0aL1n wqZyULdfwsVnTUbR1n85I2anE/DSaQk6VLzESfNf1neJ0linmRcYVz5fkzrC4F2+chCK 5cKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:from:date:message-id:subject:cc:to; bh=a418wSZ1YvP1mbwl2XkXnBkHuz9hpbGZ65mZmDNL7TM=; b=LM8N6fJNNh/1YenXWBsCNUQerz/iYiOJ/NOhTxT0BkVGrQnuUveB9N6KkdR8Qs5IPp jVlxadTxtm5aaysfPDyux0Z+2awMPC1BW/h6dM3TKHwYVIMj0FhgXcHzlyUAn+z80B9v eMS9faudyYPkaL1HHP6FbeSHtDavkw0lZLsyVHxUv/qBUHtkmuH/Vwk6SpLgPxE8BJJi ALjq8G48qLi6oHvmnncOLt4V5fim/NEDmb8Uwnvdo23lUWvwLCWEhrfPR8RZ2Rx09FC0 u81qo4BkWFpa6HsrvrgVXz1FX6p/5KvOk1XJJhY/ZMpPJOHMxwafiB5Nsa8RVKAyT9IY lSRg== 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 k12-v6si10896900plt.115.2018.10.26.07.20.56; Fri, 26 Oct 2018 07:21:28 -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 S1726341AbeJZW5Z (ORCPT + 99 others); Fri, 26 Oct 2018 18:57:25 -0400 Received: from verein.lst.de ([213.95.11.211]:37724 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726159AbeJZW5Z (ORCPT ); Fri, 26 Oct 2018 18:57:25 -0400 Received: by newverein.lst.de (Postfix, from userid 2005) id D922868C94; Fri, 26 Oct 2018 16:20:08 +0200 (CEST) To: Will Deacon , Catalin Marinas , Julien Thierry , Steven Rostedt , Josh Poimboeuf , Ingo Molnar , Ard Biesheuvel , Arnd Bergmann , AKASHI Takahiro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org Subject: [PATCH v4 0/3] arm64 live patching Message-Id: <20181026142008.D922868C94@newverein.lst.de> Date: Fri, 26 Oct 2018 16:20:08 +0200 (CEST) From: duwe@lst.de (Torsten Duwe) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi again! V4 should include all your requested changes. Since only Julien commented "OK" on the reliable stacktrace part, I finished it on my own. This set now passes the relevant tests in Libor's test suite, so livepatching the kernel proper does work. Remember to apply Jessica's addendum in order to livepatch functions that live in modules. [Changes from v3]: * Compiler support for -fpatchable-function-entry now automagically selects _WITH_REGS when DYNAMIC_FTRACE is switched on. Consequently, CONFIG_DYNAMIC_FTRACE_WITH_REGS is the only preprocessor symbol set by this feature (as asked for by Takahiro in v2) * The dynamic ftrace caller creates 2 stack frames, as suggested by Ard: first a "preliminary" for the callee, and another for ftrace_caller itself. This gives the stack layout really a clean look. * Because the ftrace-clobbered x9 is now saved immediately in the "callee" frame, it can be used to base pt_regs access. Much prettier now. * Dynamic replacement insn "mov x9, lr" is generated using the common framework; a hopefully meaningful macro name is used for abbreviation. * The use_ftrace_trampoline() helper introduced in v3 got renamed and streamlined with a reference variable, both as pointed out by Mark. * Superflous barriers during trace application removed. * #ifdef replaced by IS_ENABLED() where possible. * Made stuff compile with gcc7 or older, too ;-) * Fix my misguided .text.ftrace_regs_trampoline section assumption. the second trampoline goes into .text.ftrace_trampoline as well. * Properly detect the bottom of kthread stacks, by setting a global symbol to the address where their LR points to and compare against it. * Rewrote many comments to hopefully clear things up. [Changes from v2]: * ifeq($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y) instead of ifdef * "fix" commit 06aeaaeabf69da4. (new patch 1) Made DYNAMIC_FTRACE_WITH_REGS a real choice. The current situation would be that a linux-4.20 kernel on arm64 should be built with gcc >= 8; as in this case, as well as all other archs, the "default y" works. Only kernels >= 4.20, arm64, gcc < 8, must change this to "n" in order to not be stopped by the Makefile $(error) from patch 2/4. You'll then fall back to the DYNAMIC_FTRACE, if selected, like before. * use some S_X* constants to refer to offsets into pt_regs in assembly. * have the compiler/assembler generate the mov x9,x30 instruction that saves LR at compile time, rather than generate it repeatedly at runtime. * flip the ftrace_regs_caller stack frame so that it is no longer upside down, as Ard remarked. This change broke the graph caller somehow. * extend handling of the module arch-dependent ftrace trampoline with a companion "regs" version. * clear the _TIF_PATCH_PENDING on do_notify_resume() * took care of arch/arm64/kernel/time.c when changing stack unwinder semantics [Changes from v1]: * Missing compiler support is now a Makefile error, instead of a warning. This will keep the compile log shorter and it will thus be easier to spot the problem. * A separate ftrace_regs_caller. Only that one will write out a complete pt_regs, for efficiency. * Replace the use of X19 with X28 to remember the old PC during live patch detection, as only that is saved&restored now for non-regs ftrace. * CONFIG_DYNAMIC_FTRACE_WITH_REGS and CONFIG_DYNAMIC_FTRACE_WITH_REGS are currently synonymous on arm64, but differentiate better for the future when this is no longer the case. * Clean up "old"/"new" insn value setting vs. #ifdefs. * #define a INSN_MOV_X9_X30 with suggested aarch64_insn_gen call and use that instead of an immediate hex value. Torsten