From patchwork Thu Feb 2 11:29:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13125839 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7CFCC64EC3 for ; Thu, 2 Feb 2023 11:30:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44D3C6B007E; Thu, 2 Feb 2023 06:30:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 407316B0080; Thu, 2 Feb 2023 06:30:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C57C6B0081; Thu, 2 Feb 2023 06:30:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1EB4B6B007E for ; Thu, 2 Feb 2023 06:30:55 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EC6BD1A0167 for ; Thu, 2 Feb 2023 11:30:54 +0000 (UTC) X-FDA: 80422134828.06.94BAFC2 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by imf19.hostedemail.com (Postfix) with ESMTP id E983C1A001D for ; Thu, 2 Feb 2023 11:30:52 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=LNzRn2uO; spf=pass (imf19.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.172 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=reject) header.from=collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675337453; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7otXwiWFBXWPZObE9CW9hV/VZUa7QWv4OFOv17WGyvU=; b=yqAmB3TCXdKjF7YHCUZgsq7TPDKbFyQwcJ/CPyB/9+nuctKtEO5K9ZAL4dcIWjrhOkyZsw ZW89EEzq6SSlJeJvkyb9zozyXjPft+sLhFg0+zc2LfGriPDeWcRYcIy0pJd0vf/LZ0LJmM Y6ktHcRvvQOse+Y+zE7+xs7ornJWZn4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=LNzRn2uO; spf=pass (imf19.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.172 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=reject) header.from=collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675337453; a=rsa-sha256; cv=none; b=Yr2eC5EuRMpNBDdTpE+f5c7SYHztjOfDKXorPKZNx7MCQLVvBX1LAFK0vYB0uRLbG9O1TC sMRtD+hgC0XUfO/R5IWQ1keRsEWhDZWwBlAbJzSRXymEO74ow2zWYohnKA3mtxlHNTOJ2f 0+tj8ij8wZG4QbvLm0ttrTf1tftOz04= 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 To: Peter Xu , David Hildenbrand , Andrew Morton , =?utf-8?b?TWljaGHFgiBNaXJvc8WC?= =?utf-8?b?YXc=?= , Andrei Vagin , Danylo Mocherniuk , Paul Gofman , Cyrill Gorcunov Cc: Alexander Viro , Shuah Khan , Christian Brauner , Yang Shi , Vlastimil Babka , "Liam R . Howlett" , Yun Zhou , Suren Baghdasaryan , Alex Sierra , Muhammad Usama Anjum , 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: [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 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E983C1A001D X-Stat-Signature: xci9eqxh9eb71h8uag7ee9ax7kw6f3o1 X-Rspam-User: X-HE-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/qqdv/FurqiiS560Tvx44LZyvXAwLtV6QwA8qUkWLlmiuz3L/eLtPP5jaKOgWGUyY6QVgyL01ESSWa8vZvrwByyTsmcUqBQ+LZgdYzv8i6eOeE15GiRMR5JQj/55onkWu5tv3lzp4fxG6O6gtfCFX3WifbjGWC3HpFzbOJDnB3skoCci59CFuSYdwuiP5+THDfLKz4Mi3A/FppmxtRJdWtOtnIAa8iNq1IKW+Gpfh5JH7cRkg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add some explanation and method to use write-protection and written-to on memory range. Signed-off-by: Muhammad Usama Anjum --- 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``) + +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.