From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 229AEC433E0 for ; Sat, 4 Jul 2020 12:11:16 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E2ACC20885 for ; Sat, 4 Jul 2020 12:11:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HLH/Up0+"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="esjXWAn/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2ACC20885 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6tenVKRaV/Lvseu0+09nrRGqe+P2oVbfQPKfcEvKJqI=; b=HLH/Up0+ofcJ12uZ1mR07RiS3 Qhes9H5x8VpE5p4ZkSm0Im6xEi8c56GIHNfhzExINeQjo10SFBuXkWkhOhG6EiLgj0tV1hwKkeuXs Q9ctf6/0bBel7ESmzcdAdfoc7QLAJAEjJ38ojTFdnbWmqV+1dStHi7wZroYGEG7nNgyz5NFAmyYNW wmW3W2+bduggzjgH3wg+JVwE6xzGKwV355Mif+9lumDtOnw+b0kqFhTwUywV4g0NcGdVViEnlHdc8 d6qTUDGMCRzy9I6YqlCRI6PDmrflq4E2DW3uD7PkjFgFkrhfP9CsabYKZinhWOkPv8aKEo4S8qt3V WX+DupunQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jrgzJ-0002SK-4j; Sat, 04 Jul 2020 12:09:45 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jrgzF-0002Rv-UH for linux-arm-kernel@lists.infradead.org; Sat, 04 Jul 2020 12:09:42 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1F26C20885; Sat, 4 Jul 2020 12:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593864579; bh=X22tQmeMJ8J3B60hTKOzNA4Xdp+LVatGyVDda2h5yfI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=esjXWAn/cWRcpXzz410rtEMYcAQdEn8CFgrY8KAcQghAJyp2xZjohPVYbxTlJp7Ou l+ROhInoynGXtle7oWOE61SUDm34ZjtXWXHDFlDeThvaeUr9ErOrr1tmrW+uSgZd1p c44hkrUSNW/tEjp4YaNrlG4n7U80WqNuRlZxBRZ0= Date: Sat, 4 Jul 2020 13:09:34 +0100 From: Will Deacon To: Saravana Kannan Subject: Re: [PATCH v2] arm64/module: Optimize module load time by optimizing PLT counting Message-ID: <20200704120934.GA21097@willie-the-truck> References: <20200623011803.91232-1-saravanak@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200704_080942_188922_68F96ACC X-CRM114-Status: GOOD ( 25.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , Android Kernel Team , Ard Biesheuvel , linux-arm-kernel , Linux Kernel Mailing List Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jul 03, 2020 at 05:47:24PM -0700, Saravana Kannan wrote: > On Thu, Jul 2, 2020 at 8:30 AM Ard Biesheuvel wrote: > > On Tue, 23 Jun 2020 at 03:27, Saravana Kannan wrote: > > > diff --git a/arch/arm64/kernel/module-plts.c b/arch/arm64/kernel/module-plts.c > > > index 65b08a74aec6..0ce3a28e3347 100644 > > > --- a/arch/arm64/kernel/module-plts.c > > > +++ b/arch/arm64/kernel/module-plts.c > > > @@ -253,6 +253,40 @@ static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int num, > > > return ret; > > > } > > > > > > +static bool branch_rela_needs_plt(Elf64_Sym *syms, Elf64_Rela *rela, > > > + Elf64_Word dstidx) > > > +{ > > > + > > > + Elf64_Sym *s = syms + ELF64_R_SYM(rela->r_info); > > > + > > > + if (s->st_shndx == dstidx) > > > + return false; > > > + > > > + return ELF64_R_TYPE(rela->r_info) == R_AARCH64_JUMP26 || > > > + ELF64_R_TYPE(rela->r_info) == R_AARCH64_CALL26; > > > +} > > > + > > > +/* Group branch PLT relas at the front end of the array. */ > > > +static int partition_branch_plt_relas(Elf64_Sym *syms, Elf64_Rela *rela, > > > + int numrels, Elf64_Word dstidx) > > > +{ > > > + int i = 0, j = numrels - 1; > > > + > > > + if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE)) > > > + return 0; > > > + > > > + while (i < j) { > > > + if (branch_rela_needs_plt(syms, &rela[i], dstidx)) > > > + i++; > > > + else if (branch_rela_needs_plt(syms, &rela[j], dstidx)) > > > + swap(rela[i], rela[j]); > > > > Nit: would be slightly better to put > > > > swap(rela[i++], rela[j]); > > > > here so the next iteration of the loop will not call > > branch_rela_needs_plt() on rela[i] redundantly. But the current code > > is also correct. > > Oh yeah, I noticed that unnecessary repeat of branch_rela_needs_plt() > on rela[i] when j had to be decremented, but forgot to handle it after > I was done with all the testing. Yeah, I guess you can decrement j as well, but I just think it makes the logic harder to read and more error-prone if we change it later. > But I did compare it to the code I had written in v1 that didn't have > this extra check for rela[i]. I couldn't find any measurable > difference in the module load time. Maybe 1ms for the worst case > module, but that could have been just run to run variation. > > Anyway, maybe send this as another patch since Catalin has already > picked this mine? I think the queued code is fine, so we don't need to micro-optimise it. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel