Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp96262lqc; Thu, 29 Feb 2024 11:17:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXV00QNj0V8Irw6nFVodd8PyTxHgGNZURAzhb0s8wHOH3hxg3D0KmOX73t4Pr8EQZfsVOml5jSDr98PBrRbDZcUnDgu3MqrvVUrXaOBGw== X-Google-Smtp-Source: AGHT+IH8+N3kKtJjTwLig7BPDSnRD8bYjISOzaLtrjlL8PVRwSydxSSoyi429sSlm/Ey9AtrCeyh X-Received: by 2002:a05:6402:2314:b0:566:47dc:47e3 with SMTP id l20-20020a056402231400b0056647dc47e3mr2234280eda.15.1709234272987; Thu, 29 Feb 2024 11:17:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709234272; cv=pass; d=google.com; s=arc-20160816; b=hWhds/DCnyFs8uLF9fS+pm4KPcxp4cqy3vGrJiyluU2SeR9ElZIeM5xkCiZ2KZyhSo b6XqnwbFSQv6uCkJD9Oh+/KITV+Ouf6J2T32V3BqB0GtLBN1ZRyuw2H4aiftV2qM0LKY MMvwCYZyQiSKz8ZHY8NvSSDHIPjIN3eGb5fiHPTgt/QluhnC9rc0+yRtMntb/AIHdxAk PPrsqec4EOEJWeVCM+Uc+zT8Wx4oYPieaIW2qLQ3LOtVq+qKNvC5SARoYsRHWy1PjGvb EXBG5Dcsm71Y6FAkNs0wJp+7V90zps9++H30c7S9N20fiLSUbx7KAChZn+WkTIvQDimF OZng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=CvLGs74NJGFVasqtM+SI8neEwesQmLUQ1oSBfXimJbU=; fh=7mMsJoU89N1sfWTfdkC2zdnuPrl70gpu3cgSzBSuJYU=; b=ZjbXXbZiWYLzf1JifZ6NDZaled/+63WkJL7pmItnUpxtiIzb1giz8pnFqPPazMviwC L+WpuCefTjnF3/JWR2NkfjhlQr5mYLuquKxV8NEeJQANSTgWeXqO5Ul73hvCpKZOqcOS W3JBKomwaIG62+h5yoDhVhAu3WTEA0xqqNzVcrKsOiPA7yTh++bCRW6s+yKlGO4zXTKY LhV3nzd/SVHM8VCoJqWRoCZg+G5qUi1AmykUBGJzIgwJCi6S2a6JkncDXJQUowF69ofH 001N9J2WzGggVHWOfy1oQ/nfINQ9iiW1eulFHLWG6FMlZOey+vpDiXmq7wPtcCyoRtb/ rfow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail (test mode) header.i=@ics.forth.gr header.s=av header.b=gYOL+XtN; arc=pass (i=1 spf=pass spfdomain=ics.forth.gr dkim=pass dkdomain=ics.forth.gr dmarc=pass fromdomain=ics.forth.gr); spf=pass (google.com: domain of linux-kernel+bounces-87333-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87333-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ics.forth.gr Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cm3-20020a0564020c8300b00566b46a9208si345948edb.228.2024.02.29.11.17.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 11:17:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87333-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@ics.forth.gr header.s=av header.b=gYOL+XtN; arc=pass (i=1 spf=pass spfdomain=ics.forth.gr dkim=pass dkdomain=ics.forth.gr dmarc=pass fromdomain=ics.forth.gr); spf=pass (google.com: domain of linux-kernel+bounces-87333-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87333-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ics.forth.gr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B3AEB1F24666 for ; Thu, 29 Feb 2024 19:17:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8025B7828A; Thu, 29 Feb 2024 19:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ics.forth.gr header.i=@ics.forth.gr header.b="gYOL+XtN" Received: from mailgate.ics.forth.gr (mailgate.ics.forth.gr [139.91.1.2]) (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 1606C134439 for ; Thu, 29 Feb 2024 19:17:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=139.91.1.2 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709234266; cv=none; b=BVWOcg+7M819ZYaflbe846mte0f4tD8QuL/VzlxHDiUAL/GCMbWEqw/B2p7W9uAEePJc6ias3WXbHzYHLEepQYKRD+BYisNtfRgLJdPTCzzjXvxetSIfJ9HHf889BLYNPkPOS0ZEoXH48b8TLdBeNItsSwd50igXYuISjCFSUvs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709234266; c=relaxed/simple; bh=rRXx9P2fyWPVK8sV8uJDbjnXN7ir2je1z7JiOtduc5E=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=T2kwDMqH3AGiYNbibqbymUiJUPsBlcNIVIhRJUaOQIn/MNqGF/31yy5eTtX8GaxZqzSeVqJsNUxk2jR4p8O3jsEidj1EvaHRC3lgd0cqnev6blNPxm9iNssLxnKBsyVPNzuQgNTGepWsjCOKNvOd5JoLqJAWQbAx5Fugv+g9S2c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ics.forth.gr; spf=pass smtp.mailfrom=ics.forth.gr; dkim=pass (2048-bit key) header.d=ics.forth.gr header.i=@ics.forth.gr header.b=gYOL+XtN; arc=none smtp.client-ip=139.91.1.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ics.forth.gr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ics.forth.gr Received: from av3.ics.forth.gr (av3in.ics.forth.gr [139.91.1.77]) by mailgate.ics.forth.gr (8.15.2/ICS-FORTH/V10-1.8-GATE) with ESMTP id 41TJHc52009359 for ; Thu, 29 Feb 2024 21:17:38 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; d=ics.forth.gr; s=av; c=relaxed/simple; q=dns/txt; i=@ics.forth.gr; t=1709234253; x=1711826253; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=rRXx9P2fyWPVK8sV8uJDbjnXN7ir2je1z7JiOtduc5E=; b=gYOL+XtNrBpNzN3U4R08zOgYYjq7OJGSI0FAUc7Ds5BFAe1uGxztFtSq2Bf+t33+ 06AeFOtAPEcA6X4E59LB/CCSO5rVUBc0r87SLIb7CP2DH5+zPMH0OEJdd1e5ZYPh QEgpXuUa6nN2nEXffPI95/AR9lTtr+2sIOTSJAJ2+qGgLIObeBYPiWi0fNd9qWB/ +6ZuNFwuBQSm+RQFT3Bi19TP81SBJm2Kk9zALrBY0aVggJkjc5512mnX7oRB+zGh vjxb8jw4Tb4zzqAvw3XI6ozac2gzIHg4it4Qub/CyDFRUDDfTaH4/Cf/de5s/ZQF FI+fK8HtKed5sCPuLMitJA==; X-AuditID: 8b5b014d-a17eb70000002178-80-65e0d84d3c1c Received: from enigma.ics.forth.gr (webmail.ics.forth.gr [139.91.151.35]) by av3.ics.forth.gr (Symantec Messaging Gateway) with SMTP id 49.7E.08568.D48D0E56; Thu, 29 Feb 2024 21:17:33 +0200 (EET) X-ICS-AUTH-INFO: Authenticated user: dvlachos at ics.forth.gr From: Dimitris Vlachos To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, palmer@dabbelt.com, alexghiti@rivosinc.com, paul.walmsley@sifive.com Cc: clameter@sgi.com, akpm@linux-foundation.org, rppt@kernel.org, arnd@arndb.de, mick@ics.forth.gr, csd4492@csd.uoc.gr, maraz@ics.forth.gr Subject: [PATCH -fixes v2] riscv: Sparse-Memory/vmemmap out-of-bounds fix Date: Thu, 29 Feb 2024 21:17:23 +0200 Message-Id: <20240229191723.32779-1-dvlachos@ics.forth.gr> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRmVeSWpSXmKPExsXSHT1dWdf3xoNUg+N3lSzmrF/DZvG48Tij xd9Jx9gt1jeuY7dY8zTE4vKuOWwW2z63sFnM6P/PatH87hy7xcvLPcwWbbP4LY6s387kwOPx +9ckRo9Pl3+xeLx5+ZLF4+GmS0wem1Z1snmcmPGbxWPzknqPG7MiPO5ef8nkcan5OrvH501y AdxRXDYpqTmZZalF+nYJXBm3dzYyF/RwV8x9vZK5gXEvZxcjJ4eEgInE/75mpi5GLg4hgaOM Ev+f/WCFSNhK7F1wnAnEZhPQk1g/fw87SJGIwARGiV/vDzODOMwCcxglbrzqBspwcAgLeEpc P+oA0sAioCrxu+kiC4jNK2AlsfXlUyaQEgkBeYnFDyQgwoISJ2c+YQEJMwuoS6yfJwQSZgaq aN46m3kCI+8sJFWzEKpmIalawMi8ilEgscxYLzO5WC8tv6gkQy+9aBMjOOgZfXcw3t78Vu8Q IxMH4yFGCQ5mJRFeGcG7qUK8KYmVValF+fFFpTmpxYcYpTlYlMR5T9guSBYSSE8sSc1OTS1I LYLJMnFwSjUwCVpGr3xR84O7+JyGQ5jcQtZ3U+ymBXxp4kni+v1f+tW99NVVDDpSXLtDPW5n Fv/ok+KYxTPpeol05GVBpz86NiIbJhR0M3exp70S3xinVqqw78GFnoxHvx69WRpTEZ4avZn9 0wTDeaFy8/Rj5R8EL3j+NHPp+Q1FEWZvg7UZ06NvTHo8w1iuYJoz844DIeaGHyeVXQn2WxPW qPc2LTYydWeawJeK9xLGd9IvXXiWvO9k6stjWsV359vs/LZl2Uphbev62nmLntTKLyyvvHU1 94pb/Zc0+3kBFjPs+GcmdWot/ZUd4V60JH/d9AMXr2ae+SoU9/jXDt9ZbqvcDlk2fDmpdy78 vn7Fne7b1hwuSizFGYmGWsxFxYkA01WTUOkCAAA= Offset vmemmap so that the first page of vmemmap will be mapped to the first page of physical memory in order to ensure that vmemmap’s bounds will be respected during pfn_to_page()/page_to_pfn() operations. The conversion macros will produce correct SV39/48/57 addresses for every possible/valid DRAM_BASE inside the physical memory limits. v2:Address Alex's comments Suggested-by: Alexandre Ghiti Signed-off-by: Dimitris Vlachos Reported-by: Dimitris Vlachos Closes: https://lore.kernel.org/linux-riscv/20240202135030.42265-1-csd4492@csd.uoc.gr Fixes: d95f1a542c3d ("RISC-V: Implement sparsemem") Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 0c94260b5..875c9a079 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -84,7 +84,7 @@ * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled. */ -#define vmemmap ((struct page *)VMEMMAP_START) +#define vmemmap ((struct page *)VMEMMAP_START - (phys_ram_base >> PAGE_SHIFT)) #define PCI_IO_SIZE SZ_16M #define PCI_IO_END VMEMMAP_START -- 2.39.2