linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Nadav Amit <namit@vmware.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	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>
Subject: Re: [RFC PATCH 1/6] x86/alternative: assert text_mutex is taken
Date: Wed, 29 Aug 2018 14:00:06 -0700	[thread overview]
Message-ID: <20180829210006.GA7166@linux.intel.com> (raw)
In-Reply-To: <58345C1F-8FF3-4F49-AF2F-B4789DF50CC7@vmware.com>

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?

  reply	other threads:[~2018-08-29 21:00 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 [this message]
2018-08-29 22:56               ` Nadav Amit
2018-08-30  2:26               ` Masami Hiramatsu
2018-08-30  5:23                 ` Nadav Amit
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=20180829210006.GA7166@linux.intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=arnd@arndb.de \
    --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=namit@vmware.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;
as well as URLs for NNTP newsgroup(s).