Skip to contentSkip to conversation

several pstore related bugfixs

PATCH In review HuKeping 2 participants 4 messages Jan 28, 2015 – Feb 3, 2015

Subsystems (3)
lore
Share & tools
lore

HuKeping

author
#0 lore raw

v3 cover several pstore related bugfixs

Hi greg,
We want to use pstore on linux 3.10. But we found several bugfixs have not been merged yet. Most of them are obvious and can be cherry-picked cleanly. Would you please apply them to stable 3.10?

v1 -> v2:
- remove d4bf205da618bbd0b038e404d646f14e76915718 which has already been merged
- adjust 0405a5cec3406f19e69da07c8111a6bf1088ac29

v2 -> v3:
- attach commit to pstore/ram: avoid atomic accesses for ioremapped regions

PART 1: patches that can be cleanly applied:

bf2883339a33b7544b92ea465b90c3de55082032
pstore: Fail to unlink if a driver has not defined pstore_erase

c39524e6744284452ef45480d3153bec28960c32
pstore: d_alloc_name() doesn't return an ERR_PTR

57fd835385a043577457a385f28c08be693991bf
pstore: clarify clearing of _read_cnt in ramoops_context

aa9a4a1edfbd3d223af01db833da2f07850bc655
pstore: skip zero size persistent ram buffer in traverse

b0aa931fb84431394d995472d0af2a6c2b61064d
pstore: Fix NULL pointer fault if get NULL prz in ramoops_get_next_prz

PART 2: pathes that should be adjusted:

Rob Herring (1):
pstore/ram: avoid atomic accesses for ioremapped regions

 fs/pstore/ram_core.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 2 deletions(-)

Madper Xie (1):
efi-pstore: Make efi-pstore return a unique id

 drivers/firmware/efi/efi-pstore.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.5.5
author
#1 lore raw

PATCH v3 1/2 pstore/ram: avoid atomic accesses for ioremapped regions

From: Rob Herring <[email protected]>

Commit 0405a5cec3406f19e69da07c8111a6bf1088ac29 upstream.

For persistent RAM outside of main memory, the memory may have limitations on supported accesses. For internal RAM on highbank platform exclusive accesses are not supported and will hang the system. So atomic_cmpxchg cannot be used. This commit uses spinlock protection for buffer size and start updates on ioremapped regions instead.

[hkp: Backported to 3.10: adjust context]
---
 fs/pstore/ram_core.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 2 deletions(-)
fs/pstore/ram_core.c +52 -2
index 6ff9755..bda61a7 100644
@@ -46,7 +46,7 @@ static inline size_t buffer_start(struct persistent_ram_zone *prz)
 }
 
 /* increase and wrap the start pointer, returning the old value */
-static inline size_t buffer_start_add(struct persistent_ram_zone *prz, size_t a)
+static size_t buffer_start_add_atomic(struct persistent_ram_zone *prz, size_t a)
 {
 	int old;
 	int new;
@@ -62,7 +62,7 @@ static inline size_t buffer_start_add(struct persistent_ram_zone *prz, size_t a)
 }
 
 /* increase the size counter until it hits the max size */
-static inline void buffer_size_add(struct persistent_ram_zone *prz, size_t a)
+static void buffer_size_add_atomic(struct persistent_ram_zone *prz, size_t a)
 {
 	size_t old;
 	size_t new;
@@ -78,6 +78,53 @@ static inline void buffer_size_add(struct persistent_ram_zone *prz, size_t a)
 	} while (atomic_cmpxchg(&prz->buffer->size, old, new) != old);
 }
 
