Re: [PATCH v2] random: unify cycles_t and jiffies usage and types

From: Dominik Brodowski
Date: Fri Feb 25 2022 - 02:06:10 EST


Am Thu, Feb 24, 2022 at 10:30:30PM +0100 schrieb Jason A. Donenfeld:
> @@ -1016,19 +1010,26 @@ struct timer_rand_state {
> */
> void add_device_randomness(const void *buf, size_t size)
> {
> - unsigned long time = random_get_entropy() ^ jiffies;
> - unsigned long flags;
> + cycles_t cycles = random_get_entropy();
> + unsigned long now = jiffies, flags;

maybe "flags, now = jiffies" is a bit more reader-friendly?

> static void add_timer_randomness(struct timer_rand_state *state, unsigned int num)
> {
> - struct {
> - long jiffies;
> - unsigned int cycles;
> - unsigned int num;
> - } sample;
> + cycles_t cycles = random_get_entropy();
> + unsigned long now = jiffies, flags;

Same here.

> @@ -1291,10 +1289,10 @@ static void mix_interrupt_randomness(struct work_struct *work)
> void add_interrupt_randomness(int irq)
> {
> enum { MIX_INFLIGHT = 1U << 31 };
> + cycles_t cycles = random_get_entropy();
> + unsigned long now = jiffies;
> struct fast_pool *fast_pool = this_cpu_ptr(&irq_randomness);
> struct pt_regs *regs = get_irq_regs();
> - unsigned long now = jiffies;
> - cycles_t cycles = random_get_entropy();
> unsigned int new_count;
>
> if (cycles == 0)


Why do you change the ordering here?

Thanks,
Dominik