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=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL 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 0D594C433B4 for ; Tue, 11 May 2021 18:12:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 89D086190A for ; Tue, 11 May 2021 18:12:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89D086190A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F150D6B006E; Tue, 11 May 2021 14:12:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9E176B0070; Tue, 11 May 2021 14:12:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC9196B0072; Tue, 11 May 2021 14:12:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id ADC8B6B006E for ; Tue, 11 May 2021 14:12:36 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 622A99982 for ; Tue, 11 May 2021 18:12:36 +0000 (UTC) X-FDA: 78129745512.12.A6A6123 Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) by imf28.hostedemail.com (Postfix) with ESMTP id AE1B6200026B for ; Tue, 11 May 2021 18:12:34 +0000 (UTC) Received: by mail-io1-f54.google.com with SMTP id z24so19074658ioi.3 for ; Tue, 11 May 2021 11: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=PCQFRYKnpEWO7nMBCUi8YB2CYHmyNOt7CgGjrmkkW68=; b=jZDsQCz5XwmQC2L6QfYDJCIE6p1QmWi6VzUofsPkBsNYP+Rg+MZ6XYpnZIbsPPmdP6 jMwheKL1jFTf7dNLBaQePPbqDXK/YTxGdsvSNtYqtw9xNxJjBVgoAXINz18T1ct2yw1j aL9a6USIRweParzL8U+hZU/kSf9zY+NWmealwJiLpoH4E3MGPdvvYixJV4p2X6EzcaQI sUvkCIuGq32HGGEKj73HmW6kkOrIDXgsggwPDuVzD6DzzZh2UGjmzlP+KgpeusaRbD/j mIBRQdJ8i9WJ94hy7u8LjLmEGoDvevqtN7bMsID8p82S2w32FcnGg7YzGQYMv9/7k8TA ZF6g== 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=PCQFRYKnpEWO7nMBCUi8YB2CYHmyNOt7CgGjrmkkW68=; b=bXm14q/umfuMvQhgJeIk9s/qhBAeT7WXyQ8Sgij0hlfMKetRnJ4lNrZkMlCTUgNNoR V6Ep140kM2KjUZdmJ5KTarE6DT54/yfbj/Pziy4oPTXLHSnaMh23ycqnpSP1sjN6DI/w O6+FgO5hB/p5sazh3z7f4vz9fzlx75RUS/f8+TY7fxiFfd7j0n+23NpwpJDH//jzVFWr ohHFtyQWQauvXdl/xGa0oMR8Tm2ws/hitHs2SPPMz2nXFPJHfhBHJYmEpOeQVExLUuiz geksLSIJe//IxC7w+y6XnjpGLtTDkIyf/1wB17iP7NLDUlyoNF87zD1Gu/kOAD6p480t MQ9w== X-Gm-Message-State: AOAM531ZtBJDJVRi6Ru2rGk2RS1ZdbINJrX3EvKN5UOgmQcoA8JbP3gj smAUWLpkeIuN/PG7d7EqfUO61v8hALJYh4rGHMEDTA== X-Google-Smtp-Source: ABdhPJzBFvo3VcEWCSO2q7hhXnROuFVAiGLe4L0aS0tsYpBErdoa3yP92qxbXyMkx746h31X4FPqm9yVtN74IW6oJiE= X-Received: by 2002:a6b:cd08:: with SMTP id d8mr23698430iog.86.1620756755061; Tue, 11 May 2021 11:12:35 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Axel Rasmussen Date: Tue, 11 May 2021 11:11:58 -0700 Message-ID: Subject: Re: Userspace notifications for observing userfaultfd faults To: "Robert O'Callahan" Cc: Andrea Arcangeli , Andrew Morton , Hugh Dickins , Peter Xu , Ingo Molnar , Linux-MM , LKML , Kyle Huey Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: AE1B6200026B Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=jZDsQCz5; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.166.54 as permitted sender) smtp.mailfrom=axelrasmussen@google.com X-Rspamd-Server: rspam03 X-Stat-Signature: si8dywhymbagexotsuyka14e96cb55mi Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=mail-io1-f54.google.com; client-ip=209.85.166.54 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620756754-143907 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, May 10, 2021 at 5:38 PM Robert O'Callahan wrote: > > For rr (https://rr-project.org) to support recording and replaying > applications that use userfaultfd, we need to observe that a task we > are controlling has blocked on a userfault. Currently this is very > difficult to do, especially if a task blocks on a userfault on a page > where some other task has already triggered a userfault, so no new > userfaultfd event is generated. We also need to observe which page has > been faulted on so we can determine when the fault has been serviced > and the task is ready to run again. > > I've tried to find workarounds with existing APIs and it doesn't seem > tractable. See https://github.com/rr-debugger/rr/issues/2852#issuecomment-837514946 > for some thoughts about that. > > It seems to me that a sufficient API for us would be a new software > perf event, e.g. PERF_COUNT_SW_USERFAULTS, with an associated > PERF_SAMPLE_ADDR that would give us the address of the page. Does that > sounds like a reasonable thing to add? Is some combination of bpf and kprobes a possible solution? There are some seemingly relevant examples here: https://github.com/iovisor/bpftrace/blob/master/docs/tutorial_one_liners.md I haven't tried it, but it seems like attaching to handle_userfault() would give similar information to perf_count_sw_page_faults, but for userfaults. > > Robert O'Callahan