Re: [RFC PATCH 2/3] mm: provide rmap_wrprotect_file_page() function

From
Matthew Wilcox <willy@infradead.org>
Date
2025-01-08 17:25:05
Also in
dri-devel, linux-mm, lkml
Reply to
Lorenzo Stoakes, 2025-01-08
On Wed, Jan 08, 2025 at 04:18:41PM +0000, Lorenzo Stoakes wrote:
quoted hunk ↗ jump to hunk
+++ b/include/linux/rmap.h
@@ -754,6 +754,26 @@ unsigned long page_address_in_vma(const struct folio *folio,
  */
 int folio_mkclean(struct folio *);
 
+/**
The kerneldoc comment should be with the implementation, not the
prototype.
quoted hunk ↗ jump to hunk
+ * rmap_wrprotect_file_page() - Traverses the reverse mapping, finding all VMAs
+ * which contain a shared mapping of the single page at PFN @pfn in @mapping at
+ * offset @pgoff and write-protecting the mappings.
After the '-' should come a _short_ description ... maybe "Write protect
all mappings of this page".
quoted hunk ↗ jump to hunk
+ * The PFN mapped does not have to be a folio, but rather can be a kernel
+ * allocation that is mapped into userland. We therefore do not require that the
+ * PFN maps to a folio with a valid mapping or index field, rather these are
+ * specified in @mapping and @pgoff.
+ *
+ * @mapping:	The mapping whose reverse mapping should be traversed.
+ * @pgoff:	The page offset at which @pfn is mapped within @mapping.
+ * @nr_pages:	The number of physically contiguous base pages spanned.
+ * @pfn:	The PFN of the memory mapped in @mapping at @pgoff.
The description of the params comes between the short and full
description of the function.
+ * Return the number of write-protected PTEs, or an error.
colon after Return: so it becomes a section.
quoted hunk ↗ jump to hunk
+int rmap_wrprotect_file_page(struct address_space *mapping, pgoff_t pgoff,
+		unsigned long nr_pages, unsigned long pfn)
+{
+	struct wrprotect_file_state state = {
+		.cleaned = 0,
+		.pgoff = pgoff,
+		.pfn = pfn,
+		.nr_pages = nr_pages,
+	};
+	struct rmap_walk_control rwc = {
+		.arg = (void *)&state,
+		.rmap_one = rmap_wrprotect_file_one,
+		.invalid_vma = invalid_mkclean_vma,
+	};
+
+	if (!mapping)
+		return 0;
Should it be valid to pass in NULL?
Thread (18 messages) 18 messages, 3 authors, last reply 2025-01-13
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help