From patchwork Thu Dec 1 13:51:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13061337 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E12CC4321E for ; Thu, 1 Dec 2022 13:53:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A8FA6B0072; Thu, 1 Dec 2022 08:53:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7586A6B0073; Thu, 1 Dec 2022 08:53:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D3176B0074; Thu, 1 Dec 2022 08:53:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4CAAC6B0072 for ; Thu, 1 Dec 2022 08:53:22 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 10E7380770 for ; Thu, 1 Dec 2022 13:53:22 +0000 (UTC) X-FDA: 80193879444.23.151F6EA Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by imf11.hostedemail.com (Postfix) with ESMTP id 925624000D for ; Thu, 1 Dec 2022 13:53:21 +0000 (UTC) Received: by mail-wr1-f45.google.com with SMTP id d1so2767001wrs.12 for ; Thu, 01 Dec 2022 05:53:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; 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=bgLh6uMMR0Rcr9C+nyDLv9c+8u2wrvtTYa0+ThJna9I=; b=bmeNS2iEKjeqg6unQ+LJECbDmv0XQqeKqaACNC+HASzyAlGgmwAIi+IyPgR5TQy2Vm NKjpmkgZMPqWZdpaF0oqQrrcwqYrmQQPkcwE3JL1XH1rHQLcgECF7o6fz9wFLWkdCGEM y19q5D5ob+B6Q0p0SNy4JjQViJIShBPxcMLj9FC1HZsa6kYJM/k770E94SQ6RWRXBGbe dTBGarcCH9bDXHSGYNz/jUkT2OuX5WZUG9T6VGw8tZJAA6cHqbtFVXmon2eUWuwWOTMy JVIl5O0xYviC0vXwrGsyghXQcMnCS4OnEy88xxdHA2rM5ZTszL23U5etmCO/MItuC8JB hwBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=bgLh6uMMR0Rcr9C+nyDLv9c+8u2wrvtTYa0+ThJna9I=; b=n0n1Y+iKf8nL/MkuPhMwYwfMCF3Re9JbYCTHMY947xDGxC6i7yHTozeL0LNHkPTRXO C1DoNcd6s1Z1Aw7YzPxRoT2fgSrFrZJOzkz3gM794zkBFemUIlhUFmXjk63rXDcE/iwf NybVFUyHzMKz9yw+Y+o1PX9fg5KfSqgHXsFmN0ORPKZth+KwVRW6tsXll1WfBDaGJeOt R8A1c2DZZzuIqESY3sPvt3q3HcDZgrf+j4bPSUyUsTTL61zDYkMceKecvg+042cxTlzM dmWc+uGaFS5eY8laItsorsaBws5YIXAiCzWqLZY+GzwFQj6+4e1J64WQ11VsMwELMvAK 4D6g== X-Gm-Message-State: ANoB5pmeXvpAKudDzHK0qRq5cLx6C66i1JiqjICJf724PvOfWlcDIItq MlqXb76HtyqKxOyzWhkYl0H5ZMDwocYSJA== X-Google-Smtp-Source: AA0mqf7uWenO+LbmKE9LuMiukYmFeUw50rRJmRTVFYoCgTjjVHaNFb5qH68Z/YfC8l8bquXihHFdHw== X-Received: by 2002:a5d:6503:0:b0:22e:35e8:382d with SMTP id x3-20020a5d6503000000b0022e35e8382dmr41094490wru.475.1669902800271; Thu, 01 Dec 2022 05:53:20 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (lfbn-gre-1-201-46.w90-112.abo.wanadoo.fr. [90.112.163.46]) by smtp.gmail.com with ESMTPSA id t17-20020a05600c199100b003c7087f6c9asm9589361wmq.32.2022.12.01.05.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 05:53:19 -0800 (PST) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Qinglin Pan , linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH 1/1] riscv: Fix P4D_SHIFT definition for 3-level page table mode Date: Thu, 1 Dec 2022 14:51:28 +0100 Message-Id: <20221201135128.1482189-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221201135128.1482189-1-alexghiti@rivosinc.com> References: <20221201135128.1482189-1-alexghiti@rivosinc.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669902801; a=rsa-sha256; cv=none; b=JQSUDLKmr2nvtU4vUxZ7D+Ebioe5eRTcpdHGiPoBr6JvRPUmIEq2kXxQ00cGEOLkw+xfBS qE06Nh/P6oDXGtj/MGo3XfbkvkY75ubd4jFYD9bk3ocnnHqL3+o2p63CKge0boQ6cSGUNZ nACfL30VpbuHYIEsatmTqTVFMGFsNJ4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=bmeNS2iE; spf=pass (imf11.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669902801; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bgLh6uMMR0Rcr9C+nyDLv9c+8u2wrvtTYa0+ThJna9I=; b=eJHg6HZUZmzDXMhWjvr398h2v4Vb/hdvelZ5G0zzkZ9rmGINJDe++IweV45DCKKqAk8x5X MFfHs5B9vZbzc70jqUtSpDph25XKdvXRLvXFhYHMzx1yOOHmOFgc/jHwDqW4aZdHETzESw AK8wZd3LcG/fsLY4Xjrqfu/Ezylk67g= X-Stat-Signature: fojs11otikhc9dki97fwtznx1p9jsx6o X-Rspamd-Queue-Id: 925624000D X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=bmeNS2iE; spf=pass (imf11.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none X-Rspamd-Server: rspam05 X-HE-Tag: 1669902801-948005 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: RISC-V kernels support 3,4,5-level page tables at runtime by folding upper levels. In case of a 3-level page table, PGDIR is folded into P4D which in turn is folded into PUD: PGDIR_SHIFT value is correctly set to the same value as PUD_SHIFT, but P4D_SHIFT is not, then any use of P4D_SHIFT will access invalid address bits (all set to 1). Fix this by dynamically defining P4D_SHIFT value, like we already do for PGDIR_SHIFT. Fixes: d10efa21a937 ("riscv: mm: Control p4d's folding by pgtable_l5_enabled") Signed-off-by: Alexandre Ghiti Reviewed-by: Palmer Dabbelt --- arch/riscv/include/asm/pgtable-64.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h index dc42375c2357..42a042c0e13e 100644 --- a/arch/riscv/include/asm/pgtable-64.h +++ b/arch/riscv/include/asm/pgtable-64.h @@ -25,7 +25,11 @@ extern bool pgtable_l5_enabled; #define PGDIR_MASK (~(PGDIR_SIZE - 1)) /* p4d is folded into pgd in case of 4-level page table */ -#define P4D_SHIFT 39 +#define P4D_SHIFT_L3 30 +#define P4D_SHIFT_L4 39 +#define P4D_SHIFT_L5 39 +#define P4D_SHIFT (pgtable_l5_enabled ? P4D_SHIFT_L5 : \ + (pgtable_l4_enabled ? P4D_SHIFT_L4 : P4D_SHIFT_L3)) #define P4D_SIZE (_AC(1, UL) << P4D_SHIFT) #define P4D_MASK (~(P4D_SIZE - 1))