mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nadav Amit <namit@vmware.com>
To: Masami Hiramatsu <mhiramat@kernel.org>,
	Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@redhat.com>, X86 ML <x86@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-arch <linux-arch@vger.kernel.org>,
	Andy Lutomirski <luto@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Jason Wessel <jason.wessel@windriver.com>
Subject: Re: [RFC PATCH 1/6] x86/alternative: assert text_mutex is taken
Date: Thu, 30 Aug 2018 05:23:01 +0000	[thread overview]
Message-ID: <A729271C-5646-470D-B200-7C552EB18FC8@vmware.com> (raw)
In-Reply-To: <20180830112649.4b774f401d99a8b98e12008c@kernel.org>

at 7:26 PM, Masami Hiramatsu <mhiramat@kernel.org> wrote:

> On Wed, 29 Aug 2018 14:00:06 -0700
> Sean Christopherson <sean.j.christopherson@intel.com> wrote:
> 
>> On Wed, Aug 29, 2018 at 08:44:47PM +0000, Nadav Amit wrote:
>>> at 1:13 PM, Sean Christopherson <sean.j.christopherson@intel.com> wrote:
>>> 
>>>> On Wed, Aug 29, 2018 at 07:36:22PM +0000, Nadav Amit wrote:
>>>>> at 10:11 AM, Nadav Amit <namit@vmware.com> wrote:
>>>>> 
>>>>>> at 1:59 AM, Masami Hiramatsu <mhiramat@kernel.org> wrote:
>>>>>> 
>>>>>>> On Wed, 29 Aug 2018 01:11:42 -0700
>>>>>>> Nadav Amit <namit@vmware.com> wrote:
>>>>>>> 
>>>>>>>> Use lockdep to ensure that text_mutex is taken when text_poke() is
>>>>>>>> called.
>>>>>>>> 
>>>>>>>> Actually it is not always taken, specifically when it is called by kgdb,
>>>>>>>> so take the lock in these cases.
>>>>>>> 
>>>>>>> Can we really take a mutex in kgdb context?
>>>>>>> 
>>>>>>> kgdb_arch_remove_breakpoint
>>>>>>> <- dbg_deactivate_sw_breakpoints
>>>>>>> <- kgdb_reenter_check
>>>>>>>    <- kgdb_handle_exception
>>>>>>>       <- __kgdb_notify
>>>>>>>         <- kgdb_ll_trap
>>>>>>>           <- do_int3
>>>>>>>         <- kgdb_notify
>>>>>>>           <- die notifier
>>>>>>> 
>>>>>>> kgdb_arch_set_breakpoint
>>>>>>> <- dbg_activate_sw_breakpoints
>>>>>>> <- kgdb_reenter_check
>>>>>>>    <- kgdb_handle_exception
>>>>>>>        ...
>>>>>>> 
>>>>>>> Both seems called in exception context, so we can not take a mutex lock.
>>>>>>> I think kgdb needs a special path.
>>>>>> 
>>>>>> You are correct, but I don’t want a special path. Presumably text_mutex is
>>>>>> guaranteed not to be taken according to the code.
>>>>>> 
>>>>>> So I guess the only concern is lockdep. Do you see any problem if I change
>>>>>> mutex_lock() into mutex_trylock()? It should always succeed, and I can add a
>>>>>> warning and a failure path if it fails for some reason.
>>>>> 
>>>>> Err.. This will not work. I think I will drop this patch, since I cannot
>>>>> find a proper yet simple assertion. Creating special path just for the
>>>>> assertion seems wrong.
>>>> 
>>>> It's probably worth expanding the comment for text_poke() to call out
>>>> the kgdb case and reference kgdb_arch_{set,remove}_breakpoint(), whose
>>>> code and comments make it explicitly clear why its safe for them to
>>>> call text_poke() without acquiring the lock.  Might prevent someone
>>>> from going down this path again in the future.
>>> 
>>> I thought that the whole point of the patch was to avoid comments, and
>>> instead enforce the right behavior. I don’t understand well enough kgdb
>>> code, so I cannot attest it does the right thing. What happens if
>>> kgdb_do_roundup==0?
>> 
>> As is, the comment is wrong because there are obviously cases where
>> text_poke() is called without text_mutex being held.  I can't attest
>> to the kgdb code either.  My thought was to document the exception so
>> that if someone does want to try and enforce the right behavior they
>> can dive right into the problem instead of having to learn of the kgdb
>> gotcha the hard way.  Maybe a FIXME is the right approach?
> 
> No, kgdb ensures that the text_mutex has not been held right before
> calling text_poke. So they also take care the text_mutex. I guess
> kgdb_arch_{set,remove}_breakpoint() is supposed to be run under
> a special circumstance, like stopping all other threads/cores.
> In that case, we can just check the text_mutex is not locked.

