[RFC PATCH v2 2/9] mm/damon/core: read the CPU number with preemption disabled

From: Ravi Jonnalagadda

Date: Thu Sep 10 2026 - 13:35:42 EST


damon_report_page_fault() runs in fault context, which is preemptible, so
reading the CPU number there triggers a "using smp_processor_id() in
preemptible" report.

Read it with preemption disabled, and keep it disabled across the report
so the recorded CPU stays consistent with the per-CPU ring the report is
queued to, which is selected the same way.

Signed-off-by: Ravi Jonnalagadda <ravis.opensrc@xxxxxxxxx>
---
mm/damon/core.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 5fdb5922edb78..991ddb9a09414 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2514,7 +2514,6 @@ void damon_report_page_fault(struct vm_fault *vmf, bool huge_pmd)
struct damon_access_report access_report = {
.vaddr = vmf->address,
.size = 1, /* todo: set appripriately */
- .cpu = smp_processor_id(),
.tid = task_pid_vnr(current),
.is_write = vmf->flags & FAULT_FLAG_WRITE,
};
@@ -2524,7 +2523,15 @@ void damon_report_page_fault(struct vm_fault *vmf, bool huge_pmd)
else
access_report.paddr = PFN_PHYS(pte_pfn(vmf->orig_pte));

+ /*
+ * This runs in fault context, which is preemptible, so the CPU number
+ * is read with preemption disabled. Holding it across the report also
+ * keeps the recorded CPU consistent with the per-CPU ring the report is
+ * queued to, which damon_report_access() selects the same way.
+ */
+ access_report.cpu = get_cpu();
damon_report_access(&access_report);
+ put_cpu();
}
#endif

--
2.43.0