Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2262666iof; Wed, 8 Jun 2022 00:47:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0d484XuR2tInDyUe2SEkaU2e4ZKdqh9/wywWbXQ42Oc2VfDS5mbG44nQl9HkJOJ+lM4Jj X-Received: by 2002:a17:90b:4b4b:b0:1e8:9e0e:c362 with SMTP id mi11-20020a17090b4b4b00b001e89e0ec362mr8906998pjb.187.1654674431546; Wed, 08 Jun 2022 00:47:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654674431; cv=none; d=google.com; s=arc-20160816; b=v+flNMqxygMHPB3wEyDwhUs5HAIUOjve/6GxFzmGv6qLRIFfojTfpMIHyK4wZNmpuf 2laH4Ab8u8+Rgaz22yPc9OHcg52s5WoJAocM9gpkx/c5BuX6VXVFg8b46emxMrLS0qta Vu68ip98TVYrbjcSx5O1qykRhI4NCNEzRid5pD2i3LUruB9bsX6lq+SSgEbZw+IZEoIC GxDbNG1AypkZJRmqoCJijbYLdC0CMEXiF3joyMJXASt/XgKIEJ7XpClyZ5r+PJyL9Ihy BZgiRHqanWStwVY5DJOuQ+ykfSMBClyGtRm/U6ayhTtZZymLZJqYcar22+Q3hcSuty4E ce2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=s+usQNQe61fUNXtftBnDDPOoqNzLMBH21NqyRZq7YLo=; b=MA1LJ0PqfSMDWdtnQN/qtsxxm4EJDMMTKtGxyxbC1qc7JDcYBZsHz2ltsA7+I1PGso HNnjtc8vWpZCjPH3q/AxHy57h7BnaolwbhgLXs537ar1P0Ko3F273z6GHczeH5dAdKKM XRWEb3jxALOOYIFf+1U5QAWImhA7wKYcM/FV2dKU/PBXAw0FGilq3Zh9/dZACjTDeoiW 0KEIiQnQ23RrEXQrGQ6BnYE4/1d49gkRj4XNJpBQ/etmY/NcNxCJsYiaz59PTyVYHeAY muM26sZYkReUufUpUWNe+Vsr3anAHD5zKRGeXtedOHUHGkfa2/58yf4jZ+SWAoITi/2g AXNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b=QcJFOZkr; 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=raspberrypi.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id il6-20020a17090b164600b001df82539ad1si36236024pjb.54.2022.06.08.00.46.59; Wed, 08 Jun 2022 00:47:11 -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=@raspberrypi.com header.s=google header.b=QcJFOZkr; 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=raspberrypi.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239127AbiFGJPo (ORCPT + 99 others); Tue, 7 Jun 2022 05:15:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239072AbiFGJPc (ORCPT ); Tue, 7 Jun 2022 05:15:32 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 500AA6CAA9 for ; Tue, 7 Jun 2022 02:15:29 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id k19so23206743wrd.8 for ; Tue, 07 Jun 2022 02:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=message-id:date:mime-version:user-agent:subject:to:cc:references :from:in-reply-to:content-transfer-encoding; bh=s+usQNQe61fUNXtftBnDDPOoqNzLMBH21NqyRZq7YLo=; b=QcJFOZkr6N0djzaiBVtwqiI34B4U1YPZDK+qqBxhWRvksqYGTnrdJ2l7ks6TzStesp CLefRAOdeVlWHQFXzog5tGhwMpXNRIK8rxeKr1KewPQnqDMI/TEosM2Oyidtx2FgNDkv heHtFS1yJhRiiNE1d2ZfRmVJmmpFVWPWDGsMQ8KTW/BxHe6NXSsxnEnkGR9y2I+xCAN/ lYcVSSYtJoV2uSRZHEGaN8h+805AB5fGDQUfR352OQi25LWIjK+XwZ9DoHNTGmMZxafM rpdEA4LHFHBvqNW58ewZc2pwQN0+fcihCYVyXmOThiBzZpJGeS04EYqcHU9AEy3Vk76M fiZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :to:cc:references:from:in-reply-to:content-transfer-encoding; bh=s+usQNQe61fUNXtftBnDDPOoqNzLMBH21NqyRZq7YLo=; b=xJkD+70L8lGetxUOIz5gJ5cXheJ24hjYHrvsvMw36tMfJvzMDSZI8/NfHYKwkjI23S OiLxR/EV+nNi8O9YhCOgB5JaQI1OZ17CuIetcxiU+Kq4dV3XsN4pTgQ8UCVrxdQODUso Waxa0gv/uUchoTan6/BYK65/Lg6qfceBYR1MzsYr8MEmlfQFyvvfJbwFkbKLUJIwt6cz VatF9mjnnowSLNstF9prayZJMAzpL1Zaj8UU0x5lNIwdH8L0zxE+XVSG0mY9rQTaXgMD eESvNRUiv0EYKncIZ/qHc60emmV2nUSjiHXsbsiAT5zWRHrmb5PH+IvQ5LQG0UTP8Zsb fQIg== X-Gm-Message-State: AOAM53087U3cpCJtH5nFIkqXDi5X6Jh+vbC8KlAaJ9GM9XkBuH/Ohz7l TDZP/ajYd1gsWW4T2aZqGwCvZw== X-Received: by 2002:adf:fe0c:0:b0:218:4312:1230 with SMTP id n12-20020adffe0c000000b0021843121230mr7830352wrr.223.1654593327814; Tue, 07 Jun 2022 02:15:27 -0700 (PDT) Received: from ?IPV6:2a00:1098:3142:14:901f:dbcb:c1e4:e4b8? ([2a00:1098:3142:14:901f:dbcb:c1e4:e4b8]) by smtp.gmail.com with ESMTPSA id n5-20020a05600c3b8500b0039c4e2ff7cfsm6411598wms.43.2022.06.07.02.15.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Jun 2022 02:15:27 -0700 (PDT) Message-ID: <8c3fe744-0181-043a-3af9-dd00165a6356@raspberrypi.com> Date: Tue, 7 Jun 2022 10:15:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v2] ARM: initialize jump labels before setup_machine_fdt() To: "Jason A. Donenfeld" Cc: Russell King - ARM Linux , Russell King , linux-arm-kernel , LKML , Catalin Marinas , Stephen Boyd , Ard Biesheuvel , stable References: <8cc7ebe4-442b-a24b-9bb0-fce6e0425ee6@raspberrypi.com> From: Phil Elwell In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, 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 On 07/06/2022 09:43, Jason A. Donenfeld wrote: > Hi Phil, > > On Tue, Jun 7, 2022 at 10:29 AM Phil Elwell wrote: >> >> This patch is fatal for me in the downstream Raspberry Pi kernel - it locks up >> on boot even before the earlycon output is available. Hacking jump_label_init to >> skip the jump_entry for "crng_is_ready" allows it to boot, but is likely to have >> consequences further down the line. > > Also, reading this a few times, I'm not 100% sure I understand what > you did to hack around this and why that works. Think you could paste > your hackpatch just out of interest to the discussion (but obviously > not to be applied)? This is the minimal version of my workaround patch that at least allows the board to boot. Bear in mind that it was written with no previous knowledge of jump labels and was arrived at by iteratively bisecting the list of jump_labels until the first dangerous one was found, then later working out that there was only one. diff --git a/kernel/jump_label.c b/kernel/jump_label.c index b156e152d6b48..7b053521f7216 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -466,6 +466,7 @@ void __init jump_label_init(void) struct jump_entry *iter_stop = __stop___jump_table; struct static_key *key = NULL; struct jump_entry *iter; + int iter_count = 0; /* * Since we are initializing the static_key.enabled field with @@ -499,7 +500,9 @@ void __init jump_label_init(void) continue; key = iterk; - static_key_set_entries(key, iter); + iter_count++; + if (iter_count != 1083) + static_key_set_entries(key, iter); } static_key_initialized = true; jump_label_unlock(); I'm sure this could be rewritten in a less fragile manner making reference to crng_is_ready directly, but this is where I got to yesterday. Ha! I just proved the patch's fragility by switching from a Pi 2 to a Pi 4, so the saner version is: diff --git a/drivers/char/random.c b/drivers/char/random.c index ca17a658c2147..ca7c8a67b8314 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -79,7 +79,7 @@ static enum { CRNG_EARLY = 1, /* At least POOL_EARLY_BITS collected */ CRNG_READY = 2 /* Fully initialized with POOL_READY_BITS collected */ } crng_init __read_mostly = CRNG_EMPTY; -static DEFINE_STATIC_KEY_FALSE(crng_is_ready); +DEFINE_STATIC_KEY_FALSE(crng_is_ready); #define crng_ready() (static_branch_likely(&crng_is_ready) || crng_init >= CRNG_READY) /* Various types of waiters for crng_init->CRNG_READY transition. */ static DECLARE_WAIT_QUEUE_HEAD(crng_init_wait); diff --git a/kernel/jump_label.c b/kernel/jump_label.c index b156e152d6b48..b79de9da036fd 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -484,6 +484,7 @@ void __init jump_label_init(void) jump_label_sort_entries(iter_start, iter_stop); for (iter = iter_start; iter < iter_stop; iter++) { + extern struct static_key_false crng_is_ready; struct static_key *iterk; bool in_init; @@ -499,7 +500,8 @@ void __init jump_label_init(void) continue; key = iterk; - static_key_set_entries(key, iter); + if (key != &crng_is_ready.key) + static_key_set_entries(key, iter); } static_key_initialized = true; jump_label_unlock(); And to answer your questions from the other thread: * Without any fixing patches we see the warning messages because we are using rng-seed in DT. * I've seen the problem on a Pi 2 and a Pi 4 running 32-bit kernels. Phil