Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2220556iof; Tue, 7 Jun 2022 23:37:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0xkLkvjPZLrixBtDrQh3pVXfSmzu6WqFI7IzcrIkgA4v0HYXfHWEIbHpBJaXVKPScE05I X-Received: by 2002:a17:903:40c9:b0:167:5411:3536 with SMTP id t9-20020a17090340c900b0016754113536mr23532531pld.2.1654670234625; Tue, 07 Jun 2022 23:37:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654670234; cv=none; d=google.com; s=arc-20160816; b=UzjhLQ6HuB4VmC3sNXn4Kp8OngdReeXM2F39w5Mt4MLxPuNj5ZhWTx7UGU6JV85akd ZcHcboTQ9qEpmIopDDTsFoXdxEDvHcRtGzTnSKiz3Qyn6h4WyGZZI3VoGjEiZyfrkMFQ UM3Ma1aC9UkQfpkCx80t2A5+D/87MzRC8fl+yUMAj35DB4bEAPpXv+k7okpdCAzHG55a NDPkBQ+OQkCcBrutz3WGyuB9B/odozVGOhsKv16DCvG0wnF7oXxGlAuKllc/At8tGZdx 7I42IIzV0qmlCjLpsg71wl/xl7e2Y7kgQ/0RNV/vuznyS2ND7+MhC/gJlpLdkfI2plVp qxqA== 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=aIk3Rt4nDto2wWZJ+glqe0AEG6VQh1/nNLxNJJ+VXZQ=; b=oODvl+I7lu5n4/qKjIQhSNwRkUVNfdCquCwscfvfemmEVi8CfMYqVjJgxfrSj3lm++ ZqC5uI/Z6Kr4vMk6IylMoGQwsDcoe9wFkxSdLG+W0sg++I+YsqdnbhpFbhKIghJ9rZLG wUyypLbQ5A55/qhdMJNxU6ZtK56xAbuKnb1FHHT+Kw9TD2ehD8nxufmSHS7a+842elJf vzj5MAsi7fpXIgfVD3RCA5fML70tagZyrxYXVwtXDLkMhR1VXXyWSGo8xSkHu5pQbShO ODQ/6I3jAzPDypNGEr37A3Khy/XHxDEQtBB8SsSS7V/WJxGIVphcp7EYoqOQ6l+JngFj nYkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=ezRz14S7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m18-20020a170902bb9200b0016362b01d1fsi23548623pls.600.2022.06.07.23.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:37:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=ezRz14S7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B0177FB423; Tue, 7 Jun 2022 23:00:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231835AbiFHCS3 (ORCPT + 99 others); Tue, 7 Jun 2022 22:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1390553AbiFHBuy (ORCPT ); Tue, 7 Jun 2022 21:50:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEE6E1A43EF for ; Tue, 7 Jun 2022 12:31:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 019C0B82182 for ; Tue, 7 Jun 2022 19:31:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0832C385A2; Tue, 7 Jun 2022 19:31:15 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="ezRz14S7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1654630272; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aIk3Rt4nDto2wWZJ+glqe0AEG6VQh1/nNLxNJJ+VXZQ=; b=ezRz14S7LF6mMOq6Y8L0jlHdpkHv5/MCl5Z6EXV61XdLF/2w+XGyhz5zXj8ZQqSGJlGW3q TKZJw2/TwkTK8xN8pMLyqzHxYkaMGeqWDEaBSHyQuowIiZYvWOrs0+akt9LBRFPvs69ClY BzBioCKFw9TzQO1WYsOtHnzigc1S7js= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id e15e7cd2 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Tue, 7 Jun 2022 19:31:12 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-arm-kernel , LKML Cc: "Jason A. Donenfeld" , Stephen Boyd , Phil Elwell , Ard Biesheuvel , Russel King , Catalin Marinas Subject: [PATCH v3] ARM: initialize jump labels before setup_machine_fdt() Date: Tue, 7 Jun 2022 21:30:44 +0200 Message-Id: <20220607193044.1063287-1-Jason@zx2c4.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Stephen reported that a static key warning splat appears during early boot on arm64 systems that credit randomness from device trees that contain an "rng-seed" property, because setup_machine_fdt() is called before jump_label_init() during setup_arch(), which was fixed by 73e2d827a501 ("arm64: Initialize jump labels before setup_machine_fdt()"). The same basic issue applies to arm32 as well. So this commit adds a call to jump_label_init() just before setup_machine_fdt(). Since the page maps haven't been set yet, this also requires us to use the early patching code in the jump label code. Reported-by: Stephen Boyd Reported-by: Phil Elwell Cc: Ard Biesheuvel Cc: Russel King Cc: Catalin Marinas Fixes: f5bda35fba61 ("random: use static branch for crng_ready()") Signed-off-by: Jason A. Donenfeld --- arch/arm/kernel/jump_label.c | 3 ++- arch/arm/kernel/setup.c | 1 + arch/arm/mm/mmu.c | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm/kernel/jump_label.c b/arch/arm/kernel/jump_label.c index 303b3ab87f7e..8f8c5312f917 100644 --- a/arch/arm/kernel/jump_label.c +++ b/arch/arm/kernel/jump_label.c @@ -8,6 +8,7 @@ static void __arch_jump_label_transform(struct jump_entry *entry, enum jump_label_type type, bool is_static) { + extern bool early_mm_initialized; void *addr = (void *)entry->code; unsigned int insn; @@ -16,7 +17,7 @@ static void __arch_jump_label_transform(struct jump_entry *entry, else insn = arm_gen_nop(); - if (is_static) + if (is_static || !early_mm_initialized) __patch_text_early(addr, insn); else patch_text(addr, insn); diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 1e8a50a97edf..3ff80b1ee0b5 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1101,6 +1101,7 @@ void __init setup_arch(char **cmdline_p) atags_vaddr = FDT_VIRT_BASE(__atags_pointer); setup_processor(); + jump_label_init(); if (atags_vaddr) { mdesc = setup_machine_fdt(atags_vaddr); if (mdesc) diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index 5e2be37a198e..3f63a5581966 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -1754,10 +1754,13 @@ void __init paging_init(const struct machine_desc *mdesc) __flush_dcache_page(NULL, empty_zero_page); } +bool early_mm_initialized; + void __init early_mm_init(const struct machine_desc *mdesc) { build_mem_type_table(); early_paging_init(mdesc); + early_mm_initialized = true; } void set_pte_at(struct mm_struct *mm, unsigned long addr, -- 2.35.1