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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D922D2127C for ; Thu, 17 Oct 2024 11:29:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C80126B0083; Thu, 17 Oct 2024 07:29:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C08456B0088; Thu, 17 Oct 2024 07:29:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5B2B6B0089; Thu, 17 Oct 2024 07:29:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 83A286B0083 for ; Thu, 17 Oct 2024 07:29:05 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A527441301 for ; Thu, 17 Oct 2024 11:28:58 +0000 (UTC) X-FDA: 82682872524.14.20197A1 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf22.hostedemail.com (Postfix) with ESMTP id C71EBC0002 for ; Thu, 17 Oct 2024 11:28:51 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ot+aEOLg; spf=pass (imf22.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729164469; a=rsa-sha256; cv=none; b=WDACAKo1Sl0nfS35GVHVARTVfiwxUKZnQWxsFm8evEQZny2a2CveYiX4gDvSw4J2LMAn+L Gymk21klQjLhIjVKxszLIAN1vSruXPFD1yXygvNYqqcg0Zd7T9tYQKj3sJLAWQPhs9BeSh rJs+9SkwGA8lNRgrdDeRpZ0pO3qfX1w= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ot+aEOLg; spf=pass (imf22.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729164469; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5TEnRdFDrGp3g8cb84z8escMU96OZKkwtQ0FRZiWHBE=; b=ikaGe+C9tWpt7npjjElM5WRIL/sXDlUL0OfQW0pL1taWkx4Kfv35n2X8wjhkvoQBv1q4iL w8t120MFVZAzqLAWnqLuMxBqkoxOYzwV4sNhboeDpKucOKDVXrxSiFVHmhoC5qVfw8aDy/ v0O75u/UeDQRr8BsBNmql166MqOyCXk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id E816CA43D50; Thu, 17 Oct 2024 11:28:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A51E6C4CEC3; Thu, 17 Oct 2024 11:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729164541; bh=rt80HNwYvry4F4GclVQlY1veJ+krWpXQVKReUpcl890=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ot+aEOLgX5JjytFWTSP6bvwXMFkowa3+f8eQ2nWquiQ2RAv0bCvly8HaX5AltuwSG MSL87zIBHWGLQnCmCdiEfFC7X5ejkFjDqsJRxmUPBDOphZUPBuoh9vgoceix8Psav5 Yvn0UgFKrQvx/wSoy69QgTtp5NCCSdTL6QB1vx3PWWPTlokB4+yqFBJYWypC9U2bHQ nQtmXd5x7H21VQL4AHHLnM8nJNg1uOm2mWoaE2bjtRwnQ1e9g0HZLSZljRpX0WRG/I j7Jg7Czseip6435Tp950cr2IcSkIthwfZaEljLp7+y1XWJYi+AU0xcha6M5b6FnQGJ 4UYbNkR0gIbzA== Date: Thu, 17 Oct 2024 14:25:05 +0300 From: Mike Rapoport To: Peter Zijlstra Cc: Steven Rostedt , Andrew Morton , Luis Chamberlain , Andreas Larsson , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Borislav Petkov , Brian Cain , Catalin Marinas , Christoph Hellwig , Christophe Leroy , Dave Hansen , Dinh Nguyen , Geert Uytterhoeven , Guo Ren , Helge Deller , Huacai Chen , Ingo Molnar , Johannes Berg , John Paul Adrian Glaubitz , Kent Overstreet , "Liam R. Howlett" , Mark Rutland , Masami Hiramatsu , Matt Turner , Max Filippov , Michael Ellerman , Michal Simek , Oleg Nesterov , Palmer Dabbelt , Richard Weinberger , Russell King , Song Liu , Stafford Horne , Suren Baghdasaryan , Thomas Bogendoerfer , Thomas Gleixner , Uladzislau Rezki , Vineet Gupta , Will Deacon , bpf@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-trace-kernel@vger.kernel.org, linux-um@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, sparclinux@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH v6 6/8] x86/module: prepare module loading for ROX allocations of text Message-ID: References: <20241016122424.1655560-1-rppt@kernel.org> <20241016122424.1655560-7-rppt@kernel.org> <20241016170128.7afeb8b0@gandalf.local.home> <20241017093515.GU16066@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241017093515.GU16066@noisy.programming.kicks-ass.net> X-Stat-Signature: fjyn95w47e8kgebchg9gepmtq9ktygme X-Rspamd-Queue-Id: C71EBC0002 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1729164531-318089 X-HE-Meta: U2FsdGVkX1+SSx+ztdLjL8Nb9lpGVQygBOb0vLxDPSkkrlbJ5+VWndGuXl3+HO4zNtE48M26oSSrIequmwZec3F7Kqg+lOqT9iYqg+lGrhBF8de5v8qg+5oj8YHHxXV/Z5seUCt0BvlYJ8qdwIBZ6kaaxPC1LYzWznottP/QCwOK8c5XDBafd3PVyaL3+iOMeP0U+al/iL35C1/bxBM+jrFt9t53RVj+A/zIDp1NIQGQWfJ9UzIUHReF0HMefBzxJ+qvNOvAcj4JJY4576gMaEEnyEAJVj3QydOXzq+Hfxb6DeYKbgTJ31K4D/KjwLNzkV7d54GkJekCrTk6KR+Rxew8q7l0l0aCEyfnXvjgs+gSS3ksDEvmH2edYwv4ushZv53Ke3F5ikUl7jQ5aVbuozFkeceY4MTbJAc3aQQ4NirqsXVtT2BUvHud1T0kWhqyv9YoPSr6AODQ/cyvTdrEefI83Y4fGVXxoP9ioUuuHX5pLyNGHk5Kktux6goh90uq4vaWLR7rMmcoLnmmi8Yj/jh20Fq+MoQTx1ynTCsMh5sAYRsbkp+eJZNI9AtRf2dQtD/TpNJR18XzeOIoBPFMVWP6HwHq7Yj89c1lnbYh1OZ6glLX8sxlkRcybqWuDdfdYwFSE57tA0VO+nH6EMejKafH8sOI0pkaBN7W5DS/cQzjp7mVeet8Hcc4qyXDn9auRznT7L5cR96oL3wFsH03sl8Xm0G3ReAtOa7zU0PK+teC+CpNfdxKAfKdEJhlbtTKO8/NHWlXiyYiaiOdetFFbPAfur0H1CeG7jy9aUgyhjUnZRs2NpPkaas6bBHV0ri83QzoU4D+LPBHpw1ST1LKZQ6XpehAAdUZCEydNu6x0QFw0YESdJiym8ipI1AjuS3cuSlZDFvLJVG41+TN/F90Ts5Zim1Zhw2hVtrLeuZHVnIoz9MnvPlBo0r5+pBt1y6TZfHMQ3SmDwaYgOsiF9A n5zu7oeV n+eaiS1Qp5Hc0OWX9wRSOZScpoP8Kv/sovp3kntlIPbBJ2PozEjrhc98Q0tg8EIWLb6L5Ei5xZPSdi0DuEg6ox4DmBXNjBJiQOR0wcBocK6PfQ9g6wTWvILqNKFpDjh62f1jG/oT6TQHdvQsgus39eK91LPXuenyVCqjbP0VkYwI9Cg7WDxxi5qpipjABqkqTgYP0sKNfHv/P3KIBiDR5xHevVrETjYvwPuuqVwaBOXKmz5ekaPtEUdzyTGMcqr5jyYqhRiazFKt1WB+nQvcipaq+Vg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Oct 17, 2024 at 11:35:15AM +0200, Peter Zijlstra wrote: > On Wed, Oct 16, 2024 at 05:01:28PM -0400, Steven Rostedt wrote: > > On Wed, 16 Oct 2024 15:24:22 +0300 > > Mike Rapoport wrote: > > > > > diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c > > > index 8da0e66ca22d..b498897b213c 100644 > > > --- a/arch/x86/kernel/ftrace.c > > > +++ b/arch/x86/kernel/ftrace.c > > > @@ -118,10 +118,13 @@ ftrace_modify_code_direct(unsigned long ip, const char *old_code, > > > return ret; > > > > > > /* replace the text with the new text */ > > > - if (ftrace_poke_late) > > > + if (ftrace_poke_late) { > > > text_poke_queue((void *)ip, new_code, MCOUNT_INSN_SIZE, NULL); > > > - else > > > - text_poke_early((void *)ip, new_code, MCOUNT_INSN_SIZE); > > > + } else { > > > + mutex_lock(&text_mutex); > > > + text_poke((void *)ip, new_code, MCOUNT_INSN_SIZE); > > > + mutex_unlock(&text_mutex); > > > + } > > > return 0; > > > } > > > > So this slows down the boot by over 30ms. That may not sound like much, but > > we care very much about boot times. This code is serialized with boot and > > runs whenever ftrace is configured in the kernel. The way I measured this, > > was that I added: > > > > > If this is only needed for module load, can we at least still use the > > text_poke_early() at boot up? > > Right, so I don't understand why this is needed at all. > ftrace_module_init() runs before complete_formation() which normally > switches to ROX, as such ftrace should be able to continue to do direct > modifications here. With this series the module text is allocated as ROX at the first place, so the modifications ftrace does to module text have to either use text poking even before complete_formation() or deal with a writable copy like I did for relocations and alternatives. I've been carrying the ftrace changes from a very old prototype and didn't pay enough attention to them them until Steve's complaint. I'll look into it. > Which reminds me, at some point I did patches adding a > MODULE_STATE_UNFORMED callback in order for static_call / jump_label to > be able to avoid the expensive patching on module load as well (arguably > ftrace should be using that too, instead of a custom callback). > -- Sincerely yours, Mike.