Skip to content

Commit

Permalink
pstore/ram: Clarify resource reservation labels
Browse files Browse the repository at this point in the history
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: Kees Cook <[email protected]>
Reviewed-by: Joel Fernandes (Google) <[email protected]>
Tested-by: Sai Prakash Ranjan <[email protected]>
Tested-by: Guenter Roeck <[email protected]>
  • Loading branch information
kees committed Oct 22, 2018
1 parent 95047b0 commit 1227daa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
16 changes: 13 additions & 3 deletions fs/pstore/ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,16 @@ static int ramoops_init_przs(const char *name,
goto fail;

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,
&cxt->ecc_info,
cxt->memtype, flags);
&cxt->ecc_info,
cxt->memtype, flags, label);
if (IS_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",
Expand Down Expand Up @@ -619,6 +626,8 @@ static int ramoops_init_prz(const char *name,
struct persistent_ram_zone **prz,
phys_addr_t *paddr, size_t sz, u32 sig)
{
char *label;

if (!sz)
return 0;

Expand All @@ -629,8 +638,9 @@ static int ramoops_init_prz(const char *name,
return -ENOMEM;
}

label = kasprintf(GFP_KERNEL, "ramoops:%s", name);
*prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info,
cxt->memtype, 0);
cxt->memtype, 0, label);
if (IS_ERR(*prz)) {
int err = PTR_ERR(*prz);

Expand Down
11 changes: 7 additions & 4 deletions fs/pstore/ram_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
unsigned int memtype)
unsigned int memtype, char *label)
{
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",
(unsigned long long)size, (unsigned long long)start);
return NULL;
Expand All @@ -460,7 +460,8 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size,
if (pfn_valid(start >> PAGE_SHIFT))
prz->vaddr = persistent_ram_vmap(start, size, memtype);
else
prz->vaddr = persistent_ram_iomap(start, size, memtype);
prz->vaddr = persistent_ram_iomap(start, size, memtype,
prz->label);

if (!prz->vaddr) {
pr_err("%s: Failed to map 0x%llx pages at 0x%llx\n", __func__,
Expand Down Expand Up @@ -530,12 +531,13 @@ void persistent_ram_free(struct persistent_ram_zone *prz)
prz->ecc_info.par = NULL;

persistent_ram_free_old(prz);
kfree(prz->label);
kfree(prz);
}

struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
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;
int ret = -ENOMEM;
Expand All @@ -549,6 +551,7 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
/* Initialize general buffer state. */
raw_spin_lock_init(&prz->buffer_lock);
prz->flags = flags;
prz->label = label;

ret = persistent_ram_buffer_map(start, size, prz, memtype);
if (ret)
Expand Down
3 changes: 2 additions & 1 deletion include/linux/pstore_ram.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct persistent_ram_zone {
phys_addr_t paddr;
size_t size;
void *vaddr;
char *label;
struct persistent_ram_buffer *buffer;
size_t buffer_size;
u32 flags;
Expand All @@ -65,7 +66,7 @@ struct persistent_ram_zone {

struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
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_zap(struct persistent_ram_zone *prz);

Expand Down

0 comments on commit 1227daa

Please sign in to comment.