I assumed so too, but after looking at the code, I am not sure that this is
the case when gdb_do_roundup==0.

> Anyway, kgdb is a very rare courner case. I think if CONFIG_KGDB is
> enabled, lockdep and any assertion should be disabled, since kgdb
> can tweak anything in the kernel with unexpected ways...

Call me lazy, but I really do not want to debug syzkaller failures due to
this issue (now or in the future). If the assertion is known to be
incorrect, even in a corner case, I see no reason to have it and I certainly
do not want to be the one that added it…


  reply	other threads:[~2018-08-30  5:23 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-29  8:11 [RFC PATCH 0/6] x86: text_poke() fixes Nadav Amit
2018-08-29  8:11 ` [RFC PATCH 1/6] x86/alternative: assert text_mutex is taken Nadav Amit
2018-08-29  8:59   ` Masami Hiramatsu
2018-08-29 17:11     ` Nadav Amit
2018-08-29 19:36       ` Nadav Amit
2018-08-29 20:13         ` Sean Christopherson
2018-08-29 20:44           ` Nadav Amit
2018-08-29 21:00             ` Sean Christopherson
2018-08-29 22:56               ` Nadav Amit
2018-08-30  2:26               ` Masami Hiramatsu
2018-08-30  5:23                 ` Nadav Amit [this message]
2018-08-29  8:11 ` [RFC PATCH 2/6] x86/mm: temporary mm struct Nadav Amit
2018-08-29  9:49   ` Masami Hiramatsu
2018-08-29 15:41     ` Andy Lutomirski
2018-08-29 16:54       ` Nadav Amit
2018-08-29 21:38         ` Andy Lutomirski
2018-08-30  1:38       ` Masami Hiramatsu
2018-08-30  1:59         ` Andy Lutomirski
2018-08-31  4:42           ` Masami Hiramatsu
2018-08-29 15:46   ` Andy Lutomirski
2018-08-29  8:11 ` [RFC PATCH 3/6] fork: provide a function for copying init_mm Nadav Amit
2018-08-29  9:54   ` Masami Hiramatsu
2018-08-29  8:11 ` [RFC PATCH 4/6] x86/alternatives: initializing temporary mm for patching Nadav Amit
2018-08-29 13:21   ` Masami Hiramatsu
2018-08-29 17:45     ` Nadav Amit
2018-08-29  8:11 ` [RFC PATCH 5/6] x86/alternatives: use temporary mm for text poking Nadav Amit
2018-08-29  9:28   ` Peter Zijlstra
2018-08-29 15:46     ` Andy Lutomirski
2018-08-29 16:14       ` Peter Zijlstra
2018-08-29 16:32         ` Andy Lutomirski
2018-08-29 16:37           ` Dave Hansen
2018-08-29  8:11 ` [RFC PATCH 6/6] x86/alternatives: remove text_poke() return value Nadav Amit
2018-08-29  9:52   ` Masami Hiramatsu
2018-08-29 17:15     ` Nadav Amit

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=A729271C-5646-470D-B200-7C552EB18FC8@vmware.com \
    --to=namit@vmware.com \
    --cc=arnd@arndb.de \
    --cc=jason.wessel@windriver.com \
    --cc=keescook@chromium.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=tglx@linutronix.de \
    --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

all inboxes | Powered by JetHome®