aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorIan Munsie <imunsie@au1.ibm.com>2014-12-08 03:18:01 -0500
committerMichael Ellerman <mpe@ellerman.id.au>2014-12-11 21:06:48 -0500
commitb123429e6a9e8d03aacf888d23262835f0081448 (patch)
treeb1b9c9eb381437982de078d061c274264a25c104 /drivers/misc
parenta98e6e9f4e0224d85b4d951edc44af16dfe6094a (diff)
cxl: Unmap MMIO regions when detaching a context
If we need to force detach a context (e.g. due to EEH or simply force unbinding the driver) we should prevent the userspace contexts from being able to access the Problem State Area MMIO region further, which they may have mapped with mmap(). This patch unmaps any mapped MMIO regions when detaching a userspace context. Cc: stable@vger.kernel.org Signed-off-by: Ian Munsie <imunsie@au1.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/cxl/context.c11
-rw-r--r--drivers/misc/cxl/cxl.h7
-rw-r--r--drivers/misc/cxl/file.c6
3 files changed, 21 insertions, 3 deletions
diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
index 4aa31a3fb448..51fd6b524371 100644
--- a/drivers/misc/cxl/context.c
+++ b/drivers/misc/cxl/context.c
@@ -34,7 +34,8 @@ struct cxl_context *cxl_context_alloc(void)
34/* 34/*
35 * Initialises a CXL context. 35 * Initialises a CXL context.
36 */ 36 */
37int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master) 37int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master,
38 struct address_space *mapping)
38{ 39{
39 int i; 40 int i;
40 41
@@ -42,6 +43,8 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master)
42 ctx->afu = afu; 43 ctx->afu = afu;
43 ctx->master = master; 44 ctx->master = master;
44 ctx->pid = NULL; /* Set in start work ioctl */ 45 ctx->pid = NULL; /* Set in start work ioctl */
46 mutex_init(&ctx->mapping_lock);
47 ctx->mapping = mapping;
45 48
46 /* 49 /*
47 * Allocate the segment table before we put it in the IDR so that we 50 * Allocate the segment table before we put it in the IDR so that we
@@ -147,6 +150,12 @@ static void __detach_context(struct cxl_context *ctx)
147 afu_release_irqs(ctx); 150 afu_release_irqs(ctx);
148 flush_work(&ctx->fault_work); /* Only needed for dedicated process */ 151 flush_work(&ctx->fault_work); /* Only needed for dedicated process */
149 wake_up_all(&ctx->wq); 152 wake_up_all(&ctx->wq);
153
154 /* Release Problem State Area mapping */
155 mutex_lock(&ctx->mapping_lock);
156 if (ctx->mapping)
157 unmap_mapping_range(ctx->mapping, 0, 0, 1);
158 mutex_unlock(&ctx->mapping_lock);
150} 159}
151 160
152/* 161/*
diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index 7c05239359df..28078f8894a5 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -398,6 +398,10 @@ struct cxl_context {
398 phys_addr_t psn_phys; 398 phys_addr_t psn_phys;
399 u64 psn_size; 399 u64 psn_size;
400 400
401 /* Used to unmap any mmaps when force detaching */
402 struct address_space *mapping;
403 struct mutex mapping_lock;
404
401 spinlock_t sste_lock; /* Protects segment table entries */ 405 spinlock_t sste_lock; /* Protects segment table entries */
402 struct cxl_sste *sstp; 406 struct cxl_sste *sstp;
403 u64 sstp0, sstp1; 407 u64 sstp0, sstp1;
@@ -599,7 +603,8 @@ int cxl_alloc_sst(struct cxl_context *ctx);
599void init_cxl_native(void); 603void init_cxl_native(void);
600 604
601struct cxl_context *cxl_context_alloc(void); 605struct cxl_context *cxl_context_alloc(void);
602int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master); 606int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master,
607 struct address_space *mapping);
603void cxl_context_free(struct cxl_context *ctx); 608void cxl_context_free(struct cxl_context *ctx);
604int cxl_context_iomap(struct cxl_context *ctx, struct vm_area_struct *vma); 609int cxl_context_iomap(struct cxl_context *ctx, struct vm_area_struct *vma);
605 610
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 378b099e7c0b..e9f2f10dbb37 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -77,7 +77,7 @@ static int __afu_open(struct inode *inode, struct file *file, bool master)
77 goto err_put_afu; 77 goto err_put_afu;
78 } 78 }
79 79
80 if ((rc = cxl_context_init(ctx, afu, master))) 80 if ((rc = cxl_context_init(ctx, afu, master, inode->i_mapping)))
81 goto err_put_afu; 81 goto err_put_afu;
82 82
83 pr_devel("afu_open pe: %i\n", ctx->pe); 83 pr_devel("afu_open pe: %i\n", ctx->pe);
@@ -113,6 +113,10 @@ static int afu_release(struct inode *inode, struct file *file)
113 __func__, ctx->pe); 113 __func__, ctx->pe);
114 cxl_context_detach(ctx); 114 cxl_context_detach(ctx);
115 115
116 mutex_lock(&ctx->mapping_lock);
117 ctx->mapping = NULL;
118 mutex_unlock(&ctx->mapping_lock);
119
116 put_device(&ctx->afu->dev); 120 put_device(&ctx->afu->dev);
117 121
118 /* 122 /*