Messages in this thread |  | | From | Zong Li <> | Date | Sat, 4 Apr 2020 20:12:24 +0800 | Subject | Re: [PATCH v3 8/9] riscv: introduce interfaces to patch kernel code |
| |
On Sat, Apr 4, 2020 at 11:14 AM Masami Hiramatsu <mhiramat@kernel.org> wrote: > > Hi Zong, > > On Fri, 3 Apr 2020 17:04:51 +0800 > Zong Li <zong.li@sifive.com> wrote: > > > > > > > +{ > > > > > > + void *waddr = addr; > > > > > > + bool across_pages = (((uintptr_t) addr & ~PAGE_MASK) + len) > PAGE_SIZE; > > > > > > + unsigned long flags = 0; > > > > > > + int ret; > > > > > > + > > > > > > + raw_spin_lock_irqsave(&patch_lock, flags); > > > > > > > > > > This looks a bit odd since stop_machine() is protected by its own mutex, > > > > > and also the irq is already disabled here. > > > > > > > > We need it because we don't always enter the riscv_patch_text_nosync() > > > > through stop_machine mechanism. If we call the > > > > riscv_patch_text_nosync() directly, we need a lock to protect the > > > > page. > > > > > > Oh, OK, but it leads another question. Is that safe to patch the > > > text without sync? Would you use it for UP system? > > > I think it is better to clarify "in what case user can call _nosync()" > > > and add a comment on it. > > > > The ftrace is one of the cases, as documentation of ftrace said, when > > dynamic ftrace is initialized, it calls kstop_machine to make the > > machine act like a uniprocessor so that it can freely modify code > > without worrying about other processors executing that same code. So > > the ftrace called the _nosync interface here directly. > > Hmm, even though, since it already running under kstop_machine(), no > other thread will run. > Could you consider to use text_mutex instead of that? The text_mutex > is already widely used in x86 and kernel/kprobes.c etc. > > (Hmm, it seems except for x86, alternative code don't care about > racing...) >
Yes, text_mutex seems to be great. I'll change to use text_mutex in the next version if it works fine after testing. Thanks.
> Thank you, > -- > Masami Hiramatsu <mhiramat@kernel.org>
|  |