Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2455112pxj; Mon, 10 May 2021 03:28:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbNXEKIptps+y4NT9M8uAB0427YjiEdBqOhw9/PrZhPhvQ2t6UEwLg29uD6nO5GH9qdtKy X-Received: by 2002:a05:6e02:13d0:: with SMTP id v16mr21089026ilj.8.1620642493117; Mon, 10 May 2021 03:28:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620642493; cv=none; d=google.com; s=arc-20160816; b=Ba+7iXlFFZXK9AMsuVBebn7573AtpddwkseGQzd6SPoMk7T6SQ+gfHhSttpZSJvrCE L1DfNdjizxp02+Cxt5HW4VlYvuKP6QaNyZdoIhRBAXS4tV8iTUzpLEXYW8IMMkkfxMHV XghWXIEEsUzEUx3T9ZFd1un6XMk6buvVTQInBeO4CvqzmEWw84vcVcgdreQAVuvKO5tA iOZLhJspXacawZsKpVdsZkabBLhgHq95VnRZsaVpGfh5M1tu4I5AZkdFGIJ/TR1U6b+O N9N7k8hWH2K8MXGRYRPBEKLVTt6kAbfZiOmho1TwO5iVO7LVzk6AVFN5MhF6Vf7TTp6o Lyag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6qT6M6ncipCt/7pPJOS0xmck1g2J13iYmtTOxl1Xuos=; b=AsxMWKXf0P41CxgE6TTqKMOBtgMxYAyM8xTOkRTVER7QnvYOc2PjekNHhA0tnWEU3L KEZZEaINBYtG9KHMpLPHJPQUMAcgrSXCGTwFLxMWNq5tYJmvsWxKJh2QtmoEn3n7m2Te qSURjLHoQZKisfbfwNclrCMVp1kj81+Ja2/SR7AiZC7CehzEPp2+QiSc2yBUpAFXz9at 3q4pj4yb4T7z7alY6S4oep1ltp9VAhleEvXysRCL10isUCflVBfqIQqjCVkg0pxH+9PW eAzM+uK/L4hZlh6kDRYdhCkcQili9gPkz2RZ1KqPJ2UH/FEJoWL+WlWCsIVoRhPymiUG bmLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="f/dGRHyj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si15115911ili.130.2021.05.10.03.28.01; Mon, 10 May 2021 03:28:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="f/dGRHyj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231509AbhEJK0k (ORCPT + 99 others); Mon, 10 May 2021 06:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231289AbhEJKZw (ORCPT ); Mon, 10 May 2021 06:25:52 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5808FC061763 for ; Mon, 10 May 2021 03:24:32 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id d11so16015762wrw.8 for ; Mon, 10 May 2021 03:24:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6qT6M6ncipCt/7pPJOS0xmck1g2J13iYmtTOxl1Xuos=; b=f/dGRHyj5BIKadY6degO/5EKNGsTacO8jsgMxx9ckDzDgeJn7fEu9AIW+EMqMWwU6t 26OZxhHnWZ03QaxGTQsNiAw+QLjH4uX0atqp4tfCC5UmzavWLUbsgDdd7GoMHvR5v1cA LNV1tctfP+XdOiBxUdYQwlkxfGTGxXfwbINIho+dCGNgij0rAXjsxpDJSW1iuA+0uyL+ j60POf94ylWBPvC1/65EiPAAaxNdUmc5kQ8+4PgFmX0EW8qDNFsgGxvD7Od0jvodpV7x lWLCtLdZONS5rEJ0Dvi0nXDlpVpE4suHM2cXa/BvKpYVRHVpubruTaugJnMQKj66UWjV qBtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6qT6M6ncipCt/7pPJOS0xmck1g2J13iYmtTOxl1Xuos=; b=hNIplz3mcaWmhKMig1LtBEL5lF0mgA7ar/dMpefCH7JiSmOjMK/QfwvJ/4eupfALJB hxeHL7r/TGSgx68nfPybK5IpwoK3PfLGX7YpqWIRX46+xqO7sl8Vjkm0vLhIloupbpjT V79m4GxFZTROPqjb6mas+kKuVflTNxohkhNascLjJKRwID8R5+7x7PwUrXKoOrW8WDMp GXOrHj9uUSlqC8W5F0MAKAHCjpJO6MZZiWypUJ6p5bJkQfZwdexJhBNLy72M+4Z0WVGD VlxWNP5pXNPlTXa9tgalTV7TV5yTY9oQhgC/VsDf+ic3WejDjtdByxMj43gaRIMHQlgw nWxw== X-Gm-Message-State: AOAM532cmz9mLzb2fxzMkDk8loHR/puvZarVQgHsneJjyGOMvc2/sVXW jNG/xGJ3waAY1M1MmXFUm3UHnhIh+FHaCA== X-Received: by 2002:a5d:6811:: with SMTP id w17mr30283903wru.348.1620642270939; Mon, 10 May 2021 03:24:30 -0700 (PDT) Received: from google.com (105.168.195.35.bc.googleusercontent.com. [35.195.168.105]) by smtp.gmail.com with ESMTPSA id k6sm24748677wmi.42.2021.05.10.03.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 03:24:30 -0700 (PDT) Date: Mon, 10 May 2021 10:24:27 +0000 From: Quentin Perret To: gregkh@linuxfoundation.org, masahiroy@kernel.org Cc: linux-kernel@vger.kernel.org, maennich@google.com, gprocida@google.com, kernel-team@android.com Subject: Re: [PATCH] export: Make CRCs robust to symbol trimming Message-ID: References: <20210408180105.2496212-1-qperret@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210408180105.2496212-1-qperret@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thursday 08 Apr 2021 at 18:01:05 (+0000), Quentin Perret wrote: > The CRC calculation done by genksyms is triggered when the parser hits > EXPORT_SYMBOL*() macros. At this point, genksyms recursively expands the > types, and uses that as the input for the CRC calculation. In the case > of forward-declared structs, the type expands to 'UNKNOWN'. Next, the > result of the expansion of each type is cached, and is re-used when/if > the same type is seen again for another exported symbol in the file. > > Unfortunately, this can cause CRC 'stability' issues when a struct > definition becomes visible in the middle of a C file. For example, let's > assume code with the following pattern: > > struct foo; > > int bar(struct foo *arg) > { > /* Do work ... */ > } > EXPORT_SYMBOL_GPL(bar); > > /* This contains struct foo's definition */ > #include "foo.h" > > int baz(struct foo *arg) > { > /* Do more work ... */ > } > EXPORT_SYMBOL_GPL(baz); > > Here, baz's CRC will be computed using the expansion of struct foo that > was cached after bar's CRC calculation ('UNKOWN' here). But if > EXPORT_SYMBOL_GPL(bar) is removed from the file (because of e.g. symbol > trimming using CONFIG_TRIM_UNUSED_KSYMS), struct foo will be expanded > late, during baz's CRC calculation, which now has visibility over the > full struct definition, hence resulting in a different CRC for baz. > > This can cause annoying issues for distro kernel (such as the Android > Generic Kernel Image) which use CONFIG_UNUSED_KSYMS_WHITELIST. Indeed, > as per the above, adding a symbol to the whitelist can change the CRC of > symbols that are already kept exported. As such, modules built against a > kernel with a trimmed ABI may not load against the same kernel built > with an extended whitelist, even though they are still strictly binary > compatible. While rebuilding the modules would obviously solve the > issue, I believe this classifies as an odd genksyms corner case, and it > gets in the way of kernel updates in the GKI context. > > To work around the issue, make sure to keep issuing the > __GENKSYMS_EXPORT_SYMBOL macros for all trimmed symbols, hence making > the genksyms parsing insensitive to symbol trimming. > > Signed-off-by: Quentin Perret Gentle ping. Is there anything else I should do in this one? Thanks, Quentin