mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
Merge tag 'vfs-7.4-rc1.sync_close' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull file closing updates from Christian Brauner:
"This makes closing files synchronous for close_range(), exec and exit.
Since fput() was switched to task work every final __fput() of an
exiting task is queued on task work and run from exit_task_work().
exec and close_range() do the same. For a task with a large descriptor
table that is a cmpxchg() and a TIF_NOTIFY_RESUME test-and-set per
file plus a list entry for any later task_work_cancel() to search
under pi_lock, and then a second pass over every struct file that
isn't cache hot anymore by then. Oleg and Neil have pointed this out
over the years.
close_files(), close_range() and close-on-exec now flush and put each
file inline the way close(2) does. Kernel threads aren't affected.
They share init_files which init_task pins forever so their
exit_files() never drops the last reference, and their fput() keeps
punting to a workqueue. The one place that could put a table from a
kthread context, a failing copy_process(), can't hold the last
reference while the source table is alive.
On a 64 vCPU KVM guest tearing down 4096, 65536 and 1M descriptors
scattered at random positions in the table:
4096 fds 65536 fds 1M fds
exit 1045 -> 895 us 18.9 -> 14.9 ms 429 -> 306 ms
execve, close-on-exec 1393 -> 1190 us 21.4 -> 16.9 ms 471 -> 325 ms
close_range() 1179 -> 988 us 21.9 -> 17.4 ms 484 -> 337 ms
So that is 16-21% or 40-150 ns per closed file, largest at 1M
descriptors. With eight processes tearing down 65536 descriptors each
at once it stays at 16-21% because the second pass over 16 MB of
struct file is what gets expensive when CPUs compete for the cache.
With 32 or 64 processes both kernels are bound by pushing millions of
files through slab and rcu and the difference shrinks to 4-8%. Files
whose own release dominates gain less, 13% for eventfds, 11% for
pipes, 6% for AF_UNIX sockets. close(2) is untouched and will-it-scale
is within 2%.
The spufs coredump support is removed. It was the only reason
do_coredump() unshared the descriptor table. gdb dropped Cell
debugging in 9.1 and binutils in 2.34, the Cell blades are gone and
nothing on the PlayStation 3 produces or reads these notes. With that
unshare_files() goes away, exec installs its private table through the
new switch_files_struct() and the coredump startup completion becomes
a plain thread count waited on with the new wait_var_event_state().
Three fixes for the synchronous close are included. A failed fork
released its files under scx_fork_rwsem and deadlocked against the bpf
link's release. A session leader's exit released its tty before
disassociate_ctty() ran and the foreground job lost its SIGHUP, so the
tty is hung up before the files are closed now. And descriptor tables
are walked from the highest descriptor down which restores the order
the deferred puts had and keeps a few long-standing release ordering
bugs from deadlocking exit"
* tag 'vfs-7.4-rc1.sync_close' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
fs: close files from the highest descriptor down
coredump: factor out coredump_wait_inactive()
exit: hang up the tty before closing the files
fork: release the files of a failed fork after sched_cancel_fork()
coredump: replace the startup completion with a thread count
sched: add wait_var_event_state()
coredump: drop core_state->dumper
fs: make close_cloexec_files() synchronous
fs: rename do_close_on_exec() to close_cloexec_files()
fs: make close_range() synchronous
fs: make close_files() synchronous
fs: add filp_close_sync()
fs: remove unshare_files()
fs: move unshare_fd() to fs/file.c
fs: add switch_files_struct()
coredump: stop unsharing the file descriptor table
fs: don't open-code file_close_fd() in close_fd()
powerpc: remove coredump support
This commit is contained in:
@@ -160,7 +160,6 @@ config PPC
|
||||
select ARCH_HAS_UBSAN
|
||||
select ARCH_HAS_VDSO_ARCH_DATA
|
||||
select ARCH_HAVE_NMI_SAFE_CMPXCHG
|
||||
select ARCH_HAVE_EXTRA_ELF_NOTES if SPU_BASE
|
||||
select ARCH_KEEP_MEMBLOCK
|
||||
select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE if PPC_RADIX_MMU
|
||||
select ARCH_MIGHT_HAVE_PC_PARPORT
|
||||
|
||||
@@ -123,12 +123,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
|
||||
(0x7ff >> (PAGE_SHIFT - 12)) : \
|
||||
(0x3ffff >> (PAGE_SHIFT - 12)))
|
||||
|
||||
#ifdef CONFIG_SPU_BASE
|
||||
/* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
|
||||
#define NT_SPU 1
|
||||
|
||||
#endif /* CONFIG_SPU_BASE */
|
||||
|
||||
#ifdef CONFIG_PPC64
|
||||
|
||||
#define get_cache_geometry(level) \
|
||||
|
||||
@@ -210,15 +210,12 @@ extern long spu_sys_callback(struct spu_syscall_block *s);
|
||||
|
||||
/* syscalls implemented in spufs */
|
||||
struct file;
|
||||
struct coredump_params;
|
||||
struct spufs_calls {
|
||||
long (*create_thread)(const char __user *name,
|
||||
unsigned int flags, umode_t mode,
|
||||
struct file *neighbor);
|
||||
long (*spu_run)(struct file *filp, __u32 __user *unpc,
|
||||
__u32 __user *ustatus);
|
||||
int (*coredump_extra_notes_size)(void);
|
||||
int (*coredump_extra_notes_write)(struct coredump_params *cprm);
|
||||
void (*notify_spus_active)(void);
|
||||
struct module *owner;
|
||||
};
|
||||
|
||||
@@ -10,7 +10,6 @@ config SPU_FS
|
||||
tristate "SPU file system"
|
||||
default m
|
||||
depends on PPC_CELL
|
||||
depends on COREDUMP
|
||||
select SPU_BASE
|
||||
help
|
||||
The SPU file system is used to access Synergistic Processing
|
||||
|
||||
@@ -88,26 +88,6 @@ SYSCALL_DEFINE3(spu_run,int, fd, __u32 __user *, unpc, __u32 __user *, ustatus)
|
||||
return calls->spu_run(fd_file(arg), unpc, ustatus);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_COREDUMP
|
||||
int elf_coredump_extra_notes_size(void)
|
||||
{
|
||||
CLASS(spufs_calls, calls)();
|
||||
if (!calls)
|
||||
return 0;
|
||||
|
||||
return calls->coredump_extra_notes_size();
|
||||
}
|
||||
|
||||
int elf_coredump_extra_notes_write(struct coredump_params *cprm)
|
||||
{
|
||||
CLASS(spufs_calls, calls)();
|
||||
if (!calls)
|
||||
return 0;
|
||||
|
||||
return calls->coredump_extra_notes_write(cprm);
|
||||
}
|
||||
#endif
|
||||
|
||||
void notify_spus_active(void)
|
||||
{
|
||||
struct spufs_calls *calls;
|
||||
|
||||
@@ -4,7 +4,6 @@ obj-$(CONFIG_SPU_FS) += spufs.o
|
||||
spufs-y += inode.o file.o context.o syscalls.o
|
||||
spufs-y += sched.o backing_ops.o hw_ops.o run.o gang.o
|
||||
spufs-y += switch.o fault.o lscsa_alloc.o
|
||||
spufs-$(CONFIG_COREDUMP) += coredump.o
|
||||
|
||||
# magic for the trace events
|
||||
CFLAGS_sched.o := -I$(src)
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* SPU core dump code
|
||||
*
|
||||
* (C) Copyright 2006 IBM Corp.
|
||||
*
|
||||
* Author: Dwayne Grant McConnell <decimal@us.ibm.com>
|
||||
*/
|
||||
|
||||
#include <linux/elf.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/fdtable.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/gfp.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/syscalls.h>
|
||||
#include <linux/coredump.h>
|
||||
#include <linux/binfmts.h>
|
||||
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#include "spufs.h"
|
||||
|
||||
static int spufs_ctx_note_size(struct spu_context *ctx, int dfd)
|
||||
{
|
||||
int i, sz, total = 0;
|
||||
char *name;
|
||||
char fullname[80];
|
||||
|
||||
for (i = 0; spufs_coredump_read[i].name != NULL; i++) {
|
||||
name = spufs_coredump_read[i].name;
|
||||
sz = spufs_coredump_read[i].size;
|
||||
|
||||
sprintf(fullname, "SPU/%d/%s", dfd, name);
|
||||
|
||||
total += sizeof(struct elf_note);
|
||||
total += roundup(strlen(fullname) + 1, 4);
|
||||
total += roundup(sz, 4);
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
static int match_context(const void *v, struct file *file, unsigned fd)
|
||||
{
|
||||
struct spu_context *ctx;
|
||||
if (file->f_op != &spufs_context_fops)
|
||||
return 0;
|
||||
ctx = SPUFS_I(file_inode(file))->i_ctx;
|
||||
if (ctx->flags & SPU_CREATE_NOSCHED)
|
||||
return 0;
|
||||
return fd + 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* The additional architecture-specific notes for Cell are various
|
||||
* context files in the spu context.
|
||||
*
|
||||
* This function iterates over all open file descriptors and sees
|
||||
* if they are a directory in spufs. In that case we use spufs
|
||||
* internal functionality to dump them without needing to actually
|
||||
* open the files.
|
||||
*/
|
||||
/*
|
||||
* descriptor table is not shared, so files can't change or go away.
|
||||
*/
|
||||
static struct spu_context *coredump_next_context(int *fd)
|
||||
{
|
||||
struct spu_context *ctx = NULL;
|
||||
struct file *file;
|
||||
int n = iterate_fd(current->files, *fd, match_context, NULL);
|
||||
if (!n)
|
||||
return NULL;
|
||||
*fd = n - 1;
|
||||
|
||||
file = fget_raw(*fd);
|
||||
if (file) {
|
||||
ctx = SPUFS_I(file_inode(file))->i_ctx;
|
||||
get_spu_context(ctx);
|
||||
fput(file);
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
int spufs_coredump_extra_notes_size(void)
|
||||
{
|
||||
struct spu_context *ctx;
|
||||
int size = 0, rc, fd;
|
||||
|
||||
fd = 0;
|
||||
while ((ctx = coredump_next_context(&fd)) != NULL) {
|
||||
rc = spu_acquire_saved(ctx);
|
||||
if (rc) {
|
||||
put_spu_context(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
rc = spufs_ctx_note_size(ctx, fd);
|
||||
spu_release_saved(ctx);
|
||||
if (rc < 0) {
|
||||
put_spu_context(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
size += rc;
|
||||
|
||||
/* start searching the next fd next time */
|
||||
fd++;
|
||||
put_spu_context(ctx);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static int spufs_arch_write_note(struct spu_context *ctx, int i,
|
||||
struct coredump_params *cprm, int dfd)
|
||||
{
|
||||
size_t sz = spufs_coredump_read[i].size;
|
||||
char fullname[80];
|
||||
struct elf_note en;
|
||||
int ret;
|
||||
|
||||
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)))
|
||||
return -EIO;
|
||||
if (!dump_emit(cprm, fullname, en.n_namesz))
|
||||
return -EIO;
|
||||
if (!dump_align(cprm, 4))
|
||||
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;
|
||||
}
|
||||
|
||||
dump_skip_to(cprm, roundup(cprm->pos - ret + sz, 4));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int spufs_coredump_extra_notes_write(struct coredump_params *cprm)
|
||||
{
|
||||
struct spu_context *ctx;
|
||||
int fd, j, rc;
|
||||
|
||||
fd = 0;
|
||||
while ((ctx = coredump_next_context(&fd)) != NULL) {
|
||||
rc = spu_acquire_saved(ctx);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
for (j = 0; spufs_coredump_read[j].name != NULL; j++) {
|
||||
rc = spufs_arch_write_note(ctx, j, cprm, fd);
|
||||
if (rc) {
|
||||
spu_release_saved(ctx);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
spu_release_saved(ctx);
|
||||
|
||||
/* start searching the next fd next time */
|
||||
fd++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
#include <linux/coredump.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/ioctl.h>
|
||||
#include <linux/export.h>
|
||||
@@ -130,14 +129,6 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t spufs_dump_emit(struct coredump_params *cprm, void *buf,
|
||||
size_t size)
|
||||
{
|
||||
if (!dump_emit(cprm, buf, size))
|
||||
return -EIO;
|
||||
return size;
|
||||
}
|
||||
|
||||
#define DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
|
||||
static int __fops ## _open(struct inode *inode, struct file *file) \
|
||||
{ \
|
||||
@@ -180,12 +171,6 @@ spufs_mem_release(struct inode *inode, struct file *file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
spufs_mem_dump(struct spu_context *ctx, struct coredump_params *cprm)
|
||||
{
|
||||
return spufs_dump_emit(cprm, ctx->ops->get_ls(ctx), LS_SIZE);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
spufs_mem_read(struct file *file, char __user *buffer,
|
||||
size_t size, loff_t *pos)
|
||||
@@ -466,13 +451,6 @@ spufs_regs_open(struct inode *inode, struct file *file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
spufs_regs_dump(struct spu_context *ctx, struct coredump_params *cprm)
|
||||
{
|
||||
return spufs_dump_emit(cprm, ctx->csa.lscsa->gprs,
|
||||
sizeof(ctx->csa.lscsa->gprs));
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
spufs_regs_read(struct file *file, char __user *buffer,
|
||||
size_t size, loff_t *pos)
|
||||
@@ -523,13 +501,6 @@ static const struct file_operations spufs_regs_fops = {
|
||||
.llseek = generic_file_llseek,
|
||||
};
|
||||
|
||||
static ssize_t
|
||||
spufs_fpcr_dump(struct spu_context *ctx, struct coredump_params *cprm)
|
||||
{
|
||||
return spufs_dump_emit(cprm, &ctx->csa.lscsa->fpcr,
|
||||
sizeof(ctx->csa.lscsa->fpcr));
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
spufs_fpcr_read(struct file *file, char __user * buffer,
|
||||
size_t size, loff_t * pos)
|
||||
@@ -953,15 +924,6 @@ spufs_signal1_release(struct inode *inode, struct file *file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t spufs_signal1_dump(struct spu_context *ctx,
|
||||
struct coredump_params *cprm)
|
||||
{
|
||||
if (!ctx->csa.spu_chnlcnt_RW[3])
|
||||
return 0;
|
||||
return spufs_dump_emit(cprm, &ctx->csa.spu_chnldata_RW[3],
|
||||
sizeof(ctx->csa.spu_chnldata_RW[3]));
|
||||
}
|
||||
|
||||
static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
|
||||
size_t len)
|
||||
{
|
||||
@@ -1086,15 +1048,6 @@ spufs_signal2_release(struct inode *inode, struct file *file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t spufs_signal2_dump(struct spu_context *ctx,
|
||||
struct coredump_params *cprm)
|
||||
{
|
||||
if (!ctx->csa.spu_chnlcnt_RW[4])
|
||||
return 0;
|
||||
return spufs_dump_emit(cprm, &ctx->csa.spu_chnldata_RW[4],
|
||||
sizeof(ctx->csa.spu_chnldata_RW[4]));
|
||||
}
|
||||
|
||||
static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
|
||||
size_t len)
|
||||
{
|
||||
@@ -1924,15 +1877,6 @@ static const struct file_operations spufs_caps_fops = {
|
||||
.release = single_release,
|
||||
};
|
||||
|
||||
static ssize_t spufs_mbox_info_dump(struct spu_context *ctx,
|
||||
struct coredump_params *cprm)
|
||||
{
|
||||
if (!(ctx->csa.prob.mb_stat_R & 0x0000ff))
|
||||
return 0;
|
||||
return spufs_dump_emit(cprm, &ctx->csa.prob.pu_mb_R,
|
||||
sizeof(ctx->csa.prob.pu_mb_R));
|
||||
}
|
||||
|
||||
static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
|
||||
size_t len, loff_t *pos)
|
||||
{
|
||||
@@ -1962,15 +1906,6 @@ static const struct file_operations spufs_mbox_info_fops = {
|
||||
.llseek = generic_file_llseek,
|
||||
};
|
||||
|
||||
static ssize_t spufs_ibox_info_dump(struct spu_context *ctx,
|
||||
struct coredump_params *cprm)
|
||||
{
|
||||
if (!(ctx->csa.prob.mb_stat_R & 0xff0000))
|
||||
return 0;
|
||||
return spufs_dump_emit(cprm, &ctx->csa.priv2.puint_mb_R,
|
||||
sizeof(ctx->csa.priv2.puint_mb_R));
|
||||
}
|
||||
|
||||
static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
|
||||
size_t len, loff_t *pos)
|
||||
{
|
||||
@@ -2005,13 +1940,6 @@ static size_t spufs_wbox_info_cnt(struct spu_context *ctx)
|
||||
return (4 - ((ctx->csa.prob.mb_stat_R & 0x00ff00) >> 8)) * sizeof(u32);
|
||||
}
|
||||
|
||||
static ssize_t spufs_wbox_info_dump(struct spu_context *ctx,
|
||||
struct coredump_params *cprm)
|
||||
{
|
||||
return spufs_dump_emit(cprm, &ctx->csa.spu_mailbox_data,
|
||||
spufs_wbox_info_cnt(ctx));
|
||||
}
|
||||
|
||||
static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
|
||||
size_t len, loff_t *pos)
|
||||
{
|
||||
@@ -2059,15 +1987,6 @@ static void spufs_get_dma_info(struct spu_context *ctx,
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t spufs_dma_info_dump(struct spu_context *ctx,
|
||||
struct coredump_params *cprm)
|
||||
{
|
||||
struct spu_dma_info info;
|
||||
|
||||
spufs_get_dma_info(ctx, &info);
|
||||
return spufs_dump_emit(cprm, &info, sizeof(info));
|
||||
}
|
||||
|
||||
static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
|
||||
size_t len, loff_t *pos)
|
||||
{
|
||||
@@ -2112,15 +2031,6 @@ static void spufs_get_proxydma_info(struct spu_context *ctx,
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t spufs_proxydma_info_dump(struct spu_context *ctx,
|
||||
struct coredump_params *cprm)
|
||||
{
|
||||
struct spu_proxydma_info info;
|
||||
|
||||
spufs_get_proxydma_info(ctx, &info);
|
||||
return spufs_dump_emit(cprm, &info, sizeof(info));
|
||||
}
|
||||
|
||||
static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
|
||||
size_t len, loff_t *pos)
|
||||
{
|
||||
@@ -2580,27 +2490,3 @@ const struct spufs_tree_descr spufs_dir_debug_contents[] = {
|
||||
{ ".ctx", &spufs_ctx_fops, 0444, },
|
||||
{},
|
||||
};
|
||||
|
||||
const struct spufs_coredump_reader spufs_coredump_read[] = {
|
||||
{ "regs", spufs_regs_dump, NULL, sizeof(struct spu_reg128[128])},
|
||||
{ "fpcr", spufs_fpcr_dump, NULL, sizeof(struct spu_reg128) },
|
||||
{ "lslr", NULL, spufs_lslr_get, 19 },
|
||||
{ "decr", NULL, spufs_decr_get, 19 },
|
||||
{ "decr_status", NULL, spufs_decr_status_get, 19 },
|
||||
{ "mem", spufs_mem_dump, NULL, LS_SIZE, },
|
||||
{ "signal1", spufs_signal1_dump, NULL, sizeof(u32) },
|
||||
{ "signal1_type", NULL, spufs_signal1_type_get, 19 },
|
||||
{ "signal2", spufs_signal2_dump, NULL, sizeof(u32) },
|
||||
{ "signal2_type", NULL, spufs_signal2_type_get, 19 },
|
||||
{ "event_mask", NULL, spufs_event_mask_get, 19 },
|
||||
{ "event_status", NULL, spufs_event_status_get, 19 },
|
||||
{ "mbox_info", spufs_mbox_info_dump, NULL, sizeof(u32) },
|
||||
{ "ibox_info", spufs_ibox_info_dump, NULL, sizeof(u32) },
|
||||
{ "wbox_info", spufs_wbox_info_dump, NULL, 4 * sizeof(u32)},
|
||||
{ "dma_info", spufs_dma_info_dump, NULL, sizeof(struct spu_dma_info)},
|
||||
{ "proxydma_info", spufs_proxydma_info_dump,
|
||||
NULL, sizeof(struct spu_proxydma_info)},
|
||||
{ "object-id", NULL, spufs_object_id_get, 19 },
|
||||
{ "npc", NULL, spufs_npc_get, 19 },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
@@ -232,13 +232,9 @@ extern const struct spufs_tree_descr spufs_dir_debug_contents[];
|
||||
|
||||
/* system call implementation */
|
||||
extern struct spufs_calls spufs_calls;
|
||||
struct coredump_params;
|
||||
long spufs_run_spu(struct spu_context *ctx, u32 *npc, u32 *status);
|
||||
long spufs_create(const struct path *nd, struct dentry *dentry, unsigned int flags,
|
||||
umode_t mode, struct file *filp);
|
||||
/* ELF coredump callbacks for writing SPU ELF notes */
|
||||
extern int spufs_coredump_extra_notes_size(void);
|
||||
extern int spufs_coredump_extra_notes_write(struct coredump_params *cprm);
|
||||
|
||||
extern const struct file_operations spufs_context_fops;
|
||||
|
||||
@@ -335,14 +331,6 @@ void spufs_stop_callback(struct spu *spu, int irq);
|
||||
void spufs_mfc_callback(struct spu *spu);
|
||||
void spufs_dma_callback(struct spu *spu, int type);
|
||||
|
||||
struct spufs_coredump_reader {
|
||||
char *name;
|
||||
ssize_t (*dump)(struct spu_context *ctx, struct coredump_params *cprm);
|
||||
u64 (*get)(struct spu_context *ctx);
|
||||
size_t size;
|
||||
};
|
||||
extern const struct spufs_coredump_reader spufs_coredump_read[];
|
||||
|
||||
extern int spu_init_csa(struct spu_state *csa);
|
||||
extern void spu_fini_csa(struct spu_state *csa);
|
||||
extern int spu_save(struct spu_state *prev, struct spu *spu);
|
||||
|
||||
@@ -82,8 +82,4 @@ struct spufs_calls spufs_calls = {
|
||||
.spu_run = do_spu_run,
|
||||
.notify_spus_active = do_notify_spus_active,
|
||||
.owner = THIS_MODULE,
|
||||
#ifdef CONFIG_COREDUMP
|
||||
.coredump_extra_notes_size = spufs_coredump_extra_notes_size,
|
||||
.coredump_extra_notes_write = spufs_coredump_extra_notes_write,
|
||||
#endif
|
||||
};
|
||||
|
||||
+3
-3
@@ -1875,7 +1875,7 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
|
||||
return 0;
|
||||
|
||||
info->thread->task = dump_task;
|
||||
for (ct = dump_task->signal->core_state->dumper.next; ct; ct = ct->next) {
|
||||
for (ct = dump_task->signal->core_state->tasks; ct; ct = ct->next) {
|
||||
t = kzalloc_flex(*t, notes, info->thread_notes);
|
||||
if (unlikely(!t))
|
||||
return 0;
|
||||
@@ -2029,7 +2029,7 @@ static bool elf_core_dump(struct coredump_params *cprm)
|
||||
{
|
||||
size_t sz = info.size;
|
||||
|
||||
/* For cell spufs and x86 xstate */
|
||||
/* For x86 xstate */
|
||||
sz += elf_coredump_extra_notes_size();
|
||||
|
||||
phdr4note = kmalloc_obj(*phdr4note);
|
||||
@@ -2093,7 +2093,7 @@ static bool elf_core_dump(struct coredump_params *cprm)
|
||||
if (!write_note_info(&info, cprm))
|
||||
goto end_coredump;
|
||||
|
||||
/* For cell spufs and x86 xstate */
|
||||
/* For x86 xstate */
|
||||
if (elf_coredump_extra_notes_write(cprm))
|
||||
goto end_coredump;
|
||||
|
||||
|
||||
@@ -1504,7 +1504,7 @@ static bool elf_fdpic_core_dump(struct coredump_params *cprm)
|
||||
if (!psinfo)
|
||||
goto end_coredump;
|
||||
|
||||
for (ct = current->signal->core_state->dumper.next;
|
||||
for (ct = current->signal->core_state->tasks;
|
||||
ct; ct = ct->next) {
|
||||
tmp = elf_dump_thread_status(cprm->siginfo->si_signo,
|
||||
ct->task, &thread_status_size);
|
||||
|
||||
+22
-26
@@ -39,6 +39,7 @@
|
||||
#include <linux/oom.h>
|
||||
#include <linux/compat.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/wait_bit.h>
|
||||
#include <linux/path.h>
|
||||
#include <linux/timekeeping.h>
|
||||
#include <linux/sysctl.h>
|
||||
@@ -521,38 +522,38 @@ static int zap_threads(struct task_struct *tsk,
|
||||
nr = zap_process(signal, exit_code);
|
||||
clear_tsk_thread_flag(tsk, TIF_SIGPENDING);
|
||||
tsk->flags |= PF_DUMPCORE;
|
||||
atomic_set(&core_state->nr_threads, nr);
|
||||
atomic_set(&core_state->threads_remaining, nr);
|
||||
}
|
||||
spin_unlock_irq(&tsk->sighand->siglock);
|
||||
return nr;
|
||||
}
|
||||
|
||||
static void coredump_wait_inactive(struct core_state *core_state)
|
||||
{
|
||||
struct core_thread *ptr;
|
||||
|
||||
wait_var_event_state(&core_state->threads_remaining,
|
||||
!atomic_read_acquire(&core_state->threads_remaining),
|
||||
TASK_UNINTERRUPTIBLE | TASK_FREEZABLE);
|
||||
/*
|
||||
* Wait for all the threads to become inactive, so that
|
||||
* all the thread context (extended register state, like
|
||||
* fpu etc) gets copied to the memory.
|
||||
*/
|
||||
for (ptr = core_state->tasks; ptr; ptr = ptr->next)
|
||||
wait_task_inactive(ptr->task, TASK_ANY);
|
||||
}
|
||||
|
||||
static int coredump_wait(int exit_code, struct core_state *core_state)
|
||||
{
|
||||
struct task_struct *tsk = current;
|
||||
int core_waiters = -EBUSY;
|
||||
|
||||
init_completion(&core_state->startup);
|
||||
core_state->dumper.task = tsk;
|
||||
core_state->dumper.next = NULL;
|
||||
core_state->tasks = NULL;
|
||||
|
||||
core_waiters = zap_threads(tsk, core_state, exit_code);
|
||||
if (core_waiters > 0) {
|
||||
struct core_thread *ptr;
|
||||
|
||||
wait_for_completion_state(&core_state->startup,
|
||||
TASK_UNINTERRUPTIBLE|TASK_FREEZABLE);
|
||||
/*
|
||||
* Wait for all the threads to become inactive, so that
|
||||
* all the thread context (extended register state, like
|
||||
* fpu etc) gets copied to the memory.
|
||||
*/
|
||||
ptr = core_state->dumper.next;
|
||||
while (ptr != NULL) {
|
||||
wait_task_inactive(ptr->task, TASK_ANY);
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
if (core_waiters > 0)
|
||||
coredump_wait_inactive(core_state);
|
||||
|
||||
return core_waiters;
|
||||
}
|
||||
@@ -565,7 +566,7 @@ static void coredump_finish(enum coredump_state state)
|
||||
spin_lock_irq(¤t->sighand->siglock);
|
||||
if ((state & COREDUMP_STATE_STARTED) && !__fatal_signal_pending(current))
|
||||
current->signal->group_exit_code |= 0x80;
|
||||
next = current->signal->core_state->dumper.next;
|
||||
next = current->signal->core_state->tasks;
|
||||
current->signal->core_state = NULL;
|
||||
spin_unlock_irq(¤t->sighand->siglock);
|
||||
|
||||
@@ -1231,11 +1232,6 @@ static void do_coredump(struct core_name *cn, struct coredump_params *cprm,
|
||||
if (cprm->mask & COREDUMP_REJECT)
|
||||
return;
|
||||
|
||||
/* get us an unshared descriptor table; almost always a no-op */
|
||||
/* The cell spufs coredump code reads the file descriptor tables */
|
||||
if (unshare_files())
|
||||
return;
|
||||
|
||||
if ((cprm->mask & COREDUMP_KERNEL) && !coredump_write(cprm, binfmt))
|
||||
return;
|
||||
|
||||
|
||||
@@ -1136,6 +1136,7 @@ static void posixtimer_exec(struct task_struct *me)
|
||||
int begin_new_exec(struct linux_binprm * bprm)
|
||||
{
|
||||
struct task_struct *me = current;
|
||||
struct files_struct *files = NULL;
|
||||
int retval;
|
||||
|
||||
/* A pending PT_INTERP substitution this format cannot consume. */
|
||||
@@ -1185,9 +1186,11 @@ int begin_new_exec(struct linux_binprm * bprm)
|
||||
current->fs->in_exec = 0;
|
||||
|
||||
/* Ensure the files table is not shared. */
|
||||
retval = unshare_files();
|
||||
retval = unshare_fd(CLONE_FILES, &files);
|
||||
if (retval)
|
||||
goto out;
|
||||
if (files)
|
||||
switch_files_struct(me, files);
|
||||
|
||||
/*
|
||||
* We have to apply CLOEXEC before we change whether the process is
|
||||
@@ -1195,13 +1198,13 @@ int begin_new_exec(struct linux_binprm * bprm)
|
||||
* trying to access the should-be-closed file descriptors of a process
|
||||
* undergoing exec(2).
|
||||
*
|
||||
* This can block on filesystem ->flush() handlers, including waiting
|
||||
* for FUSE daemons, so do it before exec_mmap takes the
|
||||
* exec_update_lock.
|
||||
* This can block on filesystem ->flush() and ->release() handlers,
|
||||
* including waiting for FUSE daemons, so do it before exec_mmap
|
||||
* takes the exec_update_lock.
|
||||
* This must happen after the point of no return, and after unsharing
|
||||
* the FD table.
|
||||
*/
|
||||
do_close_on_exec(me->files);
|
||||
close_cloexec_files(me->files);
|
||||
|
||||
/*
|
||||
* Must be called _before_ exec_mmap() as bprm->mm is
|
||||
|
||||
@@ -364,7 +364,7 @@ static unsigned long fd_range_word(struct fd_range *range, unsigned int i)
|
||||
max(range->from, first) - first);
|
||||
}
|
||||
|
||||
/* Bits of word @i that dup_fd() leaves behind. */
|
||||
/* Bits of word @i that dup_fd() leaves behind and __range_close() closes. */
|
||||
static unsigned long dup_fd_dropped_word(struct fdtable *fdt, unsigned int i,
|
||||
struct fd_range *range)
|
||||
{
|
||||
@@ -531,7 +531,25 @@ struct files_struct *dup_fd(struct files_struct *oldf, struct fd_range *range)
|
||||
return newf;
|
||||
}
|
||||
|
||||
static struct fdtable *close_files(struct files_struct * files)
|
||||
/*
|
||||
* Unshare file descriptor table if it is being shared
|
||||
*/
|
||||
int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp)
|
||||
{
|
||||
struct files_struct *fd = current->files;
|
||||
|
||||
if ((unshare_flags & CLONE_FILES) &&
|
||||
(fd && atomic_read(&fd->count) > 1)) {
|
||||
fd = dup_fd(fd, NULL);
|
||||
if (IS_ERR(fd))
|
||||
return PTR_ERR(fd);
|
||||
*new_fdp = fd;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct fdtable *close_files(struct files_struct *files)
|
||||
{
|
||||
/*
|
||||
* It is safe to dereference the fd table without RCU or
|
||||
@@ -539,24 +557,21 @@ static struct fdtable *close_files(struct files_struct * files)
|
||||
* files structure.
|
||||
*/
|
||||
struct fdtable *fdt = rcu_dereference_raw(files->fdt);
|
||||
unsigned int i, j = 0;
|
||||
unsigned int j = fdt->max_fds / BITS_PER_LONG;
|
||||
|
||||
/* Highest fd first, the order the deferred puts ran in. */
|
||||
while (j--) {
|
||||
unsigned long set = fdt->open_fds[j];
|
||||
|
||||
for (;;) {
|
||||
unsigned long set;
|
||||
i = j * BITS_PER_LONG;
|
||||
if (i >= fdt->max_fds)
|
||||
break;
|
||||
set = fdt->open_fds[j++];
|
||||
while (set) {
|
||||
if (set & 1) {
|
||||
struct file *file = fdt->fd[i];
|
||||
if (file) {
|
||||
filp_close(file, files);
|
||||
cond_resched();
|
||||
}
|
||||
unsigned int bit = __fls(set);
|
||||
struct file *file = fdt->fd[j * BITS_PER_LONG + bit];
|
||||
|
||||
set ^= 1UL << bit;
|
||||
if (file) {
|
||||
filp_close_sync(file, files);
|
||||
cond_resched();
|
||||
}
|
||||
i++;
|
||||
set >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,16 +590,18 @@ void put_files_struct(struct files_struct *files)
|
||||
}
|
||||
}
|
||||
|
||||
/* Install @files on @tsk, consuming the reference, and put the old table. */
|
||||
void switch_files_struct(struct task_struct *tsk, struct files_struct *files)
|
||||
{
|
||||
scoped_guard(task_lock, tsk)
|
||||
swap(tsk->files, files);
|
||||
put_files_struct(files);
|
||||
}
|
||||
|
||||
void exit_files(struct task_struct *tsk)
|
||||
{
|
||||
struct files_struct * files = tsk->files;
|
||||
|
||||
if (files) {
|
||||
task_lock(tsk);
|
||||
tsk->files = NULL;
|
||||
task_unlock(tsk);
|
||||
put_files_struct(files);
|
||||
}
|
||||
if (tsk->files)
|
||||
switch_files_struct(tsk, NULL);
|
||||
}
|
||||
|
||||
struct files_struct init_files = {
|
||||
@@ -792,16 +809,13 @@ struct file *file_close_fd_locked(struct files_struct *files, unsigned fd)
|
||||
|
||||
int close_fd(unsigned fd)
|
||||
{
|
||||
struct files_struct *files = current->files;
|
||||
struct file *file;
|
||||
|
||||
spin_lock(&files->file_lock);
|
||||
file = file_close_fd_locked(files, fd);
|
||||
spin_unlock(&files->file_lock);
|
||||
file = file_close_fd(fd);
|
||||
if (!file)
|
||||
return -EBADF;
|
||||
|
||||
return filp_close(file, files);
|
||||
return filp_close(file, current->files);
|
||||
}
|
||||
EXPORT_SYMBOL(close_fd);
|
||||
|
||||
@@ -843,31 +857,42 @@ static inline void __range_cloexec(struct files_struct *cur_fds,
|
||||
spin_unlock(&cur_fds->file_lock);
|
||||
}
|
||||
|
||||
/* Next open descriptor in [fd, max_fd], or the next close-on-exec one. */
|
||||
static inline unsigned int next_open_fd(struct fdtable *fdt, unsigned int fd,
|
||||
unsigned int max_fd,
|
||||
struct fd_range *range)
|
||||
{
|
||||
if (range->flags & FD_RANGE_CLOEXEC_ONLY)
|
||||
return find_next_and_bit(fdt->open_fds, fdt->close_on_exec,
|
||||
max_fd + 1, fd);
|
||||
return find_next_bit(fdt->open_fds, max_fd + 1, fd);
|
||||
}
|
||||
|
||||
/* Next open descriptor in [fd, max_fd] that @range selects. */
|
||||
static inline unsigned int next_fd_to_close(struct fdtable *fdt,
|
||||
unsigned int fd, unsigned int max_fd,
|
||||
/* Highest open descriptor below @n that @range selects, or @n. */
|
||||
static inline unsigned int last_fd_to_close(struct fdtable *fdt, unsigned int n,
|
||||
struct fd_range *range)
|
||||
{
|
||||
fd = next_open_fd(fdt, fd, max_fd, range);
|
||||
/* Hop over the window the range keeps. */
|
||||
if ((range->flags & FD_RANGE_EXCEPT) &&
|
||||
fd >= range->from && fd <= range->to) {
|
||||
if (range->to >= max_fd)
|
||||
return max_fd + 1;
|
||||
fd = next_open_fd(fdt, range->to + 1, max_fd, range);
|
||||
unsigned int i, lo = 0;
|
||||
|
||||
if (!(range->flags & FD_RANGE_EXCEPT))
|
||||
lo = range->from / BITS_PER_LONG;
|
||||
for (i = n ? (n - 1) / BITS_PER_LONG + 1 : 0; i-- > lo; ) {
|
||||
unsigned long set = fdt->open_fds[i];
|
||||
|
||||
if (!set) {
|
||||
/* Skip the empty stretch at find_last_bit() speed. */
|
||||
unsigned int last = find_last_bit(fdt->open_fds, i * BITS_PER_LONG);
|
||||
|
||||
if (last >= i * BITS_PER_LONG)
|
||||
break;
|
||||
i = last / BITS_PER_LONG + 1;
|
||||
continue;
|
||||
}
|
||||
/* Hop below the kept window in one step. */
|
||||
if ((range->flags & FD_RANGE_EXCEPT) &&
|
||||
i * BITS_PER_LONG >= range->from &&
|
||||
i * BITS_PER_LONG + BITS_PER_LONG - 1 <= range->to) {
|
||||
if (!range->from)
|
||||
break;
|
||||
i = (range->from - 1) / BITS_PER_LONG + 1;
|
||||
continue;
|
||||
}
|
||||
set &= dup_fd_dropped_word(fdt, i, range);
|
||||
if (i == (n - 1) / BITS_PER_LONG)
|
||||
set &= BITMAP_LAST_WORD_MASK(n);
|
||||
if (set)
|
||||
return i * BITS_PER_LONG + __fls(set);
|
||||
}
|
||||
return fd;
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline void __range_close(struct files_struct *files,
|
||||
@@ -875,26 +900,23 @@ static inline void __range_close(struct files_struct *files,
|
||||
{
|
||||
struct file *file;
|
||||
struct fdtable *fdt;
|
||||
unsigned int fd, max_fd;
|
||||
unsigned int fd, n;
|
||||
|
||||
spin_lock(&files->file_lock);
|
||||
fdt = files_fdtable(files);
|
||||
if (range->flags & FD_RANGE_EXCEPT) {
|
||||
if (range->flags & FD_RANGE_EXCEPT)
|
||||
/* Outside of the range means the whole table. */
|
||||
fd = 0;
|
||||
max_fd = last_fd(fdt);
|
||||
} else {
|
||||
fd = range->from;
|
||||
max_fd = min(range->to, last_fd(fdt));
|
||||
}
|
||||
n = fdt->max_fds;
|
||||
else
|
||||
n = min(range->to, last_fd(fdt)) + 1;
|
||||
|
||||
for (fd = next_fd_to_close(fdt, fd, max_fd, range);
|
||||
fd <= max_fd;
|
||||
fd = next_fd_to_close(fdt, fd + 1, max_fd, range)) {
|
||||
/* Highest fd first, see close_files(). */
|
||||
while ((fd = last_fd_to_close(fdt, n, range)) < n) {
|
||||
n = fd;
|
||||
file = file_close_fd_locked(files, fd);
|
||||
if (file) {
|
||||
spin_unlock(&files->file_lock);
|
||||
filp_close(file, files);
|
||||
filp_close_sync(file, files);
|
||||
cond_resched();
|
||||
spin_lock(&files->file_lock);
|
||||
fdt = files_fdtable(files);
|
||||
@@ -986,10 +1008,7 @@ SYSCALL_DEFINE3(close_range, unsigned int, fd, unsigned int, max_fd,
|
||||
* We're done closing the files we were supposed to. Time to install
|
||||
* the new file descriptor table and drop the old one.
|
||||
*/
|
||||
task_lock(me);
|
||||
me->files = cur_fds;
|
||||
task_unlock(me);
|
||||
put_files_struct(fds);
|
||||
switch_files_struct(me, cur_fds);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1015,34 +1034,36 @@ struct file *file_close_fd(unsigned int fd)
|
||||
return file;
|
||||
}
|
||||
|
||||
void do_close_on_exec(struct files_struct *files)
|
||||
void close_cloexec_files(struct files_struct *files)
|
||||
{
|
||||
unsigned i;
|
||||
struct fdtable *fdt;
|
||||
|
||||
/* exec unshares first */
|
||||
spin_lock(&files->file_lock);
|
||||
for (i = 0; ; i++) {
|
||||
fdt = files_fdtable(files);
|
||||
/* Highest fd first, see close_files(). */
|
||||
for (i = fdt->max_fds / BITS_PER_LONG; i--; ) {
|
||||
unsigned long set;
|
||||
unsigned fd = i * BITS_PER_LONG;
|
||||
|
||||
fdt = files_fdtable(files);
|
||||
if (fd >= fdt->max_fds)
|
||||
break;
|
||||
set = fdt->close_on_exec[i];
|
||||
if (!set)
|
||||
continue;
|
||||
fdt->close_on_exec[i] = 0;
|
||||
for ( ; set ; fd++, set >>= 1) {
|
||||
while (set) {
|
||||
unsigned int bit = __fls(set);
|
||||
unsigned fd = i * BITS_PER_LONG + bit;
|
||||
struct file *file;
|
||||
if (!(set & 1))
|
||||
continue;
|
||||
|
||||
set ^= 1UL << bit;
|
||||
file = fdt->fd[fd];
|
||||
if (!file)
|
||||
continue;
|
||||
rcu_assign_pointer(fdt->fd[fd], NULL);
|
||||
__put_unused_fd(files, fd);
|
||||
spin_unlock(&files->file_lock);
|
||||
filp_close(file, files);
|
||||
filp_close_sync(file, files);
|
||||
cond_resched();
|
||||
spin_lock(&files->file_lock);
|
||||
}
|
||||
|
||||
@@ -198,6 +198,7 @@ extern struct file *do_file_open_root(const struct path *,
|
||||
extern struct open_how build_open_how(int flags, umode_t mode);
|
||||
extern int build_open_flags(const struct open_how *how, struct open_flags *op);
|
||||
struct file *file_close_fd_locked(struct files_struct *files, unsigned fd);
|
||||
int filp_close_sync(struct file *filp, fl_owner_t id);
|
||||
|
||||
int do_ftruncate(struct file *file, loff_t length, unsigned int flags);
|
||||
int chmod_common(const struct path *path, umode_t mode);
|
||||
|
||||
@@ -1562,6 +1562,19 @@ int filp_close(struct file *filp, fl_owner_t id)
|
||||
}
|
||||
EXPORT_SYMBOL(filp_close);
|
||||
|
||||
/* Like filp_close() but the last reference is put right here. */
|
||||
int filp_close_sync(struct file *filp, fl_owner_t id)
|
||||
{
|
||||
int retval;
|
||||
|
||||
/* Kernel threads must never put their final reference here. */
|
||||
VFS_WARN_ON_ONCE(current->flags & PF_KTHREAD);
|
||||
retval = filp_flush(filp, id);
|
||||
fput_close_sync(filp);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Careful here! We test whether the file pointer is NULL before
|
||||
* releasing the fd. This ensures that one clone task can't release
|
||||
@@ -1576,13 +1589,11 @@ SYSCALL_DEFINE1(close, unsigned int, fd)
|
||||
if (!file)
|
||||
return -EBADF;
|
||||
|
||||
retval = filp_flush(file, current->files);
|
||||
|
||||
/*
|
||||
* We're returning to user space. Don't bother
|
||||
* with any delayed fput() cases.
|
||||
*/
|
||||
fput_close_sync(file);
|
||||
retval = filp_close_sync(file, current->files);
|
||||
|
||||
if (likely(retval == 0))
|
||||
return 0;
|
||||
|
||||
@@ -100,7 +100,8 @@ static inline bool close_on_exec(unsigned int fd, const struct files_struct *fil
|
||||
struct task_struct;
|
||||
|
||||
void put_files_struct(struct files_struct *fs);
|
||||
int unshare_files(void);
|
||||
void switch_files_struct(struct task_struct *tsk, struct files_struct *files);
|
||||
int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp);
|
||||
enum fd_range_flags {
|
||||
/* Leave behind all descriptors outside of the specified range. */
|
||||
FD_RANGE_EXCEPT = (1U << 0),
|
||||
@@ -114,7 +115,7 @@ struct fd_range {
|
||||
enum fd_range_flags flags;
|
||||
};
|
||||
struct files_struct *dup_fd(struct files_struct *, struct fd_range *) __latent_entropy;
|
||||
void do_close_on_exec(struct files_struct *);
|
||||
void close_cloexec_files(struct files_struct *);
|
||||
int iterate_fd(struct files_struct *, unsigned,
|
||||
int (*)(const void *, struct file *, unsigned),
|
||||
const void *);
|
||||
|
||||
@@ -80,9 +80,9 @@ struct core_thread {
|
||||
};
|
||||
|
||||
struct core_state {
|
||||
atomic_t nr_threads;
|
||||
struct core_thread dumper;
|
||||
struct completion startup;
|
||||
/* Threads the dumper still waits for. */
|
||||
atomic_t threads_remaining;
|
||||
struct core_thread *tasks;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -432,6 +432,32 @@ do { \
|
||||
__ret; \
|
||||
})
|
||||
|
||||
/**
|
||||
* wait_var_event_state - wait for a variable to be updated and notified
|
||||
* @var: the address of variable being waited on
|
||||
* @condition: the condition to wait for
|
||||
* @state: the task state to sleep in, %TASK_UNINTERRUPTIBLE etc.
|
||||
*
|
||||
* Wait for a @condition to be true, only re-checking when a wake up is
|
||||
* received for the given @var (an arbitrary kernel address which need
|
||||
* not be directly related to the given condition, but usually is).
|
||||
*
|
||||
* Returns 0 if the condition became true, or %-ERESTARTSYS if a signal
|
||||
* arrived which @state allows to interrupt.
|
||||
*
|
||||
* The condition should normally use smp_load_acquire() or a similarly
|
||||
* ordered access to ensure that any changes to memory made before the
|
||||
* condition became true will be visible after the wait completes.
|
||||
*/
|
||||
#define wait_var_event_state(var, condition, state) \
|
||||
({ \
|
||||
int __ret = 0; \
|
||||
might_sleep(); \
|
||||
if (!(condition)) \
|
||||
__ret = ___wait_var_event(var, condition, (state), 0, 0, schedule()); \
|
||||
__ret; \
|
||||
})
|
||||
|
||||
/**
|
||||
* wait_var_event_any_lock - wait for a variable to be updated under a lock
|
||||
* @var: the address of the variable being waited on
|
||||
|
||||
+8
-7
@@ -17,6 +17,7 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/capability.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/wait_bit.h>
|
||||
#include <linux/personality.h>
|
||||
#include <linux/tty.h>
|
||||
#include <linux/iocontext.h>
|
||||
@@ -436,15 +437,14 @@ static void coredump_task_exit(struct task_struct *tsk,
|
||||
|
||||
self.task = tsk;
|
||||
if (self.task->flags & PF_SIGNALED)
|
||||
self.next = xchg(&core_state->dumper.next, &self);
|
||||
self.next = xchg(&core_state->tasks, &self);
|
||||
else
|
||||
self.task = NULL;
|
||||
/*
|
||||
* Implies mb(), the result of xchg() must be visible
|
||||
* to core_state->dumper.
|
||||
* to the dumper.
|
||||
*/
|
||||
if (atomic_dec_and_test(&core_state->nr_threads))
|
||||
complete(&core_state->startup);
|
||||
atomic_dec_and_wake_up(&core_state->threads_remaining);
|
||||
|
||||
for (;;) {
|
||||
set_current_state(TASK_IDLE|TASK_FREEZABLE);
|
||||
@@ -892,7 +892,7 @@ static void synchronize_group_exit(struct task_struct *tsk, long code)
|
||||
* Serialize with any possible pending coredump.
|
||||
* We must hold siglock around checking core_state
|
||||
* and setting PF_POSTCOREDUMP. The core-inducing thread
|
||||
* will increment ->nr_threads for each thread in the
|
||||
* will increment ->threads_remaining for each thread in the
|
||||
* group without PF_POSTCOREDUMP set.
|
||||
*/
|
||||
tsk->flags |= PF_POSTCOREDUMP;
|
||||
@@ -978,10 +978,11 @@ void __noreturn do_exit(long code)
|
||||
|
||||
exit_sem(tsk);
|
||||
exit_shm(tsk);
|
||||
exit_files(tsk);
|
||||
exit_fs(tsk);
|
||||
/* Hang the tty up before the last close of it can clear the session. */
|
||||
if (group_dead)
|
||||
disassociate_ctty(1);
|
||||
exit_files(tsk);
|
||||
exit_fs(tsk);
|
||||
exit_nsproxy_namespaces(tsk);
|
||||
exit_task_work(tsk);
|
||||
exit_thread(tsk);
|
||||
|
||||
+8
-49
@@ -1685,6 +1685,7 @@ static int copy_files(u64 clone_flags, struct task_struct *tsk,
|
||||
|
||||
if (clone_flags & CLONE_FILES) {
|
||||
atomic_inc(&oldf->count);
|
||||
tsk->files = oldf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2205,6 +2206,8 @@ __latent_entropy struct task_struct *copy_process(
|
||||
INIT_LIST_HEAD(&p->sibling);
|
||||
rcu_copy_process(p);
|
||||
p->vfork_done = NULL;
|
||||
/* Set by copy_files(), exit_files() on the error path skips NULL. */
|
||||
p->files = NULL;
|
||||
spin_lock_init(&p->alloc_lock);
|
||||
|
||||
init_sigpending(&p->pending);
|
||||
@@ -2308,7 +2311,7 @@ __latent_entropy struct task_struct *copy_process(
|
||||
(args->umh ? COPY_FS_UMH : 0) |
|
||||
(args->idle ? COPY_FS_IDLE : 0));
|
||||
if (retval)
|
||||
goto bad_fork_cleanup_files;
|
||||
goto bad_fork_cleanup_semundo;
|
||||
retval = copy_sighand(clone_flags, p);
|
||||
if (retval)
|
||||
goto bad_fork_cleanup_fs;
|
||||
@@ -2622,8 +2625,6 @@ bad_fork_cleanup_sighand:
|
||||
__cleanup_sighand(p->sighand);
|
||||
bad_fork_cleanup_fs:
|
||||
exit_fs(p); /* blocking */
|
||||
bad_fork_cleanup_files:
|
||||
exit_files(p); /* blocking */
|
||||
bad_fork_cleanup_semundo:
|
||||
exit_sem(p);
|
||||
bad_fork_cleanup_security:
|
||||
@@ -2634,6 +2635,8 @@ bad_fork_cleanup_perf:
|
||||
perf_event_free_task(p);
|
||||
bad_fork_sched_cancel_fork:
|
||||
sched_cancel_fork(p);
|
||||
/* ->release() of a file may need scx_fork_rwsem for write. */
|
||||
exit_files(p); /* blocking */
|
||||
bad_fork_cleanup_policy:
|
||||
lockdep_free_task(p);
|
||||
#ifdef CONFIG_NUMA
|
||||
@@ -3223,24 +3226,6 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unshare file descriptor table if it is being shared
|
||||
*/
|
||||
static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp)
|
||||
{
|
||||
struct files_struct *fd = current->files;
|
||||
|
||||
if ((unshare_flags & CLONE_FILES) &&
|
||||
(fd && atomic_read(&fd->count) > 1)) {
|
||||
fd = dup_fd(fd, NULL);
|
||||
if (IS_ERR(fd))
|
||||
return PTR_ERR(fd);
|
||||
*new_fdp = fd;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* unshare allows a process to 'unshare' part of the process
|
||||
* context which was originally shared using clone. copy_*
|
||||
@@ -3339,10 +3324,8 @@ int ksys_unshare(unsigned long unshare_flags)
|
||||
new_nsproxy = NULL;
|
||||
}
|
||||
|
||||
if (new_fd) {
|
||||
guard(task_lock)(current);
|
||||
swap(current->files, new_fd);
|
||||
}
|
||||
if (new_fd)
|
||||
switch_files_struct(current, no_free_ptr(new_fd));
|
||||
|
||||
if (new_cred) {
|
||||
/* Install the new user namespace */
|
||||
@@ -3376,30 +3359,6 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
|
||||
return ksys_unshare(unshare_flags);
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper to unshare the files of the current task.
|
||||
* We don't want to expose copy_files internals to
|
||||
* the exec layer of the kernel.
|
||||
*/
|
||||
|
||||
int unshare_files(void)
|
||||
{
|
||||
struct task_struct *task = current;
|
||||
struct files_struct *old, *copy = NULL;
|
||||
int error;
|
||||
|
||||
error = unshare_fd(CLONE_FILES, ©);
|
||||
if (error || !copy)
|
||||
return error;
|
||||
|
||||
old = task->files;
|
||||
task_lock(task);
|
||||
task->files = copy;
|
||||
task_unlock(task);
|
||||
put_files_struct(old);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sysctl_max_threads(const struct ctl_table *table, int write,
|
||||
void *buffer, size_t *lenp, loff_t *ppos)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user