lkml.org 
[lkml]   [2021]   [May]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Date
    SubjectRe: [PATCH] io_thread/x86: don't reset 'cs', 'ss', 'ds' and 'es' registers for io_threads
    On Mon, May 3, 2021 at 3:56 PM Thomas Gleixner <tglx@linutronix.de> wrote:
    >
    > It's all fine that we have lots of blurb about GDB, but there is no
    > reasoning why this does not affect regular kernel threads which take the
    > same code path.

    Actual kernel threads don't get attached to by ptrace.

    > This is a half setup user space thread which is assumed to behave like a
    > regular kernel thread, but is this assumption actually true?

    No, no.

    It's a *fully set up USER thread*.

    Those IO threads used to be kernel threads. That didn't work out for
    the reasons already mentioned earlier.

    These days they really are fully regular user threads, they just don't
    return to user space because they continue to do the IO work that they
    were created for.

    Maybe instead of Stefan's patch, we could do something like this:

    diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
    index 43cbfc84153a..890f3992e781 100644
    --- a/arch/x86/kernel/process.c
    +++ b/arch/x86/kernel/process.c
    @@ -156,7 +156,7 @@ int copy_thread(unsigned long clone_flags,
    unsigned long sp, unsigned long arg,
    #endif

    /* Kernel thread ? */
    - if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
    + if (unlikely(p->flags & PF_KTHREAD)) {
    memset(childregs, 0, sizeof(struct pt_regs));
    kthread_frame_init(frame, sp, arg);
    return 0;
    @@ -168,6 +168,17 @@ int copy_thread(unsigned long clone_flags,
    unsigned long sp, unsigned long arg,
    if (sp)
    childregs->sp = sp;

    + /*
    + * An IO thread is a user space thread, but it doesn't
    + * return to ret_after_fork(), it does the same kernel
    + * frame setup to return to a kernel function that
    + * a kernel thread does.
    + */
    + if (unlikely(p->flags & PF_IO_WORKER)) {
    + kthread_frame_init(frame, sp, arg);
    + return 0;
    + }
    +
    #ifdef CONFIG_X86_32
    task_user_gs(p) = get_user_gs(current_pt_regs());
    #endif
    does that clarify things and make people happier?

    Maybe the compiler might even notice that the

    kthread_frame_init(frame, sp, arg);
    return 0;

    part is common code and then it will result in less generated code too.

    NOTE! The above is - as usual - COMPLETELY UNTESTED. It looks obvious
    enough, and it builds cleanly. But that's all I'm going to guarantee.

    It's whitespace-damaged on purpose.

    Linus

    \
     
     \ /
      Last update: 2021-05-04 01:17    [W:3.784 / U:0.384 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site