Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1666953pxb; Fri, 10 Sep 2021 10:50:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWd72zcRTXUS7ptVghixel/KQwGCafl0pRTEJstVPadX8Gsstlr8An1233h2OjrrsSFnxC X-Received: by 2002:a05:6402:270a:: with SMTP id y10mr10114956edd.252.1631296249513; Fri, 10 Sep 2021 10:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631296249; cv=none; d=google.com; s=arc-20160816; b=aH8NXW6sL94680QXd68By8AjxvMTfQQyFajCPjMsVBdhl9KnVRIZwOR3PrF90BTr8w Ebi6Ed0YyZIbSSLX0xfO9S/jcBtKhfqBqEIpgZeh5tJzu8zfRYFTXKcI4XfML6/Yil3R M6qF1cZ+b4uYj7nAFgGGQajNgPcWkoa9mbZ2h//EuUx5KGcrX7QqcgJV41MATd14/0NM PGWIhGAwKmwErQk525HVMveUL0f483jowHkf//Du4u3+OL//ZD+DYmUxWIgDklqmG3ja ACMUXztLKfOaOq+Qexig1+VhetJV5AO6nAS8wqz1Yi2LCVGLw2oc54zk49mkQeOl04aF MZlQ== 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=ZvmshrhRRHf+OonCKONixU3Sueg2FEGkMUdYO67ivdc=; b=iRpfVV4KuNK1+kJP2j5vIBD4K5LEt0gdNSoCHu7iw311a/NukmcHZgItBtbiv615a3 cIhqELA7rlxvM45J3Q983znFqMHH1BVQhOTI6JMjYwpq4ng+u6auGkiBTkFh2u1OtOSV bQgR/zErBDr6dQPx9b+ViNL64vuSKm8x3GwdQ3iXDXca6rzv1MBtVFLbEoBrhz2Qaqps LvQk/GO7NKy52twBGYB2vbkJ+4PzeM2UgvZxEFtoctz/oJlaVMuDbsBkN0Pdylo6TUwj LXucjFgdMgmQoR0qppd78fV/yAVem+UmMpc3mdkwFWOeZ2XcepRtTAtNGUzrJzGBcApb MqgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nRwczmrL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kx11si5781806ejc.554.2021.09.10.10.50.25; Fri, 10 Sep 2021 10:50: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=@google.com header.s=20210112 header.b=nRwczmrL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229664AbhIJRuU (ORCPT + 99 others); Fri, 10 Sep 2021 13:50:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbhIJRuT (ORCPT ); Fri, 10 Sep 2021 13:50:19 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C9EEC061574 for ; Fri, 10 Sep 2021 10:49:08 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id q21so4478656ljj.6 for ; Fri, 10 Sep 2021 10:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZvmshrhRRHf+OonCKONixU3Sueg2FEGkMUdYO67ivdc=; b=nRwczmrLwdY24+0iOzfvLMv7zbOplKlYUVYrxS4yakIb7jNpRbGK1CMdpIj+VSWKVi sSxEPhOK8ff+oVlQDZmuPWDOg2Vb091nKGzmuUS2mAIeLNcz4ZeyT7lNxrfmW1MLjv0f eEHEFPOJum7M8dK4CM5F6ZF77uzwwn6V2v8bClziKGbXLD+x8pgqSGjEfOAEGHFKy25A ut82zveh+rHnKaCywQipWTLfQwVYrPuvH+Ebr/2Rx1UOOq2cyOrKJIE/0Nny+wDtkt+t GThwT449G9PXEM1F2Oigy0b+g3na21ZnkC2tpbG7a9mns59v2F0eFHQ/xlLCljO/YkZr /Gpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZvmshrhRRHf+OonCKONixU3Sueg2FEGkMUdYO67ivdc=; b=OCuPGQ6uBajCibcscXTJKzwLIsn00J2I76U4vCiQsov3AbW1cjMo4RfaoAk00hGBHe hyOTjLEUTervSXesUZ1l7OY7l6tQfojFzZtoskU/vfySaDlLZiw89J1cmqyFxfUJAirN aigoFFSMqBgQiboYL8T9uYwCTVVlghNahCZ+qd5LmoMXWCdIRtyGekFqV++aIKDZPWcg 26DcCaHxiPYZDRux8D35lpLBuf8pbB5qeYvanwD6771iOCs32heL4tqyK5NlV15sMP2F QUtUb7h1NRlwlQ4wnWfLf4dOQKN0sGhMbY/Us9SC4LpErY8wT9Wn6qoK5QIObC8za+3X dOtA== X-Gm-Message-State: AOAM532qyZZgIDLIYoFjShjnIabz+EkmrWBHnCDKMfdN+Z0XCev7c1vb GGVXIjwB3BOlee96/ZmG+uDlMfaB+7xKyP3U2AOYpg== X-Received: by 2002:a2e:9150:: with SMTP id q16mr5002276ljg.418.1631296146232; Fri, 10 Sep 2021 10:49:06 -0700 (PDT) MIME-Version: 1.0 References: <1631147036-13597-1-git-send-email-prakash.sangappa@oracle.com> <8735qcgzdu.fsf@oldenburg.str.redhat.com> <1297400717.15316.1631295199656.JavaMail.zimbra@efficios.com> In-Reply-To: <1297400717.15316.1631295199656.JavaMail.zimbra@efficios.com> From: Peter Oskolkov Date: Fri, 10 Sep 2021 10:48:54 -0700 Message-ID: Subject: Re: [RESEND RFC PATCH 0/3] Provide fast access to thread specific data To: Mathieu Desnoyers Cc: Florian Weimer , Prakash Sangappa , linux-kernel , linux-api , Ingo Molnar , Paul Turner , Jann Horn , Peter Oskolkov , Vincenzo Frascino , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 10, 2021 at 10:33 AM Mathieu Desnoyers wrote: > > ----- On Sep 10, 2021, at 12:37 PM, Florian Weimer fweimer@redhat.com wrote: > > > * Peter Oskolkov: > > > >> In short, due to the need to read/write to the userspace from > >> non-sleepable contexts in the kernel it seems that we need to have some > >> form of per task/thread kernel/userspace shared memory that is pinned, > >> similar to what your sys_task_getshared does. > > > > In glibc, we'd also like to have this for PID and TID. Eventually, > > rt_sigprocmask without kernel roundtrip in most cases would be very nice > > as well. For performance and simplicity in userspace, it would be best > > if the memory region could be at the same offset from the TCB for all > > threads. > > > > For KTLS, the idea was that the auxiliary vector would contain size and > > alignment of the KTLS. Userspace would reserve that memory, register it > > with the kernel like rseq (or the robust list pointers), and pass its > > address to the vDSO functions that need them. The last part ensures > > that the vDSO functions do not need non-global data to determine the > > offset from the TCB. Registration is still needed for the caches. > > > > I think previous discussions (in the KTLS and rseq context) did not have > > the pinning constraint. > > If this data is per-thread, and read from user-space, why is it relevant > to update this data from non-sleepable kernel context rather than update it as > needed on return-to-userspace ? When returning to userspace, sleeping due to a > page fault is entirely acceptable. This is what we currently do for rseq. > > In short, the data could be accessible from the task struct. Flags in the > task struct can let return-to-userspace know that it has outdated ktls > data. So before returning to userspace, the kernel can copy the relevant data > from the task struct to the shared memory area, without requiring any pinning. > > What am I missing ? I can't speak about other use cases, but in the context of userspace scheduling, the information that a task has blocked in the kernel and is going to be removed from its runqueue cannot wait to be delivered to the userspace until the task wakes up, as the userspace scheduler needs to know of the even when it happened so that it can schedule another task in place of the blocked one. See the discussion here: https://lore.kernel.org/lkml/CAG48ez0mgCXpXnqAUsa0TcFBPjrid-74Gj=xG8HZqj2n+OPoKw@mail.gmail.com/ > > Thanks, > > Mathieu > > > -- > Mathieu Desnoyers > EfficiOS Inc. > http://www.efficios.com