lkml.org 
[lkml]   [2013]   [Nov]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[PATCH 9/9] random: simplify accounting code
    With this we handle "reserved" in just one place.  As a bonus the
    code becomes less nested, and the "wakeup_write" flag variable
    becomes unnecessary. The variable "flags" was already unused.

    This code behaves identically to the previous version except in
    two pathological cases that don't occur. If the argument "nbytes"
    is already less than "min", then we didn't previously enforce
    "min". If r->limit is false while "reserved" is nonzero, then we
    previously applied "reserved" in checking whether we had enough
    bits, even though we don't apply it to actually limit how many we
    take. The callers of account() never exercise either of these cases.

    Before the previous commit, it was possible for "nbytes" to be less
    than "min" if userspace chose a pathological configuration, but no
    longer.

    Cc: "Theodore Ts'o" <tytso@mit.edu>
    Cc: Jiri Kosina <jkosina@suse.cz>
    Cc: "H. Peter Anvin" <hpa@zytor.com>
    Signed-off-by: Greg Price <price@mit.edu>
    ---
    drivers/char/random.c | 27 ++++++++++-----------------
    1 file changed, 10 insertions(+), 17 deletions(-)

    diff --git a/drivers/char/random.c b/drivers/char/random.c
    index 865c8db..87b41b0 100644
    --- a/drivers/char/random.c
    +++ b/drivers/char/random.c
    @@ -968,8 +968,6 @@ static void push_to_pool(struct work_struct *work)
    static size_t account(struct entropy_store *r, size_t nbytes, int min,
    int reserved)
    {
    - unsigned long flags;
    - int wakeup_write = 0;
    int have_bytes;
    int entropy_count, orig;
    size_t ibytes;
    @@ -981,24 +979,19 @@ retry:
    entropy_count = orig = ACCESS_ONCE(r->entropy_count);
    have_bytes = entropy_count >> (ENTROPY_SHIFT + 3);
    ibytes = nbytes;
    - if (have_bytes < min + reserved) {
    + /* If limited, never pull more than available */
    + if (r->limit)
    + ibytes = min_t(size_t, ibytes, have_bytes - reserved);
    + if (ibytes < min)
    ibytes = 0;
    - } else {
    - /* If limited, never pull more than available */
    - if (r->limit)
    - ibytes = min_t(size_t, ibytes, have_bytes - reserved);
    - entropy_count = max_t(int, 0,
    - entropy_count - (ibytes << (ENTROPY_SHIFT + 3)));
    - if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
    - goto retry;
    -
    - if ((r->entropy_count >> ENTROPY_SHIFT)
    - < random_write_wakeup_thresh)
    - wakeup_write = 1;
    - }
    + entropy_count = max_t(int, 0,
    + entropy_count - (ibytes << (ENTROPY_SHIFT + 3)));
    + if (ibytes && cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
    + goto retry;

    trace_debit_entropy(r->name, 8 * ibytes);
    - if (wakeup_write) {
    + if (ibytes &&
    + (r->entropy_count >> ENTROPY_SHIFT) < random_write_wakeup_thresh) {
    wake_up_interruptible(&random_write_wait);
    kill_fasync(&fasync, SIGIO, POLL_OUT);
    }
    --
    1.8.3.2

    \
     
     \ /
      Last update: 2013-11-13 09:41    [W:2.734 / U:0.028 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site