+static DEFINE_RAW_SPINLOCK(buffer_lock);
+
+/* increase and wrap the start pointer, returning the old value */
+static size_t buffer_start_add_locked(struct persistent_ram_zone *prz, size_t a)
+{
+	int old;
+	int new;
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&buffer_lock, flags);
+
+	old = atomic_read(&prz->buffer->start);
+	new = old + a;
+	while (unlikely(new > prz->buffer_size))
+		new -= prz->buffer_size;
+	atomic_set(&prz->buffer->start, new);
+
+	raw_spin_unlock_irqrestore(&buffer_lock, flags);
+
+	return old;
+}
+
+/* increase the size counter until it hits the max size */
+static void buffer_size_add_locked(struct persistent_ram_zone *prz, size_t a)
+{
+	size_t old;
+	size_t new;
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&buffer_lock, flags);
+
+	old = atomic_read(&prz->buffer->size);
+	if (old == prz->buffer_size)
+		goto exit;
+
+	new = old + a;
+	if (new > prz->buffer_size)
+		new = prz->buffer_size;
+	atomic_set(&prz->buffer->size, new);
+
+exit:
+	raw_spin_unlock_irqrestore(&buffer_lock, flags);
+}
+
+static size_t (*buffer_start_add)(struct persistent_ram_zone *, size_t) = buffer_start_add_atomic;
+static void (*buffer_size_add)(struct persistent_ram_zone *, size_t) = buffer_size_add_atomic;
+
 static void notrace persistent_ram_encode_rs8(struct persistent_ram_zone *prz,
 	uint8_t *data, size_t len, uint8_t *ecc)
 {
@@ -379,6 +426,9 @@ static void *persistent_ram_iomap(phys_addr_t start, size_t size,
 		return NULL;
 	}
 
+	buffer_start_add = buffer_start_add_locked;
+	buffer_size_add = buffer_size_add_locked;
+
 	if (memtype)
 		va = ioremap(start, size);
 	else
Signature · 1 line
1.8.5.5
author
#2 lore raw

PATCH v3 2/2 efi-pstore: Make efi-pstore return a unique id

In reply to HuKeping

From: Madper Xie <[email protected]>

Commit fdeadb43fdf1e7d5698c027b555c389174548e5a upstream.

Pstore fs expects that backends provide a unique id which could avoid pstore making entries as duplication or denominating entries the same name. So I combine the timestamp, part and count into id.

Cc Seiji Aguchi <[email protected]>
[hkp: Backported to 3.10: adjust context]
---
 drivers/firmware/efi/efi-pstore.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/firmware/efi/efi-pstore.c +13 -5
index 66c0c76..c5163e3 100644
@@ -38,6 +38,12 @@ struct pstore_read_data {
 	char **buf;
 };
 
+static inline u64 generic_id(unsigned long timestamp,
+			     unsigned int part, int count)
+{
+	return (timestamp * 100 + part) * 1000 + count;
+}
+
 static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
 {
 	efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
@@ -56,7 +62,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
 
 	if (sscanf(name, "dump-type%u-%u-%d-%lu",
 		   cb_data->type, &part, &cnt, &time) == 4) {
-		*cb_data->id = part;
+		*cb_data->id = generic_id(time, part, cnt);
 		*cb_data->count = cnt;
 		cb_data->timespec->tv_sec = time;
 		cb_data->timespec->tv_nsec = 0;
@@ -67,7 +73,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
 		 * which doesn't support holding
 		 * multiple logs, remains.
 		 */
-		*cb_data->id = part;
+		*cb_data->id = generic_id(time, part, 0);
 		*cb_data->count = 0;
 		cb_data->timespec->tv_sec = time;
 		cb_data->timespec->tv_nsec = 0;
@@ -185,14 +191,16 @@ static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
 	char name[DUMP_NAME_LEN];
 	efi_char16_t efi_name[DUMP_NAME_LEN];
 	int found, i;
+	unsigned int part;
 
-	sprintf(name, "dump-type%u-%u-%d-%lu", type, (unsigned int)id, count,
-		time.tv_sec);
+	do_div(id, 1000);
+	part = do_div(id, 100);
+	sprintf(name, "dump-type%u-%u-%d-%lu", type, part, count, time.tv_sec);
 
 	for (i = 0; i < DUMP_NAME_LEN; i++)
 		efi_name[i] = name[i];
 
-	edata.id = id;
+	edata.id = part;
 	edata.type = type;
 	edata.count = count;
 	edata.time = time;
Signature · 1 line
1.8.5.5
maintainer
#3 lore raw
In reply to HuKeping
Quoted 34 lines · HuKeping

Hi greg,
We want to use pstore on linux 3.10. But we found several bugfixs have not been merged yet. Most of them are obvious and can be cherry-picked cleanly. Would you please apply them to stable 3.10?

v1 -> v2:
- remove d4bf205da618bbd0b038e404d646f14e76915718 which has already been merged
- adjust 0405a5cec3406f19e69da07c8111a6bf1088ac29

v2 -> v3:
- attach commit to pstore/ram: avoid atomic accesses for ioremapped regions

PART 1: patches that can be cleanly applied:

bf2883339a33b7544b92ea465b90c3de55082032
pstore: Fail to unlink if a driver has not defined pstore_erase

c39524e6744284452ef45480d3153bec28960c32
pstore: d_alloc_name() doesn't return an ERR_PTR

57fd835385a043577457a385f28c08be693991bf
pstore: clarify clearing of _read_cnt in ramoops_context

aa9a4a1edfbd3d223af01db833da2f07850bc655
pstore: skip zero size persistent ram buffer in traverse

b0aa931fb84431394d995472d0af2a6c2b61064d
pstore: Fix NULL pointer fault if get NULL prz in ramoops_get_next_prz

PART 2: pathes that should be adjusted:

Rob Herring (1):
pstore/ram: avoid atomic accesses for ioremapped regions

Quoted 8 lines
 fs/pstore/ram_core.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 2 deletions(-)

Madper Xie (1):
efi-pstore: Make efi-pstore return a unique id

 drivers/firmware/efi/efi-pstore.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

All now applied, along with some of these for 3.14, thanks.

greg k-h