Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp211293yba; Wed, 17 Apr 2019 23:14:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRj8NC+wphuTyDJY4Y5O8i3YnAKbvYVhk0BBp6pThToU4t0O5+cpaCZGzYlQXmikYQ7KC1 X-Received: by 2002:a63:4e5b:: with SMTP id o27mr87543994pgl.204.1555568089626; Wed, 17 Apr 2019 23:14:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555568089; cv=none; d=google.com; s=arc-20160816; b=eSLYwJwF4jyBSRd1tM5BygzZtK4LGlqIK/Kp4eqtfpVVGJqbhsDbjfHrOdKuvzt5cH IGaOqw5QP5BhQAKAQPsxuEYnlPKxOUvAy1l1cqtkZ1CjvuGYxj2x/JIYK4/ErndFOziz TIz6oZRCQOB1ssJtLiI49d8Vb/mKY8LycThKlw/ae/xbvaX4fYKKv3NNcPRVlPzFhcHQ XG+XSeLrD5JC+uBwmRf1KJIKg82g6vCrzpT0WdBi7197/HrXGqv9qS7kz5SEFFmsMYgT BfTYzdADRugyBzlyhdPwjxTRq5j3Vg2PgWUhSjq2UDFcHiePKzFrpef3BK1X0eGouhg+ r8NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=f5gAVwPf4LXwi3q6cSJA3lDZFQJ3pBlHI2tkW6FRt4k=; b=Ik9Ys74hJb7azYvvPHpLqwAgXNuOdhcJoreOO/ZYWNQ4f1wh58C7V7c4TmlVo27PgW G8yAOZB7QaQQdwxntWRAoL11GO5ZZN85t9MRsgWkTCxYOVKX2Zr29bpik4lImXbGh+E5 9bVa9lyeTZV3s0y4wmN/HiEHq9A+UxbJkxipSYOCkP+ys+byvI8aIWJnRMYE/Fuk94EN Hcn00iLY/26RgkVA0xXXB2gl6VD089uqeX009pZrnzK7lc0A2IODlzyoaHtkQuqpw53I ugnZR6YwAxHB3G8Pfold3zSCNADTJrJxAtiDVcf0gfQxPYAqlvmbCBe2HEGlAEagYs19 GSsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=y691J5tm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s14si1052589pgs.343.2019.04.17.23.14.34; Wed, 17 Apr 2019 23:14:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=y691J5tm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387920AbfDRGNl (ORCPT + 99 others); Thu, 18 Apr 2019 02:13:41 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39945 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbfDRGNk (ORCPT ); Thu, 18 Apr 2019 02:13:40 -0400 Received: by mail-wm1-f66.google.com with SMTP id z24so1367247wmi.5 for ; Wed, 17 Apr 2019 23:13:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=f5gAVwPf4LXwi3q6cSJA3lDZFQJ3pBlHI2tkW6FRt4k=; b=y691J5tmvg28X5D2wpDYc0Ew89GB+xnBAqxtwmHhLhh0QF4SDBBcPOHGJdpMqPDB6j dxQxQs2gf6/ZRObZK3+qKtPTxOWPbvfWaJQ8SOLuFNHfI8NtrZ2RPZqU7fSf+/fMdfxM 51IhXflHFE8fJDzFFZYTJ29sqBunJSG+Xj4Hd4dENht2fHXgvG0NkGPL6Pa1QLy73S2p BkYOTIbkKyfLnhshuVXnz0ea8nb5A+aY0MGGykEFauQW7Cw51yPJELe0VjZM8mV+SyiO 1GchVq70CVrUjGKg/TqMu5FYNt7lz0Hle1i8u9S6QQOQFHv/qAopYjS4ybSYhFyAXf/u eGxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=f5gAVwPf4LXwi3q6cSJA3lDZFQJ3pBlHI2tkW6FRt4k=; b=txqveRJ5Ais3MZBDevfgFvhoICCGeCcIYAX6Bl4OQxBeJESMw0+NtAvfukAORSxv/H YLYNlI26clH+v+16dcOo/q9qJvfNPncf/HlAwr5AB9CMFg0MMP2BAwcof2d0hV7ovSAS l+YYFobPhEJWVYRxQajx0684n0IIL0ehHWBz8o9SdiEzWmmz5MRBndiQ84HVjz3fBplw GJcPZYqTtQrEWCnjEQyMSswewXRhpuYNUyZ6HUR5KU0FKqBm/Q4AiSfrSfuz9AyZoxdx NzSGEk1P7Tc+ClAU1hlSqdF1uRQpg4WpWir1BwzcN3yHR9mTYIkTXHS0u2NTCQyO7boO uDEg== X-Gm-Message-State: APjAAAUwHl1De/SMeAnOjwG4ZlB9ir1qTRy01Fdq+VRf0bbLSXej7QAg QmZBXmR8NCKJhWHcnMfT5bo8Qr9388qNlC0qgH+dQg== X-Received: by 2002:a7b:cf18:: with SMTP id l24mr1550265wmg.132.1555568018924; Wed, 17 Apr 2019 23:13:38 -0700 (PDT) MIME-Version: 1.0 References: <1555548975-7011-1-git-send-email-liush.damon@gmail.com> In-Reply-To: <1555548975-7011-1-git-send-email-liush.damon@gmail.com> From: Anup Patel Date: Thu, 18 Apr 2019 11:43:27 +0530 Message-ID: Subject: Re: [PATCH] RISC-V: redefine PTRS_PER_PGD/PTRS_PER_PMD/PTRS_PER_PTE To: damon Cc: Palmer Dabbelt , Albert Ou , Anup Patel , Mike Rapoport , sorear2@gmail.com, linux-riscv@lists.infradead.org, "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 18, 2019 at 6:26 AM damon wrote: > > Use the number of addresses to define the relevant macros. > > Signed-off-by: damon > --- > arch/riscv/include/asm/pgtable-32.h | 2 ++ > arch/riscv/include/asm/pgtable-64.h | 3 ++- > arch/riscv/include/asm/pgtable.h | 4 ++-- > 3 files changed, 6 insertions(+), 3 deletions(-) > > diff --git a/arch/riscv/include/asm/pgtable-32.h b/arch/riscv/include/asm/pgtable-32.h > index d61974b7..93607f6 100644 > --- a/arch/riscv/include/asm/pgtable-32.h > +++ b/arch/riscv/include/asm/pgtable-32.h > @@ -17,8 +17,10 @@ > #include > #include > > +#define MAX_USER_VA_BITS 32 > /* Size of region mapped by a page global directory */ > #define PGDIR_SHIFT 22 > +#define PMD_SHIFT PGDIR_SHIFT We don't have PMD in RV32. We have only two level page table for RV32 so defining PMD_SHIFT is misleading and in-correct. I suggest you drop PMD_SHIFT here instead look at below suggestion for defining PTRS_PER_PTE in asm/pgtable.h > #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT) > #define PGDIR_MASK (~(PGDIR_SIZE - 1)) > > diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h > index 7aa0ea9..a56d4d0 100644 > --- a/arch/riscv/include/asm/pgtable-64.h > +++ b/arch/riscv/include/asm/pgtable-64.h > @@ -16,6 +16,7 @@ > > #include > > +#define MAX_USER_VA_BITS 39 > #define PGDIR_SHIFT 30 > /* Size of region mapped by a page global directory */ > #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT) > @@ -34,7 +35,7 @@ > #define pmd_val(x) ((x).pmd) > #define __pmd(x) ((pmd_t) { (x) }) > > -#define PTRS_PER_PMD (PAGE_SIZE / sizeof(pmd_t)) > +#define PTRS_PER_PMD (1 << (PGDIR_SHIFT - PMD_SHIFT)) > > static inline int pud_present(pud_t pud) > { > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > index 1141364..d9cb3c8 100644 > --- a/arch/riscv/include/asm/pgtable.h > +++ b/arch/riscv/include/asm/pgtable.h > @@ -33,9 +33,9 @@ > #endif /* CONFIG_64BIT */ > > /* Number of entries in the page global directory */ > -#define PTRS_PER_PGD (PAGE_SIZE / sizeof(pgd_t)) > +#define PTRS_PER_PGD (1 << (MAX_USER_VA_BITS - PGDIR_SHIFT)) > /* Number of entries in the page table */ > -#define PTRS_PER_PTE (PAGE_SIZE / sizeof(pte_t)) > +#define PTRS_PER_PTE (1 << (PMD_SHIFT - PAGE_SHIFT)) Instead of defining PTRS_PER_PTD using PMD_SHIFT for both RV32 and RV64, do the following: #ifdef __PAGETABLE_PMD_FOLDED #define PTRS_PER_PTE (1 << (PGDIR_SHIFT - PAGE_SHIFT)) #else #define PTRS_PER_PTE (1 << (PMD_SHIFT - PAGE_SHIFT)) #endif > > /* Number of PGD entries that a user-mode program can use */ > #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) > -- > 1.9.1 > Regards, Anup