hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/include/linux/rmap.h
....@@ -11,6 +11,10 @@
1111 #include <linux/rwsem.h>
1212 #include <linux/memcontrol.h>
1313 #include <linux/highmem.h>
14
+#ifndef __GENKSYMS__
15
+#define PROTECT_TRACE_INCLUDE_PATH
16
+#include <trace/hooks/mm.h>
17
+#endif
1418
1519 /*
1620 * The anon_vma heads a list of private "related" vmas, to scan if
....@@ -38,13 +42,7 @@
3842 */
3943 atomic_t refcount;
4044
41
- /*
42
- * Count of child anon_vmas and VMAs which points to this anon_vma.
43
- *
44
- * This counter is used for making decision about reusing anon_vma
45
- * instead of forking new one. See comments in function anon_vma_clone.
46
- */
47
- unsigned degree;
45
+ unsigned degree; /* ANDROID: KABI preservation, DO NOT USE! */
4846
4947 struct anon_vma *parent; /* Parent of this anon_vma */
5048
....@@ -59,6 +57,25 @@
5957
6058 /* Interval tree of private "related" vmas */
6159 struct rb_root_cached rb_root;
60
+
61
+ /*
62
+ * ANDROID: KABI preservation, it's safe to put these at the end of this structure as it's
63
+ * only passed by a pointer everywhere, the size and internal structures are local to the
64
+ * core kernel.
65
+ */
66
+#ifndef __GENKSYMS__
67
+ /*
68
+ * Count of child anon_vmas. Equals to the count of all anon_vmas that
69
+ * have ->parent pointing to this one, including itself.
70
+ *
71
+ * This counter is used for making decision about reusing anon_vma
72
+ * instead of forking new one. See comments in function anon_vma_clone.
73
+ */
74
+ unsigned long num_children;
75
+ /* Count of VMAs whose ->anon_vma pointer points to this object. */
76
+ unsigned long num_active_vmas;
77
+#endif
78
+
6279 };
6380
6481 /*
....@@ -77,7 +94,7 @@
7794 struct anon_vma_chain {
7895 struct vm_area_struct *vma;
7996 struct anon_vma *anon_vma;
80
- struct list_head same_vma; /* locked by mmap_sem & page_table_lock */
97
+ struct list_head same_vma; /* locked by mmap_lock & page_table_lock */
8198 struct rb_node rb; /* locked by anon_vma->rwsem */
8299 unsigned long rb_subtree_last;
83100 #ifdef CONFIG_DEBUG_VM_RB
....@@ -91,15 +108,14 @@
91108
92109 TTU_SPLIT_HUGE_PMD = 0x4, /* split huge PMD if any */
93110 TTU_IGNORE_MLOCK = 0x8, /* ignore mlock */
94
- TTU_IGNORE_ACCESS = 0x10, /* don't age */
111
+ TTU_SYNC = 0x10, /* avoid racy checks with PVMW_SYNC */
95112 TTU_IGNORE_HWPOISON = 0x20, /* corrupted page is recoverable */
96113 TTU_BATCH_FLUSH = 0x40, /* Batch TLB flushes where possible
97114 * and caller guarantees they will
98115 * do a final flush if necessary */
99116 TTU_RMAP_LOCKED = 0x80, /* do not grab rmap lock:
100117 * caller holds it */
101
- TTU_SPLIT_FREEZE = 0x100, /* freeze pte under splitting thp */
102
- TTU_SYNC = 0x200, /* avoid racy checks with PVMW_SYNC */
118
+ TTU_SPLIT_FREEZE = 0x100, /* freeze pte under splitting thp */
103119 };
104120
105121 #ifdef CONFIG_MMU
....@@ -129,6 +145,11 @@
129145 static inline void anon_vma_lock_read(struct anon_vma *anon_vma)
130146 {
131147 down_read(&anon_vma->root->rwsem);
148
+}
149
+
150
+static inline int anon_vma_trylock_read(struct anon_vma *anon_vma)
151
+{
152
+ return down_read_trylock(&anon_vma->root->rwsem);
132153 }
133154
134155 static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
....@@ -175,8 +196,16 @@
175196 unsigned long, bool);
176197 void do_page_add_anon_rmap(struct page *, struct vm_area_struct *,
177198 unsigned long, int);
178
-void page_add_new_anon_rmap(struct page *, struct vm_area_struct *,
179
- unsigned long, bool);
199
+void __page_add_new_anon_rmap(struct page *page, struct vm_area_struct *vma,
200
+ unsigned long address, bool compound);
201
+static inline void page_add_new_anon_rmap(struct page *page,
202
+ struct vm_area_struct *vma,
203
+ unsigned long address, bool compound)
204
+{
205
+ VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma);
206
+ __page_add_new_anon_rmap(page, vma, address, compound);
207
+}
208
+
180209 void page_add_file_rmap(struct page *, bool);
181210 void page_remove_rmap(struct page *, bool);
182211
....@@ -187,7 +216,12 @@
187216
188217 static inline void page_dup_rmap(struct page *page, bool compound)
189218 {
190
- atomic_inc(compound ? compound_mapcount_ptr(page) : &page->_mapcount);
219
+ bool success = false;
220
+
221
+ if (!compound)
222
+ trace_android_vh_update_page_mapcount(page, true, compound, NULL, &success);
223
+ if (!success)
224
+ atomic_inc(compound ? compound_mapcount_ptr(page) : &page->_mapcount);
191225 }
192226
193227 /*
....@@ -245,17 +279,14 @@
245279
246280 void remove_migration_ptes(struct page *old, struct page *new, bool locked);
247281
248
-/*
249
- * Called by memory-failure.c to kill processes.
250
- */
251
-struct anon_vma *page_lock_anon_vma_read(struct page *page);
252
-void page_unlock_anon_vma_read(struct anon_vma *anon_vma);
253282 int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma);
254283
255284 /*
256285 * rmap_walk_control: To control rmap traversing for specific needs
257286 *
258287 * arg: passed to rmap_one() and invalid_vma()
288
+ * try_lock: bail out if the rmap lock is contended
289
+ * contended: indicate the rmap traversal bailed out due to lock contention
259290 * rmap_one: executed on each vma where page is mapped
260291 * done: for checking traversing termination condition
261292 * anon_lock: for getting anon_lock by optimized way rather than default
....@@ -263,6 +294,8 @@
263294 */
264295 struct rmap_walk_control {
265296 void *arg;
297
+ bool try_lock;
298
+ bool contended;
266299 /*
267300 * Return false if page table scanning in rmap_walk should be stopped.
268301 * Otherwise, return true.
....@@ -270,13 +303,21 @@
270303 bool (*rmap_one)(struct page *page, struct vm_area_struct *vma,
271304 unsigned long addr, void *arg);
272305 int (*done)(struct page *page);
273
- struct anon_vma *(*anon_lock)(struct page *page);
306
+ struct anon_vma *(*anon_lock)(struct page *page,
307
+ struct rmap_walk_control *rwc);
274308 bool (*invalid_vma)(struct vm_area_struct *vma, void *arg);
275309 };
276310
277311 void rmap_walk(struct page *page, struct rmap_walk_control *rwc);
278312 void rmap_walk_locked(struct page *page, struct rmap_walk_control *rwc);
279313
314
+/*
315
+ * Called by memory-failure.c to kill processes.
316
+ */
317
+struct anon_vma *page_lock_anon_vma_read(struct page *page,
318
+ struct rmap_walk_control *rwc);
319
+void page_unlock_anon_vma_read(struct anon_vma *anon_vma);
320
+
280321 #else /* !CONFIG_MMU */
281322
282323 #define anon_vma_init() do {} while (0)