# \[RFC\]\[PATCH 7/7\] livepatch,context\_tracking: Avoid disturbing NOHZ\_FULL tasks

- From: Peter Zijlstra \<peterz@infradead.org\>
- Date: 2021-09-22 11:11:37 
- List: live-patching
- Page: https://ratatoskr.run/live-patching/2021/09/1518162
- Thread: https://ratatoskr.run/live-patching/2021/09/1518181/t.md

```text
When a task is stuck in NOHZ_FULL usermode, we can simply mark the
livepatch state complete.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/livepatch/transition.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

--- a/kernel/livepatch/transition.c
+++ b/kernel/livepatch/transition.c
@@ -270,13 +270,24 @@ static int klp_check_task(struct task_st
 {
 	int ret;
 
-	if (task_curr(task))
+	if (task_curr(task)) {
+		if (context_tracking_state_cpu(task_cpu(task)) == CONTEXT_USER) {
+			/*
+			 * If we observe the CPU being in USER context, they
+			 * must issue an smp_mb() before doing much kernel
+			 * space and as such will observe the patched state,
+			 * mark it clean.
+			 */
+			goto complete;
+		}
 		return -EBUSY;
+	}
 
 	ret = klp_check_stack(task, arg);
 	if (ret)
 		return ret;
 
+complete:
 	clear_tsk_thread_flag(task, TIF_PATCH_PENDING);
 	task->patch_state = klp_target_state;
 	return 0;


```
