Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3159550pxy; Mon, 3 May 2021 17:04:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzThR8xK9ySUF+HN7L94HzaNdw3Z/kKzMGTLcZi2pdyInVviH9d39NoYOy1w5Mf8Jbv8CEn X-Received: by 2002:a17:906:a887:: with SMTP id ha7mr19155811ejb.365.1620086689458; Mon, 03 May 2021 17:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620086689; cv=none; d=google.com; s=arc-20160816; b=vmmwUf+b7+UN7CHrKiAC+6wieCrMhuM+vxCyMyzPT8oLaU9xvZqpDq/MlEhHMxOZCl pLLthTJBRY2/+DSoa5ql5VdgBdP8NZnmOaeA6bMynUMI/I+XR1mvk8hqoJ3yK0S8UFpk qycBFSxgPE8FmtHv7MSwIBAt7yUPAEs8bJAls85a8h06NJ5+iS/v9Ym4tZqfTuwuh8hM qKAkn1p6hlURoGFNw0apEyvelmy/95qW4t1mTJ+NB4ZtFH4HVbpWL/Pl4buMKI3MjNZh Qy6DCVnyCAEg7K9b3aQtlvmclfLZfCLGOoyUUpdyJDsiaAQZIHaF7fMVTLhLdwhTCkUL yurA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=DbEf8WzMRpmXnFdxRzqOlt6SZNXDW8rHHttfWoB5dR4=; b=a4vZniPeZYGWg30GfO8vzR3Qb/eqC5FihvtUEVlPqFOZsZ1Htb0khYnWUAT8dOyLoY hqJruBc7DBmzhiVDewabjA8/peS9xDZE7zH0KI1TNXLGDl5R6U1Q23Ni8jeaczzatk+D KPXnJ8JZJJriORI38tz3c+vJ6YgF8ECzSsOSatGo4M4fmVRcJl6dDa336E74B3J4uEIK X7wwlV9EHB1F0kZtbpwYMWNlC825lEXPR4Z/xJXzRIMmIZTYRegkVm6uFGp7PSIMV9Mc j/7O8ZuiJzaiW8/ff1DZAb4SfA42ZKm100PIIhLVTZy8N8LZd14yT/oC6N4sJLKEDAYG Ii2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qawfd1SE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h21si1183884ejt.566.2021.05.03.17.04.25; Mon, 03 May 2021 17:04:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qawfd1SE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbhEDACx (ORCPT + 99 others); Mon, 3 May 2021 20:02:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:37764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229673AbhEDACw (ORCPT ); Mon, 3 May 2021 20:02:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 24CB461244 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-f44.google.com with SMTP id a4so10449442ejk.1 for ; Mon, 03 May 2021 17:01:58 -0700 (PDT) X-Gm-Message-State: AOAM530kaj6Q2X7jYLZNY7zennnVW2vrU1/mbqiXC+144F1wMDpoNDFO ArvneihbdsxvIBZO1xBzfD2iJF+s86snN8G7zQvsHQ== 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: linux-kernel@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.