Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1984554yba; Thu, 25 Apr 2019 08:48:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0eMT1ZyNIopHijsVt+kcgCEcEwlAlVvUIklKOSbp6VmXTutxdYd0+1jaIvQ9qUYlNdJI5 X-Received: by 2002:a17:902:4681:: with SMTP id p1mr38783133pld.42.1556207336401; Thu, 25 Apr 2019 08:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556207336; cv=none; d=google.com; s=arc-20160816; b=bUl7gn1IXhh6tw/6EN8DjwigyLmiLIC9YKAdiZj73ZttDiVxLCTxltK9gJH64rJ3Q3 T+5R4Pth6fNP+3FTwDMOw7HLxi6RIcY2bsXpi90vPmDNLeVwb+2PxOppg9mj9WZeDtdR TVoL15MG74+wTMPqRD7aDpswkj8Td4CeU2fQUoPIROtgEWSRfedwvhruferplBockA5+ ku49WQmNcjo/zLx9XXaP8A9an7u0+BnPe/8HHmBQldn4WD70Svql4CaQ4qdEHgYJN2cT zst+pF3NIwYwgLDgEfOl2zUsOkoT6tSHscO954RL7v2iLuEIpWLk2OxigkKFFG4z91Hs mgRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=d8r5LpNAiQax8R2Lnx39k7N2WmiZ4qod+/+lXPvxVvc=; b=zmMzcQv7UNSxgVt4k3kMIrH2ej3uMUQqSElMAiUnEq2joQF3tlDYwPzMmhKhkMy0Sl 4Z/kckPlR5hbEeI2jOWmcNnMM4JUjDReRncCQN6xycUcL4cikTWntEp9R+Qza+Kqtf5g VGZI4V5fdya7zf7pG4pW7Kqj+Me/NEimqOBIHYlULqPZB0PJikLlhVMkMvUsgO7qnmhb FsYmjgwIx2BqpGRDyWJ1fuGLDf5IYkB40pdtDvkvG9NnbhVIF9at3kq0lIIKjCdGTnjS VJfx1N8cabqg+UQqHXM1enBQqbLESoWEEU/4Lu35dXgpcxaHNb3EyQnmRWlaMuU6Ti35 VyBA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11si22271100plk.419.2019.04.25.08.48.39; Thu, 25 Apr 2019 08:48:56 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728876AbfDYP0c (ORCPT + 99 others); Thu, 25 Apr 2019 11:26:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53910 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727337AbfDYP0b (ORCPT ); Thu, 25 Apr 2019 11:26:31 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A91FA307D91F; Thu, 25 Apr 2019 15:26:31 +0000 (UTC) Received: from treble (ovpn-123-99.rdu2.redhat.com [10.10.123.99]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 956FF60C8E; Thu, 25 Apr 2019 15:26:30 +0000 (UTC) Date: Thu, 25 Apr 2019 10:26:28 -0500 From: Josh Poimboeuf To: live-patching@vger.kernel.org Cc: Peter Zijlstra , Mark Rutland , linux-kernel@vger.kernel.org Subject: Livepatch vs LTO Message-ID: <20190425152628.ogk4woi3omeocwly@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 25 Apr 2019 15:26:31 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Also, what about the performance implications of this flag with LTO? Might they become more pronounced? Also I wonder if -fdump-ipa-clones works with LTO? I also wonder about the future of source-based patch generation with LLVM. Will it also have -flive-patching and -fdump-ipa-clones flags? - 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? 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.) -- Josh