Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1831805rwo; Wed, 2 Aug 2023 23:44:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlGy9iBGdqHYL29L/Y5P4s1kuFxtyZ4gkstE8GRPGScijM3N8alQNg1vxKb1YYVQqctonTWu X-Received: by 2002:a05:6402:50c8:b0:51e:5206:d69e with SMTP id h8-20020a05640250c800b0051e5206d69emr8368001edb.10.1691045061840; Wed, 02 Aug 2023 23:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691045061; cv=none; d=google.com; s=arc-20160816; b=Nmi7xRmKwBE1WV5+VzZ8+PzHLl7ciyAq4qyh41KA4DtnBs2XNKNI2yAyLKUcFZLHa0 C0iL65op2Vdqe8UJuiwqPi0bn8Ld0skmimEuLQJ66VdE/XqQ6RmLzE5LmU3e6zUioDxA t5WRaQ5clrf/pvHraKVbf3JoQ6it27I8DPEEt4MUUNnwUJppF0z0ZepiuAzvrkgVAnlF UDc5d3DohUJWYeRSgCNI5A7L1yaMYKa4Gw8QN4DfmiqoWNALMvG5ZrRCO4gk4fkM1uHv k8+czXUgpdHyDJWUVGlWG9JL8DaperATQz2S85hnSl0FPqCCpJ0lYT6xkSVppApz9isu Rh+Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=1gc6WZEQuZSdGcBZb/7lutxlV72ySAQiJg15nJmvboI=; fh=ktFmNcrNO7P0fUmBODMaNCpNQyf/Wiq+k3Cwa8bj33w=; b=Ve4HdDzUtZC8MZgCYACGxEjK+z40EFM1ARPuBxLHyhrA4H7GF7I7GaxBM0tdte2aDY uHjKMnExFdNVNs2J1bp8k+QD7WM+M/aSDNIENAvA28QrI4TbyNCSf7VsgWCv8fqeeLoR IAYIaDDqq1nt0/uZ0BuSpZDrd7Zn3YBCjNCl/PE2b5s9kWRzstazKvEIChnVVseS1mG2 mkSeed9ZXJo+F2wU7fyCdraPBjs0vIw+qKLvThRgnUPwmmBY4rGqbF54OBR4l8QHAmDv /IgUn0mLc4GMqTY0tSu3GZFy14Ez3/6YNgqfMgY+Rvu3lbQc7Krkmg9jrxHil4ZvRo0L 73cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MhDJKaWU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c20-20020aa7d614000000b00522472b99f5si7528662edr.285.2023.08.02.23.43.57; Wed, 02 Aug 2023 23:44:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MhDJKaWU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233046AbjHCGYZ (ORCPT + 99 others); Thu, 3 Aug 2023 02:24:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232177AbjHCGYU (ORCPT ); Thu, 3 Aug 2023 02:24:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F41DC10FB; Wed, 2 Aug 2023 23:24:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 753D061BCB; Thu, 3 Aug 2023 06:24:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E031C433C7; Thu, 3 Aug 2023 06:24:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691043857; bh=Hm/g9aC+hWCP6Ihz8zX5wVSTOllY15bZ3NwCc3kbbXs=; h=From:To:Cc:Subject:Date:From; b=MhDJKaWU3OZYGs1YbKGpCvZibYbdqtXrXFjQ1yFISxxL9XuMUQ5MEOcl1szgXM/n+ wjIzkIVu7a8b7lm9ukhqSpq0ASJ27Ly+1CXGVfy0vStxh665KZ4lb5FxlNUFzboYcu A9Y2D1rps7TOBWdfP961uYc2Vj6bJgP/ACq3SoRjAiCAFldEtNdnOQxeroZmVNdmDy 5l6mU41FvLLJ94rGY0rqZZjq36yBc16zWpgagBZcxfT943TN+zMf4LWy9iSVaqXBno VEbxidfHHx+ba/Oh5QpOJxXfsAAM9mbQI5KKHuA85iU2UEHf87X26O5p8JmgkNb0M9 W8nkVm/1udWxQ== From: Mike Rapoport To: Helge Deller Cc: Christoph Biedl , "James E.J. Bottomley" , John David Anglin , Mike Rapoport , Vlastimil Babka , linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] parisc/mm: preallocate fixmap page tables at init Date: Thu, 3 Aug 2023 09:24:04 +0300 Message-Id: <20230803062404.2373480-1-rppt@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Mike Rapoport (IBM)" Christoph Biedl reported early OOM on recent kernels: swapper: page allocation failure: order:0, mode:0x100(__GFP_ZERO), nodemask=(null) CPU: 0 PID: 0 Comm: swapper Not tainted 6.3.0-rc4+ #16 Hardware name: 9000/785/C3600 Backtrace: [<10408594>] show_stack+0x48/0x5c [<10e152d8>] dump_stack_lvl+0x48/0x64 [<10e15318>] dump_stack+0x24/0x34 [<105cf7f8>] warn_alloc+0x10c/0x1c8 [<105d068c>] __alloc_pages+0xbbc/0xcf8 [<105d0e4c>] __get_free_pages+0x28/0x78 [<105ad10c>] __pte_alloc_kernel+0x30/0x98 [<10406934>] set_fixmap+0xec/0xf4 [<10411ad4>] patch_map.constprop.0+0xa8/0xdc [<10411bb0>] __patch_text_multiple+0xa8/0x208 [<10411d78>] patch_text+0x30/0x48 [<1041246c>] arch_jump_label_transform+0x90/0xcc [<1056f734>] jump_label_update+0xd4/0x184 [<1056fc9c>] static_key_enable_cpuslocked+0xc0/0x110 [<1056fd08>] static_key_enable+0x1c/0x2c [<1011362c>] init_mem_debugging_and_hardening+0xdc/0xf8 [<1010141c>] start_kernel+0x5f0/0xa98 [<10105da8>] start_parisc+0xb8/0xe4 Mem-Info: active_anon:0 inactive_anon:0 isolated_anon:0 active_file:0 inactive_file:0 isolated_file:0 unevictable:0 dirty:0 writeback:0 slab_reclaimable:0 slab_unreclaimable:0 mapped:0 shmem:0 pagetables:0 sec_pagetables:0 bounce:0 kernel_misc_reclaimable:0 free:0 free_pcp:0 free_cma:0 Node 0 active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB isolated(anon):0kB isolated(file):0kB mapped:0kB dirty:0kB writeback:0kB shmem:0kB +writeback_tmp:0kB kernel_stack:0kB pagetables:0kB sec_pagetables:0kB all_unreclaimable? no Normal free:0kB boost:0kB min:0kB low:0kB high:0kB reserved_highatomic:0KB active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB writepending:0kB +present:1048576kB managed:1039360kB mlocked:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB lowmem_reserve[]: 0 0 Normal: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 0kB 0 total pagecache pages 0 pages in swap cache Free swap = 0kB Total swap = 0kB 262144 pages RAM 0 pages HighMem/MovableOnly 2304 pages reserved Backtrace: [<10411d78>] patch_text+0x30/0x48 [<1041246c>] arch_jump_label_transform+0x90/0xcc [<1056f734>] jump_label_update+0xd4/0x184 [<1056fc9c>] static_key_enable_cpuslocked+0xc0/0x110 [<1056fd08>] static_key_enable+0x1c/0x2c [<1011362c>] init_mem_debugging_and_hardening+0xdc/0xf8 [<1010141c>] start_kernel+0x5f0/0xa98 [<10105da8>] start_parisc+0xb8/0xe4 Kernel Fault: Code=15 (Data TLB miss fault) at addr 0f7fe3c0 CPU: 0 PID: 0 Comm: swapper Not tainted 6.3.0-rc4+ #16 Hardware name: 9000/785/C3600 This happens because patching static key code temporarily maps it via fixmap and if it happens before page allocator is initialized set_fixmap() cannot allocate memory using pte_alloc_kernel(). Make sure that fixmap page tables are preallocated early so that pte_offset_kernel() in set_fixmap() never resorts to pte allocation. Signed-off-by: Mike Rapoport (IBM) --- I didn't add Fixes tag with the commit Christoph bisected because that commit didn't change anything in the initialization of the static keys and I really doubt it is the actual cause of the issue. arch/parisc/mm/fixmap.c | 3 --- arch/parisc/mm/init.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/arch/parisc/mm/fixmap.c b/arch/parisc/mm/fixmap.c index cc15d737fda6..ae3493dae9dc 100644 --- a/arch/parisc/mm/fixmap.c +++ b/arch/parisc/mm/fixmap.c @@ -19,9 +19,6 @@ void notrace set_fixmap(enum fixed_addresses idx, phys_addr_t phys) pmd_t *pmd = pmd_offset(pud, vaddr); pte_t *pte; - if (pmd_none(*pmd)) - pte = pte_alloc_kernel(pmd, vaddr); - pte = pte_offset_kernel(pmd, vaddr); set_pte_at(&init_mm, vaddr, pte, __mk_pte(phys, PAGE_KERNEL_RWX)); flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE); diff --git a/arch/parisc/mm/init.c b/arch/parisc/mm/init.c index 406c52fe23d5..389941c7f209 100644 --- a/arch/parisc/mm/init.c +++ b/arch/parisc/mm/init.c @@ -669,6 +669,39 @@ static void __init gateway_init(void) PAGE_SIZE, PAGE_GATEWAY, 1); } +static void __init fixmap_init(void) +{ + unsigned long addr = FIXMAP_START; + unsigned long end = FIXMAP_START + FIXMAP_SIZE; + pgd_t *pgd = pgd_offset_k(addr); + p4d_t *p4d = p4d_offset(pgd, addr); + pud_t *pud = pud_offset(p4d, addr); + pmd_t *pmd; + + BUILD_BUG_ON(FIXMAP_SIZE > PMD_SIZE); + +#if CONFIG_PGTABLE_LEVELS == 3 + if (pud_none(*pud)) { + pmd = memblock_alloc(PAGE_SIZE << PMD_TABLE_ORDER, + PAGE_SIZE << PMD_TABLE_ORDER); + if (!pmd) + panic("fixmap: pmd allocation failed.\n"); + pud_populate(NULL, pud, pmd); + } +#endif + + pmd = pmd_offset(pud, addr); + do { + pte_t *pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE); + if (!pte) + panic("fixmap: pte allocation failed.\n"); + + pmd_populate_kernel(&init_mm, pmd, pte); + + addr += PAGE_SIZE; + } while (addr < end); +} + static void __init parisc_bootmem_free(void) { unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0, }; @@ -683,6 +716,7 @@ void __init paging_init(void) setup_bootmem(); pagetable_init(); gateway_init(); + fixmap_init(); flush_cache_all_local(); /* start with known state */ flush_tlb_all_local(NULL); base-commit: 5d0c230f1de8c7515b6567d9afba1f196fb4e2f4 -- 2.34.1