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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76FB3CD1288 for ; Wed, 3 Apr 2024 16:20:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:To:From:Subject: Cc:Message-Id:Date:Mime-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gOyhjwAEVTdQKf6hy5CvsztTNld9dw98Q38x1RIa9uA=; b=RdmagalkFNScSq 26S1QAYoyTN85+HLx7cyVNeEveAnugskN0OFpOP1R1mh9nV9aGIgTEgz/57zwssE7njNlaHXjv2vP XV3c7z+oWYdFuS6SMvQ8Q3sxYbk2Zm9l4JIMt8NES8tlFwidyv9F0eyKiQhuzrvLUnvcmXCNWACto Ontvc/syrntxYsfAnaDj8OSqsEdqlcqV3eXbdLNu8jP/6nlO6u5UWVclqMfhJ9SE9vqUSWJzk3lCY fEOXn0MAVZJSRYR0Gd06PVjwiV3ykJpYC+Ampw50OBjCqQPNLN1cTPtGbhouoJe+/RpD4phCATK+Y 6Ax58PdqMNcIJPjhqqUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rs3Lr-0000000Gw1Q-3RiJ; Wed, 03 Apr 2024 16:20:40 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rs3Lp-0000000Gw0e-0Q2Q for linux-arm-kernel@lists.infradead.org; Wed, 03 Apr 2024 16:20:38 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2FA8561316; Wed, 3 Apr 2024 16:20:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C135C433F1; Wed, 3 Apr 2024 16:20:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712161235; bh=SKjgQ1rezXkYAZkAsWgrEK+YYKJoAuGLpq/GsNbxYqM=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=QoIgth2X2LRa52jKpymcQxim2zHkAR5mCzB2kse7EnMVQ//RoMSwBiW7pi6H1Vfeo OQ4J/feQ6+H9zLeWcbkdc3PQnAr+ad7Ywu4L+YXnajRAhBY6064VSqJG2ZPmEnBPHO VVNwXjF/fxX5t7h8CwFiKy+ZDwy5Oo1XuihkQphJh42CyBO0frqYmjHo71+fMCstJr PQ+NpKPLYO3L2+tM6xAC5AUBIR3EOHJi3zZWwde/KzZHG2DKQA7tqAsSMmg3Grrd2B HIZjks76mfx7IsT2h1xQacdxSWurD9IoqyszBQJeSNZjytLDGp6z1WAx+6Le+XGu+Y IGgw/cQI3JMnA== Mime-Version: 1.0 Date: Wed, 03 Apr 2024 19:20:31 +0300 Message-Id: Cc: , , , , , , , Subject: Re: [PATCH v2 1/4] arm64: patching: always use fixmap From: "Jarkko Sakkinen" To: "Mark Rutland" , , "Catalin Marinas" , "Will Deacon" X-Mailer: aerc 0.17.0 References: <20240403150154.667649-1-mark.rutland@arm.com> <20240403150154.667649-2-mark.rutland@arm.com> In-Reply-To: <20240403150154.667649-2-mark.rutland@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240403_092037_264718_7622AA22 X-CRM114-Status: GOOD ( 28.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Wed Apr 3, 2024 at 6:01 PM EEST, Mark Rutland wrote: > For historical reasons, patch_map() won't bother to fixmap non-image > addresses when CONFIG_STRICT_MODULE_RWX=n, matching the behaviour prior > to the introduction of CONFIG_STRICT_MODULE_RWX. However, as arm64 > doesn't select CONFIG_ARCH_OPTIONAL_KERNEL_RWX, CONFIG_MODULES implies > CONFIG_STRICT_MODULE_RWX, so any kernel built with module support will > use the fixmap for any non-image address. Not familiar with the config flag but I'd guess it is essentially w^x enforcement right for the sections? > Historically we only used patch_map() for the kernel image and modules, > but these days its also used by BPF and KPROBES to write to read-only > pages of executable text. Currently these both depend on CONFIG_MODULES, > but we'd like to change that in subsequent patches, which will require > using the fixmap regardless of CONFIG_STRICT_MODULE_RWX. > > This patch changes patch_map() to always use the fixmap, and simplifies > the logic: > > * Use is_image_text() directly in the if-else, rather than using a > temporary boolean variable. > > * Use offset_in_page() to get the offset within the mapping. > > * Remove uintaddr and cast the address directly when using > is_image_text(). > > For kernels built with CONFIG_MODULES=y, there should be no functional > change as a result of this patch. > > For kernels built with CONFIG_MODULES=n, patch_map() will use the fixmap > for non-image addresses, but there are no extant users with non-image > addresses when CONFIG_MODULES=n, and hence there should be no functional > change as a result of this patch alone. > > Signed-off-by: Mark Rutland > Cc: Catalin Marinas > Cc: Will Deacon > --- > arch/arm64/kernel/patching.c | 10 +++------- > 1 file changed, 3 insertions(+), 7 deletions(-) > > Catalin, Will, this is a prerequisite for the final two patches in the > series. Are you happy for this go via the tracing tree? > > Mark. > > diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c > index 2555349303684..f0f3a2a82ca5a 100644 > --- a/arch/arm64/kernel/patching.c > +++ b/arch/arm64/kernel/patching.c > @@ -30,20 +30,16 @@ static bool is_image_text(unsigned long addr) > > static void __kprobes *patch_map(void *addr, int fixmap) > { > - unsigned long uintaddr = (uintptr_t) addr; > - bool image = is_image_text(uintaddr); > struct page *page; > > - if (image) > + if (is_image_text((unsigned long)addr)) > page = phys_to_page(__pa_symbol(addr)); > - else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) > - page = vmalloc_to_page(addr); > else > - return addr; > + page = vmalloc_to_page(addr); > > BUG_ON(!page); > return (void *)set_fixmap_offset(fixmap, page_to_phys(page) + > - (uintaddr & ~PAGE_MASK)); > + offset_in_page(addr)); nit: could be a single line but i guess it is up to the taste (and subsystem maintainer). I.e. checkpatch will allow it at least. I don't mind it too much just mentioning for completeness. > } > > static void __kprobes patch_unmap(int fixmap) If my assumption about the config flag holds this makes sense: Reviewed-by: Jarkko Sakkinen BR, Jarkko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel