Skip to content

Commit bc57eda

Browse files
Sebastian Andrzej SiewiorPaolo Abeni
authored andcommitted
ipv6: sr: Use nested-BH locking for hmac_storage
hmac_storage is a per-CPU variable and relies on disabled BH for its locking. Without per-CPU locking in local_bh_disable() on PREEMPT_RT this data structure requires explicit locking. Add a local_lock_t to the data structure and use local_lock_nested_bh() for locking. This change adds only lockdep coverage and does not alter the functional behaviour for !PREEMPT_RT. Cc: David Ahern <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 1c08297 commit bc57eda

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

net/ipv6/seg6_hmac.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@
4040
#include <net/seg6_hmac.h>
4141
#include <linux/random.h>
4242

43-
static DEFINE_PER_CPU(char [SEG6_HMAC_RING_SIZE], hmac_ring);
43+
struct hmac_storage {
44+
local_lock_t bh_lock;
45+
char hmac_ring[SEG6_HMAC_RING_SIZE];
46+
};
47+
48+
static DEFINE_PER_CPU(struct hmac_storage, hmac_storage) = {
49+
.bh_lock = INIT_LOCAL_LOCK(bh_lock),
50+
};
4451

4552
static int seg6_hmac_cmpfn(struct rhashtable_compare_arg *arg, const void *obj)
4653
{
@@ -187,7 +194,8 @@ int seg6_hmac_compute(struct seg6_hmac_info *hinfo, struct ipv6_sr_hdr *hdr,
187194
*/
188195

189196
local_bh_disable();
190-
ring = this_cpu_ptr(hmac_ring);
197+
local_lock_nested_bh(&hmac_storage.bh_lock);
198+
ring = this_cpu_ptr(hmac_storage.hmac_ring);
191199
off = ring;
192200

193201
/* source address */
@@ -212,6 +220,7 @@ int seg6_hmac_compute(struct seg6_hmac_info *hinfo, struct ipv6_sr_hdr *hdr,
212220

213221
dgsize = __do_hmac(hinfo, ring, plen, tmp_out,
214222
SEG6_HMAC_MAX_DIGESTSIZE);
223+
local_unlock_nested_bh(&hmac_storage.bh_lock);
215224
local_bh_enable();
216225

217226
if (dgsize < 0)

0 commit comments

Comments
 (0)