From patchwork Mon Oct 18 01:59:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qinglin Pan X-Patchwork-Id: 12564843 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B759BC433F5 for ; Mon, 18 Oct 2021 02:00:28 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 65968610E5 for ; Mon, 18 Oct 2021 02:00:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 65968610E5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=SvZwRqf7gExqc5K2DhG9hN7i9gdHMm+bv55M2pLs01c=; b=w+uY4jAB1i1Tzg Pe1jsXH4HEzg2ftYEEO5ef8GdbvhScPYyuXxaHRs3Nr12qKyHmQh3xoLRfd+ucoZnY6Ox7pwJBmVN PRwHXdspY1/PkVTxxKPQW+N6pKsAM8qtUUyE1Snju84385ep7PvKrTEftO5V8OX3F6aOPnDGWq4Mq DUGJSi5dznBAYA1QY+9ySufzJQ+WMFbOPAyKvBuLiFKKukpVv4hBQa0fWBhzBrC9i+gDxoyL9uUpm idYe00WC23kUvMleXjMeiHI3X3sd7agTReguAQOD0rTCDa9/JU9oHwKXUOs0u7x2QEjMUdJkTj3pc EyCb9Ln8N4spcfT0a2Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcHwn-00DmsD-6l; Mon, 18 Oct 2021 02:00:17 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcHwj-00DmrB-Kb for linux-riscv@lists.infradead.org; Mon, 18 Oct 2021 02:00:15 +0000 Received: by mail-pl1-x62d.google.com with SMTP id 21so10127909plo.13 for ; Sun, 17 Oct 2021 19:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MfGTIV1+9CdUVlBc1WjTZb6+ouybOgZMGoCpwkOkAGg=; b=NHybavCNVSIt3/FcBE8fa8ZFVsWUW9Yua6UMszWYJfBQrajjgoMR5zw0H6gRDxoClF qBYnma50YFlIKPMFrY+rYaqPfu19XcKCua995WzpezWTMRed2dJFjUNxNGriNfNtwNp9 VaXErVwx0e4i44pKvOygjcDBiQwDaVm7PGeyA9fi0wzbPCN3jWQCJ41JzAaHXhPYNIoF uBHF0zTtz86oN+kBIc/NtGoLOLoFsGLKnHRU1NTstlp+kSMeqhWet+dBfVgc2HC9RRGw UudBswOgXZeIlRhUeaKKZG2hfxoqfrrB9pT5U2KGaBF00JpJtEmdRm0O0rhyKdMmPUu7 oGxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MfGTIV1+9CdUVlBc1WjTZb6+ouybOgZMGoCpwkOkAGg=; b=ORg0mdhAXOb4aIEEPLpfeJnNy6D66sAO7K5kDfj9yIXJRHvklObnd6CwfaQx5boCpe /q9+fM0tdmzRqDal9lQDnpz6sZni8f2MHr3q6zw1XsLPDlP6rIRI+YzSURuGAtMIX8he wdWkXkhnYxkedWXXfeo7JAWz9CQ2/JrHOkm0/g6zIMQH+dGHDimvgTxwW/xwGrv2hAy5 lz+d/g1A45p4WNEFPFzhnIMNa+yEkIC/VlxfrvmNINzwWtSKlBAVguBNOwE9TDtmNjIy n4HFFJc0g/ZryWyvvhHbBddL/br8eJzxHmBPPgjzibB8WGOXH4i6RjBrsuo8XZcnlstj WmvA== X-Gm-Message-State: AOAM532jjoxqdO0gbQz5ffNv30Zj++yEk2yRBnkP0qYYZR36EDdLFgPZ D9UT+WXiiE3+d2n3HEtsuEco71o4BOKwuBiMLkv9cg== X-Google-Smtp-Source: ABdhPJyC7YkbDN6IxAFQkTsfIiEf+yarhwH9EGF1om26Pmtj2l3accPqQf2SNp7BenjDPTvmgRsU+Q== X-Received: by 2002:a17:90b:3a88:: with SMTP id om8mr29923210pjb.164.1634522411844; Sun, 17 Oct 2021 19:00:11 -0700 (PDT) Received: from localhost.localdomain ([103.135.248.171]) by smtp.gmail.com with ESMTPSA id v22sm11381975pff.93.2021.10.17.19.00.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 19:00:11 -0700 (PDT) From: Qinglin Pan X-Google-Original-From: Qinglin Pan To: linux-riscv@lists.infradead.org Cc: xuyinan@ict.ac.cn, Qinglin Pan Subject: [RFC PATCH 1/4] mm: modify pte format for Svnapot Date: Mon, 18 Oct 2021 09:59:41 +0800 Message-Id: <20211018015944.1313008-1-panqinglin00@163.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211017_190013_710392_1A382951 X-CRM114-Status: GOOD ( 13.94 ) 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: Qinglin Pan Svnapot is a RISC-V extension for marking contiguous 4K pages as a non-4K page. Its concept proof will complete soon and this patch set is for using Svnapot in Linux Kernel's boot process and hugetlb fs. The draft spec about Svnapot can be found here: https://github.com/riscv/virtual-memory/blob/main/specs/ This patch modifies PTE definition for Svnapot, and creates some functions in pgtable.h to mark a PTE as napot and check if it is a Svnapot PTE. Until now, only 64KB napot size is supported in draft spec, so some macros has only 64KB version. The qemu which we use to test this patchset can be in this repo: https://github.com/plctlab/plct-qemu/tree/plct-virtmem-dev Yours, Qinglin Signed-off-by: Qinglin Pan --- arch/riscv/include/asm/pgtable-bits.h | 29 +++++++++++++++++++++++++++ arch/riscv/include/asm/pgtable.h | 23 ++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/pgtable-bits.h b/arch/riscv/include/asm/pgtable-bits.h index 2ee413912926..8369e4d45919 100644 --- a/arch/riscv/include/asm/pgtable-bits.h +++ b/arch/riscv/include/asm/pgtable-bits.h @@ -24,6 +24,26 @@ #define _PAGE_DIRTY (1 << 7) /* Set by hardware on any write */ #define _PAGE_SOFT (1 << 8) /* Reserved for software */ +#define _PAGE_RESERVE_0_SHIFT 54 +#define _PAGE_RESERVE_1_SHIFT 55 +#define _PAGE_RESERVE_2_SHIFT 56 +#define _PAGE_RESERVE_3_SHIFT 57 +#define _PAGE_RESERVE_4_SHIFT 58 +#define _PAGE_RESERVE_5_SHIFT 59 +#define _PAGE_RESERVE_6_SHIFT 60 +#define _PAGE_RESERVE_7_SHIFT 61 +#define _PAGE_RESERVE_8_SHIFT 62 +#define _PAGE_NAPOT_SHIFT 63 +#define _PAGE_RESERVE_0 (1UL << 54) +#define _PAGE_RESERVE_1 (1UL << 55) +#define _PAGE_RESERVE_2 (1UL << 56) +#define _PAGE_RESERVE_3 (1UL << 57) +#define _PAGE_RESERVE_4 (1UL << 58) +#define _PAGE_RESERVE_5 (1UL << 59) +#define _PAGE_RESERVE_6 (1UL << 60) +#define _PAGE_RESERVE_7 (1UL << 61) +#define _PAGE_RESERVE_8 (1UL << 62) + #define _PAGE_SPECIAL _PAGE_SOFT #define _PAGE_TABLE _PAGE_PRESENT @@ -34,6 +54,15 @@ #define _PAGE_PROT_NONE _PAGE_READ #define _PAGE_PFN_SHIFT 10 +#define _PAGE_PFN_MASK (_PAGE_RESERVE_0 - (1UL << _PAGE_PFN_SHIFT)) +/* now Svnapot only supports 64KB*/ +#define NAPOT_CONT64KB_ORDER 4UL +#define NAPOT_CONT64KB_SHIFT (NAPOT_CONT64KB_ORDER + PAGE_SHIFT) +#define NAPOT_CONT64KB_SIZE (1UL << NAPOT_CONT64KB_SHIFT) +#define NAPOT_CONT64KB_MASK (NAPOT_CONT64KB_SIZE - 1) +#define NAPOT_64KB_PTE_NUM (1UL << NAPOT_CONT64KB_ORDER) +#define _PAGE_NAPOT (1UL << _PAGE_NAPOT_SHIFT) +#define NAPOT_64KB_MASK (7UL << _PAGE_PFN_SHIFT) /* Set of bits to preserve across pte_modify() */ #define _PAGE_CHG_MASK (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ | \ diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 39b550310ec6..adacb877433d 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -251,7 +251,11 @@ static inline pte_t pud_pte(pud_t pud) /* Yields the page frame number (PFN) of a page table entry */ static inline unsigned long pte_pfn(pte_t pte) { - return (pte_val(pte) >> _PAGE_PFN_SHIFT); + unsigned long val = pte_val(pte); + unsigned long is_napot = val >> _PAGE_NAPOT_SHIFT; + unsigned long pfn_field = (val & _PAGE_PFN_MASK) >> _PAGE_PFN_SHIFT; + unsigned long res = (pfn_field - is_napot) & pfn_field; + return res; } #define pte_page(x) pfn_to_page(pte_pfn(x)) @@ -304,6 +308,23 @@ static inline int pte_special(pte_t pte) return pte_val(pte) & _PAGE_SPECIAL; } +static inline unsigned long pte_napot(pte_t pte) +{ + return pte_val(pte) & _PAGE_NAPOT; +} + +static inline pte_t pte_mknapot(pte_t pte, unsigned int order) +{ + unsigned long napot_bits = (1UL << (order - 1)) << _PAGE_PFN_SHIFT; + unsigned long lower_prot = + pte_val(pte) & ((1UL << _PAGE_PFN_SHIFT) - 1UL); + unsigned long upper_prot = (pte_val(pte) >> _PAGE_PFN_SHIFT) + << _PAGE_PFN_SHIFT; + + return __pte(upper_prot | napot_bits | lower_prot | _PAGE_NAPOT); +} + + /* static inline pte_t pte_rdprotect(pte_t pte) */ static inline pte_t pte_wrprotect(pte_t pte) From patchwork Mon Oct 18 01:59:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qinglin Pan X-Patchwork-Id: 12564841 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA24DC433EF for ; Mon, 18 Oct 2021 02:00:28 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 735D861250 for ; Mon, 18 Oct 2021 02:00:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 735D861250 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=k+oyBe4UMkJkJyQSARreDf1Sm9TdOyzSTmx7exI4sxU=; b=uaO2j6ussSCs6O bsGvB79P7GdTDI5KQMXBbiam4QXlE07bevAf7o7QjvwUDI7AGuLwf33u+csRIKvTiVb0QJ0Tz6D3e L5SLn5EvjTyoZdlx+O2ByBzy2MgOURSYXayZoZL8g0pUvGqZWLWdIlQd++jLyhiv1Y2P/J6b0Dx29 4G8+2JyuA1UFqpOjaFKPvgQbhaufQWhj4KEmMrE9g+knrqmzbyi46CkZOHCi3rQ9tKZfIqzk5X1eE Rj9VfAZZ6Y0ogW9Ocv++f3Ho1rdg7JZVk12bM5ka7934OESEBVKG/SNuRBZ2XThnXYRURXfi6/32V aE76adAvSEnzZCKNCX/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcHwo-00DmsS-OE; Mon, 18 Oct 2021 02:00:18 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcHwm-00Dmrz-BP for linux-riscv@lists.infradead.org; Mon, 18 Oct 2021 02:00:17 +0000 Received: by mail-pj1-x102d.google.com with SMTP id ls18-20020a17090b351200b001a00250584aso13364663pjb.4 for ; Sun, 17 Oct 2021 19:00:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ofOP3xFW1JaHcNuB4PTXlIrU5gFqMS9igYxQdAW6Mtc=; b=H9EFj43mTpqloXAc6cvc77NT2mkmL4naRBHAfV6vUd6xmXFO+Xs7cX7XdamCoA36tL YleMH7+vo/ieHJtvc+7O6e5oJPz3iBgu0WYVzNlfFl5WwD2yLm2Tv9fOxb+1y263J5S+ lYAzrimehOhDlH90fcnBhV/cNp1GU1dcELTrS/CY8cxikUTB0IpmEfzuo8y1rO7gFgHX G/i/NADj/d6dL3I2v6ty9f6ulQaMpf6PFqr0ovoCvnv1vcGtO6MinNwX5VYr1LRU+TEK FK/e85SxJy/BmX0jMtF8uMc3B5iJgGD4xScHc7Y6icpzA9vTch0bpOuszq8XXDhS9u/j 9ABw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ofOP3xFW1JaHcNuB4PTXlIrU5gFqMS9igYxQdAW6Mtc=; b=1CIG9dharUIPi/Y1TLLKfTSzAaocDra77zGdw1j8rrVSdQqa9DoFe9hnraOcc7KpNj B0zsonBzWWusoEQznneEdX0q7QvcbhEJmh/h0o6NSYmHibmV1Zr6IJOyf9nlLEHyNE9L ZZEJP5aOwXtnIUqlb6Gp4ojYODxptRlQS02AHjPEVmxPAVYoGP8PVtJWC/u8sUEfSLya q/4d0JOH46BOOegggQtMRpE8z8FEd9rmoDamd1sm2klPeHfdJfGQyJNfsReQ5I19jLuv NhUG3FTe5DksVfzNRalDLwfk0/TpTscU1WRGFJTvf6tGWDnKofJU4rscSdiVcMHNODqW K0Qw== X-Gm-Message-State: AOAM531BkZf5EqojXdszjj75Ckn6/xOtjjCnG5Fr06lnuKT2aokk46V+ TftI2WmhsRSj2POstpQLnOCUXGrfeIZodgdC1P1clg== X-Google-Smtp-Source: ABdhPJz9PwFUV0pD/KeGWqUWUhi7m+oUNhNU5x31yp1jZvKBSDQoPWdarydWL++NTwVa9x3m7zBOLQ== X-Received: by 2002:a17:90b:4d0b:: with SMTP id mw11mr30322284pjb.135.1634522415470; Sun, 17 Oct 2021 19:00:15 -0700 (PDT) Received: from localhost.localdomain ([103.135.248.171]) by smtp.gmail.com with ESMTPSA id v22sm11381975pff.93.2021.10.17.19.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 19:00:15 -0700 (PDT) From: Qinglin Pan X-Google-Original-From: Qinglin Pan To: linux-riscv@lists.infradead.org Cc: xuyinan@ict.ac.cn, Qinglin Pan Subject: [RFC PATCH 2/4] mm: support Svnapot in physical page linear-mapping Date: Mon, 18 Oct 2021 09:59:42 +0800 Message-Id: <20211018015944.1313008-2-panqinglin00@163.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211018015944.1313008-1-panqinglin00@163.com> References: <20211018015944.1313008-1-panqinglin00@163.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211017_190016_419343_F223D042 X-CRM114-Status: GOOD ( 15.63 ) 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: Qinglin Pan Svnapot is powerful when a physical region is going to mapped to a virtual region. Kernel will do like this when mapping all allocable physical pages to kernel vm space. This patch modify the create_pte_mapping function used in linear-mapping procedure, so the kernel can be able to use Svnapot when both address and length of physical region are 64KB align. Code here will be executed only when other size huge page is not suitable, so it can be an addition of PMD_SIZE and PUD_SIZE mapping. It is tested by setting qemu's memory to a 262272k region, and the kernel can boot successfully. Signed-off-by: Qinglin Pan --- arch/riscv/mm/init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index c0cddf0fc22d..60a8e1dca79a 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -314,8 +314,18 @@ static void __init create_pte_mapping(pte_t *ptep, phys_addr_t sz, pgprot_t prot) { uintptr_t pte_idx = pte_index(va); - - BUG_ON(sz != PAGE_SIZE); + pte_t pte; + + WARN_ON(sz != NAPOT_CONT64KB_SIZE && sz != PAGE_SIZE); + if (sz == NAPOT_CONT64KB_SIZE) { + do { + pte = pfn_pte(PFN_DOWN(pa), prot); + ptep[pte_idx] = pte_mknapot(pte, NAPOT_CONT64KB_ORDER); + pte_idx++; + sz -= PAGE_SIZE; + } while (sz > 0); + return; + } if (pte_none(ptep[pte_idx])) ptep[pte_idx] = pfn_pte(PFN_DOWN(pa), prot); @@ -444,10 +454,13 @@ void __init create_pgd_mapping(pgd_t *pgdp, static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size) { /* Upgrade to PMD_SIZE mappings whenever possible */ - if ((base & (PMD_SIZE - 1)) || (size & (PMD_SIZE - 1))) - return PAGE_SIZE; + if (!((base | size) & (PMD_SIZE - 1))) + return PMD_SIZE; + + if (!((base | size) & (NAPOT_CONT64KB_SIZE - 1))) + return NAPOT_CONT64KB_SIZE; - return PMD_SIZE; + return PAGE_SIZE; } #ifdef CONFIG_XIP_KERNEL From patchwork Mon Oct 18 01:59:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qinglin Pan X-Patchwork-Id: 12564845 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5C6DC433F5 for ; Mon, 18 Oct 2021 02:00:30 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7630861250 for ; Mon, 18 Oct 2021 02:00:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7630861250 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NKti+QYDXlVGSlaiF6NZMjkvSeFom9ogS1+GP+nYnYE=; b=YYiSlR6f5aG1rc t90rHF1vRJ8efrYgC7WrnL6qqLtgnXrHI4f6O/GGECbeUtIsFz/sSWjOPIUwg/T59qkmkguMqywew Mar6uVaIAV7/KYYWZ/mixXCRodfX5BXYNQ56qypbsZU8yQzhgq32OBoKgQCWtvczMp3dJ80yGbJbi XjkJ9yzii21mRM9DMmBrkMD14ozWpOW4+AWFdR+IXJc0LivK5q9LYhplkk65u+3heMO0mlbotgYZ6 aiGyQTD7UzztFDLtBgCS4WP8VxjVwaqPjq5KDiXoX52tFUkT+R7wEQujV3vC8Vk98F3h9cDJq6P+6 jHGRiKZKll5b8new4vcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcHwt-00Dmti-Dc; Mon, 18 Oct 2021 02:00:23 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcHwp-00DmsX-CO for linux-riscv@lists.infradead.org; Mon, 18 Oct 2021 02:00:21 +0000 Received: by mail-pj1-x102c.google.com with SMTP id e5-20020a17090a804500b001a116ad95caso5853976pjw.2 for ; Sun, 17 Oct 2021 19:00:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NQEuzugfUK4Ty3ZAToh9e+0eENvZ/yGehWqj8C4n9mM=; b=LVH0F03r6yLTg9mBzvtK2KaFtuBbuhrJa1GyvcPA4TlAYa5kJUfQvZnw7BD8lo9Doa 3pwRVcjot7LNX5ME6kC/TSn5k2ike5rCtjyxCBgxPJLA7E1NYikpiusI5A2x6Q4o77Fp Kc1X43tGItaZpTyGt19eMwpiXL4bUX8C0hu9His6pypUgA2ljyaT5rmc2cjwUdUucorW Bq1sRcXqZa2Es0pHAgLiy+RL8DKj/b8sBR2dP6GOjhfayJLwBrswWEq9InEBsjv/NvGF 4mwhQYBIjov+psJAPM6sMd8jjH69s/KmKhjxdA5fiGBg/tFo2TmGhLtu0ya/+vSlDSDd Y75w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NQEuzugfUK4Ty3ZAToh9e+0eENvZ/yGehWqj8C4n9mM=; b=o7qJAnSt+qN1Hm9iLH/pEPzyU6Hn2MyW+F2gllKJ0v6v2siZ2CSB3YJPhZa1fCK2ol yP0LhKYSK9DmfQGkF+8MdhzfDE3ZdwKNU8eN5tEZq8kNaAEXnI3DiGaCtu+0ILrb97Oi Zpcd2xHKK+VFYys6Q328h7Q0Hbf6TdJzumdOtUCnho/UVC0/BSLrXRepSK9DNyPqS2vt SvLRSGz9MzSg/qhKDGnFFDzYMrCvaL0k5LR6exxoDKhjlYH9sk8KChPmEHw1EB9ylgGW BQQqFs+dCs3rylmemAYX/3q2t7V7hHBiS73JfN7u42an1vxeKWaElpkpsR38+GYF+0wk 9JPA== X-Gm-Message-State: AOAM532XZkqJZ5Fuw2bsOCXkq5vF4PJr/bLQCknmdB5Hy4Y9I0z+uiGS 9gE3axbvgi+823HVN/24dDoj1SikLrYD3b3fqF8amw== X-Google-Smtp-Source: ABdhPJwBxh3prkqxaCYEWIGfCsQu0eK4cWbvk3KRGy/ai6+Ly7TIK/eJp+RHYuk44FYhtGHo12ckYw== X-Received: by 2002:a17:90b:3687:: with SMTP id mj7mr44996122pjb.196.1634522418151; Sun, 17 Oct 2021 19:00:18 -0700 (PDT) Received: from localhost.localdomain ([103.135.248.171]) by smtp.gmail.com with ESMTPSA id v22sm11381975pff.93.2021.10.17.19.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 19:00:17 -0700 (PDT) From: Qinglin Pan X-Google-Original-From: Qinglin Pan To: linux-riscv@lists.infradead.org Cc: xuyinan@ict.ac.cn, Qinglin Pan Subject: [RFC PATCH 3/4] mm: support Svnapot in hugetlb page Date: Mon, 18 Oct 2021 09:59:43 +0800 Message-Id: <20211018015944.1313008-3-panqinglin00@163.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211018015944.1313008-1-panqinglin00@163.com> References: <20211018015944.1313008-1-panqinglin00@163.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211017_190019_463924_2100E479 X-CRM114-Status: GOOD ( 19.96 ) 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: Qinglin Pan Svnapot can be used to support 64KB hugetlb page, so it can become a new option when using hugetlbfs. This patch adds a basic implementation of hugetlb page, and support 64KB as a size in it by using Svnapot. For test, boot kernel with command line contains "hugepagesz=64K hugepages=20" and run a simple test like this: int main() { void *addr; addr = mmap(NULL, 64 * 1024, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_HUGE_64KB, -1, 0); printf("back from mmap \n"); long *ptr = (long *)addr; unsigned int i = 0; for(; i < 8 * 1024;i += 512) { printf("%lp \n", ptr); *ptr = 0xdeafabcd12345678; ptr += 512; } ptr = (long *)addr; i = 0; for(; i < 8 * 1024;i += 512) { if (*ptr != 0xdeafabcd12345678) { printf("failed! 0x%lx \n", *ptr); break; } ptr += 512; } if(i == 8 * 1024) printf("simple test passed!\n"); } And it should be passed. Signed-off-by: Qinglin Pan --- arch/riscv/Kconfig | 2 +- arch/riscv/include/asm/hugetlb.h | 29 +++- arch/riscv/include/asm/page.h | 2 +- arch/riscv/mm/hugetlbpage.c | 227 +++++++++++++++++++++++++++++++ 4 files changed, 257 insertions(+), 3 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 301a54233c7e..0ae025686faf 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -176,7 +176,7 @@ config ARCH_SELECT_MEMORY_MODEL def_bool ARCH_SPARSEMEM_ENABLE config ARCH_WANT_GENERAL_HUGETLB - def_bool y + def_bool !HUGETLB_PAGE config ARCH_SUPPORTS_UPROBES def_bool y diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h index a5c2ca1d1cd8..fa99fb9226f7 100644 --- a/arch/riscv/include/asm/hugetlb.h +++ b/arch/riscv/include/asm/hugetlb.h @@ -2,7 +2,34 @@ #ifndef _ASM_RISCV_HUGETLB_H #define _ASM_RISCV_HUGETLB_H -#include #include +extern pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, + vm_flags_t flags); +#define arch_make_huge_pte arch_make_huge_pte +#define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT +extern void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte); +#define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR +extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, + unsigned long addr, pte_t *ptep); +#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH +extern void huge_ptep_clear_flush(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep); +#define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS +extern int huge_ptep_set_access_flags(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t pte, int dirty); +#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT +extern void huge_ptep_set_wrprotect(struct mm_struct *mm, + unsigned long addr, pte_t *ptep); +#define __HAVE_ARCH_HUGE_PTE_CLEAR +extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, unsigned long sz); +#define set_huge_swap_pte_at riscv_set_huge_swap_pte_at +extern void riscv_set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned long sz); + +#include + #endif /* _ASM_RISCV_HUGETLB_H */ diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 109c97e991a6..e67506dbcd53 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -17,7 +17,7 @@ #define PAGE_MASK (~(PAGE_SIZE - 1)) #ifdef CONFIG_64BIT -#define HUGE_MAX_HSTATE 2 +#define HUGE_MAX_HSTATE 3 #else #define HUGE_MAX_HSTATE 1 #endif diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c index 932dadfdca54..b88a8dbfec3e 100644 --- a/arch/riscv/mm/hugetlbpage.c +++ b/arch/riscv/mm/hugetlbpage.c @@ -2,6 +2,224 @@ #include #include +pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, + unsigned long addr, unsigned long sz) +{ + pgd_t *pgdp = pgd_offset(mm, addr); + p4d_t *p4dp = p4d_alloc(mm, pgdp, addr); + pud_t *pudp = pud_alloc(mm, p4dp, addr); + pmd_t *pmdp = pmd_alloc(mm, pudp, addr); + + if (sz == NAPOT_CONT64KB_SIZE) { + if (!pmdp) + return NULL; + WARN_ON(addr & (sz - 1)); + return pte_alloc_map(mm, pmdp, addr); + } + + return NULL; +} + +pte_t *huge_pte_offset(struct mm_struct *mm, + unsigned long addr, unsigned long sz) +{ + pgd_t *pgdp; + p4d_t *p4dp; + pud_t *pudp; + pmd_t *pmdp; + pte_t *ptep = NULL; + + pgdp = pgd_offset(mm, addr); + if (!pgd_present(READ_ONCE(*pgdp))) + return NULL; + + p4dp = p4d_offset(pgdp, addr); + if (!p4d_present(READ_ONCE(*p4dp))) + return NULL; + + pudp = pud_offset(p4dp, addr); + if (!pud_present(READ_ONCE(*pudp))) + return NULL; + + pmdp = pmd_offset(pudp, addr); + if (!pmd_present(READ_ONCE(*pmdp))) + return NULL; + + if (sz == NAPOT_CONT64KB_SIZE) + ptep = pte_offset_kernel(pmdp, (addr & ~NAPOT_CONT64KB_MASK)); + + return ptep; +} + +int napot_pte_num(pte_t pte) +{ + if (!(pte_val(pte) & NAPOT_64KB_MASK)) + return NAPOT_64KB_PTE_NUM; + + pr_warn("%s: unrecognized napot pte size 0x%lx\n", + __func__, pte_val(pte)); + return 1; +} + +static pte_t get_clear_flush(struct mm_struct *mm, + unsigned long addr, + pte_t *ptep, + unsigned long pte_num) +{ + pte_t orig_pte = huge_ptep_get(ptep); + bool valid = pte_val(orig_pte); + unsigned long i, saddr = addr; + + for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) { + pte_t pte = ptep_get_and_clear(mm, addr, ptep); + + if (pte_dirty(pte)) + orig_pte = pte_mkdirty(orig_pte); + + if (pte_young(pte)) + orig_pte = pte_mkyoung(orig_pte); + } + + if (valid) { + struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0); + + flush_tlb_range(&vma, saddr, addr); + } + return orig_pte; +} + +static void clear_flush(struct mm_struct *mm, + unsigned long addr, + pte_t *ptep, + unsigned long pte_num) +{ + struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0); + unsigned long i, saddr = addr; + + for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) + pte_clear(mm, addr, ptep); + + flush_tlb_range(&vma, saddr, addr); +} + +pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, + vm_flags_t flags) +{ + if (shift == NAPOT_CONT64KB_SHIFT) + entry = pte_mknapot(entry, NAPOT_CONT64KB_SHIFT - PAGE_SHIFT); + + return entry; +} + +void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte) +{ + int i; + int pte_num; + + if (!pte_napot(pte)) { + set_pte_at(mm, addr, ptep, pte); + return; + } + + pte_num = napot_pte_num(pte); + for (i = 0; i < pte_num; i++, ptep++, addr += PAGE_SIZE) + set_pte_at(mm, addr, ptep, pte); +} + +int huge_ptep_set_access_flags(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t pte, int dirty) +{ + pte_t orig_pte; + int i; + int pte_num; + + if (!pte_napot(pte)) + return ptep_set_access_flags(vma, addr, ptep, pte, dirty); + + pte_num = napot_pte_num(pte); + ptep = huge_pte_offset(vma->vm_mm, addr, NAPOT_CONT64KB_SIZE); + orig_pte = huge_ptep_get(ptep); + + if (pte_dirty(orig_pte)) + pte = pte_mkdirty(pte); + + if (pte_young(orig_pte)) + pte = pte_mkyoung(pte); + + for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) + ptep_set_access_flags(vma, addr, ptep, pte, dirty); + + return true; +} + +pte_t huge_ptep_get_and_clear(struct mm_struct *mm, + unsigned long addr, pte_t *ptep) +{ + int pte_num; + pte_t orig_pte = huge_ptep_get(ptep); + + if (!pte_napot(orig_pte)) + return ptep_get_and_clear(mm, addr, ptep); + + pte_num = napot_pte_num(orig_pte); + return get_clear_flush(mm, addr, ptep, pte_num); +} + +void huge_ptep_set_wrprotect(struct mm_struct *mm, + unsigned long addr, pte_t *ptep) +{ + int i; + int pte_num; + pte_t pte = READ_ONCE(*ptep); + + if (!pte_napot(pte)) + return ptep_set_wrprotect(mm, addr, ptep); + + pte_num = napot_pte_num(pte); + ptep = huge_pte_offset(mm, addr, NAPOT_CONT64KB_SIZE); + + for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) + ptep_set_wrprotect(mm, addr, ptep); +} + +void huge_ptep_clear_flush(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep) +{ + int pte_num; + pte_t pte = READ_ONCE(*ptep); + + if (!pte_napot(pte)) { + ptep_clear_flush(vma, addr, ptep); + return; + } + + pte_num = napot_pte_num(pte); + clear_flush(vma->vm_mm, addr, ptep, pte_num); +} + +void huge_pte_clear(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, unsigned long sz) +{ + int i, pte_num; + + pte_num = napot_pte_num(READ_ONCE(*ptep)); + for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) + pte_clear(mm, addr, ptep); +} + +void riscv_set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned long sz) +{ + int i, pte_num; + + pte_num = napot_pte_num(READ_ONCE(*ptep)); + + for (i = 0; i < pte_num; i++, ptep++) + set_pte(ptep, pte); +} + int pud_huge(pud_t pud) { return pud_leaf(pud); @@ -18,6 +236,8 @@ bool __init arch_hugetlb_valid_size(unsigned long size) return true; else if (IS_ENABLED(CONFIG_64BIT) && size == PUD_SIZE) return true; + else if (size == NAPOT_CONT64KB_SIZE) + return true; else return false; } @@ -32,3 +252,10 @@ static __init int gigantic_pages_init(void) } arch_initcall(gigantic_pages_init); #endif + +static int __init hugetlbpage_init(void) +{ + hugetlb_add_hstate(NAPOT_CONT64KB_SHIFT - PAGE_SHIFT); + return 0; +} +arch_initcall(hugetlbpage_init); From patchwork Mon Oct 18 01:59:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qinglin Pan X-Patchwork-Id: 12564847 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5209BC433EF for ; Mon, 18 Oct 2021 02:00:32 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0B2C361250 for ; Mon, 18 Oct 2021 02:00:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0B2C361250 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IVst4+sa0Z1+gXTn9G0c1jNOBy0A6kVhZOPuDuoEEtQ=; b=Adr/t2L9JhgTsF w+3NwFlTyXnE6TKkLutI2hNlh5eFSOALDB2moeIq63wZZv5Bs2JJDwSCOKGpDc3Uf5tYYRoXQQfz3 7iGO+7SpNPqhvJVvuEEXv8SIW5T4pDNxkWcKOsUxgOplppbyL39XOQtbEah6046G34BDrUer0tpQp BxQ/wZN1TjZpefVA+MEsjynVqKo6sWPcewST/v49DOnwsno17AArPad4M6L2mfxeJ0m4erMZcPAbz AI30h1Z1ob24x+RfOyn5ftuLh73M5TFZcacHWtVFuVWgr9No59FvUC1BC8teWNnLzVwsUyPLQsM35 O82/6Hd/GIfv1JpF5FCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcHwv-00DmuF-38; Mon, 18 Oct 2021 02:00:25 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcHwr-00DmtJ-Rm for linux-riscv@lists.infradead.org; Mon, 18 Oct 2021 02:00:23 +0000 Received: by mail-pl1-x630.google.com with SMTP id g5so10169862plg.1 for ; Sun, 17 Oct 2021 19:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4bw/oHpLpCvL7ZLvo5Y2CIUzRMBpMTubDt9OnDYu2BI=; b=eRHI8Ja9om3HAAis0T1hCnuwIiZc3VeYxdxgW6FeOvwk5gqPup6PG51jaUX8xKbne0 xf/30qwu4vA5fHS1R3cMTtKh6yWuDAfup3B5OWN08jt0g7wXLglqiyJQeWmJ/jTRcH+f 8qhyG2JC6/zZQ/c5gKgaeX6v1OIlyyXFn/eIqm7YkuneYg3zBKAIofvxj1aM5ZToRDik LKP74jL5+s7h9+BfECadxBtchPvGFxnrggC5ujJgetPSoXUSapl9kFnZdvSWBCkilzQJ vFeaOBluB0EtM0u5nQNgxVuhweDnXlriYGGuKH+gBkGj4vHDiU3A/C+7GnAkhHMk5FXZ rT6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4bw/oHpLpCvL7ZLvo5Y2CIUzRMBpMTubDt9OnDYu2BI=; b=r7QogSuDtJn4zGgtJ2Tn6U2Snzo5Fseb5NZ38RV+FokzR88048Wqsk3dds6i88Jlfi hyrQYxRNh5HlevA5bp0U1zeI2TgBzL3qYViBOvnukwoQDoDrwZlUs7/8TfTtETwTmzRh JHkvI/atTjunfQO0qdtRfoWoY52wX6mp2l4ttLfMSiJxck3L1Y3m6wmJchKNG7RekTLi CV8rmtC+Q5W2yosHKMx1i62vlzc8QGdMi8/rwl9pt5ZQzkvzWVm7C0lc7lMYUqDY5FoK S9smO1wU302QKVi2Jfttq27CpDW/73IyAJku5B4gChA1ICZxwti5FerkAiZG8OeRKC03 M4/A== X-Gm-Message-State: AOAM53189qxTE59lVuoVETbIxolQvQw75+Se3lC9Ul4St/JOYx5WKYL0 qJr4NDcf2vHkJNA68snzvVqch3XT2DPuM93pBiasdA== X-Google-Smtp-Source: ABdhPJxd/5jn3103Z+Cf6vw4TOj1R8Om7LDI5b/e53K6/UIhgLmXb7QPhjqMExYI23V0S2+F1MprsA== X-Received: by 2002:a17:90a:f292:: with SMTP id fs18mr29276517pjb.229.1634522420830; Sun, 17 Oct 2021 19:00:20 -0700 (PDT) Received: from localhost.localdomain ([103.135.248.171]) by smtp.gmail.com with ESMTPSA id v22sm11381975pff.93.2021.10.17.19.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 19:00:20 -0700 (PDT) From: Qinglin Pan X-Google-Original-From: Qinglin Pan To: linux-riscv@lists.infradead.org Cc: xuyinan@ict.ac.cn, Qinglin Pan Subject: [RFC PATCH 4/4] mm: support Svnapot in huge vmap Date: Mon, 18 Oct 2021 09:59:44 +0800 Message-Id: <20211018015944.1313008-4-panqinglin00@163.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211018015944.1313008-1-panqinglin00@163.com> References: <20211018015944.1313008-1-panqinglin00@163.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211017_190021_924130_B12A5E91 X-CRM114-Status: GOOD ( 12.98 ) 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: Qinglin Pan The HAVE_ARCH_HUGE_VMAP option can be used to help implement arch special huge vmap size. This patch selects this option by default and re-writes the arch_vmap_pte_range_map_size for Svnapot 64KB size. It can be tested when booting kernel in qemu with pci device, which will make the kernel to call pci driver using ioremap, and the re-written function will be called. Signed-off-by: Qinglin Pan --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/pgtable.h | 35 ++++++++++++++++++++++++++++++++ arch/riscv/include/asm/vmalloc.h | 18 ++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 0ae025686faf..4a57fd56daf8 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -13,6 +13,7 @@ config 32BIT config RISCV def_bool y select ARCH_CLOCKSOURCE_INIT + select HAVE_ARCH_HUGE_VMAP select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION select ARCH_HAS_BINFMT_FLAT select ARCH_HAS_DEBUG_VM_PGTABLE diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index adacb877433d..218d95d30bfa 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -642,6 +642,41 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ +static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot) +{ + return 0; +} + +static inline int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot) +{ + return 0; +} + +static inline int pud_clear_huge(pud_t *pud) +{ + return 0; +} + +static inline int pmd_clear_huge(pmd_t *pmd) +{ + return 0; +} + +static inline int p4d_free_pud_page(p4d_t *p4d, unsigned long addr) +{ + return 0; +} + +static inline int pud_free_pmd_page(pud_t *pud, unsigned long addr) +{ + return 0; +} + +static inline int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) +{ + return 0; +} + /* * Encode and decode a swap entry * diff --git a/arch/riscv/include/asm/vmalloc.h b/arch/riscv/include/asm/vmalloc.h index ff9abc00d139..fecfa24d6a13 100644 --- a/arch/riscv/include/asm/vmalloc.h +++ b/arch/riscv/include/asm/vmalloc.h @@ -1,4 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef _ASM_RISCV_VMALLOC_H #define _ASM_RISCV_VMALLOC_H +#include + +#define arch_vmap_pte_range_map_size arch_vmap_pte_range_map_size +static inline unsigned long arch_vmap_pte_range_map_size(unsigned long addr, unsigned long end, + u64 pfn, unsigned int max_page_shift) +{ + bool is_napot_addr = !(addr & NAPOT_CONT64KB_MASK); + bool pfn_align_napot = !(pfn & (NAPOT_64KB_PTE_NUM - 1UL)); + bool space_enough = ((end - addr) >= NAPOT_CONT64KB_SIZE); + + if (is_napot_addr && pfn_align_napot && space_enough + && max_page_shift >= NAPOT_CONT64KB_SHIFT) + return NAPOT_CONT64KB_SIZE; + + return PAGE_SIZE; +} + #endif /* _ASM_RISCV_VMALLOC_H */