]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.53/cxl-fix-driver-use-count.patch
Linux 4.14.112
[thirdparty/kernel/stable-queue.git] / releases / 4.9.53 / cxl-fix-driver-use-count.patch
1 From 197267d0356004a31c4d6b6336598f5dff3301e1 Mon Sep 17 00:00:00 2001
2 From: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
3 Date: Wed, 30 Aug 2017 12:15:49 +0200
4 Subject: cxl: Fix driver use count
5
6 From: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
7
8 commit 197267d0356004a31c4d6b6336598f5dff3301e1 upstream.
9
10 cxl keeps a driver use count, which is used with the hash memory model
11 on p8 to know when to upgrade local TLBIs to global and to trigger
12 callbacks to manage the MMU for PSL8.
13
14 If a process opens a context and closes without attaching or fails the
15 attachment, the driver use count is never decremented. As a
16 consequence, TLB invalidations remain global, even if there are no
17 active cxl contexts.
18
19 We should increment the driver use count when the process is attaching
20 to the cxl adapter, and not on open. It's not needed before the
21 adapter starts using the context and the use count is decremented on
22 the detach path, so it makes more sense.
23
24 It affects only the user api. The kernel api is already doing The
25 Right Thing.
26
27 Signed-off-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
28 Cc: stable@vger.kernel.org # v4.2+
29 Fixes: 7bb5d91a4dda ("cxl: Rework context lifetimes")
30 Acked-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
31 Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
32 [ajd: backport to stable v4.9 tree]
33 Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
34 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35 ---
36 drivers/misc/cxl/api.c | 4 ++++
37 drivers/misc/cxl/file.c | 8 +++++++-
38 2 files changed, 11 insertions(+), 1 deletion(-)
39
40 --- a/drivers/misc/cxl/api.c
41 +++ b/drivers/misc/cxl/api.c
42 @@ -244,6 +244,10 @@ int cxl_start_context(struct cxl_context
43 ctx->real_mode = false;
44 }
45
46 + /*
47 + * Increment driver use count. Enables global TLBIs for hash
48 + * and callbacks to handle the segment table
49 + */
50 cxl_ctx_get();
51
52 if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) {
53 --- a/drivers/misc/cxl/file.c
54 +++ b/drivers/misc/cxl/file.c
55 @@ -91,7 +91,6 @@ static int __afu_open(struct inode *inod
56
57 pr_devel("afu_open pe: %i\n", ctx->pe);
58 file->private_data = ctx;
59 - cxl_ctx_get();
60
61 /* indicate success */
62 rc = 0;
63 @@ -213,6 +212,12 @@ static long afu_ioctl_start_work(struct
64 ctx->glpid = get_task_pid(current->group_leader, PIDTYPE_PID);
65
66
67 + /*
68 + * Increment driver use count. Enables global TLBIs for hash
69 + * and callbacks to handle the segment table
70 + */
71 + cxl_ctx_get();
72 +
73 trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr);
74
75 if ((rc = cxl_ops->attach_process(ctx, false, work.work_element_descriptor,
76 @@ -222,6 +227,7 @@ static long afu_ioctl_start_work(struct
77 put_pid(ctx->glpid);
78 put_pid(ctx->pid);
79 ctx->glpid = ctx->pid = NULL;
80 + cxl_ctx_put();
81 goto out;
82 }
83