[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YU1/Z/+IviZXog5w@alley>
Date: Fri, 24 Sep 2021 09:33:59 +0200
From: Petr Mladek <pmladek@...e.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: gor@...ux.ibm.com, jpoimboe@...hat.com, jikos@...nel.org,
mbenes@...e.cz, mingo@...nel.org, linux-kernel@...r.kernel.org,
joe.lawrence@...hat.com, fweisbec@...il.com, tglx@...utronix.de,
hca@...ux.ibm.com, svens@...ux.ibm.com, sumanthk@...ux.ibm.com,
live-patching@...r.kernel.org, paulmck@...nel.org
Subject: Re: [RFC][PATCH 7/7] livepatch,context_tracking: Avoid disturbing
NOHZ_FULL tasks
On Thu 2021-09-23 15:28:56, Peter Zijlstra wrote:
> On Thu, Sep 23, 2021 at 03:14:48PM +0200, Petr Mladek wrote:
>
> > IMHO, this is not safe:
> >
> > CPU0 CPU1
> >
> > klp_check_task(A)
> > if (context_tracking_state_cpu(task_cpu(task)) == CONTEXT_USER)
> > goto complete;
> >
> > clear_tsk_thread_flag(task, TIF_PATCH_PENDING);
> >
> > # task switching to kernel space
> > klp_update_patch_state(A)
> > if (test_and_clear_tsk_thread_flag(task, TIF_PATCH_PENDING))
> > //false
> >
> > # calling kernel code with old task->patch_state
> >
> > task->patch_state = klp_target_state;
> >
> > BANG: CPU0 sets task->patch_state when task A is already running
> > kernel code on CPU1.
>
> Why is that a problem? That is, who actually cares about
> task->patch_state ? I was under the impression that state was purely for
> klp itself, to track which task has observed the new state.
It is the other way. The patch_state is used in klp_ftrace_handler()
to decide which code must be used (old or new).
The state must change only when the given task is _not_ using
any patched function. Hence we do it when:
+ no patched function is on the stack (needed primary for kthreads)
+ entering/leaving kernel (reliable way for user space)
See "Consistency model" in Documentation/livepatch/livepatch.rst
for more details.
Best Regards,
Petr
Powered by blists - more mailing lists