Skip to content

Commit 1097044

Browse files
Joel Fernandeskees
Joel Fernandes
authored andcommitted
pstore: Make spinlock per zone instead of global
Currently pstore has a global spinlock for all zones. Since the zones are independent and modify different areas of memory, there's no need to have a global lock, so we should use a per-zone lock as introduced here. Also, when ramoops's ftrace use-case has a FTRACE_PER_CPU flag introduced later, which splits the ftrace memory area into a single zone per CPU, it will eliminate the need for locking. In preparation for this, make the locking optional. Signed-off-by: Joel Fernandes <[email protected]> [kees: updated commit message] Signed-off-by: Kees Cook <[email protected]>
1 parent 959217c commit 1097044

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

fs/pstore/ram_core.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,22 @@ static inline size_t buffer_start(struct persistent_ram_zone *prz)
4848
return atomic_read(&prz->buffer->start);
4949
}
5050

51-
static DEFINE_RAW_SPINLOCK(buffer_lock);
52-
5351
/* increase and wrap the start pointer, returning the old value */
5452
static size_t buffer_start_add(struct persistent_ram_zone *prz, size_t a)
5553
{
5654
int old;
5755
int new;
5856
unsigned long flags;
5957

60-
raw_spin_lock_irqsave(&buffer_lock, flags);
58+
raw_spin_lock_irqsave(&prz->buffer_lock, flags);
6159

6260
old = atomic_read(&prz->buffer->start);
6361
new = old + a;
6462
while (unlikely(new >= prz->buffer_size))
6563
new -= prz->buffer_size;
6664
atomic_set(&prz->buffer->start, new);
6765

68-
raw_spin_unlock_irqrestore(&buffer_lock, flags);
66+
raw_spin_unlock_irqrestore(&prz->buffer_lock, flags);
6967

7068
return old;
7169
}
@@ -77,7 +75,7 @@ static void buffer_size_add(struct persistent_ram_zone *prz, size_t a)
7775
size_t new;
7876
unsigned long flags;
7977

80-
raw_spin_lock_irqsave(&buffer_lock, flags);
78+
raw_spin_lock_irqsave(&prz->buffer_lock, flags);
8179

8280
old = atomic_read(&prz->buffer->size);
8381
if (old == prz->buffer_size)
@@ -89,7 +87,7 @@ static void buffer_size_add(struct persistent_ram_zone *prz, size_t a)
8987
atomic_set(&prz->buffer->size, new);
9088

9189
exit:
92-
raw_spin_unlock_irqrestore(&buffer_lock, flags);
90+
raw_spin_unlock_irqrestore(&prz->buffer_lock, flags);
9391
}
9492

9593
static void notrace persistent_ram_encode_rs8(struct persistent_ram_zone *prz,
@@ -493,6 +491,7 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig,
493491

494492
prz->buffer->sig = sig;
495493
persistent_ram_zap(prz);
494+
prz->buffer_lock = __RAW_SPIN_LOCK_UNLOCKED(buffer_lock);
496495

497496
return 0;
498497
}

include/linux/pstore_ram.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct persistent_ram_zone {
4040
void *vaddr;
4141
struct persistent_ram_buffer *buffer;
4242
size_t buffer_size;
43+
raw_spinlock_t buffer_lock;
4344

4445
/* ECC correction */
4546
char *par_buffer;

0 commit comments

Comments
 (0)