Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp102866rdd; Wed, 22 Nov 2023 10:26:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHahQriLfYRQskRVy4QtcRdEVVDQ+Buw0tMmdU1Jzxj+HopUZ4yUi3nndlBO07M+9UTreBT X-Received: by 2002:a9d:63d4:0:b0:6c6:4e73:f83d with SMTP id e20-20020a9d63d4000000b006c64e73f83dmr3919755otl.32.1700677585448; Wed, 22 Nov 2023 10:26:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700677585; cv=none; d=google.com; s=arc-20160816; b=J6ZE63RnyXNWUIyX95SKCLqHgXDAbST7jNEHyzNjB/ojMDf2Zf1WkK0SGnpEn4yGmE 7gnKhBYTKBUcJsPKMV9O1WlMLolItGmkBe2uZLEROlQcAqTbZPEzV+k6Ew+hIGRUBxYd 3u38v0jedKVa1NPJl6S2f9yIwYaUhZn+Rss/Yj6GmK+UzExxHUD8/EvMpG0OKDbv6hG3 UmnA28G/TC+8byxxpOHl1LbsuYIjmvUjVI4GUTSMe9YcD6f8e9aIGOuM+1tF214OUTgW j7rWyB+HCHJlJKobqMoqVA/D+GE3XhSdzKZhVz1ilCCzTch3QKG7afUeajqOi98uYAoM ZAxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zoxEo8hjT6ynXu2QIn5RXNLR4Bk19U6JI/QFXIIvaMA=; fh=dSoJpWM7d6/DShCFpWvp3o6tLDTccp4ysEUcL8mt2eE=; b=jenjDlMsHnpJYiXIYvOTSmNEcceyYh3fnGe3ry4AaCLjik2Y2CsGtmd60GWoEJMEZM Rq6SUgw6LnC4hSbOKeT0abPcXGyu/q5vV+R8dhGK9ajGjzUy5k/KYlWOVJc+wXhnHpQ2 ZinIFXMx1k04CmdPsp0S4qvUnBi1shCnxdQ7H7YP1hUnEJliSqpyeuk7XaYRG5GL2WZF Baeye0aEk9qm2dWXgvieEYTPC32UN7knSAvTeEhDvAkTIyT/iE7fX56wUA3rEenb9H61 miRanOfTENg3B9tebbi6gaF67s8kXazSvWD6Wjc1NCmTu+ivxrZSyyisCSMSsXoW6uBC +tRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZNIGol0I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id f28-20020a63511c000000b005a0018ec786si12551110pgb.854.2023.11.22.10.26.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 10:26:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZNIGol0I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 5A89E8080D6D; Wed, 22 Nov 2023 10:25:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344413AbjKVSYp (ORCPT + 99 others); Wed, 22 Nov 2023 13:24:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344284AbjKVSYc (ORCPT ); Wed, 22 Nov 2023 13:24:32 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA6FE1AE; Wed, 22 Nov 2023 10:24:28 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-507a98517f3so12128e87.0; Wed, 22 Nov 2023 10:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700677467; x=1701282267; darn=vger.kernel.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=zoxEo8hjT6ynXu2QIn5RXNLR4Bk19U6JI/QFXIIvaMA=; b=ZNIGol0IPG9+W79uNm45b8lsJeh1v+cJiBrLTfwS2Hn4zMPeKmenOj1urrx1Xyg40e +PpI8Gu9Cdg4BrPr0Kr2FvCGKKMKyg/VCCHEDOcTwD4A8KVuuMB2NI99yLW5RXkWJPnS sRlza8SmcLpEIo/vXy+bH9uA/2vc89gYENjhkkdZh20q9gHL+ZmTBAUhLh3mjeE+B8LZ 5VeoUj5V552+kN+nr9UgYRM5Pvz4GZtJzJwKCfKkg17UQs1cHbvrZF0vkVup/IY1QWZW QIw68DhJpzZnBixKymGJMm3LE10akMiBz5UMzeOLkOf/gPqsNmt0/nCktJk6/Qd8Hk7g hO2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700677467; x=1701282267; 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=zoxEo8hjT6ynXu2QIn5RXNLR4Bk19U6JI/QFXIIvaMA=; b=fdfR+1Hfz1Q3JPqakkFkZrzuFqRNGV/6aZczvO+/fn3s9WlbnCpk54OF7juRXX0vJ8 psoWPgxqv4gGMYvroBuF2AkLoMmyMp5mi1Elh/6DQsg7kBoL9O5UM70btQiVKrj1Yx3F vavEzSvpF5rJLioDlM4ab/fpSzj7jO+3upfe9++9BKZ51VGk3WTitNu6a/t9JcAo9HlT z7xnpuGJV2BvR60BUlq2IUGfcgddPiJuDrZP3q1owvL0wXak6LFPRpUzXeSecA/H3w7C jf16QsPq8DALrCl9OmGkGxXgKZ6BPpDQsaqxuZEiPkFQX7rY2iKM/jxrFpzjCJ/n5OUt tdpw== X-Gm-Message-State: AOJu0YxVWHkshNK6JRDXMCr7btnQbGzf87LivephDZa4FVnmW5pzoEoN 5EiMvlREtosp+pAAgCnur9k= X-Received: by 2002:a05:6512:3591:b0:50a:abf9:27ff with SMTP id m17-20020a056512359100b0050aabf927ffmr1805249lfr.62.1700677466786; Wed, 22 Nov 2023 10:24:26 -0800 (PST) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id o2-20020a056512050200b005009c4ba3f0sm1928839lfb.72.2023.11.22.10.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 10:24:26 -0800 (PST) From: Serge Semin To: Thomas Bogendoerfer , Andrew Morton , Mike Rapoport , Matthew Wilcox , Jiaxun Yang , Paul Burton Cc: Serge Semin , Alexey Malahov , Arnd Bergmann , Aleksandar Rikalo , Aleksandar Rikalo , Dragan Mladjenovic , Chao-ying Fu , Yinglu Yang , Tiezhu Yang , Marc Zyngier , linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] mips: Fix incorrect max_low_pfn adjustment Date: Wed, 22 Nov 2023 21:24:00 +0300 Message-ID: <20231122182419.30633-3-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231122182419.30633-1-fancer.lancer@gmail.com> References: <20231122182419.30633-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 22 Nov 2023 10:25:11 -0800 (PST) max_low_pfn variable is incorrectly adjusted if the kernel is built with high memory support and the later is detected in a running system, so the memory which actually can be directly mapped is getting into the highmem zone. See the ZONE_NORMAL range on my MIPS32r5 system: > Zone ranges: > DMA [mem 0x0000000000000000-0x0000000000ffffff] > Normal [mem 0x0000000001000000-0x0000000007ffffff] > HighMem [mem 0x0000000008000000-0x000000020fffffff] while the zones are supposed to look as follows: > Zone ranges: > DMA [mem 0x0000000000000000-0x0000000000ffffff] > Normal [mem 0x0000000001000000-0x000000001fffffff] > HighMem [mem 0x0000000020000000-0x000000020fffffff] Even though the physical memory within the range [0x08000000;0x20000000] belongs to MMIO on our system, we don't really want it to be considered as high memory since on MIPS32 that range still can be directly mapped. Note there might be other problems caused by the max_low_pfn variable misconfiguration. For instance high_memory variable is initialize with virtual address corresponding to the max_low_pfn PFN, and by design it must define the upper bound on direct map memory, then end of the normal zone. That in its turn potentially may cause problems in accessing the memory by means of the /dev/mem and /dev/kmem devices. Let's fix the discovered misconfiguration then. It turns out the commit a94e4f24ec83 ("MIPS: init: Drop boot_mem_map") didn't introduce the max_low_pfn adjustment quite correct. If the kernel is built with high memory support and the system is equipped with high memory, the max_low_pfn variable will need to be initialized with PFN of the most upper directly reachable memory address so the zone normal would be correctly setup. On MIPS that PFN corresponds to PFN_DOWN(HIGHMEM_START). If the system is built with no high memory support and one is detected in the running system, we'll just need to adjust the max_pfn variable to discard the found high memory from the system and leave the max_low_pfn as is, since the later will be less than PFN_DOWN(HIGHMEM_START) anyway by design of the for_each_memblock() loop performed a bit early in the bootmem_init() method. Fixes: a94e4f24ec83 ("MIPS: init: Drop boot_mem_map") Signed-off-by: Serge Semin --- arch/mips/kernel/setup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 2d2ca024bd47..0461ab49e8f1 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -321,11 +321,11 @@ static void __init bootmem_init(void) panic("Incorrect memory mapping !!!"); if (max_pfn > PFN_DOWN(HIGHMEM_START)) { + max_low_pfn = PFN_DOWN(HIGHMEM_START); #ifdef CONFIG_HIGHMEM - highstart_pfn = PFN_DOWN(HIGHMEM_START); + highstart_pfn = max_low_pfn; highend_pfn = max_pfn; #else - max_low_pfn = PFN_DOWN(HIGHMEM_START); max_pfn = max_low_pfn; #endif } -- 2.42.1