From: Daniel Wagner <wagi@monom.org>
To: LKML <linux-kernel@vger.kernel.org>,
linux-rt-users <linux-rt-users@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
Carsten Emde <C.Emde@osadl.org>, John Kacur <jkacur@redhat.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Tom Zanussi <tom.zanussi@linux.intel.com>,
Clark Williams <williams@redhat.com>,
Pavel Machek <pavel@denx.de>
Cc: Daniel Wagner <dwagner@suse.de>
Subject: [PATCH RT 2/9] random: Bring back the local_locks
Date: Mon, 24 Oct 2022 12:44:18 +0200 [thread overview]
Message-ID: <20221024104425.16423-3-wagi@monom.org> (raw)
In-Reply-To: <20221024104425.16423-1-wagi@monom.org>
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
v4.19.255-rt114-rc1 stable review patch.
If anyone has any objections, please let me know.
-----------
As part of the backports the random code lost its local_lock_t type and
the whole operation became a local_irq_{disable|enable}() simply because
the older kernel did not provide those primitives.
RT as of v4.9 has a slightly different variant of local_locks.
Replace the local_irq_*() operations with matching local_lock_irq*()
operations which were there as part of commit
77760fd7f7ae3 ("random: remove batched entropy locking")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/all/20220819092446.980320-2-bigeasy@linutronix.de/
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
drivers/char/random.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 2be38780a7f7..0fd0462054bd 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -53,6 +53,7 @@
#include <linux/uaccess.h>
#include <linux/siphash.h>
#include <linux/uio.h>
+#include <linux/locallock.h>
#include <crypto/chacha20.h>
#include <crypto/blake2s.h>
#include <asm/processor.h>
@@ -229,10 +230,12 @@ static struct {
struct crng {
u8 key[CHACHA20_KEY_SIZE];
unsigned long generation;
+ struct local_irq_lock lock;
};
static DEFINE_PER_CPU(struct crng, crngs) = {
- .generation = ULONG_MAX
+ .generation = ULONG_MAX,
+ .lock.lock = __SPIN_LOCK_UNLOCKED(crngs.lock.lock),
};
/* Used by crng_reseed() and crng_make_state() to extract a new seed from the input pool. */
@@ -362,7 +365,7 @@ static void crng_make_state(u32 chacha_state[CHACHA20_BLOCK_SIZE / sizeof(u32)],
if (unlikely(crng_has_old_seed()))
crng_reseed();
- local_irq_save(flags);
+ local_lock_irqsave(crngs.lock, flags);
crng = raw_cpu_ptr(&crngs);
/*
@@ -387,7 +390,7 @@ static void crng_make_state(u32 chacha_state[CHACHA20_BLOCK_SIZE / sizeof(u32)],
* should wind up here immediately.
*/
crng_fast_key_erasure(crng->key, chacha_state, random_data, random_data_len);
- local_irq_restore(flags);
+ local_unlock_irqrestore(crngs.lock, flags);
}
static void _get_random_bytes(void *buf, size_t len)
@@ -505,11 +508,13 @@ struct batch_ ##type { \
* formula of (integer_blocks + 0.5) * CHACHA20_BLOCK_SIZE. \
*/ \
type entropy[CHACHA20_BLOCK_SIZE * 3 / (2 * sizeof(type))]; \
+ struct local_irq_lock lock; \
unsigned long generation; \
unsigned int position; \
}; \
\
static DEFINE_PER_CPU(struct batch_ ##type, batched_entropy_ ##type) = { \
+ .lock.lock = __SPIN_LOCK_UNLOCKED(batched_entropy_ ##type.lock.lock), \
.position = UINT_MAX \
}; \
\
@@ -527,7 +532,7 @@ type get_random_ ##type(void) \
return ret; \
} \
\
- local_irq_save(flags); \
+ local_lock_irqsave(batched_entropy_ ##type.lock, flags); \
batch = raw_cpu_ptr(&batched_entropy_##type); \
\
next_gen = READ_ONCE(base_crng.generation); \
@@ -541,7 +546,7 @@ type get_random_ ##type(void) \
ret = batch->entropy[batch->position]; \
batch->entropy[batch->position] = 0; \
++batch->position; \
- local_irq_restore(flags); \
+ local_unlock_irqrestore(batched_entropy_ ##type.lock, flags); \
return ret; \
} \
EXPORT_SYMBOL(get_random_ ##type);
--
2.38.0
next prev parent reply other threads:[~2022-10-24 10:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 10:44 [PATCH RT 0/9] Linux v4.19.255-rt114-rc1 Daniel Wagner
2022-10-24 10:44 ` [PATCH RT 1/9] Revert "random: Use local locks for crng context access" Daniel Wagner
2022-10-24 10:44 ` Daniel Wagner [this message]
2022-10-24 10:44 ` [PATCH RT 3/9] local_lock: Provide INIT_LOCAL_LOCK() Daniel Wagner
2022-10-24 10:44 ` [PATCH RT 4/9] Revert "workqueue: Use local irq lock instead of irq disable regions" Daniel Wagner
2022-10-24 10:44 ` [PATCH RT 5/9] timers: Keep interrupts disabled for TIMER_IRQSAFE timer Daniel Wagner
2022-10-24 10:44 ` [PATCH RT 6/9] timers: Don't block on ->expiry_lock for TIMER_IRQSAFE timers Daniel Wagner
2022-10-24 10:44 ` [PATCH RT 7/9] rcu: Update rcuwait Daniel Wagner
2022-10-24 10:44 ` [PATCH RT 8/9] workqueue: Use rcuwait for wq_manager_wait Daniel Wagner
2022-10-24 10:44 ` [PATCH RT 9/9] Linux 4.19.255-rt114-rc1 Daniel Wagner
2022-10-24 10:54 ` [PATCH RT 0/9] Linux v4.19.255-rt114-rc1 Daniel Wagner
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=20221024104425.16423-3-wagi@monom.org \
--to=wagi@monom.org \
--cc=C.Emde@osadl.org \
--cc=bigeasy@linutronix.de \
--cc=dwagner@suse.de \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=pavel@denx.de \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tom.zanussi@linux.intel.com \
--cc=williams@redhat.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®