Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5989802ybc; Wed, 27 Nov 2019 13:01:01 -0800 (PST) X-Google-Smtp-Source: APXvYqyZ9ZXKkvliQsElOAybZb1zoFkp8SK1g6U9AQysDHVhFZ842PmFX4bNA+k/kvXFkLVzPF5S X-Received: by 2002:a50:d0d0:: with SMTP id g16mr27875676edf.75.1574888461720; Wed, 27 Nov 2019 13:01:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888461; cv=none; d=google.com; s=arc-20160816; b=jVKQZ6LnquqiKnpipWAz0IYrSzp8lUaxxgsn/vZnnqI8JHdVyGDFH0Fh/Vz+vpa2zp lA95UsPbTP/ZXsqbnWM8sItwpvtEAyb1k5ir6IXaT4+Mo69TCqooXVIb95APKo/au30y kbXyziJ+H/trh0QH+WwGXbk5C3LgT/clkxawk4AVXJiY74zS6XML+1BbzzVH7lheLL/K r2KKzpQjbROuhbsWdO4PRWr4/aIQCGyQr4bJA200aiOujchTnpsRmL/mvKBKt9YBxQGp qLwtpV0MKJaeHT30L07wdREHQQ00s5B6R1VjfYJbRumw9mm6/q2P7zGCXp6NfupGpkO9 AAWQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CUiAtLjH+wOCtHymebOwmrsHwdzz3z6hnTwzoDW1MvM=; b=XWyaC7bRpVkL5FNEKFGpdzB4+lt0YzcElxPNi8QXMDi5YfZXQaaSRm6sXwn5EWgaQz WYMFP6QuQRBP+Ae9aPcqSpJJwYpoxOHpNAyUur6aV5UqfHpmxenlwSd8xQFVtcgQ9/8a i2NHRopkoonKVYGMPZnsq4G40WP8CzFuntD1Knk51RYx7fmzezP8D9RPCmusilUO9Dce PsBPQjwIiHe4mawJfxb7N9oLQWb7ufTT76iAsHgVdzOBErgjanGCD+9QqEfndGyuT0f7 UP00v1qvgIdbp0PyEfgU4SFEoFbUMlrLy8Vwbxm+8fo4kVfknwuQOUXMN9M/4yZIO/Ip CyGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nTY0RZUB; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g8si4574009eds.278.2019.11.27.13.00.38; Wed, 27 Nov 2019 13:01:01 -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=nTY0RZUB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731218AbfK0U7n (ORCPT + 99 others); Wed, 27 Nov 2019 15:59:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:51250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729560AbfK0U7j (ORCPT ); Wed, 27 Nov 2019 15:59:39 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4B7B820678; Wed, 27 Nov 2019 20:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888378; bh=JBQjh57E1Ndhk4dCtXRsycP+umjDUfzghAGmYQhFalo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nTY0RZUBmfOxmdbt1aBasIvKFk42gskcKCN27Gpc4cXLso8RXc94hE4KUmwMmDbdZ U2+e/gjgNFF29NW3zRHTQQP6AQSB0/yWbPEJdIcZq4yrvr/LarqAY0++JWEmhFNN4/ kMRJBjd+u12Q+aA4Xny2oagL/0qirqMxTVdjLixU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman , Sasha Levin Subject: [PATCH 4.19 112/306] powerpc/mm/radix: Fix overuse of small pages in splitting logic Date: Wed, 27 Nov 2019 21:29:22 +0100 Message-Id: <20191127203123.406072189@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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