From patchwork Mon Jun 13 15:48:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 9173497 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4B0776086B for ; Mon, 13 Jun 2016 15:51:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D77E20223 for ; Mon, 13 Jun 2016 15:51:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 322FF25404; Mon, 13 Jun 2016 15:51:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4473620410 for ; Mon, 13 Jun 2016 15:51:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1424851AbcFMPty (ORCPT ); Mon, 13 Jun 2016 11:49:54 -0400 Received: from imap.thunk.org ([74.207.234.97]:45070 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424680AbcFMPt3 (ORCPT ); Mon, 13 Jun 2016 11:49:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=thunk.org; s=ef5046eb; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Y7re3wlEu7qz4+L6eu53tZeKdCiZmYFYAAoHzLr1PTA=; b=kCh0rFxpuYvDgzEACWzP00bEh447g5+2kpozHr5qT2+zuP6t1dFfAKQVfy7b83BMTASyln7oJhla184TZkJRlLkTMk9iDUptp9U8YERsPHeHIKmh5tuRt5uXM5ExxGNw284EOXpwi/mx5p3Q1ZDgUumE3jxW1NRfeUYgu8TMHO4=; Received: from root (helo=closure.thunk.org) by imap.thunk.org with local-esmtp (Exim 4.84_2) (envelope-from ) id 1bCU73-0005ac-1U; Mon, 13 Jun 2016 15:49:17 +0000 Received: by closure.thunk.org (Postfix, from userid 15806) id 05B2782F5C2; Mon, 13 Jun 2016 11:49:16 -0400 (EDT) From: Theodore Ts'o To: Linux Kernel Developers List Cc: linux-crypto@vger.kernel.org, smueller@chronox.de, herbert@gondor.apana.org.au, andi@firstfloor.org, sandyinchina@gmail.com, jsd@av8n.com, hpa@zytor.com, Theodore Ts'o , stable@kernel.org Subject: [PATCH 1/7] random: initialize the non-blocking pool via add_hwgenerator_randomness() Date: Mon, 13 Jun 2016 11:48:33 -0400 Message-Id: <1465832919-11316-2-git-send-email-tytso@mit.edu> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1465832919-11316-1-git-send-email-tytso@mit.edu> References: <1465832919-11316-1-git-send-email-tytso@mit.edu> X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we have a hardware RNG and are using the in-kernel rngd, we should use this to initialize the non-blocking pool so that getrandom(2) doesn't block unnecessarily. Cc: stable@kernel.org Signed-off-by: Theodore Ts'o --- drivers/char/random.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 0158d3b..4e2627a 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1849,12 +1849,18 @@ void add_hwgenerator_randomness(const char *buffer, size_t count, { struct entropy_store *poolp = &input_pool; - /* Suspend writing if we're above the trickle threshold. - * 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() || + if (unlikely(nonblocking_pool.initialized == 0)) + poolp = &nonblocking_pool; + else { + /* Suspend writing if we're above the trickle + * threshold. 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() || ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits); + } mix_pool_bytes(poolp, buffer, count); credit_entropy_bits(poolp, entropy); }