[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240711094940.GB16902@redhat.com>
Date: Thu, 11 Jul 2024 11:49:40 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: Masami Hiramatsu <mhiramat@...nel.org>
Cc: andrii@...nel.org, peterz@...radead.org, clm@...a.com, jolsa@...nel.org,
mingo@...nel.org, paulmck@...nel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] uprobes: document the usage of mm->mmap_lock
On 07/11, Masami Hiramatsu wrote:
>
> On Wed, 10 Jul 2024 17:10:07 +0200
> Oleg Nesterov <oleg@...hat.com> wrote:
>
> > > > int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
> > > > @@ -1046,7 +1046,12 @@ register_for_each_vma(struct uprobe *uprobe, struct uprobe_consumer *new)
> > > >
> > > > if (err && is_register)
> > > > goto free;
> > > > -
> > > > + /*
> > > > + * We take mmap_lock for writing to avoid the race with
> > > > + * find_active_uprobe(), install_breakpoint() must not
> > > > + * make is_trap_at_addr() true right after find_uprobe()
> > > > + * returns NULL.
> > >
...
> OK, but it seems we should write the above longer explanation here.
> What about the comment like this?
Well, I am biased, but your version looks much more confusing to me...
> /*
> * We take mmap_lock for writing to avoid the race with
> * find_active_uprobe() and is_trap_at_adder() in reader
> * side.
> * If the reader, which hits a swbp and is handling it,
> * does not take mmap_lock for reading,
this looks as if the reader which hits a swbp takes mmap_lock for reading
because of this race. No, find_active_uprobe() needs mmap_read_lock() for
vma_lookup, get_user_pages, etc.
> it is possible
> * that find_active_uprobe() returns NULL (because
> * uprobe_unregister() removes uprobes right before that),
> * but is_trap_at_addr() can return true afterwards (because
> * another thread calls uprobe_register() on the same address).
^^^^^^^^^^^^^^^
We are the thread which called uprobe_register(), we are going to
do install_breakpoint().
And btw, not that I think this makes sense, but register_for_each_vma()
could probably do
if (is_register)
mmap_write_lock(mm);
else
mmap_read_lock(mm);
Oleg.
Powered by blists - more mailing lists