From: Jason Baron <jbaron@akamai.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>,
Alexandre Chartre <alexandre.chartre@oracle.com>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>,
Steven Rostedt <rostedt@goodmis.org>,
Nadav Amit <namit@vmware.com>, X86 ML <x86@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Linus Torvalds <torvalds@linux-foundation.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Jiri Kosina <jkosina@suse.cz>,
David Laight <David.Laight@ACULAB.COM>,
Borislav Petkov <bp@alien8.de>, Julia Cartwright <julia@ni.com>,
Jessica Yu <jeyu@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Edward Cree <ecree@solarflare.com>,
Daniel Bristot de Oliveira <bristot@redhat.com>
Subject: Re: [PATCH v3 5/6] x86/alternative: Use a single access in text_poke() where possible
Date: Fri, 11 Jan 2019 12:41:08 -0500 [thread overview]
Message-ID: <d9b1c9b7-ae7b-80df-7b2f-19721f3460cf@akamai.com> (raw)
In-Reply-To: <20190111165752.z6e2dfktj2caqi4n@treble>
On 1/11/19 11:57 AM, Josh Poimboeuf wrote:
> On Fri, Jan 11, 2019 at 05:46:36PM +0100, Alexandre Chartre wrote:
>>
>>
>> On 01/11/2019 04:28 PM, Josh Poimboeuf wrote:
>>> On Fri, Jan 11, 2019 at 01:10:52PM +0100, Alexandre Chartre wrote:
>>>> To avoid any issue with live patching the call instruction, what about
>>>> toggling between two call instructions: one would be the currently active
>>>> call, while the other would currently be inactive but to be used after a
>>>> change is made. You can safely patch the inactive call and then toggle
>>>> the call flow (using a jump label) between the active and inactive calls.
>>>>
>>>> So instead of having a single call instruction:
>>>>
>>>> call function
>>>>
>>>> You would have:
>>>>
>>>> STATIC_JUMP_IF_TRUE label, key
>>>> call function1
>>>> jmp done
>>>> label:
>>>> call function2
>>>> done:
>>>>
>>>> If the key is set so that function1 is currently called then you can
>>>> safely update the call instruction for function2. Once this is done,
>>>> just flip the key to make the function2 call active. On a next update,
>>>> you would, of course, have to switch and update the call for function1.
>>>
>>> What about the following race?
>>>
>>> CPU1 CPU2
>>> static key is false, doesn't jump
>>> task gets preempted before calling function1
>>> change static key to true
>>> start patching "call function1"
>>> task resumes, sees inconsistent call instruction
>>>
>>
>> If the function1 call is active then it won't be changed, you will change
>> function2. However, I presume you can still have a race but if the function
>> is changed twice before calling function1:
>>
>> CPU1 CPU2
>> static key is false, doesn't jump
>> task gets preempted before calling function1
>> -- first function change --
>> patch "call function2"
>> change static key to true
>> -- second function change --
>> start patching "call function1"
>> task resumes, sees inconsistent call instruction
>>
>> So right, that's a problem.
>
> Right, that's what I meant to say :-)
>
could you use something like synchronize_rcu_tasks() between successive
updates to guarantee nobody's stuck in the middle of the call
instruction update? Yes its really slow but the update path is slow anyways.
Thanks,
-Jason
next prev parent reply other threads:[~2019-01-11 18:09 UTC|newest]
Thread overview: 90+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-09 22:59 [PATCH v3 0/6] Static calls Josh Poimboeuf
2019-01-09 22:59 ` [PATCH v3 1/6] compiler.h: Make __ADDRESSABLE() symbol truly unique Josh Poimboeuf
2019-01-09 22:59 ` [PATCH v3 2/6] static_call: Add basic static call infrastructure Josh Poimboeuf
2019-01-10 14:03 ` Edward Cree
2019-01-10 18:37 ` Josh Poimboeuf
2019-01-09 22:59 ` [PATCH v3 3/6] x86/static_call: Add out-of-line static call implementation Josh Poimboeuf
2019-01-10 0:16 ` Nadav Amit
2019-01-10 16:28 ` Josh Poimboeuf
2019-01-09 22:59 ` [PATCH v3 4/6] static_call: Add inline static call infrastructure Josh Poimboeuf
2019-01-09 22:59 ` [PATCH v3 5/6] x86/alternative: Use a single access in text_poke() where possible Josh Poimboeuf
2019-01-10 9:32 ` Nadav Amit
2019-01-10 17:20 ` Josh Poimboeuf
2019-01-10 17:29 ` Nadav Amit
2019-01-10 17:32 ` Steven Rostedt
2019-01-10 17:42 ` Sean Christopherson
2019-01-10 17:57 ` Steven Rostedt
2019-01-10 18:04 ` Sean Christopherson
2019-01-10 18:21 ` Josh Poimboeuf
2019-01-10 18:24 ` Steven Rostedt
2019-01-11 12:10 ` Alexandre Chartre
2019-01-11 15:28 ` Josh Poimboeuf
2019-01-11 16:46 ` Alexandre Chartre
2019-01-11 16:57 ` Josh Poimboeuf
2019-01-11 17:41 ` Jason Baron [this message]
2019-01-11 17:54 ` Nadav Amit
2019-01-15 11:10 ` Alexandre Chartre
2019-01-15 16:19 ` Steven Rostedt
2019-01-15 16:45 ` Alexandre Chartre
2019-01-11 0:59 ` hpa
2019-01-11 1:34 ` Sean Christopherson
2019-01-11 8:13 ` hpa
2019-01-09 22:59 ` [PATCH v3 6/6] x86/static_call: Add inline static call implementation for x86-64 Josh Poimboeuf
2019-01-10 1:21 ` [PATCH v3 0/6] Static calls Nadav Amit
2019-01-10 16:44 ` Josh Poimboeuf
2019-01-10 17:32 ` Nadav Amit
2019-01-10 18:18 ` Josh Poimboeuf
2019-01-10 19:45 ` Nadav Amit
2019-01-10 20:32 ` Josh Poimboeuf
2019-01-10 20:48 ` Nadav Amit
2019-01-10 20:57 ` Josh Poimboeuf
2019-01-10 21:47 ` Nadav Amit
2019-01-10 17:31 ` Linus Torvalds
2019-01-10 20:51 ` H. Peter Anvin
2019-01-10 20:30 ` Peter Zijlstra
2019-01-10 20:52 ` Josh Poimboeuf
2019-01-10 23:02 ` Linus Torvalds
2019-01-11 0:56 ` Andy Lutomirski
2019-01-11 1:47 ` Nadav Amit
2019-01-11 15:15 ` Josh Poimboeuf
2019-01-11 15:48 ` Nadav Amit
2019-01-11 16:07 ` Josh Poimboeuf
2019-01-11 17:23 ` Nadav Amit
2019-01-11 19:03 ` Linus Torvalds
2019-01-11 19:17 ` Nadav Amit
2019-01-11 19:23 ` hpa
2019-01-11 19:33 ` Nadav Amit
2019-01-11 19:34 ` Linus Torvalds
2019-01-13 0:34 ` hpa
2019-01-13 0:36 ` hpa
2019-01-11 19:39 ` Jiri Kosina
2019-01-14 2:31 ` H. Peter Anvin
2019-01-14 2:40 ` H. Peter Anvin
2019-01-14 20:11 ` Andy Lutomirski
2019-01-14 22:00 ` H. Peter Anvin
2019-01-14 22:54 ` H. Peter Anvin
2019-01-15 3:05 ` Andy Lutomirski
2019-01-15 5:01 ` H. Peter Anvin
2019-01-15 5:37 ` H. Peter Anvin
2019-01-14 23:27 ` Andy Lutomirski
2019-01-14 23:51 ` Nadav Amit
2019-01-15 2:28 ` hpa
2019-01-11 20:04 ` Josh Poimboeuf
2019-01-11 20:12 ` Linus Torvalds
2019-01-11 20:31 ` Josh Poimboeuf
2019-01-11 20:46 ` Linus Torvalds
2019-01-11 21:05 ` Andy Lutomirski
2019-01-11 21:10 ` Linus Torvalds
2019-01-11 21:32 ` Josh Poimboeuf
2019-01-14 12:28 ` Peter Zijlstra
2019-01-11 21:22 ` Josh Poimboeuf
2019-01-11 21:23 ` Josh Poimboeuf
2019-01-11 21:25 ` Josh Poimboeuf
2019-01-11 21:36 ` Nadav Amit
2019-01-11 21:41 ` Josh Poimboeuf
2019-01-11 21:55 ` Steven Rostedt
2019-01-11 21:59 ` Nadav Amit
2019-01-11 21:56 ` Nadav Amit
2019-01-12 23:54 ` Andy Lutomirski
2020-02-17 21:10 ` Jann Horn
2020-02-17 21:57 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d9b1c9b7-ae7b-80df-7b2f-19721f3460cf@akamai.com \
--to=jbaron@akamai.com \
--cc=David.Laight@ACULAB.COM \
--cc=alexandre.chartre@oracle.com \
--cc=ard.biesheuvel@linaro.org \
--cc=bp@alien8.de \
--cc=bristot@redhat.com \
--cc=ecree@solarflare.com \
--cc=hpa@zytor.com \
--cc=jeyu@kernel.org \
--cc=jkosina@suse.cz \
--cc=jpoimboe@redhat.com \
--cc=julia@ni.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=luto@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=namit@vmware.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sean.j.christopherson@intel.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).