Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6034003iog; Thu, 23 Jun 2022 10:00:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uAo56aiOYVvPG6E8+HNEZjoZ+DQXt7+nEMSLAwlgP4qkalEvRQBxT8cl1VRyrUr/5BqK9Y X-Received: by 2002:a05:6402:298b:b0:435:20fd:d65d with SMTP id eq11-20020a056402298b00b0043520fdd65dmr12221704edb.190.1656003606986; Thu, 23 Jun 2022 10:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656003606; cv=none; d=google.com; s=arc-20160816; b=VgadvIL9AnexpeF0JLN+YPes6VdQApLDsFob6+jFl59Y30wfsYHRhYMx59ATwA0O1S LEOColdoQnN1mZnhQGMmAb46djuKUDs42EkXfM0QnSYRVTRPDUerYWprsb8sZbLPWBF7 gtW+h7dCJ4Aq/Z2Q4aikdcfkhbYUMz2bl42SKyXdjpATQ5yuC969HEQbpH3CBlWM2HXa Fq52K2+olw5UcI0BeNGWkwrDfrdDIvuJCiCXQM/v8EZYlUc8FQs0ZlOJLmiPW/sHLbwC ghYBzU63TUY9Q/5Kfh9dJUluPPpIxPoO9oNAir5uamTq+3eBF/jWUktvK5ilKR68VVIT 7cTw== 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=2KO2nVmRzMT1KIADL+bg8sIvB864lwKqPXAhiWr9HaY=; b=iO4+lTqCyxwgHZS2ubbU9jJWzEnZufQRBqwRvx5kvqzFrTbT4VqBwakKRgfASws2sf BeazTzXUm+zeDR0/yBoaC1oKl43zQk0mstq4K+buhUTHGf5iBmPvc9IoL9zvPshWCv/g efl0TrILQxRTfEGalYnQ0iiqnvkyxOJQ9M3SzHOQmhUJw+rf1l50UiHOUfrqnTeUh+gw rH7qp3LS6iKYAHrDx8bW5HSrDNdMuaTvrJBQ1zhE2d8qs+xZnW3gNNMADsl9A7BAaFDd nJhhl2RdV74qFqYY7TY+4QNYeG8fiKd2Ii4dnZ/TszMbPIgSkL56gqB/xp7qYIWEOf0V h6vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q63w84Jm; 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 r25-20020a50d699000000b0042dd4a736aesi125142edi.108.2022.06.23.09.59.37; Thu, 23 Jun 2022 10:00:06 -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=q63w84Jm; 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 S232919AbiFWQ5P (ORCPT + 99 others); Thu, 23 Jun 2022 12:57:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233732AbiFWQvc (ORCPT ); Thu, 23 Jun 2022 12:51:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 605AF4BFEC; Thu, 23 Jun 2022 09:49:35 -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 946BFB8248E; Thu, 23 Jun 2022 16:49:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0DA4C3411B; Thu, 23 Jun 2022 16:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656002972; bh=m+4I8Wt7LY4EGLT+WjU98XGZ8KiRB/EpIDEz6vD3vKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q63w84JmQYXhAv1pt/AQNDVuh2s3DYjdzfHhS1cMf36mjHz6BJyoy1mYRNXvt5uZa kBA3Sq7RGEa53bngBw1IvIzrcG/h+/FBYV9AbtvDNr18tlcNKms5pNyCFavpZDkm5S 1TtwP+ItgUtqExKjsMJbwvEpn8jP+TdfdgR5imaw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sebastian Andrzej Siewior , Keerthy , Stephen Boyd , Herbert Xu , "Jason A. Donenfeld" Subject: [PATCH 4.9 046/264] random: Use wait_event_freezable() in add_hwgenerator_randomness() Date: Thu, 23 Jun 2022 18:40:39 +0200 Message-Id: <20220623164345.372822842@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 59b569480dc8bb9dce57cdff133853a842dfd805 upstream. Sebastian reports that after commit ff296293b353 ("random: Support freezable kthreads in add_hwgenerator_randomness()") we can call might_sleep() when the task state is TASK_INTERRUPTIBLE (state=1). This leads to the following warning. do not call blocking ops when !TASK_RUNNING; state=1 set at [<00000000349d1489>] prepare_to_wait_event+0x5a/0x180 WARNING: CPU: 0 PID: 828 at kernel/sched/core.c:6741 __might_sleep+0x6f/0x80 Modules linked in: CPU: 0 PID: 828 Comm: hwrng Not tainted 5.3.0-rc7-next-20190903+ #46 RIP: 0010:__might_sleep+0x6f/0x80 Call Trace: kthread_freezable_should_stop+0x1b/0x60 add_hwgenerator_randomness+0xdd/0x130 hwrng_fillfn+0xbf/0x120 kthread+0x10c/0x140 ret_from_fork+0x27/0x50 We shouldn't call kthread_freezable_should_stop() from deep within the wait_event code because the task state is still set as TASK_INTERRUPTIBLE instead of TASK_RUNNING and kthread_freezable_should_stop() will try to call into the freezer with the task in the wrong state. Use wait_event_freezable() instead so that it calls schedule() in the right place and tries to enter the freezer when the task state is TASK_RUNNING instead. Reported-by: Sebastian Andrzej Siewior Tested-by: Sebastian Andrzej Siewior Cc: Keerthy Fixes: ff296293b353 ("random: Support freezable kthreads in add_hwgenerator_randomness()") 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 | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -327,6 +327,7 @@ #include #include #include +#include #include #include #include @@ -2473,7 +2474,6 @@ 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); @@ -2484,13 +2484,11 @@ 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_freezable_should_stop(&frozen) || + wait_event_freezable(random_write_wait, + kthread_should_stop() || ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits); - if (!frozen) { - mix_pool_bytes(poolp, buffer, count); - credit_entropy_bits(poolp, entropy); - } + mix_pool_bytes(poolp, buffer, count); + credit_entropy_bits(poolp, entropy); } EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);