Commit 5456ffde authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Al Viro

powerpc/spufs: simplify spufs core dumping

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
Reviewed-by: default avatarJeremy Kerr <jk@ozlabs.org>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 6904d3d0
...@@ -21,22 +21,6 @@ ...@@ -21,22 +21,6 @@
#include "spufs.h" #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) static int spufs_ctx_note_size(struct spu_context *ctx, int dfd)
{ {
int i, sz, total = 0; int i, sz, total = 0;
...@@ -118,58 +102,43 @@ int spufs_coredump_extra_notes_size(void) ...@@ -118,58 +102,43 @@ int spufs_coredump_extra_notes_size(void)
static int spufs_arch_write_note(struct spu_context *ctx, int i, static int spufs_arch_write_note(struct spu_context *ctx, int i,
struct coredump_params *cprm, int dfd) struct coredump_params *cprm, int dfd)
{ {
loff_t pos = 0; size_t sz = spufs_coredump_read[i].size;
int sz, rc, total = 0; char fullname[80];
const int bufsz = PAGE_SIZE;
char *name;
char fullname[80], *buf;
struct elf_note en; struct elf_note en;
size_t skip; size_t ret;
buf = (void *)get_zeroed_page(GFP_KERNEL);
if (!buf)
return -ENOMEM;
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_namesz = strlen(fullname) + 1;
en.n_descsz = sz; en.n_descsz = sz;
en.n_type = NT_SPU; en.n_type = NT_SPU;
if (!dump_emit(cprm, &en, sizeof(en))) if (!dump_emit(cprm, &en, sizeof(en)))
goto Eio; return -EIO;
if (!dump_emit(cprm, fullname, en.n_namesz)) if (!dump_emit(cprm, fullname, en.n_namesz))
goto Eio; return -EIO;
if (!dump_align(cprm, 4)) if (!dump_align(cprm, 4))
goto Eio; return -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) if (spufs_coredump_read[i].dump) {
goto out; ret = spufs_coredump_read[i].dump(ctx, cprm);
if (ret < 0)
return ret;
} else {
char buf[32];
skip = roundup(cprm->pos - total + sz, 4) - cprm->pos; ret = snprintf(buf, sizeof(buf), "0x%.16llx",
if (!dump_skip(cprm, skip)) spufs_coredump_read[i].get(ctx));
goto Eio; if (ret >= sizeof(buf))
return sizeof(buf);
rc = 0; /* count trailing the NULL: */
out: if (!dump_emit(cprm, buf, ret + 1))
free_page((unsigned long)buf); return -EIO;
return rc; }
Eio:
free_page((unsigned long)buf); if (!dump_skip(cprm, roundup(cprm->pos - ret + sz, 4) - cprm->pos))
return -EIO; return -EIO;
return 0;
} }
int spufs_coredump_extra_notes_write(struct coredump_params *cprm) int spufs_coredump_extra_notes_write(struct coredump_params *cprm)
......
This diff is collapsed.
...@@ -337,8 +337,7 @@ void spufs_dma_callback(struct spu *spu, int type); ...@@ -337,8 +337,7 @@ void spufs_dma_callback(struct spu *spu, int type);
extern struct spu_coredump_calls spufs_coredump_calls; extern struct spu_coredump_calls spufs_coredump_calls;
struct spufs_coredump_reader { struct spufs_coredump_reader {
char *name; char *name;
ssize_t (*read)(struct spu_context *ctx, ssize_t (*dump)(struct spu_context *ctx, struct coredump_params *cprm);
char __user *buffer, size_t size, loff_t *pos);
u64 (*get)(struct spu_context *ctx); u64 (*get)(struct spu_context *ctx);
size_t size; size_t size;
}; };
......
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