From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B83FC433B4 for ; Tue, 4 May 2021 00:02:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3EE5661244 for ; Tue, 4 May 2021 00:02:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229677AbhEDACw (ORCPT ); Mon, 3 May 2021 20:02:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:37752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbhEDACw (ORCPT ); Mon, 3 May 2021 20:02:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 22318610E6 for ; Tue, 4 May 2021 00:01:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620086518; bh=IKpKf7PhC4k2UZheSYL1fEwwAl2gFqXtlCWhSayr0sY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Qawfd1SE7EDaQtWrx5lNXQlaa6e/mPEldFfkFRDevH8IcTz5YkOYjCK1/JyZI4UkB crpWEcIDIcqWcNLrvE0D/VGYJLuREY4B3/jHr/4xgs1gLwNwf1wOC5W7JJ+aeLolEi lOOfYejUhkHXocyB3LNG8KBFKDF4UFUQaA9xW9RNZHYIoMglM/B4ubR5LBSB/9nxGC /1js7N+YgjlYKzBQ63S3GL43xYlPDZL12QkgqjJVFlP8DfswEllWCTmcyUorv2VB8t WoC3SMhWbW6gCwK6OYY47ABF4d97KhDZnJRqqoMGGf7mLsucExFdqDmR8Y3z9Rv/An sxmlML8xUY3SA== Received: by mail-ej1-f52.google.com with SMTP id r9so10444144ejj.3 for ; Mon, 03 May 2021 17:01:58 -0700 (PDT) X-Gm-Message-State: AOAM530Y5oCdERsKd3Swd967xgXVRiXW60Pay4HP/BRYi6A3QRY/Me2l YKsCUq6mMjE0KrnkCrGOvNxBCZEklFRI9aMm2C3Grg== X-Google-Smtp-Source: ABdhPJwBn8JeNuxiPtZcB6RVcrwDaqmLIJBExddckI7Y2zSt42SGvalk9nv7cMZmnP7w5qND43ZrGzZSHhcr/YmRkkg= X-Received: by 2002:a17:906:4f91:: with SMTP id o17mr18944005eju.503.1620086516574; Mon, 03 May 2021 17:01:56 -0700 (PDT) MIME-Version: 1.0 References: <8735v3ex3h.ffs@nanos.tec.linutronix.de> <3C41339D-29A2-4AB1-958F-19DB0A92D8D7@amacapital.net> <8735v3jujv.ffs@nanos.tec.linutronix.de> In-Reply-To: From: Andy Lutomirski Date: Mon, 3 May 2021 17:01:45 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] io_thread/x86: don't reset 'cs', 'ss', 'ds' and 'es' registers for io_threads To: Linus Torvalds Cc: Thomas Gleixner , Andy Lutomirski , Jens Axboe , Stefan Metzmacher , Linux Kernel Mailing List , io-uring , "the arch/x86 maintainers" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On Mon, May 3, 2021 at 4:16 PM Linus Torvalds wrote: > > On Mon, May 3, 2021 at 3:56 PM Thomas Gleixner 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. I like this patch considerably more than I liked the previous patch. FWIW, I have this fixlet sitting around: https://git.kernel.org/pub/scm/linux/kernel/git/luto/linux.git/commit/?h=x86/kentry&id=1eef07ae5b236112c9a0c5d880d7f9bb13e73761 Your patch fixes the same bug for the specific case of io_uring.