aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2016-09-08 07:48:06 -0400
committerKees Cook <keescook@chromium.org>2016-09-08 18:00:47 -0400
commitd5a9bf0b38d2ac85c9a693c7fb851f74fd2a2494 (patch)
tree223697a08dc1c7209ed40545bb5561ca4c23c6dc
parent4407de74df18ed405cc5998990004c813ccfdbde (diff)
pstore/core: drop cmpxchg based updates
I have here a FPGA behind PCIe which exports SRAM which I use for pstore. Now it seems that the FPGA no longer supports cmpxchg based updates and writes back 0xff…ff and returns the same. This leads to crash during crash rendering pstore useless. Since I doubt that there is much benefit from using cmpxchg() here, I am dropping this atomic access and use the spinlock based version. Cc: Anton Vorontsov <anton@enomsg.org> Cc: Colin Cross <ccross@android.com> Cc: Kees Cook <keescook@chromium.org> Cc: Tony Luck <tony.luck@intel.com> Cc: Rabin Vincent <rabinv@axis.com> Tested-by: Rabin Vincent <rabinv@axis.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Reviewed-by: Guenter Roeck <linux@roeck-us.net> [kees: remove "_locked" suffix since it's the only option now] Signed-off-by: Kees Cook <keescook@chromium.org> Cc: stable@vger.kernel.org
-rw-r--r--fs/pstore/ram_core.c43
1 files changed, 2 insertions, 41 deletions
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index 76c3f80efdfa..9cc6efe0b785 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -47,43 +47,10 @@ static inline size_t buffer_start(struct persistent_ram_zone *prz)
47 return atomic_read(&prz->buffer->start); 47 return atomic_read(&prz->buffer->start);
48} 48}
49 49
50/* increase and wrap the start pointer, returning the old value */
51static size_t buffer_start_add_atomic(struct persistent_ram_zone *prz, size_t a)
52{
53 int old;
54 int new;
55
56 do {
57 old = atomic_read(&prz->buffer->start);
58 new = old + a;
59 while (unlikely(new >= prz->buffer_size))
60 new -= prz->buffer_size;
61 } while (atomic_cmpxchg(&prz->buffer->start, old, new) != old);
62
63 return old;
64}
65
66/* increase the size counter until it hits the max size */
67static void buffer_size_add_atomic(struct persistent_ram_zone *prz, size_t a)
68{
69 size_t old;
70 size_t new;
71
72 if (atomic_read(&prz->buffer->size) == prz->buffer_size)
73 return;
74
75 do {
76 old = atomic_read(&prz->buffer->size);
77 new = old + a;
78 if (new > prz->buffer_size)
79 new = prz->buffer_size;
80 } while (atomic_cmpxchg(&prz->buffer->size, old, new) != old);
81}
82
83static DEFINE_RAW_SPINLOCK(buffer_lock); 50static DEFINE_RAW_SPINLOCK(buffer_lock);
84 51
85/* increase and wrap the start pointer, returning the old value */ 52/* increase and wrap the start pointer, returning the old value */
86static size_t buffer_start_add_locked(struct persistent_ram_zone *prz, size_t a) 53static size_t buffer_start_add(struct persistent_ram_zone *prz, size_t a)
87{ 54{
88 int old; 55 int old;
89 int new; 56 int new;
@@ -103,7 +70,7 @@ static size_t buffer_start_add_locked(struct persistent_ram_zone *prz, size_t a)
103} 70}
104 71
105/* increase the size counter until it hits the max size */ 72/* increase the size counter until it hits the max size */
106static void buffer_size_add_locked(struct persistent_ram_zone *prz, size_t a) 73static void buffer_size_add(struct persistent_ram_zone *prz, size_t a)
107{ 74{
108 size_t old; 75 size_t old;
109 size_t new; 76 size_t new;
@@ -124,9 +91,6 @@ exit:
124 raw_spin_unlock_irqrestore(&buffer_lock, flags); 91 raw_spin_unlock_irqrestore(&buffer_lock, flags);
125} 92}
126 93
127static size_t (*buffer_start_add)(struct persistent_ram_zone *, size_t) = buffer_start_add_atomic;
128static void (*buffer_size_add)(struct persistent_ram_zone *, size_t) = buffer_size_add_atomic;
129
130static void notrace persistent_ram_encode_rs8(struct persistent_ram_zone *prz, 94static void notrace persistent_ram_encode_rs8(struct persistent_ram_zone *prz,
131 uint8_t *data, size_t len, uint8_t *ecc) 95 uint8_t *data, size_t len, uint8_t *ecc)
132{ 96{
@@ -426,9 +390,6 @@ static void *persistent_ram_iomap(phys_addr_t start, size_t size,
426 return NULL; 390 return NULL;
427 } 391 }
428 392
429 buffer_start_add = buffer_start_add_locked;
430 buffer_size_add = buffer_size_add_locked;
431
432 if (memtype) 393 if (memtype)
433 va = ioremap(start, size); 394 va = ioremap(start, size);
434 else 395 else