Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4114355ybc; Thu, 14 Nov 2019 22:09:45 -0800 (PST) X-Google-Smtp-Source: APXvYqyrMYl/3Z7MPan7+eeCat3x3fr8236UmgNEcUEBJe5uGfr0BAKUrdR8oEbqlJywTXdl3kyX X-Received: by 2002:a17:906:48b:: with SMTP id f11mr11257392eja.225.1573798185187; Thu, 14 Nov 2019 22:09:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573798185; cv=none; d=google.com; s=arc-20160816; b=N74SB+d1f91l+t4NpGmTA8BZEozhJck4YntTqfll9Ry/KBTFxlJDO0DIkX2sQA4/BH PXjMylz7dDammml2dP2TTl/20fPAyPhzn9FJEG8DLovxHpnP7QricYtOpy7iIdcje+Sb QhqjJn2LnXMPVMZfMHIhBs6eQzVBXNGieBzXNL7tFOsKQwtRIPHnlWrm17ZGuE7rTHhO aS6XFJAHHew1ZyMc0euMebU/J6xbJYY4SfeSTpr/lqUpB+JSMvIVu+9zAplUUnxSYpBM sRIDb0I5nmPmOmN5DY3cB9oTJJHw7nN/pL4EsuSSWQO4CJaMamCRhiNuIuqcpENsg3/R VOXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=+kpYzNZy/4lEvJhoPxmYDmFzeJa45vbXxgeai+FLFG8=; b=tFKLKCt1MWahS56Wt3VY7HV4uQMlFaVW8KaoHXU05adq1z15QrAPDIresH922NhPbk KIWEvXJK6KGVt5EcKk90wG9vZZnPUgr67Kan48sztcLlP9CuRGglQ8UtmDcC/zW7I87L RAKrGbw0ZgNc9ODGuBlWy4nohXdGQfsG/az9VpMXjKaWp3V65Yfe40HzW+xzy9BTxyra 7vIw692g0pwvclgLn5ARhnOlGRc1d1hr4TimEaxtGs1/3ljckCSsySkeWvJLEo0ClicY WIsz7xfMcpAdsnW5CbDZfRIs3NDyJpiia95dpHOtDcJoQLdYuE8mAQQ4NP6opxjO9i9T 4Txg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6si5480676edf.256.2019.11.14.22.09.20; Thu, 14 Nov 2019 22:09:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726182AbfKOGJJ (ORCPT + 99 others); Fri, 15 Nov 2019 01:09:09 -0500 Received: from helcar.hmeau.com ([216.24.177.18]:58092 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725848AbfKOGJJ (ORCPT ); Fri, 15 Nov 2019 01:09:09 -0500 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1iVUmb-0004sE-0W; Fri, 15 Nov 2019 14:08:37 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1iVUmX-000693-CF; Fri, 15 Nov 2019 14:08:33 +0800 Date: Fri, 15 Nov 2019 14:08:33 +0800 From: Herbert Xu To: "Maciej S. Szmigiero" Cc: Theodore Ts'o , Arnd Bergmann , Greg Kroah-Hartman , Sebastian Andrzej Siewior , Keerthy , Stephen Boyd , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] random: Don't freeze in add_hwgenerator_randomness() if stopping kthread Message-ID: <20191115060833.xze5kkq64pxci2la@gondor.apana.org.au> References: <20191110135543.3476097-1-mail@maciej.szmigiero.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191110135543.3476097-1-mail@maciej.szmigiero.name> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Sun, Nov 10, 2019 at 02:55:42PM +0100, Maciej S. Szmigiero wrote: > Since commit 59b569480dc8 > ("random: Use wait_event_freezable() in add_hwgenerator_randomness()") > there is a race in add_hwgenerator_randomness() between freezing and > stopping the calling kthread. > > This commit changed wait_event_interruptible() call with > kthread_freezable_should_stop() as a condition into wait_event_freezable() > with just kthread_should_stop() as a condition to fix a warning that > kthread_freezable_should_stop() might sleep inside the wait. > > wait_event_freezable() ultimately calls __refrigerator() with its > check_kthr_stop argument set to false, which causes it to keep the kthread > frozen even if somebody calls kthread_stop() on it. > > Calling wait_event_freezable() with kthread_should_stop() as a condition > is racy because it doesn't take into account the situation where this > condition becomes true on a kthread marked for freezing only after this > condition has already been checked. > > Calling freezing() should avoid the issue that the commit 59b569480dc8 has > fixed, as it is only a checking function, it doesn't actually do the > freezing. > > add_hwgenerator_randomness() has two post-boot users: in khwrng the > kthread will be frozen anyway by call to kthread_freezable_should_stop() > in its main loop, while its second user (ath9k-hwrng) is not freezable at > all. > > This change allows a VM with virtio-rng loaded to write s2disk image > successfully. > > Fixes: 59b569480dc8 ("random: Use wait_event_freezable() in add_hwgenerator_randomness()") > Signed-off-by: Maciej S. Szmigiero > --- > drivers/char/random.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) Patch applied. Thanks. -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt