From 77418921649427577143667fcf00ccb8a809762a Mon Sep 17 00:00:00 2001 From: Thomas Meyer Date: Sat, 1 Jun 2013 11:40:02 +0200 Subject: efi, pstore: Cocci spatch "memdup.spatch" Change a kmalloc() + memcpy() pair for a single kmemdup() call. Signed-off-by: Thomas Meyer Acked-by: Kees Cook Signed-off-by: Tony Luck diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c index 202d2c8..c692bb6 100644 --- a/drivers/firmware/efi/efi-pstore.c +++ b/drivers/firmware/efi/efi-pstore.c @@ -79,10 +79,9 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data) &entry->var.DataSize, entry->var.Data); size = entry->var.DataSize; - *cb_data->buf = kmalloc(size, GFP_KERNEL); + *cb_data->buf = kmemdup(entry->var.Data, size, GFP_KERNEL); if (*cb_data->buf == NULL) return -ENOMEM; - memcpy(*cb_data->buf, entry->var.Data, size); return size; } -- cgit v0.10.2 From 0405a5cec3406f19e69da07c8111a6bf1088ac29 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Mon, 8 Apr 2013 20:23:33 -0500 Subject: pstore/ram: avoid atomic accesses for ioremapped regions 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. Signed-off-by: Rob Herring Acked-by: Anton Vorontsov Signed-off-by: Tony Luck diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index 5933732..de272d4 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -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) { @@ -372,6 +419,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; + return ioremap(start, size); } -- cgit v0.10.2 From 26446654584c096e23dbe5a9b3f641edf9190c9d Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Mon, 8 Apr 2013 20:23:12 -0500 Subject: pstore/ram: remove the power of buffer size limitation There doesn't appear to be any reason for the overall pstore RAM buffer to be a power of 2 size, so remove it. The individual console, ftrace and oops buffers are still a power of 2 size. Signed-off-by: Rob Herring Acked-by: Anton Vorontsov Signed-off-by: Tony Luck diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 1376e5a..43abee2 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -399,8 +399,6 @@ static int ramoops_probe(struct platform_device *pdev) goto fail_out; } - if (!is_power_of_2(pdata->mem_size)) - pdata->mem_size = rounddown_pow_of_two(pdata->mem_size); if (!is_power_of_2(pdata->record_size)) pdata->record_size = rounddown_pow_of_two(pdata->record_size); if (!is_power_of_2(pdata->console_size)) -- cgit v0.10.2 From bf2883339a33b7544b92ea465b90c3de55082032 Mon Sep 17 00:00:00 2001 From: Aruna Balakrishnaiah Date: Tue, 25 Jun 2013 14:33:56 +0530 Subject: pstore: Fail to unlink if a driver has not defined pstore_erase pstore_erase is used to erase the record from the persistent store. So if a driver has not defined pstore_erase callback return -EPERM instead of unlinking a file as deleting the file without erasing its record in persistent store will give a wrong impression to customers. Signed-off-by: Aruna Balakrishnaiah Acked-by: Kees Cook Signed-off-by: Tony Luck diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index e4bcb2c..bfd95bf 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -178,6 +178,8 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry) if (p->psi->erase) p->psi->erase(p->type, p->id, p->count, dentry->d_inode->i_ctime, p->psi); + else + return -EPERM; return simple_unlink(dir, dentry); } -- cgit v0.10.2 From 8e48b1a8ed58595c40f2748c0f2da55b04da2dd6 Mon Sep 17 00:00:00 2001 From: Lenny Szubowicz Date: Fri, 28 Jun 2013 17:11:33 -0400 Subject: pstore: Return unique error if backend registration excluded by kernel param This is patch 1/3 of a patch set that avoids what misleadingly appears to be a error during boot: ERST: Could not register with persistent store This message is displayed if the system has a valid ACPI ERST table and the pstore.backend kernel parameter has been used to disable use of ERST by pstore. But this same message is used for errors that preclude registration. As part of fixing this, return a unique error status from pstore_register if the pstore.backend kernel parameter selects a specific facility other than the requesting facility and check for this condition before any others. This allows the caller to distinquish this benign case from the other failure cases. Also, print an informational console message about which facility successfully registered as the pstore backend. Since there are various kernel parameters, config build options, and boot-time errors that can influence which facility registers with pstore, it's useful to have a positive indication. Signed-off-by: Lenny Szubowicz Reported-by: Naotaka Hamaguchi Signed-off-by: Tony Luck diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 86d1038..b7ffe2b 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -239,17 +239,15 @@ int pstore_register(struct pstore_info *psi) { struct module *owner = psi->owner; + if (backend && strcmp(backend, psi->name)) + return -EPERM; + spin_lock(&pstore_lock); if (psinfo) { spin_unlock(&pstore_lock); return -EBUSY; } - if (backend && strcmp(backend, psi->name)) { - spin_unlock(&pstore_lock); - return -EINVAL; - } - if (!psi->write) psi->write = pstore_write_compat; psinfo = psi; @@ -274,6 +272,9 @@ int pstore_register(struct pstore_info *psi) add_timer(&pstore_timer); } + pr_info("pstore: Registered %s as persistent store backend\n", + psi->name); + return 0; } EXPORT_SYMBOL_GPL(pstore_register); -- cgit v0.10.2 From 74fd6c6f84b6d3e57bacb06161451c29949fbe51 Mon Sep 17 00:00:00 2001 From: Lenny Szubowicz Date: Fri, 28 Jun 2013 16:14:10 -0400 Subject: acpi: Eliminate console msg if pstore.backend excludes ERST This is patch 2/3 of a patch set that avoids what misleadingly appears to be a error during boot: ERST: Could not register with persistent store This message is displayed if the system has a valid ACPI ERST table and the pstore.backend kernel parameter has been used to disable use of ERST by pstore. But this same message is used for errors that preclude registration. In erst_init don't complain if the setting of kernel parameter pstore.backend precludes use of ACPI ERST for pstore. Routine pstore_register will inform about the facility that does register. Also, don't leave a dangling pointer to deallocated mem for the pstore buffer when registration fails. Signed-off-by: Lenny Szubowicz Reported-by: Naotaka Hamaguchi Signed-off-by: Tony Luck diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c index 6d894bf..f7b3b39 100644 --- a/drivers/acpi/apei/erst.c +++ b/drivers/acpi/apei/erst.c @@ -1180,20 +1180,28 @@ static int __init erst_init(void) if (!erst_erange.vaddr) goto err_release_erange; + pr_info(ERST_PFX + "Error Record Serialization Table (ERST) support is initialized.\n"); + buf = kmalloc(erst_erange.size, GFP_KERNEL); spin_lock_init(&erst_info.buf_lock); if (buf) { erst_info.buf = buf + sizeof(struct cper_pstore_record); erst_info.bufsize = erst_erange.size - sizeof(struct cper_pstore_record); - if (pstore_register(&erst_info)) { - pr_info(ERST_PFX "Could not register with persistent store\n"); + rc = pstore_register(&erst_info); + if (rc) { + if (rc != -EPERM) + pr_info(ERST_PFX + "Could not register with persistent store\n"); + erst_info.buf = NULL; + erst_info.bufsize = 0; kfree(buf); } - } - - pr_info(ERST_PFX - "Error Record Serialization Table (ERST) support is initialized.\n"); + } else + pr_err(ERST_PFX + "Failed to allocate %lld bytes for persistent store error log\n", + erst_erange.size); return 0; -- cgit v0.10.2 From 0d838347f1325cebfe8b9341a4b4c1f407022231 Mon Sep 17 00:00:00 2001 From: Lenny Szubowicz Date: Fri, 28 Jun 2013 16:14:11 -0400 Subject: efivars: If pstore_register fails, free unneeded pstore buffer This is patch 3/3 of a patch set that cleans up pstore_register failure paths. If efivars fails to register with pstore, there is no point to keeping the 4 KB buffer around. It's only used by the pstore read/write routines. Signed-off-by: Lenny Szubowicz Reported-by: Naotaka Hamaguchi Signed-off-by: Tony Luck diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c index c692bb6..91864ad 100644 --- a/drivers/firmware/efi/efi-pstore.c +++ b/drivers/firmware/efi/efi-pstore.c @@ -235,7 +235,11 @@ static __init int efivars_pstore_init(void) efi_pstore_info.bufsize = 1024; spin_lock_init(&efi_pstore_info.buf_lock); - pstore_register(&efi_pstore_info); + if (pstore_register(&efi_pstore_info)) { + kfree(efi_pstore_info.buf); + efi_pstore_info.buf = NULL; + efi_pstore_info.bufsize = 0; + } return 0; } -- cgit v0.10.2