Received: by 10.223.148.5 with SMTP id 5csp6270005wrq; Wed, 17 Jan 2018 11:30:50 -0800 (PST) X-Google-Smtp-Source: ACJfBou+skg2OILGLQGN9cB5XekbA+ci+XaXsQLfWtx8GneqtsxQzfnWQLQtg++Kc6Lm2gxonqEt X-Received: by 10.84.217.217 with SMTP id d25mr35864098plj.312.1516217450211; Wed, 17 Jan 2018 11:30:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516217450; cv=none; d=google.com; s=arc-20160816; b=nvbmh5WpzV9GPT98FlIgXwmCKCuEYFsAxWabTdE3XPsitep2Z5oRGT7B/+hDqwX49F Sqd/yHgReU29SvWF3dJJpP9y/iRhyGvKf++ou83K1wBNMOqoi+MUZFAT6ttpHYglBhJb o4iYnTCCqsL3DQE3MJSOh3TOxmV1YhhHlgRWsXQVzaVGWuLTnaCn/1DvNcaROFOkrqA9 lqBQP09hiiAskaBlGcdalxDNdE40Q0rFFbXKb5BdREx5rNj39ecvuSwLVK5hgQhHhRJv tnhovgxB75YgznC39JRlHFQedFj3ZqfWApYzjzCFTSs6SOhySPGS1daqrJBF/0Xhao9e 3Vcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=qKQ3OG2laRWATMnG4Wd6fI4pVYpXE5lzQYlSl23cN4Y=; b=WnxLsHJ5bWXzOoJ1kn1QhlAPveRcXK7zugi0rAnXnUhX/q55DGcLzh0Qnl5t+LTlGd Wpbw0hpmViIy8J4D4o6DhsBjTvrftC+7BpzYa7zP9+0kiqY8a16gmYRkfkCfoFdoWVMe UgOnKH0WnTAqKW3ctjYKKLbA/DpLrldCpIggD4EfG7Tv8uHvarNyC/CkQ5NPt9g+oklZ IONz2arXr7ouBev7BZNefrLTGUozjFDQVfJ6rXuaJmv74Kpq4Acuws4Ay6oD0tD3rjxi 2ov0CegVP+gcesf/O6JckdWEeNYxdgwNm4cgHXcBS74i2M4FSPKRKBdEtpsqYLoucDm4 J/hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=oIWvddtX; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w20si5023307plp.257.2018.01.17.11.30.36; Wed, 17 Jan 2018 11:30:50 -0800 (PST) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=oIWvddtX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932287AbeAQT36 (ORCPT + 99 others); Wed, 17 Jan 2018 14:29:58 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:50501 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932206AbeAQT3y (ORCPT ); Wed, 17 Jan 2018 14:29:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qKQ3OG2laRWATMnG4Wd6fI4pVYpXE5lzQYlSl23cN4Y=; b=oIWvddtXHMaFvodu2JtUe2n7D Sm4jn2lH1ccQL3r8UTglueTGn7R4NS736KmW6PsZO5UkXMC4qTlUmSupsVk5Si6FRZqL8EX63cguq b+doRKtPtij/NgZ85Q8IDo+wYvmekg74t00jNkdHuy6Qq30akxUjbisf/tARBH/m4+ad3ofqCqgcx Su0P3tZNo6Snc0AKVBvks7pNCOFS+jJ0hHpDs6aPTR1FesaZaPC2ypDB0EyERReA/3Rg3sfHIbfwf Hab+C7t9fM9lP+uy3w3ja6MtwS7sj0sDfaGw/Ce1yAUv6Z0EQAVegxNMtULmhGxcKVAzrZnskEZEr yn8qe80Gg==; Received: from 77.117.185.35.wireless.dyn.drei.com ([77.117.185.35] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1ebtPE-0003TN-VV; Wed, 17 Jan 2018 19:29:53 +0000 From: Christoph Hellwig To: viro@zeniv.linux.org.uk Cc: Avi Kivity , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 36/36] random: convert to ->poll_mask Date: Wed, 17 Jan 2018 20:27:42 +0100 Message-Id: <20180117192742.710-37-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180117192742.710-1-hch@lst.de> References: <20180117192742.710-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The big change is that random_read_wait and random_write_wait are merged into a single waitqueue that uses keyed wakeups. Because wait_event_* doesn't know about that this will lead to occassional spurious wakeups in _random_read and add_hwgenerator_randomness, but wait_event_* is designed to handle these and were are not in a a hot path there. Signed-off-by: Christoph Hellwig --- drivers/char/random.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 64b59562c872..9a1b85928de3 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -401,8 +401,7 @@ static struct poolinfo { /* * Static global variables */ -static DECLARE_WAIT_QUEUE_HEAD(random_read_wait); -static DECLARE_WAIT_QUEUE_HEAD(random_write_wait); +static DECLARE_WAIT_QUEUE_HEAD(random_wait); static struct fasync_struct *fasync; static DEFINE_SPINLOCK(random_ready_list_lock); @@ -710,7 +709,7 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits) /* should we wake readers? */ if (entropy_bits >= random_read_wakeup_bits) { - wake_up_interruptible(&random_read_wait); + wake_up_interruptible_poll(&random_wait, POLLIN); kill_fasync(&fasync, SIGIO, POLL_IN); } /* If the input pool is getting full, send some @@ -1293,7 +1292,7 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min, trace_debit_entropy(r->name, 8 * ibytes); if (ibytes && (r->entropy_count >> ENTROPY_SHIFT) < random_write_wakeup_bits) { - wake_up_interruptible(&random_write_wait); + wake_up_interruptible_poll(&random_wait, POLLOUT); kill_fasync(&fasync, SIGIO, POLL_OUT); } @@ -1748,7 +1747,7 @@ _random_read(int nonblock, char __user *buf, size_t nbytes) if (nonblock) return -EAGAIN; - wait_event_interruptible(random_read_wait, + wait_event_interruptible(random_wait, ENTROPY_BITS(&input_pool) >= random_read_wakeup_bits); if (signal_pending(current)) @@ -1784,14 +1783,17 @@ urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) return ret; } +static struct wait_queue_head * +random_get_poll_head(struct file *file, __poll_t events) +{ + return &random_wait; +} + static __poll_t -random_poll(struct file *file, poll_table * wait) +random_poll_mask(struct file *file, __poll_t events) { - __poll_t mask; + __poll_t mask = 0; - poll_wait(file, &random_read_wait, wait); - poll_wait(file, &random_write_wait, wait); - mask = 0; if (ENTROPY_BITS(&input_pool) >= random_read_wakeup_bits) mask |= POLLIN | POLLRDNORM; if (ENTROPY_BITS(&input_pool) < random_write_wakeup_bits) @@ -1890,7 +1892,8 @@ static int random_fasync(int fd, struct file *filp, int on) const struct file_operations random_fops = { .read = random_read, .write = random_write, - .poll = random_poll, + .get_poll_head = random_get_poll_head, + .poll_mask = random_poll_mask, .unlocked_ioctl = random_ioctl, .fasync = random_fasync, .llseek = noop_llseek, @@ -2223,7 +2226,7 @@ void add_hwgenerator_randomness(const char *buffer, size_t count, * 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_wait, kthread_should_stop() || ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits); mix_pool_bytes(poolp, buffer, count); credit_entropy_bits(poolp, entropy); -- 2.14.2