Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6137196iog; Thu, 23 Jun 2022 12:07:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tWJ2hwBZbHaAdhJBHmG37ZMjbhdg81HOno3TQkzBwLnjBPj/t1AMb/Xu2XziFwu3XmOp1t X-Received: by 2002:a05:6402:3298:b0:435:8145:e6db with SMTP id f24-20020a056402329800b004358145e6dbmr12707896eda.294.1656011245222; Thu, 23 Jun 2022 12:07:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011245; cv=none; d=google.com; s=arc-20160816; b=SoF3QKn+ASi6L7PWq6RLjbwEv7M046xuE3LCU5SOCLLW/nBZ6QyGEjOy6FpufD1iCR btIOUuvfW+ajj3gnklMNZQuLjJXqQpFdM7vrN0148H1cxWLOrfyt+FYz/JNHMfC6eoyp F1MjY5FutS+CHl3qkIw4orMpJJ2XfMfv0XTBiqBJEf9SjXNyX8lGfgjJAWdf8pVBzaN9 da/asqClrmz+iNKaBabUnweQoAPj6bn2W2vMpvrqq2804YWR+jL0BchrtYrxhOlgIK+t FP+Lg0epZxvpuMPNya+1lSd47a3DaLgpkH+mG/ymbOJ7VpbIfyOwW+fDhIuCV78PRKWY iRmg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wRAHCVqw1NBBwsBkAZNU47YQobRV6umWls0Mmp5v4dQ=; b=ADS4v/U38UxpuFXc6aEcXt4wiJbEUqi+c2HXM6qjZGplYL/RhYL53HWYe+KfvWDvEN tXpiwJ/FIwuNWyyHZLyYj8V625vb02wl1rgFD++Ub0L6ql5vxA/CDMEt7AIabDaGLPMe 8lM58R9QYd37OMlX9JDjmIqDGHO6cDymIUKd1fdD5J+OCBouzB/JKpn6rDytQvRjctp8 dSIXswb/dCSrLkjg/SZUqanY8hB/tim5/eIJIUt83rNvNtlkP8Zy69PcNHe5PmarPqIW /xo7lwrFS5noI1R3wLNbFZmtF3CfQ/HD/UK+JabI23fj5SzJ+jnrOgUg3toYBtWpQlSI Lv6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WAGYCZSk; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ec48-20020a0564020d7000b004358a8128d0si343750edb.296.2022.06.23.12.06.59; Thu, 23 Jun 2022 12:07:25 -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=@linuxfoundation.org header.s=korg header.b=WAGYCZSk; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235305AbiFWRwS (ORCPT + 99 others); Thu, 23 Jun 2022 13:52:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbiFWRvu (ORCPT ); Thu, 23 Jun 2022 13:51:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 479D69917F; Thu, 23 Jun 2022 10:12:33 -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 3EC45B82489; Thu, 23 Jun 2022 17:12:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8973AC341C4; Thu, 23 Jun 2022 17:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004349; bh=8NpyPW8fRdZfAbob49QXgobOOSiEkus4+nQosMXVvEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WAGYCZSk3Z5nVC8kHB5HkranYSQ/2eHWBZ31DyeLd0D2vHeC6ZCChaQClPkKAtVne SjymvLvhc0hXQgbhztLzee44m80hCf68yXqUzA/Ec4XHFlLKMQYdg5wS5J4fqMVpQp 4AR+CZmrB/4r2gzIktMJPzhWxTrpOliKj/GR/7Ek= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Keerthy , Stephen Boyd , Herbert Xu , "Jason A. Donenfeld" Subject: [PATCH 4.19 010/234] random: Support freezable kthreads in add_hwgenerator_randomness() Date: Thu, 23 Jun 2022 18:41:17 +0200 Message-Id: <20220623164343.347771738@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: Stephen Boyd commit ff296293b3538d19278a7f7cd1f3aa600ad9164c upstream. The kthread calling this function is freezable after commit 03a3bb7ae631 ("hwrng: core - Freeze khwrng thread during suspend") is applied. Unfortunately, this function uses wait_event_interruptible() but doesn't check for the kthread being woken up by the fake freezer signal. When a user suspends the system, this kthread will wake up and if it fails the entropy size check it will immediately go back to sleep and not go into the freezer. Eventually, suspend will fail because the task never froze and a warning message like this may appear: PM: suspend entry (deep) Filesystems sync: 0.000 seconds Freezing user space processes ... (elapsed 0.001 seconds) done. OOM killer disabled. Freezing remaining freezable tasks ... Freezing of tasks failed after 20.003 seconds (1 tasks refusing to freeze, wq_busy=0): hwrng R running task 0 289 2 0x00000020 [] (__schedule) from [] (schedule+0x3c/0xc0) [] (schedule) from [] (add_hwgenerator_randomness+0xb0/0x100) [] (add_hwgenerator_randomness) from [] (hwrng_fillfn+0xc0/0x14c [rng_core]) [] (hwrng_fillfn [rng_core]) from [] (kthread+0x134/0x148) [] (kthread) from [] (ret_from_fork+0x14/0x2c) Check for a freezer signal here and skip adding any randomness if the task wakes up because it was frozen. This should make the kthread freeze properly and suspend work again. Fixes: 03a3bb7ae631 ("hwrng: core - Freeze khwrng thread during suspend") Reported-by: Keerthy Tested-by: Keerthy Signed-off-by: Stephen Boyd Signed-off-by: Herbert Xu Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -2483,6 +2483,7 @@ void add_hwgenerator_randomness(const ch size_t entropy) { struct entropy_store *poolp = &input_pool; + bool frozen = false; if (unlikely(crng_init == 0)) { crng_fast_load(buffer, count); @@ -2493,9 +2494,12 @@ void add_hwgenerator_randomness(const ch * We'll be woken up again once below random_write_wakeup_thresh, * or when the calling thread is about to terminate. */ - wait_event_interruptible(random_write_wait, kthread_should_stop() || + wait_event_interruptible(random_write_wait, + kthread_freezable_should_stop(&frozen) || ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits); - mix_pool_bytes(poolp, buffer, count); - credit_entropy_bits(poolp, entropy); + if (!frozen) { + mix_pool_bytes(poolp, buffer, count); + credit_entropy_bits(poolp, entropy); + } } EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);