Skip to content

Commit

Permalink
powerpc/spufs: simplify spufs core dumping
Browse files Browse the repository at this point in the history
Replace the coredump ->read method with a ->dump method that must call
dump_emit itself.  That way we avoid a buffer allocation an messing with
set_fs() to call into code that is intended to deal with user buffers.
For the ->get case we can now use a small on-stack buffer and avoid
memory allocations as well.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Christoph Hellwig authored and Al Viro committed May 5, 2020
1 parent 6904d3d commit 5456ffd
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 176 deletions.
87 changes: 28 additions & 59 deletions arch/powerpc/platforms/cell/spufs/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@

#include "spufs.h"

static ssize_t do_coredump_read(int num, struct spu_context *ctx, void *buffer,
size_t size, loff_t *off)
{
u64 data;
int ret;

if (spufs_coredump_read[num].read)
return spufs_coredump_read[num].read(ctx, buffer, size, off);

data = spufs_coredump_read[num].get(ctx);
ret = snprintf(buffer, size, "0x%.16llx", data);
if (ret >= size)
return size;
return ++ret; /* count trailing NULL */
}

static int spufs_ctx_note_size(struct spu_context *ctx, int dfd)
{
int i, sz, total = 0;
Expand Down Expand Up @@ -118,58 +102,43 @@ int spufs_coredump_extra_notes_size(void)
static int spufs_arch_write_note(struct spu_context *ctx, int i,
struct coredump_params *cprm, int dfd)
{
loff_t pos = 0;
int sz, rc, total = 0;
const int bufsz = PAGE_SIZE;
char *name;
char fullname[80], *buf;
size_t sz = spufs_coredump_read[i].size;
char fullname[80];
struct elf_note en;
size_t skip;

buf = (void *)get_zeroed_page(GFP_KERNEL);
if (!buf)
return -ENOMEM;
size_t ret;

name = spufs_coredump_read[i].name;
sz = spufs_coredump_read[i].size;

sprintf(fullname, "SPU/%d/%s", dfd, name);
sprintf(fullname, "SPU/%d/%s", dfd, spufs_coredump_read[i].name);
en.n_namesz = strlen(fullname) + 1;
en.n_descsz = sz;
en.n_type = NT_SPU;

if (!dump_emit(cprm, &en, sizeof(en)))
goto Eio;

return -EIO;
if (!dump_emit(cprm, fullname, en.n_namesz))
goto Eio;

return -EIO;
if (!dump_align(cprm, 4))
goto Eio;

do {
rc = do_coredump_read(i, ctx, buf, bufsz, &pos);
if (rc > 0) {
if (!dump_emit(cprm, buf, rc))
goto Eio;
total += rc;
}
} while (rc == bufsz && total < sz);

if (rc < 0)
goto out;

skip = roundup(cprm->pos - total + sz, 4) - cprm->pos;
if (!dump_skip(cprm, skip))
goto Eio;

rc = 0;
out:
free_page((unsigned long)buf);
return rc;
Eio:
free_page((unsigned long)buf);
return -EIO;
return -EIO;

if (spufs_coredump_read[i].dump) {
ret = spufs_coredump_read[i].dump(ctx, cprm);
if (ret < 0)
return ret;
} else {
char buf[32];

ret = snprintf(buf, sizeof(buf), "0x%.16llx",
spufs_coredump_read[i].get(ctx));
if (ret >= sizeof(buf))
return sizeof(buf);

/* count trailing the NULL: */
if (!dump_emit(cprm, buf, ret + 1))
return -EIO;
}

if (!dump_skip(cprm, roundup(cprm->pos - ret + sz, 4) - cprm->pos))
return -EIO;
return 0;
}

int spufs_coredump_extra_notes_write(struct coredump_params *cprm)
Expand Down

0 comments on commit 5456ffd

Please sign in to comment.