From patchwork Wed Aug 30 04:39:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 13370236 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 F12F9C6FA8F for ; Wed, 30 Aug 2023 13:15:55 +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:To:From:Cc:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=p7gHobbN5IKAWvM26BbTmHfwP4qXXOydVGq98kF5xD0=; b=NPeDmkNMYQFRPp IkH/NfNTRyoTcSahZKkICtEWE5BB/t1HN8BAs/KS+W/FmSUnd9VvBwSFjAkf6uqq7P6Uf2whm+EH1 oEMrJ/Yt9QrakJby5fWnG0+/K/JWY/RpT41yfQmVg4+CUGMbcpEI9cObWqfk0VJYZt+X/11EVJcmX GjUypHmQKWAgljeHM5Ku1hXgOPpgKUm9k2SzFnyfS/3Bgqf8yAKwmKbHeHvp8nKeeG07dLxjrgaOj o9b9so4lYaUn+89aUxKYUEBtuygM33FCUHbi0BKwwDNonZfMLazhYiYUHuhjCqj4uzhjFanKEYJle ac85TaCmiaIynSvv+hiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qbL2q-00DX1c-1I; Wed, 30 Aug 2023 13:15:40 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qbL2n-00DX0b-1r for linux-riscv@lists.infradead.org; Wed, 30 Aug 2023 13:15:39 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bf55a81eeaso29975585ad.0 for ; Wed, 30 Aug 2023 06:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1693401336; x=1694006136; darn=lists.infradead.org; h=to:from:cc:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:from:to:cc:subject:date :message-id:reply-to; bh=EprF1uXyAHVR6ZTEqlGbvjAbCEeP9s8rUuKsD/Vy6Jk=; b=YnLgqju5/SjgIOEuWMmGTYmMMF4Pdfjy4XlVNekN3oZ8Ux5OulORXdVSufc//NkeOM 8L7ioaxIWSVCvAOXvX8IBgWS3lQCeQ4X6wpJc5flU2xsKXLK2dD/0V+WaB6BQ8bYupAj C+IsupZmZMlGN2AH3sCHqDtNu4EBDYk2z7zX+Yrk0bTLGlMYBWC9NcZxJzXG07ymCPI1 f3kQ9AoSnKOBgxEHTbXa/Qahv2LIeLA5Q3IoyXpt8iCMQQ9piYkkzfqEfJgg4C3B9bVL C5krtkQ1pJfibPvOMLuLwGyH8YjiEAh5cGG6LDcNLav1agfSUwFSXXYiYopnrh1mhc0W nsoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693401336; x=1694006136; h=to:from:cc:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EprF1uXyAHVR6ZTEqlGbvjAbCEeP9s8rUuKsD/Vy6Jk=; b=V5KMSfx3HSmSDOeDY8NbrZGLFjDjq6VfZn8YjvZ5CvIofKTh7nDJvm4NFFDHelUszF nUFdYtMARAPo5PgddYicg/6604W26m/IawgkBLNA7hdUEeMRSEpnVtbgtNvhhRTA1QP9 d1ra/2mR9Jxk5FmYmGkWjpFgwYXBFqN8YNvq1d/bqtAhhHYw/+oMJ4qk4gHDdnBz3R56 KegQMp+722tUiZULXLT8zwmfW/aBgsNYnkC2MHIdDoehfvqYnkp3zIFmTxuFNwBMbtau Z1HjfZdQTrD/eBlj37BllpbI+bE/O8iWWe+PtZzCnz5vPUZALwYSEmlWsZkmAlmAqymt tsbA== X-Gm-Message-State: AOJu0YxthuP+uSdWzY2cqvO/RJIn7wWnKZYJPhniXOY8Y8yuRVurdW9H U/Pb+wBDocmQajImAEdQdvKYgw== X-Google-Smtp-Source: AGHT+IF8a0rUAhVVitf63UZwI8k32a0/mxdA0Wk7Zf1BpmVnyTXVtB5iS/e55nCjmj3fqFQZ5eeuCg== X-Received: by 2002:a17:902:b948:b0:1b5:561a:5c9a with SMTP id h8-20020a170902b94800b001b5561a5c9amr1841082pls.39.1693401336356; Wed, 30 Aug 2023 06:15:36 -0700 (PDT) Received: from localhost ([135.180.227.0]) by smtp.gmail.com with ESMTPSA id x7-20020a170902820700b001b83e624eecsm11104947pln.81.2023.08.30.06.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 06:15:36 -0700 (PDT) Subject: [PATCH v2 1/2] RISC-V: Provide pgtable_l5_enabled on rv32 Date: Tue, 29 Aug 2023 21:39:19 -0700 Message-ID: <20230830044129.11481-2-palmer@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230830044129.11481-1-palmer@rivosinc.com> References: <20230830044129.11481-1-palmer@rivosinc.com> MIME-Version: 1.0 Cc: Palmer Dabbelt From: Palmer Dabbelt To: linux-riscv@lists.infradead.org, suagrfillet@gmail.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230830_061537_834317_6AC98F0A X-CRM114-Status: GOOD ( 11.73 ) 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 A few of the other page table level helpers are defined on rv32, but not pgtable_l5_enabled. This adds the definition as a constant and converts pgtable_l4_enabled to a constant as well. Signed-off-by: Palmer Dabbelt --- arch/riscv/include/asm/pgtable-32.h | 3 +++ arch/riscv/include/asm/pgtable.h | 1 - arch/riscv/mm/init.c | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/pgtable-32.h b/arch/riscv/include/asm/pgtable-32.h index 59ba1fbaf784..49c42016f0ed 100644 --- a/arch/riscv/include/asm/pgtable-32.h +++ b/arch/riscv/include/asm/pgtable-32.h @@ -33,4 +33,7 @@ _PAGE_WRITE | _PAGE_EXEC | \ _PAGE_USER | _PAGE_GLOBAL)) +static const __maybe_unused int pgtable_l4_enabled = 0; +static const __maybe_unused int pgtable_l5_enabled = 0; + #endif /* _ASM_RISCV_PGTABLE_32_H */ diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 75970ee2bda2..dae884f52cc1 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -878,7 +878,6 @@ extern uintptr_t _dtb_early_pa; #define dtb_early_pa _dtb_early_pa #endif /* CONFIG_XIP_KERNEL */ extern u64 satp_mode; -extern bool pgtable_l4_enabled; void paging_init(void); void misc_mem_init(void); diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 70fb31960b63..25ff8864e9bf 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -48,10 +48,12 @@ u64 satp_mode __ro_after_init = SATP_MODE_32; #endif EXPORT_SYMBOL(satp_mode); +#ifdef CONFIG_64BIT bool pgtable_l4_enabled = IS_ENABLED(CONFIG_64BIT) && !IS_ENABLED(CONFIG_XIP_KERNEL); bool pgtable_l5_enabled = IS_ENABLED(CONFIG_64BIT) && !IS_ENABLED(CONFIG_XIP_KERNEL); EXPORT_SYMBOL(pgtable_l4_enabled); EXPORT_SYMBOL(pgtable_l5_enabled); +#endif phys_addr_t phys_ram_base __ro_after_init; EXPORT_SYMBOL(phys_ram_base); From patchwork Wed Aug 30 04:39:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 13370235 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 4D02DC83F14 for ; Wed, 30 Aug 2023 13:15:50 +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:To:From:Cc:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tjU/B67fyJ+yrceDAxAfm4P6hzorg7qnt+OMmr8VywQ=; b=V9nKbhMcznJ/s/ 1zCPTI+AVi65g677TlCZ+ff53iLfkvQBCXEk0riu9Y3HQPFI7e/513Ft9AJAn1T6e1ZJPTYC/PfiF xCvrjoAdSi9gr0RWD5yncrdqcCjiZTOuFa7jJGnVPqkgaoP6G1sQk5j3vA3pzxYTkWN3GgC0gi2Df zTpumlrS+f4kgq2KW/UIFRzj6KTU0zgRe/9B4QaW9fPLrKHf3Az0C1uOKfUJGnbHQgWHoB8Hy2L+a TUBjluHL+L5MZIZH2lELxWvetFLam0HwAcT+hSkcHkvxMvE5N/X03bD4aY2CW7cryJucJm56nOyYc yGWJNVB055gE9itGTxYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qbL2q-00DX1k-31; Wed, 30 Aug 2023 13:15:40 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qbL2o-00DX0m-0l for linux-riscv@lists.infradead.org; Wed, 30 Aug 2023 13:15:39 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bf48546ccfso29812715ad.2 for ; Wed, 30 Aug 2023 06:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1693401337; x=1694006137; darn=lists.infradead.org; h=to:from:cc:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:from:to:cc:subject:date :message-id:reply-to; bh=58JmpBMuut0U4rrpw0CXIuY7q7ojOIFJjIbB/139BI0=; b=sbg4tiADjBSj3BbwWJfmIpm8qIHS+VMQ6egAGnEPQtpmL+bfUIw6rg/AsvUuaiSahK DzpPqNgI29pqhbFEvRRpCbGdYDdBuGndrLQQd87l1dkIKx5li9mOxYvFyB/SC2Gay6yA QjOlqMVhRTKN3gn+3Ee504j52+2aounIHk9SZnXC5dnm88hCQqLB8MGjvzq0cgqIsSIs fcnpiSUWKxy2og3CoBiu/z8IcLeF6NOFHwVmgNBXGndcC0wPYvBVv43ax6iN6IWCkGcH 9VA9uF3oZYkmvpSU3N/3HgUxgPmHCyAcxExlfE5McnF256wVyfPyNDrp82by0aty74o2 SfRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693401337; x=1694006137; h=to:from:cc:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=58JmpBMuut0U4rrpw0CXIuY7q7ojOIFJjIbB/139BI0=; b=EvwfDgTFIZvANxGhzVEQCim4E6YBjlKgkx0Pv4O7e8PuuEiKjR0VuqfCU8xgcR+i+1 5h+r+b9ayCKbcQtpS33Evu5s6vC55bLublS9ewPyUmZnQbYpLGqMXwEfwWOtxfglgZdw PNtSd6CyAf8IZpevbzhlnJKb2YX9OhyN04QWc/HM6WN0PHd+LqeT4T5iRCi68BFknYkf GkyJWaZRw24dTZuIv5oHDCYoZfHqbbKXiTYWHZNIVCh+4Vt6zgiCUFlVE35N1ABaxZNS vfTDrS+Xg08G3d2l9ivoCEofRXDPrbnxTw6bQx5fYrz+nWV+8JuXPJKgIpKy9ztRLL7s iXbA== X-Gm-Message-State: AOJu0YxgynmTVU9bADRSmhoJP/Q0K8VY+ANczzavgU8FkHZvZbEF7zG4 54GJylfXs4bXH3w49Q2g99Sb9D4zdTBhfsQndGI= X-Google-Smtp-Source: AGHT+IECpbqH/UrkxB1+1DlNKmoHKvp+r/ynwupNT9KnTwQXvzoUtZlWI5HNytgqOrLW6uFMy/+qpw== X-Received: by 2002:a17:902:720a:b0:1c1:f3f8:3949 with SMTP id ba10-20020a170902720a00b001c1f3f83949mr1656776plb.1.1693401337465; Wed, 30 Aug 2023 06:15:37 -0700 (PDT) Received: from localhost ([135.180.227.0]) by smtp.gmail.com with ESMTPSA id d10-20020a170902654a00b001bc445e249asm11306143pln.124.2023.08.30.06.15.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 06:15:37 -0700 (PDT) Subject: [PATCH v2 2/2] riscv: correct pt_level name via pgtable_l5/4_enabled Date: Tue, 29 Aug 2023 21:39:20 -0700 Message-ID: <20230830044129.11481-3-palmer@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230830044129.11481-1-palmer@rivosinc.com> References: <20230830044129.11481-1-palmer@rivosinc.com> MIME-Version: 1.0 Cc: Alexandre Ghiti , stable@vger.kernel.org, Palmer Dabbelt From: Palmer Dabbelt To: linux-riscv@lists.infradead.org, suagrfillet@gmail.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230830_061538_273931_18372732 X-CRM114-Status: GOOD ( 11.00 ) 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 From: Song Shuai The pt_level uses CONFIG_PGTABLE_LEVELS to display page table names. But if page mode is downgraded from kernel cmdline or restricted by the hardware in 64BIT, it will give a wrong name. Like, using no4lvl for sv39, ptdump named the 1G-mapping as "PUD" that should be "PGD": 0xffffffd840000000-0xffffffd900000000 0x00000000c0000000 3G PUD D A G . . W R V So select "P4D/PUD" or "PGD" via pgtable_l5/4_enabled to correct it. Fixes: e8a62cc26ddf ("riscv: Implement sv48 support") Reviewed-by: Alexandre Ghiti Signed-off-by: Song Shuai Link: https://lore.kernel.org/r/20230712115740.943324-1-suagrfillet@gmail.com Cc: stable@vger.kernel.org Signed-off-by: Palmer Dabbelt --- arch/riscv/mm/ptdump.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/riscv/mm/ptdump.c b/arch/riscv/mm/ptdump.c index 20a9f991a6d7..e9090b38f811 100644 --- a/arch/riscv/mm/ptdump.c +++ b/arch/riscv/mm/ptdump.c @@ -384,6 +384,9 @@ static int __init ptdump_init(void) kernel_ptd_info.base_addr = KERN_VIRT_START; + pg_level[1].name = pgtable_l5_enabled ? "P4D" : "PGD"; + pg_level[2].name = pgtable_l4_enabled ? "PUD" : "PGD"; + for (i = 0; i < ARRAY_SIZE(pg_level); i++) for (j = 0; j < ARRAY_SIZE(pte_bits); j++) pg_level[i].mask |= pte_bits[j].mask;