Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp29667pxv; Thu, 8 Jul 2021 14:13:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTuOcHWiYmSNvzTBAqz0DJvbgTHKtIDBPSxCXuDLimMuQ0kU4TdWzxTU6IvSOAV43zx82e X-Received: by 2002:a05:6638:1505:: with SMTP id b5mr19523186jat.105.1625778812915; Thu, 08 Jul 2021 14:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625778812; cv=none; d=google.com; s=arc-20160816; b=a8n8ggvvCgn3u+KKRsI9l8ROhPkSTvbntqlX/quMzG6QSt8pFT+c3lG7gFIc2JVjqg WNpP4n3WrwPTzxGh6nX0Y1T8embp47cDxs7bTh2dtKVav1nE5ByPGDs93XJIK+2Wk5do nPmfd1DRdhsKSDNTDR2P1RufBxQIMHIzFx7rrypWa+5jxwr7zgyK7qdJSVXZzHkbKAsn 4FYwQs0dWmRpkX5yKtk9R5DhLzKzr63yYdQM1qhkEsFAiegLF/f6cFzilEaPSpDOWzck WwhpCOXBtm7udlQWN6jngv0kse+u4AA/AW4Q6WSmDYD8ffvOfacLFo5BEZ++0Y+SBNFW 77xg== 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=f1NHfW9F+V78jjSXkJMUixUMtEy56ReUIzgPfUrq2/k=; b=UXz17Bl6zVMd8eLbYxEK488CU25leBlOaRYX9XjYd/meFWLLixntKzeRWXnsy0Ga5u b1XNa55ccZzPki625q6lJgs3QdvNbjifrJwUImlpsAfvL3xuOB6t4k8WUxE4dFLSEvGA Ffbvk47e821A4ArN3OEEXa5JIp7y/MoKNTrzJa66DxKDF66lt08E/gJd2YVjmIkdaPTJ 2ZfGr6ayFWqgFcfeU97H5+4CYuwAzh+7/uffcRODVqgZ0x8qlY9t8vrTSupQpWTzWIMc tuWabPGsEVE7dRKQryuKwuXxCHr82L/ySWc+8azVKgCSzkTEQygWo3lVAp/yEp3W3RWc fBPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kX91r1j3; 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 c19si3559811ild.65.2021.07.08.14.13.20; Thu, 08 Jul 2021 14:13:32 -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=20161025 header.b=kX91r1j3; 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 S230442AbhGHVPS (ORCPT + 99 others); Thu, 8 Jul 2021 17:15:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbhGHVPS (ORCPT ); Thu, 8 Jul 2021 17:15:18 -0400 Received: from mail-vs1-xe2b.google.com (mail-vs1-xe2b.google.com [IPv6:2607:f8b0:4864:20::e2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1098BC061574 for ; Thu, 8 Jul 2021 14:12:36 -0700 (PDT) Received: by mail-vs1-xe2b.google.com with SMTP id g25so4433989vss.3 for ; Thu, 08 Jul 2021 14:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=f1NHfW9F+V78jjSXkJMUixUMtEy56ReUIzgPfUrq2/k=; b=kX91r1j3b1eond5H8vs2cxeIPsnS3WnX4y41EibTl/bRNtJ+cvF05DPNYodSGN7rVl a4wPQTrKiR0MODFixrsSBlfMIf9MmbyDgxPUkorZQBy5HR3F3b2E7XOSoSym+94bTRjk sp+86F24xZ60jEwDZ/CaNsVK6Ns53eFJ3w8GLuwCUYQkI0RVU2aCtR/wmIgfnpqFuedD iw9HyEyxAS086IPLo39bzeS5KBMHgyHlFRTEX1GbVXHR4A9ivJRrh0RqyuP+4UaEq4sg /KQM1RWfaf1/ba2uau1H0GTT0lKQgSrVrFOAmBV+GQ1vMRLuX5tfgSxX+hZMobqlmPWF SArA== 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=f1NHfW9F+V78jjSXkJMUixUMtEy56ReUIzgPfUrq2/k=; b=TE2GphYu3EwmEK4YBOJkE8ovkiGTRSkKmMO2CeaJmsAOyvV52xFLmgBORzs+H50SA3 eypuJCL9ua6Mh1WT4Zq21F3td/YFReXRdEr570z7HrlzNg6gugpoIaq8SNMMJJc/6Anu SPbVcNZghYELVbthv3gKbpiGZbealK/DvOoGt4CqPtiHOI23oVkc4/YM5e4xFZ+W1kAr 9iXrlemR3XGh9AmHwS0ANSnAr3HQbyhwxOQ+7cn/r8ASSFktQgLylZus0NI0eDHftAC+ TUmW5BGk+UyeybIWCTMjzMC6DN5/1C1o0nRLlHvqk6yzaj5qhEapoZSwtd1Qs3Pzm/2E U+7g== X-Gm-Message-State: AOAM533LUQvHUNtYKxv+aRY+XYrnALYwGsqXqd4tNFZIb3kS+xzh9PH5 BdtZW641w4xHiDT8ESgB4aDfSdONLJ9QBfndeQS14Q== X-Received: by 2002:a67:d998:: with SMTP id u24mr30784838vsj.16.1625778754878; Thu, 08 Jul 2021 14:12:34 -0700 (PDT) MIME-Version: 1.0 References: <20210708194638.128950-1-posk@google.com> <20210708194638.128950-3-posk@google.com> In-Reply-To: <20210708194638.128950-3-posk@google.com> From: Jann Horn Date: Thu, 8 Jul 2021 23:12:08 +0200 Message-ID: Subject: Re: [RFC PATCH 2/3 v0.2] sched/umcg: RFC: add userspace atomic helpers To: Peter Oskolkov Cc: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Paul Turner , Ben Segall , Peter Oskolkov , Joel Fernandes , Andrei Vagin , Jim Newsome Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 8, 2021 at 9:46 PM Peter Oskolkov wrote: > Add helper functions to work atomically with userspace 32/64 bit values - > there are some .*futex.* named helpers, but they are not exactly > what is needed for UMCG; I haven't found what else I could use, so I > rolled these. > > At the moment only X86_64 is supported. > > Note: the helpers should probably go into arch/ somewhere; I have > them in kernel/sched/umcg.h temporarily for convenience. Please > let me know where I should put them and how to name them. Instead of open-coding spinlocks in userspace memory like this (which some of the reviewers will probably dislike because it will have issues around priority inversion and such), I wonder whether you could use an actual futex as your underlying locking primitive? The most straightforward way to do that would probably be to make the head structure in userspace look roughly like this? struct umcg_head { u64 head_ptr; u32 lock; }; and then from kernel code, you could build a fastpath that directly calls cmpxchg_futex_value_locked() and build a fallback based on do_futex(), or something like that. There is precedent for using futex from inside the kernel to communicate with userspace: See mm_release(), which calls do_futex() with FUTEX_WAKE for the clear_child_tid feature.