spufs: mmap fixes and updates
Subsystems (3)
cover spufs: mmap fixes and updates
This is a new version of the spufs patch removing dependency on struct page along with a bugfix for some serious bitrot that happened in spufs mmap facility lately.
I'm not reposting the 2 VM patches that this depends on as they haven't changed and are queued up with Andrew
Ben.
PATCH 1/2 spufs: remove need for struct page for SPEs
This patch removes the need for struct page for SPE local store and registers from spufs. It also makes the locking much more obvious and no longer relying on the truncate logic black magic for protecting against races between unmap_mapping_range() and new pages faulted in. It does so by switching to a nopfn() handler and using the new vm_insert_pfn() to setup the PTEs itself while holding a lock on the SPE.
The nice thing is that this patch actually removes a lot more code than it adds :-)
---
Kconfig | 2
arch/powerpc/platforms/cell/spu_priv1_mmio.c +4 -61
@@ -57,37 +57,6 @@ struct device_node *spu_devnode(struct sEXPORT_SYMBOL_GPL (spu_devnode); -static int __init cell_spuprop_present (struct spu *spu,struct device_node *spe, -const char *prop) -{ -const struct address_prop { -unsigned long address; -unsigned int len; - } __attribute__((packed)) *p; -int proplen; - -unsigned long start_pfn, nr_pages; -struct pglist_data *pgdata; -struct zone *zone; -int ret; - - p =get_property (spe, prop, &proplen); -WARN_ON (proplen !=sizeof (*p)); - - start_pfn = p->address >>PAGE_SHIFT ; - nr_pages = ((unsigned long )p->len +PAGE_SIZE -1 ) >>PAGE_SHIFT ; - - pgdata =NODE_DATA (spu->node); - zone = pgdata->node_zones; - -/* XXX rethink locking here */ -mutex_lock (&add_spumem_mutex); - ret =__add_pages (zone, start_pfn, nr_pages); -mutex_unlock (&add_spumem_mutex); - -return ret; -} -static void __iomem *__init map_spe_prop (struct spu *spu,struct device_node *n,const char *name) {
@@ -98,23 +67,13 @@ static void __iomem * __init map_spe_proconst void *p;int proplen; -void __iomem *ret =NULL ; -int err =0 ; p =get_property (n, name, &proplen);if (proplen !=sizeof (struct address_prop ))return NULL ; prop = p; - - err =cell_spuprop_present (spu, n, name); -if (err && (err != -EEXIST )) - goto out; - - ret =ioremap (prop->address, prop->len); - - out: -return ret; +return ioremap (prop->address, prop->len); }static void spu_unmap (struct spu *spu)
@@ -239,37 +198,21 @@ static int spu_map_resource(struct spu * void __iomem** virt, unsigned long *phys) { struct device_node *np = spu_get_pdata(spu)->devnode; -unsigned long start_pfn, nr_pages; -struct pglist_data *pgdata; -struct zone *zone;struct resource resource = { };unsigned long len;int ret; ret =of_address_to_resource (np, nr, &resource);if (ret) - goto out; +return ret;if (phys) *phys = resource.start; len = resource.end - resource.start +1 ; *virt =ioremap (resource.start, len);if (!*virt) - ret = -EINVAL ; - - start_pfn = resource.start >>PAGE_SHIFT ; - nr_pages = (len +PAGE_SIZE -1 ) >>PAGE_SHIFT ; - - pgdata =NODE_DATA (spu->node); - zone = pgdata->node_zones; - -/* XXX rethink locking here */ -mutex_lock (&add_spumem_mutex); - ret =__add_pages (zone, start_pfn, nr_pages); -mutex_unlock (&add_spumem_mutex); - -out: -return ret; +return -EINVAL ; +return 0 ; }static int __init spu_map_device (struct spu *spu)
arch/powerpc/platforms/cell/spufs/file.c +55 -66
279 lines not on this page · raw message
arch/powerpc/Kconfig +1 -1
@@ -832,7 +832,7 @@ config ARCH_SPARSEMEM_ENABLE config ARCH_SPARSEMEM_DEFAULT def_bool y - depends on (SMP && PPC_PSERIES) || PPC_CELL + depends on (SMP && PPC_PSERIES) || PPC_PS3 config ARCH_POPULATES_NODE_MAP def_bool y
PATCH 2/2 spufs: Fix bitrot of the SPU mmap facility
In reply to Benjamin HerrenschmidtIt looks like we've had some serious bitrot there mostly due to tracking of address_space's of mmap'ed files getting out of sync with the actual mmap code. The mfc, mss and psmap were not tracked properly and thus not invalidated on context switches (oops !)
Note that I kept the various file->f_mapping = inode->i_mapping; assignments that were done in the other open() routines though it's unclear to me wether those are really necessary as I think the generic open code already does that but then, I'm not that familiar with filesystem foo. Another improvement we might want to do is assign those to the varioux ctx-> fields at mmap time instead of file open/close time.
I also added some smp_wmb's after assigning the ctx-> fields to make sure they are visible to other CPUs. I don't think this is really necessary as I suspect locking in the fs layer will make that happen anyway but better safe than sorry.
arch/powerpc/platforms/cell/spufs/context.c | 12 ++++++++---- arch/powerpc/platforms/cell/spufs/file.c | 15 +++++++++++++++ arch/powerpc/platforms/cell/spufs/spufs.h | 2 ++ 3 files changed, 25 insertions(+), 4 deletions(-)
arch/powerpc/platforms/cell/spufs/context.c +8 -4
@@ -111,13 +111,17 @@ void spu_unmap_mappings(struct spu_conteif (ctx->local_store)unmap_mapping_range (ctx->local_store,0 ,LS_SIZE ,1 );if (ctx->mfc) -unmap_mapping_range (ctx->mfc,0 ,0x4000 ,1 ); +unmap_mapping_range (ctx->mfc,0 ,0x1000 ,1 );if (ctx->cntl) -unmap_mapping_range (ctx->cntl,0 ,0x4000 ,1 ); +unmap_mapping_range (ctx->cntl,0 ,0x1000 ,1 );if (ctx->signal1) -unmap_mapping_range (ctx->signal1,0 ,0x4000 ,1 ); +unmap_mapping_range (ctx->signal1,0 ,PAGE_SIZE ,1 );if (ctx->signal2) -unmap_mapping_range (ctx->signal2,0 ,0x4000 ,1 ); +unmap_mapping_range (ctx->signal2,0 ,PAGE_SIZE ,1 ); +if (ctx->mss) +unmap_mapping_range (ctx->mss,0 ,0x1000 ,1 ); +if (ctx->psmap) +unmap_mapping_range (ctx->psmap,0 ,0x20000 ,1 ); }int spu_acquire_exclusive (struct spu_context *ctx)
arch/powerpc/platforms/cell/spufs/file.c +15 -0
@@ -47,6 +47,7 @@ spufs_mem_open(struct inode *inode, stru file->private_data = ctx; file->f_mapping = inode->i_mapping; ctx->local_store = inode->i_mapping; +smp_wmb ();return 0 ; }
@@ -234,6 +235,7 @@ static int spufs_cntl_open(struct inode file->private_data = ctx; file->f_mapping = inode->i_mapping; ctx->cntl = inode->i_mapping; +smp_wmb ();return simple_attr_open (inode, file, spufs_cntl_get, spufs_cntl_set,"0x%08lx" ); }
@@ -719,6 +721,7 @@ static int spufs_signal1_open(struct ino file->private_data = ctx; file->f_mapping = inode->i_mapping; ctx->signal1 = inode->i_mapping; +smp_wmb ();return nonseekable_open (inode, file); }
@@ -826,6 +829,7 @@ static int spufs_signal2_open(struct ino file->private_data = ctx; file->f_mapping = inode->i_mapping; ctx->signal2 = inode->i_mapping; +smp_wmb ();return nonseekable_open (inode, file); }
@@ -1021,8 +1025,12 @@ static int spufs_mss_mmap(struct file *fstatic int spufs_mss_open (struct inode *inode,struct file *file) {struct spufs_inode_info *i =SPUFS_I (inode); +struct spu_context *ctx = i->i_ctx; file->private_data = i->i_ctx; + file->f_mapping = inode->i_mapping; + ctx->mss = inode->i_mapping; +smp_wmb ();return nonseekable_open (inode, file); }
@@ -1060,8 +1068,12 @@ static int spufs_psmap_mmap(struct filestatic int spufs_psmap_open (struct inode *inode,struct file *file) {struct spufs_inode_info *i =SPUFS_I (inode); +struct spu_context *ctx = i->i_ctx; file->private_data = i->i_ctx; + file->f_mapping = inode->i_mapping; + ctx->psmap = inode->i_mapping; +smp_wmb ();return nonseekable_open (inode, file); }
@@ -1114,6 +1126,9 @@ static int spufs_mfc_open(struct inode *return -EBUSY ; file->private_data = ctx; + file->f_mapping = inode->i_mapping; + ctx->mfc = inode->i_mapping; +smp_wmb ();return nonseekable_open (inode, file); }
arch/powerpc/platforms/cell/spufs/spufs.h +2 -0
@@ -51,6 +51,8 @@ struct spu_context {struct address_space *cntl;/* 'control' area mappings. */ struct address_space *signal1;/* 'signal1' area mappings. */ struct address_space *signal2;/* 'signal2' area mappings. */ +struct address_space *mss;/* 'mss' area mappings. */ +struct address_space *psmap;/* 'psmap' area mappings. */ u64 object_id;/* user space pointer for oprofile */ enum {SPU_STATE_RUNNABLE ,SPU_STATE_SAVED } state;
PATCH 1/1 spufs: Fix bitrot of the SPU mmap facility (#2)
spufs: Fix bitrot of the SPU mmap facility
It looks like we've had some serious bitrot there mostly due to tracking of address_space's of mmap'ed files getting out of sync with the actual mmap code. The mfc, mss and psmap were not tracked properly and thus not invalidated on context switches (oops !)
I also removed the various file->f_mapping = inode->i_mapping; assignments that were done in the other open() routines since that is already done for us by __dentry_open.
One improvement we might want to do later is to assign the various ctx-> fields at mmap time instead of file open/close time so that we don't call unmap_mapping_range() on thing that have not been mmap'ed
Finally, I added some smp_wmb's after assigning the ctx-> fields to make sure they are visible to other CPUs. I don't think this is really necessary as I suspect locking in the fs layer will make that happen anyway but better safe than sorry.
---
New version of that patch removing the f_mapping assignment.
arch/powerpc/platforms/cell/spufs/context.c +8 -4
@@ -111,13 +111,17 @@ void spu_unmap_mappings(struct spu_conteif (ctx->local_store)unmap_mapping_range (ctx->local_store,0 ,LS_SIZE ,1 );if (ctx->mfc) -unmap_mapping_range (ctx->mfc,0 ,0x4000 ,1 ); +unmap_mapping_range (ctx->mfc,0 ,0x1000 ,1 );if (ctx->cntl) -unmap_mapping_range (ctx->cntl,0 ,0x4000 ,1 ); +unmap_mapping_range (ctx->cntl,0 ,0x1000 ,1 );if (ctx->signal1) -unmap_mapping_range (ctx->signal1,0 ,0x4000 ,1 ); +unmap_mapping_range (ctx->signal1,0 ,PAGE_SIZE ,1 );if (ctx->signal2) -unmap_mapping_range (ctx->signal2,0 ,0x4000 ,1 ); +unmap_mapping_range (ctx->signal2,0 ,PAGE_SIZE ,1 ); +if (ctx->mss) +unmap_mapping_range (ctx->mss,0 ,0x1000 ,1 ); +if (ctx->psmap) +unmap_mapping_range (ctx->psmap,0 ,0x20000 ,1 ); }int spu_acquire_exclusive (struct spu_context *ctx)
arch/powerpc/platforms/cell/spufs/file.c +12 -4
@@ -45,8 +45,8 @@ spufs_mem_open(struct inode *inode, strustruct spufs_inode_info *i =SPUFS_I (inode);struct spu_context *ctx = i->i_ctx; file->private_data = ctx; - file->f_mapping = inode->i_mapping; ctx->local_store = inode->i_mapping; +smp_wmb ();return 0 ; }
@@ -232,8 +232,8 @@ static int spufs_cntl_open(struct inodestruct spu_context *ctx = i->i_ctx; file->private_data = ctx; - file->f_mapping = inode->i_mapping; ctx->cntl = inode->i_mapping; +smp_wmb ();return simple_attr_open (inode, file, spufs_cntl_get, spufs_cntl_set,"0x%08lx" ); }
@@ -717,8 +717,8 @@ static int spufs_signal1_open(struct inostruct spufs_inode_info *i =SPUFS_I (inode);struct spu_context *ctx = i->i_ctx; file->private_data = ctx; - file->f_mapping = inode->i_mapping; ctx->signal1 = inode->i_mapping; +smp_wmb ();return nonseekable_open (inode, file); }
@@ -824,8 +824,8 @@ static int spufs_signal2_open(struct inostruct spufs_inode_info *i =SPUFS_I (inode);struct spu_context *ctx = i->i_ctx; file->private_data = ctx; - file->f_mapping = inode->i_mapping; ctx->signal2 = inode->i_mapping; +smp_wmb ();return nonseekable_open (inode, file); }
@@ -1021,8 +1021,11 @@ static int spufs_mss_mmap(struct file *fstatic int spufs_mss_open (struct inode *inode,struct file *file) {struct spufs_inode_info *i =SPUFS_I (inode); +struct spu_context *ctx = i->i_ctx; file->private_data = i->i_ctx; + ctx->mss = inode->i_mapping; +smp_wmb ();return nonseekable_open (inode, file); }
@@ -1060,8 +1063,11 @@ static int spufs_psmap_mmap(struct filestatic int spufs_psmap_open (struct inode *inode,struct file *file) {struct spufs_inode_info *i =SPUFS_I (inode); +struct spu_context *ctx = i->i_ctx; file->private_data = i->i_ctx; + ctx->psmap = inode->i_mapping; +smp_wmb ();return nonseekable_open (inode, file); }
@@ -1114,6 +1120,8 @@ static int spufs_mfc_open(struct inode *return -EBUSY ; file->private_data = ctx; + ctx->mfc = inode->i_mapping; +smp_wmb ();return nonseekable_open (inode, file); }
arch/powerpc/platforms/cell/spufs/spufs.h +2 -0
@@ -51,6 +51,8 @@ struct spu_context {struct address_space *cntl;/* 'control' area mappings. */ struct address_space *signal1;/* 'signal1' area mappings. */ struct address_space *signal2;/* 'signal2' area mappings. */ +struct address_space *mss;/* 'mss' area mappings. */ +struct address_space *psmap;/* 'psmap' area mappings. */ u64 object_id;/* user space pointer for oprofile */ enum {SPU_STATE_RUNNABLE ,SPU_STATE_SAVED } state;
Re: [Cbe-oss-dev] [PATCH] spufs: Fix bitrot of the SPU mmap facility (#2)
Quoted 11 lines · Benjamin Herrenschmidt
spufs: Fix bitrot of the SPU mmap facility
It looks like we've had some serious bitrot there mostly due to tracking of address_space's of mmap'ed files getting out of sync with the actual mmap code. The mfc, mss and psmap were not tracked properly and thus not invalidated on context switches (oops !)
I also removed the various
file->f_mapping=inode->i_mapping; assignments that were done in the otheropen()routines since that is already done for us by__dentry_open.
Quoted 8 lines
One improvement we might want to do later is to assign the various ctx-> fields at mmap time instead of file open/close time so that we don't call
unmap_mapping_range()on thing that have not been mmap'edFinally, I added some smp_wmb's after assigning the ctx-> fields to make sure they are visible to other CPUs. I don't think this is really necessary as I suspect locking in the fs layer will make that happen anyway but better safe than sorry.
Looks good to me.