Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp336444pxu; Tue, 5 Jan 2021 12:19:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjhYbJZ9pTniPLLLevFXB/oxOY1fMy+IDYAYtl9Cz7QK8LNez5V4KRgoOA8doZtGreHbPw X-Received: by 2002:a17:907:111c:: with SMTP id qu28mr706754ejb.540.1609877982466; Tue, 05 Jan 2021 12:19:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609877982; cv=none; d=google.com; s=arc-20160816; b=Rqx5OvfN6WR7KQJN/NFMoxYsAddfrIe3heZQSXhR2c3Jfp9LRHABvZyMRe6ZnrH2Qd 7OkTjDiCFg8COxPHA8fhHBzZqXQaqUFYvcv1bQViO5LS0Lo0WQiwOF7gnEhgRMZoReWH 9HzEPdNoCmsSHPVGKkQRK0ijpyvMzNUDTnLYiNom0uYKR94vfJFaeJwZj+MPDT/mXkl0 /vpS7QMN3jl+rTbnkYIQozcQ+MU3+7J5iP3SRoHuLV0Le/lx74/fjX8pRV5k9eJcV+A8 rD0Uu5WQkemNK2DC64p2cRhed5VONeXsReHo34WWtnwuZCPU1K5IsTCkPnO1QRcdrNF5 gSXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AGKjJEiSSy2izG4ujkGcD0moiRRni/L2Q0MG/wluNhc=; b=l1wPiFkBd3p3TbjI+J2ifsJWYuEV+pYpXFGRpMXo0aMaW61BeG/uQ7+kXAcNNuECDU y5LXBe+/22YDMzGtzx6jnncyFHa9CYkw+Z5D7Vgu/3B89jrhyzRwBdwPccjnwHMOyuP/ EZCCkkmQ9iAPGxaok/Ak7gLuPs1kukA0m/yJ75aL1FpMdTeICks9UlcmLPppTKtIDwmO Elw0z4IHAr9BUtu1y2KrcoAF80VPHUXebs+wh3zgU3i/h6GRLgBJg06GrvmE3sC+ERTQ vgFOUDlqxpujdAD2rbNQ+nIWc2u5ztsZo34QpUyY7rDiarDBQaSmT6sykHoWjDP57BZU e6KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=mtV8E91w; 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 f14si115459ejb.79.2021.01.05.12.19.19; Tue, 05 Jan 2021 12:19:42 -0800 (PST) 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; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=mtV8E91w; 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 S1726109AbhAEMHb (ORCPT + 99 others); Tue, 5 Jan 2021 07:07:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbhAEMH2 (ORCPT ); Tue, 5 Jan 2021 07:07:28 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDC21C061574 for ; Tue, 5 Jan 2021 04:06:47 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id r7so35911314wrc.5 for ; Tue, 05 Jan 2021 04:06:47 -0800 (PST) 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=AGKjJEiSSy2izG4ujkGcD0moiRRni/L2Q0MG/wluNhc=; b=mtV8E91wND1aKNfDji9QLYJPBQMWC8mHS1I4adE/gfWGyS6lubB7mDXao3j2RV8Gmu uvYlNcWrA9nXdzJsCVF3yIA5OIQ7xTm3zkjLJEsotudU5JnoWOVITaPrlrGq82UcKjTk SfuYEppZJ5ULuLdMAJN9HJZydDXSWYqNIVljiT911GOBsYlN6+r3kLua9KF6YQQ5TNd5 EiqCuJ7lj7GlkpGGr+YxlDZgMgYBCDn3+kQmmPMEA1COtJGyh3o4GoSX50Cpk3fWNeIN vUK5NHkPWGI6ZLGwtDcGIvRktep2OxxEdLXK+aAgJeaBrAtZdI9msB7it8mYfk2uz9vE bsdA== 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=AGKjJEiSSy2izG4ujkGcD0moiRRni/L2Q0MG/wluNhc=; b=VXMIrg9nYrMS8QR/QVSmrxKLkED465y7sFViLjtMgJ5Gt91BXctL0o9mIKMDfCHDDP oiy8lQQLkU3h6iecybIWjdhih+uEDNubLjoTdkdqyH6spcrEbGwSf6X/r+8jk0KOA+40 hWcbz/+0mCUJmTGoHNz1YpaZ1Id0XBdTDzthkME5O4zTs7MO73I3DzcqIFH9Cfp8f7W3 bytPC7SrPTrsmSgX3FBiKHILVP3x//E+Hf16IuxZQNhM9qM7tW5ITL/O3taRy+c4NHh+ H0ISFUqpoz/DtAF4sG1q5BNcxq0ZjVuo8Xy7EuVTyhDcQOeuj31AoNAb1QgoJtl2YTur Y/SQ== X-Gm-Message-State: AOAM532TGvPyUH1lYCD86Ts1/bs+8ZB1sczlLYYd2s60h9GDkA7CfYo/ VxVMPTwsTjuFCHyhHXythv0C+R0hHN8Hkv0fFN0U+w== X-Received: by 2002:adf:c18d:: with SMTP id x13mr83182459wre.128.1609848406611; Tue, 05 Jan 2021 04:06:46 -0800 (PST) MIME-Version: 1.0 References: <20210104195840.1593-1-alex@ghiti.fr> <20210104195840.1593-5-alex@ghiti.fr> In-Reply-To: <20210104195840.1593-5-alex@ghiti.fr> From: Anup Patel Date: Tue, 5 Jan 2021 17:36:35 +0530 Message-ID: Subject: Re: [RFC PATCH 04/12] riscv: Allow to dynamically define VA_BITS To: Alexandre Ghiti Cc: Paul Walmsley , Palmer Dabbelt , Zong Li , Christoph Hellwig , Ard Biesheuvel , Arnd Bergmann , linux-efi , linux-arch@vger.kernel.org, linux-riscv , "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 5, 2021 at 1:33 AM Alexandre Ghiti wrote: > > With 4-level page table folding at runtime, we don't know at compile time > the size of the virtual address space so we must set VA_BITS dynamically > so that sparsemem reserves the right amount of memory for struct pages. > > Signed-off-by: Alexandre Ghiti > --- > arch/riscv/Kconfig | 10 ---------- > arch/riscv/include/asm/pgtable.h | 11 +++++++++-- > arch/riscv/include/asm/sparsemem.h | 6 +++++- > 3 files changed, 14 insertions(+), 13 deletions(-) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index 44377fd7860e..2979a44103be 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -122,16 +122,6 @@ config ZONE_DMA32 > bool > default y if 64BIT > > -config VA_BITS > - int > - default 32 if 32BIT > - default 39 if 64BIT > - > -config PA_BITS > - int > - default 34 if 32BIT > - default 56 if 64BIT > - > config PAGE_OFFSET > hex > default 0xC0000000 if 32BIT && MAXPHYSMEM_2GB > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > index 102b728ca146..c7973bfd65bc 100644 > --- a/arch/riscv/include/asm/pgtable.h > +++ b/arch/riscv/include/asm/pgtable.h > @@ -43,8 +43,14 @@ > * struct pages to map half the virtual address space. Then > * position vmemmap directly below the VMALLOC region. > */ > +#ifdef CONFIG_64BIT > +#define VA_BITS 39 > +#else > +#define VA_BITS 32 > +#endif > + > #define VMEMMAP_SHIFT \ > - (CONFIG_VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT) > + (VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT) > #define VMEMMAP_SIZE BIT(VMEMMAP_SHIFT) > #define VMEMMAP_END (VMALLOC_START - 1) > #define VMEMMAP_START (VMALLOC_START - VMEMMAP_SIZE) > @@ -83,6 +89,7 @@ > #endif /* CONFIG_64BIT */ > > #ifdef CONFIG_MMU > + > /* Number of entries in the page global directory */ > #define PTRS_PER_PGD (PAGE_SIZE / sizeof(pgd_t)) > /* Number of entries in the page table */ > @@ -453,7 +460,7 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma, > * and give the kernel the other (upper) half. > */ > #ifdef CONFIG_64BIT > -#define KERN_VIRT_START (-(BIT(CONFIG_VA_BITS)) + TASK_SIZE) > +#define KERN_VIRT_START (-(BIT(VA_BITS)) + TASK_SIZE) > #else > #define KERN_VIRT_START FIXADDR_START > #endif > diff --git a/arch/riscv/include/asm/sparsemem.h b/arch/riscv/include/asm/sparsemem.h > index 45a7018a8118..63acaecc3374 100644 > --- a/arch/riscv/include/asm/sparsemem.h > +++ b/arch/riscv/include/asm/sparsemem.h > @@ -4,7 +4,11 @@ > #define _ASM_RISCV_SPARSEMEM_H > > #ifdef CONFIG_SPARSEMEM > -#define MAX_PHYSMEM_BITS CONFIG_PA_BITS > +#ifdef CONFIG_64BIT > +#define MAX_PHYSMEM_BITS 56 > +#else > +#define MAX_PHYSMEM_BITS 34 > +#endif /* CONFIG_64BIT */ > #define SECTION_SIZE_BITS 27 > #endif /* CONFIG_SPARSEMEM */ > > -- > 2.20.1 > Looks good to me. Reviewed-by: Anup Patel Regards, Anup