Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp986510rdb; Wed, 1 Nov 2023 08:17:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEOzrIAl9+WwpxJ5SwMKvQATJhNBLVV0TeWylu5FO2BR+/mSCMlMD3Qu3iYFRu1DoCVWU3 X-Received: by 2002:a17:902:e404:b0:1cc:33ee:ddf with SMTP id m4-20020a170902e40400b001cc33ee0ddfmr9838915ple.33.1698851863255; Wed, 01 Nov 2023 08:17:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698851863; cv=none; d=google.com; s=arc-20160816; b=BU67kURTQuVh9XBLFeufxt3MnLtMG+pKRn2FyTCHYAluJ/CknZHenSHm5/uQCkrQdH ws7cDVMPlKhWztI5lZWs0l0TEbjJv09aUjmB1FVTk9W+f57vVcqkTOBG3iquYApfNkOV z16wWcJCuAuyf+Ppqe4Ya25JuUKO45stdGX77INKCrCjfNVzTJRNmJ5BtbK+R5p2rkKu NJrWhMr1FrwRB0gEVPp1DwQmank9XlyL26kNc1IK8sMvfG9hD5jNwTaKPctmNFfIrJWP nv+mUXVSpDGmJ0KkLeANov+npQ6hcKsbUFsHt1sKPNTwLmUSFIqYiKh8mwfi5owU9/dw TyGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :feedback-id:dkim-signature:dkim-signature; bh=Mm+JRDBtZvObmZ+uO6jWZAPic1sg7YIcuKFrNlBR5/c=; fh=7IIVG7Z5uBUiGqF92YYc9bge9oWMe+bYNkQEjjS1HU8=; b=M23vph0K7H8ARhG0Am62u1Pl9zC5EgUMghmorPCDB+xQFm+o1h/ibNZNvX7+nqQsVg 7SzzYEIJTKlcLALxV/tDfc95JG8qZm9PhT4TNtl5Fi3hYbHyei6dCcjg9nGGto77Jizx KjI/73L9lCdrWkqj7yb5/4VkrwCAWUqMbVPW26y/Q4HHZuSoeINaIQaIt5eOCEbZLHAW BXILaOSmzzU+33B/izaqPRpwNDX4YruMt7r7Qrk98FYNLFtRQ8tfgMq7kP5IJhKzx05W C4c3YWHRrzvTOYq6MJOxJG/Vb8nYNeOTZSiocHhB2Y0y2jDopdGIWiIGGzIe9qZX9cGm aeoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@flygoat.com header.s=fm1 header.b=URsyfAr2; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=MD4x5sfy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flygoat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l2-20020a170902f68200b001c9e680c178si3552816plg.394.2023.11.01.08.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 08:17:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@flygoat.com header.s=fm1 header.b=URsyfAr2; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=MD4x5sfy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flygoat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2C66D812A957; Wed, 1 Nov 2023 08:17:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233843AbjKAPR3 (ORCPT + 99 others); Wed, 1 Nov 2023 11:17:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233757AbjKAPRW (ORCPT ); Wed, 1 Nov 2023 11:17:22 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82258191; Wed, 1 Nov 2023 08:16:49 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id D05445C026B; Wed, 1 Nov 2023 11:16:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Wed, 01 Nov 2023 11:16:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1698851808; x=1698938208; bh=Mm+JRDBtZvObmZ+uO6jWZAPic1sg7YIcuKF rNlBR5/c=; b=URsyfAr2jR4DaeRxAEJ+ozYGQ20/t1waQFKOE81pCv3g7T84RR0 OwtHcHTHsiXqsjq31xK6GsKqMbVlnwHYTiS9QJE+JAyzYhCQkafHtP1+KOpA2mxX 3Ke/5whz4ByHA9i3yrSYG4BpV3Pw+px8M5dquDLq5pL0w1ACsP9laWypcxqZJxFT HuHRYuFds9mLbzj2eysMvR2p2rdXOCEnvFw/79QkkMlolJp4MZbFIJhXdSIVptua 7L833q+E5UWgZSGmEcKhVz/wODc0CEN8cBo4FAm997uBMkOhekd96kwyvRSbW/Qf vu1ASJByIUGgrlDzVfxfIKralmNVpTADrYg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1698851808; x=1698938208; bh=Mm+JRDBtZvObmZ+uO6jWZAPic1sg7YIcuKF rNlBR5/c=; b=MD4x5sfy8SNN6nBRoBFlSo413yZMS8RRL93V+HN7If5+1cyGX8P jMpJaXDvMmONqHW1RmZ+WLU4VzNCo2/mpNiarlbY/f4yYGe+OYGRH5JyuB0Kmea3 Gv3kQ/vgL2dc2LuJe5yKR3EUYcMNbzKrVu2Vno8DYBQGRKtPBdeIYLkd9+E987qt 1EPShDJK046p9f1LodmUFNCOlQQqFTH0UWowTYklHjFYZgcNoD5S+K1/kff6qUNr jsfwvktaBHNN2++ZpECIEFfvqH4QOLXgLgbOlkRydhsiyeVC3l7jaad2VTwyz7xE 2oLMY/VxCNo0k78K+9FGmJAmA/U/rQAQ3zw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedruddtgedgjeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffekgedugefhtdduudeghfeu veegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 1 Nov 2023 11:16:47 -0400 (EDT) From: Jiaxun Yang Date: Wed, 01 Nov 2023 11:39:09 +0000 Subject: [PATCH fixes 3/3] MIPS: Loongson64: Handle more memory types passed from firmware MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231101-loongson64_fixes-v1-3-2a2582a4bfa9@flygoat.com> References: <20231101-loongson64_fixes-v1-0-2a2582a4bfa9@flygoat.com> In-Reply-To: <20231101-loongson64_fixes-v1-0-2a2582a4bfa9@flygoat.com> To: Thomas Bogendoerfer Cc: Huacai Chen , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang , stable@vger.kernel.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 01 Nov 2023 08:17:42 -0700 (PDT) There are many types of revsered memory passed from firmware that should be reserved in memblock, and UMA memory passed from firmware that should be added to system memory for system to use. Also for memblock there is no need to align those space into page, which actually cause problems. Handle them properly to prevent memory corruption on some systems. Cc: stable@vger.kernel.org Signed-off-by: Jiaxun Yang --- arch/mips/include/asm/mach-loongson64/boot_param.h | 6 +++- arch/mips/loongson64/init.c | 42 +++++++++++++--------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h index c454ef734c45..e007edd6b60a 100644 --- a/arch/mips/include/asm/mach-loongson64/boot_param.h +++ b/arch/mips/include/asm/mach-loongson64/boot_param.h @@ -14,7 +14,11 @@ #define ADAPTER_ROM 8 #define ACPI_TABLE 9 #define SMBIOS_TABLE 10 -#define MAX_MEMORY_TYPE 11 +#define UMA_VIDEO_RAM 11 +#define VUMA_VIDEO_RAM 12 +#define MAX_MEMORY_TYPE 13 + +#define MEM_SIZE_IS_IN_BYTES (1 << 31) #define LOONGSON3_BOOT_MEM_MAP_MAX 128 struct efi_memory_map_loongson { diff --git a/arch/mips/loongson64/init.c b/arch/mips/loongson64/init.c index d62262f93069..f25caa6aa9d3 100644 --- a/arch/mips/loongson64/init.c +++ b/arch/mips/loongson64/init.c @@ -49,8 +49,7 @@ void virtual_early_config(void) void __init szmem(unsigned int node) { u32 i, mem_type; - static unsigned long num_physpages; - u64 node_id, node_psize, start_pfn, end_pfn, mem_start, mem_size; + phys_addr_t node_id, mem_start, mem_size; /* Otherwise come from DTB */ if (loongson_sysconf.fw_interface != LOONGSON_LEFI) @@ -64,27 +63,38 @@ void __init szmem(unsigned int node) mem_type = loongson_memmap->map[i].mem_type; mem_size = loongson_memmap->map[i].mem_size; - mem_start = loongson_memmap->map[i].mem_start; + + /* Memory size comes in MB if MEM_SIZE_IS_IN_BYTES not set */ + if (mem_size & MEM_SIZE_IS_IN_BYTES) + mem_size &= ~MEM_SIZE_IS_IN_BYTES; + else + mem_size = mem_size << 20; + + mem_start = (node_id << 44) | loongson_memmap->map[i].mem_start; switch (mem_type) { case SYSTEM_RAM_LOW: case SYSTEM_RAM_HIGH: - start_pfn = ((node_id << 44) + mem_start) >> PAGE_SHIFT; - node_psize = (mem_size << 20) >> PAGE_SHIFT; - end_pfn = start_pfn + node_psize; - num_physpages += node_psize; - pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n", - (u32)node_id, mem_type, mem_start, mem_size); - pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n", - start_pfn, end_pfn, num_physpages); - memblock_add_node(PFN_PHYS(start_pfn), - PFN_PHYS(node_psize), node, + case UMA_VIDEO_RAM: + pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes usable\n", + (u32)node_id, mem_type, &mem_start, &mem_size); + memblock_add_node(mem_start, mem_size, node, MEMBLOCK_NONE); break; case SYSTEM_RAM_RESERVED: - pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n", - (u32)node_id, mem_type, mem_start, mem_size); - memblock_reserve(((node_id << 44) + mem_start), mem_size << 20); + case VIDEO_ROM: + case ADAPTER_ROM: + case ACPI_TABLE: + case SMBIOS_TABLE: + pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes reserved\n", + (u32)node_id, mem_type, &mem_start, &mem_size); + memblock_reserve(mem_start, mem_size); + break; + /* We should not reserve VUMA_VIDEO_RAM as it overlaps with MMIO */ + case VUMA_VIDEO_RAM: + default: + pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes unhandled\n", + (u32)node_id, mem_type, &mem_start, &mem_size); break; } } -- 2.34.1