Commit 47d3a5fa authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Paul Mackerras

[POWERPC] spufs: Synchronize pte invalidation vs ps close

Make sure the mapping_lock also protects access to the various address_space
pointers used for tearing down the ptes on a spu context switch.

Because unmap_mapping_range can sleep we need to turn mapping_lock from
a spinlock into a sleeping mutex.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarArnd Bergmann <arnd.bergmann@de.ibm.com>
Signed-off-by: default avatarJeremy Kerr <jk@ozlabs.org>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent 89df0085
...@@ -39,7 +39,7 @@ struct spu_context *alloc_spu_context(struct spu_gang *gang) ...@@ -39,7 +39,7 @@ struct spu_context *alloc_spu_context(struct spu_gang *gang)
if (spu_init_csa(&ctx->csa)) if (spu_init_csa(&ctx->csa))
goto out_free; goto out_free;
spin_lock_init(&ctx->mmio_lock); spin_lock_init(&ctx->mmio_lock);
spin_lock_init(&ctx->mapping_lock); mutex_init(&ctx->mapping_lock);
kref_init(&ctx->kref); kref_init(&ctx->kref);
mutex_init(&ctx->state_mutex); mutex_init(&ctx->state_mutex);
mutex_init(&ctx->run_mutex); mutex_init(&ctx->run_mutex);
...@@ -103,6 +103,7 @@ void spu_forget(struct spu_context *ctx) ...@@ -103,6 +103,7 @@ void spu_forget(struct spu_context *ctx)
void spu_unmap_mappings(struct spu_context *ctx) void spu_unmap_mappings(struct spu_context *ctx)
{ {
mutex_lock(&ctx->mapping_lock);
if (ctx->local_store) if (ctx->local_store)
unmap_mapping_range(ctx->local_store, 0, LS_SIZE, 1); unmap_mapping_range(ctx->local_store, 0, LS_SIZE, 1);
if (ctx->mfc) if (ctx->mfc)
...@@ -117,6 +118,7 @@ void spu_unmap_mappings(struct spu_context *ctx) ...@@ -117,6 +118,7 @@ void spu_unmap_mappings(struct spu_context *ctx)
unmap_mapping_range(ctx->mss, 0, 0x1000, 1); unmap_mapping_range(ctx->mss, 0, 0x1000, 1);
if (ctx->psmap) if (ctx->psmap)
unmap_mapping_range(ctx->psmap, 0, 0x20000, 1); unmap_mapping_range(ctx->psmap, 0, 0x20000, 1);
mutex_unlock(&ctx->mapping_lock);
} }
/** /**
......
...@@ -45,11 +45,11 @@ spufs_mem_open(struct inode *inode, struct file *file) ...@@ -45,11 +45,11 @@ spufs_mem_open(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
file->private_data = ctx; file->private_data = ctx;
if (!i->i_openers++) if (!i->i_openers++)
ctx->local_store = inode->i_mapping; ctx->local_store = inode->i_mapping;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return 0; return 0;
} }
...@@ -59,10 +59,10 @@ spufs_mem_release(struct inode *inode, struct file *file) ...@@ -59,10 +59,10 @@ spufs_mem_release(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
if (!--i->i_openers) if (!--i->i_openers)
ctx->local_store = NULL; ctx->local_store = NULL;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return 0; return 0;
} }
...@@ -310,11 +310,11 @@ static int spufs_cntl_open(struct inode *inode, struct file *file) ...@@ -310,11 +310,11 @@ static int spufs_cntl_open(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
file->private_data = ctx; file->private_data = ctx;
if (!i->i_openers++) if (!i->i_openers++)
ctx->cntl = inode->i_mapping; ctx->cntl = inode->i_mapping;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return simple_attr_open(inode, file, spufs_cntl_get, return simple_attr_open(inode, file, spufs_cntl_get,
spufs_cntl_set, "0x%08lx"); spufs_cntl_set, "0x%08lx");
} }
...@@ -327,10 +327,10 @@ spufs_cntl_release(struct inode *inode, struct file *file) ...@@ -327,10 +327,10 @@ spufs_cntl_release(struct inode *inode, struct file *file)
simple_attr_close(inode, file); simple_attr_close(inode, file);
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
if (!--i->i_openers) if (!--i->i_openers)
ctx->cntl = NULL; ctx->cntl = NULL;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return 0; return 0;
} }
...@@ -813,11 +813,11 @@ static int spufs_signal1_open(struct inode *inode, struct file *file) ...@@ -813,11 +813,11 @@ static int spufs_signal1_open(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
file->private_data = ctx; file->private_data = ctx;
if (!i->i_openers++) if (!i->i_openers++)
ctx->signal1 = inode->i_mapping; ctx->signal1 = inode->i_mapping;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
} }
...@@ -827,10 +827,10 @@ spufs_signal1_release(struct inode *inode, struct file *file) ...@@ -827,10 +827,10 @@ spufs_signal1_release(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
if (!--i->i_openers) if (!--i->i_openers)
ctx->signal1 = NULL; ctx->signal1 = NULL;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return 0; return 0;
} }
...@@ -937,11 +937,11 @@ static int spufs_signal2_open(struct inode *inode, struct file *file) ...@@ -937,11 +937,11 @@ static int spufs_signal2_open(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
file->private_data = ctx; file->private_data = ctx;
if (!i->i_openers++) if (!i->i_openers++)
ctx->signal2 = inode->i_mapping; ctx->signal2 = inode->i_mapping;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
} }
...@@ -951,10 +951,10 @@ spufs_signal2_release(struct inode *inode, struct file *file) ...@@ -951,10 +951,10 @@ spufs_signal2_release(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
if (!--i->i_openers) if (!--i->i_openers)
ctx->signal2 = NULL; ctx->signal2 = NULL;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return 0; return 0;
} }
...@@ -1155,10 +1155,10 @@ static int spufs_mss_open(struct inode *inode, struct file *file) ...@@ -1155,10 +1155,10 @@ static int spufs_mss_open(struct inode *inode, struct file *file)
file->private_data = i->i_ctx; file->private_data = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
if (!i->i_openers++) if (!i->i_openers++)
ctx->mss = inode->i_mapping; ctx->mss = inode->i_mapping;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
} }
...@@ -1168,10 +1168,10 @@ spufs_mss_release(struct inode *inode, struct file *file) ...@@ -1168,10 +1168,10 @@ spufs_mss_release(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
if (!--i->i_openers) if (!--i->i_openers)
ctx->mss = NULL; ctx->mss = NULL;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return 0; return 0;
} }
...@@ -1212,11 +1212,11 @@ static int spufs_psmap_open(struct inode *inode, struct file *file) ...@@ -1212,11 +1212,11 @@ static int spufs_psmap_open(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
file->private_data = i->i_ctx; file->private_data = i->i_ctx;
if (!i->i_openers++) if (!i->i_openers++)
ctx->psmap = inode->i_mapping; ctx->psmap = inode->i_mapping;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
} }
...@@ -1226,10 +1226,10 @@ spufs_psmap_release(struct inode *inode, struct file *file) ...@@ -1226,10 +1226,10 @@ spufs_psmap_release(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
if (!--i->i_openers) if (!--i->i_openers)
ctx->psmap = NULL; ctx->psmap = NULL;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return 0; return 0;
} }
...@@ -1282,11 +1282,11 @@ static int spufs_mfc_open(struct inode *inode, struct file *file) ...@@ -1282,11 +1282,11 @@ static int spufs_mfc_open(struct inode *inode, struct file *file)
if (atomic_read(&inode->i_count) != 1) if (atomic_read(&inode->i_count) != 1)
return -EBUSY; return -EBUSY;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
file->private_data = ctx; file->private_data = ctx;
if (!i->i_openers++) if (!i->i_openers++)
ctx->mfc = inode->i_mapping; ctx->mfc = inode->i_mapping;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
} }
...@@ -1296,10 +1296,10 @@ spufs_mfc_release(struct inode *inode, struct file *file) ...@@ -1296,10 +1296,10 @@ spufs_mfc_release(struct inode *inode, struct file *file)
struct spufs_inode_info *i = SPUFS_I(inode); struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx; struct spu_context *ctx = i->i_ctx;
spin_lock(&ctx->mapping_lock); mutex_lock(&ctx->mapping_lock);
if (!--i->i_openers) if (!--i->i_openers)
ctx->mfc = NULL; ctx->mfc = NULL;
spin_unlock(&ctx->mapping_lock); mutex_unlock(&ctx->mapping_lock);
return 0; return 0;
} }
......
...@@ -55,7 +55,7 @@ struct spu_context { ...@@ -55,7 +55,7 @@ struct spu_context {
struct address_space *signal2; /* 'signal2' area mappings. */ struct address_space *signal2; /* 'signal2' area mappings. */
struct address_space *mss; /* 'mss' area mappings. */ struct address_space *mss; /* 'mss' area mappings. */
struct address_space *psmap; /* 'psmap' area mappings. */ struct address_space *psmap; /* 'psmap' area mappings. */
spinlock_t mapping_lock; struct mutex mapping_lock;
u64 object_id; /* user space pointer for oprofile */ u64 object_id; /* user space pointer for oprofile */
enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state; enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment