LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Tom Zanussi <tom.zanussi@linux.intel.com>
To: josh@joshtriplett.org
Cc: linux-kernel@vger.kernel.org, Tom Zanussi <tom.zanussi@linux.intel.com>
Subject: [PATCH 07/10] drivers/char: Support compiling out /dev/random
Date: Fri, 23 Jan 2015 12:37:13 -0600	[thread overview]
Message-ID: <ff386ab25078a3cfabd14714a46a8bedf4dd444f.1422035184.git.tom.zanussi@linux.intel.com> (raw)
In-Reply-To: <cover.1422035184.git.tom.zanussi@linux.intel.com>
In-Reply-To: <cover.1422035184.git.tom.zanussi@linux.intel.com>

Some embedded systems with tightly controlled userspace have no use
for /dev/random, and could benefit from the size savings gained by
omitting it.  Add a new EMBEDDED config option to disable it.

The newly marked __maybe_unused functions, random_write, random_ioctl,
and random_fasync are shared between /dev/random and /dev/urandom, and
will be compiled out if both devices are disabled.

bloat-o-meter (based on tinyconfig):

add/remove: 0/4 grow/shrink: 1/0 up/down: 139/-392 (-253)
function                                     old     new   delta
sys_getrandom                                211     350    +139
random_read                                   20       -     -20
random_poll                                   83       -     -83
random_fops                                  116       -    -116
_random_read.part                            173       -    -173

bloat-o-meter showing the difference between only CONFIG_DEVURANDOM
off and both CONFIG_DEVURANDOM and CONFIG_DEVRANDOM off:

add/remove: 0/8 grow/shrink: 1/0 up/down: 144/-851 (-707)
function                                     old     new   delta
sys_getrandom                                288     432    +144
random_fasync                                 16       -     -16
random_read                                   20       -     -20
random_write                                  42       -     -42
write_pool                                    82       -     -82
random_poll                                   83       -     -83
random_fops                                  116       -    -116
_random_read.part                            173       -    -173
random_ioctl                                 319       -    -319

So we see the extra symbols drop, while _random_read is inlined into
sys_getrandom.

Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
 drivers/char/Kconfig  | 11 +++++++++++
 drivers/char/mem.c    |  2 ++
 drivers/char/random.c | 16 ++++++++++++----
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 62290e0..9416b7e 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -67,6 +67,17 @@ config DEVFULL
 	  never use it in production, such as many embedded systems.
 	  When in doubt, say "Y".
 
+config DEVRANDOM
+	bool "/dev/random virtual device support" if EMBEDDED
+	depends on DEVMEM_BASE
+	default y
+	help
+	  Say Y here if you want to support the /dev/random
+	  device. The /dev/random device is the blocking userspace
+	  interface to the kernel random number generator, and can be
+	  disabled on systems that will never use it in production,
+	  such as many embedded systems.  When in doubt, say "Y".
+
 config SGI_SNSC
 	bool "SGI Altix system controller communication support"
 	depends on (IA64_SGI_SN2 || IA64_GENERIC)
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 5b60003..f226714 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -826,7 +826,9 @@ static const struct memdev {
 #ifdef CONFIG_DEVFULL
 	 [7] = { "full", 0666, &full_fops, NULL },
 #endif
+#ifdef CONFIG_DEVRANDOM
 	 [8] = { "random", 0666, &random_fops, NULL },
+#endif
 	 [9] = { "urandom", 0666, &urandom_fops, NULL },
 #ifdef CONFIG_PRINTK
 	[11] = { "kmsg", 0644, &kmsg_fops, NULL },
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 04645c0..8547056 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1370,11 +1370,13 @@ _random_read(int nonblock, char __user *buf, size_t nbytes)
 	}
 }
 
+#ifdef CONFIG_DEVRANDOM
 static ssize_t
 random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
 {
 	return _random_read(file->f_flags & O_NONBLOCK, buf, nbytes);
 }
+#endif
 
 static ssize_t
 urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
