Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1171525lqt; Fri, 7 Jun 2024 09:53:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVjb9ckKrWgWRVP2frPx0XtC3r2UqQXGBLyivN8qQ0bY4ywC1nRBJGdEJ3uw8SXAR7+ahAIkO/fC09EUfJRVf1/N5RcW7oZ+infZ+M4/g== X-Google-Smtp-Source: AGHT+IFp12EMf+q//QSpWDaQwfn3u1jPO0nnzd5MVDvT6fVdmAQJ13BWWZt+CtwlDV8aud69McnJ X-Received: by 2002:a05:622a:1344:b0:43d:fd98:78b4 with SMTP id d75a77b69052e-44036242e52mr103417401cf.17.1717779229400; Fri, 07 Jun 2024 09:53:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717779229; cv=pass; d=google.com; s=arc-20160816; b=v+QAgKcfkHBdjFKOFnTky2EIxHwssuzv49B6yZ1fPgYMJX3k0qZRHBqV0fK1of9tyd SN6MTAa2YMEU0Y3NJA3laWaYyQBxV/Ch30dh9uZnKZONwcqGtx1b+UTrARd12lLf2IgM t6vQncV7P0Rn0SGeDDg7XoGTzGw30bPOxhjTqVN7NxSOvfwDTG+DXHpv+rVyxgmIY1EY GhOcoIz3LAyezGGtoALxyOgofwhQy9o2A4tWoeoQ3Ohi3m6+4SV6T9QmHlFy+x92ldDA 43CHVWAd3LJ49Ib09mPyijgjewg1tREBu8XPcXyU9qk7ThMzVI1wrfXVQrADdUkaF6zZ OgtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=OTdUVFtzXix+bdaG2RB+YeH7xGkR8WmCZsiG8GhHkEU=; fh=hOCCBHPDFe9rZ/uqAWhLOXxRwl7BsHt0N4XdUhCRfyw=; b=uEONVNgCPQzUlHqUKruWVrqfWk6EZMQHpoIP7tU+ETbmyMyvPgh4YtCmnK3ZDT1cEf MXyM2TRNo6ZArsV6hnPTuvyqsYVKdrvTnD7HbdKbFN4/QSObGrb9d+3t0yERBBZ/Rk4Y O1V22RPMa79LB7hSAWzqaYaqqPcs798ytX+F9SKhS5fn4XeaJIKF641qHk/iWxK6nJHT 5dsjXbJvly/RSPFN0TnH3NyqlQaWHiHpRVk1nGxwsPBfVJmot0zE03DgdAB7XtKvgKXN sa4sntA9UqxQGhI1LU2IePlTPhQpxYdQGCR7WhLVx5Jk/HjE8n34bJo9zS20S3BgA44k 3HWA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="liZs/Fpg"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-206514-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206514-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-44038a85e11si7008091cf.210.2024.06.07.09.53.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 09:53:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206514-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="liZs/Fpg"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-206514-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206514-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 259E61C2197F for ; Fri, 7 Jun 2024 16:53:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C8C619AA76; Fri, 7 Jun 2024 16:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="liZs/Fpg" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61AF133CFC; Fri, 7 Jun 2024 16:53:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717779222; cv=none; b=pEz6TAT73is803x4RD08SKWOkpqTItFbgF1xs1D651NU1UrhRuazZPFxMbDqdSTwEBeHtNK/Ddp1CzmDPwPni3S72raTLi8b68StQuIhHR/61SDwnqp7ECcgR0aczsZQb3G96jA9giM0+0aJLdrDmxokCiDstI9bTIfOaRBkNww= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717779222; c=relaxed/simple; bh=AuzKiSundGz1izubyTxaeCOtAmwYbkm4YXdyJ4strq8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=QSZ1GyWXaC9Xn3HMHu9IDplBcRQSg+pG6VFkkGmu/JRHsYO7tR8/5SAwO3w2DukH4naX1YNcbuMqjl/HKNkwJCplXHen4bL5Lj2ImiqbQCx21oCWwPFbl15bA4m6DuI5DEeCUbMjjUlhIietcAMbxT0+BxF9RHwE+5yY1lqaVTA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=liZs/Fpg; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA7F7C2BBFC; Fri, 7 Jun 2024 16:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717779221; bh=AuzKiSundGz1izubyTxaeCOtAmwYbkm4YXdyJ4strq8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=liZs/FpgUBqXh0i2qRbhpFwXZ8OkUrXzEOV0hiHe9CLS2oZ+b4ZElccNGqhf5bH9U FZ21oo6FnA4bRsVpl5LKfQ0CmxACg2+hYTIDP1RkjB213TIHGyEfRTMQwwK0zXsorc DuRdfEvzhWc/sU2IgziSpZC83MlO+I9jp6JtCJCaaf2SHrvJLpEzWsfBIEKV7q8F96 OaHP6r8U4w65NsJf9TwWcUFTcGWh1UGnwzotVBBoW/rP/UZxnPfbyR5Cc9/fAymFgL XWvrgQ7oO7AdMpjfqYccCQOkCEyC60Jh+WiX4Wx1/RP/JdG62SpV7wE8O5ITR8XPqM IUE9PhOWiWcyw== Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2e6f2534e41so25840541fa.0; Fri, 07 Jun 2024 09:53:41 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXyvQkPIxfFb7LvKdnqYbKAnGlergi+9pyruHedm3iolVNqby9RacLCY8yhvB3p57peqXs+efStk5iNNHn89zmS5pMb/mb08x2bpi7M X-Gm-Message-State: AOJu0YyvbufcFM8sNENeTJq9wPIXvjdLxljMk/KE67knTV4XekxxbAMP Sd7v3C8gz61vPdh701NfwmUCg66+7MApCIt5JAwTWlR+8xMnf8MtgTLnAHdOFLY73Zg87XiwDt7 MGGqNRgPyse0aueT0e62qz8LEMj0= X-Received: by 2002:a2e:8609:0:b0:2ea:b908:d82a with SMTP id 38308e7fff4ca-2eadce4ac69mr19892041fa.29.1717779220298; Fri, 07 Jun 2024 09:53:40 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240605032120.3179157-1-song@kernel.org> In-Reply-To: From: Song Liu Date: Fri, 7 Jun 2024 09:53:28 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kallsyms, livepatch: Fix livepatch with CONFIG_LTO_CLANG To: Miroslav Benes Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, jpoimboe@kernel.org, jikos@kernel.org, pmladek@suse.com, joe.lawrence@redhat.com, nathan@kernel.org, morbo@google.com, justinstitt@google.com, mcgrof@kernel.org, thunder.leizhen@huawei.com, kees@kernel.org, kernel-team@meta.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Miroslav, Thanks for reviewing the patch! On Fri, Jun 7, 2024 at 6:06=E2=80=AFAM Miroslav Benes wrot= e: > > Hi, > > On Tue, 4 Jun 2024, Song Liu wrote: > > > With CONFIG_LTO_CLANG, the compiler may postfix symbols with .llvm. > > to avoid symbol duplication. scripts/kallsyms.c sorted the symbols > > without these postfixes. The default symbol lookup also removes these > > postfixes before comparing symbols. > > > > On the other hand, livepatch need to look up symbols with the full name= s. > > However, calling kallsyms_on_each_match_symbol with full name (with the > > postfix) cannot find the symbol(s). As a result, we cannot livepatch > > kernel functions with .llvm. postfix or kernel functions that use > > relocation information to symbols with .llvm. postfixes. > > > > Fix this by calling kallsyms_on_each_match_symbol without the postfix; > > and then match the full name (with postfix) in klp_match_callback. > > > > Signed-off-by: Song Liu > > --- > > include/linux/kallsyms.h | 13 +++++++++++++ > > kernel/kallsyms.c | 21 ++++++++++++++++----- > > kernel/livepatch/core.c | 32 +++++++++++++++++++++++++++++++- > > 3 files changed, 60 insertions(+), 6 deletions(-) > > I do not like much that something which seems to be kallsyms-internal is > leaked out. You need to export cleanup_symbol_name() and there is now a > lot of code outside. I would feel much more comfortable if it is all > hidden from kallsyms users and kept there. Would it be possible? I think it is possible. Currently, kallsyms_on_each_match_symbol matches symbols without the postfix. We can add a variation or a parameter, so that it matches the full name with post fix. > Moreover, isn't there a similar problem for ftrace, kprobes, ebpf,...? Yes, there is a similar problem with tracing use cases. But the requirement= s are not the same: For livepatch, we have to point to the exact symbol we want to patch or relocation to. We have sympos API defined to differentiate different symbol= s with the same name. For tracing, some discrepancy is acceptable. AFAICT, there isn't an API similar to sympos yet. Also, we can play some tricks with tracing. For example, we can use "uniq symbol + offset" to point a kprobe to one of the duplicated symbols. Given livepatch has a well defined API, while the APIs at tracing side may still change, we can change kallsyms to make sure livepatch side works. Work on the tracing side can wait. Thanks, Song