summaryrefslogtreecommitdiffstats
path: root/arch/powerpc/platforms/book3s
diff options
context:
space:
mode:
authorHaren Myneni <haren@linux.ibm.com>2022-03-01 02:13:15 +0100
committerMichael Ellerman <mpe@ellerman.id.au>2022-03-07 14:04:55 +0100
commitb5c63d90cc2de8ac6724fec84d1d72cfebcae41d (patch)
tree61ab44d743276c628bb355a87aadb859d634f6d8 /arch/powerpc/platforms/book3s
parentpowerpc/vas: Add paste address mmap fault handler (diff)
downloadlinux-b5c63d90cc2de8ac6724fec84d1d72cfebcae41d.tar.xz
linux-b5c63d90cc2de8ac6724fec84d1d72cfebcae41d.zip
powerpc/vas: Return paste instruction failure if no active window
The VAS window may not be active if the system looses credits and the NX generates page fault when it receives request on unmap paste address. The kernel handles the fault by remap new paste address if the window is active again, Otherwise return the paste instruction failure if the executed instruction that caused the fault was a paste. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Haren Myneni <haren@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/492b9aefd593061d51dda67ee4d2fc449c000dce.camel@linux.ibm.com
Diffstat (limited to 'arch/powerpc/platforms/book3s')
-rw-r--r--arch/powerpc/platforms/book3s/vas-api.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/book3s/vas-api.c b/arch/powerpc/platforms/book3s/vas-api.c
index 217b4a624d09..82f32781c5d2 100644
--- a/arch/powerpc/platforms/book3s/vas-api.c
+++ b/arch/powerpc/platforms/book3s/vas-api.c
@@ -352,6 +352,41 @@ static int coproc_release(struct inode *inode, struct file *fp)
}
/*
+ * If the executed instruction that caused the fault was a paste, then
+ * clear regs CR0[EQ], advance NIP, and return 0. Else return error code.
+ */
+static int do_fail_paste(void)
+{
+ struct pt_regs *regs = current->thread.regs;
+ u32 instword;
+
+ if (WARN_ON_ONCE(!regs))
+ return -EINVAL;
+
+ if (WARN_ON_ONCE(!user_mode(regs)))
+ return -EINVAL;
+
+ /*
+ * If we couldn't translate the instruction, the driver should
+ * return success without handling the fault, it will be retried
+ * or the instruction fetch will fault.
+ */
+ if (get_user(instword, (u32 __user *)(regs->nip)))
+ return -EAGAIN;
+
+ /*
+ * Not a paste instruction, driver may fail the fault.
+ */
+ if ((instword & PPC_INST_PASTE_MASK) != PPC_INST_PASTE)
+ return -ENOENT;
+
+ regs->ccr &= ~0xe0000000; /* Clear CR0[0-2] to fail paste */
+ regs_add_return_ip(regs, 4); /* Emulate the paste */
+
+ return 0;
+}
+
+/*
* This fault handler is invoked when the core generates page fault on
* the paste address. Happens if the kernel closes window in hypervisor
* (on pseries) due to lost credit or the paste address is not mapped.
@@ -364,6 +399,7 @@ static vm_fault_t vas_mmap_fault(struct vm_fault *vmf)
struct vas_window *txwin;
vm_fault_t fault;
u64 paste_addr;
+ int ret;
/*
* window is not opened. Shouldn't expect this error.
@@ -408,6 +444,24 @@ static vm_fault_t vas_mmap_fault(struct vm_fault *vmf)
}
mutex_unlock(&txwin->task_ref.mmap_mutex);
+ /*
+ * Received this fault due to closing the actual window.
+ * It can happen during migration or lost credits.
+ * Since no mapping, return the paste instruction failure
+ * to the user space.
+ */
+ ret = do_fail_paste();
+ /*
+ * The user space can retry several times until success (needed
+ * for migration) or should fallback to SW compression or
+ * manage with the existing open windows if available.
+ * Looking at sysfs interface, it can determine whether these
+ * failures are coming during migration or core removal:
+ * nr_used_credits > nr_total_credits when lost credits
+ */
+ if (!ret || (ret == -EAGAIN))
+ return VM_FAULT_NOPAGE;
+
return VM_FAULT_SIGBUS;
}