From patchwork Fri Feb 2 18:07:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Bresticker X-Patchwork-Id: 13543239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD88CC4828F for ; Fri, 2 Feb 2024 18:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TJckCouiw5HLiBLTcms55h6HdW1fHcOxBOtvosyAsdA=; b=rsR6uYvsZvjyet Z8D7GQY6Wh3UX8WuuJfZIaSWIvZG7pF+2e8Q7BudJMhKigJcabbPY9tg8bZdqBiqLD0ALSKhI3cOO AYVZRyjQuLPHKX+vZkLTA+LhJUKZpKCfDswFucdp/CvN68lgorTu1gNa+M3mWaslNnawE97kpMUcJ 4XNn4FMb+XrteRI6VfUfZlQxUTotmHRllksbMQRrrHBtBrtndh986GaJA+r0dKv0pp8jA9Y3ifTYY UeVTswOqu6EnmcbZI7STgSep3cnuRW2m94APZ1HRvit6po1i9LMJG9ZWYsyVdk9thlMr1j8rq3Z+f /RqnAbAfm56WykrwtB/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVxwb-0000000CmL0-0wfo; Fri, 02 Feb 2024 18:07:17 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVxwY-0000000CmJc-1cVK for linux-riscv@lists.infradead.org; Fri, 02 Feb 2024 18:07:15 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6e02597a0afso106677b3a.1 for ; Fri, 02 Feb 2024 10:07:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706897233; x=1707502033; darn=lists.infradead.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=9Yyrip3T2gRBwGLvYCLpLjUFISir/avz/b+c2luLHGY=; b=ETpc2oaJAbtqb1RPkxXv3S7VcgFQn2cFzWnRwuTx/sVKzG4Jlz/Mdurp/s+PWB5gS8 TS1pAI7U0LS0ElqTvq7T920rJaOk4KIygko+G4fDP5qYv+ZZMFY2z0nafSar8zlI/geY 5GMhl+QcbuUNBQJl7U1icyTCMBuOYvQcfkKDD7KYhn/qbn/AxIjc3FbrVVJPDkIqL3ri eFdyf9jGdgvvWFi2UxmMG2dUuJXqjlW91wNHKUEdB+b1ZbCHH2oRisr95p0y21dwo2SV g4o20ikhVwRoFLyoAZYHYn+8XmVkGHlc3bRhZQCjru6/A7rOgA/nPHZCia+CPeQUxG8f PKzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706897233; x=1707502033; 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=9Yyrip3T2gRBwGLvYCLpLjUFISir/avz/b+c2luLHGY=; b=LjZX7TYBm2DxV2NoH6UVt7XiFqBoV1E52uW9CLe2drAwDVGRJ8SSnlcPLvIbA/c6sQ gj1ixWwQc5OWf42l+dXOUQGVdZP09JXZ8QoaKZjQZ1M9dCiJDmrDh8PXXACBmXDxcYyu IFv7YaY90RdztuR3o9EGzNxB044+p6e6BlfJmyxbYI84J9nGwpw8VDHqesKNXg5zRrEx q9erPZZdsiUUSqrW1PBlvQJSpQ+ZduiavLHb+Knw2zdlNe2utFiSE7/biQ8HK/e8vcrR 6I+ExHIyG4az5nWQfySYhbvaAoF6s1pzRjAcOi9FaAM6YNvuIkEAf31KEqORqxANoKTf Pauw== X-Gm-Message-State: AOJu0YxArdRjTW46ucWpCX2bZVWrzYqEQwnv7Wj+b4ljL7YW8COnjV4k q+65oar3iWoiUYW0bwZe5GX9TqKFSfCJIdGnse94OmG2chRX21nwU3X1ysh+lII= X-Google-Smtp-Source: AGHT+IG+xYxv+LwajPk4C5nz4DY2qxbK7PqAKE+WcH5FBlppsmmhxviIkgQ4jI0JLjaR+O7wz2Jigg== X-Received: by 2002:aa7:9e11:0:b0:6ce:751b:81d9 with SMTP id y17-20020aa79e11000000b006ce751b81d9mr3346175pfq.9.1706897233322; Fri, 02 Feb 2024 10:07:13 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCU5uQRhhNr4F5Tr/eDx4VZKGJkZm2fFKhzvmErVJFdhN1keJw/2/IIbPia/PAaM3mkVII16Nt5yvabl0M3Zh8DUWKa04jN+PvoVj8IbhmJzrBJJb9Arr0kaYy98U+F3QdLE5FXpj6PMaQqSExRB9qZR4DdEU4G0klU6A2Yo5YCioE6HI4Uq69jHHuQmm1KAoMudrIvnpqJDFjQ+aG90RJGeKLQrNFSBnP1dKqm3fulhCWqUkrdAXfbWK+vNySD4eg8DV/zQ0+5yqh++ Received: from abrestic.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id s26-20020aa78d5a000000b006ddd31a701esm1989267pfe.19.2024.02.02.10.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 10:07:12 -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 v2 1/2] efi: runtime: Fix potential overflow of soft-reserved region size Date: Fri, 2 Feb 2024 10:07:03 -0800 Message-Id: <20240202180704.808766-2-abrestic@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202180704.808766-1-abrestic@rivosinc.com> References: <20240202180704.808766-1-abrestic@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240202_100714_449797_EDEBE5E5 X-CRM114-Status: GOOD ( 10.86 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org md_size will have been narrowed if we have >= 4GB worth of pages in a soft-reserved region. Signed-off-by: Andrew Bresticker --- v2: use u64 instead of unsigned long --- 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..83092d93f36a 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; + u64 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..01f0f90ea418 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; + u64 md_size = md->num_pages << EFI_PAGE_SHIFT; struct resource *res; if (!(md->attribute & EFI_MEMORY_SP)) From patchwork Fri Feb 2 18:07:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Bresticker X-Patchwork-Id: 13543241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A00D4C48292 for ; Fri, 2 Feb 2024 18:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IiX/NfDWrDPwLbViewwCqvdHSH5GgvwXDRiTFzmutC0=; b=ZVPWR7xZIiTrXM 4dYIcWL1/whjRQ3zLgDYNHZ7RTGypNn3V6obxjdkgknUmvIsn8MayC4U8f8LtYfjryF0Pgf6EVW7R 6b2VZUktl5L9nIqasae+3vrBXYUxD2tDLCKN4mKhbhzPmvfJTGzio8jMoBxo0Avk3/NXqhcGPK9KZ ab9WPFaJPJRP1vjAGj7VmRljVTzpZFROAUXCUjUe6vm/ITGV9tc3m38IpO3ZclvaVod8joxFaieIX 6H8UT7VfiU9Zn1FPDj5JDgOyxnYi9OwIj6AUZoUB5f8kqucEatZdlyNrcg+cOHC81f4d/SkNjCVmn 6i/eULT1hJQhRW9juQ3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVxwc-0000000CmLt-4BGy; Fri, 02 Feb 2024 18:07:19 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVxwa-0000000CmKL-2XJ0 for linux-riscv@lists.infradead.org; Fri, 02 Feb 2024 18:07:17 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6daf694b439so1833497b3a.1 for ; Fri, 02 Feb 2024 10:07:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706897235; x=1707502035; darn=lists.infradead.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=hDme6jlnfxJTWCG7qW4Qy8DGvSmakPXAl9L2egvk9Cw=; b=yJ+cJT9PQ4ulz1T7bGqG0cRTUOBiw5aR7MWehMyf0pkKFh1zaXAK8aEBtJlUIOad/f B+8yskDS1jOJvcVX8L3Yz9MrcKr45k2F2mrhLNKdFSMOqVVQTMLTzuFg81hbHM8Xl3KK 8ZU4OK9RPakldTh9IS+KDkgWtqlYeH7z9F/pCMmN8DS9rVDEAPxiwkPvtVyBy6ZsVlkc Wa6XqRnwGPryixxa5Tl0NqWZW73GU8H6bOvesztsFTzNQLSJoPpdeF+ti9GWC3MpYJ46 40JZHRmqdp/ylbuA/ulG64xUHQ5qH/2lpIvnngLdkkdrTex8/KoHqC0JcrAQzCX4qRTK ybWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706897235; x=1707502035; 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=hDme6jlnfxJTWCG7qW4Qy8DGvSmakPXAl9L2egvk9Cw=; b=jJhLumVQbtGCGAJceO2thattL3f64Etm0tpIa2/XmBvktbAz116JPP91dux6C/UYxK zISKzgm3jMIXCOEBdZZROvsVhx0DDuC5J9xQ+qRurx5oMw/A0ht/NszHW+oRMndjvour rZ2ombSg9tzK8A0+uU6Tz1AUc76+y8KeSls5i/nFzde/g4C53NDFlll1TijUjgdTF91c iRx7qQR8p59Uo4LpL39/afUVQGEXAq+e5DtlSZbp+7162Worx2nlkHVv0G+YQADGDgQn qNd9JetaIbjEBrJC4FjFm96+WaeZShWBcnjGeDpLIIffn4UmfT8y3fKkhQzvsTZ9Qla8 k3lw== X-Gm-Message-State: AOJu0YxXbimA4/79a5OLkE7m4WcIo6KQE6v1+jCEfOKzBrn8rF5qQtJ6 RKOEVEOwjQkUswS73LuqnZtpErz0AqkhbWEjh8hjsPIqAln2h7FSt5UOYXrx6nA= X-Google-Smtp-Source: AGHT+IGApjy1ny5FjS4Gq04ep4ZGH47dxEianIZwB0z+YLgCGzepTGWlWVGFhBvj0Leq9dER0TovMw== X-Received: by 2002:a05:6a00:2d0b:b0:6de:2f30:9aa5 with SMTP id fa11-20020a056a002d0b00b006de2f309aa5mr10452219pfb.23.1706897235504; Fri, 02 Feb 2024 10:07:15 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUwNs/zU8/SXHjEg5qUkWY+fJgs2JKC5h3bIMxiFY66H4USskIUSM3fOxkdHpyh6sQ4e2yYOdz45C57EARz86REEZiCOCXWbA5Gm0Sypq6v9RBEWN+/mx4GuYvD6I1trxf3wKO1ukvU3hoffX9eTbINn/OcE3cSok4CavXG2l66S+no2C6S9fhUfvsxLFKbFDXcy3TWbq5Aq6sHseHObZF/cMmyc0nLCh8CIDSfRN4magWGtl7jSipLlkKKq5yv2ltHVt83sqeCYfeM Received: from abrestic.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id s26-20020aa78d5a000000b006ddd31a701esm1989267pfe.19.2024.02.02.10.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 10:07:15 -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 v2 2/2] efi: Don't add memblocks for soft-reserved memory Date: Fri, 2 Feb 2024 10:07:04 -0800 Message-Id: <20240202180704.808766-3-abrestic@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202180704.808766-1-abrestic@rivosinc.com> References: <20240202180704.808766-1-abrestic@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240202_100716_664616_05333AAE X-CRM114-Status: GOOD ( 12.46 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Adding memblocks for soft-reserved regions prevents them from later being hotplugged in by dax_kmem. Signed-off-by: Andrew Bresticker --- v2: only skip adding memblocks for soft-reserved mem --- drivers/firmware/efi/efi-init.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/efi/efi-init.c b/drivers/firmware/efi/efi-init.c index d4987d013080..a00e07b853f2 100644 --- a/drivers/firmware/efi/efi-init.c +++ b/drivers/firmware/efi/efi-init.c @@ -143,15 +143,6 @@ static __init int is_usable_memory(efi_memory_desc_t *md) case EFI_BOOT_SERVICES_DATA: case EFI_CONVENTIONAL_MEMORY: case EFI_PERSISTENT_MEMORY: - /* - * Special purpose memory is 'soft reserved', which means it - * is set aside initially, but can be hotplugged back in or - * be assigned to the dax driver after boot. - */ - if (efi_soft_reserve_enabled() && - (md->attribute & EFI_MEMORY_SP)) - return false; - /* * According to the spec, these regions are no longer reserved * after calling ExitBootServices(). However, we can only use @@ -196,6 +187,16 @@ static __init void reserve_regions(void) size = npages << PAGE_SHIFT; if (is_memory(md)) { + /* + * Special purpose memory is 'soft reserved', which + * means it is set aside initially. Don't add a memblock + * for it now so that it can be hotplugged back in or + * be assigned to the dax driver after boot. + */ + if (efi_soft_reserve_enabled() && + (md->attribute & EFI_MEMORY_SP)) + continue; + early_init_dt_add_memory_arch(paddr, size); if (!is_usable_memory(md))