Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6141395iog; Thu, 23 Jun 2022 12:12:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uZxFl42UnKusqAh9zcTBQerj6vVeOy6ToGk/BiKnlO5BZqmNVHlMK6iJ9wsYDUUkcYSyij X-Received: by 2002:a17:902:7c0e:b0:16a:6ec:69e9 with SMTP id x14-20020a1709027c0e00b0016a06ec69e9mr32825008pll.108.1656011540549; Thu, 23 Jun 2022 12:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011540; cv=none; d=google.com; s=arc-20160816; b=LTreRe1JBvU1dm7VZGso0CWrZr4pmIVW/i4cOHBuoUZmlP0WlXlVpg3x+5d1QK3y9w 9QBkSQbl3FruwQOCPNJGzDwsx7xOTHuck2A3vfxltNfZN3HQMFhxS3aRkAdyK92tP6d0 bDlkRl+UnRORZUSu96VfjEP4fhe9FWQF+swSKeLqP82RMYLPcwDmv3vKdq4xf8GfPxUV a84swr+kBuWMFpuaBOIHGZ3qDouM14Pl0EBfM5FxXFIi2LrTGNr9oJscChZEmTLTc+hc cNxBiIUQj1tlHejhOoNa5x6NXVca3Nor38iSuEqFQjOZNO2ASGGBWzamUAmKz4cEKlo3 52Dg== 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=s6Cq9UOVK2cftHWbBcAA64tNv2e7LcWOzuVQozF/wbo=; b=FtLDC/Op9v/ZyWW1S2kem5cxy00GNl/t+E0b6joUIW1/jrrs6jIipQ0wipTiRh5BPs pXBTGrOI4py/bwK8Q2Cb07+PlSEtbMnlyOy1y2NBHgzdcXw0cnUHpYYDImDN65qvfwgc aY7V3RBNyp082+m4BrOjNf+vFb9l8+kZc2+mkp2y6x2pbu3yDArIUk3D0R5PnmlvWpN1 UYpxvWblb7+CXP8tuXs899eae0KMXb//1qu1zxcveohB+lAz7+LSlltlYwFzA2XOJucJ WhwETiEQ2hYCwCmaySkH702gQ+RKc39tOYKn0fTkGlbpD6gq3hE/QK7CjSTHq3f9QL7M bMVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=od1hafUw; 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 p20-20020a17090ad31400b001ead1c2f859si3691236pju.187.2022.06.23.12.12.09; Thu, 23 Jun 2022 12:12:20 -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=od1hafUw; 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 S233002AbiFWQ5T (ORCPT + 99 others); Thu, 23 Jun 2022 12:57:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233721AbiFWQv3 (ORCPT ); Thu, 23 Jun 2022 12:51:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13C73506DC; Thu, 23 Jun 2022 09:49:28 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 54C8661F90; Thu, 23 Jun 2022 16:49:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36664C3411B; Thu, 23 Jun 2022 16:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656002966; bh=wvFpbs1M7ItDJ+3maBjTlk+lo8NuZRntPs7fyIL4zXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=od1hafUwmZCbu7wFm2P307TOQ/rg3/7Po+FOUDfDzxvsywxnFVJ4pjARY0O9bsYOh CNIKDmMOlGRoOwnmqciFq1XrKvxEB8CNRKKinRKYESVUGiSozCq92msuMUANvAHC42 2IASxK9aPJyFzIBGd7VpjYHnvhNbAjK4gqZxJC3o= 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.9 044/264] random: Support freezable kthreads in add_hwgenerator_randomness() Date: Thu, 23 Jun 2022 18:40:37 +0200 Message-Id: <20220623164345.316194775@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@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 @@ -2473,6 +2473,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); @@ -2483,9 +2484,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);