Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp752520pxb; Wed, 29 Sep 2021 09:00:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE3v3Pk3gOsU6oiyx9s0gTlnhHU1Eyc3ucDRJ0ELkCmph1Dv1I6xXiSfGFrci7Ja+xgjAm X-Received: by 2002:a63:3d4a:: with SMTP id k71mr633678pga.276.1632931217815; Wed, 29 Sep 2021 09:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632931217; cv=none; d=google.com; s=arc-20160816; b=HkM92hse0au/xIwGH534XES3/TZfHbhBlN9H3DZ/4/JLiY/u8aaAlgZaw44aUlwXeg jiEmtxLUSMED4JdC73tpFaa2+diSAURZ4MgY+0TemIiMb7zTjVZCTinHMI6qwEcGj9RN 96oAimpMd3TFCIvyrABERLT9NGXaxv2sdOtM2/QZ3S1RlkVRSfV9Edhpzh6XhyiHOaWI MkmqNaXinRB6ZdsR+6+HOn8D7sk9NhRXjYTKWawOuQnL6jXXkBJK4rX8+45Ksyg4U7mA PCdPtRRyozQGjdn/r+5y1Wn//6vml0+Fr+VIDSGSmGTZs3mJKRusMu3Il7KKT4DKAI44 HCfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RA0oQ/GNq6rz6phpPIFpMyTQ81TXHbN7QIZjBCAB7To=; b=U2H1q9RRzQzYU/M+5Piemm7hYftf8FGd5KMr3r1ha4910ErqrpqQJCApDutwVrf6f4 etGd2S4sFfkDMolr2KNjg/MOFG78JpyONzN9y4Wm0V9X0ekbSn5w1QOWXJjCGVNGXx8q YiWxTb8BoeC4uXbdZhs++Srl/vX55kLUxo/uNHwwSJ6ZDunQS7YzCnE2qLX4gvNQ3xjl 2PLfrFkhixGWP1+4+EzWojHEpfbE0dYvAS02HDImBuYr6RDypI5cDO3qfhu6TrvYUcbL H+P8I+xDjybTOWeDaW8XqAjP8r6jRQzksI9voUvd9cJaDgeatzqSZBPMIPAGvBZrIDq/ 8n+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=KBJGS5QY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a8si347929pls.53.2021.09.29.09.00.00; Wed, 29 Sep 2021 09:00:17 -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; dkim=pass header.i=@canonical.com header.s=20210705 header.b=KBJGS5QY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344887AbhI2PAh (ORCPT + 99 others); Wed, 29 Sep 2021 11:00:37 -0400 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:60492 "EHLO smtp-relay-internal-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344855AbhI2PAh (ORCPT ); Wed, 29 Sep 2021 11:00:37 -0400 Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 35725402D9 for ; Wed, 29 Sep 2021 14:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632927535; bh=RA0oQ/GNq6rz6phpPIFpMyTQ81TXHbN7QIZjBCAB7To=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KBJGS5QYu396fgKtgIrzGaiJ2VGtFaXj5vdi+ehxDC6fVLL9eqpQ4PhHd2FL+oWf8 6d4BkzJEC2yadpPPfxZQkuGa7YKkChfNV8TX9b+u2Z1zzhe7jzNRBQKNX/UxDLlDVP GNQ/blnOWDA1wsKxBd1hwFxUOb9cWgBQKap/n0b8vmc+Ua6S+DhTJz50y8VrKaYprw 2CXNkr8DYK5bFgQ5ufXmc6JFaeFecH0KYwFMMlOy6+moN1DOucnv7+J+XE8Jc6vcyo dfysO4whBT3P2BNKT5bmjrtvd+8JBmi2W64axFpyhvKFnDkLP9TAyhq1gfVIa7JG6o njZJkSJC26NRg== Received: by mail-lf1-f71.google.com with SMTP id m2-20020ac24ac2000000b003f524eae63eso2649069lfp.10 for ; Wed, 29 Sep 2021 07:58:55 -0700 (PDT) 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=RA0oQ/GNq6rz6phpPIFpMyTQ81TXHbN7QIZjBCAB7To=; b=SJq4NLgl9zZ6m7QZtBKKzFVr9dzWBZHhlDtpJ6MnTbwKRXeXCX3rfJ0HYkZ3FnWiR2 /lcf4diOcXMMPVL0vQd+2+5LscUmH6rJCupQkpO+KTUMgmWEfYEz/9xhENOH9fNvDWPY JIOYcjCmy9WjH1jMN5lc8M+ztfUUAfD0pxwVuIUDjBn18VC+Y7BAiEchOnmL44wv4RIF rot3//qNg8EPFgZa+2Iy0lkEKh7WV6rvZsuMloyxjURImkHhTzemOMh0LRVG26cxn2aQ 8f33Pz8PfRKmIQNXo6V2nvwhwDlZIW/EE+UFgK2IMsL3O/vKdSMj+vc85uotpwExpgxT XcpA== X-Gm-Message-State: AOAM530G0x5bNqrYu0bFN2aJhkaB0U5YW+s+9HM1cTozUgEB0ua+i+d3 mGnbDiaxxAdvhDMzS3z0ccaJSd7HKkmS62sR1QYd+l6kP51a4H3dVhWv+ot0FfceTg4Xu3eypFn qFg9BzkHv6ND2Tbl0r8lLAbQwwiAi4rv3enroWsCrPQ== X-Received: by 2002:a5d:4601:: with SMTP id t1mr337446wrq.298.1632927523932; Wed, 29 Sep 2021 07:58:43 -0700 (PDT) X-Received: by 2002:a5d:4601:: with SMTP id t1mr337419wrq.298.1632927523734; Wed, 29 Sep 2021 07:58:43 -0700 (PDT) Received: from alex.home (lfbn-lyo-1-470-249.w2-7.abo.wanadoo.fr. [2.7.60.249]) by smtp.gmail.com with ESMTPSA id c7sm142194wmq.13.2021.09.29.07.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 07:58:43 -0700 (PDT) From: Alexandre Ghiti To: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Zong Li , Anup Patel , Atish Patra , Christoph Hellwig , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Ard Biesheuvel , Arnd Bergmann , Kees Cook , Guo Ren , Heinrich Schuchardt , Mayuresh Chitale , linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH v2 07/10] riscv: Improve virtual kernel memory layout dump Date: Wed, 29 Sep 2021 16:51:10 +0200 Message-Id: <20210929145113.1935778-8-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210929145113.1935778-1-alexandre.ghiti@canonical.com> References: <20210929145113.1935778-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the arrival of sv48 and its large address space, it would be cumbersome to statically define the unit size to use to print the different portions of the virtual memory layout: instead, determine it dynamically. Signed-off-by: Alexandre Ghiti --- arch/riscv/mm/init.c | 65 +++++++++++++++++++++++++++++++++---------- include/linux/sizes.h | 1 + 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index d7de414c6500..a304f2b3c178 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -90,34 +90,71 @@ static void __init zone_sizes_init(void) } #if defined(CONFIG_MMU) && defined(CONFIG_DEBUG_VM) + +#define LOG2_SZ_1K ilog2(SZ_1K) +#define LOG2_SZ_1M ilog2(SZ_1M) +#define LOG2_SZ_1G ilog2(SZ_1G) +#define LOG2_SZ_1T ilog2(SZ_1T) + static inline void print_mlk(char *name, unsigned long b, unsigned long t) { pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld kB)\n", name, b, t, - (((t) - (b)) >> 10)); + (((t) - (b)) >> LOG2_SZ_1K)); } static inline void print_mlm(char *name, unsigned long b, unsigned long t) { pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld MB)\n", name, b, t, - (((t) - (b)) >> 20)); + (((t) - (b)) >> LOG2_SZ_1M)); +} + +static inline void print_mlg(char *name, unsigned long b, unsigned long t) +{ + pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld GB)\n", name, b, t, + (((t) - (b)) >> LOG2_SZ_1G)); +} + +#ifdef CONFIG_64BIT +static inline void print_mlt(char *name, unsigned long b, unsigned long t) +{ + pr_notice("%12s : 0x%08lx - 0x%08lx (%4ld TB)\n", name, b, t, + (((t) - (b)) >> LOG2_SZ_1T)); +} +#endif + +static inline void print_ml(char *name, unsigned long b, unsigned long t) +{ + unsigned long diff = t - b; + +#ifdef CONFIG_64BIT + if ((diff >> LOG2_SZ_1T) >= 10) + print_mlt(name, b, t); + else +#endif + if ((diff >> LOG2_SZ_1G) >= 10) + print_mlg(name, b, t); + else if ((diff >> LOG2_SZ_1M) >= 10) + print_mlm(name, b, t); + else + print_mlk(name, b, t); } static void __init print_vm_layout(void) { pr_notice("Virtual kernel memory layout:\n"); - print_mlk("fixmap", (unsigned long)FIXADDR_START, - (unsigned long)FIXADDR_TOP); - print_mlm("pci io", (unsigned long)PCI_IO_START, - (unsigned long)PCI_IO_END); - print_mlm("vmemmap", (unsigned long)VMEMMAP_START, - (unsigned long)VMEMMAP_END); - print_mlm("vmalloc", (unsigned long)VMALLOC_START, - (unsigned long)VMALLOC_END); - print_mlm("lowmem", (unsigned long)PAGE_OFFSET, - (unsigned long)high_memory); + print_ml("fixmap", (unsigned long)FIXADDR_START, + (unsigned long)FIXADDR_TOP); + print_ml("pci io", (unsigned long)PCI_IO_START, + (unsigned long)PCI_IO_END); + print_ml("vmemmap", (unsigned long)VMEMMAP_START, + (unsigned long)VMEMMAP_END); + print_ml("vmalloc", (unsigned long)VMALLOC_START, + (unsigned long)VMALLOC_END); + print_ml("lowmem", (unsigned long)PAGE_OFFSET, + (unsigned long)high_memory); #ifdef CONFIG_64BIT - print_mlm("kernel", (unsigned long)KERNEL_LINK_ADDR, - (unsigned long)ADDRESS_SPACE_END); + print_ml("kernel", (unsigned long)KERNEL_LINK_ADDR, + (unsigned long)ADDRESS_SPACE_END); #endif } #else diff --git a/include/linux/sizes.h b/include/linux/sizes.h index 1ac79bcee2bb..0bc6cf394b08 100644 --- a/include/linux/sizes.h +++ b/include/linux/sizes.h @@ -47,6 +47,7 @@ #define SZ_8G _AC(0x200000000, ULL) #define SZ_16G _AC(0x400000000, ULL) #define SZ_32G _AC(0x800000000, ULL) +#define SZ_1T _AC(0x10000000000, ULL) #define SZ_64T _AC(0x400000000000, ULL) #endif /* __LINUX_SIZES_H__ */ -- 2.30.2