Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp192331ybs; Sun, 24 May 2020 02:19:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+MFnWW9ecc2zXhW6s6LpTjaOwkcKyW0UmITDRW3mc0X1bK9Ji5hpjbzVdakJ0JLowWIkG X-Received: by 2002:a17:906:f916:: with SMTP id lc22mr14693791ejb.96.1590311986429; Sun, 24 May 2020 02:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590311986; cv=none; d=google.com; s=arc-20160816; b=TrsfnGUzSAzlavZo9UtT5fflLvyfAaJoJK57oMkGm5E3Xfnpp6UC4+83Ve51TPy75E dfeMEufksLltXlOayeYfx/p+RyOX+rZNdr6PZ++y1b3ol3qUhBdq0p0+VEJL4ELA4F7I y/XZnDdF88/U8Vgx5it6Cnxu3YHAUDBhX+ZTHi4MWjedcilLD25LekmBiYyahG9BweHo TcCcB0AGd91ONqvAo8+wsiijCHO5GUSV88hzQVwviHJE+k7qI/MZNXF0XSm4XRXmLviO XxvyneXUiKE/0q3mAhYeowbG6MpsPv1tvc41TnmkaK0ZoA5x8vcvoX1vpO/9oVeUxFLe 8UFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=IJsAs5zzI+wKL1374Yn6oN9d9oh4ET/3jmTNhJfVXvw=; b=jGvRV5LCUZprWU0xorQsW1JomD2CDisIcCuq+ltnekWV9yMjxHF/ks03hSTvyaNjiH iJYgAZSeYvQwuzdXkJgZh0U+AwC/bhsig8EJIajPhgBU47L/424cvcOoc1NVTMe+FtoE nqCtcZoKClbJi1yhrHpG7cjqtGF2heJ8GSIYfCVX+ZhWYZ2f8/EZL2LVq+S1ACj0RTEQ KF6+WLbLe+4/L7UnbYhgK/jintLxNqSTSUS3P8TRDRYjCw/+ZCkyliHDvjawtDZtKKys ey62hozOejm8lPJ0cKL1mghYhsW8KRONWOAHgRksXEILera5rC7SkRDfql1Q3zWQNKhW VS4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id du12si8892924ejc.398.2020.05.24.02.19.24; Sun, 24 May 2020 02:19:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729249AbgEXJQZ (ORCPT + 99 others); Sun, 24 May 2020 05:16:25 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:50269 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728252AbgEXJQZ (ORCPT ); Sun, 24 May 2020 05:16:25 -0400 Received: from localhost.localdomain (lfbn-gre-1-325-105.w90-112.abo.wanadoo.fr [90.112.45.105]) (Authenticated sender: alex@ghiti.fr) by relay12.mail.gandi.net (Postfix) with ESMTPSA id B5B91200005; Sun, 24 May 2020 09:16:21 +0000 (UTC) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Zong Li , Anup Patel , Christoph Hellwig , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH 6/8] riscv: Allow user to downgrade to sv39 when hw supports sv48 Date: Sun, 24 May 2020 05:10:06 -0400 Message-Id: <20200524091008.25587-7-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200524091008.25587-1-alex@ghiti.fr> References: <20200524091008.25587-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is made possible by using the mmu-type property of the cpu node of the device tree. By default, the kernel will boot with 4-level page table if the hw supports it but it can be interesting for the user to select 3-level page table as it is less memory consuming and faster since it requires less memory accesses in case of a TLB miss. Signed-off-by: Alexandre Ghiti --- arch/riscv/mm/init.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index bad8da099ff6..1776eeb53d61 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -509,11 +509,32 @@ void disable_pgtable_l4(void) * then read SATP to see if the configuration was taken into account * meaning sv48 is supported. */ -asmlinkage __init void set_satp_mode(uintptr_t load_pa) +asmlinkage __init void set_satp_mode(uintptr_t load_pa, uintptr_t dtb_pa) { u64 identity_satp, hw_satp; int cpus_node; + /* 1/ Check if the user asked for sv39 explicitly in the device tree */ + cpus_node = fdt_path_offset((void *)dtb_pa, "/cpus"); + if (cpus_node >= 0) { + int node; + + fdt_for_each_subnode(node, (void *)dtb_pa, cpus_node) { + const char *mmu_type = fdt_getprop((void *)dtb_pa, node, + "mmu-type", NULL); + if (!mmu_type) + continue; + + if (!strcmp(mmu_type, "riscv,sv39")) { + disable_pgtable_l4(); + return; + } + + break; + } + } + + /* 2/ Determine if the HW supports sv48: if not, fallback to sv39 */ create_pgd_mapping(early_pg_dir, load_pa, (uintptr_t)early_pud, PGDIR_SIZE, PAGE_TABLE); create_pud_mapping(early_pud, load_pa, (uintptr_t)early_pmd, @@ -561,7 +582,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) load_sz = (uintptr_t)(&_end) - load_pa; #if defined(CONFIG_64BIT) && !defined(CONFIG_MAXPHYSMEM_2GB) - set_satp_mode(load_pa); + set_satp_mode(load_pa, dtb_pa); #endif kernel_virt_addr = KERNEL_VIRT_ADDR; -- 2.20.1