Message ID | 20230202112915.867409-6-usama.anjum@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp184435wrn; Thu, 2 Feb 2023 03:34:54 -0800 (PST) X-Google-Smtp-Source: AK7set9O8bTB6yIPiTX0KF6Um8+5v9vzQYMsljb+KkU3ilCkr+gs+I3lhku1mL84xg5Lmi4qJfmN X-Received: by 2002:a05:6a20:65a6:b0:b8:36a7:c5c5 with SMTP id p38-20020a056a2065a600b000b836a7c5c5mr5255250pzh.27.1675337694122; Thu, 02 Feb 2023 03:34:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675337694; cv=none; d=google.com; s=arc-20160816; b=CnBGjm/mW4+OxV4mK0BFSPxtV67yXNxnotEkURGHw42Yx5Wi9YDY6g1fof5WRnElnm DVZoZEJbhwnQ+w1pzumYT+nvrft7A6eh+jhFHj6Kf1HqqZOg+ALNCb9dR5e7oNU11Gea l4FAul8Jp2NASbitPFzXYPXgGQDnDJL0yei3PgMTzJ+BfTNP8Jep4J+tjt6QXTzRGpKs I1t5hL2rpxgZp2sX4lvbyNeWbrrei7sbJkJ3UqOmZV+0OqBwoseUP3vC0YVHy8+OrMVZ Cd4COwzL1hFolfLojsVBu7L8lXa93EII6d9x/vaS51BYAJGadzKm9gWIZ6pcYZxhZH9P Qqgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7otXwiWFBXWPZObE9CW9hV/VZUa7QWv4OFOv17WGyvU=; b=UiRVXmcQ+KI5uUHxTFKwMidi5uZ+WnRitMdoPw3+CzfhVXu23eXwyDKNBMBhrHKN+1 jCL86H0t/0yjrdBNRA0IhNkd0znjgcnLMLWcts2+XBUwnRWsd0tUtoCc1fYz83yNvaTv b5ctFan2mivIVmL+hOyi4UAZjp0I6urSj9kTZCmEjGz9USbzXLZsZMRZ4Y4f5oNPoLP2 kJFzGD2Ree4rzriOGatwY8GSrFNi7uhatyUaV7IUQtVGBUTmuIw5hViJ8hK/mGSh5IuL A6RkzDiY/LDVPT4fJrgrtJzRscwmYM72C1SAFRsriRxzGXU5s/B5xdWV5PlxMSIn0ucn cMbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=LNzRn2uO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u64-20020a637943000000b004cff99eb246si12503028pgc.794.2023.02.02.03.34.42; Thu, 02 Feb 2023 03:34:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=LNzRn2uO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232262AbjBBLbW (ORCPT <rfc822;il.mystafa@gmail.com> + 99 others); Thu, 2 Feb 2023 06:31:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232145AbjBBLaz (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 2 Feb 2023 06:30:55 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D00658C1C9; Thu, 2 Feb 2023 03:30:52 -0800 (PST) Received: from localhost.localdomain (unknown [39.45.165.226]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madras.collabora.co.uk (Postfix) with ESMTPSA id 26B706602EEF; Thu, 2 Feb 2023 11:30:44 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1675337451; bh=rLlyIO3l9/ftTkxvT1S8wXZ6q3zRzsa4+kS1JjkCdaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LNzRn2uOBHFIIGjgY3mrnWpFZOvFEVEPpbuLkKnjX3xG+zLn36zT+MY+fYEtsxhEN qJ7Jz5qYFS23tEuBe06m4B1Y38T9WnmPUCdseCE2nUs9oorRNPYM/xhi1STGdQBWqR SIiqjkQzIPqKM9vyWQpi8NmK84J6iEIEx2Fz7y54dB2Bl72OiHTdj8IU1e2TO0Lgwx +bgWdPv7XQ8eWYuBePaowISY3eROPepkYhtTMWJh62VZR1ZoWc6G0NkAoI8pROUHEj pAYLdaMZZc/tfvCrKq8mLjxVm1PlHLtInA951+Q+CuG9X4R5Yqmky7cSrsr875cHy9 6zOz9vQak55nQ== From: Muhammad Usama Anjum <usama.anjum@collabora.com> To: Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, Andrew Morton <akpm@linux-foundation.org>, =?utf-8?b?TWljaGHFgiBNaXJvc8WC?= =?utf-8?b?YXc=?= <emmir@google.com>, Andrei Vagin <avagin@gmail.com>, Danylo Mocherniuk <mdanylo@google.com>, Paul Gofman <pgofman@codeweavers.com>, Cyrill Gorcunov <gorcunov@gmail.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Shuah Khan <shuah@kernel.org>, Christian Brauner <brauner@kernel.org>, Yang Shi <shy828301@gmail.com>, Vlastimil Babka <vbabka@suse.cz>, "Liam R . Howlett" <Liam.Howlett@Oracle.com>, Yun Zhou <yun.zhou@windriver.com>, Suren Baghdasaryan <surenb@google.com>, Alex Sierra <alex.sierra@amd.com>, Muhammad Usama Anjum <usama.anjum@collabora.com>, Matthew Wilcox <willy@infradead.org>, Pasha Tatashin <pasha.tatashin@soleen.com>, Mike Rapoport <rppt@kernel.org>, Nadav Amit <namit@vmware.com>, Axel Rasmussen <axelrasmussen@google.com>, "Gustavo A . R . Silva" <gustavoars@kernel.org>, Dan Williams <dan.j.williams@intel.com>, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Greg KH <gregkh@linuxfoundation.org>, kernel@collabora.com Subject: [PATCH v10 5/6] mm/pagemap: add documentation of PAGEMAP_SCAN IOCTL Date: Thu, 2 Feb 2023 16:29:14 +0500 Message-Id: <20230202112915.867409-6-usama.anjum@collabora.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230202112915.867409-1-usama.anjum@collabora.com> References: <20230202112915.867409-1-usama.anjum@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756718897783942635?= X-GMAIL-MSGID: =?utf-8?q?1756718897783942635?= |
Series |
Implement IOCTL to get and/or the clear info about PTEs
|
|
Commit Message
Muhammad Usama Anjum
Feb. 2, 2023, 11:29 a.m. UTC
Add some explanation and method to use write-protection and written-to
on memory range.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
Documentation/admin-guide/mm/pagemap.rst | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
Comments
On Thu, Feb 02, 2023 at 04:29:14PM +0500, Muhammad Usama Anjum wrote: > Add some explanation and method to use write-protection and written-to > on memory range. > > Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> > --- > Documentation/admin-guide/mm/pagemap.rst | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst > index 6e2e416af783..1cb2189e9a0d 100644 > --- a/Documentation/admin-guide/mm/pagemap.rst > +++ b/Documentation/admin-guide/mm/pagemap.rst > @@ -230,3 +230,27 @@ Before Linux 3.11 pagemap bits 55-60 were used for "page-shift" (which is > always 12 at most architectures). Since Linux 3.11 their meaning changes > after first clear of soft-dirty bits. Since Linux 4.2 they are used for > flags unconditionally. > + > +Pagemap Scan IOCTL > +================== > + > +The ``PAGEMAP_SCAN`` IOCTL on the pagemap file can be used to get and/or clear > +the info about page table entries. The following operations are supported in > +this IOCTL: > +- Get the information if the pages have been written-to (``PAGE_IS_WRITTEN``), > + file mapped (``PAGE_IS_FILE``), present (``PAGE_IS_PRESENT``) or swapped > + (``PAGE_IS_SWAPPED``). > +- Write-protect the pages (``PAGEMAP_WP_ENGAGE``) to start finding which > + pages have been written-to. > +- Find pages which have been written-to and write protect the pages > + (atomic ``PAGE_IS_WRITTEN + PAGEMAP_WP_ENGAGE``) Could we extend this section a bit more? Some points for reference: - The new struct you introduced, definitions of each of the fields, and generic use cases for each of the field/ops. - It'll be nice to list the OPs the new interface supports (GET, WP_ENGAGE, GET+WP_ENGAGE). - When should people use this rather than the old pagemap interface? What's the major problems to solve / what's the major difference? (Maybe nice to reference the Windows API too here) > + > +To get information about which pages have been written-to and/or write protect > +the pages, following must be performed first in order: > + 1. The userfaultfd file descriptor is created with ``userfaultfd`` syscall. > + 2. The ``UFFD_FEATURE_WP_ASYNC`` feature is set by ``UFFDIO_API`` IOCTL. > + 3. The memory range is registered with ``UFFDIO_REGISTER_MODE_WP`` mode > + through ``UFFDIO_REGISTER`` IOCTL. > +Then the any part of the registered memory or the whole memory region can be > +write protected using the ``UFFDIO_WRITEPROTECT`` IOCTL or ``PAGEMAP_SCAN`` > +IOCTL. This part looks good. Thanks,
On 2/10/23 12:26 AM, Peter Xu wrote: > On Thu, Feb 02, 2023 at 04:29:14PM +0500, Muhammad Usama Anjum wrote: >> Add some explanation and method to use write-protection and written-to >> on memory range. >> >> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> >> --- >> Documentation/admin-guide/mm/pagemap.rst | 24 ++++++++++++++++++++++++ >> 1 file changed, 24 insertions(+) >> >> diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst >> index 6e2e416af783..1cb2189e9a0d 100644 >> --- a/Documentation/admin-guide/mm/pagemap.rst >> +++ b/Documentation/admin-guide/mm/pagemap.rst >> @@ -230,3 +230,27 @@ Before Linux 3.11 pagemap bits 55-60 were used for "page-shift" (which is >> always 12 at most architectures). Since Linux 3.11 their meaning changes >> after first clear of soft-dirty bits. Since Linux 4.2 they are used for >> flags unconditionally. >> + >> +Pagemap Scan IOCTL >> +================== >> + >> +The ``PAGEMAP_SCAN`` IOCTL on the pagemap file can be used to get and/or clear >> +the info about page table entries. The following operations are supported in >> +this IOCTL: >> +- Get the information if the pages have been written-to (``PAGE_IS_WRITTEN``), >> + file mapped (``PAGE_IS_FILE``), present (``PAGE_IS_PRESENT``) or swapped >> + (``PAGE_IS_SWAPPED``). >> +- Write-protect the pages (``PAGEMAP_WP_ENGAGE``) to start finding which >> + pages have been written-to. >> +- Find pages which have been written-to and write protect the pages >> + (atomic ``PAGE_IS_WRITTEN + PAGEMAP_WP_ENGAGE``) > > Could we extend this section a bit more? Some points for reference: > > - The new struct you introduced, definitions of each of the fields, and > generic use cases for each of the field/ops. > > - It'll be nice to list the OPs the new interface supports (GET, > WP_ENGAGE, GET+WP_ENGAGE). > > - When should people use this rather than the old pagemap interface? > What's the major problems to solve / what's the major difference? > (Maybe nice to reference the Windows API too here) I'll update the documentation. > >> + >> +To get information about which pages have been written-to and/or write protect >> +the pages, following must be performed first in order: >> + 1. The userfaultfd file descriptor is created with ``userfaultfd`` syscall. >> + 2. The ``UFFD_FEATURE_WP_ASYNC`` feature is set by ``UFFDIO_API`` IOCTL. >> + 3. The memory range is registered with ``UFFDIO_REGISTER_MODE_WP`` mode >> + through ``UFFDIO_REGISTER`` IOCTL. >> +Then the any part of the registered memory or the whole memory region can be >> +write protected using the ``UFFDIO_WRITEPROTECT`` IOCTL or ``PAGEMAP_SCAN`` >> +IOCTL. > > This part looks good. > > Thanks, >
diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst index 6e2e416af783..1cb2189e9a0d 100644 --- a/Documentation/admin-guide/mm/pagemap.rst +++ b/Documentation/admin-guide/mm/pagemap.rst @@ -230,3 +230,27 @@ Before Linux 3.11 pagemap bits 55-60 were used for "page-shift" (which is always 12 at most architectures). Since Linux 3.11 their meaning changes after first clear of soft-dirty bits. Since Linux 4.2 they are used for flags unconditionally. + +Pagemap Scan IOCTL +================== + +The ``PAGEMAP_SCAN`` IOCTL on the pagemap file can be used to get and/or clear +the info about page table entries. The following operations are supported in +this IOCTL: +- Get the information if the pages have been written-to (``PAGE_IS_WRITTEN``), + file mapped (``PAGE_IS_FILE``), present (``PAGE_IS_PRESENT``) or swapped + (``PAGE_IS_SWAPPED``). +- Write-protect the pages (``PAGEMAP_WP_ENGAGE``) to start finding which + pages have been written-to. +- Find pages which have been written-to and write protect the pages + (atomic ``PAGE_IS_WRITTEN + PAGEMAP_WP_ENGAGE``) + +To get information about which pages have been written-to and/or write protect +the pages, following must be performed first in order: + 1. The userfaultfd file descriptor is created with ``userfaultfd`` syscall. + 2. The ``UFFD_FEATURE_WP_ASYNC`` feature is set by ``UFFDIO_API`` IOCTL. + 3. The memory range is registered with ``UFFDIO_REGISTER_MODE_WP`` mode + through ``UFFDIO_REGISTER`` IOCTL. +Then the any part of the registered memory or the whole memory region can be +write protected using the ``UFFDIO_WRITEPROTECT`` IOCTL or ``PAGEMAP_SCAN`` +IOCTL.