From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 D00861A9F97 for ; Sun, 19 Jul 2026 09:31:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784453491; cv=none; b=tNPoOHF8U6PoT3mtI/0DmyzHzzoTdp+8T6g6mUci3jQVG/EAYYMKRM0+VrdEW2mxSzRMiM7Jk7fAz0utl459gaKz1wG8rXQ/W4DLBCbvDgiEekI480WxZnGoY9Rel4Y/VFpjb9uS8vWRHdXU29nXwXHkSkvAUY3c8wduIwqEFg4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784453491; c=relaxed/simple; bh=+LK31WMoebc8SX3x3iaEgXx5a21SHR2inKnxHfdV4rk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A815LXg9dDAccwbeRoHHhbBKAiyMsRCeYHgnKMzF/fnM/HsFxSstrQllTwdrrj8nPP/bgfdck+xtpNGrm2Il6hjSDsp4j/gKbxsI5BtL/4nVfHgUDCYNak1cfGmUWVAwp0+dTFUMmvOWhrZK4o5ozHzFrVc2XNcOA5MOwMJfczs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=f3GgDCUf; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="f3GgDCUf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=nN fRhaOga8yZmczg87holWW3UblLdJzQoSXQwr3yNc8=; b=f3GgDCUf9EkfvUeaGt PcXuB7wp8MCedOedA00blt4DU7OCEH35yFfHgVRapOEkoW5UuXByA7K5MGmkWtoY XTooAscENuIw8ehUNrGR5bVvBSdyEDQ+Nen1or5s+IfYP4l/DRkjbfza/6UI1Wxf DiI3UROcu7l+l/XvXHav3NiRg= Received: from Ubuntu.. (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgCnTyswmVxqbA0SIA--.60699S4; Sun, 19 Jul 2026 17:30:26 +0800 (CST) From: Xiaofeng Yuan To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Alexandre Ghiti , Nam Cao , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] riscv: patch: skip fixmap mapping when kernel text is already writable Date: Sun, 19 Jul 2026 09:30:24 +0000 Message-ID: <20260719093024.33351-3-xiaofengmian@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260719093024.33351-1-xiaofengmian@163.com> References: <20260719093024.33351-1-xiaofengmian@163.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 X-CM-TRANSID:PygvCgCnTyswmVxqbA0SIA--.60699S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7CF1xuw4UGF43Kr17Cry5XFb_yoW8XFy5pr s7GF1rZFW5JF4Fv3y2kwn5ury5Awn3trZxGF9rX34Svws8X34rXwn5W3y2qF10gr1j9w47 uFsIyrWS9a4UJ37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j64ENUUUUU= X-CM-SenderInfo: p0ld0w5hqjzxldq6il2tof0z/xtbDAhIkJ2pcmTIMvQAA3- Currently patch_map() always creates a temporary writable mapping via fixmap for kernel text addresses, even when CONFIG_STRICT_MODULE_RWX is disabled and the kernel text is already mapped with _PAGE_WRITE. This is unnecessary overhead at best, and on minimal configurations it can cause page faults. Skip the fixmap path for kernel text when CONFIG_STRICT_MODULE_RWX is not enabled, since the text pages are already writable in this case. Signed-off-by: Xiaofeng Yuan --- v2: add commit description (per Nam Cao's review) v3: early return when !CONFIG_STRICT_MODULE_RWX (per Nam Cao's suggestion) arch/riscv/kernel/patch.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c index 16b243376f..caef41d5ef 100644 --- a/arch/riscv/kernel/patch.c +++ b/arch/riscv/kernel/patch.c @@ -44,15 +44,16 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap) uintptr_t uintaddr = (uintptr_t) addr; phys_addr_t phys; + if (!IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) + return addr; + if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) { phys = __pa_symbol(addr); - } else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) { + } else { struct page *page = vmalloc_to_page(addr); BUG_ON(!page); phys = page_to_phys(page) + offset_in_page(addr); - } else { - return addr; } return (void *)set_fixmap_offset(fixmap, phys); -- 2.43.0