Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp665480lqb; Wed, 29 May 2024 07:14:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBAep2+Fl7GWKqwgUysGlbPMO6r0O51XmYd+SKz7Yl812sXi3VNAYxu3AXbAgnampyzvnYOrq4c/0lfZpSi8LFskYL6ywAJU1aO9xGIg== X-Google-Smtp-Source: AGHT+IFQ6wKwgFiY3g1uR8xa6qRKJ4XP4cspqC1B/n5tojhkk0Jx4q1LOPomZAz7v0hYM0I1TdZD X-Received: by 2002:ac2:4e91:0:b0:52b:3cf6:db00 with SMTP id 2adb3069b0e04-52b3cf6dbd4mr1045784e87.51.1716992062599; Wed, 29 May 2024 07:14:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716992062; cv=pass; d=google.com; s=arc-20160816; b=Tq37shJMkZBsoqkaYeB/3oWIgn57muBGtCiI17iuuAEEIfv73/VkToNQJf9VbbGd1n 4BDaO5KX2fR2LBBHg9k7kUlzIOH3r2YUTrLDF0mavt9z31vj+grc/XPa+d1Upse0BH9n nbbiheumY8iWe8MlkRsuJb1jsdij13LwvGiaPQy8Rm7AQ9YVc3Ciw1vYVWDbaCqBkuaf 5dqAVWDHJBb7FqF4CuBHeIjjk+rPOlx6B400LBU6IQfxidGZDl7JDCjF+09n7AJwUMWn 1xBtg1CtOWagWaipx6VZci7uUsLhAXjzArcqsVdjeo9q38pMRuJj4e9pHkChf1sL9QxF NEZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature; bh=Obvm5kCvdEN1g3yJAksMyUYT29qKH1+PG1MggvgBEpc=; fh=s5HeTgv+tCj3GWWBErVaWx/es5VNcnJPgLsJ7DJKNQo=; b=DVD9eWugf1gkec1PV/qo/0MlVF5xIpg4TrMCsj6SwHd31YbvX5qOQ4HkdNh900QYQZ 39d7itv5NIXxDHbTe6CUaGf+OKgAFU8kjZUZVtlbMHm8PCcN/0dSjMPjA9OGw5n/tRdp J51msDiSa7/J2o9P7a3TFRtyE6BSiFEL2BF4Z8ptB1sz3uvy9KlSNZmqofQqAam9pXAd c8RV443kBl3iZdz3JNfXVjcQhzWpEra+ywBOEAHhP/ftoVIqhdjjFs3sileQeF1ffIqM zMP/M2Pu23Xn3qwfInwQdzR7IbP2zzVAEggsbuFy7AcRWVO1bh7772uGV1nYaf1/uqWA wDlA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ZHebotvB; dkim=pass header.i=@suse.com header.s=susede1 header.b=ECZTtnEu; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-194248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cdd0337si615555466b.920.2024.05.29.07.14.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:14:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ZHebotvB; dkim=pass header.i=@suse.com header.s=susede1 header.b=ECZTtnEu; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-194248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 24F8D1F21ED5 for ; Wed, 29 May 2024 14:14:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1EEB14B976; Wed, 29 May 2024 14:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ZHebotvB"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ECZTtnEu" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9D261386A7; Wed, 29 May 2024 14:13:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716991998; cv=none; b=ESAQO5A0mIbTCZTCHBXOQRzsHtJiDsDXmx1y4aRqDCYJFXdNzmvT0mlZQqBm+3hrMvJytfONb87qYHOvtGaljwshx1cG4TE309q3+6a0566GbtSQ+WoeSCtOilWGkoQiQqPJTPG8X6kVRYuBI2yQv8WVPAKFWZciKF4KKqapN2A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716991998; c=relaxed/simple; bh=vhrBHK1oYqyYTQQ2KrX7GUmYkG+lYSlCKJrAJ9ciRt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BG5DISSfZAOU8ITqywzwEVoghWypWyLRKroKGGqEtGRCc04cpoxtYZY3wRiDttO7423FuEoyqZU+cBsRPN7Mddv5MTVy0WwCK5oTEkR7w/jFUIXGrzYb8B+g227F66SWQI7YIE6WHBTxpbO8sHReC77KahZgguL/V1mDPt2qjxY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ZHebotvB; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ECZTtnEu; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id EDF1B336BB; Wed, 29 May 2024 14:13:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1716991995; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Obvm5kCvdEN1g3yJAksMyUYT29qKH1+PG1MggvgBEpc=; b=ZHebotvBjTBb6ucKA+ydBuXs+AggyZZDheBcGKeOeGjbyOGDXHBHGvrndF4ROJsPxI+3eT 4iO7bs1BF8dSPGEA+N7ESs866pf70uQsDCUoD0b+Re0dPIysU9MzOmqmvxfqjWJWu/q1ol dlbpuNn/gcm1+lJxt2oAQSOnWdrzfgA= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=ECZTtnEu DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1716991994; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Obvm5kCvdEN1g3yJAksMyUYT29qKH1+PG1MggvgBEpc=; b=ECZTtnEunVD07ng06cHfL2A3+ArV5U2ynd6mv1GQ8i+fFkNtsWVaDKyKbi3O02mgiAodI5 jGwiclY1fMCYP15PzmVppJeHVP2RpbarCa7RBQJJULondhpgQhCf7qRCOB1rddYH2L7MrX 77+l+KC3zI2npr+B79ofBX4QoDb20js= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 89F461372E; Wed, 29 May 2024 14:13:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id CP9UFvo3V2bvWgAAD6G6ig (envelope-from ); Wed, 29 May 2024 14:13:14 +0000 From: Marcos Paulo de Souza To: Miroslav Benes Cc: mpdesouza@suse.com, Joe Lawrence , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, nstange@suse.de Subject: Re: [PATCH 1/2] docs/livepatch: Add new compiler considerations doc Date: Wed, 29 May 2024 11:12:44 -0300 Message-ID: <20240529141309.18902-1-mpdesouza@suse.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Flag: NO X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Rspamd-Queue-Id: EDF1B336BB X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.com:dkim,suse.com:email,suse.cz:email]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] From: mpdesouza@suse.com On Wed, 2 Sep 2020 15:45:33 +0200 (CEST) Miroslav Benes wrote: > Hi, > > first, I'm sorry for the late reply. Thanks, Josh, for the reminder. > > CCing Nicolai. Nicolai, could you take a look at the proposed > documentation too, please? You have more up-to-date experience. > > On Tue, 21 Jul 2020, Joe Lawrence wrote: > > > +Examples > > +======== > > + > > +Interprocedural optimization (IPA) > > +---------------------------------- > > + > > +Function inlining is probably the most common compiler optimization that > > +affects livepatching. In a simple example, inlining transforms the original > > +code:: > > + > > + foo() { ... [ foo implementation ] ... } > > + > > + bar() { ... foo() ... } > > + > > +to:: > > + > > + bar() { ... [ foo implementation ] ... } > > + > > +Inlining is comparable to macro expansion, however the compiler may inline > > +cases which it determines worthwhile (while preserving original call/return > > +semantics in others) or even partially inline pieces of functions (see cold > > +functions in GCC function suffixes section below). > > + > > +To safely livepatch ``foo()`` from the previous example, all of its callers > > +need to be taken into consideration. For those callers that the compiler had > > +inlined ``foo()``, a livepatch should include a new version of the calling > > +function such that it: > > + > > + 1. Calls a new, patched version of the inlined function, or > > + 2. Provides an updated version of the caller that contains its own inlined > > + and updated version of the inlined function > > I'm afraid the above could cause a confusion... > > "1. Calls a new, patched version of the inlined function, or". The > function is not inlined in this case. Would it be more understandable to > use function names? > > 1. Calls a new, patched version of function foo(), or > 2. Provides an updated version of bar() that contains its own inlined and > updated version of foo() (as seen in the example above). > > Not to say that it is again a call of the compiler to decide that, so one > usually prepares an updated version of foo() and updated version of bar() > calling to it. Updated foo() has to be there for non-inlined cases anyway. > > > + > > +Other interesting IPA examples include: > > + > > +- *IPA-SRA*: removal of unused parameters, replace parameters passed by > > + referenced by parameters passed by value. This optimization basically > > s/referenced/reference/ > > > + violates ABI. > > + > > + .. note:: > > + GCC changes the name of function. See GCC function suffixes > > + section below. > > + > > +- *IPA-CP*: find values passed to functions are constants and then optimizes > > + accordingly Several clones of a function are possible if a set is limited. > > "...accordingly. Several..." > > [...] > > > + void cdev_put(struct cdev *p) > > + { > > + if (p) { > > + struct module *owner = p->owner; > > + kobject_put(&p->kobj); > > + module_put(owner); > > + } > > + } > > git am complained here about whitespace damage. > > [...] > > > +kgraft-analysis-tool > > +-------------------- > > + > > +With the -fdump-ipa-clones flag, GCC will dump IPA clones that were created > > +by all inter-procedural optimizations in ``.000i.ipa-clones`` files. > > + > > +kgraft-analysis-tool pretty-prints those IPA cloning decisions. The full > > +list of affected functions provides additional updates that the source-based > > +livepatch author may need to consider. For example, for the function > > +``scatterwalk_unmap()``: > > + > > +:: > > + > > + $ ./kgraft-ipa-analysis.py --symbol=scatterwalk_unmap aesni-intel_glue.i.000i.ipa-clones > > + Function: scatterwalk_unmap/2930 (include/crypto/scatterwalk.h:81:60) > > + isra: scatterwalk_unmap.isra.2/3142 (include/crypto/scatterwalk.h:81:60) > > + inlining to: helper_rfc4106_decrypt/3007 (arch/x86/crypto/aesni-intel_glue.c:1016:12) > > + inlining to: helper_rfc4106_decrypt/3007 (arch/x86/crypto/aesni-intel_glue.c:1016:12) > > + inlining to: helper_rfc4106_encrypt/3006 (arch/x86/crypto/aesni-intel_glue.c:939:12) > > + > > + Affected functions: 3 > > + scatterwalk_unmap.isra.2/3142 (include/crypto/scatterwalk.h:81:60) > > + helper_rfc4106_decrypt/3007 (arch/x86/crypto/aesni-intel_glue.c:1016:12) > > + helper_rfc4106_encrypt/3006 (arch/x86/crypto/aesni-intel_glue.c:939:12) > > The example for the github is not up-to-date. The tool now expects > file_list with *.ipa-clones files and the output is a bit different for > the recent kernel. > > $ echo arch/x86/crypto/aesni-intel_glue.c.000i.ipa-clones | kgraft-ipa-analysis.py --symbol=scatterwalk_unmap /dev/stdin > Parsing file (1/1): arch/x86/crypto/aesni-intel_glue.c.000i.ipa-clones > Function: scatterwalk_unmap/3935 (./include/crypto/scatterwalk.h:59:20) [REMOVED] [object file: arch/x86/crypto/aesni-intel_glue.c.000i.ipa-clones] > isra: scatterwalk_unmap.isra.8/4117 (./include/crypto/scatterwalk.h:59:20) [REMOVED] > inlining to: gcmaes_crypt_by_sg/4019 (arch/x86/crypto/aesni-intel_glue.c:682:12) [REMOVED] [edges: 4] > constprop: gcmaes_crypt_by_sg.constprop.13/4182 (arch/x86/crypto/aesni-intel_glue.c:682:12) > > Affected functions: 3 > scatterwalk_unmap.isra.8/4117 (./include/crypto/scatterwalk.h:59:20) [REMOVED] > gcmaes_crypt_by_sg/4019 (arch/x86/crypto/aesni-intel_glue.c:682:12) [REMOVED] > gcmaes_crypt_by_sg.constprop.13/4182 (arch/x86/crypto/aesni-intel_glue.c:682:12) > > > > The rest looks great. Thanks a lot, Joe, for putting it together. I think that we should start provinding a "Livepatch creation how-to", something similar, but for now I believe that some documentation is better than no documentation. This document can evolve to reach such point in the future, but for now, with Miroslav suggestions applied: Acked-by: Marcos Paulo de Souza > > Miroslav