From patchwork Mon May 31 08:45:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 12288909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7F34C47094 for ; Mon, 31 May 2021 08:48:39 +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 8E49E61186 for ; Mon, 31 May 2021 08:48:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E49E61186 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@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=TtTHG1nUpZIOo8CsrTcQl/IQxV6xrQMoz0MLaRqMUGE=; b=gThCi++HZSP+vn rUDipvjg3BbZ4oD3TUKUybWTpVzmOcPvgM/+pq2egps6Fo+AuEV+gaO7TvtW6hPZNxK3Dlp5x2cqa ZuaDgelxAukGhZ4pxYINNd+Dj+LaEIWZY6oh/BcJk8zbWeaC6yKpk872ZxEXWKif9X/TYyrlLboTv kVwraoSQjvcrcQuv3oNvm7f9Oyi2XOiT/7yDhi2YS7uU1vbANyoA0rc91TbEBKFgkoa7RlsiwTFxn ONW6KZA6RcuS0BP/0MPp8PaU/cD7nObVoI4VgdBfvDhkkOv1mR8elLNTRLjvmNSYOhV8BCOYLDnbh pbSkoHJGrPGhjYRiWvVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lndZT-00BWDc-8e; Mon, 31 May 2021 08:46:51 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lndZ7-00BWAL-AH for linux-arm-kernel@lists.infradead.org; Mon, 31 May 2021 08:46:30 +0000 Received: by mail-pl1-x632.google.com with SMTP id e1so610756pld.13 for ; Mon, 31 May 2021 01:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/zyJIT7w/eGeWmQ4G0rkEMHAeL6fPSPkJSYhJ9pV1g4=; b=UgcoYLr7v9nKLPo4Qzo71PC+JN5LVIBY54596ObzRpp8EfzTdN4Bc3/Y1cyQS6dRYB Mt2v3haAsJ3OBHgLGXGw4iTyakqgpwk02XR6qaGRsWfyxtQxkDVfHchntNh2vrbAYP2o QyFnrDjJctIoRKlhI7sj4KMh6w0Me6A6gzu13OiZE4HzPRP8CQkm/wpsT6OllazsXCSl 7NBgJe/o3Njdc3DN1ZMwoE6P8hxrHFP40vjEkTM0WCOruNM8B4kdKcjQYKbYwAWSF1CW wuoUbyxSj1dZLa5MpAO+y5RMHCsZD9pFb0aDeWgLrZqGcYxs4UgLK3iJB1iKOA5Wojut IUGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/zyJIT7w/eGeWmQ4G0rkEMHAeL6fPSPkJSYhJ9pV1g4=; b=bdnNBnA45GJQDmo5Bdhj/gi1BaXBsRWlFhACg7hXpKmYPz0By7Src5N8+G2ZpMYTZz hjkqn9coxP2K9j9Iw2xwK2ZZSLS+WlAAU7J+YAaRWwkMucoePuAOk5I6GKRG91fGl+bp 5KpfjPMSoAeRrbzx6Jy1nMKMJkSO9KAW4V7SoG8FGI0dat+0S6YMX8zNTy4urSXpdEQx vRz2x0Wy0TCZLk0VDDM0xzu1O3Eu5SyU0x9RKC3kB5UEJRfiJnDoiHJXdPUeJPWi1Upq sk0e1fU2H8PuXeSbVXGYGdfjLaEkC+eXtVSmPE+IPnb6t/HdgTzN2XbjeDDdRjnpxzhp NXlA== X-Gm-Message-State: AOAM531arMK4yv3sKAALM4XFSBdCGwYCQj19QRWctsO70Su2EO46cHE+ AnnYHAylPh9Pky3mAR0uxUchvAMDHUBoEF8= X-Google-Smtp-Source: ABdhPJwsQHoGIQdCvURQG7Lg+E7EqukEge1/ZlcutjNZjsg9TvkUXViO0buZQ1l52PMlOcfwS6BcpQ== X-Received: by 2002:a17:902:a988:b029:101:86c3:df24 with SMTP id bh8-20020a170902a988b029010186c3df24mr12783937plb.64.1622450788124; Mon, 31 May 2021 01:46:28 -0700 (PDT) Received: from qualcomm-amberwing-rep-18.khw4.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id fs24sm5125677pjb.6.2021.05.31.01.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 May 2021 01:46:27 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Cc: Pingfan Liu , Catalin Marinas , Will Deacon , Ard Biesheuvel , Marc Zyngier , Kristina Martsenko , James Morse , Steven Price , Jonathan Cameron , Pavel Tatashin , Anshuman Khandual , Atish Patra , Mike Rapoport , Logan Gunthorpe , Mark Brown Subject: [PATCHv3 3/5] arm64/mm: unconditionally set IDMAP_PGTABLE_LEVELS to max pgtable level Date: Mon, 31 May 2021 04:45:38 -0400 Message-Id: <20210531084540.78546-4-kernelfans@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210531084540.78546-1-kernelfans@gmail.com> References: <20210531084540.78546-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210531_014629_407391_CE5F5374 X-CRM114-Status: GOOD ( 17.94 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org After commit 5dfe9d7d23c2 ("arm64: reduce ID map to a single page"), idmap only costs a page. While with 4K page, the current code enforces section mapping (2MB) on it due to the prot SWAPPER_MM_MMUFLAGS. But if switching to __create_pgd_mapping() to create pgtable, the code will decide the proper mapping level by itself, as the code snippet in init_pmd(): if (((addr | next | phys) & ~SECTION_MASK) == 0 && (flags & NO_BLOCK_MAPPINGS) == 0) pmd_set_huge(pmdp, phys, prot); As the case of .idmap.text, it requires pgtable up to pte level. Hence IDMAP_PGTABLE_LEVELS should be large enough to assure the capacity of IDMAP_DIR_SIZE. Signed-off-by: Pingfan Liu Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: Marc Zyngier Cc: Kristina Martsenko Cc: James Morse Cc: Steven Price Cc: Jonathan Cameron Cc: Pavel Tatashin Cc: Anshuman Khandual Cc: Atish Patra Cc: Mike Rapoport Cc: Logan Gunthorpe Cc: Mark Brown To: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/kernel-pgtable.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h index d44df9d62fc9..249ab132fced 100644 --- a/arch/arm64/include/asm/kernel-pgtable.h +++ b/arch/arm64/include/asm/kernel-pgtable.h @@ -24,23 +24,26 @@ #endif /* - * The idmap and swapper page tables need some space reserved in the kernel - * image. Both require pgd, pud (4 levels only) and pmd tables to (section) - * map the kernel. With the 64K page configuration, swapper and idmap need to + * The swapper page table needs some space reserved in the kernel + * image. It require pgd, pud (4 levels only) and pmd tables to (section) + * map the kernel. With the 64K page configuration, swapper needs to * map to pte level. The swapper also maps the FDT (see __create_page_tables - * for more information). Note that the number of ID map translation levels - * could be increased on the fly if system RAM is out of reach for the default - * VA range, so pages required to map highest possible PA are reserved in all - * cases. + * for more information). */ #if ARM64_SWAPPER_USES_SECTION_MAPS #define SWAPPER_PGTABLE_LEVELS (CONFIG_PGTABLE_LEVELS - 1) -#define IDMAP_PGTABLE_LEVELS (ARM64_HW_PGTABLE_LEVELS(PHYS_MASK_SHIFT) - 1) #else #define SWAPPER_PGTABLE_LEVELS (CONFIG_PGTABLE_LEVELS) -#define IDMAP_PGTABLE_LEVELS (ARM64_HW_PGTABLE_LEVELS(PHYS_MASK_SHIFT)) #endif +/* + * idmap also needs some space reserved in the kernel image. Since ".idmap.text" + * only occupies less than a page, idmap needs to map to pte level. + * Note that the number of ID map translation levels could be increased on the fly + * if system RAM is out of reach for the default VA range, so pages required to + * map highest possible PA are reserved in all cases. + */ +#define IDMAP_PGTABLE_LEVELS (ARM64_HW_PGTABLE_LEVELS(PHYS_MASK_SHIFT)) /* * If KASLR is enabled, then an offset K is added to the kernel address