From patchwork Fri Feb 2 16:34:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Bresticker X-Patchwork-Id: 769330 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 892FD148303 for ; Fri, 2 Feb 2024 16:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706891689; cv=none; b=h9r7rNk7u0m1K/g3n7ie7tELPVNa4snqUrkJZxWp48C/VcfmwAG+M/XIfOm/211ecndYh8kIzfwJkxMfTBnQuyMU4QWE0Gqung5yIGLWiwn8n1EQFZHefnZfyLD8xCgpMx21yASI2Ghj8jWnbeGopqCCsvSTo1/qaoFL0Q+P3jU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706891689; c=relaxed/simple; bh=Ikc0whWoh7rMxU2EQziFijF9n08K3zToYOOQC/gU6Gs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D5XJ/T/mLA2ZrtQQuCy8dNKNZzG8oOMbNKfJ1ld7fE0wjTUf5OnojY7N9tHew9fZi9l1/rqhRF9kbOuMnqrEb1hMzUrUEc9xZvFS2j0sHOpbeb2iPNW2Sx2h1aVTUBcQ0zu14fZm0oy0UVdRlRk9bMsz0lcG4ND8A0P44/uIdgY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=GtWBhmZb; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="GtWBhmZb" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-295d22bd625so1709969a91.1 for ; Fri, 02 Feb 2024 08:34:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706891688; x=1707496488; 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=M4XLcspDZ2svWPCn3b1Mu60aWYrbol9SnEepXTKa4KE=; b=GtWBhmZbc3MF+D7n2KyuoyJXPFF+HpI+Bqz01BA5dmLByc7hGNPyLEdNMO+eZJiCkY bAAm2PgUYmuSgKja+nie+Tmz/EP43bpN74WBcZ5G6dUwB49GkMuHxFrfMVoXlBscf5MC bHidPyQdE4LJDTH6i5xYH6T3b2DDqxhAmRJgbqPvm8EZwHk367pohy39O+rn7oXBM0Eg cKuPScqAr6jSfLr73WbqVPhwsGoND7b1XkjAmo2bDfJnzBhnDPB1qg1nNpr6wSA0OWH0 NZe02HBJmUgTqVP9LpJLYkzBU8ZlAOWiqW11c9UhGplh8OHI4c+eKxTiWnOj9CJYdv9n 8bKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706891688; x=1707496488; 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=M4XLcspDZ2svWPCn3b1Mu60aWYrbol9SnEepXTKa4KE=; b=gx6SKjYvl9wsvQxDZuLlB7msDFRaMM1vQbOha/1Chqz44ONDMkyKQMH+rwzSwbLdfd eO5C6vLwrRP+icfOdIOrqliM4CVb/anLyGdAKjddXOskuDhWx6pEr4WUOj1pCiS+U4Hm BXV96acp94P/C6sqTIK1n0VOf+Wwu+uJa+qcHZpMQHs0/sc0Tf60bPBqYqv711KwoCa7 mSTh661vGyqNjVwGywWTLOhiwnPTB72TDUSzR5jYmaUwKKyG+luKua1TEIqVTnVsTJ7W mKLjrAa6gDLgw8Np5+YdKW3oEHbnyMmfwvh7LgGqpl00PZzyNUrQqSPFx7vdXtS6mBUA TEAA== X-Gm-Message-State: AOJu0YzkSChRE6NSpNJKRf3ofXcKfyq1I2xI7nTfZ172Hxzl8oLLSWw0 JJwVEt0UdeGTBY+uA0k9QyDHrSG1kyrkkZPgMIIluONUPnQVIZ0ADvUz2AYG9PETBWIz0J9d6jv 9qPc= X-Google-Smtp-Source: AGHT+IFSaOJGmU3nV35wyc0qbUGGVGRDpxLFzEIabMTzgK3Mk6BNdYPxuXKelnyByl8YF5H8/0qHBA== X-Received: by 2002:a17:90b:80d:b0:295:ff5a:5e4d with SMTP id bk13-20020a17090b080d00b00295ff5a5e4dmr2634953pjb.20.1706891687915; Fri, 02 Feb 2024 08:34:47 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWl8eUkaFifVQfTIqx1jcOjqKGs+PzcPRmEeuWoGgHYEFqPgSWmGUEk8Z+2QzGzXhmi67UxDhC3lP11ZX5isxcEAUwRnOHIaqKRDQhDpW4rFHWMP1CsvPVVId7GnG8mz2+Jt2Ytj3xxCuaJFJNofafO/EUbReVVwNNgGdkYaB1HYH+faUsW9CNoLYFgaTphCuhfzUaQm+OE9phqQRx9H494jbkBk8ioZi7E7f3gLr5F4VRW/AMwDA/pj6h3qCnsXoDtCNPo2DsMQNL7 Received: from abrestic.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id ju15-20020a170903428f00b001d75c26e857sm1784870plb.288.2024.02.02.08.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 08:34:47 -0800 (PST) From: Andrew Bresticker To: Ard Biesheuvel Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Andrew Bresticker Subject: [PATCH 1/2] efi: runtime: Fix potential overflow of soft-reserved region size Date: Fri, 2 Feb 2024 08:34:32 -0800 Message-Id: <20240202163433.786581-2-abrestic@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202163433.786581-1-abrestic@rivosinc.com> References: <20240202163433.786581-1-abrestic@rivosinc.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 md_size will have been narrowed if we have >= 4GB worth of pages in a soft-reserved region. Signed-off-by: Andrew Bresticker --- drivers/firmware/efi/arm-runtime.c | 2 +- drivers/firmware/efi/riscv-runtime.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 83f5bb57fa4c..f369256c7003 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -107,7 +107,7 @@ static int __init arm_enable_runtime_services(void) efi_memory_desc_t *md; for_each_efi_memory_desc(md) { - int md_size = md->num_pages << EFI_PAGE_SHIFT; + unsigned long md_size = md->num_pages << EFI_PAGE_SHIFT; struct resource *res; if (!(md->attribute & EFI_MEMORY_SP)) diff --git a/drivers/firmware/efi/riscv-runtime.c b/drivers/firmware/efi/riscv-runtime.c index 09525fb5c240..9da79b8169d2 100644 --- a/drivers/firmware/efi/riscv-runtime.c +++ b/drivers/firmware/efi/riscv-runtime.c @@ -85,7 +85,7 @@ static int __init riscv_enable_runtime_services(void) efi_memory_desc_t *md; for_each_efi_memory_desc(md) { - int md_size = md->num_pages << EFI_PAGE_SHIFT; + unsigned long md_size = md->num_pages << EFI_PAGE_SHIFT; struct resource *res; if (!(md->attribute & EFI_MEMORY_SP)) From patchwork Fri Feb 2 16:34:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Bresticker X-Patchwork-Id: 770165 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2539149011 for ; Fri, 2 Feb 2024 16:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706891692; cv=none; b=Lq78V63SWQkGYE0ABbbb3bIVLtaJapHus3Beknat61gxVTwqsG1H9wVfFowj2/t18PcWmVFaDtcPfLh7aBYdEaQnkifCAB7HG9YgNXWJT01h/xg4rs8vptL4xIAKywraB9jyETuvN0US62bOukj861aNWDD6+ATtMmmWmn3OoIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706891692; c=relaxed/simple; bh=6wzJzUOn25V37JzavypuqOKI2HSv2Q0C4HVDvOIYmqI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qJEbF10I86mirdwuIxaRM1w1T/zDBc146wEYz9jEL4gNcmvkv5hLo/LRUvNUT7PiJcJWyVoW2t7rjiMpKku29bp9oviuZ6S8qv6fhkgmmsGWL5AuTwJgGw/unHDRh/z1IApjLkKS6n1kdEL0t+rsZ4WHMkbfr2Y/aa3d3e1w5mU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=qASvpXb5; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="qASvpXb5" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1d93f2c3701so13862835ad.3 for ; Fri, 02 Feb 2024 08:34:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706891690; x=1707496490; 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=Bqv6IbT5YBrkVHXBtAcPOljl6IyXNltBMTpBEU5EmMk=; b=qASvpXb5+QgDNx9N/WUpe1DkSlpp+G2g3zzxSJTjH4UIahWyvqFQmSaIaZuT9sUjfu 8sXbNmJpT6JQMEzl6haHnjCzsS92bKpMOyfCsVeJv/M1BodeHD4aGp4tWc8RaHmoOiFZ Pn+gL0R29J0R8Sj7SQjN7iVXAEK/A71DyMYCABfBamZQVtjanbtDyoLG8PN4F9o9bC21 vyjtrd+utvw2PmPGl3OF5DJlUg/Pfn9Fda4xYVzBOYp12bWGVQhg1LU+2zV6feoojHir y/65cKPNx5ggt2ems/5NA1Wl7smRnK7OjD8+VYXKig/HV506aUafNtgNcF9vZPMWGfup YSpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706891690; x=1707496490; 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=Bqv6IbT5YBrkVHXBtAcPOljl6IyXNltBMTpBEU5EmMk=; b=eiqhz6EIBzgUOBeIzTCL0RsRfiBePMX2wJfwKQYobb3DgiG1ljGPNZMOcGlP21quKL ClMQ0PXFMVuo5J6fkdsQLwM4anSCJycQufOGbAL5SHle+g9EfRGkxvc6qnbiykDtUAsM 6miY1kCePkifR2//8l2MCkiRLhssGgJx8BeOtQGy42+9Qe8LNGzbhVc3YUIExQPG1Lte VfDF2jjdiL/VwhtyXvqZjx0AVyIoct7gW3vQadHx5Kf0ugKdlyf97kvhuJXQe4gYy4ig WzsNYh+9XBYlH4ryscRED22Bd590d4ueeOfKwIdDIwIAqtNpOPoCYABNfQVn25HCvEdn usDA== X-Gm-Message-State: AOJu0YzYoCfuxP54QKAomeGvYRqHIGFPgR0O48XpT9pXGFz3UpQ7H+LN pNX8AfLP8ld35pi30BQ0Zt+8pN1Hee4C7Gsr1oB24G3giyROWtCo+LCBTFfpQ7c= X-Google-Smtp-Source: AGHT+IGqHgU6dK6aj/33iDUN8jETVP+XvIewbJ5TV+sTPM+PPxaI5s4OR+NQbwDplcZetb8cpjDR5g== X-Received: by 2002:a17:902:848b:b0:1d8:fcac:eff0 with SMTP id c11-20020a170902848b00b001d8fcaceff0mr7497653plo.9.1706891690057; Fri, 02 Feb 2024 08:34:50 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXMrpNV1ur1ZaUXyBREl/idQhnbrCLLbzfYUB6Yw5ZhB75G4Q5ZLpVuL60eFiSgHyQig+jkiOD/tHdIOzF+cK9nOkO9xQbFvFlf2pFBL/0ugpZBj5vBMrmBZNP44ch2ldgxCpOPavoC0ailhrqy3fOjDKBt9FTts48VbvXKCAdPTJ2pfBz1eKjn44ykacO+n6SixsVEAeA8I8Gcqw0pDXijksNLSVozgSD3J5gq9FQKAb4MDVqjy3mHagVLPo+ZjqteleNjFQnu52Zh Received: from abrestic.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id ju15-20020a170903428f00b001d75c26e857sm1784870plb.288.2024.02.02.08.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 08:34:49 -0800 (PST) From: Andrew Bresticker To: Ard Biesheuvel Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Andrew Bresticker Subject: [PATCH 2/2] efi: Don't add memblocks for unusable memory Date: Fri, 2 Feb 2024 08:34:33 -0800 Message-Id: <20240202163433.786581-3-abrestic@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202163433.786581-1-abrestic@rivosinc.com> References: <20240202163433.786581-1-abrestic@rivosinc.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adding memblocks (even if nomap) for such regions unnecessarily consumes resources by creating struct pages for memory that may never be used or, in the case of soft-reserved regions, prevents the memory from later being hotplugged in by dax_kmem. This is also consistent with how x86 handles unusable memory found in the EFI memory map. Signed-off-by: Andrew Bresticker --- drivers/firmware/efi/efi-init.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/firmware/efi/efi-init.c b/drivers/firmware/efi/efi-init.c index d4987d013080..f05bacac89b7 100644 --- a/drivers/firmware/efi/efi-init.c +++ b/drivers/firmware/efi/efi-init.c @@ -24,13 +24,6 @@ unsigned long __initdata screen_info_table = EFI_INVALID_TABLE_ADDR; -static int __init is_memory(efi_memory_desc_t *md) -{ - if (md->attribute & (EFI_MEMORY_WB|EFI_MEMORY_WT|EFI_MEMORY_WC)) - return 1; - return 0; -} - /* * Translate a EFI virtual address into a physical address: this is necessary, * as some data members of the EFI system table are virtually remapped after @@ -195,12 +188,9 @@ static __init void reserve_regions(void) memrange_efi_to_native(&paddr, &npages); size = npages << PAGE_SHIFT; - if (is_memory(md)) { + if (is_usable_memory(md)) { early_init_dt_add_memory_arch(paddr, size); - if (!is_usable_memory(md)) - memblock_mark_nomap(paddr, size); - /* keep ACPI reclaim memory intact for kexec etc. */ if (md->type == EFI_ACPI_RECLAIM_MEMORY) memblock_reserve(paddr, size);