mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/3] pstore: ramoops: fix use of wrong types on 64-bit
@ 2024-05-06 16:02 Ahmad Fatoum
  2024-05-06 16:02 ` [PATCH master 2/3] pstore: fix size of OF fixup memory region Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2024-05-06 16:02 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The kernel struct persistent_ram_buffer uses atomic_t for start and size
members in the persistent_ram_buffer chunk, which are 32-bit always,
unlike resource_size_t that we used in barebox, which is 64-bit when
CONFIG_PHYS_ADDR_T_64BIT=y.

To fix this, we could use either int32_t or atomic_t. To make
synchronization with Linux easier, let's use atomic_t.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/pstore/ram_core.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index 76b8a109be9d..24948d701744 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -14,12 +14,14 @@
 
 #define pr_fmt(fmt) "persistent_ram: " fmt
 
+#include <linux/build_bug.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/rslib.h>
 #include <linux/pstore_ram.h>
 #include <linux/string.h>
+#include <linux/atomic.h>
 #include <stdio.h>
 #include <malloc.h>
 #include <memory.h>
@@ -27,21 +29,22 @@
 
 struct persistent_ram_buffer {
 	uint32_t sig;
-	resource_size_t start;
-	resource_size_t size;
-	uint8_t data[0];
+	atomic_t start;
+	atomic_t size;
+	uint8_t data[];
 };
+static_assert(sizeof(struct persistent_ram_buffer) == 12);
 
 #define PERSISTENT_RAM_SIG (0x43474244) /* DBGC */
 
 static inline size_t buffer_size(struct persistent_ram_zone *prz)
 {
-	return prz->buffer->size;
+	return atomic_read(&prz->buffer->size);
 }
 
 static inline size_t buffer_start(struct persistent_ram_zone *prz)
 {
-	return prz->buffer->start;
+	return atomic_read(&prz->buffer->start);
 }
 
 /* increase and wrap the start pointer, returning the old value */
@@ -50,11 +53,11 @@ static size_t buffer_start_add(struct persistent_ram_zone *prz, size_t a)
 	int old;
 	int new;
 
-	old = prz->buffer->start;
+	old = atomic_read(&prz->buffer->start);
 	new = old + a;
 	while (unlikely(new >= prz->buffer_size))
 		new -= prz->buffer_size;
-	prz->buffer->start = new;
+	atomic_set(&prz->buffer->start, new);
 
 	return old;
 }
@@ -65,14 +68,14 @@ static void buffer_size_add(struct persistent_ram_zone *prz, size_t a)
 	size_t old;
 	size_t new;
 
-	old = prz->buffer->size;
+	old = atomic_read(&prz->buffer->size);
 	if (old == prz->buffer_size)
 		return;
 
 	new = old + a;
 	if (new > prz->buffer_size)
 		new = prz->buffer_size;
-	prz->buffer->size = new;
+	atomic_set(&prz->buffer->size, new);
 }
 
 static void notrace persistent_ram_encode_rs8(struct persistent_ram_zone *prz,
@@ -331,8 +334,8 @@ void persistent_ram_free_old(struct persistent_ram_zone *prz)
 
 void persistent_ram_zap(struct persistent_ram_zone *prz)
 {
-	prz->buffer->start = 0;
-	prz->buffer->size = 0;
+	atomic_set(&prz->buffer->start, 0);
+	atomic_set(&prz->buffer->size, 0);
 	persistent_ram_update_header_ecc(prz);
 }
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-07  7:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-06 16:02 [PATCH master 1/3] pstore: ramoops: fix use of wrong types on 64-bit Ahmad Fatoum
2024-05-06 16:02 ` [PATCH master 2/3] pstore: fix size of OF fixup memory region Ahmad Fatoum
2024-05-06 16:02 ` [PATCH master 3/3] pstore: return -ENOENT when file is missing Ahmad Fatoum
2024-05-07  7:33 ` [PATCH master 1/3] pstore: ramoops: fix use of wrong types on 64-bit Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox