Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp403214yba; Fri, 26 Apr 2019 02:02:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqztjhdvO8LoehkiE9f9gb/Xifjp4mvMj72O4Fp59vrt+RYP64nx6c3rw0RxAxyUODJXOGPe X-Received: by 2002:a63:1d4f:: with SMTP id d15mr41122553pgm.347.1556269338351; Fri, 26 Apr 2019 02:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556269338; cv=none; d=google.com; s=arc-20160816; b=sEJfVGo85pDTJMSV3kRNazCE6g/+fEh9NnDVnaoqkWSTb4Qf8jf0qhEMomWrQMt4/L +b/Ca6P4G7nzviawYX+mGldyS53kqIr5T+k9dmkitEhxH63x2ER36VgUJWNV734hgqY3 hiRziy48+64Og7XTL6DH41IGfvj4brir7Jwa/p/hiEHoMTNQPeVjgaBs0A717QO9bQTo 6qBi5Xw1o1YmvTbrHQQcCUAHN97XDNLae72C9JL2AfpNQNy+znHVyTO4Vz8kZT0fD2KH r4SMa9+BTGK52Z85WeR1PuGci4X5b9tUyNf4wbBED5JAovyA/JyrcWW+WhKto9j+DGrf W0pQ== 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; bh=LTfZWoZm1Vx7UzJGk239IVE+QH8jZFjCU0khGNCK3+o=; b=I9tGba8iseN43tD30tWTA5NcRzLHYaKfY5KT5eSC2VTkHfJ/QkLX1VNAZULLeUfcpn Tv6EDnoUwFWkJozkSaxVsZeW8EWPfdSjddZfLgLX5P0pWzjoessXURbEJSC6USm3XYN4 dIhR5Y3M13OevzUfxOcEB/O1PG6d9XExFToSSWNdCn1F7zK3tAr97WHhuZ06fTDb4aqp dgV3oai32xGr2CG6IaGePdz52XHUFmDJXR60j/HPAMaYZWnOiN3ilaFFceRhUw3YZ4Lb 8WpqZdLwQGC4D7miZ0K3LHuhizoxyjlJ9v6TRAluM6WUohbTz32Vnm1EeMVr9PF3uyFP kVvg== 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 k5si8003260pll.254.2019.04.26.02.02.02; Fri, 26 Apr 2019 02:02:18 -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 S1726083AbfDZJAv (ORCPT + 99 others); Fri, 26 Apr 2019 05:00:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:49656 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725854AbfDZJAv (ORCPT ); Fri, 26 Apr 2019 05:00:51 -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 04ECAAF8D; Fri, 26 Apr 2019 09:00:49 +0000 (UTC) Date: Fri, 26 Apr 2019 11:00:48 +0200 (CEST) From: Miroslav Benes To: Josh Poimboeuf cc: live-patching@vger.kernel.org, Peter Zijlstra , Mark Rutland , linux-kernel@vger.kernel.org, mliska@suse.cz, hubicka@ucw.cz Subject: Re: Livepatch vs LTO In-Reply-To: <20190425152628.ogk4woi3omeocwly@treble> Message-ID: References: <20190425152628.ogk4woi3omeocwly@treble> 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 [ adding CCs ] On Thu, 25 Apr 2019, Josh Poimboeuf wrote: > Hi all, > > On IRC, Peter expressed some concern about -flive-patching, specifically > that the flag isn't compatible with LTO. > > The upstream kernel currently doesn't support LTO, but Android is using > it with LLVM: > > https://source.android.com/devices/tech/debug/kcfi > > And there seems to be progress being made in that direction for > upstream. > > Live patching has at least the following issues with LTO: > > - For source-based patch generation (klp-convert and friends), the GCC > manual says that -flive-patching is incompatible with LTO. Does > anybody know if that's a hard incompatibility, or can it be fixed? Honza could know more. It was either that LTO by itself complicates things for live patching, or that LTO adds more optimizations which are potentially unsafe. > Also, what about the performance implications of this flag with LTO? > Might they become more pronounced? It could. Theoretically. The scope for optimizations would be much broader. > Also I wonder if -fdump-ipa-clones works with LTO? It should. According to Martin, there is (almost) nothing special about LTO. Optimization infrastructure is the same, only the scope is not limited to one translation unit. > I also wonder about the future of source-based patch generation with > LLVM. Will it also have -flive-patching and -fdump-ipa-clones flags? Honestly no idea. > - For binary-based patch generation (kpatch-build), we currently diff > objects at a per-compilation-unit level. That would have to be > changed to work on vmlinux.o instead. > > - Objtool would also have to be changed to work on vmlinux.o. It's > currently not optimized for large files, and the per-.o whitelisting > would need to be fixed. And there may be other issues lurking. > > Also, thinking about objtool in this context has given me another idea, > which might allow us to get rid of the use of -flive-patching and > -fdump-ipa-clones altogether (which are both nasty and way too > compiler-dependent): > > Since objtool is already reading every function in the kernel, it could > create a checksum associated with each function, based on all the > instructions (both within the function and any alternatives or other > special sections it relies on). The function checksums could be written > to a file. > > Then, when a patch file is applied and the kernel rebuilt, the checksum > files could be compared to determine exactly which functions have > changed at a binary level. > > Thoughts? Any reasons why that wouldn't work? I think it could work. If nothing else, it would give us the information we look for. > And, if we wanted to take the idea even further, objtool could have the > ability to write the changed functions to a new object file. Voila, we > now pretty much have kpatch-build :-) (Though whether this is better > than source-based patch generation is certainly an open question.) ...worth of discussion. Miroslav