@@ -1394,6 +1396,7 @@ urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
 	return ret;
 }
 
+#ifdef CONFIG_DEVRANDOM
 static unsigned int
 random_poll(struct file *file, poll_table * wait)
 {
@@ -1408,6 +1411,7 @@ random_poll(struct file *file, poll_table * wait)
 		mask |= POLLOUT | POLLWRNORM;
 	return mask;
 }
+#endif
 
 static int
 write_pool(struct entropy_store *r, const char __user *buffer, size_t count)
@@ -1431,8 +1435,9 @@ write_pool(struct entropy_store *r, const char __user *buffer, size_t count)
 	return 0;
 }
 
-static ssize_t random_write(struct file *file, const char __user *buffer,
-			    size_t count, loff_t *ppos)
+static ssize_t __maybe_unused random_write(struct file *file,
+					   const char __user *buffer,
+					   size_t count, loff_t *ppos)
 {
 	size_t ret;
 
@@ -1446,7 +1451,8 @@ static ssize_t random_write(struct file *file, const char __user *buffer,
 	return (ssize_t)count;
 }
 
-static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
+static long __maybe_unused random_ioctl(struct file *f, unsigned int cmd,
+					unsigned long arg)
 {
 	int size, ent_count;
 	int __user *p = (int __user *)arg;
@@ -1498,11 +1504,12 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
 	}
 }
 
-static int random_fasync(int fd, struct file *filp, int on)
+static int __maybe_unused random_fasync(int fd, struct file *filp, int on)
 {
 	return fasync_helper(fd, filp, on, &fasync);
 }
 
+#ifdef CONFIG_DEVRANDOM
 const struct file_operations random_fops = {
 	.read  = random_read,
 	.write = random_write,
@@ -1511,6 +1518,7 @@ const struct file_operations random_fops = {
 	.fasync = random_fasync,
 	.llseek = noop_llseek,
 };
+#endif
 
 const struct file_operations urandom_fops = {
 	.read  = urandom_read,
-- 
1.9.3


  parent reply	other threads:[~2015-01-23 18:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23 18:37 [PATCH 00/10] tinification: Make memory-access char devices optional Tom Zanussi
2015-01-23 18:37 ` [PATCH 01/10] drivers/char: Support compiling out memory-access char devices Tom Zanussi
2015-01-23 18:37 ` [PATCH 02/10] drivers/char: Support compiling out /dev/mem Tom Zanussi
2015-01-23 18:37 ` [PATCH 03/10] drivers/char: Support compiling out /dev/port Tom Zanussi
2015-01-23 18:37 ` [PATCH 04/10] drivers/char: Support compiling out /dev/null Tom Zanussi
2015-01-23 18:37 ` [PATCH 05/10] drivers/char: Support compiling out /dev/zero Tom Zanussi
2015-01-28 21:07   ` Pavel Machek
2015-01-28 21:51     ` josh
2015-01-28 21:52       ` Pavel Machek
2015-01-28 23:20       ` Tom Zanussi
2015-01-31 23:08         ` Josh Triplett
2015-01-23 18:37 ` [PATCH 06/10] drivers/char: Support compiling out /dev/full Tom Zanussi
2015-01-23 18:37 ` Tom Zanussi [this message]
2015-01-23 18:37 ` [PATCH 08/10] drivers/char: Support compiling out /dev/urandom Tom Zanussi
2015-01-23 18:37 ` [PATCH 09/10] drivers/char: Support compiling out /dev/kmsg Tom Zanussi
2015-01-23 18:37 ` [PATCH 10/10] drivers/char: Support compiling out the getrandom(2) syscall Tom Zanussi
2015-01-23 19:46   ` Theodore Ts'o
2015-01-23 20:04     ` Tom Zanussi
2015-01-23 22:30     ` josh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ff386ab25078a3cfabd14714a46a8bedf4dd444f.1422035184.git.tom.zanussi@linux.intel.com \
    --to=tom.zanussi@linux.intel.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH 07/10] drivers/char: Support compiling out /dev/random' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).