Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3760280pxj; Tue, 11 May 2021 11:14:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwuysKNRq511qEoI4WQw7f0EPrclpser5fglPveHrlh66Ma+rAeOz1DfT8HAjXcTujn+vJ X-Received: by 2002:a05:6402:5a:: with SMTP id f26mr38090321edu.306.1620756856904; Tue, 11 May 2021 11:14:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620756856; cv=none; d=google.com; s=arc-20160816; b=Zwx3yYX9l6JicxH+5AgzGyOgF1kp61AqgdwO3e3cnzfMBrv9ptreLsKQUhpiWrqDoW dlavkf1IfWVmhm6sA6OCEXCeBsCAdju3BDFMSqnDM63krZoHbHl7pPEyKV+MpLrWq3r1 aQ3eOdPQoamnrY/rC0IRpXbAioaYLzlFTW2Xdp/6e3/9/i9b8EefcdW/d6CvjuaKvRPe HdvZWoNcjaChH1bLWxbGNRb7GmijYlCzv+6jPMQLa2/yYQ9TNFMhGoy2zEiWvlJUFch5 zq/j9xb67ZvPFDNcHCd5xQdYuWD7Z2giR0dhtzapKtEXr4e6t/RPrb4YoGqVMoZQw1+7 9PMw== 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=PCQFRYKnpEWO7nMBCUi8YB2CYHmyNOt7CgGjrmkkW68=; b=QeR+HuKy4ZiiF7rEO7gXINFINjfOCr2KjJ11Tb6OjeLx8cvUd+QMUeKLg3JWIlQY86 snbMJ3UN8t2W1tkRcHjjEL+rEds8hHspw+6qdv2Rki97Ttz5CrU01SOQLZY2XEkUorYD LeVesBN8t+VrVIaGkbBAiEtdT4qv3jRY5mMdAJa5asM6y+wTjQUt9DwnyZpj8/Fa9jVR NiUC8HPw7uUDdunj02wCebke3G7bSFKEVh9N1sOL7z7S6thnBFiUQQ9MMN6pYpnSRcBv tnBqQmqju7mgfAnM/RphDE1wvbSa5iYi1AqL78Er19PLPv2Slv19cpo4o0Il7IbdBPkI LMHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jZDsQCz5; 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 d4si7432066ejz.692.2021.05.11.11.13.52; Tue, 11 May 2021 11:14:16 -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=jZDsQCz5; 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 S231981AbhEKSNq (ORCPT + 99 others); Tue, 11 May 2021 14:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232079AbhEKSNo (ORCPT ); Tue, 11 May 2021 14:13:44 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9AC0C061763 for ; Tue, 11 May 2021 11:12:35 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id z24so19082806ioj.7 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=P7Os7jwz9uW+CuqtVFHVMhirHXOwkg3SAq6MKoOPNgssqMmfyO5rFW2ZGjsEqH+FoH sSl9IC9+ndFDRFvH0GI/bD2YaQLqv65SbeVxdM9fR8/Yrnk3G3prMM2/eyKR98o+Y3XH Ncvol5J40D4u5CPN8xxjMwRlUsHqWU5bsDGnrQDCIGzNMAZnge4Y9ozVuwy0Ggh+DZ1T FwHoUBn9Lsnjz18BzG8oBswx3POWkvtYUyti8mbV0nqvUPX+cgYy/CY0BajVENb+ExIt 64+yCEIRSTHk9Kbvr3epVi+mTaNi4O3IXtYjOq+l+dgSvrlgV8XQ1HopRkhSjEOJIsVm Ckjw== X-Gm-Message-State: AOAM530XXusvCYSTMtF6QYozGdxOsrbnU9qS/MHVX7vRJHvvGLwsldWv UwgQ8M8ySB8fl1qG6u1o8DHUk1eGqG6KaLSr2z8rhg== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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