Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 682C5C636D6 for ; Wed, 8 Feb 2023 21:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231185AbjBHVcS (ORCPT ); Wed, 8 Feb 2023 16:32:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231634AbjBHVcP (ORCPT ); Wed, 8 Feb 2023 16:32:15 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED34018145 for ; Wed, 8 Feb 2023 13:31:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675891888; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FIAor+VDsPlrB9lj+l3LEuEZ+2Aj/cQ4916Fau1bI0Q=; b=i0cuJ2Jpe8hbwK8DOSMOXS4S73rmdVB6vb2zc9Z+hhYuuWTrVRCIqE+apmi8q+G4Zyddph dsmcFz0cLiQ6Oxo5/IjFCQwuMdD8k3RsWNCGwYbEo2Tem/8Tk2u/1iWISnHxINIYu5gVE3 WXxdj77n45E1oDgZxTpxIjo/E1l72S8= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-307-d5Tg86edMzmfH1iqxS0sUQ-1; Wed, 08 Feb 2023 16:31:27 -0500 X-MC-Unique: d5Tg86edMzmfH1iqxS0sUQ-1 Received: by mail-qk1-f197.google.com with SMTP id c9-20020a05620a11a900b0072a014ecc4aso13014741qkk.18 for ; Wed, 08 Feb 2023 13:31:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FIAor+VDsPlrB9lj+l3LEuEZ+2Aj/cQ4916Fau1bI0Q=; b=SnEbuqwrUKOglWjX1BoHlWemeYqMCJg4pCCGlH8Jpm2w0erOACCLzg6AtVWf7suNpb Djd14MTeXpAeo39SmAFgiKxePdvmGHcQahJRRZeMVaeA6iORkbfkFH9Lnxuu/JYyCnXU jTPTwtqbblByvzKkUXAepmhhL0hcRhvCN88DdpCaRHnvmmi/hQmT1omf/ypR+WrEWe7p sXK03ajY5g6vBLxRdIMZ8vbfQKwsdYUfB2NNR3BG/TAfOftPO0V4LIVConXKT6UqTPu6 KBwTpNG9twmgN/nPRe0sn7/Bb/j2F8D5I5vW4b77mVtCmzSIA0rvKw6rHULBo28KYpjN miHA== X-Gm-Message-State: AO0yUKXZBf/Her4qBiaS4xtPOwhrRy3XI9PwEqchlC/n0lwxGJnnMBoD APygJZ5QHbJSi488yS6PqiKPQ/lKkGHxiIho9QXQ39G1vmVUc2b0dzxhGkYefQj4WjIo527YazJ JWsittXm3Q7VV0hT4cubZPP/m X-Received: by 2002:a05:622a:4b:b0:3b8:6d44:ca7e with SMTP id y11-20020a05622a004b00b003b86d44ca7emr17516013qtw.4.1675891886295; Wed, 08 Feb 2023 13:31:26 -0800 (PST) X-Google-Smtp-Source: AK7set8MO3G4fUAKevd35vZj2kMQxmHZodb+yUyDlQNuQyvW5/EA2P822ioKc+/00V2eqHk7x67X+w== X-Received: by 2002:a05:622a:4b:b0:3b8:6d44:ca7e with SMTP id y11-20020a05622a004b00b003b86d44ca7emr17515958qtw.4.1675891885909; Wed, 08 Feb 2023 13:31:25 -0800 (PST) Received: from x1n (bras-base-aurron9127w-grc-56-70-30-145-63.dsl.bell.ca. [70.30.145.63]) by smtp.gmail.com with ESMTPSA id f4-20020a05622a1a0400b003b9b48cdbe8sm12419115qtb.58.2023.02.08.13.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 13:31:24 -0800 (PST) Date: Wed, 8 Feb 2023 16:31:22 -0500 From: Peter Xu To: Muhammad Usama Anjum Cc: David Hildenbrand , Andrew Morton , =?utf-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Andrei Vagin , Danylo Mocherniuk , Paul Gofman , Cyrill Gorcunov , Alexander Viro , Shuah Khan , Christian Brauner , Yang Shi , Vlastimil Babka , "Liam R . Howlett" , Yun Zhou , Suren Baghdasaryan , Alex Sierra , Matthew Wilcox , Pasha Tatashin , Mike Rapoport , Nadav Amit , Axel Rasmussen , "Gustavo A . R . Silva" , Dan Williams , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Greg KH , kernel@collabora.com Subject: Re: [PATCH v10 2/6] userfaultfd: update documentation to describe UFFD_FEATURE_WP_ASYNC Message-ID: References: <20230202112915.867409-1-usama.anjum@collabora.com> <20230202112915.867409-3-usama.anjum@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230202112915.867409-3-usama.anjum@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 02, 2023 at 04:29:11PM +0500, Muhammad Usama Anjum wrote: > Explain the difference created by UFFD_FEATURE_WP_ASYNC to the write > protection (UFFDIO_WRITEPROTECT_MODE_WP) mode. > > Signed-off-by: Muhammad Usama Anjum > --- > Documentation/admin-guide/mm/userfaultfd.rst | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/Documentation/admin-guide/mm/userfaultfd.rst b/Documentation/admin-guide/mm/userfaultfd.rst > index 83f31919ebb3..4747e7bd5b26 100644 > --- a/Documentation/admin-guide/mm/userfaultfd.rst > +++ b/Documentation/admin-guide/mm/userfaultfd.rst > @@ -221,6 +221,13 @@ former will have ``UFFD_PAGEFAULT_FLAG_WP`` set, the latter > you still need to supply a page when ``UFFDIO_REGISTER_MODE_MISSING`` was > used. > > +If ``UFFD_FEATURE_WP_ASYNC`` is set while calling ``UFFDIO_API`` ioctl, the > +behaviour of ``UFFDIO_WRITEPROTECT_MODE_WP`` changes such that faults for UFFDIO_WRITEPROTECT_MODE_WP is only a flag in UFFDIO_WRITEPROTECT, while it's forbidden only when not specified. > +anon and shmem are resolved automatically by the kernel instead of sending > +the message to the userfaultfd. The hugetlb isn't supported. The ``pagemap`` > +file can be read to find which pages have ``PM_UFFD_WP`` flag set which > +means they are write-protected. Here's my version. Please feel free to do modifications on top. If the userfaultfd context (that has ``UFFDIO_REGISTER_MODE_WP`` registered against) has ``UFFD_FEATURE_WP_ASYNC`` feature enabled, it will work in async write protection mode. It can be seen as a more accurate version of soft-dirty tracking, meanwhile the results will not be easily affected by other operations like vma merging. Comparing to the generic mode, the async mode will not generate any userfaultfd message when the protected memory range is written. Instead, the kernel will automatically resolve the page fault immediately by dropping the uffd-wp bit in the pgtables. The user app can collect the "written/dirty" status by looking up the uffd-wp bit for the pages being interested in /proc/pagemap. The page will be under track of uffd-wp async mode until the page is explicitly write-protected by ``UFFDIO_WRITEPROTECT`` ioctl with the mode flag ``UFFDIO_WRITEPROTECT_MODE_WP`` set. Trying to resolve a page fault that was tracked by async mode userfaultfd-wp is invalid. Currently ``UFFD_FEATURE_WP_ASYNC`` only support anonymous and shmem. Hugetlb is not yet supported. -- Peter Xu