Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp733017ybc; Sat, 16 Nov 2019 07:45:23 -0800 (PST) X-Google-Smtp-Source: APXvYqxEU1MhUXXerCh9AesrFzxZX/oe2Pmbwl0cCu/HNSaWBspn0TAQA7bembNFtpOGbZ69ZuaL X-Received: by 2002:a17:906:f756:: with SMTP id jp22mr10449317ejb.234.1573919123692; Sat, 16 Nov 2019 07:45:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573919123; cv=none; d=google.com; s=arc-20160816; b=WZMb14+4YVR9Koks9246kThgDaIGLThZkRemcR9vp1vURtuUU0M5maCnU+qpanlhZV T8OUXuN2sC37qy+/dnmz+EBanKC7tXu/StNoTuctRaoQ7DsO8PQW+gRWSsM+Z9DafguG gw7VgzIWxyBvuzUk/pSIoVgTSCrZeyIlCeVFI1fd2dbN3EcXqXiuFkcf2AEzXxjHh2CK R3VyvumPFo0oTs7df26XHqEHo8NOfHlHln2tJX5YSjqxetnXGC2QamZpFRMdJAQ9Ny4t dIZJQc8xQeCt1S7OvQve6te2TNvLBljRyYFNwIHNjBIU/Wj6BNM/LN6QkKAoa9aqGe03 FaZg== 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=1eIq9TraxMc7ejTZBRVX4ZWHIMpUG3DsTYDoTRgd/HY=; b=wIXHspz8+//rLu9PrDrGIyjafG+xVvJ99cd5Y3dChzwzSTukftaiH0ZAGwwStKaCNh Jz7lgMTFzw/PcCCIH5lygBrO12/jyrwO1evQBGx/NrEb8mRPswPJJy0oOOfA9lfdQvCE EQND5D8c7YL69ngykyopZBHLW8L0fyXVB6mtr5S724d5h+b29Ovc60f81VRfDDndtS9k fslbydlJCC+ZJdUhoM2Ra4Trr0GVt4KrKBoEibFDdzuU+D6SCRTfyP/x19KKQyryZKuF jVOR2BPV6yyzojPcekRPX20ngklUcJUe8cHhozmwhZmMyGwP/tTcyzEKRU6WmQpfZZyV j8cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pigAi4HV; 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 c5si7613877ejr.128.2019.11.16.07.44.59; Sat, 16 Nov 2019 07:45:23 -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=pigAi4HV; 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 S1728604AbfKPPnK (ORCPT + 99 others); Sat, 16 Nov 2019 10:43:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:46950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728579AbfKPPnF (ORCPT ); Sat, 16 Nov 2019 10:43:05 -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 3831F2072D; Sat, 16 Nov 2019 15:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918985; bh=4VAPqQgAlJy/yPDODSgeBfqeL47lgcICU6o7du9+2sY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pigAi4HV3hUZ9Hfnq4WTOrV8P15/8RcL87RvRke9dsq0yFaMwzYM7oUoAPu+zsTP4 ThgaN/9ntOI7pwCvwiYCeUoPIdB+ZpaHW8JRgt9ewnbtn5ynV2wLtN5l5OBividO95 LvV2TvlI3Nw8rNFRsOtTRMKV2oARrZC8384biJGM= 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 092/237] powerpc/mm/radix: Fix off-by-one in split mapping logic Date: Sat, 16 Nov 2019 10:38:47 -0500 Message-Id: <20191116154113.7417-92-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 5c6499b7041b43807dfaeda28aa87fc0e62558f7 ] When we have CONFIG_STRICT_KERNEL_RWX enabled, we try to split the kernel linear (1:1) mapping so that the kernel text is in a separate page to kernel data, so we can mark the former read-only. We could achieve that just by always using 64K pages for the linear mapping, but we try to be smarter. Instead we use huge pages when possible, and only switch to smaller pages when necessary. However we have an off-by-one bug in that logic, which causes us to calculate the wrong boundary between text and data. For example with the end of the kernel text at 16M we see: radix-mmu: Mapped 0x0000000000000000-0x0000000001200000 with 64.0 KiB pages radix-mmu: Mapped 0x0000000001200000-0x0000000040000000 with 2.00 MiB pages radix-mmu: Mapped 0x0000000040000000-0x0000000100000000 with 1.00 GiB pages ie. we mapped from 0 to 18M with 64K pages, even though the boundary between text and data is at 16M. With the fix we see we're correctly hitting the 16M boundary: radix-mmu: Mapped 0x0000000000000000-0x0000000001000000 with 64.0 KiB pages radix-mmu: Mapped 0x0000000001000000-0x0000000040000000 with 2.00 MiB pages radix-mmu: Mapped 0x0000000040000000-0x0000000100000000 with 1.00 GiB pages 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 3ea4c1f107d7e..24a2eadc8c21a 100644 --- a/arch/powerpc/mm/pgtable-radix.c +++ b/arch/powerpc/mm/pgtable-radix.c @@ -294,14 +294,14 @@ static int __meminit create_physical_mapping(unsigned long start, } if (split_text_mapping && (mapping_size == PUD_SIZE) && - (addr <= __pa_symbol(__init_begin)) && + (addr < __pa_symbol(__init_begin)) && (addr + mapping_size) >= __pa_symbol(_stext)) { max_mapping_size = PMD_SIZE; goto retry; } if (split_text_mapping && (mapping_size == PMD_SIZE) && - (addr <= __pa_symbol(__init_begin)) && + (addr < __pa_symbol(__init_begin)) && (addr + mapping_size) >= __pa_symbol(_stext)) { mapping_size = PAGE_SIZE; psize = mmu_virtual_psize; -- 2.20.1