Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3459328lqp; Tue, 26 Mar 2024 09:38:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUWpXeFKxH1KvgLfLLbOjtLExPdHs5jgsq+xz6hyRSln38Kc2a7jFyCbQWZyfC8s4eumFhaWbeRCspF22CvibJafkDyf7X47sdEdllRUg== X-Google-Smtp-Source: AGHT+IF0VE/v1lOFRmU94YQ2ndOWdHCg6J/GHb0t+SoKNGgL5XVVKAO+prvqsG75QWF4qDBbb69L X-Received: by 2002:a92:da4b:0:b0:368:980d:6482 with SMTP id p11-20020a92da4b000000b00368980d6482mr5241545ilq.15.1711471088082; Tue, 26 Mar 2024 09:38:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711471088; cv=pass; d=google.com; s=arc-20160816; b=yW7BxLDTjVrw2V91M/FQf8aRqU9Cu6G4ocU8hNmwlcHO1LRltzF0NEcfLz5gzDhtal 8b8xiANhDooehlpWULePg0mOdPrV8EpSWOrD6H26KtznpPyf49weTxHkiLJZJavJ44vS rgPrjkXrCLdaGBPzTr92DHWUXKnnBkv7EQi46K5SfGe7xaDRk4IO4Eh15+c5bVsCYaOK fZ3Airm4RBjRxtBgsRcMtZJp25fLCz6FGaZfeUyPYY2dQccRtEJKAlvXBkxxX6a69FR/ cbEeKQA5hObFNWhEA9EiGPk4tme6fJ9PO3lZI8MRt2Fep3ca3vpXmJpaH11iiJtxsO7F 336w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=gKEWXMEioszc2zO+gNHmkVg7gWhjf7HXxmDFmWu71tA=; fh=w7YXUMcqrOjR/8VGLlv9ETX6AnNVBK+vVFN7UOZS5uE=; b=JHw1ZnAcLo6g4oEhYeMkMdRGvHqfbUHzRiR2uWBL56OASCCngCGEi+tEVwuh0Q4Ypl S6wj7kKk/gn/xb/8IgjbkkPMAUs7xl1GaZsYKLRUz2q5kJo0IHWwkGz/IGS8zKHMJXh0 dJC3ZLqhXdD21ENw86kYHy0INx4VHCDreNL9uVCYYuCHVqLHLpru+p4FaFWC+XCZLbWN lB63iCQmaol/JgRUx6i7D829Uj62jtlfv7ZMKCpbWhAtZshFCx/KmhKD6EclXcBC1qrw N4ST2r0uliV0ERjm83rKlFAcF/yZAU+HZxb227jdIVx1+7sI7LF0NtqrIQk4L/C0TYPM UQDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-119478-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119478-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a10-20020a63cd4a000000b005e83b7f54d1si10216467pgj.736.2024.03.26.09.38.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 09:38:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119478-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-119478-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119478-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5E8332E6128 for ; Tue, 26 Mar 2024 16:36:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B04A91BDC3; Tue, 26 Mar 2024 16:36:40 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DEF918EB0 for ; Tue, 26 Mar 2024 16:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711471000; cv=none; b=bH5Jb4LOHWeiSl6I48Ct9+cThkcy6IpG9ZlS4cWub5PcNe3lgH840u1aggTECUYvOJT+RPBq5nbmrg/+w5gy5yjp2iE0dA6qErqRrChnTo98zCi26suczlqUomGldSg+nllSSvttSK/IMFDgy4L7FetA0wpyVBpQ3DCExnGoQHo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711471000; c=relaxed/simple; bh=QUwI2RCMWuIgtyxjD85G7dzGZd5QakpCU9SqOUS/EmI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o3nBTNY1VhGZOnLjcwjDVx3LWnjGGh1WZO6wtqckKMYAYumFELEmoMIGyRHuZ2NJoGcZQuk1iklD88rpo2oGf8Hzj3rN4ZO0ylgU7iHswbhx0p+bDmKBoP3HKegE9xRD9QDl6QYYVauNWuj73FEyt6nWASYaYahLqKPJZbAVtEc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6CD22339; Tue, 26 Mar 2024 09:37:10 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2AAD73F694; Tue, 26 Mar 2024 09:36:34 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: agordeev@linux.ibm.com, anil.s.keshavamurthy@intel.com, aou@eecs.berkeley.edu, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, davem@davemloft.net, gor@linux.ibm.com, hca@linux.ibm.com, jarkko@kernel.org, jcalvinowens@gmail.com, linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, mhiramat@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, palmer@dabbelt.com, paul.walmsley@sifive.com, tglx@linutronix.de, will@kernel.org Subject: [PATCH 1/4] arm64: patching: always use fixmap Date: Tue, 26 Mar 2024 16:36:21 +0000 Message-Id: <20240326163624.3253157-2-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240326163624.3253157-1-mark.rutland@arm.com> References: <20240326163624.3253157-1-mark.rutland@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. 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. Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/patching.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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)); } static void __kprobes patch_unmap(int fixmap) -- 2.30.2