Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3133889pxy; Mon, 3 May 2021 16:17:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySjjX8mVIxd4tWISsw9NJvnTGS5+7LB67m2ctTe38JZ6ek/9+EcDEQrB9DH2jWc0RpBpYs X-Received: by 2002:a17:90a:bb13:: with SMTP id u19mr23495209pjr.96.1620083855582; Mon, 03 May 2021 16:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620083855; cv=none; d=google.com; s=arc-20160816; b=Py/ukQ695EL3C03nl1Yf0lhWuLj0Bqb/tOA95wKLQVKoVrd4dgM9/joM7SKkayYt1k dbaNURFse3UnxvPlILaMOvmJrPfYoaaISpmoo9xBjUPW+mgS0t/Qw771ZP6sW9TKKnrY QhcAiYiEnjPvdXiyUrngXTrvW+m0UPrcgX2Iao1uVfDUpdx1TOtlmcDFjqpZYomQ9uTo VnAkC5VQionWKCacNmjmxrIGUM/KQal7pRDBcK4c+F4+WxlQgq/UTKRNVRMV7N2A/11Z /8w94qUo2R+yYAYRxfuvecEsTp/yh6Mu04Xkw+Vkq13FD6G7o7vUDOcMzhxROfv2UB6R qlJQ== 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=Z9KOFf1NZVdQnIit6tiPPrEtDnkQyMpuOTw2ZsjIy58=; b=FwlIE9f1FlKxRvOvRSyX0weabSTXc3dL7fILF22gubZM6WxSCCPT4GguF35yEZVyW5 5/vSXtz+LVALDswv7fE0FZ55hQQVGcMa5Fk/cOytjDR/6+R5+qQyyruvvH6YyBDSz2Zi H08yAfKlxQf6qb4SpPHIwGvjBrBJWoSN7PaUpJWgmR8kOj0dBTRdTbzTVaUEpde6bFEj 4cJj3fXkofMpgwW+Ioa3QB/BcpoHvQl5XyH6ozaq6hdkUNCeD3cQrLy/Idz2Tw5Pk7QT Hge7Rrao4lRkCYPRTkACAimDNG88k2AP4i5hLd8nC37Adk6txczZFii0YweIuMCLL3pF CC0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=dFwm+qXI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t9si1470235pgc.12.2021.05.03.16.17.22; Mon, 03 May 2021 16:17:35 -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=@linux-foundation.org header.s=google header.b=dFwm+qXI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbhECXRb (ORCPT + 99 others); Mon, 3 May 2021 19:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbhECXRa (ORCPT ); Mon, 3 May 2021 19:17:30 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D632EC061574 for ; Mon, 3 May 2021 16:16:36 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id x19so10551853lfa.2 for ; Mon, 03 May 2021 16:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Z9KOFf1NZVdQnIit6tiPPrEtDnkQyMpuOTw2ZsjIy58=; b=dFwm+qXIxzZW5CfweYRXpu8xapkcLiDD1oOidHs9QY+jXkveW3cLyH1u4aVHDQr4Bk U8HCyzhqKwEEmkASOfFuFnXNPq6X4OoiHSDosf9thWu11tr/pT1gLTndYp46+x/joSpz 8uE2SkLCDxu5zsxVEihDBIFAuYcCNygUrWjNc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Z9KOFf1NZVdQnIit6tiPPrEtDnkQyMpuOTw2ZsjIy58=; b=TFBPcZAyh68ZUJJb/s9u+HP/zecr5SghJO2UWgXrr4e/BxfAKYHYkZQzJy6AWYu6hD hQpW8vqFWwqXycu/gRmQbJmql8otdWZgP9Ize3NUVb1Wp1SPVImWg6zKpSlKtQbKfyOQ oi2K8epSLYCFeVfpj0IXOCeN8wS1i2F3PHFVwSb8xeBzK0+Ase8fOkXNFp+UwFXntLou ZvvC7LP7Oq+mCS2RJ37RhEBs1zPlBPoFRCl7vxBczQTbeQK21dyhoOlx/Y1rYrKS+5+l c3Kf6KlSMixRFlEOZP50BSXvp85fQXmqL/ROT1et3U4QH0xmDHaCLO0VBQinSi9jEvWv vQqw== X-Gm-Message-State: AOAM530YSi3ax+WP41QnUwQz/ClKl5tcO9dqS9z+GQwV2EbE5n6SfObq pFuF69/jYd2on49nMlOGsyckS62381yExviL X-Received: by 2002:a05:6512:3713:: with SMTP id z19mr12168059lfr.566.1620083795106; Mon, 03 May 2021 16:16:35 -0700 (PDT) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com. [209.85.208.182]) by smtp.gmail.com with ESMTPSA id i18sm1457832ljd.40.2021.05.03.16.16.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 May 2021 16:16:34 -0700 (PDT) Received: by mail-lj1-f182.google.com with SMTP id u20so8853248lja.13 for ; Mon, 03 May 2021 16:16:34 -0700 (PDT) X-Received: by 2002:a2e:9251:: with SMTP id v17mr1317895ljg.507.1620083793861; Mon, 03 May 2021 16:16:33 -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: <8735v3jujv.ffs@nanos.tec.linutronix.de> From: Linus Torvalds Date: Mon, 3 May 2021 16:16:17 -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: Thomas Gleixner Cc: 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 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. Linus