From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 5D3C63CAA59 for ; Thu, 15 Oct 2026 15:42:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792078982; cv=none; b=ICoalYJlLAXCqMZo6JeO/kj8sXMt2VKagQS4OVpg/sTVY/CDRnoXWrL3wIR88p0k8BGyIJZkJ+g6S6OH0UjilchWsXCzXYWxan8gviZZi2lXl1oZyS3tcS5zYciS6f3/8V0F3ehucDAshwFdoCLQYt4Ul1Uf/4N366dE9+5OE2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792078982; c=relaxed/simple; bh=1fUOi+Usxn2LQcFzjoDicMxQvfperVSbtfIS6t3a0mM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gpBzFTeqHQ+85wOmg3iSv4FePW8PwYZ+L+COgFewECgnWOWQqBBjiY6qsgTWRF+0fuV1xBlWS8UMzVYOTVlfyX0KadJxzOzoNj0/ML4/9SnWtghZG3DtqScZbrcNNOMY4u42ppcCLP3VY/wFVdpGWtX+mEsEXy7RWupzZncDN6w= 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 (2048-bit key) header.d=suse.com header.i=@suse.com header.b=R0UR9SXf; arc=none smtp.client-ip=209.85.128.48 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="R0UR9SXf" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4a01933b584so47021775e9.0 for ; Thu, 15 Oct 2026 08:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1792078967; x=1792683767; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8EVUVXTF9B/pmjVEVo0zfJaBGiZoNVg7V5lse2RyO7M=; b=R0UR9SXfSdLRKN8vgsjzhyd81oaEz7tHTwslAVD4uu2yocB8iyTzeaX91HJfAF2HSZ zfyNFy9tY2rveIy5HSk4kHu6cou98Mmm65Nw/ib9mtV2wnXWSnap0yORcKiRn9+bhNLb /HvkgPwk8c21B4vfdeFwnATqt/tKh7V1N6JFjc1GswxG79FMaIisTlhabNQRTkYz/AAi A1KK2BSF7pJOfDu8sLbpi305mh4DqIdXIenAOtLPi3roSTwyU1GWiEULVpymwqlkfLkZ ApWTy1oTpVVOcfy57kt0RsQYUZoCNCDNc0yb16GC0j95gqwCT6HKnJMFBD1/29NWON5y v/Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792078967; x=1792683767; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8EVUVXTF9B/pmjVEVo0zfJaBGiZoNVg7V5lse2RyO7M=; b=EniYDRyJh6GSSnurWKHWoT+TN8YTm5FBz0cfE9L5fm0of/PCboRTFutHzBOylXD2Y7 vxv9n6NUIWvN98GuBlwIVdZ4pYIya/c4CsPK6xyjn9VOMSQhOd8M+C0PYWSDtP0+bJHv Wk54y++e6UH62oz9WbMGpKTr56OhqHqJ5F4XM9zUdndU2rxDmUX3I7yfUVzuQAYJmOxT MvMiweCQ4rMVKAqv5qxHkj7ul6B3+eUSkDew614CuavkCs3dk7xQ1lH72jxEdVR65Gg4 yFgNu7htArKYVfc5eW5cT40+KfaE1nlEdOM8HD+F4wGtwaftb57iOXouoeC5o2PDRF3N nhOg== X-Forwarded-Encrypted: i=1; AKwUvBwngtwALYkaFiIq4RrkhN6auJDH/5w+v2fFIaXzxoa8XNR9WQdjf8UbEKsu20qvC81Cb6alDRNnFu/+l48=@vger.kernel.org X-Gm-Message-State: AFq9FYIu+JX9duAJd/t3JwHQHKIiV4wbEgDcJTgOinpAFHpWpscDDGX7 ciT8HVHqHSOkHzSm+punqa99qJ2lVErs1hQlJtkzh8sPSh/g/BarQeLPk/Cr/kFsHBI= X-Gm-Gg: AYBFou08PauyUQyjlhex5AgpNe9tdxIUrd1vIOiD9mZG+btYLWdNgSr2uYGBzFFEz3M sf7Xpdfpd0lhtpygTfDVzgwwVg3Z8b/ok8PKdd5cpGejLX1LZ3qLGdumN7Lc94jBRYKNqYQzmrd nM/NRs82IKwPPVbjYNy1sbjLJYWauPecAmlECOncUjFNno0AX6PbZnjy399SGjCC3LyIb+I1PzH 5eZ2FEdv1tCanv8w0ZU5viArIQ07qPxat2LjXQmn8YKYfLu6KBOJDjEp1I2Zwm3k/uVGGjHZPMV X25SxsMbKzhMdQ00n4GC6NXyi2qUxEoa09+gDMTIaT8aPP8LZPxMO5R6sqFm/q8fFGnYOwVZjrN xDbrhabyrnOm6jfnSyYcSJFu/VIuI1XLWOiox/j2F1m25ZapdhTfGnMrM5qdoE9Zda16cL9PkC+ 4ZWTyggM9rrV/TOBhiwV39kSO75bQWOOVh+Vmxlim+YKRY6RdfHD7OzExX+ERYg4rHtoemtzHQv qz7XvBBtrXq7iX8FNLcwRrMeiIxShMQnKO08Y/l5Z6p8w== X-Received: by 2002:a05:600c:8b82:b0:49f:fd2d:23c7 with SMTP id 5b1f17b1804b1-4a18e4b887amr354993855e9.27.1792078967287; Thu, 15 Oct 2026 08:42:47 -0700 (PDT) Received: from ?IPV6:2a07:de40:8100:0:89a9:fd0e:583d:4a53? ([2001:af0:8000:1409:193:86:92:181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a1bd66c5e6sm52172585e9.2.2026.10.15.08.42.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Oct 2026 08:42:46 -0700 (PDT) Message-ID: Date: Thu, 15 Oct 2026 17:42:45 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 13/22] modpost: cache section relocation mismatch state To: "Lorenzo Stoakes (ARM)" Cc: Linus Torvalds , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Masahiro Yamada , Alexey Gladkov , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Arnd Bergmann , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Ilias Apalodimas , Josh Poimboeuf , Peter Zijlstra , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?UTF-8?Q?Onur_=C3=96zkan?= , Jonathan Corbet , Randy Dunlap , Kees Cook , "Gustavo A. R. Silva" , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-doc@vger.kernel.org, Jens Axboe , linux-hardening@vger.kernel.org References: <20260923-build-speedup-v4-0-73128809a4a4@kernel.org> <20260923-build-speedup-v4-13-73128809a4a4@kernel.org> Content-Language: en-US From: Petr Pavlu In-Reply-To: <20260923-build-speedup-v4-13-73128809a4a4@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 9/23/26 7:18 PM, Lorenzo Stoakes (ARM) wrote: > For every relocation modpost invokes check_section_mismatch() to determine > whether there is any kind of mismatch between the source and destination, > and if so which classification applies. > > Each time it does this it invokes section_mismatch() which iterates > through the sectioncheck[] array every time it's called. > > When walked a relocation section the source is fixed and there aren't many > targets, so the same names are looked up over and over again. > > Therefore cache not only mismatch categorisation but also whether a > mismatch even exists for a given section and look up the sections in the > cache. > > Special indices (undefined, absolute, common) take the uncached path as > before. > > This results in very significant speed ups for allmodconfig incremental > builds. > > modpost is on the serial tail of every build that links vmlinux. > > Whole build, 128-thread Threadripper 9980X, best of N runs: > > before after delta > ------------------------------- > x86 defconfig, touch mm/vma.c, gcc 8.5s 8.3s -0.14s (-2%) > x86 defconfig, touch mm/vma.c, clang 7.7s 7.6s -0.13s (-2%) > x86 allmodconfig, touch mm/vma.c, gcc 33.9s 29.4s -4.5s (-13%) > x86 allmodconfig, touch mm/vma.c, clang 31.9s 27.9s -4.0s (-13%) > > Assisted-by: LLM > Signed-off-by: Lorenzo Stoakes (ARM) This looks mostly ok to me. Below are some nits you might want to consider addressing. > --- > scripts/mod/modpost.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 64 insertions(+), 2 deletions(-) > > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c > index 75374c64b8cc..0fd43c8a89ea 100644 > --- a/scripts/mod/modpost.c > +++ b/scripts/mod/modpost.c > @@ -1155,12 +1155,67 @@ static void check_export_symbol(struct module *mod, struct elf_info *elf, > name); > } > > +/* > + * mismatch_cache[section index] -> > + * 0 - uncached. > + * -1 - no mismatch. > + * >0 - mismatch index + 1. > + */ > +static int *mismatch_cache; It might be cleaner to maintain this cache per elf_info, since it logically belongs to the processing of an individual ELF file. This would also be consistent with the existing symsearch cache, which uses elf::symsearch. The description could use 'to_secndx' instead of 'section index' to clarify whether it refers to the source or destination section of a relocation. > + > +static void init_mismatch_cache(unsigned int num_sections) > +{ > + mismatch_cache = xcalloc(num_sections, sizeof(*mismatch_cache)); > +} > + > +static void reset_mismatch_cache(unsigned int num_sections) > +{ > + memset(mismatch_cache, 0, num_sections * sizeof(*mismatch_cache)); > +} > + > +static void free_mismatch_cache(void) > +{ > + free(mismatch_cache); > + mismatch_cache = NULL; > +} > + > +static const struct sectioncheck > +*cache_mismatch(unsigned int secndx, const struct sectioncheck *mismatch) Similarly here, s/secndx/to_secndx/. > +{ > + if (!mismatch) { > + mismatch_cache[secndx] = -1; > + return NULL; > + } > + > + mismatch_cache[secndx] = (mismatch - sectioncheck) + 1; > + return mismatch; > +} > + > +static const struct sectioncheck *get_section_mismatch(const char *fromsec, > + const struct elf_info *elf, unsigned int secndx) s/secndx/to_secndx/, and the fromsec and elf arguments could be swapped for consistency with the rest of the code. > +{ > + int cached; > + > + if (secndx >= elf->num_sections) > + return section_mismatch(fromsec, sec_name(elf, secndx)); > + > + cached = mismatch_cache[secndx]; > + if (cached < 0) > + return NULL; > + if (cached > 0) > + return §ioncheck[cached - 1]; > + > + return cache_mismatch(secndx, > + section_mismatch(fromsec, sec_name(elf, secndx))); > +} > + > static void check_section_mismatch(struct module *mod, struct elf_info *elf, > Elf_Sym *sym, > unsigned int fsecndx, const char *fromsec, > Elf_Addr faddr, Elf_Addr taddr) > { > - const char *tosec = sec_name(elf, get_secindex(elf, sym)); > + const unsigned int to_secndx = get_secindex(elf, sym); The const qualifier can be dropped from the to_secndx definition to match the usual kernel style. -- Thanks, Petr