Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1647784pxj; Fri, 4 Jun 2021 22:18:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwp2ATvJ1Yf079NLlHHF6o7ZSJE+md/r6/ZZnopNFBsD8nGQ9APYC/5WEYR+e/9QoIKJmu6 X-Received: by 2002:a17:906:4308:: with SMTP id j8mr7720717ejm.315.1622870281957; Fri, 04 Jun 2021 22:18:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622870281; cv=none; d=google.com; s=arc-20160816; b=LbhboYF+W115jGWxNLomxQC546OZk2yQRzrMfGVtigso1cjMoQ+00ktiCVYIZc28Ha Ci0R2yh7PzjUobqFj+1SScIQXE4HkG/AbO2SfXq8aYjz6dAk6khVqOWqxmkiRe/6nHs3 zPoSpQk+mkXrd1pHMgGyH26qUkyPUmQ3QVW6pkAGBX+zm6bUgnaWb1PCWQx/ZrqTsPoa Sztumhi4pU6N1MKU+vLSbpYbXpafxxl465/3CESRfJAymiZpaJLc5hhZpsc9BlW8i9g4 1VuHaKRh2eSPQELvkC0Lcy/tckWSwE3wice7oqkK1KSJ2W48D4rdp/ECUr70KCFf03X5 JEKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Esht7hC3eGvthzIzQpEHeHRRYQbWn2t/thK9YnHyNIg=; b=ztGUgkTQWY3rKjDMUci8W8hUvdoDZRJv5janQ/AWblDT1WTYMKKYADRVLSUwtSZK8G RzW/CDqau5/KViIzssMEEUgaVyswmrMl4maLMrngSQkt00VoDHiHtwjm2MCKct8LWKGT RAVV5MupvVucPfcT32Rc0A56aZlxjfXCKOpygSKw6lWC4ByRSSG6KE4PqJXu7yZ+VTvS dTQikgb+3QujeprJqSHDx3vOGhiP1AZDQ7HlWWgsefsWhxs2NTBASAoPjpqoUNdxmjhZ lSCVUCzT0e6Ag3ZDS8z3xQU67k0DVnhLdh/yhU8ft9UVfnGfxgaoXEVk6g2LoGpiZGUb 6srg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb5si6945099edb.276.2021.06.04.22.17.39; Fri, 04 Jun 2021 22:18:01 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230213AbhFEFSR (ORCPT + 99 others); Sat, 5 Jun 2021 01:18:17 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:7109 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbhFEFSR (ORCPT ); Sat, 5 Jun 2021 01:18:17 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Fxnps6XFszYqL6; Sat, 5 Jun 2021 13:13:41 +0800 (CST) Received: from dggpemm500009.china.huawei.com (7.185.36.225) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Sat, 5 Jun 2021 13:16:28 +0800 Received: from huawei.com (10.175.113.32) by dggpemm500009.china.huawei.com (7.185.36.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Sat, 5 Jun 2021 13:16:28 +0800 From: Liu Shixin To: Paul Walmsley , Palmer Dabbelt , Albert Ou CC: , , "Liu Shixin" Subject: [PATCH RFC] riscv: Enable pud vmap support for Sv48 Date: Sat, 5 Jun 2021 13:48:38 +0800 Message-ID: <20210605054838.2017817-2-liushixin2@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20210605054838.2017817-1-liushixin2@huawei.com> References: <20210605054838.2017817-1-liushixin2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enable pud vmap support and define the required page table functions for Sv48. Signed-off-by: Liu Shixin --- As riscv doesn't have Sv48 support currently, I test pud vmap based on Alex's patch "riscv: Implement sv48 support". arch/riscv/include/asm/pgtable-64.h | 10 ++++++++ arch/riscv/include/asm/vmalloc.h | 8 +++++- arch/riscv/mm/pgtable.c | 39 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h index e3b7c5dd6a80..8920321770c7 100644 --- a/arch/riscv/include/asm/pgtable-64.h +++ b/arch/riscv/include/asm/pgtable-64.h @@ -69,6 +69,16 @@ static inline struct page *pud_page(pud_t pud) return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT); } +static inline pud_t pfn_pud(unsigned long pfn, pgprot_t prot) +{ + return __pud((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot)); +} + +static inline unsigned long _pud_pfn(pud_t pud) +{ + return pud_val(pud) >> _PAGE_PFN_SHIFT; +} + static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot) { return __pmd((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot)); diff --git a/arch/riscv/include/asm/vmalloc.h b/arch/riscv/include/asm/vmalloc.h index 8f17f421f80c..83464895f902 100644 --- a/arch/riscv/include/asm/vmalloc.h +++ b/arch/riscv/include/asm/vmalloc.h @@ -3,7 +3,13 @@ #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -#define IOREMAP_MAX_ORDER (PMD_SHIFT) +#define IOREMAP_MAX_ORDER (PUD_SHIFT) + +#define arch_vmap_pud_supported arch_vmap_pud_supported +static inline bool __init arch_vmap_pud_supported(pgprot_t prot) +{ + return true; +} #define arch_vmap_pmd_supported arch_vmap_pmd_supported static inline bool __init arch_vmap_pmd_supported(pgprot_t prot) diff --git a/arch/riscv/mm/pgtable.c b/arch/riscv/mm/pgtable.c index 738dc6f3530f..ed13b80424e6 100644 --- a/arch/riscv/mm/pgtable.c +++ b/arch/riscv/mm/pgtable.c @@ -7,6 +7,45 @@ #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +#ifndef __PAGETABLE_PUD_FOLDED +int pud_set_huge(pud_t *pud, phys_addr_t phys, pgprot_t prot) +{ + pud_t new_pud = pfn_pud(__phys_to_pfn(phys), prot); + + set_pud(pud, new_pud); + return 1; +} + +int pud_clear_huge(pud_t *pud) +{ + if (!pud_leaf(READ_ONCE(*pud))) + return 0; + pud_clear(pud); + return 1; +} +#endif + +int pud_free_pmd_page(pud_t *pud, unsigned long addr) +{ + pmd_t *pmd; + pte_t *pte; + int i; + + pmd = (pmd_t *)pud_page_vaddr(*pud); + pud_clear(pud); + + flush_tlb_kernel_range(addr, addr + PUD_SIZE); + + for (i = 0; i < PTRS_PER_PMD; i++) { + if (!pmd_none(pmd[i])) { + pte = (pte_t *)pmd_page_vaddr(pmd[i]); + pte_free_kernel(NULL, pte); + } + } + pmd_free(NULL, pmd); + return 1; +} + #ifndef __PAGETABLE_PMD_FOLDED int pmd_set_huge(pmd_t *pmd, phys_addr_t phys, pgprot_t prot) { -- 2.18.0.huawei.25