Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp88741lqp; Thu, 4 Apr 2024 07:49:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWoI9CAgCh6tIux16oNoGwChs+N+GNd+HTW7P2YSRKnCFcg/FBjv7EXa2Ky7E5DtqfOc47WwbnqWm40YgW/udrvCRiOUPuK3OmFB0yXYw== X-Google-Smtp-Source: AGHT+IGdjrUyFREay/WyUSyc2t2o4A2vmoVYLG9PquSw27HqGdHms0JEVMTFXWJN6QNqIpsEyaGL X-Received: by 2002:a50:bb23:0:b0:56e:2452:f864 with SMTP id y32-20020a50bb23000000b0056e2452f864mr464560ede.35.1712242153964; Thu, 04 Apr 2024 07:49:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712242153; cv=pass; d=google.com; s=arc-20160816; b=zt/PI9ACEC2KTSLiR1ue+QY5hVrOdBcvG32yJJPn0XRmI1BpJzcBy3Q12lgH28VhKp M+XF37ugUM6pLits37o1vGHIApiiRCnpI4F+LGSSEdrJL3C9n3NGj+vgdbulAl3WSDFv nCHZrwPH5neHfKAmY2FNF4LB2QLfWQDBhMlIjFXiyoXOsletRgfI7fZziO1Q72thzt8l ICOiimiht3/pMMBgGDnDhRtDeq7MidX0pVSttkCKJwBzpT7TuPsTs1SvjrSFzsqD6gKS ew5f+sfYtqxH5D42N9YfbiQD8rpLMc3pB6U0Bqbweo1/CP4UQr5y5AJmdIZ/Br0DLAfz BB7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=LTPYIKU0lF+A/uPv1gtdAOvDKNMWZN7nu7anGIHUy4M=; fh=HzGRCRqnTqSZIwvOjA5hYZJ6BFT/9OzJqGNvDdFtbeo=; b=Dkvuxo4lw8D26Etn4EzXvWMBbxBY+gDDpZROXvvxqhAvQQw5oqU4ML8u2ow7w84pgI e/VyZPAm1RtPxtxfsG6bB1+Z6OeAeXXBxkhD7sLrjqnX46wgMo0abrZiD8x9sO+75oH7 nP77ac9lz1vuMszEbgHN9PmY/o46vmSFwsEAdgfU51vkzHJ0fT5+msgzsjYThCj/S5Xo h2MPZfxzbckHP+qE40PPxSPOtfy4yb9CLshHvacfMZzkD70kD/N/Ld2Hwp4QvCgXlm5b 3L265uTZE6DQwLicbgDagOnFdrgnfJzcKvSWrmPK1ReB6j9J4tiwWXhPmFeDO7OTi1RN qB8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dpM4E2Zi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-131646-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131646-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c4-20020a50d644000000b0056bb2f5041asi8114346edj.230.2024.04.04.07.49.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 07:49:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131646-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dpM4E2Zi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-131646-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131646-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AF26E1F2644A for ; Thu, 4 Apr 2024 14:49:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 216616AFB5; Thu, 4 Apr 2024 14:48:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dpM4E2Zi" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36E5D3219F for ; Thu, 4 Apr 2024 14:48:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712242135; cv=none; b=kMoiivqj5MruFmt9SU6nWQEXB9tWf/WxvzLuQixuLFam03LhFWfD23iY9/ejhB5RbhNIra/K+c962E6JG08wZXoAztsUef/7O4srGWdQ1sqhqcCMZMagQCvKnYp9SINblTVTS04O2d3b6H+2JlxYs4r1iocRtg75hg4RvZB3IdM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712242135; c=relaxed/simple; bh=a71wwcJR5TKYVGY9/88H+mkVOaP4piH5VNbwZOyifkE=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=X/Nrt3CCTmjdeQKQCXK1BW3dEJtzOxfpZ5Ym2pzgrlD9GHAyGCm+aee+KomS8znMRt2t4zRokE/q1V9GiZ9Bx2msi+wsmDGNIBEdxAm1FyAw/Ex5XdvaTBNCvCKtInCY3XRL/CkxPWs9TKMY0b1gemf1+LKnFVSfr/I4XyJwjmI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dpM4E2Zi; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57BE7C433C7; Thu, 4 Apr 2024 14:48:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712242134; bh=a71wwcJR5TKYVGY9/88H+mkVOaP4piH5VNbwZOyifkE=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=dpM4E2ZiaPCeasQyfnx+ZLamawrdyUXqIFerCmPWI2+2xBoJ4Ju9WMclnQZxoS7NS +d4/MvGPr1yMZtcFmU7OpeH9rfERecy27D7Qs1n18hqXkCIXHPLORtP+YZNK7inNZE ZiQDZRy99DTShCW1sxY39JJRhJCKQlidOPCpucKnKFN+fZYKjteERrt1PaD6ngc3Fs ycf1Msm4Oooqxy625l7BuLHK8roupVPitFu8mDZ6XLeL2ZYXOmZhfibkqRN58eiCIG niktUXljafu/ZjYQZCCRw8tIB8IX7enUresYbk8QyBsnt6bS1BpZOrflPVKh8wB/yI iEVVRRT8FtePQ== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 04 Apr 2024 17:48:50 +0300 Message-Id: Cc: , "Catalin Marinas" , "Will Deacon" , , , , , , , , Subject: Re: [PATCH v2 1/4] arm64: patching: always use fixmap From: "Jarkko Sakkinen" To: "Mark Rutland" X-Mailer: aerc 0.17.0 References: <20240403150154.667649-1-mark.rutland@arm.com> <20240403150154.667649-2-mark.rutland@arm.com> In-Reply-To: On Wed Apr 3, 2024 at 7:51 PM EEST, Mark Rutland wrote: > On Wed, Apr 03, 2024 at 07:20:31PM +0300, Jarkko Sakkinen wrote: > > 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=3Dn, matching the behaviour p= rior > > > to the introduction of CONFIG_STRICT_MODULE_RWX. However, as arm64 > > > doesn't select CONFIG_ARCH_OPTIONAL_KERNEL_RWX, CONFIG_MODULES implie= s > > > CONFIG_STRICT_MODULE_RWX, so any kernel built with module support wil= l > > > use the fixmap for any non-image address. > >=20 > > Not familiar with the config flag but I'd guess it is essentially > > w^x enforcement right for the sections? > > Essentially, yes. > > > > Historically we only used patch_map() for the kernel image and module= s, > > > 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_MODUL= ES, > > > but we'd like to change that in subsequent patches, which will requir= e > > > using the fixmap regardless of CONFIG_STRICT_MODULE_RWX. > > > > > > This patch changes patch_map() to always use the fixmap, and simplifi= es > > > 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=3Dy, there should be no functio= nal > > > change as a result of this patch. > > > > > > For kernels built with CONFIG_MODULES=3Dn, patch_map() will use the f= ixmap > > > for non-image addresses, but there are no extant users with non-image > > > addresses when CONFIG_MODULES=3Dn, and hence there should be no funct= ional > > > 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 th= e > > > series. Are you happy for this go via the tracing tree? > > > > > > Mark. > > > > > > diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patchin= g.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) > > > =20 > > > static void __kprobes *patch_map(void *addr, int fixmap) > > > { > > > - unsigned long uintaddr =3D (uintptr_t) addr; > > > - bool image =3D is_image_text(uintaddr); > > > struct page *page; > > > =20 > > > - if (image) > > > + if (is_image_text((unsigned long)addr)) > > > page =3D phys_to_page(__pa_symbol(addr)); > > > - else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) > > > - page =3D vmalloc_to_page(addr); > > > else > > > - return addr; > > > + page =3D vmalloc_to_page(addr); > > > =20 > > > BUG_ON(!page); > > > return (void *)set_fixmap_offset(fixmap, page_to_phys(page) + > > > - (uintaddr & ~PAGE_MASK)); > > > + offset_in_page(addr)); > >=20 > > 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. > >=20 > > I don't mind it too much just mentioning for completeness. > > At that point it goes to 93 chars long, and I stuck with the existing lin= e > wrapping at 80 chars. I'd rather have a temporary 'phys_addr_t phys' vari= able > and do: > > phys =3D page_to_phys(page) + offset_in_page(addr); > return (void *)set_fixmap(fixmap, phys); > > ... but I'll leave this as-is for now. > > > > } > > > =20 > > > static void __kprobes patch_unmap(int fixmap) > >=20 > > If my assumption about the config flag holds this makes sense: > >=20 > > Reviewed-by: Jarkko Sakkinen > > Thanks! I assume that should be "kernel.org", with an 'o' ;) Yes, that's correct, not from Gibraltar :-) BR, Jarkko