Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1332492pxa; Fri, 28 Aug 2020 09:44:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzz9Y6CSPGRlNUQraIuNRkIToXwvrOE60w225nv+8VMqYEe1xrVrwSe52acODtyttYFc6GF X-Received: by 2002:a05:6402:17b5:: with SMTP id j21mr2703142edy.276.1598633064546; Fri, 28 Aug 2020 09:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598633064; cv=none; d=google.com; s=arc-20160816; b=PkbxK/R/flhby8tKCEurKX/0nhJYqnuGksJy3ReG9XzSeaC/GLQrKXgy0tsD3pmClQ ui7M7f2AivlbVw8B3d5+r57kKPEfeJF56cb+VLWTyqjG6a2fuRSbsNRaEtCSW4gICyFE U5sKI+eZhwIGZHMXR62OvMATv82wntl6ngm+91y9UAuXNJsPa++TcxHAajZjOmTYrPe3 byFfb6P0yOA7PTJKnBIBjuuvLOmlwrx8Hotyd6EB+oPlUVT9G5bgeacZcHMm3lK0qO9E h0LvJ5tjOcXau+viabLrdifToANEDvuOtnzIeOq78yEaVgrfUNwvh4sfEiqsnGxLv1Cn 17tQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=SqEtKlOLR9TlXj1BYBe93Uzx53Ru+K3xFvokDPGCcnk=; b=tiwBYx4tNcVSyhj/94GB8YmUWuoGjnhpTnK7yecE1iTT8QUzLlw1WyTVRRExQ4nx/m SGAWo9KqP3mZ5MypLB93UZWSoqOQwwiUv4drUwrEpxooCBmvD6vNEJRXw9h9QGJxl7tr HiuC85VbZyO8G/0X3tmYkjuFD+tQ57ll9Gh8+vqye1lKsplhgOPPs74H3ebapdBxG4Yw lTXhGMwmUL2ywoXTCxtWPvWyknxY76SfPWXc2c189mSYQOO9FNbOlUI+LHhDreGZRhvK t8Wjr/gKQvSM9Y5WJj/gN8vBR0lIyaX0psrwQM+pcKaz+WL1KHjphUx4cgnl9rsd3GjL i5RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OAnMIBUg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id dr22si5572ejc.35.2020.08.28.09.44.02; Fri, 28 Aug 2020 09:44:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OAnMIBUg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728046AbgH1QjM (ORCPT + 99 others); Fri, 28 Aug 2020 12:39:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:40624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726524AbgH1QjI (ORCPT ); Fri, 28 Aug 2020 12:39:08 -0400 Received: from aquarius.haifa.ibm.com (nesher1.haifa.il.ibm.com [195.110.40.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 57F7520872; Fri, 28 Aug 2020 16:39:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598632748; bh=YVCQjg73RxPTvlTXDUxrWS87exJNOw0r+AtJ4Kjw2bM=; h=From:To:Cc:Subject:Date:From; b=OAnMIBUg/35kIR+XHFI3uW81Vhsq5RuiNO8PZO0o+7cScYYcfQFJ/tKoqYInqbOSi dQWnnF3AWY7qf+6NtTYAPh1hjs5+LeMHiPoLIzkFYN69Mx3EDHR9KMKJKlYqzI8jS1 aTQbasoMLnPibL/SFcRCQ2iAC1tMlDy4bHOcscvs= From: Mike Rapoport To: Vineet Gupta Cc: Eugeniy Paltsev , linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Rapoport , Mike Rapoport Subject: [PATCH] arc: fix memory initialization for systems with two memory banks Date: Fri, 28 Aug 2020 19:39:02 +0300 Message-Id: <20200828163902.4548-1-rppt@kernel.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Rapoport Rework if memory map initialization broke initialization of ARC systems with two memory banks. Before these changes, memblock was not aware of nodes configuration and the memory map was always allocated from the "lowmem" bank. After the addition of node information to memblock, the core mm attempts to allocate the memory map for the "highmem" bank from its node. The access to this memory using __va() fails because it can be only accessed using kmap. Anther problem that was uncovered is that {min,max}_high_pfn are calculated from u64 high_mem_start variable which prevents truncation to 32-bit physical address and the PFN values are above the node and zone boundaries. Use phys_addr_t type for high_mem_start and high_mem_size to ensure correspondence between PFNs and highmem zone boundaries and reserve the entire highmem bank until mem_init() to avoid accesses to it before highmem is enabled. Fixes: 51930df5801e ("mm: free_area_init: allow defining max_zone_pfn in descend ing order") Signed-off-by: Mike Rapoport --- arch/arc/mm/init.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c index f886ac69d8ad..3a35b82a718e 100644 --- a/arch/arc/mm/init.c +++ b/arch/arc/mm/init.c @@ -26,8 +26,8 @@ static unsigned long low_mem_sz; #ifdef CONFIG_HIGHMEM static unsigned long min_high_pfn, max_high_pfn; -static u64 high_mem_start; -static u64 high_mem_sz; +static phys_addr_t high_mem_start; +static phys_addr_t high_mem_sz; #endif #ifdef CONFIG_DISCONTIGMEM @@ -69,6 +69,7 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size) high_mem_sz = size; in_use = 1; memblock_add_node(base, size, 1); + memblock_reserve(base, size); #endif } @@ -157,7 +158,7 @@ void __init setup_arch_memory(void) min_high_pfn = PFN_DOWN(high_mem_start); max_high_pfn = PFN_DOWN(high_mem_start + high_mem_sz); - max_zone_pfn[ZONE_HIGHMEM] = max_high_pfn; + max_zone_pfn[ZONE_HIGHMEM] = min_low_pfn; high_memory = (void *)(min_high_pfn << PAGE_SHIFT); kmap_init(); @@ -166,22 +167,26 @@ void __init setup_arch_memory(void) free_area_init(max_zone_pfn); } -/* - * mem_init - initializes memory - * - * Frees up bootmem - * Calculates and displays memory available/used - */ -void __init mem_init(void) +static void __init highmem_init(void) { #ifdef CONFIG_HIGHMEM unsigned long tmp; - reset_all_zones_managed_pages(); + memblock_free(high_mem_start, high_mem_sz); for (tmp = min_high_pfn; tmp < max_high_pfn; tmp++) free_highmem_page(pfn_to_page(tmp)); #endif +} +/* + * mem_init - initializes memory + * + * Frees up bootmem + * Calculates and displays memory available/used + */ +void __init mem_init(void) +{ memblock_free_all(); + highmem_init(); mem_init_print_info(NULL); } -- 2.26.2