xref: /openbmc/linux/drivers/misc/cxl/fault.c (revision 174cd4b1)
1f204e0b8SIan Munsie /*
2f204e0b8SIan Munsie  * Copyright 2014 IBM Corp.
3f204e0b8SIan Munsie  *
4f204e0b8SIan Munsie  * This program is free software; you can redistribute it and/or
5f204e0b8SIan Munsie  * modify it under the terms of the GNU General Public License
6f204e0b8SIan Munsie  * as published by the Free Software Foundation; either version
7f204e0b8SIan Munsie  * 2 of the License, or (at your option) any later version.
8f204e0b8SIan Munsie  */
9f204e0b8SIan Munsie 
10f204e0b8SIan Munsie #include <linux/workqueue.h>
11174cd4b1SIngo Molnar #include <linux/sched/signal.h>
126e84f315SIngo Molnar #include <linux/sched/mm.h>
13f204e0b8SIan Munsie #include <linux/pid.h>
14f204e0b8SIan Munsie #include <linux/mm.h>
15f204e0b8SIan Munsie #include <linux/moduleparam.h>
16f204e0b8SIan Munsie 
17f204e0b8SIan Munsie #undef MODULE_PARAM_PREFIX
18f204e0b8SIan Munsie #define MODULE_PARAM_PREFIX "cxl" "."
19f204e0b8SIan Munsie #include <asm/current.h>
20f204e0b8SIan Munsie #include <asm/copro.h>
21f204e0b8SIan Munsie #include <asm/mmu.h>
22f204e0b8SIan Munsie 
23f204e0b8SIan Munsie #include "cxl.h"
249bcf28cdSIan Munsie #include "trace.h"
25f204e0b8SIan Munsie 
26eb01d4c2SIan Munsie static bool sste_matches(struct cxl_sste *sste, struct copro_slb *slb)
27eb01d4c2SIan Munsie {
28eb01d4c2SIan Munsie 	return ((sste->vsid_data == cpu_to_be64(slb->vsid)) &&
29eb01d4c2SIan Munsie 		(sste->esid_data == cpu_to_be64(slb->esid)));
30eb01d4c2SIan Munsie }
31eb01d4c2SIan Munsie 
32eb01d4c2SIan Munsie /*
33eb01d4c2SIan Munsie  * This finds a free SSTE for the given SLB, or returns NULL if it's already in
34eb01d4c2SIan Munsie  * the segment table.
35eb01d4c2SIan Munsie  */
36b03a7f57SIan Munsie static struct cxl_sste* find_free_sste(struct cxl_context *ctx,
37b03a7f57SIan Munsie 				       struct copro_slb *slb)
38f204e0b8SIan Munsie {
39eb01d4c2SIan Munsie 	struct cxl_sste *primary, *sste, *ret = NULL;
40b03a7f57SIan Munsie 	unsigned int mask = (ctx->sst_size >> 7) - 1; /* SSTP0[SegTableSize] */
415100a9d6SIan Munsie 	unsigned int entry;
42b03a7f57SIan Munsie 	unsigned int hash;
43f204e0b8SIan Munsie 
44b03a7f57SIan Munsie 	if (slb->vsid & SLB_VSID_B_1T)
45b03a7f57SIan Munsie 		hash = (slb->esid >> SID_SHIFT_1T) & mask;
46b03a7f57SIan Munsie 	else /* 256M */
47b03a7f57SIan Munsie 		hash = (slb->esid >> SID_SHIFT) & mask;
48b03a7f57SIan Munsie 
49b03a7f57SIan Munsie 	primary = ctx->sstp + (hash << 3);
50b03a7f57SIan Munsie 
51b03a7f57SIan Munsie 	for (entry = 0, sste = primary; entry < 8; entry++, sste++) {
52eb01d4c2SIan Munsie 		if (!ret && !(be64_to_cpu(sste->esid_data) & SLB_ESID_V))
53eb01d4c2SIan Munsie 			ret = sste;
54eb01d4c2SIan Munsie 		if (sste_matches(sste, slb))
55eb01d4c2SIan Munsie 			return NULL;
56f204e0b8SIan Munsie 	}
57eb01d4c2SIan Munsie 	if (ret)
58eb01d4c2SIan Munsie 		return ret;
59b03a7f57SIan Munsie 
60f204e0b8SIan Munsie 	/* Nothing free, select an entry to cast out */
61eb01d4c2SIan Munsie 	ret = primary + ctx->sst_lru;
62b03a7f57SIan Munsie 	ctx->sst_lru = (ctx->sst_lru + 1) & 0x7;
63f204e0b8SIan Munsie 
64eb01d4c2SIan Munsie 	return ret;
65f204e0b8SIan Munsie }
66f204e0b8SIan Munsie 
67f204e0b8SIan Munsie static void cxl_load_segment(struct cxl_context *ctx, struct copro_slb *slb)
68f204e0b8SIan Munsie {
69f204e0b8SIan Munsie 	/* mask is the group index, we search primary and secondary here. */
70f204e0b8SIan Munsie 	struct cxl_sste *sste;
71f204e0b8SIan Munsie 	unsigned long flags;
72f204e0b8SIan Munsie 
73f204e0b8SIan Munsie 	spin_lock_irqsave(&ctx->sste_lock, flags);
74b03a7f57SIan Munsie 	sste = find_free_sste(ctx, slb);
75eb01d4c2SIan Munsie 	if (!sste)
76eb01d4c2SIan Munsie 		goto out_unlock;
77f204e0b8SIan Munsie 
78f204e0b8SIan Munsie 	pr_devel("CXL Populating SST[%li]: %#llx %#llx\n",
79f204e0b8SIan Munsie 			sste - ctx->sstp, slb->vsid, slb->esid);
809bcf28cdSIan Munsie 	trace_cxl_ste_write(ctx, sste - ctx->sstp, slb->esid, slb->vsid);
81f204e0b8SIan Munsie 
82f204e0b8SIan Munsie 	sste->vsid_data = cpu_to_be64(slb->vsid);
83f204e0b8SIan Munsie 	sste->esid_data = cpu_to_be64(slb->esid);
84eb01d4c2SIan Munsie out_unlock:
85f204e0b8SIan Munsie 	spin_unlock_irqrestore(&ctx->sste_lock, flags);
86f204e0b8SIan Munsie }
87f204e0b8SIan Munsie 
88f204e0b8SIan Munsie static int cxl_fault_segment(struct cxl_context *ctx, struct mm_struct *mm,
89f204e0b8SIan Munsie 			     u64 ea)
90f204e0b8SIan Munsie {
91f204e0b8SIan Munsie 	struct copro_slb slb = {0,0};
92f204e0b8SIan Munsie 	int rc;
93f204e0b8SIan Munsie 
94f204e0b8SIan Munsie 	if (!(rc = copro_calculate_slb(mm, ea, &slb))) {
95f204e0b8SIan Munsie 		cxl_load_segment(ctx, &slb);
96f204e0b8SIan Munsie 	}
97f204e0b8SIan Munsie 
98f204e0b8SIan Munsie 	return rc;
99f204e0b8SIan Munsie }
100f204e0b8SIan Munsie 
101f204e0b8SIan Munsie static void cxl_ack_ae(struct cxl_context *ctx)
102f204e0b8SIan Munsie {
103f204e0b8SIan Munsie 	unsigned long flags;
104f204e0b8SIan Munsie 
1055be587b1SFrederic Barrat 	cxl_ops->ack_irq(ctx, CXL_PSL_TFC_An_AE, 0);
106f204e0b8SIan Munsie 
107f204e0b8SIan Munsie 	spin_lock_irqsave(&ctx->lock, flags);
108f204e0b8SIan Munsie 	ctx->pending_fault = true;
109f204e0b8SIan Munsie 	ctx->fault_addr = ctx->dar;
110f204e0b8SIan Munsie 	ctx->fault_dsisr = ctx->dsisr;
111f204e0b8SIan Munsie 	spin_unlock_irqrestore(&ctx->lock, flags);
112f204e0b8SIan Munsie 
113f204e0b8SIan Munsie 	wake_up_all(&ctx->wq);
114f204e0b8SIan Munsie }
115f204e0b8SIan Munsie 
116f204e0b8SIan Munsie static int cxl_handle_segment_miss(struct cxl_context *ctx,
117f204e0b8SIan Munsie 				   struct mm_struct *mm, u64 ea)
118f204e0b8SIan Munsie {
119f204e0b8SIan Munsie 	int rc;
120f204e0b8SIan Munsie 
121f204e0b8SIan Munsie 	pr_devel("CXL interrupt: Segment fault pe: %i ea: %#llx\n", ctx->pe, ea);
1229bcf28cdSIan Munsie 	trace_cxl_ste_miss(ctx, ea);
123f204e0b8SIan Munsie 
124f204e0b8SIan Munsie 	if ((rc = cxl_fault_segment(ctx, mm, ea)))
125f204e0b8SIan Munsie 		cxl_ack_ae(ctx);
126f204e0b8SIan Munsie 	else {
127f204e0b8SIan Munsie 
128f204e0b8SIan Munsie 		mb(); /* Order seg table write to TFC MMIO write */
1295be587b1SFrederic Barrat 		cxl_ops->ack_irq(ctx, CXL_PSL_TFC_An_R, 0);
130f204e0b8SIan Munsie 	}
131f204e0b8SIan Munsie 
132f204e0b8SIan Munsie 	return IRQ_HANDLED;
133f204e0b8SIan Munsie }
134f204e0b8SIan Munsie 
135f204e0b8SIan Munsie static void cxl_handle_page_fault(struct cxl_context *ctx,
136f204e0b8SIan Munsie 				  struct mm_struct *mm, u64 dsisr, u64 dar)
137f204e0b8SIan Munsie {
138f204e0b8SIan Munsie 	unsigned flt = 0;
139f204e0b8SIan Munsie 	int result;
140aefa5688SAneesh Kumar K.V 	unsigned long access, flags, inv_flags = 0;
141f204e0b8SIan Munsie 
1429bcf28cdSIan Munsie 	trace_cxl_pte_miss(ctx, dsisr, dar);
1439bcf28cdSIan Munsie 
144f204e0b8SIan Munsie 	if ((result = copro_handle_mm_fault(mm, dar, dsisr, &flt))) {
145f204e0b8SIan Munsie 		pr_devel("copro_handle_mm_fault failed: %#x\n", result);
146f204e0b8SIan Munsie 		return cxl_ack_ae(ctx);
147f204e0b8SIan Munsie 	}
148f204e0b8SIan Munsie 
149f204e0b8SIan Munsie 	/*
150f204e0b8SIan Munsie 	 * update_mmu_cache() will not have loaded the hash since current->trap
151f204e0b8SIan Munsie 	 * is not a 0x400 or 0x300, so just call hash_page_mm() here.
152f204e0b8SIan Munsie 	 */
153c7d54842SAneesh Kumar K.V 	access = _PAGE_PRESENT | _PAGE_READ;
154f204e0b8SIan Munsie 	if (dsisr & CXL_PSL_DSISR_An_S)
155c7d54842SAneesh Kumar K.V 		access |= _PAGE_WRITE;
156ac29c640SAneesh Kumar K.V 
157ac29c640SAneesh Kumar K.V 	access |= _PAGE_PRIVILEGED;
1583b1dbfa1SAneesh Kumar K.V 	if ((!ctx->kernel) || (REGION_ID(dar) == USER_REGION_ID))
159ac29c640SAneesh Kumar K.V 		access &= ~_PAGE_PRIVILEGED;
160aefa5688SAneesh Kumar K.V 
161aefa5688SAneesh Kumar K.V 	if (dsisr & DSISR_NOHPTE)
162aefa5688SAneesh Kumar K.V 		inv_flags |= HPTE_NOHPTE_UPDATE;
163aefa5688SAneesh Kumar K.V 
164f204e0b8SIan Munsie 	local_irq_save(flags);
165aefa5688SAneesh Kumar K.V 	hash_page_mm(mm, dar, access, 0x300, inv_flags);
166f204e0b8SIan Munsie 	local_irq_restore(flags);
167f204e0b8SIan Munsie 
168f204e0b8SIan Munsie 	pr_devel("Page fault successfully handled for pe: %i!\n", ctx->pe);
1695be587b1SFrederic Barrat 	cxl_ops->ack_irq(ctx, CXL_PSL_TFC_An_R, 0);
170f204e0b8SIan Munsie }
171f204e0b8SIan Munsie 
1727b8ad495SVaibhav Jain /*
1737b8ad495SVaibhav Jain  * Returns the mm_struct corresponding to the context ctx via ctx->pid
1747b8ad495SVaibhav Jain  * In case the task has exited we use the task group leader accessible
1757b8ad495SVaibhav Jain  * via ctx->glpid to find the next task in the thread group that has a
1767b8ad495SVaibhav Jain  * valid  mm_struct associated with it. If a task with valid mm_struct
1777b8ad495SVaibhav Jain  * is found the ctx->pid is updated to use the task struct for subsequent
1787b8ad495SVaibhav Jain  * translations. In case no valid mm_struct is found in the task group to
1797b8ad495SVaibhav Jain  * service the fault a NULL is returned.
1807b8ad495SVaibhav Jain  */
1817b8ad495SVaibhav Jain static struct mm_struct *get_mem_context(struct cxl_context *ctx)
1827b8ad495SVaibhav Jain {
1837b8ad495SVaibhav Jain 	struct task_struct *task = NULL;
1847b8ad495SVaibhav Jain 	struct mm_struct *mm = NULL;
1857b8ad495SVaibhav Jain 	struct pid *old_pid = ctx->pid;
1867b8ad495SVaibhav Jain 
1877b8ad495SVaibhav Jain 	if (old_pid == NULL) {
1887b8ad495SVaibhav Jain 		pr_warn("%s: Invalid context for pe=%d\n",
1897b8ad495SVaibhav Jain 			 __func__, ctx->pe);
1907b8ad495SVaibhav Jain 		return NULL;
1917b8ad495SVaibhav Jain 	}
1927b8ad495SVaibhav Jain 
1937b8ad495SVaibhav Jain 	task = get_pid_task(old_pid, PIDTYPE_PID);
1947b8ad495SVaibhav Jain 
1957b8ad495SVaibhav Jain 	/*
1967b8ad495SVaibhav Jain 	 * pid_alive may look racy but this saves us from costly
1977b8ad495SVaibhav Jain 	 * get_task_mm when the task is a zombie. In worst case
1987b8ad495SVaibhav Jain 	 * we may think a task is alive, which is about to die
1997b8ad495SVaibhav Jain 	 * but get_task_mm will return NULL.
2007b8ad495SVaibhav Jain 	 */
2017b8ad495SVaibhav Jain 	if (task != NULL && pid_alive(task))
2027b8ad495SVaibhav Jain 		mm = get_task_mm(task);
2037b8ad495SVaibhav Jain 
2047b8ad495SVaibhav Jain 	/* release the task struct that was taken earlier */
2057b8ad495SVaibhav Jain 	if (task)
2067b8ad495SVaibhav Jain 		put_task_struct(task);
2077b8ad495SVaibhav Jain 	else
2087b8ad495SVaibhav Jain 		pr_devel("%s: Context owning pid=%i for pe=%i dead\n",
2097b8ad495SVaibhav Jain 			__func__, pid_nr(old_pid), ctx->pe);
2107b8ad495SVaibhav Jain 
2117b8ad495SVaibhav Jain 	/*
2127b8ad495SVaibhav Jain 	 * If we couldn't find the mm context then use the group
2137b8ad495SVaibhav Jain 	 * leader to iterate over the task group and find a task
2147b8ad495SVaibhav Jain 	 * that gives us mm_struct.
2157b8ad495SVaibhav Jain 	 */
2167b8ad495SVaibhav Jain 	if (unlikely(mm == NULL && ctx->glpid != NULL)) {
2177b8ad495SVaibhav Jain 
2187b8ad495SVaibhav Jain 		rcu_read_lock();
2197b8ad495SVaibhav Jain 		task = pid_task(ctx->glpid, PIDTYPE_PID);
2207b8ad495SVaibhav Jain 		if (task)
2217b8ad495SVaibhav Jain 			do {
2227b8ad495SVaibhav Jain 				mm = get_task_mm(task);
2237b8ad495SVaibhav Jain 				if (mm) {
2247b8ad495SVaibhav Jain 					ctx->pid = get_task_pid(task,
2257b8ad495SVaibhav Jain 								PIDTYPE_PID);
2267b8ad495SVaibhav Jain 					break;
2277b8ad495SVaibhav Jain 				}
2287b8ad495SVaibhav Jain 				task = next_thread(task);
2297b8ad495SVaibhav Jain 			} while (task && !thread_group_leader(task));
2307b8ad495SVaibhav Jain 		rcu_read_unlock();
2317b8ad495SVaibhav Jain 
2327b8ad495SVaibhav Jain 		/* check if we switched pid */
2337b8ad495SVaibhav Jain 		if (ctx->pid != old_pid) {
2347b8ad495SVaibhav Jain 			if (mm)
2357b8ad495SVaibhav Jain 				pr_devel("%s:pe=%i switch pid %i->%i\n",
2367b8ad495SVaibhav Jain 					 __func__, ctx->pe, pid_nr(old_pid),
2377b8ad495SVaibhav Jain 					 pid_nr(ctx->pid));
2387b8ad495SVaibhav Jain 			else
2397b8ad495SVaibhav Jain 				pr_devel("%s:Cannot find mm for pid=%i\n",
2407b8ad495SVaibhav Jain 					 __func__, pid_nr(old_pid));
2417b8ad495SVaibhav Jain 
2427b8ad495SVaibhav Jain 			/* drop the reference to older pid */
2437b8ad495SVaibhav Jain 			put_pid(old_pid);
2447b8ad495SVaibhav Jain 		}
2457b8ad495SVaibhav Jain 	}
2467b8ad495SVaibhav Jain 
2477b8ad495SVaibhav Jain 	return mm;
2487b8ad495SVaibhav Jain }
2497b8ad495SVaibhav Jain 
2507b8ad495SVaibhav Jain 
2517b8ad495SVaibhav Jain 
252f204e0b8SIan Munsie void cxl_handle_fault(struct work_struct *fault_work)
253f204e0b8SIan Munsie {
254f204e0b8SIan Munsie 	struct cxl_context *ctx =
255f204e0b8SIan Munsie 		container_of(fault_work, struct cxl_context, fault_work);
256f204e0b8SIan Munsie 	u64 dsisr = ctx->dsisr;
257f204e0b8SIan Munsie 	u64 dar = ctx->dar;
258a6b07d82SMichael Neuling 	struct mm_struct *mm = NULL;
259f204e0b8SIan Munsie 
260ea2d1f95SFrederic Barrat 	if (cpu_has_feature(CPU_FTR_HVMODE)) {
261f204e0b8SIan Munsie 		if (cxl_p2n_read(ctx->afu, CXL_PSL_DSISR_An) != dsisr ||
262f204e0b8SIan Munsie 		    cxl_p2n_read(ctx->afu, CXL_PSL_DAR_An) != dar ||
263f204e0b8SIan Munsie 		    cxl_p2n_read(ctx->afu, CXL_PSL_PEHandle_An) != ctx->pe) {
264ea2d1f95SFrederic Barrat 			/* Most likely explanation is harmless - a dedicated
265ea2d1f95SFrederic Barrat 			 * process has detached and these were cleared by the
266ea2d1f95SFrederic Barrat 			 * PSL purge, but warn about it just in case
267ea2d1f95SFrederic Barrat 			 */
268f204e0b8SIan Munsie 			dev_notice(&ctx->afu->dev, "cxl_handle_fault: Translation fault regs changed\n");
269f204e0b8SIan Munsie 			return;
270f204e0b8SIan Munsie 		}
271ea2d1f95SFrederic Barrat 	}
272f204e0b8SIan Munsie 
27313da7046SIan Munsie 	/* Early return if the context is being / has been detached */
27413da7046SIan Munsie 	if (ctx->status == CLOSED) {
27513da7046SIan Munsie 		cxl_ack_ae(ctx);
27613da7046SIan Munsie 		return;
27713da7046SIan Munsie 	}
27813da7046SIan Munsie 
279f204e0b8SIan Munsie 	pr_devel("CXL BOTTOM HALF handling fault for afu pe: %i. "
280f204e0b8SIan Munsie 		"DSISR: %#llx DAR: %#llx\n", ctx->pe, dsisr, dar);
281f204e0b8SIan Munsie 
282a6b07d82SMichael Neuling 	if (!ctx->kernel) {
2837b8ad495SVaibhav Jain 
2847b8ad495SVaibhav Jain 		mm = get_mem_context(ctx);
2857b8ad495SVaibhav Jain 		/* indicates all the thread in task group have exited */
2867b8ad495SVaibhav Jain 		if (mm == NULL) {
2877b8ad495SVaibhav Jain 			pr_devel("%s: unable to get mm for pe=%d pid=%i\n",
2887b8ad495SVaibhav Jain 				 __func__, ctx->pe, pid_nr(ctx->pid));
289f204e0b8SIan Munsie 			cxl_ack_ae(ctx);
290f204e0b8SIan Munsie 			return;
2917b8ad495SVaibhav Jain 		} else {
2927b8ad495SVaibhav Jain 			pr_devel("Handling page fault for pe=%d pid=%i\n",
2937b8ad495SVaibhav Jain 				 ctx->pe, pid_nr(ctx->pid));
294f204e0b8SIan Munsie 		}
295a6b07d82SMichael Neuling 	}
296f204e0b8SIan Munsie 
297f204e0b8SIan Munsie 	if (dsisr & CXL_PSL_DSISR_An_DS)
298f204e0b8SIan Munsie 		cxl_handle_segment_miss(ctx, mm, dar);
299f204e0b8SIan Munsie 	else if (dsisr & CXL_PSL_DSISR_An_DM)
300f204e0b8SIan Munsie 		cxl_handle_page_fault(ctx, mm, dsisr, dar);
301f204e0b8SIan Munsie 	else
302f204e0b8SIan Munsie 		WARN(1, "cxl_handle_fault has nothing to handle\n");
303f204e0b8SIan Munsie 
304a6b07d82SMichael Neuling 	if (mm)
305f204e0b8SIan Munsie 		mmput(mm);
306f204e0b8SIan Munsie }
307f204e0b8SIan Munsie 
308f204e0b8SIan Munsie static void cxl_prefault_one(struct cxl_context *ctx, u64 ea)
309f204e0b8SIan Munsie {
310f204e0b8SIan Munsie 	struct mm_struct *mm;
311f204e0b8SIan Munsie 
3127b8ad495SVaibhav Jain 	mm = get_mem_context(ctx);
3137b8ad495SVaibhav Jain 	if (mm == NULL) {
314f204e0b8SIan Munsie 		pr_devel("cxl_prefault_one unable to get mm %i\n",
315f204e0b8SIan Munsie 			 pid_nr(ctx->pid));
316f204e0b8SIan Munsie 		return;
317f204e0b8SIan Munsie 	}
318f204e0b8SIan Munsie 
3197b8ad495SVaibhav Jain 	cxl_fault_segment(ctx, mm, ea);
320f204e0b8SIan Munsie 
321f204e0b8SIan Munsie 	mmput(mm);
322f204e0b8SIan Munsie }
323f204e0b8SIan Munsie 
324f204e0b8SIan Munsie static u64 next_segment(u64 ea, u64 vsid)
325f204e0b8SIan Munsie {
326f204e0b8SIan Munsie 	if (vsid & SLB_VSID_B_1T)
327f204e0b8SIan Munsie 		ea |= (1ULL << 40) - 1;
328f204e0b8SIan Munsie 	else
329f204e0b8SIan Munsie 		ea |= (1ULL << 28) - 1;
330f204e0b8SIan Munsie 
331f204e0b8SIan Munsie 	return ea + 1;
332f204e0b8SIan Munsie }
333f204e0b8SIan Munsie 
334f204e0b8SIan Munsie static void cxl_prefault_vma(struct cxl_context *ctx)
335f204e0b8SIan Munsie {
336f204e0b8SIan Munsie 	u64 ea, last_esid = 0;
337f204e0b8SIan Munsie 	struct copro_slb slb;
338f204e0b8SIan Munsie 	struct vm_area_struct *vma;
339f204e0b8SIan Munsie 	int rc;
340f204e0b8SIan Munsie 	struct mm_struct *mm;
341f204e0b8SIan Munsie 
3427b8ad495SVaibhav Jain 	mm = get_mem_context(ctx);
3437b8ad495SVaibhav Jain 	if (mm == NULL) {
344f204e0b8SIan Munsie 		pr_devel("cxl_prefault_vm unable to get mm %i\n",
345f204e0b8SIan Munsie 			 pid_nr(ctx->pid));
3467b8ad495SVaibhav Jain 		return;
347f204e0b8SIan Munsie 	}
348f204e0b8SIan Munsie 
349f204e0b8SIan Munsie 	down_read(&mm->mmap_sem);
350f204e0b8SIan Munsie 	for (vma = mm->mmap; vma; vma = vma->vm_next) {
351f204e0b8SIan Munsie 		for (ea = vma->vm_start; ea < vma->vm_end;
352f204e0b8SIan Munsie 				ea = next_segment(ea, slb.vsid)) {
353f204e0b8SIan Munsie 			rc = copro_calculate_slb(mm, ea, &slb);
354f204e0b8SIan Munsie 			if (rc)
355f204e0b8SIan Munsie 				continue;
356f204e0b8SIan Munsie 
357f204e0b8SIan Munsie 			if (last_esid == slb.esid)
358f204e0b8SIan Munsie 				continue;
359f204e0b8SIan Munsie 
360f204e0b8SIan Munsie 			cxl_load_segment(ctx, &slb);
361f204e0b8SIan Munsie 			last_esid = slb.esid;
362f204e0b8SIan Munsie 		}
363f204e0b8SIan Munsie 	}
364f204e0b8SIan Munsie 	up_read(&mm->mmap_sem);
365f204e0b8SIan Munsie 
366f204e0b8SIan Munsie 	mmput(mm);
367f204e0b8SIan Munsie }
368f204e0b8SIan Munsie 
369f204e0b8SIan Munsie void cxl_prefault(struct cxl_context *ctx, u64 wed)
370f204e0b8SIan Munsie {
371f204e0b8SIan Munsie 	switch (ctx->afu->prefault_mode) {
372f204e0b8SIan Munsie 	case CXL_PREFAULT_WED:
373f204e0b8SIan Munsie 		cxl_prefault_one(ctx, wed);
374f204e0b8SIan Munsie 		break;
375f204e0b8SIan Munsie 	case CXL_PREFAULT_ALL:
376f204e0b8SIan Munsie 		cxl_prefault_vma(ctx);
377f204e0b8SIan Munsie 		break;
378f204e0b8SIan Munsie 	default:
379f204e0b8SIan Munsie 		break;
380f204e0b8SIan Munsie 	}
381f204e0b8SIan Munsie }
382