Received: by 10.223.176.46 with SMTP id f43csp3331524wra; Mon, 22 Jan 2018 12:15:23 -0800 (PST) X-Google-Smtp-Source: AH8x2242U2jRT6GL6S7S318G9GsX7KVkmJxnbXbArm70OoG3BGmqlB4sMkIPgxL+gCmCpkIxst7J X-Received: by 10.107.144.197 with SMTP id s188mr136230iod.92.1516652123676; Mon, 22 Jan 2018 12:15:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516652123; cv=none; d=google.com; s=arc-20160816; b=bpbBa/I1bR831IHQqqeP4N5j3UA27DlaDgoACEY7TBw1k4q9qoafG4vdzZ8yquqoOL FQyjm+5CkhmbtC7YE6/XHxJ5gMCo+fxIlDx2m/2w9l0Ro7GCx8sJFYdVa2EmUZMEKpEY n+HN0HMqNAcah3+6Fd7XtXcutxIWCp7g9KW6sOr/ZA2JKOHHTqfz6UaSeORK5O3P6tP5 XuNM+6fMmIooHbCDibWtaSxTaaBnFLlJaSHfFSPgVTIlMACJY6xMqjvzfFN7IWOOXIZ/ 0GVWWcKl46dg1PJGCVfkPgoZ975f0nlTXDm+fqKR4KJ6RBbA+U2RDWKksJRfMeBFYbR/ V9uQ== 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=sMt1hQnDMCBXBOg4c0RF3H6iC4QIE49ewPJc6qxfVH6ZFTwE0/AcnkJ4DMxFKGdYlw HLwICTLJDzQ8MSMugmtMbNhi6kAQi7554BohkrtITUJFK9RqPlCpuQionvvfZzylqjtJ UvHg2KH7N3ldbeDK8dc+TzqjdsvwsM2ONJSuIJZkjt7Uz+6eXcLwfg5xM9QPWB+aQehs ll4TOoU5Yvq2pUjrPtYTPGIfgDMHWcrjO06Np3GBA+HFD8iG7EWCVYCLQ0jYVVOe7fh/ VpB0OCPrr5rOR8z2cTakp/QNoCptT4dHexvx5nF1AryfhMUjLSX/pl1Ckc54p9cbn+Zz o3VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Vc0yGfzJ; 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 j9si6194427ioo.247.2018.01.22.12.15.10; Mon, 22 Jan 2018 12:15:23 -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=Vc0yGfzJ; 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 S1752023AbeAVUOt (ORCPT + 99 others); Mon, 22 Jan 2018 15:14:49 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:51103 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751995AbeAVUOp (ORCPT ); Mon, 22 Jan 2018 15:14:45 -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=Vc0yGfzJwLhpt280RSd++zceP 6BQ4Si1GkyK2MmrgtTHY4qydPVGkcsv8v0UNQV8iFudhCY5klEc38gsuPz5fK4lWFNzZ4U+Ucdww4 gsXRzRQZk+SKFkUuQbmfv4N6bTePjnY1ijo2UQcVq0JeMntdjaVbk9ESQ+A5AxSkZM1ScO+UfbloP aNQLuB95EhEYrzSRZLqFArtkaAUdN/lMihm9JH1zPQkElC+CMAc/utjwgLOsWCnZo4oXx8Hqa9OWV dYB7puv2BkKOJtSRyREOCt5Vdzoj8PHoz4QFW2d7JHKHlf3LG7Tp1zYM02CX/zBOQ+B9fiw7Pa94X rQGdf5fQw==; Received: from 178.114.226.247.wireless.dyn.drei.com ([178.114.226.247] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1ediUM-00080f-Kx; Mon, 22 Jan 2018 20:14:43 +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: Mon, 22 Jan 2018 21:12:43 +0100 Message-Id: <20180122201243.31610-37-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180122201243.31610-1-hch@lst.de> References: <20180122201243.31610-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