From patchwork Wed Nov 22 18:24:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13465343 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZNIGol0I" 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-Google-Smtp-Source: AGHT+IEJYIyKQ6273MpBJbASGCHCzwBZ+jikHTC5hvZZZ0ytWLeA/63OtAlK6bjHb9mLuZPFtzvyfA== 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> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 }