2019-05-27 08:55:02 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-02-14 19:34:32 -08:00
|
|
|
|
2005-11-15 15:53:48 -05:00
|
|
|
/*
|
|
|
|
* SPU file system
|
|
|
|
*
|
|
|
|
* (C) Copyright IBM Deutschland Entwicklung GmbH 2005
|
|
|
|
*
|
|
|
|
* Author: Arnd Bergmann <arndb@de.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/fs.h>
|
2019-03-21 10:34:14 +00:00
|
|
|
#include <linux/fs_context.h>
|
|
|
|
#include <linux/fs_parser.h>
|
2008-05-06 09:24:24 +10:00
|
|
|
#include <linux/fsnotify.h>
|
2005-11-15 15:53:48 -05:00
|
|
|
#include <linux/backing-dev.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ioctl.h>
|
|
|
|
#include <linux/module.h>
|
2006-01-04 20:31:26 +01:00
|
|
|
#include <linux/mount.h>
|
2005-11-15 15:53:48 -05:00
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/poll.h>
|
2022-03-08 20:20:25 +01:00
|
|
|
#include <linux/of.h>
|
2021-09-20 14:33:13 +02:00
|
|
|
#include <linux/seq_file.h>
|
2005-11-15 15:53:48 -05:00
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#include <asm/spu.h>
|
2007-04-23 21:08:29 +02:00
|
|
|
#include <asm/spu_priv1.h>
|
2016-12-24 11:46:01 -08:00
|
|
|
#include <linux/uaccess.h>
|
2005-11-15 15:53:48 -05:00
|
|
|
|
|
|
|
#include "spufs.h"
|
|
|
|
|
2008-07-03 11:42:20 +10:00
|
|
|
struct spufs_sb_info {
|
2019-03-21 10:34:14 +00:00
|
|
|
bool debug;
|
2008-07-03 11:42:20 +10:00
|
|
|
};
|
|
|
|
|
2006-12-06 20:33:20 -08:00
|
|
|
static struct kmem_cache *spufs_inode_cache;
|
2006-11-20 18:45:10 +01:00
|
|
|
char *isolated_loader;
|
2007-09-19 14:38:12 +10:00
|
|
|
static int isolated_loader_size;
|
2005-11-15 15:53:48 -05:00
|
|
|
|
2008-07-03 11:42:20 +10:00
|
|
|
static struct spufs_sb_info *spufs_get_sb_info(struct super_block *sb)
|
|
|
|
{
|
|
|
|
return sb->s_fs_info;
|
|
|
|
}
|
|
|
|
|
2005-11-15 15:53:48 -05:00
|
|
|
static struct inode *
|
|
|
|
spufs_alloc_inode(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct spufs_inode_info *ei;
|
|
|
|
|
2006-12-06 20:33:17 -08:00
|
|
|
ei = kmem_cache_alloc(spufs_inode_cache, GFP_KERNEL);
|
2005-11-15 15:53:48 -05:00
|
|
|
if (!ei)
|
|
|
|
return NULL;
|
2006-10-04 17:26:15 +02:00
|
|
|
|
|
|
|
ei->i_gang = NULL;
|
|
|
|
ei->i_ctx = NULL;
|
2007-04-23 21:08:07 +02:00
|
|
|
ei->i_openers = 0;
|
2006-10-04 17:26:15 +02:00
|
|
|
|
2005-11-15 15:53:48 -05:00
|
|
|
return &ei->vfs_inode;
|
|
|
|
}
|
|
|
|
|
2019-04-10 14:55:32 -04:00
|
|
|
static void spufs_free_inode(struct inode *inode)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
|
|
|
kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-07-25 19:45:34 -07:00
|
|
|
spufs_init_once(void *p)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
|
|
|
struct spufs_inode_info *ei = p;
|
|
|
|
|
2007-05-16 22:10:57 -07:00
|
|
|
inode_init_once(&ei->vfs_inode);
|
2005-11-15 15:53:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct inode *
|
2011-07-26 04:47:14 -04:00
|
|
|
spufs_new_inode(struct super_block *sb, umode_t mode)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
inode = new_inode(sb);
|
|
|
|
if (!inode)
|
|
|
|
goto out;
|
|
|
|
|
2013-04-23 15:13:14 +00:00
|
|
|
inode->i_ino = get_next_ino();
|
2005-11-15 15:53:48 -05:00
|
|
|
inode->i_mode = mode;
|
2008-11-14 10:38:39 +11:00
|
|
|
inode->i_uid = current_fsuid();
|
|
|
|
inode->i_gid = current_fsgid();
|
2023-10-04 14:51:48 -04:00
|
|
|
simple_inode_init_ts(inode);
|
2005-11-15 15:53:48 -05:00
|
|
|
out:
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2023-01-13 12:49:11 +01:00
|
|
|
spufs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
|
2021-01-21 14:19:43 +01:00
|
|
|
struct iattr *attr)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
2015-03-17 22:26:12 +00:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2005-11-15 15:53:48 -05:00
|
|
|
|
|
|
|
if ((attr->ia_valid & ATTR_SIZE) &&
|
|
|
|
(attr->ia_size != inode->i_size))
|
|
|
|
return -EINVAL;
|
2023-01-13 12:49:11 +01:00
|
|
|
setattr_copy(&nop_mnt_idmap, inode, attr);
|
2010-06-04 11:30:02 +02:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
return 0;
|
2005-11-15 15:53:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
spufs_new_file(struct super_block *sb, struct dentry *dentry,
|
2011-07-26 04:47:14 -04:00
|
|
|
const struct file_operations *fops, umode_t mode,
|
2008-06-30 12:17:28 +10:00
|
|
|
size_t size, struct spu_context *ctx)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
2009-09-21 17:01:11 -07:00
|
|
|
static const struct inode_operations spufs_file_iops = {
|
2005-11-15 15:53:48 -05:00
|
|
|
.setattr = spufs_setattr,
|
|
|
|
};
|
|
|
|
struct inode *inode;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = -ENOSPC;
|
|
|
|
inode = spufs_new_inode(sb, S_IFREG | mode);
|
|
|
|
if (!inode)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
inode->i_op = &spufs_file_iops;
|
|
|
|
inode->i_fop = fops;
|
2008-06-30 12:17:28 +10:00
|
|
|
inode->i_size = size;
|
2006-09-27 01:50:46 -07:00
|
|
|
inode->i_private = SPUFS_I(inode)->i_ctx = get_spu_context(ctx);
|
2005-11-15 15:53:48 -05:00
|
|
|
d_add(dentry, inode);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-06-05 21:20:32 -04:00
|
|
|
spufs_evict_inode(struct inode *inode)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
2006-10-04 17:26:15 +02:00
|
|
|
struct spufs_inode_info *ei = SPUFS_I(inode);
|
2012-05-03 14:48:02 +02:00
|
|
|
clear_inode(inode);
|
2006-10-04 17:26:15 +02:00
|
|
|
if (ei->i_ctx)
|
|
|
|
put_spu_context(ei->i_ctx);
|
|
|
|
if (ei->i_gang)
|
|
|
|
put_spu_gang(ei->i_gang);
|
2005-11-15 15:53:48 -05:00
|
|
|
}
|
|
|
|
|
2006-10-04 17:26:15 +02:00
|
|
|
/* Caller must hold parent->i_mutex */
|
2024-05-09 16:36:24 -04:00
|
|
|
static void spufs_rmdir(struct inode *parent, struct dentry *dir)
|
2006-01-04 20:31:27 +01:00
|
|
|
{
|
2024-05-09 16:36:24 -04:00
|
|
|
struct spu_context *ctx = SPUFS_I(d_inode(dir))->i_ctx;
|
|
|
|
|
|
|
|
locked_recursive_removal(dir, NULL);
|
|
|
|
spu_forget(ctx);
|
2005-11-15 15:53:48 -05:00
|
|
|
}
|
|
|
|
|
2009-02-17 11:44:14 +11:00
|
|
|
static int spufs_fill_dir(struct dentry *dir,
|
2011-07-26 04:47:14 -04:00
|
|
|
const struct spufs_tree_descr *files, umode_t mode,
|
2009-02-17 11:44:14 +11:00
|
|
|
struct spu_context *ctx)
|
2006-01-04 20:31:27 +01:00
|
|
|
{
|
|
|
|
while (files->name && files->name[0]) {
|
2013-01-28 20:37:21 -05:00
|
|
|
int ret;
|
|
|
|
struct dentry *dentry = d_alloc_name(dir, files->name);
|
2006-01-04 20:31:27 +01:00
|
|
|
if (!dentry)
|
2013-01-28 20:37:21 -05:00
|
|
|
return -ENOMEM;
|
2006-01-04 20:31:27 +01:00
|
|
|
ret = spufs_new_file(dir->d_sb, dentry, files->ops,
|
2008-06-30 12:17:28 +10:00
|
|
|
files->mode & mode, files->size, ctx);
|
2025-03-08 19:26:31 -05:00
|
|
|
if (ret) {
|
|
|
|
dput(dentry);
|
2013-01-28 20:37:21 -05:00
|
|
|
return ret;
|
2025-03-08 19:26:31 -05:00
|
|
|
}
|
2006-01-04 20:31:27 +01:00
|
|
|
files++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
spufs: fix gang directory lifetimes
prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have
a problem with gang lifetimes - creation of a gang returns opened
gang directory, which normally gets removed when that gets closed,
but if somebody has created a context belonging to that gang and
kept it alive until the gang got closed, removal failed and we
ended up with a leak.
Unfortunately, it had been fixed the wrong way. Dentry of gang
directory was no longer pinned, and rmdir on close was gone.
One problem was that failure of open kept calling simple_rmdir()
as cleanup, which meant an unbalanced dput(). Another bug was
in the success case - gang creation incremented link count on
root directory, but that was no longer undone when gang got
destroyed.
Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped
in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.
Fixes: 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2025-03-12 19:18:39 -04:00
|
|
|
static void unuse_gang(struct dentry *dir)
|
|
|
|
{
|
|
|
|
struct inode *inode = dir->d_inode;
|
|
|
|
struct spu_gang *gang = SPUFS_I(inode)->i_gang;
|
|
|
|
|
|
|
|
if (gang) {
|
|
|
|
bool dead;
|
|
|
|
|
|
|
|
inode_lock(inode); // exclusion with spufs_create_context()
|
|
|
|
dead = !--gang->alive;
|
|
|
|
inode_unlock(inode);
|
|
|
|
|
|
|
|
if (dead)
|
|
|
|
simple_recursive_removal(dir, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-15 15:53:48 -05:00
|
|
|
static int spufs_dir_close(struct inode *inode, struct file *file)
|
|
|
|
{
|
2006-10-04 17:26:15 +02:00
|
|
|
struct inode *parent;
|
|
|
|
struct dentry *dir;
|
2005-11-15 15:53:48 -05:00
|
|
|
|
2006-12-08 02:37:30 -08:00
|
|
|
dir = file->f_path.dentry;
|
2015-03-17 22:26:12 +00:00
|
|
|
parent = d_inode(dir->d_parent);
|
2006-01-04 20:31:22 +01:00
|
|
|
|
2016-01-22 15:40:57 -05:00
|
|
|
inode_lock_nested(parent, I_MUTEX_PARENT);
|
2024-05-09 16:36:24 -04:00
|
|
|
spufs_rmdir(parent, dir);
|
2016-01-22 15:40:57 -05:00
|
|
|
inode_unlock(parent);
|
2006-01-04 20:31:22 +01:00
|
|
|
|
spufs: fix gang directory lifetimes
prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have
a problem with gang lifetimes - creation of a gang returns opened
gang directory, which normally gets removed when that gets closed,
but if somebody has created a context belonging to that gang and
kept it alive until the gang got closed, removal failed and we
ended up with a leak.
Unfortunately, it had been fixed the wrong way. Dentry of gang
directory was no longer pinned, and rmdir on close was gone.
One problem was that failure of open kept calling simple_rmdir()
as cleanup, which meant an unbalanced dput(). Another bug was
in the success case - gang creation incremented link count on
root directory, but that was no longer undone when gang got
destroyed.
Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped
in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.
Fixes: 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2025-03-12 19:18:39 -04:00
|
|
|
unuse_gang(dir->d_parent);
|
2005-11-15 15:53:48 -05:00
|
|
|
return dcache_dir_close(inode, file);
|
|
|
|
}
|
|
|
|
|
2007-02-12 00:55:31 -08:00
|
|
|
const struct file_operations spufs_context_fops = {
|
2005-11-15 15:53:48 -05:00
|
|
|
.open = dcache_dir_open,
|
|
|
|
.release = spufs_dir_close,
|
|
|
|
.llseek = dcache_dir_lseek,
|
|
|
|
.read = generic_read_dir,
|
2016-04-20 19:52:15 -04:00
|
|
|
.iterate_shared = dcache_readdir,
|
2010-05-26 17:53:41 +02:00
|
|
|
.fsync = noop_fsync,
|
2005-11-15 15:53:48 -05:00
|
|
|
};
|
[POWERPC] coredump: Add SPU elf notes to coredump.
This patch adds SPU elf notes to the coredump. It creates a separate note
for each of /regs, /fpcr, /lslr, /decr, /decr_status, /mem, /signal1,
/signal1_type, /signal2, /signal2_type, /event_mask, /event_status,
/mbox_info, /ibox_info, /wbox_info, /dma_info, /proxydma_info, /object-id.
A new macro, ARCH_HAVE_EXTRA_NOTES, was created for architectures to
specify they have extra elf core notes.
A new macro, ELF_CORE_EXTRA_NOTES_SIZE, was created so the size of the
additional notes could be calculated and added to the notes phdr entry.
A new macro, ELF_CORE_WRITE_EXTRA_NOTES, was created so the new notes
would be written after the existing notes.
The SPU coredump code resides in spufs. Stub functions are provided in the
kernel which are hooked into the spufs code which does the actual work via
register_arch_coredump_calls().
A new set of __spufs_<file>_read/get() functions was provided to allow the
coredump code to read from the spufs files without having to lock the
SPU context for each file read from.
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Dwayne Grant McConnell <decimal@us.ibm.com>
Signed-off-by: Arnd Bergmann <arnd.bergmann@de.ibm.com>
2006-11-23 00:46:37 +01:00
|
|
|
EXPORT_SYMBOL_GPL(spufs_context_fops);
|
2005-11-15 15:53:48 -05:00
|
|
|
|
|
|
|
static int
|
2006-10-04 17:26:14 +02:00
|
|
|
spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
|
2011-07-26 04:47:14 -04:00
|
|
|
umode_t mode)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct inode *inode;
|
|
|
|
struct spu_context *ctx;
|
|
|
|
|
|
|
|
inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
|
|
|
|
if (!inode)
|
2013-01-28 20:37:21 -05:00
|
|
|
return -ENOSPC;
|
2005-11-15 15:53:48 -05:00
|
|
|
|
2023-01-13 12:49:25 +01:00
|
|
|
inode_init_owner(&nop_mnt_idmap, inode, dir, mode | S_IFDIR);
|
2006-10-04 17:26:15 +02:00
|
|
|
ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
|
2005-11-15 15:53:48 -05:00
|
|
|
SPUFS_I(inode)->i_ctx = ctx;
|
2013-01-28 20:37:21 -05:00
|
|
|
if (!ctx) {
|
|
|
|
iput(inode);
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
2005-11-15 15:53:48 -05:00
|
|
|
|
2006-10-04 17:26:14 +02:00
|
|
|
ctx->flags = flags;
|
2007-06-29 10:57:59 +10:00
|
|
|
inode->i_op = &simple_dir_inode_operations;
|
2005-11-15 15:53:48 -05:00
|
|
|
inode->i_fop = &simple_dir_operations;
|
2013-01-28 20:37:21 -05:00
|
|
|
|
2016-01-22 15:40:57 -05:00
|
|
|
inode_lock(inode);
|
2013-01-28 20:37:21 -05:00
|
|
|
|
|
|
|
dget(dentry);
|
|
|
|
inc_nlink(dir);
|
|
|
|
inc_nlink(inode);
|
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
|
2006-10-24 18:31:16 +02:00
|
|
|
if (flags & SPU_CREATE_NOSCHED)
|
|
|
|
ret = spufs_fill_dir(dentry, spufs_dir_nosched_contents,
|
|
|
|
mode, ctx);
|
|
|
|
else
|
|
|
|
ret = spufs_fill_dir(dentry, spufs_dir_contents, mode, ctx);
|
|
|
|
|
2013-01-28 20:37:21 -05:00
|
|
|
if (!ret && spufs_get_sb_info(dir->i_sb)->debug)
|
2008-07-03 11:42:20 +10:00
|
|
|
ret = spufs_fill_dir(dentry, spufs_dir_debug_contents,
|
|
|
|
mode, ctx);
|
|
|
|
|
2024-05-09 16:36:24 -04:00
|
|
|
inode_unlock(inode);
|
|
|
|
|
2008-07-03 11:42:20 +10:00
|
|
|
if (ret)
|
2013-01-28 20:37:21 -05:00
|
|
|
spufs_rmdir(dir, dentry);
|
|
|
|
|
2005-11-15 15:53:48 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-08-04 13:21:17 -04:00
|
|
|
static int spufs_context_open(const struct path *path)
|
2006-01-04 20:31:26 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct file *filp;
|
|
|
|
|
2014-12-10 15:45:39 -08:00
|
|
|
ret = get_unused_fd_flags(0);
|
2012-06-25 11:46:13 +04:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2006-01-04 20:31:26 +01:00
|
|
|
|
2012-06-26 21:58:53 +04:00
|
|
|
filp = dentry_open(path, O_RDONLY, current_cred());
|
2006-01-04 20:31:26 +01:00
|
|
|
if (IS_ERR(filp)) {
|
|
|
|
put_unused_fd(ret);
|
2012-06-25 11:46:13 +04:00
|
|
|
return PTR_ERR(filp);
|
2006-01-04 20:31:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
filp->f_op = &spufs_context_fops;
|
|
|
|
fd_install(ret, filp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-20 21:39:47 +02:00
|
|
|
static struct spu_context *
|
|
|
|
spufs_assert_affinity(unsigned int flags, struct spu_gang *gang,
|
|
|
|
struct file *filp)
|
|
|
|
{
|
2008-01-11 15:03:26 +11:00
|
|
|
struct spu_context *tmp, *neighbor, *err;
|
2007-07-20 21:39:47 +02:00
|
|
|
int count, node;
|
|
|
|
int aff_supp;
|
|
|
|
|
|
|
|
aff_supp = !list_empty(&(list_entry(cbe_spu_info[0].spus.next,
|
|
|
|
struct spu, cbe_list))->aff_list);
|
|
|
|
|
|
|
|
if (!aff_supp)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
if (flags & SPU_CREATE_GANG)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
if (flags & SPU_CREATE_AFFINITY_MEM &&
|
|
|
|
gang->aff_ref_ctx &&
|
|
|
|
gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM)
|
|
|
|
return ERR_PTR(-EEXIST);
|
|
|
|
|
|
|
|
if (gang->aff_flags & AFF_MERGED)
|
|
|
|
return ERR_PTR(-EBUSY);
|
|
|
|
|
|
|
|
neighbor = NULL;
|
|
|
|
if (flags & SPU_CREATE_AFFINITY_SPU) {
|
|
|
|
if (!filp || filp->f_op != &spufs_context_fops)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
neighbor = get_spu_context(
|
2013-01-23 17:07:38 -05:00
|
|
|
SPUFS_I(file_inode(filp))->i_ctx);
|
2007-07-20 21:39:47 +02:00
|
|
|
|
|
|
|
if (!list_empty(&neighbor->aff_list) && !(neighbor->aff_head) &&
|
|
|
|
!list_is_last(&neighbor->aff_list, &gang->aff_list_head) &&
|
|
|
|
!list_entry(neighbor->aff_list.next, struct spu_context,
|
2008-01-11 15:03:26 +11:00
|
|
|
aff_list)->aff_head) {
|
|
|
|
err = ERR_PTR(-EEXIST);
|
|
|
|
goto out_put_neighbor;
|
|
|
|
}
|
2007-07-20 21:39:47 +02:00
|
|
|
|
2008-01-11 15:03:26 +11:00
|
|
|
if (gang != neighbor->gang) {
|
|
|
|
err = ERR_PTR(-EINVAL);
|
|
|
|
goto out_put_neighbor;
|
|
|
|
}
|
2007-07-20 21:39:47 +02:00
|
|
|
|
|
|
|
count = 1;
|
|
|
|
list_for_each_entry(tmp, &gang->aff_list_head, aff_list)
|
|
|
|
count++;
|
|
|
|
if (list_empty(&neighbor->aff_list))
|
|
|
|
count++;
|
|
|
|
|
|
|
|
for (node = 0; node < MAX_NUMNODES; node++) {
|
|
|
|
if ((cbe_spu_info[node].n_spus - atomic_read(
|
|
|
|
&cbe_spu_info[node].reserved_spus)) >= count)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-01-11 15:03:26 +11:00
|
|
|
if (node == MAX_NUMNODES) {
|
|
|
|
err = ERR_PTR(-EEXIST);
|
|
|
|
goto out_put_neighbor;
|
|
|
|
}
|
2007-07-20 21:39:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return neighbor;
|
2008-01-11 15:03:26 +11:00
|
|
|
|
|
|
|
out_put_neighbor:
|
|
|
|
put_spu_context(neighbor);
|
|
|
|
return err;
|
2007-07-20 21:39:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spufs_set_affinity(unsigned int flags, struct spu_context *ctx,
|
|
|
|
struct spu_context *neighbor)
|
|
|
|
{
|
|
|
|
if (flags & SPU_CREATE_AFFINITY_MEM)
|
|
|
|
ctx->gang->aff_ref_ctx = ctx;
|
|
|
|
|
|
|
|
if (flags & SPU_CREATE_AFFINITY_SPU) {
|
|
|
|
if (list_empty(&neighbor->aff_list)) {
|
|
|
|
list_add_tail(&neighbor->aff_list,
|
|
|
|
&ctx->gang->aff_list_head);
|
|
|
|
neighbor->aff_head = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list_is_last(&neighbor->aff_list, &ctx->gang->aff_list_head)
|
|
|
|
|| list_entry(neighbor->aff_list.next, struct spu_context,
|
|
|
|
aff_list)->aff_head) {
|
|
|
|
list_add(&ctx->aff_list, &neighbor->aff_list);
|
|
|
|
} else {
|
|
|
|
list_add_tail(&ctx->aff_list, &neighbor->aff_list);
|
|
|
|
if (neighbor->aff_head) {
|
|
|
|
neighbor->aff_head = 0;
|
|
|
|
ctx->aff_head = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ctx->gang->aff_ref_ctx)
|
|
|
|
ctx->gang->aff_ref_ctx = ctx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spufs_create_context(struct inode *inode, struct dentry *dentry,
|
2011-07-26 04:47:14 -04:00
|
|
|
struct vfsmount *mnt, int flags, umode_t mode,
|
2007-07-20 21:39:47 +02:00
|
|
|
struct file *aff_filp)
|
2006-10-04 17:26:15 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2007-07-20 21:39:47 +02:00
|
|
|
int affinity;
|
spufs: fix gang directory lifetimes
prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have
a problem with gang lifetimes - creation of a gang returns opened
gang directory, which normally gets removed when that gets closed,
but if somebody has created a context belonging to that gang and
kept it alive until the gang got closed, removal failed and we
ended up with a leak.
Unfortunately, it had been fixed the wrong way. Dentry of gang
directory was no longer pinned, and rmdir on close was gone.
One problem was that failure of open kept calling simple_rmdir()
as cleanup, which meant an unbalanced dput(). Another bug was
in the success case - gang creation incremented link count on
root directory, but that was no longer undone when gang got
destroyed.
Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped
in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.
Fixes: 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2025-03-12 19:18:39 -04:00
|
|
|
struct spu_gang *gang = SPUFS_I(inode)->i_gang;
|
2007-07-20 21:39:47 +02:00
|
|
|
struct spu_context *neighbor;
|
2012-06-26 21:58:53 +04:00
|
|
|
struct path path = {.mnt = mnt, .dentry = dentry};
|
2006-10-04 17:26:15 +02:00
|
|
|
|
2006-10-24 18:31:16 +02:00
|
|
|
if ((flags & SPU_CREATE_NOSCHED) &&
|
|
|
|
!capable(CAP_SYS_NICE))
|
2012-07-19 16:12:22 +04:00
|
|
|
return -EPERM;
|
2006-10-24 18:31:16 +02:00
|
|
|
|
|
|
|
if ((flags & (SPU_CREATE_NOSCHED | SPU_CREATE_ISOLATE))
|
|
|
|
== SPU_CREATE_ISOLATE)
|
2012-07-19 16:12:22 +04:00
|
|
|
return -EINVAL;
|
2006-10-24 18:31:16 +02:00
|
|
|
|
2006-11-27 19:18:52 +01:00
|
|
|
if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
|
2012-07-19 16:12:22 +04:00
|
|
|
return -ENODEV;
|
2006-11-27 19:18:52 +01:00
|
|
|
|
spufs: fix gang directory lifetimes
prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have
a problem with gang lifetimes - creation of a gang returns opened
gang directory, which normally gets removed when that gets closed,
but if somebody has created a context belonging to that gang and
kept it alive until the gang got closed, removal failed and we
ended up with a leak.
Unfortunately, it had been fixed the wrong way. Dentry of gang
directory was no longer pinned, and rmdir on close was gone.
One problem was that failure of open kept calling simple_rmdir()
as cleanup, which meant an unbalanced dput(). Another bug was
in the success case - gang creation incremented link count on
root directory, but that was no longer undone when gang got
destroyed.
Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped
in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.
Fixes: 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2025-03-12 19:18:39 -04:00
|
|
|
if (gang) {
|
|
|
|
if (!gang->alive)
|
|
|
|
return -ENOENT;
|
|
|
|
gang->alive++;
|
|
|
|
}
|
|
|
|
|
2007-07-20 21:39:47 +02:00
|
|
|
neighbor = NULL;
|
|
|
|
affinity = flags & (SPU_CREATE_AFFINITY_MEM | SPU_CREATE_AFFINITY_SPU);
|
|
|
|
if (affinity) {
|
|
|
|
if (!gang)
|
2012-07-19 16:12:22 +04:00
|
|
|
return -EINVAL;
|
2007-07-20 21:39:47 +02:00
|
|
|
mutex_lock(&gang->aff_mutex);
|
|
|
|
neighbor = spufs_assert_affinity(flags, gang, aff_filp);
|
|
|
|
if (IS_ERR(neighbor)) {
|
|
|
|
ret = PTR_ERR(neighbor);
|
|
|
|
goto out_aff_unlock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-12 14:54:13 +11:00
|
|
|
ret = spufs_mkdir(inode, dentry, flags, mode & 0777);
|
2025-03-12 19:38:28 -04:00
|
|
|
if (ret) {
|
|
|
|
if (neighbor)
|
|
|
|
put_spu_context(neighbor);
|
2007-07-20 21:39:47 +02:00
|
|
|
goto out_aff_unlock;
|
2025-03-12 19:38:28 -04:00
|
|
|
}
|
2007-07-20 21:39:47 +02:00
|
|
|
|
2008-01-11 15:03:26 +11:00
|
|
|
if (affinity) {
|
2015-03-17 22:26:12 +00:00
|
|
|
spufs_set_affinity(flags, SPUFS_I(d_inode(dentry))->i_ctx,
|
2007-07-20 21:39:47 +02:00
|
|
|
neighbor);
|
2008-01-11 15:03:26 +11:00
|
|
|
if (neighbor)
|
|
|
|
put_spu_context(neighbor);
|
|
|
|
}
|
2006-10-04 17:26:15 +02:00
|
|
|
|
2012-06-26 21:58:53 +04:00
|
|
|
ret = spufs_context_open(&path);
|
2012-07-19 16:07:30 +04:00
|
|
|
if (ret < 0)
|
2024-05-09 16:36:24 -04:00
|
|
|
spufs_rmdir(inode, dentry);
|
2006-10-04 17:26:15 +02:00
|
|
|
|
2007-07-20 21:39:47 +02:00
|
|
|
out_aff_unlock:
|
|
|
|
if (affinity)
|
|
|
|
mutex_unlock(&gang->aff_mutex);
|
spufs: fix gang directory lifetimes
prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have
a problem with gang lifetimes - creation of a gang returns opened
gang directory, which normally gets removed when that gets closed,
but if somebody has created a context belonging to that gang and
kept it alive until the gang got closed, removal failed and we
ended up with a leak.
Unfortunately, it had been fixed the wrong way. Dentry of gang
directory was no longer pinned, and rmdir on close was gone.
One problem was that failure of open kept calling simple_rmdir()
as cleanup, which meant an unbalanced dput(). Another bug was
in the success case - gang creation incremented link count on
root directory, but that was no longer undone when gang got
destroyed.
Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped
in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.
Fixes: 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2025-03-12 19:18:39 -04:00
|
|
|
if (ret && gang)
|
|
|
|
gang->alive--; // can't reach 0
|
2006-10-04 17:26:15 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-07-26 04:47:14 -04:00
|
|
|
spufs_mkgang(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2006-10-04 17:26:15 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct inode *inode;
|
|
|
|
struct spu_gang *gang;
|
|
|
|
|
|
|
|
ret = -ENOSPC;
|
|
|
|
inode = spufs_new_inode(dir->i_sb, mode | S_IFDIR);
|
|
|
|
if (!inode)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = 0;
|
2023-01-13 12:49:25 +01:00
|
|
|
inode_init_owner(&nop_mnt_idmap, inode, dir, mode | S_IFDIR);
|
2006-10-04 17:26:15 +02:00
|
|
|
gang = alloc_spu_gang();
|
|
|
|
SPUFS_I(inode)->i_ctx = NULL;
|
|
|
|
SPUFS_I(inode)->i_gang = gang;
|
2016-08-04 08:37:03 +03:00
|
|
|
if (!gang) {
|
|
|
|
ret = -ENOMEM;
|
2006-10-04 17:26:15 +02:00
|
|
|
goto out_iput;
|
2016-08-04 08:37:03 +03:00
|
|
|
}
|
2006-10-04 17:26:15 +02:00
|
|
|
|
2007-06-29 10:57:59 +10:00
|
|
|
inode->i_op = &simple_dir_inode_operations;
|
2006-10-04 17:26:15 +02:00
|
|
|
inode->i_fop = &simple_dir_operations;
|
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
spufs: fix gang directory lifetimes
prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have
a problem with gang lifetimes - creation of a gang returns opened
gang directory, which normally gets removed when that gets closed,
but if somebody has created a context belonging to that gang and
kept it alive until the gang got closed, removal failed and we
ended up with a leak.
Unfortunately, it had been fixed the wrong way. Dentry of gang
directory was no longer pinned, and rmdir on close was gone.
One problem was that failure of open kept calling simple_rmdir()
as cleanup, which meant an unbalanced dput(). Another bug was
in the success case - gang creation incremented link count on
root directory, but that was no longer undone when gang got
destroyed.
Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped
in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.
Fixes: 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2025-03-12 19:18:39 -04:00
|
|
|
dget(dentry);
|
2008-10-09 10:39:21 +11:00
|
|
|
inc_nlink(dir);
|
2015-03-17 22:26:12 +00:00
|
|
|
inc_nlink(d_inode(dentry));
|
2006-10-04 17:26:15 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
out_iput:
|
|
|
|
iput(inode);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
spufs: fix gang directory lifetimes
prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have
a problem with gang lifetimes - creation of a gang returns opened
gang directory, which normally gets removed when that gets closed,
but if somebody has created a context belonging to that gang and
kept it alive until the gang got closed, removal failed and we
ended up with a leak.
Unfortunately, it had been fixed the wrong way. Dentry of gang
directory was no longer pinned, and rmdir on close was gone.
One problem was that failure of open kept calling simple_rmdir()
as cleanup, which meant an unbalanced dput(). Another bug was
in the success case - gang creation incremented link count on
root directory, but that was no longer undone when gang got
destroyed.
Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped
in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.
Fixes: 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2025-03-12 19:18:39 -04:00
|
|
|
static int spufs_gang_close(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
unuse_gang(file->f_path.dentry);
|
|
|
|
return dcache_dir_close(inode, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations spufs_gang_fops = {
|
|
|
|
.open = dcache_dir_open,
|
|
|
|
.release = spufs_gang_close,
|
|
|
|
.llseek = dcache_dir_lseek,
|
|
|
|
.read = generic_read_dir,
|
|
|
|
.iterate_shared = dcache_readdir,
|
|
|
|
.fsync = noop_fsync,
|
|
|
|
};
|
|
|
|
|
2022-08-04 13:21:17 -04:00
|
|
|
static int spufs_gang_open(const struct path *path)
|
2006-10-04 17:26:15 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct file *filp;
|
|
|
|
|
2014-12-10 15:45:39 -08:00
|
|
|
ret = get_unused_fd_flags(0);
|
2012-06-25 11:46:13 +04:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2006-10-04 17:26:15 +02:00
|
|
|
|
2012-06-25 11:46:13 +04:00
|
|
|
/*
|
|
|
|
* get references for dget and mntget, will be released
|
|
|
|
* in error path of *_open().
|
|
|
|
*/
|
2012-06-26 21:58:53 +04:00
|
|
|
filp = dentry_open(path, O_RDONLY, current_cred());
|
2006-10-04 17:26:15 +02:00
|
|
|
if (IS_ERR(filp)) {
|
|
|
|
put_unused_fd(ret);
|
2012-06-25 11:46:13 +04:00
|
|
|
return PTR_ERR(filp);
|
2006-10-04 17:26:15 +02:00
|
|
|
}
|
|
|
|
|
spufs: fix gang directory lifetimes
prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have
a problem with gang lifetimes - creation of a gang returns opened
gang directory, which normally gets removed when that gets closed,
but if somebody has created a context belonging to that gang and
kept it alive until the gang got closed, removal failed and we
ended up with a leak.
Unfortunately, it had been fixed the wrong way. Dentry of gang
directory was no longer pinned, and rmdir on close was gone.
One problem was that failure of open kept calling simple_rmdir()
as cleanup, which meant an unbalanced dput(). Another bug was
in the success case - gang creation incremented link count on
root directory, but that was no longer undone when gang got
destroyed.
Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped
in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.
Fixes: 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2025-03-12 19:18:39 -04:00
|
|
|
filp->f_op = &spufs_gang_fops;
|
2006-10-04 17:26:15 +02:00
|
|
|
fd_install(ret, filp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spufs_create_gang(struct inode *inode,
|
|
|
|
struct dentry *dentry,
|
2011-07-26 04:47:14 -04:00
|
|
|
struct vfsmount *mnt, umode_t mode)
|
2006-10-04 17:26:15 +02:00
|
|
|
{
|
2012-06-26 21:58:53 +04:00
|
|
|
struct path path = {.mnt = mnt, .dentry = dentry};
|
2006-10-04 17:26:15 +02:00
|
|
|
int ret;
|
|
|
|
|
2017-01-12 14:54:13 +11:00
|
|
|
ret = spufs_mkgang(inode, dentry, mode & 0777);
|
2012-07-19 16:12:22 +04:00
|
|
|
if (!ret) {
|
|
|
|
ret = spufs_gang_open(&path);
|
spufs: fix gang directory lifetimes
prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have
a problem with gang lifetimes - creation of a gang returns opened
gang directory, which normally gets removed when that gets closed,
but if somebody has created a context belonging to that gang and
kept it alive until the gang got closed, removal failed and we
ended up with a leak.
Unfortunately, it had been fixed the wrong way. Dentry of gang
directory was no longer pinned, and rmdir on close was gone.
One problem was that failure of open kept calling simple_rmdir()
as cleanup, which meant an unbalanced dput(). Another bug was
in the success case - gang creation incremented link count on
root directory, but that was no longer undone when gang got
destroyed.
Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped
in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.
Fixes: 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2025-03-12 19:18:39 -04:00
|
|
|
if (ret < 0)
|
|
|
|
unuse_gang(dentry);
|
2007-06-04 23:26:51 +10:00
|
|
|
}
|
2006-10-04 17:26:15 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-04 20:31:26 +01:00
|
|
|
static struct file_system_type spufs_type;
|
|
|
|
|
2022-08-04 13:21:17 -04:00
|
|
|
long spufs_create(const struct path *path, struct dentry *dentry,
|
2011-07-26 04:47:14 -04:00
|
|
|
unsigned int flags, umode_t mode, struct file *filp)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
2015-03-17 22:26:12 +00:00
|
|
|
struct inode *dir = d_inode(path->dentry);
|
2005-11-15 15:53:48 -05:00
|
|
|
int ret;
|
|
|
|
|
2006-10-04 17:26:15 +02:00
|
|
|
/* check if we are on spufs */
|
2011-06-26 11:54:58 -04:00
|
|
|
if (path->dentry->d_sb->s_type != &spufs_type)
|
2012-07-19 16:23:13 +04:00
|
|
|
return -EINVAL;
|
2005-11-15 15:53:48 -05:00
|
|
|
|
2006-10-04 17:26:15 +02:00
|
|
|
/* don't accept undefined flags */
|
2006-10-04 17:26:14 +02:00
|
|
|
if (flags & (~SPU_CREATE_FLAG_ALL))
|
2012-07-19 16:23:13 +04:00
|
|
|
return -EINVAL;
|
2006-06-19 20:33:34 +02:00
|
|
|
|
2006-10-04 17:26:15 +02:00
|
|
|
/* only threads can be underneath a gang */
|
2012-07-19 16:23:13 +04:00
|
|
|
if (path->dentry != path->dentry->d_sb->s_root)
|
|
|
|
if ((flags & SPU_CREATE_GANG) || !SPUFS_I(dir)->i_gang)
|
|
|
|
return -EINVAL;
|
2006-10-04 17:26:15 +02:00
|
|
|
|
2009-03-29 19:08:22 -04:00
|
|
|
mode &= ~current_umask();
|
2005-11-15 15:53:48 -05:00
|
|
|
|
2006-10-04 17:26:15 +02:00
|
|
|
if (flags & SPU_CREATE_GANG)
|
2012-07-19 16:23:13 +04:00
|
|
|
ret = spufs_create_gang(dir, dentry, path->mnt, mode);
|
2006-10-04 17:26:15 +02:00
|
|
|
else
|
2012-07-19 16:23:13 +04:00
|
|
|
ret = spufs_create_context(dir, dentry, path->mnt, flags, mode,
|
2008-02-14 19:34:32 -08:00
|
|
|
filp);
|
2008-05-06 09:24:24 +10:00
|
|
|
if (ret >= 0)
|
2012-07-19 16:23:13 +04:00
|
|
|
fsnotify_mkdir(dir, dentry);
|
2005-11-15 15:53:48 -05:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* File system initialization */
|
2019-03-21 10:34:14 +00:00
|
|
|
struct spufs_fs_context {
|
|
|
|
kuid_t uid;
|
|
|
|
kgid_t gid;
|
|
|
|
umode_t mode;
|
|
|
|
};
|
|
|
|
|
2005-11-15 15:53:48 -05:00
|
|
|
enum {
|
2019-03-21 10:34:14 +00:00
|
|
|
Opt_uid, Opt_gid, Opt_mode, Opt_debug,
|
|
|
|
};
|
|
|
|
|
2019-09-07 07:23:15 -04:00
|
|
|
static const struct fs_parameter_spec spufs_fs_parameters[] = {
|
2019-03-21 10:34:14 +00:00
|
|
|
fsparam_u32 ("gid", Opt_gid),
|
|
|
|
fsparam_u32oct ("mode", Opt_mode),
|
|
|
|
fsparam_u32 ("uid", Opt_uid),
|
|
|
|
fsparam_flag ("debug", Opt_debug),
|
|
|
|
{}
|
2005-11-15 15:53:48 -05:00
|
|
|
};
|
|
|
|
|
2017-07-05 16:24:56 +01:00
|
|
|
static int spufs_show_options(struct seq_file *m, struct dentry *root)
|
|
|
|
{
|
|
|
|
struct spufs_sb_info *sbi = spufs_get_sb_info(root->d_sb);
|
|
|
|
struct inode *inode = root->d_inode;
|
|
|
|
|
|
|
|
if (!uid_eq(inode->i_uid, GLOBAL_ROOT_UID))
|
|
|
|
seq_printf(m, ",uid=%u",
|
|
|
|
from_kuid_munged(&init_user_ns, inode->i_uid));
|
|
|
|
if (!gid_eq(inode->i_gid, GLOBAL_ROOT_GID))
|
|
|
|
seq_printf(m, ",gid=%u",
|
|
|
|
from_kgid_munged(&init_user_ns, inode->i_gid));
|
|
|
|
if ((inode->i_mode & S_IALLUGO) != 0775)
|
|
|
|
seq_printf(m, ",mode=%o", inode->i_mode);
|
|
|
|
if (sbi->debug)
|
|
|
|
seq_puts(m, ",debug");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-21 10:34:14 +00:00
|
|
|
static int spufs_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
2019-03-21 10:34:14 +00:00
|
|
|
struct spufs_fs_context *ctx = fc->fs_private;
|
|
|
|
struct spufs_sb_info *sbi = fc->s_fs_info;
|
|
|
|
struct fs_parse_result result;
|
|
|
|
kuid_t uid;
|
|
|
|
kgid_t gid;
|
|
|
|
int opt;
|
|
|
|
|
2019-09-07 07:23:15 -04:00
|
|
|
opt = fs_parse(fc, spufs_fs_parameters, param, &result);
|
2019-03-21 10:34:14 +00:00
|
|
|
if (opt < 0)
|
|
|
|
return opt;
|
|
|
|
|
|
|
|
switch (opt) {
|
|
|
|
case Opt_uid:
|
|
|
|
uid = make_kuid(current_user_ns(), result.uint_32);
|
|
|
|
if (!uid_valid(uid))
|
|
|
|
return invalf(fc, "Unknown uid");
|
|
|
|
ctx->uid = uid;
|
|
|
|
break;
|
|
|
|
case Opt_gid:
|
|
|
|
gid = make_kgid(current_user_ns(), result.uint_32);
|
|
|
|
if (!gid_valid(gid))
|
|
|
|
return invalf(fc, "Unknown gid");
|
|
|
|
ctx->gid = gid;
|
|
|
|
break;
|
|
|
|
case Opt_mode:
|
|
|
|
ctx->mode = result.uint_32 & S_IALLUGO;
|
|
|
|
break;
|
|
|
|
case Opt_debug:
|
|
|
|
sbi->debug = true;
|
|
|
|
break;
|
2005-11-15 15:53:48 -05:00
|
|
|
}
|
2019-03-21 10:34:14 +00:00
|
|
|
|
|
|
|
return 0;
|
2005-11-15 15:53:48 -05:00
|
|
|
}
|
|
|
|
|
2007-04-23 21:08:20 +02:00
|
|
|
static void spufs_exit_isolated_loader(void)
|
|
|
|
{
|
2007-09-19 14:38:12 +10:00
|
|
|
free_pages((unsigned long) isolated_loader,
|
|
|
|
get_order(isolated_loader_size));
|
2007-04-23 21:08:20 +02:00
|
|
|
}
|
|
|
|
|
2021-12-16 17:00:22 -05:00
|
|
|
static void __init
|
2006-10-24 18:31:18 +02:00
|
|
|
spufs_init_isolated_loader(void)
|
|
|
|
{
|
|
|
|
struct device_node *dn;
|
|
|
|
const char *loader;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
dn = of_find_node_by_path("/spu-isolation");
|
|
|
|
if (!dn)
|
|
|
|
return;
|
|
|
|
|
2007-04-03 22:26:41 +10:00
|
|
|
loader = of_get_property(dn, "loader", &size);
|
2022-06-03 16:15:42 +04:00
|
|
|
of_node_put(dn);
|
2006-10-24 18:31:18 +02:00
|
|
|
if (!loader)
|
|
|
|
return;
|
|
|
|
|
2007-09-19 14:38:12 +10:00
|
|
|
/* the loader must be align on a 16 byte boundary */
|
|
|
|
isolated_loader = (char *)__get_free_pages(GFP_KERNEL, get_order(size));
|
2006-10-24 18:31:18 +02:00
|
|
|
if (!isolated_loader)
|
|
|
|
return;
|
|
|
|
|
2007-09-19 14:38:12 +10:00
|
|
|
isolated_loader_size = size;
|
2006-10-24 18:31:18 +02:00
|
|
|
memcpy(isolated_loader, loader, size);
|
|
|
|
printk(KERN_INFO "spufs: SPU isolation mode enabled\n");
|
|
|
|
}
|
|
|
|
|
2019-03-21 10:34:14 +00:00
|
|
|
static int spufs_create_root(struct super_block *sb, struct fs_context *fc)
|
2005-11-15 15:53:52 -05:00
|
|
|
{
|
2019-03-21 10:34:14 +00:00
|
|
|
struct spufs_fs_context *ctx = fc->fs_private;
|
2005-11-15 15:53:48 -05:00
|
|
|
struct inode *inode;
|
|
|
|
|
2007-06-04 23:26:51 +10:00
|
|
|
if (!spu_management_ops)
|
2019-03-21 10:34:14 +00:00
|
|
|
return -ENODEV;
|
2007-06-04 23:26:51 +10:00
|
|
|
|
2019-03-21 10:34:14 +00:00
|
|
|
inode = spufs_new_inode(sb, S_IFDIR | ctx->mode);
|
2005-11-15 15:53:48 -05:00
|
|
|
if (!inode)
|
2019-03-21 10:34:14 +00:00
|
|
|
return -ENOMEM;
|
2005-11-15 15:53:48 -05:00
|
|
|
|
2019-03-21 10:34:14 +00:00
|
|
|
inode->i_uid = ctx->uid;
|
|
|
|
inode->i_gid = ctx->gid;
|
2007-06-29 10:57:59 +10:00
|
|
|
inode->i_op = &simple_dir_inode_operations;
|
2005-11-15 15:53:48 -05:00
|
|
|
inode->i_fop = &simple_dir_operations;
|
|
|
|
SPUFS_I(inode)->i_ctx = NULL;
|
2008-10-07 18:26:55 +11:00
|
|
|
inc_nlink(inode);
|
2005-11-15 15:53:48 -05:00
|
|
|
|
2012-01-08 22:15:13 -05:00
|
|
|
sb->s_root = d_make_root(inode);
|
2005-11-15 15:53:48 -05:00
|
|
|
if (!sb->s_root)
|
2019-03-21 10:34:14 +00:00
|
|
|
return -ENOMEM;
|
2005-11-15 15:53:48 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-21 10:34:14 +00:00
|
|
|
static const struct super_operations spufs_ops = {
|
|
|
|
.alloc_inode = spufs_alloc_inode,
|
|
|
|
.free_inode = spufs_free_inode,
|
|
|
|
.statfs = simple_statfs,
|
|
|
|
.evict_inode = spufs_evict_inode,
|
|
|
|
.show_options = spufs_show_options,
|
|
|
|
};
|
2008-07-03 11:42:20 +10:00
|
|
|
|
2019-03-21 10:34:14 +00:00
|
|
|
static int spufs_fill_super(struct super_block *sb, struct fs_context *fc)
|
|
|
|
{
|
2005-11-15 15:53:48 -05:00
|
|
|
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
sb->s_blocksize = PAGE_SIZE;
|
|
|
|
sb->s_blocksize_bits = PAGE_SHIFT;
|
2005-11-15 15:53:48 -05:00
|
|
|
sb->s_magic = SPUFS_MAGIC;
|
2019-03-21 10:34:14 +00:00
|
|
|
sb->s_op = &spufs_ops;
|
|
|
|
|
|
|
|
return spufs_create_root(sb, fc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spufs_get_tree(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
return get_tree_single(fc, spufs_fill_super);
|
|
|
|
}
|
2005-11-15 15:53:48 -05:00
|
|
|
|
2019-03-21 10:34:14 +00:00
|
|
|
static void spufs_free_fc(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
kfree(fc->s_fs_info);
|
2005-11-15 15:53:48 -05:00
|
|
|
}
|
|
|
|
|
2019-03-21 10:34:14 +00:00
|
|
|
static const struct fs_context_operations spufs_context_ops = {
|
|
|
|
.free = spufs_free_fc,
|
|
|
|
.parse_param = spufs_parse_param,
|
|
|
|
.get_tree = spufs_get_tree,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int spufs_init_fs_context(struct fs_context *fc)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
2019-03-21 10:34:14 +00:00
|
|
|
struct spufs_fs_context *ctx;
|
|
|
|
struct spufs_sb_info *sbi;
|
|
|
|
|
|
|
|
ctx = kzalloc(sizeof(struct spufs_fs_context), GFP_KERNEL);
|
|
|
|
if (!ctx)
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
sbi = kzalloc(sizeof(struct spufs_sb_info), GFP_KERNEL);
|
|
|
|
if (!sbi)
|
|
|
|
goto nomem_ctx;
|
|
|
|
|
|
|
|
ctx->uid = current_uid();
|
|
|
|
ctx->gid = current_gid();
|
|
|
|
ctx->mode = 0755;
|
|
|
|
|
2019-10-08 16:13:42 +02:00
|
|
|
fc->fs_private = ctx;
|
2019-03-21 10:34:14 +00:00
|
|
|
fc->s_fs_info = sbi;
|
|
|
|
fc->ops = &spufs_context_ops;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nomem_ctx:
|
|
|
|
kfree(ctx);
|
|
|
|
nomem:
|
|
|
|
return -ENOMEM;
|
2005-11-15 15:53:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type spufs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "spufs",
|
2019-03-21 10:34:14 +00:00
|
|
|
.init_fs_context = spufs_init_fs_context,
|
2019-09-07 07:23:15 -04:00
|
|
|
.parameters = spufs_fs_parameters,
|
2005-11-15 15:53:48 -05:00
|
|
|
.kill_sb = kill_litter_super,
|
|
|
|
};
|
2013-03-02 19:39:14 -08:00
|
|
|
MODULE_ALIAS_FS("spufs");
|
2005-11-15 15:53:48 -05:00
|
|
|
|
2006-03-27 21:27:40 +02:00
|
|
|
static int __init spufs_init(void)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
|
|
|
int ret;
|
[POWERPC] coredump: Add SPU elf notes to coredump.
This patch adds SPU elf notes to the coredump. It creates a separate note
for each of /regs, /fpcr, /lslr, /decr, /decr_status, /mem, /signal1,
/signal1_type, /signal2, /signal2_type, /event_mask, /event_status,
/mbox_info, /ibox_info, /wbox_info, /dma_info, /proxydma_info, /object-id.
A new macro, ARCH_HAVE_EXTRA_NOTES, was created for architectures to
specify they have extra elf core notes.
A new macro, ELF_CORE_EXTRA_NOTES_SIZE, was created so the size of the
additional notes could be calculated and added to the notes phdr entry.
A new macro, ELF_CORE_WRITE_EXTRA_NOTES, was created so the new notes
would be written after the existing notes.
The SPU coredump code resides in spufs. Stub functions are provided in the
kernel which are hooked into the spufs code which does the actual work via
register_arch_coredump_calls().
A new set of __spufs_<file>_read/get() functions was provided to allow the
coredump code to read from the spufs files without having to lock the
SPU context for each file read from.
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Dwayne Grant McConnell <decimal@us.ibm.com>
Signed-off-by: Arnd Bergmann <arnd.bergmann@de.ibm.com>
2006-11-23 00:46:37 +01:00
|
|
|
|
2007-04-23 21:08:29 +02:00
|
|
|
ret = -ENODEV;
|
|
|
|
if (!spu_management_ops)
|
|
|
|
goto out;
|
|
|
|
|
2005-11-15 15:53:48 -05:00
|
|
|
ret = -ENOMEM;
|
|
|
|
spufs_inode_cache = kmem_cache_create("spufs_inode_cache",
|
|
|
|
sizeof(struct spufs_inode_info), 0,
|
2016-01-14 15:18:21 -08:00
|
|
|
SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT, spufs_init_once);
|
2005-11-15 15:53:48 -05:00
|
|
|
|
|
|
|
if (!spufs_inode_cache)
|
|
|
|
goto out;
|
2007-04-23 21:08:19 +02:00
|
|
|
ret = spu_sched_init();
|
2005-11-15 15:53:48 -05:00
|
|
|
if (ret)
|
|
|
|
goto out_cache;
|
2012-03-17 01:37:51 -04:00
|
|
|
ret = register_spu_syscalls(&spufs_calls);
|
2007-04-23 21:08:19 +02:00
|
|
|
if (ret)
|
|
|
|
goto out_sched;
|
2012-03-17 01:37:51 -04:00
|
|
|
ret = register_filesystem(&spufs_type);
|
[POWERPC] coredump: Add SPU elf notes to coredump.
This patch adds SPU elf notes to the coredump. It creates a separate note
for each of /regs, /fpcr, /lslr, /decr, /decr_status, /mem, /signal1,
/signal1_type, /signal2, /signal2_type, /event_mask, /event_status,
/mbox_info, /ibox_info, /wbox_info, /dma_info, /proxydma_info, /object-id.
A new macro, ARCH_HAVE_EXTRA_NOTES, was created for architectures to
specify they have extra elf core notes.
A new macro, ELF_CORE_EXTRA_NOTES_SIZE, was created so the size of the
additional notes could be calculated and added to the notes phdr entry.
A new macro, ELF_CORE_WRITE_EXTRA_NOTES, was created so the new notes
would be written after the existing notes.
The SPU coredump code resides in spufs. Stub functions are provided in the
kernel which are hooked into the spufs code which does the actual work via
register_arch_coredump_calls().
A new set of __spufs_<file>_read/get() functions was provided to allow the
coredump code to read from the spufs files without having to lock the
SPU context for each file read from.
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Dwayne Grant McConnell <decimal@us.ibm.com>
Signed-off-by: Arnd Bergmann <arnd.bergmann@de.ibm.com>
2006-11-23 00:46:37 +01:00
|
|
|
if (ret)
|
2012-03-17 01:37:51 -04:00
|
|
|
goto out_syscalls;
|
2006-10-24 18:31:18 +02:00
|
|
|
|
|
|
|
spufs_init_isolated_loader();
|
[POWERPC] coredump: Add SPU elf notes to coredump.
This patch adds SPU elf notes to the coredump. It creates a separate note
for each of /regs, /fpcr, /lslr, /decr, /decr_status, /mem, /signal1,
/signal1_type, /signal2, /signal2_type, /event_mask, /event_status,
/mbox_info, /ibox_info, /wbox_info, /dma_info, /proxydma_info, /object-id.
A new macro, ARCH_HAVE_EXTRA_NOTES, was created for architectures to
specify they have extra elf core notes.
A new macro, ELF_CORE_EXTRA_NOTES_SIZE, was created so the size of the
additional notes could be calculated and added to the notes phdr entry.
A new macro, ELF_CORE_WRITE_EXTRA_NOTES, was created so the new notes
would be written after the existing notes.
The SPU coredump code resides in spufs. Stub functions are provided in the
kernel which are hooked into the spufs code which does the actual work via
register_arch_coredump_calls().
A new set of __spufs_<file>_read/get() functions was provided to allow the
coredump code to read from the spufs files without having to lock the
SPU context for each file read from.
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Dwayne Grant McConnell <decimal@us.ibm.com>
Signed-off-by: Arnd Bergmann <arnd.bergmann@de.ibm.com>
2006-11-23 00:46:37 +01:00
|
|
|
|
2005-11-15 15:53:48 -05:00
|
|
|
return 0;
|
2007-04-23 21:08:19 +02:00
|
|
|
|
2012-03-17 01:37:51 -04:00
|
|
|
out_syscalls:
|
|
|
|
unregister_spu_syscalls(&spufs_calls);
|
2007-04-23 21:08:19 +02:00
|
|
|
out_sched:
|
|
|
|
spu_sched_exit();
|
2005-11-15 15:53:48 -05:00
|
|
|
out_cache:
|
|
|
|
kmem_cache_destroy(spufs_inode_cache);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
module_init(spufs_init);
|
|
|
|
|
2006-03-27 21:27:40 +02:00
|
|
|
static void __exit spufs_exit(void)
|
2005-11-15 15:53:48 -05:00
|
|
|
{
|
2005-11-15 15:53:52 -05:00
|
|
|
spu_sched_exit();
|
2007-04-23 21:08:20 +02:00
|
|
|
spufs_exit_isolated_loader();
|
2005-11-15 15:53:48 -05:00
|
|
|
unregister_spu_syscalls(&spufs_calls);
|
|
|
|
unregister_filesystem(&spufs_type);
|
|
|
|
kmem_cache_destroy(spufs_inode_cache);
|
|
|
|
}
|
|
|
|
module_exit(spufs_exit);
|
|
|
|
|
2024-06-15 10:06:18 -07:00
|
|
|
MODULE_DESCRIPTION("SPU file system");
|
2005-11-15 15:53:48 -05:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
|
|
|
|
|