Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp315573ybg; Wed, 3 Jun 2020 01:19:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIdFXOKaM2GSEvrUuDpe2kjZ98Io86Wvv+7mH8N2b+i5IW9641s7rRjULbY4fhX/TwMNdF X-Received: by 2002:a05:6402:642:: with SMTP id u2mr16880041edx.230.1591172384546; Wed, 03 Jun 2020 01:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591172384; cv=none; d=google.com; s=arc-20160816; b=BndTuEZPOTHIHwU9pfNzTt2iURU482NuuA/IgC7eI4oEvCf1Un4aUXxTOW900qInNU kau00/dCwXEPhhh3YqS7xa+mhJ9jP5uFw/vUuwQlzM8UpZkhALcS3FrRsdX+6yucOlAR 7HwkNJ36FNmDFeZYhQqbc339d4Be/UoSN4OtiQ5smIa/9xacHeswYzEKEeP/pIpU4FKL m1sCbQMLmlktpIsEDL7zQ8Cw+WFqnObRm69vGKIAvyuy85M7v6hzabQZ9XqQCFda8ybP +xO15iSaJZd0sR5BC1PjMPeAXZZ3/k2+5yygDVkhsKJvXijMUSxzo6Fcbu62fYE9aMkO XbzA== 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=awziwPTvIk8pQUKVX85WToAgKAMAP5kvbQWePrvjj/w=; b=R6uBvHAg4ZPrEboSMcR3VKAi1v9P8r5SHDs66bq5dVC8n6e1RwCUZ/7ovsdy0zDfnf Eku3BgE5j+20xKhSEPJUceyhPq7iW3szkkvduN8DbiDCiF9nlgh7v0aD5fQ9MblpyyzC RcHMYvSLT3emtnZPf33SFoOrzwdWR9eqj2220ZHTVi6789w7pjxmGNJT4wxt2IcAwFz9 Ne3nF4FmBneAijWsJzGLyHEbzT+gu/WjzJaWx3eN7koQAiEl+oWcWAR14FNkPDiQp/6I 5SEw0FHu0JIRX3AKFKo3vBrzO2GAInvXOAZ/tgh48S2Cj6u+ytdocFm2ZnNVOO13Jyg6 LzgA== 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 l3si674572edi.536.2020.06.03.01.19.21; Wed, 03 Jun 2020 01:19:44 -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 S1726083AbgFCIR0 (ORCPT + 99 others); Wed, 3 Jun 2020 04:17:26 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:40067 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725275AbgFCIRZ (ORCPT ); Wed, 3 Jun 2020 04:17:25 -0400 Received: from debian.home (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 352FF200004; Wed, 3 Jun 2020 08:17: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 v2 6/8] riscv: Allow user to downgrade to sv39 when hw supports sv48 Date: Wed, 3 Jun 2020 04:11:02 -0400 Message-Id: <20200603081104.14004-7-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200603081104.14004-1-alex@ghiti.fr> References: <20200603081104.14004-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 Reviewed-by: Anup Patel --- arch/riscv/mm/init.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index a937173af13d..4064639b24e4 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -509,10 +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, @@ -560,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