Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1701227ybb; Fri, 29 Mar 2019 09:32:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyptDuOHhq5w1FBz3+Gfo4JnmOcK4iFFh7bOc8DbamkQNtNEMmOHqZ05tnMFWmosISB5NtH X-Received: by 2002:a17:902:820c:: with SMTP id x12mr37561744pln.199.1553877154630; Fri, 29 Mar 2019 09:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553877154; cv=none; d=google.com; s=arc-20160816; b=kJQ+WQLzy/Jl8x2Kzgl0EdCpV1GcmYNECPfKUnRj8BVvcML7ZL2tf1J2j+sFvMqmYj Q1bZ8s+LWQ4NeFwYGwH4yRdn8K7yQZeJ895BFaIFEkyZ5jUbc6CtcECbx+iqjuzH4eci 0JzTl2UxplRh9Nh9+3eicYh0J0QVdFm1tXly9t/ahAg1N9gBdJOg6FoUYP6EYpiUnI4v FQFGdAC6qAQCFgl/YCJS+X8ss58Kmw8dksbBNF4pz1W8RnqGexn+0G4/kGjfYX6+Kb2v Gk6i9y41BoPZqn1N/Oj99VAMCw+hWWoNl5/DAgu7rL7r8wVgZQmxPlFNfQpoxSIOwaC3 YqVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=5wVClvFgd3LDEE7FEsLGeVOjrW7iIngATqwcf9oa0Ew=; b=q2RqSYPUv2ALxxYXbAKmx3qDAU9Br4yI7TD0vDVszGdDH7f4VPcx1vlK0Z+prDFqRd sUftCqtYCzjVF/RViYa2uuOpf0NrOd4g14r1J3bxGgRvBzJeQmjtWxms8HA8jhC72vb+ cCk/kQqLuAlaXYkfXJ1u6hAiVhtu/6ko/K5l9tBffaACBFHvscwnGw0WramLvDLmH+fv m+RLbYyaR1nwnpUBW9ku2Gu0zuDlVeJFvtjcTIhC7m+YR1YpysYpnpe/kjOLLo58a5K6 N8jFWPbhFDW+h7Tko/0bfl4jVXk3lR6L8hLRuXSQPXX/y+A6Wu+IcVQ78Z906bAek11i Gyjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 32si2282313pls.415.2019.03.29.09.32.18; Fri, 29 Mar 2019 09:32:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729662AbfC2QaO (ORCPT + 99 others); Fri, 29 Mar 2019 12:30:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54866 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728815AbfC2QaO (ORCPT ); Fri, 29 Mar 2019 12:30:14 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1226E8830C; Fri, 29 Mar 2019 16:30:14 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-116-220.ams2.redhat.com [10.36.116.220]) by smtp.corp.redhat.com (Postfix) with ESMTP id 792501F8; Fri, 29 Mar 2019 16:30:12 +0000 (UTC) From: Laurent Vivier To: linux-kernel@vger.kernel.org Cc: Herbert Xu , linux-crypto@vger.kernel.org, Matt Mackall Subject: [PATCH] hwrng: core - don't block in add_early_randomness() Date: Fri, 29 Mar 2019 17:30:11 +0100 Message-Id: <20190329163011.7370-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 29 Mar 2019 16:30:14 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the device is not ready to provide data the kernel will be stuck indefinitely in the init function. This is not a problem if the device is driven using a module, but if the driver is linked directly into the kernel then the kernel boot sequence hangs. This can happen with virtio-rng device with rng-egd backend with no data provider, for instance with QEMU command line parameters: ... -chardev socket,id=charrng0,host=localhost,port=2345,server,nowait \ -object rng-egd,id=objrng0,chardev=charrng0 \ -device virtio-rng-pci,rng=objrng0,id=rng0 To avoid that, we can call rng_get_data() in non blocking mode because the function already manages the case where byte_read is 0 (if the device is not already initialized). See also commit d3cc7996473a ("hwrng: fetch randomness only after device init") Signed-off-by: Laurent Vivier --- drivers/char/hw_random/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index 95be7228f327..3866d6b8017c 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c @@ -67,7 +67,7 @@ static void add_early_randomness(struct hwrng *rng) size_t size = min_t(size_t, 16, rng_buffer_size()); mutex_lock(&reading_mutex); - bytes_read = rng_get_data(rng, rng_buffer, size, 1); + bytes_read = rng_get_data(rng, rng_buffer, size, 0); mutex_unlock(&reading_mutex); if (bytes_read > 0) add_device_randomness(rng_buffer, bytes_read); -- 2.20.1