Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp774844ybc; Sat, 16 Nov 2019 08:27:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxZojZPVvcGYbvEKgksaxM7z+lSTYN33yYgpmBSYG5Cx7Zu2JyNdDywwb0PPTLho4k0Ejvy X-Received: by 2002:adf:cd8f:: with SMTP id q15mr20874300wrj.21.1573921677048; Sat, 16 Nov 2019 08:27:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921677; cv=none; d=google.com; s=arc-20160816; b=JhPk5tysEqr8U+7VJWU76sknIDRwgEMKfXQH75FaGhyeh3HYpumM6rxVqLircaCv01 TyZ8xD6IRfWqfBvdlSc9qAN8vccfGz4l0sjJX5zELQytwpwyWcZCSfMNCeoKfWCEyY92 a8BsZO4JTeKxBKR7togaFHdsrrjYfzjEVt2bBihfPFW7PCR3QekAoFgOu5H46AAPFxh2 6WkEimEruRfPMWweYPecP+IH6OKHDADGdp1oeh9b7gXK38lE/qDvjNoWe92zcitxsNl9 v9Y0XW3BVpXzZR9GDYB+ds8Y8x/KDaroDBrWE5i3sNYAQDNRNxr7xysY3Fo+vIPZxY+P C0zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CUiAtLjH+wOCtHymebOwmrsHwdzz3z6hnTwzoDW1MvM=; b=SYsRyS/VTb8cmv60atnPw5TrLifj9RygM2LLSEy2Ir0/NwyUNxHY6PjJOyKW2RbN/i 489DOV7aoUhd9qO4GjFfOFfTZjH4YuuV81nksIuHlj3/WsGX2wFd0NcT1/GHNyH0IYRv 9EoZF1FNRhrthx9eByIKOs9IyQ3iN/fWXPnGHHs68Ya+H7p42hDqYIDuX7vRgUChnmsy teuPoqcB/j7MIPZ6fKAGghEG4L18mzEHFeQhbSp0SMGue2PxVoivRHxhHmWpYTOpiz9x bPSlIDV4UFqTAbrxt/B9dv3TYwa+1iWqgpUlNQ2JPcsnEcrvJrKTlWd8/UPlb45ReSro /SVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DiCle8aV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y2si9835148ede.431.2019.11.16.08.27.31; Sat, 16 Nov 2019 08:27:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DiCle8aV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729314AbfKPQWz (ORCPT + 99 others); Sat, 16 Nov 2019 11:22:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:46996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728589AbfKPPnI (ORCPT ); Sat, 16 Nov 2019 10:43:08 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4365B2073B; Sat, 16 Nov 2019 15:43:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918987; bh=JBQjh57E1Ndhk4dCtXRsycP+umjDUfzghAGmYQhFalo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DiCle8aVQ1+TFNBe0ZGRZPqYP4/raLrYW0l2u6KLVSQl0cp1rmn2Uf7DCsgz8WU8J wjmdOfT2XldSn1JGK88lG8dt+yAhEkTISCLTQauaM4XLaHDdS0XITE9kzUO752iy/S NHwOo+QPdJuqMIr6dgH2vzTMoSLjx7OAushChkzw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Michael Ellerman , Sasha Levin , linuxppc-dev@lists.ozlabs.org Subject: [PATCH AUTOSEL 4.19 093/237] powerpc/mm/radix: Fix overuse of small pages in splitting logic Date: Sat, 16 Nov 2019 10:38:48 -0500 Message-Id: <20191116154113.7417-93-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Ellerman [ Upstream commit 3b5657ed5b4e27ccf593a41ff3c5aa27dae8df18 ] When we have CONFIG_STRICT_KERNEL_RWX enabled, we want to split the linear mapping at the text/data boundary so we can map the kernel text read only. But the current logic uses small pages for the entire text section, regardless of whether a larger page size would fit. eg. with the boundary at 16M we could use 2M pages, but instead we use 64K pages up to the 16M boundary: Mapped 0x0000000000000000-0x0000000001000000 with 64.0 KiB pages Mapped 0x0000000001000000-0x0000000040000000 with 2.00 MiB pages Mapped 0x0000000040000000-0x0000000100000000 with 1.00 GiB pages This is because the test is checking if addr is < __init_begin and addr + mapping_size is >= _stext. But that is true for all pages between _stext and __init_begin. Instead what we want to check is if we are crossing the text/data boundary, which is at __init_begin. With that fixed we see: Mapped 0x0000000000000000-0x0000000000e00000 with 2.00 MiB pages Mapped 0x0000000000e00000-0x0000000001000000 with 64.0 KiB pages Mapped 0x0000000001000000-0x0000000040000000 with 2.00 MiB pages Mapped 0x0000000040000000-0x0000000100000000 with 1.00 GiB pages ie. we're correctly using 2MB pages below __init_begin, but we still drop down to 64K pages unnecessarily at the boundary. Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/mm/pgtable-radix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c index 24a2eadc8c21a..b387c7b917b7e 100644 --- a/arch/powerpc/mm/pgtable-radix.c +++ b/arch/powerpc/mm/pgtable-radix.c @@ -295,14 +295,14 @@ static int __meminit create_physical_mapping(unsigned long start, if (split_text_mapping && (mapping_size == PUD_SIZE) && (addr < __pa_symbol(__init_begin)) && - (addr + mapping_size) >= __pa_symbol(_stext)) { + (addr + mapping_size) >= __pa_symbol(__init_begin)) { max_mapping_size = PMD_SIZE; goto retry; } if (split_text_mapping && (mapping_size == PMD_SIZE) && (addr < __pa_symbol(__init_begin)) && - (addr + mapping_size) >= __pa_symbol(_stext)) { + (addr + mapping_size) >= __pa_symbol(__init_begin)) { mapping_size = PAGE_SIZE; psize = mmu_virtual_psize; } -- 2.20.1