Commit 1227daa4 authored by Kees Cook's avatar Kees Cook

pstore/ram: Clarify resource reservation labels

When ramoops reserved a memory region in the kernel, it had an unhelpful
label of "persistent_memory". When reading /proc/iomem, it would be
repeated many times, did not hint that it was ramoops in particular,
and didn't clarify very much about what each was used for:

400000000-407ffffff : Persistent Memory (legacy)
  400000000-400000fff : persistent_memory
  400001000-400001fff : persistent_memory
...
  4000ff000-4000fffff : persistent_memory

Instead, this adds meaningful labels for how the various regions are
being used:

400000000-407ffffff : Persistent Memory (legacy)
  400000000-400000fff : ramoops:dump(0/252)
  400001000-400001fff : ramoops:dump(1/252)
...
  4000fc000-4000fcfff : ramoops:dump(252/252)
  4000fd000-4000fdfff : ramoops:console
  4000fe000-4000fe3ff : ramoops:ftrace(0/3)
  4000fe400-4000fe7ff : ramoops:ftrace(1/3)
  4000fe800-4000febff : ramoops:ftrace(2/3)
  4000fec00-4000fefff : ramoops:ftrace(3/3)
  4000ff000-4000fffff : ramoops:pmsg
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarJoel Fernandes (Google) <joel@joelfernandes.org>
Tested-by: default avatarSai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
Tested-by: default avatarGuenter Roeck <groeck@chromium.org>
parent 95047b05
...@@ -587,9 +587,16 @@ static int ramoops_init_przs(const char *name, ...@@ -587,9 +587,16 @@ static int ramoops_init_przs(const char *name,
goto fail; goto fail;
for (i = 0; i < *cnt; i++) { for (i = 0; i < *cnt; i++) {
char *label;
if (*cnt == 1)
label = kasprintf(GFP_KERNEL, "ramoops:%s", name);
else
label = kasprintf(GFP_KERNEL, "ramoops:%s(%d/%d)",
name, i, *cnt - 1);
prz_ar[i] = persistent_ram_new(*paddr, zone_sz, sig, prz_ar[i] = persistent_ram_new(*paddr, zone_sz, sig,
&cxt->ecc_info, &cxt->ecc_info,
cxt->memtype, flags); cxt->memtype, flags, label);
if (IS_ERR(prz_ar[i])) { if (IS_ERR(prz_ar[i])) {
err = PTR_ERR(prz_ar[i]); err = PTR_ERR(prz_ar[i]);
dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n", dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n",
...@@ -619,6 +626,8 @@ static int ramoops_init_prz(const char *name, ...@@ -619,6 +626,8 @@ static int ramoops_init_prz(const char *name,
struct persistent_ram_zone **prz, struct persistent_ram_zone **prz,
phys_addr_t *paddr, size_t sz, u32 sig) phys_addr_t *paddr, size_t sz, u32 sig)
{ {
char *label;
if (!sz) if (!sz)
return 0; return 0;
...@@ -629,8 +638,9 @@ static int ramoops_init_prz(const char *name, ...@@ -629,8 +638,9 @@ static int ramoops_init_prz(const char *name,
return -ENOMEM; return -ENOMEM;
} }
label = kasprintf(GFP_KERNEL, "ramoops:%s", name);
*prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info, *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info,
cxt->memtype, 0); cxt->memtype, 0, label);
if (IS_ERR(*prz)) { if (IS_ERR(*prz)) {
int err = PTR_ERR(*prz); int err = PTR_ERR(*prz);
......
...@@ -433,11 +433,11 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size, ...@@ -433,11 +433,11 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
} }
static void *persistent_ram_iomap(phys_addr_t start, size_t size, static void *persistent_ram_iomap(phys_addr_t start, size_t size,
unsigned int memtype) unsigned int memtype, char *label)
{ {
void *va; void *va;
if (!request_mem_region(start, size, "persistent_ram")) { if (!request_mem_region(start, size, label ?: "ramoops")) {
pr_err("request mem region (0x%llx@0x%llx) failed\n", pr_err("request mem region (0x%llx@0x%llx) failed\n",
(unsigned long long)size, (unsigned long long)start); (unsigned long long)size, (unsigned long long)start);
return NULL; return NULL;
...@@ -460,7 +460,8 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size, ...@@ -460,7 +460,8 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size,
if (pfn_valid(start >> PAGE_SHIFT)) if (pfn_valid(start >> PAGE_SHIFT))
prz->vaddr = persistent_ram_vmap(start, size, memtype); prz->vaddr = persistent_ram_vmap(start, size, memtype);
else else
prz->vaddr = persistent_ram_iomap(start, size, memtype); prz->vaddr = persistent_ram_iomap(start, size, memtype,
prz->label);
if (!prz->vaddr) { if (!prz->vaddr) {
pr_err("%s: Failed to map 0x%llx pages at 0x%llx\n", __func__, pr_err("%s: Failed to map 0x%llx pages at 0x%llx\n", __func__,
...@@ -530,12 +531,13 @@ void persistent_ram_free(struct persistent_ram_zone *prz) ...@@ -530,12 +531,13 @@ void persistent_ram_free(struct persistent_ram_zone *prz)
prz->ecc_info.par = NULL; prz->ecc_info.par = NULL;
persistent_ram_free_old(prz); persistent_ram_free_old(prz);
kfree(prz->label);
kfree(prz); kfree(prz);
} }
struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
u32 sig, struct persistent_ram_ecc_info *ecc_info, u32 sig, struct persistent_ram_ecc_info *ecc_info,
unsigned int memtype, u32 flags) unsigned int memtype, u32 flags, char *label)
{ {
struct persistent_ram_zone *prz; struct persistent_ram_zone *prz;
int ret = -ENOMEM; int ret = -ENOMEM;
...@@ -549,6 +551,7 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, ...@@ -549,6 +551,7 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
/* Initialize general buffer state. */ /* Initialize general buffer state. */
raw_spin_lock_init(&prz->buffer_lock); raw_spin_lock_init(&prz->buffer_lock);
prz->flags = flags; prz->flags = flags;
prz->label = label;
ret = persistent_ram_buffer_map(start, size, prz, memtype); ret = persistent_ram_buffer_map(start, size, prz, memtype);
if (ret) if (ret)
......
...@@ -46,6 +46,7 @@ struct persistent_ram_zone { ...@@ -46,6 +46,7 @@ struct persistent_ram_zone {
phys_addr_t paddr; phys_addr_t paddr;
size_t size; size_t size;
void *vaddr; void *vaddr;
char *label;
struct persistent_ram_buffer *buffer; struct persistent_ram_buffer *buffer;
size_t buffer_size; size_t buffer_size;
u32 flags; u32 flags;
...@@ -65,7 +66,7 @@ struct persistent_ram_zone { ...@@ -65,7 +66,7 @@ struct persistent_ram_zone {
struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
u32 sig, struct persistent_ram_ecc_info *ecc_info, u32 sig, struct persistent_ram_ecc_info *ecc_info,
unsigned int memtype, u32 flags); unsigned int memtype, u32 flags, char *label);
void persistent_ram_free(struct persistent_ram_zone *prz); void persistent_ram_free(struct persistent_ram_zone *prz);
void persistent_ram_zap(struct persistent_ram_zone *prz); void persistent_ram_zap(struct persistent_ram_zone *prz);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment