Add new generic HW RNG core
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Review
Quoted 11 lines · Michael Buesch
...
(quoted diff) +8
-0+static inline +int hwrng_init(struct hwrng *rng) +static inline +void hwrng_cleanup(struct hwrng *rng) +static inline +int hwrng_data_present(struct hwrng *rng) +static inline +int hwrng_data_read(struct hwrng *rng, u32 *data)
Lose the newlines, please.
Quoted 1 line
+static int
rng_dev_open(struct inode *inode, struct file *filp)
Like that.
Quoted 51 lines
(quoted diff) +51
-0+static ssize_t rng_dev_read(struct file *filp, char __user *buf, + size_t size, loff_t *offp) +{ + int have_data; + u32 data; + ssize_t ret = 0; + int i, err = 0; + + while (size) { + err = -ERESTARTSYS; + if (mutex_lock_interruptible(&rng_mutex)) + goto out; + if (!current_rng) { + mutex_unlock(&rng_mutex); + err = -ENODEV; + goto out; + } + have_data = 0; + if (hwrng_data_present(current_rng)) + have_data = hwrng_data_read(current_rng, &data); + mutex_unlock(&rng_mutex); + + err = -EFAULT; + while (have_data && size) { + if (put_user((u8)data, buf++)) + goto out; + size--; + ret++; + have_data--; + data >>= 8; + } + + err = -EAGAIN; + if (filp->f_flags & O_NONBLOCK) + goto out; + + err = -ERESTARTSYS; + if (need_resched()) { + if (schedule_timeout_interruptible(1)) + goto out; + } else { + if (mutex_lock_interruptible(&rng_mutex)) + goto out; + if (!current_rng) { + mutex_unlock(&rng_mutex); + err = -ENODEV; + goto out; + } + for (i = 0; i < 20; i++) { + if (hwrng_data_present(current_rng)) + break;
Review
Quoted 10 lines
(quoted diff) +10
-0+ udelay(10); + } + mutex_unlock(&rng_mutex); + } + if (signal_pending(current)) + goto out; + } +out: + return ret ? : err; +}
What's going on with the need_resched() tricks in there? (Unobvious, needs a comment). From my reading, it'll cause a caller to this function to hang for arbitrary periods of time if something if causing heavy scheduling pressure.
What's the polling of hwrng_data_present() doing in here? (Unobvious, needs a comment).
Review
Quoted 8 lines
(quoted diff) +8
-0+static ssize_t hwrng_attr_current_store(struct class_device *class, + const char *buf, size_t len) +{ + int err; + struct hwrng *rng; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM;
Are the sysfs permissions not adequate?
Quoted 1 line
+MODULE_AUTHOR("The Linux Kernel team");
Mutter. Might as well remove this.
A MAINTAINERS record would be nice.
I will send patches for the following stuff, on top of your current -mm, which has my previous patches applied.
Quoted 11 lines · you
Review
Quoted 8 lines · Michael Buesch
(quoted diff) +8
-0+static inline +int hwrng_init(struct hwrng *rng) +static inline +void hwrng_cleanup(struct hwrng *rng) +static inline +int hwrng_data_present(struct hwrng *rng) +static inline +int hwrng_data_read(struct hwrng *rng, u32 *data)Lose the newlines, please.
No problem.
Quoted 4 lines
What's going on with the
need_resched()tricks in there? (Unobvious, needs a comment). From my reading, it'll cause a caller to this function to hang for arbitrary periods of time if something if causing heavy scheduling pressure.
Yeah, it was like this in the old RNG driver. I would also like to drop it, as I don't see a real advantage from it. But I don't like to drop the hwrng_data_present() polling bit of it, because...
Quoted 2 lines
What's the polling of
hwrng_data_present()doing in here? (Unobvious, needs a comment).
Some HW RNG might require some time between data_reads to gather new entropy. The short polling here makes sure we don't return too early from the syscall. So it reduces syscall overhead. Imagine a device which needs 20usecs between reads to gather new entropy. The first read will succeed and probably only return one byte of entropy. The next attempt to data_present in the while loop will fail and the syscall will return with one byte read. userspace will need to call the syscall for every byte (in this case).
We could, of course, add a variable to struct hwrng that indicates the average needed time a device needs to gather new entropy in most cases. So we could poll for this time instead of the rather random 200usecs.
Quoted 10 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+static ssize_t hwrng_attr_current_store(struct class_device *class, + const char *buf, size_t len) +{ + int err; + struct hwrng *rng; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM;Are the sysfs permissions not adequate?
Will drop this.
Quoted 3 lines
Quoted 1 line
+MODULE_AUTHOR("The Linux Kernel team");
Mutter. Might as well remove this.
Sure. Leftover from the old driver.
Quoted 1 line
A
MAINTAINERSrecord would be nice.
Yes, sir.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [patch 6/9] Add VIA HW RNG driver
Quoted 7 lines · Michael Buesch
Signed-off-by Michael Buesch <[email protected]>Index: hwrng/drivers/char/hw_random/Kconfig
===================================================================
drivers/char/hw_random/Kconfig line 54
Quoted 7 lines
drivers/char/hw_random/Kconfig +4
-0@@ -48,3 +48,16 @@ module will be called geode-rng. If unsure, say Y. + +config HW_RANDOM_VIA + tristate "VIA HW Random Number Generator support" + depends on HW_RANDOM && X86
Perhaps you want X86_32 here.
drivers/char/hw_random/Kconfig line 55
Quoted 1 line
drivers/char/hw_random/Kconfig +1
-0+ if (!cpu_has_xstore)
Because this doesn't exist on x86_64.
Re: [patch 6/9] Add VIA HW RNG driver
Quoted 9 lines · Andrew Morton
Quoted 8 lines · Michael Buesch
Signed-off-by Michael Buesch <[email protected]>Index: hwrng/drivers/char/hw_random/Kconfig
===================================================================drivers/char/hw_random/Kconfig +0
-0@@ -48,3 +48,16 @@ module will be called geode-rng.
Quoted 7 lines
drivers/char/hw_random/Kconfig line 54
Quoted 5 lines
drivers/char/hw_random/Kconfig +4
-0If unsure, say Y. + +config HW_RANDOM_VIA + tristate "VIA HW Random Number Generator support" + depends on HW_RANDOM && X86Perhaps you want
X86_32here.
correct (for now)
Quoted 3 lines
drivers/char/hw_random/Kconfig line 55
Quoted 1 line
drivers/char/hw_random/Kconfig +1
-0+ if (!cpu_has_xstore)Because this doesn't exist on
x86_64.
correct (for now)
Jeff