mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 1/3] pstore: ramoops: fix use of wrong types on 64-bit
Date: Mon,  6 May 2024 18:02:44 +0200	[thread overview]
Message-ID: <20240506160246.2198975-1-a.fatoum@pengutronix.de> (raw)

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




             reply	other threads:[~2024-05-06 16:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06 16:02 Ahmad Fatoum [this message]
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

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=20240506160246.2198975-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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