From patchwork Wed Jan 17 08:53:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Jia X-Patchwork-Id: 13521500 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 564A9C47258 for ; Wed, 17 Jan 2024 08:58:17 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=cn3NM4DSVZZ0YEgmYYbIe/KyGajt8HsRuPygWW0sLsc=; b=fLIm+PFdwS38/x YsYjb37dKlybWqk2LPllOKZmfqeLyl9ZaSSreVcePFgd3ttGl8nsAx4Ne+M1bZkl0Y+5nXyJY0QaI VgOdxvljboncJ99jD0w1r5fffzToo0x1TpxXiGBoDz17FT1Lyg4ENYc6Gklte8clZQcsiFyr2I3Fw l4GCioZLw4u/TNEjuAwZZlmwHTQpsWjTzRPlo2V4jQO5Yq8nygAtChbpaaseQ1DFkX2lXyKk/Fo/l AF+0EjdMUw1cYv/GiQVvidgpNsvybSte3vAepVG+EVSb1tMdqIyEr9RwXPXbAwFpzQasgvQoSjDQv D/1aUw0zlg7hMGPAgNmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rQ1k5-00Eyr6-1z; Wed, 17 Jan 2024 08:57:49 +0000 Received: from mail-oa1-f50.google.com ([209.85.160.50]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rQ1k2-00EykH-04 for linux-arm-kernel@lists.infradead.org; Wed, 17 Jan 2024 08:57:48 +0000 Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-2109023ccb0so483318fac.2 for ; Wed, 17 Jan 2024 00:57:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1705481801; x=1706086601; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=go4Vs1Ubv/hS773yJGURKRCxyCNGdiSDMhcIn69n/QY=; b=K2iizstWsUYO7dXgmXrAn0DJ1pJ3TBLn3PisMD1hjJm380iq7qzXhcdMC1CoEU1Nq+ jA+OtROsibNAtf1UnnsCvsRRPW7LkS9w85YcR2/NumoqO3msfejEB7TKfFWj7Ep7dOOG 9SdIqoCNFy+HFy8mmwJOWx/Ri5dFfyXMTedXhr3tSkgKWh3ocyYfYS1grEyMbLFDG5kX MKMtrC5ma+YU0ZFSENEwQZpLYnJeqM/PGbG8SgX4Briy6rk+ppcqvxsbOUWMi/odpMMX dRybpJOaKx/egxgWKyKffYKBK5X/sro6ltdOayyhBhGhuIERBTpTUCu3TK2qP7QPfK1t 9hUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705481801; x=1706086601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=go4Vs1Ubv/hS773yJGURKRCxyCNGdiSDMhcIn69n/QY=; b=Ktfnd7VVKDusR4Mh2maYMz7Y8Bbch6bl4R5foVzanA7GR9EiA6RnCVaJm0ViLpRCEO PO2cYMSVs9Msm3iKDzjoSvL9tkMACkOJ46tpMrAky7fUnXfaTRcaie0txuGxeTQuwKeu Kqljh6G3qUKj4/DE4EXmED8k8lK+pS/flGIxO+xnVTgGjS4HQfGPi4Mz5A4txfL5NIxP 5BPwAmm+PKUh/kV+rzH8dTm6TtMkEST32KazdOW9veLQChyeJk2xReNcCJa5N/Py8m1f xGsH+1aeI/Kfrfrpxu1ClEgfrrdBmOdlurVZ4pJrEmvXvRwNNBDonJVKkJgdu4ueYzAu yQwg== X-Gm-Message-State: AOJu0YwerxQXqJRAx6WCnTdLoKT0uue5ffF9ekGlDqmB7u76tGns6laK noJe34OQtMXyNqflkE9rBS4o/Q4sAnvLUA== X-Google-Smtp-Source: AGHT+IHzXZQ651QR48qYQK3goo/FqUmsGCcl/Y8eJIkwGTQHzdjd21HNfMjv4K6S2Qd3nE7F4eJFOQ== X-Received: by 2002:a05:6870:e0cb:b0:206:878:61d8 with SMTP id a11-20020a056870e0cb00b00206087861d8mr11503527oab.19.1705481800126; Wed, 17 Jan 2024 00:56:40 -0800 (PST) Received: from C02G87K0MD6R.bytedance.net ([203.208.167.154]) by smtp.gmail.com with ESMTPSA id cb19-20020a056a02071300b005cdbebd61d8sm10006224pgb.9.2024.01.17.00.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 00:56:39 -0800 (PST) From: Hao Jia To: mark.rutland@arm.com, rmk+kernel@armlinux.org.uk, catalin.marinas@arm.com, corbet@lwn.net, will@kernel.org, willy@infradead.org Cc: linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, Hao Jia Subject: [PATCH v3 19/19] arm64: text replication: keep modules inside module region when REPLICATE_KTEXT is enabled Date: Wed, 17 Jan 2024 16:53:57 +0800 Message-Id: <20240117085357.31693-20-jiahao.os@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20240117085357.31693-1-jiahao.os@bytedance.com> References: <20240117085357.31693-1-jiahao.os@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240117_005746_083048_39956DE3 X-CRM114-Status: GOOD ( 13.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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Kernel text replication requires maintaining a separate per-node page table for kernel text. To accomplish this without affecting other kernel memory maps, it is best to place the kernel in a location that does not share L0 page table entries with any other mappings. So, limit the module_alloc() address range so that they do not overlap. Signed-off-by: Hao Jia --- arch/arm64/kernel/module.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index dd851297596e..53e1c5e50907 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -112,6 +112,7 @@ subsys_initcall(module_init_limits); void *module_alloc(unsigned long size) { + u64 module_direct_end, module_plt_end; void *p = NULL; /* @@ -119,18 +120,33 @@ void *module_alloc(unsigned long size) * kernel such that no PLTs are necessary. */ if (module_direct_base) { +#ifdef CONFIG_REPLICATE_KTEXT + /* + * Kernel text replication requires an L0 page table entry to + * be exclusive to kernel text, so no other mappings should be + * shared with it. + */ + module_direct_end = MODULES_END; +#else + module_direct_end = module_direct_base + SZ_128M; +#endif p = __vmalloc_node_range(size, MODULE_ALIGN, module_direct_base, - module_direct_base + SZ_128M, + module_direct_end, GFP_KERNEL | __GFP_NOWARN, PAGE_KERNEL, 0, NUMA_NO_NODE, __builtin_return_address(0)); } if (!p && module_plt_base) { +#ifdef CONFIG_REPLICATE_KTEXT + module_plt_end = MODULES_END; +#else + module_plt_end = module_plt_base + SZ_2G; +#endif p = __vmalloc_node_range(size, MODULE_ALIGN, module_plt_base, - module_plt_base + SZ_2G, + module_plt_end, GFP_KERNEL | __GFP_NOWARN, PAGE_KERNEL, 0, NUMA_NO_NODE, __builtin_return_address(0));